hash2curve/map2curve.rs
1//! Traits for mapping field elements to points on the curve.
2
3use elliptic_curve::array::typenum::{NonZero, Unsigned};
4use elliptic_curve::array::{Array, ArraySize};
5use elliptic_curve::group::cofactor::CofactorGroup;
6use elliptic_curve::ops::Reduce;
7use elliptic_curve::{CurveArithmetic, ProjectivePoint};
8
9/// Trait for converting field elements into a point via a mapping method like
10/// Simplified Shallue-van de Woestijne-Ulas or Elligator.
11pub trait MapToCurve:
12 CurveArithmetic<ProjectivePoint: CofactorGroup<Subgroup = Self::ProjectivePoint>>
13{
14 /// The target security level in bytes:
15 /// <https://www.rfc-editor.org/rfc/rfc9380.html#section-8.9-2.2>
16 /// <https://www.rfc-editor.org/rfc/rfc9380.html#name-target-security-levels>
17 type SecurityLevel: Unsigned;
18 /// The field element representation for a group value with multiple elements.
19 type FieldElement: Reduce<Array<u8, Self::Length>> + Default + Copy;
20 /// The `L` parameter as specified in the [RFC](https://www.rfc-editor.org/rfc/rfc9380.html#section-5-6).
21 type Length: ArraySize + NonZero;
22
23 /// Map a field element into a curve point.
24 fn map_to_curve(element: Self::FieldElement) -> ProjectivePoint<Self>;
25}