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

Use blake3 instead of blake2_simd #1140

Merged
merged 9 commits into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## **[Unreleased]**

- [#1140](https://github.com/wasmerio/wasmer/pull/1140) Use [`blake3`](https://github.com/BLAKE3-team/BLAKE3) as default hashing algorithm for caching.
- [#1128](https://github.com/wasmerio/wasmer/pull/1128) Fix a crash when a host function is missing and the `allow_missing_functions` flag is enabled
- [#1099](https://github.com/wasmerio/wasmer/pull/1099) Remove `backend::Backend` from `wasmer_runtime_core`
- [#1098](https://github.com/wasmerio/wasmer/pull/1098) Remove `backend::Backend` from `wasmer_runtime_core`
Expand Down
14 changes: 8 additions & 6 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions lib/runtime-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ edition = "2018"
nix = "0.15"
page_size = "0.4"
wasmparser = "0.45.0"
parking_lot = "0.9"
parking_lot = "0.10.0"
lazy_static = "1.4"
errno = "0.2"
libc = "0.2.60"
hex = "0.3"
hex = "0.4"
smallvec = "0.6"
bincode = "1.1"

Expand All @@ -36,16 +36,16 @@ version = "1.0"
version = "0.11"
[dependencies.serde-bench]
version = "0.0.7"
[dependencies.blake2b_simd]
version = "0.5"
[dependencies.blake3]
version = "0.1.0"
[dependencies.digest]
version = "0.8"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["memoryapi"] }

[build-dependencies]
blake2b_simd = "0.5"
blake3 = "0.1.0"
rustc_version = "0.2"
cc = "1.0"

Expand Down
7 changes: 3 additions & 4 deletions lib/runtime-core/build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use blake2b_simd::blake2bp;
use std::{env, fs, io::Write, path::PathBuf};

const WASMER_VERSION: &'static str = env!("CARGO_PKG_VERSION");

fn main() {
let mut state = blake2bp::State::new();
state.update(WASMER_VERSION.as_bytes());
let mut hasher = blake3::Hasher::new();
hasher.update(WASMER_VERSION.as_bytes());

let hasher = state.finalize();
let hasher = hasher.finalize();
let hash_string = hasher.to_hex().as_str().to_owned();

let crate_dir = env::var("OUT_DIR").unwrap();
Expand Down
13 changes: 6 additions & 7 deletions lib/runtime-core/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! and loaded to allow skipping compilation and fast startup.

use crate::{module::ModuleInfo, sys::Memory};
use blake2b_simd::blake2bp;
use std::{io, mem, slice};

/// Indicates the invalid type of invalid cache file
Expand Down Expand Up @@ -59,16 +58,16 @@ impl WasmHash {
/// is, in fact, a wasm module.
pub fn generate(wasm: &[u8]) -> Self {
let mut first_part = [0u8; 32];
let mut second_part = [0u8; 32];
// We don't use the second part for now, since the blake3 hash is 32 byte array
let second_part = [0u8; 32];
syrusakbary marked this conversation as resolved.
Show resolved Hide resolved

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

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

first_part.copy_from_slice(&generic_array[0..32]);
second_part.copy_from_slice(&generic_array[32..64]);
WasmHash(first_part, second_part)
}

Expand Down