changed: in Crypt:

renamed Hash() -> HashBin()
         HashBin() is using a binary output from OpenSSL now
	 previously we are using the hex output and with the new OpenSSL version
         the text has additional characters and causes some problems
	 added: HashHex() - it is using the HashBin() and then converts the output
	 to hex format itself
	 



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@891 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2012-09-19 23:17:10 +00:00
parent 5cdf6eff36
commit 26e87b20b1
5 changed files with 153 additions and 64 deletions

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* Copyright (c) 2011-2012, Tomasz Sowa
* All rights reserved.
*
*/
@@ -50,11 +50,11 @@ public:
in - input buffer
inlen - the length of the buffer
output:
out - the hash
out - the hash in binary form
*/
bool Hash(int hash, const char * in, size_t inlen, std::string & out);
bool Hash(int hash, const char * in, std::string & out);
bool Hash(int hash, const std::string & in, std::string & out);
bool HashBin(int hash, const char * in, size_t inlen, std::string & out);
bool HashBin(int hash, const char * in, std::string & out);
bool HashBin(int hash, const std::string & in, std::string & out);
/*
@@ -66,11 +66,43 @@ public:
in - input buffer
inlen - the length of the buffer
output:
out - the hash
out - the hash in binary form
*/
bool Hash(int hash, const wchar_t * in, size_t inlen, std::wstring & out);
bool Hash(int hash, const wchar_t * in, std::wstring & out);
bool Hash(int hash, const std::wstring & in, std::wstring & out);
bool HashBin(int hash, const wchar_t * in, size_t inlen, std::string & out);
bool HashBin(int hash, const wchar_t * in, std::string & out);
bool HashBin(int hash, const std::wstring & in, std::string & out);
/*
calculating a hash from a given input
input:
hash - the kind of the hash - WINIX_CRYPT_HASH_*
in - input buffer
inlen - the length of the buffer
output:
out - the hash in the hex form (one byte is saved as two hex digits)
*/
bool HashHex(int hash, const char * in, size_t inlen, std::string & out);
bool HashHex(int hash, const char * in, std::string & out);
bool HashHex(int hash, const std::string & in, std::string & out);
/*
calculating a hash from a given input
the input string is first changed to UTF8 and then hash is calculated
input:
hash - the kind of the hash - WINIX_CRYPT_HASH_*
in - input buffer
inlen - the length of the buffer
output:
out - the hash in the hex form (one byte is saved as two hex digits)
the 'out' here is std::wstring (not std::string like beforehand)
*/
bool HashHex(int hash, const wchar_t * in, size_t inlen, std::wstring & out);
bool HashHex(int hash, const wchar_t * in, std::wstring & out);
bool HashHex(int hash, const std::wstring & in, std::wstring & out);
/*
@@ -83,7 +115,7 @@ public:
inlen - the size of the buffer
output:
out - encrypted or decrypted buffer
out - encrypted or decrypted buffer (always binary)
*/
bool RSA(bool encrypt, const char * keypath, const char * in, size_t inlen, std::string & out);
bool RSA(bool encrypt, const char * keypath, const std::string & in, std::string & out);
@@ -179,22 +211,27 @@ public:
private:
void TrimLastWhite(std::string & str);
Config * config;
Run run;
std::string command, bufina, bufouta, keypatha;
std::string command, bufina, keypatha;
//std::wstring pass_salted;//, pass_hashed;
//std::string pass_hasheda, pass_encrypteda;
std::wstring pass_salted, pass_org;
std::string passa;
std::string passa, out_temp;
std::wstring empty;
template<typename StringType>
void ConvertToHexForm(const std::string & in, StringType & out);
char ConvertToHexForm(int val);
};
template<class StringType>
template<typename StringType>
void Crypt::ClearString(StringType & str)
{
for(size_t i=0 ; i<str.size() ; ++i)
@@ -204,6 +241,22 @@ void Crypt::ClearString(StringType & str)
}
template<typename StringType>
void Crypt::ConvertToHexForm(const std::string & in, StringType & out)
{
out.clear();
if( in.size() * 2 > out.capacity() )
out.reserve(in.size() * 2);
for(size_t i=0 ; i<in.size() ; ++i)
{
out += ConvertToHexForm(((unsigned char)in[i]) >> 4);
out += ConvertToHexForm(((unsigned char)in[i]) & 0x0f);
}
}
#endif