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.

85 lines
2.6 KiB

  1. use crate::{fq::Fq, fr::Fr};
  2. use ark_ec::{
  3. models::CurveConfig,
  4. scalar_mul::glv::GLVConfig,
  5. short_weierstrass::{self as sw, SWCurveConfig},
  6. };
  7. use ark_ff::{AdditiveGroup, BigInt, Field, MontFp, PrimeField, Zero};
  8. #[cfg(test)]
  9. mod tests;
  10. #[derive(Copy, Clone, Default, PartialEq, Eq)]
  11. pub struct VestaConfig;
  12. impl CurveConfig for VestaConfig {
  13. type BaseField = Fq;
  14. type ScalarField = Fr;
  15. /// COFACTOR = 1
  16. const COFACTOR: &'static [u64] = &[0x1];
  17. /// COFACTOR_INV = 1
  18. const COFACTOR_INV: Fr = Fr::ONE;
  19. }
  20. pub type Affine = sw::Affine<VestaConfig>;
  21. pub type Projective = sw::Projective<VestaConfig>;
  22. impl SWCurveConfig for VestaConfig {
  23. /// COEFF_A = 0
  24. const COEFF_A: Fq = Fq::ZERO;
  25. /// COEFF_B = 5
  26. const COEFF_B: Fq = MontFp!("5");
  27. /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y)
  28. const GENERATOR: Affine = Affine::new_unchecked(G_GENERATOR_X, G_GENERATOR_Y);
  29. #[inline(always)]
  30. fn mul_by_a(_: Self::BaseField) -> Self::BaseField {
  31. Self::BaseField::zero()
  32. }
  33. }
  34. impl GLVConfig for VestaConfig {
  35. const ENDO_COEFFS: &'static [Self::BaseField] = &[MontFp!(
  36. "26005156700822196841419187675678338661165322343552424574062261873906994770353"
  37. )];
  38. const LAMBDA: Self::ScalarField =
  39. MontFp!("20444556541222657078399132219657928148671392403212669005631716460534733845831");
  40. const SCALAR_DECOMP_COEFFS: [(bool, <Self::ScalarField as PrimeField>::BigInt); 4] = [
  41. (false, BigInt!("98231058071100081932162823354453065729")),
  42. (true, BigInt!("98231058071186745657228807397848383488")),
  43. (false, BigInt!("196462116142286827589391630752301449217")),
  44. (false, BigInt!("98231058071100081932162823354453065729")),
  45. ];
  46. fn endomorphism(p: &Projective) -> Projective {
  47. // Endomorphism of the points on the curve.
  48. // endomorphism_p(x,y) = (BETA * x, y)
  49. // where BETA is a non-trivial cubic root of unity in Fq.
  50. let mut res = (*p).clone();
  51. res.x *= Self::ENDO_COEFFS[0];
  52. res
  53. }
  54. fn endomorphism_affine(p: &Affine) -> Affine {
  55. // Endomorphism of the points on the curve.
  56. // endomorphism_p(x,y) = (BETA * x, y)
  57. // where BETA is a non-trivial cubic root of unity in Fq.
  58. let mut res = (*p).clone();
  59. res.x *= Self::ENDO_COEFFS[0];
  60. res
  61. }
  62. }
  63. /// G_GENERATOR_X = -1
  64. /// Encoded in Montgomery form, so the value here is -R mod p.
  65. pub const G_GENERATOR_X: Fq = MontFp!("-1");
  66. /// G_GENERATOR_Y = 2
  67. /// Encoded in Montgomery form, so the value here is 2R mod p.
  68. pub const G_GENERATOR_Y: Fq = MontFp!("2");