add mcrypt module

This commit is contained in:
Sascha Schumann 1999-04-25 16:50:40 +00:00
parent c4442ed7c5
commit 11fc109ca6
8 changed files with 159 additions and 1 deletions

View 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

6
ext/mcrypt/Makefile.am Normal file
View File

@ -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

2
ext/mcrypt/config.h.stub Normal file
View File

@ -0,0 +1,2 @@
/* define if you want to use the mcrypt extension */
#undef HAVE_LIBMCRYPT

28
ext/mcrypt/config.m4 Normal file
View File

@ -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)
])

99
ext/mcrypt/mcrypt.c Normal file
View File

@ -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

15
ext/mcrypt/php_mcrypt.h Normal file
View File

@ -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

6
ext/mcrypt/setup.stub Normal file
View File

@ -0,0 +1,6 @@
# $Source$
# $Id$
define_option with-mcrypt 'mcrypt support?' yesnodir no \
' Whether to build the mcrypt extension.'

View 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,