Adding custom ciphers to pyCrypto

A python module for adding custom ciphers to pyCrypto.

In GSMK's software, as a way of future proofing our ciphers, we XOR the result of two ciphers togehter:

Tandem(x) = AES(x) ^ Twofish(x)

Where AES and Twofish are each initialized with a different key.

Now I wanted to use the PyCrypto library as a basis for implementing some of our algorithms. Since Tandem cipher is not something supported by PyCrypto, i would need to add my own cipher, with a interface compatible with pyCrypto's. The problem i found is that in order to use the more complex ciphering modes found in pyCrypto you need to provide PyCrypto with a cipher which already supports several of the more basic ciphering modes.

The advanced modes implemented in Crypto/Cipher/ are these: MODE_CCM MODE_OPENPGP MODE_EAX MODE_SIV MODE_GCM

These are building upon the simple modes implemented by block_template.c: MODE_CTR MODE_CBC MODE_ECB MODE_CFB MODE_OFB and MODE_PGP ( no longer supported by PyCrypto )

So i wrote a base class which adds the simple modes to a cipher providing only the encrypt_block and decrypt_block methods.

The module can be found at:


For the puprpose of testing _BlockCipher, i wrote an AES adapter using my _BlockCipher base class, and several wrapper objects implementing the various basic modes.

Now testing involves comparing the results of the wrapper objects against the original AES with MODE_xxx. This is done in


Comments powered by Disqus