Skip to content

Commit 3f73764

Browse files
tarcierinewpavlov
authored andcommitted
universal-hash: Split KeySize/OutputSize (RustCrypto#55)
1 parent 49ff722 commit 3f73764

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

universal-hash/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## 0.2.0 (2019-08-31)
8+
### Changed
9+
- Split KeySize/OutputSize ([#55])
10+
11+
[#55]: https://github.com/RustCrypto/traits/pull/55
12+
713
## 0.1.0 (2019-08-30)
814

915
- Initial release

universal-hash/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "universal-hash"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
authors = ["RustCrypto Developers"]
55
license = "MIT OR Apache-2.0"
66
description = "Trait for universal hash functions"

universal-hash/src/lib.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ use subtle::{Choice, ConstantTimeEq};
2929
/// The `UniversalHash` trait defines a generic interface for universal hash
3030
/// functions.
3131
pub trait UniversalHash: Clone {
32-
/// Size of a block (e.g. field element) this universal hash operates on
33-
type BlockSize: ArrayLength<u8>;
32+
/// Size of the key for the universal hash function
33+
type KeySize: ArrayLength<u8>;
34+
/// Size of the output from the universal hash function
35+
type OutputSize: ArrayLength<u8>;
3436

3537
/// Instantiate a universal hash function with the given key
36-
fn new(key: &GenericArray<u8, Self::BlockSize>) -> Self;
38+
fn new(key: &GenericArray<u8, Self::KeySize>) -> Self;
3739

3840
/// Input a block into the universal hash function
39-
fn update_block(&mut self, block: &GenericArray<u8, Self::BlockSize>);
41+
fn update_block(&mut self, block: &GenericArray<u8, Self::OutputSize>);
4042

4143
/// Input data into the universal hash function. If the length of the
4244
/// data is not a multiple of the block size, the remaining data is
@@ -45,7 +47,7 @@ pub trait UniversalHash: Clone {
4547
/// This approach is frequently used by AEAD modes which use
4648
/// Message Authentication Codes (MACs) based on universal hashing.
4749
fn update_padded(&mut self, data: &[u8]) {
48-
let mut chunks = data.chunks_exact(Self::BlockSize::to_usize());
50+
let mut chunks = data.chunks_exact(Self::OutputSize::to_usize());
4951

5052
for chunk in &mut chunks {
5153
self.update_block(GenericArray::from_slice(chunk));
@@ -64,11 +66,11 @@ pub trait UniversalHash: Clone {
6466
fn reset(&mut self);
6567

6668
/// Obtain the [`Output`] of a `UniversalHash` function and consume it.
67-
fn result(self) -> Output<Self::BlockSize>;
69+
fn result(self) -> Output<Self::OutputSize>;
6870

6971
/// Obtain the [`Output`] of a `UniversalHash` computation and reset it back
7072
/// to its initial state.
71-
fn result_reset(&mut self) -> Output<Self::BlockSize> {
73+
fn result_reset(&mut self) -> Output<Self::OutputSize> {
7274
let res = self.clone().result();
7375
self.reset();
7476
res
@@ -77,7 +79,7 @@ pub trait UniversalHash: Clone {
7779
/// Verify the `UniversalHash` of the processed input matches a given [`Output`].
7880
/// This is useful when constructing Message Authentication Codes (MACs)
7981
/// from universal hash functions.
80-
fn verify(self, other: &GenericArray<u8, Self::BlockSize>) -> Result<(), Error> {
82+
fn verify(self, other: &GenericArray<u8, Self::OutputSize>) -> Result<(), Error> {
8183
if self.result() == other.into() {
8284
Ok(())
8385
} else {

0 commit comments

Comments
 (0)