libsodium_crypto_kx (libsodium v3.0.1)
View SourceKey exchange based on X25519 and BLAKE2b.
A client and a server each hold a key pair of publickeybytes/0 and
secretkeybytes/0 bytes. After exchanging public keys, both sides derive
the same pair of sessionkeybytes/0 byte session keys: a key for receiving
(Rx) and a key for transmitting (Tx). The client's Tx equals the
server's Rx and vice versa.
The session keys are bound to both public keys; use them with a symmetric
construction such as libsodium_crypto_secretbox.
{ClientPK, ClientSK} = libsodium_crypto_kx:keypair(),
{ServerPK, ServerSK} = libsodium_crypto_kx:keypair(),
{ClientRx, ClientTx} = libsodium_crypto_kx:client_session_keys(ClientPK, ClientSK, ServerPK),
{ServerRx, ServerTx} = libsodium_crypto_kx:server_session_keys(ServerPK, ServerSK, ClientPK),
ClientRx = ServerTx,
ClientTx = ServerRx.
Summary
Types
A crypto_kx_PUBLICKEYBYTES (32-byte) binary.
A crypto_kx_SECRETKEYBYTES (32-byte) binary.
A crypto_kx_PUBLICKEYBYTES (32-byte) binary.
A crypto_kx_SESSIONKEYBYTES (32-byte) binary.
A crypto_kx_SEEDBYTES (32-byte) binary.
A crypto_kx_PUBLICKEYBYTES (32-byte) binary.
A crypto_kx_SECRETKEYBYTES (32-byte) binary.
A crypto_kx_SECRETKEYBYTES (32-byte) binary.
A crypto_kx_SESSIONKEYBYTES (32-byte) binary.
Functions
Compute the client's session keys from its key pair ClientPK and
ClientSK and the server's public key ServerPK.
Generate a random key pair. Returns {PK, SK}.
Return crypto_kx_primitive() as an atom.
Return crypto_kx_publickeybytes(), in bytes.
Return crypto_kx_secretkeybytes(), in bytes.
Deterministically derive a key pair from the seedbytes/0 byte Seed.
Returns {PK, SK}.
Return crypto_kx_seedbytes(), in bytes.
Compute the server's session keys from its key pair ServerPK and
ServerSK and the client's public key ClientPK.
Return crypto_kx_sessionkeybytes(), in bytes.
Types
-type client_pk() :: <<_:256>>.
A crypto_kx_PUBLICKEYBYTES (32-byte) binary.
-type client_sk() :: <<_:256>>.
A crypto_kx_SECRETKEYBYTES (32-byte) binary.
-type pk() :: <<_:256>>.
A crypto_kx_PUBLICKEYBYTES (32-byte) binary.
-type rx() :: <<_:256>>.
A crypto_kx_SESSIONKEYBYTES (32-byte) binary.
-type seed() :: <<_:256>>.
A crypto_kx_SEEDBYTES (32-byte) binary.
-type server_pk() :: <<_:256>>.
A crypto_kx_PUBLICKEYBYTES (32-byte) binary.
-type server_sk() :: <<_:256>>.
A crypto_kx_SECRETKEYBYTES (32-byte) binary.
-type sk() :: <<_:256>>.
A crypto_kx_SECRETKEYBYTES (32-byte) binary.
-type tx() :: <<_:256>>.
A crypto_kx_SESSIONKEYBYTES (32-byte) binary.
Functions
-spec client_session_keys(ClientPK, ClientSK, ServerPK) -> Result when ClientPK :: client_pk(), ClientSK :: client_sk(), ServerPK :: server_pk(), Result :: {rx(), tx()} | -1.
Compute the client's session keys from its key pair ClientPK and
ClientSK and the server's public key ServerPK.
Returns {Rx, Tx}, or -1 when ServerPK is unacceptable.
Generate a random key pair. Returns {PK, SK}.
-spec primitive() -> Result when Result :: x25519blake2b.
Return crypto_kx_primitive() as an atom.
-spec publickeybytes() -> Result when Result :: 32.
Return crypto_kx_publickeybytes(), in bytes.
-spec secretkeybytes() -> Result when Result :: 32.
Return crypto_kx_secretkeybytes(), in bytes.
Deterministically derive a key pair from the seedbytes/0 byte Seed.
Returns {PK, SK}.
-spec seedbytes() -> Result when Result :: 32.
Return crypto_kx_seedbytes(), in bytes.
-spec server_session_keys(ServerPK, ServerSK, ClientPK) -> Result when ServerPK :: server_pk(), ServerSK :: server_sk(), ClientPK :: client_pk(), Result :: {rx(), tx()} | -1.
Compute the server's session keys from its key pair ServerPK and
ServerSK and the client's public key ClientPK.
Returns {Rx, Tx}, or -1 when ClientPK is unacceptable.
-spec sessionkeybytes() -> Result when Result :: 32.
Return crypto_kx_sessionkeybytes(), in bytes.