Replace Fq implementation with bls12_381::Scalar

This commit is contained in:
Jack Grigg 2019-11-26 19:15:57 +00:00
parent e2e0f5089f
commit 4c1da9d8bc
No known key found for this signature in database
GPG Key ID: 9E8255172BBF9898
5 changed files with 42 additions and 1092 deletions

View File

@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1 - uses: actions-rs/toolchain@v1
with: with:
toolchain: 1.33.0 toolchain: 1.36.0
override: true override: true
# Ensure all code has been formatted with rustfmt # Ensure all code has been formatted with rustfmt
@ -33,7 +33,7 @@ jobs:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1 - uses: actions-rs/toolchain@v1
with: with:
toolchain: 1.33.0 toolchain: 1.36.0
override: true override: true
- name: cargo fetch - name: cargo fetch
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
@ -58,7 +58,7 @@ jobs:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1 - uses: actions-rs/toolchain@v1
with: with:
toolchain: 1.33.0 toolchain: 1.36.0
override: true override: true
- run: rustup target add thumbv6m-none-eabi - run: rustup target add thumbv6m-none-eabi
- name: cargo fetch - name: cargo fetch

View File

@ -13,6 +13,10 @@ repository = "https://github.com/zkcrypto/jubjub"
version = "0.2.0" version = "0.2.0"
edition = "2018" edition = "2018"
[dependencies.bls12_381]
version = "0.1"
default-features = false
[dependencies.byteorder] [dependencies.byteorder]
version = "1" version = "1"
default-features = false default-features = false

View File

@ -8,7 +8,7 @@
This is a pure Rust implementation of the Jubjub elliptic curve group and its associated fields. This is a pure Rust implementation of the Jubjub elliptic curve group and its associated fields.
* **This implementation has not been reviewed or audited. Use at your own risk.** * **This implementation has not been reviewed or audited. Use at your own risk.**
* This implementation targets Rust `1.33` or later. * This implementation targets Rust `1.36` or later.
* All operations are constant time unless explicitly noted. * All operations are constant time unless explicitly noted.
## Features ## Features

1053
src/fq.rs

File diff suppressed because it is too large Load Diff

View File

@ -43,9 +43,8 @@ use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
#[macro_use] #[macro_use]
mod util; mod util;
mod fq;
mod fr; mod fr;
pub use fq::Fq; pub use bls12_381::Scalar as Fq;
pub use fr::Fr; pub use fr::Fr;
const FR_MODULUS_BYTES: [u8; 32] = [ const FR_MODULUS_BYTES: [u8; 32] = [
@ -463,9 +462,9 @@ impl AffinePoint {
/// for use in multiple additions. /// for use in multiple additions.
pub const fn to_niels(&self) -> AffineNielsPoint { pub const fn to_niels(&self) -> AffineNielsPoint {
AffineNielsPoint { AffineNielsPoint {
v_plus_u: self.v.field_add(&self.u), v_plus_u: Fq::add(&self.v, &self.u),
v_minus_u: self.v.subtract(&self.u), v_minus_u: Fq::sub(&self.v, &self.u),
t2d: self.u.multiply(&self.v).multiply(&EDWARDS_D2), t2d: Fq::mul(&Fq::mul(&self.u, &self.v), &EDWARDS_D2),
} }
} }
@ -953,17 +952,17 @@ fn test_extended_niels_point_identity() {
#[test] #[test]
fn test_assoc() { fn test_assoc() {
let p = ExtendedPoint::from(AffinePoint { let p = ExtendedPoint::from(AffinePoint {
u: Fq([ u: Fq::from_raw([
0xc0115cb656ae4839, 0x81c571e5d883cfb0,
0x623dc3ff81d64c26, 0x049f7a686f147029,
0x5868e739b5794f2c, 0xf539c860bc3ea21f,
0x23bd4fbb18d39c9c, 0x4284715b7ccc8162,
]), ]),
v: Fq([ v: Fq::from_raw([
0x7588ee6d6dd40deb, 0xbf096275684bb8ca,
0x9d6d7a23ebdb7c4c, 0xc7ba245890af256d,
0x46462e26d4edb8c7, 0x59119f3e86380eb0,
0x10b4c1517ca82e9b, 0x3793de182f9fb1d2,
]), ]),
}) })
.mul_by_cofactor(); .mul_by_cofactor();
@ -979,17 +978,17 @@ fn test_assoc() {
#[test] #[test]
fn test_batch_normalize() { fn test_batch_normalize() {
let mut p = ExtendedPoint::from(AffinePoint { let mut p = ExtendedPoint::from(AffinePoint {
u: Fq([ u: Fq::from_raw([
0xc0115cb656ae4839, 0x81c571e5d883cfb0,
0x623dc3ff81d64c26, 0x049f7a686f147029,
0x5868e739b5794f2c, 0xf539c860bc3ea21f,
0x23bd4fbb18d39c9c, 0x4284715b7ccc8162,
]), ]),
v: Fq([ v: Fq::from_raw([
0x7588ee6d6dd40deb, 0xbf096275684bb8ca,
0x9d6d7a23ebdb7c4c, 0xc7ba245890af256d,
0x46462e26d4edb8c7, 0x59119f3e86380eb0,
0x10b4c1517ca82e9b, 0x3793de182f9fb1d2,
]), ]),
}) })
.mul_by_cofactor(); .mul_by_cofactor();
@ -1214,17 +1213,17 @@ fn test_mul_consistency() {
]); ]);
assert_eq!(a * b, c); assert_eq!(a * b, c);
let p = ExtendedPoint::from(AffinePoint { let p = ExtendedPoint::from(AffinePoint {
u: Fq([ u: Fq::from_raw([
0xc0115cb656ae4839, 0x81c571e5d883cfb0,
0x623dc3ff81d64c26, 0x049f7a686f147029,
0x5868e739b5794f2c, 0xf539c860bc3ea21f,
0x23bd4fbb18d39c9c, 0x4284715b7ccc8162,
]), ]),
v: Fq([ v: Fq::from_raw([
0x7588ee6d6dd40deb, 0xbf096275684bb8ca,
0x9d6d7a23ebdb7c4c, 0xc7ba245890af256d,
0x46462e26d4edb8c7, 0x59119f3e86380eb0,
0x10b4c1517ca82e9b, 0x3793de182f9fb1d2,
]), ]),
}) })
.mul_by_cofactor(); .mul_by_cofactor();