Skip to content

Commit

Permalink
ed25519 ciphersuite: use dalek multiscalar
Browse files Browse the repository at this point in the history
  • Loading branch information
survived committed Apr 22, 2024
1 parent ca49116 commit 23801c0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 83 deletions.
82 changes: 0 additions & 82 deletions givre/src/ciphersuite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,85 +362,3 @@ pub fn is_key_share_normalized<C: Ciphersuite>(
) -> bool {
C::is_normalized(&key_share.shared_public_key)
}

/// Overrides multiscalar multiplication used with the ciphersuite
pub struct WithMultiscalar<C, M> {
_ph: core::marker::PhantomData<fn() -> (C, M)>,
}

impl<C, M> Clone for WithMultiscalar<C, M> {
fn clone(&self) -> Self {
Self {
_ph: core::marker::PhantomData,
}
}
}
impl<C, M> Copy for WithMultiscalar<C, M> {}
impl<C, M> core::fmt::Debug for WithMultiscalar<C, M> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("WithMultiscalar")
}
}

impl<C: Ciphersuite, M: generic_ec::multiscalar::MultiscalarMul<C::Curve>> Ciphersuite
for WithMultiscalar<C, M>
{
const NAME: &'static str = C::NAME;
type Curve = C::Curve;
type Digest = C::Digest;
type MultiscalarMul = M;

fn h1(msg: &[&[u8]]) -> Scalar<Self::Curve> {
C::h1(msg)
}
fn compute_challenge(
group_commitment: &NormalizedPoint<Self, Point<Self::Curve>>,
group_public_key: &NormalizedPoint<Self, NonZero<Point<Self::Curve>>>,
msg: &[u8],
) -> Scalar<Self::Curve> {
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<Self::Curve> {
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::Curve>) -> Self::PointBytes {
C::serialize_point(point)
}
fn deserialize_point(bytes: &[u8]) -> Result<Point<Self::Curve>, InvalidPoint> {
C::deserialize_point(bytes)
}

type ScalarBytes = C::ScalarBytes;
const SCALAR_SIZE: usize = C::SCALAR_SIZE;
fn serialize_scalar(scalar: &Scalar<Self::Curve>) -> Self::ScalarBytes {
C::serialize_scalar(scalar)
}
fn deserialize_scalar(bytes: &[u8]) -> Result<Scalar<Self::Curve>, InvalidScalar> {
C::deserialize_scalar(bytes)
}

type NormalizedPointBytes = C::NormalizedPointBytes;
const NORMALIZED_POINT_SIZE: usize = C::NORMALIZED_POINT_SIZE;
fn serialize_normalized_point<P: AsRef<Point<Self::Curve>>>(
point: &NormalizedPoint<Self, P>,
) -> Self::NormalizedPointBytes {
let point = NormalizedPoint(*point.0.as_ref(), core::marker::PhantomData);
C::serialize_normalized_point(&point)
}
fn deserialize_normalized_point(
bytes: &[u8],
) -> Result<NormalizedPoint<Self, Point<Self::Curve>>, InvalidPoint> {
C::deserialize_normalized_point(bytes)
.map(|point| NormalizedPoint(point.0, core::marker::PhantomData))
}
}
2 changes: 1 addition & 1 deletion givre/src/ciphersuite/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl Ciphersuite for Ed25519 {

type Curve = generic_ec::curves::Ed25519;
type Digest = sha2::Sha512;
type MultiscalarMul = generic_ec::multiscalar::Default;
type MultiscalarMul = generic_ec::multiscalar::Dalek;

fn h1(msg: &[&[u8]]) -> generic_ec::Scalar<Self::Curve> {
let mut hash = sha2::Sha512::new()
Expand Down

0 comments on commit 23801c0

Please sign in to comment.