elliptic_curve/
arithmetic.rs

1//! Elliptic curve arithmetic traits.
2
3use crate::{
4    ops::LinearCombination, AffineXCoordinate, Curve, FieldBytes, IsHigh, PrimeCurve, ScalarCore,
5};
6use core::fmt::Debug;
7use subtle::{ConditionallySelectable, ConstantTimeEq};
8use zeroize::DefaultIsZeroes;
9
10/// Elliptic curve with affine arithmetic implementation.
11#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
12pub trait AffineArithmetic: Curve + ScalarArithmetic {
13    /// Elliptic curve point in affine coordinates.
14    type AffinePoint: 'static
15        + AffineXCoordinate<Self>
16        + Copy
17        + Clone
18        + ConditionallySelectable
19        + ConstantTimeEq
20        + Debug
21        + Default
22        + DefaultIsZeroes
23        + Eq
24        + PartialEq
25        + Sized
26        + Send
27        + Sync;
28}
29
30/// Prime order elliptic curve with projective arithmetic implementation.
31#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
32pub trait PrimeCurveArithmetic:
33    PrimeCurve + ProjectiveArithmetic<ProjectivePoint = Self::CurveGroup>
34{
35    /// Prime order elliptic curve group.
36    type CurveGroup: group::prime::PrimeCurve<Affine = <Self as AffineArithmetic>::AffinePoint>;
37}
38
39/// Elliptic curve with projective arithmetic implementation.
40#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
41pub trait ProjectiveArithmetic: Curve + AffineArithmetic {
42    /// Elliptic curve point in projective coordinates.
43    ///
44    /// Note: the following bounds are provided by [`group::Group`]:
45    /// - `'static`
46    /// - [`Copy`]
47    /// - [`Clone`]
48    /// - [`Debug`]
49    /// - [`Eq`]
50    /// - [`Sized`]
51    /// - [`Send`]
52    /// - [`Sync`]
53    type ProjectivePoint: ConditionallySelectable
54        + ConstantTimeEq
55        + Default
56        + DefaultIsZeroes
57        + From<Self::AffinePoint>
58        + Into<Self::AffinePoint>
59        + LinearCombination
60        + group::Curve<AffineRepr = Self::AffinePoint>
61        + group::Group<Scalar = Self::Scalar>;
62}
63
64/// Scalar arithmetic.
65#[cfg(feature = "arithmetic")]
66#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
67pub trait ScalarArithmetic: Curve {
68    /// Scalar field type.
69    ///
70    /// Note: the following bounds are provided by [`ff::Field`]:
71    /// - `'static`
72    /// - [`Copy`]
73    /// - [`Clone`]
74    /// - [`ConditionallySelectable`]
75    /// - [`ConstantTimeEq`]
76    /// - [`Debug`]
77    /// - [`Default`]
78    /// - [`Send`]
79    /// - [`Sync`]
80    type Scalar: DefaultIsZeroes
81        + From<ScalarCore<Self>>
82        + Into<FieldBytes<Self>>
83        + Into<Self::UInt>
84        + IsHigh
85        + ff::Field
86        + ff::PrimeField<Repr = FieldBytes<Self>>;
87}