aws_lc_rs/aead/
aes_gcm.rs

1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0 OR ISC
3
4use crate::aead::{Algorithm, AlgorithmID};
5
6use crate::aead::aead_ctx::AeadCtx;
7use crate::cipher::aes::{AES_128_KEY_LEN, AES_192_KEY_LEN, AES_256_KEY_LEN};
8use crate::error::Unspecified;
9
10/// AES-128 in GCM mode with 128-bit tags and 96 bit nonces.
11pub const AES_128_GCM: Algorithm = Algorithm {
12    init: init_128_aead,
13    key_len: AES_128_KEY_LEN,
14    id: AlgorithmID::AES_128_GCM,
15    max_input_len: u64::MAX,
16};
17
18/// AES-192 in GCM mode with 128-bit tags and 96 bit nonces.
19pub const AES_192_GCM: Algorithm = Algorithm {
20    init: init_192_aead,
21    key_len: AES_192_KEY_LEN,
22    id: AlgorithmID::AES_192_GCM,
23    max_input_len: u64::MAX,
24};
25
26/// AES-256 in GCM mode with 128-bit tags and 96 bit nonces.
27pub const AES_256_GCM: Algorithm = Algorithm {
28    init: init_256_aead,
29    key_len: AES_256_KEY_LEN,
30    id: AlgorithmID::AES_256_GCM,
31    max_input_len: u64::MAX,
32};
33
34/// AES-256 in GCM mode with nonce reuse resistance, 128-bit tags and 96 bit nonces.
35pub const AES_256_GCM_SIV: Algorithm = Algorithm {
36    init: init_256_aead_siv,
37    key_len: AES_256_KEY_LEN,
38    id: AlgorithmID::AES_256_GCM_SIV,
39    max_input_len: u64::MAX,
40};
41
42/// AES-128 in GCM mode with nonce reuse resistance, 128-bit tags and 96 bit nonces.
43pub const AES_128_GCM_SIV: Algorithm = Algorithm {
44    init: init_128_aead_siv,
45    key_len: AES_128_KEY_LEN,
46    id: AlgorithmID::AES_128_GCM_SIV,
47    max_input_len: u64::MAX,
48};
49
50#[inline]
51fn init_128_aead(key: &[u8], tag_len: usize) -> Result<AeadCtx, Unspecified> {
52    AeadCtx::aes_128_gcm(key, tag_len)
53}
54
55#[inline]
56fn init_192_aead(key: &[u8], tag_len: usize) -> Result<AeadCtx, Unspecified> {
57    AeadCtx::aes_192_gcm(key, tag_len)
58}
59
60#[inline]
61fn init_256_aead(key: &[u8], tag_len: usize) -> Result<AeadCtx, Unspecified> {
62    AeadCtx::aes_256_gcm(key, tag_len)
63}
64
65#[inline]
66fn init_256_aead_siv(key: &[u8], tag_len: usize) -> Result<AeadCtx, Unspecified> {
67    AeadCtx::aes_256_gcm_siv(key, tag_len)
68}
69
70#[inline]
71fn init_128_aead_siv(key: &[u8], tag_len: usize) -> Result<AeadCtx, Unspecified> {
72    AeadCtx::aes_128_gcm_siv(key, tag_len)
73}