Expand description
Key exchange
This module implements libsodium’s key exchange functions, which uses a combination of Curve25519, Diffie-Hellman, and Blake2b to generate shared session keys.
Classic API example
use dryoc::classic::crypto_kx::*;
// Generate random client & server keypairs
let (client_pk, client_sk) = crypto_kx_keypair();
let (server_pk, server_sk) = crypto_kx_keypair();
// Variables for client & server rx/tx session keys
let (mut crx, mut ctx, mut srx, mut stx) = (
SessionKey::default(),
SessionKey::default(),
SessionKey::default(),
SessionKey::default(),
);
// Calculate the client Rx & Tx keys
crypto_kx_client_session_keys(&mut crx, &mut ctx, &client_pk, &client_sk, &server_pk)
.expect("client kx failed");
// Calculate the server Rx & Tx keys
crypto_kx_server_session_keys(&mut srx, &mut stx, &server_pk, &server_sk, &client_pk)
.expect("server kx failed");
assert_eq!(crx, stx);
assert_eq!(ctx, srx);
Functions
Computes client session keys for
rx
and tx
, using client_pk
,
client_sk
, and server_pk
. Returns unit ()
upon success.Returns a randomly generated keypair, suitable for use with key exchange.
Computes and returns a keypair of
(PublicKey, SecretKey)
based on seed
upon success. Uses the Blake2b function to derive a secret from seed
.Computes server session keys for
rx
and tx
, using client_pk
,
client_sk
, and server_pk
. Returns unit ()
upon success.Type Definitions
Public key type for key exchange
Secret key type for key exchange
Session data type for key exchange