MCPcopy Index your code
hub / github.com/RustCrypto/stream-ciphers

github.com/RustCrypto/stream-ciphers @hc-256-v0.6.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release hc-256-v0.6.0 ↗ · + Follow
216 symbols 312 edges 33 files 19 documented · 9% updated 9d ago★ 3233 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

RustCrypto: stream ciphers

Project Chat dependency status Apache2/MIT licensed [HAZMAT]hazmat-link

Collection of stream ciphers written in pure Rust.

⚠️ Security Warning: Hazmat!

Crates in this repository do not ensure ciphertexts are authentic (i.e. by using a MAC to verify ciphertext integrity), which can lead to serious vulnerabilities if used incorrectly!

Aside from the chacha20 crate, no crates in this repository have yet received any formal cryptographic and security reviews/audits.

USE AT YOUR OWN RISK!

Crates

Name Crate name Crates.io Docs MSRV Security
ChaCha [chacha20] crates.io Documentation MSRV 1.81 💚
HC-256 [hc-256] crates.io Documentation MSRV 1.81 💛
Rabbit [rabbit] crates.io Documentation MSRV 1.81 💛
RC4 [rc4] crates.io Documentation MSRV 1.81 💔
Salsa20 [salsa20] crates.io Documentation MSRV 1.81 💚

Security Level Legend

The following describes the security level ratings associated with each hash function (i.e. algorithms, not the specific implementation):

Heart Description
:green_heart: No known successful attacks
:yellow_heart: Theoretical break: security lower than claimed
:broken_heart: Attack demonstrated in practice: avoid if at all possible

Example

Crates functionality is expressed in terms of traits defined in the [cipher] crate.

Let's use ChaCha20 to demonstrate usage of synchronous stream cipher:

use chacha20::ChaCha20;
// Import relevant traits
use chacha20::cipher::{KeyIvInit, StreamCipher, StreamCipherSeek};
use hex_literal::hex;

let key = [0x42; 32];
let nonce = [0x24; 12];
let plaintext = hex!("00010203 04050607 08090a0b 0c0d0e0f");
let ciphertext = hex!("e405626e 4f1236b3 670ee428 332ea20e");

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

let mut buffer = plaintext;

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

let ciphertext = buffer;

// ChaCha ciphers support seeking
cipher.seek(0u32);

// decrypt ciphertext by applying keystream again
cipher.apply_keystream(&mut buffer);
assert_eq!(buffer, plaintext);

// stream ciphers can be used with streaming messages
cipher.seek(0u32);
for chunk in buffer.chunks_mut(3) {
    cipher.apply_keystream(chunk);
}
assert_eq!(buffer, ciphertext);

License

All crates 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.

Extension points exported contracts — how you extend this code

Rounds (Interface)
Marker type for a number of ChaCha rounds to perform. [3 implementers]
chacha20/src/lib.rs
Variant (Interface)
A trait that distinguishes some ChaCha variants. Contains configurations for "Legacy" DJB variant and the IETF variant. [2 …
chacha20/src/variants.rs
Sealed (Interface)
(no doc) [2 implementers]
chacha20/src/variants.rs

Core symbols most depended-on inside this repo

quarter_round
called by 16
chacha20/src/lib.rs
quarter_round
called by 16
salsa20/src/backends/soft.rs
set_block_pos
called by 8
chacha20/src/lib.rs
next_state
called by 3
rabbit/src/lib.rs
increment_ctr
called by 3
chacha20/src/backends/avx512.rs
to_u32
called by 3
salsa20/src/xsalsa.rs
get_block_pos
called by 2
chacha20/src/lib.rs
add_xor_rot
called by 2
chacha20/src/backends/avx512.rs

Shape

Function 105
Method 86
Class 20
Interface 3
Enum 2

Languages

Rust100%

Modules by API surface

chacha20/tests/rng.rs24 symbols
chacha20/src/backends/avx512.rs23 symbols
rabbit/src/lib.rs16 symbols
hc-256/src/lib.rs16 symbols
rc4/tests/lib.rs15 symbols
chacha20/src/lib.rs13 symbols
chacha20/src/backends/sse2.rs11 symbols
chacha20/src/backends/neon.rs11 symbols
chacha20/src/backends/avx2.rs11 symbols
rc4/src/lib.rs10 symbols
salsa20/tests/mod.rs9 symbols
salsa20/src/xsalsa.rs8 symbols

For agents

$ claude mcp add stream-ciphers \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page