MCPcopy Index your code
hub / github.com/Dstack-TEE/dstack / dh_agree

Function dh_agree

dstack-util/src/crypto.rs:12–17  ·  view source on GitHub ↗
(secret: [u8; 32], their_pubkey: [u8; 32])

Source from the content-addressed store, hash-verified

10use x25519_dalek::{PublicKey, StaticSecret};
11
12pub fn dh_agree(secret: [u8; 32], their_pubkey: [u8; 32]) -> [u8; 32] {
13 let secret = StaticSecret::from(secret);
14 let their_public = PublicKey::from(their_pubkey);
15 let shared_secret = secret.diffie_hellman(&their_public);
16 shared_secret.to_bytes()
17}
18
19pub fn dh_decrypt(secret: [u8; 32], ciphertext: &[u8]) -> Result<Vec<u8>> {
20 // Extract components (matching JS implementation)

Callers 2

dh_decryptFunction · 0.85
test_dh_agreeFunction · 0.85

Calls 1

to_bytesMethod · 0.80

Tested by 1

test_dh_agreeFunction · 0.68