arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/ed_on_bls12_377/src/curves/mod.rs
ed_on_bls12_377/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<EdwardsParameters>;
13pub type EdwardsProjective = Projective<EdwardsParameters>;
14
15#[derive(Clone, Default, PartialEq, Eq)]
16pub struct EdwardsParameters;
17
18impl CurveConfig for EdwardsParameters {
19    type BaseField = Fq;
20    type ScalarField = Fr;
21
22    /// COFACTOR = 4
23    const COFACTOR: &'static [u64] = &[4];
24
25    /// COFACTOR_INV =
26    /// 527778859339273151515551558673846658209717731602102048798421311598680340096
27    const COFACTOR_INV: Fr =
28        MontFp!("527778859339273151515551558673846658209717731602102048798421311598680340096");
29}
30
31impl TECurveConfig for EdwardsParameters {
32    /// COEFF_A = -1
33    const COEFF_A: Fq = MontFp!("-1");
34
35    /// COEFF_D = 3021
36    const COEFF_D: Fq = MontFp!("3021");
37
38    /// Generated randomly
39    const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y);
40
41    type MontCurveConfig = EdwardsParameters;
42
43    /// Multiplication by `a` is just negation.
44    /// Is `a` 1 or -1?
45    #[inline(always)]
46    fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField {
47        -*elem
48    }
49}
50
51impl MontCurveConfig for EdwardsParameters {
52    /// COEFF_A = 0x8D26E3FADA9010A26949031ECE3971B93952AD84D4753DDEDB748DA37E8F552
53    ///         = 3990301581132929505568273333084066329187552697088022219156688740916631500114
54    const COEFF_A: Fq =
55        MontFp!("3990301581132929505568273333084066329187552697088022219156688740916631500114");
56
57    /// COEFF_B = 0x9D8F71EEC83A44C3A1FBCEC6F5418E5C6154C2682B8AC231C5A3725C8170AAD
58    ///         = 4454160168295440918680551605697480202188346638066041608778544715000777738925
59    const COEFF_B: Fq =
60        MontFp!("4454160168295440918680551605697480202188346638066041608778544715000777738925");
61
62    type TECurveConfig = EdwardsParameters;
63}
64
65/// GENERATOR_X =
66/// 4497879464030519973909970603271755437257548612157028181994697785683032656389,
67const GENERATOR_X: Fq =
68    MontFp!("4497879464030519973909970603271755437257548612157028181994697785683032656389");
69
70/// GENERATOR_Y =
71/// 4357141146396347889246900916607623952598927460421559113092863576544024487809
72const GENERATOR_Y: Fq =
73    MontFp!("4357141146396347889246900916607623952598927460421559113092863576544024487809");