Stream ciphers
Encrypt or decrypt bytes by XORing them with a keystream.
Choose an algorithm and pass a key, a nonce and the data. apply_keystream
returns the data XORed with the keystream, so the same call encrypts and
decrypts. new returns a cipher object that keeps its keystream position
across calls. Cipher objects cannot be copied or pickled, because a copy would
reuse keystream.
Stream ciphers do not authenticate data. Never reuse a key and nonce pair.
Invalid key, nonce, counter or offset values raise ValueError. Inputs that
are not bytes or int raise TypeError.
Algorithms
- ChaCha ChaCha8/12/20 (RFC 8439), XChaCha8/12/20 and the original 64-bit-nonce ChaCha20.
- Salsa20 Salsa20/8, Salsa20/12, Salsa20 and XSalsa20 variants.
- HC-256 The eSTREAM software-portfolio cipher.
- Rabbit RFC 4503, with or without IV setup.
- RC4 Legacy cipher for interoperability only.
Zeroization
A cipher object owns its Rust cipher state: the key schedule or internal
state, the counter and any buffered keystream. The upstream crates are written to
overwrite this state with zeros when the object is freed; oxcrypto has not
verified this independently. Every wrapped upstream type must implement
ZeroizeOnDrop, which is checked when oxcrypto is compiled.
Zeroization does not cover:
- Keys, nonces and data passed in as Python
bytes, or the returnedbytes, including decrypted plaintext. Python owns these objects. oxcrypto does not wipe them, and Python may copy them or leave them in freed memory. - Short-lived copies the upstream crates make on the stack or in CPU registers during setup and keystream generation. Examples are the XChaCha and XSalsa20 subkey, the HC-256 initialization buffer, Rabbit key-setup temporaries and single keystream blocks.
- Copies left behind when Rust moves the cipher state into the object.
Treat zeroization as defense in depth. It does not guarantee that secrets are gone from process memory.