IGE
IGE mode for any block cipher selector.
from oxcrypto.cipher.ige import IGE
from oxcrypto.cipher.aes import AES
mode = IGE.IGE
key = AES.AES128.generate_key()
iv = bytes(32) # use a fresh, unpredictable IV for every message
ciphertext = mode.encrypt(key, b"hello", cipher=AES.AES128, iv=iv)
assert mode.decrypt(key, ciphertext, cipher=AES.AES128, iv=iv) == b"hello"
encryptor = mode.encryptor(key, cipher=AES.AES128, iv=iv)
assert encryptor.update(b"hel") + encryptor.update(b"lo") + encryptor.finalize() == ciphertextStandard: Infinite garble extension (used by MTProto); not NIST-approved. The IV is two blocks long.
Padded modes take padding=: Padding.PKCS7 (default), Padding.ISO10126, Padding.ISO7816, Padding.ANSI_X923 or Padding.NONE. With Padding.NONE the data must be a whole number of blocks. Padding.ISO10126 writes PKCS #7 bytes, which ISO 10126 allows, and accepts any filler on decryption. A wrong key or tampered data raises ValueError for invalid padding; these modes provide no integrity, so prefer an AEAD.
encryptor and decryptor return a single-use CipherContext: call update any number of times, then finalize once. Further calls raise ValueError.