From 09167f9a150b8d145c7d5249026447dcfd867576 Mon Sep 17 00:00:00 2001 From: dishmaker <141624503+dishmaker@users.noreply.github.com> Date: Tue, 13 May 2025 13:02:18 +0200 Subject: [PATCH] apply nightly clippy fixes: const `div_ceil` (2025-05-12) --- slh-dsa/src/hashes/sha2.rs | 10 +++++----- slh-dsa/src/hashes/shake.rs | 10 +++++----- slh-dsa/src/util.rs | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/slh-dsa/src/hashes/sha2.rs b/slh-dsa/src/hashes/sha2.rs index 0f78f56f..d9959cde 100644 --- a/slh-dsa/src/hashes/sha2.rs +++ b/slh-dsa/src/hashes/sha2.rs @@ -166,7 +166,7 @@ impl HypertreeParams for Sha2_128s { impl ForsParams for Sha2_128s { type K = U<14>; type A = U<12>; - type MD = U<{ (12 * 14 + 7) / 8 }>; + type MD = U<{ (12 * 14usize).div_ceil(8) }>; } impl ParameterSet for Sha2_128s { const NAME: &'static str = "SLH-DSA-SHA2-128s"; @@ -329,7 +329,7 @@ impl HypertreeParams for Sha2_192s { impl ForsParams for Sha2_192s { type K = U<17>; type A = U<14>; - type MD = U<{ (14 * 17 + 7) / 8 }>; + type MD = U<{ (14 * 17usize).div_ceil(8) }>; } impl ParameterSet for Sha2_192s { const NAME: &'static str = "SLH-DSA-SHA2-192s"; @@ -352,7 +352,7 @@ impl HypertreeParams for Sha2_192f { impl ForsParams for Sha2_192f { type K = U<33>; type A = U<8>; - type MD = U<{ (33 * 8 + 7) / 8 }>; + type MD = U<{ (33 * 8usize).div_ceil(8) }>; } impl ParameterSet for Sha2_192f { const NAME: &'static str = "SLH-DSA-SHA2-192f"; @@ -375,7 +375,7 @@ impl HypertreeParams for Sha2_256s { impl ForsParams for Sha2_256s { type K = U<22>; type A = U<14>; - type MD = U<{ (14 * 22 + 7) / 8 }>; + type MD = U<{ (14 * 22usize).div_ceil(8) }>; } impl ParameterSet for Sha2_256s { const NAME: &'static str = "SLH-DSA-SHA2-256s"; @@ -398,7 +398,7 @@ impl HypertreeParams for Sha2_256f { impl ForsParams for Sha2_256f { type K = U<35>; type A = U<9>; - type MD = U<{ (35 * 9 + 7) / 8 }>; + type MD = U<{ (35 * 9usize).div_ceil(8) }>; } impl ParameterSet for Sha2_256f { const NAME: &'static str = "SLH-DSA-SHA2-256f"; diff --git a/slh-dsa/src/hashes/shake.rs b/slh-dsa/src/hashes/shake.rs index d5e79f68..0bc59657 100644 --- a/slh-dsa/src/hashes/shake.rs +++ b/slh-dsa/src/hashes/shake.rs @@ -143,7 +143,7 @@ impl HypertreeParams for Shake128s { impl ForsParams for Shake128s { type K = U<14>; type A = U<12>; - type MD = U<{ (12 * 14 + 7) / 8 }>; + type MD = U<{ (12 * 14usize).div_ceil(8) }>; } impl ParameterSet for Shake128s { const NAME: &'static str = "SLH-DSA-SHAKE-128s"; @@ -189,7 +189,7 @@ impl HypertreeParams for Shake192s { impl ForsParams for Shake192s { type K = U<17>; type A = U<14>; - type MD = U<{ (14 * 17 + 7) / 8 }>; + type MD = U<{ (14 * 17usize).div_ceil(8) }>; } impl ParameterSet for Shake192s { const NAME: &'static str = "SLH-DSA-SHAKE-192s"; @@ -212,7 +212,7 @@ impl HypertreeParams for Shake192f { impl ForsParams for Shake192f { type K = U<33>; type A = U<8>; - type MD = U<{ (33 * 8 + 7) / 8 }>; + type MD = U<{ (33 * 8usize).div_ceil(8) }>; } impl ParameterSet for Shake192f { const NAME: &'static str = "SLH-DSA-SHAKE-192f"; @@ -235,7 +235,7 @@ impl HypertreeParams for Shake256s { impl ForsParams for Shake256s { type K = U<22>; type A = U<14>; - type MD = U<{ (14 * 22 + 7) / 8 }>; + type MD = U<{ (14 * 22usize).div_ceil(8) }>; } impl ParameterSet for Shake256s { const NAME: &'static str = "SLH-DSA-SHAKE-256s"; @@ -258,7 +258,7 @@ impl HypertreeParams for Shake256f { impl ForsParams for Shake256f { type K = U<35>; type A = U<9>; - type MD = U<{ (35 * 9 + 7) / 8 }>; + type MD = U<{ (35 * 9usize).div_ceil(8) }>; } impl ParameterSet for Shake256f { const NAME: &'static str = "SLH-DSA-SHAKE-256f"; diff --git a/slh-dsa/src/util.rs b/slh-dsa/src/util.rs index 9b0a9c29..4956223c 100644 --- a/slh-dsa/src/util.rs +++ b/slh-dsa/src/util.rs @@ -3,7 +3,7 @@ use hybrid_array::{Array, ArraySize, typenum::Unsigned}; // Algorithm 3 pub fn base_2b(x: &[u8]) -> Array { - debug_assert!(x.len() >= (OutLen::USIZE * B::USIZE + 7) / 8); + debug_assert!(x.len() >= (OutLen::USIZE * B::USIZE).div_ceil(8)); debug_assert!(B::USIZE <= 16); let mut bits = 0usize;