diff options
author | Matt Caswell <matt@openssl.org> | 2016-06-20 09:08:10 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2016-06-24 13:22:40 +0100 |
commit | a6211814c4c6f29358f29f639d468387b01518f8 (patch) | |
tree | fff1531b407a571af5431c53c0f17cea6248b95a | |
parent | d6079a87db58ad17550b5d00a74512464e6a029e (diff) | |
download | openssl-a6211814c4c6f29358f29f639d468387b01518f8.tar.gz |
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: Tim Hudson <tjh@openssl.org>
-rw-r--r-- | crypto/hmac/hmac.c | 5 | ||||
-rw-r--r-- | include/openssl/hmac.h | 1 | ||||
-rw-r--r-- | test/hmactest.c | 15 | ||||
-rw-r--r-- | util/libcrypto.num | 1 |
4 files changed, 22 insertions, 0 deletions
diff --git a/crypto/hmac/hmac.c b/crypto/hmac/hmac.c index da7f58688f..3374105cbb 100644 --- a/crypto/hmac/hmac.c +++ b/crypto/hmac/hmac.c @@ -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; +} diff --git a/include/openssl/hmac.h b/include/openssl/hmac.h index 809ca34227..9f06896059 100644 --- a/include/openssl/hmac.h +++ b/include/openssl/hmac.h @@ -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 } diff --git a/test/hmactest.c b/test/hmactest.c index 145c467e50..0f4348b73c 100644 --- a/test/hmactest.c +++ b/test/hmactest.c @@ -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++; diff --git a/util/libcrypto.num b/util/libcrypto.num index fa07ecfef9..fc118b19bb 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -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: |