From 12230a49e058e3aa17ff72f82e2f4ac287dd33e8 Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Mon, 22 Feb 2021 16:30:05 -0700 Subject: [PATCH] Move CURVE_ID to CurveExt. --- src/arithmetic/curves.rs | 6 +++--- src/pasta/curves.rs | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/arithmetic/curves.rs b/src/arithmetic/curves.rs index 37dd97a..3cffdbd 100644 --- a/src/arithmetic/curves.rs +++ b/src/arithmetic/curves.rs @@ -33,6 +33,9 @@ pub trait CurveExt: + Mul + for<'r> Mul; + /// CURVE_ID used for hash-to-curve. + const CURVE_ID: &'static str; + /// Apply the curve endomorphism by multiplying the x-coordinate /// by an element of multiplicative order 3. fn endo(&self) -> Self; @@ -96,9 +99,6 @@ pub trait CurveAffine: /// The projective form of the curve type CurveExt: CurveExt::ScalarExt>; - /// CURVE_ID used for hash-to-curve. - const CURVE_ID: &'static str; - /// Gets the $(x, y)$ coordinates of this point. fn get_xy(&self) -> CtOption<(Self::Base, Self::Base)>; diff --git a/src/pasta/curves.rs b/src/pasta/curves.rs index b687b20..006d693 100644 --- a/src/pasta/curves.rs +++ b/src/pasta/curves.rs @@ -92,7 +92,9 @@ macro_rules! new_curve_impl { type Base = $base; type AffineExt = $name_affine; - impl_projective_curve_ext!($name, $name_affine, $iso, $base, $curve_type); + const CURVE_ID: &'static str = $curve_id; + + impl_projective_curve_ext!($name, $iso, $base, $curve_type); fn a() -> Self::Base { $name::curve_constant_a() @@ -615,8 +617,6 @@ macro_rules! new_curve_impl { type Base = $base; type CurveExt = $name; - const CURVE_ID: &'static str = $curve_id; - fn is_on_curve(&self) -> Choice { // y^2 - x^3 - ax ?= b (self.y.square() - (self.x.square() + &$name::curve_constant_a()) * self.x).ct_eq(&$name::curve_constant_b()) @@ -834,13 +834,13 @@ macro_rules! impl_projective_curve_specific { } macro_rules! impl_projective_curve_ext { - ($name:ident, $name_affine:ident, $iso:ident, $base:ident, special_a0_b5) => { + ($name:ident, $iso:ident, $base:ident, special_a0_b5) => { fn hash_to_curve<'a>(domain_prefix: &'a str) -> Box Self + 'a> { use super::hashtocurve; Box::new(move |message| { let mut us = [Field::zero(); 2]; - hashtocurve::hash_to_field($name_affine::CURVE_ID, domain_prefix, message, &mut us); + hashtocurve::hash_to_field($name::CURVE_ID, domain_prefix, message, &mut us); let q0 = hashtocurve::map_to_curve_simple_swu::<$base, $name, $iso>( &us[0], $name::THETA, @@ -867,7 +867,7 @@ macro_rules! impl_projective_curve_ext { } } }; - ($name:ident, $name_affine:ident, $iso:ident, $base:ident, general) => { + ($name:ident, $iso:ident, $base:ident, general) => { /// Unimplemented: hashing to this curve is not supported fn hash_to_curve<'a>(_domain_prefix: &'a str) -> Box Self + 'a> { unimplemented!()