Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cas-lib"
version = "0.2.53"
version = "0.2.54"
edition = "2021"
description = "Core lib for CAS"
license = "Apache-2.0"
Expand Down
32 changes: 16 additions & 16 deletions src/asymmetric/cas_rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use super::types::{CASRSAEncryption, RSAKeyPairResult};
pub struct CASRSA;

impl CASRSAEncryption for CASRSA {
// Generates an RSA key pair of the specified size.
// The key size must be at of a supported kind like 1024, 2048, 4096 bits.
/// Generates an RSA key pair of the specified size.
/// The key size must be at of a supported kind like 1024, 2048, 4096 bits.
fn generate_rsa_keys(key_size: usize) -> RSAKeyPairResult {
// TODO: do a check for key_size, if it is too small, return an error
let mut rng: OsRng = OsRng;
Expand All @@ -34,8 +34,8 @@ impl CASRSAEncryption for CASRSA {
result
}

// Generates an RSA key pair of the specified size on the threadpool.
// The key size must be at of a supported kind like 1024, 2048, 4096 bits.
/// Generates an RSA key pair of the specified size on the threadpool.
/// The key size must be at of a supported kind like 1024, 2048, 4096 bits.
fn generate_rsa_keys_threadpool(key_size: usize) -> RSAKeyPairResult {
let (sender, receiver) = mpsc::channel();
rayon::spawn(move || {
Expand All @@ -46,8 +46,8 @@ impl CASRSAEncryption for CASRSA {
thread_result
}

// Sign the given hash with the provided private key of the RSA key pair.
// The parameter `hash` doesn't necessarily have to be a hash, it can be any data that you want to sign.
/// Sign the given hash with the provided private key of the RSA key pair.
/// The parameter `hash` doesn't necessarily have to be a hash, it can be any data that you want to sign.
fn sign(private_key: String, hash: Vec<u8>) -> Vec<u8> {
let private_key = RsaPrivateKey::from_pkcs8_pem(&private_key).unwrap();
let signed_data = private_key
Expand All @@ -56,10 +56,10 @@ impl CASRSAEncryption for CASRSA {
signed_data
}

// Sign the given hash with the provided private key of the RSA key pair on the threadpool.
// The parameter `hash` doesn't necessarily have to be a hash, it can be any data that you want to sign.
// Returns the signed data as a byte vector.
// This is useful for signing data in a non-blocking way.
/// Sign the given hash with the provided private key of the RSA key pair on the threadpool.
/// The parameter `hash` doesn't necessarily have to be a hash, it can be any data that you want to sign.
/// Returns the signed data as a byte vector.
/// This is useful for signing data in a non-blocking way.
fn sign_threadpool(private_key: String, hash: Vec<u8>) -> Vec<u8> {
let (sender, receiver) = mpsc::channel();
rayon::spawn(move || {
Expand All @@ -70,9 +70,9 @@ impl CASRSAEncryption for CASRSA {
signed_data
}

// Verify the signature of the given hash with the provided public key of the RSA key pair.
// The parameter `hash` doesn't necessarily have to be a hash, it can be any data that you want to verify.
// Returns true if the signature is valid, false otherwise.
/// Verify the signature of the given hash with the provided public key of the RSA key pair.
/// The parameter `hash` doesn't necessarily have to be a hash, it can be any data that you want to verify.
/// Returns true if the signature is valid, false otherwise.
fn verify(public_key: String, hash: Vec<u8>, signature: Vec<u8>) -> bool {
let public_key = RsaPublicKey::from_pkcs1_pem(&public_key).unwrap();
let verified = public_key.verify(Pkcs1v15Sign::new_unprefixed(), &hash, &signature);
Expand All @@ -83,9 +83,9 @@ impl CASRSAEncryption for CASRSA {
}
}

// Verify the signature of the given hash with the provided public key of the RSA key pair on the threadpool.
// The parameter `hash` doesn't necessarily have to be a hash, it can be any data that you want to verify.
// Returns true if the signature is valid, false otherwise.
/// Verify the signature of the given hash with the provided public key of the RSA key pair on the threadpool.
/// The parameter `hash` doesn't necessarily have to be a hash, it can be any data that you want to verify.
/// Returns true if the signature is valid, false otherwise.
fn verify_threadpool(public_key: String, hash: Vec<u8>, signed_text: Vec<u8>) -> bool {
let (sender, receiver) = mpsc::channel();
rayon::spawn(move || {
Expand Down
8 changes: 4 additions & 4 deletions src/symmetric/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ pub struct CASAES256;

impl CASAES256Encryption for CASAES256 {

// Generates an AES256 key from a vector
/// Generates an AES256 key from a vector
fn key_from_vec(key_slice: Vec<u8>) -> Vec<u8> {
let result = Key::<Aes256Gcm>::from_slice(&key_slice).to_vec();
result
}

// Generates an AES256 key from a vector on the threadpool
/// Generates an AES256 key from a vector on the threadpool
fn key_from_vec_threadpool(key_slice: Vec<u8>) -> Vec<u8> {
let (sender, receiver) = mpsc::channel();
rayon::spawn(move || {
Expand Down Expand Up @@ -137,13 +137,13 @@ impl CASAES256Encryption for CASAES256 {

impl CASAES128Encryption for CASAES128 {

// Generates an AES128 key from a vector
/// Generates an AES128 key from a vector
fn key_from_vec(key_slice: Vec<u8>) -> Vec<u8> {
let result = Key::<Aes128Gcm>::from_slice(&key_slice).to_vec();
result
}

// Generates an AES128 key from a vector on the threadpool
/// Generates an AES128 key from a vector on the threadpool
fn key_from_vec_threadpool(key_slice: Vec<u8>) -> Vec<u8> {
let (sender, receiver) = mpsc::channel();
rayon::spawn(move || {
Expand Down