@@ -124,10 +124,11 @@ const { webcrypto: { subtle }, KeyObject } = require('crypto');
124124 const vectors = [
125125 [ 'PBKDF2' , 'deriveKey' , 528 ] ,
126126 [ 'HKDF' , 'deriveKey' , 528 ] ,
127- [ { name : 'HMAC' , hash : 'SHA-1' } , 'sign' , 160 ] ,
128- [ { name : 'HMAC' , hash : 'SHA-256' } , 'sign' , 256 ] ,
129- [ { name : 'HMAC' , hash : 'SHA-384' } , 'sign' , 384 ] ,
130- [ { name : 'HMAC' , hash : 'SHA-512' } , 'sign' , 512 ] ,
127+ [ { name : 'HMAC' , hash : 'SHA-1' } , 'sign' , 512 ] ,
128+ [ { name : 'HMAC' , hash : 'SHA-256' } , 'sign' , 512 ] ,
129+ // Not long enough secret generated by ECDH
130+ // [{ name: 'HMAC', hash: 'SHA-384' }, 'sign', 1024],
131+ // [{ name: 'HMAC', hash: 'SHA-512' }, 'sign', 1024],
131132 ] ;
132133
133134 ( async ( ) => {
@@ -151,6 +152,28 @@ const { webcrypto: { subtle }, KeyObject } = require('crypto');
151152 } ) ( ) . then ( common . mustCall ( ) ) ;
152153}
153154
155+ {
156+ const vectors = [
157+ [ { name : 'HMAC' , hash : 'SHA-1' } , 'sign' , 512 ] ,
158+ [ { name : 'HMAC' , hash : 'SHA-256' } , 'sign' , 512 ] ,
159+ [ { name : 'HMAC' , hash : 'SHA-384' } , 'sign' , 1024 ] ,
160+ [ { name : 'HMAC' , hash : 'SHA-512' } , 'sign' , 1024 ] ,
161+ ] ;
162+
163+ ( async ( ) => {
164+ for ( const [ derivedKeyAlgorithm , usage , expected ] of vectors ) {
165+ const derived = await subtle . deriveKey (
166+ { name : 'PBKDF2' , salt : new Uint8Array ( [ ] ) , hash : 'SHA-256' , iterations : 20 } ,
167+ await subtle . importKey ( 'raw' , new Uint8Array ( [ ] ) , { name : 'PBKDF2' } , false , [ 'deriveKey' ] ) ,
168+ derivedKeyAlgorithm ,
169+ false ,
170+ [ usage ] ) ;
171+
172+ assert . strictEqual ( derived . algorithm . length , expected ) ;
173+ }
174+ } ) ( ) . then ( common . mustCall ( ) ) ;
175+ }
176+
154177// Test X25519 and X448 key derivation
155178{
156179 async function test ( name ) {
0 commit comments