From 2d17d0e783638de2a726d8ba7ee522d5b12535f7 Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Thu, 9 Aug 2018 11:59:31 +0200 Subject: [PATCH] Replace ring with tiny-keccak. --- Cargo.toml | 2 +- src/lib.rs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5c275dd..11920bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,9 +18,9 @@ log = "0.4.1" pairing = { version = "0.14.2", features = ["u128-support"] } rand = "0.4.2" rand_derive = "0.3.1" -ring = "^0.12" serde = "1.0.55" serde_derive = "1.0.55" +tiny-keccak = "1.4" [dev-dependencies] bincode = "1.0.0" diff --git a/src/lib.rs b/src/lib.rs index 24b47d6..7afae85 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,10 +14,10 @@ extern crate pairing; extern crate rand; #[macro_use] extern crate rand_derive; -extern crate ring; extern crate serde; #[macro_use] extern crate serde_derive; +extern crate tiny_keccak; pub mod error; mod into_fr; @@ -33,7 +33,7 @@ use init_with::InitWith; use pairing::bls12_381::{Bls12, Fr, G1, G1Affine, G2, G2Affine}; use pairing::{CurveAffine, CurveProjective, Engine, Field}; use rand::{ChaChaRng, OsRng, Rng, SeedableRng}; -use ring::digest; +use tiny_keccak::sha3_256; use error::{Error, Result}; use into_fr::IntoFr; @@ -445,7 +445,7 @@ impl SecretKeySet { /// Returns a hash of the given message in `G2`. fn hash_g2>(msg: M) -> G2 { - let digest = digest::digest(&digest::SHA256, msg.as_ref()); + let digest = sha3_256(msg.as_ref()); let seed = <[u32; CHACHA_RNG_SEED_SIZE]>::init_with_indices(|i| { BigEndian::read_u32(&digest.as_ref()[(4 * i)..(4 * i + 4)]) }); @@ -458,8 +458,7 @@ fn hash_g1_g2>(g1: G1, msg: M) -> G2 { // If the message is large, hash it, otherwise copy it. // TODO: Benchmark and optimize the threshold. let mut msg = if msg.as_ref().len() > 64 { - let digest = digest::digest(&digest::SHA256, msg.as_ref()); - digest.as_ref().to_vec() + sha3_256(msg.as_ref()).to_vec() } else { msg.as_ref().to_vec() }; @@ -469,7 +468,7 @@ fn hash_g1_g2>(g1: G1, msg: M) -> G2 { /// Returns a hash of the group element with the specified length in bytes. fn hash_bytes(g1: G1, len: usize) -> Vec { - let digest = digest::digest(&digest::SHA256, g1.into_affine().into_compressed().as_ref()); + let digest = sha3_256(g1.into_affine().into_compressed().as_ref()); let seed = <[u32; CHACHA_RNG_SEED_SIZE]>::init_with_indices(|i| { BigEndian::read_u32(&digest.as_ref()[(4 * i)..(4 * i + 4)]) });