arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/ed_on_cp6_782/src/curves/mod.rs
ed_on_cp6_782/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    /// COFACTOR = 8
23    const COFACTOR: &'static [u64] = &[8];
24
25    /// COFACTOR^(-1) mod r =
26    /// 12124894969357926281749346891948134384518445910386624712788431705725441736421489799867521238554906438478484045560
27    #[rustfmt::skip]
28    const COFACTOR_INV: Fr = field_new!(Fr, "12124894969357926281749346891948134384518445910386624712788431705725441736421489799867521238554906438478484045560");
29}
30
31impl TEModelParameters for EdwardsParameters {
32    /// COEFF_A = -1 =
33    #[rustfmt::skip]
34    const COEFF_A: Fq = field_new!(Fq, "-1");
35
36    /// COEFF_D = 79743
37    #[rustfmt::skip]
38    const COEFF_D: Fq = field_new!(Fq, "79743");
39
40    /// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y)
41    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
42
43    type MontgomeryModelParameters = EdwardsParameters;
44
45    /// Multiplication by `a` is just negation.
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 = 0x95D53EB3F6AC3F7A53C26020144439DC6073BCAE513E03FD06B6B3BAA390F25E51534B26719E33F4CD906D4DA9B535
54    #[rustfmt::skip]
55    const COEFF_A: Fq = field_new!(Fq, "90083623084271891037116870487743067984710080209539149685414147055329063590616489392386084989619674926965747987765");
56    /// COEFF_B = 0x118650763CE64AB4BE743604C8D05013DC2663652A3D58B21ECAB7BFF65B70DB8BA09F9098E61CC903B2F92B2564ACA
57    #[rustfmt::skip]
58    const COEFF_B: Fq = field_new!(Fq, "168580802928697202973535863207150465551683432545375510854470115611391404757724333382582803149953685197474573470410");
59
60    type TEModelParameters = EdwardsParameters;
61}
62
63/// GENERATOR_X =
64/// 174701772324485506941690903512423551998294352968833659960042362742684869862495746426366187462669992073196420267127
65#[rustfmt::skip]
66const GENERATOR_X: Fq = field_new!(Fq, "174701772324485506941690903512423551998294352968833659960042362742684869862495746426366187462669992073196420267127");
67
68/// GENERATOR_Y =
69/// 208487200052258845495340374451540775445408439654930191324011635560142523886549663106522691296420655144190624954833
70#[rustfmt::skip]
71const GENERATOR_Y: Fq = field_new!(Fq, "208487200052258845495340374451540775445408439654930191324011635560142523886549663106522691296420655144190624954833");