rust_x3dh_e2e is a robust and secure project that focuses on implementing end-to-end encryption using the Extended Triple Diffie-Hellman (X3DH) key agreement protocol. The project aims to provide a reliable solution for secure communication, ensuring privacy and data integrity. It's designed with the vision of making the internet a safer place by enabling developers to easily integrate high-standard encryption into their applications.
This utility provides functions for encrypting and decrypting data using the AES-256-GCM encryption algorithm. It utilizes the aes_gcm
crate for encryption and decryption operations.
Ensure that you have Rust and Cargo installed on your machine. You can install them by following the instructions provided at https://www.rust-lang.org/tools/install.
-
Add the
aes_gcm
andrand
crates as dependencies in yourCargo.toml
file:[dependencies] aes_gcm = "0.9.0" rand = "0.8.4" ```
-
Import the required crates in your Rust code:
extern crate hex; use rand::{RngCore, thread_rng}; use aes_gcm::{Aes256Gcm, KeyInit, aead::Aead}; use aes_gcm::aead::generic_array::GenericArray; ```
-
Implement the
hex_string_to_bytes
function to convert a hexadecimal string to a byte vector:#[allow(dead_code)] pub fn hex_string_to_bytes(hex_string: &str) -> Vec<u8> { // Implementation details... } ```
-
Implement the
perform_encryption
function to perform the encryption process:#[allow(dead_code)] fn perform_encryption(key: &[u8], plaintext: &[u8]) -> (Vec<u8>, Vec<u8>) { // Implementation details... } ```
-
Implement the
encrypt_with_string_key
function to encrypt data using a shared secret key provided as a hexadecimal string:#[allow(dead_code)] pub fn encrypt_with_string_key(shared_secret_key: String, plaintext: String) -> (Vec<u8>, Vec<u8>) { // Implementation details... } ```
-
Implement the
encrypt_with_bytes_key
function to encrypt data using a shared secret key provided as a byte vector:#[allow(dead_code)] pub fn encrypt_with_bytes_key(shared_secret_key: Vec<u8>, plaintext: String) -> (Vec<u8>, Vec<u8>) { // Implementation details... } ```
-
Implement the
decrypt_with_hex_string_key
function to decrypt data using a shared secret key provided as a hexadecimal string:#[allow(dead_code)] pub fn decrypt_with_hex_string_key(shared_secret_key: String, ciphertext: Vec<u8>, iv: Vec<u8>) -> String { // Implementation details... } ```
-
Implement the
decrypt_with_bytes_key
function to decrypt data using a shared secret key provided as a byte vector:#[allow(dead_code)] pub fn decrypt_with_bytes_key(shared_secret_key: Vec<u8>, ciphertext: Vec<u8>, iv: Vec<u8>) -> String { // Implementation details... } ```
-
Use the provided functions in your code to encrypt and decrypt data as needed.
fn main() { let shared_secret_key = "0123456789abcdef0123456789abcdef".to_string(); let plaintext = "This is a secret message.".to_string(); let (ciphertext, iv) = encrypt_with_string_key(shared_secret_key.clone(), plaintext.clone()); println!("Ciphertext: {:?}", ciphertext); println!("IV: {:?}", iv); let decrypted_text = decrypt_with_hex_string_key(shared_secret_key, ciphertext, iv); println!("Decrypted Text: {}", decrypted_text); } ``` Remember to replace `0123456789abcdef0123456789abcdef` with your actual shared secret key.
You can run tests for this project using the following command:
$ cargo test
The test results will be displayed in the console.
Performance BenchmarksTo measure the performance of this project, you can run benchmarks using the following command:
You can run bench for this project using the following command:
$ cargo bench --bench x3dh_e2e_bench -- --sample-size 100
Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.
Feel free to customize the content according to your specific requirements and project details.