KCl v0.6.6 Kcl

pure Elixir NaCl crypto suite substitute

The box and unbox functions exposed here are the equivalent of NaCl’s:

  • crypto_box_curve25519xsalsa20poly1305
  • crypto_box_curve25519xsalsa20poly1305_open

Summary

Types

public or private key

key varieties

shared nonce

computed signature

Types

key()
key() :: binary

public or private key

key_variety()
key_variety() :: :sign | :encrypt

key varieties

nonce()
nonce() :: binary

shared nonce

signature()
signature() :: binary

computed signature

Functions

box(msg, nonce, state)
box(binary, nonce, Kcl.State.t) :: {binary, Kcl.State.t}
box(msg, nonce, our_private, their_public)
box(binary, nonce, key, key) :: {binary, Kcl.State.t}

box up an authenticated packet

derive_public_key(private_key, variety \\ :encrypt)
derive_public_key(key, key_variety) :: key | :error

derive a public key from a private key

generate_key_pair(variety \\ :encrypt)
generate_key_pair(key_variety) :: {key, key} | :error

generate a {private, public} key pair

new_connection_state(our_private, our_public \\ nil, their_public)
new_connection_state(key, key | nil, key) :: Kcl.State.t

create an inital state for a peer connection

A convenience wrapper around Kcl.State.init and Kcl.State.new_peer

secretbox(msg, nonce, key)
secretbox(binary, nonce, key) :: binary

box based on a shared secret

secretunbox(packet, nonce, key)
secretunbox(binary, nonce, key) :: binary | :error

unbox based on a shared secret

shared_secret(our_private, their_public)

pre-compute a shared key

Mainly useful in a situation where many messages will be exchanged.

sign(message, secret_key, public_key \\ nil)
sign(binary, key, key) :: signature

sign a message

If only the secret key is provided, the public key will be derived therefrom. This can add significant overhead to the signing operation.

unbox(packet, nonce, state)
unbox(packet, nonce, our_private, their_public)
unbox(binary, nonce, key, key) ::
  {binary, Kcl.State.t} |
  :error

unbox an authenticated packet

Returns :error when the packet contents cannot be authenticated, otherwise the decrypted payload and updated state.

valid_signature?(signature, message, public_key)
valid_signature?(signature, binary, key) :: boolean

validate a message signature