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 d657ae6

Browse filesBrowse files
tniessenBethGriggs
authored andcommitted
crypto: fix RSA-PSS default saltLength
PR-URL: #39999 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent fc45cbe commit d657ae6
Copy full SHA for d657ae6

File tree

Expand file treeCollapse file tree

2 files changed

+44
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+44
-2
lines changed
Open diff view settings
Collapse file

‎src/crypto/crypto_rsa.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_rsa.cc
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,15 @@ EVPKeyCtxPointer RsaKeyGenTraits::Setup(RsaKeyPairGenConfig* params) {
7979
return EVPKeyCtxPointer();
8080
}
8181

82-
if (params->params.saltlen >= 0 &&
82+
int saltlen = params->params.saltlen;
83+
if (saltlen < 0 && params->params.md != nullptr) {
84+
saltlen = EVP_MD_size(params->params.md);
85+
}
86+
87+
if (saltlen >= 0 &&
8388
EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen(
8489
ctx.get(),
85-
params->params.saltlen) <= 0) {
90+
saltlen) <= 0) {
8691
return EVPKeyCtxPointer();
8792
}
8893
}
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-keygen.js
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,43 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
391391
}));
392392
}
393393

394+
{
395+
// RFC 8017, A.2.3.: "For a given hashAlgorithm, the default value of
396+
// saltLength is the octet length of the hash value."
397+
398+
generateKeyPair('rsa-pss', {
399+
modulusLength: 512,
400+
hashAlgorithm: 'sha512'
401+
}, common.mustSucceed((publicKey, privateKey) => {
402+
const expectedKeyDetails = {
403+
modulusLength: 512,
404+
publicExponent: 65537n,
405+
hashAlgorithm: 'sha512',
406+
mgf1HashAlgorithm: 'sha512',
407+
saltLength: 64
408+
};
409+
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
410+
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
411+
}));
412+
413+
// It is still possible to explicitly set saltLength to 0.
414+
generateKeyPair('rsa-pss', {
415+
modulusLength: 512,
416+
hashAlgorithm: 'sha512',
417+
saltLength: 0
418+
}, common.mustSucceed((publicKey, privateKey) => {
419+
const expectedKeyDetails = {
420+
modulusLength: 512,
421+
publicExponent: 65537n,
422+
hashAlgorithm: 'sha512',
423+
mgf1HashAlgorithm: 'sha512',
424+
saltLength: 0
425+
};
426+
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
427+
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
428+
}));
429+
}
430+
394431
{
395432
const privateKeyEncoding = {
396433
type: 'pkcs8',

0 commit comments

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