Skip to content

Commit

Permalink
Use Reduce<64> trait
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Varlakov <[email protected]>
  • Loading branch information
survived committed Jul 8, 2024
1 parent b48c087 commit f968f20
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 20 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions givre/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"
Expand All @@ -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"]

17 changes: 3 additions & 14 deletions givre/src/ciphersuite/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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<Self::Curve> {
Expand All @@ -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 {
Expand Down Expand Up @@ -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<generic_ec::curves::Ed25519> {
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)
}

0 comments on commit f968f20

Please sign in to comment.