diff --git a/crypto/dilithium/internal.h b/crypto/dilithium/internal.h index ccb28066cf..be19b0d561 100644 --- a/crypto/dilithium/internal.h +++ b/crypto/dilithium/internal.h @@ -56,6 +56,7 @@ struct pqdsa_key_st { int PQDSA_KEY_init(PQDSA_KEY *key, const PQDSA *pqdsa); const PQDSA * PQDSA_find_dsa_by_nid(int nid); +const EVP_PKEY_ASN1_METHOD *PQDSA_find_asn1_by_nid(int nid); const PQDSA *PQDSA_KEY_get0_dsa(PQDSA_KEY* key); PQDSA_KEY *PQDSA_KEY_new(void); void PQDSA_KEY_free(PQDSA_KEY *key); diff --git a/crypto/dilithium/pqdsa.c b/crypto/dilithium/pqdsa.c index 5bc5ceb235..708b3e9c9d 100644 --- a/crypto/dilithium/pqdsa.c +++ b/crypto/dilithium/pqdsa.c @@ -4,8 +4,9 @@ #include #include -#include "internal.h" +#include "../evp_extra/internal.h" #include "../fipsmodule/delocate.h" +#include "internal.h" #include "ml_dsa.h" // ML-DSA OIDs as defined within: @@ -107,3 +108,12 @@ const PQDSA *PQDSA_find_dsa_by_nid(int nid) { return NULL; } } + +const EVP_PKEY_ASN1_METHOD *PQDSA_find_asn1_by_nid(int nid) { + switch (nid) { + case NID_MLDSA65: + return &pqdsa_asn1_meth; + default: + return NULL; + } +} diff --git a/crypto/evp_extra/evp_asn1.c b/crypto/evp_extra/evp_asn1.c index 4c17794937..7009a12d0b 100644 --- a/crypto/evp_extra/evp_asn1.c +++ b/crypto/evp_extra/evp_asn1.c @@ -68,6 +68,7 @@ #include "../bytestring/internal.h" #include "../internal.h" #include "internal.h" +#include "../dilithium/internal.h" static const EVP_PKEY_ASN1_METHOD *parse_key_type(CBS *cbs) { CBS oid; @@ -93,13 +94,8 @@ static const EVP_PKEY_ASN1_METHOD *parse_key_type(CBS *cbs) { // The pkey_id for the pqdsa_asn1_meth is EVP_PKEY_PQDSA, as this holds all // asn1 functions for pqdsa types. However, the incoming CBS has the OID for // the specific algorithm. So we must search explicitly for the algorithm. - - //TODO find a way to search through the OIDs of known PQDSA methods and return - // the ans1 meth #ifdef ENABLE_DILITHIUM - if (OBJ_cbs2nid(&oid) == NID_MLDSA65) { - return &pqdsa_asn1_meth; - } + return PQDSA_find_asn1_by_nid(OBJ_cbs2nid(&oid)); #endif return NULL; }