start migrating to edition 2018
This commit is contained in:
parent
76c2d3451f
commit
1dae6b69db
@ -22,11 +22,7 @@ rand = "0.4"
|
|||||||
byteorder = "1"
|
byteorder = "1"
|
||||||
#ff_ce = {version = "0.6", features = ["derive"] }
|
#ff_ce = {version = "0.6", features = ["derive"] }
|
||||||
#ff_ce = { git = 'https://github.com/matter-labs/ff', features = ["derive"], branch = "gpu"}
|
#ff_ce = { git = 'https://github.com/matter-labs/ff', features = ["derive"], branch = "gpu"}
|
||||||
ff_ce = { path = '../ff', features = ["derive", "derive_serde"]}
|
ff = { path = '../ff', package = "ff_ce", features = ["derive"]}
|
||||||
serde = "1.0.80"
|
|
||||||
serde_derive = "1.0.80"
|
|
||||||
serde_json = "1.0.33"
|
|
||||||
hex = "0.3.2"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
unstable-features = ["expose-arith"]
|
unstable-features = ["expose-arith"]
|
||||||
|
@ -753,10 +753,12 @@ pub mod g1 {
|
|||||||
impl RawEncodable for G1Affine {
|
impl RawEncodable for G1Affine {
|
||||||
fn into_raw_uncompressed_le(&self) -> Self::Uncompressed {
|
fn into_raw_uncompressed_le(&self) -> Self::Uncompressed {
|
||||||
let mut res = Self::Uncompressed::empty();
|
let mut res = Self::Uncompressed::empty();
|
||||||
|
{
|
||||||
let mut writer = &mut res.0[..];
|
let mut writer = &mut res.0[..];
|
||||||
|
|
||||||
self.x.into_raw_repr().write_le(&mut writer).unwrap();
|
self.x.into_raw_repr().write_le(&mut writer).unwrap();
|
||||||
self.y.into_raw_repr().write_le(&mut writer).unwrap();
|
self.y.into_raw_repr().write_le(&mut writer).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
@ -645,10 +645,12 @@ pub mod g1 {
|
|||||||
impl RawEncodable for G1Affine {
|
impl RawEncodable for G1Affine {
|
||||||
fn into_raw_uncompressed_le(&self) -> Self::Uncompressed {
|
fn into_raw_uncompressed_le(&self) -> Self::Uncompressed {
|
||||||
let mut res = Self::Uncompressed::empty();
|
let mut res = Self::Uncompressed::empty();
|
||||||
|
{
|
||||||
let mut writer = &mut res.0[..];
|
let mut writer = &mut res.0[..];
|
||||||
|
|
||||||
self.x.into_raw_repr().write_le(&mut writer).unwrap();
|
self.x.into_raw_repr().write_le(&mut writer).unwrap();
|
||||||
self.y.into_raw_repr().write_le(&mut writer).unwrap();
|
self.y.into_raw_repr().write_le(&mut writer).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
@ -1078,25 +1080,6 @@ pub mod g2 {
|
|||||||
G1Affine
|
G1Affine
|
||||||
);
|
);
|
||||||
|
|
||||||
// impl Rand for G2 {
|
|
||||||
// fn rand<R: Rng>(rng: &mut R) -> Self {
|
|
||||||
|
|
||||||
// let mut r = G2::one();
|
|
||||||
// let k = Fr::rand(rng);
|
|
||||||
// r.mul_assign(k);
|
|
||||||
// return r;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl Rand for G2Affine {
|
|
||||||
// fn rand<R: Rng>(rng: &mut R) -> Self {
|
|
||||||
// let mut r = G2::one();
|
|
||||||
// let k = Fr::rand(rng);
|
|
||||||
// r.mul_assign(k);
|
|
||||||
// return r.into_affine();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
impl Rand for G2 {
|
impl Rand for G2 {
|
||||||
fn rand<R: Rng>(rng: &mut R) -> Self {
|
fn rand<R: Rng>(rng: &mut R) -> Self {
|
||||||
loop {
|
loop {
|
||||||
@ -1471,6 +1454,50 @@ pub mod g2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_generate_g2_in_subgroup() {
|
||||||
|
use SqrtField;
|
||||||
|
|
||||||
|
let mut x = Fq2::zero();
|
||||||
|
loop {
|
||||||
|
// y^2 = x^3 + b
|
||||||
|
let mut rhs = x;
|
||||||
|
rhs.square();
|
||||||
|
rhs.mul_assign(&x);
|
||||||
|
rhs.add_assign(&G2Affine::get_coeff_b());
|
||||||
|
|
||||||
|
if let Some(y) = rhs.sqrt() {
|
||||||
|
let mut negy = y;
|
||||||
|
negy.negate();
|
||||||
|
|
||||||
|
let p = G2Affine {
|
||||||
|
x: x,
|
||||||
|
y: if y < negy { y } else { negy },
|
||||||
|
infinity: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
let g2 = p.into_projective();
|
||||||
|
let mut minus_one = Fr::one();
|
||||||
|
minus_one.negate();
|
||||||
|
|
||||||
|
let mut expected_zero = p.mul(minus_one);
|
||||||
|
expected_zero.add_assign(&g2);
|
||||||
|
|
||||||
|
if !expected_zero.is_zero() {
|
||||||
|
let p = expected_zero.into_affine();
|
||||||
|
let scaled_by_cofactor = p.scale_by_cofactor();
|
||||||
|
if scaled_by_cofactor.is_zero() {
|
||||||
|
let g2 = G2Affine::from(expected_zero);
|
||||||
|
println!("Invalid subgroup point = {}", g2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
x.add_assign(&Fq2::one());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use rand::{SeedableRng, XorShiftRng};
|
use rand::{SeedableRng, XorShiftRng};
|
||||||
|
|
||||||
|
10
src/lib.rs
10
src/lib.rs
@ -14,21 +14,13 @@
|
|||||||
extern crate byteorder;
|
extern crate byteorder;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
|
|
||||||
extern crate hex;
|
|
||||||
extern crate serde;
|
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests;
|
pub mod tests;
|
||||||
|
|
||||||
pub extern crate ff_ce as ff;
|
pub extern crate ff;
|
||||||
|
|
||||||
pub use ff::*;
|
pub use ff::*;
|
||||||
|
|
||||||
// pub mod ff {
|
|
||||||
// pub use ff::*;
|
|
||||||
// }
|
|
||||||
|
|
||||||
pub mod bls12_381;
|
pub mod bls12_381;
|
||||||
pub mod bn256;
|
pub mod bn256;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user