mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-01-31 07:42:15 +00:00
Add Engine
associated type to CurveProject/CurveAffine.
This commit is contained in:
parent
40ec989184
commit
053698eefb
@ -108,6 +108,7 @@ macro_rules! curve_impl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CurveAffine for $affine {
|
impl CurveAffine for $affine {
|
||||||
|
type Engine = Bls12;
|
||||||
type Scalar = $scalarfield;
|
type Scalar = $scalarfield;
|
||||||
type Base = $basefield;
|
type Base = $basefield;
|
||||||
type Prepared = $prepared;
|
type Prepared = $prepared;
|
||||||
@ -174,6 +175,7 @@ macro_rules! curve_impl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CurveProjective for $projective {
|
impl CurveProjective for $projective {
|
||||||
|
type Engine = Bls12;
|
||||||
type Scalar = $scalarfield;
|
type Scalar = $scalarfield;
|
||||||
type Base = $basefield;
|
type Base = $basefield;
|
||||||
type Affine = $affine;
|
type Affine = $affine;
|
||||||
@ -582,7 +584,7 @@ macro_rules! curve_impl {
|
|||||||
pub mod g1 {
|
pub mod g1 {
|
||||||
use rand::{Rand, Rng};
|
use rand::{Rand, Rng};
|
||||||
use super::g2::G2Affine;
|
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};
|
use ::{CurveProjective, CurveAffine, PrimeField, SqrtField, PrimeFieldRepr, Field, BitIterator, EncodedPoint, GroupDecodingError, Engine};
|
||||||
|
|
||||||
curve_impl!("G1", G1, G1Affine, G1Prepared, Fq, Fr, G1Uncompressed, G1Compressed, G2Affine);
|
curve_impl!("G1", G1, G1Affine, G1Prepared, Fq, Fr, G1Uncompressed, G1Compressed, G2Affine);
|
||||||
@ -1134,7 +1136,7 @@ pub mod g1 {
|
|||||||
|
|
||||||
pub mod g2 {
|
pub mod g2 {
|
||||||
use rand::{Rand, Rng};
|
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 super::g1::G1Affine;
|
||||||
use ::{CurveProjective, CurveAffine, PrimeField, SqrtField, PrimeFieldRepr, Field, BitIterator, EncodedPoint, GroupDecodingError, Engine};
|
use ::{CurveProjective, CurveAffine, PrimeField, SqrtField, PrimeFieldRepr, Field, BitIterator, EncodedPoint, GroupDecodingError, Engine};
|
||||||
|
|
||||||
|
12
src/lib.rs
12
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.)
|
/// An "engine" is a collection of types (fields, elliptic curve groups, etc.)
|
||||||
/// with well-defined relationships. In particular, the G1/G2 curve groups are
|
/// with well-defined relationships. In particular, the G1/G2 curve groups are
|
||||||
/// of prime order `r`, and are equipped with a bilinear pairing function.
|
/// 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.
|
/// This is the scalar field of the G1/G2 groups.
|
||||||
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<Base=Self::Fq, Scalar=Self::Fr, Affine=Self::G1Affine> + From<Self::G1Affine>;
|
type G1: CurveProjective<Engine=Self, Base=Self::Fq, Scalar=Self::Fr, Affine=Self::G1Affine> + From<Self::G1Affine>;
|
||||||
|
|
||||||
/// The affine representation of an element in G1.
|
/// The affine representation of an element in G1.
|
||||||
type G1Affine: CurveAffine<Base=Self::Fq, Scalar=Self::Fr, Projective=Self::G1, Pair=Self::G2Affine, PairingResult=Self::Fqk> + From<Self::G1>;
|
type G1Affine: CurveAffine<Engine=Self, Base=Self::Fq, Scalar=Self::Fr, Projective=Self::G1, Pair=Self::G2Affine, PairingResult=Self::Fqk> + From<Self::G1>;
|
||||||
|
|
||||||
/// The projective representation of an element in G2.
|
/// The projective representation of an element in G2.
|
||||||
type G2: CurveProjective<Base=Self::Fqe, Scalar=Self::Fr, Affine=Self::G2Affine> + From<Self::G2Affine>;
|
type G2: CurveProjective<Engine=Self, Base=Self::Fqe, Scalar=Self::Fr, Affine=Self::G2Affine> + From<Self::G2Affine>;
|
||||||
|
|
||||||
/// The affine representation of an element in G2.
|
/// The affine representation of an element in G2.
|
||||||
type G2Affine: CurveAffine<Base=Self::Fqe, Scalar=Self::Fr, Projective=Self::G2, Pair=Self::G1Affine, PairingResult=Self::Fqk> + From<Self::G2>;
|
type G2Affine: CurveAffine<Engine=Self, Base=Self::Fqe, Scalar=Self::Fr, Projective=Self::G2, Pair=Self::G1Affine, PairingResult=Self::Fqk> + From<Self::G2>;
|
||||||
|
|
||||||
/// The base field that hosts G1.
|
/// The base field that hosts G1.
|
||||||
type Fq: PrimeField + SqrtField;
|
type Fq: PrimeField + SqrtField;
|
||||||
@ -97,6 +97,7 @@ pub trait CurveProjective: PartialEq +
|
|||||||
rand::Rand +
|
rand::Rand +
|
||||||
'static
|
'static
|
||||||
{
|
{
|
||||||
|
type Engine: Engine;
|
||||||
type Scalar: PrimeField;
|
type Scalar: PrimeField;
|
||||||
type Base: SqrtField;
|
type Base: SqrtField;
|
||||||
type Affine: CurveAffine<Projective=Self, Scalar=Self::Scalar>;
|
type Affine: CurveAffine<Projective=Self, Scalar=Self::Scalar>;
|
||||||
@ -166,6 +167,7 @@ pub trait CurveAffine: Copy +
|
|||||||
Eq +
|
Eq +
|
||||||
'static
|
'static
|
||||||
{
|
{
|
||||||
|
type Engine: Engine;
|
||||||
type Scalar: PrimeField;
|
type Scalar: PrimeField;
|
||||||
type Base: SqrtField;
|
type Base: SqrtField;
|
||||||
type Projective: CurveProjective<Affine=Self, Scalar=Self::Scalar>;
|
type Projective: CurveProjective<Affine=Self, Scalar=Self::Scalar>;
|
||||||
|
Loading…
Reference in New Issue
Block a user