Add the function EVP_PKEY_new_CMAC_key()
authorMatt Caswell <matt@openssl.org>
Mon, 5 Mar 2018 17:23:57 +0000 (17:23 +0000)
committerMatt Caswell <matt@openssl.org>
Thu, 15 Mar 2018 12:47:27 +0000 (12:47 +0000)
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5520)

crypto/err/openssl.txt
crypto/evp/evp_err.c
crypto/evp/p_lib.c
include/openssl/evp.h
include/openssl/evperr.h
util/libcrypto.num

index f33e9612c00d2d3184a4aa414a0cce170646b4ee..1e396adfe12b43de451bb6e7b5b47e78766f2dc1 100644 (file)
@@ -703,6 +703,7 @@ EVP_F_EVP_PKEY_GET0_SIPHASH:172:EVP_PKEY_get0_siphash
 EVP_F_EVP_PKEY_KEYGEN:146:EVP_PKEY_keygen
 EVP_F_EVP_PKEY_KEYGEN_INIT:147:EVP_PKEY_keygen_init
 EVP_F_EVP_PKEY_NEW:106:EVP_PKEY_new
+EVP_F_EVP_PKEY_NEW_CMAC_KEY:193:EVP_PKEY_new_CMAC_key
 EVP_F_EVP_PKEY_NEW_PRIVATE_KEY:191:EVP_PKEY_new_private_key
 EVP_F_EVP_PKEY_NEW_PUBLIC_KEY:192:EVP_PKEY_new_public_key
 EVP_F_EVP_PKEY_PARAMGEN:148:EVP_PKEY_paramgen
@@ -2085,6 +2086,7 @@ EVP_R_INVALID_KEY:163:invalid key
 EVP_R_INVALID_KEY_LENGTH:130:invalid key length
 EVP_R_INVALID_OPERATION:148:invalid operation
 EVP_R_KEYGEN_FAILURE:120:keygen failure
+EVP_R_KEY_SETUP_FAILED:180:key setup failed
 EVP_R_MEMORY_LIMIT_EXCEEDED:172:memory limit exceeded
 EVP_R_MESSAGE_DIGEST_IS_NULL:159:message digest is null
 EVP_R_METHOD_NOT_SUPPORTED:144:method not supported
index d45f2b96b1143b948693349efafa0e3fec2b7315..7ab2a249fd3fb2bf63e2f8d0fc9cf405cc344f6a 100644 (file)
@@ -93,6 +93,8 @@ static const ERR_STRING_DATA EVP_str_functs[] = {
     {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_PKEY_KEYGEN_INIT, 0),
      "EVP_PKEY_keygen_init"},
     {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_PKEY_NEW, 0), "EVP_PKEY_new"},
+    {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_PKEY_NEW_CMAC_KEY, 0),
+     "EVP_PKEY_new_CMAC_key"},
     {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_PKEY_NEW_PRIVATE_KEY, 0),
      "EVP_PKEY_new_private_key"},
     {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_PKEY_NEW_PUBLIC_KEY, 0),
@@ -187,6 +189,7 @@ static const ERR_STRING_DATA EVP_str_reasons[] = {
     {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_INVALID_KEY_LENGTH), "invalid key length"},
     {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_INVALID_OPERATION), "invalid operation"},
     {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_KEYGEN_FAILURE), "keygen failure"},
+    {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_KEY_SETUP_FAILED), "key setup failed"},
     {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_MEMORY_LIMIT_EXCEEDED),
     "memory limit exceeded"},
     {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_MESSAGE_DIGEST_IS_NULL),
index a92b169f7a6970b999f731ff553a741f3d829daf..ee121c4a56835c5dd6d330b3bd9f39ecc70ff34f 100644 (file)
@@ -18,6 +18,7 @@
 #include <openssl/rsa.h>
 #include <openssl/dsa.h>
 #include <openssl/dh.h>
+#include <openssl/cmac.h>
 #include <openssl/engine.h>
 
 #include "internal/asn1_int.h"
@@ -279,6 +280,33 @@ EVP_PKEY *EVP_PKEY_new_public_key(int type, ENGINE *e,
     return NULL;
 }
 
+EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv,
+                                size_t len, const EVP_CIPHER *cipher)
+{
+    EVP_PKEY *ret = EVP_PKEY_new();
+    CMAC_CTX *cmctx = CMAC_CTX_new();
+
+    if (ret == NULL
+            || cmctx == NULL
+            || !pkey_set_type(ret, e, EVP_PKEY_CMAC, NULL, -1)) {
+        /* EVPerr already called */
+        goto err;
+    }
+
+    if (!CMAC_Init(cmctx, priv, len, cipher, e)) {
+        EVPerr(EVP_F_EVP_PKEY_NEW_CMAC_KEY, EVP_R_KEY_SETUP_FAILED);
+        goto err;
+    }
+
+    ret->pkey.ptr = cmctx;
+    return ret;
+
+ err:
+    EVP_PKEY_free(ret);
+    CMAC_CTX_free(cmctx);
+    return NULL;
+
+}
 
 int EVP_PKEY_set_type(EVP_PKEY *pkey, int type)
 {
index d80ca41e65011fda25d3361ebcf2e4b3429f7208..e8d46286d00eca50173e9f982d005157652c9749 100644 (file)
@@ -1343,6 +1343,8 @@ EVP_PKEY *EVP_PKEY_new_private_key(int type, ENGINE *e,
 EVP_PKEY *EVP_PKEY_new_public_key(int type, ENGINE *e,
                                   const unsigned char *pub,
                                   size_t len);
+EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv,
+                                size_t len, const EVP_CIPHER *cipher);
 
 void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data);
 void *EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx);
index 83dcd053ea491b2dcccfabe3084a077c95675110..3cdd554f31d9980badf4383997e37bcafd4d79f7 100644 (file)
@@ -78,6 +78,7 @@ int ERR_load_EVP_strings(void);
 # define EVP_F_EVP_PKEY_KEYGEN                            146
 # define EVP_F_EVP_PKEY_KEYGEN_INIT                       147
 # define EVP_F_EVP_PKEY_NEW                               106
+# define EVP_F_EVP_PKEY_NEW_CMAC_KEY                      193
 # define EVP_F_EVP_PKEY_NEW_PRIVATE_KEY                   191
 # define EVP_F_EVP_PKEY_NEW_PUBLIC_KEY                    192
 # define EVP_F_EVP_PKEY_PARAMGEN                          148
@@ -139,6 +140,7 @@ int ERR_load_EVP_strings(void);
 # define EVP_R_INVALID_KEY_LENGTH                         130
 # define EVP_R_INVALID_OPERATION                          148
 # define EVP_R_KEYGEN_FAILURE                             120
+# define EVP_R_KEY_SETUP_FAILED                           180
 # define EVP_R_MEMORY_LIMIT_EXCEEDED                      172
 # define EVP_R_MESSAGE_DIGEST_IS_NULL                     159
 # define EVP_R_METHOD_NOT_SUPPORTED                       144
index 401d9fd9f689563ace80371ede649d1da9ee238b..b74ed2bec249ea44059486f36a8faf343371a6d4 100644 (file)
@@ -4524,3 +4524,4 @@ OSSL_STORE_SEARCH_get0_digest           4465      1_1_1   EXIST::FUNCTION:
 RAND_DRBG_set_reseed_defaults           4466   1_1_1   EXIST::FUNCTION:
 EVP_PKEY_new_private_key                4467   1_1_1   EXIST::FUNCTION:
 EVP_PKEY_new_public_key                 4468   1_1_1   EXIST::FUNCTION:
+EVP_PKEY_new_CMAC_key                   4469   1_1_1   EXIST::FUNCTION: