implement a subset of "Modern Algorithms in the Web Cryptography API"#6403
implement a subset of "Modern Algorithms in the Web Cryptography API"#6403panva wants to merge 2 commits into
Conversation
|
/bigbonk review this pull-request. make sure everything aligns with Node.js. roast this pr as much as you can. |
There was a problem hiding this comment.
Review Summary
Substantial PR implementing a subset of the "Modern Algorithms in the Web Cryptography API" spec. The implementation is well-structured with good use of C++ templates for the ML-KEM/ML-DSA parameter dispatch. Key findings:
- Compat flag gating: These new algorithms and APIs (ML-KEM, ML-DSA, ChaCha20-Poly1305, SHA-3, encapsulate/decapsulate/getPublicKey) are unconditionally available with no compat flag or autogate. Given the project's strong backward compatibility commitment and the fact that these APIs add new methods to
SubtleCryptoplus new key usage strings, this should be gated behind a compat flag. - Dead code allocation in
mldsa.c++:importSpkithat unnecessarily allocates a buffer that is immediately shadowed. raw-privateformat is accepted inimportKeySyncbut never handled by any algorithm — potential developer confusion.DigestStreamgap: SHA-3/TurboSHAKE/cSHAKE are not supported in the streamingDigestStream— onlysubtle.digest(). May be acceptable as a known limitation.outputLengthfor cSHAKE allows 0: The cSHAKE path acceptsoutputLength >= 0(allowing 0) while TurboSHAKE requires> 0. Deliberate or inconsistency?- Minor style nits on variable naming and an unnecessary
_kjcsuffix.
This review was generated by an AI assistant and may contain inaccuracies.
|
Review posted successfully. Here's a summary of what I flagged: Key findings posted as inline comments:
|
|
@anonrig will update the WPTs separately and then i'll rebase this on top to just get the diff in WPTs related to these changes. |
This comment has been minimized.
This comment has been minimized.
|
/bigbonk roast this pr |
There was a problem hiding this comment.
Review Summary
- ML-KEM/ML-DSA seed not wiped on destroy: Private key seeds stored as plain
kj::Array<kj::byte>instead ofZeroOnFree— secret key material left in memory after key destruction. getPublicKeyspec ordering: Algorithm-support check should precede the key-type check per the spec.- Missing
jsgGetMemoryInfoin ML-KEM/ML-DSA: These key classes tracksizeof(Self)but don't report heap-allocated seed/publicKeyBytes. - XOF
outputLengthhas no upper bound: User-controlledoutputLengthon TurboSHAKE/cSHAKE could allocate unbounded memory. - Nit:
_kjcsuffix on string literal in ChaCha20 code. - TS_OVERRIDE gap: New methods not included in the
JSG_TS_OVERRIDEblock. - Nit: Dead
spki2/algId2/cbb2variable naming in ML-DSAexportSpki.
This review was generated by an AI assistant and may contain inaccuracies.
|
Review posted successfully. Here's a summary of what I flagged across 8 inline comments:
|
83a98f5 to
6a5af36
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6403 +/- ##
==========================================
- Coverage 70.71% 70.00% -0.72%
==========================================
Files 427 431 +4
Lines 117262 119074 +1812
Branches 18903 19193 +290
==========================================
+ Hits 82918 83353 +435
- Misses 23093 24455 +1362
- Partials 11251 11266 +15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jasnell
left a comment
There was a problem hiding this comment.
LGTM but I'm going to ask someone from our crypto team to take a look as well.
|
@bwesterb ... any chance we can get a crypto/security review on this? |
In that case I'll hand it over to you folk. You're better suited to push this across the line for workerd than I am. I don't think this is a lot to take in given it's mostly wiring. And I would hate if by the virtue of splitting this things get missed. |
|
ping @jasnell |
|
@panva ... I'll follow up with the crypto team to see if they've had a chance to review. |
|
I might take a pass through to tweak a few minor things before landing... specifically, there are a few uses of memcpy where using the kj::ArrayPtr copyFrom would be a bit safer, etc. All just basic cleanup stuff, nothing critical that I can see. |
|
rebased to resolve conflicts |
|
Before I can land this I'll need to get an internal PR opened that adds the new rust dependency in that environment. Otherwise it's ready to go |
|
@panva ... any chance you can grant me permissions to modify this branch? there are a few smaller edits and I think we might go with a different rust sha3 impl but I need to experiment a bit with it first. |
|
Alternatively I can pull these commits into a new local branch and work from there... whichever you prefer |
|
Edits by maintainers are/were allowed. Go at it! I'm hands off from this point on. |
|
Just fyi... planning on getting this merged but we're going to need to replace the dependency used. On my list of things to get to in the next few weeks but I've had a few higher priority items I've needed to focus on . |
👍 in the meantime i'm also adding JWK support for ML-KEM (also landed in node) and the Updated WPTs from upstream would be nice too but that would have to come from your end to rebase upon, can also be dealt with after merging. |
Co-authored-by: GitHub Copilot <copilot@github.com>
|
@jasnell which dependency you want to change to? I can see if it's an easy switch |
|
aws-lc |
Farewell |
|
Yeah, there are some limitations there :-/ |
aws-lc-sys is needed for the SHAKE XOF, i assume that's ok. |
Refs: #3642
From https://wicg.github.io/webcrypto-modern-algos/ this implements:
TurboSHAKE (128, 256)Tested using existing WPTs as well as using the https://github.com/panva/hpke and https://github.com/panva/jose test suites.
For SHA3, TurboSHAKE, and cSHAKE I added the sha3 crate, everything else goes through BoringSSL.These are all available in Node.js too.
Co-authored-by: GitHub Copilot copilot@github.com