Skip to Content
oxcrypto

Block ciphers

Encrypt with a block cipher selector and a mode.

Choose a mode, then pass a block cipher selector as cipher=. Inputs are positional bytes; options are keyword-only. Wrong lengths raise ValueError and wrong types raise TypeError. Every selector has block_size, key_size and generate_key(), which uses the operating system CSPRNG.

from oxcrypto.cipher.aes import AES
from oxcrypto.cipher.ctr import CTR

key = AES.AES256.generate_key()
nonce = bytes(16)  # never reuse a key and nonce pair
ciphertext = CTR.CTR128BE.encrypt(key, b"hello", cipher=AES.AES256, iv=nonce)

These modes do not authenticate data. Use them for interoperability or wrap them with a MAC.

Modes

CBC · PCBC · IGE · CFB · CFB-8 · OFB · CTR · BelT-CTR · Hazmat and ECB

Ciphers

AES · ARIA · BelT block cipher · Camellia · CAST6 · GIFT-128 · Kuznyechik · Magma · RC5 · Serpent · SM4 · Speck · Threefish · Twofish

Legacy compatibility

Blowfish · CAST5 · DES and Triple DES · IDEA · RC2 · XTEA

Zeroization

With oxcrypto's build, the upstream crates are written to zeroize expanded key schedules and mode state (IV, counter and buffered keystream or blocks) when a selector call or context ends, and oxcrypto zeroizes its own copies of padded blocks and outputs. oxcrypto read the upstream source and requires ZeroizeOnDrop at compile time, but has not independently verified that memory is erased. This covers memory owned by Rust only. The bytes keys, plaintexts and ciphertexts you pass in or receive are Python objects: oxcrypto cannot wipe them, Python may copy them, and freed memory may still hold them. Values in CPU registers, on the stack of upstream code and in swap are not covered.

On this page