diff --git a/.github/workflows/linux-pr.yml b/.github/workflows/linux-pr.yml index 0f4cd14..b8a6b5d 100644 --- a/.github/workflows/linux-pr.yml +++ b/.github/workflows/linux-pr.yml @@ -17,4 +17,4 @@ jobs: - name: Build run: cargo build --release --verbose - name: Run tests - run: cargo test --verbose + run: cargo test --release --verbose diff --git a/.github/workflows/windows-pr.yml b/.github/workflows/windows-pr.yml index d147eba..6ee5b0c 100644 --- a/.github/workflows/windows-pr.yml +++ b/.github/workflows/windows-pr.yml @@ -17,4 +17,4 @@ jobs: - name: Build run: cargo build --release --verbose - name: Run tests - run: cargo test --verbose + run: cargo test --release --verbose diff --git a/Cargo.toml b/Cargo.toml index fa6a791..bc0fa37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cas-lib" -version = "0.2.56" +version = "0.2.57" edition = "2021" description = "Core lib for CAS" license = "Apache-2.0" @@ -23,7 +23,6 @@ scrypt = "0.11.0" sha3 = "0.10.8" x25519-dalek = {version = "2.0.0", features = ["static_secrets"]} ascon-aead = "0.5.1" -rayon = "1.10.0" hmac = "0.12.1" sha2 = "0.10.8" zstd = "0.13" diff --git a/src/asymmetric/cas_rsa.rs b/src/asymmetric/cas_rsa.rs index 5d121f2..16e0b7e 100644 --- a/src/asymmetric/cas_rsa.rs +++ b/src/asymmetric/cas_rsa.rs @@ -1,5 +1,3 @@ -use std::sync::mpsc; - use rand::rngs::OsRng; use rsa::{ pkcs1::{DecodeRsaPublicKey, EncodeRsaPublicKey}, @@ -34,18 +32,6 @@ 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. - fn generate_rsa_keys_threadpool(key_size: usize) -> RSAKeyPairResult { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let thread_result = Self::generate_rsa_keys(key_size); - sender.send(thread_result).unwrap(); - }); - let thread_result: RSAKeyPairResult = receiver.recv().unwrap(); - 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. fn sign(private_key: String, hash: Vec) -> Vec { @@ -56,19 +42,6 @@ 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. - fn sign_threadpool(private_key: String, hash: Vec) -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let signed_data = Self::sign(private_key, hash); - sender.send(signed_data).unwrap(); - }); - let signed_data = receiver.recv().unwrap(); - 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. @@ -82,17 +55,4 @@ impl CASRSAEncryption for CASRSA { return false; } } - - /// 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, signed_text: Vec) -> bool { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let verified = Self::verify(public_key, hash, signed_text); - sender.send(verified).unwrap(); - }); - let verified = receiver.recv().unwrap(); - verified - } } \ No newline at end of file diff --git a/src/asymmetric/types.rs b/src/asymmetric/types.rs index 8c9c0d2..d25f7ef 100644 --- a/src/asymmetric/types.rs +++ b/src/asymmetric/types.rs @@ -5,9 +5,6 @@ pub struct RSAKeyPairResult { pub trait CASRSAEncryption { fn generate_rsa_keys(key_size: usize) -> RSAKeyPairResult; - fn generate_rsa_keys_threadpool(key_size: usize) -> RSAKeyPairResult; fn sign(private_key: String, hash: Vec) -> Vec; - fn sign_threadpool(private_key: String, hash: Vec) -> Vec; fn verify(public_key: String, hash: Vec, signed_text: Vec) -> bool; - fn verify_threadpool(public_key: String, hash: Vec, signed_text: Vec) -> bool; } \ No newline at end of file diff --git a/src/compression/zstd.rs b/src/compression/zstd.rs index b982476..3c98b90 100644 --- a/src/compression/zstd.rs +++ b/src/compression/zstd.rs @@ -1,4 +1,4 @@ -use std::{io::Cursor, sync::mpsc}; +use std::io::Cursor; /// Compresses data using Zstandard compression algorithm. /// The `level` parameter controls the compression level (0-22). @@ -10,34 +10,10 @@ pub fn compress(data_to_compress: Vec, level: i32) -> Vec { compressed_data } -/// Compresses data using Zstandard compression algorithm on the threadpool. -/// The `level` parameter controls the compression level (0-22). -/// Higher levels result in better compression but slower performance. -pub fn compress_threadpool(data_to_compress: Vec, level: i32) -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let compressed_data = compress(data_to_compress, level); - sender.send(compressed_data).unwrap(); - }); - let result = receiver.recv().unwrap(); - result -} - /// Decompresses data using Zstandard decompression algorithm. pub fn decompress(data_to_decompress: Vec) -> Vec { let mut cursor = Cursor::new(data_to_decompress); let mut decompressed_data = Vec::new(); zstd::stream::copy_decode(&mut cursor, &mut decompressed_data).unwrap(); decompressed_data -} - -/// Decompresses data using Zstandard decompression algorithm on the threadpool. -pub fn decompress_threadpool(data_to_decompress: Vec) -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let decompressed_data = decompress(data_to_decompress); - sender.send(decompressed_data).unwrap(); - }); - let result = receiver.recv().unwrap(); - result -} +} \ No newline at end of file diff --git a/src/digital_signature/cas_digital_signature_rsa.rs b/src/digital_signature/cas_digital_signature_rsa.rs index 0dc19f9..f9f220f 100644 --- a/src/digital_signature/cas_digital_signature_rsa.rs +++ b/src/digital_signature/cas_digital_signature_rsa.rs @@ -9,15 +9,11 @@ pub struct SHAED25519DalekDigitalSignatureResult { } pub trait RSADigitalSignature { - fn digital_signature_rsa(rsa_key_size: u32, data_to_sign: Vec) -> RSADigitalSignatureResult; - fn digital_signature_rsa_threadpool(rsa_key_size: u32, data_to_sign: Vec) -> RSADigitalSignatureResult; + fn digital_signature_rsa(rsa_key_size: u32, data_to_sign: Vec) -> RSADigitalSignatureResult; fn verify_rsa(public_key: String, data_to_verify: Vec, signature: Vec) -> bool; - fn verify_rsa_threadpool(public_key: String, data_to_verify: Vec, signature: Vec) -> bool; } pub trait ED25519DigitalSignature { fn digital_signature_ed25519(data_to_sign: Vec) -> SHAED25519DalekDigitalSignatureResult; - fn digital_signature_ed25519_threadpool(data_to_sign: Vec) -> SHAED25519DalekDigitalSignatureResult; fn digital_signature_ed25519_verify(public_key: Vec, data_to_verify: Vec, signature: Vec) -> bool; - fn digital_signature_ed25519_verify_threadpool(public_key: Vec, data_to_verify: Vec, signature: Vec) -> bool; } \ No newline at end of file diff --git a/src/digital_signature/sha_256_ed25519.rs b/src/digital_signature/sha_256_ed25519.rs index ef30571..0bf55d4 100644 --- a/src/digital_signature/sha_256_ed25519.rs +++ b/src/digital_signature/sha_256_ed25519.rs @@ -1,4 +1,4 @@ -use std::sync::mpsc; + use sha3::{Digest, Sha3_256}; @@ -38,26 +38,4 @@ impl ED25519DigitalSignature for SHA256ED25519DigitalSignature { let sha_hash_bytes = sha_hasher_result.to_vec(); return ed25519_verify_with_public_key(public_key, signature, sha_hash_bytes); } - - /// Creates a digital signature using SHA-256 as the hashing algorithm and Ed25519-Dalek as the signing algorithm on the threadpool. - fn digital_signature_ed25519_threadpool(data_to_sign: Vec) -> SHAED25519DalekDigitalSignatureResult { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = Self::digital_signature_ed25519(data_to_sign); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } - - /// Verifys a digital signature using SHA-256 as the hashing algorithm and Ed25519-Dalek as the verification algorithm on the threadpool. - fn digital_signature_ed25519_verify_threadpool(public_key: Vec, data_to_verify: Vec, signature: Vec) -> bool { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = Self::digital_signature_ed25519_verify(public_key, data_to_verify, signature); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } } diff --git a/src/digital_signature/sha_256_rsa.rs b/src/digital_signature/sha_256_rsa.rs index 17a1613..aa5c9b6 100644 --- a/src/digital_signature/sha_256_rsa.rs +++ b/src/digital_signature/sha_256_rsa.rs @@ -1,4 +1,4 @@ -use std::sync::mpsc; + use rand::rngs::OsRng; use rsa::{ @@ -43,17 +43,6 @@ impl RSADigitalSignature for SHA256RSADigitalSignature { result } - /// Creates a digital signature using SHA-256 as the hashing algorithm and RSA as the signing algorithm on the threadpool. - fn digital_signature_rsa_threadpool(rsa_key_size: u32, data_to_sign: Vec) -> RSADigitalSignatureResult { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ::digital_signature_rsa(rsa_key_size, data_to_sign); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } - /// Verifys a digital signature using SHA-256 as the hashing algorithm and RSA as the verification algorithm. /// The public key is expected to be in PEM format. fn verify_rsa(public_key: String, data_to_verify: Vec, signature: Vec) -> bool { @@ -72,16 +61,4 @@ impl RSADigitalSignature for SHA256RSADigitalSignature { return false; } } - - /// Verifys a digital signature using SHA-256 as the hashing algorithm and RSA as the verification algorithm on the threadpool. - /// The public key is expected to be in PEM format. - fn verify_rsa_threadpool(public_key: String, data_to_verify: Vec, signature: Vec) -> bool { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ::verify_rsa(public_key, data_to_verify, signature); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } } \ No newline at end of file diff --git a/src/digital_signature/sha_512_ed25519.rs b/src/digital_signature/sha_512_ed25519.rs index 34b4f8e..477d84d 100644 --- a/src/digital_signature/sha_512_ed25519.rs +++ b/src/digital_signature/sha_512_ed25519.rs @@ -1,4 +1,4 @@ -use std::sync::mpsc; + use sha3::{Digest, Sha3_512}; @@ -41,26 +41,4 @@ impl ED25519DigitalSignature for SHA512ED25519DigitalSignature { let sha_hash_bytes = sha_hasher_result.to_vec(); return ed25519_verify_with_public_key(public_key, signature, sha_hash_bytes); } - - /// Creates a digital signature using SHA-512 as the hashing algorithm and Ed25519-Dalek as the signing algorithm on the threadpool. - fn digital_signature_ed25519_threadpool(data_to_sign: Vec) -> SHAED25519DalekDigitalSignatureResult { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ::digital_signature_ed25519(data_to_sign); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } - - /// Verifys a digital signature using SHA-512 as the hashing algorithm and Ed25519-Dalek as the verification algorithm on the threadpool. - fn digital_signature_ed25519_verify_threadpool(public_key: Vec, data_to_verify: Vec, signature: Vec) -> bool { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ::digital_signature_ed25519_verify(public_key, data_to_verify, signature); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } } \ No newline at end of file diff --git a/src/digital_signature/sha_512_rsa.rs b/src/digital_signature/sha_512_rsa.rs index 9169b74..b4bff74 100644 --- a/src/digital_signature/sha_512_rsa.rs +++ b/src/digital_signature/sha_512_rsa.rs @@ -1,5 +1,5 @@ -use std::sync::mpsc; + use rand::rngs::OsRng; use rsa::{ @@ -42,17 +42,6 @@ impl RSADigitalSignature for SHA512RSADigitalSignature { result } - /// Creates a digital signature using SHA-512 as the hashing algorithm and RSA as the signing algorithm on the threadpool. - fn digital_signature_rsa_threadpool(rsa_key_size: u32, data_to_sign: Vec) -> RSADigitalSignatureResult { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ::digital_signature_rsa(rsa_key_size, data_to_sign); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } - /// Verifys a digital signature using SHA-512 as the hashing algorithm and RSA as the verification algorithm. /// The public key is expected to be in PEM format. fn verify_rsa(public_key: String, data_to_verify: Vec, signature: Vec) -> bool { @@ -71,16 +60,4 @@ impl RSADigitalSignature for SHA512RSADigitalSignature { return false; } } - - /// Verifys a digital signature using SHA-512 as the hashing algorithm and RSA as the verification algorithm on the threadpool. - /// The public key is expected to be in PEM format. - fn verify_rsa_threadpool(public_key: String, data_to_verify: Vec, signature: Vec) -> bool { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ::verify_rsa(public_key, data_to_verify, signature); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } } \ No newline at end of file diff --git a/src/hashers/blake2.rs b/src/hashers/blake2.rs index 3442fc3..6784f95 100644 --- a/src/hashers/blake2.rs +++ b/src/hashers/blake2.rs @@ -1,4 +1,4 @@ -use std::sync::mpsc; + use super::cas_hasher::CASHasher; use blake2::{Blake2b512, Blake2s256, Digest}; @@ -41,52 +41,4 @@ impl CASHasher for CASBlake2 { let result = hasher.finalize(); return hash_to_verify.eq(&result.to_vec()); } - - /// Hashes data using the Blake2b-512 algorithm on the threadpool. - /// Returns the hash as a vector of bytes. - fn hash_512_threadpool(data_to_hash: Vec) -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ::hash_512(data_to_hash); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } - - /// Verifies a hash using the Blake2b-512 algorithm on the threadpool. - /// Returns true if the hash matches the data, false otherwise. - fn verify_512_threadpool(hash_to_verify: Vec, data_to_verify: Vec) -> bool { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ::verify_512(hash_to_verify, data_to_verify); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } - - /// Hashes data using the Blake2s-256 algorithm on the threadpool. - /// Returns the hash as a vector of bytes. - fn hash_256_threadpool(data_to_hash: Vec) -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ::hash_256(data_to_hash); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } - - /// Verifies a hash using the Blake2s-256 algorithm on the threadpool. - /// Returns true if the hash matches the data, false otherwise. - fn verify_256_threadpool(hash_to_verify: Vec, data_to_verify: Vec) -> bool { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ::verify_256(hash_to_verify, data_to_verify); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } } \ No newline at end of file diff --git a/src/hashers/cas_hasher.rs b/src/hashers/cas_hasher.rs index 41b15ac..3719eec 100644 --- a/src/hashers/cas_hasher.rs +++ b/src/hashers/cas_hasher.rs @@ -3,8 +3,4 @@ pub trait CASHasher { fn verify_512(hash_to_verify: Vec, data_to_verify: Vec) -> bool; fn hash_256(data_to_hash: Vec) -> Vec; fn verify_256(hash_to_verify: Vec, data_to_verify: Vec) -> bool; - fn hash_512_threadpool(data_to_hash: Vec) -> Vec; - fn verify_512_threadpool(hash_to_verify: Vec, data_to_verify: Vec) -> bool; - fn hash_256_threadpool(data_to_hash: Vec) -> Vec; - fn verify_256_threadpool(hash_to_verify: Vec, data_to_verify: Vec) -> bool; } diff --git a/src/hashers/sha.rs b/src/hashers/sha.rs index d68d810..8782324 100644 --- a/src/hashers/sha.rs +++ b/src/hashers/sha.rs @@ -1,4 +1,3 @@ -use std::sync::mpsc; use super::cas_hasher::CASHasher; use sha3::{Digest, Sha3_256, Sha3_512}; @@ -40,52 +39,4 @@ impl CASHasher for CASSHA { let result = hasher.finalize(); return hash_to_verify.eq(&result.to_vec()); } - - /// Hashes data using the SHA-512 algorithm on the threadpool. - /// Returns the hash as a vector of bytes. - fn hash_512_threadpool(data_to_hash: Vec) -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ::hash_512(data_to_hash); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } - - /// Verifies a hash using the SHA-512 algorithm on the threadpool. - /// Returns true if the hash matches the data, false otherwise. - fn verify_512_threadpool(hash_to_verify: Vec, data_to_verify: Vec) -> bool { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ::verify_512(hash_to_verify, data_to_verify); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } - - /// Hashes data using the SHA-256 algorithm on the threadpool. - /// Returns the hash as a vector of bytes. - fn hash_256_threadpool(data_to_hash: Vec) -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ::hash_256(data_to_hash); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } - - /// Verifies a hash using the SHA-256 algorithm on the threadpool. - /// Returns true if the hash matches the data, false otherwise. - fn verify_256_threadpool(hash_to_verify: Vec, data_to_verify: Vec) -> bool { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ::verify_256(hash_to_verify, data_to_verify); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } } \ No newline at end of file diff --git a/src/key_exchange/cas_key_exchange.rs b/src/key_exchange/cas_key_exchange.rs index dcee7a9..6348381 100644 --- a/src/key_exchange/cas_key_exchange.rs +++ b/src/key_exchange/cas_key_exchange.rs @@ -2,7 +2,5 @@ use super::x25519::X25519SecretPublicKeyResult; pub trait CASKeyExchange { fn generate_secret_and_public_key() -> X25519SecretPublicKeyResult; - fn generate_secret_and_public_key_threadpool() -> X25519SecretPublicKeyResult; fn diffie_hellman(my_secret_key: Vec, users_public_key: Vec) -> Vec; - fn diffie_hellman_threadpool(my_secret_key: Vec, users_public_key: Vec) -> Vec; } diff --git a/src/key_exchange/x25519.rs b/src/key_exchange/x25519.rs index 4f8bdc4..74e0dd0 100644 --- a/src/key_exchange/x25519.rs +++ b/src/key_exchange/x25519.rs @@ -1,4 +1,4 @@ -use std::sync::mpsc; + use rand::rngs::OsRng; use x25519_dalek::{PublicKey, StaticSecret}; @@ -39,32 +39,4 @@ impl CASKeyExchange for X25519 { let public_key = PublicKey::from(*users_public_key_box); return secret_key.diffie_hellman(&public_key).as_bytes().to_vec(); } - - /// Generates a secret key and public key using X25519 on the threadpool. - /// Returns a result containing the secret key and public key as vectors of bytes. - /// This function spawns a thread to perform the key generation. - /// Returns the result of the key generation. - fn generate_secret_and_public_key_threadpool() -> X25519SecretPublicKeyResult { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ::generate_secret_and_public_key(); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } - - /// Performs a Diffie-Hellman key exchange using the provided secret key and user's public key on the threadpool. - /// Returns the shared secret as a vector of bytes. - /// The shared secret is computed as the Diffie-Hellman result of the secret key and the user's public key. - /// The secret key and user's public key are expected to be in byte array format. - fn diffie_hellman_threadpool(my_secret_key: Vec, users_public_key: Vec) -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ::diffie_hellman(my_secret_key, users_public_key); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } } \ No newline at end of file diff --git a/src/message/cas_hmac.rs b/src/message/cas_hmac.rs index 1661e81..5849348 100644 --- a/src/message/cas_hmac.rs +++ b/src/message/cas_hmac.rs @@ -1,6 +1,4 @@ pub trait CASHMAC { fn sign(key: Vec, message: Vec) -> Vec; - fn sign_threadpool(key: Vec, message: Vec) -> Vec; fn verify(key: Vec, message: Vec, signature: Vec) -> bool; - fn verify_threadpool(key: Vec, message: Vec, signature: Vec) -> bool; } \ No newline at end of file diff --git a/src/message/hmac.rs b/src/message/hmac.rs index 3e8609a..c7fe6c7 100644 --- a/src/message/hmac.rs +++ b/src/message/hmac.rs @@ -1,4 +1,3 @@ -use std::sync::mpsc; use super::cas_hmac::CASHMAC; use hmac::{Hmac, Mac}; @@ -17,17 +16,7 @@ impl CASHMAC for HMAC { result } - /// Signs a message using HMAC with SHA-256 on the threadpool. - /// Returns the signature as a vector of bytes. - fn sign_threadpool(key: Vec, message: Vec) -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = Self::sign(key, message); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } + /// Verifies a signature using HMAC with SHA-256. /// Returns true if the signature is valid, false otherwise. @@ -37,15 +26,5 @@ impl CASHMAC for HMAC { return mac.verify_slice(&signature).is_ok(); } - /// Verifies a signature using HMAC with SHA-256 on the threadpool. - /// Returns true if the signature is valid, false otherwise. - fn verify_threadpool(key: Vec, message: Vec, signature: Vec) -> bool { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = Self::verify(key, message, signature); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } + } diff --git a/src/password_hashers/argon2.rs b/src/password_hashers/argon2.rs index 137ea5e..6ea96cc 100644 --- a/src/password_hashers/argon2.rs +++ b/src/password_hashers/argon2.rs @@ -1,8 +1,3 @@ - - - -use std::sync::mpsc; - use argon2::{ password_hash::{rand_core::OsRng, SaltString}, Argon2, PasswordHash, PasswordHasher, PasswordVerifier, @@ -58,33 +53,4 @@ impl CASArgon { .verify_password(password_to_verify.as_bytes(), &hashed_password) .is_ok(); } - - /// Hashes a password using Argon2 on the threadpool. - /// Returns the hashed password as a string. - /// This function spawns a thread to perform the hashing. - /// The password to hash is expected to be in string format. - /// Returns the hashed password. - pub fn hash_password_threadpool(password: String) -> String { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let hash = Self::hash_password(password); - sender.send(hash).unwrap(); - }); - let hash = receiver.recv().unwrap(); - hash - } - - /// Verifies a password against a hashed password using Argon2 on the threadpool. - /// Returns true if the password matches the hashed password, false otherwise. - /// This function spawns a thread to perform the verification. - /// The hashed password and password to verify are expected to be in string format. - pub fn verify_password_threadpool(hashed_password: String, password_to_verify: String) -> bool { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let hash = Self::verify_password(hashed_password, password_to_verify); - sender.send(hash).unwrap(); - }); - let hash = receiver.recv().unwrap(); - hash - } } \ No newline at end of file diff --git a/src/password_hashers/bcrypt.rs b/src/password_hashers/bcrypt.rs index 178aa97..2a1b576 100644 --- a/src/password_hashers/bcrypt.rs +++ b/src/password_hashers/bcrypt.rs @@ -1,4 +1,4 @@ -use std::sync::mpsc; + use bcrypt::{hash, verify, DEFAULT_COST}; @@ -18,28 +18,4 @@ impl CASPasswordHasher for CASBCrypt { fn verify_password(hashed_password: String, password_to_verify: String) -> bool { return verify(password_to_verify, &hashed_password).unwrap(); } - - /// Hashes a password using bcrypt on the threadpool. - /// Returns the hashed password as a string. - fn hash_password_threadpool(password: String) -> String { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let hash = Self::hash_password(password); - sender.send(hash).unwrap(); - }); - let hash = receiver.recv().unwrap(); - hash - } - - /// Verifies a password against a hashed password using bcrypt on the threadpool. - /// Returns true if the password matches the hashed password, false otherwise. - fn verify_password_threadpool(hashed_password: String, password_to_verify: String) -> bool { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let hash = Self::verify_password(hashed_password, password_to_verify); - sender.send(hash).unwrap(); - }); - let hash = receiver.recv().unwrap(); - hash - } } diff --git a/src/password_hashers/cas_password_hasher.rs b/src/password_hashers/cas_password_hasher.rs index dcd974c..48a4fff 100644 --- a/src/password_hashers/cas_password_hasher.rs +++ b/src/password_hashers/cas_password_hasher.rs @@ -1,8 +1,6 @@ pub trait CASPasswordHasher { fn hash_password(password_to_hash: String) -> String; - fn hash_password_threadpool(password: String) -> String; fn verify_password(hashed_password: String, password_to_verify: String) -> bool; - fn verify_password_threadpool(hashed_password: String, password_to_verify: String) -> bool; } pub struct Pbkdf2Result { diff --git a/src/password_hashers/scrypt.rs b/src/password_hashers/scrypt.rs index ee57d7e..6d84b72 100644 --- a/src/password_hashers/scrypt.rs +++ b/src/password_hashers/scrypt.rs @@ -1,4 +1,4 @@ -use std::sync::mpsc; + @@ -30,28 +30,4 @@ impl CASPasswordHasher for CASScrypt { .verify_password(password_to_verify.as_bytes(), &parsed_hash) .is_ok(); } - - /// Hashes a password using Scrypt on the threadpool. - /// Returns the hashed password as a string. - fn hash_password_threadpool(password: String) -> String { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let hash = Self::hash_password(password); - sender.send(hash).unwrap(); - }); - let hash = receiver.recv().unwrap(); - hash - } - - /// Verifies a password against a hashed password using Scrypt on the threadpool. - /// Returns true if the password matches the hashed password, false otherwise. - fn verify_password_threadpool(hashed_password: String, password_to_verify: String) -> bool { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let hash = Self::verify_password(hashed_password, password_to_verify); - sender.send(hash).unwrap(); - }); - let hash = receiver.recv().unwrap(); - hash - } } \ No newline at end of file diff --git a/src/signatures/ed25519.rs b/src/signatures/ed25519.rs index 3deb0db..97eeb14 100644 --- a/src/signatures/ed25519.rs +++ b/src/signatures/ed25519.rs @@ -1,7 +1,7 @@ extern crate ed25519_dalek; extern crate rand; -use std::sync::mpsc; + use ed25519_dalek::{Signer, SigningKey, VerifyingKey}; use ed25519_dalek::Signature; @@ -18,18 +18,6 @@ pub fn get_ed25519_key_pair() -> Vec { keypair_vec } -/// Generates a new Ed25519 key pair on the threadpool. -/// Returns the key pair as a vector of bytes. -pub fn get_ed25519_key_pair_threadpool() -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = get_ed25519_key_pair(); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result -} - /// Signs a message using the provided Ed25519 key pair. /// Returns the signature and public key as an Ed25519ByteSignature. pub fn ed25519_sign_with_key_pair(key_pair: Vec, message_to_sign: Vec) -> Ed25519ByteSignature { @@ -47,18 +35,6 @@ pub fn ed25519_sign_with_key_pair(key_pair: Vec, message_to_sign: Vec) - result } -/// Signs a message using the provided Ed25519 key pair on the threadpool. -/// Returns the signature and public key as an Ed25519ByteSignature. -pub fn ed25519_sign_with_key_pair_threadpool(key_pair: Vec, message_to_sign: Vec) -> Ed25519ByteSignature { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ed25519_sign_with_key_pair(key_pair, message_to_sign); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result -} - /// Verifies a signature using the provided Ed25519 key pair. /// Returns true if the signature is valid, false otherwise. /// The key pair is expected to be in byte array format. @@ -73,19 +49,6 @@ pub fn ed25519_verify_with_key_pair(key_pair: Vec, signature: Vec, messa return keypair.verify(&message, &signature).is_ok(); } -/// Verifies a signature using the provided Ed25519 key pair on the threadpool. -/// Returns true if the signature is valid, false otherwise. -/// The key pair is expected to be in byte array format. -pub fn ed25519_verify_with_key_pair_threadpool(key_pair: Vec, signature: Vec, message: Vec) -> bool { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ed25519_verify_with_key_pair(key_pair, signature, message); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result -} - /// Verifies a signature using the provided public key. /// Returns true if the signature is valid, false otherwise. /// The public key and signature are expected to be in byte array format. @@ -101,17 +64,4 @@ pub fn ed25519_verify_with_public_key(public_key: Vec, signature: Vec, m return verifying_key .verify_strict(&message, &signature_parsed) .is_ok(); -} - -/// Verifies a signature using the provided public key on the threadpool. -/// Returns true if the signature is valid, false otherwise. -/// The public key and signature are expected to be in byte array format. -pub fn ed25519_verify_with_public_key_threadpool(public_key: Vec, signature: Vec, message: Vec) -> bool { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = ed25519_verify_with_public_key(public_key, signature, message); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result } \ No newline at end of file diff --git a/src/sponges/ascon_aead.rs b/src/sponges/ascon_aead.rs index dbcca7b..e972cf9 100644 --- a/src/sponges/ascon_aead.rs +++ b/src/sponges/ascon_aead.rs @@ -1,5 +1,5 @@ -use std::sync::mpsc; + use aes_gcm::AeadCore; use ascon_aead::{aead::{generic_array::GenericArray, Aead, KeyInit, OsRng}, AsconAead128 as Ascon128}; @@ -20,20 +20,6 @@ impl CASAsconAead for AsconAead { ciphertext } - /// Encrypts with AscondAead on the threadpool - fn encrypt_threadpool(key: Vec, nonce: Vec, plaintext: Vec) -> Vec { - if key.len() != 16 || nonce.len() != 16 { - panic!("Key and nonce must be 16 bytes long"); - } - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let ciphertext = Self::encrypt(key, nonce, plaintext); - sender.send(ciphertext).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } - /// Decrypts with AscondAead fn decrypt(key: Vec, nonce: Vec, ciphertext: Vec) -> Vec { if key.len() != 16 || nonce.len() != 16 { @@ -45,50 +31,14 @@ impl CASAsconAead for AsconAead { let plaintext = cipher.decrypt(&nonce_generic_array, ciphertext.as_ref()).unwrap(); plaintext } - - /// Decrypts with AscondAead on the threadpool - fn decrypt_threadpool(key: Vec, nonce: Vec, ciphertext: Vec) -> Vec { - if key.len() != 16 || nonce.len() != 16 { - panic!("Key and nonce must be 16 bytes long"); - } - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let plaintext = Self::decrypt(key, nonce, ciphertext); - sender.send(plaintext).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } /// Generates a 16-byte key for Ascon Aead fn generate_key() -> Vec { return Ascon128::generate_key(&mut OsRng).to_vec(); } - - /// Generates a 16-byte key for Ascon Aead on the threadpool - fn generate_key_threadpool() -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let key = Self::generate_key(); - sender.send(key).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } /// Generates a Ascon Aead nonce fn generate_nonce() -> Vec { return Ascon128::generate_nonce(&mut OsRng).to_vec(); } - - /// Generates a Ascon Aead nonce on the threadpool - fn generate_nonce_threadpool() -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let key = ::generate_nonce(); - sender.send(key).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } } \ No newline at end of file diff --git a/src/sponges/cas_ascon_aead.rs b/src/sponges/cas_ascon_aead.rs index 30f5500..f41556e 100644 --- a/src/sponges/cas_ascon_aead.rs +++ b/src/sponges/cas_ascon_aead.rs @@ -1,10 +1,6 @@ pub trait CASAsconAead { fn generate_key() -> Vec; - fn generate_key_threadpool() -> Vec; fn generate_nonce() -> Vec; - fn generate_nonce_threadpool() -> Vec; fn encrypt(key: Vec, nonce: Vec, plaintext: Vec) -> Vec; - fn encrypt_threadpool(key: Vec, nonce: Vec, plaintext: Vec) -> Vec; fn decrypt(key: Vec, nonce: Vec, ciphertext: Vec) -> Vec; - fn decrypt_threadpool(key: Vec, nonce: Vec, ciphertext: Vec) -> Vec; } \ No newline at end of file diff --git a/src/symmetric/aes.rs b/src/symmetric/aes.rs index 036463b..5d971ae 100644 --- a/src/symmetric/aes.rs +++ b/src/symmetric/aes.rs @@ -1,5 +1,3 @@ -use std::sync::mpsc; - use aes_gcm::Key; use hkdf::Hkdf; @@ -24,32 +22,11 @@ impl CASAES256Encryption for CASAES256 { result } - /// Generates an AES256 key from a vector on the threadpool - fn key_from_vec_threadpool(key_slice: Vec) -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = Key::::from_slice(&key_slice).to_vec(); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } - /// Generates an AES 256 32-bit Key fn generate_key() -> Vec { return Aes256Gcm::generate_key(&mut OsRng).to_vec(); } - /// Generates an AES 256 32-bit Key on the threadpool - fn generate_key_threadpool() -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let thread_result = Self::generate_key(); - sender.send(thread_result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } /// Encrypts with AES-256-GCM taking an aes_key and aes_nonce fn encrypt_plaintext(aes_key: Vec, nonce: Vec, plaintext: Vec) -> Vec { @@ -60,16 +37,6 @@ impl CASAES256Encryption for CASAES256 { ciphertext } - /// Encrypts with AES-256-GCM taking an aes_key and aes_nonce on the threadpool - fn encrypt_plaintext_threadpool(aes_key: Vec, nonce: Vec, plaintext: Vec) -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let ciphertext = Self::encrypt_plaintext(aes_key, nonce, plaintext); - sender.send(ciphertext).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } /// Decrypts with AES-256-GCM taking an aes_key and aes_nonce fn decrypt_ciphertext(aes_key: Vec, nonce: Vec, ciphertext: Vec) -> Vec { @@ -80,17 +47,6 @@ impl CASAES256Encryption for CASAES256 { plaintext } - /// Encrypts with AES-256-GCM taking an aes_key and aes_nonce on the threadpool - fn decrypt_ciphertext_threadpool(aes_key: Vec, nonce: Vec, ciphertext: Vec) -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let plaintext = Self::decrypt_ciphertext(aes_key, nonce, ciphertext); - sender.send(plaintext).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } - /// Creates an AES-256 key 32-byte key from an X25519 Shared Secret fn key_from_x25519_shared_secret(shared_secret: Vec) -> Aes256KeyFromX25519SharedSecret { let hk = Hkdf::::new(None, &shared_secret); @@ -105,16 +61,6 @@ impl CASAES256Encryption for CASAES256 { result } - /// Creates an AES-256 key 32-byte key from an X25519 Shared Secret on the threadpool - fn key_from_x25519_shared_secret_threadpool(shared_secret: Vec) -> Aes256KeyFromX25519SharedSecret { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = Self::key_from_x25519_shared_secret(shared_secret); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } /// Generates an AES nonce fn generate_nonce() -> Vec { @@ -122,17 +68,6 @@ impl CASAES256Encryption for CASAES256 { OsRng.fill_bytes(&mut bytes); bytes.to_vec() } - - /// Generates an AES nonce on the threadpool - fn generate_nonce_threadpool() -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let random_bytes = Self::generate_nonce(); - sender.send(random_bytes).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } } impl CASAES128Encryption for CASAES128 { @@ -143,32 +78,14 @@ impl CASAES128Encryption for CASAES128 { result } - /// Generates an AES128 key from a vector on the threadpool - fn key_from_vec_threadpool(key_slice: Vec) -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = Key::::from_slice(&key_slice).to_vec(); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } + /// Generates an AES-128 16-byte key fn generate_key() -> Vec { return Aes128Gcm::generate_key(&mut OsRng).to_vec(); } - /// Generates an AES-128 16-byte key on the threadpool - fn generate_key_threadpool() -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let key = Self::generate_key(); - sender.send(key).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } + /// Encrypts with AES-128-GCM taking an aes_key and aes_nonce fn encrypt_plaintext(aes_key: Vec, nonce: Vec, plaintext: Vec) -> Vec { @@ -179,16 +96,7 @@ impl CASAES128Encryption for CASAES128 { ciphertext } - /// Encrypts with AES-128-GCM taking an aes_key and aes_nonce on the threadpool - fn encrypt_plaintext_threadpool(aes_key: Vec, nonce: Vec, plaintext: Vec) -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let ciphertext = Self::encrypt_plaintext(aes_key, nonce, plaintext); - sender.send(ciphertext).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } + /// Decrypts with AES-128-GCM taking an aes_key and aes_nonce fn decrypt_ciphertext(aes_key: Vec, nonce: Vec, ciphertext: Vec) -> Vec { @@ -199,16 +107,7 @@ impl CASAES128Encryption for CASAES128 { plaintext } - /// Decrypts with AES-128-GCM taking an aes_key and aes_nonce on the threadpool - fn decrypt_ciphertext_threadpool(aes_key: Vec, nonce: Vec, ciphertext: Vec) -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let plaintext = Self::decrypt_ciphertext(aes_key, nonce, ciphertext); - sender.send(plaintext).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } + /// Generates an AES-128 16-byte key from an X25519 shared secret fn key_from_x25519_shared_secret(shared_secret: Vec) -> Aes128KeyFromX25519SharedSecret { @@ -224,16 +123,7 @@ impl CASAES128Encryption for CASAES128 { result } - /// Generates an AES-128 16-byte key from an X25519 shared secret on the threadpool - fn key_from_x25519_shared_secret_threadpool(shared_secret: Vec) -> Aes128KeyFromX25519SharedSecret { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let result = Self::key_from_x25519_shared_secret(shared_secret); - sender.send(result).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } + /// Generates an AES nonce fn generate_nonce() -> Vec { @@ -242,14 +132,5 @@ impl CASAES128Encryption for CASAES128 { bytes.to_vec() } - /// Generates an AES nonce on the threadpool - fn generate_nonce_threadpool() -> Vec { - let (sender, receiver) = mpsc::channel(); - rayon::spawn(move || { - let random_bytes = Self::generate_nonce(); - sender.send(random_bytes).unwrap(); - }); - let result = receiver.recv().unwrap(); - result - } + } \ No newline at end of file diff --git a/src/symmetric/cas_symmetric_encryption.rs b/src/symmetric/cas_symmetric_encryption.rs index c599e64..d67378a 100644 --- a/src/symmetric/cas_symmetric_encryption.rs +++ b/src/symmetric/cas_symmetric_encryption.rs @@ -10,30 +10,18 @@ pub struct Aes128KeyFromX25519SharedSecret { pub trait CASAES256Encryption { fn generate_key() -> Vec; - fn generate_key_threadpool() -> Vec; fn encrypt_plaintext(aes_key: Vec, nonce: Vec, plaintext: Vec) -> Vec; - fn encrypt_plaintext_threadpool(aes_key: Vec, nonce: Vec, plaintext: Vec) -> Vec; fn decrypt_ciphertext(aes_key: Vec, nonce: Vec, ciphertext: Vec) -> Vec; - fn decrypt_ciphertext_threadpool(aes_key: Vec, nonce: Vec, ciphertext: Vec) -> Vec; fn key_from_x25519_shared_secret(shared_secret: Vec) -> Aes256KeyFromX25519SharedSecret; - fn key_from_x25519_shared_secret_threadpool(shared_secret: Vec) -> Aes256KeyFromX25519SharedSecret; fn generate_nonce() -> Vec; - fn generate_nonce_threadpool() -> Vec; fn key_from_vec(key_slice: Vec) -> Vec; - fn key_from_vec_threadpool(key_slice: Vec) -> Vec; } pub trait CASAES128Encryption { fn generate_key() -> Vec; - fn generate_key_threadpool() -> Vec; fn encrypt_plaintext(aes_key: Vec, nonce: Vec, plaintext: Vec) -> Vec; - fn encrypt_plaintext_threadpool(aes_key: Vec, nonce: Vec, plaintext: Vec) -> Vec; fn decrypt_ciphertext(aes_key: Vec, nonce: Vec, ciphertext: Vec) -> Vec; - fn decrypt_ciphertext_threadpool(aes_key: Vec, nonce: Vec, ciphertext: Vec) -> Vec; fn key_from_x25519_shared_secret(shared_secret: Vec) -> Aes128KeyFromX25519SharedSecret; - fn key_from_x25519_shared_secret_threadpool(shared_secret: Vec) -> Aes128KeyFromX25519SharedSecret; fn generate_nonce() -> Vec; - fn generate_nonce_threadpool() -> Vec; fn key_from_vec(key_slice: Vec) -> Vec; - fn key_from_vec_threadpool(key_slice: Vec) -> Vec; } \ No newline at end of file diff --git a/tests/asymmetric.rs b/tests/asymmetric.rs index d436c0d..472f24f 100644 --- a/tests/asymmetric.rs +++ b/tests/asymmetric.rs @@ -9,13 +9,6 @@ mod asymmetric { assert!(!key_pair.public_key.is_empty()); } - #[test] - pub fn generate_rsa_keys_threadpool() { - let key_pair: RSAKeyPairResult = CASRSA::generate_rsa_keys_threadpool(4096); - assert!(!key_pair.private_key.is_empty()); - assert!(!key_pair.public_key.is_empty()); - } - #[test] pub fn signature() { let key_pair: RSAKeyPairResult = CASRSA::generate_rsa_keys(1024); @@ -24,14 +17,6 @@ mod asymmetric { assert!(document != signature, "Signature should not be the same as the document"); } - #[test] - pub fn signature_threadpool() { - let key_pair: RSAKeyPairResult = CASRSA::generate_rsa_keys(2048); - let document = b"Hello, world!".to_vec(); - let signature = CASRSA::sign_threadpool(key_pair.private_key, document.clone()); - assert!(document != signature, "Signature should not be the same as the document"); - } - #[test] pub fn verification() { let key_pair: RSAKeyPairResult = CASRSA::generate_rsa_keys(2048); @@ -40,13 +25,4 @@ mod asymmetric { let verification = CASRSA::verify(key_pair.public_key, document, signature); assert!(verification, "Signature should be valid"); } - - #[test] - pub fn verification_threadpool() { - let key_pair: RSAKeyPairResult = CASRSA::generate_rsa_keys(4096); - let document = b"Hello, world!".to_vec(); - let signature = CASRSA::sign_threadpool(key_pair.private_key.clone(), document.clone()); - let verification = CASRSA::verify(key_pair.public_key, document, signature); - assert!(verification, "Signature should be valid"); - } } \ No newline at end of file diff --git a/tests/digital_signatures.rs b/tests/digital_signatures.rs index 6616dc3..79a3bb0 100644 --- a/tests/digital_signatures.rs +++ b/tests/digital_signatures.rs @@ -10,14 +10,6 @@ mod digital_signatures { assert_eq!(true, verification); } - #[test] - pub fn ed25519_sha_512_digital_signature_threadpool_verify() { - let data_to_sign = b"This is a test of a digital signature".to_vec(); - let result: SHAED25519DalekDigitalSignatureResult = ::digital_signature_ed25519_threadpool(data_to_sign.clone()); - let verification = ::digital_signature_ed25519_verify_threadpool(result.public_key, data_to_sign, result.signature); - assert_eq!(true, verification); - } - #[test] pub fn ed25519_sha_256_digital_signature_verify() { let data_to_sign = b"This is a test of a digital signature".to_vec(); @@ -26,14 +18,6 @@ mod digital_signatures { assert_eq!(true, verification); } - #[test] - pub fn ed25519_sha_256_digital_signature_threadpool_verify() { - let data_to_sign = b"This is a test of a digital signature".to_vec(); - let result: SHAED25519DalekDigitalSignatureResult = ::digital_signature_ed25519_threadpool(data_to_sign.clone()); - let verification = ::digital_signature_ed25519_verify_threadpool(result.public_key, data_to_sign, result.signature); - assert_eq!(true, verification); - } - #[test] pub fn rsa_sha_512_digital_signature_verify() { let data_to_sign = b"This is a test of a digital signature".to_vec(); @@ -42,14 +26,6 @@ mod digital_signatures { assert_eq!(true, verification); } - #[test] - pub fn rsa_sha_512_digital_signature_threadpool_verify() { - let data_to_sign = b"This is a test of a digital signature".to_vec(); - let result: RSADigitalSignatureResult = SHA512RSADigitalSignature::digital_signature_rsa_threadpool(4096, data_to_sign.clone()); - let verification = SHA512RSADigitalSignature::verify_rsa_threadpool(result.public_key, data_to_sign, result.signature); - assert_eq!(true, verification); - } - #[test] pub fn rsa_sha_256_digital_signature_verify() { let data_to_sign = b"This is a test of a digital signature".to_vec(); @@ -57,12 +33,4 @@ mod digital_signatures { let verification = SHA256RSADigitalSignature::verify_rsa(result.public_key, data_to_sign, result.signature); assert_eq!(true, verification); } - - #[test] - pub fn rsa_sha_256_digital_signature_threadpool_verify() { - let data_to_sign = b"This is a test of a digital signature".to_vec(); - let result: RSADigitalSignatureResult = SHA256RSADigitalSignature::digital_signature_rsa_threadpool(4096, data_to_sign.clone()); - let verification = SHA256RSADigitalSignature::verify_rsa_threadpool(result.public_key, data_to_sign, result.signature); - assert_eq!(true, verification); - } } \ No newline at end of file diff --git a/tests/hashers.rs b/tests/hashers.rs index c65d096..1b2bc63 100644 --- a/tests/hashers.rs +++ b/tests/hashers.rs @@ -55,54 +55,4 @@ mod tests { assert_eq!(hash, hash_2); } - - #[test] - fn test_sha_256_threadpool_compare_fail() { - let path = Path::new("tests/test.docx"); - let file_bytes: Vec = std::fs::read(path).unwrap(); - let hash = ::hash_256_threadpool(file_bytes); - - let path_2 = Path::new("tests/test2.docx"); - let file_bytes_2: Vec = std::fs::read(path_2).unwrap(); - let hash_2 = ::hash_256_threadpool(file_bytes_2); - - assert_ne!(hash, hash_2); - } - - #[test] - fn test_sha_256_threadpool_success() { - let path = Path::new("tests/test.docx"); - let file_bytes: Vec = std::fs::read(path).unwrap(); - let hash = ::hash_256_threadpool(file_bytes); - - let file_bytes_2: Vec = std::fs::read(path).unwrap(); - let hash_2 = ::hash_256_threadpool(file_bytes_2); - - assert_eq!(hash, hash_2); - } - - #[test] - fn test_sha_512_threadpool_compare_fail() { - let path = Path::new("tests/test.docx"); - let file_bytes: Vec = std::fs::read(path).unwrap(); - let hash = ::hash_512_threadpool(file_bytes); - - let path_2 = Path::new("tests/test2.docx"); - let file_bytes_2: Vec = std::fs::read(path_2).unwrap(); - let hash_2 = ::hash_512_threadpool(file_bytes_2); - - assert_ne!(hash, hash_2); - } - - #[test] - fn test_sha_512_threadpool_success() { - let path = Path::new("tests/test.docx"); - let file_bytes: Vec = std::fs::read(path).unwrap(); - let hash = ::hash_512_threadpool(file_bytes); - - let file_bytes_2: Vec = std::fs::read(path).unwrap(); - let hash_2 = ::hash_512_threadpool(file_bytes_2); - - assert_eq!(hash, hash_2); - } } \ No newline at end of file diff --git a/tests/key_exchange.rs b/tests/key_exchange.rs index 125a429..dbb3746 100644 --- a/tests/key_exchange.rs +++ b/tests/key_exchange.rs @@ -11,14 +11,4 @@ mod key_exchange { let bob_shared_secret = X25519::diffie_hellman(bob.secret_key.clone(), alice.public_key.clone()); assert_eq!(alice_shared_secret, bob_shared_secret); } - - #[test] - pub fn x25519_diffie_hellman_threadpool() { - let alice: X25519SecretPublicKeyResult = X25519::generate_secret_and_public_key_threadpool(); - let bob: X25519SecretPublicKeyResult = X25519::generate_secret_and_public_key_threadpool(); - - let alice_shared_secret = X25519::diffie_hellman_threadpool(alice.secret_key.clone(), bob.public_key.clone()); - let bob_shared_secret = X25519::diffie_hellman_threadpool(bob.secret_key.clone(), alice.public_key.clone()); - assert_eq!(alice_shared_secret, bob_shared_secret); - } } \ No newline at end of file diff --git a/tests/password_hashers.rs b/tests/password_hashers.rs index 445fb15..83bdc4e 100644 --- a/tests/password_hashers.rs +++ b/tests/password_hashers.rs @@ -29,32 +29,6 @@ mod password_hashers { assert_eq!(file_bytes, decrypted); } - #[test] - pub fn argon2_derive_aes_128_and_encrypt_threadpool() { - let password = b"BadPassword".to_vec(); // do not use this as a password. - let key = CASArgon::derive_aes_128_key(password); - let nonce = CASAES128::generate_nonce_threadpool(); - let path = Path::new("tests/test.docx"); - let file_bytes: Vec = std::fs::read(path).unwrap(); - - let encrypted = CASAES128::encrypt_plaintext_threadpool(key.clone(), nonce.clone(), file_bytes.clone()); - let decrypted = CASAES128::decrypt_ciphertext_threadpool(key, nonce, encrypted); - assert_eq!(file_bytes, decrypted); - } - - #[test] - pub fn argon2_derive_aes_256_and_encrypt_threadpool() { - let password = b"BadPassword".to_vec(); // do not use this as a password. - let key = CASArgon::derive_aes_256_key(password); - let nonce = CASAES128::generate_nonce(); - let path = Path::new("tests/test.docx"); - let file_bytes: Vec = std::fs::read(path).unwrap(); - - let encrypted = CASAES256::encrypt_plaintext(key.clone(), nonce.clone(), file_bytes.clone()); - let decrypted = CASAES256::decrypt_ciphertext(key, nonce, encrypted); - assert_eq!(file_bytes, decrypted); - } - #[test] pub fn argon2_hash_password() { let password = "BadPassword".to_string(); @@ -63,14 +37,6 @@ mod password_hashers { assert_eq!(true, verification); } - #[test] - pub fn argon2_hash_password_threadpool() { - let password = "BadPassword".to_string(); - let hash = CASArgon::hash_password_threadpool(password.clone()); - let verification = CASArgon::verify_password_threadpool(hash, password); - assert_eq!(true, verification); - } - #[test] pub fn scrypt_hash_password() { let password = "DoNotUseThisPassword".to_string(); @@ -79,14 +45,6 @@ mod password_hashers { assert_eq!(true, verification); } - #[test] - pub fn scrypt_hash_password_threadpool() { - let password = "DoNotUseThisPassword".to_string(); - let hash = CASScrypt::hash_password_threadpool(password.clone()); - let verification = CASScrypt::verify_password_threadpool(hash, password); - assert_eq!(true, verification); - } - #[test] pub fn bcrypt_hash_password() { let password = "DoNotUseThisPassword".to_string(); @@ -95,13 +53,5 @@ mod password_hashers { assert_eq!(true, verification); } - #[test] - pub fn bcrypt_hash_password_threadpool() { - let password = "DoNotUseThisPassword".to_string(); - let hash = CASBCrypt::hash_password_threadpool(password.clone()); - let verification = CASBCrypt::verify_password_threadpool(hash, password); - assert_eq!(true, verification); - } - } \ No newline at end of file diff --git a/tests/signatures.rs b/tests/signatures.rs index d2e087b..fc3ecdd 100644 --- a/tests/signatures.rs +++ b/tests/signatures.rs @@ -1,6 +1,6 @@ #[cfg(test)] mod ed25519 { - use cas_lib::signatures::ed25519::{ed25519_sign_with_key_pair, ed25519_sign_with_key_pair_threadpool, ed25519_verify_with_key_pair, ed25519_verify_with_key_pair_threadpool, ed25519_verify_with_public_key, ed25519_verify_with_public_key_threadpool, get_ed25519_key_pair, get_ed25519_key_pair_threadpool}; + use cas_lib::signatures::ed25519::{ed25519_sign_with_key_pair, ed25519_verify_with_key_pair, ed25519_verify_with_public_key, get_ed25519_key_pair}; #[test] pub fn get_key_pair_test() { @@ -8,12 +8,6 @@ mod ed25519 { assert!(key_pair != [0; 32], "Array is all zeros"); } - #[test] - pub fn get_key_pair_test_threadpool() { - let key_pair = get_ed25519_key_pair_threadpool(); - assert!(key_pair != [0; 32], "Array is all zeros"); - } - #[test] pub fn sign_with_key_pair() { let key_pair = get_ed25519_key_pair(); @@ -23,15 +17,6 @@ mod ed25519 { assert!(signature.public_key != [0; 32], "Array is all zeros"); } - #[test] - pub fn sign_with_key_pair_threadpool() { - let key_pair = get_ed25519_key_pair_threadpool(); - let message_to_sign = b"Hello World Message To Sign".to_vec(); - let signature = ed25519_sign_with_key_pair_threadpool(key_pair, message_to_sign); - assert!(signature.signature != [0; 64], "Array is all zeros"); - assert!(signature.public_key != [0; 32], "Array is all zeros"); - } - #[test] pub fn verify_with_public_key_() { let key_pair = get_ed25519_key_pair(); @@ -41,15 +26,6 @@ mod ed25519 { assert_eq!(verification, true); } - #[test] - pub fn verify_with_public_key_threadpool() { - let key_pair = get_ed25519_key_pair_threadpool(); - let message_to_sign = b"Hello World Message To Sign".to_vec(); - let signature = ed25519_sign_with_key_pair_threadpool(key_pair, message_to_sign.clone()); - let verification = ed25519_verify_with_public_key_threadpool(signature.public_key, signature.signature, message_to_sign); - assert_eq!(verification, true); - } - #[test] pub fn verify_with_key_pair() { let key_pair = get_ed25519_key_pair(); @@ -58,13 +34,4 @@ mod ed25519 { let verification = ed25519_verify_with_key_pair(key_pair, signature.signature, message_to_sign); assert_eq!(verification, true); } - - #[test] - pub fn verify_with_key_pair_threadpool() { - let key_pair = get_ed25519_key_pair(); - let message_to_sign = b"Hello World Message To Sign".to_vec(); - let signature = ed25519_sign_with_key_pair_threadpool(key_pair.clone(), message_to_sign.clone()); - let verification = ed25519_verify_with_key_pair_threadpool(key_pair, signature.signature, message_to_sign); - assert_eq!(verification, true); - } } diff --git a/tests/sponges.rs b/tests/sponges.rs index 28bbadb..907bee7 100644 --- a/tests/sponges.rs +++ b/tests/sponges.rs @@ -18,20 +18,4 @@ mod tests { file.write_all(&decrypted_bytes).unwrap(); assert_eq!(file_bytes, decrypted_bytes); } - - #[test] - fn test_ascon_128_threadpool() { - let path = Path::new("tests/test.docx"); - let file_bytes: Vec = std::fs::read(path).unwrap(); - let ascon_nonce = ::generate_nonce_threadpool(); - let ascon_key = ::generate_key_threadpool(); - let encrypted_bytes = ::encrypt_threadpool(ascon_key.clone(), ascon_nonce.clone(), file_bytes.clone()); - let mut file = File::create("encrypted.docx").unwrap(); - file.write_all(&encrypted_bytes).unwrap(); - - let decrypted_bytes = ::decrypt_threadpool(ascon_key, ascon_nonce, encrypted_bytes); - let mut file = File::create("decrypted.docx").unwrap(); - file.write_all(&decrypted_bytes).unwrap(); - assert_eq!(file_bytes, decrypted_bytes); - } } \ No newline at end of file