From 9ca5a94f2e4b6787af051a0ebae811b72181147f Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 16 Mar 2020 15:22:10 -0700 Subject: [PATCH] Update digest requirement from 0.7 to 0.8 (#141) * Update `digest` and `blake2` requirement from 0.7 to 0.8 Updates the requirements on [digest](https://github.com/RustCrypto/traits) to permit the latest version. - [Release notes](https://github.com/RustCrypto/traits/releases) - [Commits](https://github.com/RustCrypto/traits/compare/digest_v0.7.2...digest-v0.8.1) Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Pratyush Mishra --- .hooks/pre-commit | 6 +++--- cp-benches/Cargo.toml | 4 ++-- crypto-primitives/Cargo.toml | 4 ++-- crypto-primitives/src/prf/blake2s/constraints.rs | 12 ++++++------ crypto-primitives/src/prf/blake2s/mod.rs | 11 +++++++---- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/.hooks/pre-commit b/.hooks/pre-commit index f3a3b0d..b8a7c30 100755 --- a/.hooks/pre-commit +++ b/.hooks/pre-commit @@ -4,7 +4,7 @@ rustfmt --version &>/dev/null if [ $? != 0 ]; then printf "[pre_commit] \033[0;31merror\033[0m: \"rustfmt\" not available. \n" printf "[pre_commit] \033[0;31merror\033[0m: rustfmt can be installed via - \n" - printf "[pre_commit] $ rustup component add rustfmt-preview \n" + printf "[pre_commit] $ rustup component add rustfmt \n" exit 1 fi @@ -13,7 +13,7 @@ problem_files=() # collect ill-formatted files for file in $(git diff --name-only --cached); do if [ ${file: -3} == ".rs" ]; then - rustfmt --check $file &>/dev/null + rustfmt +nightly --check $file &>/dev/null if [ $? != 0 ]; then problem_files+=($file) fi @@ -33,4 +33,4 @@ else done fi -exit 0 \ No newline at end of file +exit 0 diff --git a/cp-benches/Cargo.toml b/cp-benches/Cargo.toml index a97aa0e..018bbfd 100644 --- a/cp-benches/Cargo.toml +++ b/cp-benches/Cargo.toml @@ -22,8 +22,8 @@ edition = "2018" ################################# Dependencies ################################ [dev-dependencies] -algebra = { path = "../algebra", default-features = false } -blake2 = { version = "0.7", default-features = false } +algebra = { path = "../algebra", default-features = false, features = [ "edwards_bls12" ] } +blake2 = { version = "0.8", default-features = false } criterion = "0.3.1" crypto-primitives = { path = "../crypto-primitives" } rand = { version = "0.7" } diff --git a/crypto-primitives/Cargo.toml b/crypto-primitives/Cargo.toml index 2f12c95..6111856 100644 --- a/crypto-primitives/Cargo.toml +++ b/crypto-primitives/Cargo.toml @@ -25,8 +25,8 @@ edition = "2018" algebra-core = { path = "../algebra-core", default-features = false } bench-utils = { path = "../bench-utils" } -blake2 = { version = "0.7", default-features = false } -digest = "0.7" +blake2 = { version = "0.8", default-features = false } +digest = "0.8" ff-fft = { path = "../ff-fft", default-features = false } gm17 = { path = "../gm17", optional = true, default-features = false } diff --git a/crypto-primitives/src/prf/blake2s/constraints.rs b/crypto-primitives/src/prf/blake2s/constraints.rs index f23d620..e3d96a9 100644 --- a/crypto-primitives/src/prf/blake2s/constraints.rs +++ b/crypto-primitives/src/prf/blake2s/constraints.rs @@ -530,12 +530,11 @@ impl PRFGadget for Blake2sGadget #[cfg(test)] mod test { use algebra::jubjub::Fq as Fr; - use digest::{FixedOutput, Input}; use rand::{Rng, SeedableRng}; use rand_xorshift::XorShiftRng; use crate::prf::blake2s::{constraints::blake2s_gadget, Blake2s as B2SPRF}; - use blake2::Blake2s; + use blake2::VarBlake2s; use r1cs_core::ConstraintSystem; use super::Blake2sGadget; @@ -634,13 +633,15 @@ mod test { let mut rng = XorShiftRng::seed_from_u64(1231275789u64); for input_len in (0..32).chain((32..256).filter(|a| a % 8 == 0)) { - let mut h = Blake2s::new_keyed(&[], 32); + use digest::*; + let mut h = VarBlake2s::new_keyed(&[], 32); let data: Vec = (0..input_len).map(|_| rng.gen()).collect(); - h.process(&data); + h.input(&data); - let hash_result = h.fixed_result(); + let mut hash_result = Vec::with_capacity(h.output_size()); + h.variable_result(|res| hash_result.extend_from_slice(res)); let mut cs = TestConstraintSystem::::new(); @@ -663,7 +664,6 @@ mod test { assert!(cs.is_satisfied()); let mut s = hash_result - .as_ref() .iter() .flat_map(|&byte| (0..8).map(move |i| (byte >> i) & 1u8 == 1u8)); diff --git a/crypto-primitives/src/prf/blake2s/mod.rs b/crypto-primitives/src/prf/blake2s/mod.rs index 18c1dc9..0aa15a5 100644 --- a/crypto-primitives/src/prf/blake2s/mod.rs +++ b/crypto-primitives/src/prf/blake2s/mod.rs @@ -1,5 +1,5 @@ use alloc::vec::Vec; -use blake2::Blake2s as b2s; +use blake2::{Blake2s as B2s, VarBlake2s}; use digest::Digest; use super::PRF; @@ -18,7 +18,7 @@ impl PRF for Blake2s { fn evaluate(seed: &Self::Seed, input: &Self::Input) -> Result { let eval_time = start_timer!(|| "Blake2s::Eval"); - let mut h = b2s::new(); + let mut h = B2s::new(); h.input(seed.as_ref()); h.input(input.as_ref()); let mut result = [0u8; 32]; @@ -80,10 +80,13 @@ impl Blake2sWithParameterBlock { } pub fn evaluate(&self, input: &[u8]) -> Vec { + use digest::*; let eval_time = start_timer!(|| "Blake2sWithParameterBlock::Eval"); - let mut h = b2s::with_parameter_block(&self.parameters()); + let mut h = VarBlake2s::with_parameter_block(&self.parameters()); h.input(input.as_ref()); end_timer!(eval_time); - h.result().to_vec() + let mut buf = Vec::with_capacity(h.output_size()); + h.variable_result(|res| buf.extend_from_slice(res)); + buf } }