]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
EVP_PKEY_new_raw_private_key: Allow zero length keys
authorTomas Mraz <tomas@openssl.org>
Mon, 7 Jun 2021 09:54:04 +0000 (11:54 +0200)
committerPauli <pauli@openssl.org>
Tue, 8 Jun 2021 12:01:34 +0000 (22:01 +1000)
Allocate at least one byte to distinguish a zero length key
from an unset key.

Fixes #15632

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15643)

providers/implementations/keymgmt/mac_legacy_kmgmt.c
test/evp_extra_test.c

index 3b378d38ff60412f07244a83839b65ddd38fed1c..e1e2609dfa3485920f33dbbbf9aa7f63d537b1f6 100644 (file)
@@ -190,7 +190,8 @@ static int mac_key_fromdata(MAC_KEY *key, const OSSL_PARAM params[])
             return 0;
         }
         OPENSSL_secure_clear_free(key->priv_key, key->priv_key_len);
-        key->priv_key = OPENSSL_secure_malloc(p->data_size);
+        /* allocate at least one byte to distinguish empty key from no key set */
+        key->priv_key = OPENSSL_secure_malloc(p->data_size > 0 ? p->data_size : 1);
         if (key->priv_key == NULL) {
             ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
             return 0;
index 61f6b4ce00374916b62360d02a1d0204dce7f539..33bb698ff37db2d89ea661e803081cc7cbdcebab 100644 (file)
@@ -1681,6 +1681,9 @@ static struct keys_st {
 } keys[] = {
     {
         EVP_PKEY_HMAC, "0123456789", NULL
+    },
+    {
+        EVP_PKEY_HMAC, "", NULL
 #ifndef OPENSSL_NO_POLY1305
     }, {
         EVP_PKEY_POLY1305, "01234567890123456789012345678901", NULL