https://github.com/rustaceanrob/chacha20
zero dependency, stack allocated ChaCha20 implementation
https://github.com/rustaceanrob/chacha20
chacha20 cryptography stack-allocated stream-cipher
Last synced: 6 months ago
JSON representation
zero dependency, stack allocated ChaCha20 implementation
- Host: GitHub
- URL: https://github.com/rustaceanrob/chacha20
- Owner: rustaceanrob
- License: mit
- Created: 2024-03-03T02:14:39.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-12T20:13:21.000Z (over 1 year ago)
- Last Synced: 2025-03-12T06:47:38.717Z (7 months ago)
- Topics: chacha20, cryptography, stack-allocated, stream-cipher
- Language: Rust
- Homepage: https://crates.io/crates/rust_chacha20
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## ChaCha20
A Rust implementation of the ChaCha20 stream cipher. Complete with simple, auditable code.
#### Features
- [x] Stack-allocated
- [x] No unsafe code blocks
- [x] Zero dependencies
- [x] Seek an index in the keystream or a block in the keystream.#### Usage
```rust
use chacha20::ChaCha20;
let key = hex::decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f").unwrap();
let key: [u8; 32] = key.try_into().unwrap();
let nonce = hex::decode("000000000000004a00000000").unwrap();
let nonce: [u8; 12] = nonce.try_into().unwrap();
let seek = 42; // start the cipher at the 42nd index
let mut chacha = ChaCha20::new(key, nonce, seek);
let mut binding = *b"Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it.";
let to = binding.as_mut_slice();
chacha.apply_keystream(to);
chacha.seek(seek); // move the keystream index back to 42
```