Skip to content

Commit

Permalink
chore: remove dependency on psa-crypto
Browse files Browse the repository at this point in the history
Fix #100
  • Loading branch information
hug-dev committed Dec 22, 2024
1 parent c45a81b commit ed995eb
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 149 deletions.
82 changes: 0 additions & 82 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions cryptoki/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ rust-version = "1.66.0"
bitflags = "1.3"
libloading = "0.7.0"
log = "0.4.14"
psa-crypto = { version = "0.12.0", default-features = false, optional = true }
cryptoki-sys = { path = "../cryptoki-sys", version = "0.2.0" }
paste = "1.0.6"
secrecy = "0.8.0"
Expand All @@ -28,6 +27,5 @@ serial_test = "0.5.1"
testresult = "0.4.1"

[features]
psa-crypto-conversions = ["psa-crypto"]
generate-bindings = ["cryptoki-sys/generate-bindings"]
serde = ["secrecy/serde"]
44 changes: 0 additions & 44 deletions cryptoki/src/mechanism/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,47 +1140,3 @@ fn make_mechanism<T>(mechanism: CK_MECHANISM_TYPE, param: &T) -> CK_MECHANISM {
.expect("usize can not fit in CK_ULONG"),
}
}

#[cfg(feature = "psa-crypto-conversions")]
#[allow(deprecated)]
impl TryFrom<psa_crypto::types::algorithm::Algorithm> for Mechanism<'_> {
type Error = Error;

fn try_from(alg: psa_crypto::types::algorithm::Algorithm) -> Result<Self, Self::Error> {
use psa_crypto::types::algorithm::{
Algorithm, AsymmetricEncryption, AsymmetricSignature, Hash, SignHash,
};

match alg {
Algorithm::Hash(Hash::Sha1) => Ok(Mechanism::Sha1),
Algorithm::Hash(Hash::Sha256) => Ok(Mechanism::Sha256),
Algorithm::Hash(Hash::Sha384) => Ok(Mechanism::Sha384),
Algorithm::Hash(Hash::Sha512) => Ok(Mechanism::Sha512),
Algorithm::AsymmetricSignature(AsymmetricSignature::RsaPkcs1v15Sign { .. })
| Algorithm::AsymmetricEncryption(AsymmetricEncryption::RsaPkcs1v15Crypt { .. }) => {
Ok(Mechanism::RsaPkcs)
}
Algorithm::AsymmetricSignature(AsymmetricSignature::RsaPss {
hash_alg: SignHash::Specific(hash_alg),
}) => Ok(Mechanism::RsaPkcsPss(rsa::PkcsPssParams {
hash_alg: Mechanism::try_from(Algorithm::from(hash_alg))?.mechanism_type(),
mgf: rsa::PkcsMgfType::from_psa_crypto_hash(hash_alg)?,
s_len: hash_alg.hash_length().try_into()?,
})),
Algorithm::AsymmetricSignature(AsymmetricSignature::Ecdsa { .. }) => {
Ok(Mechanism::Ecdsa)
}
Algorithm::AsymmetricEncryption(AsymmetricEncryption::RsaOaep { hash_alg }) => {
Ok(Mechanism::RsaPkcsOaep(PkcsOaepParams::new(
Mechanism::try_from(Algorithm::from(hash_alg))?.mechanism_type(),
rsa::PkcsMgfType::from_psa_crypto_hash(hash_alg)?,
rsa::PkcsOaepSource::empty(),
)))
}
alg => {
error!("{:?} is not a supported algorithm", alg);
Err(Error::NotSupported)
}
}
}
}
21 changes: 0 additions & 21 deletions cryptoki/src/mechanism/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,24 +185,3 @@ impl<'a> From<PkcsOaepParams<'a>> for Mechanism<'a> {
Mechanism::RsaPkcsOaep(pkcs_oaep_params)
}
}

#[cfg(feature = "psa-crypto-conversions")]
#[allow(deprecated)]
impl PkcsMgfType {
/// Convert a PSA Crypto Hash algorithm to a MGF type
pub fn from_psa_crypto_hash(alg: psa_crypto::types::algorithm::Hash) -> Result<Self> {
use psa_crypto::types::algorithm::Hash;

match alg {
Hash::Sha1 => Ok(PkcsMgfType::MGF1_SHA1),
Hash::Sha224 => Ok(PkcsMgfType::MGF1_SHA224),
Hash::Sha256 => Ok(PkcsMgfType::MGF1_SHA256),
Hash::Sha384 => Ok(PkcsMgfType::MGF1_SHA384),
Hash::Sha512 => Ok(PkcsMgfType::MGF1_SHA512),
alg => {
error!("{:?} is not a supported MGF1 algorithm", alg);
Err(Error::NotSupported)
}
}
}
}

0 comments on commit ed995eb

Please sign in to comment.