c2_chacha/
lib.rs

1// copyright 2019 Kaz Wesley
2
3//! Pure Rust ChaCha with SIMD optimizations.
4//!
5//! Stream-cipher usage:
6//! ```
7//! #[cfg(features = "std")]
8//! fn demo() {
9//! extern crate c2_chacha;
10//!
11//! use c2_chacha::stream_cipher::{NewStreamCipher, SyncStreamCipher, SyncStreamCipherSeek};
12//! use c2_chacha::{ChaCha20, ChaCha12};
13//!
14//! let key = b"very secret key-the most secret.";
15//! let iv = b"my nonce";
16//! let plaintext = b"The quick brown fox jumps over the lazy dog.";
17//!
18//! let mut buffer = plaintext.to_vec();
19//! // create cipher instance
20//! let mut cipher = ChaCha20::new_var(key, iv).unwrap();
21//! // apply keystream (encrypt)
22//! cipher.apply_keystream(&mut buffer);
23//! // and decrypt it back
24//! cipher.seek(0);
25//! cipher.apply_keystream(&mut buffer);
26//! // stream ciphers can be used with streaming messages
27//! let mut cipher = ChaCha12::new_var(key, iv).unwrap();
28//! for chunk in buffer.chunks_mut(3) {
29//!     cipher.apply_keystream(chunk);
30//! }
31//! }
32//! ```
33
34#![cfg_attr(not(feature = "std"), no_std)]
35
36#[cfg(test)]
37#[macro_use]
38extern crate hex_literal;
39
40#[macro_use]
41extern crate ppv_lite86;
42
43pub mod guts;
44
45#[cfg(feature = "rustcrypto_api")]
46mod rustcrypto_impl;
47#[cfg(feature = "rustcrypto_api")]
48pub use self::rustcrypto_impl::{stream_cipher, Ietf, ChaCha8, ChaCha12, ChaCha20, XChaCha8, XChaCha12, XChaCha20};