Browse Source

fixed blake2 bug on my M1 mac

pull/8/head
Nanak Nihal Singh Khalsa 1 year ago
parent
commit
2367e15363
2 changed files with 32 additions and 20 deletions
  1. +6
    -5
      Cargo.toml
  2. +26
    -15
      src/lib.rs

+ 6
- 5
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"]

+ 26
- 15
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<u8> {
let hash = blake_hash::Blake512::digest(b);
hash.to_vec()
}
// #[cfg(not(feature = "aarch64"))]
// fn blh(b: &[u8]) -> Vec<u8> {
// 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<u8> {
// let mut hash = [0; 64];
// blake::hash(512, b, &mut hash).unwrap();
// hash.to_vec()
// }
#[cfg(feature = "aarch64")]
fn blh(b: &[u8]) -> Vec<u8> {
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,

Loading…
Cancel
Save