Skip to content

Commit 0516e9f

Browse files
committed
Change the GeneratorsChain to use SHAKE256
1 parent 1703a79 commit 0516e9f

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ description = "A pure-Rust implementation of Bulletproofs using Ristretto"
1414
[dependencies]
1515
curve25519-dalek = { version = "0.19", features = ["serde"] }
1616
subtle = "0.7"
17-
sha2 = "^0.7"
17+
sha3 = "0.7"
18+
digest = "0.7"
1819
rand = "0.5.0-pre.2"
1920
byteorder = "1.2.1"
2021
serde = "1"

src/generators.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,29 @@
44
#![allow(non_snake_case)]
55
#![deny(missing_docs)]
66

7-
// XXX we should use Sha3 everywhere
8-
use sha2::{Digest, Sha512};
9-
107
use curve25519_dalek::ristretto::RistrettoPoint;
118
use curve25519_dalek::scalar::Scalar;
129
use curve25519_dalek::traits::MultiscalarMul;
1310

11+
use digest::{ExtendableOutput, Input, XofReader};
12+
use sha3::{Sha3XofReader, Shake256};
13+
1414
/// The `GeneratorsChain` creates an arbitrary-long sequence of orthogonal generators.
1515
/// The sequence can be deterministically produced starting with an arbitrary point.
1616
struct GeneratorsChain {
17-
next_point: RistrettoPoint,
17+
reader: Sha3XofReader,
1818
}
1919

2020
impl GeneratorsChain {
2121
/// Creates a chain of generators, determined by the hash of `label`.
2222
fn new(label: &[u8]) -> Self {
23-
let mut hash = Sha512::default();
24-
hash.input(b"GeneratorsChainInit");
25-
hash.input(label);
26-
let next_point = RistrettoPoint::from_hash(hash);
27-
GeneratorsChain { next_point }
23+
let mut shake = Shake256::default();
24+
shake.process(b"GeneratorsChain");
25+
shake.process(label);
26+
27+
GeneratorsChain {
28+
reader: shake.xof_result(),
29+
}
2830
}
2931
}
3032

@@ -36,13 +38,16 @@ impl Default for GeneratorsChain {
3638

3739
impl Iterator for GeneratorsChain {
3840
type Item = RistrettoPoint;
41+
3942
fn next(&mut self) -> Option<Self::Item> {
40-
let current_point = self.next_point;
41-
let mut hash = Sha512::default();
42-
hash.input(b"GeneratorsChainNext");
43-
hash.input(current_point.compress().as_bytes());
44-
self.next_point = RistrettoPoint::from_hash(hash);
45-
Some(current_point)
43+
let mut uniform_bytes = [0u8; 64];
44+
self.reader.read(&mut uniform_bytes);
45+
46+
Some(RistrettoPoint::from_uniform_bytes(&uniform_bytes))
47+
}
48+
49+
fn size_hint(&self) -> (usize, Option<usize>) {
50+
(usize::max_value(), None)
4651
}
4752
}
4853

src/inner_product_proof.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ mod tests {
326326
use super::*;
327327

328328
use rand::OsRng;
329-
use sha2::Sha512;
329+
use sha3::Sha3_512;
330330
use util;
331331

332332
fn test_helper_create(n: usize) {
@@ -338,7 +338,7 @@ mod tests {
338338
let H = gens.share(0).H.to_vec();
339339

340340
// Q would be determined upstream in the protocol, so we pick a random one.
341-
let Q = RistrettoPoint::hash_from_bytes::<Sha512>(b"test point");
341+
let Q = RistrettoPoint::hash_from_bytes::<Sha3_512>(b"test point");
342342

343343
// a and b are the vectors for which we want to prove c = <a,b>
344344
let a: Vec<_> = (0..n).map(|_| Scalar::random(&mut rng)).collect();

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
extern crate byteorder;
1212
extern crate core;
1313
extern crate curve25519_dalek;
14+
extern crate digest;
1415
#[macro_use]
1516
extern crate failure;
1617
extern crate rand;
17-
extern crate sha2;
18+
extern crate sha3;
1819
extern crate subtle;
1920
extern crate tiny_keccak;
2021
#[macro_use]

0 commit comments

Comments
 (0)