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 crate::{fq::Fq, fr::Fr};
 2use ark_ec::{
 3    models::{ModelParameters, MontgomeryModelParameters, TEModelParameters},
 4    twisted_edwards_extended::{GroupAffine, GroupProjective},
 5};
 6use ark_ff::field_new;
 7
 8#[cfg(test)]
 9mod tests;
10
11pub type EdwardsAffine = GroupAffine<EdwardsParameters>;
12pub type EdwardsProjective = GroupProjective<EdwardsParameters>;
13
14#[derive(Clone, Default, PartialEq, Eq)]
15pub struct EdwardsParameters;
16
17impl ModelParameters for EdwardsParameters {
18    type BaseField = Fq;
19    type ScalarField = Fr;
20
21    /// COFACTOR = 4
22    const COFACTOR: &'static [u64] = &[4];
23
24    /// COFACTOR_INV =
25    /// 527778859339273151515551558673846658209717731602102048798421311598680340096
26    #[rustfmt::skip]
27    const COFACTOR_INV: Fr = field_new!(Fr, "527778859339273151515551558673846658209717731602102048798421311598680340096");
28}
29
30impl TEModelParameters for EdwardsParameters {
31    /// COEFF_A = -1
32    #[rustfmt::skip]
33    const COEFF_A: Fq = field_new!(Fq, "-1");
34
35    /// COEFF_D = 3021
36    #[rustfmt::skip]
37    const COEFF_D: Fq = field_new!(Fq, "3021");
38
39    /// Generated randomly
40    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
41
42    type MontgomeryModelParameters = EdwardsParameters;
43
44    /// Multiplication by `a` is just negation.
45    /// Is `a` 1 or -1?
46    #[inline(always)]
47    fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField {
48        -*elem
49    }
50}
51
52impl MontgomeryModelParameters for EdwardsParameters {
53    /// COEFF_A = 0x8D26E3FADA9010A26949031ECE3971B93952AD84D4753DDEDB748DA37E8F552
54    ///         = 3990301581132929505568273333084066329187552697088022219156688740916631500114
55    #[rustfmt::skip]
56    const COEFF_A: Fq = field_new!(Fq, "3990301581132929505568273333084066329187552697088022219156688740916631500114");
57    /// COEFF_B = 0x9D8F71EEC83A44C3A1FBCEC6F5418E5C6154C2682B8AC231C5A3725C8170AAD
58    ///         = 4454160168295440918680551605697480202188346638066041608778544715000777738925
59    #[rustfmt::skip]
60    const COEFF_B: Fq = field_new!(Fq, "4454160168295440918680551605697480202188346638066041608778544715000777738925");
61
62    type TEModelParameters = EdwardsParameters;
63}
64
65/// GENERATOR_X =
66/// 4497879464030519973909970603271755437257548612157028181994697785683032656389,
67#[rustfmt::skip]
68const GENERATOR_X: Fq = field_new!(Fq, "4497879464030519973909970603271755437257548612157028181994697785683032656389");
69
70/// GENERATOR_Y =
71/// 4357141146396347889246900916607623952598927460421559113092863576544024487809
72#[rustfmt::skip]
73const GENERATOR_Y: Fq = field_new!(Fq, "4357141146396347889246900916607623952598927460421559113092863576544024487809");