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::CurveConfig,
 3    twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig},
 4};
 5use ark_ff::MontFp;
 6
 7use crate::{fq::Fq, fr::Fr};
 8
 9#[cfg(test)]
10mod tests;
11
12pub type EdwardsAffine = Affine<EdwardsConfig>;
13pub type EdwardsProjective = Projective<EdwardsConfig>;
14
15#[derive(Clone, Default, PartialEq, Eq)]
16pub struct EdwardsConfig;
17
18impl CurveConfig for EdwardsConfig {
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        "29745142885578832859584328103315528221570304936126890280067991221921526670592508030983158"
29    );
30}
31
32// Many parameters need to be written down in the Montgomery residue form,
33// discussed below. Some useful numbers:
34// R for Fq: 223364648326281414938801705359223029554923725549792420683051274872200260503540791531766876
35// R for Fr: 104384076783966083500464392945960916666734135485183910065100558776489954102951241798239545
36
37impl TECurveConfig for EdwardsConfig {
38    /// COEFF_A = -1
39    /// Needs to be in the Montgomery residue form in Fq
40    /// I.e., -1 * R for Fq
41    ///     = 252557637842979910814547544293825421990201153003031094870216460866964386803867699028196261
42    const COEFF_A: Fq = MontFp!("-1");
43
44    /// COEFF_D = 4212
45    /// Needs to be in the Montgomery residue form in Fq
46    /// I.e., 4212 * R for Fq
47    ///     = 389461279836940033614665658623660232171971995346409183754923941118154161474636585314923000
48    const COEFF_D: Fq = MontFp!("4212");
49
50    /// Generated randomly
51    const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y);
52
53    type MontCurveConfig = EdwardsConfig;
54
55    /// Multiplication by `a` is just negation.
56    #[inline(always)]
57    fn mul_by_a(elem: Self::BaseField) -> Self::BaseField {
58        -elem
59    }
60}
61
62impl MontCurveConfig for EdwardsConfig {
63    /// COEFF_A = 203563247015667910991582090642011229452721346107806307863040223071914240315202967004285204
64    const COEFF_A: Fq = MontFp!("203563247015667910991582090642011229452721346107806307863040223071914240315202967004285204");
65
66    /// COEFF_B = 272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931
67    const COEFF_B: Fq = MontFp!("272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931");
68
69    type TECurveConfig = EdwardsConfig;
70}
71
72/// GENERATOR_X =
73/// 282406820114868156776872298252698015906762052916420164316497572033519876761239463633892227
74const GENERATOR_X: Fq = MontFp!(
75    "282406820114868156776872298252698015906762052916420164316497572033519876761239463633892227"
76);
77
78/// GENERATOR_Y =
79/// 452667754940241021433619311795265643711152068500301853535337412655162600774122192283142703
80const GENERATOR_Y: Fq = MontFp!(
81    "452667754940241021433619311795265643711152068500301853535337412655162600774122192283142703"
82);