diff --git a/README.md b/README.md index eba64a6..7a976bf 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ There are following zero-dependency algorithms: - [abstract/weierstrass: Short Weierstrass curve](#abstractweierstrass-short-weierstrass-curve) - [abstract/edwards: Twisted Edwards curve](#abstractedwards-twisted-edwards-curve) - [abstract/montgomery: Montgomery curve](#abstractmontgomery-montgomery-curve) -- [abstract/bls: BLS curves](#abstractbls-bls-curves) +- [abstract/bls: Barreto-Lynn-Scott curves](#abstractbls-barreto-lynn-scott-curves) - [abstract/hash-to-curve: Hashing strings to curve points](#abstracthash-to-curve-hashing-strings-to-curve-points) - [abstract/poseidon: Poseidon hash](#abstractposeidon-poseidon-hash) - [abstract/modular: Modular arithmetics utilities](#abstractmodular-modular-arithmetics-utilities) @@ -452,7 +452,7 @@ Proper Elliptic Curve Points are not implemented yet. You must specify curve params `Fp`, `a`, `Gu` coordinate of u, `montgomeryBits` and `nByteLength`. -### abstract/bls: BLS curves +### abstract/bls: Barreto-Lynn-Scott curves The module abstracts BLS (Barreto-Lynn-Scott) pairing-friendly elliptic curve construction. They allow to construct [zk-SNARKs](https://z.cash/technology/zksnarks/) and diff --git a/test/ed448.test.js b/test/ed448.test.js index c96c07e..42406a9 100644 --- a/test/ed448.test.js +++ b/test/ed448.test.js @@ -566,22 +566,34 @@ describe('ed448', () => { }); should('not verify when sig.s >= CURVE.n', () => { - const privateKey = ed448.utils.randomPrivateKey(); - const message = Uint8Array.from([0xab, 0xbc, 0xcd, 0xde]); - const publicKey = ed448.getPublicKey(privateKey); - const signature = ed448.sign(message, privateKey); - - const R = signature.slice(0, 56); - let s = signature.slice(56, 112); - - s = bytesToHex(s.slice().reverse()); - s = BigInt('0x' + s); - s = s + ed448.CURVE.n; - s = numberToBytesLE(s, 56); - - const sig_invalid = concatBytes(R, s); + function get56bSig() { + const privateKey = ed448.utils.randomPrivateKey(); + const message = Uint8Array.from([0xab, 0xbc, 0xcd, 0xde]); + const publicKey = ed448.getPublicKey(privateKey); + const signature = ed448.sign(message, privateKey); + + const R = signature.slice(0, 56); + let s = signature.slice(56, 112); + + s = bytesToHex(s.slice().reverse()); + s = BigInt('0x' + s); + s = s + ed448.CURVE.n; + s = numberToBytesLE(s, 56); + + const sig_invalid = concatBytes(R, s); + return { sig_invalid, message, publicKey }; + } + let sig; + while (true) { + try { + sig = get56bSig(); + break; + } catch (error) { + // non-56b sig was generated, try again + } + } throws(() => { - ed448.verify(sig_invalid, message, publicKey); + ed448.verify(sig.sig_invalid, sig.message, sig.publicKey); }); });