SLH-DSA: Add EVP_PKEY_CTX_dup() support.
Reviewed-by: Tim Hudson <tjh@openssl.org> Reviewed-by: Viktor Dukhovni <viktor@openssl.org> Reviewed-by: Paul Dale <ppzgs1@gmail.com> (Merged from https://github.com/openssl/openssl/pull/26701)
This commit is contained in:
parent
3fcefd51a1
commit
0e43652489
7 changed files with 116 additions and 13 deletions
|
@ -32,6 +32,7 @@ static OSSL_FUNC_keymgmt_gen_init_fn slh_dsa_gen_init;
|
|||
static OSSL_FUNC_keymgmt_gen_cleanup_fn slh_dsa_gen_cleanup;
|
||||
static OSSL_FUNC_keymgmt_gen_set_params_fn slh_dsa_gen_set_params;
|
||||
static OSSL_FUNC_keymgmt_gen_settable_params_fn slh_dsa_gen_settable_params;
|
||||
static OSSL_FUNC_keymgmt_dup_fn slh_dsa_dup_key;
|
||||
|
||||
#define SLH_DSA_POSSIBLE_SELECTIONS (OSSL_KEYMGMT_SELECT_KEYPAIR)
|
||||
|
||||
|
@ -56,6 +57,13 @@ static void slh_dsa_free_key(void *keydata)
|
|||
ossl_slh_dsa_key_free((SLH_DSA_KEY *)keydata);
|
||||
}
|
||||
|
||||
static void *slh_dsa_dup_key(const void *keydata_from, int selection)
|
||||
{
|
||||
if (ossl_prov_is_running())
|
||||
return ossl_slh_dsa_key_dup(keydata_from, selection);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int slh_dsa_has(const void *keydata, int selection)
|
||||
{
|
||||
const SLH_DSA_KEY *key = keydata;
|
||||
|
@ -412,6 +420,7 @@ static void slh_dsa_gen_cleanup(void *genctx)
|
|||
const OSSL_DISPATCH ossl_slh_dsa_##fn##_keymgmt_functions[] = { \
|
||||
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))slh_dsa_##fn##_new_key }, \
|
||||
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))slh_dsa_free_key }, \
|
||||
{ OSSL_FUNC_KEYMGMT_DUP, (void (*)(void))slh_dsa_dup_key }, \
|
||||
{ OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))slh_dsa_has }, \
|
||||
{ OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))slh_dsa_match }, \
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))slh_dsa_import }, \
|
||||
|
|
|
@ -34,9 +34,13 @@ static OSSL_FUNC_signature_digest_sign_init_fn slh_dsa_digest_signverify_init;
|
|||
static OSSL_FUNC_signature_digest_sign_fn slh_dsa_digest_sign;
|
||||
static OSSL_FUNC_signature_digest_verify_fn slh_dsa_digest_verify;
|
||||
static OSSL_FUNC_signature_freectx_fn slh_dsa_freectx;
|
||||
static OSSL_FUNC_signature_dupctx_fn slh_dsa_dupctx;
|
||||
static OSSL_FUNC_signature_set_ctx_params_fn slh_dsa_set_ctx_params;
|
||||
static OSSL_FUNC_signature_settable_ctx_params_fn slh_dsa_settable_ctx_params;
|
||||
|
||||
/*
|
||||
* NOTE: Any changes to this structure may require updating slh_dsa_dupctx().
|
||||
*/
|
||||
typedef struct {
|
||||
SLH_DSA_KEY *key; /* Note that the key is not owned by this object */
|
||||
SLH_DSA_HASH_CTX *hash_ctx;
|
||||
|
@ -86,6 +90,35 @@ static void *slh_dsa_newctx(void *provctx, const char *alg, const char *propq)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void *slh_dsa_dupctx(void *vctx)
|
||||
{
|
||||
PROV_SLH_DSA_CTX *src = (PROV_SLH_DSA_CTX *)vctx;
|
||||
PROV_SLH_DSA_CTX *ret;
|
||||
|
||||
if (!ossl_prov_is_running())
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* Note that the SLH_DSA_KEY is ref counted via EVP_PKEY so we can just copy
|
||||
* the key here.
|
||||
*/
|
||||
ret = OPENSSL_memdup(src, sizeof(*src));
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
ret->propq = NULL;
|
||||
ret->hash_ctx = NULL;
|
||||
if (src->propq != NULL && (ret->propq = OPENSSL_strdup(src->propq)) == NULL)
|
||||
goto err;
|
||||
ret->hash_ctx = ossl_slh_dsa_hash_ctx_dup(src->hash_ctx);
|
||||
if (ret->hash_ctx == NULL)
|
||||
goto err;
|
||||
|
||||
return ret;
|
||||
err:
|
||||
slh_dsa_freectx(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int slh_dsa_set_alg_id_buffer(PROV_SLH_DSA_CTX *ctx)
|
||||
{
|
||||
int ret;
|
||||
|
@ -334,6 +367,7 @@ static int slh_dsa_get_ctx_params(void *vctx, OSSL_PARAM *params)
|
|||
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY, \
|
||||
(void (*)(void))slh_dsa_digest_verify }, \
|
||||
{ OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))slh_dsa_freectx }, \
|
||||
{ OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))slh_dsa_dupctx }, \
|
||||
{ OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, (void (*)(void))slh_dsa_set_ctx_params },\
|
||||
{ OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS, \
|
||||
(void (*)(void))slh_dsa_settable_ctx_params }, \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue