@@ -110,7 +110,22 @@ function assert_goodCryptoKey(key, algorithm, extractable, usages, kind) {
110
110
assert_equals ( key . extractable , extractable , "Extractability is correct" ) ;
111
111
112
112
assert_equals ( key . algorithm . name , registeredAlgorithmName , "Correct algorithm name" ) ;
113
- assert_equals ( key . algorithm . length , algorithm . length , "Correct length" ) ;
113
+ if ( key . algorithm . name . toUpperCase ( ) === "HMAC" && algorithm . length === undefined ) {
114
+ switch ( key . algorithm . hash . name . toUpperCase ( ) ) {
115
+ case 'SHA-1' :
116
+ case 'SHA-256' :
117
+ assert_equals ( key . algorithm . length , 512 , "Correct length" ) ;
118
+ break ;
119
+ case 'SHA-384' :
120
+ case 'SHA-512' :
121
+ assert_equals ( key . algorithm . length , 1024 , "Correct length" ) ;
122
+ break ;
123
+ default :
124
+ assert_unreached ( "Unrecognized hash" ) ;
125
+ }
126
+ } else {
127
+ assert_equals ( key . algorithm . length , algorithm . length , "Correct length" ) ;
128
+ }
114
129
if ( [ "HMAC" , "RSASSA-PKCS1-v1_5" , "RSA-PSS" ] . includes ( registeredAlgorithmName ) ) {
115
130
assert_equals ( key . algorithm . hash . name . toUpperCase ( ) , algorithm . hash . toUpperCase ( ) , "Correct hash function" ) ;
116
131
}
@@ -166,12 +181,16 @@ function allAlgorithmSpecifiersFor(algorithmName) {
166
181
} ) ;
167
182
} else if ( algorithmName . toUpperCase ( ) === "HMAC" ) {
168
183
[
169
- { name : "SHA-1" , length : 160 } ,
170
- { name : "SHA-256" , length : 256 } ,
171
- { name : "SHA-384" , length : 384 } ,
172
- { name : "SHA-512" , length : 512 }
184
+ { hash : "SHA-1" , length : 160 } ,
185
+ { hash : "SHA-256" , length : 256 } ,
186
+ { hash : "SHA-384" , length : 384 } ,
187
+ { hash : "SHA-512" , length : 512 } ,
188
+ { hash : "SHA-1" } ,
189
+ { hash : "SHA-256" } ,
190
+ { hash : "SHA-384" } ,
191
+ { hash : "SHA-512" } ,
173
192
] . forEach ( function ( hashAlgorithm ) {
174
- results . push ( { name : algorithmName , hash : hashAlgorithm . name , length : hashAlgorithm . length } ) ;
193
+ results . push ( { name : algorithmName , ... hashAlgorithm } ) ;
175
194
} ) ;
176
195
} else if ( algorithmName . toUpperCase ( ) . substring ( 0 , 3 ) === "RSA" ) {
177
196
hashes . forEach ( function ( hashName ) {
0 commit comments