Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions blake2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## 0.11.1 (UNRELEASED)
### Fixed
- Zeroization with enabled `reset` crate feature ([#966])
- Panic in `new_with_salt_and_personal` on too long key, salt or persona ([#969])

[#966]: https://github.com/RustCrypto/hashes/pull/966
[#969]: https://github.com/RustCrypto/hashes/pull/969

## 0.11.0 (2026-08-26)
### Added
Expand Down
10 changes: 5 additions & 5 deletions blake2/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ macro_rules! blake2_mac_impl {
/// # Errors
///
/// If key is `Some`, then its length should not be zero or bigger
/// than the block size. The salt and persona length should not be
/// bigger than quarter of block size. If any of those conditions is
/// than the key size. The salt and persona length should not be
/// bigger than quarter of key size. If any of those conditions is
/// false the method will return an error.
#[inline]
pub fn new_with_salt_and_personal(
Expand All @@ -308,9 +308,9 @@ macro_rules! blake2_mac_impl {
persona: &[u8],
) -> Result<Self, InvalidLength> {
let kl = key.map_or(0, |k| k.len());
let bs = <$hash as BlockSizeUser>::BlockSize::USIZE;
let qbs = bs / 4;
if key.is_some() && kl == 0 || kl > bs || salt.len() > qbs || persona.len() > qbs {
let ks = <Self as KeySizeUser>::KeySize::USIZE;
let qks = ks / 4;
if key.is_some() && kl == 0 || kl > ks || salt.len() > qks || persona.len() > qks {
return Err(InvalidLength);
}
let buffer = if let Some(k) = key {
Expand Down
24 changes: 24 additions & 0 deletions blake2/tests/persona.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,27 @@ fn blake2b_mac_persona() {
),
);
}

#[test]
fn blake2b_mac_salt_personal_limits() {
let key = [1u8; 128];
// Maximum key size is 64 bytes, maximum salt and persona size is 16 bytes.
assert!(
Blake2bMac512::new_with_salt_and_personal(Some(&key[..64]), &[0; 16], &[0; 16]).is_ok()
);
assert!(Blake2bMac512::new_with_salt_and_personal(Some(&key[..65]), &[], &[]).is_err());
assert!(Blake2bMac512::new_with_salt_and_personal(Some(&key[..128]), &[], &[]).is_err());
assert!(Blake2bMac512::new_with_salt_and_personal(None, &[0; 17], &[]).is_err());
assert!(Blake2bMac512::new_with_salt_and_personal(None, &[], &[0; 32]).is_err());
}

#[test]
fn blake2s_mac_salt_personal_limits() {
let key = [1u8; 64];
// Maximum key size is 32 bytes, maximum salt and persona size is 8 bytes.
assert!(Blake2sMac256::new_with_salt_and_personal(Some(&key[..32]), &[0; 8], &[0; 8]).is_ok());
assert!(Blake2sMac256::new_with_salt_and_personal(Some(&key[..33]), &[], &[]).is_err());
assert!(Blake2sMac256::new_with_salt_and_personal(Some(&key[..64]), &[], &[]).is_err());
assert!(Blake2sMac256::new_with_salt_and_personal(None, &[0; 9], &[]).is_err());
assert!(Blake2sMac256::new_with_salt_and_personal(None, &[], &[0; 16]).is_err());
}
Loading