chacha20/
legacy.rs

1//! Legacy version of ChaCha20 with a 64-bit nonce
2
3use crate::chacha::Key;
4use crate::{ChaChaCore, R20};
5use cipher::{
6    IvSizeUser, KeyIvInit, KeySizeUser, StreamCipherCoreWrapper,
7    array::Array,
8    consts::{U8, U32},
9};
10
11/// Nonce type used by [`ChaCha20Legacy`].
12pub type LegacyNonce = Array<u8, U8>;
13use crate::variants::Legacy;
14
15/// The ChaCha20 stream cipher (legacy "djb" construction with 64-bit nonce).
16pub type ChaCha20Legacy = StreamCipherCoreWrapper<ChaCha20LegacyCore>;
17
18/// /// The ChaCha20 stream cipher (legacy "djb" construction with 64-bit nonce).
19pub type ChaCha20LegacyCore = ChaChaCore<R20, Legacy>;
20
21impl KeySizeUser for ChaCha20LegacyCore {
22    type KeySize = U32;
23}
24
25impl IvSizeUser for ChaCha20LegacyCore {
26    type IvSize = U8;
27}
28
29impl KeyIvInit for ChaCha20LegacyCore {
30    #[inline(always)]
31    fn new(key: &Key, iv: &LegacyNonce) -> Self {
32        ChaChaCore::<R20, Legacy>::new_internal(key.as_ref(), iv.as_ref())
33    }
34}