ark-curves-cherry-picked/ed_on_cp6_782/src/curves/mod.rs
ed_on_cp6_782/src/curves/mod.rsRaw
1use ark_ec::{
2 models::{ModelParameters, MontgomeryModelParameters, TEModelParameters},
3 twisted_edwards_extended::{GroupAffine, GroupProjective},
4};
5use ark_ff::{biginteger::BigInteger384 as BigInteger, 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
23impl TEModelParameters for EdwardsParameters {
24 /// COEFF_A = -1 =
25 /// 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458176
26 #[rustfmt::skip]
27 const COEFF_A: Fq = field_new!(Fq, BigInteger([
28 9384023879812382873,
29 14252412606051516495,
30 9184438906438551565,
31 11444845376683159689,
32 8738795276227363922,
33 81297770384137296,
34 ]));
35
36 /// COEFF_D = 79743
37 #[rustfmt::skip]
38 const COEFF_D: Fq = field_new!(Fq, BigInteger([
39 0x4669ffffff46a638,
40 0xa56bbe0a7f9fae05,
41 0x403b425466a710b4,
42 0xf6648db6ea4e988b,
43 0x74d51b5923d35a8d,
44 0xf8ed90b17fe903,
45 ]));
46
47 /// COFACTOR = 8
48 const COFACTOR: &'static [u64] = &[8];
49
50 /// COFACTOR^(-1) mod r =
51 /// 12124894969357926281749346891948134384518445910386624712788431705725441736421489799867521238554906438478484045560
52 #[rustfmt::skip]
53 const COFACTOR_INV: Fr = field_new!(Fr, BigInteger([
54 7353538464571651976,
55 2030910049503177537,
56 16726103313845754033,
57 1110650741117127777,
58 5304838729792721053,
59 4975067790294675,
60 ]));
61
62 /// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y)
63 const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
64
65 type MontgomeryModelParameters = EdwardsParameters;
66
67 /// Multiplication by `a` is just negation.
68 #[inline(always)]
69 fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField {
70 -*elem
71 }
72}
73
74impl MontgomeryModelParameters for EdwardsParameters {
75 /// COEFF_A = 0x95D53EB3F6AC3F7A53C26020144439DC6073BCAE513E03FD06B6B3BAA390F25E51534B26719E33F4CD906D4DA9B535
76 #[rustfmt::skip]
77 const COEFF_A: Fq = field_new!(Fq, BigInteger([
78 7594254284108454966u64,
79 14287343397973578077u64,
80 6490358977072726023u64,
81 8023375322051995268u64,
82 8242802613686040715u64,
83 100541941146122331u64,
84 ]));
85 /// COEFF_B = 0x118650763CE64AB4BE743604C8D05013DC2663652A3D58B21ECAB7BFF65B70DB8BA09F9098E61CC903B2F92B2564ACA
86 #[rustfmt::skip]
87 const COEFF_B: Fq = field_new!(Fq, BigInteger([
88 11173793475516310780u64,
89 14217481814129454913u64,
90 11878518835804377107u64,
91 14866315431314324110u64,
92 9234787938768687129u64,
93 62053599622152261u64,
94 ]));
95
96 type TEModelParameters = EdwardsParameters;
97}
98
99/// GENERATOR_X =
100/// 174701772324485506941690903512423551998294352968833659960042362742684869862495746426366187462669992073196420267127
101#[rustfmt::skip]
102const GENERATOR_X: Fq = field_new!(Fq, BigInteger([
103 3737364149926089590,
104 13002967008679663837,
105 9954144214462864555,
106 3365719140389487049,
107 8643066672427471196,
108 120355578793479865,
109]));
110
111/// GENERATOR_Y =
112/// 208487200052258845495340374451540775445408439654930191324011635560142523886549663106522691296420655144190624954833
113#[rustfmt::skip]
114const GENERATOR_Y: Fq = field_new!(Fq, BigInteger([
115 6027299446526298157,
116 12854429557810467099,
117 11207279014226687864,
118 17040621363687352702,
119 6112671509202865855,
120 44040319652922447,
121]));