lambdaworks_math/elliptic_curve/
traits.rs1use crate::{
2 cyclic_group::IsGroup,
3 errors::PairingError,
4 field::{element::FieldElement, traits::IsField},
5};
6use core::fmt::Debug;
7
8#[derive(Debug, PartialEq, Eq)]
9pub enum EllipticCurveError {
10 InvalidPoint,
11}
12
13pub trait IsEllipticCurve {
14 type BaseField: IsField + Clone + Debug;
17
18 type PointRepresentation: IsGroup + FromAffine<Self::BaseField>;
22
23 fn generator() -> Self::PointRepresentation;
25
26 fn create_point_from_affine(
28 x: FieldElement<Self::BaseField>,
29 y: FieldElement<Self::BaseField>,
30 ) -> Result<Self::PointRepresentation, EllipticCurveError> {
31 Self::PointRepresentation::from_affine(x, y)
32 }
33}
34
35pub trait FromAffine<F: IsField>: Sized {
36 fn from_affine(x: FieldElement<F>, y: FieldElement<F>) -> Result<Self, EllipticCurveError>;
37}
38
39pub trait IsPairing {
40 type G1Point: IsGroup;
41 type G2Point: IsGroup;
42 type OutputField: IsField;
43
44 fn compute_batch(
47 pairs: &[(&Self::G1Point, &Self::G2Point)],
48 ) -> Result<FieldElement<Self::OutputField>, PairingError>;
49
50 fn compute(
52 p: &Self::G1Point,
53 q: &Self::G2Point,
54 ) -> Result<FieldElement<Self::OutputField>, PairingError> {
55 Self::compute_batch(&[(p, q)])
56 }
57}