@std/crypto/chacha20poly1305.ms#
Import each required symbol with import Name from "@std/crypto/chacha20poly1305.ms".
chacha20 Function#
Encrypts or decrypts data with the ChaCha20 stream cipher (RFC 8439); the same call does both.
key is 32 bytes, nonce 12 bytes and counter the initial 32-bit block counter (normally 1 after the Poly1305 key block).
Returns EINVAL for a wrong key or nonce length, a counter outside 0 through 2^32 - 1, or data that needs more blocks than the 32-bit counter has left.
Never reuse a key and nonce pair.
fn chacha20(key Bytes, nonce Bytes, counter Int, data Bytes) Result[Bytes, Error] { ... }chacha20poly1305_open Function#
Authenticates and decrypts a value produced by chacha20poly1305_seal. A wrong key,
nonce or associated data, or an altered ciphertext, returns EAUTH. A key or nonce of
the wrong length, or sealed input shorter than the 16-byte tag, returns EINVAL.
fn chacha20poly1305_open(key Bytes, nonce Bytes, sealed Bytes, associated_data Bytes) Result[Bytes, Error] { ... }chacha20poly1305_seal Function#
Encrypts and authenticates plaintext with ChaCha20-Poly1305 (RFC 8439), returning
the ciphertext followed by a 16-byte tag.
key is 32 bytes and nonce 12 bytes; a wrong length returns EINVAL. The caller
supplies a nonce that is never reused with the key.
fn chacha20poly1305_seal(key Bytes, nonce Bytes, plaintext Bytes, associated_data Bytes) Result[Bytes, Error] { ... }poly1305 Function#
Computes the Poly1305 one-time authenticator (RFC 8439) of data with a 32-byte
one-time key and returns 16 bytes; a key of any other length returns EINVAL. Use each
key for one message only. Prefer chacha20poly1305_seal unless you are implementing
a protocol that needs the bare authenticator.
fn poly1305(key Bytes, data Bytes) Result[Bytes, Error] { ... }