| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,6 +50,8 @@ const { | |||
| 50 | 50 | isArrayBufferView, | |
| 51 | 51 | } = require('internal/util/types'); | |
| 52 | 52 | ||
| 53 | + const constants = internalBinding('constants').crypto; | ||
| 54 | + | ||
| 53 | 55 | function Sign(algorithm, options) { | |
| 54 | 56 | if (!(this instanceof Sign)) | |
| 55 | 57 | return new Sign(algorithm, options); | |
@@ -85,7 +87,11 @@ function getPadding(options) { | |||
| 85 | 87 | } | |
| 86 | 88 | ||
| 87 | 89 | function getSaltLength(options) { | |
| 88 | - return getIntOption('saltLength', options); | ||
| 90 | + let saltLength = getIntOption('saltLength', options); | ||
| 91 | + if (options.padding === constants.RSA_PKCS1_PSS_PADDING && saltLength === undefined) { | ||
| 92 | + saltLength = constants.RSA_PSS_SALTLEN_MAX_SIGN; | ||
| 93 | + } | ||
| 94 | + return saltLength; | ||
| 89 | 95 | } | |
| 90 | 96 | ||
| 91 | 97 | function getDSASignatureEncoding(options) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,37 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + if (!common.hasCrypto) | ||
| 4 | + common.skip('missing crypto'); | ||
| 5 | + | ||
| 6 | + const assert = require('assert'); | ||
| 7 | + const crypto = require('crypto'); | ||
| 8 | + | ||
| 9 | + const fixtures = require('../common/fixtures'); | ||
| 10 | + | ||
| 11 | + const privateKey = crypto.createPrivateKey(fixtures.readKey('rsa_private.pem', 'ascii')); | ||
| 12 | + const publicKey = crypto.createPublicKey(fixtures.readKey('rsa_public.pem', 'ascii')); | ||
| 13 | + | ||
| 14 | + const data = crypto.randomBytes(32); | ||
| 15 | + | ||
| 16 | + for (const digest of ['sha256', 'sha384', 'sha512']) { | ||
| 17 | + const hLen = crypto.hash(digest, data, 'buffer').byteLength; | ||
| 18 | + const maxSaltLength = | ||
| 19 | + privateKey.asymmetricKeyDetails.modulusLength / 8 - hLen - 2; | ||
| 20 | + | ||
| 21 | + const sig = crypto.sign(digest, data, { | ||
| 22 | + key: privateKey, | ||
| 23 | + padding: crypto.constants.RSA_PKCS1_PSS_PADDING, | ||
| 24 | + // No "saltLength" provided, documented default RSA_PSS_SALTLEN_MAX_SIGN expected | ||
| 25 | + }); | ||
| 26 | + | ||
| 27 | + assert.strictEqual(crypto.verify( | ||
| 28 | + digest, | ||
| 29 | + data, | ||
| 30 | + { | ||
| 31 | + key: publicKey, | ||
| 32 | + padding: crypto.constants.RSA_PKCS1_PSS_PADDING, | ||
| 33 | + saltLength: maxSaltLength, | ||
| 34 | + }, | ||
| 35 | + sig | ||
| 36 | + ), true); | ||
| 37 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments