diff --git a/Cargo.lock b/Cargo.lock index 994db19844a..7160377b27a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -428,6 +428,15 @@ dependencies = [ "opaque-debug 0.3.0", ] +[[package]] +name = "blake2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "block-buffer" version = "0.7.3" @@ -1363,6 +1372,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", "crypto-common", + "subtle", ] [[package]] @@ -2932,6 +2942,7 @@ dependencies = [ name = "iroha_crypto" version = "2.0.0-pre-rc.20" dependencies = [ + "blake2 0.10.6", "derive_more", "getset", "hex", @@ -5969,7 +5980,7 @@ dependencies = [ "amcl", "amcl_wrapper", "arrayref", - "blake2", + "blake2 0.9.2", "block-modes", "block-padding 0.2.1", "chacha20poly1305", diff --git a/crypto/Cargo.toml b/crypto/Cargo.toml index 3d0aba7b827..f71d2de62dd 100644 --- a/crypto/Cargo.toml +++ b/crypto/Cargo.toml @@ -35,9 +35,11 @@ serde = { workspace = true, features = ["derive"] } serde_with = { workspace = true, features = ["macros"] } hex = { workspace = true, features = ["alloc", "serde"] } openssl-sys = { version = "0.9.93", features = ["vendored"], optional = true } -ursa = { workspace = true, optional = true } getset = { workspace = true } +ursa = { workspace = true, optional = true } +blake2 = "0.10.6" + [dev-dependencies] hex-literal = { workspace = true } serde_json = { workspace = true } diff --git a/crypto/src/hash.rs b/crypto/src/hash.rs index f1ca35b89e8..aedd4fda803 100644 --- a/crypto/src/hash.rs +++ b/crypto/src/hash.rs @@ -2,6 +2,11 @@ use alloc::{borrow::ToOwned as _, format, string::String, vec, vec::Vec}; use core::{hash, marker::PhantomData, num::NonZeroU8, str::FromStr}; +#[cfg(all(feature = "std", not(feature = "ffi_import")))] +use blake2::{ + digest::{Update, VariableOutput}, + Blake2bVar, +}; use derive_more::{DebugCustom, Deref, DerefMut, Display}; #[cfg(any(feature = "std", feature = "ffi_import"))] use iroha_macro::ffi_impl_opaque; @@ -9,11 +14,6 @@ use iroha_schema::{IntoSchema, TypeId}; use parity_scale_codec::{Decode, Encode}; use serde::{Deserialize, Serialize}; use serde_with::DeserializeFromStr; -#[cfg(all(feature = "std", not(feature = "ffi_import")))] -use ursa::blake2::{ - digest::{Update, VariableOutput}, - VarBlake2b, -}; use crate::{error::Error, hex_decode}; @@ -46,7 +46,7 @@ impl Hash { /// Length of hash pub const LENGTH: usize = 32; - /// Wrap the given bytes; they must be prehashed with `VarBlake2b` + /// Wrap the given bytes; they must be prehashed with `Blake2bVar` pub fn prehashed(mut hash: [u8; Self::LENGTH]) -> Self { hash[Self::LENGTH - 1] |= 1; // SAFETY: @@ -72,7 +72,7 @@ impl Hash { // NOTE: Panic is predicated by implementation not user input #[allow(clippy::missing_panics_doc)] pub fn new(bytes: impl AsRef<[u8]>) -> Self { - let vec_hash = VarBlake2b::new(Self::LENGTH) + let vec_hash = Blake2bVar::new(Self::LENGTH) .expect("Failed to initialize variable size hash") .chain(bytes) .finalize_boxed(); @@ -328,7 +328,7 @@ mod tests { #[cfg(feature = "std")] #[cfg(not(feature = "ffi_import"))] fn blake2_32b() { - let mut hasher = VarBlake2b::new(32).unwrap(); + let mut hasher = Blake2bVar::new(32).unwrap(); hasher.update(hex_literal::hex!("6920616d2064617461")); hasher.finalize_variable(|res| { assert_eq!( diff --git a/crypto/src/lib.rs b/crypto/src/lib.rs index f9e42a07b6c..dcabf50099d 100755 --- a/crypto/src/lib.rs +++ b/crypto/src/lib.rs @@ -22,6 +22,9 @@ use core::{fmt, str::FromStr}; #[cfg(feature = "base64")] pub use base64; +#[cfg(feature = "std")] +#[cfg(not(feature = "ffi_import"))] +pub use blake2; use derive_more::{DebugCustom, Display}; use error::{Error, NoSuchAlgorithm}; use getset::{CopyGetters, Getters}; diff --git a/p2p/src/lib.rs b/p2p/src/lib.rs index 7d785eec1e9..8a5232ab45f 100644 --- a/p2p/src/lib.rs +++ b/p2p/src/lib.rs @@ -3,14 +3,12 @@ //! Cryptography are chosen in this module, and encapsulated. use std::{io, net::AddrParseError}; -use iroha_crypto::ursa::{ +use iroha_crypto::{ blake2::{ digest::{Update, VariableOutput}, - VarBlake2b, + Blake2bVar, }, - encryption::symm::prelude::ChaCha20Poly1305, - kex::x25519::X25519Sha256, - CryptoError, + ursa::{encryption::symm::prelude::ChaCha20Poly1305, kex::x25519::X25519Sha256, CryptoError}, }; pub use network::message::*; use parity_scale_codec::{Decode, Encode}; @@ -157,7 +155,7 @@ pub(crate) mod unbounded_with_len { /// Create Blake2b hash as u64 value pub fn blake2b_hash(slice: impl AsRef<[u8]>) -> u64 { const U64_SIZE: usize = core::mem::size_of::(); - let hash = VarBlake2b::new(U64_SIZE) + let hash = Blake2bVar::new(U64_SIZE) .expect("Failed to create hash with given length") .chain(&slice) .finalize_boxed();