Skip to main content

Crate rabbit

Crate rabbit 

Source
Expand description

§RustCrypto: Rabbit Stream Cipher Algorithm

Crate Docs Build Status Apache2/MIT licensed Rust Version Project Chat HAZMAT

Implementation of the Rabbit stream cipher (RFC 4503).

§⚠️ Security Warning: Hazmat!

This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to verify ciphertext integrity), which can lead to serious vulnerabilities if used incorrectly!

No security audits of this crate have ever been performed, and it has not been thoroughly assessed to ensure its operation is constant-time on common CPU architectures.

USE AT YOUR OWN RISK!

§Examples

use rabbit::Rabbit;
use rabbit::cipher::{KeyIvInit, StreamCipher};
use hex_literal::hex;

let key = [0x42; 16];
let nonce = [0x24; 8];
let plaintext = hex!("000102030405060708090A0B0C0D0E0F");
let ciphertext = hex!("10298496ceda18ee0e257cbb1ab43bcc");

// Key and IV must be references to the `Array` 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;

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

let ciphertext = buffer;

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

§License

Licensed under either of:

at your option.

§Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Re-exports§

pub use cipher;

Structs§

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

Type Aliases§

Iv
Rabbit Stream Cipher Initialization Vector.
Key
Rabbit Stream Cipher Key.
Rabbit
The Rabbit stream cipher initialized with key and IV.
RabbitKeyOnly
The Rabbit stream cipher initialized only with key.