Crate rabbit

source ·
Expand description

Implementation of the Rabbit stream cipher.

Cipher functionality is accessed using traits from re-exported cipher crate.

§⚠️ Security Warning: Hazmat!

This crate does not ensure ciphertexts are authentic! Thus ciphertext integrity is not verified, which can lead to serious vulnerabilities!

USE AT YOUR OWN RISK!

§Example

use rabbit::Rabbit;
// Import relevant traits
use rabbit::cipher::{KeyIvInit, StreamCipher};
use hex_literal::hex;

let key = [0x42; 16];
let nonce = [0x24; 8];
let plaintext = hex!("00010203 04050607 08090A0B 0C0D0E0F");
let ciphertext = hex!("10298496 ceda18ee 0e257cbb 1ab43bcc");

// Key and IV must be references to the `GenericArray` type.
// Here we use the `Into` trait to convert arrays into it.
let mut cipher = Rabbit::new(&key.into(), &nonce.into());

let mut buffer = plaintext.clone();

// apply keystream (encrypt)
cipher.apply_keystream(&mut buffer);
assert_eq!(buffer, ciphertext);

let ciphertext = buffer.clone();

// decrypt ciphertext by applying keystream again
let mut cipher = Rabbit::new(&key.into(), &nonce.into());
cipher.apply_keystream(&mut buffer);
assert_eq!(buffer, plaintext);

// stream ciphers can be used with streaming messages
let mut cipher = Rabbit::new(&key.into(), &nonce.into());
for chunk in buffer.chunks_mut(3) {
    cipher.apply_keystream(chunk);
}
assert_eq!(buffer, ciphertext);

Re-exports§

Structs§

  • Core state of the Rabbit stream cipher initialized with key and IV.
  • Core state of the Rabbit stream cipher initialized only with key.

Type Aliases§

  • Rabbit Stream Cipher Initialization Vector.
  • Rabbit Stream Cipher Key.
  • The Rabbit stream cipher initializied with key and IV.
  • The Rabbit stream cipher initializied only with key.