Skip to content

Commit e8a2c4e

Browse files
authored
Merge pull request #563 from RobertDrazkowskiGL/calib-psa-cipher
[CryptoAuthLib provider] PsaCipherEncrypt and PsaCipherDecrypt implementation
2 parents 56d69c9 + ed63c4d commit e8a2c4e

File tree

10 files changed

+890
-37
lines changed

10 files changed

+890
-37
lines changed

e2e_tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ publish = false
1111

1212
[dependencies]
1313
serde = { version = "1.0.123", features = ["derive"] }
14-
parsec-client = { git = "https://github.com/parallaxsecond/parsec-client-rust", rev = "119664eac501c7f1d207f03905311a0634db13a6", features = ["testing", "spiffe-auth"] }
14+
parsec-client = { git = "https://github.com/parallaxsecond/parsec-client-rust", rev = "bf01a58fe20a65f6151fc32c7c6c9d09ae7b741f", features = ["testing", "spiffe-auth"] }
1515
log = "0.4.14"
1616
# Compatible version with crate rsa
1717
rand = "0.7.3"

e2e_tests/src/lib.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ use parsec_client::core::interface::operations::list_authenticators::Authenticat
4545
use parsec_client::core::interface::operations::list_keys::KeyInfo;
4646
use parsec_client::core::interface::operations::list_providers::ProviderInfo;
4747
use parsec_client::core::interface::operations::psa_algorithm::{
48-
Aead, AeadWithDefaultLengthTag, Algorithm, AsymmetricEncryption, AsymmetricSignature, Hash,
49-
KeyAgreement, RawKeyAgreement,
48+
Aead, AeadWithDefaultLengthTag, Algorithm, AsymmetricEncryption, AsymmetricSignature, Cipher,
49+
Hash, KeyAgreement, RawKeyAgreement,
5050
};
5151
use parsec_client::core::interface::operations::psa_key_attributes::{
5252
Attributes, EccFamily, Lifetime, Policy, Type, UsageFlags,
@@ -390,6 +390,19 @@ impl TestClient {
390390
self.import_key(key_name, attributes, data)
391391
}
392392

393+
/// Import an AES key.
394+
pub fn import_aes_key_cipher(
395+
&mut self,
396+
key_name: String,
397+
data: Vec<u8>,
398+
encryption_alg: Cipher,
399+
) -> Result<()> {
400+
let mut attributes = TestClient::default_encrypt_aes_attrs();
401+
attributes.bits = 0;
402+
attributes.policy.permitted_algorithms = encryption_alg.into();
403+
self.import_key(key_name, attributes, data)
404+
}
405+
393406
/// Import ECC key pair with secp R1 curve family.
394407
/// The key can only be used for key agreement with Ecdh algorithm.
395408
pub fn import_ecc_pair_secp_r1_key(&mut self, key_name: String, data: Vec<u8>) -> Result<()> {
@@ -762,6 +775,28 @@ impl TestClient {
762775
.map_err(convert_error)
763776
}
764777

778+
pub fn cipher_encrypt_message(
779+
&mut self,
780+
key_name: String,
781+
alg: Cipher,
782+
plaintext: &[u8],
783+
) -> Result<Vec<u8>> {
784+
self.basic_client
785+
.psa_cipher_encrypt(key_name, alg, plaintext)
786+
.map_err(convert_error)
787+
}
788+
789+
pub fn cipher_decrypt_message(
790+
&mut self,
791+
key_name: String,
792+
alg: Cipher,
793+
ciphertext: &[u8],
794+
) -> Result<Vec<u8>> {
795+
self.basic_client
796+
.psa_cipher_decrypt(key_name, alg, ciphertext)
797+
.map_err(convert_error)
798+
}
799+
765800
pub fn hash_compute(&mut self, alg: Hash, input: &[u8]) -> Result<Vec<u8>> {
766801
self.basic_client
767802
.psa_hash_compute(alg, input)

0 commit comments

Comments
 (0)