Skip to content

Commit 9d498e6

Browse files
committed
Add ML-DSA SPKI/PKCS#8 DER support to d2i_PUBKEY and d2i_PrivateKey.
1 parent 5151a69 commit 9d498e6

9 files changed

Lines changed: 3506 additions & 84 deletions

File tree

certs/mldsa/README.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ML-DSA (FIPS 204) test key material for wolfSSL tests.
2+
3+
File variants, per level N in {44, 65, 87}:
4+
mldsa<N>_bare-seed.der raw 32-byte seed
5+
mldsa<N>_seed-only.der PKCS#8 with seed-only private key
6+
mldsa<N>_bare-priv.der raw expanded private key
7+
mldsa<N>_priv-only.der PKCS#8 with expanded-only private key
8+
mldsa<N>_seed-priv.der PKCS#8 with seed-and-expanded private key
9+
mldsa<N>_oqskeypair.der liboqs concatenated (priv || pub) format
10+
mldsa<N>_pub-spki.der SubjectPublicKeyInfo wrapping the public key
11+
12+
The *_pub-spki.der files were derived from the matching *_priv-only.der files
13+
using OpenSSL 3.5+:
14+
15+
openssl pkey -inform DER -in mldsa<N>_priv-only.der \
16+
-pubout -outform DER -out mldsa<N>_pub-spki.der
17+
18+
Regenerating the private-key variants requires producing each of the
19+
PKCS#8 shape options explicitly; OpenSSL's default output is the
20+
seed-and-expanded form.

certs/mldsa/include.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33
#
44

55
EXTRA_DIST += \
6+
certs/mldsa/README.txt \
67
certs/mldsa/mldsa44_seed-only.der \
78
certs/mldsa/mldsa44_priv-only.der \
9+
certs/mldsa/mldsa44_pub-spki.der \
810
certs/mldsa/mldsa44_seed-priv.der \
911
certs/mldsa/mldsa44_oqskeypair.der \
1012
certs/mldsa/mldsa44_bare-seed.der \
1113
certs/mldsa/mldsa44_bare-priv.der \
1214
certs/mldsa/mldsa65_seed-only.der \
1315
certs/mldsa/mldsa65_priv-only.der \
16+
certs/mldsa/mldsa65_pub-spki.der \
1417
certs/mldsa/mldsa65_seed-priv.der \
1518
certs/mldsa/mldsa65_oqskeypair.der \
1619
certs/mldsa/mldsa65_bare-seed.der \
1720
certs/mldsa/mldsa65_bare-priv.der \
1821
certs/mldsa/mldsa87_seed-only.der \
1922
certs/mldsa/mldsa87_priv-only.der \
23+
certs/mldsa/mldsa87_pub-spki.der \
2024
certs/mldsa/mldsa87_seed-priv.der \
2125
certs/mldsa/mldsa87_oqskeypair.der \
2226
certs/mldsa/mldsa87_bare-seed.der \

certs/mldsa/mldsa44_pub-spki.der

1.3 KB
Binary file not shown.

certs/mldsa/mldsa65_pub-spki.der

1.93 KB
Binary file not shown.

certs/mldsa/mldsa87_pub-spki.der

2.55 KB
Binary file not shown.

gencertbuf.pl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,6 +2094,51 @@
20942094
20952095
";
20962096

2097+
# ML-DSA test key material encoded per the IETF LAMPS WG profile:
2098+
# SubjectPublicKeyInfo for public keys, PKCS#8 PrivateKeyInfo for
2099+
# private keys, using the NIST id-ml-dsa-N OIDs.
2100+
print OUT_FILE "#if defined(HAVE_DILITHIUM)\n\n";
2101+
2102+
for my $L ( [44,"WOLFSSL_NO_ML_DSA_44"],
2103+
[65,"WOLFSSL_NO_ML_DSA_65"],
2104+
[87,"WOLFSSL_NO_ML_DSA_87"] ) {
2105+
my ($n, $noLevel) = @$L;
2106+
2107+
print OUT_FILE "#if !defined($noLevel)\n\n";
2108+
2109+
print OUT_FILE "#ifndef WOLFSSL_DILITHIUM_NO_VERIFY\n";
2110+
print OUT_FILE "/* ./certs/mldsa/mldsa${n}_pub-spki.der */\n";
2111+
print OUT_FILE "static const unsigned char mldsa${n}_pub_spki[] =\n{\n";
2112+
file_to_hex("./certs/mldsa/mldsa${n}_pub-spki.der");
2113+
print OUT_FILE "};\n";
2114+
print OUT_FILE "#define sizeof_mldsa${n}_pub_spki (sizeof(mldsa${n}_pub_spki))\n";
2115+
print OUT_FILE "#endif /* !WOLFSSL_DILITHIUM_NO_VERIFY */\n\n";
2116+
2117+
print OUT_FILE "#ifndef WOLFSSL_DILITHIUM_NO_SIGN\n";
2118+
print OUT_FILE "/* ./certs/mldsa/mldsa${n}_priv-only.der */\n";
2119+
print OUT_FILE "static const unsigned char mldsa${n}_priv_only[] =\n{\n";
2120+
file_to_hex("./certs/mldsa/mldsa${n}_priv-only.der");
2121+
print OUT_FILE "};\n";
2122+
print OUT_FILE "#define sizeof_mldsa${n}_priv_only (sizeof(mldsa${n}_priv_only))\n";
2123+
2124+
print OUT_FILE "/* ./certs/mldsa/mldsa${n}_seed-priv.der */\n";
2125+
print OUT_FILE "static const unsigned char mldsa${n}_seed_priv[] =\n{\n";
2126+
file_to_hex("./certs/mldsa/mldsa${n}_seed-priv.der");
2127+
print OUT_FILE "};\n";
2128+
print OUT_FILE "#define sizeof_mldsa${n}_seed_priv (sizeof(mldsa${n}_seed_priv))\n";
2129+
2130+
print OUT_FILE "/* ./certs/mldsa/mldsa${n}_seed-only.der */\n";
2131+
print OUT_FILE "static const unsigned char mldsa${n}_seed_only[] =\n{\n";
2132+
file_to_hex("./certs/mldsa/mldsa${n}_seed-only.der");
2133+
print OUT_FILE "};\n";
2134+
print OUT_FILE "#define sizeof_mldsa${n}_seed_only (sizeof(mldsa${n}_seed_only))\n";
2135+
print OUT_FILE "#endif /* !WOLFSSL_DILITHIUM_NO_SIGN */\n\n";
2136+
2137+
print OUT_FILE "#endif /* !$noLevel */\n\n";
2138+
}
2139+
2140+
print OUT_FILE "#endif /* HAVE_DILITHIUM */\n\n";
2141+
20972142
# convert and print 256-bit cert/keys
20982143
print OUT_FILE "#if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)\n\n";
20992144
for (my $i = 0; $i < $num_ecc; $i++) {

0 commit comments

Comments
 (0)