group: Renaming prior to trait refactor
This will reduce the size of the subsequent refactor diff.
This commit is contained in:
parent
df13cd7480
commit
d52053d877
|
@ -12,7 +12,7 @@
|
||||||
//! [Groth16]: https://eprint.iacr.org/2016/260
|
//! [Groth16]: https://eprint.iacr.org/2016/260
|
||||||
|
|
||||||
use ff::PrimeField;
|
use ff::PrimeField;
|
||||||
use group::CurveProjective;
|
use group::CofactorCurve;
|
||||||
|
|
||||||
use super::SynthesisError;
|
use super::SynthesisError;
|
||||||
|
|
||||||
|
@ -196,23 +196,23 @@ pub trait Group<Scalar: PrimeField>: Sized + Copy + Clone + Send + Sync {
|
||||||
fn group_sub_assign(&mut self, other: &Self);
|
fn group_sub_assign(&mut self, other: &Self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Point<G: CurveProjective>(pub G);
|
pub struct Point<G: CofactorCurve>(pub G);
|
||||||
|
|
||||||
impl<G: CurveProjective> PartialEq for Point<G> {
|
impl<G: CofactorCurve> PartialEq for Point<G> {
|
||||||
fn eq(&self, other: &Point<G>) -> bool {
|
fn eq(&self, other: &Point<G>) -> bool {
|
||||||
self.0 == other.0
|
self.0 == other.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: CurveProjective> Copy for Point<G> {}
|
impl<G: CofactorCurve> Copy for Point<G> {}
|
||||||
|
|
||||||
impl<G: CurveProjective> Clone for Point<G> {
|
impl<G: CofactorCurve> Clone for Point<G> {
|
||||||
fn clone(&self) -> Point<G> {
|
fn clone(&self) -> Point<G> {
|
||||||
*self
|
*self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: CurveProjective> Group<G::Scalar> for Point<G> {
|
impl<G: CofactorCurve> Group<G::Scalar> for Point<G> {
|
||||||
fn group_zero() -> Self {
|
fn group_zero() -> Self {
|
||||||
Point(G::identity())
|
Point(G::identity())
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::ops::{AddAssign, MulAssign};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use ff::{Field, PrimeField};
|
use ff::{Field, PrimeField};
|
||||||
use group::{CurveAffine, CurveProjective, Group, Wnaf};
|
use group::{CurveAffine, CofactorCurve, Group, Wnaf};
|
||||||
use pairing::Engine;
|
use pairing::Engine;
|
||||||
|
|
||||||
use super::{Parameters, VerifyingKey};
|
use super::{Parameters, VerifyingKey};
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::sync::Arc;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
|
|
||||||
use ff::{Field, PrimeField};
|
use ff::{Field, PrimeField};
|
||||||
use group::{CurveAffine, CurveProjective};
|
use group::{CurveAffine, CofactorCurve};
|
||||||
use pairing::Engine;
|
use pairing::Engine;
|
||||||
|
|
||||||
use super::{ParameterSource, Proof};
|
use super::{ParameterSource, Proof};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use ff::{Field, PrimeField};
|
use ff::{Field, PrimeField};
|
||||||
use group::{CurveAffine, CurveProjective, Group, GroupEncoding, PrimeGroup, UncompressedEncoding};
|
use group::{CurveAffine, CofactorCurve, Group, GroupEncoding, PrimeGroup, UncompressedEncoding};
|
||||||
use pairing::{Engine, MillerLoopResult, MultiMillerLoop, PairingCurveAffine};
|
use pairing::{Engine, MillerLoopResult, MultiMillerLoop, PairingCurveAffine};
|
||||||
|
|
||||||
use rand_core::RngCore;
|
use rand_core::RngCore;
|
||||||
|
@ -393,7 +393,7 @@ impl Group for Fr {
|
||||||
|
|
||||||
impl PrimeGroup for Fr {}
|
impl PrimeGroup for Fr {}
|
||||||
|
|
||||||
impl CurveProjective for Fr {
|
impl CofactorCurve for Fr {
|
||||||
type Affine = Fr;
|
type Affine = Fr;
|
||||||
|
|
||||||
fn to_affine(&self) -> Fr {
|
fn to_affine(&self) -> Fr {
|
||||||
|
@ -425,7 +425,7 @@ impl AsRef<[u8]> for FakePoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CurveAffine for Fr {
|
impl CurveAffine for Fr {
|
||||||
type Projective = Fr;
|
type Curve = Fr;
|
||||||
type Scalar = Fr;
|
type Scalar = Fr;
|
||||||
|
|
||||||
fn identity() -> Self {
|
fn identity() -> Self {
|
||||||
|
@ -440,7 +440,7 @@ impl CurveAffine for Fr {
|
||||||
Choice::from(if <Fr as Field>::is_zero(self) { 1 } else { 0 })
|
Choice::from(if <Fr as Field>::is_zero(self) { 1 } else { 0 })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_projective(&self) -> Self::Projective {
|
fn to_curve(&self) -> Self::Curve {
|
||||||
*self
|
*self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use group::{CurveAffine, CurveProjective};
|
use group::{CurveAffine, CofactorCurve};
|
||||||
use pairing::{MillerLoopResult, MultiMillerLoop};
|
use pairing::{MillerLoopResult, MultiMillerLoop};
|
||||||
use std::ops::{AddAssign, Neg};
|
use std::ops::{AddAssign, Neg};
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ pub fn verify_proof<'a, E: MultiMillerLoop>(
|
||||||
return Err(SynthesisError::MalformedVerifyingKey);
|
return Err(SynthesisError::MalformedVerifyingKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut acc = pvk.ic[0].to_projective();
|
let mut acc = pvk.ic[0].to_curve();
|
||||||
|
|
||||||
for (i, b) in public_inputs.iter().zip(pvk.ic.iter().skip(1)) {
|
for (i, b) in public_inputs.iter().zip(pvk.ic.iter().skip(1)) {
|
||||||
AddAssign::<&E::G1>::add_assign(&mut acc, &(*b * i));
|
AddAssign::<&E::G1>::add_assign(&mut acc, &(*b * i));
|
||||||
|
|
|
@ -2,7 +2,7 @@ use super::multicore::Worker;
|
||||||
use bit_vec::{self, BitVec};
|
use bit_vec::{self, BitVec};
|
||||||
use ff::{Endianness, Field, PrimeField};
|
use ff::{Endianness, Field, PrimeField};
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use group::{CurveAffine, CurveProjective};
|
use group::{CofactorCurve, CurveAffine};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::ops::AddAssign;
|
use std::ops::AddAssign;
|
||||||
|
@ -25,17 +25,17 @@ pub trait Source<G: CurveAffine> {
|
||||||
fn skip(&mut self, amt: usize) -> Result<(), SynthesisError>;
|
fn skip(&mut self, amt: usize) -> Result<(), SynthesisError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait AddAssignFromSource: CurveProjective {
|
pub trait AddAssignFromSource: CofactorCurve {
|
||||||
/// Parses the element from the source. Fails if the point is at infinity.
|
/// Parses the element from the source. Fails if the point is at infinity.
|
||||||
fn add_assign_from_source<S: Source<<Self as CurveProjective>::Affine>>(
|
fn add_assign_from_source<S: Source<<Self as CofactorCurve>::Affine>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
source: &mut S,
|
source: &mut S,
|
||||||
) -> Result<(), SynthesisError> {
|
) -> Result<(), SynthesisError> {
|
||||||
AddAssign::<&<Self as CurveProjective>::Affine>::add_assign(self, source.next()?);
|
AddAssign::<&<Self as CofactorCurve>::Affine>::add_assign(self, source.next()?);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<G> AddAssignFromSource for G where G: CurveProjective {}
|
impl<G> AddAssignFromSource for G where G: CofactorCurve {}
|
||||||
|
|
||||||
impl<G: CurveAffine> SourceBuilder<G> for (Arc<Vec<G>>, usize) {
|
impl<G: CurveAffine> SourceBuilder<G> for (Arc<Vec<G>>, usize) {
|
||||||
type Source = (Arc<Vec<G>>, usize);
|
type Source = (Arc<Vec<G>>, usize);
|
||||||
|
@ -162,8 +162,8 @@ fn multiexp_inner<Q, D, G, S>(
|
||||||
where
|
where
|
||||||
for<'a> &'a Q: QueryDensity,
|
for<'a> &'a Q: QueryDensity,
|
||||||
D: Send + Sync + 'static + Clone + AsRef<Q>,
|
D: Send + Sync + 'static + Clone + AsRef<Q>,
|
||||||
G: CurveProjective,
|
G: CofactorCurve,
|
||||||
S: SourceBuilder<<G as CurveProjective>::Affine>,
|
S: SourceBuilder<<G as CofactorCurve>::Affine>,
|
||||||
{
|
{
|
||||||
// Perform this region of the multiexp
|
// Perform this region of the multiexp
|
||||||
let this = {
|
let this = {
|
||||||
|
@ -274,8 +274,8 @@ pub fn multiexp<Q, D, G, S>(
|
||||||
where
|
where
|
||||||
for<'a> &'a Q: QueryDensity,
|
for<'a> &'a Q: QueryDensity,
|
||||||
D: Send + Sync + 'static + Clone + AsRef<Q>,
|
D: Send + Sync + 'static + Clone + AsRef<Q>,
|
||||||
G: CurveProjective,
|
G: CofactorCurve,
|
||||||
S: SourceBuilder<<G as CurveProjective>::Affine>,
|
S: SourceBuilder<<G as CofactorCurve>::Affine>,
|
||||||
{
|
{
|
||||||
let c = if exponents.len() < 32 {
|
let c = if exponents.len() < 32 {
|
||||||
3u32
|
3u32
|
||||||
|
@ -296,8 +296,8 @@ where
|
||||||
#[cfg(feature = "pairing")]
|
#[cfg(feature = "pairing")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_with_bls12() {
|
fn test_with_bls12() {
|
||||||
fn naive_multiexp<G: CurveProjective>(
|
fn naive_multiexp<G: CofactorCurve>(
|
||||||
bases: Arc<Vec<<G as CurveProjective>::Affine>>,
|
bases: Arc<Vec<<G as CofactorCurve>::Affine>>,
|
||||||
exponents: Arc<Vec<G::Scalar>>,
|
exponents: Arc<Vec<G::Scalar>>,
|
||||||
) -> G {
|
) -> G {
|
||||||
assert_eq!(bases.len(), exponents.len());
|
assert_eq!(bases.len(), exponents.len());
|
||||||
|
|
|
@ -88,12 +88,10 @@ pub trait PrimeGroup: Group {}
|
||||||
|
|
||||||
/// Projective representation of an elliptic curve point guaranteed to be
|
/// Projective representation of an elliptic curve point guaranteed to be
|
||||||
/// in the correct prime order subgroup.
|
/// in the correct prime order subgroup.
|
||||||
pub trait CurveProjective:
|
pub trait CofactorCurve:
|
||||||
Group
|
Group + GroupOps<<Self as CofactorCurve>::Affine> + GroupOpsOwned<<Self as CofactorCurve>::Affine>
|
||||||
+ GroupOps<<Self as CurveProjective>::Affine>
|
|
||||||
+ GroupOpsOwned<<Self as CurveProjective>::Affine>
|
|
||||||
{
|
{
|
||||||
type Affine: CurveAffine<Projective = Self, Scalar = Self::Scalar>
|
type Affine: CurveAffine<Curve = Self, Scalar = Self::Scalar>
|
||||||
+ Mul<Self::Scalar, Output = Self>
|
+ Mul<Self::Scalar, Output = Self>
|
||||||
+ for<'r> Mul<Self::Scalar, Output = Self>;
|
+ for<'r> Mul<Self::Scalar, Output = Self>;
|
||||||
|
|
||||||
|
@ -134,11 +132,11 @@ pub trait CurveAffine:
|
||||||
+ 'static
|
+ 'static
|
||||||
+ GroupEncoding
|
+ GroupEncoding
|
||||||
+ Neg<Output = Self>
|
+ Neg<Output = Self>
|
||||||
+ Mul<<Self as CurveAffine>::Scalar, Output = <Self as CurveAffine>::Projective>
|
+ Mul<<Self as CurveAffine>::Scalar, Output = <Self as CurveAffine>::Curve>
|
||||||
+ for<'r> Mul<<Self as CurveAffine>::Scalar, Output = <Self as CurveAffine>::Projective>
|
+ for<'r> Mul<<Self as CurveAffine>::Scalar, Output = <Self as CurveAffine>::Curve>
|
||||||
{
|
{
|
||||||
type Scalar: PrimeField;
|
type Scalar: PrimeField;
|
||||||
type Projective: CurveProjective<Affine = Self, Scalar = Self::Scalar>;
|
type Curve: CofactorCurve<Affine = Self, Scalar = Self::Scalar>;
|
||||||
|
|
||||||
/// Returns the additive identity.
|
/// Returns the additive identity.
|
||||||
fn identity() -> Self;
|
fn identity() -> Self;
|
||||||
|
@ -150,8 +148,8 @@ pub trait CurveAffine:
|
||||||
/// additive identity.
|
/// additive identity.
|
||||||
fn is_identity(&self) -> Choice;
|
fn is_identity(&self) -> Choice;
|
||||||
|
|
||||||
/// Converts this element into its affine representation.
|
/// Converts this element into its efficient representation.
|
||||||
fn to_projective(&self) -> Self::Projective;
|
fn to_curve(&self) -> Self::Curve;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait GroupEncoding: Sized {
|
pub trait GroupEncoding: Sized {
|
||||||
|
|
|
@ -3,9 +3,9 @@ use rand::SeedableRng;
|
||||||
use rand_xorshift::XorShiftRng;
|
use rand_xorshift::XorShiftRng;
|
||||||
use std::ops::{Mul, Neg};
|
use std::ops::{Mul, Neg};
|
||||||
|
|
||||||
use crate::{CurveAffine, CurveProjective, GroupEncoding, UncompressedEncoding};
|
use crate::{CofactorCurve, CurveAffine, GroupEncoding, UncompressedEncoding};
|
||||||
|
|
||||||
pub fn curve_tests<G: CurveProjective>() {
|
pub fn curve_tests<G: CofactorCurve>() {
|
||||||
let mut rng = XorShiftRng::from_seed([
|
let mut rng = XorShiftRng::from_seed([
|
||||||
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
||||||
0xe5,
|
0xe5,
|
||||||
|
@ -50,8 +50,8 @@ pub fn curve_tests<G: CurveProjective>() {
|
||||||
// Transformations
|
// Transformations
|
||||||
{
|
{
|
||||||
let a = G::random(&mut rng);
|
let a = G::random(&mut rng);
|
||||||
let b = a.to_affine().to_projective();
|
let b = a.to_affine().to_curve();
|
||||||
let c = a.to_affine().to_projective().to_affine().to_projective();
|
let c = a.to_affine().to_curve().to_affine().to_curve();
|
||||||
assert_eq!(a, b);
|
assert_eq!(a, b);
|
||||||
assert_eq!(b, c);
|
assert_eq!(b, c);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ pub fn curve_tests<G: CurveProjective>() {
|
||||||
random_compressed_encoding_tests::<G>();
|
random_compressed_encoding_tests::<G>();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn random_wnaf_tests<G: CurveProjective>() {
|
fn random_wnaf_tests<G: CofactorCurve>() {
|
||||||
use crate::wnaf::*;
|
use crate::wnaf::*;
|
||||||
|
|
||||||
let mut rng = XorShiftRng::from_seed([
|
let mut rng = XorShiftRng::from_seed([
|
||||||
|
@ -184,7 +184,7 @@ fn random_wnaf_tests<G: CurveProjective>() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn random_negation_tests<G: CurveProjective>() {
|
fn random_negation_tests<G: CofactorCurve>() {
|
||||||
let mut rng = XorShiftRng::from_seed([
|
let mut rng = XorShiftRng::from_seed([
|
||||||
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
||||||
0xe5,
|
0xe5,
|
||||||
|
@ -214,7 +214,7 @@ fn random_negation_tests<G: CurveProjective>() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn random_doubling_tests<G: CurveProjective>() {
|
fn random_doubling_tests<G: CofactorCurve>() {
|
||||||
let mut rng = XorShiftRng::from_seed([
|
let mut rng = XorShiftRng::from_seed([
|
||||||
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
||||||
0xe5,
|
0xe5,
|
||||||
|
@ -242,7 +242,7 @@ fn random_doubling_tests<G: CurveProjective>() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn random_multiplication_tests<G: CurveProjective>() {
|
fn random_multiplication_tests<G: CofactorCurve>() {
|
||||||
let mut rng = XorShiftRng::from_seed([
|
let mut rng = XorShiftRng::from_seed([
|
||||||
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
||||||
0xe5,
|
0xe5,
|
||||||
|
@ -277,7 +277,7 @@ fn random_multiplication_tests<G: CurveProjective>() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn random_addition_tests<G: CurveProjective>() {
|
fn random_addition_tests<G: CofactorCurve>() {
|
||||||
let mut rng = XorShiftRng::from_seed([
|
let mut rng = XorShiftRng::from_seed([
|
||||||
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
||||||
0xe5,
|
0xe5,
|
||||||
|
@ -325,17 +325,17 @@ fn random_addition_tests<G: CurveProjective>() {
|
||||||
// Mixed addition
|
// Mixed addition
|
||||||
|
|
||||||
// (a + b) + c
|
// (a + b) + c
|
||||||
tmp[3] = a_affine.to_projective();
|
tmp[3] = a_affine.to_curve();
|
||||||
tmp[3].add_assign(&b_affine);
|
tmp[3].add_assign(&b_affine);
|
||||||
tmp[3].add_assign(&c_affine);
|
tmp[3].add_assign(&c_affine);
|
||||||
|
|
||||||
// a + (b + c)
|
// a + (b + c)
|
||||||
tmp[4] = b_affine.to_projective();
|
tmp[4] = b_affine.to_curve();
|
||||||
tmp[4].add_assign(&c_affine);
|
tmp[4].add_assign(&c_affine);
|
||||||
tmp[4].add_assign(&a_affine);
|
tmp[4].add_assign(&a_affine);
|
||||||
|
|
||||||
// (a + c) + b
|
// (a + c) + b
|
||||||
tmp[5] = a_affine.to_projective();
|
tmp[5] = a_affine.to_curve();
|
||||||
tmp[5].add_assign(&c_affine);
|
tmp[5].add_assign(&c_affine);
|
||||||
tmp[5].add_assign(&b_affine);
|
tmp[5].add_assign(&b_affine);
|
||||||
|
|
||||||
|
@ -357,7 +357,7 @@ fn random_addition_tests<G: CurveProjective>() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn random_transformation_tests<G: CurveProjective>() {
|
fn random_transformation_tests<G: CofactorCurve>() {
|
||||||
let mut rng = XorShiftRng::from_seed([
|
let mut rng = XorShiftRng::from_seed([
|
||||||
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
||||||
0xe5,
|
0xe5,
|
||||||
|
@ -366,7 +366,7 @@ fn random_transformation_tests<G: CurveProjective>() {
|
||||||
for _ in 0..1000 {
|
for _ in 0..1000 {
|
||||||
let g = G::random(&mut rng);
|
let g = G::random(&mut rng);
|
||||||
let g_affine = g.to_affine();
|
let g_affine = g.to_affine();
|
||||||
let g_projective = g_affine.to_projective();
|
let g_projective = g_affine.to_curve();
|
||||||
assert_eq!(g, g_projective);
|
assert_eq!(g, g_projective);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,7 +382,7 @@ fn random_transformation_tests<G: CurveProjective>() {
|
||||||
}
|
}
|
||||||
for _ in 0..5 {
|
for _ in 0..5 {
|
||||||
let s = between.sample(&mut rng);
|
let s = between.sample(&mut rng);
|
||||||
v[s] = v[s].to_affine().to_projective();
|
v[s] = v[s].to_affine().to_curve();
|
||||||
}
|
}
|
||||||
|
|
||||||
let expected_v = v.iter().map(|v| v.to_affine()).collect::<Vec<_>>();
|
let expected_v = v.iter().map(|v| v.to_affine()).collect::<Vec<_>>();
|
||||||
|
@ -394,7 +394,7 @@ fn random_transformation_tests<G: CurveProjective>() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn random_compressed_encoding_tests<G: CurveProjective>() {
|
fn random_compressed_encoding_tests<G: CofactorCurve>() {
|
||||||
let mut rng = XorShiftRng::from_seed([
|
let mut rng = XorShiftRng::from_seed([
|
||||||
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
||||||
0xe5,
|
0xe5,
|
||||||
|
@ -420,9 +420,9 @@ fn random_compressed_encoding_tests<G: CurveProjective>() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn random_uncompressed_encoding_tests<G: CurveProjective>()
|
pub fn random_uncompressed_encoding_tests<G: CofactorCurve>()
|
||||||
where
|
where
|
||||||
G::Affine: UncompressedEncoding,
|
<G as CofactorCurve>::Affine: UncompressedEncoding,
|
||||||
{
|
{
|
||||||
let mut rng = XorShiftRng::from_seed([
|
let mut rng = XorShiftRng::from_seed([
|
||||||
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
||||||
|
|
|
@ -2,10 +2,10 @@ use byteorder::{ByteOrder, LittleEndian};
|
||||||
use ff::PrimeField;
|
use ff::PrimeField;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
use super::{CurveProjective, Group};
|
use super::{CofactorCurve, Group};
|
||||||
|
|
||||||
/// Replaces the contents of `table` with a w-NAF window table for the given window size.
|
/// Replaces the contents of `table` with a w-NAF window table for the given window size.
|
||||||
pub(crate) fn wnaf_table<G: CurveProjective>(table: &mut Vec<G>, mut base: G, window: usize) {
|
pub(crate) fn wnaf_table<G: CofactorCurve>(table: &mut Vec<G>, mut base: G, window: usize) {
|
||||||
table.truncate(0);
|
table.truncate(0);
|
||||||
table.reserve(1 << (window - 1));
|
table.reserve(1 << (window - 1));
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ pub(crate) fn wnaf_form<S: AsRef<[u8]>>(wnaf: &mut Vec<i64>, c: S, window: usize
|
||||||
///
|
///
|
||||||
/// This function must be provided a `table` and `wnaf` that were constructed with
|
/// This function must be provided a `table` and `wnaf` that were constructed with
|
||||||
/// the same window size; otherwise, it may panic or produce invalid results.
|
/// the same window size; otherwise, it may panic or produce invalid results.
|
||||||
pub(crate) fn wnaf_exp<G: CurveProjective>(table: &[G], wnaf: &[i64]) -> G {
|
pub(crate) fn wnaf_exp<G: CofactorCurve>(table: &[G], wnaf: &[i64]) -> G {
|
||||||
let mut result = G::identity();
|
let mut result = G::identity();
|
||||||
|
|
||||||
let mut found_one = false;
|
let mut found_one = false;
|
||||||
|
@ -110,7 +110,7 @@ pub struct Wnaf<W, B, S> {
|
||||||
window_size: W,
|
window_size: W,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: CurveProjective> Wnaf<(), Vec<G>, Vec<i64>> {
|
impl<G: CofactorCurve> Wnaf<(), Vec<G>, Vec<i64>> {
|
||||||
/// Construct a new wNAF context without allocating.
|
/// Construct a new wNAF context without allocating.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Wnaf {
|
Wnaf {
|
||||||
|
@ -157,7 +157,7 @@ impl<G: CurveProjective> Wnaf<(), Vec<G>, Vec<i64>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, G: CurveProjective> Wnaf<usize, &'a [G], &'a mut Vec<i64>> {
|
impl<'a, G: CofactorCurve> Wnaf<usize, &'a [G], &'a mut Vec<i64>> {
|
||||||
/// Constructs new space for the scalar representation while borrowing
|
/// Constructs new space for the scalar representation while borrowing
|
||||||
/// the computed window table, for sending the window table across threads.
|
/// the computed window table, for sending the window table across threads.
|
||||||
pub fn shared(&self) -> Wnaf<usize, &'a [G], Vec<i64>> {
|
pub fn shared(&self) -> Wnaf<usize, &'a [G], Vec<i64>> {
|
||||||
|
@ -169,7 +169,7 @@ impl<'a, G: CurveProjective> Wnaf<usize, &'a [G], &'a mut Vec<i64>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, G: CurveProjective> Wnaf<usize, &'a mut Vec<G>, &'a [i64]> {
|
impl<'a, G: CofactorCurve> Wnaf<usize, &'a mut Vec<G>, &'a [i64]> {
|
||||||
/// Constructs new space for the window table while borrowing
|
/// Constructs new space for the window table while borrowing
|
||||||
/// the computed scalar representation, for sending the scalar representation
|
/// the computed scalar representation, for sending the scalar representation
|
||||||
/// across threads.
|
/// across threads.
|
||||||
|
@ -184,7 +184,7 @@ impl<'a, G: CurveProjective> Wnaf<usize, &'a mut Vec<G>, &'a [i64]> {
|
||||||
|
|
||||||
impl<B, S: AsRef<[i64]>> Wnaf<usize, B, S> {
|
impl<B, S: AsRef<[i64]>> Wnaf<usize, B, S> {
|
||||||
/// Performs exponentiation given a base.
|
/// Performs exponentiation given a base.
|
||||||
pub fn base<G: CurveProjective>(&mut self, base: G) -> G
|
pub fn base<G: CofactorCurve>(&mut self, base: G) -> G
|
||||||
where
|
where
|
||||||
B: AsMut<Vec<G>>,
|
B: AsMut<Vec<G>>,
|
||||||
{
|
{
|
||||||
|
@ -195,7 +195,7 @@ impl<B, S: AsRef<[i64]>> Wnaf<usize, B, S> {
|
||||||
|
|
||||||
impl<B, S: AsMut<Vec<i64>>> Wnaf<usize, B, S> {
|
impl<B, S: AsMut<Vec<i64>>> Wnaf<usize, B, S> {
|
||||||
/// Performs exponentiation given a scalar.
|
/// Performs exponentiation given a scalar.
|
||||||
pub fn scalar<G: CurveProjective>(&mut self, scalar: &<G as Group>::Scalar) -> G
|
pub fn scalar<G: CofactorCurve>(&mut self, scalar: &<G as Group>::Scalar) -> G
|
||||||
where
|
where
|
||||||
B: AsRef<[G]>,
|
B: AsRef<[G]>,
|
||||||
{
|
{
|
||||||
|
|
|
@ -199,7 +199,7 @@ macro_rules! curve_impl {
|
||||||
|
|
||||||
impl CurveAffine for $affine {
|
impl CurveAffine for $affine {
|
||||||
type Scalar = $scalarfield;
|
type Scalar = $scalarfield;
|
||||||
type Projective = $projective;
|
type Curve = $projective;
|
||||||
|
|
||||||
fn identity() -> Self {
|
fn identity() -> Self {
|
||||||
$affine {
|
$affine {
|
||||||
|
@ -217,7 +217,7 @@ macro_rules! curve_impl {
|
||||||
Choice::from(if self.infinity { 1 } else { 0 })
|
Choice::from(if self.infinity { 1 } else { 0 })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_projective(&self) -> $projective {
|
fn to_curve(&self) -> $projective {
|
||||||
(*self).into()
|
(*self).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -466,30 +466,28 @@ macro_rules! curve_impl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'r> ::std::ops::Add<&'r <$projective as CurveProjective>::Affine> for $projective {
|
impl<'r> ::std::ops::Add<&'r $affine> for $projective {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add(self, other: &<$projective as CurveProjective>::Affine) -> Self {
|
fn add(self, other: &$affine) -> Self {
|
||||||
let mut ret = self;
|
let mut ret = self;
|
||||||
ret.add_assign(other);
|
ret.add_assign(other);
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::std::ops::Add<<$projective as CurveProjective>::Affine> for $projective {
|
impl ::std::ops::Add<$affine> for $projective {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add(self, other: <$projective as CurveProjective>::Affine) -> Self {
|
fn add(self, other: $affine) -> Self {
|
||||||
self + &other
|
self + &other
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'r> ::std::ops::AddAssign<&'r <$projective as CurveProjective>::Affine>
|
impl<'r> ::std::ops::AddAssign<&'r $affine> for $projective {
|
||||||
for $projective
|
fn add_assign(&mut self, other: &$affine) {
|
||||||
{
|
|
||||||
fn add_assign(&mut self, other: &<$projective as CurveProjective>::Affine) {
|
|
||||||
if other.is_identity().into() {
|
if other.is_identity().into() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -567,44 +565,42 @@ macro_rules! curve_impl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::std::ops::AddAssign<<$projective as CurveProjective>::Affine> for $projective {
|
impl ::std::ops::AddAssign<$affine> for $projective {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add_assign(&mut self, other: <$projective as CurveProjective>::Affine) {
|
fn add_assign(&mut self, other: $affine) {
|
||||||
self.add_assign(&other);
|
self.add_assign(&other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'r> ::std::ops::Sub<&'r <$projective as CurveProjective>::Affine> for $projective {
|
impl<'r> ::std::ops::Sub<&'r $affine> for $projective {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub(self, other: &<$projective as CurveProjective>::Affine) -> Self {
|
fn sub(self, other: &$affine) -> Self {
|
||||||
let mut ret = self;
|
let mut ret = self;
|
||||||
ret.sub_assign(other);
|
ret.sub_assign(other);
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::std::ops::Sub<<$projective as CurveProjective>::Affine> for $projective {
|
impl ::std::ops::Sub<$affine> for $projective {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub(self, other: <$projective as CurveProjective>::Affine) -> Self {
|
fn sub(self, other: $affine) -> Self {
|
||||||
self - &other
|
self - &other
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'r> ::std::ops::SubAssign<&'r <$projective as CurveProjective>::Affine>
|
impl<'r> ::std::ops::SubAssign<&'r $affine> for $projective {
|
||||||
for $projective
|
fn sub_assign(&mut self, other: &$affine) {
|
||||||
{
|
|
||||||
fn sub_assign(&mut self, other: &<$projective as CurveProjective>::Affine) {
|
|
||||||
self.add_assign(&other.neg());
|
self.add_assign(&other.neg());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::std::ops::SubAssign<<$projective as CurveProjective>::Affine> for $projective {
|
impl ::std::ops::SubAssign<$affine> for $projective {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub_assign(&mut self, other: <$projective as CurveProjective>::Affine) {
|
fn sub_assign(&mut self, other: $affine) {
|
||||||
self.sub_assign(&other);
|
self.sub_assign(&other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -746,7 +742,7 @@ macro_rules! curve_impl {
|
||||||
|
|
||||||
impl PrimeGroup for $projective {}
|
impl PrimeGroup for $projective {}
|
||||||
|
|
||||||
impl CurveProjective for $projective {
|
impl CofactorCurve for $projective {
|
||||||
type Affine = $affine;
|
type Affine = $affine;
|
||||||
|
|
||||||
fn batch_normalize(p: &[Self], q: &mut [$affine]) {
|
fn batch_normalize(p: &[Self], q: &mut [$affine]) {
|
||||||
|
@ -908,7 +904,7 @@ pub mod g1 {
|
||||||
use crate::{Engine, PairingCurveAffine};
|
use crate::{Engine, PairingCurveAffine};
|
||||||
use ff::{BitIterator, Field, PrimeField};
|
use ff::{BitIterator, Field, PrimeField};
|
||||||
use group::{
|
use group::{
|
||||||
CurveAffine, CurveProjective, Group, GroupEncoding, PrimeGroup, UncompressedEncoding,
|
CofactorCurve, CurveAffine, Group, GroupEncoding, PrimeGroup, UncompressedEncoding,
|
||||||
};
|
};
|
||||||
use rand_core::RngCore;
|
use rand_core::RngCore;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -1462,15 +1458,15 @@ pub mod g1 {
|
||||||
assert!(b.is_on_curve() && b.is_in_correct_subgroup_assuming_on_curve());
|
assert!(b.is_on_curve() && b.is_in_correct_subgroup_assuming_on_curve());
|
||||||
assert!(c.is_on_curve() && c.is_in_correct_subgroup_assuming_on_curve());
|
assert!(c.is_on_curve() && c.is_in_correct_subgroup_assuming_on_curve());
|
||||||
|
|
||||||
let mut tmp1 = a.to_projective();
|
let mut tmp1 = a.to_curve();
|
||||||
tmp1.add_assign(&b.to_projective());
|
tmp1.add_assign(&b.to_curve());
|
||||||
assert_eq!(tmp1.to_affine(), c);
|
assert_eq!(tmp1.to_affine(), c);
|
||||||
assert_eq!(tmp1, c.to_projective());
|
assert_eq!(tmp1, c.to_curve());
|
||||||
|
|
||||||
let mut tmp2 = a.to_projective();
|
let mut tmp2 = a.to_curve();
|
||||||
tmp2.add_assign(&b);
|
tmp2.add_assign(&b);
|
||||||
assert_eq!(tmp2.to_affine(), c);
|
assert_eq!(tmp2.to_affine(), c);
|
||||||
assert_eq!(tmp2, c.to_projective());
|
assert_eq!(tmp2, c.to_curve());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1487,7 +1483,7 @@ pub mod g2 {
|
||||||
use crate::{Engine, PairingCurveAffine};
|
use crate::{Engine, PairingCurveAffine};
|
||||||
use ff::{BitIterator, Field, PrimeField};
|
use ff::{BitIterator, Field, PrimeField};
|
||||||
use group::{
|
use group::{
|
||||||
CurveAffine, CurveProjective, Group, GroupEncoding, PrimeGroup, UncompressedEncoding,
|
CofactorCurve, CurveAffine, Group, GroupEncoding, PrimeGroup, UncompressedEncoding,
|
||||||
};
|
};
|
||||||
use rand_core::RngCore;
|
use rand_core::RngCore;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use ff::PrimeField;
|
use ff::PrimeField;
|
||||||
use group::{CurveAffine, CurveProjective, GroupEncoding, UncompressedEncoding};
|
use group::{CofactorCurve, CurveAffine, GroupEncoding, UncompressedEncoding};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
@ -55,7 +55,7 @@ fn test_pairing_result_against_relic() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uncompressed_test_vectors<G: CurveProjective>(expected: &[u8])
|
fn uncompressed_test_vectors<G: CofactorCurve>(expected: &[u8])
|
||||||
where
|
where
|
||||||
G::Affine: UncompressedEncoding,
|
G::Affine: UncompressedEncoding,
|
||||||
{
|
{
|
||||||
|
@ -85,7 +85,7 @@ where
|
||||||
assert_eq!(&v[..], expected);
|
assert_eq!(&v[..], expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compressed_test_vectors<G: CurveProjective>(expected: &[u8]) {
|
fn compressed_test_vectors<G: CofactorCurve>(expected: &[u8]) {
|
||||||
let mut e = G::identity();
|
let mut e = G::identity();
|
||||||
let encoded_len = <G::Affine as GroupEncoding>::Repr::default().as_ref().len();
|
let encoded_len = <G::Affine as GroupEncoding>::Repr::default().as_ref().len();
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ pub mod bls12_381;
|
||||||
use core::ops::Mul;
|
use core::ops::Mul;
|
||||||
use ff::{Field, PrimeField};
|
use ff::{Field, PrimeField};
|
||||||
use group::{
|
use group::{
|
||||||
CurveAffine, CurveProjective, GroupOps, GroupOpsOwned, ScalarMul, ScalarMulOwned,
|
CofactorCurve, CurveAffine, GroupOps, GroupOpsOwned, ScalarMul, ScalarMulOwned,
|
||||||
UncompressedEncoding,
|
UncompressedEncoding,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ pub trait Engine: Sized + 'static + Clone {
|
||||||
type Fr: PrimeField;
|
type Fr: PrimeField;
|
||||||
|
|
||||||
/// The projective representation of an element in G1.
|
/// The projective representation of an element in G1.
|
||||||
type G1: CurveProjective<Scalar = Self::Fr, Affine = Self::G1Affine>
|
type G1: CofactorCurve<Scalar = Self::Fr, Affine = Self::G1Affine>
|
||||||
+ From<Self::G1Affine>
|
+ From<Self::G1Affine>
|
||||||
+ GroupOps<Self::G1Affine>
|
+ GroupOps<Self::G1Affine>
|
||||||
+ GroupOpsOwned<Self::G1Affine>
|
+ GroupOpsOwned<Self::G1Affine>
|
||||||
|
@ -45,7 +45,7 @@ pub trait Engine: Sized + 'static + Clone {
|
||||||
/// The affine representation of an element in G1.
|
/// The affine representation of an element in G1.
|
||||||
type G1Affine: PairingCurveAffine<
|
type G1Affine: PairingCurveAffine<
|
||||||
Scalar = Self::Fr,
|
Scalar = Self::Fr,
|
||||||
Projective = Self::G1,
|
Curve = Self::G1,
|
||||||
Pair = Self::G2Affine,
|
Pair = Self::G2Affine,
|
||||||
PairingResult = Self::Gt,
|
PairingResult = Self::Gt,
|
||||||
> + From<Self::G1>
|
> + From<Self::G1>
|
||||||
|
@ -53,7 +53,7 @@ pub trait Engine: Sized + 'static + Clone {
|
||||||
+ for<'a> Mul<&'a Self::Fr, Output = Self::G1>;
|
+ for<'a> Mul<&'a Self::Fr, Output = Self::G1>;
|
||||||
|
|
||||||
/// The projective representation of an element in G2.
|
/// The projective representation of an element in G2.
|
||||||
type G2: CurveProjective<Scalar = Self::Fr, Affine = Self::G2Affine>
|
type G2: CofactorCurve<Scalar = Self::Fr, Affine = Self::G2Affine>
|
||||||
+ From<Self::G2Affine>
|
+ From<Self::G2Affine>
|
||||||
+ GroupOps<Self::G2Affine>
|
+ GroupOps<Self::G2Affine>
|
||||||
+ GroupOpsOwned<Self::G2Affine>
|
+ GroupOpsOwned<Self::G2Affine>
|
||||||
|
@ -63,7 +63,7 @@ pub trait Engine: Sized + 'static + Clone {
|
||||||
/// The affine representation of an element in G2.
|
/// The affine representation of an element in G2.
|
||||||
type G2Affine: PairingCurveAffine<
|
type G2Affine: PairingCurveAffine<
|
||||||
Scalar = Self::Fr,
|
Scalar = Self::Fr,
|
||||||
Projective = Self::G2,
|
Curve = Self::G2,
|
||||||
Pair = Self::G1Affine,
|
Pair = Self::G1Affine,
|
||||||
PairingResult = Self::Gt,
|
PairingResult = Self::Gt,
|
||||||
> + From<Self::G2>
|
> + From<Self::G2>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use ff::{Endianness, Field, PrimeField};
|
use ff::{Endianness, Field, PrimeField};
|
||||||
use group::{CurveAffine, CurveProjective, Group};
|
use group::{CofactorCurve, CurveAffine, Group};
|
||||||
use rand_core::SeedableRng;
|
use rand_core::SeedableRng;
|
||||||
use rand_xorshift::XorShiftRng;
|
use rand_xorshift::XorShiftRng;
|
||||||
use std::ops::MulAssign;
|
use std::ops::MulAssign;
|
||||||
|
|
Loading…
Reference in New Issue