]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Implementation of EVP_SKEY_import_SKEYMGMT
authorDmitry Belyavskiy <beldmit@gmail.com>
Fri, 29 Aug 2025 11:52:55 +0000 (13:52 +0200)
committerNeil Horman <nhorman@openssl.org>
Sun, 31 Aug 2025 01:11:06 +0000 (21:11 -0400)
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28369)

crypto/evp/s_lib.c
doc/man3/EVP_SKEY.pod
include/openssl/evp.h

index f8d132a666f32de42f42534eb77285237dbd6fda..b8cf42260c0cdbed7fa1f0d3aa46e2360c2c2937 100644 (file)
@@ -103,6 +103,25 @@ EVP_SKEY *EVP_SKEY_import(OSSL_LIB_CTX *libctx, const char *skeymgmtname, const
     return NULL;
 }
 
+EVP_SKEY *EVP_SKEY_import_SKEYMGMT(OSSL_LIB_CTX *libctx, EVP_SKEYMGMT *skeymgmt,
+                                   int selection, const OSSL_PARAM *params)
+{
+    EVP_SKEY *skey = evp_skey_alloc(skeymgmt);
+
+    if (skey == NULL)
+        return NULL;
+
+    skey->keydata = evp_skeymgmt_import(skey->skeymgmt, selection, params);
+    if (skey->keydata == NULL)
+        goto err;
+
+    return skey;
+
+ err:
+    EVP_SKEY_free(skey);
+    return NULL;
+}
+
 EVP_SKEY *EVP_SKEY_generate(OSSL_LIB_CTX *libctx, const char *skeymgmtname,
                             const char *propquery, const OSSL_PARAM *params)
 {
index 27ad844d7ed421758b44d4f1f5d449fcc8749c43..2124f4e3dc439b1f7e6737d2ee38431a766877cf 100644 (file)
@@ -2,11 +2,10 @@
 
 =head1 NAME
 
-EVP_SKEY, EVP_SKEY_generate,
-EVP_SKEY_import, EVP_SKEY_import_raw_key, EVP_SKEY_up_ref,
-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
+EVP_SKEY, EVP_SKEY_generate, EVP_SKEY_import, EVP_SKEY_import_raw_key,
+EVP_SKEY_import_SKEYMGMT, EVP_SKEY_up_ref, 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
 
 =head1 SYNOPSIS
@@ -23,6 +22,8 @@ EVP_SKEY_free, EVP_SKEY_is_a, EVP_SKEY_to_provider
  EVP_SKEY *EVP_SKEY_import_raw_key(OSSL_LIB_CTX *libctx, const char *skeymgmtname,
                                    unsigned char *key, size_t *len,
                                    const char *propquery);
+ EVP_SKEY *EVP_SKEY_import_SKEYMGMT(OSSL_LIB_CTX *libctx, EVP_SKEYMGMT *skeymgmt,
+                                    int selection, const OSSL_PARAM *params);
  int EVP_SKEY_export(const EVP_SKEY *skey, int selection,
                      OSSL_CALLBACK *export_cb, void *export_cbarg);
  int EVP_SKEY_get0_raw_key(const EVP_SKEY *skey, const unsigned char **key,
@@ -59,6 +60,10 @@ the B<params> argument.
 The EVP_SKEY_import_raw_key() function is a helper that creates an B<EVP_SKEY> object
 containing the raw byte representation of the symmetric keys.
 
+The EVP_SKEY_import_SKEYMGMT() function is a helper that creates an B<EVP_SKEY>
+object containing the representation of the symmetric keys specific to the
+particular B<EVP_SKEYMGMT>.
+
 The EVP_SKEY_export() function extracts values from a key I<skey> using the
 I<selection>.  I<selection> is described below. It uses a callback I<export_cb>
 that gets passed the value of I<export_cbarg>.  See L<openssl-core.h(7)> for
@@ -119,8 +124,9 @@ key I<skey> cannot be exported from its provider.
 
 =head1 RETURN VALUES
 
-EVP_SKEY_generate(), EVP_SKEY_import() and EVP_SKEY_import_raw_key() return
-either the newly allocated B<EVP_SKEY> structure or NULL if an error occurred.
+EVP_SKEY_generate(), EVP_SKEY_import(), EVP_SKEY_import_raw_key(), and
+EVP_SKEY_import_SKEYMGMT() return either the newly allocated B<EVP_SKEY>
+structure or NULL if an error occurred.
 
 EVP_SKEY_get0_key_id() returns either a valid pointer or NULL.
 
@@ -150,6 +156,8 @@ EVP_SKEY_get0_key_id(), EVP_SKEY_get0_provider_name(),
 EVP_SKEY_get0_skeymgmt_name(), EVP_SKEY_is_a(), EVP_SKEY_to_provider()
 were introduced in OpenSSL 3.5.
 
+The EVP_SKEY_import_SKEYMGMT() function was introduced in OpenSSL 4.0.
+
 =head1 COPYRIGHT
 
 Copyright 2025 The OpenSSL Project Authors. All Rights Reserved.
index 1603b450ff557bcb0d24739e0918f848ba2df586..ec37c22d3f7b399a14fdb8debcbf939afdbbbd4e 100644 (file)
@@ -2322,6 +2322,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);
+EVP_SKEY *EVP_SKEY_import_SKEYMGMT(OSSL_LIB_CTX *libctx, EVP_SKEYMGMT *skeymgmt,
+                                   int selection, const OSSL_PARAM *params);
 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);