CryptoMOO is a simple Python library which implements cryptographic modes of operation.
The API is very simple and contains all the methods needed as follows:
get_key() -> bytes
- get a key in a safe mannerset_key(key: bytes) -> None
- set a key for encryption/decryptionget_iv() -> bytes
- get an IV in a safe mannerget_ctr() -> bytes
- get a counter in a safe mannerinc_ctr(ctr: bytes) -> bytes
- returns the given counter incrementedset_mode(mode: Mode) -> None
- mode of operation setupblock_cipher_encrypt(data: bytes) -> bytes
- encrypt a blockblock_cipher_decrypt(data: bytes) -> bytes
- decrypt a blockpad(data: bytes, pkcs7: bool) -> bytes
- pad a block (including an empty block)unpad(data: bytes, pkcs7: bool) -> bytes
- unpad a block (including an empty block)proccess_block_encrypt(data: bytes, is_final_block: bool, padding: str) -> bytes
- add one block for encryption- This method is responsible for the main logic, mode branching happens here.
process_block_decrypt(data: bytes, is_final_block: bool, padding: str) -> bytes
- the same method, but for decryptionencrypt(data: bytes, iv: bytes = None) -> bytes
- encrypt data of arbitrary lengthdecrypt(data: bytes, iv: bytes) -> bytes
- decrypt data of arbitrary length
The methods that are most likely to be looked for in the first place are set_key
, set_mode
, encrypt
and decrypt
.
The tests prove correctness of the primitives from the theoretical point of view.
To demonstrate how things work from the practical perspective, however, there is a separate program which decrypts the sample strings using the modes and the keys, all given in samples.txt
You can see the decrypted strings by running sample_dec.py
or by looking directly at the results in samples_dec.txt