提交 a6211814 编写于 作者: M Matt Caswell

Add a getter to obtain the HMAC_CTX md

As a result of opaque HMAC_CTX apps need a getter for the HMAC_CTX md.

GitHub Issue #1152
Reviewed-by: NTim Hudson <tjh@openssl.org>
上级 d6079a87
......@@ -233,3 +233,8 @@ void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags)
EVP_MD_CTX_set_flags(ctx->o_ctx, flags);
EVP_MD_CTX_set_flags(ctx->md_ctx, flags);
}
const EVP_MD *HMAC_CTX_get_md(const HMAC_CTX *ctx)
{
return ctx->md;
}
......@@ -40,6 +40,7 @@ unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
__owur int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx);
void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags);
const EVP_MD *HMAC_CTX_get_md(const HMAC_CTX *ctx);
#ifdef __cplusplus
}
......
......@@ -123,6 +123,11 @@ int main(int argc, char *argv[])
err++;
goto end;
}
if (HMAC_CTX_get_md(ctx) != NULL) {
printf("Message digest not NULL for HMAC (test 4)\n");
err++;
goto test5;
}
if (HMAC_Init_ex(ctx, NULL, 0, NULL, NULL)) {
printf("Should fail to initialise HMAC with empty MD and key (test 4)\n");
err++;
......@@ -155,6 +160,11 @@ test5:
}
HMAC_CTX_reset(ctx);
if (HMAC_CTX_get_md(ctx) != NULL) {
printf("Message digest not NULL for HMAC (test 5)\n");
err++;
goto test6;
}
if (HMAC_Init_ex(ctx, test[4].key, test[4].key_len, NULL, NULL)) {
printf("Should fail to initialise HMAC with empty MD (test 5)\n");
err++;
......@@ -202,6 +212,11 @@ test5:
err++;
goto test6;
}
if (HMAC_CTX_get_md(ctx) != EVP_sha256()) {
printf("Unexpected message digest for HMAC (test 5)\n");
err++;
goto test6;
}
if (!HMAC_Update(ctx, test[5].data, test[5].data_len)) {
printf("Error updating HMAC with data (sha256) (test 5)\n");
err++;
......
......@@ -4149,3 +4149,4 @@ X509_get_pathlen 4092 1_1_0 EXIST::FUNCTION:
ECDSA_SIG_set0 4093 1_1_0 EXIST::FUNCTION:EC
DSA_SIG_set0 4094 1_1_0 EXIST::FUNCTION:DSA
EVP_PKEY_get0_hmac 4095 1_1_0 EXIST::FUNCTION:
HMAC_CTX_get_md 4096 1_1_0 EXIST::FUNCTION:
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册