Skip to content

script: Implement WebCrypto encapsulation and decapsulation with ML-KEM#41617

Merged
TimvdLippe merged 3 commits intoservo:mainfrom
kkoyung:ml-kem-encap-decap
Jan 1, 2026
Merged

script: Implement WebCrypto encapsulation and decapsulation with ML-KEM#41617
TimvdLippe merged 3 commits intoservo:mainfrom
kkoyung:ml-kem-encap-decap

Conversation

Continue on adding ML-KEM support to WebCrypto API. Specification:
https://wicg.github.io/webcrypto-modern-algos/#ml-kem

This patch implements encapsulate and decapsulate operations of ML-KEM,
with `ml-kem` crate.

Note that these two operations are not currently in use. They are
intended for the upcoming `SubtleCrypto.encapsulateKey`,
`SubtleCrypto.encapsulateBits`, `SubtleCrypto.decapsulateKey`, and
`SubtleCrypto.decapsulateBits`` methods, which have not yet been
implemented. This patch prepares usable encapsulation and decapsulation
operations of ML-KEM to support those new methods when they are added.

Testing: No behavioral change.
Fixes: Part of 41473

Signed-off-by: Kingsley Yung <[email protected]>
@kkoyung kkoyung requested a review from gterzian as a code owner January 1, 2026 11:15
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jan 1, 2026
@TimvdLippe
Copy link
Copy Markdown
Contributor

Can you add a second commit that introduces the usages of these methods? That way we have test coverage. Otherwise it's only dead code and might drift from expectations in the future.

@kkoyung
Copy link
Copy Markdown
Member Author

kkoyung commented Jan 1, 2026

Sure. I can bring in the implementation of SubtleCrypto.encapsulateBits and SubtleCrypto.decapsulateBits methods to this PR so that WPT can test the code.

I also have the implementation of SubtleCrypto.encapsulateKey and SubtleCrypto.decapsulateKey methods in hand, which could also be added to this PR. However, this would make the PR slightly larger (~250 lines for the former two methods, ~320 lines for the latter methods). Do you prefer them all to be in this PR, or to put the latter two methods in a separate PR?

@TimvdLippe
Copy link
Copy Markdown
Contributor

Let's put that in two separate commits, but in the same PR. That way I can review them separately, but we can test them in combination

This patch implements `SubtleCrypto.encapsulateBits` and
`SubtleCrypto.decapsulateBits` of WebCrypto.

Specification of `SubtleCrypto.encapsulateBits`:
https://wicg.github.io/webcrypto-modern-algos/#SubtleCrypto-method-encapsulateBits
Specification of `SubtleCrypto.decapsulateBits`:
https://wicg.github.io/webcrypto-modern-algos/#SubtleCrypto-method-decapsulateBits

Since we have implemented the "encapsulate" and "decapsulate" operations
of ML-KEM, the `encapsulateBits` and `decapsulateBits` methods can call
them to encapsulate and decapsulate bits using ML-KEM algorithm.

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of 41473

Signed-off-by: Kingsley Yung <[email protected]>
This patch implements `SubtleCrypto.encapsulateKey` and
`SubtleCrypto.decapsulateKey` of WebCrypto.

Specification of `SubtleCrypto.encapsulateKey`:
https://wicg.github.io/webcrypto-modern-algos/#SubtleCrypto-method-encapsulateKey
Specification of `SubtleCrypto.decapsulateKey`:
https://wicg.github.io/webcrypto-modern-algos/#SubtleCrypto-method-decapsulateKey

Since we have implemented the "encapsulate" and "decapsulate" operations
of ML-KEM, the `encapsulateKey` and `decapsulateKey` methods can call
them to encapsulate and decapsulate key using ML-KEM algorithm.

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of 41473

Signed-off-by: Kingsley Yung <[email protected]>
@kkoyung kkoyung changed the title script: Implement encapsulate and decapsulate operations of ML-KEM script: Implement WebCrypto encapsulation and decapsulation with ML-KEM Jan 1, 2026
Copy link
Copy Markdown
Contributor

@TimvdLippe TimvdLippe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Jan 1, 2026
@TimvdLippe TimvdLippe added this pull request to the merge queue Jan 1, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jan 1, 2026
Merged via the queue into servo:main with commit 96ddb0b Jan 1, 2026
30 checks passed
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jan 1, 2026
@kkoyung kkoyung deleted the ml-kem-encap-decap branch January 9, 2026 05:48
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.

3 participants