diff --git a/test/utils/cryptography/P256.test.js b/test/utils/cryptography/P256.test.js index b9655cad3f..f8735420d1 100644 --- a/test/utils/cryptography/P256.test.js +++ b/test/utils/cryptography/P256.test.js @@ -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 () { + 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) {