Skip to content

Commit 24ee6d9

Browse files
committed
Implement hash_to_scalar
1 parent d3fe124 commit 24ee6d9

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

elliptic-curve/src/hash2curve/group_digest.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
use super::MapToCurve;
22
use crate::{
33
hash2field::{hash_to_field, ExpandMsg, FromOkm},
4-
Result,
4+
ProjectiveArithmetic, Result,
55
};
66
use group::cofactor::CofactorGroup;
77

88
/// Adds hashing arbitrary byte sequences to a valid group element
9-
pub trait GroupDigest {
9+
pub trait GroupDigest: ProjectiveArithmetic<ProjectivePoint = Self::Output> {
1010
/// The field element representation for a group value with multiple elements
11-
type FieldElement: FromOkm + Default + Copy;
11+
type FieldElement: FromOkm
12+
+ MapToCurve<Output = Self::Output>
13+
+ Default
14+
+ Copy
15+
+ Into<Self::Scalar>;
1216
/// The resulting group element
13-
type Output: CofactorGroup<Subgroup = Self::Output>
14-
+ MapToCurve<FieldElement = Self::FieldElement, Output = Self::Output>;
17+
type Output: CofactorGroup<Subgroup = Self::Output>;
1518

1619
/// Computes the hash to curve routine according to
1720
/// <https://www.ietf.org/archive/id/draft-irtf-cfrg-hash-to-curve-13.html>
@@ -69,4 +72,13 @@ pub trait GroupDigest {
6972
let q0 = Self::Output::map_to_curve(u[0]);
7073
Ok(q0.clear_cofactor())
7174
}
75+
76+
/// Computes the hash to field routine according to
77+
/// <https://www.ietf.org/archive/id/draft-irtf-cfrg-hash-to-curve-13.html#section-5>
78+
/// and returns a scalar.
79+
fn hash_to_scalar<X: ExpandMsg>(msg: &[u8], dst: &'static [u8]) -> Result<Self::Scalar> {
80+
let mut u = [Self::FieldElement::default()];
81+
hash_to_field::<X, _>(msg, dst, &mut u)?;
82+
Ok(u[0].into())
83+
}
7284
}

elliptic-curve/src/hash2curve/map2curve.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
/// via a mapping method like Simplified Shallue-van de Woestijne-Ulas
33
/// or Elligator
44
pub trait MapToCurve {
5-
/// The input values representing x and y
6-
type FieldElement;
75
/// The output point
86
type Output;
97

108
/// Map a field element into a point
11-
fn map_to_curve(u: Self::FieldElement) -> Self::Output;
9+
fn map_to_curve(u: Self) -> Self::Output;
1210
}

0 commit comments

Comments
 (0)