Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 24a1016

Browse filesBrowse files
panvajuanarbol
authored andcommitted
crypto: return correct bit length in KeyObject's asymmetricKeyDetails
PR-URL: #46106 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 36be0c4 commit 24a1016
Copy full SHA for 24a1016

File tree

Expand file treeCollapse file tree

3 files changed

+31
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+31
-3
lines changed
Open diff view settings
Collapse file

‎src/crypto/crypto_dsa.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_dsa.cc
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ Maybe<bool> GetDsaKeyDetail(
147147

148148
DSA_get0_pqg(dsa, &p, &q, nullptr);
149149

150-
size_t modulus_length = BN_num_bytes(p) * CHAR_BIT;
151-
size_t divisor_length = BN_num_bytes(q) * CHAR_BIT;
150+
size_t modulus_length = BN_num_bits(p);
151+
size_t divisor_length = BN_num_bits(q);
152152

153153
if (target
154154
->Set(
Collapse file

‎src/crypto/crypto_rsa.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_rsa.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ Maybe<bool> GetRsaKeyDetail(
529529

530530
RSA_get0_key(rsa, &n, &e, nullptr);
531531

532-
size_t modulus_length = BN_num_bytes(n) * CHAR_BIT;
532+
size_t modulus_length = BN_num_bits(n);
533533

534534
if (target
535535
->Set(
Collapse file

‎test/parallel/test-crypto-keygen.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-keygen.js
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,3 +1817,31 @@ generateKeyPair('rsa', {
18171817
hashAlgorithm: 'sha1'
18181818
}, common.mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE' });
18191819
}
1820+
1821+
{
1822+
// https://github.com/nodejs/node/issues/46102#issuecomment-1372153541
1823+
1824+
generateKeyPair('rsa', {
1825+
modulusLength: 513,
1826+
}, common.mustSucceed((publicKey, privateKey) => {
1827+
assert.strictEqual(privateKey.asymmetricKeyDetails.modulusLength, 513);
1828+
assert.strictEqual(publicKey.asymmetricKeyDetails.modulusLength, 513);
1829+
}));
1830+
1831+
generateKeyPair('rsa-pss', {
1832+
modulusLength: 513,
1833+
}, common.mustSucceed((publicKey, privateKey) => {
1834+
assert.strictEqual(privateKey.asymmetricKeyDetails.modulusLength, 513);
1835+
assert.strictEqual(publicKey.asymmetricKeyDetails.modulusLength, 513);
1836+
}));
1837+
1838+
if (common.hasOpenSSL3) {
1839+
generateKeyPair('dsa', {
1840+
modulusLength: 2049,
1841+
divisorLength: 256,
1842+
}, common.mustSucceed((publicKey, privateKey) => {
1843+
assert.strictEqual(privateKey.asymmetricKeyDetails.modulusLength, 2049);
1844+
assert.strictEqual(publicKey.asymmetricKeyDetails.modulusLength, 2049);
1845+
}));
1846+
}
1847+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.