From f8f2e2c4f2b226709b14c68ed24a8e53b063b6be Mon Sep 17 00:00:00 2001 From: Jonas Bostoen Date: Fri, 6 Sep 2024 20:38:42 +0200 Subject: [PATCH] refactor: everything in `hash_chunks` --- ssz-rs/src/merkleization/hasher.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/ssz-rs/src/merkleization/hasher.rs b/ssz-rs/src/merkleization/hasher.rs index b2223825..46d465b3 100644 --- a/ssz-rs/src/merkleization/hasher.rs +++ b/ssz-rs/src/merkleization/hasher.rs @@ -11,18 +11,12 @@ static INIT: Once = Once::new(); #[inline] #[cfg(feature = "hashtree")] -pub fn hash_chunks_hashtree( - left: impl AsRef<[u8]>, - right: impl AsRef<[u8]>, -) -> [u8; BYTES_PER_CHUNK] { +fn hash_chunks_hashtree(left: impl AsRef<[u8]>, right: impl AsRef<[u8]>) -> [u8; BYTES_PER_CHUNK] { // Initialize the hashtree library (once) INIT.call_once(|| { hashtree::init(); }); - debug_assert!(left.as_ref().len() == BYTES_PER_CHUNK); - debug_assert!(right.as_ref().len() == BYTES_PER_CHUNK); - let mut out = [0u8; BYTES_PER_CHUNK]; let mut chunks = [0u8; 2 * BYTES_PER_CHUNK]; @@ -39,13 +33,7 @@ pub fn hash_chunks_hashtree( #[inline] #[cfg(not(feature = "hashtree"))] -pub fn hash_chunks_sha256( - left: impl AsRef<[u8]>, - right: impl AsRef<[u8]>, -) -> [u8; BYTES_PER_CHUNK] { - debug_assert!(left.as_ref().len() == BYTES_PER_CHUNK); - debug_assert!(right.as_ref().len() == BYTES_PER_CHUNK); - +fn hash_chunks_sha256(left: impl AsRef<[u8]>, right: impl AsRef<[u8]>) -> [u8; BYTES_PER_CHUNK] { let mut hasher = Sha256::new(); hasher.update(left.as_ref()); hasher.update(right.as_ref()); @@ -59,6 +47,9 @@ pub fn hash_chunks_sha256( /// - hashtree (with the "hashtree" feature flag) #[inline] pub fn hash_chunks(left: impl AsRef<[u8]>, right: impl AsRef<[u8]>) -> [u8; BYTES_PER_CHUNK] { + debug_assert!(left.as_ref().len() == BYTES_PER_CHUNK); + debug_assert!(right.as_ref().len() == BYTES_PER_CHUNK); + #[cfg(feature = "hashtree")] return hash_chunks_hashtree(left, right);