From 4b770e137e0dfe50860ee46e37004d20ddf3e4df Mon Sep 17 00:00:00 2001 From: Skalman Date: Fri, 12 Jan 2024 08:42:23 -0500 Subject: [PATCH] Make elligator curve map a static object following revert of revert of #679 --- .../{elligator2/mod.rs => elligator2.rs} | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) rename ec/src/hashing/curve_maps/{elligator2/mod.rs => elligator2.rs} (94%) diff --git a/ec/src/hashing/curve_maps/elligator2/mod.rs b/ec/src/hashing/curve_maps/elligator2.rs similarity index 94% rename from ec/src/hashing/curve_maps/elligator2/mod.rs rename to ec/src/hashing/curve_maps/elligator2.rs index f5a7fcacf..e94ccffde 100644 --- a/ec/src/hashing/curve_maps/elligator2/mod.rs +++ b/ec/src/hashing/curve_maps/elligator2.rs @@ -32,7 +32,7 @@ pub trait Elligator2Config: TECurveConfig + MontCurveConfig { /// Represents the Elligator2 hash-to-curve map defined by `P`. pub struct Elligator2Map(PhantomData P>); -impl Elligator2Map

{ +impl MapToCurve> for Elligator2Map

{ /// Checks if `P` represents a valid Elligator2 map. Panics otherwise. fn check_parameters() -> Result<(), HashToCurveError> { // We assume that the Montgomery curve is correct and as such we do @@ -60,18 +60,9 @@ impl Elligator2Map

{ ); Ok(()) } -} - -impl MapToCurve> for Elligator2Map

{ - fn new() -> Result { - // Checking validity `Elligator2Config` so we actually representing a valid Elligator2 map. - Self::check_parameters()?; - - Ok(Elligator2Map(PhantomData)) - } /// Map an arbitrary base field element `element` to a curve point. - fn map_to_curve(&self, element: P::BaseField) -> Result, HashToCurveError> { + fn map_to_curve(element: P::BaseField) -> Result, HashToCurveError> { // 1. x1 = -(J / K) * inv0(1 + Z * u^2) // 2. If x1 == 0, set x1 = -(J / K) // 3. gx1 = x1^3 + (J / K) * x1^2 + x1 / K^2 @@ -273,16 +264,16 @@ mod test { #[test] fn map_field_to_curve_elligator2() { Elligator2Map::::check_parameters().unwrap(); - let test_map_to_curve = Elligator2Map::::new().unwrap(); let mut map_range: Vec> = vec![]; // We are mapping all elemnts of the field to the curve, verifying that // map is not constant on that set. for current_field_element in 0..101 { map_range.push( - test_map_to_curve - .map_to_curve(F101::from(current_field_element as u64)) - .unwrap(), + Elligator2Map::::map_to_curve(F101::from( + current_field_element as u64, + )) + .unwrap(), ); }