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
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cas-lib"
version = "0.2.72"
version = "0.2.73"
edition = "2021"
description = "A function wrapper layer for RustCrypto and Dalek-Cryptography. Intended to be used in FFI situations with a global heap deallactor at the top level project."
license = "Apache-2.0"
Expand All @@ -12,17 +12,17 @@ crate-type = ["lib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aes-gcm = {version = "0.11.0-rc.2"}
aes-gcm = "0.10.3"
argon2 = "0.5.2"
bcrypt = "0.15.0"
bcrypt = "0.18.0"
blake2 = "0.10.6"
rand = "0.8.5"
rand_chacha = "0.3.1"
rsa = "0.9.6"
scrypt = "0.11.0"
sha3 = "0.10.8"
x25519-dalek = {version = "2.0.0", features = ["static_secrets"]}
ascon-aead = {version = "0.6.0-pre.2"}
ascon-aead = "0.5.2"
hmac = "0.12.1"
sha2 = "0.10.8"
zstd = "0.13"
Expand All @@ -31,10 +31,10 @@ uuid = { version = "1.10.0", features = ["v4"] }
pbkdf2 = "0.12.2"
ed25519-dalek = { version = "2", features = ["rand_core"] }
hkdf = "0.12.4"
chacha20poly1305 = { version = "0.11.0-rc.2" }
chacha20poly1305 = "0.10.1"
slh-dsa = "0.0.3"
ml-kem = "0.2.1"
reqwest = { version = "0.12.24", features = ["json", "cookies", "rustls-tls"] }
reqwest = { version = "0.12.24", default-features = false, features = ["json", "cookies", "rustls-tls"] }
serde = { version = "1.0.228", features = ["derive"] }
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread"] }
url = "2.5.7"
Expand Down
2 changes: 1 addition & 1 deletion src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub async fn send_benchmark(time_in_milliseconds: i64, class_name: String, metho
let base_url = BASE_URL.lock().unwrap().clone();
let client = BENCHMARK_SENDER_CLIENT.lock().unwrap().as_ref().unwrap().clone();

let response = client
let _response = client
.post(format!("{}/{}/Benchmark", base_url, determine_api_route()))
.json(&payload)
.send()
Expand Down
48 changes: 25 additions & 23 deletions src/symmetric/aes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use aes_gcm::{Key, aes::cipher::crypto_common::Generate};
use aes_gcm::{Key};

use hkdf::Hkdf;
use rand::{RngCore, rngs::OsRng};
Expand All @@ -17,32 +17,33 @@ impl CASAES256Encryption for CASAES256 {

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

/// Generates an AES 256 32-bit Key
fn generate_key() -> Vec<u8> {
return Key::<Aes256Gcm>::generate().to_vec();
let mut os_rng = OsRng;
return Aes256Gcm::generate_key(&mut os_rng).to_vec();
}


/// Encrypts with AES-256-GCM taking an aes_key and aes_nonce
fn encrypt_plaintext(aes_key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
let key = Key::<Aes256Gcm>::try_from(aes_key.as_slice()).unwrap();
let cipher = Aes256Gcm::new(&key);
let nonce = Nonce::try_from(nonce.as_slice()).unwrap();
let ciphertext = cipher.encrypt(&nonce, plaintext.as_ref()).unwrap();
let key = Key::<Aes256Gcm>::from_slice(aes_key.as_slice());
let cipher = Aes256Gcm::new(key);
let nonce = Nonce::from_slice(nonce.as_slice());
let ciphertext = cipher.encrypt(nonce, plaintext.as_ref()).unwrap();
ciphertext
}


/// Decrypts with AES-256-GCM taking an aes_key and aes_nonce
fn decrypt_ciphertext(aes_key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
let key = Key::<Aes256Gcm>::try_from(aes_key.as_slice()).unwrap();
let cipher = Aes256Gcm::new(&key);
let nonce = Nonce::try_from(nonce.as_slice()).unwrap();
let plaintext = cipher.decrypt(&nonce, ciphertext.as_ref()).unwrap();
let key = Key::<Aes256Gcm>::from_slice(aes_key.as_slice());
let cipher = Aes256Gcm::new(key);
let nonce = Nonce::from_slice(nonce.as_slice());
let plaintext = cipher.decrypt(nonce, ciphertext.as_ref()).unwrap();
plaintext
}

Expand All @@ -68,34 +69,35 @@ impl CASAES128Encryption for CASAES128 {

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

/// Generates an AES-128 16-byte key
fn generate_key() -> Vec<u8> {
return Key::<Aes128Gcm>::generate().to_vec();
let mut os_rng = OsRng;
return Aes128Gcm::generate_key(&mut os_rng).to_vec();
}



/// Encrypts with AES-128-GCM taking an aes_key and aes_nonce
fn encrypt_plaintext(aes_key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
let key = Key::<Aes128Gcm>::try_from(aes_key.as_slice()).unwrap();
let cipher = Aes128Gcm::new(&key);
let nonce = Nonce::try_from(nonce.as_slice()).unwrap();
let ciphertext = cipher.encrypt(&nonce, plaintext.as_ref()).unwrap().into();
let key = Key::<Aes128Gcm>::from_slice(aes_key.as_slice());
let cipher = Aes128Gcm::new(key);
let nonce = Nonce::from_slice(nonce.as_slice());
let ciphertext = cipher.encrypt(nonce, plaintext.as_ref()).unwrap();
ciphertext
}



/// Decrypts with AES-128-GCM taking an aes_key and aes_nonce
fn decrypt_ciphertext(aes_key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
let key = Key::<Aes128Gcm>::try_from(aes_key.as_slice()).unwrap();
let cipher = Aes128Gcm::new(&key);
let nonce = Nonce::try_from(nonce.as_slice()).unwrap();
let plaintext = cipher.decrypt(&nonce, ciphertext.as_ref()).unwrap();
let key = Key::<Aes128Gcm>::from_slice(aes_key.as_slice());
let cipher = Aes128Gcm::new(key);
let nonce = Nonce::from_slice(nonce.as_slice());
let plaintext = cipher.decrypt(nonce, ciphertext.as_ref()).unwrap();
plaintext
}

Expand Down
22 changes: 13 additions & 9 deletions src/symmetric/chacha20poly1305.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use aes_gcm::{aead::Aead, aes::cipher::crypto_common::Generate};
use rand::RngCore;
use aes_gcm::{aead::Aead};
use chacha20poly1305::{ChaCha20Poly1305, Key, Nonce, KeyInit};
use rand::rngs::OsRng;

use crate::symmetric::cas_symmetric_encryption::Chacha20Poly1305Encryption;

Expand All @@ -9,24 +11,26 @@ pub struct CASChacha20Poly1305;
impl Chacha20Poly1305Encryption for CASChacha20Poly1305 {

fn generate_key() -> Vec<u8> {
Key::generate().to_vec()
ChaCha20Poly1305::generate_key(&mut OsRng).to_vec()
}

fn encrypt_plaintext(aes_key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
let key = Key::try_from(aes_key.as_slice()).unwrap();
let key = Key::from_slice(aes_key.as_slice());
let cipher = ChaCha20Poly1305::new(&key);
let nonce = Nonce::try_from(nonce.as_slice()).unwrap();
cipher.encrypt(&nonce, plaintext.as_ref()).expect("encryption failed")
let nonce = Nonce::from_slice(nonce.as_slice());
cipher.encrypt(nonce, plaintext.as_ref()).expect("encryption failed")
}

fn decrypt_ciphertext(aes_key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
let key = Key::try_from(aes_key.as_slice()).unwrap();
let key = Key::from_slice(aes_key.as_slice());
let cipher = ChaCha20Poly1305::new(&key);
let nonce = Nonce::try_from(nonce.as_slice()).unwrap();
cipher.decrypt(&nonce, ciphertext.as_ref()).expect("decryption failed")
let nonce = Nonce::from_slice(nonce.as_slice());
cipher.decrypt(nonce, ciphertext.as_ref()).expect("decryption failed")
}

fn generate_nonce() -> Vec<u8> {
Nonce::try_generate().unwrap().to_vec()
let mut nonce = [0u8; 12]; // ChaCha20Poly1305 uses 96-bit (12-byte) nonces
OsRng.fill_bytes(&mut nonce);
nonce.to_vec()
}
}