Esempio n. 1
0
void hb_hmac_sha224_init(hmac_sha224_ctx *ctx, const void *keyv,
                         unsigned int key_size)
{
    unsigned int fill;
    unsigned int num;

    const unsigned char *key = ( const unsigned char * ) keyv;
    const unsigned char *key_used;
    unsigned char key_temp[SHA224_DIGEST_SIZE];
    unsigned int i;

    if (key_size == SHA224_BLOCK_SIZE) {
        key_used = key;
        num = SHA224_BLOCK_SIZE;
    } else {
        if (key_size > SHA224_BLOCK_SIZE){
            hb_sha224(key, key_size, key_temp);
            key_used = key_temp;
            num = SHA224_DIGEST_SIZE;
        } else { /* key_size > SHA224_BLOCK_SIZE */
            key_used = key;
            num = key_size;
        }
        fill = SHA224_BLOCK_SIZE - num;

        memset(ctx->block_ipad + num, 0x36, fill);
        memset(ctx->block_opad + num, 0x5c, fill);
    }

    for (i = 0; i < num; i++) {
        ctx->block_ipad[i] = key_used[i] ^ 0x36;
        ctx->block_opad[i] = key_used[i] ^ 0x5c;
    }

    hb_sha224_init(&ctx->ctx_inside);
    hb_sha224_update(&ctx->ctx_inside, ctx->block_ipad, SHA224_BLOCK_SIZE);

    hb_sha224_init(&ctx->ctx_outside);
    hb_sha224_update(&ctx->ctx_outside, ctx->block_opad,
                  SHA224_BLOCK_SIZE);

    /* for hmac_reinit */
    memcpy(&ctx->ctx_inside_reinit, &ctx->ctx_inside,
           sizeof(sha224_ctx));
    memcpy(&ctx->ctx_outside_reinit, &ctx->ctx_outside,
           sizeof(sha224_ctx));
}
Esempio n. 2
0
File: sha2.c Progetto: xharbour/core
void hb_sha224( const void * message, unsigned int len,
                unsigned char * digest )
{
   sha224_ctx ctx;

   hb_sha224_init( &ctx );
   hb_sha224_update( &ctx, message, len );
   hb_sha224_final( &ctx, digest );
}