diff options
author | Matt Caswell <matt@openssl.org> | 2018-03-05 15:13:43 +0000 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2018-03-15 12:47:27 +0000 |
commit | e32b52a27e20a45f51f489e4efc04d1ca72b9609 (patch) | |
tree | 95cbe2c2b77ed2b929b34f00f3ac794e0fb14408 /crypto/hmac | |
parent | cc8b15c7e1934ba710fbce32676451acc9cbe8a0 (diff) |
Add support for setting raw private HMAC keys
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5520)
Diffstat (limited to 'crypto/hmac')
-rw-r--r-- | crypto/hmac/hm_ameth.c | 37 |
1 files changed, 36 insertions, 1 deletions
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 <openssl/evp.h> #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, }; |