mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-19 18:05:41 +00:00
Move cryptographic hashing procedures to crypto folder. (#2306)
Step towards https://github.com/paritytech/polkadot-sdk/issues/1975 As reported https://github.com/paritytech/polkadot-sdk/issues/1975#issuecomment-1774534225 I'd like to encapsulate crypto related stuff in a dedicated folder. Currently all cryptographic primitive wrappers are all sparsed in `substrate/core` which contains "misc core" stuff. To simplify the process, as the first step with this PR I propose to move the cryptographic hashing there. The `substrate/crypto` folder was already created to contains `ec-utils` crate. Notes: - rename `sp-core-hashing` to `sp-crypto-hashing` - rename `sp-core-hashing-proc-macro` to `sp-crypto-hashing-proc-macro` - As the crates name is changed I took the freedom to restart fresh from version 0.1.0 for both crates --------- Co-authored-by: Robert Hambrock <roberthambrock@gmail.com>
This commit is contained in:
@@ -17,11 +17,11 @@ workspace = true
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
|
||||
[dependencies]
|
||||
bytes = { version = "1.1.0", default-features = false }
|
||||
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["bytes"] }
|
||||
sp-core = { path = "../core", default-features = false }
|
||||
sp-crypto-hashing = { path = "../crypto/hashing", default-features = false }
|
||||
sp-keystore = { path = "../keystore", default-features = false, optional = true }
|
||||
sp-std = { path = "../std", default-features = false }
|
||||
libsecp256k1 = { version = "0.7", optional = true }
|
||||
@@ -52,6 +52,7 @@ std = [
|
||||
"log/std",
|
||||
"secp256k1",
|
||||
"sp-core/std",
|
||||
"sp-crypto-hashing/std",
|
||||
"sp-externalities/std",
|
||||
"sp-keystore/std",
|
||||
"sp-runtime-interface/std",
|
||||
|
||||
@@ -1251,42 +1251,42 @@ pub trait Crypto {
|
||||
pub trait Hashing {
|
||||
/// Conduct a 256-bit Keccak hash.
|
||||
fn keccak_256(data: &[u8]) -> [u8; 32] {
|
||||
sp_core::hashing::keccak_256(data)
|
||||
sp_crypto_hashing::keccak_256(data)
|
||||
}
|
||||
|
||||
/// Conduct a 512-bit Keccak hash.
|
||||
fn keccak_512(data: &[u8]) -> [u8; 64] {
|
||||
sp_core::hashing::keccak_512(data)
|
||||
sp_crypto_hashing::keccak_512(data)
|
||||
}
|
||||
|
||||
/// Conduct a 256-bit Sha2 hash.
|
||||
fn sha2_256(data: &[u8]) -> [u8; 32] {
|
||||
sp_core::hashing::sha2_256(data)
|
||||
sp_crypto_hashing::sha2_256(data)
|
||||
}
|
||||
|
||||
/// Conduct a 128-bit Blake2 hash.
|
||||
fn blake2_128(data: &[u8]) -> [u8; 16] {
|
||||
sp_core::hashing::blake2_128(data)
|
||||
sp_crypto_hashing::blake2_128(data)
|
||||
}
|
||||
|
||||
/// Conduct a 256-bit Blake2 hash.
|
||||
fn blake2_256(data: &[u8]) -> [u8; 32] {
|
||||
sp_core::hashing::blake2_256(data)
|
||||
sp_crypto_hashing::blake2_256(data)
|
||||
}
|
||||
|
||||
/// Conduct four XX hashes to give a 256-bit result.
|
||||
fn twox_256(data: &[u8]) -> [u8; 32] {
|
||||
sp_core::hashing::twox_256(data)
|
||||
sp_crypto_hashing::twox_256(data)
|
||||
}
|
||||
|
||||
/// Conduct two XX hashes to give a 128-bit result.
|
||||
fn twox_128(data: &[u8]) -> [u8; 16] {
|
||||
sp_core::hashing::twox_128(data)
|
||||
sp_crypto_hashing::twox_128(data)
|
||||
}
|
||||
|
||||
/// Conduct two XX hashes to give a 64-bit result.
|
||||
fn twox_64(data: &[u8]) -> [u8; 8] {
|
||||
sp_core::hashing::twox_64(data)
|
||||
sp_crypto_hashing::twox_64(data)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user