Updates the hash function used to Keccak-256
This commit is contained in:
parent
7808835f1c
commit
97bd323a52
@ -10,16 +10,16 @@ pub use self::bls_aggregates::Signature;
|
|||||||
|
|
||||||
pub const BLS_AGG_SIG_BYTE_SIZE: usize = 97;
|
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
|
/// 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.
|
/// was signed by the secret key that corresponds to that public key.
|
||||||
pub fn verify_proof_of_possession(sig: &Signature, pubkey: &PublicKey) -> bool {
|
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)
|
sig.verify_hashed(&hash, &pubkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_proof_of_possession(keypair: &Keypair) -> Signature {
|
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)
|
Signature::new_hashed(&hash, &keypair.sk)
|
||||||
}
|
}
|
||||||
|
@ -4,4 +4,4 @@ version = "0.1.0"
|
|||||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
blake2-rfc = "0.2.18"
|
tiny-keccak = "1.4.2"
|
@ -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<u8> {
|
pub fn canonical_hash(input: &[u8]) -> Vec<u8> {
|
||||||
let result = blake2b(64, &[], input);
|
let mut keccak = Keccak::new_keccak256();
|
||||||
result.as_bytes()[0..32].to_vec()
|
keccak.update(input);
|
||||||
}
|
let mut result = Vec::with_capacity(32);
|
||||||
|
keccak.finalize(result.as_mut_slice());
|
||||||
pub fn proof_of_possession_hash(input: &[u8]) -> Vec<u8> {
|
result
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user