elliptic_curve/
arithmetic.rs
1use crate::{
4 ops::{Invert, LinearCombination, MulByGenerator, Reduce, ShrAssign},
5 point::AffineCoordinates,
6 scalar::{FromUintUnchecked, IsHigh},
7 Curve, FieldBytes, PrimeCurve, ScalarPrimitive,
8};
9use core::fmt::Debug;
10use subtle::{ConditionallySelectable, ConstantTimeEq, CtOption};
11use zeroize::DefaultIsZeroes;
12
13pub trait CurveArithmetic: Curve {
15 type AffinePoint: 'static
17 + AffineCoordinates<FieldRepr = FieldBytes<Self>>
18 + Copy
19 + ConditionallySelectable
20 + ConstantTimeEq
21 + Debug
22 + Default
23 + DefaultIsZeroes
24 + Eq
25 + PartialEq
26 + Sized
27 + Send
28 + Sync;
29
30 type ProjectivePoint: ConditionallySelectable
42 + ConstantTimeEq
43 + Default
44 + DefaultIsZeroes
45 + From<Self::AffinePoint>
46 + Into<Self::AffinePoint>
47 + LinearCombination
48 + MulByGenerator
49 + group::Curve<AffineRepr = Self::AffinePoint>
50 + group::Group<Scalar = Self::Scalar>;
51
52 type Scalar: AsRef<Self::Scalar>
65 + DefaultIsZeroes
66 + From<ScalarPrimitive<Self>>
67 + FromUintUnchecked<Uint = Self::Uint>
68 + Into<FieldBytes<Self>>
69 + Into<ScalarPrimitive<Self>>
70 + Into<Self::Uint>
71 + Invert<Output = CtOption<Self::Scalar>>
72 + IsHigh
73 + PartialOrd
74 + Reduce<Self::Uint, Bytes = FieldBytes<Self>>
75 + ShrAssign<usize>
76 + ff::Field
77 + ff::PrimeField<Repr = FieldBytes<Self>>;
78}
79
80pub trait PrimeCurveArithmetic:
82 PrimeCurve + CurveArithmetic<ProjectivePoint = Self::CurveGroup>
83{
84 type CurveGroup: group::prime::PrimeCurve<Affine = <Self as CurveArithmetic>::AffinePoint>;
86}