mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
MFB: Make the old mhash API a wrapper around hash, this removes a dependency.
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
PHP hash
|
||||
Sara Golemon, Rasmus Lerdorf, Stefan Esser, Michael Wallner
|
||||
Sara Golemon, Rasmus Lerdorf, Stefan Esser, Michael Wallner, Scott MacVicar
|
||||
|
||||
@@ -4,6 +4,14 @@ 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])
|
||||
|
||||
|
||||
283
ext/hash/hash.c
283
ext/hash/hash.c
@@ -13,6 +13,7 @@
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Sara Golemon <pollita@php.net> |
|
||||
| Scott MacVicar <scottmac@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
@@ -35,6 +36,48 @@ HashTable php_hash_hashtable;
|
||||
# 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,12 +117,12 @@ PHP_HASH_API int php_hash_copy(const void *ops, void *orig_context, void *dest_c
|
||||
|
||||
/* 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_uchar data_type = IS_STRING;
|
||||
zend_bool raw_output = 0;
|
||||
zend_bool raw_output = raw_output_default;
|
||||
const php_hash_ops *ops;
|
||||
void *context;
|
||||
php_stream *stream = NULL;
|
||||
@@ -175,7 +218,7 @@ Generate a hash of a given input string
|
||||
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);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@@ -184,16 +227,16 @@ Generate a hash of a given file
|
||||
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_uchar data_type = IS_STRING, key_type = IS_STRING;
|
||||
zend_bool raw_output = 0;
|
||||
zend_bool raw_output = raw_output_default;
|
||||
const php_hash_ops *ops;
|
||||
void *context;
|
||||
php_stream *stream = NULL;
|
||||
@@ -338,7 +381,7 @@ Generate a hash of a given input string with a key using HMAC
|
||||
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);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@@ -347,7 +390,7 @@ Generate a hash of a given file with a key using HMAC
|
||||
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);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@@ -731,6 +774,186 @@ static void php_hash_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* {{{ proto binary mhash(int hash, binary data [, binary key]) U
|
||||
Hash data with hash */
|
||||
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;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string mhash_get_hash_name(int hash) U
|
||||
Gets the name of hash */
|
||||
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;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto int mhash_count(void) U
|
||||
Gets the number of available hashes */
|
||||
PHP_FUNCTION(mhash_count)
|
||||
{
|
||||
if (zend_parse_parameters_none() == FAILURE) {
|
||||
return;
|
||||
}
|
||||
RETURN_LONG(MHASH_NUM_ALGOS - 1);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto int mhash_get_block_size(int hash) U
|
||||
Gets the block size of hash */
|
||||
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
|
||||
|
||||
/* {{{ proto binary mhash_keygen_s2k(int hash, binary input_password, binary salt, int bytes)
|
||||
Generates a key using hash functions */
|
||||
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
|
||||
|
||||
#define PHP_HASH_HAVAL_REGISTER(p,b) php_hash_register_algo("haval" #b "," #p , &php_hash_##p##haval##b##_ops);
|
||||
|
||||
/* {{{ PHP_MINIT_FUNCTION
|
||||
@@ -787,6 +1010,10 @@ PHP_MINIT_FUNCTION(hash)
|
||||
|
||||
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;
|
||||
}
|
||||
/* }}} */
|
||||
@@ -908,6 +1135,38 @@ static
|
||||
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
|
||||
|
||||
# define PHP_HASH_FE(n) PHP_FE(n,arginfo_##n)
|
||||
#else
|
||||
# define PHP_HASH_FE(n) PHP_FE(n,NULL)
|
||||
@@ -932,6 +1191,14 @@ const zend_function_entry hash_functions[] = {
|
||||
|
||||
PHP_HASH_FE(hash_algos)
|
||||
|
||||
#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}
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
73
ext/hash/tests/mhash_001.phpt
Normal file
73
ext/hash/tests/mhash_001.phpt
Normal file
@@ -0,0 +1,73 @@
|
||||
--TEST--
|
||||
mhash() test
|
||||
--INI--
|
||||
magic_quotes_runtime=0
|
||||
--SKIPIF--
|
||||
<?php
|
||||
include "skip_mhash.inc";
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$supported_hash_al = array(
|
||||
"MHASH_MD5" => "2d9bdb91f94e96d9c4e2ae532acc936a",
|
||||
"MHASH_SHA1" => "2f9341e55a9083edf5497bf83ba3db812a7de0a3",
|
||||
"MHASH_HAVAL256" => "b255feff01ad641b27358dc7909bc695a1fca53bddfdfaf19020b275928793af",
|
||||
"MHASH_HAVAL192" => "4ce837de481e1e30092ab2c610057094c988dfd7db1e01cd",
|
||||
"MHASH_HAVAL224" => "5362d1856752bf2c139bb2d6fdd772b9c515c8ce5ec82695264b85e1",
|
||||
"MHASH_HAVAL160" => "c6b36f87750b18576981bc17b4f22271947bf9cb",
|
||||
"MHASH_RIPEMD160" => "6c47435aa1d359c4b7c6af46349f0c3e1258583d",
|
||||
"MHASH_GOST" => "101b0a2552cebdf5137cadf15147f21e55b6432935bb9c2c03c7e28d188b2d9e",
|
||||
"MHASH_TIGER" => "fdb9019a79c33a95677e2097abae91eb0de00b3054bb5c39",
|
||||
"MHASH_CRC32" => "83041db8",
|
||||
"MHASH_CRC32B" => "a4b75adf"
|
||||
);
|
||||
|
||||
$data = "This is the test of the mhash extension...";
|
||||
|
||||
foreach ($supported_hash_al as $hash=>$wanted) {
|
||||
$result = mhash(constant($hash), $data);
|
||||
if (bin2hex($result)==$wanted) {
|
||||
echo "$hash\nok\n";
|
||||
} else {
|
||||
echo "$hash: ";
|
||||
var_dump($wanted);
|
||||
echo "$hash: ";
|
||||
var_dump($result);
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
MHASH_MD5
|
||||
ok
|
||||
|
||||
MHASH_SHA1
|
||||
ok
|
||||
|
||||
MHASH_HAVAL256
|
||||
ok
|
||||
|
||||
MHASH_HAVAL192
|
||||
ok
|
||||
|
||||
MHASH_HAVAL224
|
||||
ok
|
||||
|
||||
MHASH_HAVAL160
|
||||
ok
|
||||
|
||||
MHASH_RIPEMD160
|
||||
ok
|
||||
|
||||
MHASH_GOST
|
||||
ok
|
||||
|
||||
MHASH_TIGER
|
||||
ok
|
||||
|
||||
MHASH_CRC32
|
||||
ok
|
||||
|
||||
MHASH_CRC32B
|
||||
ok
|
||||
@@ -2,7 +2,7 @@
|
||||
mhash_get_block_size() & mhash_get_hash_name() test
|
||||
--SKIPIF--
|
||||
<?php
|
||||
include "skip.inc";
|
||||
include "skip_mhash.inc";
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
71
ext/hash/tests/mhash_003.phpt
Normal file
71
ext/hash/tests/mhash_003.phpt
Normal file
@@ -0,0 +1,71 @@
|
||||
--TEST--
|
||||
mhash_keygen_s2k() test
|
||||
--SKIPIF--
|
||||
<?php
|
||||
include "skip_mhash.inc";
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$supported_hash_al = array(
|
||||
"MHASH_MD5" => b"8690154eaf9432cde9347aa15094b9c046eb06e6a0940c5479aa7a6367ae68b5e0e0745e5709fede2d9fe9739d9aad413759faa73acced821077b4ddb2788064e371eb53b3a9d55ed2839aab2655c82cfedbe83a208461c799d9d77ae481061c81539b01",
|
||||
"MHASH_SHA1" => b"dd315c70061d07455d53c2fb0b08df0c61aa665c1ab1a701fa10955423248ba832a5ade406b39b78630aba3d1688e622494a0eae279d4ece9ad4bdf76e878fcb084a33c9153c2b48131d30a75b00a7c05b91f1ffeabf59bb1271c4d8a11990b84baf6d49",
|
||||
"MHASH_HAVAL256" => b"0ede47009f87d5e9a24ecf5077d60c483657a5d98404ab2bb780f5872c90caf61c0d67645a848e55fee107296f4169c95b4e61f0aeeefab2648554c1171fb0a2fc32aa5aeed3d5c155d334367d4959622cdadefe43ae17bd1a75f9d4fef77bf192be5b78",
|
||||
"MHASH_HAVAL224" => b"5c4aff3d825ad608f608c8eae779ee3868610bc60a98f3d770b311a6677c797fc2dadcab71dde0c0191e068397ab297f0de5cbbc6cbcd0c78ca8470c42401f6b77e81dc2ba8d51930ff982760335324fb850ac2d30b73514004c096d60472d320e0ec349",
|
||||
"MHASH_HAVAL192" => b"22e0c27126023c852ef94107bb2f1ee132b064178b9dcbfb1c32e658760b8f70bdc5b1c52599031628c2433bee2b0870ab7a38aeb21215134ec1088975b9a96487642971ef9eb3d987baf9765fd9e6d64d494e1719aa84afe7e0a0784c74979ebab1c787",
|
||||
"MHASH_HAVAL160" => b"d6e5f0ef07f3facced646eedb6364758ecde6dc6fb061e00a496f5ceb723f78ea135884d9682226ded69c11d8431240ef97cad583c4f29593bbf3dd3cab0b8792eb3d86022ca6002ebd0d9b4429909d4af85bed2b5a96b3e47b9b8cac919c1177ec40d7e",
|
||||
"MHASH_RIPEMD160" => b"e4d5db469af29f78e2b90dc735c9cf020a1d5b19a6674458677794d4dca144d426c562aff98d8e866a8a924299ebf6b0ea9a1637f987a1fb5de9b647edc35b1447605e1babc3084be7a003931117eb33432d4142e225df044b033f3ff64bb4a18682a4f9",
|
||||
"MHASH_GOST" => b"c044f669bd7e8643953d77c682fd179242d9df157dadf873be4d9601e4647c018234689359e7220ab0492a6240d184c478634073dea87f79be7f86fd4e2564f7d709b68a46440a121250e00fc7d57d45a9c07ee23a704ff4148c0dad7077ec527b194d87",
|
||||
"MHASH_TIGER" => b"67eac97b9dca0a47b1f6262f330264e4ce1c233760fe3255f642512fd3127929baccf1e758236b2768a4c2c0c06e118b19e40e2f04a5f745820fb8a99bdbc00698702a4d3120171856c4c94bda79ba1b4f60d509d7f8954da818a29797368dd47c1122aa",
|
||||
"MHASH_CRC32" => b"481c40148c26185f9a59ef18e86f51c5d2d0315b46711d22ae08c1ccdd669fe956c817380815e3a545f6ee453c9da48d1d994dbc3ac8ba85a572108412f06b2a16b1489cda75b118e82f7d9bdfdb68336957bbf19e4a3f76750d6985a53dd557229dfcf3",
|
||||
"MHASH_CRC32B" => b"b56cab65a63e7dfb2aa95d7fb646d79b36138a6243cdcb8f2e0949af0f966a9ccea530d0db0d1f3c98c62e5179e796beb68d7469fdb07862d8247d830bf598c8b49309d7cfacc88c44c5444b8513e931754cf0dd36a7a160f7e6c98f907c4563f1047fb0"
|
||||
);
|
||||
|
||||
foreach ($supported_hash_al as $hash=>$wanted) {
|
||||
$passwd = str_repeat($hash, 10);
|
||||
$salt = str_repeat($hash, 2);
|
||||
$result = mhash_keygen_s2k(constant($hash), (binary)$passwd, (binary)$salt, 100);
|
||||
if (!strcmp(bin2hex($result), $wanted)) {
|
||||
echo "$hash\nok\n";
|
||||
} else {
|
||||
echo "$hash: ";
|
||||
var_dump($wanted);
|
||||
echo "$hash: ";
|
||||
var_dump(bin2hex($result));
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
MHASH_MD5
|
||||
ok
|
||||
|
||||
MHASH_SHA1
|
||||
ok
|
||||
|
||||
MHASH_HAVAL256
|
||||
ok
|
||||
|
||||
MHASH_HAVAL224
|
||||
ok
|
||||
|
||||
MHASH_HAVAL192
|
||||
ok
|
||||
|
||||
MHASH_HAVAL160
|
||||
ok
|
||||
|
||||
MHASH_RIPEMD160
|
||||
ok
|
||||
|
||||
MHASH_GOST
|
||||
ok
|
||||
|
||||
MHASH_TIGER
|
||||
ok
|
||||
|
||||
MHASH_CRC32
|
||||
ok
|
||||
|
||||
MHASH_CRC32B
|
||||
ok
|
||||
@@ -6,32 +6,7 @@ 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_MHASH_MISSING_PROTOS=
|
||||
AC_MSG_CHECKING(for missing protos)
|
||||
AC_EGREP_HEADER(mhash_get_hash_name_static, [$MHASH_DIR/include/mhash.h], [
|
||||
AC_DEFINE([HAVE_MHASH_GET_HASH_NAME_STATIC_PROTO], 1, [ ])
|
||||
], [
|
||||
PHP_MHASH_MISSING_PROTOS="mhash_get_hash_name_static"
|
||||
])
|
||||
AC_EGREP_HEADER(mhash_get_keygen_name_static, [$MHASH_DIR/include/mhash.h], [
|
||||
AC_DEFINE([HAVE_MHASH_GET_KEYGEN_NAME_STATIC_PROTO], 1, [ ])
|
||||
], [
|
||||
PHP_MHASH_MISSING_PROTOS="mhash_get_keygen_name_static $PHP_MHASH_MISSING_PROTOS"
|
||||
])
|
||||
AC_MSG_RESULT([$PHP_MHASH_MISSING_PROTOS])
|
||||
|
||||
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_NEW_EXTENSION(mhash, mhash.c, $ext_shared)
|
||||
PHP_SUBST(MHASH_SHARED_LIBADD)
|
||||
PHP_ADD_EXTENSION_DEP(mhash, hash, true)
|
||||
fi
|
||||
|
||||
@@ -24,27 +24,12 @@
|
||||
|
||||
#include "php.h"
|
||||
|
||||
#if HAVE_LIBMHASH
|
||||
|
||||
#include "fcntl.h"
|
||||
#include "php_mhash.h"
|
||||
#include "php_ini.h"
|
||||
#include "php_globals.h"
|
||||
#include "ext/standard/info.h"
|
||||
|
||||
const zend_function_entry mhash_functions[] = {
|
||||
PHP_FE(mhash_count, NULL)
|
||||
PHP_FE(mhash_get_block_size, NULL)
|
||||
PHP_FE(mhash_get_hash_name, NULL)
|
||||
PHP_FE(mhash_keygen_count, NULL)
|
||||
PHP_FE(mhash_get_keygen_name, NULL)
|
||||
PHP_FE(mhash_keygen_uses_hash, NULL)
|
||||
PHP_FE(mhash_keygen_uses_salt, NULL)
|
||||
PHP_FE(mhash_get_keygen_salt_size, NULL)
|
||||
PHP_FE(mhash_keygen_uses_count, NULL)
|
||||
PHP_FE(mhash, NULL)
|
||||
PHP_FE(mhash_keygen, NULL)
|
||||
PHP_FE(mhash_keygen_s2k, NULL)
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -63,131 +48,9 @@ zend_module_entry mhash_module_entry = {
|
||||
ZEND_GET_MODULE(mhash)
|
||||
#endif
|
||||
|
||||
#define NO_ARGS() (SUCCESS == zend_parse_parameters_none())
|
||||
|
||||
#ifndef HAVE_MHASH_GET_HASH_NAME_STATIC_PROTO
|
||||
extern const char *mhash_get_hash_name_static(hashid hash);
|
||||
#endif
|
||||
#ifndef HAVE_MHASH_GET_KEYGEN_NAME_STATIC_PROTO
|
||||
extern const char *mhash_get_keygen_name_static(hashid type);
|
||||
#endif
|
||||
|
||||
/* {{{ int php_mhash */
|
||||
int php_mhash(hashid hash, const char *input_str, int input_len, const char *key_str, int key_len, char **enc, int *len TSRMLS_DC)
|
||||
{
|
||||
size_t pbsize;
|
||||
char *result;
|
||||
MHASH mh;
|
||||
|
||||
if (key_len) {
|
||||
if (!(pbsize = mhash_get_hash_pblock(hash))) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "HMAC incompatible hash algorithm");
|
||||
return FAILURE;
|
||||
}
|
||||
mh = mhash_hmac_init(hash, (char *) key_str, key_len, pbsize);
|
||||
} else {
|
||||
mh = mhash_init(hash);
|
||||
}
|
||||
|
||||
if (mh == MHASH_FAILED) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "mhash initialization failed");
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
mhash(mh, input_str, input_len);
|
||||
|
||||
if (key_len) {
|
||||
result = mhash_hmac_end(mh);
|
||||
} else {
|
||||
result = mhash_end(mh);
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
*len = mhash_get_block_size(hash);
|
||||
*enc = estrndup(result, *len);
|
||||
|
||||
mhash_free(result);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ int php_mhash_keygen */
|
||||
int php_mhash_keygen(keygenid type, hashid hash1, hashid hash2, const char *pass_str, int pass_len, const char *salt_str, size_t salt_len, char **key, int *len, int max_len, int max_count TSRMLS_DC)
|
||||
{
|
||||
KEYGEN keygen;
|
||||
|
||||
if (type < 0 || type > mhash_keygen_count()) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unknown keygen type %d", type);
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
memset(&keygen, 0, sizeof(keygen));
|
||||
|
||||
if (mhash_keygen_uses_hash_algorithm(type)) {
|
||||
if (hash1 == -1) {
|
||||
hash1 = hash2;
|
||||
}
|
||||
if (hash2 == -1) {
|
||||
hash2 = hash1;
|
||||
}
|
||||
keygen.hash_algorithm[0] = hash1;
|
||||
keygen.hash_algorithm[1] = hash2;
|
||||
}
|
||||
|
||||
if (mhash_keygen_uses_salt(type)) {
|
||||
if (salt_len <= 0) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s requires a salt", mhash_get_keygen_name_static(type));
|
||||
return FAILURE;
|
||||
}
|
||||
keygen.salt = (void *) salt_str;
|
||||
keygen.salt_size = salt_len;
|
||||
}
|
||||
|
||||
keygen.count = max_count;
|
||||
|
||||
if (max_len > 0) {
|
||||
*len = max_len;
|
||||
} else {
|
||||
*len = 128;
|
||||
}
|
||||
|
||||
*key = safe_emalloc(1, *len, 1);
|
||||
|
||||
if (mhash_keygen_ext(type, keygen, *key, *len, (void *) pass_str, pass_len) < 0) {
|
||||
efree(*key);
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "key generation failed");
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
(*key)[*len] = '\0';
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ PHP_MINIT */
|
||||
PHP_MINIT_FUNCTION(mhash)
|
||||
{
|
||||
int i, n, l;
|
||||
const char *name;
|
||||
char buf[128];
|
||||
|
||||
for (i = 0, n = mhash_count() + 1; i < n; ++i) {
|
||||
if ((name = (const char *) mhash_get_hash_name_static(i))) {
|
||||
l = snprintf(buf, sizeof(buf), "MHASH_%s", name);
|
||||
zend_register_long_constant(buf, l + 1, i, CONST_PERSISTENT, module_number TSRMLS_CC);
|
||||
}
|
||||
}
|
||||
for (i = 0, n = mhash_keygen_count() + 1; i < n; ++i) {
|
||||
if ((name = (const char *) mhash_get_keygen_name_static(i))) {
|
||||
l = snprintf(buf, sizeof(buf), "MHASH_KEYGEN_%s", name);
|
||||
zend_register_long_constant(buf, l + 1, i, CONST_PERSISTENT, module_number TSRMLS_CC);
|
||||
}
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
@@ -195,208 +58,13 @@ PHP_MINIT_FUNCTION(mhash)
|
||||
/* {{{ PHP_MINFO */
|
||||
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");
|
||||
php_info_print_table_end();
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto int mhash_count(void) U
|
||||
Gets the number of available hashes */
|
||||
PHP_FUNCTION(mhash_count)
|
||||
{
|
||||
if (!NO_ARGS()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RETURN_LONG(mhash_count());
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto int mhash_get_block_size(int hash) U
|
||||
Gets the block size of hash */
|
||||
PHP_FUNCTION(mhash_get_block_size)
|
||||
{
|
||||
long hash;
|
||||
|
||||
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &hash)) {
|
||||
return;
|
||||
}
|
||||
|
||||
RETURN_LONG(mhash_get_block_size(hash));
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string mhash_get_hash_name(int hash) U
|
||||
Gets the name of hash */
|
||||
PHP_FUNCTION(mhash_get_hash_name)
|
||||
{
|
||||
const char *name;
|
||||
long hash;
|
||||
|
||||
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &hash)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((name = (const char *) mhash_get_hash_name_static(hash))) {
|
||||
RETVAL_ASCII_STRING((char *) name, 1);
|
||||
} else {
|
||||
RETVAL_FALSE;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto int mhash_keygen_count() U
|
||||
Get the number of available keygen algorithms */
|
||||
PHP_FUNCTION(mhash_keygen_count)
|
||||
{
|
||||
if (!NO_ARGS()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RETURN_LONG(mhash_keygen_count());
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string mhash_get_keygen_name(int keygen) U
|
||||
Get the name of the keygen algorithm */
|
||||
PHP_FUNCTION(mhash_get_keygen_name)
|
||||
{
|
||||
const char *name;
|
||||
long keygen;
|
||||
|
||||
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &keygen)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((name = (const char *) mhash_get_keygen_name_static(keygen))) {
|
||||
RETVAL_ASCII_STRING((char *) name, 1);
|
||||
} else {
|
||||
RETVAL_FALSE;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool mhash_keygen_uses_hash(int keygen) U
|
||||
Whether the keygen algorithm uses a hash algorithm */
|
||||
PHP_FUNCTION(mhash_keygen_uses_hash)
|
||||
{
|
||||
long keygen;
|
||||
|
||||
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &keygen)) {
|
||||
return;
|
||||
}
|
||||
|
||||
RETURN_BOOL(mhash_keygen_uses_hash_algorithm(keygen));
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool mhash_keygen_uses_count(int keygen) U
|
||||
Whether the keygen algorithm uses the bytes_count parameter */
|
||||
PHP_FUNCTION(mhash_keygen_uses_count)
|
||||
{
|
||||
long keygen;
|
||||
|
||||
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &keygen)) {
|
||||
return;
|
||||
}
|
||||
|
||||
RETURN_BOOL(mhash_keygen_uses_count(keygen));
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool mhash_keygen_uses_salt(int keygen) U
|
||||
Whether the keygen algorithm requires a salt */
|
||||
PHP_FUNCTION(mhash_keygen_uses_salt)
|
||||
{
|
||||
long keygen;
|
||||
|
||||
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &keygen)) {
|
||||
return;
|
||||
}
|
||||
|
||||
RETURN_BOOL(mhash_keygen_uses_salt(keygen));
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool mhash_get_keygen_salt_size(int keygen) U
|
||||
Get the required size of the salt for the keygen algorithm */
|
||||
PHP_FUNCTION(mhash_get_keygen_salt_size)
|
||||
{
|
||||
long keygen;
|
||||
|
||||
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &keygen)) {
|
||||
return;
|
||||
}
|
||||
|
||||
RETURN_LONG(mhash_get_keygen_salt_size(keygen));
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto binary mhash(int hash, binary data [, binary key]) U
|
||||
Hash data with hash */
|
||||
PHP_FUNCTION(mhash)
|
||||
{
|
||||
long hash;
|
||||
char *result, *data, *key = NULL;
|
||||
int result_len, data_len, key_len = 0;
|
||||
|
||||
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lS|S", &hash, &data, &data_len, &key, &key_len)) {
|
||||
return;
|
||||
}
|
||||
if (SUCCESS != php_mhash(hash, data, data_len, key, key_len, &result, &result_len TSRMLS_CC)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_STRINGL(result, result_len, 0);
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto binary mhash_keygen(int type, int hash1, int hash2, binary password[, binary salt[, int max_key_size = 128[, int bytes_count = 0]]) U
|
||||
Generate a key */
|
||||
PHP_FUNCTION(mhash_keygen)
|
||||
{
|
||||
long hash1, hash2, type, max_len = 0, bytes_count = 0;
|
||||
char *result_str, *pass_str, *salt_str = NULL;
|
||||
int result_len, pass_len, salt_len = 0;
|
||||
|
||||
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllS|Sll", &type, &hash1, &hash2, &pass_str, &pass_len, &salt_str, &salt_len, &max_len, &bytes_count)) {
|
||||
return;
|
||||
}
|
||||
if (SUCCESS != php_mhash_keygen(type, hash1, hash2, pass_str, pass_len, salt_str, salt_len, &result_str, &result_len, max_len, bytes_count TSRMLS_CC)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_STRINGL(result_str, result_len, 0);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto binary mhash_keygen_s2k(int hash, binary input_password, binary salt, int bytes)
|
||||
Generates a key using hash functions */
|
||||
PHP_FUNCTION(mhash_keygen_s2k)
|
||||
{
|
||||
long hash, max_len = 0;
|
||||
char *result_str, *pass_str, *salt_str = NULL;
|
||||
int result_len, pass_len, salt_len = 0;
|
||||
|
||||
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lSSl", &hash, &pass_str, &pass_len, &salt_str, &salt_len, &max_len)) {
|
||||
return;
|
||||
}
|
||||
if (SUCCESS != php_mhash_keygen(KEYGEN_S2K_SALTED, hash, hash, pass_str, pass_len, salt_str, salt_len, &result_str, &result_len, max_len, 0 TSRMLS_CC)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_STRINGL(result_str, result_len, 0);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
# Microsoft Developer Studio Project File - Name="mhash" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=mhash - Win32 Release_TS
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "mhash.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "mhash.mak" CFG="mhash - Win32 Release_TS"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "mhash - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "mhash - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "mhash - Win32 Release_TS"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release_TS"
|
||||
# PROP BASE Intermediate_Dir "Release_TS"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "..\..\Release_TS"
|
||||
# PROP Intermediate_Dir "Release_TS"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "..\..\..\Zend" /I "..\..\..\TSRM" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL_MHASH" /D ZTS=1 /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /I "..\..\win32" /D "WIN32" /D "MHASH_EXPORTS" /D "COMPILE_DL_MHASH" /D HAVE_LIBMHASH=1 /D ZEND_DEBUG=0 /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ZEND_WIN32" /D "PHP_WIN32" /D ZTS=1 /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x406 /d "NDEBUG"
|
||||
# ADD RSC /l 0x406 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php5ts.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 php5ts.lib libmhash.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_mhash.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "mhash - Win32 Debug_TS"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Debug_TS"
|
||||
# PROP BASE Intermediate_Dir "Debug_TS"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "..\..\Debug_TS"
|
||||
# PROP Intermediate_Dir "Debug_TS"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL_MHASH" /D ZTS=1 /YX /FD /c
|
||||
# ADD CPP /nologo /MDd /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /I "..\..\win32" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MHASH_EXPORTS" /D "COMPILE_DL_MHASH" /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_MHASH=1 /D ZTS=1 /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x406 /d "NDEBUG"
|
||||
# ADD RSC /l 0x406 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php5ts_debug.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 php5ts_debug.lib libmhash.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Debug_TS/php_mhash.dll" /libpath:"..\..\Debug_TS"
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "mhash - Win32 Release_TS"
|
||||
# Name "mhash - Win32 Debug_TS"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\mhash.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\php_mhash.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
@@ -21,40 +21,11 @@
|
||||
#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"
|
||||
#include "internal_functions.h"
|
||||
#endif
|
||||
|
||||
#include "mhash.h"
|
||||
|
||||
extern zend_module_entry mhash_module_entry;
|
||||
#define mhash_module_ptr &mhash_module_entry
|
||||
|
||||
int php_mhash(hashid hash, const char *input_str, int input_len, const char *key_str, int key_len, char **enc, int *len TSRMLS_DC);
|
||||
int php_mhash_keygen(keygenid type, hashid hash1, hashid hash2, const char *pass_str, int pass_len, const char *salt_str, size_t salt_len, char **key, int *len, int max_len, int max_count TSRMLS_DC);
|
||||
|
||||
PHP_MINIT_FUNCTION(mhash);
|
||||
PHP_MINFO_FUNCTION(mhash);
|
||||
PHP_FUNCTION(mhash_count);
|
||||
PHP_FUNCTION(mhash_get_block_size);
|
||||
PHP_FUNCTION(mhash_get_hash_name);
|
||||
PHP_FUNCTION(mhash_keygen_count);
|
||||
PHP_FUNCTION(mhash_get_keygen_name);
|
||||
PHP_FUNCTION(mhash_keygen_uses_hash);
|
||||
PHP_FUNCTION(mhash_keygen_uses_salt);
|
||||
PHP_FUNCTION(mhash_get_keygen_salt_size);
|
||||
PHP_FUNCTION(mhash_keygen_uses_count);
|
||||
PHP_FUNCTION(mhash);
|
||||
PHP_FUNCTION(mhash_keygen);
|
||||
PHP_FUNCTION(mhash_keygen_s2k);
|
||||
|
||||
#else
|
||||
#define mhash_module_ptr NULL
|
||||
#endif
|
||||
|
||||
#define phpext_mhash_ptr mhash_module_ptr
|
||||
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
--TEST--
|
||||
mhash() test
|
||||
--SKIPIF--
|
||||
<?php
|
||||
include "skip.inc";
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$supported_hash_al = array(
|
||||
"MHASH_MD5" => "-›Û‘ùN–ÙÄâ®S*Ì“j",
|
||||
"MHASH_SHA1" => "/“AåZ<C3A5>ƒíõI{ø;£Û<C2A3>*}à£",
|
||||
"MHASH_HAVAL256" => "²Uþÿd'5<>Ç<EFBFBD>›Æ•¡ü¥;Ýýúñ<C3BA> ²u’‡“¯",
|
||||
"MHASH_HAVAL192" => "Lè7ÞH0 *²Æp”Ɉß×ÛÍ",
|
||||
"MHASH_HAVAL224" => "SbÑ…gR¿,›²Öý×r¹ÅÈÎ^È&•&K…á",
|
||||
"MHASH_HAVAL160" => "Ƴo‡uWi<57>¼´ò\"q”{ùË",
|
||||
"MHASH_RIPEMD160" => "lGCZ¡ÓYķƯF4Ÿ\x0C>XX=",
|
||||
"MHASH_GOST" => "\x0A%Rνõ|ñQGòU¶C)5»œ,Çâ<C387>‹-ž",
|
||||
"MHASH_TIGER" => "ý¹šyÃ:•g~ —«®‘ë
|
||||
à0T»\9",
|
||||
"MHASH_CRC32" => "ƒ¸",
|
||||
"MHASH_CRC32B" => "¤·Zß"
|
||||
);
|
||||
|
||||
$data = "This is the test of the mhash extension...";
|
||||
|
||||
foreach ($supported_hash_al as $hash=>$wanted) {
|
||||
$result = mhash(constant($hash), $data);
|
||||
if ($result==$wanted) {
|
||||
echo "$hash\nok\n";
|
||||
} else {
|
||||
echo "$hash: ";
|
||||
var_dump($wanted);
|
||||
echo "$hash: ";
|
||||
var_dump($result);
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
MHASH_MD5
|
||||
ok
|
||||
|
||||
MHASH_SHA1
|
||||
ok
|
||||
|
||||
MHASH_HAVAL256
|
||||
ok
|
||||
|
||||
MHASH_HAVAL192
|
||||
ok
|
||||
|
||||
MHASH_HAVAL224
|
||||
ok
|
||||
|
||||
MHASH_HAVAL160
|
||||
ok
|
||||
|
||||
MHASH_RIPEMD160
|
||||
ok
|
||||
|
||||
MHASH_GOST
|
||||
ok
|
||||
|
||||
MHASH_TIGER
|
||||
ok
|
||||
|
||||
MHASH_CRC32
|
||||
ok
|
||||
|
||||
MHASH_CRC32B
|
||||
ok
|
||||
@@ -1,73 +0,0 @@
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
<EFBFBD>
|
||||
Reference in New Issue
Block a user