Skip to main content

Module rfc9935

Module rfc9935 

Source
Expand description

RFC 9935 standard ASN.1 DER and PEM codecs for ML-KEM-512, ML-KEM-768, and ML-KEM-1024 SubjectPublicKeyInfo (SPKI) and PKCS#8 (PrivateKeyInfo).

§Official NIST CSOR OIDs (RFC 9935)

  • ML-KEM-512: 2.16.840.1.101.3.4.4.1 (06 09 60 86 48 01 65 03 04 04 01)
  • ML-KEM-768: 2.16.840.1.101.3.4.4.2 (06 09 60 86 48 01 65 03 04 04 02)
  • ML-KEM-1024: 2.16.840.1.101.3.4.4.3 (06 09 60 86 48 01 65 03 04 04 03)

Per RFC 9935:

  • 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, 64 bytes d || z, RFC 9935 recommended)
    • expandedKey (OCTET STRING, tag 0x04, 1632 / 2400 / 3168 bytes)
    • both (SEQUENCE { OCTET STRING (64), OCTET STRING (expanded) }, tag 0x30)
  • PKCS#8 decoding strictly enforces RFC 5958 OneAsymmetricKey: version 0 MUST omit [1] publicKey, and version 1 MUST include [1] publicKey, which must equal the encapsulation key belonging to the private key. 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 9935 PKCS#8 DER ML-KEM private key (supports all three CHOICE forms: seed [0], expandedKey, and both), enforcing policy and consistency checks.
decode_pkcs8_pem
Decodes an RFC 9935 PEM private key (-----BEGIN PRIVATE KEY-----).
decode_spki_der
Decodes an RFC 9935 SPKI DER public key, enforcing policy and FIPS 203 Section 7.2 checks.
decode_spki_pem
Decodes an RFC 9935 PEM public key (-----BEGIN PUBLIC KEY-----).
encode_pkcs8_expanded_der
Encodes an expanded ML-KEM decapsulation key into RFC 9935 PKCS#8 DER (expandedKey CHOICE tag 0x04).
encode_pkcs8_seed_der
Encodes an ML-KEM 64-byte (d || z) seed into RFC 9935 PKCS#8 DER (seed CHOICE tag 0x80).
encode_pkcs8_seed_pem
Encodes an ML-KEM 64-byte seed into RFC 9935 PEM (-----BEGIN PRIVATE KEY-----).
encode_spki_der
Encodes an ML-KEM public key into RFC 9935 SPKI DER (SubjectPublicKeyInfo).
encode_spki_pem
Encodes an ML-KEM public key into RFC 9935 PEM (-----BEGIN PUBLIC KEY-----).