forked from wolfSSL/wolfssl
HMAC_Init_ex with NULL key to recover Hmac initial state
This commit is contained in:
committed by
Jacob Barthelmeh
parent
8f1fc8ad2e
commit
f38a321e64
14
src/ssl.c
14
src/ssl.c
@ -24645,7 +24645,7 @@ int wolfSSL_HMAC_CTX_Init(WOLFSSL_HMAC_CTX* ctx)
|
|||||||
int wolfSSL_HMAC_Init_ex(WOLFSSL_HMAC_CTX* ctx, const void* key,
|
int wolfSSL_HMAC_Init_ex(WOLFSSL_HMAC_CTX* ctx, const void* key,
|
||||||
int keylen, const EVP_MD* type, WOLFSSL_ENGINE* e)
|
int keylen, const EVP_MD* type, WOLFSSL_ENGINE* e)
|
||||||
{
|
{
|
||||||
WOLFSSL_ENTER("wolfSSL_HMAC_Init_ex()");
|
WOLFSSL_ENTER("wolfSSL_HMAC_Init_ex");
|
||||||
|
|
||||||
/* WOLFSSL_ENGINE not used, call wolfSSL_HMAC_Init */
|
/* WOLFSSL_ENGINE not used, call wolfSSL_HMAC_Init */
|
||||||
(void)e;
|
(void)e;
|
||||||
@ -24805,10 +24805,16 @@ int wolfSSL_HMAC_Init(WOLFSSL_HMAC_CTX* ctx, const void* key, int keylen,
|
|||||||
wc_HmacFree(&ctx->hmac);
|
wc_HmacFree(&ctx->hmac);
|
||||||
return WOLFSSL_FAILURE;
|
return WOLFSSL_FAILURE;
|
||||||
}
|
}
|
||||||
|
XMEMCPY((byte *)&ctx->save_key, (const byte*)key, (word32)keylen);
|
||||||
|
ctx->save_len = keylen;
|
||||||
|
}
|
||||||
|
/* OpenSSL compat, no error */
|
||||||
|
} else if(ctx->type) {
|
||||||
|
WOLFSSL_MSG("recover hmac");
|
||||||
|
if (wc_HmacInit(&ctx->hmac, NULL, INVALID_DEVID) == 0) {
|
||||||
|
wc_HmacSetKey(&ctx->hmac, ctx->type, (byte *)&ctx->save_key,
|
||||||
|
(word32)ctx->save_len);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
WOLFSSL_MSG("no key or keylen");
|
|
||||||
return WOLFSSL_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return WOLFSSL_SUCCESS;
|
return WOLFSSL_SUCCESS;
|
||||||
|
@ -53,6 +53,8 @@ WOLFSSL_API unsigned char* wolfSSL_HMAC(const WOLFSSL_EVP_MD* evp_md,
|
|||||||
typedef struct WOLFSSL_HMAC_CTX {
|
typedef struct WOLFSSL_HMAC_CTX {
|
||||||
Hmac hmac;
|
Hmac hmac;
|
||||||
int type;
|
int type;
|
||||||
|
byte save_key[HMAC_BLOCK_SIZE]; /* save initial hmac after wc_HmacSetKey */
|
||||||
|
word32 save_len;
|
||||||
} WOLFSSL_HMAC_CTX;
|
} WOLFSSL_HMAC_CTX;
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user