Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Update features & some fixes #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ edition = "2018"
rand = "0.4"
byteorder = "1"
cfg-if = "1.0"
ff = {package = "ff_ce", version = "0.13.*", features = ["derive"]}
ff = { package = "ff_ce", version = "0.13.*", features = ["derive"] }
# ff = { path = '../ff', package = "ff_ce", features = ["derive"]}

[features]
Expand Down
8 changes: 4 additions & 4 deletions benches/bls12_381/ec.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod g1 {
use rand::{Rand, SeedableRng, XorShiftRng};

use pairing::bls12_381::*;
use pairing::CurveProjective;
use pairing_ce::bls12_381::*;
use pairing_ce::CurveProjective;

#[bench]
fn bench_g1_mul_assign(b: &mut ::test::Bencher) {
Expand Down Expand Up @@ -65,8 +65,8 @@ mod g1 {
mod g2 {
use rand::{Rand, SeedableRng, XorShiftRng};

use pairing::bls12_381::*;
use pairing::CurveProjective;
use pairing_ce::bls12_381::*;
use pairing_ce::CurveProjective;

#[bench]
fn bench_g2_mul_assign(b: &mut ::test::Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion benches/bls12_381/fq.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use ff::{Field, PrimeField, PrimeFieldRepr, SqrtField};
use pairing::bls12_381::*;
use pairing_ce::bls12_381::*;

#[bench]
fn bench_fq_repr_add_nocarry(b: &mut ::test::Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion benches/bls12_381/fq12.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use ff::Field;
use pairing::bls12_381::*;
use pairing_ce::bls12_381::*;

#[bench]
fn bench_fq12_add_assign(b: &mut ::test::Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion benches/bls12_381/fq2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use ff::{Field, SqrtField};
use pairing::bls12_381::*;
use pairing_ce::bls12_381::*;

#[bench]
fn bench_fq2_add_assign(b: &mut ::test::Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion benches/bls12_381/fr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use ff::{Field, PrimeField, PrimeFieldRepr, SqrtField};
use pairing::bls12_381::*;
use pairing_ce::bls12_381::*;

#[bench]
fn bench_fr_repr_add_nocarry(b: &mut ::test::Bencher) {
Expand Down
4 changes: 2 additions & 2 deletions benches/bls12_381/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ mod fr;

use rand::{Rand, SeedableRng, XorShiftRng};

use pairing::bls12_381::*;
use pairing::{CurveAffine, Engine};
use pairing_ce::bls12_381::*;
use pairing_ce::{CurveAffine, Engine};

#[bench]
fn bench_pairing_g1_preparation(b: &mut ::test::Bencher) {
Expand Down
8 changes: 4 additions & 4 deletions benches/bn256/ec.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod g1 {
use rand::{Rand, SeedableRng, XorShiftRng};

use pairing::bn256::*;
use pairing::CurveProjective;
use pairing_ce::bn256::*;
use pairing_ce::CurveProjective;

#[bench]
fn bench_g1_mul_assign(b: &mut ::test::Bencher) {
Expand Down Expand Up @@ -65,8 +65,8 @@ mod g1 {
mod g2 {
use rand::{Rand, SeedableRng, XorShiftRng};

use pairing::bls12_381::*;
use pairing::CurveProjective;
use pairing_ce::bls12_381::*;
use pairing_ce::CurveProjective;

#[bench]
fn bench_g2_mul_assign(b: &mut ::test::Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion benches/bn256/fq.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use ff::{Field, PrimeField, PrimeFieldRepr, SqrtField};
use pairing::bn256::*;
use pairing_ce::bn256::*;

#[bench]
fn bench_fq_repr_add_nocarry(b: &mut ::test::Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion benches/bn256/fq12.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use ff::Field;
use pairing::bn256::*;
use pairing_ce::bn256::*;

#[bench]
fn bench_fq12_add_assign(b: &mut ::test::Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion benches/bn256/fq2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use ff::{Field, SqrtField};
use pairing::bn256::*;
use pairing_ce::bn256::*;

#[bench]
fn bench_fq2_add_assign(b: &mut ::test::Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion benches/bn256/fr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use ff::{Field, PrimeField, PrimeFieldRepr, SqrtField};
use pairing::bn256::*;
use pairing_ce::bn256::*;

#[bench]
fn bench_fr_repr_add_nocarry(b: &mut ::test::Bencher) {
Expand Down
5 changes: 2 additions & 3 deletions benches/bn256/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ mod fq12;
mod fq2;
mod fr;

use pairing_ce::bn256::*;
use pairing_ce::{CurveAffine, Engine};
use rand::{Rand, SeedableRng, XorShiftRng};

use pairing::bn256::*;
use pairing::{CurveAffine, Engine};

#[bench]
fn bench_pairing_g1_preparation(b: &mut ::test::Bencher) {
const SAMPLES: usize = 1000;
Expand Down
18 changes: 9 additions & 9 deletions src/bls12_381/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn test_pairing_result_against_relic() {
0F41E58663BF08CF 068672CBD01A7EC7 3BACA4D72CA93544 DEFF686BFD6DF543 D48EAA24AFE47E1E FDE449383B676631
*/

assert_eq!(Bls12::pairing(G1::one(), G2::one()), Fq12 {
assert_eq!(Bls12::pairing(<G1 as GenericCurveProjective>::one(), <G2 as GenericCurveProjective>::one()), Fq12 {
c0: Fq6 {
c0: Fq2 {
c0: Fq::from_str("2819105605953691245277803056322684086884703000473961065716485506033588504203831029066448642358042597501014294104502").unwrap(),
Expand Down Expand Up @@ -99,7 +99,7 @@ fn test_g2_compressed_valid_vectors() {
#[test]
fn test_g1_uncompressed_invalid_vectors() {
{
let z = G1Affine::zero().into_uncompressed();
let z = <G1Affine as CurveAffine>::zero().into_uncompressed();

{
let mut z = z;
Expand Down Expand Up @@ -132,7 +132,7 @@ fn test_g1_uncompressed_invalid_vectors() {
}
}

let o = G1Affine::one().into_uncompressed();
let o = <G1Affine as CurveAffine>::one().into_uncompressed();

{
let mut o = o;
Expand Down Expand Up @@ -213,7 +213,7 @@ fn test_g1_uncompressed_invalid_vectors() {
#[test]
fn test_g2_uncompressed_invalid_vectors() {
{
let z = G2Affine::zero().into_uncompressed();
let z = <G2Affine as CurveAffine>::zero().into_uncompressed();

{
let mut z = z;
Expand Down Expand Up @@ -246,7 +246,7 @@ fn test_g2_uncompressed_invalid_vectors() {
}
}

let o = G2Affine::one().into_uncompressed();
let o = <G2Affine as CurveAffine>::one().into_uncompressed();

{
let mut o = o;
Expand Down Expand Up @@ -355,7 +355,7 @@ fn test_g2_uncompressed_invalid_vectors() {
#[test]
fn test_g1_compressed_invalid_vectors() {
{
let z = G1Affine::zero().into_compressed();
let z = <G1Affine as CurveAffine>::zero().into_compressed();

{
let mut z = z;
Expand Down Expand Up @@ -388,7 +388,7 @@ fn test_g1_compressed_invalid_vectors() {
}
}

let o = G1Affine::one().into_compressed();
let o = <G1Affine as CurveAffine>::one().into_compressed();

{
let mut o = o;
Expand Down Expand Up @@ -471,7 +471,7 @@ fn test_g1_compressed_invalid_vectors() {
#[test]
fn test_g2_compressed_invalid_vectors() {
{
let z = G2Affine::zero().into_compressed();
let z = <G2Affine as CurveAffine>::zero().into_compressed();

{
let mut z = z;
Expand Down Expand Up @@ -504,7 +504,7 @@ fn test_g2_compressed_invalid_vectors() {
}
}

let o = G2Affine::one().into_compressed();
let o = <G2Affine as CurveAffine>::one().into_compressed();

{
let mut o = o;
Expand Down
25 changes: 13 additions & 12 deletions src/bn256/fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ff::{Field, PrimeField, PrimeFieldRepr};
cfg_if::cfg_if! {
if #[cfg(feature = "asm")] {
use ff::PrimeFieldAsm;
use std::arch::asm;

#[derive(PrimeFieldAsm)]
#[PrimeFieldModulus = "21888242871839275222246405745257275088696311157297823662689037894645226208583"]
Expand Down Expand Up @@ -62,11 +63,11 @@ pub const G1_GENERATOR_Y: Fq = Fq(FqRepr([
]));

// Generator of G2
//
// x = 11559732032986387107991004021392285783925812861821192530917403151452391805634*u
//
// x = 11559732032986387107991004021392285783925812861821192530917403151452391805634*u
// + 10857046999023057135944570762232829481370756359578518086990519993285655852781
//
// y = 4082367875863433681332203403145435568316851327593401208105741076214120093531*u
// y = 4082367875863433681332203403145435568316851327593401208105741076214120093531*u
// + 8495653923123431417604973247489272438418190587263600148770280649306958101930

pub const G2_GENERATOR_X_C0: Fq = Fq(FqRepr([
Expand Down Expand Up @@ -117,15 +118,15 @@ pub const FROBENIUS_COEFF_FQ2_C1: [Fq; 2] = [
// Fq2(u + 9)**(((q^1) - 1) / 2)
pub const XI_TO_Q_MINUS_1_OVER_2: Fq2 = Fq2 {
c0: Fq(FqRepr([
0xe4bbdd0c2936b629,
0xbb30f162e133bacb,
0x31a9d1b6f9645366,
0xe4bbdd0c2936b629,
0xbb30f162e133bacb,
0x31a9d1b6f9645366,
0x253570bea500f8dd,
])),
c1: Fq(FqRepr([
0xa1d77ce45ffe77c7,
0x07affd117826d1db,
0x6d16bd27bb7edc6b,
0xa1d77ce45ffe77c7,
0x07affd117826d1db,
0x6d16bd27bb7edc6b,
0x2c87200285defecc,
])),
};
Expand All @@ -151,9 +152,9 @@ pub const FROBENIUS_COEFF_FQ6_C1: [Fq2; 6] = [
0x1956bcd8118214ec,
])),
c1: Fq(FqRepr([
0x6e849f1ea0aa4757,
0xaa1c7b6d89f89141,
0xb6e713cdfae0ca3a,
0x6e849f1ea0aa4757,
0xaa1c7b6d89f89141,
0xb6e713cdfae0ca3a,
0x26694fbb4e82ebc3,
])),
},
Expand Down
3 changes: 2 additions & 1 deletion src/bn256/fr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use ff::{Field, PrimeField, PrimeFieldRepr};
cfg_if::cfg_if! {
if #[cfg(feature = "asm")] {
use ff::PrimeFieldAsm;

use std::arch::asm;

#[derive(PrimeFieldAsm)]
#[PrimeFieldModulus = "21888242871839275222246405745257275088548364400416034343698204186575808495617"]
#[PrimeFieldGenerator = "7"]
Expand Down
14 changes: 7 additions & 7 deletions src/bn256/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ pub const BN_U: u64 = 4965661367192848881;
pub const SIX_U_PLUS_2_NAF : [i8; 65] = [
0, 0, 0, 1, 0, 1, 0, -1,
0, 0, 1, -1, 0, 0, 1, 0,
0, 1, 1, 0, -1, 0, 0, 1,
0, 1, 1, 0, -1, 0, 0, 1,
0, -1, 0, 0, 0, 0, 1, 1,
1, 0, 0, -1, 0, 0, 1, 0,
1, 0, 0, -1, 0, 0, 1, 0,
0, 0, 0, 0, -1, 0, 0, 1,
1, 0, 0, -1, 0, 0, 0, 1,
1, 0, -1, 0, 0, 1, 0, 1,
1, 0, 0, -1, 0, 0, 0, 1,
1, 0, -1, 0, 0, 1, 0, 1,
1];


Expand Down Expand Up @@ -83,7 +83,7 @@ impl Engine for Bn256 {
}

let mut f = Fq12::one();

for i in (1..SIX_U_PLUS_2_NAF.len()).rev() {
if i != SIX_U_PLUS_2_NAF.len() - 1 {
f.square();
Expand Down Expand Up @@ -401,7 +401,7 @@ impl G2Prepared {

let mut ztsquared = r.z;
ztsquared.square();

t10.sub_assign(&ztsquared);

// corresponds to line 18
Expand Down Expand Up @@ -472,7 +472,7 @@ use rand::{Rand, SeedableRng, XorShiftRng};
fn test_pairing() {
use crate::{CurveProjective};
let mut g1 = G1::one();

let mut g2 = G2::one();
g2.double();

Expand Down
Loading