aws_lc_rs/aead/chacha.rs
1// Copyright 2016 Brian Smith.
2// Portions Copyright (c) 2016, Google Inc.
3// SPDX-License-Identifier: ISC
4// Modifications copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5// SPDX-License-Identifier: Apache-2.0 OR ISC
6
7use crate::aead::aead_ctx::AeadCtx;
8use crate::aead::{Algorithm, AlgorithmID};
9use crate::cipher::chacha::KEY_LEN;
10use crate::error;
11
12/// ChaCha20-Poly1305 as described in [RFC 7539].
13///
14/// The keys are 256 bits long and the nonces are 96 bits long.
15///
16/// [RFC 7539]: https://tools.ietf.org/html/rfc7539
17pub const CHACHA20_POLY1305: Algorithm = Algorithm {
18 init: init_chacha_aead,
19 key_len: KEY_LEN,
20 id: AlgorithmID::CHACHA20_POLY1305,
21 max_input_len: u64::MAX,
22};
23
24#[inline]
25fn init_chacha_aead(key: &[u8], tag_len: usize) -> Result<AeadCtx, error::Unspecified> {
26 AeadCtx::chacha20(key, tag_len)
27}