GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — crypto: avoid repeated OpenSSL lookups by anonrig · Pull Request #67109 · nodejs/node Conversation
|
| Benchmark | Result |
|---|---|
| crypto/create-hmac.js | +4% to +15% for all 12 configs (***), geomean +10.9% |
| crypto/class-construction.js | DiffieHellmanGroup +25%, Hmac +13%, Sign +11%, Verify +11% |
crypto/hkdf.js with sync=1 |
+6% to +11% for 10 and 64 byte outputs |
These were 30 runs each. Nothing else is slower after Holm-Bonferroni correction:
scenario=first-after-generate (-1.5%). Neither reproduced as significant in 30 interleaved runs (-2.4% with z=1.35 and -3.5% with z=1.43, while A/A runs were within 1%).createHash() doesn't run any changed code. Interleaved runs of the createHash configs in webcrypto-digest.js show about -2% (A/A: +0.2%), which I haven't been able to attribute. crypto/create-hash.js and the Hash case of crypto/class-construction.js show no significant change.
test: cover crypto digest and HMAC caches adds two tests:
createHmac() instances with the same digest and different keys, interleaves their updates, and checks each result against the RFC 4231 vectors for SHA-256 and SHA-512.createHmac() is the only one of these operations that would reveal a stale cache entry, because the other ones also need a signature or KDF fetch that fails in FIPS mode. I checked that the test fails when the cache is never invalidated.The existing crypto, webcrypto, WPT webcrypto, async-hooks, TLS and HTTPS tests pass locally, and each commit builds on its own.
This was developed with an AI coding agent (Grok), which also drafted this description.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Review requested:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Please split the inlining from general improvements. I explored this in #63595, including operation-specific thresholds and a guard that sent fanout to the threadpool. The reason I stopped was HTTP server responsiveness. After @mcollina raised that concern, I measured it and found that accounting for responsiveness reduced the viable candidates to non-RSA key generation and symmetric operations, with thresholds below 4 KiB, sometimes 8 KiB, rather than 64 KiB. At that point I didn't think the remaining benefit justified the churn and maintenance burden. Closing comment. The narrower scope and 1 KiB budget here are relevant differences, but crypto throughput alone doesn't establish that the responsiveness concern is resolved. Deferring promise settlement to a microtask still allows serial There's also a specification question. The current A separate synchronous WebCrypto API is being discussed as well. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@ ## main #67109 +/- ## ========================================== + Coverage 90.64% 90.67% +0.02% ========================================== Files 797 797 Lines 278797 278809 +12 Branches 53627 53625 -2 ========================================== + Hits 252717 252799 +82 + Misses 16413 16378 -35 + Partials 9667 9632 -35
🚀 New features to boost your workflow:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Please add regression tests covering:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
createHmac(), createSign(), createVerify() and the synchronous one-shot sign, verify, HKDF and PBKDF2 functions looked up their digest with Digest::FromName(). That returns OpenSSL's legacy EVP_MD, so every EVP_DigestInit_ex() and HMAC init had to fetch the provider implementation again through the method store. Look these digests up through the per-Environment cache that createHash() and crypto.hash() already use. Jobs on the thread pool keep using Digest::FromName(): with the cache, Web Crypto digest and HMAC throughput went down, because workers that finish sooner have to be woken up for each new job more often. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok
ClearErrorOnReturn calls ERR_clear_error() when it is created and again when it goes out of scope. That function resets all 16 slots of the thread's error queue, including two free() calls per slot, even when the queue is empty, which is almost always the case. Check for a queued error first, which costs a fraction of that. ClearErrorOnReturn guards most crypto operations, including every CryptoJob, so this applies to all of them. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok
Every HMAC context was created with EVP_MAC_fetch() and keyed with the digest passed by name, so the provider fetched the digest again on each init. Both lookups go through OpenSSL's method store. Keep an HMAC context without a key for each digest in the per-Environment digest cache, and duplicate it in createHmac(). A duplicated context already has its digest, so keying it with the same digest no longer fetches anything. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok
Check that HMAC instances duplicated from the same cached context stay independent when their updates are interleaved, and that warmed digest and HMAC caches follow FIPS mode changes without breaking an HMAC that is already in progress. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Every HMAC context was created with EVP_MAC_fetch() and keyed with the digest passed by name, so the provider fetched the digest again on each init. Both lookups go through OpenSSL's method store. Keep an HMAC context without a key for each digest in the per-Environment digest cache, and duplicate it in createHmac(). A duplicated context already has its digest, so keying it with the same digest no longer fetches anything. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: #67109 Reviewed-By: Filip Skokan <[email protected]>
Check that HMAC instances duplicated from the same cached context stay independent when their updates are interleaved, and that warmed digest and HMAC caches follow FIPS mode changes without breaking an HMAC that is already in progress. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: #67109 Reviewed-By: Filip Skokan <[email protected]>
createHmac(), createSign(), createVerify() and the synchronous one-shot sign, verify, HKDF and PBKDF2 functions looked up their digest with Digest::FromName(). That returns OpenSSL's legacy EVP_MD, so every EVP_DigestInit_ex() and HMAC init had to fetch the provider implementation again through the method store. Look these digests up through the per-Environment cache that createHash() and crypto.hash() already use. Jobs on the thread pool keep using Digest::FromName(): with the cache, Web Crypto digest and HMAC throughput went down, because workers that finish sooner have to be woken up for each new job more often. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: #67109 Reviewed-By: Filip Skokan <[email protected]>
ClearErrorOnReturn calls ERR_clear_error() when it is created and again when it goes out of scope. That function resets all 16 slots of the thread's error queue, including two free() calls per slot, even when the queue is empty, which is almost always the case. Check for a queued error first, which costs a fraction of that. ClearErrorOnReturn guards most crypto operations, including every CryptoJob, so this applies to all of them. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: #67109 Reviewed-By: Filip Skokan <[email protected]>
Every HMAC context was created with EVP_MAC_fetch() and keyed with the digest passed by name, so the provider fetched the digest again on each init. Both lookups go through OpenSSL's method store. Keep an HMAC context without a key for each digest in the per-Environment digest cache, and duplicate it in createHmac(). A duplicated context already has its digest, so keying it with the same digest no longer fetches anything. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: #67109 Reviewed-By: Filip Skokan <[email protected]>
Check that HMAC instances duplicated from the same cached context stay independent when their updates are interleaved, and that warmed digest and HMAC caches follow FIPS mode changes without breaking an HMAC that is already in progress. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: #67109 Reviewed-By: Filip Skokan <[email protected]>
ClearErrorOnReturn calls ERR_clear_error() when it is created and again when it goes out of scope. That function resets all 16 slots of the thread's error queue, including two free() calls per slot, even when the queue is empty, which is almost always the case. Check for a queued error first, which costs a fraction of that. ClearErrorOnReturn guards most crypto operations, including every CryptoJob, so this applies to all of them. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: #67109 Reviewed-By: Filip Skokan <[email protected]>
Check that HMAC instances duplicated from the same cached context stay independent when their updates are interleaved, and that warmed digest and HMAC caches follow FIPS mode changes without breaking an HMAC that is already in progress. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: #67109 Reviewed-By: Filip Skokan <[email protected]>
ClearErrorOnReturn calls ERR_clear_error() when it is created and again when it goes out of scope. That function resets all 16 slots of the thread's error queue, including two free() calls per slot, even when the queue is empty, which is almost always the case. Check for a queued error first, which costs a fraction of that. ClearErrorOnReturn guards most crypto operations, including every CryptoJob, so this applies to all of them. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: #67109 Reviewed-By: Filip Skokan <[email protected]>
Check that HMAC instances duplicated from the same cached context stay independent when their updates are interleaved, and that warmed digest and HMAC caches follow FIPS mode changes without breaking an HMAC that is already in progress. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: #67109 Reviewed-By: Filip Skokan <[email protected]>
createHmac(), createSign(), createVerify() and the synchronous one-shot sign, verify, HKDF and PBKDF2 functions looked up their digest with Digest::FromName(). That returns OpenSSL's legacy EVP_MD, so every EVP_DigestInit_ex() and HMAC init had to fetch the provider implementation again through the method store. Look these digests up through the per-Environment cache that createHash() and crypto.hash() already use. Jobs on the thread pool keep using Digest::FromName(): with the cache, Web Crypto digest and HMAC throughput went down, because workers that finish sooner have to be woken up for each new job more often. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: nodejs#67109 Reviewed-By: Filip Skokan <[email protected]>
Every HMAC context was created with EVP_MAC_fetch() and keyed with the digest passed by name, so the provider fetched the digest again on each init. Both lookups go through OpenSSL's method store. Keep an HMAC context without a key for each digest in the per-Environment digest cache, and duplicate it in createHmac(). A duplicated context already has its digest, so keying it with the same digest no longer fetches anything. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: nodejs#67109 Reviewed-By: Filip Skokan <[email protected]>
createHmac(), createSign(), createVerify() and the synchronous one-shot sign, verify, HKDF and PBKDF2 functions looked up their digest with Digest::FromName(). That returns OpenSSL's legacy EVP_MD, so every EVP_DigestInit_ex() and HMAC init had to fetch the provider implementation again through the method store. Look these digests up through the per-Environment cache that createHash() and crypto.hash() already use. Jobs on the thread pool keep using Digest::FromName(): with the cache, Web Crypto digest and HMAC throughput went down, because workers that finish sooner have to be woken up for each new job more often. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: #67109 Backport-PR-URL: #67442 Reviewed-By: Antoine du Hamel <[email protected]>
Every HMAC context was created with EVP_MAC_fetch() and keyed with the digest passed by name, so the provider fetched the digest again on each init. Both lookups go through OpenSSL's method store. Keep an HMAC context without a key for each digest in the per-Environment digest cache, and duplicate it in createHmac(). A duplicated context already has its digest, so keying it with the same digest no longer fetches anything. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: #67109 Backport-PR-URL: #67442 Reviewed-By: Antoine du Hamel <[email protected]>
ClearErrorOnReturn calls ERR_clear_error() when it is created and again when it goes out of scope. That function resets all 16 slots of the thread's error queue, including two free() calls per slot, even when the queue is empty, which is almost always the case. Check for a queued error first, which costs a fraction of that. ClearErrorOnReturn guards most crypto operations, including every CryptoJob, so this applies to all of them. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: #67109 Reviewed-By: Filip Skokan <[email protected]>
ClearErrorOnReturn calls ERR_clear_error() when it is created and again when it goes out of scope. That function resets all 16 slots of the thread's error queue, including two free() calls per slot, even when the queue is empty, which is almost always the case. Check for a queued error first, which costs a fraction of that. ClearErrorOnReturn guards most crypto operations, including every CryptoJob, so this applies to all of them. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: nodejs#67109 Reviewed-By: Filip Skokan <[email protected]>
createHmac(), createSign(), createVerify() and the synchronous one-shot sign, verify, HKDF and PBKDF2 functions looked up their digest with Digest::FromName(). That returns OpenSSL's legacy EVP_MD, so every EVP_DigestInit_ex() and HMAC init had to fetch the provider implementation again through the method store. Look these digests up through the per-Environment cache that createHash() and crypto.hash() already use. Jobs on the thread pool keep using Digest::FromName(): with the cache, Web Crypto digest and HMAC throughput went down, because workers that finish sooner have to be woken up for each new job more often. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: nodejs#67109 Reviewed-By: Filip Skokan <[email protected]>
ClearErrorOnReturn calls ERR_clear_error() when it is created and again when it goes out of scope. That function resets all 16 slots of the thread's error queue, including two free() calls per slot, even when the queue is empty, which is almost always the case. Check for a queued error first, which costs a fraction of that. ClearErrorOnReturn guards most crypto operations, including every CryptoJob, so this applies to all of them. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: nodejs#67109 Reviewed-By: Filip Skokan <[email protected]>
Every HMAC context was created with EVP_MAC_fetch() and keyed with the digest passed by name, so the provider fetched the digest again on each init. Both lookups go through OpenSSL's method store. Keep an HMAC context without a key for each digest in the per-Environment digest cache, and duplicate it in createHmac(). A duplicated context already has its digest, so keying it with the same digest no longer fetches anything. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: nodejs#67109 Reviewed-By: Filip Skokan <[email protected]>
Check that HMAC instances duplicated from the same cached context stay independent when their updates are interleaved, and that warmed digest and HMAC caches follow FIPS mode changes without breaking an HMAC that is already in progress. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Grok PR-URL: nodejs#67109 Reviewed-By: Filip Skokan <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.