Fix tests

This commit is contained in:
Paul Miller 2023-04-02 14:50:27 +00:00
parent 31d92cce11
commit d424c661fb
No known key found for this signature in database
GPG Key ID: 697079DA6878B89B
2 changed files with 29 additions and 17 deletions

@ -174,7 +174,7 @@ There are following zero-dependency algorithms:
- [abstract/weierstrass: Short Weierstrass curve](#abstractweierstrass-short-weierstrass-curve) - [abstract/weierstrass: Short Weierstrass curve](#abstractweierstrass-short-weierstrass-curve)
- [abstract/edwards: Twisted Edwards curve](#abstractedwards-twisted-edwards-curve) - [abstract/edwards: Twisted Edwards curve](#abstractedwards-twisted-edwards-curve)
- [abstract/montgomery: Montgomery curve](#abstractmontgomery-montgomery-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/hash-to-curve: Hashing strings to curve points](#abstracthash-to-curve-hashing-strings-to-curve-points)
- [abstract/poseidon: Poseidon hash](#abstractposeidon-poseidon-hash) - [abstract/poseidon: Poseidon hash](#abstractposeidon-poseidon-hash)
- [abstract/modular: Modular arithmetics utilities](#abstractmodular-modular-arithmetics-utilities) - [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`. 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. The module abstracts BLS (Barreto-Lynn-Scott) pairing-friendly elliptic curve construction.
They allow to construct [zk-SNARKs](https://z.cash/technology/zksnarks/) and They allow to construct [zk-SNARKs](https://z.cash/technology/zksnarks/) and

@ -566,22 +566,34 @@ describe('ed448', () => {
}); });
should('not verify when sig.s >= CURVE.n', () => { should('not verify when sig.s >= CURVE.n', () => {
const privateKey = ed448.utils.randomPrivateKey(); function get56bSig() {
const message = Uint8Array.from([0xab, 0xbc, 0xcd, 0xde]); const privateKey = ed448.utils.randomPrivateKey();
const publicKey = ed448.getPublicKey(privateKey); const message = Uint8Array.from([0xab, 0xbc, 0xcd, 0xde]);
const signature = ed448.sign(message, privateKey); const publicKey = ed448.getPublicKey(privateKey);
const signature = ed448.sign(message, privateKey);
const R = signature.slice(0, 56);
let s = signature.slice(56, 112); const R = signature.slice(0, 56);
let s = signature.slice(56, 112);
s = bytesToHex(s.slice().reverse());
s = BigInt('0x' + s); s = bytesToHex(s.slice().reverse());
s = s + ed448.CURVE.n; s = BigInt('0x' + s);
s = numberToBytesLE(s, 56); s = s + ed448.CURVE.n;
s = numberToBytesLE(s, 56);
const sig_invalid = concatBytes(R, s);
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(() => { throws(() => {
ed448.verify(sig_invalid, message, publicKey); ed448.verify(sig.sig_invalid, sig.message, sig.publicKey);
}); });
}); });