phpkeymcrypttwofish

Mcrypt are very confusing


I was searching for twofish encryption then I found mcrypt and they said I should use the cipher: MCRYPT_TWOFISH256 (because I want 256 bit key size) But it didnt work and I checked my version and the version to use MCRYPT_TWOFISH256.

THIS maked me confusing: In the mcrypt documentary is said that I needed an OLDER version too use MCRYPT_TWOFISHxxx and the newer version used only MCRYPT_TWOFISH and NO numbers after it that tells the key size so my question:

How big is the key size for the cipher: MCRYPT_TWOFISH. Because it dosnt have any numbers in the end that tells the key size. Example: MCRYPT_SERPENT_256


Solution

  • For MCRYPT_TWOFISH, the keysize is 256 bits.

    From http://php.net/manual/en/mcrypt.ciphers.php#101462:

    The MCRYPT_TWOFISH constant when defined by mcrypt version 2.4.x and later is the 256 bit version of Twofish; it uses a 1-32 byte key, a 16 byte IV, and outputs 16 byte blocks in CBC mode.

    A quick look trough the PHP and mcrypt source code seems to support this statement. Specifically http://mcrypt.cvs.sourceforge.net/viewvc/mcrypt/libmcrypt-nm/lib/mcrypt_extra.c?view=markup#l60, which contains MCRYPT_ENTRY(MCRYPT_TWOFISH, 16, 32, 1) where 32 is the keysize in bytes.