Add BLAKE2.

This commit is contained in:
Sean Bowe 2016-09-19 10:35:32 -06:00
parent 6e51712fce
commit a66949d24a
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
7 changed files with 41 additions and 8 deletions

14
Cargo.lock generated
View File

@ -4,6 +4,7 @@ version = "0.0.1"
dependencies = [
"ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bincode 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"blake2-rfc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
"bn 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -37,6 +38,14 @@ dependencies = [
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "blake2-rfc"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"constant_time_eq 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bn"
version = "0.4.0"
@ -52,6 +61,11 @@ name = "byteorder"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "constant_time_eq"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "crossbeam"
version = "0.2.9"

View File

@ -43,6 +43,7 @@ bn = "0.4.0"
crossbeam = "0.2.9"
rand = "0.3.14"
rustc-serialize = "~0.3.19"
blake2-rfc = "0.2.17"
log = "*"
env_logger = "*"
time = "*"

View File

@ -5,6 +5,7 @@ extern crate rand;
extern crate snark;
extern crate crossbeam;
extern crate rustc_serialize;
extern crate blake2_rfc;
extern crate bincode;
#[macro_use]
@ -123,17 +124,22 @@ impl ConnectionHandler {
let mut peers = vec![];
let mut pubkeys = vec![];
let mut commitments: Vec<[u8; 32]> = vec![];
let mut commitments: Vec<PublicKeyHash> = vec![];
for peerid in new_peers.into_iter().take(PLAYERS) {
info!("Initializing new player (peerid={})", peerid.to_hex());
info!("Asking for commitment to PublicKey (peerid={})", peerid.to_hex());
let comm = self.read(&peerid);
commitments.push(comm);
let comm: PublicKeyHash = self.read(&peerid);
if comm.len() != 64 {
error!("Peer sent invalid length commitment (peerid={})", peerid.to_hex());
panic!("cannot recover.");
}
info!("PublicKey Commitment received (peerid={})", peerid.to_hex());
peers.push(peerid);
info!("Writing commitment to transcript");
encode_into(&comm, &mut transcript, Infinite).unwrap();
commitments.push(comm);
peers.push(peerid);
}
// The remote end should never hang up, so this should always be `PLAYERS`.

View File

@ -6,6 +6,7 @@ extern crate rand;
extern crate snark;
extern crate crossbeam;
extern crate rustc_serialize;
extern crate blake2_rfc;
extern crate bincode;
mod protocol;

View File

@ -5,7 +5,7 @@ use super::spair::{Spair, same_power};
use snark::*;
use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
pub type PublicKeyHash = [u8; 32];
pub type PublicKeyHash = Vec<u8>;
#[derive(Clone, PartialEq, Eq)]
pub struct PublicKey {
@ -45,8 +45,13 @@ impl PublicKey {
}
pub fn hash(&self) -> PublicKeyHash {
// TODO
[0xff; 32]
use bincode::SizeLimit::Infinite;
use bincode::rustc_serialize::encode;
use blake2_rfc::blake2b::blake2b;
let serialized = encode(self, Infinite).unwrap();
blake2b(64, &[], &serialized).as_bytes().to_vec()
}
pub fn tau_g2(&self) -> Spair<G2> {

View File

@ -3,6 +3,8 @@ extern crate rand;
extern crate snark;
extern crate crossbeam;
extern crate rustc_serialize;
extern crate blake2_rfc;
extern crate bincode;
mod protocol;
use protocol::*;

View File

@ -3,6 +3,7 @@ extern crate rand;
extern crate snark;
extern crate crossbeam;
extern crate rustc_serialize;
extern crate blake2_rfc;
extern crate bincode;
mod protocol;
@ -35,7 +36,10 @@ fn main() {
let mut commitments = vec![];
let mut pubkeys = vec![];
for i in 0..num_players {
let comm: [u8; 32] = decode_from(&mut f, Infinite).unwrap();
let comm: PublicKeyHash = decode_from(&mut f, Infinite).unwrap();
if comm.len() != 64 {
panic!("Commitment length invalid.");
}
commitments.push(comm);
}