diff --git a/beacon_chain/utils/bls/src/lib.rs b/beacon_chain/utils/bls/src/lib.rs index dcd2a9d29..0c69a9865 100644 --- a/beacon_chain/utils/bls/src/lib.rs +++ b/beacon_chain/utils/bls/src/lib.rs @@ -10,16 +10,16 @@ pub use self::bls_aggregates::Signature; pub const BLS_AGG_SIG_BYTE_SIZE: usize = 97; -use hashing::proof_of_possession_hash; +use hashing::canonical_hash; /// For some signature and public key, ensure that the signature message was the public key and it /// was signed by the secret key that corresponds to that public key. pub fn verify_proof_of_possession(sig: &Signature, pubkey: &PublicKey) -> bool { - let hash = proof_of_possession_hash(&pubkey.as_bytes()); + let hash = canonical_hash(&pubkey.as_bytes()); sig.verify_hashed(&hash, &pubkey) } pub fn create_proof_of_possession(keypair: &Keypair) -> Signature { - let hash = proof_of_possession_hash(&keypair.pk.as_bytes()); + let hash = canonical_hash(&keypair.pk.as_bytes()); Signature::new_hashed(&hash, &keypair.sk) } diff --git a/beacon_chain/utils/hashing/Cargo.toml b/beacon_chain/utils/hashing/Cargo.toml index 36cbc41ef..8bed7adaf 100644 --- a/beacon_chain/utils/hashing/Cargo.toml +++ b/beacon_chain/utils/hashing/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" authors = ["Paul Hauner "] [dependencies] -blake2-rfc = "0.2.18" +tiny-keccak = "1.4.2" \ No newline at end of file diff --git a/beacon_chain/utils/hashing/src/lib.rs b/beacon_chain/utils/hashing/src/lib.rs index 7c349e39d..40dddb7a5 100644 --- a/beacon_chain/utils/hashing/src/lib.rs +++ b/beacon_chain/utils/hashing/src/lib.rs @@ -1,17 +1,11 @@ -extern crate blake2_rfc; +extern crate tiny_keccak; -use self::blake2_rfc::blake2b::blake2b; +use tiny_keccak::Keccak; pub fn canonical_hash(input: &[u8]) -> Vec { - let result = blake2b(64, &[], input); - result.as_bytes()[0..32].to_vec() -} - -pub fn proof_of_possession_hash(input: &[u8]) -> Vec { - let result = blake2b(64, &[], input); - let mut hash = result.as_bytes()[32..64].to_vec(); - // TODO: this padding is not part of the spec, it is required otherwise Milagro will panic. - // We should either drop the padding or ensure the padding is in the spec. - hash.append(&mut vec![0; 18]); - hash + let mut keccak = Keccak::new_keccak256(); + keccak.update(input); + let mut result = Vec::with_capacity(32); + keccak.finalize(result.as_mut_slice()); + result }