Skip to content

Commit 623d387

Browse files
committed
crypto: rsa-pss keygen params aligned with asymmetricKeyDetails
1 parent 63bd37a commit 623d387

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

doc/api/crypto.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3375,6 +3375,10 @@ generateKey('hmac', { length: 64 }, (err, key) => {
33753375
<!-- YAML
33763376
added: v10.12.0
33773377
changes:
3378+
- version: REPLACEME
3379+
pr-url: https://github.com/nodejs/node/pull/39927
3380+
description: Add ability to define `RSASSA-PSS-params` sequence parameters
3381+
for RSA-PSS keys pairs.
33783382
- version:
33793383
- v13.9.0
33803384
- v12.17.0
@@ -3397,6 +3401,10 @@ changes:
33973401
* `options`: {Object}
33983402
* `modulusLength`: {number} Key size in bits (RSA, DSA).
33993403
* `publicExponent`: {number} Public exponent (RSA). **Default:** `0x10001`.
3404+
* `hashAlgorithm`: {string} Name of the message digest (RSA-PSS).
3405+
* `mgf1HashAlgorithm`: {string} Name of the message digest used by
3406+
MGF1 (RSA-PSS).
3407+
* `saltLength`: {number} Minimal salt length in bytes (RSA-PSS).
34003408
* `divisorLength`: {number} Size of `q` in bits (DSA).
34013409
* `namedCurve`: {string} Name of the curve to use (EC).
34023410
* `prime`: {Buffer} The prime parameter (DH).
@@ -3475,6 +3483,10 @@ a `Promise` for an `Object` with `publicKey` and `privateKey` properties.
34753483
<!-- YAML
34763484
added: v10.12.0
34773485
changes:
3486+
- version: REPLACEME
3487+
pr-url: https://github.com/nodejs/node/pull/39927
3488+
description: Add ability to define `RSASSA-PSS-params` sequence parameters
3489+
for RSA-PSS keys pairs.
34783490
- version:
34793491
- v13.9.0
34803492
- v12.17.0
@@ -3494,6 +3506,10 @@ changes:
34943506
* `options`: {Object}
34953507
* `modulusLength`: {number} Key size in bits (RSA, DSA).
34963508
* `publicExponent`: {number} Public exponent (RSA). **Default:** `0x10001`.
3509+
* `hashAlgorithm`: {string} Name of the message digest (RSA-PSS).
3510+
* `mgf1HashAlgorithm`: {string} Name of the message digest used by
3511+
MGF1 (RSA-PSS).
3512+
* `saltLength`: {number} Minimal salt length in bytes (RSA-PSS).
34973513
* `divisorLength`: {number} Size of `q` in bits (DSA).
34983514
* `namedCurve`: {string} Name of the curve to use (EC).
34993515
* `prime`: {Buffer} The prime parameter (DH).

lib/internal/crypto/keygen.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,13 @@ function createJob(mode, type, options) {
193193
...encoding);
194194
}
195195

196-
const { hash, mgf1Hash, saltLength } = options;
197-
if (hash !== undefined && typeof hash !== 'string')
198-
throw new ERR_INVALID_ARG_VALUE('options.hash', hash);
199-
if (mgf1Hash !== undefined && typeof mgf1Hash !== 'string')
200-
throw new ERR_INVALID_ARG_VALUE('options.mgf1Hash', mgf1Hash);
196+
const { hashAlgorithm, mgf1HashAlgorithm, saltLength } = options;
197+
if (hashAlgorithm !== undefined && typeof hashAlgorithm !== 'string')
198+
throw new ERR_INVALID_ARG_VALUE('options.hash', hashAlgorithm);
199+
if (mgf1HashAlgorithm !== undefined &&
200+
typeof mgf1HashAlgorithm !== 'string')
201+
throw new ERR_INVALID_ARG_VALUE('options.mgf1HashAlgorithm',
202+
mgf1HashAlgorithm);
201203
if (saltLength !== undefined && (!isInt32(saltLength) || saltLength < 0))
202204
throw new ERR_INVALID_ARG_VALUE('options.saltLength', saltLength);
203205

@@ -206,8 +208,8 @@ function createJob(mode, type, options) {
206208
kKeyVariantRSA_PSS,
207209
modulusLength,
208210
publicExponent,
209-
hash,
210-
mgf1Hash,
211+
hashAlgorithm,
212+
mgf1HashAlgorithm,
211213
saltLength,
212214
...encoding);
213215
}

test/parallel/test-crypto-keygen.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
302302
generateKeyPair('rsa-pss', {
303303
modulusLength: 512,
304304
saltLength: 16,
305-
hash: 'sha256',
306-
mgf1Hash: 'sha256'
305+
hashAlgorithm: 'sha256',
306+
mgf1HashAlgorithm: 'sha256'
307307
}, common.mustSucceed((publicKey, privateKey) => {
308308
assert.strictEqual(publicKey.type, 'public');
309309
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa-pss');
@@ -1301,7 +1301,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
13011301
assert.throws(() => {
13021302
generateKeyPairSync('rsa-pss', {
13031303
modulusLength: 4096,
1304-
hash: hashValue
1304+
hashAlgorithm: hashValue
13051305
});
13061306
}, {
13071307
name: 'TypeError',
@@ -1316,8 +1316,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
13161316
generateKeyPair('rsa-pss', {
13171317
modulusLength: 512,
13181318
saltLength: 2147483648,
1319-
hash: 'sha256',
1320-
mgf1Hash: 'sha256'
1319+
hashAlgorithm: 'sha256',
1320+
mgf1HashAlgorithm: 'sha256'
13211321
}, common.mustNotCall());
13221322
}, {
13231323
name: 'TypeError',
@@ -1330,8 +1330,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
13301330
generateKeyPair('rsa-pss', {
13311331
modulusLength: 512,
13321332
saltLength: -1,
1333-
hash: 'sha256',
1334-
mgf1Hash: 'sha256'
1333+
hashAlgorithm: 'sha256',
1334+
mgf1HashAlgorithm: 'sha256'
13351335
}, common.mustNotCall());
13361336
}, {
13371337
name: 'TypeError',
@@ -1428,8 +1428,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
14281428
generateKeyPair('rsa-pss', {
14291429
modulusLength: 512,
14301430
saltLength: 16,
1431-
hash: 'sha256',
1432-
mgf1Hash: undefined
1431+
hashAlgorithm: 'sha256',
1432+
mgf1HashAlgorithm: undefined
14331433
});
14341434
},
14351435
{
@@ -1439,21 +1439,21 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
14391439
}
14401440
);
14411441

1442-
for (const mgf1Hash of [null, 0, false, {}, []]) {
1442+
for (const mgf1HashAlgorithm of [null, 0, false, {}, []]) {
14431443
assert.throws(
14441444
() => {
14451445
generateKeyPair('rsa-pss', {
14461446
modulusLength: 512,
14471447
saltLength: 16,
1448-
hash: 'sha256',
1449-
mgf1Hash
1448+
hashAlgorithm: 'sha256',
1449+
mgf1HashAlgorithm
14501450
}, common.mustNotCall());
14511451
},
14521452
{
14531453
name: 'TypeError',
14541454
code: 'ERR_INVALID_ARG_VALUE',
1455-
message: "The property 'options.mgf1Hash' is invalid. " +
1456-
`Received ${inspect(mgf1Hash)}`
1455+
message: "The property 'options.mgf1HashAlgorithm' is invalid. " +
1456+
`Received ${inspect(mgf1HashAlgorithm)}`
14571457

14581458
}
14591459
);

0 commit comments

Comments
 (0)