Skip to content

Commit

Permalink
Add SHAn-RSA-PKCS-PSS mechanisms
Browse files Browse the repository at this point in the history
Signed-off-by: Ionut Mihalcea <[email protected]>
  • Loading branch information
ionut-arm committed Jan 27, 2022
1 parent e9aa3bd commit 0bf210a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
39 changes: 38 additions & 1 deletion cryptoki/src/mechanism/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ impl MechanismType {
val: CKM_SHA512_RSA_PKCS,
};

// SHAn-RSA-PKCS-PSS
/// SHA1-RSA-PKCS-PSS mechanism
pub const SHA1_RSA_PKCS_PSS: MechanismType = MechanismType {
val: CKM_SHA1_RSA_PKCS_PSS,
};
/// SHA256-RSA-PKCS-PSS mechanism
pub const SHA256_RSA_PKCS_PSS: MechanismType = MechanismType {
val: CKM_SHA256_RSA_PKCS_PSS,
};
/// SHA384-RSA-PKCS-PSS mechanism
pub const SHA384_RSA_PKCS_PSS: MechanismType = MechanismType {
val: CKM_SHA384_RSA_PKCS_PSS,
};
/// SHA512-RSA-PKCS-PSS mechanism
pub const SHA512_RSA_PKCS_PSS: MechanismType = MechanismType {
val: CKM_SHA512_RSA_PKCS_PSS,
};

pub(crate) fn stringify(mech: CK_MECHANISM_TYPE) -> String {
match mech {
CKM_RSA_PKCS_KEY_PAIR_GEN => String::from(stringify!(CKM_RSA_PKCS_KEY_PAIR_GEN)),
Expand Down Expand Up @@ -575,6 +593,16 @@ pub enum Mechanism {
Sha384RsaPkcs,
/// SHA512-RSA-PKCS mechanism
Sha512RsaPkcs,

// SHAn-RSA-PKCS-PSS
/// SHA1-RSA-PKCS-PSS mechanism
Sha1RsaPkcsPss(rsa::PkcsPssParams),
/// SHA256-RSA-PKCS-PSS mechanism
Sha256RsaPkcsPss(rsa::PkcsPssParams),
/// SHA256-RSA-PKCS-PSS mechanism
Sha384RsaPkcsPss(rsa::PkcsPssParams),
/// SHA256-RSA-PKCS-PSS mechanism
Sha512RsaPkcsPss(rsa::PkcsPssParams),
}

impl Mechanism {
Expand Down Expand Up @@ -605,6 +633,11 @@ impl Mechanism {
Mechanism::Sha256RsaPkcs => MechanismType::SHA256_RSA_PKCS,
Mechanism::Sha384RsaPkcs => MechanismType::SHA384_RSA_PKCS,
Mechanism::Sha512RsaPkcs => MechanismType::SHA512_RSA_PKCS,

Mechanism::Sha1RsaPkcsPss(_) => MechanismType::SHA1_RSA_PKCS_PSS,
Mechanism::Sha256RsaPkcsPss(_) => MechanismType::SHA256_RSA_PKCS_PSS,
Mechanism::Sha384RsaPkcsPss(_) => MechanismType::SHA384_RSA_PKCS_PSS,
Mechanism::Sha512RsaPkcsPss(_) => MechanismType::SHA512_RSA_PKCS_PSS,
}
}
}
Expand All @@ -613,7 +646,11 @@ impl From<&Mechanism> for CK_MECHANISM {
fn from(mech: &Mechanism) -> Self {
let mechanism = mech.mechanism_type().into();
match mech {
Mechanism::RsaPkcsPss(params) => CK_MECHANISM {
Mechanism::RsaPkcsPss(params)
| Mechanism::Sha1RsaPkcsPss(params)
| Mechanism::Sha256RsaPkcsPss(params)
| Mechanism::Sha384RsaPkcsPss(params)
| Mechanism::Sha512RsaPkcsPss(params) => CK_MECHANISM {
mechanism,
pParameter: params as *const _ as *mut c_void,
ulParameterLen: std::mem::size_of::<CK_RSA_PKCS_PSS_PARAMS>()
Expand Down
6 changes: 0 additions & 6 deletions cryptoki/src/mechanism/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,6 @@ pub struct PkcsPssParams {
pub s_len: Ulong,
}

impl From<PkcsPssParams> for Mechanism {
fn from(pkcs_pss_params: PkcsPssParams) -> Self {
Mechanism::RsaPkcsPss(pkcs_pss_params)
}
}

/// Parameters of the RsaPkcsOaep mechanism
#[derive(Copy, Debug, Clone)]
#[repr(C)]
Expand Down

0 comments on commit 0bf210a

Please sign in to comment.