MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / derive_nonce

Function derive_nonce

sodiumbox/src/lib.rs:43–55  ·  view source on GitHub ↗
(ephemeral_pk: &[u8], recipient_pk: &[u8])

Source from the content-addressed store, hash-verified

41/// Uses Blake2b to hash the concatenation of both keys to create a 24-byte nonce.
42#[inline]
43fn 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]

Callers 2

sealFunction · 0.85
open_sealed_boxFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected