summaryrefslogtreecommitdiff
path: root/ext/mcrypt
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mcrypt')
-rw-r--r--ext/mcrypt/mcrypt.c40
-rw-r--r--ext/mcrypt/php_mcrypt.h3
-rw-r--r--ext/mcrypt/tests/blowfish.phpt16
-rw-r--r--ext/mcrypt/tests/bug37595.phptbin0 -> 1094 bytes
4 files changed, 35 insertions, 24 deletions
diff --git a/ext/mcrypt/mcrypt.c b/ext/mcrypt/mcrypt.c
index 983e85264..40b64324a 100644
--- a/ext/mcrypt/mcrypt.c
+++ b/ext/mcrypt/mcrypt.c
@@ -16,7 +16,7 @@
| Derick Rethans <derick@derickrethans.nl> |
+----------------------------------------------------------------------+
*/
-/* $Id: mcrypt.c,v 1.91.2.3 2006/01/01 12:50:08 sniper Exp $ */
+/* $Id: mcrypt.c,v 1.91.2.3.2.5 2006/06/26 16:33:38 bjori Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -63,7 +63,7 @@ zend_function_entry mcrypt_functions[] = {
PHP_FE(mcrypt_generic_init, NULL)
PHP_FE(mcrypt_generic, NULL)
PHP_FE(mdecrypt_generic, NULL)
- PHP_FE(mcrypt_generic_end, NULL)
+ PHP_DEP_FALIAS(mcrypt_generic_end, mcrypt_generic_deinit, NULL)
PHP_FE(mcrypt_generic_deinit, NULL)
PHP_FE(mcrypt_enc_self_test, NULL)
@@ -93,6 +93,8 @@ static PHP_MINFO_FUNCTION(mcrypt);
static PHP_MINIT_FUNCTION(mcrypt);
static PHP_MSHUTDOWN_FUNCTION(mcrypt);
+ZEND_DECLARE_MODULE_GLOBALS(mcrypt)
+
zend_module_entry mcrypt_module_entry = {
STANDARD_MODULE_HEADER,
"mcrypt",
@@ -101,11 +103,13 @@ zend_module_entry mcrypt_module_entry = {
NULL, NULL,
PHP_MINFO(mcrypt),
NO_VERSION_YET,
- STANDARD_MODULE_PROPERTIES,
+ PHP_MODULE_GLOBALS(mcrypt),
+ NULL,
+ NULL,
+ NULL,
+ STANDARD_MODULE_PROPERTIES_EX
};
-ZEND_DECLARE_MODULE_GLOBALS(mcrypt)
-
#ifdef COMPILE_DL_MCRYPT
ZEND_GET_MODULE(mcrypt)
#endif
@@ -245,11 +249,6 @@ static void php_mcrypt_module_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
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 */
@@ -492,6 +491,10 @@ PHP_FUNCTION(mcrypt_generic)
ZEND_FETCH_RESOURCE(pm, php_mcrypt *, mcryptind, -1, "MCrypt", le_mcrypt);
PHP_MCRYPT_INIT_CHECK
convert_to_string_ex(data);
+ if (Z_STRLEN_PP(data) == 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "An empty string was passed");
+ RETURN_FALSE
+ }
/* Check blocksize */
if (mcrypt_enc_is_block_mode(pm->td) == 1) { /* It's a block algorithm */
@@ -533,6 +536,10 @@ PHP_FUNCTION(mdecrypt_generic)
ZEND_FETCH_RESOURCE(pm, php_mcrypt * , mcryptind, -1, "MCrypt", le_mcrypt);
PHP_MCRYPT_INIT_CHECK
convert_to_string_ex(data);
+ if (Z_STRLEN_PP(data) == 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "An empty string was passed");
+ RETURN_FALSE
+ }
/* Check blocksize */
if (mcrypt_enc_is_block_mode(pm->td) == 1) { /* It's a block algorithm */
@@ -597,16 +604,6 @@ PHP_FUNCTION(mcrypt_module_close)
/* }}} */
-/* {{{ 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)
@@ -1097,7 +1094,8 @@ static void php_mcrypt_do_crypt (char* cipher, zval **key, zval **data, char *mo
}
if (mcrypt_generic_init(td, key_s, use_key_length, iv_s) < 0) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Mcrypt initialisation failed");
+ php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Mcrypt initialisation failed");
+ RETURN_FALSE;
}
if (dencrypt == MCRYPT_ENCRYPT) {
mcrypt_generic(td, data_s, data_size);
diff --git a/ext/mcrypt/php_mcrypt.h b/ext/mcrypt/php_mcrypt.h
index bce9880f9..32119e7a2 100644
--- a/ext/mcrypt/php_mcrypt.h
+++ b/ext/mcrypt/php_mcrypt.h
@@ -16,7 +16,7 @@
| Derick Rethans <derick@derickrethans.nl> |
+----------------------------------------------------------------------+
*/
-/* $Id: php_mcrypt.h,v 1.26.2.1 2006/01/01 12:50:08 sniper Exp $ */
+/* $Id: php_mcrypt.h,v 1.26.2.1.2.1 2006/06/26 16:33:38 bjori Exp $ */
#ifndef PHP_MCRYPT_H
#define PHP_MCRYPT_H
@@ -52,7 +52,6 @@ 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);
diff --git a/ext/mcrypt/tests/blowfish.phpt b/ext/mcrypt/tests/blowfish.phpt
index dc51da65b..ce258d3e1 100644
--- a/ext/mcrypt/tests/blowfish.phpt
+++ b/ext/mcrypt/tests/blowfish.phpt
@@ -36,7 +36,19 @@ foreach($vectors as $data) {
($crypt==$guess ? "OK" : "BAD")
);
}
-}
+}
+
+// Longer test case from http://www.schneier.com/code/vectors.txt
+$td = mcrypt_module_open ("blowfish", "", MCRYPT_MODE_CBC, "");
+
+$key = hex2bin( "0123456789ABCDEFF0E1D2C3B4A59687" );
+$iv = hex2bin( "FEDCBA9876543210" );
+$plain = hex2bin( "37363534333231204E6F77206973207468652074696D6520666F722000" );
+
+mcrypt_generic_init( $td, $key, $iv );
+$guess = bin2hex( mcrypt_generic( $td, $plain ) );
+
+echo "\n", $guess, "\n";
?>
--EXPECT--
key plain crypt guess stat
@@ -73,3 +85,5 @@ E0FEE0FEF1FEF1FE 0123456789ABCDEF c39e072d9fac631d c39e072d9fac631d OK
FFFFFFFFFFFFFFFF 0000000000000000 f21e9a77b71c49bc f21e9a77b71c49bc OK
0123456789ABCDEF 0000000000000000 245946885754369a 245946885754369a OK
FEDCBA9876543210 FFFFFFFFFFFFFFFF 6b5c5a9c5d9e0a5a 6b5c5a9c5d9e0a5a OK
+
+6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc
diff --git a/ext/mcrypt/tests/bug37595.phpt b/ext/mcrypt/tests/bug37595.phpt
new file mode 100644
index 000000000..3c682129f
--- /dev/null
+++ b/ext/mcrypt/tests/bug37595.phpt
Binary files differ