From f39d164e94b20c3558be3d4dd76696911ccaa7e2 Mon Sep 17 00:00:00 2001 From: Carlos Medeiros Date: Mon, 13 Jan 2025 17:15:28 +0000 Subject: [PATCH] update ed25519-dalek --- bolos-mock/Cargo.toml | 2 +- bolos-mock/src/crypto/ecfp256.rs | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/bolos-mock/Cargo.toml b/bolos-mock/Cargo.toml index ec2fbc3..6f24906 100644 --- a/bolos-mock/Cargo.toml +++ b/bolos-mock/Cargo.toml @@ -22,7 +22,7 @@ hmac = "0.11.0" cfg-if = "1.0.0" -ed25519-dalek = "1.0.1" +ed25519-dalek = "2.1.1" k256 = "0.13.1" p256 = "0.13.2" diff --git a/bolos-mock/src/crypto/ecfp256.rs b/bolos-mock/src/crypto/ecfp256.rs index 364f5d0..9a72827 100644 --- a/bolos-mock/src/crypto/ecfp256.rs +++ b/bolos-mock/src/crypto/ecfp256.rs @@ -127,7 +127,11 @@ impl SecretKey { *secret.to_bytes().as_ref() } Curve::Ed25519 => { - let secret = ed25519_dalek::SecretKey::generate(&mut Self::rng7(path)); + use rand_chacha7::rand_core::RngCore; + let mut rng = Self::rng7(path); + let mut bytes = [0u8; 32]; + rng.fill_bytes(&mut bytes); + let secret = ed25519_dalek::SigningKey::from_bytes(&bytes); secret.to_bytes() } @@ -172,12 +176,10 @@ impl SecretKey { (bytes, uncompressed_point.len()) } Curve::Ed25519 => { - let secret = ed25519_dalek::SecretKey::from_bytes(&self.bytes[..]).unwrap(); - - let public = ed25519_dalek::PublicKey::from(&secret); + let secret = ed25519_dalek::SigningKey::from_bytes(&self.bytes); + let public = secret.verifying_key(); let mut bytes = [0; 65]; - bytes[..32].copy_from_slice(&public.as_bytes()[..]); - + bytes[..32].copy_from_slice(public.as_bytes()); (bytes, 32) } _ => unreachable!(), @@ -233,13 +235,8 @@ impl SecretKey { } Curve::Ed25519 => { use ed25519_dalek::Signer; - - let secret = ed25519_dalek::SecretKey::from_bytes(&self.bytes[..]).unwrap(); - let public = ed25519_dalek::PublicKey::from(&secret); - - let keypair = ed25519_dalek::Keypair { secret, public }; - let sig = keypair.sign(data); - + let secret = ed25519_dalek::SigningKey::from_bytes(&self.bytes); + let sig = secret.sign(data); out[..64].copy_from_slice(&sig.to_bytes()[..]); Ok((Default::default(), 64)) }