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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
use crate::;
use Debug;
use ZeroizeOnDrop;
/// Stores the secret key used in AEGIS encryption and decryption.
///
/// This type takes a const generic parameter (`BYTES`) specifying the
/// number of key bytes. `AEGIS-128[L|X]` ciphers use 128 bit keys while
/// `AEGIS-256[X]` ciphers use 256 bit keys. (All ciphers validate the
/// provided `Key` size at compile time making it impossible to use an
/// incorrect `Key` size.)
///
/// Since only 128 or 256 bit keys are valid for AEGIS ciphers, only values
/// `16` and `32` are supported for the `Key`'s `BYTES` const generic
/// parameter. This too is validated at compile time.
///
/// [`Key128`] (for `Key<16>`) and [`Key256`] (for `Key<32>`) type aliases are
/// provided for convenience and should be preferred over raw `Key` usage.
///
/// **Use [`Key::generate()`] to securely create random `Key`s** instead of
/// generating key bytes yourself and passing them to [`Key::new()`] or
/// [`Key::from_bytes()`]. The [`Key::generate()`] method will use an
/// appropriate [_cryptographically secure_ random number generator][csrng]
/// (CSRNG) provided by the OS.
///
/// You can access the internal key bytes with [`Key::expose_secret()`]. This
/// method is also the _only_ way to access secret bytes once they are stored in
/// `Key`, making security audits easier.
///
/// `Key` uses a custom implementation of [`Debug`][std::fmt::Debug] that
/// _always_ redacts the key bytes to prevent accidental exposure of secrets
/// through logs or other machinery.
///
/// This type is zeroized on [`Drop`].
///
/// Note that derives for [`Eq`] and [`PartialEq`] are intentionally omitted to
/// prevent accidental non-constant-time equality comparisons. Use
/// [`Key::expose_secret()`] and the
/// [`constant_time_eq`](https://lib.rs/crates/constant_time_eq) crate if you
/// need this.
/// [`Clone`] is not implemented to prevent accidental secret duplication.
///
/// [csrng]: https://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator
// We need to implement Debug to make `Key` less annoying to deal with due to
// Debug trait bounds (especially in tests), but we always redact the contents.
/// A type alias for a 128 bit (16 byte) [`Key`].
pub type Key128 = ;
/// A type alias for a 256 bit (32 byte) [`Key`].
pub type Key256 = ;