Deprecate (and remove) Mcrypt View as Markdown

Implemented (PHP 7.1)
Authors
Scott Arciszewski, security@paragonie.com
Date
2016-01-09
Version
1.0
Source
wiki.php.net/rfc/mcrypt-viking-funeral

Vote

Deprecate then Remove Mcrypt from the PHP Core? closed
Yes
23
No
6
29 voters
bwoebi Yes 2016-03-15 16:42
colinodell Yes 2016-03-15 18:30
davey Yes 2016-03-15 20:53
derick No 2016-03-15 16:17
diegopires Yes 2016-03-17 17:22
dmitry No 2016-03-17 08:31
frozenfire Yes 2016-03-15 17:17
gasolwu Yes 2016-03-16 06:50
jedisct1 Yes 2016-03-15 17:36
krakjoe Yes 2016-03-15 17:26
leigh Yes 2016-03-17 18:35
lstrojny Yes 2016-03-21 12:32
mariano Yes 2016-03-16 16:15
mbeccati No 2016-03-17 15:59
mcmic Yes 2016-03-17 02:52
mightyuhu Yes 2016-03-15 18:07
mikemike Yes 2016-03-18 12:05
nikic Yes 2016-03-15 19:48
ocramius Yes 2016-03-16 10:24
pauloelr Yes 2016-03-17 18:34
philstu Yes 2016-03-17 14:29
pollita No 2016-03-16 02:37
ramsey Yes 2016-03-22 13:12
remi Yes 2016-03-15 16:20
sammyk Yes 2016-03-16 18:49
svpernova09 Yes 2016-03-15 17:57
trowski Yes 2016-03-22 16:36
willfitch No 2016-03-15 16:18
zimt No 2016-03-20 13:33

Discussions on the mailing list

[RFC][VOTE] Deprecate then Remove Mcrypt
by Scott Arciszewski · 12 messages
[RFC][VOTE] Deprecate then Remove Mcrypt Closed (23-6)
by Scott Arciszewski · 18 messages
Intention to move mcrypt to PECL
by Leigh · 22 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:51 UTC

Introduction

Let's get rid of ext/mcrypt, which is abandonware and inhibits the growth of the language, as soon as humanly possible.

Proposal

In PHP 7.1, all mcrypt_* functions will raise an E_DEPRECATED notice.

In PHP 7.1+1 (be it 7.2 or 8.0), the mcrypt extension will be moved out of core and into PECL, where people who *really* want to install it may still do so if they can install PHP extensions from PECL.

This RFC does not concern itself with the concept of shims or compatibility layers, and those topics are out of scope. If this RFC passes, another RFC could be drafted by interested parties to propose such a feature at a later date.

Background Information (Regarding Security)

A survey of websites where people share cryptography code reveals a lot about how people use mcrypt. You'll most likely find gems like this:

/**
 * Don't use this. It was copied from StackOverflow to demonstrate how
 * unsuccessful developers are at using the mcrypt extension:
 */
function fnEncrypt($sValue, $sSecretKey)
{
    return rtrim(
        base64_encode(
            mcrypt_encrypt(
                MCRYPT_RIJNDAEL_256,
                $sSecretKey, $sValue,
                MCRYPT_MODE_ECB,
                mcrypt_create_iv(
                    mcrypt_get_iv_size(
                        MCRYPT_RIJNDAEL_256,
                        MCRYPT_MODE_ECB
                    ),
                    MCRYPT_RAND)
                )
            ), "\0"
        );
}

function fnDecrypt($sValue, $sSecretKey)
{
    return rtrim(
        mcrypt_decrypt(
            MCRYPT_RIJNDAEL_256,
            $sSecretKey,
            base64_decode($sValue),
            MCRYPT_MODE_ECB,
            mcrypt_create_iv(
                mcrypt_get_iv_size(
                    MCRYPT_RIJNDAEL_256,
                    MCRYPT_MODE_ECB
                ),
                MCRYPT_RAND
            )
        ), "\0"
    );
}

Problems with this code:

  • It's using ECB Mode
  • It's attempting to generate an IV for ECB mode (which is a waste of CPU since IVs aren't used in ECB mode)
  • It's using MCRYPT_RAND for IV generation, which isn't a CSPRNG
  • fnEncrypt() will rtrim() null bytes off the encrypted value before base64 encoding it, which means a 1/256 chance of data corruption that prevents decryption
  • fnDecrypt() will rtrim() null bytes off the decrypted plaintext, which means if your plaintext message was raw binary (e.g. gzip compressed), it's now corrupted
  • There is no MAC, so you transmit this over a network, it's vulnerable to chosen-ciphertext attacks

Mcrypt has a lot of design warts and puts a lot of burden on the implementer to choose the right components (and stitch them together correctly). Blaming the implementer leads to error-prone cryptographic designs. Error-prone cryptographic designs leads to insecure applications.

If libmcrypt were still being maintained, we could work with the libmcrypt team to improve it. Unfortunately, it was abandoned in 2007, and contains unfixed bugs and patches that will never be merged.

Everything libmcrypt can do, openssl can do too (and often better), either out-of-the-box or via its support for pluggable ciphers.

For example: OpenSSL's AES implementation (which mcrypt still called MCRYPT_RIJNDAEL_128 before it was abandoned) uses AES-NI on modern processors to deliver very fast AES that withstands cache-timing attacks. Mcrypt's AES still used S-boxes.

Comparing libmcrypt to openssl, you will find that it is:

  • Less well-maintained
  • Less standards compliant (NULL byte padding can cause data loss on decryption; PKCS#7 padding, which openssl_encrypt() uses, does not)
  • More confusing for end-users (not that OpenSSL's API and documentation are stellar)
  • Slower on modern hardware
  • Less resistant to active attackers
  • Less feature-rich (no public-key cryptography)

Backward Incompatible Changes

Any cryptography code that depends on mcrypt will need to be refactored against openssl. This isn't as difficult as it sounds, provided you're using a trustworthy cipher (e.g. MCRYPT_RIJNDAEL_128). Based on this 3v4l, I can generally conclude that the following MCRYPT ciphers are not currently supported by openssl:

  • GOST
  • TwoFish
  • Loki97
  • RC6
  • Rijndael-192 (not to be confused with AES-192)
  • Rijndael-256 (not to be confused with AES-256)
  • Saferplus
  • Wake
  • Serpent
  • XTEA
  • Enigma

This is an acceptable loss: Most of the ciphers in the list above should not be used in new software anyway. Most cryptography experts would consider their inclusion in any software written in 2016 to be a code smell and indicative of a bad protocol design. Some of them (e.g. Enigma) are outright insecure and should not be used at all.

Proposed PHP Version(s)

Deprecation: Next minor version (7.1.0).

Removal from core: The following major/minor version (7.2.0 or 8.0.0).

Proposed Voting Choices

Vote “Yes” to raise an E_DEPRECATED notice in PHP 7.1 when any mcrypt function is used and to remove the extension from core in 7.1+1.

Vote “No” otherwise.

Since this would break backwards compatibility, a 2/3 majority is required.

Vote: Deprecate then Remove Mcrypt from the PHP Core? — Yes: 23 · No: 6 (closed)

This vote is opened on March 15th, 2016 and will close March 22nd at 17:00 UTC as announced on list.

Patches and Tests

Patches are available:

References

Rejected Features