Skip to content

Commit

Permalink
added PQDSA assign
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemas committed Nov 7, 2024
1 parent 7e524df commit 8d6ff48
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
4 changes: 1 addition & 3 deletions crypto/dilithium/p_dilithium3.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,10 @@ static int pkey_pqdsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) {
if (key == NULL ||
!PQDSA_KEY_init(key, pqdsa) ||
!pqdsa->method->keygen(key->public_key, key->secret_key) ||
!EVP_PKEY_set_type(pkey, EVP_PKEY_PQDSA)) {
!EVP_PKEY_assign_PQDSA_KEY(pkey, key)) {
PQDSA_KEY_free(key);
return 0;
}

pkey->pkey.pqdsa_key = key;
return 1;
}

Expand Down
9 changes: 0 additions & 9 deletions crypto/evp_extra/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ typedef struct {
char has_private;
} X25519_KEY;

#ifdef ENABLE_DILITHIUM

typedef struct {
uint8_t *pub;
uint8_t *priv;
} DILITHIUM3_KEY;

#endif

extern const size_t asn1_evp_pkey_methods_size;
extern const EVP_PKEY_ASN1_METHOD *const asn1_evp_pkey_methods[];
extern const EVP_PKEY_ASN1_METHOD dsa_asn1_meth;
Expand Down
15 changes: 15 additions & 0 deletions crypto/fipsmodule/evp/evp.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,17 @@ EC_KEY *EVP_PKEY_get1_EC_KEY(const EVP_PKEY *pkey) {
return ec_key;
}

#ifdef ENABLE_DILITHIUM
int EVP_PKEY_assign_PQDSA_KEY(EVP_PKEY *pkey, PQDSA_KEY *key) {
SET_DIT_AUTO_RESET;
const EVP_PKEY_ASN1_METHOD *meth = evp_pkey_asn1_find(EVP_PKEY_PQDSA);
assert(meth != NULL);
evp_pkey_set_method(pkey, meth);
pkey->pkey.ptr = key;
return key != NULL;
}
#endif

int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key) {
// This function can only be used to assign RSA, DSA, EC, and DH keys. Other
// key types have internal representations which are not exposed through the
Expand All @@ -436,6 +447,10 @@ int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key) {
return EVP_PKEY_assign_EC_KEY(pkey, key);
case EVP_PKEY_DH:
return EVP_PKEY_assign_DH(pkey, key);
#ifdef ENABLE_DILITHIUM
case EVP_PKEY_PQDSA:
return EVP_PKEY_assign_PQDSA_KEY(pkey, key);
#endif
default:
if (!EVP_PKEY_set_type(pkey, type)) {
return 0;
Expand Down
2 changes: 2 additions & 0 deletions include/openssl/evp.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ OPENSSL_EXPORT int EVP_PKEY_assign_DH(EVP_PKEY *pkey, DH *key);
OPENSSL_EXPORT DH *EVP_PKEY_get0_DH(const EVP_PKEY *pkey);
OPENSSL_EXPORT DH *EVP_PKEY_get1_DH(const EVP_PKEY *pkey);

OPENSSL_EXPORT int EVP_PKEY_assign_PQDSA_KEY(EVP_PKEY *pkey, PQDSA_KEY *key);

// EVP_PKEY_CTX_set_dh_paramgen_prime_len sets the length of the DH prime
// parameter p for DH parameter generation. If this function is not called,
// the default length of 2048 is used. |pbits| must be greater than or equal
Expand Down

0 comments on commit 8d6ff48

Please sign in to comment.