summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--acinclude.m42
-rw-r--r--ext/mcrypt/Makefile.am6
-rw-r--r--ext/mcrypt/config.h.stub2
-rw-r--r--ext/mcrypt/config.m428
-rw-r--r--ext/mcrypt/mcrypt.c99
-rw-r--r--ext/mcrypt/php_mcrypt.h15
-rw-r--r--ext/mcrypt/setup.stub6
-rw-r--r--internal_functions.c2
8 files changed, 159 insertions, 1 deletions
diff --git a/acinclude.m4 b/acinclude.m4
index f090513cb4..82f3894449 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -10,7 +10,7 @@ AC_DEFUN(AC_CHECK_CC_OPTION,[
echo "main(){return 0;}" > conftest.$ac_ext
opt="$1"
var=`echo -n $opt|tr -c a-zA-Z0-9 _`
- AC_MSG_CHECKING([if compiler supports $1 really])
+ AC_MSG_CHECKING([if compiler supports -$1 really])
ac_compile='${CC-cc} -$opt -c $CFLAGS $CPPFLAGS conftest.$ac_ext 2>&1'
if eval $ac_compile | egrep "$opt" > /dev/null 2>&1 ; then
eval php_cc_$var=no
diff --git a/ext/mcrypt/Makefile.am b/ext/mcrypt/Makefile.am
new file mode 100644
index 0000000000..01baf80148
--- /dev/null
+++ b/ext/mcrypt/Makefile.am
@@ -0,0 +1,6 @@
+# $Id$
+
+INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend
+noinst_LIBRARIES=libphpext_mcrypt.a
+libphpext_mcrypt_a_SOURCES=mcrypt.c
+
diff --git a/ext/mcrypt/config.h.stub b/ext/mcrypt/config.h.stub
new file mode 100644
index 0000000000..28fbe03ae2
--- /dev/null
+++ b/ext/mcrypt/config.h.stub
@@ -0,0 +1,2 @@
+/* define if you want to use the mcrypt extension */
+#undef HAVE_LIBMCRYPT
diff --git a/ext/mcrypt/config.m4 b/ext/mcrypt/config.m4
new file mode 100644
index 0000000000..78dd7fb497
--- /dev/null
+++ b/ext/mcrypt/config.m4
@@ -0,0 +1,28 @@
+dnl $Id$
+dnl config.m4 for extension mcrypt
+dnl don't forget to call PHP_EXTENSION(mcrypt)
+
+AC_MSG_CHECKING(for mcrypt support)
+AC_ARG_WITH(mcrypt,
+[ --with-mcrypt[=DIR] Include mcrypt support. DIR is the mcrypt
+ install directory.],
+[
+ if test "$withval" != "no"; then
+ for i in /usr/local /usr $withval; do
+ if test -f $i/include/lcrypt.h; then
+ MCRYPT_DIR=$i
+ fi
+ done
+ INCLUDES="$INCLUDES -I$MCRYPT_DIR/include"
+ EXTRA_LIBS="$EXTRA_LIBS -L$MCRYPT_DIR/lib -lmcrypt"
+
+ AC_DEFINE(HAVE_LIBMCRYPT)
+
+ AC_MSG_RESULT(yes)
+ PHP_EXTENSION(mcrypt)
+ else
+ AC_MSG_RESULT(no)
+ fi
+],[
+ AC_MSG_RESULT(no)
+])
diff --git a/ext/mcrypt/mcrypt.c b/ext/mcrypt/mcrypt.c
new file mode 100644
index 0000000000..59dac95de9
--- /dev/null
+++ b/ext/mcrypt/mcrypt.c
@@ -0,0 +1,99 @@
+
+#include "php.h"
+
+#if HAVE_LIBMCRYPT
+
+#include "php_mcrypt.h"
+
+#include "lcrypt.h"
+
+function_entry mcrypt_functions[] = {
+ PHP_FE(mcrypt_ecb, NULL)
+ {0},
+};
+
+static int php3_minit_mcrypt(INIT_FUNC_ARGS);
+
+zend_module_entry mcrypt_module_entry = {
+ "mcrypt",
+ mcrypt_functions,
+ php3_minit_mcrypt, NULL,
+ NULL, NULL,
+ NULL,
+ STANDARD_MODULE_PROPERTIES,
+};
+
+#if 0
+
+typedef struct mcrypt_global_struct {
+ int le_h;
+} mcrypt_global_struct;
+
+static mcrypt_global_struct mcryptg;
+
+#define MCRYPTG(x) mcryptg.x
+
+#endif
+
+#define MCRYPT_ENTRY(a) REGISTER_LONG_CONSTANT("MC_" #a, a, 0)
+
+static int php3_minit_mcrypt(INIT_FUNC_ARGS)
+{
+ MCRYPT_ENTRY(BLOWFISH);
+ MCRYPT_ENTRY(DES);
+ MCRYPT_ENTRY(TripleDES);
+ MCRYPT_ENTRY(ThreeWAY);
+ MCRYPT_ENTRY(GOST);
+ MCRYPT_ENTRY(SAFER64);
+ MCRYPT_ENTRY(SAFER128);
+ MCRYPT_ENTRY(CAST128);
+ MCRYPT_ENTRY(TEAN);
+ MCRYPT_ENTRY(TWOFISH);
+ MCRYPT_ENTRY(RC2);
+#ifdef CRYPT
+ MCRYPT_ENTRY(CRYPT);
+#endif
+ return SUCCESS;
+}
+
+PHP_FUNCTION(mcrypt_ecb)
+{
+ pval *cipher, *data, *key, *mode;
+ int td;
+ char *ndata;
+ size_t bsize;
+ size_t nr;
+ size_t nsize;
+
+ if(ARG_COUNT(ht) != 4 || getParameters(ht, 4, &cipher, &key, &data, &mode) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_long(cipher);
+ convert_to_long(mode);
+ convert_to_string(data);
+ convert_to_string(key);
+
+ bsize = get_block_size(cipher->value.lval);
+ nr = (data->value.str.len + bsize - 1) / bsize;
+ nsize = nr * bsize;
+
+ td = init_mcrypt_ecb(cipher->value.lval, key->value.str.val, key->value.str.len);
+ if(td == -1) {
+ php3_error(E_WARNING, "mcrypt initialization failed");
+ RETURN_FALSE;
+ }
+
+ ndata = ecalloc(nr, bsize);
+ memcpy(ndata, data->value.str.val, data->value.str.len);
+
+ if(mode->value.lval == 0)
+ mcrypt_ecb(td, ndata, nsize);
+ else
+ mdecrypt_ecb(td, ndata, nsize);
+
+ end_mcrypt(td);
+
+ RETURN_STRINGL(ndata, nsize, 0);
+}
+
+#endif
diff --git a/ext/mcrypt/php_mcrypt.h b/ext/mcrypt/php_mcrypt.h
new file mode 100644
index 0000000000..21a6d67e67
--- /dev/null
+++ b/ext/mcrypt/php_mcrypt.h
@@ -0,0 +1,15 @@
+#ifndef PHP_MCRYPT_H
+#define PHP_MCRYPT_H
+
+#if HAVE_LIBMCRYPT
+
+extern zend_module_entry mcrypt_module_entry;
+#define mcrypt_module_ptr &mcrypt_module_entry
+
+PHP_FUNCTION(mcrypt_ecb);
+
+#else
+#define mcrypt_module_ptr NULL
+#endif
+
+#endif
diff --git a/ext/mcrypt/setup.stub b/ext/mcrypt/setup.stub
new file mode 100644
index 0000000000..76d795b16e
--- /dev/null
+++ b/ext/mcrypt/setup.stub
@@ -0,0 +1,6 @@
+# $Source$
+# $Id$
+
+define_option with-mcrypt 'mcrypt support?' yesnodir no \
+' Whether to build the mcrypt extension.'
+
diff --git a/internal_functions.c b/internal_functions.c
index 8dedf3d092..dd2cd0925c 100644
--- a/internal_functions.c
+++ b/internal_functions.c
@@ -72,6 +72,7 @@
#include "ext/sysvsem/php3_sysvsem.h"
#include "ext/sysvshm/php3_sysvshm.h"
#include "ext/dav/php3_dav.h"
+#include "ext/mcrypt/php_mcrypt.h"
unsigned char first_arg_force_ref[] = { 1, BYREF_FORCE };
unsigned char first_arg_allow_ref[] = { 1, BYREF_ALLOW };
@@ -86,6 +87,7 @@ zend_module_entry *php3_builtin_modules[] =
php3_filestat_module_ptr,
php3_file_module_ptr,
php3_header_module_ptr,
+ mcrypt_module_ptr,
mail_module_ptr,
syslog_module_ptr,
mysql_module_ptr,