From e560b60facda7c903062c3efc7014aaabd1595f0 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?= Date: Sun, 9 Jan 2022 05:53:25 +0300 Subject: [PATCH 1/4] blake2: fix KeySize value --- blake2/src/macros.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blake2/src/macros.rs b/blake2/src/macros.rs index ef3e0299..9b048d29 100644 --- a/blake2/src/macros.rs +++ b/blake2/src/macros.rs @@ -309,7 +309,7 @@ macro_rules! blake2_mac_impl { OutSize: ArrayLength + IsLessOrEqual<$max_size>, LeEq: NonZero, { - type KeySize = <$hash as BlockSizeUser>::BlockSize; + type KeySize = $max_size; } impl KeyInit for $name From a3d04d656769f5d3a20a0676cbacceb6ceb79d76 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?= Date: Sun, 9 Jan 2022 05:57:35 +0300 Subject: [PATCH 2/4] bump version to v0.10.2 and update changelog --- Cargo.lock | 2 +- blake2/CHANGELOG.md | 8 ++++++++ blake2/Cargo.toml | 4 ++-- blake2/src/lib.rs | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d15f22c8..a447f4c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "blake2" -version = "0.10.1" +version = "0.10.2" dependencies = [ "digest", "hex-literal", diff --git a/blake2/CHANGELOG.md b/blake2/CHANGELOG.md index 4276105f..abd63a81 100644 --- a/blake2/CHANGELOG.md +++ b/blake2/CHANGELOG.md @@ -5,6 +5,14 @@ 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.10.2 (2022-01-09) +## Fixed +- Rare compilation error by adding `'static` bound on `OutSize`. ([#347]) +- Values of `KeySize` associated type. ([#349]) + +[#347]: https://github.com/RustCrypto/hashes/pull/347 +[#349]: https://github.com/RustCrypto/hashes/pull/349 + ## 0.10.1 (2022-01-05) ## Fixed - Compilation error with enabled `reset` feature. ([#342]) diff --git a/blake2/Cargo.toml b/blake2/Cargo.toml index 99d58944..a49b7a54 100644 --- a/blake2/Cargo.toml +++ b/blake2/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "blake2" # Also update html_root_url in lib.rs when bumping this -version = "0.10.1" # Also update html_root_url in lib.rs when bumping this +name = "blake2" +version = "0.10.2" # Also update html_root_url in lib.rs when bumping this description = "BLAKE2 hash functions" authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" diff --git a/blake2/src/lib.rs b/blake2/src/lib.rs index 8a28109b..e92bc5ce 100644 --- a/blake2/src/lib.rs +++ b/blake2/src/lib.rs @@ -72,7 +72,7 @@ #![doc( html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg", html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg", - html_root_url = "https://docs.rs/blake2/0.10.1" + html_root_url = "https://docs.rs/blake2/0.10.2" )] #![warn(missing_docs, rust_2018_idioms)] #![cfg_attr(feature = "simd", feature(platform_intrinsics, repr_simd))] From e9c8bc2714892d2565bd8c13bc2263e76b6c96d5 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?= Date: Sun, 9 Jan 2022 06:18:17 +0300 Subject: [PATCH 3/4] fix reset --- blake2/src/macros.rs | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/blake2/src/macros.rs b/blake2/src/macros.rs index 9b048d29..34b04c95 100644 --- a/blake2/src/macros.rs +++ b/blake2/src/macros.rs @@ -265,7 +265,7 @@ macro_rules! blake2_mac_impl { core: $hash, buffer: LazyBuffer<<$hash as BlockSizeUser>::BlockSize>, #[cfg(feature = "reset")] - key_block: Block<$hash>, + key_block: Key, _out: PhantomData, } @@ -291,14 +291,17 @@ macro_rules! blake2_mac_impl { if kl > bs || salt.len() > qbs || persona.len() > qbs { return Err(InvalidLength); } - let mut key_block = Block::<$hash>::default(); - key_block[..kl].copy_from_slice(key); - let buffer = LazyBuffer::new(&key_block); + let mut padded_key = Block::<$hash>::default(); + padded_key[..kl].copy_from_slice(key); Ok(Self { core: <$hash>::new_with_params(salt, persona, key.len(), OutSize::USIZE), - buffer, + buffer: LazyBuffer::new(&padded_key), #[cfg(feature = "reset")] - key_block, + key_block: { + let mut t = Key::::default(); + t[..kl].copy_from_slice(key); + t + }, _out: PhantomData, }) } @@ -318,9 +321,12 @@ macro_rules! blake2_mac_impl { LeEq: NonZero, { fn new(key: &Key) -> Self { + let kl = key.len(); + let mut padded_key = Block::<$hash>::default(); + padded_key[..kl].copy_from_slice(key); Self { core: <$hash>::new_with_params(key, &[], key.len(), OutSize::USIZE), - buffer: LazyBuffer::new(key), + buffer: LazyBuffer::new(&padded_key), #[cfg(feature = "reset")] key_block: key.clone(), _out: PhantomData, @@ -329,16 +335,20 @@ macro_rules! blake2_mac_impl { fn new_from_slice(key: &[u8]) -> Result { let kl = key.len(); - if kl > <$hash as BlockSizeUser>::BlockSize::USIZE { + if kl > ::KeySize::USIZE { return Err(InvalidLength); } - let mut key_block = Block::<$hash>::default(); - key_block[..kl].copy_from_slice(key); + let mut padded_key = Block::<$hash>::default(); + padded_key[..kl].copy_from_slice(key); Ok(Self { core: <$hash>::new_with_params(&[], &[], key.len(), OutSize::USIZE), - buffer: LazyBuffer::new(&key_block), + buffer: LazyBuffer::new(&padded_key), #[cfg(feature = "reset")] - key_block, + key_block: { + let mut t = Key::::default(); + t[..kl].copy_from_slice(key); + t + }, _out: PhantomData, }) } @@ -386,7 +396,10 @@ macro_rules! blake2_mac_impl { { fn reset(&mut self) { self.core.reset(); - self.buffer = LazyBuffer::new(&self.key_block); + let kl = self.key_block.len(); + let mut padded_key = Block::<$hash>::default(); + padded_key[..kl].copy_from_slice(&self.key_block); + self.buffer = LazyBuffer::new(&padded_key); } } @@ -401,14 +414,12 @@ macro_rules! blake2_mac_impl { let Self { core, buffer, - key_block, .. } = self; let mut full_res = Default::default(); core.finalize_variable_core(buffer, &mut full_res); out.copy_from_slice(&full_res[..OutSize::USIZE]); - core.reset(); - *buffer = LazyBuffer::new(key_block); + self.reset(); } } From 36e27c361916beb453533ceeea1c5c88a43d4992 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?= Date: Sun, 9 Jan 2022 06:21:47 +0300 Subject: [PATCH 4/4] fmt --- blake2/src/macros.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/blake2/src/macros.rs b/blake2/src/macros.rs index 34b04c95..3c1301c5 100644 --- a/blake2/src/macros.rs +++ b/blake2/src/macros.rs @@ -411,11 +411,7 @@ macro_rules! blake2_mac_impl { { #[inline] fn finalize_into_reset(&mut self, out: &mut Output) { - let Self { - core, - buffer, - .. - } = self; + let Self { core, buffer, .. } = self; let mut full_res = Default::default(); core.finalize_variable_core(buffer, &mut full_res); out.copy_from_slice(&full_res[..OutSize::USIZE]);