@@ -8,6 +8,7 @@ pub mod elliptic_curve;
88pub mod hkdf;
99mod mechanism_info;
1010pub mod rsa;
11+ pub mod vendor_defined;
1112
1213use crate :: error:: Error ;
1314use cryptoki_sys:: * ;
@@ -18,6 +19,7 @@ use std::fmt::Formatter;
1819use std:: mem:: size_of;
1920use std:: ops:: Deref ;
2021use std:: ptr:: null_mut;
22+ use vendor_defined:: VendorDefinedMechanism ;
2123
2224use crate :: mechanism:: rsa:: PkcsOaepParams ;
2325pub use mechanism_info:: MechanismInfo ;
@@ -298,6 +300,28 @@ impl MechanismType {
298300 /// HKDF-DATA mechanism
299301 pub const HKDF_DATA : MechanismType = MechanismType { val : CKM_HKDF_DATA } ;
300302
303+ /// Create vendor defined mechanism
304+ ///
305+ /// # Arguments
306+ ///
307+ /// * `adding` - The adding based on `CKM_VENDOR_DEFINED`
308+ ///
309+ /// Usually vendors defines custom mechanism like this:
310+ /// ```c
311+ /// #define CKM_SOME_CUSTOM_MECH (CKM_VENDOR_DEFINED | 0x00000001UL)
312+ /// ```
313+ ///
314+ /// It maps to
315+ /// ```rust
316+ /// pub const CKM_SOME_CUSTOM_MECH: MechanismType =
317+ /// MechanismType::new_vendor_defined(0x00000001);
318+ /// ```
319+ pub const fn new_vendor_defined ( adding : u64 ) -> MechanismType {
320+ MechanismType {
321+ val : CKM_VENDOR_DEFINED | adding,
322+ }
323+ }
324+
301325 pub ( crate ) fn stringify ( mech : CK_MECHANISM_TYPE ) -> String {
302326 match mech {
303327 CKM_RSA_PKCS_KEY_PAIR_GEN => String :: from ( stringify ! ( CKM_RSA_PKCS_KEY_PAIR_GEN ) ) ,
@@ -937,6 +961,9 @@ pub enum Mechanism<'a> {
937961 HkdfDerive ( hkdf:: HkdfParams < ' a > ) ,
938962 /// HKDF-DATA mechanism
939963 HkdfData ( hkdf:: HkdfParams < ' a > ) ,
964+
965+ /// Vendor defined mechanism
966+ VendorDefined ( VendorDefinedMechanism < ' a > ) ,
940967}
941968
942969impl Mechanism < ' _ > {
@@ -1008,6 +1035,10 @@ impl Mechanism<'_> {
10081035 Mechanism :: HkdfKeyGen => MechanismType :: HKDF_KEY_GEN ,
10091036 Mechanism :: HkdfDerive ( _) => MechanismType :: HKDF_DERIVE ,
10101037 Mechanism :: HkdfData ( _) => MechanismType :: HKDF_DATA ,
1038+
1039+ Mechanism :: VendorDefined ( vm) => MechanismType {
1040+ val : vm. inner . mechanism ,
1041+ } ,
10111042 }
10121043 }
10131044}
@@ -1087,6 +1118,8 @@ impl From<&Mechanism<'_>> for CK_MECHANISM {
10871118 pParameter : null_mut ( ) ,
10881119 ulParameterLen : 0 ,
10891120 } ,
1121+ // Vendor defined mechanisms
1122+ Mechanism :: VendorDefined ( vm) => vm. inner ,
10901123 }
10911124 }
10921125}
0 commit comments