Skip to main content

Crate rc4

Crate rc4 

Source
Expand description

§RustCrypto: RC4

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

Pure Rust implementation of the RC4 stream cipher.

§🚨 Warning: Cryptographically Broken 🚨

RC4 is cryptographically broken and unsuitable for further use!

RFC7465 and RFC8758 prohibit the use of RC4 in TLS and SSH protocols respectively, noting that cryptographic weaknesses in the cipher’s design make it practical to recover repeatedly encrypted plaintexts.

This crate is provided for the purposes of legacy interoperability with protocols and systems which continue to mandate the use of RC4. It should not be relied on for security/confidentiality.

USE AT YOUR OWN RISK!

§Examples

use hex_literal::hex;
use rc4::{KeyInit, Rc4, StreamCipher};

let mut rc4 = Rc4::new_from_slice(b"Key").unwrap();
let mut data = *b"Plaintext";
rc4.apply_keystream(&mut data);
assert_eq!(data, hex!("BBF316E8D940AF0AD3"));

let mut rc4 = Rc4::new_from_slice(b"Wiki").unwrap();
let mut data = *b"pedia";
rc4.apply_keystream(&mut data);
assert_eq!(data, hex!("1021BF0420"));

let mut rc4 = Rc4::new_from_slice(b"Secret").unwrap();
let mut data = *b"Attack at dawn";
rc4.apply_keystream(&mut data);
assert_eq!(data, hex!("45A01F645FC35B383552544B9BF5"));

Note that Rc4 accepts keys of 1 to 256 bytes, though short keys are insecure and real-world usage typically uses 5–32 bytes (40–256 bits).

§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;

Modules§

consts

Structs§

Rc4
RC4 stream cipher.

Traits§

KeyInit
Types which can be initialized from a key.
StreamCipher
Stream cipher trait.