NAME

Crypt::Sodium::XS::kx - Asymmetric (public/secret key) derivation from client/server asymmetric key pairs

SYNOPSIS

use Crypt::Sodium::XS::kx ":default";

# client
my ($client_pk, $client_sk) = kx_keypair();
my ($server_pk, $server_sk) = kx_keypair();

# client must have server's public key
# shared keys for server->client (client_rx) and client->server (client_tx)
my ($client_rx, $client_tx)
  = kx_client_session_keys($client_pk, $client_sk, $server_pk);

# server must have client's public key
# shared keys for client->server (server_rx) and server->client (server_tx)
my ($server_rx, $server_tx)
  = kx_client_session_keys($server_pk, $server_sk, $client_pk);

DESCRIPTION

Using Crypt::Sodium::XS::kx, two parties can securely compute a set of shared keys using their peer's public key and their own secret key.

FUNCTIONS

Nothing is exported by default. A :default tag imports the functions and constants as documented below. A separate import tag is provided for each of the primitives listed in "PRIMITIVES". For example, :x25519blake2b imports kx_x25519blake2b_client_session_keys. You should use at least one import tag.

kx_keypair

my ($public_key, $secret_key) = kx_keypair();
my ($public_key, $secret_key) = kx_keypair($seed);

$seed is optional. If provided, it must be "kx_SEEDBYTES" in length. Using the same seed will generate the same key pair, so it must be kept confidential. If omitted, a key pair is randomly generated.

kx_client_session_keys

my ($client_rx, $client_tx)
  = kx_client_session_keys($client_pk, $client_sk, $server_pk);

kx_server_session_keys

my ($server_rx, $server_tx)
  = kx_client_session_keys($server_pk, $server_sk, $client_pk);

CONSTANTS

kx_PRIMITIVE

my $default_primitive = kx_PRIMITIVE();

kx_PUBLICKEYBYTES

my $public_key_length = kx_PUBLICKEYBYTES();

kx_SECRETKEYBYTES

my $secret_key_length = kx_SECRETKEYBYTES();

kx_SEEDBYTES

my $seed_length = kx_SEEDKEYBYTES();

kx_SESSIONKEYBYTES

my $session_key_length = kx_SESSIONKEYBYTES();

PRIMITIVES

All constants (except _PRIMITIVE) and functions have kx_<primitive>-prefixed couterparts (e.g., kx_x25519blake2b_keypair, kx_x25519blake2b_PUBLICKEYBYTES).

  • x25519blake2b

SEE ALSO

Crypt::Sodium::XS
Crypt::Sodium::XS::OO::kx
https://doc.libsodium.org/key_exchange

FEEDBACK

For reporting bugs, giving feedback, submitting patches, etc. please use the following:

AUTHOR

Brad Barden <perlmodules@5c30.org>

COPYRIGHT & LICENSE

Copyright (c) 2022 Brad Barden. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.