Skip to content

Commit 0e62d32

Browse files
committed
Upgrade to universal-hash v0.4.0-pre
- (Vicariously) bumps `generic-array` to v0.14 - Splits out `NewUniversalHash` from `UniversalHash` - Uses `GenericArray` type aliases - Renames `update_block` to `update` - Gets rid of redundant buffering logic in `poly1305` - Adds notes about the NCC/MobileCoin security audit
1 parent 84141e1 commit 0e62d32

15 files changed

Lines changed: 170 additions & 262 deletions

File tree

Cargo.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ members = [
44
"poly1305",
55
"polyval"
66
]
7+
8+
[patch.crates-io]
9+
universal-hash = { git = "https://github.com/RustCrypto/traits" }

ghash/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ghash"
3-
version = "0.2.3"
3+
version = "0.3.0-pre"
44
authors = ["RustCrypto Developers"]
55
license = "MIT OR Apache-2.0"
66
description = """
@@ -15,7 +15,7 @@ categories = ["cryptography", "no-std"]
1515
edition = "2018"
1616

1717
[dependencies]
18-
polyval = { version = "0.3", path = "../polyval" }
18+
polyval = { version = "= 0.4.0-pre", path = "../polyval" }
1919
zeroize = { version = "1", optional = true, default-features = false }
2020

2121
[dev-dependencies]

ghash/README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ Its primary intended use is for implementing [AES-GCM][4].
1313

1414
[Documentation][docs-link]
1515

16-
## Security Warning
16+
## Security Notes
1717

18-
No security audits of this crate have ever been performed, and it has not been
19-
thoroughly assessed to ensure its operation is constant-time on common CPU
20-
architectures.
18+
This crate has received one [security audit by NCC Group][5], with no significant
19+
findings. We would like to thank [MobileCoin][6] for funding the audit.
2120

22-
USE AT YOUR OWN RISK!
21+
All implementations contained in the crate are designed to execute in constant
22+
time, either by relying on hardware intrinsics (i.e. AVX2 on x86/x86_64), or
23+
using a portable implementation which is only constant time on processors which
24+
implement constant-time multiplication.
25+
26+
It is not suitable for use on processors with a variable-time multiplication
27+
operation (e.g. short circuit on multiply-by-zero / multiply-by-one, such as
28+
certain 32-bit PowerPC CPUs and some non-ARM microcontrollers).
2329

2430
## License
2531

@@ -53,3 +59,5 @@ dual licensed as above, without any additional terms or conditions.
5359
[2]: https://en.wikipedia.org/wiki/Universal_hashing
5460
[3]: https://en.wikipedia.org/wiki/Message_authentication_code
5561
[4]: https://en.wikipedia.org/wiki/Galois/Counter_Mode
62+
[5]: https://research.nccgroup.com/2020/02/26/public-report-rustcrypto-aes-gcm-and-chacha20poly1305-implementation-review/
63+
[6]: https://www.mobilecoin.com/

ghash/src/lib.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,19 @@ pub use polyval::universal_hash;
2929

3030
use core::convert::TryInto;
3131
use polyval::Polyval;
32-
use universal_hash::generic_array::{typenum::U16, GenericArray};
33-
use universal_hash::{Output, UniversalHash};
32+
use universal_hash::{consts::U16, NewUniversalHash, UniversalHash};
3433
#[cfg(feature = "zeroize")]
3534
use zeroize::Zeroize;
3635

36+
/// GHASH keys (16-bytes)
37+
pub type Key = universal_hash::Key<GHash>;
38+
39+
/// GHASH blocks (16-bytes)
40+
pub type Block = universal_hash::Block<GHash>;
41+
42+
/// GHASH tags (16-bytes)
43+
pub type Tag = universal_hash::Output<GHash>;
44+
3745
/// **GHASH**: universal hash over GF(2^128) used by AES-GCM.
3846
///
3947
/// GHASH is a universal hash function used for message authentication in
@@ -42,12 +50,11 @@ use zeroize::Zeroize;
4250
#[repr(align(16))]
4351
pub struct GHash(Polyval);
4452

45-
impl UniversalHash for GHash {
53+
impl NewUniversalHash for GHash {
4654
type KeySize = U16;
47-
type BlockSize = U16;
4855

4956
/// Initialize GHASH with the given `H` field element
50-
fn new(h: &GenericArray<u8, U16>) -> Self {
57+
fn new(h: &Key) -> Self {
5158
let mut h = *h;
5259
h.reverse();
5360

@@ -65,12 +72,16 @@ impl UniversalHash for GHash {
6572

6673
result
6774
}
75+
}
76+
77+
impl UniversalHash for GHash {
78+
type BlockSize = U16;
6879

6980
/// Input a field element `X` to be authenticated
70-
fn update_block(&mut self, x: &GenericArray<u8, U16>) {
81+
fn update(&mut self, x: &Block) {
7182
let mut x = *x;
7283
x.reverse();
73-
self.0.update_block(&x);
84+
self.0.update(&x);
7485
}
7586

7687
/// Reset internal state
@@ -79,10 +90,10 @@ impl UniversalHash for GHash {
7990
}
8091

8192
/// Get GHASH output
82-
fn result(self) -> Output<U16> {
93+
fn result(self) -> Tag {
8394
let mut output = self.0.result().into_bytes();
8495
output.reverse();
85-
Output::new(output)
96+
Tag::new(output)
8697
}
8798
}
8899

@@ -92,7 +103,7 @@ impl UniversalHash for GHash {
92103
///
93104
/// [1]: https://tools.ietf.org/html/rfc8452#appendix-A
94105
#[allow(non_snake_case)]
95-
fn mulX_POLYVAL(block: &GenericArray<u8, U16>) -> GenericArray<u8, U16> {
106+
fn mulX_POLYVAL(block: &Block) -> Block {
96107
let mut v0 = u64::from_le_bytes(block[..8].try_into().unwrap());
97108
let mut v1 = u64::from_le_bytes(block[8..].try_into().unwrap());
98109

ghash/tests/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#[macro_use]
22
extern crate hex_literal;
33

4-
use ghash::{universal_hash::UniversalHash, GHash};
4+
use ghash::{
5+
universal_hash::{NewUniversalHash, UniversalHash},
6+
GHash,
7+
};
58

69
//
710
// Test vectors for GHASH from RFC 8452 Appendix A
@@ -18,8 +21,8 @@ const GHASH_RESULT: [u8; 16] = hex!("bd9b3997046731fb96251b91f9c99d7a");
1821
#[test]
1922
fn ghash_test_vector() {
2023
let mut ghash = GHash::new(&H.into());
21-
ghash.update_block(&X_1.into());
22-
ghash.update_block(&X_2.into());
24+
ghash.update(&X_1.into());
25+
ghash.update(&X_2.into());
2326

2427
let result = ghash.result();
2528
assert_eq!(&GHASH_RESULT[..], result.into_bytes().as_slice());

poly1305/Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "poly1305"
3-
version = "0.5.2"
3+
version = "0.6.0-pre"
44
authors = ["RustCrypto Developers"]
5-
license = "MIT OR Apache-2.0"
5+
license = "Apache-2.0 OR MIT"
66
description = "The Poly1305 universal hash function and message authentication code"
77
documentation = "https://docs.rs/poly1305"
88
repository = "https://github.com/RustCrypto/universal-hashes"
@@ -11,8 +11,11 @@ categories = ["cryptography", "no-std"]
1111
readme = "README.md"
1212
edition = "2018"
1313

14+
[badges]
15+
maintenance = { status = "passively-maintained" }
16+
1417
[dependencies]
15-
universal-hash = { version = "0.3", default-features = false }
18+
universal-hash = { version = "= 0.4.0-pre", default-features = false }
1619
zeroize = { version = "1", optional = true, default-features = false }
1720

1821
[features]

poly1305/README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@ In practice, Poly1305 is primarily combined with ciphers from the
1515

1616
[Documentation][docs-link]
1717

18-
## Security Warning
18+
## Security Notes
1919

20-
No security audits of this crate have ever been performed, and it has not been
21-
thoroughly assessed to ensure its operation is constant-time on common CPU
22-
architectures.
20+
This crate has received one [security audit by NCC Group][7], with no significant
21+
findings. We would like to thank [MobileCoin][8] for funding the audit.
2322

24-
USE AT YOUR OWN RISK!
23+
All implementations contained in the crate are designed to execute in constant
24+
time, either by relying on hardware intrinsics (i.e. AVX2 on x86/x86_64), or
25+
using a portable implementation which is only constant time on processors which
26+
implement constant-time multiplication.
27+
28+
It is not suitable for use on processors with a variable-time multiplication
29+
operation (e.g. short circuit on multiply-by-zero / multiply-by-one, such as
30+
certain 32-bit PowerPC CPUs and some non-ARM microcontrollers).
2531

2632
## License
2733

@@ -57,3 +63,5 @@ dual licensed as above, without any additional terms or conditions.
5763
[4]: https://cr.yp.to/snuffle/salsafamily-20071225.pdf
5864
[5]: https://github.com/RustCrypto/AEADs/tree/master/chacha20poly1305
5965
[6]: https://github.com/RustCrypto/AEADs/tree/master/xsalsa20poly1305
66+
[7]: https://research.nccgroup.com/2020/02/26/public-report-rustcrypto-aes-gcm-and-chacha20poly1305-implementation-review/
67+
[8]: https://www.mobilecoin.com/

0 commit comments

Comments
 (0)