Skip to content

Commit

Permalink
Use hybrid_array::slice_as_chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Nov 12, 2023
1 parent a92cf0d commit a61ac8f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 73 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 0 additions & 49 deletions universal-hash/Cargo.lock

This file was deleted.

2 changes: 1 addition & 1 deletion universal-hash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "Traits which describe the functionality of universal hash functio
authors = ["RustCrypto Developers"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.56"
rust-version = "1.65"
readme = "README.md"
documentation = "https://docs.rs/universal-hash"
repository = "https://github.com/RustCrypto/traits"
Expand Down
4 changes: 2 additions & 2 deletions universal-hash/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
20 changes: 3 additions & 17 deletions universal-hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,7 +94,7 @@ pub trait UniversalHash: BlockSizeUser + Sized {
fn call<B: UhfBackend<BlockSize = BS>>(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);
}
Expand All @@ -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);

Expand Down Expand Up @@ -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<T, N: ArraySize>(data: &[T]) -> (&[Array<T, N>], &[T]) {
let nb = data.len() / N::USIZE;
let (left, right) = data.split_at(nb * N::USIZE);
let p = left.as_ptr() as *const Array<T, N>;
// 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)
}

0 comments on commit a61ac8f

Please sign in to comment.