Skip to content

Commit 3a497b1

Browse files
authored
bash-hash: fix finalization for non-multiple-of-8 output sizes (#964)
The bug was introduced in #746.
1 parent c930667 commit 3a497b1

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎bash-hash/CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 0.1.2 (UNRELEASED)
9+
### Fixed
10+
- Implementation for non-multiple-of-8 output sizes ([#964])
11+
12+
[#964]: https://github.com/RustCrypto/hashes/pull/964
13+
814
## 0.1.1 (2026-06-24)
915
### Fixed
1016
- Package metadata and README links ([#886])

‎bash-hash/src/block_api.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ impl<OS: OutputSize> FixedOutputCore for BashHashCore<OS> {
8181

8282
// 5. Y ← S[...2ℓ)
8383
// TODO: use `as_chunks` after MSRV is bumped to 1.88+
84-
for (src, dst) in self.state.iter().zip(out.chunks_exact_mut(8)) {
85-
dst.copy_from_slice(&src.to_le_bytes());
84+
for (src, dst) in self.state.iter().zip(out.chunks_mut(8)) {
85+
let n = dst.len();
86+
dst.copy_from_slice(&src.to_le_bytes()[..n]);
8687
}
8788
}
8889
}

‎bash-hash/tests/mod.rs‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use bash_hash::{BashHash256, BashHash384, BashHash512};
2-
use digest::Digest;
1+
use bash_hash::{BashHash, BashHash256, BashHash384, BashHash512};
32
use digest::dev::fixed_reset_test;
3+
use digest::{Digest, consts};
44
use hex_literal::hex;
55

66
// Test vectors from STB 34.101.77-2020 (Appendix A, Table A.3)
@@ -46,3 +46,25 @@ test_bash_rand!(
4646
digest::hash_serialization_test!(bash256_serialization, BashHash256);
4747
digest::hash_serialization_test!(bash384_serialization, BashHash384);
4848
digest::hash_serialization_test!(bash512_serialization, BashHash512);
49+
50+
#[test]
51+
fn bash_hash_small_sizes() {
52+
let data = b"hello world";
53+
assert_eq!(BashHash::<consts::U4>::digest(data), hex!("227ecff0"));
54+
assert_eq!(
55+
BashHash::<consts::U8>::digest(data),
56+
hex!("630403a5b20b6ff3"),
57+
);
58+
assert_eq!(
59+
BashHash::<consts::U12>::digest(data),
60+
hex!("cd4ef716cfadbc01e91311bf"),
61+
);
62+
assert_eq!(
63+
BashHash::<consts::U16>::digest(data),
64+
hex!("38e027a61df909cfca638ca72e1d9f30"),
65+
);
66+
assert_eq!(
67+
BashHash::<consts::U20>::digest(data),
68+
hex!("9f5d4eb2d230684074ee9597ae98d1d7694b9452"),
69+
);
70+
}

0 commit comments

Comments
 (0)