Skip to content

Commit

Permalink
DESERIALIZER: Add deserializers for the rest of our asymmetric key types
Browse files Browse the repository at this point in the history
To be able to implement this, there was a need for the standard
EVP_PKEY_set1_, EVP_PKEY_get0_ and EVP_PKEY_get1_ functions for
ED25519, ED448, X25519 and X448, as well as the corresponding
EVP_PKEY_assign_ macros.  There was also a need to extend the list of
hard coded names that EVP_PKEY_is_a() recognise.

Along with this, OSSL_FUNC_keymgmt_load() are implemented for all
those key types.

The deserializers for these key types are all implemented generically,
in providers/implementations/serializers/deserializer_der2key.c.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12544)
  • Loading branch information
levitte authored and paulidale committed Aug 1, 2020
1 parent 3ff8159 commit 7c664b1
Show file tree
Hide file tree
Showing 18 changed files with 684 additions and 384 deletions.
2 changes: 2 additions & 0 deletions crypto/err/openssl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ EVP_F_EVP_PKEY_ENCRYPT_INIT:139:EVP_PKEY_encrypt_init
EVP_F_EVP_PKEY_ENCRYPT_OLD:152:EVP_PKEY_encrypt_old
EVP_F_EVP_PKEY_GET0_DH:119:EVP_PKEY_get0_DH
EVP_F_EVP_PKEY_GET0_DSA:120:EVP_PKEY_get0_DSA
EVP_F_EVP_PKEY_GET0_ECX_KEY:222:
EVP_F_EVP_PKEY_GET0_EC_KEY:131:EVP_PKEY_get0_EC_KEY
EVP_F_EVP_PKEY_GET0_HMAC:183:EVP_PKEY_get0_hmac
EVP_F_EVP_PKEY_GET0_POLY1305:184:EVP_PKEY_get0_poly1305
Expand Down Expand Up @@ -2532,6 +2533,7 @@ EVP_R_EXPECTING_AN_HMAC_KEY:174:expecting an hmac key
EVP_R_EXPECTING_AN_RSA_KEY:127:expecting an rsa key
EVP_R_EXPECTING_A_DH_KEY:128:expecting a dh key
EVP_R_EXPECTING_A_DSA_KEY:129:expecting a dsa key
EVP_R_EXPECTING_A_ECX_KEY:219:expecting a ecx key
EVP_R_EXPECTING_A_EC_KEY:142:expecting a ec key
EVP_R_EXPECTING_A_POLY1305_KEY:164:expecting a poly1305 key
EVP_R_EXPECTING_A_SIPHASH_KEY:175:expecting a siphash key
Expand Down
2 changes: 2 additions & 0 deletions crypto/evp/evp_err.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ static const ERR_STRING_DATA EVP_str_reasons[] = {
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_EXPECTING_A_DH_KEY), "expecting a dh key"},
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_EXPECTING_A_DSA_KEY),
"expecting a dsa key"},
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_EXPECTING_A_ECX_KEY),
"expecting a ecx key"},
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_EXPECTING_A_EC_KEY), "expecting a ec key"},
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_EXPECTING_A_POLY1305_KEY),
"expecting a poly1305 key"},
Expand Down
61 changes: 61 additions & 0 deletions crypto/evp/p_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "crypto/asn1.h"
#include "crypto/evp.h"
#include "crypto/ecx.h"
#include "internal/evp.h"
#include "internal/provider.h"
#include "evp_local.h"
Expand Down Expand Up @@ -855,6 +856,54 @@ EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey)
EC_KEY_up_ref(ret);
return ret;
}

static int EVP_PKEY_set1_ECX_KEY(EVP_PKEY *pkey, int type, ECX_KEY *key)
{
int ret = EVP_PKEY_assign(pkey, type, key);
if (ret)
ecx_key_up_ref(key);
return ret;
}

static ECX_KEY *EVP_PKEY_get0_ECX_KEY(const EVP_PKEY *pkey, int type)
{
if (!evp_pkey_downgrade((EVP_PKEY *)pkey)) {
ERR_raise(ERR_LIB_EVP, EVP_R_INACCESSIBLE_KEY);
return NULL;
}
if (EVP_PKEY_base_id(pkey) != type) {
ERR_raise(ERR_LIB_EVP, EVP_R_EXPECTING_A_ECX_KEY);
return NULL;
}
return pkey->pkey.ecx;
}

static ECX_KEY *EVP_PKEY_get1_ECX_KEY(EVP_PKEY *pkey, int type)
{
ECX_KEY *ret = EVP_PKEY_get0_ECX_KEY(pkey, type);
if (ret != NULL)
ecx_key_up_ref(ret);
return ret;
}

# define IMPLEMENT_ECX_VARIANT(NAME) \
int EVP_PKEY_set1_##NAME(EVP_PKEY *pkey, ECX_KEY *key) \
{ \
return EVP_PKEY_set1_ECX_KEY(pkey, EVP_PKEY_##NAME, key); \
} \
ECX_KEY *EVP_PKEY_get0_##NAME(const EVP_PKEY *pkey) \
{ \
return EVP_PKEY_get0_ECX_KEY(pkey, EVP_PKEY_##NAME); \
} \
ECX_KEY *EVP_PKEY_get1_##NAME(EVP_PKEY *pkey) \
{ \
return EVP_PKEY_get1_ECX_KEY(pkey, EVP_PKEY_##NAME); \
}
IMPLEMENT_ECX_VARIANT(X25519)
IMPLEMENT_ECX_VARIANT(X448)
IMPLEMENT_ECX_VARIANT(ED25519)
IMPLEMENT_ECX_VARIANT(ED448)

# endif

# ifndef OPENSSL_NO_DH
Expand Down Expand Up @@ -940,6 +989,18 @@ int EVP_PKEY_is_a(const EVP_PKEY *pkey, const char *name)
#ifndef OPENSSL_NO_EC
else if (strcasecmp(name, "EC") == 0)
type = EVP_PKEY_EC;
else if (strcasecmp(name, "ED25519") == 0)
type = EVP_PKEY_ED25519;
else if (strcasecmp(name, "ED448") == 0)
type = EVP_PKEY_ED448;
else if (strcasecmp(name, "X25519") == 0)
type = EVP_PKEY_X25519;
else if (strcasecmp(name, "X448") == 0)
type = EVP_PKEY_X448;
#endif
#ifndef OPENSSL_NO_DH
else if (strcasecmp(name, "DH") == 0)
type = EVP_PKEY_DH;
#endif
#ifndef OPENSSL_NO_DSA
else if (strcasecmp(name, "DSA") == 0)
Expand Down
55 changes: 43 additions & 12 deletions doc/man3/EVP_PKEY_set1_RSA.pod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
=head1 NAME

EVP_PKEY_set1_RSA, EVP_PKEY_set1_DSA, EVP_PKEY_set1_DH, EVP_PKEY_set1_EC_KEY,
EVP_PKEY_set1_ED25519, EVP_PKEY_set1_ED448,
EVP_PKEY_set1_X25519, EVP_PKEY_set1_X448,
EVP_PKEY_get1_RSA, EVP_PKEY_get1_DSA, EVP_PKEY_get1_DH, EVP_PKEY_get1_EC_KEY,
EVP_PKEY_get1_ED25519, EVP_PKEY_get1_ED448,
EVP_PKEY_get1_X25519, EVP_PKEY_get1_X448,
EVP_PKEY_get0_RSA, EVP_PKEY_get0_DSA, EVP_PKEY_get0_DH, EVP_PKEY_get0_EC_KEY,
EVP_PKEY_get0_ED25519, EVP_PKEY_get0_ED448,
EVP_PKEY_get0_X25519, EVP_PKEY_get0_X448,
EVP_PKEY_assign_RSA, EVP_PKEY_assign_DSA, EVP_PKEY_assign_DH,
EVP_PKEY_assign_EC_KEY, EVP_PKEY_assign_POLY1305, EVP_PKEY_assign_SIPHASH,
EVP_PKEY_assign_ED25519, EVP_PKEY_assign_ED448,
EVP_PKEY_assign_X25519, EVP_PKEY_assign_X448,
EVP_PKEY_get0_hmac, EVP_PKEY_get0_poly1305, EVP_PKEY_get0_siphash,
EVP_PKEY_type, EVP_PKEY_id, EVP_PKEY_base_id, EVP_PKEY_set_alias_type,
EVP_PKEY_set1_engine, EVP_PKEY_get0_engine - EVP_PKEY assignment functions
Expand All @@ -19,11 +27,19 @@ EVP_PKEY_set1_engine, EVP_PKEY_get0_engine - EVP_PKEY assignment functions
int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key);
int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key);
int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key);
int EVP_PKEY_set1_ED25519(EVP_PKEY *pkey, ECX_KEY *key);
int EVP_PKEY_set1_ED448(EVP_PKEY *pkey, ECX_KEY *key);
int EVP_PKEY_set1_X25519(EVP_PKEY *pkey, ECX_KEY *key);
int EVP_PKEY_set1_X448(EVP_PKEY *pkey, ECX_KEY *key);

RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey);
EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);
ECX_KEY *EVP_PKEY_get1_ED25519(EVP_PKEY *pkey);
ECX_KEY *EVP_PKEY_get1_ED448(EVP_PKEY *pkey);
ECX_KEY *EVP_PKEY_get1_X25519(EVP_PKEY *pkey);
ECX_KEY *EVP_PKEY_get1_X448(EVP_PKEY *pkey);

const unsigned char *EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len);
const unsigned char *EVP_PKEY_get0_poly1305(const EVP_PKEY *pkey, size_t *len);
Expand All @@ -32,11 +48,19 @@ EVP_PKEY_set1_engine, EVP_PKEY_get0_engine - EVP_PKEY assignment functions
DSA *EVP_PKEY_get0_DSA(const EVP_PKEY *pkey);
DH *EVP_PKEY_get0_DH(const EVP_PKEY *pkey);
EC_KEY *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey);
ECX_KEY *EVP_PKEY_get0_ED25519(EVP_PKEY *pkey);
ECX_KEY *EVP_PKEY_get0_ED448(EVP_PKEY *pkey);
ECX_KEY *EVP_PKEY_get0_X25519(EVP_PKEY *pkey);
ECX_KEY *EVP_PKEY_get0_X448(EVP_PKEY *pkey);

int EVP_PKEY_assign_RSA(EVP_PKEY *pkey, RSA *key);
int EVP_PKEY_assign_DSA(EVP_PKEY *pkey, DSA *key);
int EVP_PKEY_assign_DH(EVP_PKEY *pkey, DH *key);
int EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey, EC_KEY *key);
int EVP_PKEY_assign_ED25519(EVP_PKEY *pkey, ECX_KEY *key);
int EVP_PKEY_assign_ED448(EVP_PKEY *pkey, ECX_KEY *key);
int EVP_PKEY_assign_X25519(EVP_PKEY *pkey, ECX_KEY *key);
int EVP_PKEY_assign_X448(EVP_PKEY *pkey, ECX_KEY *key);
int EVP_PKEY_assign_POLY1305(EVP_PKEY *pkey, ASN1_OCTET_STRING *key);
int EVP_PKEY_assign_SIPHASH(EVP_PKEY *pkey, ASN1_OCTET_STRING *key);

Expand All @@ -50,24 +74,31 @@ EVP_PKEY_set1_engine, EVP_PKEY_get0_engine - EVP_PKEY assignment functions

=head1 DESCRIPTION

EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and
EVP_PKEY_set1_EC_KEY() set the key referenced by I<pkey> to I<key>.
EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH(),
EVP_PKEY_set1_EC_KEY(), EVP_PKEY_set1_ED25519(), EVP_PKEY_set1_ED448(),
EVP_PKEY_set1_X25519() and EVP_PKEY_set1_X448() set the key referenced by
I<pkey> to I<key>.

EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and
EVP_PKEY_get1_EC_KEY() return the referenced key in I<pkey> or
NULL if the key is not of the correct type.
EVP_PKEY_get1_EC_KEY(), EVP_PKEY_get1_ED25519(), EVP_PKEY_get1_ED448(),
EVP_PKEY_get1_X25519() and EVP_PKEY_get1_X448() return the referenced key in
I<pkey> or NULL if the key is not of the correct type. The returned key must
be freed after use.

EVP_PKEY_get0_hmac(), EVP_PKEY_get0_poly1305(), EVP_PKEY_get0_siphash(),
EVP_PKEY_get0_RSA(), EVP_PKEY_get0_DSA(), EVP_PKEY_get0_DH()
and EVP_PKEY_get0_EC_KEY() also return the referenced key in I<pkey> or NULL
if the key is not of the correct type but the reference count of the
returned key is B<not> incremented and so must not be freed up after use.
EVP_PKEY_get0_RSA(), EVP_PKEY_get0_DSA(), EVP_PKEY_get0_DH(),
EVP_PKEY_get0_EC_KEY(), EVP_PKEY_get0_ED25519(), EVP_PKEY_get0_ED448(),
EVP_PKEY_get0_X25519() and EVP_PKEY_get0_X448() return the referenced
key in I<pkey> or NULL if the key is not of the correct type but the
reference count of the returned key is B<not> incremented and so must not be
freed after use.

EVP_PKEY_assign_RSA(), EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH(),
EVP_PKEY_assign_EC_KEY(), EVP_PKEY_assign_POLY1305() and
EVP_PKEY_assign_SIPHASH() also set the referenced key to I<key>
however these use the supplied I<key> internally and so I<key>
will be freed when the parent I<pkey> is freed.
EVP_PKEY_assign_EC_KEY(), EVP_PKEY_assign_ED25519(), EVP_PKEY_assign_ED448(),
EVP_PKEY_assign_X25519(), EVP_PKEY_assign_X448(), EVP_PKEY_assign_POLY1305() and
EVP_PKEY_assign_SIPHASH() set the referenced key to I<key> however these use
the supplied I<key> internally and so I<key> will be freed when the parent
I<pkey> is freed.

EVP_PKEY_base_id() returns the type of I<pkey>. For example
an RSA key will return B<EVP_PKEY_RSA>.
Expand Down
21 changes: 21 additions & 0 deletions include/openssl/evp.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,14 @@ typedef int (EVP_PBE_KEYGEN) (EVP_CIPHER_CTX *ctx, const char *pass,
# ifndef OPENSSL_NO_EC
# define EVP_PKEY_assign_EC_KEY(pkey,eckey) EVP_PKEY_assign((pkey),EVP_PKEY_EC,\
(eckey))
# define EVP_PKEY_assign_X25519(pkey,ecxkey) EVP_PKEY_assign((pkey),EVP_PKEY_X25519,\
(ecxkey))
# define EVP_PKEY_assign_X448(pkey,ecxkey) EVP_PKEY_assign((pkey),EVP_PKEY_X448,\
(ecxkey))
# define EVP_PKEY_assign_ED25519(pkey,ecxkey) EVP_PKEY_assign((pkey),EVP_PKEY_ED25519,\
(ecxkey))
# define EVP_PKEY_assign_ED448(pkey,ecxkey) EVP_PKEY_assign((pkey),EVP_PKEY_ED448,\
(ecxkey))
# endif
# ifndef OPENSSL_NO_SIPHASH
# define EVP_PKEY_assign_SIPHASH(pkey,shkey) EVP_PKEY_assign((pkey),\
Expand Down Expand Up @@ -1222,6 +1230,19 @@ struct ec_key_st;
int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, struct ec_key_st *key);
struct ec_key_st *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey);
struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);
struct ecx_key_st;
int EVP_PKEY_set1_X25519(EVP_PKEY *pkey, struct ecx_key_st *key);
struct ecx_key_st *EVP_PKEY_get0_X25519(const EVP_PKEY *pkey);
struct ecx_key_st *EVP_PKEY_get1_X25519(EVP_PKEY *pkey);
int EVP_PKEY_set1_X448(EVP_PKEY *pkey, struct ecx_key_st *key);
struct ecx_key_st *EVP_PKEY_get0_X448(const EVP_PKEY *pkey);
struct ecx_key_st *EVP_PKEY_get1_X448(EVP_PKEY *pkey);
int EVP_PKEY_set1_ED25519(EVP_PKEY *pkey, struct ecx_key_st *key);
struct ecx_key_st *EVP_PKEY_get0_ED25519(const EVP_PKEY *pkey);
struct ecx_key_st *EVP_PKEY_get1_ED25519(EVP_PKEY *pkey);
int EVP_PKEY_set1_ED448(EVP_PKEY *pkey, struct ecx_key_st *key);
struct ecx_key_st *EVP_PKEY_get0_ED448(const EVP_PKEY *pkey);
struct ecx_key_st *EVP_PKEY_get1_ED448(EVP_PKEY *pkey);
# endif

EVP_PKEY *EVP_PKEY_new(void);
Expand Down
2 changes: 2 additions & 0 deletions include/openssl/evperr.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ int ERR_load_EVP_strings(void);
# define EVP_F_EVP_PKEY_ENCRYPT_OLD 0
# define EVP_F_EVP_PKEY_GET0_DH 0
# define EVP_F_EVP_PKEY_GET0_DSA 0
# define EVP_F_EVP_PKEY_GET0_ECX_KEY 0
# define EVP_F_EVP_PKEY_GET0_EC_KEY 0
# define EVP_F_EVP_PKEY_GET0_HMAC 0
# define EVP_F_EVP_PKEY_GET0_POLY1305 0
Expand Down Expand Up @@ -185,6 +186,7 @@ int ERR_load_EVP_strings(void);
# define EVP_R_EXPECTING_AN_RSA_KEY 127
# define EVP_R_EXPECTING_A_DH_KEY 128
# define EVP_R_EXPECTING_A_DSA_KEY 129
# define EVP_R_EXPECTING_A_ECX_KEY 219
# define EVP_R_EXPECTING_A_EC_KEY 142
# define EVP_R_EXPECTING_A_POLY1305_KEY 164
# define EVP_R_EXPECTING_A_SIPHASH_KEY 175
Expand Down
14 changes: 14 additions & 0 deletions providers/deserializers.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@
# error Macro DESER undefined
#endif

#ifndef OPENSSL_NO_DH
DESER("DH", "yes", "der", der_to_dh_deserializer_functions),
#endif
#ifndef OPENSSL_NO_DSA
DESER("DSA", "yes", "der", der_to_dsa_deserializer_functions),
#endif
#ifndef OPENSSL_NO_EC
DESER("EC", "yes", "der", der_to_ec_deserializer_functions),
DESER("ED25519", "yes", "der", der_to_ed25519_deserializer_functions),
DESER("ED448", "yes", "der", der_to_ed448_deserializer_functions),
DESER("X25519", "yes", "der", der_to_x25519_deserializer_functions),
DESER("X448", "yes", "der", der_to_x448_deserializer_functions),
#endif
DESER("RSA", "yes", "der", der_to_rsa_deserializer_functions),
DESER("RSA-PSS", "yes", "der", der_to_rsapss_deserializer_functions),

DESER("DER", "yes", "pem", pem_to_der_deserializer_functions),
7 changes: 7 additions & 0 deletions providers/implementations/include/prov/implementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,13 @@ extern const OSSL_DISPATCH ec_priv_pem_serializer_functions[];
extern const OSSL_DISPATCH ec_pub_pem_serializer_functions[];
extern const OSSL_DISPATCH ec_param_pem_serializer_functions[];

extern const OSSL_DISPATCH der_to_dh_deserializer_functions[];
extern const OSSL_DISPATCH der_to_dsa_deserializer_functions[];
extern const OSSL_DISPATCH der_to_ec_deserializer_functions[];
extern const OSSL_DISPATCH der_to_x25519_deserializer_functions[];
extern const OSSL_DISPATCH der_to_x448_deserializer_functions[];
extern const OSSL_DISPATCH der_to_ed25519_deserializer_functions[];
extern const OSSL_DISPATCH der_to_ed448_deserializer_functions[];
extern const OSSL_DISPATCH der_to_rsa_deserializer_functions[];
extern const OSSL_DISPATCH der_to_rsapss_deserializer_functions[];
extern const OSSL_DISPATCH pem_to_der_deserializer_functions[];
16 changes: 16 additions & 0 deletions providers/implementations/keymgmt/dh_kmgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static OSSL_FUNC_keymgmt_gen_set_params_fn dh_gen_set_params;
static OSSL_FUNC_keymgmt_gen_settable_params_fn dh_gen_settable_params;
static OSSL_FUNC_keymgmt_gen_fn dh_gen;
static OSSL_FUNC_keymgmt_gen_cleanup_fn dh_gen_cleanup;
static OSSL_FUNC_keymgmt_load_fn dh_load;
static OSSL_FUNC_keymgmt_get_params_fn dh_get_params;
static OSSL_FUNC_keymgmt_gettable_params_fn dh_gettable_params;
static OSSL_FUNC_keymgmt_set_params_fn dh_set_params;
Expand Down Expand Up @@ -644,6 +645,20 @@ static void dh_gen_cleanup(void *genctx)
OPENSSL_free(gctx);
}

void *dh_load(const void *reference, size_t reference_sz)
{
DH *dh = NULL;

if (reference_sz == sizeof(dh)) {
/* The contents of the reference is the address to our object */
dh = *(DH **)reference;
/* We grabbed, so we detach it */
*(DH **)reference = NULL;
return dh;
}
return NULL;
}

const OSSL_DISPATCH dh_keymgmt_functions[] = {
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))dh_newdata },
{ OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))dh_gen_init },
Expand All @@ -653,6 +668,7 @@ const OSSL_DISPATCH dh_keymgmt_functions[] = {
(void (*)(void))dh_gen_settable_params },
{ OSSL_FUNC_KEYMGMT_GEN, (void (*)(void))dh_gen },
{ OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))dh_gen_cleanup },
{ OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void))dh_load },
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))dh_freedata },
{ OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))dh_get_params },
{ OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))dh_gettable_params },
Expand Down
16 changes: 16 additions & 0 deletions providers/implementations/keymgmt/dsa_kmgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static OSSL_FUNC_keymgmt_gen_set_params_fn dsa_gen_set_params;
static OSSL_FUNC_keymgmt_gen_settable_params_fn dsa_gen_settable_params;
static OSSL_FUNC_keymgmt_gen_fn dsa_gen;
static OSSL_FUNC_keymgmt_gen_cleanup_fn dsa_gen_cleanup;
static OSSL_FUNC_keymgmt_load_fn dsa_load;
static OSSL_FUNC_keymgmt_get_params_fn dsa_get_params;
static OSSL_FUNC_keymgmt_gettable_params_fn dsa_gettable_params;
static OSSL_FUNC_keymgmt_has_fn dsa_has;
Expand Down Expand Up @@ -557,6 +558,20 @@ static void dsa_gen_cleanup(void *genctx)
OPENSSL_free(gctx);
}

void *dsa_load(const void *reference, size_t reference_sz)
{
DSA *dsa = NULL;

if (reference_sz == sizeof(dsa)) {
/* The contents of the reference is the address to our object */
dsa = *(DSA **)reference;
/* We grabbed, so we detach it */
*(DSA **)reference = NULL;
return dsa;
}
return NULL;
}

const OSSL_DISPATCH dsa_keymgmt_functions[] = {
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))dsa_newdata },
{ OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))dsa_gen_init },
Expand All @@ -566,6 +581,7 @@ const OSSL_DISPATCH dsa_keymgmt_functions[] = {
(void (*)(void))dsa_gen_settable_params },
{ OSSL_FUNC_KEYMGMT_GEN, (void (*)(void))dsa_gen },
{ OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))dsa_gen_cleanup },
{ OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void))dsa_load },
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))dsa_freedata },
{ OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))dsa_get_params },
{ OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))dsa_gettable_params },
Expand Down

0 comments on commit 7c664b1

Please sign in to comment.