diff options
author | David Benjamin <davidben@chromium.org> | 2014-12-25 11:44:17 +0300 |
---|---|---|
committer | Adam Langley <agl@google.com> | 2015-01-14 23:35:47 +0300 |
commit | 238510a67989a1a05d606019249aa4d5e5427627 (patch) | |
tree | 5e1d4ebea421b00580a60b3496fa36c050655a92 /crypto/hmac | |
parent | bbd8444d92dd7c4d19828177300579bcdc9f52f7 (diff) |
Introduce HMAC_CTX_copy_ex and deprecate HMAC_CTX_copy.
HMAC_CTX_copy's documentation is off. It actually follows the old copy
functions which call FOO_init on dest first. Notably this means that they leak
memory if dest is currently in use.
Add HMAC_CTX_copy_ex as an analog of EVP_MD_CTX_copy and deprecate
HMAC_CTX_copy. (EVP_CIPHER_CTX_copy, in contrast, was correct from the start.)
Change-Id: I48566c858663d3f659bd356200cf862e196576c9
Reviewed-on: https://boringssl-review.googlesource.com/2694
Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/hmac')
-rw-r--r-- | crypto/hmac/hmac.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/crypto/hmac/hmac.c b/crypto/hmac/hmac.c index bb96606c..9c1e77ae 100644 --- a/crypto/hmac/hmac.c +++ b/crypto/hmac/hmac.c @@ -188,10 +188,10 @@ size_t HMAC_size(const HMAC_CTX *ctx) { return EVP_MD_size(ctx->md); } -int HMAC_CTX_copy(HMAC_CTX *dest, const HMAC_CTX *src) { - if (!EVP_MD_CTX_copy(&dest->i_ctx, &src->i_ctx) || - !EVP_MD_CTX_copy(&dest->o_ctx, &src->o_ctx) || - !EVP_MD_CTX_copy(&dest->md_ctx, &src->md_ctx)) { +int HMAC_CTX_copy_ex(HMAC_CTX *dest, const HMAC_CTX *src) { + if (!EVP_MD_CTX_copy_ex(&dest->i_ctx, &src->i_ctx) || + !EVP_MD_CTX_copy_ex(&dest->o_ctx, &src->o_ctx) || + !EVP_MD_CTX_copy_ex(&dest->md_ctx, &src->md_ctx)) { return 0; } @@ -213,3 +213,8 @@ int HMAC_Init(HMAC_CTX *ctx, const void *key, int key_len, const EVP_MD *md) { } return HMAC_Init_ex(ctx, key, key_len, md, NULL); } + +int HMAC_CTX_copy(HMAC_CTX *dest, const HMAC_CTX *src) { + HMAC_CTX_init(dest); + return HMAC_CTX_copy_ex(dest, src); +} |