]> granicus.if.org Git - php/commitdiff
add mcrypt module
authorSascha Schumann <sas@php.net>
Sun, 25 Apr 1999 16:50:40 +0000 (16:50 +0000)
committerSascha Schumann <sas@php.net>
Sun, 25 Apr 1999 16:50:40 +0000 (16:50 +0000)
acinclude.m4
ext/mcrypt/Makefile.am [new file with mode: 0644]
ext/mcrypt/config.h.stub [new file with mode: 0644]
ext/mcrypt/config.m4 [new file with mode: 0644]
ext/mcrypt/mcrypt.c [new file with mode: 0644]
ext/mcrypt/php_mcrypt.h [new file with mode: 0644]
ext/mcrypt/setup.stub [new file with mode: 0644]
internal_functions.c

index f090513cb4dfeebdf935c039d92c1c37b1a75b9a..82f3894449acf8b0e3a97794a8cd0dc41d79f921 100644 (file)
@@ -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 (file)
index 0000000..01baf80
--- /dev/null
@@ -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 (file)
index 0000000..28fbe03
--- /dev/null
@@ -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 (file)
index 0000000..78dd7fb
--- /dev/null
@@ -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 (file)
index 0000000..59dac95
--- /dev/null
@@ -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 (file)
index 0000000..21a6d67
--- /dev/null
@@ -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 (file)
index 0000000..76d795b
--- /dev/null
@@ -0,0 +1,6 @@
+# $Source$
+# $Id$
+
+define_option with-mcrypt 'mcrypt support?' yesnodir no \
+'    Whether to build the mcrypt extension.'
+       
index 8dedf3d09254a9ff0047f9f784d0df01545f1118..dd2cd0925c36139db7bb61e1e5f06ab4efbb9982 100644 (file)
@@ -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,