Debian Codegraph @

debian/rust-vendor/chacha20/src/chacha.rs

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