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 .github/workflows/linux-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: Build
run: cargo build --release --verbose
- name: Run tests
run: cargo test --verbose
run: cargo test --release --verbose
2 changes: 1 addition & 1 deletion .github/workflows/windows-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: Build
run: cargo build --release --verbose
- name: Run tests
run: cargo test --verbose
run: cargo test --release --verbose
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
40 changes: 0 additions & 40 deletions src/asymmetric/cas_rsa.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::mpsc;

use rand::rngs::OsRng;
use rsa::{
pkcs1::{DecodeRsaPublicKey, EncodeRsaPublicKey},
Expand Down Expand Up @@ -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<u8>) -> Vec<u8> {
Expand All @@ -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<u8>) -> Vec<u8> {
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.
Expand All @@ -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<u8>, signed_text: Vec<u8>) -> 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
}
}
3 changes: 0 additions & 3 deletions src/asymmetric/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>) -> Vec<u8>;
fn sign_threadpool(private_key: String, hash: Vec<u8>) -> Vec<u8>;
fn verify(public_key: String, hash: Vec<u8>, signed_text: Vec<u8>) -> bool;
fn verify_threadpool(public_key: String, hash: Vec<u8>, signed_text: Vec<u8>) -> bool;
}
28 changes: 2 additions & 26 deletions src/compression/zstd.rs
Original file line number Diff line number Diff line change
@@ -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).
Expand All @@ -10,34 +10,10 @@ pub fn compress(data_to_compress: Vec<u8>, level: i32) -> Vec<u8> {
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<u8>, level: i32) -> Vec<u8> {
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<u8>) -> Vec<u8> {
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<u8>) -> Vec<u8> {
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
}
}
6 changes: 1 addition & 5 deletions src/digital_signature/cas_digital_signature_rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ pub struct SHAED25519DalekDigitalSignatureResult {
}

pub trait RSADigitalSignature {
fn digital_signature_rsa(rsa_key_size: u32, data_to_sign: Vec<u8>) -> RSADigitalSignatureResult;
fn digital_signature_rsa_threadpool(rsa_key_size: u32, data_to_sign: Vec<u8>) -> RSADigitalSignatureResult;
fn digital_signature_rsa(rsa_key_size: u32, data_to_sign: Vec<u8>) -> RSADigitalSignatureResult;
fn verify_rsa(public_key: String, data_to_verify: Vec<u8>, signature: Vec<u8>) -> bool;
fn verify_rsa_threadpool(public_key: String, data_to_verify: Vec<u8>, signature: Vec<u8>) -> bool;
}

pub trait ED25519DigitalSignature {
fn digital_signature_ed25519(data_to_sign: Vec<u8>) -> SHAED25519DalekDigitalSignatureResult;
fn digital_signature_ed25519_threadpool(data_to_sign: Vec<u8>) -> SHAED25519DalekDigitalSignatureResult;
fn digital_signature_ed25519_verify(public_key: Vec<u8>, data_to_verify: Vec<u8>, signature: Vec<u8>) -> bool;
fn digital_signature_ed25519_verify_threadpool(public_key: Vec<u8>, data_to_verify: Vec<u8>, signature: Vec<u8>) -> bool;
}
24 changes: 1 addition & 23 deletions src/digital_signature/sha_256_ed25519.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::mpsc;


use sha3::{Digest, Sha3_256};

Expand Down Expand Up @@ -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<u8>) -> 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<u8>, data_to_verify: Vec<u8>, signature: Vec<u8>) -> 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
}
}
25 changes: 1 addition & 24 deletions src/digital_signature/sha_256_rsa.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::mpsc;


use rand::rngs::OsRng;
use rsa::{
Expand Down Expand Up @@ -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<u8>) -> RSADigitalSignatureResult {
let (sender, receiver) = mpsc::channel();
rayon::spawn(move || {
let result = <SHA256RSADigitalSignature as RSADigitalSignature>::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<u8>, signature: Vec<u8>) -> bool {
Expand All @@ -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<u8>, signature: Vec<u8>) -> bool {
let (sender, receiver) = mpsc::channel();
rayon::spawn(move || {
let result = <SHA256RSADigitalSignature as RSADigitalSignature>::verify_rsa(public_key, data_to_verify, signature);
sender.send(result).unwrap();
});
let result = receiver.recv().unwrap();
result
}
}
24 changes: 1 addition & 23 deletions src/digital_signature/sha_512_ed25519.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::mpsc;


use sha3::{Digest, Sha3_512};

Expand Down Expand Up @@ -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<u8>) -> SHAED25519DalekDigitalSignatureResult {
let (sender, receiver) = mpsc::channel();
rayon::spawn(move || {
let result = <SHA512ED25519DigitalSignature as ED25519DigitalSignature>::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<u8>, data_to_verify: Vec<u8>, signature: Vec<u8>) -> bool {
let (sender, receiver) = mpsc::channel();
rayon::spawn(move || {
let result = <SHA512ED25519DigitalSignature as ED25519DigitalSignature>::digital_signature_ed25519_verify(public_key, data_to_verify, signature);
sender.send(result).unwrap();
});
let result = receiver.recv().unwrap();
result
}
}
25 changes: 1 addition & 24 deletions src/digital_signature/sha_512_rsa.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

use std::sync::mpsc;


use rand::rngs::OsRng;
use rsa::{
Expand Down Expand Up @@ -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<u8>) -> RSADigitalSignatureResult {
let (sender, receiver) = mpsc::channel();
rayon::spawn(move || {
let result = <SHA512RSADigitalSignature as RSADigitalSignature>::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<u8>, signature: Vec<u8>) -> bool {
Expand All @@ -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<u8>, signature: Vec<u8>) -> bool {
let (sender, receiver) = mpsc::channel();
rayon::spawn(move || {
let result = <SHA512RSADigitalSignature as RSADigitalSignature>::verify_rsa(public_key, data_to_verify, signature);
sender.send(result).unwrap();
});
let result = receiver.recv().unwrap();
result
}
}
50 changes: 1 addition & 49 deletions src/hashers/blake2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::mpsc;


use super::cas_hasher::CASHasher;
use blake2::{Blake2b512, Blake2s256, Digest};
Expand Down Expand Up @@ -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<u8>) -> Vec<u8> {
let (sender, receiver) = mpsc::channel();
rayon::spawn(move || {
let result = <CASBlake2 as CASHasher>::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<u8>, data_to_verify: Vec<u8>) -> bool {
let (sender, receiver) = mpsc::channel();
rayon::spawn(move || {
let result = <CASBlake2 as CASHasher>::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<u8>) -> Vec<u8> {
let (sender, receiver) = mpsc::channel();
rayon::spawn(move || {
let result = <CASBlake2 as CASHasher>::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<u8>, data_to_verify: Vec<u8>) -> bool {
let (sender, receiver) = mpsc::channel();
rayon::spawn(move || {
let result = <CASBlake2 as CASHasher>::verify_256(hash_to_verify, data_to_verify);
sender.send(result).unwrap();
});
let result = receiver.recv().unwrap();
result
}
}
4 changes: 0 additions & 4 deletions src/hashers/cas_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ pub trait CASHasher {
fn verify_512(hash_to_verify: Vec<u8>, data_to_verify: Vec<u8>) -> bool;
fn hash_256(data_to_hash: Vec<u8>) -> Vec<u8>;
fn verify_256(hash_to_verify: Vec<u8>, data_to_verify: Vec<u8>) -> bool;
fn hash_512_threadpool(data_to_hash: Vec<u8>) -> Vec<u8>;
fn verify_512_threadpool(hash_to_verify: Vec<u8>, data_to_verify: Vec<u8>) -> bool;
fn hash_256_threadpool(data_to_hash: Vec<u8>) -> Vec<u8>;
fn verify_256_threadpool(hash_to_verify: Vec<u8>, data_to_verify: Vec<u8>) -> bool;
}
Loading
Loading