skey: convert generic SKEY to use generated param parser

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/28144)
This commit is contained in:
Pauli 2025-07-22 09:48:10 +10:00
parent b20da23280
commit d1d94e0fbe
3 changed files with 22 additions and 14 deletions

View File

@ -9,7 +9,7 @@
#include <openssl/core_dispatch.h>
#include "crypto/types.h"
#include "skeymgmt_lcl.h"
#include "prov/skeymgmt_lcl.h"
#include "internal/skey.h"
#include "prov/implementations.h"

View File

@ -6,15 +6,20 @@
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
{-
use OpenSSL::paramnames qw(produce_param_decoder);
-}
#include <string.h>
#include <openssl/core_dispatch.h>
#include <openssl/core_names.h>
#include "crypto/types.h"
#include "internal/cryptlib.h"
#include "internal/skey.h"
#include "prov/provider_ctx.h"
#include "prov/providercommon.h"
#include "prov/implementations.h"
#include "skeymgmt_lcl.h"
#include "prov/skeymgmt_lcl.h"
void generic_free(void *keydata)
{
@ -23,14 +28,18 @@ void generic_free(void *keydata)
if (generic == NULL)
return;
OPENSSL_free(generic->data);
OPENSSL_clear_free(generic->data, generic->length);
OPENSSL_free(generic);
}
{- produce_param_decoder('generic_skey_import',
(['SKEY_PARAM_RAW_BYTES', 'raw_bytes', 'octet_string'],
)); -}
void *generic_import(void *provctx, int selection, const OSSL_PARAM params[])
{
OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(provctx);
const OSSL_PARAM *raw_bytes;
struct generic_skey_import_st p;
PROV_SKEY *generic = NULL;
int ok = 0;
@ -40,8 +49,11 @@ void *generic_import(void *provctx, int selection, const OSSL_PARAM params[])
if ((selection & OSSL_SKEYMGMT_SELECT_SECRET_KEY) == 0)
return NULL;
raw_bytes = OSSL_PARAM_locate_const(params, OSSL_SKEY_PARAM_RAW_BYTES);
if (raw_bytes == NULL)
if (!generic_skey_import_decoder(params, &p))
return NULL;
if (p.raw_bytes == NULL
|| p.raw_bytes->data_type != OSSL_PARAM_OCTET_STRING)
return NULL;
generic = OPENSSL_zalloc(sizeof(PROV_SKEY));
@ -52,9 +64,10 @@ void *generic_import(void *provctx, int selection, const OSSL_PARAM params[])
generic->type = SKEY_TYPE_GENERIC;
if ((generic->data = OPENSSL_memdup(raw_bytes->data, raw_bytes->data_size)) == NULL)
if ((generic->data = OPENSSL_memdup(p.raw_bytes->data,
p.raw_bytes->data_size)) == NULL)
goto end;
generic->length = raw_bytes->data_size;
generic->length = p.raw_bytes->data_size;
ok = 1;
end:
@ -65,14 +78,9 @@ end:
return generic;
}
static const OSSL_PARAM generic_import_params[] = {
OSSL_PARAM_octet_string(OSSL_SKEY_PARAM_RAW_BYTES, NULL, 0),
OSSL_PARAM_END
};
const OSSL_PARAM *generic_imp_settable_params(void *provctx)
{
return generic_import_params;
return generic_skey_import_list;
}
int generic_export(void *keydata, int selection,