Skip to main content

group/
prime.rs

1use core::fmt;
2use core::ops::{Mul, Neg};
3use ff::PrimeField;
4use subtle::Choice;
5
6use crate::{Curve, Group, GroupEncoding};
7
8/// This trait represents an element of a prime-order cryptographic group.
9pub trait PrimeGroup: Group + GroupEncoding {}
10
11/// Efficient representation of an elliptic curve point guaranteed to be
12/// in the correct prime order subgroup.
13pub trait PrimeCurve: Curve<AffineRepr = <Self as PrimeCurve>::Affine> + PrimeGroup {
14    type Affine: PrimeCurveAffine<Curve = Self, Scalar = Self::Scalar>
15        + Mul<Self::Scalar, Output = Self>
16        + for<'r> Mul<Self::Scalar, Output = Self>;
17}
18
19/// Affine representation of an elliptic curve point guaranteed to be
20/// in the correct prime order subgroup.
21pub trait PrimeCurveAffine:
22    GroupEncoding
23    + Copy
24    + Clone
25    + Sized
26    + Send
27    + Sync
28    + fmt::Debug
29    + PartialEq
30    + Eq
31    + 'static
32    + Neg<Output = Self>
33    + Mul<<Self as PrimeCurveAffine>::Scalar, Output = <Self as PrimeCurveAffine>::Curve>
34    + for<'r> Mul<<Self as PrimeCurveAffine>::Scalar, Output = <Self as PrimeCurveAffine>::Curve>
35{
36    type Scalar: PrimeField;
37    type Curve: PrimeCurve<Affine = Self, Scalar = Self::Scalar>;
38
39    /// Returns the additive identity.
40    fn identity() -> Self;
41
42    /// Returns a fixed generator of unknown exponent.
43    fn generator() -> Self;
44
45    /// Determines if this point represents the point at infinity; the
46    /// additive identity.
47    fn is_identity(&self) -> Choice;
48
49    /// Converts this element to its curve representation.
50    fn to_curve(&self) -> Self::Curve;
51}