hashx: Simplify hash_to_bytes, only support fixed output width
In response to review feedback. The byte output is only needed for unit tests right now, since Equi-X uses u64 output exclusively. The optimization for shorter output widths can shave tiny amounts of time off hash benchmarks, but in this case it's more helpful to avoid introducing APIs that offer parameters with incomplete compile-time range checking. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
This commit is contained in:
parent
d17c12b152
commit
10b7352c98
|
@ -25,7 +25,7 @@ fn bench_one_runtime(c: &mut Criterion, runtime: RuntimeOption, name: &str) {
|
|||
c,
|
||||
runtime,
|
||||
&format!("{}-full-hash", name),
|
||||
|hash_instance, input| hash_instance.hash_to_bytes::<{ HashX::FULL_SIZE }>(input),
|
||||
|hash_instance, input| hash_instance.hash_to_bytes(input),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -144,11 +144,11 @@ impl HashX {
|
|||
self.hash_to_regs(input).digest(self.register_key)[0]
|
||||
}
|
||||
|
||||
/// Calculate the hash function, and return it as a byte array in HashX's
|
||||
/// canonical little-endian byte order
|
||||
pub fn hash_to_bytes<const SIZE: usize>(&self, input: u64) -> [u8; SIZE] {
|
||||
/// Calculate the hash function at its full output width, returning a fixed
|
||||
/// size byte array
|
||||
pub fn hash_to_bytes(&self, input: u64) -> [u8; Self::FULL_SIZE] {
|
||||
let words = self.hash_to_regs(input).digest(self.register_key);
|
||||
let mut bytes = [0_u8; SIZE];
|
||||
let mut bytes = [0_u8; Self::FULL_SIZE];
|
||||
for word in 0..words.len() {
|
||||
bytes[word * 8..(word + 1) * 8].copy_from_slice(&words[word].to_le_bytes());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue