From 400e73db30c2e857416633b3991a86a82b45b6e3 Mon Sep 17 00:00:00 2001 From: nemynm <180121731+nemynm@users.noreply.github.com> Date: Thu, 10 Oct 2024 09:34:25 -0400 Subject: [PATCH] Add ANSI-X9.63-KDF support: adjust comments on hashmaxlen and remove unnecessary overflow check --- ansi-x963-kdf/src/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ansi-x963-kdf/src/lib.rs b/ansi-x963-kdf/src/lib.rs index c5dc67e..1a80357 100644 --- a/ansi-x963-kdf/src/lib.rs +++ b/ansi-x963-kdf/src/lib.rs @@ -69,17 +69,16 @@ where return Err(Error::NoOutput); } - // 1. Check if |Z| + |SharedInfo| + 4 >= hashmaxlen + // 1. Check that |Z| + |SharedInfo| + 4 < hashmaxlen + // where "hashmaxlen denote the maximum length in octets of messages that can be hashed using Hash". + // N.B.: `D::OutputSize::U64 * (u32::MAX as u64)`` is currently used as an approximation of hashmaxlen. if secret.len() as u64 + shared_info.len() as u64 + 4 >= D::OutputSize::U64 * (u32::MAX as u64) { return Err(Error::InputOverflow); } - // Counter overflow is possible only on architectures with usize bigger than 4 bytes. - const OVERFLOW_IS_POSSIBLE: bool = core::mem::size_of::() > 4; - // 2. Check that keydatalen < hashlen × (2^32 − 1) - if OVERFLOW_IS_POSSIBLE && (key.len() as u64 >= D::OutputSize::U64 * (u32::MAX as u64)) { + if key.len() as u64 >= D::OutputSize::U64 * (u32::MAX as u64) { return Err(Error::CounterOverflow); }