(ephemeral_pk: &[u8], recipient_pk: &[u8])
| 41 | /// Uses Blake2b to hash the concatenation of both keys to create a 24-byte nonce. |
| 42 | #[inline] |
| 43 | fn derive_nonce(ephemeral_pk: &[u8], recipient_pk: &[u8]) -> Result<xsalsa20poly1305::Nonce, ()> { |
| 44 | let mut nonce_material = Vec::with_capacity(PUBLICKEYBYTES * 2); |
| 45 | nonce_material.extend_from_slice(ephemeral_pk); |
| 46 | nonce_material.extend_from_slice(recipient_pk); |
| 47 | |
| 48 | let mut hasher = Blake2bVar::new(24).map_err(|_| ())?; |
| 49 | hasher.update(&nonce_material); |
| 50 | |
| 51 | let mut nonce_bytes = [0u8; 24]; |
| 52 | hasher.finalize_variable(&mut nonce_bytes).map_err(|_| ())?; |
| 53 | |
| 54 | Ok(xsalsa20poly1305::Nonce::from(nonce_bytes)) |
| 55 | } |
| 56 | |
| 57 | /// Derives a symmetric key from the shared secret using HSalsa20. |
| 58 | #[inline] |
no outgoing calls
no test coverage detected