Skip to content

Commit 0911e88

Browse files
committed
crypto: fix rsa key gen with non-default exponent
EVP_PKEY_CTX_set_rsa_keygen_pubexp() accepts ownership of the exponent on success, so do not free it. Fixes: #27087 PR-URL: #27092 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent f96a660 commit 0911e88

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/node_crypto.cc

+2
Original file line numberDiff line numberDiff line change
@@ -6084,8 +6084,10 @@ class RSAKeyPairGenerationConfig : public KeyPairGenerationConfig {
60846084
BignumPointer bn(BN_new());
60856085
CHECK_NOT_NULL(bn.get());
60866086
CHECK(BN_set_word(bn.get(), exponent_));
6087+
// EVP_CTX acceps ownership of bn on success.
60876088
if (EVP_PKEY_CTX_set_rsa_keygen_pubexp(ctx.get(), bn.get()) <= 0)
60886089
return false;
6090+
bn.release();
60896091
}
60906092

60916093
return true;

test/parallel/test-crypto-keygen.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
8787
// To make the test faster, we will only test sync key generation once and
8888
// with a relatively small key.
8989
const ret = generateKeyPairSync('rsa', {
90-
publicExponent: 0x10001,
90+
publicExponent: 3,
9191
modulusLength: 512,
9292
publicKeyEncoding: {
9393
type: 'pkcs1',
@@ -160,7 +160,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
160160

161161
// Now do the same with an encrypted private key.
162162
generateKeyPair('rsa', {
163-
publicExponent: 0x10001,
163+
publicExponent: 0x1001,
164164
modulusLength: 512,
165165
publicKeyEncoding,
166166
privateKeyEncoding: {

0 commit comments

Comments
 (0)