]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
EVP_SKEY_get_raw_key => EVP_SKEY_get0_raw_key
authorDmitry Belyavskiy <beldmit@gmail.com>
Wed, 19 Feb 2025 14:40:00 +0000 (15:40 +0100)
committerDmitry Belyavskiy <beldmit@gmail.com>
Fri, 21 Feb 2025 16:58:41 +0000 (17:58 +0100)
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/26832)

crypto/evp/evp_enc.c
crypto/evp/s_lib.c
doc/man3/EVP_SKEY.pod
include/openssl/evp.h
test/evp_skey_test.c
util/libcrypto.num

index b0060ec9e5b20a0af167dbea1ddbbf457c9b97ad..69a1c8f08b2d6e583ede27f017998ea1805e546d 100644 (file)
@@ -586,7 +586,7 @@ static int evp_cipher_init_skey_internal(EVP_CIPHER_CTX *ctx,
             const unsigned char *keydata = NULL;
             size_t keylen = 0;
 
-            if (skey != NULL && !EVP_SKEY_get_raw_key(skey, &keydata, &keylen)) {
+            if (skey != NULL && !EVP_SKEY_get0_raw_key(skey, &keydata, &keylen)) {
                 ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
                 return 0;
             }
@@ -607,7 +607,7 @@ static int evp_cipher_init_skey_internal(EVP_CIPHER_CTX *ctx,
             const unsigned char *keydata = NULL;
             size_t keylen = 0;
 
-            if (skey != NULL && !EVP_SKEY_get_raw_key(skey, &keydata, &keylen)) {
+            if (skey != NULL && !EVP_SKEY_get0_raw_key(skey, &keydata, &keylen)) {
                 ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
                 return 0;
             }
index 85480b5b151d6d861c142f1bda2ba82ec8e5ac9b..f8d132a666f32de42f42534eb77285237dbd6fda 100644 (file)
@@ -138,8 +138,8 @@ static int get_secret_key(const OSSL_PARAM params[], void *arg)
     return 0;
 }
 
-int EVP_SKEY_get_raw_key(const EVP_SKEY *skey, const unsigned char **key,
-                         size_t *len)
+int EVP_SKEY_get0_raw_key(const EVP_SKEY *skey, const unsigned char **key,
+                          size_t *len)
 {
     struct raw_key_details_st raw_key;
 
index 8ff05e6645e64f7f5237d151e84aab93697ec830..27ad844d7ed421758b44d4f1f5d449fcc8749c43 100644 (file)
@@ -4,7 +4,7 @@
 
 EVP_SKEY, EVP_SKEY_generate,
 EVP_SKEY_import, EVP_SKEY_import_raw_key, EVP_SKEY_up_ref,
-EVP_SKEY_export, EVP_SKEY_get_raw_key, EVP_SKEY_get0_key_id,
+EVP_SKEY_export, EVP_SKEY_get0_raw_key, EVP_SKEY_get0_key_id,
 EVP_SKEY_get0_skeymgmt_name, EVP_SKEY_get0_provider_name,
 EVP_SKEY_free, EVP_SKEY_is_a, EVP_SKEY_to_provider
 - opaque symmetric key allocation and handling functions
@@ -25,7 +25,7 @@ EVP_SKEY_free, EVP_SKEY_is_a, EVP_SKEY_to_provider
                                    const char *propquery);
  int EVP_SKEY_export(const EVP_SKEY *skey, int selection,
                      OSSL_CALLBACK *export_cb, void *export_cbarg);
- int EVP_SKEY_get_raw_key(const EVP_SKEY *skey, const unsigned char **key,
+ int EVP_SKEY_get0_raw_key(const EVP_SKEY *skey, const unsigned char **key,
                           size_t *len);
  const char *EVP_SKEY_get0_key_id(const EVP_SKEY *skey);
 
@@ -65,9 +65,10 @@ that gets passed the value of I<export_cbarg>.  See L<openssl-core.h(7)> for
 more information about the callback. Note that the L<OSSL_PARAM(3)> array that
 is passed to the callback is not persistent after the callback returns.
 
-The EVP_SKEY_get_raw_key() function copies raw key bytes to the passed buffer
-and sets the key len. The operation can fail when the underlying key
-management doesn't support export of the secret key.
+The EVP_SKEY_get0_raw_key() returns a pointer to a raw key bytes to the passed
+address and sets the key len. The returned address is managed by the internal
+key management and shouldn't be freed explicitly.  The operation can fail when
+the underlying key management doesn't support export of the secret key.
 
 The EVP_SKEY_get0_key_id() returns a NUL-terminated string providing some
 human-readable identifier of the key if provided by the underlying key
@@ -125,7 +126,7 @@ EVP_SKEY_get0_key_id() returns either a valid pointer or NULL.
 
 EVP_SKEY_up_ref() returns 1 for success and 0 on failure.
 
-EVP_SKEY_export() and EVP_SKEY_get_raw_key() return 1 for success and 0 on failure.
+EVP_SKEY_export() and EVP_SKEY_get0_raw_key() return 1 for success and 0 on failure.
 
 EVP_SKEY_get0_skeymgmt_name() and EVP_SKEY_get0_provider_name() return the
 names of the associated EVP_SKEYMGMT object and its provider correspondigly.
@@ -143,7 +144,7 @@ L<EVP_SKEYMGMT(3)>, L<provider(7)>, L<OSSL_PARAM(3)>
 =head1 HISTORY
 
 The B<EVP_SKEY> API and functions EVP_SKEY_export(),
-EVP_SKEY_free(), EVP_SKEY_get_raw_key(), EVP_SKEY_import(),
+EVP_SKEY_free(), EVP_SKEY_get0_raw_key(), EVP_SKEY_import(),
 EVP_SKEY_import_raw_key(), EVP_SKEY_up_ref(), EVP_SKEY_generate(),
 EVP_SKEY_get0_key_id(), EVP_SKEY_get0_provider_name(),
 EVP_SKEY_get0_skeymgmt_name(), EVP_SKEY_is_a(), EVP_SKEY_to_provider()
index 0cbb38aad89c8cf078b31b6e5474775b59dd0f22..c8be0201535e8c526aad243705d215ebd200de00 100644 (file)
@@ -2292,8 +2292,8 @@ EVP_SKEY *EVP_SKEY_generate(OSSL_LIB_CTX *libctx, const char *skeymgmtname,
 EVP_SKEY *EVP_SKEY_import_raw_key(OSSL_LIB_CTX *libctx, const char *skeymgmtname,
                                   unsigned char *key, size_t keylen,
                                   const char *propquery);
-int EVP_SKEY_get_raw_key(const EVP_SKEY *skey, const unsigned char **key,
-                         size_t *len);
+int EVP_SKEY_get0_raw_key(const EVP_SKEY *skey, const unsigned char **key,
+                          size_t *len);
 const char *EVP_SKEY_get0_key_id(const EVP_SKEY *skey);
 int EVP_SKEY_export(const EVP_SKEY *skey, int selection,
                     OSSL_CALLBACK *export_cb, void *export_cbarg);
index 92e435471da9845e9f4039ab9ba6945ba70d593b..774b84ef135282400affe1560d742afff0d77f83 100644 (file)
@@ -76,7 +76,7 @@ static int test_skey_cipher(void)
         goto end;
 
     /* Export raw key */
-    if (!TEST_int_gt(EVP_SKEY_get_raw_key(key, &export, &export_len), 0)
+    if (!TEST_int_gt(EVP_SKEY_get0_raw_key(key, &export, &export_len), 0)
         || !TEST_mem_eq(export, export_len, import_key, sizeof(import_key)))
         goto end;
 
@@ -134,7 +134,7 @@ static int test_aes_raw_skey(void)
     if (!TEST_ptr(skey))
         goto end;
 
-    if (!TEST_int_gt(EVP_SKEY_get_raw_key(skey, &export_key, &export_length), 0)
+    if (!TEST_int_gt(EVP_SKEY_get0_raw_key(skey, &export_key, &export_length), 0)
         || !TEST_mem_eq(aes_key, KEY_SIZE, export_key, export_length))
         goto end;
 
@@ -211,7 +211,7 @@ static int test_des_raw_skey(void)
     if (!TEST_ptr(skey))
         goto end;
 
-    if (!TEST_int_gt(EVP_SKEY_get_raw_key(skey, &export_key, &export_length), 0)
+    if (!TEST_int_gt(EVP_SKEY_get0_raw_key(skey, &export_key, &export_length), 0)
         || !TEST_mem_eq(des_key, DES_KEY_SIZE, export_key, export_length))
         goto end;
 
index 25f20e40655f845a4aef5499477afce1bc672854..07c811914656cf6c279b4566353344da75383361 100644 (file)
@@ -5894,7 +5894,7 @@ EVP_CipherInit_SKEY                     ? 3_5_0   EXIST::FUNCTION:
 EVP_SKEY_import                         ?      3_5_0   EXIST::FUNCTION:
 EVP_SKEY_generate                       ?      3_5_0   EXIST::FUNCTION:
 EVP_SKEY_import_raw_key                 ?      3_5_0   EXIST::FUNCTION:
-EVP_SKEY_get_raw_key                    ?      3_5_0   EXIST::FUNCTION:
+EVP_SKEY_get0_raw_key                   ?      3_5_0   EXIST::FUNCTION:
 EVP_SKEY_export                         ?      3_5_0   EXIST::FUNCTION:
 EVP_SKEY_up_ref                         ?      3_5_0   EXIST::FUNCTION:
 EVP_SKEY_free                           ?      3_5_0   EXIST::FUNCTION: