Browse Source

compatability with previous blake hash

pull/8/head
Nanak Nihal Khalsa 1 year ago
parent
commit
44630c26d3
2 changed files with 31 additions and 35 deletions
  1. +7
    -6
      Cargo.toml
  2. +24
    -29
      src/lib.rs

+ 7
- 6
Cargo.toml

@ -12,12 +12,13 @@ readme = "README.md"
ff = {package="ff_ce", version= "0.11", features = ["derive"]}
rand_new = {package="rand", version="0.8.5"}
rand = "0.4.6"
# rand = "0.8"
num = "0.4"
num-bigint = {version = "0.4", features = ["rand"]}
num-traits = "0.2.8"
blake2 = "0.10.6"
# 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"
@ -34,6 +35,6 @@ hex = "0.4"
name = "bench_babyjubjub"
harness = false
# [features]
# default = ["blake-hash"]
# aarch64 = ["blake"]
[features]
default = ["blake-hash"]
aarch64 = ["blake"]

+ 24
- 29
src/lib.rs

@ -6,15 +6,12 @@ use rand::ThreadRng;
use std::{iter::Sum, ops::{Neg, AddAssign}, fmt::Error};
use num::Num;
use std::fmt;
// use serde::{Serialize, ser::SerializeSeq, Deserialize};
use serde::{Serialize, ser::SerializeStruct, de::Visitor, de::MapAccess, Deserialize, Deserializer};
// use bytes::{BytesMut, BufMut};
use poseidon_rs::Poseidon;
pub type Fr = poseidon_rs::Fr; // alias
extern crate rand_new;
extern crate rand;
// #[macro_use]
extern crate ff;
// Create a new primefield for the subgroup defined by the base point, order Fl:
@ -25,13 +22,12 @@ pub struct Fl(FpRepr);
use arrayref::array_ref;
// #[cfg(not(feature = "aarch64"))]
// use blake_hash::Digest; // 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
// #[cfg(feature = "aarch64")]
// extern crate blake; // compatible version with Blake used at circomlib
use blake2::{Blake2b512, Digest};
// use hex_literal::hex;
use std::{cmp::min, str::FromStr};
use num_bigint::{BigInt, RandBigInt, Sign, ToBigInt};
@ -502,30 +498,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> {
// println!("hashing {:?} {:?}", b.len(), b);
// let debugggggggggme = blake_hash::Blake512::digest(b);
// println!("debugging {:?}", debugggggggggme);
#[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()
}
// 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()
// pub fn blh(b: &[u8]) -> Vec<u8> {
// let mut h = Blake2b512::new();
// h.update(b);
// let digest = h.finalize();
// return digest[..].to_vec();
// }
pub fn blh(b: &[u8]) -> Vec<u8> {
let mut h = Blake2b512::new();
h.update(b);
let digest = h.finalize();
return digest[..].to_vec();
}
#[derive(Debug, Clone, Serialize)]
pub struct Signature {
pub r_b8: Point,

Loading…
Cancel
Save