Exemple #1
0
void hb_hmac_sha384_init(hmac_sha384_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[SHA384_DIGEST_SIZE];
    unsigned int i;

    if (key_size == SHA384_BLOCK_SIZE) {
        key_used = key;
        num = SHA384_BLOCK_SIZE;
    } else {
        if (key_size > SHA384_BLOCK_SIZE){
            hb_sha384(key, key_size, key_temp);
            key_used = key_temp;
            num = SHA384_DIGEST_SIZE;
        } else { /* key_size > SHA384_BLOCK_SIZE */
            key_used = key;
            num = key_size;
        }
        fill = SHA384_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_sha384_init(&ctx->ctx_inside);
    hb_sha384_update(&ctx->ctx_inside, ctx->block_ipad, SHA384_BLOCK_SIZE);

    hb_sha384_init(&ctx->ctx_outside);
    hb_sha384_update(&ctx->ctx_outside, ctx->block_opad,
                  SHA384_BLOCK_SIZE);

    /* for hmac_reinit */
    memcpy(&ctx->ctx_inside_reinit, &ctx->ctx_inside,
           sizeof(sha384_ctx));
    memcpy(&ctx->ctx_outside_reinit, &ctx->ctx_outside,
           sizeof(sha384_ctx));
}
Exemple #2
0
void hb_sha384( const void * message, unsigned int len,
                unsigned char * digest )
{
   sha384_ctx ctx;

   hb_sha384_init( &ctx );
   hb_sha384_update( &ctx, message, len );
   hb_sha384_final( &ctx, digest );
}