1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use crate::{
buffer::ResizeBuffer,
error::Error,
generic_array::{ArrayLength, GenericArray},
};
#[cfg(feature = "crypto_box")]
#[cfg_attr(docsrs, doc(cfg(feature = "crypto_box")))]
pub mod crypto_box;
pub trait KeyAeadInPlace {
fn encrypt_in_place(
&self,
buffer: &mut dyn ResizeBuffer,
nonce: &[u8],
aad: &[u8],
) -> Result<usize, Error>;
fn decrypt_in_place(
&self,
buffer: &mut dyn ResizeBuffer,
nonce: &[u8],
aad: &[u8],
) -> Result<(), Error>;
fn aead_params(&self) -> KeyAeadParams;
fn aead_padding(&self, _msg_len: usize) -> usize {
0
}
}
pub trait KeyAeadMeta {
type NonceSize: ArrayLength<u8>;
type TagSize: ArrayLength<u8>;
#[cfg(feature = "getrandom")]
fn random_nonce() -> GenericArray<u8, Self::NonceSize> {
let mut nonce = GenericArray::default();
crate::random::fill_random(nonce.as_mut_slice());
nonce
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct KeyAeadParams {
pub nonce_length: usize,
pub tag_length: usize,
}