You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.6 KiB

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