4 releases (breaking)

Uses old Rust 2015

0.4.0 Jan 8, 2025
0.3.0 Jan 27, 2019
0.2.0 Sep 13, 2018
0.1.0 Mar 6, 2016

#175 in Cryptography

Download history 41910/week @ 2024-12-05 38752/week @ 2024-12-12 18527/week @ 2024-12-19 11563/week @ 2024-12-26 31490/week @ 2025-01-02 42410/week @ 2025-01-09 45762/week @ 2025-01-16 44879/week @ 2025-01-23 39190/week @ 2025-01-30 43391/week @ 2025-02-06 54208/week @ 2025-02-13 41296/week @ 2025-02-20 41183/week @ 2025-02-27 43820/week @ 2025-03-06 42465/week @ 2025-03-13 32438/week @ 2025-03-20

168,911 downloads per month
Used in 114 crates (9 directly)

MIT/Apache

35KB
634 lines

documenation crates.io link

Adding a Dependency

If you are using a stable Rust build:

[dependencies]
chacha = "0.1.0"

If you need maximum performance, using a nightly Rust build:

[dependencies.chacha]
version = "0.1.0"
features = ["nightly"]

Example

extern crate chacha;

use chacha::{ChaCha, KeyStream};

fn main() {
    let secret_key = [
        0x29, 0xfa, 0x35, 0x60, 0x88, 0x45, 0xc6, 0xf9, 
        0xd8, 0xfe, 0x65, 0xe3, 0x22, 0x0e, 0x5b, 0x05, 
        0x03, 0x4a, 0xa0, 0x9f, 0x9e, 0x27, 0xad, 0x0f, 
        0x6c, 0x90, 0xa5, 0x73, 0xa8, 0x10, 0xe4, 0x94, 
    ];
    let nonce = [0u8; 8];
    let mut stream = ChaCha::new_chacha20(&secret_key, &nonce);

    let mut buffer = *b"abcdef";
    println!("Plaintext = {:?}", buffer);
    stream.xor_read(&mut buffer[..]).expect("hit end of stream far too soon");
    println!("Ciphertext = {:?}", buffer);
}

Dependencies