mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 07:01:05 +00:00
Reduce usage of Blake2Hasher (#5132)
This reduces the usage of `Blake2Hasher` in the code base and replaces it with `BlakeTwo256`. The most important change is the removal of the custom extern function for `Blake2Hasher`. The runtime `Hash` trait is now also simplified and directly requires that the implementing type implements `Hashable`.
This commit is contained in:
committed by
GitHub
parent
406fa981bb
commit
5a33228ea9
@@ -16,27 +16,10 @@
|
||||
|
||||
//! Substrate Blake2b Hasher implementation
|
||||
|
||||
use hash_db::Hasher;
|
||||
use hash256_std_hasher::Hash256StdHasher;
|
||||
use crate::hash::H256;
|
||||
|
||||
pub mod blake2 {
|
||||
use super::{Hasher, Hash256StdHasher, H256};
|
||||
#[cfg(feature = "std")]
|
||||
use crate::hashing::blake2_256;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
extern "C" {
|
||||
fn ext_blake2_256(data: *const u8, len: u32, out: *mut u8);
|
||||
}
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn blake2_256(data: &[u8]) -> [u8; 32] {
|
||||
let mut result: [u8; 32] = Default::default();
|
||||
unsafe {
|
||||
ext_blake2_256(data.as_ptr(), data.len() as u32, result.as_mut_ptr());
|
||||
}
|
||||
result
|
||||
}
|
||||
use hash_db::Hasher;
|
||||
use hash256_std_hasher::Hash256StdHasher;
|
||||
use crate::hash::H256;
|
||||
|
||||
/// Concrete implementation of Hasher using Blake2b 256-bit hashes
|
||||
#[derive(Debug)]
|
||||
@@ -46,8 +29,9 @@ pub mod blake2 {
|
||||
type Out = H256;
|
||||
type StdHasher = Hash256StdHasher;
|
||||
const LENGTH: usize = 32;
|
||||
|
||||
fn hash(x: &[u8]) -> Self::Out {
|
||||
blake2_256(x).into()
|
||||
crate::hashing::blake2_256(x).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ pub mod ed25519;
|
||||
pub mod sr25519;
|
||||
pub mod ecdsa;
|
||||
pub mod hash;
|
||||
#[cfg(feature = "std")]
|
||||
mod hasher;
|
||||
pub mod offchain;
|
||||
pub mod sandbox;
|
||||
@@ -77,8 +78,7 @@ pub use changes_trie::{ChangesTrieConfiguration, ChangesTrieConfigurationRange};
|
||||
pub use crypto::{DeriveJunction, Pair, Public};
|
||||
|
||||
pub use hash_db::Hasher;
|
||||
// Switch back to Blake after PoC-3 is out
|
||||
// pub use self::hasher::blake::BlakeHasher;
|
||||
#[cfg(feature = "std")]
|
||||
pub use self::hasher::blake2::Blake2Hasher;
|
||||
|
||||
pub use sp_storage as storage;
|
||||
|
||||
Reference in New Issue
Block a user