Skip to main content

CuaimaCrypt

Struct CuaimaCrypt 

Source
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

Source

pub fn new() -> Self

Creates a new CuaimaCrypt with the default 9 RakeCodecs.

§Returns

A new CuaimaCrypt instance with default initial state. Call password to initialize with a key.

§Examples
use cuaimacrypt::CuaimaCrypt;

let mut cc = CuaimaCrypt::new();
cc.password("secret").unwrap();
Source

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());
Source

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());
Source

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 (two i64 values, 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]);
Source

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 (two i64 values, 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);
Source

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);
Source

pub fn num_seeds(&self) -> usize

Returns the total number of ShiftCodecs in the system.

Source

pub fn get_seed_value(&self, ns: usize) -> i64

Returns the seed value of the ShiftCodec at flat index ns.

§Parameters
  • ns: Flat ShiftCodec index (0..num_seeds).
§Returns

The seed value, or 0 if the index is out of range.

Trait Implementations§

Source§

impl Default for CuaimaCrypt

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for CuaimaCrypt

Source§

fn drop(&mut self)

Securely clears sensitive internal state on drop.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.