Switch to using the blake2-rfc crate instead.

This commit is contained in:
Sean Bowe
2018-03-05 17:58:34 -07:00
parent 2e846844e7
commit 058801bdfc
5 changed files with 17 additions and 19 deletions

View File

@@ -14,7 +14,7 @@ features = ["expose-arith"]
[dependencies] [dependencies]
rand = "0.4" rand = "0.4"
blake2 = "0.7" blake2-rfc = "0.2.18"
digest = "0.7" digest = "0.7"
bellman = "0.0.9" bellman = "0.0.9"

View File

@@ -313,8 +313,7 @@ mod test {
use ::circuit::test::TestConstraintSystem; use ::circuit::test::TestConstraintSystem;
use super::blake2s; use super::blake2s;
use bellman::{ConstraintSystem}; use bellman::{ConstraintSystem};
use blake2::{Blake2s}; use blake2_rfc::blake2s::Blake2s;
use digest::{FixedOutput, Input};
#[test] #[test]
fn test_blake2s_constraints() { fn test_blake2s_constraints() {
@@ -357,13 +356,13 @@ mod test {
for input_len in (0..32).chain((32..256).filter(|a| a % 8 == 0)) for input_len in (0..32).chain((32..256).filter(|a| a % 8 == 0))
{ {
let mut h = Blake2s::new_keyed(&[], 32); let mut h = Blake2s::new(32);
let data: Vec<u8> = (0..input_len).map(|_| rng.gen()).collect(); let data: Vec<u8> = (0..input_len).map(|_| rng.gen()).collect();
h.process(&data); h.update(&data);
let hash_result = h.fixed_result(); let hash_result = h.finalize();
let mut cs = TestConstraintSystem::<Bls12>::new(); let mut cs = TestConstraintSystem::<Bls12>::new();

View File

@@ -16,12 +16,12 @@ use bellman::{
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt::Write; use std::fmt::Write;
use blake2::{Blake2s};
use digest::{FixedOutput, Input};
use byteorder::{BigEndian, ByteOrder}; use byteorder::{BigEndian, ByteOrder};
use std::cmp::Ordering; use std::cmp::Ordering;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use blake2_rfc::blake2s::Blake2s;
#[derive(Debug)] #[derive(Debug)]
enum NamedObject { enum NamedObject {
Constraint(usize), Constraint(usize),
@@ -107,7 +107,7 @@ fn hash_lc<E: Engine>(
let mut buf = [0u8; 9 + 32]; let mut buf = [0u8; 9 + 32];
BigEndian::write_u64(&mut buf[0..8], map.len() as u64); BigEndian::write_u64(&mut buf[0..8], map.len() as u64);
h.process(&buf[0..8]); h.update(&buf[0..8]);
for (var, coeff) in map { for (var, coeff) in map {
match var.0.get_unchecked() { match var.0.get_unchecked() {
@@ -123,7 +123,7 @@ fn hash_lc<E: Engine>(
coeff.into_repr().write_be(&mut buf[9..]).unwrap(); coeff.into_repr().write_be(&mut buf[9..]).unwrap();
h.process(&buf); h.update(&buf);
} }
} }
@@ -230,14 +230,14 @@ impl<E: Engine> TestConstraintSystem<E> {
} }
pub fn hash(&self) -> String { pub fn hash(&self) -> String {
let mut h = Blake2s::new_keyed(&[], 32); let mut h = Blake2s::new(32);
{ {
let mut buf = [0u8; 24]; let mut buf = [0u8; 24];
BigEndian::write_u64(&mut buf[0..8], self.inputs.len() as u64); BigEndian::write_u64(&mut buf[0..8], self.inputs.len() as u64);
BigEndian::write_u64(&mut buf[8..16], self.aux.len() as u64); BigEndian::write_u64(&mut buf[8..16], self.aux.len() as u64);
BigEndian::write_u64(&mut buf[16..24], self.constraints.len() as u64); BigEndian::write_u64(&mut buf[16..24], self.constraints.len() as u64);
h.process(&buf); h.update(&buf);
} }
for constraint in &self.constraints { for constraint in &self.constraints {
@@ -247,7 +247,7 @@ impl<E: Engine> TestConstraintSystem<E> {
} }
let mut s = String::new(); let mut s = String::new();
for b in h.fixed_result().as_ref() { for b in h.finalize().as_ref() {
s += &format!("{:02x}", b); s += &format!("{:02x}", b);
} }

View File

@@ -1,7 +1,6 @@
use jubjub::*; use jubjub::*;
use pairing::*; use pairing::*;
use blake2::{Blake2s}; use blake2_rfc::blake2s::Blake2s;
use digest::{FixedOutput, Input};
/// Produces an (x, y) pair (Montgomery) for a /// Produces an (x, y) pair (Montgomery) for a
/// random point in the Jubjub curve. The point /// random point in the Jubjub curve. The point
@@ -15,9 +14,9 @@ pub fn group_hash<E: JubjubEngine>(
// Check to see that scalar field is 255 bits // Check to see that scalar field is 255 bits
assert!(E::Fr::NUM_BITS == 255); assert!(E::Fr::NUM_BITS == 255);
let mut h = Blake2s::new_keyed(&[], 32); let mut h = Blake2s::new(32);
h.process(tag); h.update(tag);
let mut h = h.fixed_result().to_vec(); let mut h = h.finalize().as_ref().to_vec();
assert!(h.len() == 32); assert!(h.len() == 32);
// Take first/unset first bit of hash // Take first/unset first bit of hash

View File

@@ -1,6 +1,6 @@
extern crate pairing; extern crate pairing;
extern crate bellman; extern crate bellman;
extern crate blake2; extern crate blake2_rfc;
extern crate digest; extern crate digest;
extern crate rand; extern crate rand;