Skip to Content
oxcrypto

NaCl

libsodium-compatible crypto_box and crypto_secretbox.

These modules wrap the RustCrypto nacl-compat crates. Their byte formats match libsodium: a 16-byte Poly1305 tag followed by the ciphertext, 24-byte nonces, raw 32-byte keys, and the libsodium sealed-box layout.

Important

Never reuse a nonce with the same key or key pair. Random 24-byte nonces from oxcrypto.random.bytes are suitable for XSalsa20 and XChaCha20.

Choose a variant on the selector, then pass keys, a nonce and data.

Wrong key or nonce lengths raise ValueError. Inputs that are not bytes or the expected key class raise TypeError. A failed tag check raises oxcrypto.InvalidTag. Private keys are generated from the operating system CSPRNG, are never shown in repr, and cannot be copied or pickled.

Algorithms

Upstream status

crypto_box 0.9.1 and crypto_secretbox 0.1.1 are stable releases with no published audit.

Low-order public keys

libsodium rejects public keys that produce an all-zero X25519 shared secret. crypto_box 0.9.1 does not check for this, so such keys are accepted.

Zeroization

Private key objects hold their 32 bytes in Rust memory that is overwritten with zeros when the object is freed. Decrypted plaintext is also wiped from the Rust buffer after it is copied into Python. The upstream SalsaBox, ChaChaBox and secretbox ciphers zeroize their key on drop, as do the upstream XSalsa20 and XChaCha20 subkeys, cipher states and Poly1305 state (the zeroize features of salsa20, chacha20 and poly1305 are enabled). oxcrypto has not verified the upstream behavior independently.

Note

Zeroization does not cover keys, nonces and data passed in or returned as Python bytes, the bytes field of the per-call crypto_box SecretKey and the ephemeral sealed-box key (upstream wipes only the scalar), or other short-lived stack and register copies made during a call. It does not guarantee that secrets are gone from process memory.

On this page