Module Hacl_star__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 optionbox_beforenm pk skprecomputes a 32-byte X25519 shared keyckusing one party's 32-byte public keypkand the other party's 32-byte secret keysk. The shared key can then be used in the Box precomputation interface (box_afternmandbox_open_afternmfunctions) in bothEasyandDetached.
Secretbox
val secretbox : pt:bytes -> n:bytes -> key:bytes -> bytes optionsecretbox pt n keyauthenticates and encrypts plaintextptusing secret keykeyand noncenand 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 optionsecretbox_open ct n keyattempts to verify and decrypt ciphertextctusing secret keykeyand noncenand returns the plaintext if successful.
module Noalloc : sig ... endVersions of these functions which write their output in a buffer passed in as an argument