Improve cleanup logic for HMAC
Older OpenSSL version have a cleanup function that can be used here. This removes a whole bunch of now no longer needed logic and custom conditionals. These functions have existed since 0.9.8 and can be used here. Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Этот коммит содержится в:
родитель
d1806a523c
Коммит
b6bf5bfd15
@ -291,25 +291,10 @@ HMAC_CTX *HMAC_CTX_new(void)
|
|||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hmac_ctx_cleanup(HMAC_CTX *ctx)
|
|
||||||
{
|
|
||||||
EVP_MD_CTX_reset(&ctx->i_ctx);
|
|
||||||
EVP_MD_CTX_reset(&ctx->o_ctx);
|
|
||||||
EVP_MD_CTX_reset(&ctx->md_ctx);
|
|
||||||
ctx->md = NULL;
|
|
||||||
ctx->key_length = 0;
|
|
||||||
OPENSSL_cleanse(ctx->key, sizeof(ctx->key));
|
|
||||||
}
|
|
||||||
|
|
||||||
void HMAC_CTX_free(HMAC_CTX *ctx)
|
void HMAC_CTX_free(HMAC_CTX *ctx)
|
||||||
{
|
{
|
||||||
if (ctx != NULL) {
|
if (ctx != NULL) {
|
||||||
hmac_ctx_cleanup(ctx);
|
HMAC_CTX_cleanup(ctx);
|
||||||
#if OPENSSL_VERSION_NUMBER > 0x10100000L
|
|
||||||
EVP_MD_CTX_free(&ctx->i_ctx);
|
|
||||||
EVP_MD_CTX_free(&ctx->o_ctx);
|
|
||||||
EVP_MD_CTX_free(&ctx->md_ctx);
|
|
||||||
#endif
|
|
||||||
OPENSSL_free(ctx);
|
OPENSSL_free(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user