@@ -43,6 +43,7 @@ const good = [
4343 N : 1024 ,
4444 p : 16 ,
4545 r : 8 ,
46+ testAsync : true ,
4647 expected :
4748 'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b373162' +
4849 '2eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640' ,
@@ -65,32 +66,11 @@ const good = [
6566 cost : 16 ,
6667 parallelization : 1 ,
6768 blockSize : 1 ,
69+ testAsync : true ,
6870 expected :
6971 '77d6576238657b203b19ca42c18a0497f16b4844e3074ae8dfdffa3fede21442' +
7072 'fcd0069ded0948f8326a753a0fc81f17e8d3e0fb2e0d3628cf35e20c38d18906' ,
7173 } ,
72- {
73- pass : 'password' ,
74- salt : 'NaCl' ,
75- keylen : 64 ,
76- cost : 1024 ,
77- parallelization : 16 ,
78- blockSize : 8 ,
79- expected :
80- 'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b373162' +
81- '2eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640' ,
82- } ,
83- {
84- pass : 'pleaseletmein' ,
85- salt : 'SodiumChloride' ,
86- keylen : 64 ,
87- cost : 16384 ,
88- parallelization : 1 ,
89- blockSize : 8 ,
90- expected :
91- '7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b543f6545da1f2' +
92- 'd5432955613f0fcf62d49705242a9af9e61e85dc0d651e40dfcf017b45575887' ,
93- } ,
9474] ;
9575
9676// Test vectors that contain invalid parameters.
@@ -171,9 +151,11 @@ if (isFips) {
171151 const { pass, salt, keylen, expected } = options ;
172152 const actual = crypto . scryptSync ( pass , salt , keylen , options ) ;
173153 assert . strictEqual ( actual . toString ( 'hex' ) , expected ) ;
174- crypto . scrypt ( pass , salt , keylen , options , common . mustSucceed ( ( actual ) => {
175- assert . strictEqual ( actual . toString ( 'hex' ) , expected ) ;
176- } ) ) ;
154+ if ( options . testAsync ) {
155+ crypto . scrypt ( pass , salt , keylen , options , common . mustSucceed ( ( actual ) => {
156+ assert . strictEqual ( actual . toString ( 'hex' ) , expected ) ;
157+ } ) ) ;
158+ }
177159 }
178160}
179161
@@ -215,12 +197,11 @@ for (const options of toobig) {
215197}
216198
217199if ( ! isFips ) {
218- const defaults = { N : 16384 , p : 1 , r : 8 } ;
219- const expected = crypto . scryptSync ( 'pass' , 'salt' , 1 , defaults ) ;
220- const actual = crypto . scryptSync ( 'pass' , 'salt' , 1 ) ;
221- assert . deepStrictEqual ( actual . toString ( 'hex' ) , expected . toString ( 'hex' ) ) ;
222- crypto . scrypt ( 'pass' , 'salt' , 1 , common . mustSucceed ( ( actual ) => {
223- assert . deepStrictEqual ( actual . toString ( 'hex' ) , expected . toString ( 'hex' ) ) ;
200+ const expected = '4cac4540' ;
201+ const actual = crypto . scryptSync ( 'pass' , 'salt' , 4 ) ;
202+ assert . strictEqual ( actual . toString ( 'hex' ) , expected ) ;
203+ crypto . scrypt ( 'pass' , 'salt' , 4 , common . mustSucceed ( ( actual ) => {
204+ assert . strictEqual ( actual . toString ( 'hex' ) , expected ) ;
224205 } ) ) ;
225206}
226207
@@ -241,9 +222,9 @@ for (const { args, expected } of badargs) {
241222 // Values for maxmem that do not fit in 32 bits but that are still safe
242223 // integers should be allowed.
243224 if ( ! isFips ) {
244- crypto . scrypt ( '' , '' , 4 , { maxmem : 2 ** 52 } ,
225+ crypto . scrypt ( '' , '' , 4 , { N : 16 , maxmem : 2 ** 52 } ,
245226 common . mustSucceed ( ( actual ) => {
246- assert . strictEqual ( actual . toString ( 'hex' ) , 'd72c87d0 ' ) ;
227+ assert . strictEqual ( actual . toString ( 'hex' ) , 'e2b18837 ' ) ;
247228 } ) ) ;
248229 }
249230
@@ -258,9 +239,12 @@ if (!isFips) {
258239
259240 function testParameter ( name , value ) {
260241 let accessCount = 0 ;
242+ // This regression checks getter access, so the derivation can be cheap.
243+ const options = name === 'cost' ? { cost : 16 } : { N : 16 } ;
261244
262245 // Find out how often the value is accessed.
263246 crypto . scryptSync ( '' , '' , 1 , {
247+ ...options ,
264248 get [ name ] ( ) {
265249 accessCount ++ ;
266250 return value ;
@@ -270,6 +254,7 @@ if (!isFips) {
270254 // Try to crash the process on the last access.
271255 assert . throws ( ( ) => {
272256 crypto . scryptSync ( '' , '' , 1 , {
257+ ...options ,
273258 get [ name ] ( ) {
274259 if ( -- accessCount === 0 )
275260 return '' ;
@@ -282,7 +267,7 @@ if (!isFips) {
282267 }
283268
284269 [
285- [ 'N' , 16384 ] , [ 'cost' , 16384 ] ,
270+ [ 'N' , 16 ] , [ 'cost' , 16 ] ,
286271 [ 'r' , 8 ] , [ 'blockSize' , 8 ] ,
287272 [ 'p' , 1 ] , [ 'parallelization' , 1 ] ,
288273 ] . forEach ( ( arg ) => testParameter ( ...arg ) ) ;
@@ -292,17 +277,18 @@ if (!isFips) {
292277// IsInt32() assertion. Assert that `-0` produces the same outcome as
293278// `+0` (which differs by OpenSSL build).
294279{
280+ const options = { N : 16 } ;
295281 let posError ;
296282 let posResult ;
297283 try {
298- posResult = crypto . scryptSync ( '' , '' , 0 ) ;
284+ posResult = crypto . scryptSync ( '' , '' , 0 , options ) ;
299285 } catch ( err ) {
300286 posError = err ;
301287 }
302288 let negError ;
303289 let negResult ;
304290 try {
305- negResult = crypto . scryptSync ( '' , '' , - 0 ) ;
291+ negResult = crypto . scryptSync ( '' , '' , - 0 , options ) ;
306292 } catch ( err ) {
307293 negError = err ;
308294 }
@@ -314,9 +300,9 @@ if (!isFips) {
314300
315301 if ( isFips ) {
316302 assert . throws (
317- ( ) => crypto . scrypt ( '' , '' , - 0 , ( ) => { } ) ,
303+ ( ) => crypto . scrypt ( '' , '' , - 0 , options , ( ) => { } ) ,
318304 { code : 'ERR_CRYPTO_INVALID_SCRYPT_PARAMS' } ) ;
319305 } else {
320- crypto . scrypt ( '' , '' , - 0 , common . mustCall ( ) ) ;
306+ crypto . scrypt ( '' , '' , - 0 , options , common . mustCall ( ) ) ;
321307 }
322308}
0 commit comments