diff options
| author | Sascha Schumann <sas@php.net> | 1999-04-25 16:50:40 +0000 |
|---|---|---|
| committer | Sascha Schumann <sas@php.net> | 1999-04-25 16:50:40 +0000 |
| commit | 11fc109ca647ecb70c544fa8e6a93b9cfb0f3853 (patch) | |
| tree | fd82426253f9aa26fed0cb8ef533abfebb316770 /ext | |
| parent | c4442ed7c56de371cb8d76b6a2148b48f5889e1b (diff) | |
| download | php-git-11fc109ca647ecb70c544fa8e6a93b9cfb0f3853.tar.gz | |
add mcrypt module
Diffstat (limited to 'ext')
| -rw-r--r-- | ext/mcrypt/Makefile.am | 6 | ||||
| -rw-r--r-- | ext/mcrypt/config.h.stub | 2 | ||||
| -rw-r--r-- | ext/mcrypt/config.m4 | 28 | ||||
| -rw-r--r-- | ext/mcrypt/mcrypt.c | 99 | ||||
| -rw-r--r-- | ext/mcrypt/php_mcrypt.h | 15 | ||||
| -rw-r--r-- | ext/mcrypt/setup.stub | 6 |
6 files changed, 156 insertions, 0 deletions
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.' + |
