Reuse hashers by hasher.finalize_reset which is slightly faster than constructing the hasher object each time.

This commit is contained in:
Kostas Chalkias
2021-02-04 17:00:17 -08:00
parent 099f887530
commit e32b240ce2
2 changed files with 12 additions and 15 deletions
+2 -3
View File
@@ -84,17 +84,16 @@ pub(crate) fn expand_message_xmd<H: Hash>(
h.update(&b[0]);
h.update(&i2osp(1, 1));
h.update(&dst_prime);
b.push(h.finalize().to_vec()); // b[1]
b.push(h.finalize_reset().to_vec()); // b[1]
let mut uniform_bytes: Vec<u8> = Vec::new();
uniform_bytes.extend_from_slice(&b[1]);
for i in 2..(ell + 1) {
let mut h = H::new();
h.update(xor(&b[0], &b[i - 1])?);
h.update(&i2osp(i, 1));
h.update(&dst_prime);
b.push(h.finalize().to_vec()); // b[i]
b.push(h.finalize_reset().to_vec()); // b[i]
uniform_bytes.extend_from_slice(&b[i]);
}