1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! Authenticated encryption with associated data (AEAD), ported from Bouncy
//! Castle C#: the [`AeadCipher`] and [`AeadCipherInit`] contracts, and the
//! modes that build them on any engine implementing the `tc_block_cipher`
//! traits, such as `tc_aes::AesEngine`:
//!
//! - [`GcmBlockCipher`] — GCM (NIST SP 800-38D).
//! - [`EaxBlockCipher`] — EAX, over 8- or 16-byte blocks.
//! - `CcmBlockCipher` — CCM (NIST SP 800-38C, RFC 3610).
//! - `GcmSivBlockCipher` — GCM-SIV (RFC 8452), which tolerates nonce reuse.
//! - `OcbBlockCipher` — OCB3 (RFC 7253).
//! - `KccmBlockCipher` — KCCM (DSTU 7624:2014), over 16-, 32- or 64-byte
//! blocks.
//!
//! Algorithms that carry their own primitive implement the same contracts in
//! their own crates: `tc_ascon_aead`, `tc_chacha_aead`, `tc_grain128_aead`
//! and `tc_sparkle_aead`.
//!
//! The crate is `no_std`, needs no allocator by default and contains no
//! `unsafe` code. The default-off `alloc` feature adds the four modes that
//! buffer the whole message, CCM, GCM-SIV, OCB and KCCM, and
//! `AeadParamsOwned` and `ParamsWithAeadOwned`, which own and wipe their bytes.
//!
//! Every engine documents its timing. The modes are constant time exactly when
//! their block cipher is, and lengths are public throughout. Decryption may
//! write unauthenticated plaintext before `do_final` verifies the tag, so
//! discard the output when `do_final` fails.
//!
//! # Example
//!
//! ```
//! use tc_aead_cipher::{AeadCipher, AeadCipherInit, AeadParamsRef, GcmBlockCipher};
//! use tc_aes::AesEngine;
//! use tc_block_cipher::CipherDirection;
//!
//! let (key, nonce) = ([0x42; 16], [0x24; 12]);
//! let params = AeadParamsRef::new(&key, &nonce, 16, b"header");
//! let mut gcm = GcmBlockCipher::new(AesEngine::new());
//!
//! gcm.init(CipherDirection::Encrypt, ¶ms)?;
//! let mut sealed = [0; 14 + 16];
//! let written = gcm.process_bytes(b"attack at dawn", &mut sealed)?;
//! gcm.do_final(&mut sealed[written..])?;
//!
//! gcm.init(CipherDirection::Decrypt, ¶ms)?;
//! let mut opened = [0; 14];
//! let written = gcm.process_bytes(&sealed, &mut opened)?;
//! gcm.do_final(&mut opened[written..])?;
//! assert_eq!(&opened, b"attack at dawn");
//! # Ok::<(), Box<dyn core::error::Error>>(())
//! ```
extern crate alloc;
pub use CcmBlockCipher;
pub use EaxBlockCipher;
pub use ;
pub use GcmBlockCipher;
pub use GcmSivBlockCipher;
pub use KccmBlockCipher;
pub use OcbBlockCipher;
pub use AeadParamsOwned;
pub use AeadParamsRef;
pub use ParamsWithAeadOwned;
pub use ParamsWithAeadRef;
pub use ;