aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2015-11-30 23:42:39 +0100
committerRichard Levitte <levitte@openssl.org>2015-12-07 17:39:23 +0100
commit32fd54a9a36c172cf4e5fe4b7af2ae1f1ce1bc0a (patch)
tree3078c0fe1029db6dd116af0c910a6218c5ac6c03
parent74cabf3fef77ab73c45e27cf6ed90f6db020e7c7 (diff)
downloadopenssl-32fd54a9a36c172cf4e5fe4b7af2ae1f1ce1bc0a.zip
openssl-32fd54a9a36c172cf4e5fe4b7af2ae1f1ce1bc0a.tar.gz
openssl-32fd54a9a36c172cf4e5fe4b7af2ae1f1ce1bc0a.tar.bz2
Remove HMAC_CTX_cleanup and combine its functionality into EVP_MD_CTX_init
This follows the same idea as the combination of EVP_MD_CTX_cleanup and EVP_MD_CTX_init into one function. Reviewed-by: Rich Salz <rsalz@openssl.org>
-rw-r--r--crypto/hmac/hmac.c34
-rw-r--r--include/openssl/hmac.h3
2 files changed, 18 insertions, 19 deletions
diff --git a/crypto/hmac/hmac.c b/crypto/hmac/hmac.c
index 9b29861..6d1aaf8 100644
--- a/crypto/hmac/hmac.c
+++ b/crypto/hmac/hmac.c
@@ -180,38 +180,46 @@ HMAC_CTX *HMAC_CTX_new(void)
return ctx;
}
+static void hmac_ctx_cleanup(HMAC_CTX *ctx)
+{
+ EVP_MD_CTX_init(ctx->i_ctx);
+ EVP_MD_CTX_init(ctx->o_ctx);
+ EVP_MD_CTX_init(ctx->md_ctx);
+ ctx->md = NULL;
+ ctx->key_length = 0;
+ memset(ctx->key, 0, sizeof(HMAC_MAX_MD_CBLOCK));
+}
+
void HMAC_CTX_free(HMAC_CTX *ctx)
{
if (ctx != NULL) {
- HMAC_CTX_cleanup(ctx);
+ hmac_ctx_cleanup(ctx);
+ EVP_MD_CTX_destroy(ctx->i_ctx);
+ EVP_MD_CTX_destroy(ctx->o_ctx);
+ EVP_MD_CTX_destroy(ctx->md_ctx);
OPENSSL_free(ctx);
}
}
int HMAC_CTX_init(HMAC_CTX *ctx)
{
+ hmac_ctx_cleanup(ctx);
if (ctx->i_ctx == NULL)
ctx->i_ctx = EVP_MD_CTX_create();
- else
- EVP_MD_CTX_init(ctx->i_ctx);
if (ctx->i_ctx == NULL)
goto err;
if (ctx->o_ctx == NULL)
ctx->o_ctx = EVP_MD_CTX_create();
- else
- EVP_MD_CTX_init(ctx->o_ctx);
if (ctx->o_ctx == NULL)
goto err;
if (ctx->md_ctx == NULL)
ctx->md_ctx = EVP_MD_CTX_create();
- else
- EVP_MD_CTX_init(ctx->md_ctx);
if (ctx->md_ctx == NULL)
goto err;
ctx->md = NULL;
return 1;
err:
- HMAC_CTX_cleanup(ctx);
+ hmac_ctx_cleanup(ctx);
return 0;
}
@@ -230,18 +238,10 @@ int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx)
dctx->md = sctx->md;
return 1;
err:
- HMAC_CTX_cleanup(dctx);
+ hmac_ctx_cleanup(dctx);
return 0;
}
-void HMAC_CTX_cleanup(HMAC_CTX *ctx)
-{
- EVP_MD_CTX_destroy(ctx->i_ctx);
- EVP_MD_CTX_destroy(ctx->o_ctx);
- EVP_MD_CTX_destroy(ctx->md_ctx);
- memset(ctx, 0, sizeof(*ctx));
-}
-
unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
const unsigned char *d, size_t n, unsigned char *md,
unsigned int *md_len)
diff --git a/include/openssl/hmac.h b/include/openssl/hmac.h
index 48aade3..aa52c8e 100644
--- a/include/openssl/hmac.h
+++ b/include/openssl/hmac.h
@@ -70,9 +70,8 @@ extern "C" {
size_t HMAC_size(HMAC_CTX *e);
HMAC_CTX *HMAC_CTX_new(void);
-void HMAC_CTX_free(HMAC_CTX *ctx);
int HMAC_CTX_init(HMAC_CTX *ctx);
-void HMAC_CTX_cleanup(HMAC_CTX *ctx);
+void HMAC_CTX_free(HMAC_CTX *ctx);
#ifdef OPENSSL_USE_DEPRECATED