Module Hacl.NaCl
Box (public-key authenticated encryption) and Secretbox (secret-key authenticated encryption)
Portable C implementations offering both the easy and detached interfaces of Box and Secretbox (see NaCl.Noalloc). For Box, the precomputation interface is also supported.
Box
One-shot interface
Precomputation interface
A shared key ck is first obtained using NaCl.box_beforenm. This is useful when calling the functions repeatedly, as it avoids computing the shared key on every function call.
- val box_beforenm : pk:bytes -> sk:bytes -> bytes option
- box_beforenm pk skprecomputes a 32-byte X25519 shared key- ckusing one party's 32-byte public key- pkand the other party's 32-byte secret key- sk. The shared key can then be used in the Box precomputation interface (- box_afternmand- box_open_afternmfunctions) in both- Easyand- Detached.
Secretbox
- val secretbox : pt:bytes -> n:bytes -> key:bytes -> bytes option
- secretbox pt n keyauthenticates and encrypts plaintext- ptusing secret key- keyand nonce- nand returns both the message authentication tag and the ciphertext in a single buffer if successful.
- val secretbox_open : ct:bytes -> n:bytes -> key:bytes -> bytes option
- secretbox_open ct n keyattempts to verify and decrypt ciphertext- ctusing secret key- keyand nonce- nand returns the plaintext if successful.
- module Noalloc : sig ... end
- Versions of these functions which write their output in a buffer passed in as an argument