ark-curves-cherry-picked/ed_on_mnt4_298/src/curves/mod.rs
ed_on_mnt4_298/src/curves/mod.rsRaw
1use ark_ec::{
2 models::{ModelParameters, MontgomeryModelParameters, TEModelParameters},
3 twisted_edwards_extended::{GroupAffine, GroupProjective},
4};
5use ark_ff::{biginteger::BigInteger320, field_new};
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
23// Many parameters need to be written down in the Montgomery residue form,
24// discussed below. Some useful numbers:
25// R for Fq: 223364648326281414938801705359223029554923725549792420683051274872200260503540791531766876
26// R for Fr: 104384076783966083500464392945960916666734135485183910065100558776489954102951241798239545
27
28impl TEModelParameters for EdwardsParameters {
29 /// COEFF_A = -1
30 /// Needs to be in the Montgomery residue form in Fq
31 /// I.e., -1 * R for Fq
32 /// = 252557637842979910814547544293825421990201153003031094870216460866964386803867699028196261
33 #[rustfmt::skip]
34 const COEFF_A: Fq = field_new!(Fq, BigInteger320([
35 17882590928154426277u64,
36 6901912683734848330u64,
37 364575608937879866u64,
38 8740893163049517815u64,
39 2181130330288u64,
40 ]));
41
42 /// COEFF_D = 4212
43 /// Needs to be in the Montgomery residue form in Fq
44 /// I.e., 4212 * R for Fq
45 /// = 389461279836940033614665658623660232171971995346409183754923941118154161474636585314923000
46 #[rustfmt::skip]
47 const COEFF_D: Fq = field_new!(Fq, BigInteger320([
48 8040159930071495160u64,
49 16503302848883893212u64,
50 4541498709509651666u64,
51 11429056610118256373u64,
52 3363453258354u64,
53 ]));
54
55 /// COFACTOR = 4
56 const COFACTOR: &'static [u64] = &[4];
57
58 /// COFACTOR_INV (mod r) =
59 /// 29745142885578832859584328103315528221570304936126890280067991221921526670592508030983158
60 /// Needs to be in the Montgomery residue form in Fr
61 /// I.e., 29745142885578832859584328103315528221570304936126890280067991221921526670592508030983158 * R for Fr
62 /// = 55841162081570353734700426339805757388253838807422867796343130916044015196330318480543044
63 #[rustfmt::skip]
64 const COFACTOR_INV: Fr = field_new!(Fr, BigInteger320([
65 6539529304383425860u64,
66 7567022062893857598u64,
67 17399624368177871129u64,
68 14575354999847441509u64,
69 482253688048u64,
70 ]));
71
72 /// Generated randomly
73 const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
74
75 type MontgomeryModelParameters = EdwardsParameters;
76
77 /// Multiplication by `a` is just negation.
78 #[inline(always)]
79 fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField {
80 -*elem
81 }
82}
83
84impl MontgomeryModelParameters for EdwardsParameters {
85 /// COEFF_A = 203563247015667910991582090642011229452721346107806307863040223071914240315202967004285204
86 /// Needs to be in the Montgomery residue form in Fq
87 /// I.e., 203563247015667910991582090642011229452721346107806307863040223071914240315202967004285204 * R for Fq
88 /// = 184958108588233737086787169006685138672129232027042887479256778022373554352621152610883766
89 #[rustfmt::skip]
90 const COEFF_A: Fq = field_new!(Fq, BigInteger320([
91 13866101745789245622u64,
92 14126297534943667090u64,
93 11307578615387704385u64,
94 8263080598809044705u64,
95 1597329401399u64,
96 ]));
97 /// COEFF_B = 272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931
98 /// Needs to be in the Montgomery residue form in Fq
99 // I.e., 272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931 * R for Fq
100 // = 320157167097726084542307919580965705308273073979019302261176143711555219255114245445508756
101 #[rustfmt::skip]
102 const COEFF_B: Fq = field_new!(Fq, BigInteger320([
103 3452336036810055316u64,
104 18124271906235581187u64,
105 7868316676197606962u64,
106 9218705727289990924u64,
107 2764931259177u64,
108 ]));
109
110 type TEModelParameters = EdwardsParameters;
111}
112
113/// GENERATOR_X =
114/// 282406820114868156776872298252698015906762052916420164316497572033519876761239463633892227
115/// Needs to be in the Montgomery residue form in Fq
116/// I.e., 282406820114868156776872298252698015906762052916420164316497572033519876761239463633892227 * R for Fq
117/// = 6917556742108450905978293995070573074174231920036503115659104908111915200040057661385715
118#[rustfmt::skip]
119const GENERATOR_X: Fq = field_new!(Fq, BigInteger320([
120 797921980254612467u64,
121 14323677897559322103u64,
122 16879595040064082265u64,
123 5138786402348661261u64,
124 59741186014u64,
125]));
126
127/// GENERATOR_Y =
128/// 452667754940241021433619311795265643711152068500301853535337412655162600774122192283142703
129/// Needs to be in the Montgomery residue form in Fq
130/// I.e., 452667754940241021433619311795265643711152068500301853535337412655162600774122192283142703 * R for Fq
131/// = 411219337323952690830344109182130393590959634960952808951091963301565250764467583592890490
132#[rustfmt::skip]
133const GENERATOR_Y: Fq = field_new!(Fq, BigInteger320([
134 16522567711648317562u64,
135 4273808507945498262u64,
136 17459848913470201097u64,
137 16519670308098023011u64,
138 3551359510243u64,
139]));