Search code examples
phpcryptographymcrypt

How to find out supported modes for given cipher in mcrypt?


PHP has functions:

Can I presume that all other ciphers implemented in mcrypt supports CBC, OFB, NOFB, CFB, and ECB block cipher modes?

In theory they should. I'm interested if it is so in practice.

Thanks!


Solution

  • The library introduction page in the PHP documentation says:

    This is an interface to the mcrypt library, which supports a wide variety of block algorithms such as DES, TripleDES, Blowfish (default), 3-WAY, SAFER-SK64, SAFER-SK128, TWOFISH, TEA, RC2 and GOST in CBC, OFB, CFB and ECB cipher modes.

    This looks like the library is designed to support the different modes of operations orthogonally to the block cipher selection, which seems like a good idea in general. Also, as you already found out, there are two functions mcrypt_list_algorithms and mcrypt_list_modes to access them independently

    On the other hand, the home page of the underlying library libmcrypt says:

    It should be remembered that not all modes will work with all block ciphers, either because of implementation constraints or design constraints.

    There is no indication which mode would or wouldn't work with which cipher, though - maybe this could be dependent on block size?

    It looks like detailed answers can only be found in the sources of either libmcrypt or the PHP wrapper.