Title: crypto: scrypt with params over maxmem leaves an OpenSSL error queued; the next createPrivateKey fails · Issue #66668 · nodejs/node · GitHub
Open Graph Title: crypto: scrypt with params over maxmem leaves an OpenSSL error queued; the next createPrivateKey fails · Issue #66668 · nodejs/node
X Title: crypto: scrypt with params over maxmem leaves an OpenSSL error queued; the next createPrivateKey fails · Issue #66668 · nodejs/node
Description: Version v24.13.0 (OpenSSL 3.5.4) Platform Windows 11 x64 (10.0.22631). Not yet checked on Linux/macOS. Subsystem crypto What steps will reproduce the bug? import crypto from "node:crypto"; const { privateKey } = crypto.generateKeyPairSyn...
Open Graph Description: Version v24.13.0 (OpenSSL 3.5.4) Platform Windows 11 x64 (10.0.22631). Not yet checked on Linux/macOS. Subsystem crypto What steps will reproduce the bug? import crypto from "node:crypto"; const { ...
X Description: Version v24.13.0 (OpenSSL 3.5.4) Platform Windows 11 x64 (10.0.22631). Not yet checked on Linux/macOS. Subsystem crypto What steps will reproduce the bug? import crypto from "node:crypto"...
Opengraph URL: https://github.com/nodejs/node/issues/66668
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"crypto: scrypt with params over maxmem leaves an OpenSSL error queued; the next createPrivateKey fails","articleBody":"### Version\nv24.13.0 (OpenSSL 3.5.4)\n\n### Platform\nWindows 11 x64 (10.0.22631). Not yet checked on Linux/macOS.\n\n### Subsystem\ncrypto\n\n### What steps will reproduce the bug?\n\n```js\nimport crypto from \"node:crypto\";\n\nconst { privateKey } = crypto.generateKeyPairSync(\"rsa\", {\n modulusLength: 2048,\n privateKeyEncoding: { type: \"pkcs8\", format: \"pem\" },\n publicKeyEncoding: { type: \"spki\", format: \"pem\" },\n});\n\ncrypto.createPrivateKey(privateKey); // ok\n\ntry {\n // 128 * r * (N + 2) > maxmem → ERR_CRYPTO_INVALID_SCRYPT_PARAMS (expected)\n crypto.scryptSync(\"pw\", crypto.randomBytes(16), 32, { N: 131072, r: 32, p: 1, maxmem: 256 * 1024 * 1024 });\n} catch (e) {\n console.log(e.code); // ERR_CRYPTO_INVALID_SCRYPT_PARAMS\n}\n\ncrypto.createPrivateKey(privateKey);\n// throws: ERR_OSSL_EVP_MEMORY_LIMIT_EXCEEDED\n// error:030000AC:digital envelope routines::memory limit exceeded\n\ncrypto.createPrivateKey(privateKey); // ok again\n```\n\nThe asynchronous `crypto.scrypt(..., cb)` behaves the same way: its parameter check throws synchronously and leaves the\nsame error queued.\n\n### How often does it reproduce? Is there a required condition?\nAlways, when the scrypt parameters exceed `maxmem` (the memory check). A non-power-of-two `N` (also\n`ERR_CRYPTO_INVALID_SCRYPT_PARAMS`) does not leave an error behind.\n\n### What is the expected behavior? Why is that the expected behavior?\nThe failed scrypt parameter check should not affect unrelated later crypto calls: `createPrivateKey` of a valid key\nshould succeed. The OpenSSL error queue should be cleared when the parameter check fails, as Node does elsewhere.\n\n### What do you see instead?\nThe first `createPrivateKey` (or other key-parsing call) after the failed scrypt throws the scrypt's\n`EVP_R_MEMORY_LIMIT_EXCEEDED`. Through jsonwebtoken this surfaced as «secretOrPrivateKey must be an asymmetric key when\nusing RS256» (jsonwebtoken retries a key that fails `createPrivateKey` as an HMAC secret), which made it look like a\nrandom signing failure under load.\n\n### Additional information\nThe likely source is the fix for #53291 (PR #53300): when `ncrypto::checkScryptParams` fails, `src/crypto/crypto_scrypt.cc`\n(line ~92 on `main`) reads the OpenSSL error with `ERR_peek_last_error()` to build the message, but never pops or\nclears it, so it stays queued for the next OpenSSL consumer on the thread. A `ClearErrorOnReturn` (or\n`ERR_get_error()` / `ERR_clear_error()` after formatting) on that path should fix it. Same class as #45485\n(`X509Certificate.checkPrivateKey()` with a non-matching key makes the next `createPrivateKey()` fail), #21281 and\n#42793.\n","author":{"url":"https://github.com/etray7","@type":"Person","name":"etray7"},"datePublished":"2026-10-12T01:42:24Z","url":"https://github.com/nodejs/node/issues/66668"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:68a1ef37-c771-b85c-13e0-f0daeebe7861 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8DA2:27CA4:2984FDA:3746605:6B033B08 |
| html-safe-nonce | a7145c84e1ea2fb9b058cd2c7bd83714fad2f8643349f49434616bfb3477baa7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4REEyOjI3Q0E0OjI5ODRGREE6Mzc0NjYwNTo2QjAzM0IwOCIsInZpc2l0b3JfaWQiOiIzNDk4NjM2ODc0NTczMTAxODMyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2c64b1ef717c64a0284bae5eb23e230543a59ee05ae3633da81e9341b3504fc7 |
| hovercard-subject-tag | issue:5807165611 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/66668/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c6c5fdb5527f1cf2a51d5bb909af3018a2f4fe429c1c066d947ce3e81716bdce/nodejs/node/issues/66668 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c6c5fdb5527f1cf2a51d5bb909af3018a2f4fe429c1c066d947ce3e81716bdce/nodejs/node/issues/66668 |
| og:image:alt | Version v24.13.0 (OpenSSL 3.5.4) Platform Windows 11 x64 (10.0.22631). Not yet checked on Linux/macOS. Subsystem crypto What steps will reproduce the bug? import crypto from "node:crypto"; const { ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | etray7 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width