5
5
6
6
use core:: { convert:: TryInto , marker:: PhantomData , ptr, slice} ;
7
7
8
- use cryptoki_sys:: {
9
- CK_ATTRIBUTE_PTR , CK_DERIVED_KEY , CK_DERIVED_KEY_PTR , CK_OBJECT_HANDLE , CK_OBJECT_HANDLE_PTR ,
10
- CK_PRF_DATA_PARAM , CK_PRF_DATA_PARAM_PTR , CK_SP800_108_BYTE_ARRAY , CK_SP800_108_COUNTER ,
11
- CK_SP800_108_COUNTER_FORMAT , CK_SP800_108_DKM_LENGTH , CK_SP800_108_DKM_LENGTH_FORMAT ,
12
- CK_SP800_108_DKM_LENGTH_SUM_OF_KEYS , CK_SP800_108_DKM_LENGTH_SUM_OF_SEGMENTS ,
13
- CK_SP800_108_FEEDBACK_KDF_PARAMS , CK_SP800_108_ITERATION_VARIABLE , CK_SP800_108_KDF_PARAMS ,
14
- CK_ULONG ,
15
- } ;
16
-
17
8
use crate :: object:: Attribute ;
18
9
19
10
use super :: MechanismType ;
@@ -33,7 +24,7 @@ pub enum Endianness {
33
24
#[ derive( Debug , Clone , Copy ) ]
34
25
#[ repr( transparent) ]
35
26
pub struct KbkdfCounterFormat {
36
- inner : CK_SP800_108_COUNTER_FORMAT ,
27
+ inner : cryptoki_sys :: CK_SP800_108_COUNTER_FORMAT ,
37
28
}
38
29
39
30
impl KbkdfCounterFormat {
@@ -46,7 +37,7 @@ impl KbkdfCounterFormat {
46
37
/// * `width_in_bits` - The number of bits used to represent the counter value.
47
38
pub fn new ( endianness : Endianness , width_in_bits : usize ) -> Self {
48
39
Self {
49
- inner : CK_SP800_108_COUNTER_FORMAT {
40
+ inner : cryptoki_sys :: CK_SP800_108_COUNTER_FORMAT {
50
41
bLittleEndian : ( endianness == Endianness :: Little ) . into ( ) ,
51
42
ulWidthInBits : width_in_bits
52
43
. try_into ( )
@@ -73,7 +64,7 @@ pub enum DkmLengthMethod {
73
64
#[ derive( Debug , Clone , Copy ) ]
74
65
#[ repr( transparent) ]
75
66
pub struct KbkdfDkmLengthFormat {
76
- inner : CK_SP800_108_DKM_LENGTH_FORMAT ,
67
+ inner : cryptoki_sys :: CK_SP800_108_DKM_LENGTH_FORMAT ,
77
68
}
78
69
79
70
impl KbkdfDkmLengthFormat {
@@ -92,10 +83,12 @@ impl KbkdfDkmLengthFormat {
92
83
width_in_bits : usize ,
93
84
) -> Self {
94
85
Self {
95
- inner : CK_SP800_108_DKM_LENGTH_FORMAT {
86
+ inner : cryptoki_sys :: CK_SP800_108_DKM_LENGTH_FORMAT {
96
87
dkmLengthMethod : match dkm_length_method {
97
- DkmLengthMethod :: SumOfKeys => CK_SP800_108_DKM_LENGTH_SUM_OF_KEYS ,
98
- DkmLengthMethod :: SumOfSegments => CK_SP800_108_DKM_LENGTH_SUM_OF_SEGMENTS ,
88
+ DkmLengthMethod :: SumOfKeys => cryptoki_sys:: CK_SP800_108_DKM_LENGTH_SUM_OF_KEYS ,
89
+ DkmLengthMethod :: SumOfSegments => {
90
+ cryptoki_sys:: CK_SP800_108_DKM_LENGTH_SUM_OF_SEGMENTS
91
+ }
99
92
} ,
100
93
bLittleEndian : ( endianness == Endianness :: Little ) . into ( ) ,
101
94
ulWidthInBits : width_in_bits. try_into ( ) . expect (
@@ -125,7 +118,7 @@ pub enum PrfDataParamType<'a> {
125
118
#[ derive( Debug , Clone , Copy ) ]
126
119
#[ repr( transparent) ]
127
120
pub struct PrfDataParam < ' a > {
128
- inner : CK_PRF_DATA_PARAM ,
121
+ inner : cryptoki_sys :: CK_PRF_DATA_PARAM ,
129
122
/// Marker type to ensure we don't outlive the data
130
123
_marker : PhantomData < & ' a [ u8 ] > ,
131
124
}
@@ -139,23 +132,25 @@ impl<'a> PrfDataParam<'a> {
139
132
pub fn new ( type_ : PrfDataParamType < ' a > ) -> Self {
140
133
Self {
141
134
inner : match type_ {
142
- PrfDataParamType :: IterationVariable => CK_PRF_DATA_PARAM {
143
- type_ : CK_SP800_108_ITERATION_VARIABLE ,
135
+ PrfDataParamType :: IterationVariable => cryptoki_sys :: CK_PRF_DATA_PARAM {
136
+ type_ : cryptoki_sys :: CK_SP800_108_ITERATION_VARIABLE ,
144
137
pValue : ptr:: null_mut ( ) ,
145
138
ulValueLen : 0 ,
146
139
} ,
147
- PrfDataParamType :: Counter ( counter_format) => CK_PRF_DATA_PARAM {
148
- type_ : CK_SP800_108_COUNTER ,
140
+ PrfDataParamType :: Counter ( counter_format) => cryptoki_sys :: CK_PRF_DATA_PARAM {
141
+ type_ : cryptoki_sys :: CK_SP800_108_COUNTER ,
149
142
pValue : & counter_format. inner as * const _ as * mut _ ,
150
- ulValueLen : size_of :: < CK_SP800_108_COUNTER_FORMAT > ( ) as CK_ULONG ,
143
+ ulValueLen : size_of :: < cryptoki_sys:: CK_SP800_108_COUNTER_FORMAT > ( )
144
+ as cryptoki_sys:: CK_ULONG ,
151
145
} ,
152
- PrfDataParamType :: DkmLength ( dkm_length_format) => CK_PRF_DATA_PARAM {
153
- type_ : CK_SP800_108_DKM_LENGTH ,
146
+ PrfDataParamType :: DkmLength ( dkm_length_format) => cryptoki_sys :: CK_PRF_DATA_PARAM {
147
+ type_ : cryptoki_sys :: CK_SP800_108_DKM_LENGTH ,
154
148
pValue : & dkm_length_format. inner as * const _ as * mut _ ,
155
- ulValueLen : size_of :: < CK_SP800_108_DKM_LENGTH_FORMAT > ( ) as CK_ULONG ,
149
+ ulValueLen : size_of :: < cryptoki_sys:: CK_SP800_108_DKM_LENGTH_FORMAT > ( )
150
+ as cryptoki_sys:: CK_ULONG ,
156
151
} ,
157
- PrfDataParamType :: ByteArray ( data) => CK_PRF_DATA_PARAM {
158
- type_ : CK_SP800_108_BYTE_ARRAY ,
152
+ PrfDataParamType :: ByteArray ( data) => cryptoki_sys :: CK_PRF_DATA_PARAM {
153
+ type_ : cryptoki_sys :: CK_SP800_108_BYTE_ARRAY ,
159
154
pValue : data. as_ptr ( ) as * mut _ ,
160
155
ulValueLen : data
161
156
. len ( )
@@ -185,7 +180,7 @@ pub enum PrfCounterDataParamType<'a> {
185
180
#[ derive( Debug , Clone , Copy ) ]
186
181
#[ repr( transparent) ]
187
182
pub struct PrfCounterDataParam < ' a > {
188
- inner : CK_PRF_DATA_PARAM ,
183
+ inner : cryptoki_sys :: CK_PRF_DATA_PARAM ,
189
184
/// Marker type to ensure we don't outlive the data
190
185
_marker : PhantomData < & ' a [ u8 ] > ,
191
186
}
@@ -199,18 +194,24 @@ impl<'a> PrfCounterDataParam<'a> {
199
194
pub fn new ( type_ : PrfCounterDataParamType < ' a > ) -> Self {
200
195
Self {
201
196
inner : match type_ {
202
- PrfCounterDataParamType :: IterationVariable ( counter_format) => CK_PRF_DATA_PARAM {
203
- type_ : CK_SP800_108_ITERATION_VARIABLE ,
204
- pValue : & counter_format. inner as * const _ as * mut _ ,
205
- ulValueLen : size_of :: < CK_SP800_108_COUNTER_FORMAT > ( ) as CK_ULONG ,
206
- } ,
207
- PrfCounterDataParamType :: DkmLength ( dkm_length_format) => CK_PRF_DATA_PARAM {
208
- type_ : CK_SP800_108_DKM_LENGTH ,
209
- pValue : & dkm_length_format. inner as * const _ as * mut _ ,
210
- ulValueLen : size_of :: < CK_SP800_108_DKM_LENGTH_FORMAT > ( ) as CK_ULONG ,
211
- } ,
212
- PrfCounterDataParamType :: ByteArray ( data) => CK_PRF_DATA_PARAM {
213
- type_ : CK_SP800_108_BYTE_ARRAY ,
197
+ PrfCounterDataParamType :: IterationVariable ( counter_format) => {
198
+ cryptoki_sys:: CK_PRF_DATA_PARAM {
199
+ type_ : cryptoki_sys:: CK_SP800_108_ITERATION_VARIABLE ,
200
+ pValue : & counter_format. inner as * const _ as * mut _ ,
201
+ ulValueLen : size_of :: < cryptoki_sys:: CK_SP800_108_COUNTER_FORMAT > ( )
202
+ as cryptoki_sys:: CK_ULONG ,
203
+ }
204
+ }
205
+ PrfCounterDataParamType :: DkmLength ( dkm_length_format) => {
206
+ cryptoki_sys:: CK_PRF_DATA_PARAM {
207
+ type_ : cryptoki_sys:: CK_SP800_108_DKM_LENGTH ,
208
+ pValue : & dkm_length_format. inner as * const _ as * mut _ ,
209
+ ulValueLen : size_of :: < cryptoki_sys:: CK_SP800_108_DKM_LENGTH_FORMAT > ( )
210
+ as cryptoki_sys:: CK_ULONG ,
211
+ }
212
+ }
213
+ PrfCounterDataParamType :: ByteArray ( data) => cryptoki_sys:: CK_PRF_DATA_PARAM {
214
+ type_ : cryptoki_sys:: CK_SP800_108_BYTE_ARRAY ,
214
215
pValue : data. as_ptr ( ) as * mut _ ,
215
216
ulValueLen : data
216
217
. len ( )
@@ -227,7 +228,7 @@ impl<'a> PrfCounterDataParam<'a> {
227
228
#[ derive( Debug , Clone , Copy ) ]
228
229
#[ repr( transparent) ]
229
230
pub struct DerivedKey < ' a > {
230
- inner : CK_DERIVED_KEY ,
231
+ inner : cryptoki_sys :: CK_DERIVED_KEY ,
231
232
/// Marker type to ensure we don't outlive the data
232
233
_marker : PhantomData < & ' a [ u8 ] > ,
233
234
}
@@ -242,13 +243,13 @@ impl<'a> DerivedKey<'a> {
242
243
/// * `handle` - The location into which will be written the handle of the new derived key.
243
244
pub fn new ( template : & ' a [ Attribute ] , handle : & ' a mut u64 ) -> Self {
244
245
Self {
245
- inner : CK_DERIVED_KEY {
246
- pTemplate : template. as_ptr ( ) as CK_ATTRIBUTE_PTR ,
246
+ inner : cryptoki_sys :: CK_DERIVED_KEY {
247
+ pTemplate : template. as_ptr ( ) as cryptoki_sys :: CK_ATTRIBUTE_PTR ,
247
248
ulAttributeCount : template
248
249
. len ( )
249
250
. try_into ( )
250
251
. expect ( "number of attributes in template does not fit in CK_ULONG" ) ,
251
- phKey : handle as CK_OBJECT_HANDLE_PTR ,
252
+ phKey : handle as cryptoki_sys :: CK_OBJECT_HANDLE_PTR ,
252
253
} ,
253
254
_marker : PhantomData ,
254
255
}
@@ -261,7 +262,7 @@ impl<'a> DerivedKey<'a> {
261
262
#[ derive( Debug , Clone , Copy ) ]
262
263
#[ repr( transparent) ]
263
264
pub struct KbkdfCounterParams < ' a > {
264
- inner : CK_SP800_108_KDF_PARAMS ,
265
+ inner : cryptoki_sys :: CK_SP800_108_KDF_PARAMS ,
265
266
/// Marker type to ensure we don't outlive the data
266
267
_marker : PhantomData < & ' a [ u8 ] > ,
267
268
}
@@ -283,25 +284,26 @@ impl<'a> KbkdfCounterParams<'a> {
283
284
additional_derived_keys : & ' a mut [ DerivedKey < ' a > ] ,
284
285
) -> Self {
285
286
Self {
286
- inner : CK_SP800_108_KDF_PARAMS {
287
+ inner : cryptoki_sys :: CK_SP800_108_KDF_PARAMS {
287
288
prfType : prf_mechanism. into ( ) ,
288
289
ulNumberOfDataParams : prf_data_params
289
290
. len ( )
290
291
. try_into ( )
291
292
. expect ( "number of data parameters does not fit in CK_ULONG" ) ,
292
- pDataParams : prf_data_params. as_ptr ( ) as CK_PRF_DATA_PARAM_PTR ,
293
+ pDataParams : prf_data_params. as_ptr ( ) as cryptoki_sys :: CK_PRF_DATA_PARAM_PTR ,
293
294
ulAdditionalDerivedKeys : additional_derived_keys
294
295
. len ( )
295
296
. try_into ( )
296
297
. expect ( "number of additional derived keys does not fit in CK_ULONG" ) ,
297
- pAdditionalDerivedKeys : additional_derived_keys. as_mut_ptr ( ) as CK_DERIVED_KEY_PTR ,
298
+ pAdditionalDerivedKeys : additional_derived_keys. as_mut_ptr ( )
299
+ as cryptoki_sys:: CK_DERIVED_KEY_PTR ,
298
300
} ,
299
301
_marker : PhantomData ,
300
302
}
301
303
}
302
304
303
305
/// The additional keys derived by the KDF, as per the params
304
- pub fn additional_derived_keys ( & self ) -> Vec < CK_OBJECT_HANDLE > {
306
+ pub fn additional_derived_keys ( & self ) -> Vec < cryptoki_sys :: CK_OBJECT_HANDLE > {
305
307
let derived_keys = unsafe {
306
308
slice:: from_raw_parts (
307
309
self . inner . pAdditionalDerivedKeys ,
@@ -324,7 +326,7 @@ impl<'a> KbkdfCounterParams<'a> {
324
326
#[ derive( Debug , Clone , Copy ) ]
325
327
#[ repr( transparent) ]
326
328
pub struct KbkdfFeedbackParams < ' a > {
327
- inner : CK_SP800_108_FEEDBACK_KDF_PARAMS ,
329
+ inner : cryptoki_sys :: CK_SP800_108_FEEDBACK_KDF_PARAMS ,
328
330
/// Marker type to ensure we don't outlive the data
329
331
_marker : PhantomData < & ' a [ u8 ] > ,
330
332
}
@@ -349,13 +351,13 @@ impl<'a> KbkdfFeedbackParams<'a> {
349
351
additional_derived_keys : & ' a mut [ DerivedKey < ' a > ] ,
350
352
) -> Self {
351
353
Self {
352
- inner : CK_SP800_108_FEEDBACK_KDF_PARAMS {
354
+ inner : cryptoki_sys :: CK_SP800_108_FEEDBACK_KDF_PARAMS {
353
355
prfType : prf_mechanism. into ( ) ,
354
356
ulNumberOfDataParams : prf_data_params
355
357
. len ( )
356
358
. try_into ( )
357
359
. expect ( "number of data parameters does not fit in CK_ULONG" ) ,
358
- pDataParams : prf_data_params. as_ptr ( ) as CK_PRF_DATA_PARAM_PTR ,
360
+ pDataParams : prf_data_params. as_ptr ( ) as cryptoki_sys :: CK_PRF_DATA_PARAM_PTR ,
359
361
ulIVLen : iv. map_or ( 0 , |iv| {
360
362
iv. len ( )
361
363
. try_into ( )
@@ -366,14 +368,15 @@ impl<'a> KbkdfFeedbackParams<'a> {
366
368
. len ( )
367
369
. try_into ( )
368
370
. expect ( "number of additional derived keys does not fit in CK_ULONG" ) ,
369
- pAdditionalDerivedKeys : additional_derived_keys. as_mut_ptr ( ) as CK_DERIVED_KEY_PTR ,
371
+ pAdditionalDerivedKeys : additional_derived_keys. as_mut_ptr ( )
372
+ as cryptoki_sys:: CK_DERIVED_KEY_PTR ,
370
373
} ,
371
374
_marker : PhantomData ,
372
375
}
373
376
}
374
377
375
378
/// The additional keys derived by the KDF, as per the params
376
- pub fn additional_derived_keys ( & self ) -> Vec < CK_OBJECT_HANDLE > {
379
+ pub fn additional_derived_keys ( & self ) -> Vec < cryptoki_sys :: CK_OBJECT_HANDLE > {
377
380
let derived_keys = unsafe {
378
381
slice:: from_raw_parts (
379
382
self . inner . pAdditionalDerivedKeys ,
@@ -396,7 +399,7 @@ impl<'a> KbkdfFeedbackParams<'a> {
396
399
#[ derive( Debug , Clone , Copy ) ]
397
400
#[ repr( transparent) ]
398
401
pub struct KbkdfDoublePipelineParams < ' a > {
399
- inner : CK_SP800_108_KDF_PARAMS ,
402
+ inner : cryptoki_sys :: CK_SP800_108_KDF_PARAMS ,
400
403
/// Marker type to ensure we don't outlive the data
401
404
_marker : PhantomData < & ' a [ u8 ] > ,
402
405
}
@@ -418,25 +421,26 @@ impl<'a> KbkdfDoublePipelineParams<'a> {
418
421
additional_derived_keys : & ' a mut [ DerivedKey < ' a > ] ,
419
422
) -> Self {
420
423
Self {
421
- inner : CK_SP800_108_KDF_PARAMS {
424
+ inner : cryptoki_sys :: CK_SP800_108_KDF_PARAMS {
422
425
prfType : prf_mechanism. into ( ) ,
423
426
ulNumberOfDataParams : prf_data_params
424
427
. len ( )
425
428
. try_into ( )
426
429
. expect ( "number of data parameters does not fit in CK_ULONG" ) ,
427
- pDataParams : prf_data_params. as_ptr ( ) as CK_PRF_DATA_PARAM_PTR ,
430
+ pDataParams : prf_data_params. as_ptr ( ) as cryptoki_sys :: CK_PRF_DATA_PARAM_PTR ,
428
431
ulAdditionalDerivedKeys : additional_derived_keys
429
432
. len ( )
430
433
. try_into ( )
431
434
. expect ( "number of additional derived keys does not fit in CK_ULONG" ) ,
432
- pAdditionalDerivedKeys : additional_derived_keys. as_mut_ptr ( ) as CK_DERIVED_KEY_PTR ,
435
+ pAdditionalDerivedKeys : additional_derived_keys. as_mut_ptr ( )
436
+ as cryptoki_sys:: CK_DERIVED_KEY_PTR ,
433
437
} ,
434
438
_marker : PhantomData ,
435
439
}
436
440
}
437
441
438
442
/// The additional keys derived by the KDF, as per the params
439
- pub fn additional_derived_keys ( & self ) -> Vec < CK_OBJECT_HANDLE > {
443
+ pub fn additional_derived_keys ( & self ) -> Vec < cryptoki_sys :: CK_OBJECT_HANDLE > {
440
444
let derived_keys = unsafe {
441
445
slice:: from_raw_parts (
442
446
self . inner . pAdditionalDerivedKeys ,
0 commit comments