Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
update tiny-keccak (#4093)
Browse files Browse the repository at this point in the history
* update tiny-keccak

* fix

* Update Cargo.toml

* update Cargo.lock

* remove keccak-hasher
  • Loading branch information
kigawas authored and gavofyork committed Nov 12, 2019
1 parent 8fad033 commit 4c15d8a
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 21 deletions.
26 changes: 16 additions & 10 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions core/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ runtime-interface = { package = "substrate-runtime-interface", path = "../runtim
externalities = { package = "substrate-externalities", path = "../externalities" }
parking_lot = "0.9.0"
log = "0.4.8"
libsecp256k1 = "0.3.0"
tiny-keccak = "1.5.0"
libsecp256k1 = "0.3.2"

cranelift-codegen = { version = "0.46.1", optional = true }
cranelift-entity = { version = "0.46.1", optional = true }
Expand Down
6 changes: 3 additions & 3 deletions core/executor/src/deprecated_host_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use codec::Encode;
use std::{convert::TryFrom, str};
use primitives::{
blake2_128, blake2_256, twox_64, twox_128, twox_256, ed25519, sr25519, Blake2Hasher, Pair,
blake2_128, blake2_256, twox_64, twox_128, twox_256, ed25519, sr25519, keccak_256, Blake2Hasher, Pair,
crypto::KeyTypeId, offchain,
};
use trie::{TrieConfiguration, trie_types::Layout};
Expand Down Expand Up @@ -538,11 +538,11 @@ impl_wasm_host_interface! {

ext_keccak_256(data: Pointer<u8>, len: WordSize, out: Pointer<u8>) {
let result: [u8; 32] = if len == 0 {
tiny_keccak::keccak256(&[0u8; 0])
keccak_256(&[0u8; 0])
} else {
let mem = context.read_memory(data, len)
.map_err(|_| "Invalid attempt to get data in ext_keccak_256")?;
tiny_keccak::keccak256(&mem)
keccak_256(&mem)
};
context.write_memory(out, &result)
.map_err(|_| "Invalid attempt to set result in ext_keccak_256")?;
Expand Down
3 changes: 2 additions & 1 deletion core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ zeroize = { version = "0.10.1", default-features = false }
lazy_static = { version = "1.4.0", default-features = false, optional = true }
parking_lot = { version = "0.9.0", optional = true }
libsecp256k1 = { version = "0.3.0", default-features = false, optional = true }
tiny-keccak = { version = "1.5.0", optional = true }
tiny-keccak = { version = "2.0.1", features = ["keccak"], optional = true }
substrate-debug-derive = { version = "2.0.0", path = "./debug-derive" }
externalities = { package = "substrate-externalities", path = "../externalities", optional = true }
primitives-storage = { package = "substrate-primitives-storage", path = "storage", default-features = false }
Expand Down Expand Up @@ -100,6 +100,7 @@ std = [
full_crypto = [
"ed25519-dalek",
"blake2-rfc",
"tiny-keccak",
"schnorrkel",
"libsecp256k1",
"hex",
Expand Down
10 changes: 10 additions & 0 deletions core/primitives/src/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//! Hashing functions.

use blake2_rfc;
use tiny_keccak::{Hasher, Keccak};
use twox_hash;

/// Do a Blake2 512-bit hash and place result in `dest`.
Expand Down Expand Up @@ -121,3 +122,12 @@ pub fn twox_256(data: &[u8]) -> [u8; 32] {
twox_256_into(data, &mut r);
r
}

/// Do a keccak 256 hash and return result.
pub fn keccak_256(data: &[u8]) -> [u8; 32] {
let mut keccak = Keccak::v256();
keccak.update(data);
let mut output = [0u8; 32];
keccak.finalize(&mut output);
output
}
2 changes: 1 addition & 1 deletion core/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ 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, twox_64, twox_128, twox_256};
pub use hashing::{blake2_128, blake2_256, twox_64, twox_128, twox_256, keccak_256};
#[cfg(feature = "std")]
pub mod hexdisplay;
pub mod crypto;
Expand Down
2 changes: 0 additions & 2 deletions core/sr-io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ hash-db = { version = "0.15.2", default-features = false }
primitives = { package = "substrate-primitives", path = "../primitives", default-features = false }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
libsecp256k1 = { version = "0.3.0", optional = true }
tiny-keccak = { version = "1.5.0", optional = true }
substrate-state-machine = { path = "../state-machine", optional = true }
runtime-interface = { package = "substrate-runtime-interface", path = "../runtime-interface", default-features = false }
trie = { package = "substrate-trie", path = "../trie", optional = true }
Expand All @@ -27,7 +26,6 @@ std = [
"trie",
"substrate-state-machine",
"libsecp256k1",
"tiny-keccak",
"runtime-interface/std",
"externalities",
"log",
Expand Down
2 changes: 1 addition & 1 deletion core/sr-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ pub trait Crypto {
pub trait Hashing {
/// Conduct a 256-bit Keccak hash.
fn keccak_256(data: &[u8]) -> [u8; 32] {
tiny_keccak::keccak256(data)
primitives::hashing::keccak_256(data)
}

/// Conduct a 128-bit Blake2 hash.
Expand Down
1 change: 0 additions & 1 deletion core/trie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ primitives = { package = "substrate-primitives", path = "../primitives", defaul
[dev-dependencies]
trie-bench = "0.16.2"
trie-standardmap = "0.15.2"
keccak-hasher = "0.15.2"
criterion = "0.2.11"
hex-literal = "0.2.1"

Expand Down

0 comments on commit 4c15d8a

Please sign in to comment.