scottmac                Thu Jun 26 22:33:16 2008 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/ext/hash/tests     mhash_001.phpt mhash_002.phpt 
                                mhash_003.phpt skip_mhash.inc 

  Removed files:               
    /php-src/ext/mhash  mhash.dsp 
    /php-src/ext/mhash/tests    001.phpt 002.phpt 003.phpt skip.inc 

  Modified files:              
    /php-src/ext/hash   CREDITS config.m4 hash.c 
    /php-src/ext/mhash  config.m4 mhash.c php_mhash.h 
  Log:
  Make the old mhash API a wrapper around hash, this removes a dependency.
  
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/hash/CREDITS?r1=1.2.2.2&r2=1.2.2.2.4.1&diff_format=u
Index: php-src/ext/hash/CREDITS
diff -u php-src/ext/hash/CREDITS:1.2.2.2 php-src/ext/hash/CREDITS:1.2.2.2.4.1
--- php-src/ext/hash/CREDITS:1.2.2.2    Fri Dec  2 01:59:44 2005
+++ php-src/ext/hash/CREDITS    Thu Jun 26 22:33:16 2008
@@ -1,2 +1,2 @@
 PHP hash
-Sara Golemon, Rasmus Lerdorf, Stefan Esser, Michael Wallner
+Sara Golemon, Rasmus Lerdorf, Stefan Esser, Michael Wallner, Scott MacVicar
http://cvs.php.net/viewvc.cgi/php-src/ext/hash/config.m4?r1=1.10.2.4.2.1&r2=1.10.2.4.2.1.2.1&diff_format=u
Index: php-src/ext/hash/config.m4
diff -u php-src/ext/hash/config.m4:1.10.2.4.2.1 
php-src/ext/hash/config.m4:1.10.2.4.2.1.2.1
--- php-src/ext/hash/config.m4:1.10.2.4.2.1     Tue Jul  3 17:25:33 2007
+++ php-src/ext/hash/config.m4  Thu Jun 26 22:33:16 2008
@@ -1,9 +1,17 @@
-dnl $Id: config.m4,v 1.10.2.4.2.1 2007/07/03 17:25:33 sniper Exp $
+dnl $Id: config.m4,v 1.10.2.4.2.1.2.1 2008/06/26 22:33:16 scottmac Exp $
 dnl config.m4 for extension hash
 
 PHP_ARG_ENABLE(hash, whether to enable hash support,
 [  --disable-hash          Disable hash support], yes)
 
+if test "$PHP_MHASH" != "no"; then
+  if test "$PHP_HASH" == "no"; then
+    PHP_HASH="yes"
+  fi
+
+  AC_DEFINE(PHP_MHASH_BC, 1, [ ])
+fi
+
 if test "$PHP_HASH" != "no"; then
   AC_DEFINE(HAVE_HASH_EXT,1,[Have HASH Extension])
 
http://cvs.php.net/viewvc.cgi/php-src/ext/hash/hash.c?r1=1.18.2.5.2.7.2.6&r2=1.18.2.5.2.7.2.7&diff_format=u
Index: php-src/ext/hash/hash.c
diff -u php-src/ext/hash/hash.c:1.18.2.5.2.7.2.6 
php-src/ext/hash/hash.c:1.18.2.5.2.7.2.7
--- php-src/ext/hash/hash.c:1.18.2.5.2.7.2.6    Tue Jun  3 17:25:42 2008
+++ php-src/ext/hash/hash.c     Thu Jun 26 22:33:16 2008
@@ -13,10 +13,11 @@
   | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author: Sara Golemon <[EMAIL PROTECTED]>                               |
+  |         Scott MacVicar <[EMAIL PROTECTED]>                            |
   +----------------------------------------------------------------------+
 */
 
-/* $Id: hash.c,v 1.18.2.5.2.7.2.6 2008/06/03 17:25:42 scottmac Exp $ */
+/* $Id: hash.c,v 1.18.2.5.2.7.2.7 2008/06/26 22:33:16 scottmac Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -35,6 +36,48 @@
 # define DEFAULT_CONTEXT NULL
 #endif
 
+#ifdef PHP_MHASH_BC
+struct mhash_bc_entry {
+       char *mhash_name;
+       char *hash_name;
+       int value;
+};
+
+#define MHASH_NUM_ALGOS 29
+
+static struct mhash_bc_entry mhash_to_hash[MHASH_NUM_ALGOS] = {
+       {"CRC32", "crc32", 0},
+       {"MD5", "md5", 1},
+       {"SHA1", "sha1", 2},
+       {"HAVAL256", "haval256,3", 3},
+       {NULL, NULL, 4},
+       {"RIPEMD160", "ripemd160", 5},
+       {NULL, NULL, 6},
+       {"TIGER", "tiger192,3", 7},
+       {"GOST", "gost", 8},
+       {"CRC32B", "crc32b", 9},
+       {"HAVAL224", "haval224,3", 10},
+       {"HAVAL192", "haval192,3", 11},
+       {"HAVAL160", "haval160,3", 12},
+       {"HAVAL128", "haval128,3", 13},
+       {"TIGER128", "tiger128,3", 14},
+       {"TIGER160", "tiger160,3", 15},
+       {"MD4", "md4", 16},
+       {"SHA256", "sha256", 17},
+       {"ADLER32", "adler32", 18},
+       {"SHA224", "sha224", 19},
+       {"SHA512", "sha512", 20},
+       {"SHA384", "sha384", 21},
+       {"WHIRLPOOL", "whirlpool", 22},
+       {"RIPEMD128", "ripemd128", 23},
+       {"RIPEMD256", "ripemd256", 24},
+       {"RIPEMD320", "ripemd320", 25},
+       {NULL, NULL, 26}, /* support needs to be added for snefru 128 */
+       {"SNEFRU256", "snefru256", 27},
+       {"MD2", "md2", 28}
+};
+#endif
+
 /* Hash Registry Access */
 
 PHP_HASH_API const php_hash_ops *php_hash_fetch_ops(const char *algo, int 
algo_len) /* {{{ */
@@ -74,11 +117,11 @@
 
 /* Userspace */
 
-static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename) /* 
{{{ */
+static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename, 
zend_bool raw_output_default) /* {{{ */
 {
        char *algo, *data, *digest;
        int algo_len, data_len;
-       zend_bool raw_output = 0;
+       zend_bool raw_output = raw_output_default;
        const php_hash_ops *ops;
        void *context;
        php_stream *stream = NULL;
@@ -138,7 +181,7 @@
 Returns lowercase hexits by default */
 PHP_FUNCTION(hash)
 {
-       php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
+       php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 0);
 }
 /* }}} */
 
@@ -147,15 +190,15 @@
 Returns lowercase hexits by default */
 PHP_FUNCTION(hash_file)
 {
-       php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
+       php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1, 0);
 }
 /* }}} */
 
-static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int 
isfilename) /* {{{ */
+static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int 
isfilename, zend_bool raw_output_default) /* {{{ */
 {
        char *algo, *data, *digest, *key, *K;
        int algo_len, data_len, key_len, i;
-       zend_bool raw_output = 0;
+       zend_bool raw_output = raw_output_default;
        const php_hash_ops *ops;
        void *context;
        php_stream *stream = NULL;
@@ -250,7 +293,7 @@
 Returns lowercase hexits by default */
 PHP_FUNCTION(hash_hmac)
 {
-       php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
+       php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 0);
 }
 /* }}} */
 
@@ -259,7 +302,7 @@
 Returns lowercase hexits by default */
 PHP_FUNCTION(hash_hmac_file)
 {
-       php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
+       php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1, 0);
 }
 /* }}} */
 
@@ -562,6 +605,172 @@
 
 #define PHP_HASH_HAVAL_REGISTER(p,b)   php_hash_register_algo("haval" #b "," 
#p , &php_hash_##p##haval##b##_ops);
 
+#ifdef PHP_MHASH_BC
+
+static void mhash_init(INIT_FUNC_ARGS)
+{
+       char buf[128];
+       int len;
+       int algo_number = 0;
+
+       for (algo_number = 0; algo_number < MHASH_NUM_ALGOS; algo_number++) {
+               struct mhash_bc_entry algorithm = mhash_to_hash[algo_number];
+               if (algorithm.mhash_name == NULL) {
+                       continue;
+               }
+
+               len = slprintf(buf, 127, "MHASH_%s", algorithm.mhash_name, 
strlen(algorithm.mhash_name));
+               {
+                       char name[len+1];
+                       memcpy(name, buf, len+1);
+                       REGISTER_LONG_CONSTANT(name, algorithm.value, CONST_CS 
| CONST_PERSISTENT);
+               }
+       }
+}
+
+PHP_FUNCTION(mhash)
+{
+       zval **z_algorithm;
+       int algorithm;
+
+       if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_ex(1, &z_algorithm) == 
FAILURE) {
+               WRONG_PARAM_COUNT;
+       }
+
+       algorithm = Z_LVAL_PP(z_algorithm);
+
+       /* need to conver the first parameter from int to string */
+       if (algorithm >= 0 && algorithm < MHASH_NUM_ALGOS) {
+               struct mhash_bc_entry algorithm_lookup = 
mhash_to_hash[algorithm];
+               if (algorithm_lookup.hash_name) {
+                       ZVAL_STRING(*z_algorithm, algorithm_lookup.hash_name, 
1);
+               }
+       }
+
+       if (ZEND_NUM_ARGS() == 3) {
+               php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 1);
+       } else if (ZEND_NUM_ARGS() == 2) {
+               php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 1);
+       } else {
+               WRONG_PARAM_COUNT;
+       }
+}
+
+PHP_FUNCTION(mhash_get_hash_name)
+{
+       int algorithm;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &algorithm) 
== FAILURE) {
+               return;
+       }
+
+       if (algorithm >= 0 && algorithm  < MHASH_NUM_ALGOS) {
+               struct mhash_bc_entry algorithm_lookup = 
mhash_to_hash[algorithm];
+               if (algorithm_lookup.mhash_name) {
+                       RETURN_STRING(algorithm_lookup.mhash_name, 1);
+               }
+       }
+       RETURN_FALSE;
+}
+
+PHP_FUNCTION(mhash_count)
+{
+       if (zend_parse_parameters_none() == FAILURE) {
+               return;
+       }
+       RETURN_LONG(MHASH_NUM_ALGOS - 1);
+}
+
+PHP_FUNCTION(mhash_get_block_size)
+{
+       int algorithm;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &algorithm) 
== FAILURE) {
+               return;
+       }
+       RETVAL_FALSE;
+
+       if (algorithm >= 0 && algorithm  < MHASH_NUM_ALGOS) {
+               struct mhash_bc_entry algorithm_lookup = 
mhash_to_hash[algorithm];
+               if (algorithm_lookup.mhash_name) {
+                       const php_hash_ops *ops = 
php_hash_fetch_ops(algorithm_lookup.hash_name, 
strlen(algorithm_lookup.hash_name));
+                       if (ops) {
+                               RETVAL_LONG(ops->digest_size);
+                       }
+               }
+       }
+}
+
+#define SALT_SIZE 8
+
+PHP_FUNCTION(mhash_keygen_s2k)
+{
+       int algorithm, bytes;
+       char *password, *salt;
+       int password_len, salt_len;
+       char padded_salt[SALT_SIZE];
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lssl", 
&algorithm, &password, &password_len, &salt, &salt_len, &bytes) == FAILURE) {
+               return;
+       }
+
+       if (bytes <= 0){
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "the byte parameter 
must be greater than 0");
+               RETURN_FALSE;
+       }
+
+       salt_len = MIN(salt_len, SALT_SIZE);
+
+       memcpy(padded_salt, salt, salt_len);
+       if (salt_len < SALT_SIZE) {
+               memset(padded_salt + salt_len, 0, SALT_SIZE - salt_len);
+       }
+       salt_len = SALT_SIZE;
+
+       RETVAL_FALSE;
+       if (algorithm >= 0 && algorithm < MHASH_NUM_ALGOS) {
+               struct mhash_bc_entry algorithm_lookup = 
mhash_to_hash[algorithm];
+               if (algorithm_lookup.mhash_name) {
+                       const php_hash_ops *ops = 
php_hash_fetch_ops(algorithm_lookup.hash_name, 
strlen(algorithm_lookup.hash_name));
+                       if (ops) {
+                               unsigned char null = '\0';
+                               void *context;
+                               char *key, *digest;
+                               int i = 0, j = 0;
+                               int block_size = ops->digest_size;
+                               int times = bytes / block_size;
+                               if (bytes % block_size  != 0) times++;
+
+                               context = emalloc(ops->context_size);
+                               ops->hash_init(context);
+
+                               key = ecalloc(1, times * block_size);
+                               digest = emalloc(ops->digest_size + 1);
+
+                               for (i = 0; i < times; i++) {
+                                       ops->hash_init(context);
+
+                                       for (j=0;j<i;j++) {
+                                               ops->hash_update(context, 
&null, 1);
+                                       }
+                                       ops->hash_update(context, (unsigned 
char *)padded_salt, salt_len);
+                                       ops->hash_update(context, password, 
password_len);
+                                       ops->hash_final(digest, context);
+                                       memcpy( &key[i*block_size], digest, 
block_size);
+                               }
+
+                               RETVAL_STRINGL(key, bytes, 1);
+                               memset(key, 0, bytes);
+                               efree(digest);
+                               efree(context);
+                               efree(key);
+                       }
+               }
+       }
+}
+
+#endif
+
 /* {{{ PHP_MINIT_FUNCTION
  */
 PHP_MINIT_FUNCTION(hash)
@@ -616,6 +825,10 @@
 
        REGISTER_LONG_CONSTANT("HASH_HMAC",             PHP_HASH_HMAC,  
CONST_CS | CONST_PERSISTENT);
 
+#ifdef PHP_MHASH_BC
+       mhash_init(INIT_FUNC_ARGS_PASSTHRU);
+#endif
+
        return SUCCESS;
 }
 /* }}} */
@@ -755,6 +968,38 @@
 ZEND_BEGIN_ARG_INFO(arginfo_hash_algos, 0)
 ZEND_END_ARG_INFO()
 
+/* BC Land */
+#ifdef PHP_MHASH_BC
+static
+ZEND_BEGIN_ARG_INFO(arginfo_mhash_get_block_size, 0)
+       ZEND_ARG_INFO(0, hash)
+ZEND_END_ARG_INFO()
+
+static
+ZEND_BEGIN_ARG_INFO(arginfo_mhash_get_hash_name, 0)
+       ZEND_ARG_INFO(0, hash)
+ZEND_END_ARG_INFO()
+
+static
+ZEND_BEGIN_ARG_INFO(arginfo_mhash_keygen_s2k, 0)
+       ZEND_ARG_INFO(0, hash)
+       ZEND_ARG_INFO(0, input_password)
+       ZEND_ARG_INFO(0, salt)
+       ZEND_ARG_INFO(0, bytes)
+ZEND_END_ARG_INFO()
+
+static
+ZEND_BEGIN_ARG_INFO(arginfo_mhash_count, 0)
+ZEND_END_ARG_INFO()
+
+static
+ZEND_BEGIN_ARG_INFO_EX(arginfo_mhash, 0, 0, 2)
+       ZEND_ARG_INFO(0, hash)
+       ZEND_ARG_INFO(0, data)
+       ZEND_ARG_INFO(0, key)
+ZEND_END_ARG_INFO()
+#endif
+
 /* }}} */
 
 /* {{{ hash_functions[]
@@ -786,6 +1031,14 @@
        PHP_NAMED_FE(sha1_file, php_if_sha1_file,               
arginfo_hash_sha1_file)
 #endif /* PHP_HASH_SHA1_NOT_IN_CORE */
 
+#ifdef PHP_MHASH_BC
+       PHP_FE(mhash_keygen_s2k, arginfo_mhash_keygen_s2k)
+       PHP_FE(mhash_get_block_size, arginfo_mhash_get_block_size)
+       PHP_FE(mhash_get_hash_name, arginfo_mhash_get_hash_name)
+       PHP_FE(mhash_count, arginfo_mhash_count)
+       PHP_FE(mhash, arginfo_mhash)
+#endif
+
        {NULL, NULL, NULL}
 };
 /* }}} */
http://cvs.php.net/viewvc.cgi/php-src/ext/mhash/config.m4?r1=1.15.4.1&r2=1.15.4.1.2.1&diff_format=u
Index: php-src/ext/mhash/config.m4
diff -u php-src/ext/mhash/config.m4:1.15.4.1 
php-src/ext/mhash/config.m4:1.15.4.1.2.1
--- php-src/ext/mhash/config.m4:1.15.4.1        Sat Dec 23 17:58:47 2006
+++ php-src/ext/mhash/config.m4 Thu Jun 26 22:33:16 2008
@@ -1,23 +1,12 @@
 dnl
-dnl $Id: config.m4,v 1.15.4.1 2006/12/23 17:58:47 derick Exp $
+dnl $Id: config.m4,v 1.15.4.1.2.1 2008/06/26 22:33:16 scottmac Exp $
 dnl
 
 PHP_ARG_WITH(mhash, for mhash support,
 [  --with-mhash[=DIR]      Include mhash support])
 
 if test "$PHP_MHASH" != "no"; then
-  for i in $PHP_MHASH /usr/local /usr /opt/mhash; do
-    test -f $i/include/mhash.h && MHASH_DIR=$i && break
-  done
-
-  if test -z "$MHASH_DIR"; then
-    AC_MSG_ERROR(Please reinstall libmhash - I cannot find mhash.h)
-  fi
-
-  PHP_ADD_INCLUDE($MHASH_DIR/include)
-  PHP_ADD_LIBRARY_WITH_PATH(mhash, $MHASH_DIR/$PHP_LIBDIR, MHASH_SHARED_LIBADD)
-
   PHP_NEW_EXTENSION(mhash, mhash.c, $ext_shared)
   PHP_SUBST(MHASH_SHARED_LIBADD)
-  AC_DEFINE(HAVE_LIBMHASH,1,[ ])
+  PHP_ADD_EXTENSION_DEP(mhash, hash, true)
 fi
http://cvs.php.net/viewvc.cgi/php-src/ext/mhash/mhash.c?r1=1.48.2.3.2.5.2.3&r2=1.48.2.3.2.5.2.4&diff_format=u
Index: php-src/ext/mhash/mhash.c
diff -u php-src/ext/mhash/mhash.c:1.48.2.3.2.5.2.3 
php-src/ext/mhash/mhash.c:1.48.2.3.2.5.2.4
--- php-src/ext/mhash/mhash.c:1.48.2.3.2.5.2.3  Mon Mar 10 22:12:34 2008
+++ php-src/ext/mhash/mhash.c   Thu Jun 26 22:33:16 2008
@@ -16,29 +16,19 @@
    |          Nikos Mavroyanopoulos <[EMAIL PROTECTED]> (HMAC, KEYGEN)       |
    +----------------------------------------------------------------------+
  */
-/* $Id: mhash.c,v 1.48.2.3.2.5.2.3 2008/03/10 22:12:34 felipe Exp $ */
+/* $Id: mhash.c,v 1.48.2.3.2.5.2.4 2008/06/26 22:33:16 scottmac Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
 #include "php.h"
-
-#if HAVE_LIBMHASH
-
-#include "fcntl.h"
 #include "php_mhash.h"
-#include "mhash.h"
 #include "php_ini.h"
 #include "php_globals.h"
 #include "ext/standard/info.h"
 
 const zend_function_entry mhash_functions[] = {
-       PHP_FE(mhash_get_block_size, NULL)
-       PHP_FE(mhash_get_hash_name, NULL)
-       PHP_FE(mhash_keygen_s2k, NULL)
-       PHP_FE(mhash_count, NULL)
-       PHP_FE(mhash, NULL)
        {NULL, NULL, NULL}
 };
 
@@ -57,193 +47,19 @@
 ZEND_GET_MODULE(mhash)
 #endif
 
-/* SALTED S2K uses a fixed salt */
-#define SALT_SIZE 8
-
 PHP_MINIT_FUNCTION(mhash)
 {
-       int i, n, l;
-       char *name;
-       char buf[128];
-
-       n = mhash_count() + 1;
-
-       for (i=0; i<n; i++) {
-               if ((name = mhash_get_hash_name(i))) {
-                       l = slprintf(buf, 127, "MHASH_%s", name);
-                       zend_register_long_constant(buf, l + 1, i, 
CONST_PERSISTENT, module_number TSRMLS_CC);
-                       free(name);
-               }
-       }
-
        return SUCCESS;
 }
 
 PHP_MINFO_FUNCTION(mhash)
 {
-       char version[32];
-       
-       snprintf(version, sizeof(version), "%d", MHASH_API_VERSION);
-       
        php_info_print_table_start();
        php_info_print_table_row(2, "MHASH support", "Enabled");
-       php_info_print_table_row(2, "MHASH API Version", version);
+       php_info_print_table_row(2, "MHASH API Version", "Emulated Support");
        php_info_print_table_end();
 }
 
-/* {{{ proto int mhash_count(void)
-   Gets the number of available hashes */
-PHP_FUNCTION(mhash_count)
-{
-       if (zend_parse_parameters_none() == FAILURE) {
-               return;
-       }
-
-       RETURN_LONG(mhash_count());
-}
-
-/* }}} */
-
-/* {{{ proto int mhash_get_block_size(int hash)
-   Gets the block size of hash */
-PHP_FUNCTION(mhash_get_block_size)
-{
-       long hash;
-
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &hash) == 
FAILURE) {
-               return;
-       }
-
-       RETURN_LONG(mhash_get_block_size(hash));
-}
-
-/* }}} */
-
-/* {{{ proto string mhash_get_hash_name(int hash)
-   Gets the name of hash */
-PHP_FUNCTION(mhash_get_hash_name)
-{
-       char *name;
-       long hash;
-
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &hash) == 
FAILURE) {
-               return;
-       }
-
-       name = mhash_get_hash_name(hash);
-       if (name) {
-               RETVAL_STRING(name, 1);
-               free(name);
-       } else {
-               RETVAL_FALSE;
-       }
-}
-
-/* }}} */
-
-/* {{{ proto string mhash(int hash, string data [, string key])
-   Hash data with hash */
-PHP_FUNCTION(mhash)
-{
-       MHASH td;
-       int bsize;
-       unsigned char *hash_data;
-       long hash;
-       int data_len, key_len=0;
-       char *data, *key=NULL;
-       
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls|s", &hash, 
&data, &data_len, &key, &key_len) == FAILURE) {
-               return;
-       }
-       
-       bsize = mhash_get_block_size(hash);
-       
-       if (key_len) {
-               if (mhash_get_hash_pblock(hash) == 0) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "mhash 
initialization failed");
-                       RETURN_FALSE;
-               }
-               td = mhash_hmac_init(hash, key, key_len, 
mhash_get_hash_pblock(hash));
-       } else {
-               td = mhash_init(hash);
-       }
-
-       if (td == MHASH_FAILED) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "mhash 
initialization failed");
-               RETURN_FALSE;
-       }
-
-       mhash(td, data, data_len);
-
-       if (key_len) {
-               hash_data = (unsigned char *) mhash_hmac_end(td);
-       } else {
-               hash_data = (unsigned char *) mhash_end(td);
-       }
-       
-       if (hash_data) {
-               RETVAL_STRINGL(hash_data, bsize, 1);
-               mhash_free(hash_data);
-       } else {
-               RETURN_FALSE;
-       }
-}
-
-/* }}} */
-
-/* {{{ proto string mhash_keygen_s2k(int hash, string input_password, string 
salt, int bytes)
-   Generates a key using hash functions */
-PHP_FUNCTION(mhash_keygen_s2k)
-{
-       KEYGEN keystruct;
-       char salt[SALT_SIZE], *ret;
-       long hash, bytes;
-       char *password, *in_salt;
-       int password_len, salt_len;
-       
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lssl", &hash, 
&password, &password_len, &in_salt, &salt_len, &bytes) == FAILURE) {
-               return;
-       }
-       if (bytes <= 0){
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "the byte parameter 
must be greater than 0");
-               RETURN_FALSE;
-       }
-       
-       salt_len = MIN(salt_len, SALT_SIZE);
-
-       if (salt_len > mhash_get_keygen_salt_size(KEYGEN_S2K_SALTED)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, 
-                       "The specified salt [%d] is more bytes than the 
required by the algorithm [%d]\n", 
-                       salt_len, 
mhash_get_keygen_salt_size(KEYGEN_S2K_SALTED));
-       }
-
-       memcpy(salt, in_salt, salt_len);
-       if (salt_len < SALT_SIZE) {
-               memset(salt + salt_len, 0, SALT_SIZE - salt_len);
-       }       
-       salt_len = SALT_SIZE;
-       
-       keystruct.hash_algorithm[0] = hash;
-       keystruct.hash_algorithm[1] = hash;
-       keystruct.count = 0;
-       keystruct.salt = salt;
-       keystruct.salt_size = salt_len;
-
-       ret = safe_emalloc(1, bytes, 1);
-
-       if (mhash_keygen_ext(KEYGEN_S2K_SALTED, keystruct, ret, bytes, 
password, password_len) >= 0) {
-               ret[bytes] = '\0';
-               RETVAL_STRINGL(ret, bytes, 0);
-       } else {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "mhash key 
generation failed");
-               efree(ret);
-               RETURN_FALSE;
-       }
-}
-/* }}} */
-
-#endif
-
 /*
  * Local variables:
  * tab-width: 4
http://cvs.php.net/viewvc.cgi/php-src/ext/mhash/php_mhash.h?r1=1.12.2.1.2.1.2.1&r2=1.12.2.1.2.1.2.2&diff_format=u
Index: php-src/ext/mhash/php_mhash.h
diff -u php-src/ext/mhash/php_mhash.h:1.12.2.1.2.1.2.1 
php-src/ext/mhash/php_mhash.h:1.12.2.1.2.1.2.2
--- php-src/ext/mhash/php_mhash.h:1.12.2.1.2.1.2.1      Mon Dec 31 07:17:10 2007
+++ php-src/ext/mhash/php_mhash.h       Thu Jun 26 22:33:16 2008
@@ -16,13 +16,11 @@
    |          Nikos Mavroyanopoulos <[EMAIL PROTECTED]> (HMAC, KEYGEN)       |
    +----------------------------------------------------------------------+
  */
-/* $Id: php_mhash.h,v 1.12.2.1.2.1.2.1 2007/12/31 07:17:10 sebastian Exp $ */
+/* $Id: php_mhash.h,v 1.12.2.1.2.1.2.2 2008/06/26 22:33:16 scottmac Exp $ */
 
 #ifndef PHP_MHASH_H
 #define PHP_MHASH_H
 
-#if HAVE_LIBMHASH
-
 #if PHP_API_VERSION < 19990421
 #define  zend_module_entry zend_module_entry
 #include "zend_modules.h"
@@ -34,15 +32,6 @@
 
 PHP_MINIT_FUNCTION(mhash);
 PHP_MINFO_FUNCTION(mhash);
-PHP_FUNCTION(mhash_get_block_size);
-PHP_FUNCTION(mhash_get_hash_name);
-PHP_FUNCTION(mhash_count);
-PHP_FUNCTION(mhash_keygen_s2k);
-PHP_FUNCTION(mhash);
-
-#else
-#define mhash_module_ptr NULL
-#endif
 
 #define phpext_mhash_ptr mhash_module_ptr
 

http://cvs.php.net/viewvc.cgi/php-src/ext/hash/tests/mhash_001.phpt?view=markup&rev=1.1
Index: php-src/ext/hash/tests/mhash_001.phpt
+++ php-src/ext/hash/tests/mhash_001.phpt

http://cvs.php.net/viewvc.cgi/php-src/ext/hash/tests/mhash_002.phpt?view=markup&rev=1.1
Index: php-src/ext/hash/tests/mhash_002.phpt
+++ php-src/ext/hash/tests/mhash_002.phpt

http://cvs.php.net/viewvc.cgi/php-src/ext/hash/tests/mhash_003.phpt?view=markup&rev=1.1
Index: php-src/ext/hash/tests/mhash_003.phpt
+++ php-src/ext/hash/tests/mhash_003.phpt

http://cvs.php.net/viewvc.cgi/php-src/ext/hash/tests/skip_mhash.inc?view=markup&rev=1.1
Index: php-src/ext/hash/tests/skip_mhash.inc
+++ php-src/ext/hash/tests/skip_mhash.inc

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to