Implement SHA-3 support for node crypto#6680
Conversation
There was a problem hiding this comment.
I'm Bonk, and I've done a quick review of your PR.
This PR adds SHA-3 hash and HMAC support to node:crypto via RustCrypto crates through the existing CXX bridge, cleanly routing only SHA-3 algorithm names through Rust while preserving existing BoringSSL paths.
Issues (ranked by severity):
- [LOW] The
getHashes()comment says "hashes supported in BoringSSL" but SHA-3 hashes are now backed by RustCrypto, not BoringSSL. The comment should be updated. - [LOW] The
INT_MAXchecks on the Rust SHA-3update()paths are unnecessary — Rust&[u8]slices accept anyusizelength, and the Keccak sponge has no inherent input length limit. The checks are harmless but asymmetric with the Rust side's actual constraints. Not blocking.
This review was generated by an AI assistant and may contain inaccuracies.
| @@ -190,9 +190,9 @@ export function getHashes(): string[] { | |||
| // expected to change infrequently based of bssl's stability-focused approach. | |||
There was a problem hiding this comment.
[LOW] This comment is now inaccurate — SHA-3 hashes are backed by RustCrypto, not BoringSSL.
| // expected to change infrequently based of bssl's stability-focused approach. | |
| // Hardcoded list of supported hashes. Most are backed by BoringSSL; sha3-* variants use | |
| // RustCrypto via the Rust CXX bridge since BoringSSL does not expose SHA-3 EVP digests. |
|
Review posted successfully on PR #6680. Here's a summary of the review: Findings:
What looked good (not mentioned in the review per tone guidelines):
|
Summary
sha3-224,sha3-256,sha3-384, andsha3-512support fornode:cryptohashes andcreateHmac().sha3crate through the existing Rust CXX bridge because BoringSSL does not provide SHA-3 EVP digests.crypto.getHashes()and covers streaming, one-shot, case-insensitive names, copy, and HMAC behavior in node crypto tests.Implementation
src/rust/api/lib.rs.HashContextandHmacContext; existing BoringSSL-backed algorithms continue using EVP/HMAC.Hash.copy()by cloning RustCrypto hash state before finalization.digest()behavior by caching the finalized JS-visible digest in the existing context state.Dependency Security View
sha3andhmac, which are widely used Rust cryptography implementations maintained under the RustCrypto organization.sha3implements the standardized FIPS 202 SHA-3 family and depends on the RustCryptokeccakpermutation implementation.Tests
bazel build //src/rust/api //src/workerd/api/node:nodebazel test //src/workerd/api/node/tests:crypto_hash-test@ //src/workerd/api/node/tests:crypto_hmac-test@ --nocache_test_resultsbazel test //src/rust/... --nocache_test_resultsbazel test //src/workerd/api/node/tests:crypto_hash-test@ //src/workerd/api/node/tests:crypto_hash-test@all-compat-flags //src/workerd/api/node/tests:crypto_hash-test@all-autogates //src/workerd/api/node/tests:crypto_hmac-test@ //src/workerd/api/node/tests:crypto_hmac-test@all-compat-flags //src/workerd/api/node/tests:crypto_hmac-test@all-autogates --nocache_test_resultsjust format