MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / shsFinal

Function shsFinal

src/core/sha.cpp:287–327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285 }
286
287void shsFinal(SHS_INFO *shsInfo)
288{
289 int count;
290 uint32 lowBitcount = shsInfo->countLo, highBitcount = shsInfo->countHi;
291
292 /* Compute number of bytes mod 64 */
293 count = ( int ) ( ( shsInfo->countLo >> 3 ) & 0x3F );
294
295 /* Set the first char of padding to 0x80. This is safe since there is
296 always at least one byte free */
297 ( ( uint8 * ) shsInfo->data )[ count++ ] = 0x80;
298
299 /* Pad out to 56 mod 64 */
300 if( count > 56 )
301 {
302 /* Two lots of padding: Pad the first block to 64 bytes */
303 memset( ( char * ) shsInfo->data + count, 0, 64 - count );
304#ifndef WORDS_BIGENDIAN
305 byteReverse( shsInfo->data, SHS_BLOCKSIZE );
306#endif /* #ifndef WORDS_BIGENDIAN */
307 shsTransform( shsInfo );
308
309 /* Now fill the next block with 56 bytes */
310 memset( (char *) shsInfo->data, 0, 56 );
311 }
312 else
313 /* Pad block to 56 bytes */
314 memset( ( char * ) shsInfo->data + count, 0, 56 - count );
315#ifndef WORDS_BIGENDIAN
316 byteReverse( shsInfo->data, SHS_BLOCKSIZE );
317#endif /* #ifndef WORDS_BIGENDIAN */
318
319 /* Append length in bits and transform */
320 shsInfo->data[ 14 ] = highBitcount;
321 shsInfo->data[ 15 ] = lowBitcount;
322
323 shsTransform( shsInfo );
324#ifndef WORDS_BIGENDIAN
325 byteReverse( shsInfo->data, SHS_DIGESTSIZE );
326#endif /* #ifndef WORDS_BIGENDIAN */
327 }
328
329#ifdef TEST
330

Callers 2

FinitMethod · 0.85
mainFunction · 0.85

Calls 2

shsTransformFunction · 0.85
byteReverseFunction · 0.70

Tested by

no test coverage detected