|
1 | 1 | use super::MapToCurve; |
2 | 2 | use crate::{ |
3 | 3 | hash2field::{hash_to_field, ExpandMsg, FromOkm}, |
4 | | - Result, |
| 4 | + ProjectiveArithmetic, Result, |
5 | 5 | }; |
6 | 6 | use group::cofactor::CofactorGroup; |
7 | 7 |
|
8 | 8 | /// Adds hashing arbitrary byte sequences to a valid group element |
9 | | -pub trait GroupDigest { |
| 9 | +pub trait GroupDigest: ProjectiveArithmetic<ProjectivePoint = Self::Output> { |
10 | 10 | /// 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>; |
12 | 16 | /// 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>; |
15 | 18 |
|
16 | 19 | /// Computes the hash to curve routine according to |
17 | 20 | /// <https://www.ietf.org/archive/id/draft-irtf-cfrg-hash-to-curve-13.html> |
@@ -69,4 +72,13 @@ pub trait GroupDigest { |
69 | 72 | let q0 = Self::Output::map_to_curve(u[0]); |
70 | 73 | Ok(q0.clear_cofactor()) |
71 | 74 | } |
| 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 | + } |
72 | 84 | } |
0 commit comments