1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6
7const assert = require('assert');
8const {
9  generateKeyPair,
10} = require('crypto');
11
12// RFC 8017, A.2.3.: "For a given hashAlgorithm, the default value of
13// saltLength is the octet length of the hash value."
14{
15  generateKeyPair('rsa-pss', {
16    modulusLength: 512,
17    hashAlgorithm: 'sha512'
18  }, common.mustSucceed((publicKey, privateKey) => {
19    const expectedKeyDetails = {
20      modulusLength: 512,
21      publicExponent: 65537n,
22      hashAlgorithm: 'sha512',
23      mgf1HashAlgorithm: 'sha512',
24      saltLength: 64
25    };
26    assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
27    assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
28  }));
29
30  // It is still possible to explicitly set saltLength to 0.
31  generateKeyPair('rsa-pss', {
32    modulusLength: 512,
33    hashAlgorithm: 'sha512',
34    saltLength: 0
35  }, common.mustSucceed((publicKey, privateKey) => {
36    const expectedKeyDetails = {
37      modulusLength: 512,
38      publicExponent: 65537n,
39      hashAlgorithm: 'sha512',
40      mgf1HashAlgorithm: 'sha512',
41      saltLength: 0
42    };
43    assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
44    assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
45  }));
46}
47