diff --git a/crypto/src/kex/mod.rs b/crypto/src/kex/mod.rs index 4e7bae30456..db8e45bfb74 100644 --- a/crypto/src/kex/mod.rs +++ b/crypto/src/kex/mod.rs @@ -10,7 +10,7 @@ use alloc::vec::Vec; pub use x25519::X25519Sha256; -use crate::{error::ParseError, KeyPairGenOption, SessionKey}; +use crate::{error::ParseError, KeyGenOption, SessionKey}; /// A Generic trait for key exchange schemes. Each scheme provides a way to generate keys and /// do a diffie-hellman computation @@ -24,14 +24,14 @@ pub trait KeyExchangeScheme { fn new() -> Self; /// Create new keypairs. If - /// - `options` is [`Random`](KeyPairGenOption::Random), the keys are generated ephemerally from the [`OsRng`](rand::rngs::OsRng) - /// - `options` is [`UseSeed`](KeyPairGenOption::UseSeed), the keys are generated ephemerally from the sha256 hash of the seed which is + /// - `options` is [`Random`](KeyGenOption::Random), the keys are generated ephemerally from the [`OsRng`](rand::rngs::OsRng) + /// - `options` is [`UseSeed`](KeyGenOption::UseSeed), the keys are generated ephemerally from the sha256 hash of the seed which is /// then used to seed the [`ChaChaRng`](rand_chacha::ChaChaRng) - /// - `options` is [`FromPrivateKey`](KeyPairGenOption::FromPrivateKey), the corresponding public key is returned. This should be used for + /// - `options` is [`FromPrivateKey`](KeyGenOption::FromPrivateKey), the corresponding public key is returned. This should be used for /// static Diffie-Hellman and loading a long-term key. fn keypair( &self, - options: KeyPairGenOption, + options: KeyGenOption, ) -> (Self::PublicKey, Self::PrivateKey); /// Compute the diffie-hellman shared secret. diff --git a/crypto/src/kex/x25519.rs b/crypto/src/kex/x25519.rs index 6dd0f7daa85..16207186d45 100644 --- a/crypto/src/kex/x25519.rs +++ b/crypto/src/kex/x25519.rs @@ -12,7 +12,7 @@ use x25519_dalek::{PublicKey, StaticSecret}; use zeroize::Zeroize; use super::KeyExchangeScheme; -use crate::{error::ParseError, KeyPairGenOption, SessionKey}; +use crate::{error::ParseError, KeyGenOption, SessionKey}; /// Implements the [`KeyExchangeScheme`] using X25519 key exchange and SHA256 hash function. #[derive(Copy, Clone)] @@ -28,17 +28,17 @@ impl KeyExchangeScheme for X25519Sha256 { fn keypair( &self, - mut option: KeyPairGenOption, + mut option: KeyGenOption, ) -> (Self::PublicKey, Self::PrivateKey) { match option { #[cfg(feature = "rand")] - KeyPairGenOption::Random => { + KeyGenOption::Random => { let rng = OsRng; let sk = StaticSecret::random_from_rng(rng); let pk = PublicKey::from(&sk); (pk, sk) } - KeyPairGenOption::UseSeed(ref mut s) => { + KeyGenOption::UseSeed(ref mut s) => { let hash = sha2::Sha256::digest(s.as_slice()); s.zeroize(); let rng = ChaChaRng::from_seed(*array_ref!(hash.as_slice(), 0, 32)); @@ -46,7 +46,7 @@ impl KeyExchangeScheme for X25519Sha256 { let pk = PublicKey::from(&sk); (pk, sk) } - KeyPairGenOption::FromPrivateKey(ref sk) => { + KeyGenOption::FromPrivateKey(ref sk) => { let pk = PublicKey::from(sk); (pk, sk.clone()) } @@ -91,15 +91,14 @@ mod tests { #[test] fn key_exchange() { let scheme = X25519Sha256::new(); - let (public_key1, secret_key1) = scheme.keypair(KeyPairGenOption::Random); + let (public_key1, secret_key1) = scheme.keypair(KeyGenOption::Random); - let (public_key2, secret_key2) = scheme.keypair(KeyPairGenOption::Random); + let (public_key2, secret_key2) = scheme.keypair(KeyGenOption::Random); let shared_secret1 = scheme.compute_shared_secret(&secret_key2, &public_key1); let shared_secret2 = scheme.compute_shared_secret(&secret_key1, &public_key2); assert_eq!(shared_secret1.payload(), shared_secret2.payload()); - let (public_key2, _secret_key1) = - scheme.keypair(KeyPairGenOption::FromPrivateKey(secret_key1)); + let (public_key2, _secret_key1) = scheme.keypair(KeyGenOption::FromPrivateKey(secret_key1)); assert_eq!(public_key2, public_key1); } } diff --git a/crypto/src/lib.rs b/crypto/src/lib.rs index 00165239440..4440291d571 100755 --- a/crypto/src/lib.rs +++ b/crypto/src/lib.rs @@ -111,24 +111,11 @@ impl FromStr for Algorithm { } } -/// Needed since it couldn't be represented in FFI -#[derive(Clone)] -#[cfg_attr(not(feature = "ffi_import"), derive(Debug))] -enum KeyPairGenConfigInner { - /// Use random number generator - #[cfg(feature = "rand")] - Random { algorithm: Algorithm }, - /// Use seed - UseSeed { seed: Vec, algorithm: Algorithm }, - /// Derive from a private key - FromPrivateKey(PrivateKey), -} - -/// While [`KeyPairGenConfig`] is for external users, this structure is for internal use +/// While [`KeyGenConfig`] is for external users, this structure is for internal use /// to pass it to a specific algorithm. -/// Parameter `K` is intended to be set as a `PrivateKey` type of that specific algorithm. +/// Parameter `K` is intended to be set as a private key type of that specific algorithm. #[derive(Debug)] -pub enum KeyPairGenOption { +pub enum KeyGenOption { /// Use random number generator #[cfg(feature = "rand")] Random, @@ -142,19 +129,32 @@ ffi::ffi_item! { /// Configuration for key generation #[derive(Clone)] #[cfg_attr(not(feature = "ffi_import"), derive(Debug))] - pub struct KeyPairGenConfig{ - inner: KeyPairGenConfigInner + pub struct KeyGenConfig{ + inner: KeyGenConfigInner } } +/// Needed since it couldn't be represented in FFI +#[derive(Clone)] +#[cfg_attr(not(feature = "ffi_import"), derive(Debug))] +enum KeyGenConfigInner { + /// Use random number generator + #[cfg(feature = "rand")] + Random { algorithm: Algorithm }, + /// Use seed + UseSeed { seed: Vec, algorithm: Algorithm }, + /// Derive from a private key + FromPrivateKey(PrivateKey), +} + #[ffi_impl_opaque] -impl KeyPairGenConfig { +impl KeyGenConfig { /// Generate using random number generation with a specified algorithm #[cfg(feature = "rand")] #[must_use] pub fn from_random(algorithm: Algorithm) -> Self { Self { - inner: KeyPairGenConfigInner::Random { algorithm }, + inner: KeyGenConfigInner::Random { algorithm }, } } @@ -162,7 +162,7 @@ impl KeyPairGenConfig { #[must_use] pub fn from_seed(seed: Vec, algorithm: Algorithm) -> Self { Self { - inner: KeyPairGenConfigInner::UseSeed { seed, algorithm }, + inner: KeyGenConfigInner::UseSeed { seed, algorithm }, } } @@ -170,7 +170,7 @@ impl KeyPairGenConfig { #[must_use] pub fn from_private_key(key: PrivateKey) -> Self { Self { - inner: KeyPairGenConfigInner::FromPrivateKey(key), + inner: KeyGenConfigInner::FromPrivateKey(key), } } @@ -198,7 +198,7 @@ impl KeyPair { /// Generates a random key pair using [`Algorithm::default()`] #[cfg(feature = "rand")] pub fn generate() -> Self { - Self::generate_with_config(KeyPairGenConfig::from_random(Algorithm::default())) + Self::generate_with_config(KeyGenConfig::from_random(Algorithm::default())) } } @@ -230,29 +230,29 @@ impl KeyPair { }) } - /// Generates a pair of Public and Private key with the corresponding [`KeyPairGenOption`]. - pub fn generate_with_config(config: KeyPairGenConfig) -> Self { - use KeyPairGenConfigInner; - use KeyPairGenOption; + /// Generates a pair of Public and Private key with the corresponding [`KeyGenOption`]. + pub fn generate_with_config(config: KeyGenConfig) -> Self { + use KeyGenConfigInner; + use KeyGenOption; macro_rules! with_algorithm_variations { ($(($alg:ident, $alg_mod:path)),+) => { match config.inner { #[cfg(feature = "rand")] - KeyPairGenConfigInner::Random { algorithm } => { + KeyGenConfigInner::Random { algorithm } => { match algorithm { - $(Algorithm::$alg => <$alg_mod>::keypair(KeyPairGenOption::Random).into()),* + $(Algorithm::$alg => <$alg_mod>::keypair(KeyGenOption::Random).into()),* } - }, - KeyPairGenConfigInner::UseSeed { seed, algorithm } => { + } + KeyGenConfigInner::UseSeed { seed, algorithm } => { match algorithm { - $(Algorithm::$alg => <$alg_mod>::keypair(KeyPairGenOption::UseSeed(seed)).into()),* + $(Algorithm::$alg => <$alg_mod>::keypair(KeyGenOption::UseSeed(seed)).into()),* } } - KeyPairGenConfigInner::FromPrivateKey(key) => { + KeyGenConfigInner::FromPrivateKey(key) => { match *key.0 { $( - PrivateKeyInner::$alg(secret) => <$alg_mod>::keypair(KeyPairGenOption::FromPrivateKey(secret)).into(), + PrivateKeyInner::$alg(secret) => <$alg_mod>::keypair(KeyGenOption::FromPrivateKey(secret)).into(), )* } } @@ -595,7 +595,7 @@ impl From for PublicKey { match $private_inner { $( PrivateKeyInner::$alg(secret) => { - PublicKeyInner::$alg(<$alg_mod>::keypair(KeyPairGenOption::FromPrivateKey(secret)).0) + PublicKeyInner::$alg(<$alg_mod>::keypair(KeyGenOption::FromPrivateKey(secret)).0) } )* } @@ -865,7 +865,7 @@ mod ffi { #[cfg(any(feature = "ffi_export", feature = "ffi_import"))] iroha_ffi::handles! { - KeyPairGenConfig, + KeyGenConfig, PublicKey, PrivateKey, KeyPair, @@ -876,8 +876,8 @@ mod ffi { iroha_ffi::decl_ffi_fns! { link_prefix="iroha_crypto" Drop, Clone, Eq, Ord, Default } #[cfg(all(feature = "ffi_export", not(feature = "ffi_import")))] iroha_ffi::def_ffi_fns! { link_prefix="iroha_crypto" - Drop: { KeyPairGenConfig, PublicKey, PrivateKey, KeyPair, Signature }, - Clone: { KeyPairGenConfig, PublicKey, PrivateKey, KeyPair, Signature }, + Drop: { KeyGenConfig, PublicKey, PrivateKey, KeyPair, Signature }, + Clone: { KeyGenConfig, PublicKey, PrivateKey, KeyPair, Signature }, Eq: { PublicKey, PrivateKey, KeyPair, Signature }, Ord: { PublicKey, Signature }, } @@ -937,7 +937,7 @@ mod tests { Algorithm::BlsNormal, Algorithm::BlsSmall, ] { - let key_pair = KeyPairGenConfig::from_random(algorithm).generate(); + let key_pair = KeyGenConfig::from_random(algorithm).generate(); assert_eq!( key_pair, @@ -996,7 +996,7 @@ mod tests { Algorithm::BlsNormal, Algorithm::BlsSmall, ] { - let key_pair = KeyPairGenConfig::from_random(algorithm).generate(); + let key_pair = KeyGenConfig::from_random(algorithm).generate(); let (public_key, _) = key_pair.into(); let encoded_public_key = public_key.encode(); diff --git a/crypto/src/signature/bls/implementation.rs b/crypto/src/signature/bls/implementation.rs index 9638b8aaccc..db12726b263 100644 --- a/crypto/src/signature/bls/implementation.rs +++ b/crypto/src/signature/bls/implementation.rs @@ -12,7 +12,7 @@ use zeroize::Zeroize as _; pub(super) const MESSAGE_CONTEXT: &[u8; 20] = b"for signing messages"; -use crate::{Algorithm, Error, KeyPairGenOption, ParseError}; +use crate::{Algorithm, Error, KeyGenOption, ParseError}; pub trait BlsConfiguration { const ALGORITHM: Algorithm; @@ -25,13 +25,13 @@ impl BlsImpl { // the names are from an RFC, not a good idea to change them #[allow(clippy::similar_names)] pub fn keypair( - mut option: KeyPairGenOption>, + mut option: KeyGenOption>, ) -> (PublicKey, SecretKey) { let private_key = match option { #[cfg(feature = "rand")] - KeyPairGenOption::Random => SecretKey::generate(OsRng), + KeyGenOption::Random => SecretKey::generate(OsRng), // Follows https://datatracker.ietf.org/doc/draft-irtf-cfrg-bls-signature/?include_text=1 - KeyPairGenOption::UseSeed(ref mut seed) => { + KeyGenOption::UseSeed(ref mut seed) => { let salt = b"BLS-SIG-KEYGEN-SALT-"; let info = [0u8, C::Engine::SECRET_KEY_SIZE.try_into().unwrap()]; // key_info || I2OSP(L, 2) let mut ikm = vec![0u8; seed.len() + 1]; @@ -44,7 +44,7 @@ impl BlsImpl { SecretKey::::from_seed(&okm) } - KeyPairGenOption::FromPrivateKey(ref key) => key.clone(), + KeyGenOption::FromPrivateKey(ref key) => key.clone(), }; (private_key.into_public(), private_key) } diff --git a/crypto/src/signature/bls/tests.rs b/crypto/src/signature/bls/tests.rs index bde5c5cb567..31b21a64987 100644 --- a/crypto/src/signature/bls/tests.rs +++ b/crypto/src/signature/bls/tests.rs @@ -5,7 +5,7 @@ use super::{ normal::NormalConfiguration, small::SmallConfiguration, }; -use crate::KeyPairGenOption; +use crate::KeyGenOption; const MESSAGE_1: &[u8; 22] = b"This is a test message"; const MESSAGE_2: &[u8; 20] = b"Another test message"; @@ -13,8 +13,8 @@ const SEED: &[u8; 10] = &[1u8; 10]; #[allow(clippy::similar_names)] fn test_keypair_generation_from_seed() { - let (pk_1, sk_1) = BlsImpl::::keypair(KeyPairGenOption::UseSeed(SEED.to_vec())); - let (pk_2, sk_2) = BlsImpl::::keypair(KeyPairGenOption::UseSeed(SEED.to_vec())); + let (pk_1, sk_1) = BlsImpl::::keypair(KeyGenOption::UseSeed(SEED.to_vec())); + let (pk_2, sk_2) = BlsImpl::::keypair(KeyGenOption::UseSeed(SEED.to_vec())); assert!( (pk_1, sk_1.to_bytes()) == (pk_2, sk_2.to_bytes()), @@ -23,7 +23,7 @@ fn test_keypair_generation_from_seed() { } fn test_signature_verification() { - let (pk, sk) = BlsImpl::::keypair(KeyPairGenOption::Random); + let (pk, sk) = BlsImpl::::keypair(KeyGenOption::Random); let signature_1 = BlsImpl::::sign(MESSAGE_1, &sk); BlsImpl::::verify(MESSAGE_1, &signature_1, &pk) @@ -31,7 +31,7 @@ fn test_signature_verification() { } fn test_signature_verification_different_messages() { - let (pk, sk) = BlsImpl::::keypair(KeyPairGenOption::Random); + let (pk, sk) = BlsImpl::::keypair(KeyGenOption::Random); let signature = BlsImpl::::sign(MESSAGE_1, &sk); BlsImpl::::verify(MESSAGE_2, &signature, &pk) @@ -40,8 +40,8 @@ fn test_signature_verification_different_messages() { #[allow(clippy::similar_names)] fn test_signature_verification_different_keys() { - let (_pk_1, sk_1) = BlsImpl::::keypair(KeyPairGenOption::Random); - let (pk_2, _sk_2) = BlsImpl::::keypair(KeyPairGenOption::Random); + let (_pk_1, sk_1) = BlsImpl::::keypair(KeyGenOption::Random); + let (pk_2, _sk_2) = BlsImpl::::keypair(KeyGenOption::Random); let signature = BlsImpl::::sign(MESSAGE_1, &sk_1); BlsImpl::::verify(MESSAGE_1, &signature, &pk_2) diff --git a/crypto/src/signature/ed25519.rs b/crypto/src/signature/ed25519.rs index 23c4d33f815..3ab7ab4ab26 100644 --- a/crypto/src/signature/ed25519.rs +++ b/crypto/src/signature/ed25519.rs @@ -5,7 +5,7 @@ use ed25519_dalek::Signature; use rand::rngs::OsRng; use signature::{Signer as _, Verifier as _}; -use crate::{Error, KeyPairGenOption, ParseError}; +use crate::{Error, KeyGenOption, ParseError}; pub type PublicKey = ed25519_dalek::VerifyingKey; pub type PrivateKey = ed25519_dalek::SigningKey; @@ -17,14 +17,12 @@ use alloc::{string::ToString as _, vec::Vec}; pub struct Ed25519Sha512; impl Ed25519Sha512 { - pub fn keypair(option: KeyPairGenOption) -> (PublicKey, PrivateKey) { + pub fn keypair(option: KeyGenOption) -> (PublicKey, PrivateKey) { let signing_key = match option { #[cfg(feature = "rand")] - KeyPairGenOption::Random => PrivateKey::generate(&mut OsRng), - KeyPairGenOption::UseSeed(seed) => { - PrivateKey::generate(&mut super::rng_from_seed(seed)) - } - KeyPairGenOption::FromPrivateKey(ref s) => PrivateKey::clone(s), + KeyGenOption::Random => PrivateKey::generate(&mut OsRng), + KeyGenOption::UseSeed(seed) => PrivateKey::generate(&mut super::rng_from_seed(seed)), + KeyGenOption::FromPrivateKey(ref s) => PrivateKey::clone(s), }; (signing_key.verifying_key(), signing_key) } @@ -61,7 +59,7 @@ mod test { use self::Ed25519Sha512; use super::*; - use crate::{signature::ed25519, Algorithm, KeyPairGenOption, PrivateKey, PublicKey}; + use crate::{signature::ed25519, Algorithm, KeyGenOption, PrivateKey, PublicKey}; const MESSAGE_1: &[u8] = b"This is a dummy message for use with tests"; const SIGNATURE_1: &str = "451b5b8e8725321541954997781de51f4142e4a56bab68d24f6a6b92615de5eefb74134138315859a32c7cf5fe5a488bc545e2e08e5eedfd1fb10188d532d808"; @@ -69,7 +67,7 @@ mod test { const PUBLIC_KEY: &str = "27c96646f2d4632d4fc241f84cbc427fbc3ecaa95becba55088d6c7b81fc5bbf"; fn key_pair_factory() -> (ed25519::PublicKey, ed25519::PrivateKey) { - Ed25519Sha512::keypair(KeyPairGenOption::FromPrivateKey( + Ed25519Sha512::keypair(KeyGenOption::FromPrivateKey( Ed25519Sha512::parse_private_key(&hex::decode(PRIVATE_KEY).unwrap()).unwrap(), )) } @@ -77,7 +75,7 @@ mod test { #[test] #[ignore] fn create_new_keys() { - let (p, s) = Ed25519Sha512::keypair(KeyPairGenOption::Random); + let (p, s) = Ed25519Sha512::keypair(KeyGenOption::Random); println!("{s:?}"); println!("{p:?}"); diff --git a/crypto/src/signature/mod.rs b/crypto/src/signature/mod.rs index de5568a7fd3..58994209c55 100644 --- a/crypto/src/signature/mod.rs +++ b/crypto/src/signature/mod.rs @@ -563,12 +563,12 @@ mod tests { use serde_json::json; use super::*; - use crate::KeyPairGenConfig; + use crate::KeyGenConfig; #[test] #[cfg(feature = "rand")] fn create_signature_ed25519() { - let key_pair = KeyPairGenConfig::from_random(crate::Algorithm::Ed25519).generate(); + let key_pair = KeyGenConfig::from_random(crate::Algorithm::Ed25519).generate(); let message = b"Test message to sign."; let signature = Signature::new(&key_pair, message); assert_eq!(*signature.public_key(), *key_pair.public_key()); @@ -578,7 +578,7 @@ mod tests { #[test] #[cfg(feature = "rand")] fn create_signature_secp256k1() { - let key_pair = KeyPairGenConfig::from_random(crate::Algorithm::Secp256k1).generate(); + let key_pair = KeyGenConfig::from_random(crate::Algorithm::Secp256k1).generate(); let message = b"Test message to sign."; let signature = Signature::new(&key_pair, message); assert_eq!(*signature.public_key(), *key_pair.public_key()); @@ -588,7 +588,7 @@ mod tests { #[test] #[cfg(feature = "rand")] fn create_signature_bls_normal() { - let key_pair = KeyPairGenConfig::from_random(crate::Algorithm::BlsNormal).generate(); + let key_pair = KeyGenConfig::from_random(crate::Algorithm::BlsNormal).generate(); let message = b"Test message to sign."; let signature = Signature::new(&key_pair, message); assert_eq!(*signature.public_key(), *key_pair.public_key()); @@ -598,7 +598,7 @@ mod tests { #[test] #[cfg(all(feature = "rand", any(feature = "std", feature = "ffi_import")))] fn create_signature_bls_small() { - let key_pair = KeyPairGenConfig::from_random(crate::Algorithm::BlsSmall).generate(); + let key_pair = KeyGenConfig::from_random(crate::Algorithm::BlsSmall).generate(); let message = b"Test message to sign."; let signature = Signature::new(&key_pair, message); assert_eq!(*signature.public_key(), *key_pair.public_key()); diff --git a/crypto/src/signature/secp256k1.rs b/crypto/src/signature/secp256k1.rs index 16d5d003f17..c1522f7a72a 100644 --- a/crypto/src/signature/secp256k1.rs +++ b/crypto/src/signature/secp256k1.rs @@ -2,7 +2,7 @@ use alloc::{format, vec::Vec}; use self::ecdsa_secp256k1::EcdsaSecp256k1Impl; -use crate::{Error, KeyPairGenOption, ParseError}; +use crate::{Error, KeyGenOption, ParseError}; pub struct EcdsaSecp256k1Sha256; @@ -10,7 +10,7 @@ pub type PublicKey = k256::PublicKey; pub type PrivateKey = k256::SecretKey; impl EcdsaSecp256k1Sha256 { - pub fn keypair(option: KeyPairGenOption) -> (PublicKey, PrivateKey) { + pub fn keypair(option: KeyGenOption) -> (PublicKey, PrivateKey) { EcdsaSecp256k1Impl::keypair(option) } @@ -40,19 +40,19 @@ mod ecdsa_secp256k1 { use signature::{Signer as _, Verifier as _}; use super::{PrivateKey, PublicKey}; - use crate::{Error, KeyPairGenOption, ParseError}; + use crate::{Error, KeyGenOption, ParseError}; pub struct EcdsaSecp256k1Impl; impl EcdsaSecp256k1Impl { - pub fn keypair(option: KeyPairGenOption) -> (PublicKey, PrivateKey) { + pub fn keypair(option: KeyGenOption) -> (PublicKey, PrivateKey) { let signing_key = match option { #[cfg(feature = "rand")] - KeyPairGenOption::Random => PrivateKey::random(&mut OsRng), - KeyPairGenOption::UseSeed(seed) => { + KeyGenOption::Random => PrivateKey::random(&mut OsRng), + KeyGenOption::UseSeed(seed) => { PrivateKey::random(&mut super::super::rng_from_seed(seed)) } - KeyPairGenOption::FromPrivateKey(ref s) => s.clone(), + KeyGenOption::FromPrivateKey(ref s) => s.clone(), }; let public_key = signing_key.public_key(); @@ -133,7 +133,7 @@ mod test { #[test] fn secp256k1_compatibility() { let secret = private_key(); - let (p, s) = EcdsaSecp256k1Sha256::keypair(KeyPairGenOption::FromPrivateKey(secret)); + let (p, s) = EcdsaSecp256k1Sha256::keypair(KeyGenOption::FromPrivateKey(secret)); let _sk = secp256k1::SecretKey::from_slice(&s.to_bytes()).unwrap(); let _pk = secp256k1::PublicKey::from_slice(&p.to_sec1_bytes()).unwrap(); @@ -183,7 +183,7 @@ mod test { #[test] fn secp256k1_sign() { let secret = private_key(); - let (pk, sk) = EcdsaSecp256k1Sha256::keypair(KeyPairGenOption::FromPrivateKey(secret)); + let (pk, sk) = EcdsaSecp256k1Sha256::keypair(KeyGenOption::FromPrivateKey(secret)); let sig = EcdsaSecp256k1Sha256::sign(MESSAGE_1, &sk); EcdsaSecp256k1Sha256::verify(MESSAGE_1, &sig, &pk).unwrap(); @@ -248,7 +248,7 @@ mod test { EcdsaSecp256k1Sha256::verify(MESSAGE_1, openssl_sig.as_slice(), &pk).unwrap(); - let (p, s) = EcdsaSecp256k1Sha256::keypair(KeyPairGenOption::Random); + let (p, s) = EcdsaSecp256k1Sha256::keypair(KeyGenOption::Random); let signed = EcdsaSecp256k1Sha256::sign(MESSAGE_1, &s); EcdsaSecp256k1Sha256::verify(MESSAGE_1, &signed, &p).unwrap(); } diff --git a/p2p/src/peer.rs b/p2p/src/peer.rs index 18f411244e4..fd8551cb969 100644 --- a/p2p/src/peer.rs +++ b/p2p/src/peer.rs @@ -370,7 +370,7 @@ mod run { mod state { //! Module for peer stages. - use iroha_crypto::{KeyPair, KeyPairGenOption, Signature}; + use iroha_crypto::{KeyGenOption, KeyPair, Signature}; use iroha_primitives::addr::SocketAddr; use super::{cryptographer::Cryptographer, *}; @@ -418,7 +418,7 @@ mod state { }: Self, ) -> Result, crate::Error> { let key_exchange = K::new(); - let (kx_local_pk, kx_local_sk) = key_exchange.keypair(KeyPairGenOption::Random); + let (kx_local_pk, kx_local_sk) = key_exchange.keypair(KeyGenOption::Random); let write_half = &mut connection.write; garbage::write(write_half).await?; write_half @@ -464,7 +464,7 @@ mod state { }: Self, ) -> Result, crate::Error> { let key_exchange = K::new(); - let (kx_local_pk, kx_local_sk) = key_exchange.keypair(KeyPairGenOption::Random); + let (kx_local_pk, kx_local_sk) = key_exchange.keypair(KeyGenOption::Random); let kx_local_pk_raw = K::encode_public_key(&kx_local_pk); let read_half = &mut connection.read; let kx_remote_pk = { diff --git a/tools/kagami/src/crypto.rs b/tools/kagami/src/crypto.rs index a4f8524816b..749a59da472 100644 --- a/tools/kagami/src/crypto.rs +++ b/tools/kagami/src/crypto.rs @@ -1,6 +1,6 @@ use clap::{builder::PossibleValue, ArgGroup, ValueEnum}; use color_eyre::eyre::WrapErr as _; -use iroha_crypto::{Algorithm, KeyPair, KeyPairGenConfig, PrivateKey}; +use iroha_crypto::{Algorithm, KeyGenConfig, KeyPair, PrivateKey}; use super::*; @@ -85,15 +85,15 @@ impl Args { let algorithm = self.algorithm.0; let config = match (self.seed, self.private_key) { - (None, None) => KeyPairGenConfig::from_random(algorithm), + (None, None) => KeyGenConfig::from_random(algorithm), (None, Some(private_key_hex)) => { let private_key = PrivateKey::from_hex(algorithm, private_key_hex) .wrap_err("Failed to decode private key")?; - KeyPairGenConfig::from_private_key(private_key) + KeyGenConfig::from_private_key(private_key) } (Some(seed), None) => { let seed: Vec = seed.as_bytes().into(); - KeyPairGenConfig::from_seed(seed, algorithm) + KeyGenConfig::from_seed(seed, algorithm) } _ => unreachable!("Clap group invariant"), }; diff --git a/tools/swarm/src/compose.rs b/tools/swarm/src/compose.rs index bc4d4cd01d5..a3c0f3f4ac1 100644 --- a/tools/swarm/src/compose.rs +++ b/tools/swarm/src/compose.rs @@ -8,7 +8,7 @@ use std::{ }; use color_eyre::eyre::{eyre, Context, ContextCompat}; -use iroha_crypto::{Algorithm, KeyPair, KeyPairGenConfig, PrivateKey, PublicKey}; +use iroha_crypto::{Algorithm, KeyGenConfig, KeyPair, PrivateKey, PublicKey}; use iroha_data_model::{prelude::PeerId, ChainId}; use iroha_primitives::addr::{socket_addr, SocketAddr}; use peer_generator::Peer; @@ -466,10 +466,10 @@ impl DockerComposeBuilder<'_> { fn generate_key_pair(base_seed: Option<&[u8]>, additional_seed: &[u8]) -> KeyPair { let cfg = base_seed.map_or_else( - || KeyPairGenConfig::from_random(Algorithm::default()), + || KeyGenConfig::from_random(Algorithm::default()), |base| { let seed: Vec<_> = base.iter().chain(additional_seed).copied().collect(); - KeyPairGenConfig::from_seed(seed, Algorithm::default()) + KeyGenConfig::from_seed(seed, Algorithm::default()) }, ); @@ -640,7 +640,7 @@ mod tests { let mut map = BTreeMap::new(); let chain_id = ChainId::from("00000000-0000-0000-0000-000000000000"); - let key_pair = KeyPairGenConfig::from_seed( + let key_pair = KeyGenConfig::from_seed( vec![1, 5, 1, 2, 2, 3, 4, 1, 2, 3], Algorithm::default(), ) @@ -715,7 +715,7 @@ mod tests { fn empty_genesis_private_key_is_skipped_in_env() { let chain_id = ChainId::from("00000000-0000-0000-0000-000000000000"); - let key_pair = KeyPairGenConfig::from_seed(vec![0, 1, 2], Algorithm::default()).generate(); + let key_pair = KeyGenConfig::from_seed(vec![0, 1, 2], Algorithm::default()).generate(); let env: FullPeerEnv = CompactPeerEnv { chain_id,