mirror of https://github.com/zcash/mpc.git
Add BLAKE2.
This commit is contained in:
parent
6e51712fce
commit
a66949d24a
|
@ -4,6 +4,7 @@ version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"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]]
|
[[package]]
|
||||||
name = "bn"
|
name = "bn"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
|
@ -52,6 +61,11 @@ name = "byteorder"
|
||||||
version = "0.5.3"
|
version = "0.5.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
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]]
|
[[package]]
|
||||||
name = "crossbeam"
|
name = "crossbeam"
|
||||||
version = "0.2.9"
|
version = "0.2.9"
|
||||||
|
|
|
@ -43,6 +43,7 @@ bn = "0.4.0"
|
||||||
crossbeam = "0.2.9"
|
crossbeam = "0.2.9"
|
||||||
rand = "0.3.14"
|
rand = "0.3.14"
|
||||||
rustc-serialize = "~0.3.19"
|
rustc-serialize = "~0.3.19"
|
||||||
|
blake2-rfc = "0.2.17"
|
||||||
log = "*"
|
log = "*"
|
||||||
env_logger = "*"
|
env_logger = "*"
|
||||||
time = "*"
|
time = "*"
|
||||||
|
|
|
@ -5,6 +5,7 @@ extern crate rand;
|
||||||
extern crate snark;
|
extern crate snark;
|
||||||
extern crate crossbeam;
|
extern crate crossbeam;
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
|
extern crate blake2_rfc;
|
||||||
extern crate bincode;
|
extern crate bincode;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -123,17 +124,22 @@ impl ConnectionHandler {
|
||||||
|
|
||||||
let mut peers = vec![];
|
let mut peers = vec![];
|
||||||
let mut pubkeys = 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) {
|
for peerid in new_peers.into_iter().take(PLAYERS) {
|
||||||
info!("Initializing new player (peerid={})", peerid.to_hex());
|
info!("Initializing new player (peerid={})", peerid.to_hex());
|
||||||
info!("Asking for commitment to PublicKey (peerid={})", peerid.to_hex());
|
info!("Asking for commitment to PublicKey (peerid={})", peerid.to_hex());
|
||||||
let comm = self.read(&peerid);
|
let comm: PublicKeyHash = self.read(&peerid);
|
||||||
commitments.push(comm);
|
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());
|
info!("PublicKey Commitment received (peerid={})", peerid.to_hex());
|
||||||
peers.push(peerid);
|
|
||||||
|
|
||||||
info!("Writing commitment to transcript");
|
info!("Writing commitment to transcript");
|
||||||
encode_into(&comm, &mut transcript, Infinite).unwrap();
|
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`.
|
// The remote end should never hang up, so this should always be `PLAYERS`.
|
||||||
|
|
|
@ -6,6 +6,7 @@ extern crate rand;
|
||||||
extern crate snark;
|
extern crate snark;
|
||||||
extern crate crossbeam;
|
extern crate crossbeam;
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
|
extern crate blake2_rfc;
|
||||||
extern crate bincode;
|
extern crate bincode;
|
||||||
|
|
||||||
mod protocol;
|
mod protocol;
|
||||||
|
|
|
@ -5,7 +5,7 @@ use super::spair::{Spair, same_power};
|
||||||
use snark::*;
|
use snark::*;
|
||||||
use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
|
use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
|
||||||
|
|
||||||
pub type PublicKeyHash = [u8; 32];
|
pub type PublicKeyHash = Vec<u8>;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq)]
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
pub struct PublicKey {
|
pub struct PublicKey {
|
||||||
|
@ -45,8 +45,13 @@ impl PublicKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hash(&self) -> PublicKeyHash {
|
pub fn hash(&self) -> PublicKeyHash {
|
||||||
// TODO
|
use bincode::SizeLimit::Infinite;
|
||||||
[0xff; 32]
|
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> {
|
pub fn tau_g2(&self) -> Spair<G2> {
|
||||||
|
|
|
@ -3,6 +3,8 @@ extern crate rand;
|
||||||
extern crate snark;
|
extern crate snark;
|
||||||
extern crate crossbeam;
|
extern crate crossbeam;
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
|
extern crate blake2_rfc;
|
||||||
|
extern crate bincode;
|
||||||
|
|
||||||
mod protocol;
|
mod protocol;
|
||||||
use protocol::*;
|
use protocol::*;
|
||||||
|
|
|
@ -3,6 +3,7 @@ extern crate rand;
|
||||||
extern crate snark;
|
extern crate snark;
|
||||||
extern crate crossbeam;
|
extern crate crossbeam;
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
|
extern crate blake2_rfc;
|
||||||
extern crate bincode;
|
extern crate bincode;
|
||||||
|
|
||||||
mod protocol;
|
mod protocol;
|
||||||
|
@ -35,7 +36,10 @@ fn main() {
|
||||||
let mut commitments = vec![];
|
let mut commitments = vec![];
|
||||||
let mut pubkeys = vec![];
|
let mut pubkeys = vec![];
|
||||||
for i in 0..num_players {
|
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);
|
commitments.push(comm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue