@@ -268,6 +268,137 @@ test(() => {
268268 } ) ,
269269 'Invalid hash parameter should return false'
270270 ) ;
271+ assert_false (
272+ SubtleCrypto . supports (
273+ 'encrypt' , { name : 'AES-CBC' , iv : new Uint8Array ( 10 ) } ) ,
274+ 'Invalid IV for AES-CBC should return false' ) ;
275+ assert_false (
276+ SubtleCrypto . supports ( 'encrypt' , {
277+ name : 'AES-CTR' ,
278+ counter : new Uint8Array ( 10 ) ,
279+ length : 128 ,
280+ } ) ,
281+ 'Invalid IV for AES-CTR should return false' ) ;
282+ assert_false (
283+ SubtleCrypto . supports ( 'encrypt' , {
284+ name : 'AES-CTR' ,
285+ counter : new Uint8Array ( 16 ) ,
286+ length : 0 ,
287+ } ) ,
288+ 'Invalid length=0 for AES-CTR should return false' ) ;
289+ assert_false (
290+ SubtleCrypto . supports ( 'encrypt' , {
291+ name : 'AES-CTR' ,
292+ counter : new Uint8Array ( 16 ) ,
293+ length : 129 ,
294+ } ) ,
295+ 'Invalid length=129 for AES-CTR should return false' ) ;
296+ assert_false (
297+ SubtleCrypto . supports ( 'encrypt' , {
298+ name : 'AES-GCM' ,
299+ iv : new Uint8Array ( 16 ) ,
300+ tagLength : 100 ,
301+ } ) ,
302+ 'Invalid tag length for AES-GCM should return false' ) ;
303+ assert_false (
304+ SubtleCrypto . supports ( 'generateKey' , { name : 'ECDH' , namedCurve : 'P-51' } ) ,
305+ 'Invalid curve for ECDH should return false' ) ;
306+ assert_false (
307+ SubtleCrypto . supports (
308+ 'deriveBits' , {
309+ name : 'HKDF' ,
310+ hash : 'SHA-25' ,
311+ salt : new Uint8Array ( 16 ) ,
312+ info : new Uint8Array ( 0 ) ,
313+ } ,
314+ 8 ) ,
315+ 'Invalid hash for HKDF should return false' ) ;
316+ assert_false (
317+ SubtleCrypto . supports (
318+ 'deriveBits' , {
319+ name : 'HKDF' ,
320+ hash : 'SHA-256' ,
321+ salt : new Uint8Array ( 16 ) ,
322+ info : new Uint8Array ( 0 ) ,
323+ } ,
324+ 11 ) ,
325+ 'Invalid length for HKDF should return false' ) ;
326+ assert_false (
327+ SubtleCrypto . supports (
328+ 'deriveBits' , {
329+ name : 'HKDF' ,
330+ hash : 'SHA-256' ,
331+ salt : new Uint8Array ( 16 ) ,
332+ info : new Uint8Array ( 0 ) ,
333+ } ) ,
334+ 'null length for HKDF should return false' ) ;
335+ assert_false (
336+ SubtleCrypto . supports ( 'generateKey' , {
337+ name : 'HMAC' ,
338+ hash : 'SHA-25' ,
339+ } ) ,
340+ 'Invalid hash for HMAC should return false' ) ;
341+ assert_false (
342+ SubtleCrypto . supports ( 'generateKey' , {
343+ name : 'HMAC' ,
344+ hash : 'SHA-256' ,
345+ length : 0 ,
346+ } ) ,
347+ 'Invalid length for HMAC should return false' ) ;
348+ assert_false (
349+ SubtleCrypto . supports (
350+ 'deriveBits' , {
351+ name : 'PBKDF2' ,
352+ hash : 'SHA-25' ,
353+ salt : new Uint8Array ( 16 ) ,
354+ iterations : 100000 ,
355+ } ,
356+ 8 ) ,
357+ 'Invalid hash for PBKDF2 should return false' ) ;
358+ assert_false (
359+ SubtleCrypto . supports (
360+ 'deriveBits' , {
361+ name : 'PBKDF2' ,
362+ hash : 'SHA-256' ,
363+ salt : new Uint8Array ( 16 ) ,
364+ iterations : 100000 ,
365+ } ,
366+ 11 ) ,
367+ 'Invalid length for PBKDF2 should return false' ) ;
368+ assert_false (
369+ SubtleCrypto . supports (
370+ 'deriveBits' , {
371+ name : 'PBKDF2' ,
372+ hash : 'SHA-256' ,
373+ salt : new Uint8Array ( 16 ) ,
374+ iterations : 100000 ,
375+ } ) ,
376+ 'null length for PBKDF2 should return false' ) ;
377+ assert_false (
378+ SubtleCrypto . supports ( 'generateKey' , {
379+ name : 'RSASSA-PKCS1-v1_5' ,
380+ modulusLength : 2048 ,
381+ publicExponent : new Uint8Array ( [ 1 , 0 , 1 ] ) ,
382+ hash : 'SHA-56' ,
383+ } ) ,
384+ 'Invalid hash for RSA PKCS1 should return false' ) ;
385+ assert_false (
386+ SubtleCrypto . supports ( 'generateKey' , {
387+ name : 'RSA-PSS' ,
388+ modulusLength : 2048 ,
389+ publicExponent : new Uint8Array ( [ 1 , 0 , 1 ] ) ,
390+ hash : 'SHA-56' ,
391+ } ) ,
392+ 'Invalid hash for RSA PSS should return false' ) ;
393+ assert_false (
394+ SubtleCrypto . supports ( 'generateKey' , {
395+ name : 'RSA-OAEP' ,
396+ modulusLength : 2048 ,
397+ publicExponent : new Uint8Array ( [ 1 , 0 , 1 ] ) ,
398+ hash : 'SHA-26' ,
399+ } ) ,
400+ 'Invalid hash for RSA OAEP should return false' ) ;
401+
271402} , 'supports returns false for algorithm objects with invalid parameters' ) ;
272403
273404// Test some specific combinations that should work
@@ -394,4 +525,49 @@ test(() => {
394525 ) ;
395526} , 'Invalid algorithm and operation combinations fail' ) ;
396527
528+ // Test supports for deriveKey op
529+ test ( ( ) => {
530+ assert_true (
531+ SubtleCrypto . supports (
532+ 'deriveKey' , {
533+ name : 'HKDF' ,
534+ hash : 'SHA-256' ,
535+ salt : new Uint8Array ( 16 ) ,
536+ info : new Uint8Array ( 0 ) ,
537+ } ,
538+ { name : 'HMAC' , hash : 'SHA-256' } ) ,
539+
540+ 'deriveKey HKDF-HMAC should pass' ) ;
541+ } , 'deriveKey tests' ) ;
542+
543+ promise_test ( async ( t ) => {
544+ let keypair = await crypto . subtle . generateKey (
545+ {
546+ name : 'X25519' ,
547+ } ,
548+ false , [ 'deriveKey' , 'deriveBits' ] ) ;
549+
550+ assert_true (
551+ SubtleCrypto . supports (
552+ 'deriveKey' , {
553+ name : 'X25519' ,
554+ public : keypair . publicKey ,
555+ } ,
556+ { name : 'AES-GCM' , length : 256 } ) ,
557+
558+ 'deriveKey X25519-AES-GCM-256 should pass' ) ;
559+
560+ assert_false (
561+ SubtleCrypto . supports (
562+ 'deriveKey' , {
563+ name : 'X25519' ,
564+ public : keypair . publicKey ,
565+ } ,
566+ { name : 'HMAC' , hash : 'SHA-256' } ) ,
567+
568+ 'deriveKey X25519-HMAC-SHA-256 should fail' ) ;
569+ } , 'deriveKey promise tests' ) ;
570+
571+
572+
397573done ( ) ;
0 commit comments