Introduce `Group` for generic group operations.
This commit is contained in:
parent
56c75c0c8a
commit
1434ad7b28
|
@ -43,6 +43,18 @@ macro_rules! curve_impl {
|
|||
}
|
||||
}
|
||||
|
||||
impl Group<$engine> for $name {
|
||||
fn group_mul_assign(&mut self, e: &$engine, scalar: &$scalarfield) {
|
||||
self.mul_assign(e, scalar);
|
||||
}
|
||||
fn group_add_assign(&mut self, e: &$engine, other: &Self) {
|
||||
self.add_assign(e, other);
|
||||
}
|
||||
fn group_sub_assign(&mut self, e: &$engine, other: &Self) {
|
||||
self.sub_assign(e, other);
|
||||
}
|
||||
}
|
||||
|
||||
impl CurveAffine<$engine, $name> for $name_affine {
|
||||
type Uncompressed = $name_uncompressed;
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::borrow::Borrow;
|
|||
use super::{
|
||||
WindowTable,
|
||||
Engine,
|
||||
Group,
|
||||
Curve,
|
||||
CurveAffine,
|
||||
CurveRepresentation,
|
||||
|
@ -95,6 +96,18 @@ fp_impl!(
|
|||
inv = 0xfffffffeffffffff
|
||||
);
|
||||
|
||||
impl Group<Bls381> for Fr {
|
||||
fn group_mul_assign(&mut self, e: &Bls381, scalar: &Fr) {
|
||||
self.mul_assign(e, scalar);
|
||||
}
|
||||
fn group_add_assign(&mut self, e: &Bls381, other: &Self) {
|
||||
self.add_assign(e, other);
|
||||
}
|
||||
fn group_sub_assign(&mut self, e: &Bls381, other: &Self) {
|
||||
self.sub_assign(e, other);
|
||||
}
|
||||
}
|
||||
|
||||
curve_impl!(Bls381, G1, G1Affine, G1Affine, G1Uncompressed, G1Params, g1params, Fq, Fr);
|
||||
curve_impl!(Bls381, G2, G2Affine, G2Prepared, G2Uncompressed, G2Params, g2params, Fq2, Fr);
|
||||
|
||||
|
|
|
@ -46,13 +46,21 @@ pub trait Engine: Sized + Clone
|
|||
fn batch_baseexp<G: Curve<Self>, S: AsRef<[Self::Fr]>>(&self, table: &WindowTable<Self, G, Vec<G>>, scalars: S) -> Vec<G::Affine>;
|
||||
}
|
||||
|
||||
pub trait Group<E: Engine>
|
||||
{
|
||||
fn group_mul_assign(&mut self, &E, scalar: &E::Fr);
|
||||
fn group_add_assign(&mut self, &E, other: &Self);
|
||||
fn group_sub_assign(&mut self, &E, other: &Self);
|
||||
}
|
||||
|
||||
pub trait Curve<E: Engine>: Sized +
|
||||
Copy +
|
||||
Clone +
|
||||
Send +
|
||||
Sync +
|
||||
fmt::Debug +
|
||||
'static
|
||||
'static +
|
||||
Group<E>
|
||||
{
|
||||
type Affine: CurveAffine<E, Self>;
|
||||
type Prepared: Clone + Send + Sync + 'static;
|
||||
|
@ -193,7 +201,7 @@ pub trait PrimeField<E: Engine>: SqrtField<E> + Convert<[u64], E>
|
|||
fn capacity(&E) -> usize;
|
||||
}
|
||||
|
||||
pub trait SnarkField<E: Engine>: PrimeField<E>
|
||||
pub trait SnarkField<E: Engine>: PrimeField<E> + Group<E>
|
||||
{
|
||||
fn s(&E) -> u64;
|
||||
fn multiplicative_generator(&E) -> Self;
|
||||
|
|
Loading…
Reference in New Issue