(
rng: &mut R,
msg: &[u8],
other_pk: &G,
g: &G,
salt: Option<&[u8]>,
info: Option<&[u8]>,
)
| 40 | Encryption<G, KEY_BYTE_SIZE, NONCE_BYTE_SIZE> |
| 41 | { |
| 42 | pub fn encrypt<R: RngCore, A: Aead + KeyInit>( |
| 43 | rng: &mut R, |
| 44 | msg: &[u8], |
| 45 | other_pk: &G, |
| 46 | g: &G, |
| 47 | salt: Option<&[u8]>, |
| 48 | info: Option<&[u8]>, |
| 49 | ) -> Self { |
| 50 | let (sk, pk) = keygen::<R, G>(rng, g); |
| 51 | let shared_secret = *other_pk * sk.0; |
| 52 | let mut shared_secret_bytes = vec![]; |
| 53 | shared_secret |
| 54 | .serialize_compressed(&mut shared_secret_bytes) |
| 55 | .unwrap(); |
| 56 | let hk = Hkdf::<Sha256>::new(salt, &shared_secret_bytes); |
| 57 | let mut sym_key = [0u8; KEY_BYTE_SIZE]; |
| 58 | // TODO: Fix unwrap |
| 59 | hk.expand(info.unwrap_or_else(|| &[]), &mut sym_key) |
| 60 | .unwrap(); |
| 61 | let mut nonce = [0u8; NONCE_BYTE_SIZE]; |
| 62 | rng.fill_bytes(&mut nonce); |
| 63 | let cipher = A::new(GenericArray::from_slice(&sym_key)); |
| 64 | // TODO: Fix unwrap |
| 65 | let ciphertext = cipher |
| 66 | .encrypt(GenericArray::from_slice(&nonce), msg) |
| 67 | .unwrap(); |
| 68 | Self { |
| 69 | ciphertext, |
| 70 | nonce, |
| 71 | ephemeral_pk: pk.0, |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | pub fn decrypt<A: Aead + KeyInit>( |
| 76 | self, |
nothing calls this directly
no test coverage detected