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<&'r 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: GroupEncoding
22    + Copy
23    + Clone
24    + Sized
25    + Send
26    + Sync
27    + fmt::Debug
28    + PartialEq
29    + Eq
30    + 'static
31    + Neg<Output = Self>
32    + Mul<<Self as PrimeCurveAffine>::Scalar, Output = <Self as PrimeCurveAffine>::Curve>
33    + for<'r> Mul<&'r <Self as PrimeCurveAffine>::Scalar, Output = <Self as PrimeCurveAffine>::Curve>
34{
35    type Scalar: PrimeField;
36    type Curve: PrimeCurve<Affine = Self, Scalar = Self::Scalar>;
37
38    /// Returns the additive identity.
39    fn identity() -> Self;
40
41    /// Returns a fixed generator of unknown exponent.
42    fn generator() -> Self;
43
44    /// Determines if this point represents the point at infinity; the
45    /// additive identity.
46    fn is_identity(&self) -> Choice;
47
48    /// Converts this element to its curve representation.
49    fn to_curve(&self) -> Self::Curve;
50}