Skip to main content

Module rfc9881

Module rfc9881 

Source
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.parameters MUST be absent (no NULL).
  • PKCS#8 private keys support all three ASN.1 CHOICE representations:
    • seed ([0] IMPLICIT OCTET STRING, tag 0x80, 32-byte xi, RFC 9881 recommended)
    • expandedKey (OCTET STRING, tag 0x04, 2560 / 4032 / 4896 bytes)
    • both (SEQUENCE { OCTET STRING (32), OCTET STRING (expanded) }, tag 0x30) — validated by recomputing KeyGen_internal(seed) and checking byte-for-byte equality in constant time.
  • PKCS#8 decoding strictly enforces RFC 5958 OneAsymmetricKey: version 0 MUST omit [1] publicKey, and version 1 MUST include [1] publicKey. For seed and both it must equal the key derived from the seed. For expandedKey it must match the rho and tr stored in the private key (an expanded key carries no seed to re-derive t1 from). Well-formed [0] attributes are accepted and ignored. Encoders emit version 0 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), and both (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 xi and expanded key into RFC 9881 PKCS#8 DER (both tag 0x30).
encode_pkcs8_expanded_der
Encodes an expanded ML-DSA signing key into RFC 9881 PKCS#8 DER (expandedKey tag 0x04).
encode_pkcs8_seed_der
Encodes an ML-DSA 32-byte seed xi into RFC 9881 PKCS#8 DER (seed CHOICE tag 0x80).
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-----).