diff --git a/Cargo.toml b/Cargo.toml index f8b1757..c7a3873 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cas_core_lib" -version = "0.2.2" +version = "0.2.3" edition = "2021" description = "This is a Rust library providing external facing functions to performant and trusted encryption in Rust" license = "Apache-2.0" @@ -14,5 +14,5 @@ crate-type = ["dylib"] [dependencies] libc = "0.2.146" -cas-lib = "0.2.56" +cas-lib = "0.2.58" zeroizing-alloc = "0.1.0" diff --git a/README.md b/README.md index 452b656..3e9acc9 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,13 @@ [![image](https://img.shields.io/badge/Discord-5865F2?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/7bXXCQj45q) ## Overview -This is our experimental core library which provides a simple FFI layer that takes advantage of Rust's thread safe nature to provide an abstraction layer to higher level languages to run industry standard crytographic operations sequentially and in parallel. Our goal is to decrease the redundancy of engineer's creating this layer proprietary within their internal systems. +This is our experimental core library which provides a simple FFI layer that takes advantage of Rust's thread safe nature to provide an abstraction layer to higher level languages to run industry standard crytographic operations. Our goal is to decrease the redundancy of engineer's creating this layer proprietary within their internal systems. ## Consuming Library Documentation We utilize some smart people's existing work and we believe their documentation should be reviewed when possible. - [Spin Research](https://github.com/SpinResearch) - [Dalek-Cryptography](https://github.com/dalek-cryptography) - [Rust Crypto](https://github.com/RustCrypto) -- [Rayon](https://github.com/rayon-rs/rayon) ## Disclaimer diff --git a/src/aes.rs b/src/aes.rs index b949b27..ecad890 100644 --- a/src/aes.rs +++ b/src/aes.rs @@ -64,34 +64,7 @@ pub extern "C" fn aes_256_key_and_nonce_from_x25519_diffie_hellman_shared_secret result } -#[no_mangle] -pub extern "C" fn aes_256_key_and_nonce_from_x25519_diffie_hellman_shared_secret_threadpool( - shared_secret: *const c_uchar, - shared_secret_length: usize, -) -> AesNonceAndKeyFromX25519DiffieHellman { - let shared_secret_slice: Vec = - unsafe { std::slice::from_raw_parts(shared_secret, shared_secret_length) }.to_vec(); - let mut aes_nonce = Vec::with_capacity(12); - aes_nonce.resize(12, 0); - aes_nonce.copy_from_slice(&shared_secret_slice[..12]); - let capacity = aes_nonce.capacity(); - aes_nonce.reserve_exact(capacity); - - let mut aes_key = ::key_from_vec_threadpool(shared_secret_slice); - let aes_key_capacity = aes_key.capacity(); - aes_key.reserve_exact(aes_key_capacity); - - let result = AesNonceAndKeyFromX25519DiffieHellman { - aes_key_ptr: aes_key.as_mut_ptr(), - aes_key_ptr_length: aes_key.len(), - aes_nonce_ptr: aes_nonce.as_mut_ptr(), - aes_nonce_ptr_length: aes_nonce.len() - }; - std::mem::forget(aes_nonce); - std::mem::forget(aes_key); - result -} #[test] pub fn aes_256_key_and_nonce_from_x25519_diffie_hellman_shared_secret_test() { @@ -180,36 +153,7 @@ pub extern "C" fn aes_128_key_and_nonce_from_x25519_diffie_hellman_shared_secret result } -#[no_mangle] -pub extern "C" fn aes_128_key_and_nonce_from_x25519_diffie_hellman_shared_secret_threadpool( - shared_secret: *const c_uchar, - shared_secret_length: usize, -) -> AesNonceAndKeyFromX25519DiffieHellman { - let shared_secret_slice: Vec = - unsafe { std::slice::from_raw_parts(shared_secret, shared_secret_length) }.to_vec(); - let mut shorted_shared_secret: [u8; 16] = Default::default(); - shorted_shared_secret.copy_from_slice(&shared_secret_slice[..16]); - let mut aes_nonce = Vec::with_capacity(12); - aes_nonce.resize(12, 0); - aes_nonce.copy_from_slice(&shared_secret_slice[..12]); - let capacity = aes_nonce.capacity(); - aes_nonce.reserve_exact(capacity); - - let mut aes_key = ::key_from_vec_threadpool(shorted_shared_secret.to_vec()); - let aes_key_capacity = aes_key.capacity(); - aes_key.reserve_exact(aes_key_capacity); - - let result = AesNonceAndKeyFromX25519DiffieHellman { - aes_key_ptr: aes_key.as_mut_ptr(), - aes_key_ptr_length: aes_key.len(), - aes_nonce_ptr: aes_nonce.as_mut_ptr(), - aes_nonce_ptr_length: aes_nonce.len() - }; - std::mem::forget(aes_nonce); - std::mem::forget(aes_key); - result -} #[test] pub fn aes_128_key_and_nonce_from_x25519_diffie_hellman_shared_secret_test() { @@ -280,18 +224,7 @@ pub extern "C" fn aes_nonce() -> AesNonce { result } -#[no_mangle] -pub extern "C" fn aes_nonce_threadpool() -> AesNonce { - let mut random_bytes = ::generate_nonce_threadpool(); - let capacity = random_bytes.capacity(); - random_bytes.reserve_exact(capacity); - let result = AesNonce { - nonce: random_bytes.as_mut_ptr(), - length: random_bytes.len() - }; - std::mem::forget(random_bytes); - result -} + #[no_mangle] pub extern "C" fn aes_256_key() -> AesKeyResult { @@ -306,18 +239,7 @@ pub extern "C" fn aes_256_key() -> AesKeyResult { result } -#[no_mangle] -pub extern "C" fn aes_256_key_threadpool() -> AesKeyResult { - let mut key = ::generate_key_threadpool(); - let capacity = key.capacity(); - key.reserve_exact(capacity); - let result = AesKeyResult { - key: key.as_mut_ptr(), - length: key.len() - }; - std::mem::forget(key); - result -} + #[no_mangle] pub extern "C" fn aes_128_key() -> AesKeyResult { @@ -332,18 +254,7 @@ pub extern "C" fn aes_128_key() -> AesKeyResult { result } -#[no_mangle] -pub extern "C" fn aes_128_key_threadpool() -> AesKeyResult { - let mut key = ::generate_key_threadpool(); - let capacity = key.capacity(); - key.reserve_exact(capacity); - let result = AesKeyResult { - key: key.as_mut_ptr(), - length: key.len() - }; - std::mem::forget(key); - result -} + #[no_mangle] @@ -370,29 +281,7 @@ pub extern "C" fn aes_128_encrypt_bytes_with_key( return result; } -#[no_mangle] -pub extern "C" fn aes_128_encrypt_bytes_with_key_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, -) -> AesBytesEncrypt { - let nonce_slice: Vec = unsafe { std::slice::from_raw_parts(nonce_key, nonce_key_length) }.to_vec(); - let key_slice: Vec = unsafe {std::slice::from_raw_parts(key, key_length)}.to_vec(); - let to_encrypt_slice: Vec = - unsafe { std::slice::from_raw_parts(to_encrypt, to_encrypt_length) }.to_vec(); - let mut ciphertext = ::encrypt_plaintext_threadpool(key_slice, nonce_slice, to_encrypt_slice); - let capacity = ciphertext.capacity(); - ciphertext.reserve_exact(capacity); - let result = AesBytesEncrypt { - ciphertext: ciphertext.as_mut_ptr(), - length: ciphertext.len(), - }; - std::mem::forget(ciphertext); - return result; -} + #[no_mangle] pub extern "C" fn aes_256_encrypt_bytes_with_key( @@ -417,28 +306,7 @@ pub extern "C" fn aes_256_encrypt_bytes_with_key( return result; } -#[no_mangle] -pub extern "C" fn aes_256_encrypt_bytes_with_key_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, -) -> AesBytesEncrypt { - let nonce_slice = unsafe { std::slice::from_raw_parts(nonce_key, nonce_key_length) }.to_vec(); - let key_slice = unsafe {std::slice::from_raw_parts(key, key_length)}.to_vec(); - let to_encrypt_slice = unsafe { std::slice::from_raw_parts(to_encrypt, to_encrypt_length) }.to_vec(); - let mut ciphertext = ::encrypt_plaintext_threadpool(key_slice, nonce_slice, to_encrypt_slice); - let capacity = ciphertext.capacity(); - ciphertext.reserve_exact(capacity); - let result = AesBytesEncrypt { - ciphertext: ciphertext.as_mut_ptr(), - length: ciphertext.len(), - }; - std::mem::forget(ciphertext); - return result; -} + #[no_mangle] pub extern "C" fn aes_128_decrypt_bytes_with_key( @@ -463,29 +331,6 @@ pub extern "C" fn aes_128_decrypt_bytes_with_key( return result; } -#[no_mangle] -pub extern "C" fn aes_128_decrypt_bytes_with_key_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, -) -> AesBytesDecrypt { - let nonce_slice = unsafe { std::slice::from_raw_parts(nonce_key, nonce_key_length) }.to_vec(); - let key_slice = unsafe {std::slice::from_raw_parts(key, key_length)}.to_vec(); - let to_decrypt_slice = unsafe { std::slice::from_raw_parts(to_decrypt, to_decrypt_length) }.to_vec(); - let mut plaintext = ::decrypt_ciphertext_threadpool(key_slice, nonce_slice, to_decrypt_slice); - let capacity = plaintext.capacity(); - plaintext.reserve_exact(capacity); - let result = AesBytesDecrypt { - plaintext: plaintext.as_mut_ptr(), - length: plaintext.len(), - }; - std::mem::forget(plaintext); - return result; -} - #[no_mangle] pub extern "C" fn aes_256_decrypt_bytes_with_key( nonce_key: *const c_uchar, @@ -508,26 +353,3 @@ pub extern "C" fn aes_256_decrypt_bytes_with_key( std::mem::forget(plaintext); return result; } - -#[no_mangle] -pub extern "C" fn aes_256_decrypt_bytes_with_key_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, -) -> AesBytesDecrypt { - let nonce_slice = unsafe { std::slice::from_raw_parts(nonce_key, nonce_key_length) }.to_vec(); - let key_slice = unsafe {std::slice::from_raw_parts(key, key_length)}.to_vec(); - let to_decrypt_slice = unsafe { std::slice::from_raw_parts(to_decrypt, to_decrypt_length) }.to_vec(); - let mut plaintext = ::decrypt_ciphertext_threadpool(key_slice, nonce_slice, to_decrypt_slice); - let capacity = plaintext.capacity(); - plaintext.reserve_exact(capacity); - let result = AesBytesDecrypt { - plaintext: plaintext.as_mut_ptr(), - length: plaintext.len(), - }; - std::mem::forget(plaintext); - return result; -} diff --git a/src/ascon_aead.rs b/src/ascon_aead.rs index b3c15ee..ede4189 100644 --- a/src/ascon_aead.rs +++ b/src/ascon_aead.rs @@ -39,19 +39,6 @@ pub extern "C" fn ascon_128_key() -> Ascon128Key { result } -#[no_mangle] -pub extern "C" fn ascon_128_key_threadpool() -> Ascon128Key { - let mut key = ::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] @@ -67,18 +54,6 @@ pub extern "C" fn ascon_128_nonce() -> Ascon128Nonce { result } -#[no_mangle] -pub extern "C" fn ascon_128_nonce_threadpool() -> Ascon128Nonce { - let mut nonce = ::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( @@ -103,28 +78,7 @@ pub extern "C" fn ascon_128_encrypt( result } -#[no_mangle] -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, -) -> 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 = ::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 -} + #[no_mangle] @@ -148,27 +102,4 @@ pub extern "C" fn ascon_128_decrypt( }; std::mem::forget(plaintext); result -} - -#[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 = ::decrypt_threadpool(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 } \ No newline at end of file diff --git a/src/blake2/mod.rs b/src/blake2/mod.rs index df9af5e..a5e1d25 100644 --- a/src/blake2/mod.rs +++ b/src/blake2/mod.rs @@ -27,27 +27,6 @@ pub extern "C" fn blake2_512_bytes( return_result } -#[no_mangle] -pub extern "C" fn blake2_512_bytes_threadpool( - data: *const c_uchar, - data_length: usize, -) -> Blake2HashByteResult { - let data_slice = unsafe { - assert!(!data.is_null()); - std::slice::from_raw_parts(data, data_length) - } - .to_vec(); - let mut result: Vec = ::hash_512_threadpool(data_slice); - let capacity = result.capacity(); - result.reserve_exact(capacity); - let return_result = Blake2HashByteResult { - result_bytes_ptr: result.as_mut_ptr(), - length: result.len(), - }; - std::mem::forget(result); - return_result -} - #[test] fn blake2_512_bytes_test() { let data_to_hash = "Blake2512HashingTechnique"; @@ -78,28 +57,6 @@ pub extern "C" fn blake2_512_bytes_verify( return ::verify_512(data_slice, to_compare_slice); } -#[no_mangle] -pub extern "C" fn blake2_512_bytes_verify_threadpool( - hashed_data: *const c_uchar, - hashed_data_length: usize, - to_compare: *const c_uchar, - to_compare_length: usize, -) -> bool { - let data_slice = unsafe { - assert!(!hashed_data.is_null()); - std::slice::from_raw_parts(hashed_data, hashed_data_length) - } - .to_vec(); - let to_compare_slice = unsafe { - assert!(!to_compare.is_null()); - std::slice::from_raw_parts(to_compare, to_compare_length) - } - .to_vec(); - let result: bool = - ::verify_512_threadpool(data_slice, to_compare_slice); - result -} - #[no_mangle] pub extern "C" fn blake2_256_bytes( data_to_hash: *const c_uchar, @@ -121,27 +78,6 @@ pub extern "C" fn blake2_256_bytes( return return_result; } -#[no_mangle] -pub extern "C" fn blake2_256_bytes_threadpool( - data_to_hash: *const c_uchar, - data_to_hash_length: usize, -) -> Blake2HashByteResult { - let data_to_hash_slice = unsafe { - assert!(!data_to_hash.is_null()); - std::slice::from_raw_parts(data_to_hash, data_to_hash_length) - } - .to_vec(); - let mut result = ::hash_256_threadpool(data_to_hash_slice); - let capacity = result.capacity(); - result.reserve_exact(capacity); - let return_result = Blake2HashByteResult { - result_bytes_ptr: result.as_mut_ptr(), - length: result.len(), - }; - std::mem::forget(result); - return_result -} - #[test] fn blake2_256_bytes_test() { let data_to_hash = "Blake2256HashingTechnique"; @@ -174,26 +110,6 @@ pub extern "C" fn blake2_256_bytes_verify( result } -#[no_mangle] -pub extern "C" fn blake2_256_bytes_verify_threadpool( - hashed_data: *const c_uchar, - hashed_data_length: usize, - to_compare: *const c_uchar, - to_compare_length: usize, -) -> bool { - let data_slice = unsafe { - assert!(!hashed_data.is_null()); - std::slice::from_raw_parts(hashed_data, hashed_data_length) - } - .to_vec(); - let to_compare_slice = unsafe { - assert!(!to_compare.is_null()); - std::slice::from_raw_parts(to_compare, to_compare_length) - } - .to_vec(); - let result = ::verify_256_threadpool(data_slice, to_compare_slice); - result -} #[test] fn blake2_256_bytes_verify_test() { diff --git a/src/digital_signature.rs b/src/digital_signature.rs index 29bf0ab..154d257 100644 --- a/src/digital_signature.rs +++ b/src/digital_signature.rs @@ -53,35 +53,6 @@ pub extern "C" fn sha_512_rsa_digital_signature( result } -#[no_mangle] -pub extern "C" fn sha_512_rsa_digital_signature_threadpool( - rsa_key_size: usize, - data_to_sign: *const c_uchar, - data_length: usize, -) -> SHARSADigitalSignatureResult { - assert!(!data_to_sign.is_null()); - let data_to_sign_slice = - unsafe { std::slice::from_raw_parts(data_to_sign, data_length) }.to_vec(); - if rsa_key_size != 1024 && rsa_key_size != 2048 && rsa_key_size != 4096 { - panic!("Not a valid RSA key length"); - } - let result = ::digital_signature_rsa_threadpool( - rsa_key_size as u32, - data_to_sign_slice, - ); - let mut signed_data = result.signature; - let capacity = signed_data.capacity(); - signed_data.reserve_exact(capacity); - let result = SHARSADigitalSignatureResult { - public_key: CString::new(result.public_key).unwrap().into_raw(), - private_key: CString::new(result.private_key).unwrap().into_raw(), - signature_raw_ptr: signed_data.as_mut_ptr(), - length: signed_data.len(), - }; - std::mem::forget(signed_data); - result -} - #[no_mangle] pub extern "C" fn sha_256_rsa_digital_signature( rsa_key_size: usize, @@ -111,35 +82,6 @@ pub extern "C" fn sha_256_rsa_digital_signature( result } -#[no_mangle] -pub extern "C" fn sha_256_rsa_digital_signature_threadpool( - rsa_key_size: usize, - data_to_sign: *const c_uchar, - data_length: usize, -) -> SHARSADigitalSignatureResult { - assert!(!data_to_sign.is_null()); - let data_to_sign_slice = - unsafe { std::slice::from_raw_parts(data_to_sign, data_length) }.to_vec(); - if rsa_key_size != 1024 && rsa_key_size != 2048 && rsa_key_size != 4096 { - panic!("Not a valid RSA key length"); - } - let result = ::digital_signature_rsa_threadpool( - rsa_key_size as u32, - data_to_sign_slice, - ); - let mut signed_data = result.signature; - let capacity = signed_data.capacity(); - signed_data.reserve_exact(capacity); - let result = SHARSADigitalSignatureResult { - public_key: CString::new(result.public_key).unwrap().into_raw(), - private_key: CString::new(result.private_key).unwrap().into_raw(), - signature_raw_ptr: signed_data.as_mut_ptr(), - length: signed_data.len(), - }; - std::mem::forget(signed_data); - result -} - #[no_mangle] pub extern "C" fn sha_512_rsa_digital_signature_verify( public_key: *const c_char, @@ -173,38 +115,7 @@ pub extern "C" fn sha_512_rsa_digital_signature_verify( result } -#[no_mangle] -pub extern "C" fn sha_512_rsa_digital_signature_verify_threadpool( - public_key: *const c_char, - data_to_verify: *const c_uchar, - data_to_verify_length: usize, - signature: *const c_uchar, - signature_length: usize, -) -> bool { - let public_key_string = unsafe { - assert!(!public_key.is_null()); - CStr::from_ptr(public_key) - } - .to_str() - .unwrap() - .to_string(); - let data_to_verify_slice: Vec = unsafe { - assert!(!data_to_verify.is_null()); - std::slice::from_raw_parts(data_to_verify, data_to_verify_length) - } - .to_vec(); - let signature_slice: Vec = unsafe { - assert!(!signature.is_null()); - std::slice::from_raw_parts(signature, signature_length) - } - .to_vec(); - let result = ::verify_rsa_threadpool( - public_key_string, - data_to_verify_slice, - signature_slice, - ); - result -} + #[no_mangle] pub extern "C" fn sha_256_rsa_digital_signature_verify( @@ -239,38 +150,6 @@ pub extern "C" fn sha_256_rsa_digital_signature_verify( result } -#[no_mangle] -pub extern "C" fn sha_256_rsa_digital_signature_verify_threadpool( - public_key: *const c_char, - data_to_verify: *const c_uchar, - data_to_verify_length: usize, - signature: *const c_uchar, - signature_length: usize, -) -> bool { - let public_key_string = unsafe { - assert!(!public_key.is_null()); - CStr::from_ptr(public_key) - } - .to_str() - .unwrap() - .to_string(); - let data_to_verify_slice: Vec = unsafe { - assert!(!data_to_verify.is_null()); - std::slice::from_raw_parts(data_to_verify, data_to_verify_length) - } - .to_vec(); - let signature_slice: Vec = unsafe { - assert!(!signature.is_null()); - std::slice::from_raw_parts(signature, signature_length) - } - .to_vec(); - let result = ::verify_rsa_threadpool( - public_key_string, - data_to_verify_slice, - signature_slice, - ); - result -} #[no_mangle] pub extern "C" fn sha512_ed25519_digital_signature( @@ -303,37 +182,6 @@ pub extern "C" fn sha512_ed25519_digital_signature( result } -#[no_mangle] -pub extern "C" fn sha512_ed25519_digital_signature_threadpool( - data_to_sign: *const c_uchar, - data_length: usize, -) -> SHAED25519DalekDigitalSignatureResult { - let data_to_sign_slice = unsafe { - assert!(!data_to_sign.is_null()); - std::slice::from_raw_parts(data_to_sign, data_length) - } - .to_vec(); - let result = - ::digital_signature_ed25519_threadpool( - data_to_sign_slice, - ); - let mut public_key = result.public_key; - let public_key_capacity = public_key.capacity(); - public_key.reserve_exact(public_key_capacity); - let mut signature = result.signature; - let signature_capacity = signature.capacity(); - signature.reserve_exact(signature_capacity); - let result = SHAED25519DalekDigitalSignatureResult { - public_key: public_key.as_mut_ptr(), - public_key_length: public_key.len(), - signature_raw_ptr: signature.as_mut_ptr(), - signature_length: signature.len(), - }; - std::mem::forget(public_key); - std::mem::forget(signature); - result -} - #[no_mangle] pub extern "C" fn sha256_ed25519_digital_signature( data_to_sign: *const c_uchar, @@ -365,37 +213,6 @@ pub extern "C" fn sha256_ed25519_digital_signature( result } -#[no_mangle] -pub extern "C" fn sha256_ed25519_digital_signature_threadpool( - data_to_sign: *const c_uchar, - data_length: usize, -) -> SHAED25519DalekDigitalSignatureResult { - let data_to_sign_slice = unsafe { - assert!(!data_to_sign.is_null()); - std::slice::from_raw_parts(data_to_sign, data_length) - } - .to_vec(); - let result = - ::digital_signature_ed25519_threadpool( - data_to_sign_slice, - ); - let mut public_key = result.public_key; - let public_key_capacity = public_key.capacity(); - public_key.reserve_exact(public_key_capacity); - let mut signature = result.signature; - let signature_capacity = signature.capacity(); - signature.reserve_exact(signature_capacity); - let result = SHAED25519DalekDigitalSignatureResult { - public_key: public_key.as_mut_ptr(), - public_key_length: public_key.len(), - signature_raw_ptr: signature.as_mut_ptr(), - signature_length: signature.len(), - }; - std::mem::forget(public_key); - std::mem::forget(signature); - result -} - #[no_mangle] pub extern "C" fn sha512_ed25519_digital_signature_verify( public_key: *const c_uchar, @@ -424,34 +241,6 @@ pub extern "C" fn sha512_ed25519_digital_signature_verify( result } -#[no_mangle] -pub extern "C" fn sha512_ed25519_digital_signature_verify_threadpool( - public_key: *const c_uchar, - public_key_length: usize, - data_to_verify: *const c_uchar, - data_to_verify_length: usize, - signature: *const c_uchar, - signature_length: usize, -) -> bool { - let public_key_slice = unsafe { - assert!(!public_key.is_null()); - std::slice::from_raw_parts(public_key, public_key_length) - } - .to_vec(); - let data_to_verify_slice = unsafe { - assert!(!data_to_verify.is_null()); - std::slice::from_raw_parts(data_to_verify, data_to_verify_length) - } - .to_vec(); - let signature_slice = unsafe { - assert!(!signature.is_null()); - std::slice::from_raw_parts(signature, signature_length) - } - .to_vec(); - let result = ::digital_signature_ed25519_verify_threadpool(public_key_slice, data_to_verify_slice, signature_slice); - result -} - #[no_mangle] pub extern "C" fn sha256_ed25519_digital_signature_verify( public_key: *const c_uchar, @@ -478,32 +267,4 @@ pub extern "C" fn sha256_ed25519_digital_signature_verify( .to_vec(); let result = ::digital_signature_ed25519_verify(public_key_slice, data_to_verify_slice, signature_slice); result -} - -#[no_mangle] -pub extern "C" fn sha256_ed25519_digital_signature_verify_threadpool( - public_key: *const c_uchar, - public_key_length: usize, - data_to_verify: *const c_uchar, - data_to_verify_length: usize, - signature: *const c_uchar, - signature_length: usize, -) -> bool { - let public_key_slice = unsafe { - assert!(!public_key.is_null()); - std::slice::from_raw_parts(public_key, public_key_length) - } - .to_vec(); - let data_to_verify_slice = unsafe { - assert!(!data_to_verify.is_null()); - std::slice::from_raw_parts(data_to_verify, data_to_verify_length) - } - .to_vec(); - let signature_slice = unsafe { - assert!(!signature.is_null()); - std::slice::from_raw_parts(signature, signature_length) - } - .to_vec(); - let result = ::digital_signature_ed25519_verify_threadpool(public_key_slice, data_to_verify_slice, signature_slice); - result } \ No newline at end of file diff --git a/src/ed25519.rs b/src/ed25519.rs index 5625c33..4774227 100644 --- a/src/ed25519.rs +++ b/src/ed25519.rs @@ -1,4 +1,4 @@ -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}; use libc::c_uchar; #[repr(C)] @@ -28,19 +28,6 @@ pub extern "C" fn get_ed25519_key_pair_bytes() -> Ed25519KeyPairBytesResult { result } -#[no_mangle] -pub extern "C" fn get_ed25519_key_pair_bytes_threadpool() -> Ed25519KeyPairBytesResult { - let mut keypair = get_ed25519_key_pair_threadpool(); - let capacity = keypair.capacity(); - keypair.reserve_exact(capacity); - let result = Ed25519KeyPairBytesResult { - length: keypair.len(), - key_pair: keypair.as_mut_ptr(), - }; - std::mem::forget(keypair); - result -} - #[test] fn get_ed25519_key_pair_bytes_test() { @@ -84,40 +71,6 @@ pub extern "C" fn sign_with_key_pair_bytes( result } -#[no_mangle] -pub extern "C" fn sign_with_key_pair_bytes_threadpool( - key_pair: *const c_uchar, - key_pair_length: usize, - message_to_sign: *const c_uchar, - message_to_sign_length: usize, -) -> Ed25519ByteSignatureResult { - let key_pair_slice = unsafe { - assert!(!key_pair.is_null()); - std::slice::from_raw_parts(key_pair, key_pair_length) - } - .to_vec(); - let message_to_sign_slice = unsafe { - assert!(!message_to_sign.is_null()); - std::slice::from_raw_parts(message_to_sign, message_to_sign_length) - } - .to_vec(); - let result = ed25519_sign_with_key_pair_threadpool(key_pair_slice, message_to_sign_slice); - let mut public_key = result.public_key; - let public_key_capacity = public_key.capacity(); - public_key.reserve_exact(public_key_capacity); - let mut signature = result.signature; - let siganture_capacity = signature.capacity(); - signature.reserve_exact(siganture_capacity); - let result = Ed25519ByteSignatureResult { - signature_byte_ptr: signature.as_mut_ptr(), - signature_length: signature.len(), - public_key: public_key.as_mut_ptr(), - public_key_length: public_key.len(), - }; - std::mem::forget(public_key); - std::mem::forget(signature); - result -} #[test] fn sign_with_key_pair_bytes_test() { @@ -160,29 +113,6 @@ pub extern "C" fn verify_with_key_pair_bytes( return ed25519_verify_with_key_pair(key_pair_slice, signature_slice, message_slice); } -#[no_mangle] -pub extern "C" fn verify_with_key_pair_bytes_threadpool( - key_pair: *const c_uchar, - key_pair_length: usize, - signature: *const c_uchar, - signature_length: usize, - message: *const c_uchar, - message_length: usize, -) -> bool { - let key_pair_slice = unsafe { - assert!(!key_pair.is_null()); - std::slice::from_raw_parts(key_pair, key_pair_length) - }.to_vec(); - let signature_slice = unsafe { - assert!(!signature.is_null()); - std::slice::from_raw_parts(signature, signature_length) - }.to_vec(); - let message_slice = unsafe { - assert!(!message.is_null()); - std::slice::from_raw_parts(message, message_length) - }.to_vec(); - return ed25519_verify_with_key_pair_threadpool(key_pair_slice, signature_slice, message_slice); -} #[test] fn verify_with_key_pair_bytes_test() { @@ -229,30 +159,6 @@ pub extern "C" fn verify_with_public_key_bytes( return ed25519_verify_with_public_key(public_key_slice, signature_slice, message_slice); } -#[no_mangle] -pub extern "C" fn verify_with_public_key_bytes_threadpool( - public_key: *const c_uchar, - public_key_length: usize, - signature: *const c_uchar, - signature_length: usize, - message: *const c_uchar, - message_length: usize, -) -> bool { - let public_key_slice = unsafe { - assert!(!public_key.is_null()); - std::slice::from_raw_parts(public_key, public_key_length) - }.to_vec(); - let signature_slice = unsafe { - assert!(!signature.is_null()); - std::slice::from_raw_parts(signature, signature_length) - }.to_vec(); - let message_slice = unsafe { - assert!(!message.is_null()); - std::slice::from_raw_parts(message, message_length) - }.to_vec(); - return ed25519_verify_with_public_key_threadpool(public_key_slice, signature_slice, message_slice); -} - #[test] fn verify_with_public_key_bytes_test() { let key_pair = get_ed25519_key_pair_bytes(); diff --git a/src/hmac/mod.rs b/src/hmac/mod.rs index 711804a..af3597d 100644 --- a/src/hmac/mod.rs +++ b/src/hmac/mod.rs @@ -28,29 +28,6 @@ pub extern "C" fn hmac_sign_bytes( return_result } -#[no_mangle] -pub extern "C" fn hmac_sign_bytes_threadpool( - key: *const c_uchar, - key_length: usize, - message: *const c_uchar, - message_length: usize, -) -> HmacSignByteResult { - assert!(!key.is_null()); - assert!(!message.is_null()); - let key_slice: Vec = unsafe { std::slice::from_raw_parts(key, key_length) }.to_vec(); - let message_slice: Vec = - unsafe { std::slice::from_raw_parts(message, message_length) }.to_vec(); - let mut result = ::sign_threadpool(key_slice, message_slice); - let capacity = result.capacity(); - result.reserve_exact(capacity); - let return_result = HmacSignByteResult { - result_bytes_ptr: result.as_mut_ptr(), - length: result.len(), - }; - std::mem::forget(result); - return_result -} - #[test] fn hmac_sign_bytes_test() { let data_to_sign = "Bad Hmac Test"; @@ -87,25 +64,6 @@ pub extern "C" fn hmac_verify_bytes( result } -#[no_mangle] -pub extern "C" fn hmac_verify_bytes_threadpool( - key: *const c_uchar, - key_length: usize, - message: *const c_uchar, - message_length: usize, - signature: *const c_uchar, - signature_length: usize, -) -> bool { - assert!(!key.is_null()); - assert!(!message.is_null()); - assert!(!signature.is_null()); - let key_slice: Vec = unsafe { std::slice::from_raw_parts(key, key_length) }.to_vec(); - let message_slice: Vec = unsafe { std::slice::from_raw_parts(message, message_length) }.to_vec(); - let signature_slice: Vec = unsafe { std::slice::from_raw_parts(signature, signature_length) }.to_vec(); - let result = ::verify_threadpool(key_slice, message_slice, signature_slice); - result -} - #[test] fn hmac_verify_bytes_test() { let data_to_sign = "Bad Hmac Test 1234567890"; diff --git a/src/password_hashers/argon2.rs b/src/password_hashers/argon2.rs index 6434cc5..f0e7395 100644 --- a/src/password_hashers/argon2.rs +++ b/src/password_hashers/argon2.rs @@ -75,41 +75,6 @@ fn argon2_verify_test() { assert_eq!(true, is_valid); } -#[no_mangle] -pub extern "C" fn argon2_verify_threadpool(hashed_pass: *const c_char, password: *const c_char) -> bool { - let hashed_pass_string = unsafe { - assert!(!hashed_pass.is_null()); - CStr::from_ptr(hashed_pass) - } - .to_str() - .unwrap() - .to_string(); - - let password_string = unsafe { - assert!(!password.is_null()); - CStr::from_ptr(password) - } - .to_str() - .unwrap() - .to_string(); - let result: bool = CASArgon::verify_password_threadpool(hashed_pass_string, password_string); - result -} - -#[test] -fn argon2_verify_threadpool_test() { - let password = "PasswordToVerify"; - let password_cstr = CString::new(password).unwrap(); - let password_bytes = password_cstr.as_bytes_with_nul(); - let password_ptr = password_bytes.as_ptr() as *const i8; - let hashed_password = argon2_hash_threadpool(password_ptr); - let hashed_password_ctr = unsafe { CString::from_raw(hashed_password) }; - let hashed_password_bytes = hashed_password_ctr.as_bytes_with_nul(); - let hashed_password_ptr = hashed_password_bytes.as_ptr() as *const i8; - let is_valid = argon2_verify_threadpool(hashed_password_ptr, password_ptr); - assert_eq!(true, is_valid); -} - #[no_mangle] pub extern "C" fn argon2_hash(pass_to_hash: *const c_char) -> *mut c_char { let password = unsafe { @@ -134,30 +99,4 @@ fn argon2_hash_test() { let hashed_password_ctr = unsafe { CString::from_raw(hashed_password_ptr) }; let hashed_password_str = hashed_password_ctr.to_str().unwrap(); assert_ne!(password, hashed_password_str); -} - -#[no_mangle] -pub extern "C" fn argon2_hash_threadpool(pass_to_hash: *const c_char) -> *mut c_char { - let password = unsafe { - assert!(!pass_to_hash.is_null()); - CStr::from_ptr(pass_to_hash) - } - .to_str() - .unwrap() - .to_string(); - let new_hash = CASArgon::hash_password_threadpool(password); - let result = CString::new(new_hash).unwrap().into_raw(); - result -} - -#[test] -fn argon2_hash_threadpool_test() { - let password = "DontUseThisPassword"; - let password_cstr = CString::new(password).unwrap(); - let password_bytes = password_cstr.as_bytes_with_nul(); - let password_ptr = password_bytes.as_ptr() as *const i8; - let hashed_password_ptr = argon2_hash_threadpool(password_ptr); - let hashed_password_ctr = unsafe { CString::from_raw(hashed_password_ptr) }; - let hashed_password_str = hashed_password_ctr.to_str().unwrap(); - assert_ne!(password, hashed_password_str); } \ No newline at end of file diff --git a/src/password_hashers/bcrypt.rs b/src/password_hashers/bcrypt.rs index 96fd076..532848a 100644 --- a/src/password_hashers/bcrypt.rs +++ b/src/password_hashers/bcrypt.rs @@ -29,32 +29,6 @@ fn bcrypt_hash_test() { assert_ne!(hashed_password_str, password); } -#[no_mangle] -pub extern "C" fn bcrypt_hash_threadpool(pass_to_hash: *const c_char) -> *mut c_char { - let string_pass = unsafe { - assert!(!pass_to_hash.is_null()); - - CStr::from_ptr(pass_to_hash) - } - .to_str() - .unwrap() - .to_string(); - let new_hash = CASBCrypt::hash_password_threadpool(string_pass); - return CString::new(new_hash).unwrap().into_raw(); -} - -#[test] -fn bcrypt_hash_threadpool_test() { - let password = "PasswordToHash"; - let password_cstr = CString::new(password).unwrap(); - let password_bytes = password_cstr.as_bytes_with_nul(); - let passsword_ptr = password_bytes.as_ptr() as *const i8; - let hashed_password = bcrypt_hash_threadpool(passsword_ptr); - let hashed_password_ctr = unsafe { CString::from_raw(hashed_password) }; - let hashed_password_str = hashed_password_ctr.to_str().unwrap(); - assert_ne!(hashed_password_str, password); -} - #[no_mangle] pub extern "C" fn bcrypt_verify(pass: *const c_char, hash: *const c_char) -> bool { let string_pass = unsafe { @@ -91,38 +65,3 @@ fn bcrypt_verify_test() { assert_eq!(true, is_valid); } -#[no_mangle] -pub extern "C" fn bcrypt_verify_threadpool(pass: *const c_char, hash: *const c_char) -> bool { - let string_pass = unsafe { - assert!(!pass.is_null()); - - CStr::from_ptr(pass) - } - .to_str() - .unwrap() - .to_string(); - - let string_hash = unsafe { - assert!(!hash.is_null()); - - CStr::from_ptr(hash) - } - .to_str() - .unwrap() - .to_string(); - return ::verify_password(string_hash, string_pass); -} - -#[test] -fn bcrypt_verify_threadpool_test() { - let password = "PasswordToHash"; - let password_cstr = CString::new(password).unwrap(); - let password_bytes = password_cstr.as_bytes_with_nul(); - let password_ptr = password_bytes.as_ptr() as *const i8; - let hashed_password = bcrypt_hash_threadpool(password_ptr); - let hashed_password_ctr = unsafe { CString::from_raw(hashed_password) }; - let hashed_password_bytes = hashed_password_ctr.as_bytes_with_nul(); - let hashed_password_ptr = hashed_password_bytes.as_ptr() as *const i8; - let is_valid = bcrypt_verify_threadpool(password_ptr, hashed_password_ptr); - assert_eq!(true, is_valid); -} \ No newline at end of file diff --git a/src/password_hashers/scrypt.rs b/src/password_hashers/scrypt.rs index f87ad8e..0825991 100644 --- a/src/password_hashers/scrypt.rs +++ b/src/password_hashers/scrypt.rs @@ -27,32 +27,6 @@ fn scrypt_hash_test() { assert_ne!(hashed_str, password); } -#[no_mangle] -pub extern "C" fn scrypt_hash_threadpool(pass_to_hash: *const c_char) -> *mut c_char { - let string_pass = unsafe { - assert!(!pass_to_hash.is_null()); - - CStr::from_ptr(pass_to_hash) - } - .to_str() - .unwrap() - .to_string(); - let new_hash = CASScrypt::hash_password_threadpool(string_pass); - return CString::new(new_hash).unwrap().into_raw(); -} - -#[test] -fn scrypt_hash_threadpool_test() { - let password = "PasswordToTest"; - let password_cstr = CString::new(password).unwrap(); - let password_bytes = password_cstr.as_bytes_with_nul(); - let password_ptr = password_bytes.as_ptr() as *const i8; - let hashed = scrypt_hash_threadpool(password_ptr); - let hashed_ctr = unsafe { CString::from_raw(hashed) }; - let hashed_str = hashed_ctr.to_str().unwrap(); - assert_ne!(hashed_str, password); -} - #[no_mangle] pub extern "C" fn scrypt_verify( hash_to_check: *const c_char, @@ -91,44 +65,4 @@ fn scrypt_verify_test() { let hashed_ptr = hashed_bytes.as_ptr() as *const i8; let is_valid = scrypt_verify(hashed_ptr, password_ptr); assert_eq!(true, is_valid); -} - -#[no_mangle] -pub extern "C" fn scrypt_verify_threadpool( - pass_to_check: *const c_char, - hash_to_check: *const c_char, -) -> bool { - let string_pass = unsafe { - assert!(!pass_to_check.is_null()); - - CStr::from_ptr(pass_to_check) - } - .to_str() - .unwrap() - .to_string(); - - let string_hash = unsafe { - assert!(!hash_to_check.is_null()); - - CStr::from_ptr(hash_to_check) - } - .to_str() - .unwrap() - .to_string(); - - return ::verify_password(string_hash, string_pass); -} - -#[test] -fn scrypt_verify_threadpool_test() { - let password = "NotThePasswordYouAreLookingFor"; - let password_cstr = CString::new(password).unwrap(); - let password_bytes = password_cstr.as_bytes_with_nul(); - let password_ptr = password_bytes.as_ptr() as *const i8; - let hash = scrypt_hash_threadpool(password_ptr); - let hash_ctr = unsafe { CString::from_raw(hash) }; - let hashed_bytes = hash_ctr.as_bytes_with_nul(); - let hashed_ptr = hashed_bytes.as_ptr() as *const i8; - let is_valid = scrypt_verify_threadpool(password_ptr, hashed_ptr); - assert_eq!(true, is_valid); } \ No newline at end of file diff --git a/src/rsa/mod.rs b/src/rsa/mod.rs index 7aa2d66..55c36ee 100644 --- a/src/rsa/mod.rs +++ b/src/rsa/mod.rs @@ -17,16 +17,6 @@ pub extern "C" fn get_key_pair(key_size: usize) -> RsaKeyPair { result } -#[no_mangle] -pub extern "C" fn get_key_pair_threadpool(rsa_key_size: usize) -> RsaKeyPair { - let rsa_key_result: RSAKeyPairResult = ::generate_rsa_keys_threadpool(rsa_key_size); - let result = RsaKeyPair { - priv_key: CString::new(rsa_key_result.private_key).unwrap().into_raw(), - pub_key: CString::new(rsa_key_result.public_key).unwrap().into_raw() - }; - result -} - #[no_mangle] pub extern "C" fn rsa_sign_with_key_bytes( private_key: *const c_char, @@ -57,37 +47,6 @@ pub extern "C" fn rsa_sign_with_key_bytes( return result; } -#[no_mangle] -pub extern "C" fn rsa_sign_with_key_bytes_threadpool( - private_key: *const c_char, - data_to_sign: *const c_uchar, - data_to_sign_length: usize, -) -> RsaSignBytesResults { - let private_key_string = unsafe { - assert!(!private_key.is_null()); - - CStr::from_ptr(private_key) - } - .to_str() - .unwrap() - .to_string(); - - let data_to_sign_slice = unsafe { - assert!(!data_to_sign.is_null()); - std::slice::from_raw_parts(data_to_sign, data_to_sign_length) - }.to_vec(); - - let mut signed_data = ::sign_threadpool(private_key_string, data_to_sign_slice); - let capacity = signed_data.capacity(); - signed_data.reserve_exact(capacity); - let result = RsaSignBytesResults { - signature_raw_ptr: signed_data.as_mut_ptr(), - length: signed_data.len(), - }; - std::mem::forget(signed_data); - return result; -} - #[no_mangle] pub extern "C" fn rsa_verify_bytes( public_key: *const c_char, @@ -118,36 +77,6 @@ pub extern "C" fn rsa_verify_bytes( verified } -#[no_mangle] -pub extern "C" fn rsa_verify_bytes_threadpool( - public_key: *const c_char, - data_to_verify: *const c_uchar, - data_to_verify_length: usize, - signature: *const c_uchar, - signature_length: usize, -) -> bool { - let public_key_string = unsafe { - assert!(!public_key.is_null()); - - CStr::from_ptr(public_key) - } - .to_str() - .unwrap() - .to_string(); - - let data_to_verify_slice = unsafe { - assert!(!data_to_verify.is_null()); - std::slice::from_raw_parts(data_to_verify, data_to_verify_length) - }.to_vec(); - - let signature_slice = unsafe { - assert!(!signature.is_null()); - std::slice::from_raw_parts(signature, signature_length) - }.to_vec(); - let verified = ::verify_threadpool(public_key_string, data_to_verify_slice, signature_slice); - verified -} - #[test] fn get_key_pair_test() { let key_size = 4096 as usize; diff --git a/src/sha/mod.rs b/src/sha/mod.rs index ffe41d6..116bac1 100644 --- a/src/sha/mod.rs +++ b/src/sha/mod.rs @@ -21,24 +21,6 @@ pub extern "C" fn sha512_bytes(data_to_hash: *const c_uchar, data_len: usize) -> return_result } -#[no_mangle] -pub extern "C" fn sha512_bytes_threadpool( - data_to_hash: *const c_uchar, - data_len: usize, -) -> SHAHashByteResult { - assert!(!data_to_hash.is_null()); - let data_to_hash_slice = unsafe { std::slice::from_raw_parts(data_to_hash, data_len) }.to_vec(); - let mut result = ::hash_512_threadpool(data_to_hash_slice); - let capacity = result.capacity(); - result.reserve_exact(capacity); - let return_result = SHAHashByteResult { - result_bytes_ptr: result.as_mut_ptr(), - length: result.len(), - }; - std::mem::forget(result); - return_result -} - #[no_mangle] pub extern "C" fn sha512_bytes_verify( data_to_hash: *const c_uchar, @@ -55,23 +37,6 @@ pub extern "C" fn sha512_bytes_verify( result } -#[no_mangle] -pub extern "C" fn sha512_bytes_verify_threadpool( - data_to_hash: *const c_uchar, - data_len: usize, - data_to_verify: *const c_uchar, - data_to_verify_len: usize, -) -> bool { - assert!(!data_to_hash.is_null()); - assert!(!data_to_verify.is_null()); - let data_to_hash_slice = unsafe { std::slice::from_raw_parts(data_to_hash, data_len) }.to_vec(); - let data_to_verify_slice = - unsafe { std::slice::from_raw_parts(data_to_verify, data_to_verify_len) }.to_vec(); - let result = - ::verify_512_threadpool(data_to_verify_slice, data_to_hash_slice); - result -} - #[test] fn sha512_bytes_test() { let data_to_hash = "This is a test hash"; @@ -98,24 +63,6 @@ pub extern "C" fn sha256_bytes(data_to_hash: *const c_uchar, data_len: usize) -> return_result } -#[no_mangle] -pub extern "C" fn sha256_bytes_threadpool( - data_to_hash: *const c_uchar, - data_len: usize, -) -> SHAHashByteResult { - assert!(!data_to_hash.is_null()); - let data_to_hash_slice = unsafe { std::slice::from_raw_parts(data_to_hash, data_len) }.to_vec(); - let mut result = ::hash_256_threadpool(data_to_hash_slice); - let capacity = result.capacity(); - result.reserve_exact(capacity); - let return_result = SHAHashByteResult { - result_bytes_ptr: result.as_mut_ptr(), - length: result.len(), - }; - std::mem::forget(result); - return_result -} - #[no_mangle] pub extern "C" fn sha256_bytes_verify( data_to_hash: *const c_uchar, @@ -132,22 +79,6 @@ pub extern "C" fn sha256_bytes_verify( result } -#[no_mangle] -pub extern "C" fn sha256_bytes_verify_threadpool( - data_to_hash: *const c_uchar, - data_len: usize, - data_to_verify: *const c_uchar, - data_to_verify_len: usize, -) -> bool { - assert!(!data_to_hash.is_null()); - assert!(!data_to_verify.is_null()); - let data_to_hash_slice = unsafe { std::slice::from_raw_parts(data_to_hash, data_len) }.to_vec(); - let data_to_verify_slice = - unsafe { std::slice::from_raw_parts(data_to_verify, data_to_verify_len) }.to_vec(); - let result = ::verify_256_threadpool(data_to_verify_slice, data_to_hash_slice); - result -} - #[test] fn sha256_bytes_test() { let data_to_hash = "This is a test hash for SHA 256"; diff --git a/src/x25519.rs b/src/x25519.rs index 4559a88..26fa1d6 100644 --- a/src/x25519.rs +++ b/src/x25519.rs @@ -35,25 +35,6 @@ pub extern "C" fn generate_secret_and_public_key() -> x25519SecretPublicKeyResul result } -#[no_mangle] -pub extern "C" fn generate_secret_and_public_key_threadpool() -> x25519SecretPublicKeyResult { - let result = ::generate_secret_and_public_key_threadpool(); - let mut secret_key = result.secret_key; - let mut public_key = result.public_key; - let secret_key_capacity = secret_key.capacity(); - secret_key.reserve_exact(secret_key_capacity); - let public_key_capacity = public_key.capacity(); - public_key.reserve_exact(public_key_capacity); - let result = x25519SecretPublicKeyResult { - secret_key: secret_key.as_mut_ptr(), - secret_key_length: secret_key.len(), - public_key: public_key.as_mut_ptr(), - public_key_length: public_key.len(), - }; - std::mem::forget(public_key); - std::mem::forget(secret_key); - result -} #[test] pub fn diffie_hellman_test() { @@ -113,28 +94,4 @@ pub extern "C" fn diffie_hellman( }; std::mem::forget(result); return_result -} - -#[no_mangle] -pub extern "C" fn diffie_hellman_threadpool( - secret_key: *const c_uchar, - secret_key_length: usize, - other_user_public_key: *const c_uchar, - other_user_public_key_length: usize, -) -> x25519SharedSecretResult { - let secret_key_slice = - unsafe { std::slice::from_raw_parts(secret_key, secret_key_length) }.to_vec(); - let other_user_public_key = - unsafe { std::slice::from_raw_parts(other_user_public_key, other_user_public_key_length) } - .to_vec(); - let mut result = - ::diffie_hellman_threadpool(secret_key_slice, other_user_public_key); - let capacity = result.capacity(); - result.reserve_exact(capacity); - let return_result = x25519SharedSecretResult { - shared_secret: result.as_mut_ptr(), - shared_secret_length: result.len(), - }; - std::mem::forget(result); - return_result } \ No newline at end of file diff --git a/src/zstd/mod.rs b/src/zstd/mod.rs index cf1b0c5..e3551ca 100644 --- a/src/zstd/mod.rs +++ b/src/zstd/mod.rs @@ -21,20 +21,6 @@ pub extern "C" fn decompress(data_to_decompress: *const c_uchar, data_to_decompr result } -#[no_mangle] -pub extern "C" fn decompress_threadpool(data_to_decompress: *const c_uchar, data_to_decompress_length: usize) -> ZstdCompressResult { - let data_to_decompress = unsafe { std::slice::from_raw_parts(data_to_decompress, data_to_decompress_length) }.to_vec(); - let mut decompressed_data = zstd::decompress_threadpool(data_to_decompress); - let capacity = decompressed_data.capacity(); - decompressed_data.reserve_exact(capacity); - let result = ZstdCompressResult { - data: decompressed_data.as_mut_ptr(), - length: decompressed_data.len() - }; - std::mem::forget(decompressed_data); - result -} - #[no_mangle] pub extern "C" fn compress(data_to_compress: *const c_uchar, data_to_compress_length: usize, level: usize) -> ZstdCompressResult { let data_to_compress = unsafe { std::slice::from_raw_parts(data_to_compress, data_to_compress_length) }.to_vec(); @@ -47,18 +33,4 @@ pub extern "C" fn compress(data_to_compress: *const c_uchar, data_to_compress_le }; std::mem::forget(compressed_data); result -} - -#[no_mangle] -pub extern "C" fn compress_threadpool(data_to_compress: *const c_uchar, data_to_compress_length: usize, level: usize) -> ZstdCompressResult { - let data_to_compress = unsafe { std::slice::from_raw_parts(data_to_compress, data_to_compress_length) }.to_vec(); - let mut compressed_data = zstd::compress_threadpool(data_to_compress, level as i32); - let capacity = compressed_data.capacity(); - compressed_data.reserve_exact(capacity); - let result = ZstdCompressResult { - data: compressed_data.as_mut_ptr(), - length: compressed_data.len() - }; - std::mem::forget(compressed_data); - result } \ No newline at end of file