ec/curve_ops.rs
1//! Generic curve abstraction.
2//!
3//! The main goal of this trait is to decouple:
4//! 1. the **curve model** (short Weierstrass, Montgomery, Edwards, ...), and
5//! 2. the **point representation** (affine, projective, x-only, ...).
6//!
7//! Each concrete curve type chooses its base field and its native point type
8//! through associated types.
9
10use fp::field_ops::FieldOps;
11use crate::point_ops::PointOps;
12
13/// Generic elliptic-curve model.
14///
15/// A curve model fixes:
16/// - the base field,
17/// - the point type used with that model,
18/// - and the membership test `is_on_curve`.
19///
20/// This is intentionally minimal so that different models (Montgomery,
21/// short/general Weierstrass, Edwards, Hessian, ...)
22/// can implement it without being forced into one particular formula set.
23pub trait Curve: Sized + Clone + PartialEq + Eq {
24 /// Base field of the curve.
25 type BaseField: FieldOps;
26
27 /// Native point representation for this curve model.
28 type Point: PointOps<Curve = Self, BaseField = Self::BaseField>;
29
30 /// Return `true` if `point` is a valid point on this curve.
31 fn is_on_curve(&self, point: &Self::Point) -> bool;
32
33 /// Return a random point that is on the curve.
34 fn random_point(&self, rng: &mut (impl rand::CryptoRng + rand::Rng)) -> Self::Point;
35
36 /// Return the j_invariant of the curve;
37 fn j_invariant(&self) -> Self::BaseField;
38
39 // Return the a-invariants of the curve.
40 ///
41 /// The interpretation depends on the curve model:
42 /// - **Weierstrass** \to `[a_1, a_2, a_3, a_4, a_6]` (5 elements)
43 /// - **Montgomery** \to `[A, B]` (2 elements)
44 /// - **Edwards** \to `[a, d]` (2 elements)
45 fn a_invariants(&self) -> Vec<Self::BaseField>;
46
47 /// Return the group identity.
48 fn identity(&self) -> Self::Point {
49 Self::Point::identity(self)
50 }
51}