From d13b4db9a7b19001ecb69b13567a225e7f6f1b94 Mon Sep 17 00:00:00 2001 From: Alexander Wagner Date: Sun, 8 Sep 2024 12:01:34 +0200 Subject: [PATCH] hss/aux: Fix aux_data is empty cmp --- src/hss/aux.rs | 2 +- src/hss/mod.rs | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/hss/aux.rs b/src/hss/aux.rs index 81e83a42..424c4633 100644 --- a/src/hss/aux.rs +++ b/src/hss/aux.rs @@ -205,7 +205,7 @@ pub fn hss_extract_aux_data( let start_index = lms_leaf_identifier as usize * hash_size; let end_index = start_index + hash_size; - if src[start_index..end_index] == [0u8; MAX_HASH_SIZE] { + if src[start_index..end_index].iter().all(|&b| b == 0u8) { return None; } diff --git a/src/hss/mod.rs b/src/hss/mod.rs index cd7db949..8f3664da 100644 --- a/src/hss/mod.rs +++ b/src/hss/mod.rs @@ -471,35 +471,41 @@ mod tests { #[test] fn test_signing_sha256_128() { - test_signing_core::(); + test_signing_core_sha_x::(); } #[test] fn test_signing_sha256_192() { - test_signing_core::(); + test_signing_core_sha_x::(); } #[test] fn test_signing_sha256_256() { - test_signing_core::(); + test_signing_core_sha_x::(); } #[test] fn test_signing_shake256_128() { - test_signing_core::(); + test_signing_core_sha_x::(); } #[test] fn test_signing_shake256_192() { - test_signing_core::(); + test_signing_core_sha_x::(); } #[test] fn test_signing_shake256_256() { - test_signing_core::(); + test_signing_core_sha_x::(); } - fn test_signing_core() { + fn test_signing_core_sha_x() { + test_signing_core::(&mut None); + let mut aux_data = [0u8; 1_000]; + test_signing_core::(&mut Some(&mut aux_data)); + } + + fn test_signing_core(aux_data: &mut Option<&mut [u8]>) { let seed = gen_random_seed::(); let (mut signing_key, verifying_key) = hss_keygen::( &[ @@ -508,7 +514,7 @@ mod tests { HssParameter::construct_default_parameters(), ], &seed, - None, + aux_data.as_mut(), ) .expect("Should generate HSS keys"); @@ -529,7 +535,7 @@ mod tests { &message, signing_key_const.as_slice(), &mut update_private_key, - None, + aux_data.as_mut(), ) .expect("Signing should complete without error.");