1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#![no_std]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg"
)]
#![warn(missing_docs, rust_2018_idioms)]
pub use polyval::universal_hash;
use polyval::Polyval;
use universal_hash::{consts::U16, NewUniversalHash, UniversalHash};
#[cfg(feature = "zeroize")]
use zeroize::Zeroize;
pub type Key = universal_hash::Key<GHash>;
pub type Block = universal_hash::Block<GHash>;
pub type Tag = universal_hash::Output<GHash>;
#[derive(Clone)]
pub struct GHash(Polyval);
impl NewUniversalHash for GHash {
type KeySize = U16;
#[inline]
fn new(h: &Key) -> Self {
let mut h = *h;
h.reverse();
#[allow(unused_mut)]
let mut h_polyval = polyval::mulx(&h);
#[cfg(feature = "zeroize")]
h.zeroize();
#[allow(clippy::let_and_return)]
let result = GHash(Polyval::new(&h_polyval));
#[cfg(feature = "zeroize")]
h_polyval.zeroize();
result
}
}
impl UniversalHash for GHash {
type BlockSize = U16;
#[inline]
fn update(&mut self, x: &Block) {
let mut x = *x;
x.reverse();
self.0.update(&x);
}
#[inline]
fn reset(&mut self) {
self.0.reset();
}
#[inline]
fn finalize(self) -> Tag {
let mut output = self.0.finalize().into_bytes();
output.reverse();
Tag::new(output)
}
}
opaque_debug::implement!(GHash);