diff --git a/givre/src/ciphersuite.rs b/givre/src/ciphersuite.rs index 8ddf1b9..8f85e0d 100644 --- a/givre/src/ciphersuite.rs +++ b/givre/src/ciphersuite.rs @@ -362,3 +362,85 @@ pub fn is_key_share_normalized( ) -> bool { C::is_normalized(&key_share.shared_public_key) } + +/// Overrides multiscalar multiplication used with the ciphersuite +pub struct WithMultiscalar { + _ph: core::marker::PhantomData (C, M)>, +} + +impl Clone for WithMultiscalar { + fn clone(&self) -> Self { + Self { + _ph: core::marker::PhantomData, + } + } +} +impl Copy for WithMultiscalar {} +impl core::fmt::Debug for WithMultiscalar { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("WithMultiscalar") + } +} + +impl> Ciphersuite + for WithMultiscalar +{ + const NAME: &'static str = C::NAME; + type Curve = C::Curve; + type Digest = C::Digest; + type MultiscalarMul = M; + + fn h1(msg: &[&[u8]]) -> Scalar { + C::h1(msg) + } + fn compute_challenge( + group_commitment: &NormalizedPoint>, + group_public_key: &NormalizedPoint>>, + msg: &[u8], + ) -> Scalar { + let group_commitment = NormalizedPoint(group_commitment.0, core::marker::PhantomData); + let group_public_key = NormalizedPoint(group_public_key.0, core::marker::PhantomData); + C::compute_challenge(&group_commitment, &group_public_key, msg) + } + fn h3(msg: &[&[u8]]) -> Scalar { + C::h3(msg) + } + fn h4() -> Self::Digest { + C::h4() + } + fn h5() -> Self::Digest { + C::h5() + } + + type PointBytes = C::PointBytes; + fn serialize_point(point: &Point) -> Self::PointBytes { + C::serialize_point(point) + } + fn deserialize_point(bytes: &[u8]) -> Result, InvalidPoint> { + C::deserialize_point(bytes) + } + + type ScalarBytes = C::ScalarBytes; + const SCALAR_SIZE: usize = C::SCALAR_SIZE; + fn serialize_scalar(scalar: &Scalar) -> Self::ScalarBytes { + C::serialize_scalar(scalar) + } + fn deserialize_scalar(bytes: &[u8]) -> Result, InvalidScalar> { + C::deserialize_scalar(bytes) + } + + type NormalizedPointBytes = C::NormalizedPointBytes; + const NORMALIZED_POINT_SIZE: usize = C::NORMALIZED_POINT_SIZE; + fn serialize_normalized_point>>( + point: &NormalizedPoint, + ) -> Self::NormalizedPointBytes { + let point = NormalizedPoint(*point.0.as_ref(), core::marker::PhantomData); + C::serialize_normalized_point(&point) + } + fn deserialize_normalized_point( + bytes: &[u8], + ) -> Result>, InvalidPoint> { + C::deserialize_normalized_point(bytes) + .map(|point| NormalizedPoint(point.0, core::marker::PhantomData)) + } +}