Skip to content

Conversation

meisterluk
Copy link

@meisterluk meisterluk commented Jul 2, 2025

Content:

  • add dependency to pkcs8 crate and define features pkcs8 & alloc
  • implement AssociatedOid and AssociatedAlgorithmIdentifier for ML-KEM parameter sets {MlKem512Params,MlKem768Params,MlKem1024Params}
  • implement AssociatedAlgorithmIdentifier for EncapsulationKey & DecapsulationKey
  • serialization:
    implement EncodePublicKey for EncapsulationKey
    implement EncodePrivateKey for DecapsulationKey
  • deserialization:
    implement TryFrom<pkcs8::SubjectPublicKeyInfoRef> for EncapsulationKey
    implement TryFrom<pkcs8::PrivateKeyInfo> for DecapsulationKey
  • add testcase with DER serialization roundtrip

Remark:
A dependency const-oid would be resolved to const-oid v0.9.6, because der v0.7.10 includes const-oid v0.9.6. Recognize that const-oid v0.9.6 does not yet support FIPS 203 which features the ML-KEM OIDs. Recognize that an additional const-oid v0.10 dependency would be incompatible with the ObjectIdentifier of const-oid v0.9.6.

In short, if the entire stack moves to const-oid v0.10, we can use it in this crate too.

But as of now, we cannot use fips203 through const-oid and thus the OIDs are contained explicitly.

Remark:
The encapsulation key is serialized into a Subject Public Key Info as defined in RFC 5280 § 4.1.2.7 or more specifically for ML-KEM, draft-ietf-lamps-kyber-certificates-latest from 2025-05-27 § 4: https://lamps-wg.github.io/kyber-certificates/draft-ietf-lamps-kyber-certificates.html#name-subject-public-key-fields

The decapsulation key is serialized into a Private Key Info as defined in RFC 5958 § 2 or more specifically for ML-KEM, draft-ietf-lamps-kyber-certificates-latest from 2025-05-27 § 6: https://lamps-wg.github.io/kyber-certificates/draft-ietf-lamps-kyber-certificates.html#name-private-key-format

Implementation was paid for by our company fragmentiX, because we have the usecase internally as well. Many thanks! And also to my colleague for the helpful remarks.

Solves issue #54

• add dependency to pkcs8 crate and define features pkcs8 & alloc
• implement AssociatedOid and AssociatedAlgorithmIdentifier
  for ML-KEM parameter sets {MlKem512Params,MlKem768Params,MlKem1024Params}
• implement AssociatedAlgorithmIdentifier
  for EncapsulationKey & DecapsulationKey
• serialization:
  implement EncodePublicKey for EncapsulationKey
  implement EncodePrivateKey for DecapsulationKey
• deserialization:
  implement TryFrom<pkcs8::SubjectPublicKeyInfoRef> for EncapsulationKey
  implement TryFrom<pkcs8::PrivateKeyInfo> for DecapsulationKey
• add testcase with DER serialization roundtrip

REMARK:
A dependency const-oid would be resolved to const-oid v0.9.6,
because der v0.7.10 includes const-oid v0.9.6. Recognize that
const-oid v0.9.6 does not yet support FIPS 203 which features
the ML-KEM OIDs. Recognize that an additional const-oid v0.10
dependency would be incompatible with the ObjectIdentifier of
const-oid v0.9.6.

In short, if the entire stack moves to const-oid v0.10,
we can use it in this crate too.

But as of now, we cannot use fips203 through const-oid
and thus the OIDs are contained explicitly.

REMARK:
The encapsulation key is serialized into a Subject Public Key Info
as defined in RFC 5280 § 4.1.2.7 or more specifically for ML-KEM,
draft-ietf-lamps-kyber-certificates-latest from 2025-05-27 § 4:
https://lamps-wg.github.io/kyber-certificates/draft-ietf-lamps-kyber-certificates.html#name-subject-public-key-fields

The decapsulation key is serialized into a Private Key Info
as defined in RFC 5958 § 2 or more specifically for ML-KEM,
draft-ietf-lamps-kyber-certificates-latest from 2025-05-27 § 6:
https://lamps-wg.github.io/kyber-certificates/draft-ietf-lamps-kyber-certificates.html#name-private-key-format
@meisterluk meisterluk force-pushed the meisterluk/mlkem-pkcs8 branch from 53829e8 to 788ac73 Compare July 2, 2025 15:16
@meisterluk meisterluk changed the title ml-kem: implement PKCS#8 serialization; includes testcase ml-kem: implement PKCS#8 serialization for pkcs8 0.10 Jul 2, 2025
@tarcieri
Copy link
Member

tarcieri commented Jul 3, 2025

Closing in favor of #124

@tarcieri tarcieri closed this Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants