pub struct CuaimaCrypt { /* private fields */ }Expand description
Symmetric hybrid cipher engine operating on 128-bit blocks.
§Architecture
CuaimaCrypt orchestrates N RakeCodecs in cascade. Each RakeCodec contains 4 ShiftCodecs in a ring topology. Between each pair of RakeCodecs, a CrossByte permutation mixes the block halves. Before/after the cascade, Walsh spread-spectrum and Interleaving/DeInterleaving add diffusion.
After each block, all ShiftCodec states advance (shift) and the SeedHopping permutation swaps states across the entire system.
Implementations§
Source§impl CuaimaCrypt
impl CuaimaCrypt
Sourcepub fn with_num_rakes(num_rakes: usize) -> Result<Self, CuaimaCryptError>
pub fn with_num_rakes(num_rakes: usize) -> Result<Self, CuaimaCryptError>
Creates a new CuaimaCrypt with a custom number of RakeCodecs.
More RakeCodecs increase security at the cost of throughput.
§Parameters
num_rakes: Number of RakeCodecs (minimum 2, maximum 1024).
§Errors
Returns CuaimaCryptError::InvalidNumRakeCodecs if num_rakes < 2
or num_rakes > 1024.
§Examples
use cuaimacrypt::CuaimaCrypt;
let mut cc = CuaimaCrypt::with_num_rakes(16).unwrap();
cc.password("secret").unwrap();use cuaimacrypt::CuaimaCrypt;
let result = CuaimaCrypt::with_num_rakes(1);
assert!(result.is_err());Sourcepub fn password(&mut self, passw: &str) -> Result<(), CuaimaCryptError>
pub fn password(&mut self, passw: &str) -> Result<(), CuaimaCryptError>
Initializes the cipher from a password string (Key Derivation Function).
Derives all internal state (seeds, chain topology, cross-bit sequence, seed hopping sequence, window positions, shift leaps, Walsh code) from the given password using PasswordSparker and KAOSrand.
§Parameters
passw: The password string (minimum 1 character).
§Errors
Returns CuaimaCryptError::PasswordTooShort if the password is too short.
§Examples
use cuaimacrypt::CuaimaCrypt;
let mut cc = CuaimaCrypt::new();
assert!(cc.password("valid_password").is_ok());use cuaimacrypt::CuaimaCrypt;
let mut cc = CuaimaCrypt::new();
assert!(cc.password("").is_err());Sourcepub fn codec(&mut self, block: &mut [i64; 2])
pub fn codec(&mut self, block: &mut [i64; 2])
Encrypts a 128-bit block in place.
The cipher state advances after each call, so encrypting the same plaintext twice produces different ciphertext (stream cipher property).
§Parameters
block: The 128-bit block to encrypt (twoi64values, modified in place).
§Examples
use cuaimacrypt::CuaimaCrypt;
let mut cc = CuaimaCrypt::new();
cc.password("secret").unwrap();
let mut block: [i64; 2] = [42, 84];
cc.codec(&mut block);
assert_ne!(block, [42, 84]);Sourcepub fn decodec(&mut self, block: &mut [i64; 2])
pub fn decodec(&mut self, block: &mut [i64; 2])
Decrypts a 128-bit block in place.
Must be called on the same sequential block position as the
corresponding codec call on the encoder instance.
§Parameters
block: The 128-bit block to decrypt (twoi64values, modified in place).
§Examples
use cuaimacrypt::CuaimaCrypt;
let mut encoder = CuaimaCrypt::new();
encoder.password("secret").unwrap();
let mut decoder = CuaimaCrypt::new();
decoder.password("secret").unwrap();
let original: [i64; 2] = [42, 84];
let mut block = original;
encoder.codec(&mut block);
decoder.decodec(&mut block);
assert_eq!(block, original);Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets all ShiftCodecs to their seed states.
After reset, encrypting the same plaintext sequence produces the
same ciphertext as after the initial password call.
§Examples
use cuaimacrypt::CuaimaCrypt;
let mut cc = CuaimaCrypt::new();
cc.password("secret").unwrap();
let mut b1: [i64; 2] = [1, 2];
cc.codec(&mut b1);
cc.reset();
let mut b2: [i64; 2] = [1, 2];
cc.codec(&mut b2);
assert_eq!(b1, b2);