Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#52 thread pool implementation #54

Merged
merged 33 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
67d9013
#53 refactoring and create rsa keys on threadpool
WingZer0o May 17, 2024
9872a68
#52 rsa encrypt threadpool
WingZer0o May 17, 2024
4b4de2d
#52 rsa decrypt threadpool
WingZer0o May 17, 2024
3222117
#52 rsa sign and verify threadpool
WingZer0o May 17, 2024
944c787
#52 blake2 hashing and verification on the threadpool
WingZer0o May 17, 2024
6838c34
#52 hmac threadpool
WingZer0o May 18, 2024
3c2a380
#52 sha hashing and verification on the threadpool.
WingZer0o May 18, 2024
06af167
argon2 to use cas-lib
WingZer0o May 19, 2024
b5b7d9f
scrypt to cas-lib
WingZer0o May 19, 2024
8717fb1
bcrypt cas-lib logic
WingZer0o May 19, 2024
e3d7bcd
updating cargo toml removing password hashers
WingZer0o May 19, 2024
03ea3ee
removing imports from bcrypt
WingZer0o May 19, 2024
2e34d4e
rsa log into cas-lib
WingZer0o May 19, 2024
03c8352
removing imports and useless tests
WingZer0o May 19, 2024
8ccbd4b
adjusting is verified threadpool rsa
WingZer0o May 20, 2024
3271f69
blake 2 refactor
WingZer0o May 24, 2024
27c023b
refactoring for hmac to use cas-lib
WingZer0o May 24, 2024
30462bb
sha refactor
WingZer0o May 25, 2024
ffb20c9
removing comment
WingZer0o May 25, 2024
550e9e3
refactoring aes
WingZer0o May 25, 2024
9bbe404
aes threadpool
WingZer0o May 25, 2024
47cf914
aes threadpool implementation
WingZer0o May 25, 2024
41e3778
cas-lib implementation
WingZer0o May 25, 2024
30eee0a
ascond threadpool implementation
WingZer0o May 25, 2024
7ea0277
x25519 threadpool
WingZer0o May 26, 2024
5b8e2af
rsa digital signature to cas-lib
WingZer0o May 26, 2024
75b4572
ed25519 digital signature cas-lib
WingZer0o May 26, 2024
d2e2267
#52 digital signature threadpool
WingZer0o May 26, 2024
db7bc50
refactoring to use cas-lib
WingZer0o May 26, 2024
d2fbef1
removing base64 crate
WingZer0o May 26, 2024
7111ee6
#52 ed25519 threadpool refactor
WingZer0o May 26, 2024
e2d7c7c
ed25519 threadpool implementation
WingZer0o May 26, 2024
081f440
changing cas-lib version to crates.io instead of local file path
WingZer0o May 26, 2024
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
22 changes: 1 addition & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,5 @@ crate-type = ["dylib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aes-gcm = "0.10.1"
argon2 = "0.4.1"
base64 = "0.20.0"
bcrypt = "0.13.0"
rand = "0.8.5"
rand_07 = { package = "rand", version = "0.7.0" }
rsa = "0.7.2"
scrypt = "0.10.0"
sha3 = "0.10.6"
hmac = "0.12.1"
sha2 = "0.10.6"
blake2 = "0.10.6"
libc = "0.2.146"
rayon = "1.8.0"
x25519-dalek = {version = "2.0.0", features = ["static_secrets"]}
ascon-aead = "0.4.2"

[profile.dev.package.num-bigint-dig]
opt-level = 3

[dependencies.ed25519-dalek]
version = "1"
cas-lib = "0.1.6"
273 changes: 223 additions & 50 deletions src/aes.rs

Large diffs are not rendered by default.

163 changes: 124 additions & 39 deletions src/ascon_aead.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::ffi::{c_char, c_uchar, CStr, CString};

use ascon_aead::aead::{generic_array::GenericArray, Aead, AeadCore, KeyInit, OsRng};
use ascon_aead::Ascon128;
use cas_lib::sponges::ascon_aead::AsconAead;
use cas_lib::sponges::cas_ascon_aead::{CASAsconAead};

#[repr(C)]
pub struct Ascon128EncryptResult {
Expand All @@ -15,39 +14,85 @@ pub struct Ascon128DecryptResult {
length: usize,
}

#[repr(C)]
pub struct Ascon128Key {
key: *mut c_uchar,
length: usize
}

#[repr(C)]
pub struct Ascon128Nonce {
nonce: *mut c_uchar,
length: usize
}

#[no_mangle]
pub extern "C" fn ascon_128_key() -> *mut c_char {
return CString::new(base64::encode(Ascon128::generate_key(&mut OsRng)))
.unwrap()
.into_raw();
pub extern "C" fn ascon_128_key() -> Ascon128Key {
let mut key = <AsconAead as CASAsconAead>::generate_key();
let capacity = key.capacity();
key.reserve_exact(capacity);
let result = Ascon128Key {
key: key.as_mut_ptr(),
length: key.len()
};
std::mem::forget(key);
result
}

#[no_mangle]
pub extern "C" fn ascon_128_nonce() -> *mut c_char {
return CString::new(base64::encode(Ascon128::generate_nonce(&mut OsRng)))
.unwrap()
.into_raw();
pub extern "C" fn ascon_128_key_threadpool() -> Ascon128Key {
let mut key = <AsconAead as CASAsconAead>::generate_key_threadpool();
let capacity = key.capacity();
key.reserve_exact(capacity);
let result = Ascon128Key {
key: key.as_mut_ptr(),
length: key.len()
};
std::mem::forget(key);
result
}



#[no_mangle]
pub extern "C" fn ascon_128_nonce() -> Ascon128Nonce {
let mut nonce = <AsconAead as CASAsconAead>::generate_nonce();
let capacity = nonce.capacity();
nonce.reserve_exact(capacity);
let result = Ascon128Nonce {
nonce: nonce.as_mut_ptr(),
length: nonce.len()
};
std::mem::forget(nonce);
result
}

#[no_mangle]
pub extern "C" fn ascon_128_nonce_threadpool() -> Ascon128Nonce {
let mut nonce = <AsconAead as CASAsconAead>::generate_nonce_threadpool();
let capacity = nonce.capacity();
nonce.reserve_exact(capacity);
let result = Ascon128Nonce {
nonce: nonce.as_mut_ptr(),
length: nonce.len()
};
std::mem::forget(nonce);
result
}

#[no_mangle]
pub extern "C" fn ascon_128_encrypt(
nonce_key: *const c_char,
key: *const c_char,
nonce_key: *const c_uchar,
nonce_key_length: usize,
key: *const c_uchar,
key_length: usize,
to_encrypt: *const c_uchar,
to_encrypt_length: usize,
) -> Ascon128EncryptResult {
let nonce_key = unsafe { CStr::from_ptr(nonce_key) }.to_str().unwrap();
let key = unsafe { CStr::from_ptr(key) }.to_str().unwrap();
let to_encrypt = unsafe { std::slice::from_raw_parts(to_encrypt, to_encrypt_length) };

let decoded_nonce_key = base64::decode(nonce_key).unwrap();
let decoded_key = base64::decode(key).unwrap();

let key = GenericArray::from_slice(&decoded_nonce_key);
let nonce_key = GenericArray::from_slice(&decoded_key);

let cipher = Ascon128::new(key);
let mut ciphertext = cipher.encrypt(&nonce_key, to_encrypt.as_ref()).unwrap();
let nonce_key = unsafe { std::slice::from_raw_parts(nonce_key, nonce_key_length) }.to_vec();
let key = unsafe { std::slice::from_raw_parts(key, key_length) }.to_vec();
let to_encrypt = unsafe { std::slice::from_raw_parts(to_encrypt, to_encrypt_length) }.to_vec();
let mut ciphertext = <AsconAead as CASAsconAead>::encrypt(key, nonce_key, to_encrypt);
let capacity = ciphertext.capacity();
ciphertext.reserve_exact(capacity);
let result = Ascon128EncryptResult {
Expand All @@ -58,26 +103,66 @@ pub extern "C" fn ascon_128_encrypt(
result
}


#[no_mangle]
pub extern "C" fn ascon_128_decrypt(
nonce_key: *const c_char,
key: *const c_char,
pub extern "C" fn ascon_128_encrypt_threadpool(
nonce_key: *const c_uchar,
nonce_key_length: usize,
key: *const c_uchar,
key_length: usize,
to_encrypt: *const c_uchar,
to_encrypt_length: usize,
) -> Ascon128DecryptResult {
let nonce_key = unsafe { CStr::from_ptr(nonce_key) }.to_str().unwrap();
let key = unsafe { CStr::from_ptr(key) }.to_str().unwrap();
let to_encrypt = unsafe { std::slice::from_raw_parts(to_encrypt, to_encrypt_length) };
) -> Ascon128EncryptResult {
let nonce_key = unsafe { std::slice::from_raw_parts(nonce_key, nonce_key_length) }.to_vec();
let key = unsafe { std::slice::from_raw_parts(key, key_length) }.to_vec();
let to_encrypt = unsafe { std::slice::from_raw_parts(to_encrypt, to_encrypt_length) }.to_vec();
let mut ciphertext = <AsconAead as CASAsconAead>::encrypt_threadpool(key, nonce_key, to_encrypt);
let capacity = ciphertext.capacity();
ciphertext.reserve_exact(capacity);
let result = Ascon128EncryptResult {
ciphertext: ciphertext.as_mut_ptr(),
length: ciphertext.len(),
};
std::mem::forget(ciphertext);
result
}

let decoded_nonce_key = base64::decode(nonce_key).unwrap();
let decoded_key = base64::decode(key).unwrap();

let key = GenericArray::from_slice(&decoded_nonce_key);
let nonce_key = GenericArray::from_slice(&decoded_key);
#[no_mangle]
pub extern "C" fn ascon_128_decrypt(
nonce_key: *const c_uchar,
nonce_key_length: usize,
key: *const c_uchar,
key_length: usize,
to_decrypt: *const c_uchar,
to_decrypt_length: usize,
) -> Ascon128DecryptResult {
let nonce_key = unsafe { std::slice::from_raw_parts(nonce_key, nonce_key_length) }.to_vec();
let key = unsafe { std::slice::from_raw_parts(key, key_length) }.to_vec();
let to_decrypt = unsafe { std::slice::from_raw_parts(to_decrypt, to_decrypt_length) }.to_vec();
let mut plaintext = <AsconAead as CASAsconAead>::decrypt(key, nonce_key, to_decrypt);
let capacity = plaintext.capacity();
plaintext.reserve_exact(capacity);
let result = Ascon128DecryptResult {
plaintext: plaintext.as_mut_ptr(),
length: plaintext.len(),
};
std::mem::forget(plaintext);
result
}

let cipher = Ascon128::new(key);
let mut plaintext = cipher.decrypt(&nonce_key, to_encrypt.as_ref()).unwrap();
#[no_mangle]
pub extern "C" fn ascon_128_decrypt_threadpool(
nonce_key: *const c_uchar,
nonce_key_length: usize,
key: *const c_uchar,
key_length: usize,
to_decrypt: *const c_uchar,
to_decrypt_length: usize,
) -> Ascon128DecryptResult {
let nonce_key = unsafe { std::slice::from_raw_parts(nonce_key, nonce_key_length) }.to_vec();
let key = unsafe { std::slice::from_raw_parts(key, key_length) }.to_vec();
let to_decrypt = unsafe { std::slice::from_raw_parts(to_decrypt, to_decrypt_length) }.to_vec();
let mut plaintext = <AsconAead as CASAsconAead>::decrypt_threadpool(key, nonce_key, to_decrypt);
let capacity = plaintext.capacity();
plaintext.reserve_exact(capacity);
let result = Ascon128DecryptResult {
Expand Down
135 changes: 0 additions & 135 deletions src/blake2.rs

This file was deleted.

Loading
Loading