LibCrypto: Support the parsing of certs and keys for ml-kem keys

This commit is contained in:
Tete17 2025-11-28 23:05:39 +01:00 committed by Shannon Booth
parent 5348e97f87
commit 18cf5db272
2 changed files with 35 additions and 6 deletions

View file

@ -46,6 +46,11 @@ constexpr static Array<int, 9>
ml_dsa_65_oid { 2, 16, 840, 1, 101, 3, 4, 3, 18 },
ml_dsa_87_oid { 2, 16, 840, 1, 101, 3, 4, 3, 19 };
constexpr static Array<int, 9>
ml_kem_512_oid { 2, 16, 840, 1, 101, 3, 4, 4, 1 },
ml_kem_768_oid { 2, 16, 840, 1, 101, 3, 4, 4, 2 },
ml_kem_1024_oid { 2, 16, 840, 1, 101, 3, 4, 4, 3 };
#define _ENUM(key, value) key,
#define __ENUM_OBJECT_CLASS \

View file

@ -55,7 +55,7 @@ static ErrorOr<AlgorithmIdentifier> parse_algorithm_identifier(ASN1::Decoder& de
READ_OBJECT(ObjectIdentifier, Vector<int>, algorithm);
POP_SCOPE();
constexpr static Array<Span<int const>, 16> known_algorithm_identifiers {
constexpr static Array<Span<int const>, 19> known_algorithm_identifiers {
ASN1::rsa_encryption_oid,
ASN1::rsa_md5_encryption_oid,
ASN1::rsa_sha1_encryption_oid,
@ -71,7 +71,10 @@ static ErrorOr<AlgorithmIdentifier> parse_algorithm_identifier(ASN1::Decoder& de
ASN1::ed448_oid,
ASN1::ml_dsa_44_oid,
ASN1::ml_dsa_65_oid,
ASN1::ml_dsa_87_oid
ASN1::ml_dsa_87_oid,
ASN1::ml_kem_512_oid,
ASN1::ml_kem_768_oid,
ASN1::ml_kem_1024_oid
};
bool is_known_algorithm = false;
@ -134,7 +137,10 @@ static ErrorOr<AlgorithmIdentifier> parse_algorithm_identifier(ASN1::Decoder& de
// https://datatracker.ietf.org/doc/html/rfc9881/#section-2
// The contents of the parameters component for each algorithm MUST be absent.
constexpr static Array<Span<int const>, 12> no_parameter_algorithms = {
// https://datatracker.ietf.org/doc/html/rfc8410#section-9
// For all of the OIDs, the parameters MUST be absent.
constexpr static Array<Span<int const>, 15> no_parameter_algorithms = {
ASN1::ecdsa_with_sha224_encryption_oid,
ASN1::ecdsa_with_sha256_encryption_oid,
ASN1::ecdsa_with_sha384_encryption_oid,
@ -146,6 +152,10 @@ static ErrorOr<AlgorithmIdentifier> parse_algorithm_identifier(ASN1::Decoder& de
ASN1::ml_dsa_44_oid,
ASN1::ml_dsa_65_oid,
ASN1::ml_dsa_87_oid,
ASN1::ed448_oid,
ASN1::ml_kem_512_oid,
ASN1::ml_kem_768_oid,
ASN1::ml_kem_1024_oid
};
bool is_no_parameter_algorithm = false;
@ -238,7 +248,10 @@ ErrorOr<SubjectPublicKey> parse_subject_public_key_info(ASN1::Decoder& decoder,
// https://datatracker.ietf.org/doc/html/rfc9881/#section-2
// The contents of the parameters component for each algorithm MUST be absent.
constexpr static Array<Span<int const>, 8> no_parameter_algorithms = {
// https://datatracker.ietf.org/doc/html/draft-ietf-lamps-kyber-certificates-07#section-3-6
// The parameters field of the AlgorithmIdentifier for the ML-KEM public key MUST be absent.
constexpr static Array<Span<int const>, 12> no_parameter_algorithms = {
ASN1::ec_public_key_encryption_oid,
ASN1::x25519_oid,
ASN1::x448_oid,
@ -247,6 +260,10 @@ ErrorOr<SubjectPublicKey> parse_subject_public_key_info(ASN1::Decoder& decoder,
ASN1::ml_dsa_44_oid,
ASN1::ml_dsa_65_oid,
ASN1::ml_dsa_87_oid,
ASN1::ed448_oid,
ASN1::ml_kem_512_oid,
ASN1::ml_kem_768_oid,
ASN1::ml_kem_1024_oid
};
for (auto const& inner : no_parameter_algorithms) {
@ -344,7 +361,10 @@ ErrorOr<PrivateKey> parse_private_key_info(ASN1::Decoder& decoder, Vector<String
// https://datatracker.ietf.org/doc/html/rfc9881/#section-2
// The contents of the parameters component for each algorithm MUST be absent.
constexpr static Array<Span<int const>, 8> no_parameter_algorithms = {
// https://datatracker.ietf.org/doc/html/draft-ietf-lamps-kyber-certificates-07#section-3-6
// The parameters field of the AlgorithmIdentifier for the ML-KEM public key MUST be absent.
constexpr static Array<Span<int const>, 12> no_parameter_algorithms = {
ASN1::ec_public_key_encryption_oid,
ASN1::x25519_oid,
ASN1::x448_oid,
@ -352,7 +372,11 @@ ErrorOr<PrivateKey> parse_private_key_info(ASN1::Decoder& decoder, Vector<String
ASN1::ed448_oid,
ASN1::ml_dsa_44_oid,
ASN1::ml_dsa_65_oid,
ASN1::ml_dsa_87_oid
ASN1::ml_dsa_87_oid,
ASN1::ed448_oid,
ASN1::ml_kem_512_oid,
ASN1::ml_kem_768_oid,
ASN1::ml_kem_1024_oid
};
for (auto const& inner : no_parameter_algorithms) {