elliptic_curve/
arithmetic.rs1use crate::{
4 Curve, CurveAffine, CurveGroup, Error, FieldBytes, Group, NonZeroScalar, PrimeCurve,
5 ScalarValue,
6 ctutils::{CtEq, CtSelect},
7 ops::{Invert, LinearCombination, Mul, MulByGeneratorVartime, MulVartime, Reduce},
8 point::{AffineCoordinates, NonIdentity},
9 scalar::{FromUintUnchecked, IsHigh},
10};
11use bigint::modular::Retrieve;
12use common::Generate;
13use core::fmt::Debug;
14use subtle::{ConditionallySelectable, ConstantTimeEq, CtOption};
15use zeroize::DefaultIsZeroes;
16
17pub trait CurveArithmetic: Curve {
19 type AffinePoint: 'static
21 + AffineCoordinates<FieldRepr = FieldBytes<Self>>
22 + Copy
23 + ConditionallySelectable
24 + ConstantTimeEq
25 + CtEq
26 + CtSelect
27 + CurveAffine<Curve = Self::ProjectivePoint, Scalar = Self::Scalar>
28 + Debug
29 + Default
30 + DefaultIsZeroes
31 + Eq
32 + From<NonIdentity<Self::AffinePoint>>
33 + Generate
34 + MulVartime<Self::Scalar>
35 + for<'a> MulVartime<&'a Self::Scalar>
36 + PartialEq
37 + Sized
38 + Send
39 + Sync
40 + TryInto<NonIdentity<Self::AffinePoint>, Error = Error>;
41
42 type ProjectivePoint: ConditionallySelectable
54 + ConstantTimeEq
55 + CtEq
56 + CtSelect
57 + Default
58 + DefaultIsZeroes
59 + From<Self::AffinePoint>
60 + From<NonIdentity<Self::ProjectivePoint>>
61 + Generate
62 + Into<Self::AffinePoint>
63 + LinearCombination<[(Self::ProjectivePoint, Self::Scalar)]>
64 + LinearCombination<[(Self::ProjectivePoint, Self::Scalar); 2]>
65 + MulByGeneratorVartime
66 + MulVartime<Self::Scalar>
67 + for<'a> MulVartime<&'a Self::Scalar>
68 + TryInto<NonIdentity<Self::ProjectivePoint>, Error = Error>
69 + CurveGroup<Affine = Self::AffinePoint>
70 + Group<Scalar = Self::Scalar>;
71
72 type Scalar: AsRef<Self::Scalar>
85 + CtEq
86 + CtSelect
87 + DefaultIsZeroes
88 + From<NonZeroScalar<Self>>
89 + From<ScalarValue<Self>>
90 + FromUintUnchecked<Uint = Self::Uint>
91 + Generate
92 + Into<FieldBytes<Self>>
93 + Into<ScalarValue<Self>>
94 + Into<Self::Uint>
95 + Invert<Output = CtOption<Self::Scalar>>
96 + IsHigh
97 + Mul<Self::AffinePoint, Output = Self::ProjectivePoint>
98 + MulVartime<Self::AffinePoint>
99 + for<'a> Mul<&'a Self::AffinePoint, Output = Self::ProjectivePoint>
100 + for<'a> MulVartime<&'a Self::AffinePoint>
101 + Mul<Self::ProjectivePoint, Output = Self::ProjectivePoint>
102 + MulVartime<Self::ProjectivePoint>
103 + for<'a> Mul<&'a Self::ProjectivePoint, Output = Self::ProjectivePoint>
104 + for<'a> MulVartime<&'a Self::ProjectivePoint>
105 + PartialOrd
106 + Reduce<Self::Uint>
107 + Reduce<FieldBytes<Self>>
108 + Retrieve<Output = Self::Uint>
109 + TryInto<NonZeroScalar<Self>, Error = Error>
110 + ff::PrimeField<Repr = FieldBytes<Self>>;
111}
112
113pub trait PrimeCurveArithmetic:
115 PrimeCurve + CurveArithmetic<ProjectivePoint = Self::CurveGroup>
116{
117 type CurveGroup: group::prime::PrimeCurve<Affine = <Self as CurveArithmetic>::AffinePoint>;
119}