chacha20_poly1305_aead/lib.rs
1// Copyright 2016 chacha20-poly1305-aead Developers
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7
8//! A pure Rust implementation of the ChaCha20-Poly1305 AEAD from RFC 7539.
9//!
10//! An Authenticated Encryption with Associated Data (AEAD) mode
11//! encrypts data and generates an authentication tag, or decrypts data
12//! and verifies an authentication tag, as a single operation. The tag
13//! can also validate additional authenticated data (AAD) which is not
14//! included in the cyphertext, for instance a plaintext header.
15//!
16//! The ChaCha20-Poly1305 AEAD uses a 256-bit (32-byte) key, and a
17//! 96-bit (12-byte) nonce. For each key, a given nonce should be used
18//! only once, otherwise the encryption and authentication can be
19//! broken. One way to prevent reuse is for the nonce to contain a
20//! sequence number.
21//!
22//! The amount of data that can be encrypted in a single call is 2^32 - 1
23//! blocks of 64 bytes, slightly less than 256 GiB.
24
25#![warn(missing_docs)]
26
27#![cfg_attr(feature = "clippy", feature(plugin))]
28#![cfg_attr(feature = "clippy", plugin(clippy))]
29#![cfg_attr(feature = "clippy", warn(clippy_pedantic))]
30
31#![cfg_attr(all(feature = "bench", test), feature(test))]
32#![cfg_attr(feature = "simd", feature(platform_intrinsics, repr_simd))]
33#![cfg_attr(feature = "simd_opt", feature(cfg_target_feature))]
34
35#[cfg(all(feature = "bench", test))]
36extern crate test;
37
38extern crate constant_time_eq;
39
40mod as_bytes;
41mod clone_from_slice;
42
43mod simdty;
44mod simdint;
45mod simdop;
46mod simd_opt;
47mod simd;
48
49mod chacha20;
50mod poly1305;
51mod aead;
52
53pub use aead::{DecryptError, decrypt, encrypt, encrypt_read};
54
55/// Runs the self-test for ChaCha20, Poly1305, and the AEAD.
56#[cold]
57pub fn selftest() {
58 chacha20::selftest();
59 poly1305::selftest();
60 aead::selftest::selftest();
61}