fire_crypto/cipher/
shared_secret.rs

1use super::{Key, Nonce};
2
3use std::{cmp, fmt};
4
5use x25519_dalek as x;
6
7// should be hashed with
8pub struct SharedSecret {
9	inner: x::SharedSecret,
10}
11
12impl SharedSecret {
13	pub const LEN: usize = 32;
14
15	pub(crate) fn from_shared_secret(inner: x::SharedSecret) -> Self {
16		Self { inner }
17	}
18
19	// nonce size U24
20	/// ## Warning
21	/// Don't call this function with the same nonce again.
22	/// This probably leads to an insecure key.
23	pub fn to_key(&self, initial_nonce: Nonce) -> Key {
24		Key::new(self.to_bytes(), initial_nonce.into_bytes())
25	}
26
27	fn to_bytes(&self) -> [u8; 32] {
28		self.inner.to_bytes()
29	}
30
31	pub(crate) fn as_slice(&self) -> &[u8] {
32		self.inner.as_bytes()
33	}
34}
35
36impl fmt::Debug for SharedSecret {
37	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38		f.write_str("SharedSecret")
39	}
40}
41
42impl cmp::PartialEq for SharedSecret {
43	fn eq(&self, other: &SharedSecret) -> bool {
44		self.as_slice() == other.as_slice()
45	}
46}
47
48impl cmp::Eq for SharedSecret {}