Noise.Protocol (Noise Protocol v0.3.0)

View Source

A parsed Noise protocol name (spec §8): handshake pattern plus the DH, cipher and hash functions it names, resolved to implementation modules.

Build one with Noise.protocol/1. Supported components:

  • DH: 25519, 448, secp256k1 (needs the optional lib_secp256k1 dep)
  • Cipher: AESGCM, ChaChaPoly
  • Hash: SHA256, SHA512, BLAKE2s, BLAKE2b

Summary

Types

t()

@type t() :: %Noise.Protocol{
  cipher: module(),
  dh: module(),
  dhlen: pos_integer(),
  hash: module(),
  hashlen: 32 | 64,
  name: String.t(),
  pattern: Noise.Pattern.t()
}

Functions

decrypt(protocol, k, n, ad, cipher_text)

@spec decrypt(
  t(),
  Noise.Crypto.Cipher.key(),
  Noise.Crypto.Cipher.nonce(),
  binary(),
  binary()
) ::
  binary() | :error

dh(protocol, keypair, pubkey)

@spec dh(t(), Noise.Crypto.DH.keypair(), Noise.Crypto.DH.pubkey()) ::
  {:ok, binary()} | {:error, :invalid_public_key}

encrypt(protocol, k, n, ad, plain_text)

from_name(name)

@spec from_name(String.t()) :: t()

Parses a protocol name such as "Noise_XX_25519_ChaChaPoly_BLAKE2s".

Raises ArgumentError for names that are malformed, longer than 255 bytes (spec §8), or that reference an unsupported pattern, modifier or primitive.

generate_keypair(protocol)

@spec generate_keypair(t()) :: Noise.Crypto.DH.keypair()

hash(protocol, data)

@spec hash(t(), iodata()) :: Noise.Crypto.Hash.hash()

hkdf(protocol, ck, ikm, n)

@spec hkdf(t(), Noise.Crypto.Hash.hash(), binary(), 2 | 3) :: tuple()

rekey(protocol, key)