Skip to content

Commit ee52c03

Browse files
authored
ML-DSA: ASN.1 Module - add parsing of BOTH private key format (#2416)
1 parent 5a74835 commit ee52c03

File tree

4 files changed

+595
-17
lines changed

4 files changed

+595
-17
lines changed

crypto/evp_extra/p_pqdsa_asn1.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,10 @@ static int pqdsa_priv_decode(EVP_PKEY *out, CBS *oid, CBS *params, CBS *key, CBS
155155
}
156156

157157
// Try to parse as one of the three ASN.1 formats defined in ML-DSA-XX-PrivateKey
158-
// Currently only the following cases are supported:
158+
// https://datatracker.ietf.org/doc/draft-ietf-lamps-dilithium-certificates/
159159
// Case 1: seed [0] OCTET STRING
160160
// Case 2: expandedKey OCTET STRING
161-
162-
// Once https://datatracker.ietf.org/doc/draft-ietf-lamps-dilithium-certificates/
163-
// is stable we will implement:
164-
// Case 3: both SEQUENCE { seed, expandedKey }
161+
// Case 3: both SEQUENCE {seed, expandedKey}
165162

166163
if (CBS_peek_asn1_tag(key, CBS_ASN1_CONTEXT_SPECIFIC | 0)) {
167164
// Case 1: seed [0] OCTET STRING
@@ -191,6 +188,17 @@ static int pqdsa_priv_decode(EVP_PKEY *out, CBS *oid, CBS *params, CBS *key, CBS
191188
}
192189

193190
return PQDSA_KEY_set_raw_private_key(out->pkey.pqdsa_key, &expanded_key);
191+
} else if (CBS_peek_asn1_tag(key, CBS_ASN1_SEQUENCE)) {
192+
// Case 3: both SEQUENCE {seed, expandedKey}
193+
CBS sequence, seed, expanded_key;
194+
if (!CBS_get_asn1(key, &sequence, CBS_ASN1_SEQUENCE) ||
195+
!CBS_get_asn1(&sequence, &seed, CBS_ASN1_OCTETSTRING) ||
196+
!CBS_get_asn1(&sequence, &expanded_key, CBS_ASN1_OCTETSTRING)) {
197+
OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);
198+
return 0;
199+
}
200+
201+
return PQDSA_KEY_set_raw_keypair_from_both(out->pkey.pqdsa_key, &seed, &expanded_key);
194202
} else {
195203
OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);
196204
return 0;

0 commit comments

Comments
 (0)