From 053698eefb59278bc2e4e4ff5fff9786a96acd02 Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Sun, 30 Jul 2017 00:54:23 -0600 Subject: [PATCH] Add `Engine` associated type to CurveProject/CurveAffine. --- src/bls12_381/ec.rs | 6 ++++-- src/lib.rs | 12 +++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/bls12_381/ec.rs b/src/bls12_381/ec.rs index a4eaa1a..16deca5 100644 --- a/src/bls12_381/ec.rs +++ b/src/bls12_381/ec.rs @@ -108,6 +108,7 @@ macro_rules! curve_impl { } impl CurveAffine for $affine { + type Engine = Bls12; type Scalar = $scalarfield; type Base = $basefield; type Prepared = $prepared; @@ -174,6 +175,7 @@ macro_rules! curve_impl { } impl CurveProjective for $projective { + type Engine = Bls12; type Scalar = $scalarfield; type Base = $basefield; type Affine = $affine; @@ -582,7 +584,7 @@ macro_rules! curve_impl { pub mod g1 { use rand::{Rand, Rng}; use super::g2::G2Affine; - use super::super::{Fq, Fr, FrRepr, FqRepr, Fq12}; + use super::super::{Bls12, Fq, Fr, FrRepr, FqRepr, Fq12}; use ::{CurveProjective, CurveAffine, PrimeField, SqrtField, PrimeFieldRepr, Field, BitIterator, EncodedPoint, GroupDecodingError, Engine}; curve_impl!("G1", G1, G1Affine, G1Prepared, Fq, Fr, G1Uncompressed, G1Compressed, G2Affine); @@ -1134,7 +1136,7 @@ pub mod g1 { pub mod g2 { use rand::{Rand, Rng}; - use super::super::{Fq2, Fr, Fq, FrRepr, FqRepr, Fq12}; + use super::super::{Bls12, Fq2, Fr, Fq, FrRepr, FqRepr, Fq12}; use super::g1::G1Affine; use ::{CurveProjective, CurveAffine, PrimeField, SqrtField, PrimeFieldRepr, Field, BitIterator, EncodedPoint, GroupDecodingError, Engine}; diff --git a/src/lib.rs b/src/lib.rs index 96ea04b..55b0c19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,21 +34,21 @@ use std::io::{self, Read, Write}; /// An "engine" is a collection of types (fields, elliptic curve groups, etc.) /// with well-defined relationships. In particular, the G1/G2 curve groups are /// of prime order `r`, and are equipped with a bilinear pairing function. -pub trait Engine { +pub trait Engine: Sized { /// This is the scalar field of the G1/G2 groups. type Fr: PrimeField; /// The projective representation of an element in G1. - type G1: CurveProjective + From; + type G1: CurveProjective + From; /// The affine representation of an element in G1. - type G1Affine: CurveAffine + From; + type G1Affine: CurveAffine + From; /// The projective representation of an element in G2. - type G2: CurveProjective + From; + type G2: CurveProjective + From; /// The affine representation of an element in G2. - type G2Affine: CurveAffine + From; + type G2Affine: CurveAffine + From; /// The base field that hosts G1. type Fq: PrimeField + SqrtField; @@ -97,6 +97,7 @@ pub trait CurveProjective: PartialEq + rand::Rand + 'static { + type Engine: Engine; type Scalar: PrimeField; type Base: SqrtField; type Affine: CurveAffine; @@ -166,6 +167,7 @@ pub trait CurveAffine: Copy + Eq + 'static { + type Engine: Engine; type Scalar: PrimeField; type Base: SqrtField; type Projective: CurveProjective;