3
3
//! Mechanisms of NIST key-based key derive functions (SP 800-108, informally KBKDF)
4
4
//! See: <https://docs.oasis-open.org/pkcs11/pkcs11-curr/v3.0/os/pkcs11-curr-v3.0-os.html#_Toc30061446>
5
5
6
- use core:: { convert:: TryInto , marker:: PhantomData , pin :: Pin , ptr} ;
6
+ use core:: { convert:: TryInto , marker:: PhantomData , ptr} ;
7
7
use std:: num:: NonZeroUsize ;
8
8
9
9
use cryptoki_sys:: {
@@ -182,7 +182,9 @@ impl<'a> PrfDataParam<'a> {
182
182
/// Container for information on an additional key to be derived.
183
183
#[ derive( Debug ) ]
184
184
pub struct DerivedKey {
185
- template : Pin < Box < [ CK_ATTRIBUTE ] > > ,
185
+ /// Holds own data so that we have a contiguous memory region for backend to reference.
186
+ /// Because of this, the address of this allocation must remain stable during its lifetime.
187
+ template : Box < [ CK_ATTRIBUTE ] > ,
186
188
handle : CK_OBJECT_HANDLE ,
187
189
}
188
190
@@ -194,7 +196,6 @@ impl DerivedKey {
194
196
/// * `template` - The template for the key to be derived.
195
197
pub fn new ( template : & [ Attribute ] ) -> Self {
196
198
let template: Box < [ CK_ATTRIBUTE ] > = template. iter ( ) . map ( Into :: into) . collect ( ) ;
197
- let template = Pin :: new ( template) ;
198
199
199
200
Self {
200
201
template,
@@ -231,8 +232,9 @@ impl From<&mut DerivedKey> for CK_DERIVED_KEY {
231
232
/// This structure wraps a `CK_SP800_108_KDF_PARAMS` structure.
232
233
#[ derive( Debug ) ]
233
234
pub struct KbkdfParams < ' a > {
234
- /// Holds own data so that we have a contiguous memory region to give to backend
235
- _additional_derived_keys : Option < Pin < Box < [ CK_DERIVED_KEY ] > > > ,
235
+ /// Holds own data so that we have a contiguous memory region for backend to reference.
236
+ /// Because of this, the address of this allocation must remain stable during its lifetime.
237
+ _additional_derived_keys : Option < Box < [ CK_DERIVED_KEY ] > > ,
236
238
237
239
inner : CK_SP800_108_KDF_PARAMS ,
238
240
/// Marker type to ensure we don't outlive the data
@@ -260,8 +262,7 @@ impl<'a> KbkdfParams<'a> {
260
262
keys. iter_mut ( )
261
263
. map ( Into :: into)
262
264
. collect :: < Box < [ CK_DERIVED_KEY ] > > ( )
263
- } )
264
- . map ( Pin :: new) ;
265
+ } ) ;
265
266
266
267
let inner = CK_SP800_108_KDF_PARAMS {
267
268
prfType : prf_mechanism. into ( ) ,
@@ -300,8 +301,9 @@ impl<'a> KbkdfParams<'a> {
300
301
/// This structure wraps a `CK_SP800_108_FEEDBACK_KDF_PARAMS` structure.
301
302
#[ derive( Debug ) ]
302
303
pub struct KbkdfFeedbackParams < ' a > {
303
- /// Holds own data so that we have a contiguous memory region to give to backend
304
- _additional_derived_keys : Option < Pin < Box < [ CK_DERIVED_KEY ] > > > ,
304
+ /// Holds own data so that we have a contiguous memory region for backend to reference.
305
+ /// Because of this, the address of this allocation must remain stable during its lifetime.
306
+ _additional_derived_keys : Option < Box < [ CK_DERIVED_KEY ] > > ,
305
307
306
308
inner : CK_SP800_108_FEEDBACK_KDF_PARAMS ,
307
309
/// Marker type to ensure we don't outlive the data
@@ -332,8 +334,7 @@ impl<'a> KbkdfFeedbackParams<'a> {
332
334
keys. iter_mut ( )
333
335
. map ( Into :: into)
334
336
. collect :: < Box < [ CK_DERIVED_KEY ] > > ( )
335
- } )
336
- . map ( Pin :: new) ;
337
+ } ) ;
337
338
338
339
let inner = CK_SP800_108_FEEDBACK_KDF_PARAMS {
339
340
prfType : prf_mechanism. into ( ) ,
0 commit comments