@@ -95,18 +95,21 @@ extern crate std;
95
95
use core:: fmt;
96
96
use hmac:: digest:: {
97
97
block_buffer:: Eager ,
98
- core_api:: { AlgorithmName , BufferKindUser , CoreProxy , FixedOutputCore , UpdateCore } ,
99
- generic_array:: typenum:: Unsigned ,
100
- Digest , FixedOutput , KeyInit , Output , Update ,
98
+ core_api:: {
99
+ AlgorithmName , BlockSizeUser , BufferKindUser , CoreProxy , FixedOutputCore , OutputSizeUser ,
100
+ UpdateCore ,
101
+ } ,
102
+ generic_array:: typenum:: { IsLess , Le , NonZero , Unsigned , U256 } ,
103
+ FixedOutput , HashMarker , KeyInit , Output , Update ,
101
104
} ;
102
105
use hmac:: Hmac ;
103
106
104
107
/// Error that is returned when supplied pseudorandom key (PRK) is not long enough.
105
- #[ derive( Copy , Clone , Eq , PartialEq , Debug ) ]
108
+ #[ derive( Copy , Clone , Debug ) ]
106
109
pub struct InvalidPrkLength ;
107
110
108
111
/// Structure for InvalidLength, used for output error handling.
109
- #[ derive( Copy , Clone , Eq , PartialEq , Debug ) ]
112
+ #[ derive( Copy , Clone , Debug ) ]
110
113
pub struct InvalidLength ;
111
114
112
115
/// Structure representing the streaming context of an HKDF-Extract operation
@@ -124,20 +127,34 @@ pub struct InvalidLength;
124
127
#[ derive( Clone ) ]
125
128
pub struct HkdfExtract < D >
126
129
where
127
- D : CoreProxy + Digest ,
128
- D :: Core : UpdateCore + FixedOutputCore + BufferKindUser < BufferKind = Eager > + Default + Clone ,
130
+ D : CoreProxy ,
131
+ D :: Core : HashMarker
132
+ + UpdateCore
133
+ + FixedOutputCore
134
+ + BufferKindUser < BufferKind = Eager >
135
+ + Default
136
+ + Clone ,
137
+ <D :: Core as BlockSizeUser >:: BlockSize : IsLess < U256 > ,
138
+ Le < <D :: Core as BlockSizeUser >:: BlockSize , U256 > : NonZero ,
129
139
{
130
140
hmac : Hmac < D > ,
131
141
}
132
142
133
143
impl < D > HkdfExtract < D >
134
144
where
135
- D : CoreProxy + Digest ,
136
- D :: Core : UpdateCore + FixedOutputCore + BufferKindUser < BufferKind = Eager > + Default + Clone ,
145
+ D : CoreProxy ,
146
+ D :: Core : HashMarker
147
+ + UpdateCore
148
+ + FixedOutputCore
149
+ + BufferKindUser < BufferKind = Eager >
150
+ + Default
151
+ + Clone ,
152
+ <D :: Core as BlockSizeUser >:: BlockSize : IsLess < U256 > ,
153
+ Le < <D :: Core as BlockSizeUser >:: BlockSize , U256 > : NonZero ,
137
154
{
138
155
/// Initiates the HKDF-Extract context with the given optional salt
139
156
pub fn new ( salt : Option < & [ u8 ] > ) -> HkdfExtract < D > {
140
- let default_salt = Output :: < D > :: default ( ) ;
157
+ let default_salt = Output :: < D :: Core > :: default ( ) ;
141
158
let salt = salt. unwrap_or ( & default_salt) ;
142
159
let hmac = Hmac :: < D > :: new_from_slice ( salt) . expect ( "HMAC can take a key of any size" ) ;
143
160
HkdfExtract { hmac }
@@ -159,13 +176,16 @@ where
159
176
160
177
impl < D > fmt:: Debug for HkdfExtract < D >
161
178
where
162
- D : CoreProxy + Digest ,
163
- D :: Core : AlgorithmName
179
+ D : CoreProxy ,
180
+ D :: Core : HashMarker
181
+ + AlgorithmName
164
182
+ UpdateCore
165
183
+ FixedOutputCore
166
184
+ BufferKindUser < BufferKind = Eager >
167
185
+ Default
168
186
+ Clone ,
187
+ <D :: Core as BlockSizeUser >:: BlockSize : IsLess < U256 > ,
188
+ Le < <D :: Core as BlockSizeUser >:: BlockSize , U256 > : NonZero ,
169
189
{
170
190
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
171
191
f. write_str ( "HkdfExtract<" ) ?;
@@ -178,16 +198,30 @@ where
178
198
#[ derive( Clone ) ]
179
199
pub struct Hkdf < D >
180
200
where
181
- D : CoreProxy + Digest ,
182
- D :: Core : UpdateCore + FixedOutputCore + BufferKindUser < BufferKind = Eager > + Default + Clone ,
201
+ D : CoreProxy ,
202
+ D :: Core : HashMarker
203
+ + UpdateCore
204
+ + FixedOutputCore
205
+ + BufferKindUser < BufferKind = Eager >
206
+ + Default
207
+ + Clone ,
208
+ <D :: Core as BlockSizeUser >:: BlockSize : IsLess < U256 > ,
209
+ Le < <D :: Core as BlockSizeUser >:: BlockSize , U256 > : NonZero ,
183
210
{
184
211
hmac : Hmac < D > ,
185
212
}
186
213
187
214
impl < D > Hkdf < D >
188
215
where
189
- D : CoreProxy + Digest ,
190
- D :: Core : UpdateCore + FixedOutputCore + BufferKindUser < BufferKind = Eager > + Default + Clone ,
216
+ D : CoreProxy ,
217
+ D :: Core : HashMarker
218
+ + UpdateCore
219
+ + FixedOutputCore
220
+ + BufferKindUser < BufferKind = Eager >
221
+ + Default
222
+ + Clone ,
223
+ <D :: Core as BlockSizeUser >:: BlockSize : IsLess < U256 > ,
224
+ Le < <D :: Core as BlockSizeUser >:: BlockSize , U256 > : NonZero ,
191
225
{
192
226
/// Convenience method for [`extract`][Hkdf::extract] when the generated
193
227
/// pseudorandom key can be ignored and only HKDF-Expand operation is needed. This is the most
@@ -201,7 +235,7 @@ where
201
235
/// as per section 3.3 from RFC5869.
202
236
pub fn from_prk ( prk : & [ u8 ] ) -> Result < Hkdf < D > , InvalidPrkLength > {
203
237
// section 2.3 specifies that prk must be "at least HashLen octets"
204
- if prk. len ( ) < D :: OutputSize :: to_usize ( ) {
238
+ if prk. len ( ) < < D :: Core as OutputSizeUser > :: OutputSize :: to_usize ( ) {
205
239
return Err ( InvalidPrkLength ) ;
206
240
}
207
241
@@ -228,7 +262,7 @@ where
228
262
) -> Result < ( ) , InvalidLength > {
229
263
let mut prev: Option < Output < D :: Core > > = None ;
230
264
231
- let chunk_len = D :: OutputSize :: USIZE ;
265
+ let chunk_len = < D :: Core as OutputSizeUser > :: OutputSize :: USIZE ;
232
266
if okm. len ( ) > chunk_len * 255 {
233
267
return Err ( InvalidLength ) ;
234
268
}
@@ -269,13 +303,16 @@ where
269
303
270
304
impl < D > fmt:: Debug for Hkdf < D >
271
305
where
272
- D : CoreProxy + Digest ,
273
- D :: Core : AlgorithmName
306
+ D : CoreProxy ,
307
+ D :: Core : HashMarker
308
+ + AlgorithmName
274
309
+ UpdateCore
275
310
+ FixedOutputCore
276
311
+ BufferKindUser < BufferKind = Eager >
277
312
+ Default
278
313
+ Clone ,
314
+ <D :: Core as BlockSizeUser >:: BlockSize : IsLess < U256 > ,
315
+ Le < <D :: Core as BlockSizeUser >:: BlockSize , U256 > : NonZero ,
279
316
{
280
317
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
281
318
f. write_str ( "Hkdf<" ) ?;
0 commit comments