pub struct TequelEncrypt {
pub salt: String,
pub iterations: u32,
}Expand description
TequelEncrypt is a struct that controls Encryption, it uses Salt and Custom Iterations.
You use this struct to use encrypt in Tequel.
use tequel::encrypt::TequelEncrypt;
fn main() {
let mut teq_encrypt: TequelEncrypt = TequelEncrypt::new();
}Fields§
§salt: String§iterations: u32Implementations§
Source§impl TequelEncrypt
impl TequelEncrypt
pub fn new() -> Self
pub fn with_salt(self, salt: &str) -> Self
pub fn with_iteration(self, value: u32) -> Self
Sourcepub fn encrypt(
&mut self,
data: &[u8],
key: &str,
) -> Result<TequelEncryption, TequelError>
pub fn encrypt( &mut self, data: &[u8], key: &str, ) -> Result<TequelEncryption, TequelError>
Encrypts a byte slice using the Tequel protocol with AVX2 acceleration.
This function implements a multi-layered transformation “ladder” based on internal constants, a random salt, and a user-provided key. It ensures data integrity by generating a MAC (Message Authentication Code) as part of the encryption process.
§Arguments
data- A byte slice (&[u8]) containing the plaintext to be encrypted.key- A string slice that serves as the master key for the cipher derivation.
§Returns
Ok(TequelEncryption)- A struct containing the hex-encoded encrypted data, the salt used, and the integrity MAC.Err(TequelError::EmptyKey)- If the provided key string is empty.
§Performance
On x86_64 systems supporting AVX2, this function processes data in 32-byte chunks using SIMD instructions. It automatically falls back to a scalar implementation for the remaining bytes or unsupported hardware.
§Example
use tequel::encrypt::TequelEncrypt;
let mut teq = TequelEncrypt::new();
let secret_data = b"Tequel: Weighted and Measured";
let master_key = "guard_the_gate";
if let Ok(encryption) = teq.encrypt(secret_data, master_key) {
println!("Ciphertext: {}", encryption.encrypted_data);
println!("MAC: {}", encryption.mac);
}Sourcepub fn decrypt(
&mut self,
tequel_encryption: &TequelEncryption,
key: &str,
) -> Result<String, TequelError>
pub fn decrypt( &mut self, tequel_encryption: &TequelEncryption, key: &str, ) -> Result<String, TequelError>
Decrypts a Tequel-encrypted structure and verifies its integrity.
This function performs a reverse transformation of the Tequel protocol, using AVX2 SIMD instructions when available. Before decryption, it reconstructs the MAC (Message Authentication Code) to ensure the ciphertext, salt, and key have not been tampered with.
§Arguments
tequel_encryption- A reference to theTequelEncryptionstruct containing the hex-encoded data, salt, and MAC.key- The string slice key used during the original encryption process.
§Returns
Ok(String)- The original plaintext as a UTF-8 string.Err(TequelError::InvalidMac)- If the calculated MAC does not match the provided one (Integrity violation).Err(TequelError::InvalidUtf8)- If the decrypted bytes are not valid UTF-8.Err(TequelError::InvalidHex)- If the input strings are not valid hex.
§Security
The function follows a “Verify-then-Decrypt” pattern. If the MAC check fails, the decryption logic is never executed, protecting against certain types of side-channel attacks.
§Example
use tequel::encrypt::TequelEncrypt;
fn main() {
let mut teq = TequelEncrypt::new();
let encrypted_obj = teq.encrypt(b"secret", "master_key").expect("Failed to encrypt");
let decrypted = teq.decrypt(&encrypted_obj, "master_key")
.expect("Failed to decrypt or verify data");
println!("Decrypted content: {}", decrypted);
}Trait Implementations§
Source§impl Clone for TequelEncrypt
impl Clone for TequelEncrypt
Source§fn clone(&self) -> TequelEncrypt
fn clone(&self) -> TequelEncrypt
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more