3
3
//! Data types for mechanisms
4
4
5
5
pub mod aead;
6
+ pub mod ekdf;
6
7
pub mod elliptic_curve;
7
8
mod mechanism_info;
8
9
pub mod rsa;
9
- pub mod ekdf;
10
10
11
11
use crate :: error:: Error ;
12
12
use cryptoki_sys:: * ;
@@ -17,8 +17,8 @@ use std::fmt::Formatter;
17
17
use std:: ops:: Deref ;
18
18
use std:: ptr:: null_mut;
19
19
20
+ use crate :: mechanism:: rsa:: PkcsOaepParams ;
20
21
pub use mechanism_info:: MechanismInfo ;
21
- use crate :: mechanism:: rsa:: { PkcsOaepParams , PkcsOaepSource } ;
22
22
23
23
#[ derive( Copy , Debug , Clone , PartialEq , Eq ) ]
24
24
// transparent so that a vector of MechanismType should have the same layout than a vector of
@@ -67,7 +67,9 @@ impl MechanismType {
67
67
pub const AES_GCM : MechanismType = MechanismType { val : CKM_AES_GCM } ;
68
68
69
69
/// Derivation via encryption
70
- pub const AES_CBC_ENCRYPT_DATA : MechanismType = MechanismType { val : CKM_AES_CBC_ENCRYPT_DATA } ;
70
+ pub const AES_CBC_ENCRYPT_DATA : MechanismType = MechanismType {
71
+ val : CKM_AES_CBC_ENCRYPT_DATA ,
72
+ } ;
71
73
72
74
// RSA
73
75
/// PKCS #1 RSA key pair generation mechanism
@@ -247,8 +249,8 @@ impl MechanismType {
247
249
val : CKM_SHA512_RSA_PKCS_PSS ,
248
250
} ;
249
251
/// GENERIC-SECRET-KEY-GEN mechanism
250
- pub const GENERIC_SECRET_KEY_GEN : MechanismType = MechanismType {
251
- val : CKM_GENERIC_SECRET_KEY_GEN
252
+ pub const GENERIC_SECRET_KEY_GEN : MechanismType = MechanismType {
253
+ val : CKM_GENERIC_SECRET_KEY_GEN ,
252
254
} ;
253
255
254
256
pub ( crate ) fn stringify ( mech : CK_MECHANISM_TYPE ) -> String {
@@ -706,7 +708,7 @@ pub enum Mechanism<'a> {
706
708
/// derivation of keys using the result of an encryption operation as the key value.
707
709
///
708
710
/// For derivation, the message length must be a multiple of the block
709
- /// size. See https://www.cryptsoft.com/pkcs11doc/v220/
711
+ /// size. See < https://www.cryptsoft.com/pkcs11doc/v220/>.
710
712
AesCbcEncryptData ( ekdf:: AesCbcDeriveParams < ' a > ) ,
711
713
712
714
// RSA
@@ -837,7 +839,7 @@ pub enum Mechanism<'a> {
837
839
Sha512RsaPkcsPss ( rsa:: PkcsPssParams ) ,
838
840
839
841
/// GENERIC-SECRET-KEY-GEN mechanism
840
- GenericSecretKeyGen
842
+ GenericSecretKeyGen ,
841
843
}
842
844
843
845
impl Mechanism < ' _ > {
@@ -851,7 +853,7 @@ impl Mechanism<'_> {
851
853
Mechanism :: AesKeyWrap => MechanismType :: AES_KEY_WRAP ,
852
854
Mechanism :: AesKeyWrapPad => MechanismType :: AES_KEY_WRAP_PAD ,
853
855
Mechanism :: AesGcm ( _) => MechanismType :: AES_GCM ,
854
- Mechanism :: AesCbcEncryptData ( _) =>MechanismType :: AES_CBC_ENCRYPT_DATA ,
856
+ Mechanism :: AesCbcEncryptData ( _) => MechanismType :: AES_CBC_ENCRYPT_DATA ,
855
857
Mechanism :: RsaPkcsKeyPairGen => MechanismType :: RSA_PKCS_KEY_PAIR_GEN ,
856
858
Mechanism :: RsaPkcs => MechanismType :: RSA_PKCS ,
857
859
Mechanism :: RsaPkcsPss ( _) => MechanismType :: RSA_PKCS_PSS ,
@@ -897,7 +899,7 @@ impl Mechanism<'_> {
897
899
Mechanism :: Sha384RsaPkcsPss ( _) => MechanismType :: SHA384_RSA_PKCS_PSS ,
898
900
Mechanism :: Sha512RsaPkcsPss ( _) => MechanismType :: SHA512_RSA_PKCS_PSS ,
899
901
900
- Mechanism :: GenericSecretKeyGen => MechanismType :: GENERIC_SECRET_KEY_GEN
902
+ Mechanism :: GenericSecretKeyGen => MechanismType :: GENERIC_SECRET_KEY_GEN ,
901
903
}
902
904
}
903
905
}
@@ -907,13 +909,10 @@ impl From<&Mechanism<'_>> for CK_MECHANISM {
907
909
let mechanism = mech. mechanism_type ( ) . into ( ) ;
908
910
match mech {
909
911
// Mechanisms with parameters
910
- Mechanism :: AesCbc ( params)
911
- | Mechanism :: AesCbcPad ( params) => {
912
+ Mechanism :: AesCbc ( params) | Mechanism :: AesCbcPad ( params) => {
912
913
make_mechanism ( mechanism, params)
913
- } ,
914
- Mechanism :: AesCbcEncryptData ( params) => {
915
- make_mechanism ( mechanism, params)
916
- } ,
914
+ }
915
+ Mechanism :: AesCbcEncryptData ( params) => make_mechanism ( mechanism, params) ,
917
916
Mechanism :: DesCbc ( params)
918
917
| Mechanism :: Des3Cbc ( params)
919
918
| Mechanism :: DesCbcPad ( params)
@@ -1021,7 +1020,7 @@ impl TryFrom<psa_crypto::types::algorithm::Algorithm> for Mechanism<'_> {
1021
1020
Ok ( Mechanism :: RsaPkcsOaep ( PkcsOaepParams :: new (
1022
1021
Mechanism :: try_from ( Algorithm :: from ( hash_alg) ) ?. mechanism_type ( ) ,
1023
1022
rsa:: PkcsMgfType :: from_psa_crypto_hash ( hash_alg) ?,
1024
- PkcsOaepSource :: empty ( ) ,
1023
+ rsa :: PkcsOaepSource :: empty ( ) ,
1025
1024
) ) )
1026
1025
}
1027
1026
alg => {
0 commit comments