MCPcopy Create free account
hub / github.com/nodejs/node / testPSS

Function testPSS

test/parallel/test-crypto-sign-verify.js:160–282  ·  view source on GitHub ↗
(algo, hLen)

Source from the content-addressed store, hash-verified

158// Special tests for RSA_PKCS1_PSS_PADDING
159{
160 function testPSS(algo, hLen) {
161 // Maximum permissible salt length
162 const max = keySize / 8 - hLen - 2;
163
164 function getEffectiveSaltLength(saltLength) {
165 switch (saltLength) {
166 case crypto.constants.RSA_PSS_SALTLEN_DIGEST:
167 return hLen;
168 case crypto.constants.RSA_PSS_SALTLEN_MAX_SIGN:
169 return max;
170 default:
171 return saltLength;
172 }
173 }
174
175 const signSaltLengths = [
176 crypto.constants.RSA_PSS_SALTLEN_DIGEST,
177 getEffectiveSaltLength(crypto.constants.RSA_PSS_SALTLEN_DIGEST),
178 crypto.constants.RSA_PSS_SALTLEN_MAX_SIGN,
179 getEffectiveSaltLength(crypto.constants.RSA_PSS_SALTLEN_MAX_SIGN),
180 0, 16, 32, 64, 128,
181 ];
182
183 const verifySaltLengths = [
184 crypto.constants.RSA_PSS_SALTLEN_DIGEST,
185 getEffectiveSaltLength(crypto.constants.RSA_PSS_SALTLEN_DIGEST),
186 getEffectiveSaltLength(crypto.constants.RSA_PSS_SALTLEN_MAX_SIGN),
187 0, 16, 32, 64, 128,
188 ];
189 const errMessage = /^Error:.*data too large for key size$/;
190
191 const data = Buffer.from('Test123');
192
193 signSaltLengths.forEach((signSaltLength) => {
194 if (signSaltLength > max) {
195 // If the salt length is too big, an Error should be thrown
196 assert.throws(() => {
197 crypto.createSign(algo)
198 .update(data)
199 .sign({
200 key: keyPem,
201 padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
202 saltLength: signSaltLength
203 });
204 }, errMessage);
205 assert.throws(() => {
206 crypto.sign(algo, data, {
207 key: keyPem,
208 padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
209 saltLength: signSaltLength
210 });
211 }, errMessage);
212 } else {
213 // Otherwise, a valid signature should be generated
214 const s4 = crypto.createSign(algo)
215 .update(data)
216 .sign({
217 key: keyPem,

Callers 1

Calls 5

getEffectiveSaltLengthFunction · 0.85
forEachMethod · 0.65
updateMethod · 0.65
fromMethod · 0.45
verifyMethod · 0.45

Tested by

no test coverage detected