Skip to content

Commit

Permalink
Removed deprecated mcrypt_ecb() etc
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Mar 9, 2015
1 parent c488a45 commit 7810659
Show file tree
Hide file tree
Showing 24 changed files with 49 additions and 2,702 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -104,6 +104,7 @@
- Mcrypt:
. Fixed possible read after end of buffer and use after free. (Dmitry)
. Removed mcrypt_generic_end() alias. (Nikita)
. Removed mcrypt_ecb(), mcrypt_cbc(), mcrypt_cfb(), mcrypt_ofb(). (Nikita)

- Opcache:
. Fixed bug with try blocks being removed when extended_info opcode
Expand Down
5 changes: 4 additions & 1 deletion UPGRADING
Expand Up @@ -362,8 +362,11 @@ Other
them consistent with other GMP functions.

- Mcrypt
. Removed deprecate mcrypt_generic_end() alias in favor of
. Removed deprecated mcrypt_generic_end() alias in favor of
mcrypt_generic_deinit().
. Removed deprecated mcrypt_ecb(), mcrypt_cbc(), mcrypt_cfb() and mcrypt_ofb()
functions in favor of mcrypt_encrypt() and mcrypt_decrypt() with an
MCRYPT_MODE_* flag.

- Session
. session_start() accepts all INI settings as array. e.g. ['cache_limiter'=>'private']
Expand Down
100 changes: 0 additions & 100 deletions ext/mcrypt/mcrypt.c
Expand Up @@ -200,49 +200,13 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_decrypt, 0, 0, 5)
ZEND_ARG_INFO(0, iv)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_ecb, 0, 0, 5)
ZEND_ARG_INFO(0, cipher)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, mode)
ZEND_ARG_INFO(0, iv)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_cbc, 0, 0, 5)
ZEND_ARG_INFO(0, cipher)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, mode)
ZEND_ARG_INFO(0, iv)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_cfb, 0, 0, 5)
ZEND_ARG_INFO(0, cipher)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, mode)
ZEND_ARG_INFO(0, iv)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_ofb, 0, 0, 5)
ZEND_ARG_INFO(0, cipher)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, mode)
ZEND_ARG_INFO(0, iv)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_create_iv, 0, 0, 1)
ZEND_ARG_INFO(0, size)
ZEND_ARG_INFO(0, source)
ZEND_END_ARG_INFO()
/* }}} */

const zend_function_entry mcrypt_functions[] = { /* {{{ */
PHP_DEP_FE(mcrypt_ecb, arginfo_mcrypt_ecb)
PHP_DEP_FE(mcrypt_cbc, arginfo_mcrypt_cbc)
PHP_DEP_FE(mcrypt_cfb, arginfo_mcrypt_cfb)
PHP_DEP_FE(mcrypt_ofb, arginfo_mcrypt_ofb)
PHP_FE(mcrypt_get_key_size, arginfo_mcrypt_get_key_size)
PHP_FE(mcrypt_get_block_size, arginfo_mcrypt_get_block_size)
PHP_FE(mcrypt_get_cipher_name, arginfo_mcrypt_get_cipher_name)
Expand Down Expand Up @@ -1342,70 +1306,6 @@ PHP_FUNCTION(mcrypt_decrypt)
}
/* }}} */

/* {{{ proto string mcrypt_ecb(int cipher, string key, string data, int mode, string iv)
ECB crypt/decrypt data using key key with cipher cipher starting with iv */
PHP_FUNCTION(mcrypt_ecb)
{
zval *mode;
char *cipher, *key, *data, *iv = NULL;
size_t cipher_len, key_len, data_len, iv_len = 0;

MCRYPT_GET_CRYPT_ARGS

convert_to_long_ex(mode);

php_mcrypt_do_crypt(cipher, key, key_len, data, data_len, "ecb", iv, iv_len, Z_LVAL_P(mode), return_value);
}
/* }}} */

/* {{{ proto string mcrypt_cbc(int cipher, string key, string data, int mode, string iv)
CBC crypt/decrypt data using key key with cipher cipher starting with iv */
PHP_FUNCTION(mcrypt_cbc)
{
zval *mode;
char *cipher, *key, *data, *iv = NULL;
size_t cipher_len, key_len, data_len, iv_len = 0;

MCRYPT_GET_CRYPT_ARGS

convert_to_long_ex(mode);

php_mcrypt_do_crypt(cipher, key, key_len, data, data_len, "cbc", iv, iv_len, Z_LVAL_P(mode), return_value);
}
/* }}} */

/* {{{ proto string mcrypt_cfb(int cipher, string key, string data, int mode, string iv)
CFB crypt/decrypt data using key key with cipher cipher starting with iv */
PHP_FUNCTION(mcrypt_cfb)
{
zval *mode;
char *cipher, *key, *data, *iv = NULL;
size_t cipher_len, key_len, data_len, iv_len = 0;

MCRYPT_GET_CRYPT_ARGS

convert_to_long_ex(mode);

php_mcrypt_do_crypt(cipher, key, key_len, data, data_len, "cfb", iv, iv_len, Z_LVAL_P(mode), return_value);
}
/* }}} */

/* {{{ proto string mcrypt_ofb(int cipher, string key, string data, int mode, string iv)
OFB crypt/decrypt data using key key with cipher cipher starting with iv */
PHP_FUNCTION(mcrypt_ofb)
{
zval *mode;
char *cipher, *key, *data, *iv = NULL;
size_t cipher_len, key_len, data_len, iv_len = 0;

MCRYPT_GET_CRYPT_ARGS

convert_to_long_ex(mode);

php_mcrypt_do_crypt(cipher, key, key_len, data, data_len, "ofb", iv, iv_len, Z_LVAL_P(mode), return_value);
}
/* }}} */

/* {{{ proto string mcrypt_create_iv(int size, int source)
Create an initialization vector (IV) */
PHP_FUNCTION(mcrypt_create_iv)
Expand Down
16 changes: 5 additions & 11 deletions ext/mcrypt/tests/mcrypt_cbc.phpt
Expand Up @@ -8,24 +8,18 @@ $key = "0123456789012345";
$secret = "PHP Testfest 2008";
$cipher = MCRYPT_RIJNDAEL_128;

$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher, MCRYPT_MODE_ECB), MCRYPT_RAND);
$enc_data = mcrypt_cbc($cipher, $key, $secret, MCRYPT_ENCRYPT, $iv);
$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher, MCRYPT_MODE_CBC), MCRYPT_RAND);
$enc_data = mcrypt_encrypt($cipher, $key, $secret, MCRYPT_MODE_CBC, $iv);

// we have to trim as AES rounds the blocks and decrypt doesnt detect that
echo trim(mcrypt_cbc($cipher, $key, $enc_data, MCRYPT_DECRYPT, $iv)) . "\n";
echo trim(mcrypt_decrypt($cipher, $key, $enc_data, MCRYPT_MODE_CBC, $iv)) . "\n";

// a warning must be issued if we don't use a IV on a AES cipher, that usually requires an IV
var_dump(mcrypt_cbc($cipher, $key, $enc_data, MCRYPT_DECRYPT));
var_dump(mcrypt_decrypt($cipher, $key, $enc_data, MCRYPT_MODE_CBC));

?>
--EXPECTF--

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
PHP Testfest 2008

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): Encryption mode requires an initialization vector of size 16 in %s on line %d
Warning: mcrypt_decrypt(): Encryption mode requires an initialization vector of size 16 in %s on line %d
bool(false)
34 changes: 7 additions & 27 deletions ext/mcrypt/tests/mcrypt_cbc_3des_decrypt.phpt
Expand Up @@ -14,12 +14,8 @@ if (!extension_loaded("mcrypt")) {
* Alias to functions:
*/

echo "*** Testing mcrypt_cbc() : basic functionality ***\n";


$cipher = MCRYPT_TRIPLEDES;
$data = b"This is the secret message which must be encrypted";
$mode = MCRYPT_DECRYPT;

// tripledes uses keys with exactly 192 bits (24 bytes)
$keys = array(
Expand Down Expand Up @@ -51,14 +47,14 @@ $iv = b'12345678';
echo "\n--- testing different key lengths\n";
for ($i = 0; $i < sizeof($keys); $i++) {
echo "\nkey length=".strlen($keys[$i])."\n";
special_var_dump(mcrypt_cbc($cipher, $keys[$i], base64_decode($data1[$i]), $mode, $iv));
special_var_dump(mcrypt_decrypt($cipher, $keys[$i], base64_decode($data1[$i]), MCRYPT_MODE_CBC, $iv));
}

$key = b'123456789012345678901234';
echo "\n--- testing different iv lengths\n";
for ($i = 0; $i < sizeof($ivs); $i++) {
echo "\niv length=".strlen($ivs[$i])."\n";
special_var_dump(mcrypt_cbc($cipher, $key, base64_decode($data2[$i]), $mode, $ivs[$i]));
special_var_dump(mcrypt_decrypt($cipher, $key, base64_decode($data2[$i]), MCRYPT_MODE_CBC, $ivs[$i]));
}

function special_var_dump($str) {
Expand All @@ -67,54 +63,38 @@ function special_var_dump($str) {
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_cbc() : basic functionality ***

--- testing different key lengths

key length=8

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): Key of size 8 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
Warning: mcrypt_decrypt(): Key of size 8 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
string(0) ""

key length=20

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): Key of size 20 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
Warning: mcrypt_decrypt(): Key of size 20 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
string(0) ""

key length=24

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
string(32) "736563726574206d6573736167650000"

key length=26

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): Key of size 26 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
Warning: mcrypt_decrypt(): Key of size 26 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
string(0) ""

--- testing different iv lengths

iv length=4

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): Received initialization vector of size 4, but size 8 is required for this encryption mode in %s on line %d
Warning: mcrypt_decrypt(): Received initialization vector of size 4, but size 8 is required for this encryption mode in %s on line %d
string(0) ""

iv length=8

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
string(32) "659ec947f4dc3a3b9c50de744598d3c8"

iv length=9

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): Received initialization vector of size 9, but size 8 is required for this encryption mode in %s on line %d
Warning: mcrypt_decrypt(): Received initialization vector of size 9, but size 8 is required for this encryption mode in %s on line %d
string(0) ""
===DONE===
34 changes: 7 additions & 27 deletions ext/mcrypt/tests/mcrypt_cbc_3des_encrypt.phpt
Expand Up @@ -14,12 +14,8 @@ if (!extension_loaded("mcrypt")) {
* Alias to functions:
*/

echo "*** Testing mcrypt_cbc() : basic functionality ***\n";


$cipher = MCRYPT_TRIPLEDES;
$data = b"This is the secret message which must be encrypted";
$mode = MCRYPT_ENCRYPT;

// tripledes uses keys with exactly 192 bits (24 bytes)
$keys = array(
Expand All @@ -38,66 +34,50 @@ $iv = b'12345678';
echo "\n--- testing different key lengths\n";
foreach ($keys as $key) {
echo "\nkey length=".strlen($key)."\n";
var_dump(bin2hex(mcrypt_cbc($cipher, $key, $data, $mode, $iv)));
var_dump(bin2hex(mcrypt_encrypt($cipher, $key, $data, MCRYPT_MODE_CBC, $iv)));
}

$key = b'123456789012345678901234';
echo "\n--- testing different iv lengths\n";
foreach ($ivs as $iv) {
echo "\niv length=".strlen($iv)."\n";
var_dump(bin2hex(mcrypt_cbc($cipher, $key, $data, $mode, $iv)));
var_dump(bin2hex(mcrypt_encrypt($cipher, $key, $data, MCRYPT_MODE_CBC, $iv)));
}
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_cbc() : basic functionality ***

--- testing different key lengths

key length=8

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): Key of size 8 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
Warning: mcrypt_encrypt(): Key of size 8 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
string(0) ""

key length=20

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): Key of size 20 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
Warning: mcrypt_encrypt(): Key of size 20 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
string(0) ""

key length=24

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
string(112) "b85e21072239d60c63a80e7c9ae493cb741a1cd407e52f451c5f43a0d103f55a7b62617eb2e44213c2d44462d388bc0b8f119384b12c84ac"

key length=26

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): Key of size 26 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
Warning: mcrypt_encrypt(): Key of size 26 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
string(0) ""

--- testing different iv lengths

iv length=4

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): Received initialization vector of size 4, but size 8 is required for this encryption mode in %s on line %d
Warning: mcrypt_encrypt(): Received initialization vector of size 4, but size 8 is required for this encryption mode in %s on line %d
string(0) ""

iv length=8

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
string(112) "b85e21072239d60c63a80e7c9ae493cb741a1cd407e52f451c5f43a0d103f55a7b62617eb2e44213c2d44462d388bc0b8f119384b12c84ac"

iv length=9

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): Received initialization vector of size 9, but size 8 is required for this encryption mode in %s on line %d
Warning: mcrypt_encrypt(): Received initialization vector of size 9, but size 8 is required for this encryption mode in %s on line %d
string(0) ""
===DONE===

0 comments on commit 7810659

Please sign in to comment.