rustls_mbedcrypto_provider/
aead.rs

1/* Copyright (c) Fortanix, Inc.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 */
7
8use mbedtls::cipher::raw::{CipherId, CipherMode, CipherType};
9
10/// All the AEADs we support use 128-bit tags.
11pub(crate) const TAG_LEN: usize = 16;
12
13/// AES-128 in GCM mode with 128-bit tags and 96 bit nonces.
14pub static AES128_GCM: Algorithm = Algorithm {
15    key_length: 128 / 8,
16    cipher_type: CipherType::Aes128Gcm,
17    cipher_id: CipherId::Aes,
18    cipher_mode: CipherMode::GCM,
19};
20
21/// AES-256 in GCM mode with 256-bit tags and 96 bit nonces.
22pub static AES256_GCM: Algorithm = Algorithm {
23    key_length: 256 / 8,
24    cipher_type: CipherType::Aes256Gcm,
25    cipher_id: CipherId::Aes,
26    cipher_mode: CipherMode::GCM,
27};
28
29/// ChaCha20-Poly1305 as described in [RFC 8439].
30///
31/// The keys are 256 bits long and the nonces are 96 bits long.
32///
33/// [RFC 8439]: https://tools.ietf.org/html/rfc8439
34pub static CHACHA20_POLY1305: Algorithm = Algorithm {
35    key_length: 256 / 8,
36    cipher_type: CipherType::Chacha20Poly1305,
37    cipher_id: CipherId::Chacha20,
38    cipher_mode: CipherMode::CHACHAPOLY,
39};
40
41/// An AEAD Algorithm.
42pub struct Algorithm {
43    pub(crate) key_length: usize,
44    pub(crate) cipher_type: CipherType,
45    pub(crate) cipher_id: CipherId,
46    pub(crate) cipher_mode: CipherMode,
47}