Skip to content

Commit

Permalink
add test case with cunsupported private keys in the P256 unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Sep 25, 2024
1 parent cc6ccb5 commit c12fbbd
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/utils/cryptography/P256.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,27 @@ describe('P256', function () {
});
});

describe('edge cases', function () {
// In theory, all private keys between 1 and P256.N-1 should be supported. However, the `_jAdd` limitation,
// that indirectly affects `_preComputeJacobianPoints` causes issues for some private/public key pairs
//
// In particular, the following key pairs are not supported:
// * private = 1 (P = G)
// * private = 2 (P = 2G)
// * private = 3 (P = 3G)
// * private = N - 3 (P = -3G)
// * private = N - 2 (P = -2G)
// * private = N - 1 (P = -G)
for (const privateKey of [1n, 2n, 3n, -3n, -2n, -1n]) {
it(`unsuported case: P = ${privateKey} * G`, async function () {

Check failure on line 135 in test/utils/cryptography/P256.test.js

View workflow job for this annotation

GitHub Actions / codespell

unsuported ==> unsupported
const { messageHash, signature, publicKey } = prepareSignature(
privateKey < 0 ? privateKey + secp256r1.CURVE.n : privateKey,
);
expect(await this.mock.$verifySolidity(messageHash, ...signature, ...publicKey)).to.be.false;
});
}
});

// test cases for https://github.com/C2SP/wycheproof/blob/4672ff74d68766e7785c2cac4c597effccef2c5c/testvectors/ecdsa_secp256r1_sha256_p1363_test.json
describe('wycheproof tests', function () {
for (const { key, tests } of require('./ecdsa_secp256r1_sha256_p1363_test.json').testGroups) {
Expand Down

0 comments on commit c12fbbd

Please sign in to comment.