Change Group::hash_to_curve to return Result
This commit is contained in:
+3
-3
@@ -58,7 +58,7 @@ pub trait Group: Copy + Sized + for<'a> Mul<&'a <Self as Group>::Scalar, Output
|
|||||||
type UniformBytesLen: ArrayLength<u8>;
|
type UniformBytesLen: ArrayLength<u8>;
|
||||||
|
|
||||||
/// Hashes a slice of pseudo-random bytes of the correct length to a curve point
|
/// Hashes a slice of pseudo-random bytes of the correct length to a curve point
|
||||||
fn hash_to_curve(uniform_bytes: &GenericArray<u8, Self::UniformBytesLen>) -> Self;
|
fn hash_to_curve(uniform_bytes: &GenericArray<u8, Self::UniformBytesLen>) -> Result<Self, InternalPakeError>;
|
||||||
|
|
||||||
/// Get the base point for the group
|
/// Get the base point for the group
|
||||||
fn base_point() -> Self;
|
fn base_point() -> Self;
|
||||||
@@ -128,14 +128,14 @@ impl Group for RistrettoPoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UniformBytesLen = U64;
|
type UniformBytesLen = U64;
|
||||||
fn hash_to_curve(uniform_bytes: &GenericArray<u8, Self::UniformBytesLen>) -> Self {
|
fn hash_to_curve(uniform_bytes: &GenericArray<u8, Self::UniformBytesLen>) -> Result<Self, InternalPakeError> {
|
||||||
// https://caniuse.rs/features/array_gt_32_impls
|
// https://caniuse.rs/features/array_gt_32_impls
|
||||||
let bits: [u8; 64] = {
|
let bits: [u8; 64] = {
|
||||||
let mut bytes = [0u8; 64];
|
let mut bytes = [0u8; 64];
|
||||||
bytes.copy_from_slice(uniform_bytes);
|
bytes.copy_from_slice(uniform_bytes);
|
||||||
bytes
|
bytes
|
||||||
};
|
};
|
||||||
RistrettoPoint::from_uniform_bytes(&bits)
|
Ok(RistrettoPoint::from_uniform_bytes(&bits))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn base_point() -> Self {
|
fn base_point() -> Self {
|
||||||
|
|||||||
+2
-2
@@ -43,9 +43,9 @@ impl GroupWithMapToCurve for RistrettoPoint {
|
|||||||
fn map_to_curve<H: Hash>(msg: &[u8], dst: &[u8]) -> Result<Self, InternalPakeError> {
|
fn map_to_curve<H: Hash>(msg: &[u8], dst: &[u8]) -> Result<Self, InternalPakeError> {
|
||||||
let uniform_bytes =
|
let uniform_bytes =
|
||||||
expand_message_xmd::<H>(msg, dst, <H as Digest>::OutputSize::to_usize())?;
|
expand_message_xmd::<H>(msg, dst, <H as Digest>::OutputSize::to_usize())?;
|
||||||
Ok(<Self as Group>::hash_to_curve(
|
<Self as Group>::hash_to_curve(
|
||||||
&GenericArray::clone_from_slice(&uniform_bytes[..]),
|
&GenericArray::clone_from_slice(&uniform_bytes[..]),
|
||||||
))
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hash_to_scalar<H: Hash>(
|
fn hash_to_scalar<H: Hash>(
|
||||||
|
|||||||
Reference in New Issue
Block a user