KCl v0.5.0 Kcl

A poor 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

shared nonce

Functions

box up an authenticated packet

derive a public key from a private key

generate a {private, public} key pair

create an inital state for a peer connection

box based on a shared secret

unbox based on a shared secret

pre-compute a shared key

unbox an authenticated packet

Types

key :: <<_::32 * 8>>

public or private key

nonce :: <<_::24 * 8>>

shared nonce

Functions

box(msg, nonce, state)

Specs

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

Specs

box(binary, nonce, key, key) :: {binary, Kcl.State.t}

box up an authenticated packet

derive_public_key(private_key)

Specs

derive_public_key(key) :: key | :error

derive a public key from a private key

generate_key_pair()

Specs

generate_key_pair :: {key, key} | :error

generate a {private, public} key pair

new_connection_state(our_private, our_public \\ nil, their_public)

Specs

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)

Specs

secretbox(binary, nonce, key) :: binary

box based on a shared secret

secretunbox(packet, nonce, key)

Specs

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.

unbox(packet, nonce, state)
unbox(packet, nonce, our_private, their_public)

Specs

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.