From f968f200aae05cfc536b34526412b51ba33f88ba Mon Sep 17 00:00:00 2001 From: Denis Varlakov Date: Mon, 8 Jul 2024 10:20:22 +0200 Subject: [PATCH] Use `Reduce<64>` trait Signed-off-by: Denis Varlakov --- Cargo.lock | 2 -- givre/Cargo.toml | 5 +---- givre/src/ciphersuite/ed25519.rs | 17 +++-------------- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fff3121..e1d1075 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -548,11 +548,9 @@ name = "givre" version = "0.1.0" dependencies = [ "cggmp21-keygen", - "curve25519-dalek", "digest", "futures", "generic-ec", - "generic-ec-curves", "k256", "key-share", "rand_core", diff --git a/givre/Cargo.toml b/givre/Cargo.toml index 64fc25b..224fe24 100644 --- a/givre/Cargo.toml +++ b/givre/Cargo.toml @@ -10,7 +10,6 @@ cggmp21-keygen = { version = "0.3", optional = true } key-share = { version = "0.4", default-features = false } generic-ec = { version = "0.4", default-features = false, features = ["alloc"] } -generic-ec-curves = { version = "0.2", default-features = false, optional = true } rand_core = { version = "0.6", default-features = false } digest = { version = "0.10", default-features = false } @@ -23,8 +22,6 @@ sha2 = { version = "0.10", default-features = false, optional = true } serde = { version = "1", default-features = false, features = ["derive"], optional = true } -curve25519-dalek = { version = "4", default-features = false, optional = true } - [dev-dependencies] rand_core = { version = "0.6", default-features = false, features = ["getrandom"] } futures = "0.3" @@ -50,6 +47,6 @@ hd-wallets = ["key-share/hd-wallets", "cggmp21-keygen?/hd-wallets"] all-ciphersuites = ["ciphersuite-secp256k1", "ciphersuite-ed25519", "ciphersuite-bitcoin"] ciphersuite-secp256k1 = ["generic-ec/curve-secp256k1", "k256", "sha2", "static_assertions"] -ciphersuite-ed25519 = ["generic-ec/curve-ed25519", "sha2", "curve25519-dalek", "generic-ec-curves/ed25519"] +ciphersuite-ed25519 = ["generic-ec/curve-ed25519", "sha2"] ciphersuite-bitcoin = ["ciphersuite-secp256k1"] diff --git a/givre/src/ciphersuite/ed25519.rs b/givre/src/ciphersuite/ed25519.rs index 458526c..8cb7df3 100644 --- a/givre/src/ciphersuite/ed25519.rs +++ b/givre/src/ciphersuite/ed25519.rs @@ -23,7 +23,7 @@ impl Ciphersuite for Ed25519 { } let hash = hash.finalize(); - reduce_512bits_le_scalar_mod_order(&hash.into()) + generic_ec::traits::Reduce::<64>::from_le_array_mod_order(&hash.into()) } fn compute_challenge( @@ -37,7 +37,7 @@ impl Ciphersuite for Ed25519 { .chain_update(msg) .finalize(); - reduce_512bits_le_scalar_mod_order(&hash.into()) + generic_ec::traits::Reduce::<64>::from_le_array_mod_order(&hash.into()) } fn h3(msg: &[&[u8]]) -> generic_ec::Scalar { @@ -49,7 +49,7 @@ impl Ciphersuite for Ed25519 { } let hash = hash.finalize(); - reduce_512bits_le_scalar_mod_order(&hash.into()) + generic_ec::traits::Reduce::<64>::from_le_array_mod_order(&hash.into()) } fn h4() -> Self::Digest { @@ -100,14 +100,3 @@ impl Ciphersuite for Ed25519 { Ok(Self::normalize_point(point)) } } - -/// Reduces 512 bits integer mod curve order -/// -/// This is a more efficient version of [`generic_ec::Scalar::from_le_bytes_mod_order`] -fn reduce_512bits_le_scalar_mod_order( - bytes: &[u8; 64], -) -> generic_ec::Scalar { - let out = curve25519_dalek::Scalar::from_bytes_mod_order_wide(bytes); - let out = generic_ec_curves::ed25519::Scalar(out); - generic_ec::as_raw::FromRaw::from_raw(out) -}