Expand description
RFC 9881 standard ASN.1 DER and PEM codecs for ML-DSA-44, ML-DSA-65, and ML-DSA-87
SubjectPublicKeyInfo (SPKI) and PKCS#8 (OneAsymmetricKey / PrivateKeyInfo).
§Official NIST CSOR OIDs (RFC 9881)
ML-DSA-44:2.16.840.1.101.3.4.3.17(06 09 60 86 48 01 65 03 04 03 11)ML-DSA-65:2.16.840.1.101.3.4.3.18(06 09 60 86 48 01 65 03 04 03 12)ML-DSA-87:2.16.840.1.101.3.4.3.19(06 09 60 86 48 01 65 03 04 03 13)
Per RFC 9881:
AlgorithmIdentifier.parametersMUST be absent (noNULL).PKCS#8private keys support all three ASN.1CHOICErepresentations:seed([0] IMPLICIT OCTET STRING, tag0x80, 32-bytexi, RFC 9881 recommended)expandedKey(OCTET STRING, tag0x04, 2560 / 4032 / 4896 bytes)both(SEQUENCE { OCTET STRING (32), OCTET STRING (expanded) }, tag0x30) — validated by recomputingKeyGen_internal(seed)and checking byte-for-byte equality in constant time.
PKCS#8decoding strictly enforces RFC 5958OneAsymmetricKey:version0 MUST omit[1] publicKey, andversion1 MUST include[1] publicKey. Forseedandbothit must equal the key derived from the seed. ForexpandedKeyit must match therhoandtrstored in the private key (an expanded key carries no seed to re-derivet1from). Well-formed[0] attributesare accepted and ignored. Encoders emitversion0 without a public key.- Secret intermediates are held in zeroize-on-drop buffers, and private-key PEM uses constant-time base64.
Functions§
- decode_
pkcs8_ der - Decodes an RFC 9881 PKCS#8 DER private key supporting
seed(0x80),expandedKey(0x04), andboth(0x30, with mandatory constant-time seed consistency check). - decode_
pkcs8_ pem - Decodes an RFC 9881 PEM private key (
-----BEGIN PRIVATE KEY-----). - decode_
spki_ der - Decodes an RFC 9881 SPKI DER verifying key while enforcing
policy. - decode_
spki_ pem - Decodes an RFC 9881 PEM verifying key (
-----BEGIN PUBLIC KEY-----). - encode_
pkcs8_ both_ der - Encodes both the 32-byte seed
xiand expanded key into RFC 9881 PKCS#8 DER (bothtag0x30). - encode_
pkcs8_ expanded_ der - Encodes an expanded ML-DSA signing key into RFC 9881 PKCS#8 DER (
expandedKeytag0x04). - encode_
pkcs8_ seed_ der - Encodes an ML-DSA 32-byte seed
xiinto RFC 9881 PKCS#8 DER (seedCHOICE tag0x80). - encode_
pkcs8_ seed_ pem - Encodes an ML-DSA 32-byte seed into RFC 9881 PEM (
-----BEGIN PRIVATE KEY-----). - encode_
spki_ der - Encodes an ML-DSA verifying key into RFC 9881 SPKI DER (
SubjectPublicKeyInfo). - encode_
spki_ pem - Encodes an ML-DSA verifying key into RFC 9881 PEM (
-----BEGIN PUBLIC KEY-----).