mirror of
https://github.com/saymrwulf/pasta_curves-source.git
synced 2026-09-04 20:03:39 +00:00
Add CurveExt and AffineExt associated types to project Group trait implementations.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
This commit is contained in:
parent
a7b9ca44f8
commit
df8dcce042
2 changed files with 14 additions and 4 deletions
|
|
@ -2,7 +2,7 @@
|
|||
//! write code that generalizes over a pair of groups.
|
||||
|
||||
use core::cmp;
|
||||
use core::ops::{Add, Sub};
|
||||
use core::ops::{Add, Mul, Sub};
|
||||
use group::prime::{PrimeCurve, PrimeCurveAffine};
|
||||
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ use std::io::{self, Read, Write};
|
|||
/// curve group in a "projective" form, where that arithmetic is usually more
|
||||
/// efficient.
|
||||
pub trait CurveExt:
|
||||
PrimeCurve
|
||||
PrimeCurve<Affine = <Self as CurveExt>::AffineExt>
|
||||
+ group::Group<Scalar = <Self as CurveExt>::ScalarExt>
|
||||
+ Default
|
||||
+ PartialEq
|
||||
|
|
@ -28,6 +28,10 @@ pub trait CurveExt:
|
|||
type ScalarExt: FieldExt;
|
||||
/// The base field over which this elliptic curve is constructed.
|
||||
type Base: FieldExt;
|
||||
/// The affine version of the curve
|
||||
type AffineExt: CurveAffine<CurveExt = Self, ScalarExt = <Self as CurveExt>::ScalarExt>
|
||||
+ Mul<Self::ScalarExt, Output = Self>
|
||||
+ for<'r> Mul<Self::ScalarExt, Output = Self>;
|
||||
|
||||
/// Apply the curve endomorphism by multiplying the x-coordinate
|
||||
/// by an element of multiplicative order 3.
|
||||
|
|
@ -75,8 +79,10 @@ pub trait CurveExt:
|
|||
/// This trait is the affine counterpart to `Curve` and is used for
|
||||
/// serialization, storage in memory, and inspection of $x$ and $y$ coordinates.
|
||||
pub trait CurveAffine:
|
||||
PrimeCurveAffine<Scalar = <Self as CurveAffine>::ScalarExt>
|
||||
+ Default
|
||||
PrimeCurveAffine<
|
||||
Scalar = <Self as CurveAffine>::ScalarExt,
|
||||
Curve = <Self as CurveAffine>::CurveExt,
|
||||
> + Default
|
||||
+ Add<Output = <Self as PrimeCurveAffine>::Curve>
|
||||
+ Sub<Output = <Self as PrimeCurveAffine>::Curve>
|
||||
+ ConditionallySelectable
|
||||
|
|
@ -87,6 +93,8 @@ pub trait CurveAffine:
|
|||
type ScalarExt: FieldExt;
|
||||
/// The base field over which this elliptic curve is constructed.
|
||||
type Base: FieldExt;
|
||||
/// The projective form of the curve
|
||||
type CurveExt: CurveExt<AffineExt = Self, ScalarExt = <Self as CurveAffine>::ScalarExt>;
|
||||
|
||||
/// Personalization of BLAKE2b hasher used to generate the uniform
|
||||
/// random string.
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ macro_rules! new_curve_impl {
|
|||
impl CurveExt for $name {
|
||||
type ScalarExt = $scalar;
|
||||
type Base = $base;
|
||||
type AffineExt = $name_affine;
|
||||
|
||||
impl_projective_curve_ext!($name, $name_affine, $iso, $base, $curve_type);
|
||||
|
||||
|
|
@ -612,6 +613,7 @@ macro_rules! new_curve_impl {
|
|||
impl CurveAffine for $name_affine {
|
||||
type ScalarExt = $scalar;
|
||||
type Base = $base;
|
||||
type CurveExt = $name;
|
||||
|
||||
const BLAKE2B_PERSONALIZATION: &'static [u8; 16] = $blake2b_personalization;
|
||||
const CURVE_ID: &'static str = $curve_id;
|
||||
|
|
|
|||
Loading…
Reference in a new issue