11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif (!common.hasCrypto)
51cb0ef41Sopenharmony_ci  common.skip('missing crypto');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ciconst {
91cb0ef41Sopenharmony_ci  generateKeyPair,
101cb0ef41Sopenharmony_ci} = require('crypto');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci// RFC 8017, A.2.3.: "For a given hashAlgorithm, the default value of
131cb0ef41Sopenharmony_ci// saltLength is the octet length of the hash value."
141cb0ef41Sopenharmony_ci{
151cb0ef41Sopenharmony_ci  generateKeyPair('rsa-pss', {
161cb0ef41Sopenharmony_ci    modulusLength: 512,
171cb0ef41Sopenharmony_ci    hashAlgorithm: 'sha512'
181cb0ef41Sopenharmony_ci  }, common.mustSucceed((publicKey, privateKey) => {
191cb0ef41Sopenharmony_ci    const expectedKeyDetails = {
201cb0ef41Sopenharmony_ci      modulusLength: 512,
211cb0ef41Sopenharmony_ci      publicExponent: 65537n,
221cb0ef41Sopenharmony_ci      hashAlgorithm: 'sha512',
231cb0ef41Sopenharmony_ci      mgf1HashAlgorithm: 'sha512',
241cb0ef41Sopenharmony_ci      saltLength: 64
251cb0ef41Sopenharmony_ci    };
261cb0ef41Sopenharmony_ci    assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
271cb0ef41Sopenharmony_ci    assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
281cb0ef41Sopenharmony_ci  }));
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci  // It is still possible to explicitly set saltLength to 0.
311cb0ef41Sopenharmony_ci  generateKeyPair('rsa-pss', {
321cb0ef41Sopenharmony_ci    modulusLength: 512,
331cb0ef41Sopenharmony_ci    hashAlgorithm: 'sha512',
341cb0ef41Sopenharmony_ci    saltLength: 0
351cb0ef41Sopenharmony_ci  }, common.mustSucceed((publicKey, privateKey) => {
361cb0ef41Sopenharmony_ci    const expectedKeyDetails = {
371cb0ef41Sopenharmony_ci      modulusLength: 512,
381cb0ef41Sopenharmony_ci      publicExponent: 65537n,
391cb0ef41Sopenharmony_ci      hashAlgorithm: 'sha512',
401cb0ef41Sopenharmony_ci      mgf1HashAlgorithm: 'sha512',
411cb0ef41Sopenharmony_ci      saltLength: 0
421cb0ef41Sopenharmony_ci    };
431cb0ef41Sopenharmony_ci    assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
441cb0ef41Sopenharmony_ci    assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
451cb0ef41Sopenharmony_ci  }));
461cb0ef41Sopenharmony_ci}
47