ark-curves-cherry-picked/ed_on_bls12_377/src/curves/mod.rs
ed_on_bls12_377/src/curves/mod.rsRaw
1use ark_ec::{
2 models::{ModelParameters, MontgomeryModelParameters, TEModelParameters},
3 twisted_edwards_extended::{GroupAffine, GroupProjective},
4};
5use ark_ff::MontFp;
6
7use crate::{fq::Fq, fr::Fr};
8
9#[cfg(test)]
10mod tests;
11
12pub type EdwardsAffine = GroupAffine<EdwardsParameters>;
13pub type EdwardsProjective = GroupProjective<EdwardsParameters>;
14
15#[derive(Clone, Default, PartialEq, Eq)]
16pub struct EdwardsParameters;
17
18impl ModelParameters for EdwardsParameters {
19 type BaseField = Fq;
20 type ScalarField = Fr;
21
22 /// COFACTOR = 4
23 const COFACTOR: &'static [u64] = &[4];
24
25 /// COFACTOR_INV =
26 /// 527778859339273151515551558673846658209717731602102048798421311598680340096
27 const COFACTOR_INV: Fr = MontFp!(
28 Fr,
29 "527778859339273151515551558673846658209717731602102048798421311598680340096"
30 );
31}
32
33impl TEModelParameters for EdwardsParameters {
34 /// COEFF_A = -1
35 const COEFF_A: Fq = MontFp!(Fq, "-1");
36
37 /// COEFF_D = 3021
38 const COEFF_D: Fq = MontFp!(Fq, "3021");
39
40 /// Generated randomly
41 const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
42
43 type MontgomeryModelParameters = EdwardsParameters;
44
45 /// Multiplication by `a` is just negation.
46 /// Is `a` 1 or -1?
47 #[inline(always)]
48 fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField {
49 -*elem
50 }
51}
52
53impl MontgomeryModelParameters for EdwardsParameters {
54 /// COEFF_A = 0x8D26E3FADA9010A26949031ECE3971B93952AD84D4753DDEDB748DA37E8F552
55 /// = 3990301581132929505568273333084066329187552697088022219156688740916631500114
56 const COEFF_A: Fq = MontFp!(
57 Fq,
58 "3990301581132929505568273333084066329187552697088022219156688740916631500114"
59 );
60
61 /// COEFF_B = 0x9D8F71EEC83A44C3A1FBCEC6F5418E5C6154C2682B8AC231C5A3725C8170AAD
62 /// = 4454160168295440918680551605697480202188346638066041608778544715000777738925
63 const COEFF_B: Fq = MontFp!(
64 Fq,
65 "4454160168295440918680551605697480202188346638066041608778544715000777738925"
66 );
67
68 type TEModelParameters = EdwardsParameters;
69}
70
71/// GENERATOR_X =
72/// 4497879464030519973909970603271755437257548612157028181994697785683032656389,
73const GENERATOR_X: Fq = MontFp!(
74 Fq,
75 "4497879464030519973909970603271755437257548612157028181994697785683032656389"
76);
77
78/// GENERATOR_Y =
79/// 4357141146396347889246900916607623952598927460421559113092863576544024487809
80const GENERATOR_Y: Fq = MontFp!(
81 Fq,
82 "4357141146396347889246900916607623952598927460421559113092863576544024487809"
83);