1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// This trait resresents elliptic curve and its scalar field
use super::{algebra::Ring, basic::Basic, comp::ParityCmp, field::PrimeField};
/// y^2 = x^3 + ax + b
use core::ops::Mul;

pub trait Affine: ParityCmp + Basic + PartialEq + Eq {
    // scalar field of curve
    type ScalarField: PrimeField;

    // range field of curve
    type RangeField: PrimeField;

    // projective coordinate representation
    type Projective: Projective;

    // a param
    const PARAM_A: Self::RangeField;

    // b param
    const PARAM_B: Self::RangeField;

    // convert affine to projective representation
    fn to_projective(self) -> Self::Projective;

    // check that point is on curve
    fn is_identity(self) -> bool;

    // check that point is on curve
    fn is_on_curve(self) -> bool;
}

pub trait Projective: ParityCmp + Basic + Ring + Mul<Self::ScalarField, Output = Self> {
    // scalar field of curve
    type ScalarField: PrimeField;

    // range field of curve
    type RangeField: PrimeField;

    // affine coordinate representation
    type Affine: Affine;

    // a param
    const PARAM_A: Self::RangeField;

    // b param
    const PARAM_B: Self::RangeField;

    // convert projective to affine representation
    fn to_affine(self) -> Self::Affine;

    // check that point is on curve
    fn is_identity(self) -> bool;

    // doubling this point
    fn double(self) -> Self;

    // check that point is on curve
    fn is_on_curve(self) -> bool;

    // get x coordinate
    fn get_x(&self) -> Self::RangeField;

    // get y coordinate
    fn get_y(&self) -> Self::RangeField;

    // get z coordinate
    fn get_z(&self) -> Self::RangeField;

    // set x coordinate
    fn set_x(&mut self, value: Self::RangeField);

    // set y coordinate
    fn set_y(&mut self, value: Self::RangeField);

    // set z coordinate
    fn set_z(&mut self, value: Self::RangeField);
}