Description
Version
v18.12.1
Platform
Darwin G76106VXHK 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct 9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000 arm64
Subsystem
No response
What steps will reproduce the bug?
Simply try to create a keypair with an odd modulusLength
:
const { generateKeyPairSync } = require('crypto');
const keypair = generateKeyPairSync('rsa', {
modulusLength: 2049,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
}
});
console.log(keypair);
This creates a key pair with 2084
length instead of 2049
as specified by the modulusLength
(checked via openssl rsa -text -noout -in private.key).
I can reproduce this issue with other odd modulusLength
as well.
How often does it reproduce? Is there a required condition?
The bug can be reproduced consistently.
What is the expected behavior?
I would expect that a key pair with the odd input modulusLength
(e.g., 2049
) is generated.
What do you see instead?
A key pair with the "next" even modulusLength
(e.g., 2048
) is generated.
Additional information
The problem can be reproduced in node v18. In contrast, node v16 (e.g., 16.19.0) creates key pairs with odd modulusLength
just fine.