From e32b52a27e20a45f51f489e4efc04d1ca72b9609 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Mon, 5 Mar 2018 15:13:43 +0000 Subject: Add support for setting raw private HMAC keys Reviewed-by: Richard Levitte (Merged from https://github.com/openssl/openssl/pull/5520) --- crypto/hmac/hm_ameth.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'crypto/hmac') diff --git a/crypto/hmac/hm_ameth.c b/crypto/hmac/hm_ameth.c index 4d830b8ded..b8c13331cb 100644 --- a/crypto/hmac/hm_ameth.c +++ b/crypto/hmac/hm_ameth.c @@ -11,6 +11,7 @@ #include "internal/cryptlib.h" #include #include "internal/asn1_int.h" +#include "internal/evp_int.h" /* * HMAC "ASN1" method. This is just here to indicate the maximum HMAC output @@ -49,6 +50,28 @@ static int hmac_pkey_public_cmp(const EVP_PKEY *a, const EVP_PKEY *b) return ASN1_OCTET_STRING_cmp(EVP_PKEY_get0(a), EVP_PKEY_get0(b)); } +static int hmac_set_priv_key(EVP_PKEY *pkey, const unsigned char *priv, + size_t len) +{ + ASN1_OCTET_STRING *os; + + if (pkey->pkey.ptr != NULL) + return 0; + + os = ASN1_OCTET_STRING_new(); + if (os == NULL) + return 0; + + + if (!ASN1_OCTET_STRING_set(os, priv, len)) { + ASN1_OCTET_STRING_free(os); + return 0; + } + + pkey->pkey.ptr = os; + return 1; +} + const EVP_PKEY_ASN1_METHOD hmac_asn1_meth = { EVP_PKEY_HMAC, EVP_PKEY_HMAC, @@ -67,5 +90,17 @@ const EVP_PKEY_ASN1_METHOD hmac_asn1_meth = { hmac_key_free, hmac_pkey_ctrl, - 0, 0 + NULL, + NULL, + + NULL, + NULL, + NULL, + + NULL, + NULL, + NULL, + + hmac_set_priv_key, + NULL, }; -- cgit v1.2.3