package noise

  1. Overview
  2. Docs

Module NoiseSource

An OCaml implementation of the Noise Protocol Framework (rev 34).

Supported DH: Curve25519 (X25519). Supported ciphers: AES-256-GCM, ChaCha20-Poly1305. Supported hashes: SHA-256, SHA-512, BLAKE2s, BLAKE2b.

Security notes

  • generate_keypair, and Handshake.write_message when it generates an ephemeral, draw from the default RNG and raise if it is unseeded. Call Mirage_crypto_rng_unix.use_default (), or another CSPRNG initialiser, once at startup.
  • Keys and shared secrets are OCaml strings. Being immutable and subject to GC copying, they cannot be reliably zeroized after use, and this lib makes no attempt to wipe them.
  • When using Handshake.handshake_hash or Handshake.remote_static to authenticate a peer, compare the bytes in constant time. A plain String.equal leaks via early exit; use Eqaf.equal or equivalent.
  • Handshake and transport values are mutable and advance their nonce in place. They are not safe to share across threads or domains; two operations racing on one value can reuse a nonce. A single session is sequential, so give each one owner and run separate sessions in parallel.

Error type

Sourcemodule Error : sig ... end

Errors returned across all Noise API boundaries.

Key types

Sourcetype keypair = {
  1. priv : string;
  2. pub : string;
}
Sourcetype role =
  1. | Initiator
  2. | Responder
Sourceval generate_keypair : unit -> (keypair, Error.t) result

Generate a fresh X25519 keypair. Requires an initialised CSPRNG.

Sourceval keypair_of_secret : string -> (keypair, Error.t) result

keypair_of_secret priv_bytes decodes a raw 32-byte X25519 private key and derives the corresponding public key.

Handshake

Sourcemodule Handshake : sig ... end

Post-handshake transport

Sourcemodule Transport : sig ... end