Module cryptoxide::chacha20

source ·
Expand description

ChaCha20 Stream Cipher

Implementation of ChaCha spec, which is a fast and lean stream cipher.

Along with the standard ChaCha20, there is support for the XChaCha20 variant with extended nonce.

Note that with stream cipher, there’s only one operation ChaCha20::process instead of the typical encrypt and decrypt.

Examples

Combine a simple input using a 128 bits key and 64 bit nonce:

use cryptoxide::chacha20::ChaCha20;

let key : [u8; 16] = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
let nonce : [u8; 8] = [1,2,3,4,5,6,7,8];
let input : &[u8; 12] = b"hello world!";
let mut out : [u8; 12] = [0u8; 12];

// create a new cipher
let mut cipher = ChaCha20::new(&key, &nonce);

// encrypt the msg
cipher.process(input, &mut out);

Structs

ChaCha Context

Type Definitions