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)); }
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 ); }
void hb_hmac_sha224_final(hmac_sha224_ctx *ctx, unsigned char *mac, unsigned int mac_size) { unsigned char digest_inside[SHA224_DIGEST_SIZE]; unsigned char mac_temp[SHA224_DIGEST_SIZE]; hb_sha224_final(&ctx->ctx_inside, digest_inside); hb_sha224_update(&ctx->ctx_outside, digest_inside, SHA224_DIGEST_SIZE); hb_sha224_final(&ctx->ctx_outside, mac_temp); memcpy(mac, mac_temp, mac_size); }
void hb_hmac_sha224_update(hmac_sha224_ctx *ctx, const void *message, unsigned int message_len) { hb_sha224_update(&ctx->ctx_inside, message, message_len); }