Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed Sep 22, 2023
1 parent c23de7f commit 064f56d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions base_layer/core/src/consensus/consensus_encoding/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ mod tests {

#[test]
fn it_hashes_using_the_domain_hasher() {
let mut hasher = Blake2b::<U64>::default();
let mut hasher = Blake2b::<U32>::default();
TestHashDomain::add_domain_separation_tag(&mut hasher, "foo");

let expected_hash = hasher.chain_update(b"\xff\x00\x00\x00\x00\x00\x00\x00").finalize();
Expand All @@ -162,7 +162,7 @@ mod tests {
fn it_adds_to_hash_challenge_in_complete_chunks() {
// Script is chosen because the consensus encoding impl for TariScript has 2 writes
let test_subject = script!(Nop);
let mut hasher = Blake2b::<U64>::default();
let mut hasher = Blake2b::<U32>::default();
TestHashDomain::add_domain_separation_tag(&mut hasher, "foo");

let expected_hash = hasher.chain_update(b"\x01\x73").finalize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

use blake2::Blake2b;
use borsh::{BorshDeserialize, BorshSerialize};
use digest::consts::U32;
use digest::consts::U64;
use rand::rngs::OsRng;
use serde::{Deserialize, Serialize};
use tari_common_types::types::{FixedHash, PrivateKey, PublicKey, Signature};
use tari_common_types::types::{PrivateKey, PublicKey, Signature};
use tari_crypto::{hash_domain, hashing::DomainSeparatedHasher, keys::PublicKey as PublicKeyT};
use tari_utilities::ByteArray;

Expand All @@ -50,13 +50,13 @@ impl ValidatorNodeSignature {
let (secret_nonce, public_nonce) = PublicKey::random_keypair(&mut OsRng);
let public_key = PublicKey::from_secret_key(private_key);
let challenge = Self::construct_challenge(&public_key, &public_nonce, msg);
let signature = Signature::sign_raw(private_key, secret_nonce, &*challenge)
.expect("Sign cannot fail with 32-byte challenge and a RistrettoPublicKey");
let signature = Signature::sign_raw(private_key, secret_nonce, &challenge)
.expect("Sign cannot fail with 64-byte challenge and a RistrettoPublicKey");
Self { public_key, signature }
}

fn construct_challenge(public_key: &PublicKey, public_nonce: &PublicKey, msg: &[u8]) -> FixedHash {
let hasher = DomainSeparatedHasher::<Blake2b<U32>, ValidatorNodeHashDomain>::new_with_label("registration")
fn construct_challenge(public_key: &PublicKey, public_nonce: &PublicKey, msg: &[u8]) -> [u8; 64] {
let hasher = DomainSeparatedHasher::<Blake2b<U64>, ValidatorNodeHashDomain>::new_with_label("registration")
.chain(public_key.as_bytes())
.chain(public_nonce.as_bytes())
.chain(msg);
Expand All @@ -65,7 +65,7 @@ impl ValidatorNodeSignature {

pub fn is_valid_signature_for(&self, msg: &[u8]) -> bool {
let challenge = Self::construct_challenge(&self.public_key, self.signature.get_public_nonce(), msg);
self.signature.verify_challenge(&self.public_key, &*challenge)
self.signature.verify_challenge(&self.public_key, &challenge)
}

pub fn public_key(&self) -> &PublicKey {
Expand Down

0 comments on commit 064f56d

Please sign in to comment.