lib_hash_drbg/src/sha256.c
/*
 * Finalize the sha256 context and return the hash result
 *  FIPS180-4, Sec. 5.1.1 (pg. 13)
 *
 * Parameters:
 * SHA256_CTX* context - structure holding the sha256 context
 * uint8_t* hash_bytes - 32 byte output buffer to hold the hash result
 */
Finalize the sha256 context and return the hash result
FIPS180-4, Sec.

SHA256_CTX* context - structure holding the sha256 context
uint8_t* hash_bytes - 32 byte output buffer to hold the hash result
Finalize the sha256 context and return the hash result FIPS180 - 4 Sec . SHA256_CTX * context - structure holding the sha256 context uint8_t * hash_bytes - 32 byte output buffer to hold the hash result
void
sha256_finalize(SHA256_CTX* context, uint8_t* hash_bytes)
{
    uint32_t i;
    context->data[context->datalen++] = 0x80;
    while (context->datalen != 56) {
        if (context->datalen == 64) {
            sha256_transform(context);
            context->datalen = 0;
        }
        context->data[context->datalen++] = 0x00;
    }
    for (i = 0; i < 8; i += 1) {
        context->data[56+i] =  (context->bitlen >> (56-i*8)) & 0xff;
    }
    sha256_transform(context);
    for (i = 0; i < 8; i += 1) {
        *hash_bytes++ = (context->H[i] >> 24) & 0xff;
        *hash_bytes++ = (context->H[i] >> 16) & 0xff;
        *hash_bytes++ = (context->H[i] >>  8) & 0xff;
        *hash_bytes++ =  context->H[i]        & 0xff;
    }
}
void sha256_finalize ( SHA256_CTX * context , uint8_t * hash_bytes ) { uint32_t i ; context -> data [ context -> datalen ++ ] = 0x80 ; while ( context -> datalen != 56 ) { if ( context -> datalen == 64 ) { sha256_transform ( context ) ; context -> datalen = 0 ; } context -> data [ context -> datalen ++ ] = 0x00 ; } for ( i = 0 ; i < 8 ; i += 1 ) { context -> data [ 56 + i ] = ( context -> bitlen >> ( 56 - i * 8 ) ) & 0xff ; } sha256_transform ( context ) ; for ( i = 0 ; i < 8 ; i += 1 ) { * hash_bytes ++ = ( context -> H [ i ] >> 24 ) & 0xff ; * hash_bytes ++ = ( context -> H [ i ] >> 16 ) & 0xff ; * hash_bytes ++ = ( context -> H [ i ] >> 8 ) & 0xff ; * hash_bytes ++ = context -> H [ i ] & 0xff ; } }
Finalize the sha256 context and return the hash result
  FIPS180-4, Sec.
Finalize the sha256 context and return the hash result FIPS180 - 4 Sec .
/*
     * Pad the remaining data in the context data buffer
     *  and call sha256_transform on the padded data
     * The pad is a '1' bit, followed by enough '0' bits
     *  to fill out to byte 56, (the last eight bytes
     *  will be the length of the messsage).
     *
     * If the buffer is currently too full to contain the padding
     *  plus message length, two calls to sha256_transform will be required
     */ /*
     * Add the bit length to the message
     */ /*
     * Perform the last transform on the padded data
     */ /*
     * Copy the eight hash context registers to hash_output
     */