From 0f09596fda6effb83de839c36353462e06ba1f12 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 27 Jun 2026 18:04:36 +0000 Subject: [PATCH 1/3] Initial plan From 9d1221addf0d85846deec304288cd38d2d46562a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 27 Jun 2026 18:08:06 +0000 Subject: [PATCH 2/3] Apply remaining changes --- src/cryptoECC.js | 22 ++++++++++++++++++++++ src/ecdh.js | 14 ++------------ src/ecdsa.js | 14 ++------------ test/Test.Ecdh.js | 5 +++++ test/Test.Ecdsa.js | 5 +++++ 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/cryptoECC.js b/src/cryptoECC.js index 3d214a5..d7b7be0 100644 --- a/src/cryptoECC.js +++ b/src/cryptoECC.js @@ -2002,6 +2002,19 @@ function MsrcryptoECC() { var curvesInternal = {}; + var curveElementLengths = { + "P-256": 32, + "P-384": 48, + "P-521": 66, + "BN-254": 32, + "NUMSP256D1": 32, + "NUMSP256T1": 32, + "NUMSP384D1": 48, + "NUMSP384T1": 48, + "NUMSP512D1": 64, + "NUMSP512T1": 64 + }; + var createCurve = function(curveName) { var curveData = curvesInternal[curveName.toUpperCase()]; @@ -2028,8 +2041,17 @@ function MsrcryptoECC() { return opp.validatePoint(point); }; + var curveElementLength = function(curveName) { + if (!curveName) { + return undefined; + } + + return curveElementLengths[curveName.toUpperCase()]; + }; + return { createCurve: createCurve, + curveElementLength: curveElementLength, curves: curvesInternal, sec1EncodingFp: sec1EncodingFp, validatePoint: validateEccPoint, diff --git a/src/ecdh.js b/src/ecdh.js index f267881..8c17abb 100644 --- a/src/ecdh.js +++ b/src/ecdh.js @@ -156,12 +156,7 @@ if ( typeof operations !== "undefined" ) { // Pad each value to the curve's fixed element length so leading zeros // are preserved (matches Chrome / Chromium-based Edge behavior). - var partLen = { - "P-256": 32, "P-384": 48, "P-521": 66, - "NUMSP256D1": 32, "NUMSP256T1": 32, - "NUMSP384D1": 48, "NUMSP384T1": 48, - "NUMSP512D1": 64, "NUMSP512T1": 64 - }[p.algorithm.namedCurve]; + var partLen = cryptoECC.curveElementLength(p.algorithm.namedCurve); var pad = msrcryptoUtilities.padFront; keyPairData.publicKey.x = pad(keyPairData.publicKey.x, 0, partLen); keyPairData.publicKey.y = pad(keyPairData.publicKey.y, 0, partLen); @@ -250,12 +245,7 @@ if ( typeof operations !== "undefined" ) { // Accept keys with or without trimmed leading zeros and pad each // value to the curve's fixed element length (Chrome/Chromium behavior). - var partLen = { - "P-256": 32, "P-384": 48, "P-521": 66, - "NUMSP256D1": 32, "NUMSP256T1": 32, - "NUMSP384D1": 48, "NUMSP384T1": 48, - "NUMSP512D1": 64, "NUMSP512T1": 64 - }[p.algorithm.namedCurve]; + var partLen = cryptoECC.curveElementLength(p.algorithm.namedCurve); if ( keyObject.x ) { keyObject.x = msrcryptoUtilities.padFront(keyObject.x, 0, partLen); } if ( keyObject.y ) { keyObject.y = msrcryptoUtilities.padFront(keyObject.y, 0, partLen); } if ( keyObject.d ) { keyObject.d = msrcryptoUtilities.padFront(keyObject.d, 0, partLen); } diff --git a/src/ecdsa.js b/src/ecdsa.js index 46dc708..2eebfdc 100644 --- a/src/ecdsa.js +++ b/src/ecdsa.js @@ -207,12 +207,7 @@ if (typeof operations !== "undefined") { // Pad each value to the curve's fixed element length so leading zeros // are preserved (matches Chrome / Chromium-based Edge behavior). - var partLen = { - "P-256": 32, "P-384": 48, "P-521": 66, - "NUMSP256D1": 32, "NUMSP256T1": 32, - "NUMSP384D1": 48, "NUMSP384T1": 48, - "NUMSP512D1": 64, "NUMSP512T1": 64 - }[p.algorithm.namedCurve]; + var partLen = cryptoECC.curveElementLength(p.algorithm.namedCurve); function padToCurveLength( array ) { return msrcryptoUtilities.padFront(array, 0, partLen); @@ -307,12 +302,7 @@ if (typeof operations !== "undefined") { // Accept keys with or without trimmed leading zeros and pad each // value to the curve's fixed element length (Chrome/Chromium behavior). - var partLen = { - "P-256": 32, "P-384": 48, "P-521": 66, - "NUMSP256D1": 32, "NUMSP256T1": 32, - "NUMSP384D1": 48, "NUMSP384T1": 48, - "NUMSP512D1": 64, "NUMSP512T1": 64 - }[p.algorithm.namedCurve]; + var partLen = cryptoECC.curveElementLength(p.algorithm.namedCurve); if ( keyObject.x ) { keyObject.x = msrcryptoUtilities.padFront(keyObject.x, 0, partLen); } if ( keyObject.y ) { keyObject.y = msrcryptoUtilities.padFront(keyObject.y, 0, partLen); } if ( keyObject.d ) { keyObject.d = msrcryptoUtilities.padFront(keyObject.d, 0, partLen); } diff --git a/test/Test.Ecdh.js b/test/Test.Ecdh.js index 41adae3..9ad33e9 100644 --- a/test/Test.Ecdh.js +++ b/test/Test.Ecdh.js @@ -125,6 +125,10 @@ function ecdhTests() { ts.keyGeneratePairTest(ecdhKeyAlg("P-521"), ["deriveKey", "deriveBits"], inspectEcdhKey, context(iterations, assert)); }); + QUnit.test(label + " generateKeyTest BN-254", function(assert) { + ts.keyGeneratePairTest(ecdhKeyAlg("BN-254"), ["deriveKey", "deriveBits"], inspectEcdhKey, context(iterations, assert)); + }); + QUnit.test(label + " ts.deriveKeyTest P-256 --> Aes-Cbc-256 ", function(assert) { ts.deriveKeyTest(ecdh.p256.DeriveKey, undefined, context(iterations, assert)); }); @@ -226,6 +230,7 @@ var ecdhKeyLengths = { "P-256": 32, "P-384": 48, "P-521": 66, + "BN-254": 32, "NUMSP256D1": 32, "NUMSP256T1": 32, "NUMSP384D1": 48, diff --git a/test/Test.Ecdsa.js b/test/Test.Ecdsa.js index e0b8215..278386b 100644 --- a/test/Test.Ecdsa.js +++ b/test/Test.Ecdsa.js @@ -248,6 +248,10 @@ function ecdsaTests() { ts.keyGeneratePairTest( ecdsaKeyAlg( "P-521" ), [VERIFY, SIGN], inspectEcdsaKey, context( iterations, assert ) ); } ); + QUnit.test(label + " generateKeyTest BN-254", function(assert) { + ts.keyGeneratePairTest(ecdsaKeyAlg("BN-254"), [VERIFY, SIGN], inspectEcdsaKey, context(iterations, assert)); + }); + QUnit.test(label + " generateKeyTest NUMSP256D1", function(assert) { ts.keyGeneratePairTest(ecdsaKeyAlg("NUMSP256D1"), [VERIFY, SIGN], inspectEcdsaKey, context(iterations, assert)); }); @@ -423,6 +427,7 @@ var ecdsaKeyLengths = { "P-256": 32, "P-384": 48, "P-521": 66, + "BN-254": 32, "NUMSP256D1": 32, "NUMSP256T1": 32, "NUMSP384D1": 48, From 36444a3a486b3e3c1969a2ffca3cfd468a93c010 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 27 Jun 2026 18:25:53 +0000 Subject: [PATCH 3/3] Apply remaining changes --- test/Test.Ecdh.js | 19 +++++-------------- test/Test.Ecdsa.js | 19 +++++-------------- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/test/Test.Ecdh.js b/test/Test.Ecdh.js index 9ad33e9..fcea4b0 100644 --- a/test/Test.Ecdh.js +++ b/test/Test.Ecdh.js @@ -226,18 +226,9 @@ function ecdhTests() { }); } -var ecdhKeyLengths = { - "P-256": 32, - "P-384": 48, - "P-521": 66, - "BN-254": 32, - "NUMSP256D1": 32, - "NUMSP256T1": 32, - "NUMSP384D1": 48, - "NUMSP384T1": 48, - "NUMSP512D1": 64, - "NUMSP512T1": 64 -}; +function ecdhCurveElementLength(namedCurve) { + return cryptoECC.curveElementLength(namedCurve); +} function ecdhKeyAlg(namedCurve) { return { @@ -250,7 +241,7 @@ var inspectEcdhKey = { public: function(keyObj, algorithm, usages, reason) { var fail = []; - var expLenMax = ecdhKeyLengths[algorithm.namedCurve]; + var expLenMax = ecdhCurveElementLength(algorithm.namedCurve); var expLenMin = expLenMax; // has crv property equal to "P-521" @@ -309,7 +300,7 @@ var inspectEcdhKey = { // } // } - var expLenMax = ecdhKeyLengths[algorithm.namedCurve]; + var expLenMax = ecdhCurveElementLength(algorithm.namedCurve); var expLenMin = expLenMax; this.public(keyObj, algorithm, usages, reason); diff --git a/test/Test.Ecdsa.js b/test/Test.Ecdsa.js index 278386b..56a201a 100644 --- a/test/Test.Ecdsa.js +++ b/test/Test.Ecdsa.js @@ -423,18 +423,9 @@ function ecdsaTests() { }); } -var ecdsaKeyLengths = { - "P-256": 32, - "P-384": 48, - "P-521": 66, - "BN-254": 32, - "NUMSP256D1": 32, - "NUMSP256T1": 32, - "NUMSP384D1": 48, - "NUMSP384T1": 48, - "NUMSP512D1": 64, - "NUMSP512T1": 64 -}; +function ecdsaCurveElementLength(namedCurve) { + return cryptoECC.curveElementLength(namedCurve); +} function ecdsaKeyAlg(curve) { return { @@ -455,7 +446,7 @@ var inspectEcdsaKey = { var fail = []; - var expLenMax = ecdsaKeyLengths[algorithm.namedCurve]; + var expLenMax = ecdsaCurveElementLength(algorithm.namedCurve); var expLenMin = expLenMax; // has crv property equal to "P-521" @@ -498,7 +489,7 @@ var inspectEcdsaKey = { }, private: function(keyObj, algorithm, usages, reason) { - var expLenMax = ecdsaKeyLengths[algorithm.namedCurve]; + var expLenMax = ecdsaCurveElementLength(algorithm.namedCurve); var expLenMin = expLenMax; this.public(keyObj, algorithm, usages, reason);