halo2curves/pasta/
vesta.rs

1use core::{
2    cmp,
3    fmt::Debug,
4    iter::Sum,
5    ops::{Add, Mul, Neg, Sub},
6};
7
8use ff::{Field, PrimeField, WithSmallOrderMulGroup};
9use rand::RngCore;
10use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
11
12use super::{fp::Fp, fq::Fq};
13use crate::{
14    group::{cofactor::CofactorGroup, prime::PrimeCurveAffine, Curve, Group, GroupEncoding},
15    impl_binops_additive, impl_binops_additive_specify_output, impl_binops_multiplicative,
16    impl_binops_multiplicative_mixed, new_curve_impl, Coordinates, CurveAffine, CurveExt,
17};
18
19new_curve_impl!(
20    (pub),
21    Vesta,
22    VestaAffine,
23    Fq,
24    Fp,
25    (- Fq::ONE, Fq::from_raw([2,0,0,0])),
26    Fq::ZERO,// Curve a parameter
27    Fq::from_raw([5,0,0,0]),// Curve b parameter
28    "vesta",
29    |domain_prefix| crate::hash_to_curve::hash_to_curve(domain_prefix, Vesta::default_hash_to_curve_suite()),
30    crate::serde::CompressedFlagConfig::SingleSpare,
31    standard_sign
32);
33
34// NOTE: Temporary impl to satisfy macro requirements
35
36impl CofactorGroup for Vesta {
37    type Subgroup = Vesta;
38
39    fn clear_cofactor(&self) -> Self {
40        *self
41    }
42
43    fn into_subgroup(self) -> CtOption<Self::Subgroup> {
44        CtOption::new(self, 1.into())
45    }
46
47    fn is_torsion_free(&self) -> Choice {
48        1.into()
49    }
50}
51
52impl Vesta {
53    /// Z = -13
54    pub const SVDW_Z: Fq = Fq::from_raw([
55        0x8c46eb20fffffff4,
56        0x224698fc0994a8dd,
57        0x0000000000000000,
58        0x4000000000000000,
59    ]);
60    fn default_hash_to_curve_suite() -> crate::hash_to_curve::Suite<Self, sha2::Sha256, 48> {
61        crate::hash_to_curve::Suite::<Vesta, sha2::Sha256, 48>::new(
62            b"vesta:SHA-256_SVDW_RO_",
63            Self::SVDW_Z,
64            crate::hash_to_curve::Method::SVDW,
65        )
66    }
67}
68
69#[cfg(test)]
70mod test {
71    use group::UncompressedEncoding;
72    use rand_core::OsRng;
73
74    use super::*;
75    use crate::{curve_testing_suite, serde::SerdeObject};
76
77    curve_testing_suite!(
78        Vesta,
79        "constants",
80        Fq::MODULUS,
81        Fq::ZERO,
82        Fq::from_raw([5, 0, 0, 0]),
83        -Fq::ONE,
84        Fq::from_raw([2, 0, 0, 0]),
85        Fp::MODULUS
86    );
87
88    curve_testing_suite!(Vesta);
89    curve_testing_suite!(Vesta, "endo_consistency");
90    curve_testing_suite!(Vesta, "ecdsa_example");
91}