Skip to content

Commit 0fb2842

Browse files
committed
Fix ECDH/ECDSA browser tests: restore local curve element length tables
The #26 change replaced the tests' own curve-length tables with calls to cryptoECC.curveElementLength(). cryptoECC is an internal module inside the UMD bundle and is not exposed as a global, so SubtleTests.html threw ReferenceError: cryptoECC is not defined. Restore independent test-local tables (keeping the new BN-254 entry); the production de-duplication in ecdh.js/ecdsa.js/cryptoECC.js is unaffected.
1 parent 1020f0f commit 0fb2842

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

test/Test.Ecdh.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,18 @@ function ecdhTests() {
226226
});
227227
}
228228

229-
function ecdhCurveElementLength(namedCurve) {
230-
return cryptoECC.curveElementLength(namedCurve);
231-
}
229+
var ecdhKeyLengths = {
230+
"P-256": 32,
231+
"P-384": 48,
232+
"P-521": 66,
233+
"BN-254": 32,
234+
"NUMSP256D1": 32,
235+
"NUMSP256T1": 32,
236+
"NUMSP384D1": 48,
237+
"NUMSP384T1": 48,
238+
"NUMSP512D1": 64,
239+
"NUMSP512T1": 64
240+
};
232241

233242
function ecdhKeyAlg(namedCurve) {
234243
return {
@@ -241,7 +250,7 @@ var inspectEcdhKey = {
241250
public: function(keyObj, algorithm, usages, reason) {
242251

243252
var fail = [];
244-
var expLenMax = ecdhCurveElementLength(algorithm.namedCurve);
253+
var expLenMax = ecdhKeyLengths[algorithm.namedCurve];
245254
var expLenMin = expLenMax;
246255

247256
// has crv property equal to the algorithm's namedCurve
@@ -300,7 +309,7 @@ var inspectEcdhKey = {
300309
// }
301310
// }
302311

303-
var expLenMax = ecdhCurveElementLength(algorithm.namedCurve);
312+
var expLenMax = ecdhKeyLengths[algorithm.namedCurve];
304313
var expLenMin = expLenMax;
305314

306315
this.public(keyObj, algorithm, usages, reason);

test/Test.Ecdsa.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,18 @@ function ecdsaTests() {
423423
});
424424
}
425425

426-
function ecdsaCurveElementLength(namedCurve) {
427-
return cryptoECC.curveElementLength(namedCurve);
428-
}
426+
var ecdsaKeyLengths = {
427+
"P-256": 32,
428+
"P-384": 48,
429+
"P-521": 66,
430+
"BN-254": 32,
431+
"NUMSP256D1": 32,
432+
"NUMSP256T1": 32,
433+
"NUMSP384D1": 48,
434+
"NUMSP384T1": 48,
435+
"NUMSP512D1": 64,
436+
"NUMSP512T1": 64
437+
};
429438

430439
function ecdsaKeyAlg(curve) {
431440
return {
@@ -446,7 +455,7 @@ var inspectEcdsaKey = {
446455

447456
var fail = [];
448457

449-
var expLenMax = ecdsaCurveElementLength(algorithm.namedCurve);
458+
var expLenMax = ecdsaKeyLengths[algorithm.namedCurve];
450459
var expLenMin = expLenMax;
451460

452461
// has crv property equal to the algorithm's namedCurve
@@ -489,7 +498,7 @@ var inspectEcdsaKey = {
489498
},
490499
private: function(keyObj, algorithm, usages, reason) {
491500

492-
var expLenMax = ecdsaCurveElementLength(algorithm.namedCurve);
501+
var expLenMax = ecdsaKeyLengths[algorithm.namedCurve];
493502
var expLenMin = expLenMax;
494503

495504
this.public(keyObj, algorithm, usages, reason);

0 commit comments

Comments
 (0)