40 #ifndef __INCLUDE_HASH_ALGORITHM__
41 #define __INCLUDE_HASH_ALGORITHM__
43 #ifndef __INCLUDE_MIST_CONF_H__
91 typedef unsigned long long int uint64;
95 unsigned char *digest;
99 virtual void compute_hash(
const void *bytes,
uint64 len ) = 0;
106 virtual const std::string name( )
const = 0;
112 unsigned char operator [](
size_type index )
const {
return( digest[ index ] ); }
116 std::string to_string( )
const
118 static char x16[ 16 ] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'a',
'b',
'c',
'd',
'e',
'f' };
121 for(
size_type i = 0 ; i < size( ) ; i++ )
123 str += x16[ ( digest[ i ] >> 4 ) & 0x0f ];
124 str += x16[ digest[ i ] & 0x0f ];
140 hash_algorithm(
const std::string &str ) : nbytes( str.length( ) / 2 ), digest( new unsigned char[ nbytes ] )
142 static uint8 x16[ 256 ] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
143 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
144 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
145 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
146 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
147 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
148 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
149 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
151 for(
size_type i = 0, indx = 0 ; i < size( ) ; i++, indx += 2 )
155 digest[ i ] = ( ( x16[ s1 ] << 4 ) & 0xf0 ) | ( x16[ s2 ] & 0x0f );
170 if( size( ) != h.
size( ) )
176 for(
size_type i = 0 ; i < size( ) ; i++ )
178 if( digest[ i ] != h[ i ] )
188 bool operator ==(
const std::string &str )
const
190 return( str == to_string( ) );
217 #ifndef __INCLUDE_MD5__
221 #ifndef __INCLUDE_SHA__
226 #endif // __INCLUDE_HASH_ALGORITHM__