arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
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::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 (mod r) =
26    /// 29745142885578832859584328103315528221570304936126890280067991221921526670592508030983158
27    const COFACTOR_INV: Fr = MontFp!(
28        Fr,
29        "29745142885578832859584328103315528221570304936126890280067991221921526670592508030983158"
30    );
31}
32
33// Many parameters need to be written down in the Montgomery residue form,
34// discussed below. Some useful numbers:
35// R for Fq: 223364648326281414938801705359223029554923725549792420683051274872200260503540791531766876
36// R for Fr: 104384076783966083500464392945960916666734135485183910065100558776489954102951241798239545
37
38impl TEModelParameters for EdwardsParameters {
39    /// COEFF_A = -1
40    /// Needs to be in the Montgomery residue form in Fq
41    /// I.e., -1 * R for Fq
42    ///     = 252557637842979910814547544293825421990201153003031094870216460866964386803867699028196261
43    const COEFF_A: Fq = MontFp!(Fq, "-1");
44
45    /// COEFF_D = 4212
46    /// Needs to be in the Montgomery residue form in Fq
47    /// I.e., 4212 * R for Fq
48    ///     = 389461279836940033614665658623660232171971995346409183754923941118154161474636585314923000
49    const COEFF_D: Fq = MontFp!(Fq, "4212");
50
51    /// Generated randomly
52    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
53
54    type MontgomeryModelParameters = EdwardsParameters;
55
56    /// Multiplication by `a` is just negation.
57    #[inline(always)]
58    fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField {
59        -*elem
60    }
61}
62
63impl MontgomeryModelParameters for EdwardsParameters {
64    /// COEFF_A = 203563247015667910991582090642011229452721346107806307863040223071914240315202967004285204
65    const COEFF_A: Fq = MontFp!(Fq, "203563247015667910991582090642011229452721346107806307863040223071914240315202967004285204");
66
67    /// COEFF_B = 272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931
68    const COEFF_B: Fq = MontFp!(Fq, "272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931");
69
70    type TEModelParameters = EdwardsParameters;
71}
72
73/// GENERATOR_X =
74/// 282406820114868156776872298252698015906762052916420164316497572033519876761239463633892227
75const GENERATOR_X: Fq = MontFp!(
76    Fq,
77    "282406820114868156776872298252698015906762052916420164316497572033519876761239463633892227"
78);
79
80/// GENERATOR_Y =
81/// 452667754940241021433619311795265643711152068500301853535337412655162600774122192283142703
82const GENERATOR_Y: Fq = MontFp!(
83    Fq,
84    "452667754940241021433619311795265643711152068500301853535337412655162600774122192283142703"
85);