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::{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, "-1");
35
36    /// COEFF_D = 4212
37    /// Needs to be in the Montgomery residue form in Fq
38    /// I.e., 4212 * R for Fq
39    ///     = 389461279836940033614665658623660232171971995346409183754923941118154161474636585314923000
40    #[rustfmt::skip]
41    const COEFF_D: Fq = field_new!(Fq, "4212");
42
43    /// COFACTOR = 4
44    const COFACTOR: &'static [u64] = &[4];
45
46    /// COFACTOR_INV (mod r) =
47    /// 29745142885578832859584328103315528221570304936126890280067991221921526670592508030983158
48    #[rustfmt::skip]
49    const COFACTOR_INV: Fr = field_new!(Fr, "29745142885578832859584328103315528221570304936126890280067991221921526670592508030983158");
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    #[rustfmt::skip]
66    const COEFF_A: Fq = field_new!(Fq, "203563247015667910991582090642011229452721346107806307863040223071914240315202967004285204");
67    /// COEFF_B = 272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931
68    #[rustfmt::skip]
69    const COEFF_B: Fq = field_new!(Fq, "272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931");
70
71    type TEModelParameters = EdwardsParameters;
72}
73
74/// GENERATOR_X =
75/// 282406820114868156776872298252698015906762052916420164316497572033519876761239463633892227
76#[rustfmt::skip]
77const GENERATOR_X: Fq = field_new!(Fq, "282406820114868156776872298252698015906762052916420164316497572033519876761239463633892227");
78
79/// GENERATOR_Y =
80/// 452667754940241021433619311795265643711152068500301853535337412655162600774122192283142703
81#[rustfmt::skip]
82const GENERATOR_Y: Fq = field_new!(Fq, "452667754940241021433619311795265643711152068500301853535337412655162600774122192283142703");