Skip to content

Commit

Permalink
Make elligator curve map a static object following revert of revert
Browse files Browse the repository at this point in the history
  • Loading branch information
drskalman committed Jan 12, 2024
1 parent da3f36d commit 4b770e1
Showing 1 changed file with 6 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub trait Elligator2Config: TECurveConfig + MontCurveConfig {
/// Represents the Elligator2 hash-to-curve map defined by `P`.
pub struct Elligator2Map<P: TECurveConfig>(PhantomData<fn() -> P>);

impl<P: Elligator2Config> Elligator2Map<P> {
impl<P: Elligator2Config> MapToCurve<Projective<P>> for Elligator2Map<P> {
/// 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
Expand Down Expand Up @@ -60,18 +60,9 @@ impl<P: Elligator2Config> Elligator2Map<P> {
);
Ok(())
}
}

impl<P: Elligator2Config> MapToCurve<Projective<P>> for Elligator2Map<P> {
fn new() -> Result<Self, HashToCurveError> {
// 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<Affine<P>, HashToCurveError> {
fn map_to_curve(element: P::BaseField) -> Result<Affine<P>, 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
Expand Down Expand Up @@ -273,16 +264,16 @@ mod test {
#[test]
fn map_field_to_curve_elligator2() {
Elligator2Map::<TestElligator2MapToCurveConfig>::check_parameters().unwrap();
let test_map_to_curve = Elligator2Map::<TestElligator2MapToCurveConfig>::new().unwrap();

let mut map_range: Vec<Affine<TestElligator2MapToCurveConfig>> = 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::<TestElligator2MapToCurveConfig>::map_to_curve(F101::from(
current_field_element as u64,
))
.unwrap(),
);
}

Expand Down

0 comments on commit 4b770e1

Please sign in to comment.