Skip to content

Commit

Permalink
cleaned up search for asn1 method by nid
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemas committed Nov 14, 2024
1 parent c4afe50 commit 2622a60
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions crypto/dilithium/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion crypto/dilithium/pqdsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#include <openssl/mem.h>

#include <openssl/base.h>
#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:
Expand Down Expand Up @@ -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;
}
}
8 changes: 2 additions & 6 deletions crypto/evp_extra/evp_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 2622a60

Please sign in to comment.