Skip to content

Commit

Permalink
Merge pull request #214 from wasmerio/fix/better-hashing
Browse files Browse the repository at this point in the history
Improved hashing algorithm
  • Loading branch information
syrusakbary authored Feb 26, 2019
2 parents f2886db + e6d0f91 commit e5dc0b1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
35 changes: 25 additions & 10 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 lib/runtime-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ version = "1.0"
version = "0.10"
[dependencies.serde-bench]
version = "0.0.7"
[dependencies.meowhash]
version = "0.1.2"
[dependencies.blake2b_simd]
version = "0.4.1"
[dependencies.digest]
version = "0.8.0"
[dependencies.hashbrown]
Expand Down
10 changes: 7 additions & 3 deletions lib/runtime-core/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use crate::{
module::{Module, ModuleInfo},
sys::Memory,
};
use digest::Digest;
use meowhash::MeowHasher;
use blake2b_simd::blake2bp;
use std::{fmt, io, mem, slice};

#[derive(Debug)]
Expand Down Expand Up @@ -45,7 +44,12 @@ impl WasmHash {
pub fn generate(wasm: &[u8]) -> Self {
let mut first_part = [0u8; 32];
let mut second_part = [0u8; 32];
let generic_array = MeowHasher::digest(wasm);

let mut state = blake2bp::State::new();
state.update(wasm);

let mut hasher = state.finalize();
let generic_array = hasher.as_bytes();

first_part.copy_from_slice(&generic_array[0..32]);
second_part.copy_from_slice(&generic_array[32..64]);
Expand Down

0 comments on commit e5dc0b1

Please sign in to comment.