From 04e3178ed3e9fd29f98a7a3910c5ae83ad79ea88 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sat, 11 Nov 2023 21:18:42 -0700 Subject: [PATCH] Use hybrid_array::slice_as_chunks --- Cargo.lock | 8 ++++---- universal-hash/README.md | 4 ++-- universal-hash/src/lib.rs | 20 +++----------------- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a5d218d74..d7307ab0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -111,7 +111,7 @@ dependencies = [ [[package]] name = "block-buffer" version = "0.11.0-pre" -source = "git+https://github.com/RustCrypto/utils.git#b755f1a29b074d8b0a6fc5fda5744312a11632c7" +source = "git+https://github.com/RustCrypto/utils.git#708aa72b9ebde06a02e862368e890fb3ddcb2fb9" dependencies = [ "crypto-common 0.2.0-pre", ] @@ -128,7 +128,7 @@ dependencies = [ [[package]] name = "block-padding" version = "0.4.0-pre" -source = "git+https://github.com/RustCrypto/utils.git#b755f1a29b074d8b0a6fc5fda5744312a11632c7" +source = "git+https://github.com/RustCrypto/utils.git#708aa72b9ebde06a02e862368e890fb3ddcb2fb9" dependencies = [ "hybrid-array", ] @@ -640,7 +640,7 @@ dependencies = [ [[package]] name = "hybrid-array" version = "0.2.0-pre.5" -source = "git+https://github.com/RustCrypto/utils.git#b755f1a29b074d8b0a6fc5fda5744312a11632c7" +source = "git+https://github.com/RustCrypto/utils.git#708aa72b9ebde06a02e862368e890fb3ddcb2fb9" dependencies = [ "typenum", ] @@ -658,7 +658,7 @@ dependencies = [ [[package]] name = "inout" version = "0.2.0-pre" -source = "git+https://github.com/RustCrypto/utils.git#b755f1a29b074d8b0a6fc5fda5744312a11632c7" +source = "git+https://github.com/RustCrypto/utils.git#708aa72b9ebde06a02e862368e890fb3ddcb2fb9" dependencies = [ "block-padding 0.4.0-pre", "hybrid-array", diff --git a/universal-hash/README.md b/universal-hash/README.md index 9fd55a0cf..3bc9d0977 100644 --- a/universal-hash/README.md +++ b/universal-hash/README.md @@ -15,7 +15,7 @@ See [RustCrypto/universal-hashes] for implementations which use this trait. ## Minimum Supported Rust Version -Rust **1.56** or higher. +Rust **1.65** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -47,7 +47,7 @@ dual licensed as above, without any additional terms or conditions. [docs-image]: https://docs.rs/universal-hash/badge.svg [docs-link]: https://docs.rs/universal-hash/ [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.56+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260051-universal-hashes [build-image]: https://github.com/RustCrypto/traits/workflows/universal-hash/badge.svg?branch=master&event=push diff --git a/universal-hash/src/lib.rs b/universal-hash/src/lib.rs index 5d34bbe42..b36c3b94c 100644 --- a/universal-hash/src/lib.rs +++ b/universal-hash/src/lib.rs @@ -37,7 +37,7 @@ pub use crypto_common::{ use core::slice; use crypto_common::{ - array::{Array, ArraySize}, + array::{slice_as_chunks, Array}, BlockSizeUser, BlockSizes, ParBlocksSizeUser, }; use subtle::ConstantTimeEq; @@ -94,7 +94,7 @@ pub trait UniversalHash: BlockSizeUser + Sized { fn call>(self, backend: &mut B) { let pb = B::ParBlocksSize::USIZE; if pb > 1 { - let (par_blocks, tail) = to_blocks(self.blocks); + let (par_blocks, tail) = slice_as_chunks(self.blocks); for par_block in par_blocks { backend.proc_par_blocks(par_block); } @@ -120,7 +120,7 @@ pub trait UniversalHash: BlockSizeUser + Sized { /// Message Authentication Codes (MACs) based on universal hashing. #[inline] fn update_padded(&mut self, data: &[u8]) { - let (blocks, tail) = to_blocks(data); + let (blocks, tail) = slice_as_chunks(data); self.update(blocks); @@ -175,17 +175,3 @@ impl core::fmt::Display for Error { #[cfg(feature = "std")] impl std::error::Error for Error {} - -/// Split message into slice of blocks and leftover tail. -// TODO: replace with `slice::as_chunks` on migration to const generics -#[inline(always)] -fn to_blocks(data: &[T]) -> (&[Array], &[T]) { - let nb = data.len() / N::USIZE; - let (left, right) = data.split_at(nb * N::USIZE); - let p = left.as_ptr() as *const Array; - // SAFETY: we guarantee that `blocks` does not point outside of `data` - // and `p` is valid for reads - #[allow(unsafe_code)] - let blocks = unsafe { slice::from_raw_parts(p, nb) }; - (blocks, right) -}