Skip to main content

elliptic_curve/
arithmetic.rs

1//! Elliptic curve arithmetic traits.
2
3use crate::{Curve, FieldBytes};
4use core::fmt::Debug;
5use subtle::{ConditionallySelectable, ConstantTimeEq};
6
7/// Elliptic curve with affine arithmetic implementation.
8#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
9pub trait AffineArithmetic: Curve + ScalarArithmetic {
10    /// Elliptic curve point in affine coordinates.
11    type AffinePoint: Copy
12        + Clone
13        + ConditionallySelectable
14        + ConstantTimeEq
15        + Debug
16        + Default
17        + Sized
18        + Send
19        + Sync
20        + 'static;
21}
22
23/// Elliptic curve with projective arithmetic implementation.
24#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
25pub trait ProjectiveArithmetic: Curve + AffineArithmetic {
26    /// Elliptic curve point in projective coordinates.
27    ///
28    /// Note: the following bounds are enforced by [`group::Group`]:
29    /// - `Copy`
30    /// - `Clone`
31    /// - `Debug`
32    /// - `Eq`
33    /// - `Sized`
34    /// - `Send`
35    /// - `Sync`
36    type ProjectivePoint: ConditionallySelectable
37        + ConstantTimeEq
38        + Default
39        + From<Self::AffinePoint>
40        + Into<Self::AffinePoint>
41        + group::Curve<AffineRepr = Self::AffinePoint>
42        + group::Group<Scalar = Self::Scalar>;
43}
44
45/// Scalar arithmetic.
46#[cfg(feature = "arithmetic")]
47#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
48pub trait ScalarArithmetic: Curve {
49    /// Scalar field type.
50    ///
51    /// Note: the following bounds are enforced by [`ff::Field`]:
52    /// - `Copy`
53    /// - `Clone`
54    /// - `ConditionallySelectable`
55    /// - `Debug`
56    /// - `Default`
57    /// - `Send`
58    /// - `Sync`
59    type Scalar: ConstantTimeEq + ff::Field + ff::PrimeField<Repr = FieldBytes<Self>>;
60}