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
#[cfg(feature = "alloc")]
use crate::buffer::SecretBytes;
use crate::{buffer::WriteBuffer, error::Error};
#[cfg(feature = "argon2")]
#[cfg_attr(docsrs, doc(cfg(feature = "argon2")))]
pub mod argon2;
pub mod concat;
pub mod ecdh_1pu;
pub mod ecdh_es;
pub trait KeyExchange<Rhs: ?Sized = Self> {
fn write_key_exchange(&self, other: &Rhs, out: &mut dyn WriteBuffer) -> Result<(), Error>;
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
fn key_exchange_bytes(&self, other: &Rhs) -> Result<SecretBytes, Error> {
let mut buf = SecretBytes::with_capacity(128);
self.write_key_exchange(other, &mut buf)?;
Ok(buf)
}
}
pub trait FromKeyExchange<Lhs: ?Sized, Rhs: ?Sized>: Sized {
fn from_key_exchange(lhs: &Lhs, rhs: &Rhs) -> Result<Self, Error>;
}
pub trait KeyDerivation {
fn derive_key_bytes(&mut self, key_output: &mut [u8]) -> Result<(), Error>;
}
pub trait FromKeyDerivation {
fn from_key_derivation<D: KeyDerivation>(derive: D) -> Result<Self, Error>
where
Self: Sized;
}