logo

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.

Documentation

⚠️ Security Warning

This crate is provided for the purposes of legacy interoperability with protocols and systems which mandate the use of RC4.

However, 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.

USE AT YOUR OWN RISK!

Minimum Supported Rust Version

Rust 1.56 or higher.

Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump.

SemVer Policy

  • All on-by-default features of this library are covered by SemVer
  • MSRV is considered exempt from SemVer as noted above

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.

Usage

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

let mut rc4 = Rc4::new(b"Key".into());
let mut data = b"Plaintext".to_vec();
rc4.apply_keystream(&mut data);
assert_eq!(data, [0xBB, 0xF3, 0x16, 0xE8, 0xD9, 0x40, 0xAF, 0x0A, 0xD3]);

let mut rc4 = Rc4::new(b"Wiki".into());
let mut data = b"pedia".to_vec();
rc4.apply_keystream(&mut data);
assert_eq!(data, [0x10, 0x21, 0xBF, 0x04, 0x20]);

let key = Key::<U6>::from_slice(b"Secret");
let mut rc4 = Rc4::<_>::new(key);
let mut data = b"Attack at dawn".to_vec();
rc4.apply_keystream(&mut data);
assert_eq!(
    data,
    [0x45, 0xA0, 0x1F, 0x64, 0x5F, 0xC3, 0x5B, 0x38, 0x35, 0x52, 0x54, 0x4B, 0x9B, 0xF5]
);

Re-exports

pub use cipher;

Modules

Type aliases for many constants.

Structs

Core state of the RC4 stream cipher initialized only with key.

Traits

Types which can be initialized from key.

Synchronous stream cipher core trait.

Type Definitions

RC4 key type (8–2048 bits/ 1-256 bytes)

The RC4 stream cipher initialized with key.