diff options
Diffstat (limited to 'ext/mcrypt')
-rw-r--r-- | ext/mcrypt/CREDITS | 2 | ||||
-rw-r--r-- | ext/mcrypt/TODO | 6 | ||||
-rw-r--r-- | ext/mcrypt/config.m4 | 63 | ||||
-rw-r--r-- | ext/mcrypt/mcrypt.c | 1271 | ||||
-rw-r--r-- | ext/mcrypt/mcrypt.dsp | 117 | ||||
-rw-r--r-- | ext/mcrypt/php_mcrypt.h | 95 | ||||
-rw-r--r-- | ext/mcrypt/tests/blowfish.phpt | 77 | ||||
-rw-r--r-- | ext/mcrypt/tests/bug8040.phpt | 26 | ||||
-rw-r--r-- | ext/mcrypt/tests/vectors.txt | 33 |
9 files changed, 0 insertions, 1690 deletions
diff --git a/ext/mcrypt/CREDITS b/ext/mcrypt/CREDITS deleted file mode 100644 index 00f871b171..0000000000 --- a/ext/mcrypt/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -mcrypt -Sascha Schumann, Derick Rethans diff --git a/ext/mcrypt/TODO b/ext/mcrypt/TODO deleted file mode 100644 index ca743a4b10..0000000000 --- a/ext/mcrypt/TODO +++ /dev/null @@ -1,6 +0,0 @@ -/* $Id$ */ - -TODO: -- Convert to zend_parse_parameters -- Unify error handling -- Implement encryption streams diff --git a/ext/mcrypt/config.m4 b/ext/mcrypt/config.m4 deleted file mode 100644 index 183cc324f6..0000000000 --- a/ext/mcrypt/config.m4 +++ /dev/null @@ -1,63 +0,0 @@ -dnl -dnl $Id$ -dnl - -AC_DEFUN(PHP_MCRYPT_CHECK_VERSION,[ - old_CPPFLAGS=$CPPFLAGS - CPPFLAGS=-I$MCRYPT_DIR/include - AC_MSG_CHECKING(for libmcrypt version) - AC_EGREP_CPP(yes,[ -#include <mcrypt.h> -#if MCRYPT_API_VERSION >= 20021217 - yes -#endif - ],[ - AC_MSG_RESULT(>= 2.5.6) - ],[ - AC_MSG_ERROR(libmcrypt version 2.5.6 or greater required.) - ]) - CPPFLAGS=$old_CPPFLAGS -]) - - -PHP_ARG_WITH(mcrypt, for mcrypt support, -[ --with-mcrypt[=DIR] Include mcrypt support.]) - -if test "$PHP_MCRYPT" != "no"; then - for i in /usr/local /usr $PHP_MCRYPT; do - if test -f $i/include/mcrypt.h; then - MCRYPT_DIR=$i - fi - done - - if test -z "$MCRYPT_DIR"; then - AC_MSG_ERROR(mcrypt.h not found. Please reinstall libmcrypt.) - fi - - PHP_MCRYPT_CHECK_VERSION - - PHP_CHECK_LIBRARY(mcrypt, mcrypt_module_open, - [ - PHP_ADD_LIBRARY(ltdl,, MCRYPT_SHARED_LIBADD) - AC_DEFINE(HAVE_LIBMCRYPT,1,[ ]) - ],[ - unset found - unset ac_cv_lib_mcrypt_mcrypt_module_open - PHP_CHECK_LIBRARY(mcrypt, mcrypt_module_open, - [ - AC_DEFINE(HAVE_LIBMCRYPT,1,[ ]) - ],[ - AC_MSG_ERROR([Sorry, I was not able to diagnose which libmcrypt version you have installed.]) - ],[ - -L$MCRYPT_DIR/lib - ]) - ],[ - -L$MCRYPT_DIR/lib -lltdl - ]) - - PHP_ADD_LIBRARY_WITH_PATH(mcrypt, $MCRYPT_DIR/lib, MCRYPT_SHARED_LIBADD) - PHP_ADD_INCLUDE($MCRYPT_DIR/include) - - PHP_SUBST(MCRYPT_SHARED_LIBADD) - PHP_NEW_EXTENSION(mcrypt, mcrypt.c, $ext_shared) -fi diff --git a/ext/mcrypt/mcrypt.c b/ext/mcrypt/mcrypt.c deleted file mode 100644 index b40f8bc13a..0000000000 --- a/ext/mcrypt/mcrypt.c +++ /dev/null @@ -1,1271 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Sascha Schumann <sascha@schumann.cx> | - | Derick Rethans <d.rethans@jdimedia.nl> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" - -#if HAVE_LIBMCRYPT - -#include "php_mcrypt.h" -#include "fcntl.h" - -#define NON_FREE -#define MCRYPT2 -#include "mcrypt.h" -#include "php_ini.h" -#include "php_globals.h" -#include "ext/standard/info.h" - -static int le_mcrypt; - -function_entry mcrypt_functions[] = { - PHP_FE(mcrypt_ecb, NULL) - PHP_FE(mcrypt_cbc, NULL) - PHP_FE(mcrypt_cfb, NULL) - PHP_FE(mcrypt_ofb, NULL) - PHP_FE(mcrypt_get_key_size, NULL) - PHP_FE(mcrypt_get_block_size, NULL) - PHP_FE(mcrypt_get_cipher_name, NULL) - PHP_FE(mcrypt_create_iv, NULL) - - PHP_FE(mcrypt_list_algorithms, NULL) - PHP_FE(mcrypt_list_modes, NULL) - PHP_FE(mcrypt_get_iv_size, NULL) - PHP_FE(mcrypt_encrypt, NULL) - PHP_FE(mcrypt_decrypt, NULL) - - PHP_FE(mcrypt_module_open, NULL) - PHP_FE(mcrypt_generic_init, NULL) - PHP_FE(mcrypt_generic, NULL) - PHP_FE(mdecrypt_generic, NULL) - PHP_FE(mcrypt_generic_end, NULL) - PHP_FE(mcrypt_generic_deinit, NULL) - - PHP_FE(mcrypt_enc_self_test, NULL) - PHP_FE(mcrypt_enc_is_block_algorithm_mode, NULL) - PHP_FE(mcrypt_enc_is_block_algorithm, NULL) - PHP_FE(mcrypt_enc_is_block_mode, NULL) - PHP_FE(mcrypt_enc_get_block_size, NULL) - PHP_FE(mcrypt_enc_get_key_size, NULL) - PHP_FE(mcrypt_enc_get_supported_key_sizes, NULL) - PHP_FE(mcrypt_enc_get_iv_size, NULL) - PHP_FE(mcrypt_enc_get_algorithms_name, NULL) - PHP_FE(mcrypt_enc_get_modes_name, NULL) - PHP_FE(mcrypt_module_self_test, NULL) - - PHP_FE(mcrypt_module_is_block_algorithm_mode, NULL) - PHP_FE(mcrypt_module_is_block_algorithm, NULL) - PHP_FE(mcrypt_module_is_block_mode, NULL) - PHP_FE(mcrypt_module_get_algo_block_size, NULL) - PHP_FE(mcrypt_module_get_algo_key_size, NULL) - PHP_FE(mcrypt_module_get_supported_key_sizes, NULL) - - PHP_FE(mcrypt_module_close, NULL) - {NULL, NULL, NULL} -}; - -static PHP_MINFO_FUNCTION(mcrypt); -static PHP_MINIT_FUNCTION(mcrypt); -static PHP_MSHUTDOWN_FUNCTION(mcrypt); - -zend_module_entry mcrypt_module_entry = { - STANDARD_MODULE_HEADER, - "mcrypt", - mcrypt_functions, - PHP_MINIT(mcrypt), PHP_MSHUTDOWN(mcrypt), - NULL, NULL, - PHP_MINFO(mcrypt), - NO_VERSION_YET, - STANDARD_MODULE_PROPERTIES, -}; - -ZEND_DECLARE_MODULE_GLOBALS(mcrypt) - -#ifdef COMPILE_DL_MCRYPT -ZEND_GET_MODULE(mcrypt) -#endif - -#define MCRYPT_ARGS2 \ - zval **cipher, **data, **key, **mode; \ - int td; \ - char *ndata; \ - size_t bsize; \ - size_t nr; \ - size_t nsize - -#define MCRYPT_ARGS \ - MCRYPT_ARGS2; \ - zval **iv - -#define MCRYPT_CONVERT \ - convert_to_string_ex(cipher); \ - convert_to_string_ex(mode); \ - convert_to_string_ex(data); \ - convert_to_string_ex(key) -#define MCRYPT_CONVERT_WO_MODE \ - convert_to_string_ex(cipher); \ - convert_to_string_ex(data); \ - convert_to_string_ex(key) - -#define MCRYPT_SIZE \ - bsize = mcrypt_get_block_size(Z_LVAL_PP(cipher)); \ - nr = (Z_STRLEN_PP(data) + bsize - 1) / bsize; \ - nsize = nr * bsize - -#define MCRYPT_CHECK_TD_CPY \ - if (td < 0) { \ - php_error_docref(NULL TSRMLS_CC, E_WARNING, MCRYPT_FAILED); \ - RETURN_FALSE; \ - } \ - ndata = ecalloc(nr, bsize); \ - memcpy(ndata, Z_STRVAL_PP(data), Z_STRLEN_PP(data)) - -#define MCRYPT_CHECK_IV \ - convert_to_string_ex(iv); \ - if (Z_STRLEN_PP(iv) != bsize) { \ - php_error_docref(NULL TSRMLS_CC, E_WARNING, MCRYPT_IV_WRONG_SIZE); \ - RETURN_FALSE; \ - } - -#define MCRYPT_ACTION(x) \ - if (Z_LVAL_PP(mode) == 0) { \ - mcrypt_##x(td, ndata, nsize); \ - } else { \ - mdecrypt_##x(td, ndata, nsize); \ - } \ - end_mcrypt_##x(td) - -#define MCRYPT_IV_WRONG_SIZE "The IV parameter must be as long as the blocksize" - -#define MCRYPT_ENCRYPT 0 -#define MCRYPT_DECRYPT 1 - -#define MCRYPT_GET_INI \ - cipher_dir_string = MCG(algorithms_dir); \ - module_dir_string = MCG(modes_dir); - -#define MCRYPT_CHECK_PARAM_COUNT(a,b) \ - if (argc < (a) || argc > (b)) { \ - WRONG_PARAM_COUNT; \ - } -/* - * #warning is not ANSI C - * #warning Invalidate resource if the param count is wrong, or other problems - * #warning occurred during functions. - */ - -#define MCRYPT_GET_CRYPT_ARGS \ - switch (argc) { \ - case 5: \ - if (zend_get_parameters_ex(5, &cipher, &key, &data, &mode, &iv) == FAILURE) { \ - WRONG_PARAM_COUNT; \ - } \ - convert_to_string_ex(iv); \ - break; \ - case 4: \ - if (zend_get_parameters_ex(4, &cipher, &key, &data, &mode) == FAILURE) { \ - WRONG_PARAM_COUNT; \ - } \ - iv = NULL; \ - break; \ - default: \ - WRONG_PARAM_COUNT; \ - } - -#define MCRYPT_GET_TD_ARG \ - zval **mcryptind; \ - MCRYPT td; \ - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &mcryptind) == FAILURE) { \ - WRONG_PARAM_COUNT \ - } \ - ZEND_FETCH_RESOURCE (td, MCRYPT, mcryptind, -1, "MCrypt", le_mcrypt); - -#define MCRYPT_GET_MODE_DIR_ARGS(DIRECTORY) \ - char *dir = NULL; \ - int dir_len; \ - char *module; \ - int module_len; \ - if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, \ - "s|s", &module, &module_len, &dir, &dir_len) == FAILURE) { \ - return; \ - } - -#define MCRYPT_OPEN_MODULE_FAILED "Module initialization failed" - -#define MCRYPT_ENTRY2_2_4(a,b) REGISTER_STRING_CONSTANT("MCRYPT_" #a, b, CONST_PERSISTENT) -#define MCRYPT_ENTRY2_4(a) MCRYPT_ENTRY_NAMED(a, a) - -PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("mcrypt.algorithms_dir", NULL, PHP_INI_ALL, OnUpdateString, algorithms_dir, zend_mcrypt_globals, mcrypt_globals) - STD_PHP_INI_ENTRY("mcrypt.modes_dir", NULL, PHP_INI_ALL, OnUpdateString, modes_dir, zend_mcrypt_globals, mcrypt_globals) -PHP_INI_END() - -static void php_mcrypt_module_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) -{ - MCRYPT td = (MCRYPT) rsrc->ptr; - mcrypt_module_close (td); -} - - -static PHP_MINIT_FUNCTION(mcrypt) -{ -#if defined(ZTS) - ZEND_INIT_MODULE_GLOBALS(mcrypt, NULL, NULL); - Z_TYPE(mcrypt_module_entry) = type; -#endif - - le_mcrypt = zend_register_list_destructors_ex(php_mcrypt_module_dtor, NULL, "mcrypt", module_number); - - /* modes for mcrypt_??? routines */ - REGISTER_LONG_CONSTANT("MCRYPT_ENCRYPT", 0, CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("MCRYPT_DECRYPT", 1, CONST_PERSISTENT); - - /* sources for mcrypt_create_iv */ - REGISTER_LONG_CONSTANT("MCRYPT_DEV_RANDOM", 0, CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("MCRYPT_DEV_URANDOM", 1, CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("MCRYPT_RAND", 2, CONST_PERSISTENT); - - /* ciphers */ - MCRYPT_ENTRY2_2_4(3DES, "tripledes"); - MCRYPT_ENTRY2_2_4(ARCFOUR_IV, "arcfour-iv"); - MCRYPT_ENTRY2_2_4(ARCFOUR, "arcfour"); - MCRYPT_ENTRY2_2_4(BLOWFISH, "blowfish"); - MCRYPT_ENTRY2_2_4(BLOWFISH_COMPAT, "blowfish-compat"); - MCRYPT_ENTRY2_2_4(CAST_128, "cast-128"); - MCRYPT_ENTRY2_2_4(CAST_256, "cast-256"); - MCRYPT_ENTRY2_2_4(CRYPT, "crypt"); - MCRYPT_ENTRY2_2_4(DES, "des"); - MCRYPT_ENTRY2_2_4(ENIGNA, "crypt"); - MCRYPT_ENTRY2_2_4(GOST, "gost"); - MCRYPT_ENTRY2_2_4(LOKI97, "loki97"); - MCRYPT_ENTRY2_2_4(PANAMA, "panama"); - MCRYPT_ENTRY2_2_4(RC2, "rc2"); - MCRYPT_ENTRY2_2_4(RIJNDAEL_128, "rijndael-128"); - MCRYPT_ENTRY2_2_4(RIJNDAEL_192, "rijndael-192"); - MCRYPT_ENTRY2_2_4(RIJNDAEL_256, "rijndael-256"); - MCRYPT_ENTRY2_2_4(SAFER64, "safer-sk64"); - MCRYPT_ENTRY2_2_4(SAFER128, "safer-sk128"); - MCRYPT_ENTRY2_2_4(SAFERPLUS, "saferplus"); - MCRYPT_ENTRY2_2_4(SERPENT, "serpent"); - MCRYPT_ENTRY2_2_4(THREEWAY, "threeway"); - MCRYPT_ENTRY2_2_4(TRIPLEDES, "tripledes"); - MCRYPT_ENTRY2_2_4(TWOFISH, "twofish"); - MCRYPT_ENTRY2_2_4(WAKE, "wake"); - MCRYPT_ENTRY2_2_4(XTEA, "xtea"); - - MCRYPT_ENTRY2_2_4(IDEA, "idea"); - MCRYPT_ENTRY2_2_4(MARS, "mars"); - MCRYPT_ENTRY2_2_4(RC6, "rc6"); - MCRYPT_ENTRY2_2_4(SKIPJACK, "skipjack"); -/* modes */ - MCRYPT_ENTRY2_2_4(MODE_CBC, "cbc"); - MCRYPT_ENTRY2_2_4(MODE_CFB, "cfb"); - MCRYPT_ENTRY2_2_4(MODE_ECB, "ecb"); - MCRYPT_ENTRY2_2_4(MODE_NOFB, "nofb"); - MCRYPT_ENTRY2_2_4(MODE_OFB, "ofb"); - MCRYPT_ENTRY2_2_4(MODE_STREAM, "stream"); - REGISTER_INI_ENTRIES(); - return SUCCESS; -} - -static PHP_MSHUTDOWN_FUNCTION(mcrypt) -{ - UNREGISTER_INI_ENTRIES(); - return SUCCESS; -} - -#include "ext/standard/php_smart_str.h" - -PHP_MINFO_FUNCTION(mcrypt) -{ - char **modules; - char mcrypt_api_no[16]; - int i, count; - smart_str tmp1 = {0}; - smart_str tmp2 = {0}; - - modules = mcrypt_list_algorithms (MCG(algorithms_dir), &count); - if (count == 0) { - smart_str_appends (&tmp1, "none"); - } - for (i = 0; i < count; i++) { - smart_str_appends (&tmp1, modules[i]); - smart_str_appendc (&tmp1, ' '); - } - smart_str_0 (&tmp1); - mcrypt_free_p (modules, count); - - modules = mcrypt_list_modes (MCG(modes_dir), &count); - if (count == 0) { - smart_str_appends (&tmp2, "none"); - } - for (i = 0; i < count; i++) { - smart_str_appends (&tmp2, modules[i]); - smart_str_appendc (&tmp2, ' '); - } - smart_str_0 (&tmp2); - mcrypt_free_p (modules, count); - - snprintf (mcrypt_api_no, 16, "%d", MCRYPT_API_VERSION); - - php_info_print_table_start(); - php_info_print_table_header(2, "mcrypt support", "enabled"); - php_info_print_table_row(2, "Version", LIBMCRYPT_VERSION); - php_info_print_table_row(2, "Api No", mcrypt_api_no); - php_info_print_table_row(2, "Supported ciphers", tmp1.c); - php_info_print_table_row(2, "Supported modes", tmp2.c); - smart_str_free (&tmp1); - smart_str_free (&tmp2); - php_info_print_table_end(); - - DISPLAY_INI_ENTRIES(); -} - -typedef enum { - RANDOM = 0, - URANDOM, - RAND -} iv_source; - -/* {{{ proto resource mcrypt_module_open(string cipher, string cipher_directory, string mode, string mode_directory) - Opens the module of the algorithm and the mode to be used */ -PHP_FUNCTION(mcrypt_module_open) -{ - char *cipher, *cipher_dir; - char *mode, *mode_dir; - int cipher_len, cipher_dir_len; - int mode_len, mode_dir_len; - MCRYPT td; - - if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "ssss", - &cipher, &cipher_len, &cipher_dir, &cipher_dir_len, - &mode, &mode_len, &mode_dir, &mode_dir_len)) { - return; - } - - td = mcrypt_module_open ( - cipher, - cipher_dir_len > 0 ? cipher_dir : MCG(algorithms_dir), - mode, - mode_dir_len > 0 ? mode_dir : MCG(modes_dir) - ); - - if (td == MCRYPT_FAILED) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not open encryption module"); - RETURN_FALSE; - } else { - ZEND_REGISTER_RESOURCE (return_value, td, le_mcrypt); - } -} -/* }}} */ - - -/* {{{ proto int mcrypt_generic_init(resource td, string key, string iv) - This function initializes all buffers for the specific module */ -PHP_FUNCTION(mcrypt_generic_init) -{ - zval **key, **iv; - zval **mcryptind; - unsigned char *key_s, *iv_s; - int max_key_size, key_size, iv_size; - MCRYPT td; - int argc; - int result = 0; - - argc = ZEND_NUM_ARGS(); - MCRYPT_CHECK_PARAM_COUNT (3,3) - - zend_get_parameters_ex(3, &mcryptind, &key, &iv); - ZEND_FETCH_RESOURCE (td, MCRYPT, mcryptind, -1, "MCrypt", le_mcrypt); - convert_to_string_ex (key); - convert_to_string_ex (iv); - - max_key_size = mcrypt_enc_get_key_size (td); - iv_size = mcrypt_enc_get_iv_size (td); - - if (Z_STRLEN_PP(key) == 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Key size is 0"); - } - - key_s = emalloc (Z_STRLEN_PP(key)); - memset (key_s, 0, Z_STRLEN_PP(key)); - - iv_s = emalloc (iv_size + 1); - memset (iv_s, 0, iv_size + 1); - - if (Z_STRLEN_PP(key) > max_key_size) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Key size too large; supplied length: %d, max: %d", Z_STRLEN_PP(key), max_key_size); - key_size = max_key_size; - } else { - key_size = Z_STRLEN_PP(key); - } - memcpy (key_s, Z_STRVAL_PP(key), Z_STRLEN_PP(key)); - - if (Z_STRLEN_PP(iv) != iv_size) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Iv size incorrect; supplied length: %d, needed: %d", Z_STRLEN_PP(iv), iv_size); - } - memcpy (iv_s, Z_STRVAL_PP(iv), iv_size); - - result = mcrypt_generic_init (td, key_s, key_size, iv_s); - - /* If this function fails, close the mcrypt module to prevent crashes - * when further functions want to access this resource */ - if (result < 0) { - zend_list_delete (Z_LVAL_PP(mcryptind)); - switch (result) { - case -3: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Key length incorrect"); - break; - case -4: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Memory allocation error"); - break; - case -1: - default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown error"); - break; - } - } - RETVAL_LONG (result); - - efree (iv_s); - efree (key_s); -} -/* }}} */ - - -/* {{{ proto string mcrypt_generic(resource td, string data) - This function encrypts the plaintext */ -PHP_FUNCTION(mcrypt_generic) -{ - zval **data, **mcryptind; - MCRYPT td; - int argc; - unsigned char* data_s; - int block_size, data_size; - - argc = ZEND_NUM_ARGS(); - MCRYPT_CHECK_PARAM_COUNT (2,2) - - zend_get_parameters_ex(2, &mcryptind, &data); - ZEND_FETCH_RESOURCE (td, MCRYPT, mcryptind, -1, "MCrypt", le_mcrypt); - convert_to_string_ex (data); - - /* Check blocksize */ - if (mcrypt_enc_is_block_mode (td) == 1) { /* It's a block algorithm */ - block_size = mcrypt_enc_get_block_size (td); - data_size = (((Z_STRLEN_PP(data) - 1) / block_size) + 1) * block_size; - data_s = emalloc (data_size + 1); - memset (data_s, 0, data_size); - memcpy (data_s, Z_STRVAL_PP(data), Z_STRLEN_PP(data)); - } else { /* It's not a block algorithm */ - data_size = Z_STRLEN_PP(data); - data_s = emalloc (data_size + 1); - memset (data_s, 0, data_size); - memcpy (data_s, Z_STRVAL_PP(data), Z_STRLEN_PP(data)); - } - - mcrypt_generic (td, data_s, data_size); - data_s[data_size] = '\0'; - - RETVAL_STRINGL (data_s, data_size, 1); - efree (data_s); -} -/* }}} */ - - -/* {{{ proto string mdecrypt_generic(resource td, string data) - This function decrypts the plaintext */ -PHP_FUNCTION(mdecrypt_generic) -{ - zval **data, **mcryptind; - MCRYPT td; - int argc; - char* data_s; - int block_size, data_size; - - argc = ZEND_NUM_ARGS(); - MCRYPT_CHECK_PARAM_COUNT (2,2) - - zend_get_parameters_ex(2, &mcryptind, &data); - ZEND_FETCH_RESOURCE (td, MCRYPT, mcryptind, -1, "MCrypt", le_mcrypt); - convert_to_string_ex (data); - - /* Check blocksize */ - if (mcrypt_enc_is_block_mode (td) == 1) { /* It's a block algorithm */ - block_size = mcrypt_enc_get_block_size (td); - data_size = (((Z_STRLEN_PP(data) - 1) / block_size) + 1) * block_size; - data_s = emalloc (data_size + 1); - memset (data_s, 0, data_size); - memcpy (data_s, Z_STRVAL_PP(data), Z_STRLEN_PP(data)); - } else { /* It's not a block algorithm */ - data_size = Z_STRLEN_PP(data); - data_s = emalloc (data_size + 1); - memset (data_s, 0, data_size); - memcpy (data_s, Z_STRVAL_PP(data), Z_STRLEN_PP(data)); - } - - mdecrypt_generic (td, data_s, data_size); - - RETVAL_STRINGL (data_s, data_size, 1); - efree (data_s); -} -/* }}} */ - - -/* {{{ proto int mcrypt_enc_get_supported_key_sizes(resource td) - This function decrypts the crypttext */ -PHP_FUNCTION(mcrypt_enc_get_supported_key_sizes) -{ - int i, count = 0; - int *key_sizes; - - MCRYPT_GET_TD_ARG - array_init(return_value); - - key_sizes = mcrypt_enc_get_supported_key_sizes(td, &count); - - for (i = 0; i < count; i++) { - add_index_long(return_value, i, key_sizes[i]); - } - - mcrypt_free(key_sizes); -} -/* }}} */ - - -/* {{{ proto int mcrypt_enc_self_test(resource td) - This function runs the self test on the algorithm specified by the descriptor td */ -PHP_FUNCTION(mcrypt_enc_self_test) -{ - MCRYPT_GET_TD_ARG - RETURN_LONG(mcrypt_enc_self_test(td)); -} -/* }}} */ - -/* {{{ proto bool mcrypt_module_close(resource td) - Free the descriptor td */ -PHP_FUNCTION(mcrypt_module_close) -{ - MCRYPT_GET_TD_ARG - zend_list_delete(Z_LVAL_PP(mcryptind)); - RETURN_TRUE; -} -/* }}} */ - - -/* {{{ proto bool mcrypt_generic_end(resource td) - This function terminates encrypt specified by the descriptor td */ -PHP_FUNCTION(mcrypt_generic_end) -{ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function is deprecated, please use mcrypt_generic_deinit()"); - zif_mcrypt_generic_deinit(INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - - -/* {{{ proto bool mcrypt_generic_deinit(resource td) - This function terminates encrypt specified by the descriptor td */ -PHP_FUNCTION(mcrypt_generic_deinit) -{ - MCRYPT_GET_TD_ARG - - if (mcrypt_generic_deinit(td) < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not terminate encryption specifier"); - RETURN_FALSE - } - RETURN_TRUE -} -/* }}} */ - - -/* {{{ proto bool mcrypt_enc_is_block_algorithm_mode(resource td) - Returns TRUE if the mode is for use with block algorithms */ -PHP_FUNCTION(mcrypt_enc_is_block_algorithm_mode) -{ - MCRYPT_GET_TD_ARG - - if (mcrypt_enc_is_block_algorithm_mode(td) == 1) { - RETURN_TRUE - } else { - RETURN_FALSE - } -} -/* }}} */ - - -/* {{{ proto bool mcrypt_enc_is_block_algorithm(resource td) - Returns TRUE if the alrogithm is a block algorithms */ -PHP_FUNCTION(mcrypt_enc_is_block_algorithm) -{ - MCRYPT_GET_TD_ARG - - if (mcrypt_enc_is_block_algorithm(td) == 1) { - RETURN_TRUE - } else { - RETURN_FALSE - } -} -/* }}} */ - - -/* {{{ proto bool mcrypt_enc_is_block_mode(resource td) - Returns TRUE if the mode outputs blocks */ -PHP_FUNCTION(mcrypt_enc_is_block_mode) -{ - MCRYPT_GET_TD_ARG - - if (mcrypt_enc_is_block_mode(td) == 1) { - RETURN_TRUE - } else { - RETURN_FALSE - } -} -/* }}} */ - - -/* {{{ proto int mcrypt_enc_get_block_size(resource td) - Returns the block size of the cipher specified by the descriptor td */ -PHP_FUNCTION(mcrypt_enc_get_block_size) -{ - MCRYPT_GET_TD_ARG - RETURN_LONG(mcrypt_enc_get_block_size(td)); -} -/* }}} */ - - -/* {{{ proto int mcrypt_enc_get_key_size(resource td) - Returns the maximum supported key size in bytes of the algorithm specified by the descriptor td */ -PHP_FUNCTION(mcrypt_enc_get_key_size) -{ - MCRYPT_GET_TD_ARG - RETURN_LONG(mcrypt_enc_get_key_size(td)); -} -/* }}} */ - - -/* {{{ proto int mcrypt_enc_get_iv_size(resource td) - Returns the size of the IV in bytes of the algorithm specified by the descriptor td */ -PHP_FUNCTION(mcrypt_enc_get_iv_size) -{ - MCRYPT_GET_TD_ARG - RETURN_LONG(mcrypt_enc_get_iv_size(td)); -} -/* }}} */ - - -/* {{{ proto string mcrypt_enc_get_algorithms_name(resource td) - Returns the name of the algorithm specified by the descriptor td */ -PHP_FUNCTION(mcrypt_enc_get_algorithms_name) -{ - char *name; - MCRYPT_GET_TD_ARG - - name = mcrypt_enc_get_algorithms_name(td); - RETVAL_STRING(name, 1); - mcrypt_free(name); -} -/* }}} */ - - -/* {{{ proto string mcrypt_enc_get_modes_name(resource td) - Returns the name of the mode specified by the descriptor td */ -PHP_FUNCTION(mcrypt_enc_get_modes_name) -{ - char *name; - MCRYPT_GET_TD_ARG - - name = mcrypt_enc_get_modes_name(td); - RETVAL_STRING(name, 1); - mcrypt_free(name); -} -/* }}} */ - - -/* {{{ proto bool mcrypt_module_self_test(string algorithm [, string lib_dir]) - Does a self test of the module "module" */ -PHP_FUNCTION(mcrypt_module_self_test) -{ - MCRYPT_GET_MODE_DIR_ARGS(algorithms_dir); - - if (mcrypt_module_self_test(module, dir) == 0) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -/* {{{ proto bool mcrypt_module_is_block_algorithm_mode(string mode [, string lib_dir]) - Returns TRUE if the mode is for use with block algorithms */ -PHP_FUNCTION(mcrypt_module_is_block_algorithm_mode) -{ - MCRYPT_GET_MODE_DIR_ARGS(modes_dir) - - if (mcrypt_module_is_block_algorithm_mode(module, dir) == 1) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -/* {{{ proto bool mcrypt_module_is_block_algorithm(string algorithm [, string lib_dir]) - Returns TRUE if the algorithm is a block algorithm */ -PHP_FUNCTION(mcrypt_module_is_block_algorithm) -{ - MCRYPT_GET_MODE_DIR_ARGS(algorithms_dir) - - if (mcrypt_module_is_block_algorithm(module, dir) == 1) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -/* {{{ proto bool mcrypt_module_is_block_mode(string mode [, string lib_dir]) - Returns TRUE if the mode outputs blocks of bytes */ -PHP_FUNCTION(mcrypt_module_is_block_mode) -{ - MCRYPT_GET_MODE_DIR_ARGS(modes_dir) - - if (mcrypt_module_is_block_mode(module, dir) == 1) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -/* {{{ proto int mcrypt_module_get_algo_block_size(string algorithm [, string lib_dir]) - Returns the block size of the algorithm */ -PHP_FUNCTION(mcrypt_module_get_algo_block_size) -{ - MCRYPT_GET_MODE_DIR_ARGS(algorithms_dir) - - RETURN_LONG(mcrypt_module_get_algo_block_size(module, dir)); -} -/* }}} */ - - -/* {{{ proto int mcrypt_module_get_algo_key_size(string algorithm [, string lib_dir]) - Returns the maximum supported key size of the algorithm */ -PHP_FUNCTION(mcrypt_module_get_algo_key_size) -{ - MCRYPT_GET_MODE_DIR_ARGS(algorithms_dir); - - RETURN_LONG(mcrypt_module_get_algo_key_size(module, dir)); -} -/* }}} */ - - -/* {{{ proto int mcrypt_module_get_supported_key_sizes(string algorithm [, string lib_dir]) - This function decrypts the crypttext */ -PHP_FUNCTION(mcrypt_module_get_supported_key_sizes) -{ - int i, count = 0; - int *key_sizes; - - MCRYPT_GET_MODE_DIR_ARGS(algorithms_dir) - array_init(return_value); - - key_sizes = mcrypt_module_get_algo_supported_key_sizes(module, dir, &count); - - for (i = 0; i < count; i++) { - add_index_long(return_value, i, key_sizes[i]); - } - mcrypt_free(key_sizes); -} -/* }}} */ - - -/* {{{ proto array mcrypt_list_algorithms([string lib_dir]) - List all algorithms in "module_dir" */ -PHP_FUNCTION(mcrypt_list_algorithms) -{ - char **modules; - char *lib_dir = MCG(algorithms_dir); - int lib_dir_len; - int i, count; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", - &lib_dir, &lib_dir_len) == FAILURE) { - return; - } - - array_init(return_value); - modules = mcrypt_list_algorithms(lib_dir, &count); - - if (count == 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "No algorithms found in module dir"); - } - for (i = 0; i < count; i++) { - add_index_string(return_value, i, modules[i], 1); - } - mcrypt_free_p(modules, count); -} -/* }}} */ - - -/* {{{ proto array mcrypt_list_modes([string lib_dir]) - List all modes "module_dir" */ -PHP_FUNCTION(mcrypt_list_modes) -{ - char **modules; - char *lib_dir = MCG(modes_dir); - int lib_dir_len; - int i, count; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", - &lib_dir, &lib_dir_len) == FAILURE) { - return; - } - - array_init(return_value); - modules = mcrypt_list_modes(lib_dir, &count); - - if (count == 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "No modes found in module dir"); - } - for (i = 0; i < count; i++) { - add_index_string(return_value, i, modules[i], 1); - } - mcrypt_free_p(modules, count); -} -/* }}} */ - - -/* {{{ proto int mcrypt_get_key_size(string cipher, string module) - Get the key size of cipher */ -PHP_FUNCTION(mcrypt_get_key_size) -{ - char *cipher; - char *module; - int cipher_len, module_len; - char *cipher_dir_string; - char *module_dir_string; - MCRYPT td; - - MCRYPT_GET_INI - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", - &cipher, &cipher_len, &module, &module_len) == FAILURE) { - return; - } - - td = mcrypt_module_open(cipher, cipher_dir_string, module, module_dir_string); - if (td != MCRYPT_FAILED) { - RETVAL_LONG(mcrypt_enc_get_key_size(td)); - mcrypt_module_close(td); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, MCRYPT_OPEN_MODULE_FAILED); - RETURN_FALSE; - } -} -/* }}} */ - - -/* {{{ proto int mcrypt_get_block_size(string cipher, string module) - Get the key size of cipher */ -PHP_FUNCTION(mcrypt_get_block_size) -{ - char *cipher; - char *module; - int cipher_len, module_len; - char *cipher_dir_string; - char *module_dir_string; - MCRYPT td; - - MCRYPT_GET_INI - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", - &cipher, &cipher_len, &module, &module_len) == FAILURE) { - return; - } - - td = mcrypt_module_open(cipher, cipher_dir_string, module, module_dir_string); - if (td != MCRYPT_FAILED) { - RETVAL_LONG(mcrypt_enc_get_block_size(td)); - mcrypt_module_close(td); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, MCRYPT_OPEN_MODULE_FAILED); - RETURN_FALSE; - } -} -/* }}} */ - - -/* {{{ proto int mcrypt_get_iv_size(string cipher, string module) - Get the IV size of cipher (Usually the same as the blocksize) */ -PHP_FUNCTION(mcrypt_get_iv_size) -{ - char *cipher; - char *module; - int cipher_len, module_len; - char *cipher_dir_string; - char *module_dir_string; - MCRYPT td; - - MCRYPT_GET_INI - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", - &cipher, &cipher_len, &module, &module_len) == FAILURE) { - return; - } - - td = mcrypt_module_open(cipher, cipher_dir_string, module, module_dir_string); - if (td != MCRYPT_FAILED) { - RETVAL_LONG(mcrypt_enc_get_iv_size(td)); - mcrypt_module_close(td); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, MCRYPT_OPEN_MODULE_FAILED); - RETURN_FALSE; - } -} -/* }}} */ - - -/* {{{ proto string mcrypt_get_cipher_name(string cipher) - Get the key size of cipher */ -PHP_FUNCTION(mcrypt_get_cipher_name) -{ - char *cipher_dir_string; - char *module_dir_string; - char *cipher_name; - char *cipher; - int cipher_len; - MCRYPT td; - - MCRYPT_GET_INI - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", - &cipher, &cipher_len) == FAILURE) { - return; - } - - /* The code below is actually not very nice, but I didn't see a better - * method */ - td = mcrypt_module_open(cipher, cipher_dir_string, "ecb", module_dir_string); - if (td != MCRYPT_FAILED) { - cipher_name = mcrypt_enc_get_algorithms_name(td); - mcrypt_module_close(td); - RETVAL_STRING(cipher_name,1); - mcrypt_free(cipher_name); - } else { - td = mcrypt_module_open(cipher, cipher_dir_string, "stream", module_dir_string); - if (td != MCRYPT_FAILED) { - cipher_name = mcrypt_enc_get_algorithms_name(td); - mcrypt_module_close(td); - RETVAL_STRING(cipher_name,1); - mcrypt_free(cipher_name); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, MCRYPT_OPEN_MODULE_FAILED); - RETURN_FALSE; - } - } -} -/* }}} */ - - -static void php_mcrypt_do_crypt (char* cipher, zval **key, zval **data, char *mode, zval **iv, int argc, int dencrypt, zval* return_value TSRMLS_DC) -{ - char *cipher_dir_string; - char *module_dir_string; - int block_size, max_key_length, use_key_length, i, count, iv_size; - unsigned long int data_size; - int *key_length_sizes; - char *key_s = NULL, *iv_s; - char *data_s; - MCRYPT td; - - MCRYPT_GET_INI - - td = mcrypt_module_open(cipher, cipher_dir_string, mode, module_dir_string); - if (td == MCRYPT_FAILED) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, MCRYPT_OPEN_MODULE_FAILED); - RETURN_FALSE; - } - /* Checking for key-length */ - max_key_length = mcrypt_enc_get_key_size (td); - if (Z_STRLEN_PP(key) > max_key_length) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Size of key is too large for this algorithm"); - } - key_length_sizes = mcrypt_enc_get_supported_key_sizes (td, &count); - if (count == 0 && key_length_sizes == NULL) { /* all lengths 1 - k_l_s = OK */ - use_key_length = Z_STRLEN_PP(key); - key_s = emalloc (use_key_length); - memset (key_s, 0, use_key_length); - memcpy (key_s, Z_STRVAL_PP(key), use_key_length); - } else if (count == 1) { /* only m_k_l = OK */ - key_s = emalloc (key_length_sizes[0]); - memset (key_s, 0, key_length_sizes[0]); - memcpy (key_s, Z_STRVAL_PP(key), MIN(Z_STRLEN_PP(key), key_length_sizes[0])); - use_key_length = key_length_sizes[0]; - } else { /* dertermine smallest supported key > length of requested key */ - use_key_length = max_key_length; /* start with max key length */ - for (i = 0; i < count; i++) { - if (key_length_sizes[i] >= Z_STRLEN_PP(key) && - key_length_sizes[i] < use_key_length) - { - use_key_length = key_length_sizes[i]; - } - } - key_s = emalloc (use_key_length); - memset (key_s, 0, use_key_length); - memcpy (key_s, Z_STRVAL_PP(key), MIN(Z_STRLEN_PP(key), use_key_length)); - } - mcrypt_free (key_length_sizes); - - /* Check IV */ - iv_s = NULL; - iv_size = mcrypt_enc_get_iv_size (td); - if (argc == 5) { - if (iv_size != Z_STRLEN_PP(iv)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, MCRYPT_IV_WRONG_SIZE); - } else { - iv_s = emalloc (iv_size + 1); - memcpy (iv_s, Z_STRVAL_PP(iv), iv_size); - } - } else if (argc == 4) { - if (iv_size != 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to use an empty IV, which is NOT recommend"); - iv_s = emalloc (iv_size + 1); - memset (iv_s, 0, iv_size + 1); - } - } - - /* Check blocksize */ - if (mcrypt_enc_is_block_mode (td) == 1) { /* It's a block algorithm */ - block_size = mcrypt_enc_get_block_size (td); - data_size = (((Z_STRLEN_PP(data) - 1) / block_size) + 1) * block_size; - data_s = emalloc (data_size); - memset (data_s, 0, data_size); - memcpy (data_s, Z_STRVAL_PP(data), Z_STRLEN_PP(data)); - } else { /* It's not a block algorithm */ - data_size = Z_STRLEN_PP(data); - data_s = emalloc (data_size); - memset (data_s, 0, data_size); - memcpy (data_s, Z_STRVAL_PP(data), Z_STRLEN_PP(data)); - } - - if (mcrypt_generic_init (td, key_s, use_key_length, iv_s) < 0) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Mcrypt initialisation failed"); - } - if (dencrypt == MCRYPT_ENCRYPT) { - mcrypt_generic (td, data_s, data_size); - } else { - mdecrypt_generic (td, data_s, data_size); - } - - RETVAL_STRINGL (data_s, data_size, 1); - -/* freeing vars */ - mcrypt_generic_end (td); - if (key_s != NULL) - efree (key_s); - if (iv_s != NULL) - efree (iv_s); - efree (data_s); -} - -/* {{{ proto string mcrypt_encrypt(string cipher, string key, string data, string mode, string iv) - OFB crypt/decrypt data using key key with cipher cipher starting with iv */ -PHP_FUNCTION(mcrypt_encrypt) -{ - zval **cipher, **key, **data, **mode, **iv; - int argc; - - argc = ZEND_NUM_ARGS(); - - MCRYPT_CHECK_PARAM_COUNT (4, 5) - MCRYPT_GET_CRYPT_ARGS - - MCRYPT_CONVERT; - - php_mcrypt_do_crypt (Z_STRVAL_PP(cipher), key, data, Z_STRVAL_PP(mode), iv, argc, MCRYPT_ENCRYPT, return_value TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto string mcrypt_decrypt(string cipher, string key, string data, string mode, string iv) - OFB crypt/decrypt data using key key with cipher cipher starting with iv */ -PHP_FUNCTION(mcrypt_decrypt) -{ - zval **cipher, **key, **data, **mode, **iv; - int argc; - - argc = ZEND_NUM_ARGS(); - - MCRYPT_CHECK_PARAM_COUNT (4, 5) - MCRYPT_GET_CRYPT_ARGS - - MCRYPT_CONVERT; - - php_mcrypt_do_crypt (Z_STRVAL_PP(cipher), key, data, Z_STRVAL_PP(mode), iv, argc, MCRYPT_DECRYPT, return_value TSRMLS_CC); -} -/* }}} */ - -/* {{{ 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 **cipher, **key, **data, **mode, **iv; - int argc; - - argc = ZEND_NUM_ARGS(); - - MCRYPT_CHECK_PARAM_COUNT (4, 5) - MCRYPT_GET_CRYPT_ARGS - - MCRYPT_CONVERT_WO_MODE; - convert_to_long_ex(mode); - - php_mcrypt_do_crypt (Z_STRVAL_PP(cipher), key, data, "ecb", iv, argc, Z_LVAL_PP(mode), return_value TSRMLS_CC); -} -/* }}} */ - -/* {{{ 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 **cipher, **key, **data, **mode, **iv; - int argc; - - argc = ZEND_NUM_ARGS(); - - MCRYPT_CHECK_PARAM_COUNT (4, 5) - MCRYPT_GET_CRYPT_ARGS - - MCRYPT_CONVERT_WO_MODE; - convert_to_long_ex(mode); - - php_mcrypt_do_crypt (Z_STRVAL_PP(cipher), key, data, "cbc", iv, argc, Z_LVAL_PP(mode), return_value TSRMLS_CC); -} -/* }}} */ - -/* {{{ 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 **cipher, **key, **data, **mode, **iv; - int argc; - - argc = ZEND_NUM_ARGS(); - - MCRYPT_CHECK_PARAM_COUNT (4, 5) - MCRYPT_GET_CRYPT_ARGS - - MCRYPT_CONVERT_WO_MODE; - convert_to_long_ex(mode); - - php_mcrypt_do_crypt (Z_STRVAL_PP(cipher), key, data, "cfb", iv, argc, Z_LVAL_PP(mode), return_value TSRMLS_CC); -} -/* }}} */ - -/* {{{ 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 **cipher, **key, **data, **mode, **iv; - int argc; - - argc = ZEND_NUM_ARGS(); - - MCRYPT_CHECK_PARAM_COUNT (4, 5) - MCRYPT_GET_CRYPT_ARGS - - MCRYPT_CONVERT_WO_MODE; - convert_to_long_ex(mode); - - php_mcrypt_do_crypt (Z_STRVAL_PP(cipher), key, data, "ofb", iv, argc, Z_LVAL_PP(mode), return_value TSRMLS_CC); -} -/* }}} */ - - -/* {{{ proto string mcrypt_create_iv(int size, int source) - Create an initialization vector (IV) */ -PHP_FUNCTION(mcrypt_create_iv) -{ - char *iv; - iv_source source = RANDOM; - long size; - int n = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &size, &source) == FAILURE) { - return; - } - - if (size <= 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can not create an IV with size 0 or smaller"); - RETURN_FALSE; - } - - iv = ecalloc(size + 1, 1); - - if (source == RANDOM || source == URANDOM) { - int fd; - size_t read_bytes = 0; - - fd = open(source == RANDOM ? "/dev/random" : "/dev/urandom", - O_RDONLY); - if (fd < 0) { - efree(iv); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot open source device"); - RETURN_FALSE; - } - while (read_bytes < size) { - n = read(fd, iv + read_bytes, size - read_bytes); - if (n < 0) - break; - read_bytes += n; - } - n = read_bytes; - close(fd); - if (n < size) { - efree(iv); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not gather sufficient random data"); - RETURN_FALSE; - } - } else { - n = size; - while (size) { - iv[--size] = 255.0 * rand() / RAND_MAX; - } - } - RETURN_STRINGL(iv, n, 0); -} -/* }}} */ - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/mcrypt/mcrypt.dsp b/ext/mcrypt/mcrypt.dsp deleted file mode 100644 index 0665f724d3..0000000000 --- a/ext/mcrypt/mcrypt.dsp +++ /dev/null @@ -1,117 +0,0 @@ -# Microsoft Developer Studio Project File - Name="mcrypt" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=mcrypt - Win32 Release_TS
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "mcrypt.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "mcrypt.mak" CFG="mcrypt - Win32 Release_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "mcrypt - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "mcrypt - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "mcrypt - Win32 Release_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release_TS"
-# PROP BASE Intermediate_Dir "Release_TS"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release_TS"
-# PROP Intermediate_Dir "Release_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "..\..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\..\TSRM" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MSSQL_EXPORTS" /D "COMPILE_DL_MCRYPT" /D "DBNTWIN32" /D ZTS=1 /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\mcrypt\include" /D ZEND_DEBUG=0 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MCRYPT_EXPORTS" /D "COMPILE_DL_MCRYPT" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_LIBMCRYPT=1 /D HAVE_LIBMCRYPT24=1 /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x406 /d "NDEBUG"
-# ADD RSC /l 0x406 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib ntwdblib.lib /nologo /dll /machine:I386 /out:"MSSQL_65_Release/php_mssql.dll" /libpath:"..\..\Release_TS"
-# ADD LINK32 php4ts.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libmcrypt.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_mcrypt.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\..\php_build\mcrypt" /libpath:"..\..\Release_TS_Inline" /libpath:"..\..\TSRM\Release_TS" /libpath:"..\..\TSRM\Release_TS_Inline"
-
-!ELSEIF "$(CFG)" == "mcrypt - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Debug_TS"
-# PROP BASE Intermediate_Dir "Debug_TS"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "mssql-70" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MSSQL_EXPORTS" /D "COMPILE_DL_MCRYPT" /D "DBNTWIN32" /D ZTS=1 /D MSSQL70=1 /YX /FD /c
-# ADD CPP /nologo /MDd /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\mcrypt\include" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MCRYPT_EXPORTS" /D "COMPILE_DL_MCRYPT" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_LIBMCRYPT=1 /D HAVE_LIBMCRYPT24=1 /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x406 /d "NDEBUG"
-# ADD RSC /l 0x406 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib ntwdblib.lib /nologo /dll /machine:I386 /out:"MSSQL_65_Release/php_mssql.dll" /libpath:"..\..\Release_TS" /libpath:"mssql-70"
-# ADD LINK32 php4ts_debug.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libmcrypt.lib /nologo /dll /machine:I386 /out:"..\..\Debug_TS/php_mcrypt.dll" /libpath:"..\..\Debug_TS" /libpath:"..\..\..\php_build\mcrypt\lib"
-
-!ENDIF
-
-# Begin Target
-
-# Name "mcrypt - Win32 Release_TS"
-# Name "mcrypt - Win32 Debug_TS"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\mcrypt.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\win32\readdir.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\php_mcrypt.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\win32\readdir.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/ext/mcrypt/php_mcrypt.h b/ext/mcrypt/php_mcrypt.h deleted file mode 100644 index 5846a77411..0000000000 --- a/ext/mcrypt/php_mcrypt.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Sascha Schumann <sascha@schumann.cx> | - | Derick Rethans <d.rethans@jdimedia.nl> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#ifndef PHP_MCRYPT_H -#define PHP_MCRYPT_H - -#if HAVE_LIBMCRYPT - -#ifdef ZTS -#include "TSRM.h" -#endif - -extern zend_module_entry mcrypt_module_entry; -#define mcrypt_module_ptr &mcrypt_module_entry - -/* Functions for both old and new API */ -PHP_FUNCTION(mcrypt_ecb); -PHP_FUNCTION(mcrypt_cbc); -PHP_FUNCTION(mcrypt_cfb); -PHP_FUNCTION(mcrypt_ofb); -PHP_FUNCTION(mcrypt_get_cipher_name); -PHP_FUNCTION(mcrypt_get_block_size); -PHP_FUNCTION(mcrypt_get_key_size); -PHP_FUNCTION(mcrypt_create_iv); - -/* Support functions for old API */ -PHP_FUNCTION(mcrypt_list_algorithms); -PHP_FUNCTION(mcrypt_list_modes); -PHP_FUNCTION(mcrypt_get_iv_size); -PHP_FUNCTION(mcrypt_encrypt); -PHP_FUNCTION(mcrypt_decrypt); - -/* Functions for new API */ -PHP_FUNCTION(mcrypt_module_open); -PHP_FUNCTION(mcrypt_generic_init); -PHP_FUNCTION(mcrypt_generic); -PHP_FUNCTION(mdecrypt_generic); -PHP_FUNCTION(mcrypt_generic_end); -PHP_FUNCTION(mcrypt_generic_deinit); - -PHP_FUNCTION(mcrypt_enc_self_test); -PHP_FUNCTION(mcrypt_enc_is_block_algorithm_mode); -PHP_FUNCTION(mcrypt_enc_is_block_algorithm); -PHP_FUNCTION(mcrypt_enc_is_block_mode); -PHP_FUNCTION(mcrypt_enc_get_block_size); -PHP_FUNCTION(mcrypt_enc_get_key_size); -PHP_FUNCTION(mcrypt_enc_get_supported_key_sizes); -PHP_FUNCTION(mcrypt_enc_get_iv_size); -PHP_FUNCTION(mcrypt_enc_get_algorithms_name); -PHP_FUNCTION(mcrypt_enc_get_modes_name); -PHP_FUNCTION(mcrypt_module_self_test); -PHP_FUNCTION(mcrypt_module_is_block_algorithm_mode); -PHP_FUNCTION(mcrypt_module_is_block_algorithm); -PHP_FUNCTION(mcrypt_module_is_block_mode); -PHP_FUNCTION(mcrypt_module_get_algo_block_size); -PHP_FUNCTION(mcrypt_module_get_algo_key_size); -PHP_FUNCTION(mcrypt_module_get_supported_key_sizes); -PHP_FUNCTION(mcrypt_module_close); - -ZEND_BEGIN_MODULE_GLOBALS(mcrypt) - int le_h; - char *modes_dir; - char *algorithms_dir; -ZEND_END_MODULE_GLOBALS(mcrypt) - -#ifdef ZTS -# define MCG(v) TSRMG(mcrypt_globals_id, zend_mcrypt_globals *, v) -#else -# define MCG(v) (mcrypt_globals.v) -#endif - -#else -#define mcrypt_module_ptr NULL -#endif - -#define phpext_mcrypt_ptr mcrypt_module_ptr - -#endif diff --git a/ext/mcrypt/tests/blowfish.phpt b/ext/mcrypt/tests/blowfish.phpt deleted file mode 100644 index c2273c165d..0000000000 --- a/ext/mcrypt/tests/blowfish.phpt +++ /dev/null @@ -1,77 +0,0 @@ ---TEST-- -Test for blowfish compatibility ---SKIPIF-- -<?php if (!extension_loaded("mcrypt")) print "skip"; ?> ---POST-- ---GET-- ---FILE-- -<?php -function hex2bin($data) { - $len = strlen($data); - return pack("H" . $len, $data); -} - -print "key plain crypt guess stat\n"; -$null = "\0\0\0\0\0\0\0\0"; -$vectors = file("ext/mcrypt/tests/vectors.txt"); - -$td = mcrypt_module_open ("blowfish", "", MCRYPT_MODE_ECB, ""); - -foreach($vectors as $data) { - $data = trim($data); - if ($data) { - list($key,$plain,$crypt) = split("[[:space:]]+",$data); - printf("%s %s ", - $key, - $plain - ); - $key = hex2bin(trim($key)); - $plain = hex2bin(($plain)); - $crypt = strtolower(trim($crypt)); - - mcrypt_generic_init ($td, $key, $null); - $guess = mcrypt_generic ($td, $plain); - $guess = bin2hex($guess); - printf("%s %s %s\n", - $crypt, - $guess, - ($crypt==$guess ? "OK" : "BAD") - ); - } -} -?> ---EXPECT-- -key plain crypt guess stat -0000000000000000 0000000000000000 4ef997456198dd78 4ef997456198dd78 OK -FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF 51866fd5b85ecb8a 51866fd5b85ecb8a OK -3000000000000000 1000000000000001 7d856f9a613063f2 7d856f9a613063f2 OK -1111111111111111 1111111111111111 2466dd878b963c9d 2466dd878b963c9d OK -0123456789ABCDEF 1111111111111111 61f9c3802281b096 61f9c3802281b096 OK -1111111111111111 0123456789ABCDEF 7d0cc630afda1ec7 7d0cc630afda1ec7 OK -FEDCBA9876543210 0123456789ABCDEF 0aceab0fc6a0a28d 0aceab0fc6a0a28d OK -7CA110454A1A6E57 01A1D6D039776742 59c68245eb05282b 59c68245eb05282b OK -0131D9619DC1376E 5CD54CA83DEF57DA b1b8cc0b250f09a0 b1b8cc0b250f09a0 OK -07A1133E4A0B2686 0248D43806F67172 1730e5778bea1da4 1730e5778bea1da4 OK -3849674C2602319E 51454B582DDF440A a25e7856cf2651eb a25e7856cf2651eb OK -04B915BA43FEB5B6 42FD443059577FA2 353882b109ce8f1a 353882b109ce8f1a OK -0113B970FD34F2CE 059B5E0851CF143A 48f4d0884c379918 48f4d0884c379918 OK -0170F175468FB5E6 0756D8E0774761D2 432193b78951fc98 432193b78951fc98 OK -43297FAD38E373FE 762514B829BF486A 13f04154d69d1ae5 13f04154d69d1ae5 OK -07A7137045DA2A16 3BDD119049372802 2eedda93ffd39c79 2eedda93ffd39c79 OK -04689104C2FD3B2F 26955F6835AF609A d887e0393c2da6e3 d887e0393c2da6e3 OK -37D06BB516CB7546 164D5E404F275232 5f99d04f5b163969 5f99d04f5b163969 OK -1F08260D1AC2465E 6B056E18759F5CCA 4a057a3b24d3977b 4a057a3b24d3977b OK -584023641ABA6176 004BD6EF09176062 452031c1e4fada8e 452031c1e4fada8e OK -025816164629B007 480D39006EE762F2 7555ae39f59b87bd 7555ae39f59b87bd OK -49793EBC79B3258F 437540C8698F3CFA 53c55f9cb49fc019 53c55f9cb49fc019 OK -4FB05E1515AB73A7 072D43A077075292 7a8e7bfa937e89a3 7a8e7bfa937e89a3 OK -49E95D6D4CA229BF 02FE55778117F12A cf9c5d7a4986adb5 cf9c5d7a4986adb5 OK -018310DC409B26D6 1D9D5C5018F728C2 d1abb290658bc778 d1abb290658bc778 OK -1C587F1C13924FEF 305532286D6F295A 55cb3774d13ef201 55cb3774d13ef201 OK -0101010101010101 0123456789ABCDEF fa34ec4847b268b2 fa34ec4847b268b2 OK -1F1F1F1F0E0E0E0E 0123456789ABCDEF a790795108ea3cae a790795108ea3cae OK -E0FEE0FEF1FEF1FE 0123456789ABCDEF c39e072d9fac631d c39e072d9fac631d OK -0000000000000000 FFFFFFFFFFFFFFFF 014933e0cdaff6e4 014933e0cdaff6e4 OK -FFFFFFFFFFFFFFFF 0000000000000000 f21e9a77b71c49bc f21e9a77b71c49bc OK -0123456789ABCDEF 0000000000000000 245946885754369a 245946885754369a OK -FEDCBA9876543210 FFFFFFFFFFFFFFFF 6b5c5a9c5d9e0a5a 6b5c5a9c5d9e0a5a OK diff --git a/ext/mcrypt/tests/bug8040.phpt b/ext/mcrypt/tests/bug8040.phpt deleted file mode 100644 index e2d8c15b41..0000000000 --- a/ext/mcrypt/tests/bug8040.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -Bug #8040 ---SKIPIF-- -<?php if (!extension_loaded("mcrypt")) print "skip"; ?> ---POST-- ---GET-- ---FILE-- -<?php - error_reporting (E_ALL ^ E_NOTICE); - echo MCRYPT_TWOFISH."\n"; - echo MCRYPT_MODE_CBC."\n"; - - define ("MODE1", MCRYPT_MODE_CBC); - echo MODE1."\n"; - - define ("CIPHER", MCRYPT_TWOFISH); - define ("MODE2", MCRYPT_MODE_CBC); - define ("MODE3", MCRYPT_CBC); - - printf ("cipher=".CIPHER. " mode1=".MODE2. " mode2=". MODE3."\n"); -?> ---EXPECT-- -twofish -cbc -cbc -cipher=twofish mode1=cbc mode2=MCRYPT_CBC diff --git a/ext/mcrypt/tests/vectors.txt b/ext/mcrypt/tests/vectors.txt deleted file mode 100644 index 3624ed6d69..0000000000 --- a/ext/mcrypt/tests/vectors.txt +++ /dev/null @@ -1,33 +0,0 @@ -0000000000000000 0000000000000000 4EF997456198DD78 -FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF 51866FD5B85ECB8A -3000000000000000 1000000000000001 7D856F9A613063F2 -1111111111111111 1111111111111111 2466DD878B963C9D -0123456789ABCDEF 1111111111111111 61F9C3802281B096 -1111111111111111 0123456789ABCDEF 7D0CC630AFDA1EC7 -FEDCBA9876543210 0123456789ABCDEF 0ACEAB0FC6A0A28D -7CA110454A1A6E57 01A1D6D039776742 59C68245EB05282B -0131D9619DC1376E 5CD54CA83DEF57DA B1B8CC0B250F09A0 -07A1133E4A0B2686 0248D43806F67172 1730E5778BEA1DA4 -3849674C2602319E 51454B582DDF440A A25E7856CF2651EB -04B915BA43FEB5B6 42FD443059577FA2 353882B109CE8F1A -0113B970FD34F2CE 059B5E0851CF143A 48F4D0884C379918 -0170F175468FB5E6 0756D8E0774761D2 432193B78951FC98 -43297FAD38E373FE 762514B829BF486A 13F04154D69D1AE5 -07A7137045DA2A16 3BDD119049372802 2EEDDA93FFD39C79 -04689104C2FD3B2F 26955F6835AF609A D887E0393C2DA6E3 -37D06BB516CB7546 164D5E404F275232 5F99D04F5B163969 -1F08260D1AC2465E 6B056E18759F5CCA 4A057A3B24D3977B -584023641ABA6176 004BD6EF09176062 452031C1E4FADA8E -025816164629B007 480D39006EE762F2 7555AE39F59B87BD -49793EBC79B3258F 437540C8698F3CFA 53C55F9CB49FC019 -4FB05E1515AB73A7 072D43A077075292 7A8E7BFA937E89A3 -49E95D6D4CA229BF 02FE55778117F12A CF9C5D7A4986ADB5 -018310DC409B26D6 1D9D5C5018F728C2 D1ABB290658BC778 -1C587F1C13924FEF 305532286D6F295A 55CB3774D13EF201 -0101010101010101 0123456789ABCDEF FA34EC4847B268B2 -1F1F1F1F0E0E0E0E 0123456789ABCDEF A790795108EA3CAE -E0FEE0FEF1FEF1FE 0123456789ABCDEF C39E072D9FAC631D -0000000000000000 FFFFFFFFFFFFFFFF 014933E0CDAFF6E4 -FFFFFFFFFFFFFFFF 0000000000000000 F21E9A77B71C49BC -0123456789ABCDEF 0000000000000000 245946885754369A -FEDCBA9876543210 FFFFFFFFFFFFFFFF 6B5C5A9C5D9E0A5A |