Skip to content

Commit 799469a

Browse files
Qualified all cryptoki_sys imports as a stylistic choice
Signed-off-by: Jacob Prud'homme <[email protected]>
1 parent 0641873 commit 799469a

File tree

1 file changed

+62
-58
lines changed

1 file changed

+62
-58
lines changed

cryptoki/src/mechanism/kbkdf.rs

Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@
55
66
use core::{convert::TryInto, marker::PhantomData, ptr, slice};
77

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-
178
use crate::object::Attribute;
189

1910
use super::MechanismType;
@@ -33,7 +24,7 @@ pub enum Endianness {
3324
#[derive(Debug, Clone, Copy)]
3425
#[repr(transparent)]
3526
pub struct KbkdfCounterFormat {
36-
inner: CK_SP800_108_COUNTER_FORMAT,
27+
inner: cryptoki_sys::CK_SP800_108_COUNTER_FORMAT,
3728
}
3829

3930
impl KbkdfCounterFormat {
@@ -46,7 +37,7 @@ impl KbkdfCounterFormat {
4637
/// * `width_in_bits` - The number of bits used to represent the counter value.
4738
pub fn new(endianness: Endianness, width_in_bits: usize) -> Self {
4839
Self {
49-
inner: CK_SP800_108_COUNTER_FORMAT {
40+
inner: cryptoki_sys::CK_SP800_108_COUNTER_FORMAT {
5041
bLittleEndian: (endianness == Endianness::Little).into(),
5142
ulWidthInBits: width_in_bits
5243
.try_into()
@@ -73,7 +64,7 @@ pub enum DkmLengthMethod {
7364
#[derive(Debug, Clone, Copy)]
7465
#[repr(transparent)]
7566
pub struct KbkdfDkmLengthFormat {
76-
inner: CK_SP800_108_DKM_LENGTH_FORMAT,
67+
inner: cryptoki_sys::CK_SP800_108_DKM_LENGTH_FORMAT,
7768
}
7869

7970
impl KbkdfDkmLengthFormat {
@@ -92,10 +83,12 @@ impl KbkdfDkmLengthFormat {
9283
width_in_bits: usize,
9384
) -> Self {
9485
Self {
95-
inner: CK_SP800_108_DKM_LENGTH_FORMAT {
86+
inner: cryptoki_sys::CK_SP800_108_DKM_LENGTH_FORMAT {
9687
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+
}
9992
},
10093
bLittleEndian: (endianness == Endianness::Little).into(),
10194
ulWidthInBits: width_in_bits.try_into().expect(
@@ -125,7 +118,7 @@ pub enum PrfDataParamType<'a> {
125118
#[derive(Debug, Clone, Copy)]
126119
#[repr(transparent)]
127120
pub struct PrfDataParam<'a> {
128-
inner: CK_PRF_DATA_PARAM,
121+
inner: cryptoki_sys::CK_PRF_DATA_PARAM,
129122
/// Marker type to ensure we don't outlive the data
130123
_marker: PhantomData<&'a [u8]>,
131124
}
@@ -139,23 +132,25 @@ impl<'a> PrfDataParam<'a> {
139132
pub fn new(type_: PrfDataParamType<'a>) -> Self {
140133
Self {
141134
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,
144137
pValue: ptr::null_mut(),
145138
ulValueLen: 0,
146139
},
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,
149142
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,
151145
},
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,
154148
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,
156151
},
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,
159154
pValue: data.as_ptr() as *mut _,
160155
ulValueLen: data
161156
.len()
@@ -185,7 +180,7 @@ pub enum PrfCounterDataParamType<'a> {
185180
#[derive(Debug, Clone, Copy)]
186181
#[repr(transparent)]
187182
pub struct PrfCounterDataParam<'a> {
188-
inner: CK_PRF_DATA_PARAM,
183+
inner: cryptoki_sys::CK_PRF_DATA_PARAM,
189184
/// Marker type to ensure we don't outlive the data
190185
_marker: PhantomData<&'a [u8]>,
191186
}
@@ -199,18 +194,24 @@ impl<'a> PrfCounterDataParam<'a> {
199194
pub fn new(type_: PrfCounterDataParamType<'a>) -> Self {
200195
Self {
201196
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,
214215
pValue: data.as_ptr() as *mut _,
215216
ulValueLen: data
216217
.len()
@@ -227,7 +228,7 @@ impl<'a> PrfCounterDataParam<'a> {
227228
#[derive(Debug, Clone, Copy)]
228229
#[repr(transparent)]
229230
pub struct DerivedKey<'a> {
230-
inner: CK_DERIVED_KEY,
231+
inner: cryptoki_sys::CK_DERIVED_KEY,
231232
/// Marker type to ensure we don't outlive the data
232233
_marker: PhantomData<&'a [u8]>,
233234
}
@@ -242,13 +243,13 @@ impl<'a> DerivedKey<'a> {
242243
/// * `handle` - The location into which will be written the handle of the new derived key.
243244
pub fn new(template: &'a [Attribute], handle: &'a mut u64) -> Self {
244245
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,
247248
ulAttributeCount: template
248249
.len()
249250
.try_into()
250251
.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,
252253
},
253254
_marker: PhantomData,
254255
}
@@ -261,7 +262,7 @@ impl<'a> DerivedKey<'a> {
261262
#[derive(Debug, Clone, Copy)]
262263
#[repr(transparent)]
263264
pub struct KbkdfCounterParams<'a> {
264-
inner: CK_SP800_108_KDF_PARAMS,
265+
inner: cryptoki_sys::CK_SP800_108_KDF_PARAMS,
265266
/// Marker type to ensure we don't outlive the data
266267
_marker: PhantomData<&'a [u8]>,
267268
}
@@ -283,25 +284,26 @@ impl<'a> KbkdfCounterParams<'a> {
283284
additional_derived_keys: &'a mut [DerivedKey<'a>],
284285
) -> Self {
285286
Self {
286-
inner: CK_SP800_108_KDF_PARAMS {
287+
inner: cryptoki_sys::CK_SP800_108_KDF_PARAMS {
287288
prfType: prf_mechanism.into(),
288289
ulNumberOfDataParams: prf_data_params
289290
.len()
290291
.try_into()
291292
.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,
293294
ulAdditionalDerivedKeys: additional_derived_keys
294295
.len()
295296
.try_into()
296297
.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,
298300
},
299301
_marker: PhantomData,
300302
}
301303
}
302304

303305
/// 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> {
305307
let derived_keys = unsafe {
306308
slice::from_raw_parts(
307309
self.inner.pAdditionalDerivedKeys,
@@ -324,7 +326,7 @@ impl<'a> KbkdfCounterParams<'a> {
324326
#[derive(Debug, Clone, Copy)]
325327
#[repr(transparent)]
326328
pub struct KbkdfFeedbackParams<'a> {
327-
inner: CK_SP800_108_FEEDBACK_KDF_PARAMS,
329+
inner: cryptoki_sys::CK_SP800_108_FEEDBACK_KDF_PARAMS,
328330
/// Marker type to ensure we don't outlive the data
329331
_marker: PhantomData<&'a [u8]>,
330332
}
@@ -349,13 +351,13 @@ impl<'a> KbkdfFeedbackParams<'a> {
349351
additional_derived_keys: &'a mut [DerivedKey<'a>],
350352
) -> Self {
351353
Self {
352-
inner: CK_SP800_108_FEEDBACK_KDF_PARAMS {
354+
inner: cryptoki_sys::CK_SP800_108_FEEDBACK_KDF_PARAMS {
353355
prfType: prf_mechanism.into(),
354356
ulNumberOfDataParams: prf_data_params
355357
.len()
356358
.try_into()
357359
.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,
359361
ulIVLen: iv.map_or(0, |iv| {
360362
iv.len()
361363
.try_into()
@@ -366,14 +368,15 @@ impl<'a> KbkdfFeedbackParams<'a> {
366368
.len()
367369
.try_into()
368370
.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,
370373
},
371374
_marker: PhantomData,
372375
}
373376
}
374377

375378
/// 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> {
377380
let derived_keys = unsafe {
378381
slice::from_raw_parts(
379382
self.inner.pAdditionalDerivedKeys,
@@ -396,7 +399,7 @@ impl<'a> KbkdfFeedbackParams<'a> {
396399
#[derive(Debug, Clone, Copy)]
397400
#[repr(transparent)]
398401
pub struct KbkdfDoublePipelineParams<'a> {
399-
inner: CK_SP800_108_KDF_PARAMS,
402+
inner: cryptoki_sys::CK_SP800_108_KDF_PARAMS,
400403
/// Marker type to ensure we don't outlive the data
401404
_marker: PhantomData<&'a [u8]>,
402405
}
@@ -418,25 +421,26 @@ impl<'a> KbkdfDoublePipelineParams<'a> {
418421
additional_derived_keys: &'a mut [DerivedKey<'a>],
419422
) -> Self {
420423
Self {
421-
inner: CK_SP800_108_KDF_PARAMS {
424+
inner: cryptoki_sys::CK_SP800_108_KDF_PARAMS {
422425
prfType: prf_mechanism.into(),
423426
ulNumberOfDataParams: prf_data_params
424427
.len()
425428
.try_into()
426429
.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,
428431
ulAdditionalDerivedKeys: additional_derived_keys
429432
.len()
430433
.try_into()
431434
.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,
433437
},
434438
_marker: PhantomData,
435439
}
436440
}
437441

438442
/// 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> {
440444
let derived_keys = unsafe {
441445
slice::from_raw_parts(
442446
self.inner.pAdditionalDerivedKeys,

0 commit comments

Comments
 (0)