Skip to content

Commit

Permalink
Add ANSI-X9.63-KDF support: adjust comments on hashmaxlen and remove …
Browse files Browse the repository at this point in the history
…unnecessary overflow check
  • Loading branch information
nemynm committed Oct 10, 2024
1 parent 5052040 commit 400e73d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions ansi-x963-kdf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<usize>() > 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);
}

Expand Down

0 comments on commit 400e73d

Please sign in to comment.