sha1.c
void
SHA1Final(unsigned char digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context)
{
    unsigned int i;
    unsigned char finalcount[8];

    for (i = 0; i < 8; i++) {
        finalcount[i] = (unsigned char)((context->count >>
            ((7 - (i & 7)) * 8)) & 255);  /* Endian independent */
    }
    SHA1Update(context, (unsigned char *)"\200", 1);
    while ((context->count & 504) != 448) {
        SHA1Update(context, (unsigned char *)"\0", 1);
    }
    SHA1Update(context, finalcount, 8);  /* Should cause a SHA1Transform() */

    if (digest)
        for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
            digest[i] = (unsigned char)((context->state[i >> 2] >>
                ((3 - (i & 3)) * 8)) & 255);
      }
    memset(finalcount, '\0', 8);
#if 0	/* We want to use this for "keyfill" */
    /* Wipe variables */
    i = 0;
    bzero(context->buffer, 64);
    bzero(context->state, 20);
    bzero(context->count, 8);
#ifdef SHA1HANDSOFF  /* make SHA1Transform overwrite its own static vars */
    SHA1Transform(context->state, context->buffer);
#endif
#endif
}
/* Add padding and return the message digest. */
Add padding and return the message digest.
Add padding and return the message digest .
void
SHA1Final(unsigned char digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context)
{
    unsigned int i;
    unsigned char finalcount[8];
    for (i = 0; i < 8; i++) {
        finalcount[i] = (unsigned char)((context->count >>
            ((7 - (i & 7)) * 8)) & 255);  
    }
    SHA1Update(context, (unsigned char *)"\200", 1);
    while ((context->count & 504) != 448) {
        SHA1Update(context, (unsigned char *)"\0", 1);
    }
    SHA1Update(context, finalcount, 8);  
    if (digest)
        for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
            digest[i] = (unsigned char)((context->state[i >> 2] >>
                ((3 - (i & 3)) * 8)) & 255);
      }
    memset(finalcount, '\0', 8);
#if 0	
    i = 0;
    bzero(context->buffer, 64);
    bzero(context->state, 20);
    bzero(context->count, 8);
#ifdef SHA1HANDSOFF  
    SHA1Transform(context->state, context->buffer);
#endif
#endif
}
void SHA1Final ( unsigned char digest [ SHA1_DIGEST_LENGTH ] , SHA1_CTX * context ) { unsigned int i ; unsigned char finalcount [ 8 ] ; for ( i = 0 ; i < 8 ; i ++ ) { finalcount [ i ] = ( unsigned char ) ( ( context -> count >> ( ( 7 - ( i & 7 ) ) * 8 ) ) & 255 ) ; } SHA1Update ( context , ( unsigned char * ) " \200 " , 1 ) ; while ( ( context -> count & 504 ) != 448 ) { SHA1Update ( context , ( unsigned char * ) " \0 " , 1 ) ; } SHA1Update ( context , finalcount , 8 ) ; if ( digest ) for ( i = 0 ; i < SHA1_DIGEST_LENGTH ; i ++ ) { digest [ i ] = ( unsigned char ) ( ( context -> state [ i >> 2 ] >> ( ( 3 - ( i & 3 ) ) * 8 ) ) & 255 ) ; } memset ( finalcount , ' \0 ' , 8 ) ; #if 0 i = 0 ; bzero ( context -> buffer , 64 ) ; bzero ( context -> state , 20 ) ; bzero ( context -> count , 8 ) ; #ifdef SHA1HANDSOFF SHA1Transform ( context -> state , context -> buffer ) ; #endif #endif }
Add padding and return the message digest.
Add padding and return the message digest .
/* Endian independent */ /* Should cause a SHA1Transform() */ /* We want to use this for "keyfill" */ /* Wipe variables */ /* make SHA1Transform overwrite its own static vars */