From c1eb9828f4191842d89744d041d74e399b7d9ca3 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Mon, 14 May 2018 13:18:33 +0100 Subject: [PATCH] hcrypto: Add HMAC_CTX_new and HMAC_CTX_free Add a pair of functions which can be used to allocate and free an HMAC_CTX structure on the heap. This means that the caller doesn't need to know the size of the underlying structure. --- lib/hcrypto/hmac.c | 13 +++++++++++++ lib/hcrypto/hmac.h | 4 ++++ lib/hcrypto/libhcrypto-exports.def | 2 ++ lib/hcrypto/version-script.map | 2 ++ 4 files changed, 21 insertions(+) diff --git a/lib/hcrypto/hmac.c b/lib/hcrypto/hmac.c index 29e6af479..ee641a8db 100644 --- a/lib/hcrypto/hmac.c +++ b/lib/hcrypto/hmac.c @@ -66,6 +66,19 @@ HMAC_CTX_cleanup(HMAC_CTX *ctx) } } +HMAC_CTX * +HMAC_CTX_new(void) +{ + return calloc(1, sizeof(HMAC_CTX)); +} + +void +HMAC_CTX_free(HMAC_CTX *ctx) +{ + HMAC_CTX_cleanup(ctx); + free(ctx); +} + size_t HMAC_size(const HMAC_CTX *ctx) { diff --git a/lib/hcrypto/hmac.h b/lib/hcrypto/hmac.h index 3ea17a93f..2c7d9b880 100644 --- a/lib/hcrypto/hmac.h +++ b/lib/hcrypto/hmac.h @@ -39,6 +39,8 @@ #include /* symbol renaming */ +#define HMAC_CTX_new hc_HMAC_CTX_new +#define HMAC_CTX_free hc_HMAC_CTX_free #define HMAC_CTX_init hc_HMAC_CTX_init #define HMAC_CTX_cleanup hc_HMAC_CTX_cleanup #define HMAC_size hc_HMAC_size @@ -68,6 +70,8 @@ struct hc_HMAC_CTX { void HMAC_CTX_init(HMAC_CTX *); void HMAC_CTX_cleanup(HMAC_CTX *ctx); +HMAC_CTX *HMAC_CTX_new(void); +void HMAC_CTX_free(HMAC_CTX *ctx); size_t HMAC_size(const HMAC_CTX *ctx); diff --git a/lib/hcrypto/libhcrypto-exports.def b/lib/hcrypto/libhcrypto-exports.def index ab692b4e5..098dfa900 100644 --- a/lib/hcrypto/libhcrypto-exports.def +++ b/lib/hcrypto/libhcrypto-exports.def @@ -259,6 +259,8 @@ EXPORTS hc_HMAC hc_HMAC_CTX_cleanup hc_HMAC_CTX_init + hc_HMAC_CTX_free + hc_HMAC_CTX_new hc_HMAC_Final hc_HMAC_Init_ex hc_HMAC_Update diff --git a/lib/hcrypto/version-script.map b/lib/hcrypto/version-script.map index 5b9d34a45..ba55e6b0d 100644 --- a/lib/hcrypto/version-script.map +++ b/lib/hcrypto/version-script.map @@ -243,7 +243,9 @@ HEIMDAL_CRYPTO_1.0 { hc_EVP_hcrypto_aes_256_cts; hc_HMAC; hc_HMAC_CTX_cleanup; + hc_HMAC_CTX_free; hc_HMAC_CTX_init; + hc_HMAC_CTX_new; hc_HMAC_Final; hc_HMAC_Init_ex; hc_HMAC_Update;