From 78d2f78e7861ea4465af3070acf1bb80ef836cec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Wed, 23 Apr 2025 09:50:26 +0400 Subject: [PATCH 1/2] skein: fix implementation for output sizes not multiple of 8 --- skein/Cargo.toml | 2 +- skein/src/lib.rs | 4 ++-- skein/tests/lib.rs | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/skein/Cargo.toml b/skein/Cargo.toml index 5f1d59871..5b0341b7c 100644 --- a/skein/Cargo.toml +++ b/skein/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "skein" -version = "0.1.0" +version = "0.1.1" description = "Skein hash functions" authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" diff --git a/skein/src/lib.rs b/skein/src/lib.rs index 6f6bcf76e..0d71ef2d4 100644 --- a/skein/src/lib.rs +++ b/skein/src/lib.rs @@ -156,8 +156,8 @@ macro_rules! define_hasher { block[..8].copy_from_slice(&(i as u64).to_le_bytes()); Self::process_block(&mut ctr, &block, 8); - for (src, dst) in ctr.x.iter().zip(chunk.chunks_exact_mut(8)) { - dst.copy_from_slice(&src.to_le_bytes()); + for (src, dst) in ctr.x.iter().zip(chunk.chunks_mut(8)) { + dst.copy_from_slice(&src.to_le_bytes()[..dst.len()]); } } } diff --git a/skein/tests/lib.rs b/skein/tests/lib.rs index 54360d763..4ddc9f98f 100644 --- a/skein/tests/lib.rs +++ b/skein/tests/lib.rs @@ -1,7 +1,8 @@ +use hex_literal::hex; use skein::{ - consts::{U128, U32, U64}, + consts::{U128, U32, U64, U7}, digest::{dev::fixed_test, new_test}, - Skein1024, Skein256, Skein512, + Digest, Skein1024, Skein256, Skein512, }; new_test!(skein256_32, "skein256_32", Skein256, fixed_test); @@ -11,3 +12,15 @@ new_test!(skein512_64, "skein512_64", Skein512, fixed_test); new_test!(skein1024_32, "skein1024_32", Skein1024, fixed_test); new_test!(skein1024_64, "skein1024_64", Skein1024, fixed_test); new_test!(skein1024_128, "skein1024_128", Skein1024, fixed_test); + +/// Regression tests for https://github.com/RustCrypto/hashes/issues/681 +#[test] +fn skein_uncommon_sizes() { + let s = "hello world"; + let h = Skein256::::digest(s); + assert_eq!(h[..], hex!("31bffb70f5dafe")[..]); + let h = Skein512::::digest(s); + assert_eq!(h[..], hex!("ee6004efedd69c")[..]); + let h = Skein1024::::digest(s); + assert_eq!(h[..], hex!("a2808b638681c6")[..]); +} From 034256c1f1d5adfc4744f27e85d3665863c55708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Wed, 23 Apr 2025 09:59:09 +0400 Subject: [PATCH 2/2] Update changelog --- skein/CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/skein/CHANGELOG.md b/skein/CHANGELOG.md index 54f3b9ef0..0dc2f44c0 100644 --- a/skein/CHANGELOG.md +++ b/skein/CHANGELOG.md @@ -5,7 +5,13 @@ 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.0 (2023-06-09) +## 0.1.1 (2025-04-23) +### Fixed +- Implementation for output sizes not multiple of 8 ([#682]) + +[#682]: https://github.com/RustCrypto/hashes/pull/682 + +## 0.1.0 (2023-06-09) [YANKED] - Initial release ([#483]) [#483]: https://github.com/RustCrypto/hashes/pull/483