crypto.x25519.shared
Compute an X25519 shared secret.
📝Syntax
sharedSecret = crypto.x25519.shared(secretKey, peerPublicKey)
📥Input Arguments
Parameter Description
secretKey a uint8 vector of 32 bytes or 64 hexadecimal characters: your private key.
peerPublicKey a uint8 vector of 32 bytes or 64 hexadecimal characters: the other party public key.
📤Output Arguments
Parameter Description
sharedSecret a character vector: 64 lowercase hexadecimal characters (32 bytes).
📄Description

crypto.x25519.shared computes the Diffie-Hellman shared secret (RFC 7748) from your secret key and a peer public key. Both parties obtain the same value.

Do not use the raw shared secret as an encryption key: hash it first, for example with crypto.blake2b(shared, [], 32).

💡Examples
both peers agree on the same secret
[aPub, aSec] = crypto.x25519.keypair();
[bPub, bSec] = crypto.x25519.keypair();
isequal(crypto.x25519.shared(aSec, bPub), crypto.x25519.shared(bSec, aPub))
🔗See Also
crypto.x25519.publiccrypto.x25519.keypaircrypto.aead.encrypt
Used Functions
Monocypher
📚Bibliography
https://www.rfc-editor.org/rfc/rfc7748, https://monocypher.org/
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub