crypto_secretbox
Secret-key authenticated encryption compatible with libsodium crypto_secretbox.
from oxcrypto.nacl.crypto_secretbox import CRYPTO_SECRETBOX
from oxcrypto.random import bytes as random_bytes
box = CRYPTO_SECRETBOX.XSALSA20POLY1305
key, nonce = random_bytes(32), random_bytes(24)
ciphertext = box.encrypt(key, nonce, b"hello")
assert box.decrypt(key, nonce, ciphertext) == b"hello"| Variant | libsodium name | Key | Nonce |
|---|---|---|---|
XSALSA20POLY1305 | crypto_secretbox_xsalsa20poly1305 | 32 bytes | 24 bytes |
XCHACHA20POLY1305 | crypto_secretbox_xchacha20poly1305 | 32 bytes | 24 bytes |
The output is the 16-byte tag followed by the ciphertext, as in
crypto_secretbox_easy. Associated data is not supported by this
construction.
| Property | Value |
|---|---|
| Standard | NaCl and libsodium construction; not an IETF or NIST standard |
| Crate | crypto_secretbox 0.1.1, stable, no published audit |
| MSRV | Rust 1.60 declared; builds with Rust 1.88 |
| Test vectors | crypto_secretbox 0.1.1 tests/lib.rs: NaCl tests/secretbox.c for XSalsa20-Poly1305, libsodium-generated for XChaCha20-Poly1305 |