crypto: add TurboSHAKE and KangarooTwelve Web Cryptography algorithms#62183
crypto: add TurboSHAKE and KangarooTwelve Web Cryptography algorithms#62183panva wants to merge 5 commits intonodejs:mainfrom
Conversation
|
Review requested:
|
4afe257 to
a9f6b32
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
| namespace { | ||
|
|
||
| inline uint64_t ROL64(uint64_t val, int offset) { | ||
| if (offset == 0) return val; |
There was a problem hiding this comment.
This will fix an undefined behavior.
| if (offset == 0) return val; | |
| if (offset <= 0) return val; |
There was a problem hiding this comment.
The offset values come from the static rhotates table which only contains values 0–62, so this can never happen in practice.
| if (offset == 0) return val; | ||
| return (val << offset) | (val >> (64 - offset)); |
There was a problem hiding this comment.
| if (offset == 0) return val; | |
| return (val << offset) | (val >> (64 - offset)); | |
| offset &= 63; // reduce to [0, 63] | |
| if (offset == 0) return val; | |
| return (val << offset) | (val >> (64 - offset)); | |
| } |
There was a problem hiding this comment.
Same, the offsets are fixed values in the range of 0..62
| // Load/store 64-bit lanes in little-endian byte order. | ||
| // The Keccak state uses LE lane encoding (FIPS 202 Section 1, B.1). | ||
| // These helpers ensure correctness on both LE and BE platforms. | ||
| inline uint64_t LoadLE64(const uint8_t* src) { |
There was a problem hiding this comment.
You need to have an assert somewhere making sure that src has size at least 8.
There was a problem hiding this comment.
These helpers are only called on the internal 200-byte Keccak state and fixed-size padding buffers. Same pattern as OpenSSL's keccak1600.c they're adapted from.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62183 +/- ##
==========================================
- Coverage 89.65% 89.64% -0.01%
==========================================
Files 676 678 +2
Lines 206546 206984 +438
Branches 39558 39632 +74
==========================================
+ Hits 185179 185553 +374
- Misses 13485 13516 +31
- Partials 7882 7915 +33
🚀 New features to boost your workflow:
|
Adds RFC 9861 - KangarooTwelve and TurboSHAKE digest algorithm to Web Cryptography API per WICG/webcrypto-modern-algos#41 using adapted OpenSSL's keccak1600 implementation, to be replaced when OpenSSL supports them natively at which point we'd also make them available in stable
node:crypto.Refs: https://wicg.github.io/webcrypto-modern-algos/#kangarootwelve
Refs: https://wicg.github.io/webcrypto-modern-algos/#turboshake
Refs: https://www.rfc-editor.org/rfc/rfc9861.html
Refs: https://redirect.github.com/openssl/openssl/issues/30304
The tests for the implementation use both test vectors from the RFC as well as ones generated using PyCryptodome