ark-curves-cherry-picked/ed25519/src/curves/mod.rs
ed25519/src/curves/mod.rsRaw
1use crate::{Fq, Fr};
2use ark_ec::{
3 models::CurveConfig,
4 twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig},
5};
6use ark_ff::MontFp;
7
8#[cfg(test)]
9mod tests;
10
11pub type EdwardsAffine = Affine<EdwardsParameters>;
12pub type EdwardsProjective = Projective<EdwardsParameters>;
13
14#[derive(Clone, Default, PartialEq, Eq)]
15pub struct EdwardsParameters;
16
17impl CurveConfig for EdwardsParameters {
18 type BaseField = Fq;
19 type ScalarField = Fr;
20
21 /// COFACTOR = 8
22 const COFACTOR: &'static [u64] = &[8];
23
24 /// COFACTOR_INV (mod r) =
25 /// 2713877091499598330239944961141122840321418634767465352250731601857045344121
26 const COFACTOR_INV: Fr =
27 MontFp!("2713877091499598330239944961141122840321418634767465352250731601857045344121");
28}
29
30impl TECurveConfig for EdwardsParameters {
31 /// COEFF_A = -1
32 const COEFF_A: Fq = MontFp!("-1");
33
34 /// COEFF_D = -121665 / 121666
35 const COEFF_D: Fq =
36 MontFp!("37095705934669439343138083508754565189542113879843219016388785533085940283555");
37
38 /// Standard generators from <https://neuromancer.sk/std/other/Ed25519>.
39 const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y);
40
41 type MontCurveConfig = EdwardsParameters;
42
43 /// Multiplication by `a` is just negation.
44 #[inline(always)]
45 fn mul_by_a(elem: Self::BaseField) -> Self::BaseField {
46 -elem
47 }
48}
49
50// We want to emphasize that this Montgomery curve is not Curve25519.
51impl MontCurveConfig for EdwardsParameters {
52 /// COEFF_A = 486662
53 const COEFF_A: Fq = MontFp!("486662");
54
55 /// COEFF_B = 57896044618658097711785492504343953926634992332820282019728792003956564333285
56 /// This is not one, because ed25519 != curve25519
57 const COEFF_B: Fq =
58 MontFp!("57896044618658097711785492504343953926634992332820282019728792003956564333285");
59
60 type TECurveConfig = EdwardsParameters;
61}
62
63/// GENERATOR_X =
64/// 15112221349535400772501151409588531511454012693041857206046113283949847762202
65const GENERATOR_X: Fq =
66 MontFp!("15112221349535400772501151409588531511454012693041857206046113283949847762202");
67
68/// GENERATOR_Y =
69/// (4/5)
70/// 46316835694926478169428394003475163141307993866256225615783033603165251855960
71const GENERATOR_Y: Fq =
72 MontFp!("46316835694926478169428394003475163141307993866256225615783033603165251855960");