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::{biginteger::BigInteger256, 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
 22impl TEModelParameters for EdwardsParameters {
 23    /// COEFF_A = -1
 24    #[rustfmt::skip]
 25    const COEFF_A: Fq = field_new!(Fq, BigInteger256([
 26        0x8cf500000000000e,
 27        0xe75281ef6000000e,
 28        0x49dc37a90b0ba012,
 29        0x55f8b2c6e710ab9,
 30    ]));
 31
 32    /// COEFF_D = 3021
 33    #[rustfmt::skip]
 34    const COEFF_D: Fq = field_new!(Fq, BigInteger256([
 35        0xd047ffffffff5e30,
 36        0xf0a91026ffff57d2,
 37        0x9013f560d102582,
 38        0x9fd242ca7be5700,
 39    ]));
 40
 41    /// COFACTOR = 4
 42    const COFACTOR: &'static [u64] = &[4];
 43
 44    /// COFACTOR_INV =
 45    /// 527778859339273151515551558673846658209717731602102048798421311598680340096
 46    #[rustfmt::skip]
 47    const COFACTOR_INV: Fr = field_new!(Fr, BigInteger256([
 48        10836190823041854989,
 49        14880086764632731920,
 50        5023208332782666747,
 51        239524813690824359,
 52    ]));
 53
 54    /// Generated randomly
 55    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
 56
 57    type MontgomeryModelParameters = EdwardsParameters;
 58
 59    /// Multiplication by `a` is just negation.
 60    /// Is `a` 1 or -1?
 61    #[inline(always)]
 62    fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField {
 63        -*elem
 64    }
 65}
 66
 67impl MontgomeryModelParameters for EdwardsParameters {
 68    /// COEFF_A = 0x8D26E3FADA9010A26949031ECE3971B93952AD84D4753DDEDB748DA37E8F552
 69    #[rustfmt::skip]
 70    const COEFF_A: Fq = field_new!(Fq, BigInteger256([
 71        13800168384327121454u64,
 72        6841573379969807446u64,
 73        12529593083398462246u64,
 74        853978956621483129u64,
 75    ]));
 76    /// COEFF_B = 0x9D8F71EEC83A44C3A1FBCEC6F5418E5C6154C2682B8AC231C5A3725C8170AAD
 77    #[rustfmt::skip]
 78    const COEFF_B: Fq = field_new!(Fq, BigInteger256([
 79        7239382437352637935u64,
 80        14509846070439283655u64,
 81        5083066350480839936u64,
 82        1265663645916442191u64,
 83    ]));
 84
 85    type TEModelParameters = EdwardsParameters;
 86}
 87
 88/// GENERATOR_X =
 89/// 7810607721416582242904415504650443951498042435501746664987470571546413371306
 90#[rustfmt::skip]
 91const GENERATOR_X: Fq = field_new!(Fq, BigInteger256([
 92    0x5bbc9878d817221d,
 93    0xd2b03489424e720,
 94    0x6b66f128c16bb3c9,
 95    0xdd3bff78733576d,
 96]));
 97
 98/// GENERATOR_Y =
 99/// 1867362672570137759132108893390349941423731440336755218616442213142473202417
100#[rustfmt::skip]
101const GENERATOR_Y: Fq = field_new!(Fq, BigInteger256([
102    0x471517ae5e5e979e,
103    0xd9c97f6a73a7ff83,
104    0x85a95b45a5494402,
105    0xfad27c9b545b1f0,
106]));