36 Message_Block_Index = 0;
62 for(
int i = 0; i < 20; ++i )
63 sprintf( buf + i * 2,
"%02x", (
unsigned char)( H[i >> 2] >> ( ( 3 - ( i & 3 ) ) << 3 ) ) );
65 return std::string( buf, 40 );
73 unsigned char digest[20];
74 for(
int i = 0; i < 20; ++i )
75 digest[i] = (
unsigned char)( H[i >> 2] >> ( ( 3 - ( i & 3 ) ) << 3 ) );
77 return std::string( (
char*)digest, 20 );
89 void SHA::feed(
const unsigned char* data,
unsigned length )
94 if( m_finished || m_corrupted )
100 while( length-- && !m_corrupted )
102 Message_Block[Message_Block_Index++] = ( *data & 0xFF );
105 Length_Low &= 0xFFFFFFFF;
106 if( Length_Low == 0 )
109 Length_High &= 0xFFFFFFFF;
110 if( Length_High == 0 )
116 if( Message_Block_Index == 64 )
127 feed( (
const unsigned char*)data.c_str(), (int)data.length() );
132 const unsigned K[] = { 0x5A827999,
140 unsigned A, B, C, D, E;
142 for( t = 0; t < 16; t++ )
144 W[t] = ((unsigned) Message_Block[t * 4]) << 24;
145 W[t] |= ((unsigned) Message_Block[t * 4 + 1]) << 16;
146 W[t] |= ((unsigned) Message_Block[t * 4 + 2]) << 8;
147 W[t] |= ((unsigned) Message_Block[t * 4 + 3]);
150 for( t = 16; t < 80; ++t )
152 W[t] = shift( 1, W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16] );
161 for( t = 0; t < 20; ++t )
163 temp = shift( 5, A ) + ( ( B & C ) | ( ( ~B ) & D ) ) + E + W[t] + K[0];
172 for( t = 20; t < 40; ++t )
174 temp = shift( 5, A ) + ( B ^ C ^ D ) + E + W[t] + K[1];
183 for( t = 40; t < 60; ++t )
185 temp = shift( 5, A ) + ( ( B & C ) | ( B & D ) | ( C & D ) ) + E + W[t] + K[2];
194 for( t = 60; t < 80; ++t )
196 temp = shift( 5, A ) + ( B ^ C ^ D ) + E + W[t] + K[3];
205 H[0] = ( H[0] + A ) & 0xFFFFFFFF;
206 H[1] = ( H[1] + B ) & 0xFFFFFFFF;
207 H[2] = ( H[2] + C ) & 0xFFFFFFFF;
208 H[3] = ( H[3] + D ) & 0xFFFFFFFF;
209 H[4] = ( H[4] + E ) & 0xFFFFFFFF;
211 Message_Block_Index = 0;
216 Message_Block[Message_Block_Index++] = 0x80;
218 if( Message_Block_Index > 56 )
220 while( Message_Block_Index < 64 )
222 Message_Block[Message_Block_Index++] = 0;
228 while( Message_Block_Index < 56 )
230 Message_Block[Message_Block_Index++] = 0;
233 Message_Block[56] =
static_cast<unsigned char>( ( Length_High >> 24 ) & 0xFF );
234 Message_Block[57] =
static_cast<unsigned char>( ( Length_High >> 16 ) & 0xFF );
235 Message_Block[58] =
static_cast<unsigned char>( ( Length_High >> 8 ) & 0xFF );
236 Message_Block[59] =
static_cast<unsigned char>( ( Length_High ) & 0xFF );
237 Message_Block[60] =
static_cast<unsigned char>( ( Length_Low >> 24 ) & 0xFF );
238 Message_Block[61] =
static_cast<unsigned char>( ( Length_Low >> 16 ) & 0xFF );
239 Message_Block[62] =
static_cast<unsigned char>( ( Length_Low >> 8 ) & 0xFF );
240 Message_Block[63] =
static_cast<unsigned char>( ( Length_Low ) & 0xFF );
246 unsigned SHA::shift(
int bits,
unsigned word )
248 return ( ( word << bits ) & 0xFFFFFFFF) | ( ( word & 0xFFFFFFFF ) >> ( 32-bits ) );
The namespace for the gloox library.
void feed(const unsigned char *data, unsigned length)
const std::string binary()
const std::string EmptyString