@ -10,7 +10,6 @@
# include <cstring>
# include "crypt.h"
# include "utf8/utf8.h"
# include "misc.h"
# include "log.h"
@ -21,22 +20,19 @@ void Crypt::SetConfig(Config * pconfig)
}
void Crypt : : TrimLastWhite ( std : : string & str )
char Crypt : : ConvertToHexForm ( int val )
{
if ( str. empty ( ) )
return ;
if ( val < 10 )
return val + ' 0 ' ;
size_t i = str . size ( ) ;
return val - 10 + ' a ' ;
}
while ( i > 0 & & ( IsWhite ( str [ i - 1 ] ) | | str [ i - 1 ] = = 10 ) )
i - = 1 ;
if ( i < str . size ( ) )
str . erase ( i ) ;
}
bool Crypt : : Hash ( int hash , const char * in , size_t inlen , std : : string & out )
bool Crypt : : HashBin ( int hash , const char * in , size_t inlen , std : : string & out )
{
out . clear ( ) ;
@ -47,6 +43,7 @@ bool Crypt::Hash(int hash, const char * in, size_t inlen, std::string & out)
PT : : WideToUTF8 ( config - > opensll_path , command ) ;
run . Cmd ( command ) ;
run . Par ( " dgst " ) ;
run . Par ( " -binary " ) ;
switch ( hash )
{
@ -62,52 +59,96 @@ bool Crypt::Hash(int hash, const char * in, size_t inlen, std::string & out)
return false ;
}
bool result = run . Go ( in , inlen , out ) = = 0 ;
TrimLastWhite ( out ) ;
return result ;
return run . Go ( in , inlen , out ) = = 0 ;
}
bool Crypt : : Hash ( int hash , const char * in , std : : string & out )
bool Crypt : : Hash Bin ( int hash , const char * in , std : : string & out )
{
size_t len = strlen ( in ) ;
return Hash ( hash , in , len , out ) ;
return Hash Bin ( hash , in , len , out ) ;
}
bool Crypt : : Hash ( int hash , const std : : string & in , std : : string & out )
bool Crypt : : Hash Bin ( int hash , const std : : string & in , std : : string & out )
{
return Hash ( hash , in . c_str ( ) , in . size ( ) , out ) ;
return Hash Bin ( hash , in . c_str ( ) , in . size ( ) , out ) ;
}
bool Crypt : : Hash ( int hash , const wchar_t * in , size_t inlen , std : : w string & out )
bool Crypt : : Hash Bin ( int hash , const wchar_t * in , size_t inlen , std : : string & out )
{
PT : : WideToUTF8 ( in , inlen , bufina ) ;
int res = Hash ( hash , bufina . c_str ( ) , bufina . size ( ) , bufouta ) ;
int res = HashBin ( hash , bufina . c_str ( ) , bufina . size ( ) , out ) ;
bufina . clear ( ) ;
// the output hash is not a UTF8 string
// it consists only from ascii letters
AssignString ( bufouta , out ) ;
return res ;
}
bool Crypt : : Hash ( int hash , const wchar_t * in , std : : w string & out )
bool Crypt : : Hash Bin ( int hash , const wchar_t * in , std : : string & out )
{
size_t len = wcslen ( in ) ;
return Hash ( hash , in , len , out ) ;
return HashBin ( hash , in , len , out ) ;
}
bool Crypt : : HashBin ( int hash , const std : : wstring & in , std : : string & out )
{
return HashBin ( hash , in . c_str ( ) , in . size ( ) , out ) ;
}
bool Crypt : : Hash ( int hash , const std : : wstring & in , std : : wstring & out )
bool Crypt : : HashHex ( int hash , const char * in , size_t inlen , std : : string & out )
{
int res = HashBin ( hash , in , inlen , out_temp ) ;
ConvertToHexForm ( out_temp , out ) ;
out_temp . clear ( ) ;
return res ;
}
bool Crypt : : HashHex ( int hash , const char * in , std : : string & out )
{
size_t len = strlen ( in ) ;
return HashHex ( hash , in , len , out ) ;
}
bool Crypt : : HashHex ( int hash , const std : : string & in , std : : string & out )
{
return HashHex ( hash , in . c_str ( ) , in . size ( ) , out ) ;
}
bool Crypt : : HashHex ( int hash , const wchar_t * in , size_t inlen , std : : wstring & out )
{
int res = HashBin ( hash , in , inlen , out_temp ) ;
ConvertToHexForm ( out_temp , out ) ;
out_temp . clear ( ) ;
return res ;
}
bool Crypt : : HashHex ( int hash , const wchar_t * in , std : : wstring & out )
{
size_t len = wcslen ( in ) ;
return HashHex ( hash , in , len , out ) ;
}
bool Crypt : : HashHex ( int hash , const std : : wstring & in , std : : wstring & out )
{
return Hash ( hash , in . c_str ( ) , in . size ( ) , out ) ;
return Hash Hex ( hash , in . c_str ( ) , in . size ( ) , out ) ;
}
@ -199,7 +240,7 @@ bool Crypt::PassHash(const std::wstring & salt, UserPass & up)
pass_salted = up . pass ;
pass_salted + = salt ;
if ( Hash ( up . pass_type , pass_salted , up . pass ) )
if ( Hash Hex ( up . pass_type , pass_salted , up . pass ) )
{
if ( ! salt . empty ( ) )
up . pass_hash_salted = true ;