From 2367e15363f5e6e444f957c14b98fdbd38125430 Mon Sep 17 00:00:00 2001 From: Nanak Nihal Singh Khalsa Date: Tue, 24 Jan 2023 15:50:20 -0500 Subject: [PATCH] fixed blake2 bug on my M1 mac --- Cargo.toml | 11 ++++++----- src/lib.rs | 41 ++++++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3c87354..d3a0bb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,9 @@ rand = "0.8" num = "0.4" num-bigint = {version = "0.4", features = ["rand"]} num-traits = "0.2.8" -blake-hash = {version="0.4.0", optional=true} -blake = {version="2.0.1", optional=true} +blake2 = "0.10.6" +# blake-hash = {version="0.4.0", optional=true} +# blake = {version="2.0.1", optional=true} generic-array = "0.14" poseidon-rs = "0.0.8" arrayref = "0.3.5" @@ -30,6 +31,6 @@ hex = "0.4" name = "bench_babyjubjub" harness = false -[features] -default = ["blake-hash"] -aarch64 = ["blake"] +# [features] +# default = ["blake-hash"] +# aarch64 = ["blake"] diff --git a/src/lib.rs b/src/lib.rs index 0039b7d..878f269 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,12 +8,13 @@ pub type Fr = poseidon_rs::Fr; // alias use arrayref::array_ref; -#[cfg(not(feature = "aarch64"))] -use blake_hash::Digest; // compatible version with Blake used at circomlib - -#[cfg(feature = "aarch64")] -extern crate blake; // compatible version with Blake used at circomlib +// #[cfg(not(feature = "aarch64"))] +// use blake_hash::Digest; // compatible version with Blake used at circomlib +// #[cfg(feature = "aarch64")] +// extern crate blake; // compatible version with Blake used at circomlib +use blake2::{Blake2b512, Blake2s256, Digest}; +// use hex_literal::hex; use std::cmp::min; use num_bigint::{BigInt, RandBigInt, Sign, ToBigInt}; @@ -223,19 +224,29 @@ pub fn decompress_point(bb: [u8; 32]) -> Result { Ok(Point { x: x_fr, y: y_fr }) } -#[cfg(not(feature = "aarch64"))] -fn blh(b: &[u8]) -> Vec { - let hash = blake_hash::Blake512::digest(b); - hash.to_vec() -} +// #[cfg(not(feature = "aarch64"))] +// fn blh(b: &[u8]) -> Vec { +// println!("hashing {:?} {:?}", b.len(), b); +// let debugggggggggme = blake_hash::Blake512::digest(b); +// println!("debugging {:?}", debugggggggggme); + +// let hash = blake_hash::Blake512::digest(b); +// hash.to_vec() +// } + +// #[cfg(feature = "aarch64")] +// fn blh(b: &[u8]) -> Vec { +// let mut hash = [0; 64]; +// blake::hash(512, b, &mut hash).unwrap(); +// hash.to_vec() +// } -#[cfg(feature = "aarch64")] fn blh(b: &[u8]) -> Vec { - let mut hash = [0; 64]; - blake::hash(512, b, &mut hash).unwrap(); - hash.to_vec() + let mut h = Blake2b512::new(); + h.update(b); + let digest = h.finalize(); + return digest[..].to_vec(); } - #[derive(Debug, Clone)] pub struct Signature { pub r_b8: Point,