Compare commits

...
Sign in to create a new pull request.

2 commits

Author SHA1 Message Date
manzerbredes
075a3f6f44 Clear branch 2015-03-11 10:18:34 +04:00
manzerbredes
3b86f1c910 Create stable empty branch. 2015-03-11 10:14:31 +04:00
6 changed files with 2 additions and 233 deletions

View file

@ -1,68 +0,0 @@
/**
* @file HASHCrypt.cpp
* @brief HASHCrypt class definitions
* @author manzerbredes
* @date 8 Mars 2015
*
* Contain all definitions of HASHCrypt class.
*
*/
#include "HASHCrypt.hpp"
//Constructor
HASHCrypt::HASHCrypt(){
}
//Destructor
HASHCrypt::~HASHCrypt(){
}
void HASHCrypt::getMD5_128(std::string chain, byte* digest, int size){
//Digest size controller
this->checkDigestSize(CryptoPP::Weak1::MD5::DIGESTSIZE,size);
//Create the MD5 on digest parameter
CryptoPP::Weak1::MD5 hash;
hash.CalculateDigest( digest, (byte*) chain.c_str(), chain.length() );
}
void HASHCrypt::getSHA_256(std::string chain, byte* digest, int size){
//Digest size controller
this->checkDigestSize(CryptoPP::SHA256::DIGESTSIZE,size);
//Create the SHA-256 on digest parameter
CryptoPP::SHA256 hash;
hash.CalculateDigest( digest, (byte*) chain.c_str(), chain.length() );
}
void HASHCrypt::checkDigestSize(int sizeRequired, int size){
try{
if(size !=sizeRequired){
throw this->getInvalidDigestSizeError(sizeRequired, size);
}
}
catch(std::string erreur){
std::cerr << erreur <<std::endl;
std::exit(EXIT_FAILURE);
}
}
std::string HASHCrypt::getInvalidDigestSizeError(int sizeRequired, int size){
std::ostringstream erreurStream;
erreurStream << "Invalid digest size ! ("<< sizeRequired <<" bytes required and "<< size <<" given)";
return erreurStream.str();
}

View file

@ -1,99 +0,0 @@
/**
* @file HASHCrypt.hpp
* @brief HASHCrypt class header
* @author manzerbredes
* @date 8 Mars 2015
*
* Contain all prototypes of HASHCrypt class.
*
*/
//----- std -----
#include <iostream>
#include <string>
#include <sstream>
//----- crypto++ -----
#include <crypto++/md5.h> //For MD5
#include <crypto++/hex.h> //For Hex convertion
#include <crypto++/sha.h> //For SHA
/**
* @class HASHCrypt HASHCrypt.hpp "/CryptClass/HASHCrypt.hpp"
* @brief Hashing class
* @author manzerbredes
*
* Class who handle hashing functions to a byte* parameter.
* HASHCrypt try to detect errors and throw exceptions.
* HASHCrypt use crypto++ library.
*/
class HASHCrypt{
public:
/**
* @brief Contructor
*/
HASHCrypt();
/**
* @brief Destructor
*/
~HASHCrypt();
/**
* @brief Create an MD5 over 128 bits on a digest array of bytes.
*
* @param chain : Chain to hash
* @param digest : An array of bytes (8 bits)
* @param size : Length of the array digest
*
* **Warning** digest will be modified.
* Digest must be an array of byte with 16 entries
*/
void getMD5_128(std::string chain, byte* digest, int size);
/**
* @brief Create an SHA over 256 bits on a digest array of bytes.
*
* @param chain : Chain to hash
* @param digest : An array of bytes (8 bits)
* @param size : Length of the array digest
*
* **Warning** digest will be modified.
* Digest must be an array of byte with 32 entries
*/
void getSHA_256(std::string chain, byte* digest, int size); //Retourne SHA_256
private:
/**
* @brief Check the digest size
*
* @param sizeRequired : Digest size expected
* @param size : Given digest size
*
* Throw an exception, and stop the programm if
* sizeRequired != size
* Use getInvalidDigestSizeError method.
*/
void checkDigestSize(int sizeRequired, int size);
/**
* @brief Make and error message.
*
* @param sizeRequired : Digest size expected
* @param size : Given digest size
*
* @return a string correspond to the error message
*
* Construct an error message with sizeRequired and size.
*/
std::string getInvalidDigestSizeError(int sizeRequired, int size);
};

2
Empty.md Normal file
View file

@ -0,0 +1,2 @@
Empty branch
=====

View file

@ -1,66 +0,0 @@
/**
* @file main.cpp
* @brief Entry point
* @author manzerbredes
* @version Prototype
* @date 8 Mars 2015
*
* Entry point of the application.
*
*/
//----- std -----
#include <iostream>
#include <string>
//----- class -----
#include "CryptClass/HASHCrypt.hpp"
//----- Prototype -----
void aff(std::string chaine);
/**
* @fn int main(int argc, char *argv[])
* @author manzerbredes
* @brief main function
* @param argc contain *argv[] length
* @param *argv[] contain the arguments list
* @return Return code, an int.
*/
int main(int argc, char *argv[]){
HASHCrypt hash= HASHCrypt();
byte code[16];
hash.getMD5_128("Phrase de test !", code, sizeof(code));
for(int i=0; i<16;i++){
std::cout << code[i];
}
return 0;
}
//---- Functions -----
void aff(std::string chaine){
std::cout << chaine;
}