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.parametersMUST be absent (noNULL).PKCS#8private keys support all three ASN.1CHOICErepresentations:seed([0] IMPLICIT OCTET STRING, tag0x80, 64 bytesd || z, RFC 9935 recommended)expandedKey(OCTET STRING, tag0x04, 1632 / 2400 / 3168 bytes)both(SEQUENCE { OCTET STRING (64), OCTET STRING (expanded) }, tag0x30)
PKCS#8decoding strictly enforces RFC 5958OneAsymmetricKey:version0 MUST omit[1] publicKey, andversion1 MUST include[1] publicKey, which must equal the encapsulation key belonging to the private key. 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 9935 PKCS#8 DER ML-KEM private key (supports all three
CHOICEforms:seed [0],expandedKey, andboth), enforcingpolicyand 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
policyand 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 (
expandedKeyCHOICE tag0x04). - encode_
pkcs8_ seed_ der - Encodes an ML-KEM 64-byte
(d || z)seed into RFC 9935 PKCS#8 DER (seedCHOICE tag0x80). - 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-----).