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

View File

@ -13,6 +13,10 @@ repository = "https://github.com/zkcrypto/jubjub"
version = "0.2.0"
edition = "2018"
[dependencies.bls12_381]
version = "0.1"
default-features = false
[dependencies.byteorder]
version = "1"
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 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.
## 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]
mod util;
mod fq;
mod fr;
pub use fq::Fq;
pub use bls12_381::Scalar as Fq;
pub use fr::Fr;
const FR_MODULUS_BYTES: [u8; 32] = [
@ -463,9 +462,9 @@ impl AffinePoint {
/// for use in multiple additions.
pub const fn to_niels(&self) -> AffineNielsPoint {
AffineNielsPoint {
v_plus_u: self.v.field_add(&self.u),
v_minus_u: self.v.subtract(&self.u),
t2d: self.u.multiply(&self.v).multiply(&EDWARDS_D2),
v_plus_u: Fq::add(&self.v, &self.u),
v_minus_u: Fq::sub(&self.v, &self.u),
t2d: Fq::mul(&Fq::mul(&self.u, &self.v), &EDWARDS_D2),
}
}
@ -953,17 +952,17 @@ fn test_extended_niels_point_identity() {
#[test]
fn test_assoc() {
let p = ExtendedPoint::from(AffinePoint {
u: Fq([
0xc0115cb656ae4839,
0x623dc3ff81d64c26,
0x5868e739b5794f2c,
0x23bd4fbb18d39c9c,
u: Fq::from_raw([
0x81c571e5d883cfb0,
0x049f7a686f147029,
0xf539c860bc3ea21f,
0x4284715b7ccc8162,
]),
v: Fq([
0x7588ee6d6dd40deb,
0x9d6d7a23ebdb7c4c,
0x46462e26d4edb8c7,
0x10b4c1517ca82e9b,
v: Fq::from_raw([
0xbf096275684bb8ca,
0xc7ba245890af256d,
0x59119f3e86380eb0,
0x3793de182f9fb1d2,
]),
})
.mul_by_cofactor();
@ -979,17 +978,17 @@ fn test_assoc() {
#[test]
fn test_batch_normalize() {
let mut p = ExtendedPoint::from(AffinePoint {
u: Fq([
0xc0115cb656ae4839,
0x623dc3ff81d64c26,
0x5868e739b5794f2c,
0x23bd4fbb18d39c9c,
u: Fq::from_raw([
0x81c571e5d883cfb0,
0x049f7a686f147029,
0xf539c860bc3ea21f,
0x4284715b7ccc8162,
]),
v: Fq([
0x7588ee6d6dd40deb,
0x9d6d7a23ebdb7c4c,
0x46462e26d4edb8c7,
0x10b4c1517ca82e9b,
v: Fq::from_raw([
0xbf096275684bb8ca,
0xc7ba245890af256d,
0x59119f3e86380eb0,
0x3793de182f9fb1d2,
]),
})
.mul_by_cofactor();
@ -1214,17 +1213,17 @@ fn test_mul_consistency() {
]);
assert_eq!(a * b, c);
let p = ExtendedPoint::from(AffinePoint {
u: Fq([
0xc0115cb656ae4839,
0x623dc3ff81d64c26,
0x5868e739b5794f2c,
0x23bd4fbb18d39c9c,
u: Fq::from_raw([
0x81c571e5d883cfb0,
0x049f7a686f147029,
0xf539c860bc3ea21f,
0x4284715b7ccc8162,
]),
v: Fq([
0x7588ee6d6dd40deb,
0x9d6d7a23ebdb7c4c,
0x46462e26d4edb8c7,
0x10b4c1517ca82e9b,
v: Fq::from_raw([
0xbf096275684bb8ca,
0xc7ba245890af256d,
0x59119f3e86380eb0,
0x3793de182f9fb1d2,
]),
})
.mul_by_cofactor();