Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move cryptographic hashing procedures to crypto folder. #2306

Merged
merged 18 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,9 @@ members = [
"substrate/primitives/consensus/sassafras",
"substrate/primitives/consensus/slots",
"substrate/primitives/core",
"substrate/primitives/core/hashing",
"substrate/primitives/core/hashing/proc-macro",
"substrate/primitives/crypto/ec-utils",
"substrate/primitives/crypto/hashing",
"substrate/primitives/crypto/hashing/proc-macro",
"substrate/primitives/database",
"substrate/primitives/debug-derive",
"substrate/primitives/externalities",
Expand Down
8 changes: 4 additions & 4 deletions substrate/frame/alliance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ scale-info = { version = "2.10.0", default-features = false, features = ["derive

sp-std = { path = "../../primitives/std", default-features = false}
sp-core = { path = "../../primitives/core", default-features = false}
sp-core-hashing = { path = "../../primitives/core/hashing", default-features = false, optional = true }
sp-crypto-hashing = { path = "../../primitives/crypto/hashing", default-features = false, optional = true }
sp-io = { path = "../../primitives/io", default-features = false}
sp-runtime = { path = "../../primitives/runtime", default-features = false}

Expand All @@ -34,7 +34,7 @@ pallet-collective = { path = "../collective", default-features = false, optional

[dev-dependencies]
array-bytes = "6.1"
sp-core-hashing = { path = "../../primitives/core/hashing", default-features = false}
sp-crypto-hashing = { path = "../../primitives/crypto/hashing", default-features = false}
pallet-balances = { path = "../balances" }
pallet-collective = { path = "../collective" }

Expand All @@ -50,8 +50,8 @@ std = [
"pallet-collective?/std",
"pallet-identity/std",
"scale-info/std",
"sp-core-hashing?/std",
"sp-core/std",
"sp-crypto-hashing?/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
Expand All @@ -64,7 +64,7 @@ runtime-benchmarks = [
"pallet-balances/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"sp-core-hashing",
"sp-crypto-hashing",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/alliance/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn assert_last_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>::
}

fn cid(input: impl AsRef<[u8]>) -> Cid {
let result = sp_core_hashing::sha2_256(input.as_ref());
let result = sp_crypto_hashing::sha2_256(input.as_ref());
Cid::new_v0(result)
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/alliance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ pub fn new_bench_ext() -> sp_io::TestExternalities {
}

pub fn test_cid() -> Cid {
let result = sp_core_hashing::sha2_256(b"hello world");
let result = sp_crypto_hashing::sha2_256(b"hello world");
Cid::new_v0(result)
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bitflags = "1.3"
impl-trait-for-tuples = "0.2.2"
smallvec = "1.11.0"
log = { version = "0.4.17", default-features = false }
sp-core-hashing-proc-macro = { path = "../../primitives/core/hashing/proc-macro" }
sp-crypto-hashing-proc-macro = { path = "../../primitives/crypto/hashing/proc-macro" }
k256 = { version = "0.13.1", default-features = false, features = ["ecdsa"] }
environmental = { version = "1.1.4", default-features = false }
sp-genesis-builder = { path = "../../primitives/genesis-builder", default-features=false}
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/support/procedural/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ frame-support-procedural-tools = { path = "tools" }
macro_magic = { version = "0.5.0", features = ["proc_support"] }
proc-macro-warning = { version = "1.0.0", default-features = false }
expander = "2.0.0"
sp-core-hashing = { path = "../../../primitives/core/hashing" }
sp-crypto-hashing = { path = "../../../primitives/crypto/hashing" }

[features]
default = [ "std" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ pub fn check_pallet_call_return_type(type_: &syn::Type) -> syn::Result<()> {
}

pub(crate) fn two128_str(s: &str) -> TokenStream {
bytes_to_array(sp_core_hashing::twox_128(s.as_bytes()).into_iter())
bytes_to_array(sp_crypto_hashing::twox_128(s.as_bytes()).into_iter())
}

pub(crate) fn bytes_to_array(bytes: impl IntoIterator<Item = u8>) -> TokenStream {
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub mod __private {
pub use scale_info;
pub use serde;
pub use sp_core::{OpaqueMetadata, Void};
pub use sp_core_hashing_proc_macro;
pub use sp_crypto_hashing_proc_macro;
pub use sp_inherents;
pub use sp_io::{self, hashing, storage::root as storage_root};
pub use sp_metadata_ir as metadata_ir;
Expand Down Expand Up @@ -328,7 +328,7 @@ macro_rules! parameter_types {
impl< $($ty_params),* > $name< $($ty_params),* > {
/// Returns the key for this parameter type.
pub fn key() -> [u8; 16] {
$crate::__private::sp_core_hashing_proc_macro::twox_128!(b":", $name, b":")
$crate::__private::sp_crypto_hashing_proc_macro::twox_128!(b":", $name, b":")
}

/// Set the value of this parameter type in the storage.
Expand Down
9 changes: 4 additions & 5 deletions substrate/primitives/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ libsecp256k1 = { version = "0.7", default-features = false, features = ["static-
schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated", "u64_backend"], default-features = false }
merlin = { version = "2.0", default-features = false }
secp256k1 = { version = "0.24.0", default-features = false, features = ["recovery", "alloc"], optional = true }
sp-core-hashing = { path = "hashing", default-features = false, optional = true }
sp-crypto-hashing = { path = "../crypto/hashing", default-features = false, optional = true }
sp-runtime-interface = { path = "../runtime-interface", default-features = false}

# bls crypto
Expand All @@ -63,7 +63,6 @@ bandersnatch_vrfs = { git = "https://github.com/w3f/ring-vrf", rev = "cbc342e",
[dev-dependencies]
criterion = "0.4.0"
serde_json = "1.0.108"
sp-core-hashing-proc-macro = { path = "hashing/proc-macro" }

[[bench]]
name = "bench"
Expand Down Expand Up @@ -109,7 +108,7 @@ std = [
"secp256k1/std",
"secrecy/alloc",
"serde/std",
"sp-core-hashing/std",
"sp-crypto-hashing/std",
"sp-debug-derive/std",
"sp-externalities/std",
"sp-runtime-interface/std",
Expand All @@ -135,7 +134,7 @@ serde = [
"primitive-types/serde_no_std",
"scale-info/serde",
"secrecy/alloc",
"sp-core-hashing",
"sp-crypto-hashing",
"sp-storage/serde",
]

Expand All @@ -148,7 +147,7 @@ full_crypto = [
"ed25519-zebra",
"libsecp256k1",
"secp256k1",
"sp-core-hashing",
"sp-crypto-hashing",
"sp-runtime-interface/disable_target_static_assertions",
]

Expand Down
2 changes: 1 addition & 1 deletion substrate/primitives/core/src/bandersnatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl TraitPair for Pair {
_seed: Option<Seed>,
) -> Result<(Pair, Option<Seed>), DeriveError> {
let derive_hard = |seed, cc| -> Seed {
("bandersnatch-vrf-HDKD", seed, cc).using_encoded(sp_core_hashing::blake2_256)
("bandersnatch-vrf-HDKD", seed, cc).using_encoded(sp_crypto_hashing::blake2_256)
};

let mut seed = self.seed();
Expand Down
2 changes: 1 addition & 1 deletion substrate/primitives/core/src/bls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ trait HardJunctionId {
/// Derive a single hard junction.
#[cfg(feature = "full_crypto")]
fn derive_hard_junction<T: HardJunctionId>(secret_seed: &Seed, cc: &[u8; 32]) -> Seed {
(T::ID, secret_seed, cc).using_encoded(sp_core_hashing::blake2_256)
(T::ID, secret_seed, cc).using_encoded(sp_crypto_hashing::blake2_256)
}

#[cfg(feature = "full_crypto")]
Expand Down
2 changes: 1 addition & 1 deletion substrate/primitives/core/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl DeriveJunction {
let mut cc: [u8; JUNCTION_ID_LEN] = Default::default();
index.using_encoded(|data| {
if data.len() > JUNCTION_ID_LEN {
cc.copy_from_slice(&sp_core_hashing::blake2_256(data));
cc.copy_from_slice(&sp_crypto_hashing::blake2_256(data));
} else {
cc[0..data.len()].copy_from_slice(data);
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/primitives/core/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl From<RecoverableSignature> for Signature {
/// Derive a single hard junction.
#[cfg(feature = "full_crypto")]
fn derive_hard_junction(secret_seed: &Seed, cc: &[u8; 32]) -> Seed {
("Secp256k1HDKD", secret_seed, cc).using_encoded(sp_core_hashing::blake2_256)
("Secp256k1HDKD", secret_seed, cc).using_encoded(sp_crypto_hashing::blake2_256)
}

/// A key pair.
Expand Down
2 changes: 1 addition & 1 deletion substrate/primitives/core/src/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl Derive for Public {}
/// Derive a single hard junction.
#[cfg(feature = "full_crypto")]
fn derive_hard_junction(secret_seed: &Seed, cc: &[u8; 32]) -> Seed {
("Ed25519HDKD", secret_seed, cc).using_encoded(sp_core_hashing::blake2_256)
("Ed25519HDKD", secret_seed, cc).using_encoded(sp_crypto_hashing::blake2_256)
}

#[cfg(feature = "full_crypto")]
Expand Down
66 changes: 0 additions & 66 deletions substrate/primitives/core/src/hashing.rs

This file was deleted.

7 changes: 3 additions & 4 deletions substrate/primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ pub use sp_debug_derive::RuntimeDebug;
pub use impl_serde::serialize as bytes;

#[cfg(feature = "full_crypto")]
pub mod hashing;

#[cfg(feature = "full_crypto")]
pub use hashing::{blake2_128, blake2_256, keccak_256, twox_128, twox_256, twox_64};
pub use sp_crypto_hashing::{
self as hashing, blake2_128, blake2_256, keccak_256, twox_128, twox_256, twox_64,
};
pub mod crypto;
pub mod hexdisplay;
pub use paste;
Expand Down
Loading
Loading