Skip to main content

chacha20/
chacha.rs

1pub use cipher::{
2    IvSizeUser, KeyIvInit, KeySizeUser, StreamCipherCoreWrapper,
3    array::Array,
4    consts::{U12, U32, U64},
5};
6
7use crate::{ChaChaCore, R8, R12, R20, Rounds, variants::Ietf};
8
9/// Key type used by all ChaCha variants.
10pub type Key = Array<u8, U32>;
11
12/// Nonce type used by ChaCha variants.
13pub type Nonce = Array<u8, U12>;
14
15/// ChaCha8 stream cipher (reduced-round variant of [`ChaCha20`] with 8 rounds)
16pub type ChaCha8 = StreamCipherCoreWrapper<ChaChaCore<R8, Ietf>>;
17
18/// ChaCha12 stream cipher (reduced-round variant of [`ChaCha20`] with 12 rounds)
19pub type ChaCha12 = StreamCipherCoreWrapper<ChaChaCore<R12, Ietf>>;
20
21/// ChaCha20 stream cipher (RFC 8439 version with 96-bit nonce)
22pub type ChaCha20 = StreamCipherCoreWrapper<ChaChaCore<R20, Ietf>>;
23
24pub(crate) type Block = Array<u8, U64>;
25
26impl<R: Rounds> KeySizeUser for ChaChaCore<R, Ietf> {
27    type KeySize = U32;
28}
29
30impl<R: Rounds> IvSizeUser for ChaChaCore<R, Ietf> {
31    type IvSize = U12;
32}
33impl<R: Rounds> KeyIvInit for ChaChaCore<R, Ietf> {
34    #[inline]
35    fn new(key: &Key, iv: &Nonce) -> Self {
36        ChaChaCore::<R, Ietf>::new_internal(key.as_ref(), iv.as_ref())
37    }
38}