Skip to content
Merged
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
6 changes: 6 additions & 0 deletions bash-hash/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.1.2 (UNRELEASED)
### Fixed
- Implementation for non-multiple-of-8 output sizes ([#964])

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

## 0.1.1 (2026-06-24)
### Fixed
- Package metadata and README links ([#886])
Expand Down
5 changes: 3 additions & 2 deletions bash-hash/src/block_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ impl<OS: OutputSize> FixedOutputCore for BashHashCore<OS> {

// 5. Y ← S[...2ℓ)
// TODO: use `as_chunks` after MSRV is bumped to 1.88+
for (src, dst) in self.state.iter().zip(out.chunks_exact_mut(8)) {
dst.copy_from_slice(&src.to_le_bytes());
for (src, dst) in self.state.iter().zip(out.chunks_mut(8)) {
let n = dst.len();
dst.copy_from_slice(&src.to_le_bytes()[..n]);
}
}
}
Expand Down
26 changes: 24 additions & 2 deletions bash-hash/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bash_hash::{BashHash256, BashHash384, BashHash512};
use digest::Digest;
use bash_hash::{BashHash, BashHash256, BashHash384, BashHash512};
use digest::dev::fixed_reset_test;
use digest::{Digest, consts};
use hex_literal::hex;

// Test vectors from STB 34.101.77-2020 (Appendix A, Table A.3)
Expand Down Expand Up @@ -46,3 +46,25 @@ test_bash_rand!(
digest::hash_serialization_test!(bash256_serialization, BashHash256);
digest::hash_serialization_test!(bash384_serialization, BashHash384);
digest::hash_serialization_test!(bash512_serialization, BashHash512);

#[test]
fn bash_hash_small_sizes() {
let data = b"hello world";
assert_eq!(BashHash::<consts::U4>::digest(data), hex!("227ecff0"));
assert_eq!(
BashHash::<consts::U8>::digest(data),
hex!("630403a5b20b6ff3"),
);
assert_eq!(
BashHash::<consts::U12>::digest(data),
hex!("cd4ef716cfadbc01e91311bf"),
);
assert_eq!(
BashHash::<consts::U16>::digest(data),
hex!("38e027a61df909cfca638ca72e1d9f30"),
);
assert_eq!(
BashHash::<consts::U20>::digest(data),
hex!("9f5d4eb2d230684074ee9597ae98d1d7694b9452"),
);
}