summaryrefslogtreecommitdiff
path: root/ext/hash
diff options
context:
space:
mode:
authorMichael Maclean <mgdm@php.net>2010-03-23 22:21:39 +0000
committerMichael Maclean <mgdm@php.net>2010-03-23 22:21:39 +0000
commitd05ce2574605ced3ef8a15ca15eb6f4ac536f745 (patch)
treec44a8be68714a51f06892547c3608b4f74e08e5f /ext/hash
parent880bde60a2e507472cf860c8dfa99a54145b8fd0 (diff)
downloadphp-git-d05ce2574605ced3ef8a15ca15eb6f4ac536f745.tar.gz
Add FNV-1 support to ext/hash
Diffstat (limited to 'ext/hash')
-rw-r--r--ext/hash/config.m44
-rw-r--r--ext/hash/hash.c8
-rw-r--r--ext/hash/hash_fnv.c229
-rw-r--r--ext/hash/php_hash.h2
-rw-r--r--ext/hash/php_hash_fnv.h79
-rw-r--r--ext/hash/tests/fnv132.phpt202
-rw-r--r--ext/hash/tests/fnv164.phpt202
7 files changed, 723 insertions, 3 deletions
diff --git a/ext/hash/config.m4 b/ext/hash/config.m4
index d8a26fd11f..61e9394f6c 100644
--- a/ext/hash/config.m4
+++ b/ext/hash/config.m4
@@ -27,11 +27,11 @@ if test "$PHP_HASH" != "no"; then
EXT_HASH_SOURCES="hash.c hash_md.c hash_sha.c hash_ripemd.c hash_haval.c \
hash_tiger.c hash_gost.c hash_snefru.c hash_whirlpool.c hash_adler32.c \
- hash_crc32.c hash_salsa.c"
+ hash_crc32.c hash_salsa.c hash_fnv.c"
EXT_HASH_HEADERS="php_hash.h php_hash_md.h php_hash_sha.h php_hash_ripemd.h \
php_hash_haval.h php_hash_tiger.h php_hash_gost.h php_hash_snefru.h \
php_hash_whirlpool.h php_hash_adler32.h php_hash_crc32.h php_hash_salsa.h \
- php_hash_types.h"
+ php_hash_fnv.h php_hash_types.h"
PHP_NEW_EXTENSION(hash, $EXT_HASH_SOURCES, $ext_shared)
ifdef([PHP_INSTALL_HEADERS], [
diff --git a/ext/hash/hash.c b/ext/hash/hash.c
index 73b0931a01..75acc81599 100644
--- a/ext/hash/hash.c
+++ b/ext/hash/hash.c
@@ -74,7 +74,11 @@ static struct mhash_bc_entry mhash_to_hash[MHASH_NUM_ALGOS] = {
{"RIPEMD320", "ripemd320", 25},
{NULL, NULL, 26}, /* support needs to be added for snefru 128 */
{"SNEFRU256", "snefru256", 27},
- {"MD2", "md2", 28}
+ {"MD2", "md2", 28},
+ {"FNV132", "fnv132", 29},
+ {"FNV1a32", "fnv1a32", 30},
+ {"FNV164", "fnv164", 31},
+ {"FNV1a64", "fnv1a64", 32},
};
#endif
@@ -841,6 +845,8 @@ PHP_MINIT_FUNCTION(hash)
php_hash_register_algo("crc32b", &php_hash_crc32b_ops);
php_hash_register_algo("salsa10", &php_hash_salsa10_ops);
php_hash_register_algo("salsa20", &php_hash_salsa20_ops);
+ php_hash_register_algo("fnv132", &php_hash_fnv132_ops);
+ php_hash_register_algo("fnv164", &php_hash_fnv164_ops);
PHP_HASH_HAVAL_REGISTER(3,128);
PHP_HASH_HAVAL_REGISTER(3,160);
diff --git a/ext/hash/hash_fnv.c b/ext/hash/hash_fnv.c
new file mode 100644
index 0000000000..dea67abdc0
--- /dev/null
+++ b/ext/hash/hash_fnv.c
@@ -0,0 +1,229 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2010 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Michael Maclean <mgdm@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+/* Based on the public domain algorithm found at
+ http://www.isthe.com/chongo/tech/comp/fnv/index.html */
+
+#include "php_hash.h"
+#include "php_hash_fnv.h"
+
+const php_hash_ops php_hash_fnv132_ops = {
+ (php_hash_init_func_t) PHP_FNV132Init,
+ (php_hash_update_func_t) PHP_FNV132Update,
+ (php_hash_final_func_t) PHP_FNV132Final,
+ (php_hash_copy_func_t) php_hash_copy,
+ 4,
+ 4,
+ sizeof(PHP_FNV132_CTX)
+};
+
+ const php_hash_ops php_hash_fnv1a32_ops = {
+ (php_hash_init_func_t) PHP_FNV132Init,
+ (php_hash_update_func_t) PHP_FNV1a32Update,
+ (php_hash_final_func_t) PHP_FNV132Final,
+ (php_hash_copy_func_t) php_hash_copy,
+ 4,
+ 4,
+ sizeof(PHP_FNV132_CTX)
+};
+
+const php_hash_ops php_hash_fnv164_ops = {
+ (php_hash_init_func_t) PHP_FNV164Init,
+ (php_hash_update_func_t) PHP_FNV164Update,
+ (php_hash_final_func_t) PHP_FNV164Final,
+ (php_hash_copy_func_t) php_hash_copy,
+ 8,
+ 4,
+ sizeof(PHP_FNV164_CTX)
+};
+
+const php_hash_ops php_hash_fnv1a64_ops = {
+ (php_hash_init_func_t) PHP_FNV164Init,
+ (php_hash_update_func_t) PHP_FNV1a64Update,
+ (php_hash_final_func_t) PHP_FNV164Final,
+ (php_hash_copy_func_t) php_hash_copy,
+ 8,
+ 4,
+ sizeof(PHP_FNV164_CTX)
+};
+
+/* {{{ PHP_FNV132Init
+ * 32-bit FNV-1 hash initialisation
+ */
+PHP_HASH_API void PHP_FNV132Init(PHP_FNV132_CTX *context)
+{
+ context->state = PHP_FNV1_32_INIT;
+}
+/* }}} */
+
+PHP_HASH_API void PHP_FNV132Update(PHP_FNV132_CTX *context, const unsigned char *input,
+ unsigned int inputLen)
+{
+ context->state = fnv_32_buf((void *)input, inputLen, context->state, 0);
+}
+
+PHP_HASH_API void PHP_FNV1a32Update(PHP_FNV132_CTX *context, const unsigned char *input,
+ unsigned int inputLen)
+{
+ context->state = fnv_32_buf((void *)input, inputLen, context->state, 1);
+}
+
+PHP_HASH_API void PHP_FNV132Final(unsigned char digest[4], PHP_FNV132_CTX * context)
+{
+#ifdef WORDS_BIGENDIAN
+ memcpy(digest, &context->state, 4);
+#else
+ int i = 0;
+ unsigned char *c = (unsigned char *) &context->state;
+
+ for (i = 0; i < 4; i++) {
+ digest[i] = c[3 - i];
+ }
+#endif
+}
+
+/* {{{ PHP_FNV164Init
+ * 64-bit FNV-1 hash initialisation
+ */
+PHP_HASH_API void PHP_FNV164Init(PHP_FNV164_CTX *context)
+{
+ context->state = PHP_FNV1_64_INIT;
+}
+/* }}} */
+
+PHP_HASH_API void PHP_FNV164Update(PHP_FNV164_CTX *context, const unsigned char *input,
+ unsigned int inputLen)
+{
+ context->state = fnv_64_buf((void *)input, inputLen, context->state, 0);
+}
+
+PHP_HASH_API void PHP_FNV1a64Update(PHP_FNV164_CTX *context, const unsigned char *input,
+ unsigned int inputLen)
+{
+ context->state = fnv_64_buf((void *)input, inputLen, context->state, 1);
+}
+
+PHP_HASH_API void PHP_FNV164Final(unsigned char digest[8], PHP_FNV164_CTX * context)
+{
+#ifdef WORDS_BIGENDIAN
+ memcpy(digest, &context->state, 8);
+#else
+ int i = 0;
+ unsigned char *c = (unsigned char *) &context->state;
+
+ for (i = 0; i < 8; i++) {
+ digest[i] = c[7 - i];
+ }
+#endif
+}
+
+
+/*
+ * fnv_32_buf - perform a 32 bit Fowler/Noll/Vo hash on a buffer
+ *
+ * input:
+ * buf - start of buffer to hash
+ * len - length of buffer in octets
+ * hval - previous hash value or 0 if first call
+ * alternate - if > 0 use the alternate version
+ *
+ * returns:
+ * 32 bit hash as a static hash type
+ */
+static php_hash_uint32
+fnv_32_buf(void *buf, size_t len, php_hash_uint32 hval, int alternate)
+{
+ unsigned char *bp = (unsigned char *)buf; /* start of buffer */
+ unsigned char *be = bp + len; /* beyond end of buffer */
+
+ /*
+ * FNV-1 hash each octet in the buffer
+ */
+ while (bp < be) {
+
+ if (alternate == 0) {
+ /* multiply by the 32 bit FNV magic prime mod 2^32 */
+ hval *= PHP_FNV_32_PRIME;
+
+ /* xor the bottom with the current octet */
+ hval ^= (php_hash_uint32)*bp++;
+ } else {
+ /* xor the bottom with the current octet */
+ hval ^= (php_hash_uint32)*bp++;
+
+ /* multiply by the 32 bit FNV magic prime mod 2^32 */
+ hval *= PHP_FNV_32_PRIME;
+ }
+ }
+
+ /* return our new hash value */
+ return hval;
+}
+
+/*
+ * fnv_64_buf - perform a 64 bit Fowler/Noll/Vo hash on a buffer
+ *
+ * input:
+ * buf - start of buffer to hash
+ * len - length of buffer in octets
+ * hval - previous hash value or 0 if first call
+ * alternate - if > 0 use the alternate version
+ *
+ * returns:
+ * 64 bit hash as a static hash type
+ */
+static php_hash_uint64
+fnv_64_buf(void *buf, size_t len, php_hash_uint64 hval, int alternate)
+{
+ unsigned char *bp = (unsigned char *)buf; /* start of buffer */
+ unsigned char *be = bp + len; /* beyond end of buffer */
+
+ /*
+ * FNV-1 hash each octet of the buffer
+ */
+ while (bp < be) {
+
+ if (alternate == 0) {
+ /* multiply by the 64 bit FNV magic prime mod 2^64 */
+ hval *= PHP_FNV_64_PRIME;
+
+ /* xor the bottom with the current octet */
+ hval ^= (php_hash_uint64)*bp++;
+ } else {
+ /* xor the bottom with the current octet */
+ hval ^= (php_hash_uint64)*bp++;
+
+ /* multiply by the 64 bit FNV magic prime mod 2^64 */
+ hval *= PHP_FNV_64_PRIME;
+ }
+ }
+
+ /* return our new hash value */
+ return hval;
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
diff --git a/ext/hash/php_hash.h b/ext/hash/php_hash.h
index 487048da45..af88159586 100644
--- a/ext/hash/php_hash.h
+++ b/ext/hash/php_hash.h
@@ -80,6 +80,8 @@ extern const php_hash_ops php_hash_crc32_ops;
extern const php_hash_ops php_hash_crc32b_ops;
extern const php_hash_ops php_hash_salsa10_ops;
extern const php_hash_ops php_hash_salsa20_ops;
+extern const php_hash_ops php_hash_fnv132_ops;
+extern const php_hash_ops php_hash_fnv164_ops;
#define PHP_HASH_HAVAL_OPS(p,b) extern const php_hash_ops php_hash_##p##haval##b##_ops;
diff --git a/ext/hash/php_hash_fnv.h b/ext/hash/php_hash_fnv.h
new file mode 100644
index 0000000000..353878b052
--- /dev/null
+++ b/ext/hash/php_hash_fnv.h
@@ -0,0 +1,79 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2010 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Michael Maclean <mgdm@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#ifndef PHP_HASH_FNV_H
+#define PHP_HASH_FNV_H
+
+#define PHP_FNV1_32_INIT ((php_hash_uint32)0x811c9dc5)
+#define PHP_FNV1_32A_INIT PHP_FNV1_32_INIT
+
+#define PHP_FNV_32_PRIME ((php_hash_uint32)0x01000193)
+
+#define PHP_FNV1_64_INIT ((php_hash_uint64)0xcbf29ce484222325ULL)
+#define PHP_FNV1A_64_INIT FNV1_64_INIT
+
+#define PHP_FNV_64_PRIME ((php_hash_uint64)0x100000001b3ULL)
+
+
+/*
+ * hash types
+ */
+enum php_fnv_type {
+ PHP_FNV_NONE = 0, /* invalid FNV hash type */
+ PHP_FNV0_32 = 1, /* FNV-0 32 bit hash */
+ PHP_FNV1_32 = 2, /* FNV-1 32 bit hash */
+ PHP_FNV1a_32 = 3, /* FNV-1a 32 bit hash */
+ PHP_FNV0_64 = 4, /* FNV-0 64 bit hash */
+ PHP_FNV1_64 = 5, /* FNV-1 64 bit hash */
+ PHP_FNV1a_64 = 6, /* FNV-1a 64 bit hash */
+};
+
+typedef struct {
+ php_hash_uint32 state;
+} PHP_FNV132_CTX;
+
+typedef struct {
+ php_hash_uint64 state;
+} PHP_FNV164_CTX;
+
+
+PHP_HASH_API void PHP_FNV132Init(PHP_FNV132_CTX *context);
+PHP_HASH_API void PHP_FNV132Update(PHP_FNV132_CTX *context, const unsigned char *input, unsigned int inputLen);
+PHP_HASH_API void PHP_FNV1a32Update(PHP_FNV132_CTX *context, const unsigned char *input, unsigned int inputLen);
+PHP_HASH_API void PHP_FNV132Final(unsigned char digest[16], PHP_FNV132_CTX * context);
+
+PHP_HASH_API void PHP_FNV164Init(PHP_FNV164_CTX *context);
+PHP_HASH_API void PHP_FNV164Update(PHP_FNV164_CTX *context, const unsigned char *input, unsigned int inputLen);
+PHP_HASH_API void PHP_FNV1a64Update(PHP_FNV164_CTX *context, const unsigned char *input, unsigned int inputLen);
+PHP_HASH_API void PHP_FNV164Final(unsigned char digest[16], PHP_FNV164_CTX * context);
+
+static php_hash_uint32 fnv_32_buf(void *buf, size_t len, php_hash_uint32 hval, int alternate);
+static php_hash_uint64 fnv_64_buf(void *buf, size_t len, php_hash_uint64 hval, int alternate);
+
+#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
diff --git a/ext/hash/tests/fnv132.phpt b/ext/hash/tests/fnv132.phpt
new file mode 100644
index 0000000000..051386ab75
--- /dev/null
+++ b/ext/hash/tests/fnv132.phpt
@@ -0,0 +1,202 @@
+--TEST--
+FNV
+--SKIPIF--
+<?php extension_loaded('hash') or die ('Skip - hash extension not available'); ?>
+--FILE--
+<?php
+
+function R10($t) {
+ return str_repeat($t, 10);
+}
+
+function R500($t) {
+ return str_repeat($t, 500);
+}
+
+$tests = array(
+ array( "", "811c9dc5" ),
+ array( "a", "050c5d7e" ),
+ array( "b", "050c5d7d" ),
+ array( "c", "050c5d7c" ),
+ array( "d", "050c5d7b" ),
+ array( "e", "050c5d7a" ),
+ array( "f", "050c5d79" ),
+ array( "fo", "6b772514" ),
+ array( "foo", "408f5e13" ),
+ array( "foob", "b4b1178b" ),
+ array( "fooba", "fdc80fb0" ),
+ array( "foobar", "31f0b262" ),
+ array( "\0", "050c5d1f" ),
+ array( "a\0", "70772d5a" ),
+ array( "b\0", "6f772bc7" ),
+ array( "c\0", "6e772a34" ),
+ array( "d\0", "6d7728a1" ),
+ array( "e\0", "6c77270e" ),
+ array( "f\0", "6b77257b" ),
+ array( "fo\0", "408f5e7c" ),
+ array( "foo\0", "b4b117e9" ),
+ array( "foob\0", "fdc80fd1" ),
+ array( "fooba\0", "31f0b210" ),
+ array( "foobar\0", "ffe8d046" ),
+ array( "ch", "6e772a5c" ),
+ array( "cho", "4197aebb" ),
+ array( "chon", "fcc8100f" ),
+ array( "chong", "fdf147fa" ),
+ array( "chongo", "bcd44ee1" ),
+ array( "chongo ", "23382c13" ),
+ array( "chongo w", "846d619e" ),
+ array( "chongo wa", "1630abdb" ),
+ array( "chongo was", "c99e89b2" ),
+ array( "chongo was ", "1692c316" ),
+ array( "chongo was h", "9f091bca" ),
+ array( "chongo was he", "2556be9b" ),
+ array( "chongo was her", "628e0e73" ),
+ array( "chongo was here", "98a0bf6c" ),
+ array( "chongo was here!", "b10d5725" ),
+ array( "chongo was here!\n", "dd002f35" ),
+ array( "ch\0", "4197aed4" ),
+ array( "cho\0", "fcc81061" ),
+ array( "chon\0", "fdf1479d" ),
+ array( "chong\0", "bcd44e8e" ),
+ array( "chongo\0", "23382c33" ),
+ array( "chongo \0", "846d61e9" ),
+ array( "chongo w\0", "1630abba" ),
+ array( "chongo wa\0", "c99e89c1" ),
+ array( "chongo was\0", "1692c336" ),
+ array( "chongo was \0", "9f091ba2" ),
+ array( "chongo was h\0", "2556befe" ),
+ array( "chongo was he\0", "628e0e01" ),
+ array( "chongo was her\0", "98a0bf09" ),
+ array( "chongo was here\0", "b10d5704" ),
+ array( "chongo was here!\0", "dd002f3f" ),
+ array( "chongo was here!\n\0", "1c4a506f" ),
+ array( "cu", "6e772a41" ),
+ array( "cur", "26978421" ),
+ array( "curd", "e184ff97" ),
+ array( "curds", "9b5e5ac6" ),
+ array( "curds ", "5b88e592" ),
+ array( "curds a", "aa8164b7" ),
+ array( "curds an", "20b18c7b" ),
+ array( "curds and", "f28025c5" ),
+ array( "curds and ", "84bb753f" ),
+ array( "curds and w", "3219925a" ),
+ array( "curds and wh", "384163c6" ),
+ array( "curds and whe", "54f010d7" ),
+ array( "curds and whey", "8cea820c" ),
+ array( "curds and whey\n", "e12ab8ee" ),
+ array( "cu\0", "26978453" ),
+ array( "cur\0", "e184fff3" ),
+ array( "curd\0", "9b5e5ab5" ),
+ array( "curds\0", "5b88e5b2" ),
+ array( "curds \0", "aa8164d6" ),
+ array( "curds a\0", "20b18c15" ),
+ array( "curds an\0", "f28025a1" ),
+ array( "curds and\0", "84bb751f" ),
+ array( "curds and \0", "3219922d" ),
+ array( "curds and w\0", "384163ae" ),
+ array( "curds and wh\0", "54f010b2" ),
+ array( "curds and whe\0", "8cea8275" ),
+ array( "curds and whey\0", "e12ab8e4" ),
+ array( "curds and whey\n\0", "64411eaa" ),
+ array( "line 1\nline 2\nline 3", "31ae8f83" ),
+ array( "chongo <Landon Curt Noll> /\\../\\", "995fa9c4" ),
+ array( "chongo <Landon Curt Noll> /\\../\\\0", "35983f8c" ),
+ array( "chongo (Landon Curt Noll) /\\../\\", "5036a251" ),
+ array( "chongo (Landon Curt Noll) /\\../\\\0", "97018583" ),
+ array( "http://antwrp.gsfc.nasa.gov/apod/astropix.html", "b4448d60" ),
+ array( "http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash", "025dfe59" ),
+ array( "http://epod.usra.edu/", "c5eab3af" ),
+ array( "http://exoplanet.eu/", "7d21ba1e" ),
+ array( "http://hvo.wr.usgs.gov/cam3/", "7704cddb" ),
+ array( "http://hvo.wr.usgs.gov/cams/HMcam/", "d0071bfe" ),
+ array( "http://hvo.wr.usgs.gov/kilauea/update/deformation.html", "0ff3774c" ),
+ array( "http://hvo.wr.usgs.gov/kilauea/update/images.html", "b0fea0ea" ),
+ array( "http://hvo.wr.usgs.gov/kilauea/update/maps.html", "58177303" ),
+ array( "http://hvo.wr.usgs.gov/volcanowatch/current_issue.html", "4f599cda" ),
+ array( "http://neo.jpl.nasa.gov/risk/", "3e590a47" ),
+ array( "http://norvig.com/21-days.html", "965595f8" ),
+ array( "http://primes.utm.edu/curios/home.php", "c37f178d" ),
+ array( "http://slashdot.org/", "9711dd26" ),
+ array( "http://tux.wr.usgs.gov/Maps/155.25-19.5.html", "23c99b7f" ),
+ array( "http://volcano.wr.usgs.gov/kilaueastatus.php", "6e568b17" ),
+ array( "http://www.avo.alaska.edu/activity/Redoubt.php", "43f0245b" ),
+ array( "http://www.dilbert.com/fast/", "bcb7a001" ),
+ array( "http://www.fourmilab.ch/gravitation/orbits/", "12e6dffe" ),
+ array( "http://www.fpoa.net/", "0792f2d6" ),
+ array( "http://www.ioccc.org/index.html", "b966936b" ),
+ array( "http://www.isthe.com/cgi-bin/number.cgi", "46439ac5" ),
+ array( "http://www.isthe.com/chongo/bio.html", "728d49af" ),
+ array( "http://www.isthe.com/chongo/index.html", "d33745c9" ),
+ array( "http://www.isthe.com/chongo/src/calc/lucas-calc", "bc382a57" ),
+ array( "http://www.isthe.com/chongo/tech/astro/venus2004.html", "4bda1d31" ),
+ array( "http://www.isthe.com/chongo/tech/astro/vita.html", "ce35ccae" ),
+ array( "http://www.isthe.com/chongo/tech/comp/c/expert.html", "3b6eed94" ),
+ array( "http://www.isthe.com/chongo/tech/comp/calc/index.html", "445c9c58" ),
+ array( "http://www.isthe.com/chongo/tech/comp/fnv/index.html", "3db8bf9d" ),
+ array( "http://www.isthe.com/chongo/tech/math/number/howhigh.html", "2dee116d" ),
+ array( "http://www.isthe.com/chongo/tech/math/number/number.html", "c18738da" ),
+ array( "http://www.isthe.com/chongo/tech/math/prime/mersenne.html", "5b156176" ),
+ array( "http://www.isthe.com/chongo/tech/math/prime/mersenne.html#largest", "2aa7d593" ),
+ array( "http://www.lavarnd.org/cgi-bin/corpspeak.cgi", "b2409658" ),
+ array( "http://www.lavarnd.org/cgi-bin/haiku.cgi", "e1489528" ),
+ array( "http://www.lavarnd.org/cgi-bin/rand-none.cgi", "fe1ee07e" ),
+ array( "http://www.lavarnd.org/cgi-bin/randdist.cgi", "e8842315" ),
+ array( "http://www.lavarnd.org/index.html", "3a6a63a2" ),
+ array( "http://www.lavarnd.org/what/nist-test.html", "06d2c18c" ),
+ array( "http://www.macosxhints.com/", "f8ef7225" ),
+ array( "http://www.mellis.com/", "843d3300" ),
+ array( "http://www.nature.nps.gov/air/webcams/parks/havoso2alert/havoalert.cfm", "bb24f7ae" ),
+ array( "http://www.nature.nps.gov/air/webcams/parks/havoso2alert/timelines_24.cfm", "878c0ec9" ),
+ array( "http://www.paulnoll.com/", "b557810f" ),
+ array( "http://www.pepysdiary.com/", "57423246" ),
+ array( "http://www.sciencenews.org/index/home/activity/view", "87f7505e" ),
+ array( "http://www.skyandtelescope.com/", "bb809f20" ),
+ array( "http://www.sput.nl/~rob/sirius.html", "8932abb5" ),
+ array( "http://www.systemexperts.com/", "0a9b3aa0" ),
+ array( "http://www.tq-international.com/phpBB3/index.php", "b8682a24" ),
+ array( "http://www.travelquesttours.com/index.htm", "a7ac1c56" ),
+ array( "http://www.wunderground.com/global/stations/89606.html", "11409252" ),
+ array( R10("21701"), "a987f517" ),
+ array( R10("M21701"), "f309e7ed" ),
+ array( R10("2^21701-1"), "c9e8f417" ),
+ array( R10("\x54\xc5"), "7f447bdd" ),
+ array( R10("\xc5\x54"), "b929adc5" ),
+ array( R10("23209"), "57022879" ),
+ array( R10("M23209"), "dcfd2c49" ),
+ array( R10("2^23209-1"), "6edafff5" ),
+ array( R10("\x5a\xa9"), "f04fb1f1" ),
+ array( R10("\xa9\x5a"), "fb7de8b9" ),
+ array( R10("391581216093"), "c5f1d7e9" ),
+ array( R10("391581*2^216093-1"), "32c1f439" ),
+ array( R10("\x05\xf9\x9d\x03\x4c\x81"), "7fd3eb7d" ),
+ array( R10("FEDCBA9876543210"), "81597da5" ),
+ array( R10("\xfe\xdc\xba\x98\x76\x54\x32\x10"), "05eb7a25" ),
+ array( R10("EFCDAB8967452301"), "9c0fa1b5" ),
+ array( R10("\xef\xcd\xab\x89\x67\x45\x23\x01"), "53ccb1c5" ),
+ array( R10("0123456789ABCDEF"), "fabece15" ),
+ array( R10("\x01\x23\x45\x67\x89\xab\xcd\xef"), "4ad745a5" ),
+ array( R10("1032547698BADCFE"), "e5bdc495" ),
+ array( R10("\x10\x32\x54\x76\x98\xba\xdc\xfe"), "23b3c0a5" ),
+ array( R500("\x00"), "fa823dd5" ),
+ array( R500("\x07"), "0c6c58b9" ),
+ array( R500("~"), "e2dbccd5" ),
+ array( R500("\x7f"), "db7f50f9" ),
+);
+
+$i = 0;
+$pass = true;
+foreach($tests as $test) {
+ $result = hash('fnv132', $test[0]);
+ if ($result != $test[1]) {
+ echo "Iteration " . $i . " failed - expected '" . $test[1] . "', got '" . $result . "' for '" . $test[1] . "'\n";
+ $pass = false;
+ }
+ $i++;
+}
+
+if($pass) {
+ echo "PASS";
+}
+?>
+--EXPECT--
+PASS
diff --git a/ext/hash/tests/fnv164.phpt b/ext/hash/tests/fnv164.phpt
new file mode 100644
index 0000000000..b5e69420a6
--- /dev/null
+++ b/ext/hash/tests/fnv164.phpt
@@ -0,0 +1,202 @@
+--TEST--
+FNV
+--SKIPIF--
+<?php extension_loaded('hash') or die ('Skip - hash extension not available'); ?>
+--FILE--
+<?php
+
+function R10($t) {
+ return str_repeat($t, 10);
+}
+
+function R500($t) {
+ return str_repeat($t, 500);
+}
+
+$tests = array(
+ array( "", "cbf29ce484222325" ),
+ array( "a", "af63bd4c8601b7be" ),
+ array( "b", "af63bd4c8601b7bd" ),
+ array( "c", "af63bd4c8601b7bc" ),
+ array( "d", "af63bd4c8601b7bb" ),
+ array( "e", "af63bd4c8601b7ba" ),
+ array( "f", "af63bd4c8601b7b9" ),
+ array( "fo", "08326207b4eb2f34" ),
+ array( "foo", "d8cbc7186ba13533" ),
+ array( "foob", "0378817ee2ed65cb" ),
+ array( "fooba", "d329d59b9963f790" ),
+ array( "foobar", "340d8765a4dda9c2" ),
+ array( "\0", "af63bd4c8601b7df" ),
+ array( "a\0", "08326707b4eb37da" ),
+ array( "b\0", "08326607b4eb3627" ),
+ array( "c\0", "08326507b4eb3474" ),
+ array( "d\0", "08326407b4eb32c1" ),
+ array( "e\0", "08326307b4eb310e" ),
+ array( "f\0", "08326207b4eb2f5b" ),
+ array( "fo\0", "d8cbc7186ba1355c" ),
+ array( "foo\0", "0378817ee2ed65a9" ),
+ array( "foob\0", "d329d59b9963f7f1" ),
+ array( "fooba\0", "340d8765a4dda9b0" ),
+ array( "foobar\0", "50a6d3b724a774a6" ),
+ array( "ch", "08326507b4eb341c" ),
+ array( "cho", "d8d5c8186ba98bfb" ),
+ array( "chon", "1ccefc7ef118dbef" ),
+ array( "chong", "0c92fab3ad3db77a" ),
+ array( "chongo", "9b77794f5fdec421" ),
+ array( "chongo ", "0ac742dfe7874433" ),
+ array( "chongo w", "d7dad5766ad8e2de" ),
+ array( "chongo wa", "a1bb96378e897f5b" ),
+ array( "chongo was", "5b3f9b6733a367d2" ),
+ array( "chongo was ", "b07ce25cbea969f6" ),
+ array( "chongo was h", "8d9e9997f9df0d6a" ),
+ array( "chongo was he", "838c673d9603cb7b" ),
+ array( "chongo was her", "8b5ee8a5e872c273" ),
+ array( "chongo was here", "4507c4e9fb00690c" ),
+ array( "chongo was here!", "4c9ca59581b27f45" ),
+ array( "chongo was here!\n", "e0aca20b624e4235" ),
+ array( "ch\0", "d8d5c8186ba98b94" ),
+ array( "cho\0", "1ccefc7ef118db81" ),
+ array( "chon\0", "0c92fab3ad3db71d" ),
+ array( "chong\0", "9b77794f5fdec44e" ),
+ array( "chongo\0", "0ac742dfe7874413" ),
+ array( "chongo \0", "d7dad5766ad8e2a9" ),
+ array( "chongo w\0", "a1bb96378e897f3a" ),
+ array( "chongo wa\0", "5b3f9b6733a367a1" ),
+ array( "chongo was\0", "b07ce25cbea969d6" ),
+ array( "chongo was \0", "8d9e9997f9df0d02" ),
+ array( "chongo was h\0", "838c673d9603cb1e" ),
+ array( "chongo was he\0", "8b5ee8a5e872c201" ),
+ array( "chongo was her\0", "4507c4e9fb006969" ),
+ array( "chongo was here\0", "4c9ca59581b27f64" ),
+ array( "chongo was here!\0", "e0aca20b624e423f" ),
+ array( "chongo was here!\n\0", "13998e580afa800f" ),
+ array( "cu", "08326507b4eb3401" ),
+ array( "cur", "d8d5ad186ba95dc1" ),
+ array( "curd", "1c72e17ef0ca4e97" ),
+ array( "curds", "2183c1b327c38ae6" ),
+ array( "curds ", "b66d096c914504f2" ),
+ array( "curds a", "404bf57ad8476757" ),
+ array( "curds an", "887976bd815498bb" ),
+ array( "curds and", "3afd7f02c2bf85a5" ),
+ array( "curds and ", "fc4476b0eb70177f" ),
+ array( "curds and w", "186d2da00f77ecba" ),
+ array( "curds and wh", "f97140fa48c74066" ),
+ array( "curds and whe", "a2b1cf49aa926d37" ),
+ array( "curds and whey", "0690712cd6cf940c" ),
+ array( "curds and whey\n", "f7045b3102b8906e" ),
+ array( "cu\0", "d8d5ad186ba95db3" ),
+ array( "cur\0", "1c72e17ef0ca4ef3" ),
+ array( "curd\0", "2183c1b327c38a95" ),
+ array( "curds\0", "b66d096c914504d2" ),
+ array( "curds \0", "404bf57ad8476736" ),
+ array( "curds a\0", "887976bd815498d5" ),
+ array( "curds an\0", "3afd7f02c2bf85c1" ),
+ array( "curds and\0", "fc4476b0eb70175f" ),
+ array( "curds and \0", "186d2da00f77eccd" ),
+ array( "curds and w\0", "f97140fa48c7400e" ),
+ array( "curds and wh\0", "a2b1cf49aa926d52" ),
+ array( "curds and whe\0", "0690712cd6cf9475" ),
+ array( "curds and whey\0", "f7045b3102b89064" ),
+ array( "curds and whey\n\0", "74f762479f9d6aea" ),
+ array( "line 1\nline 2\nline 3", "a64e5f36c9e2b0e3" ),
+ array( "chongo <Landon Curt Noll> /\\../\\", "8fd0680da3088a04" ),
+ array( "chongo <Landon Curt Noll> /\\../\\\0", "67aad32c078284cc" ),
+ array( "chongo (Landon Curt Noll) /\\../\\", "b37d55d81c57b331" ),
+ array( "chongo (Landon Curt Noll) /\\../\\\0", "55ac0f3829057c43" ),
+ array( "http://antwrp.gsfc.nasa.gov/apod/astropix.html", "cb27f4b8e1b6cc20" ),
+ array( "http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash", "26caf88bcbef2d19" ),
+ array( "http://epod.usra.edu/", "8e6e063b97e61b8f" ),
+ array( "http://exoplanet.eu/", "b42750f7f3b7c37e" ),
+ array( "http://hvo.wr.usgs.gov/cam3/", "f3c6ba64cf7ca99b" ),
+ array( "http://hvo.wr.usgs.gov/cams/HMcam/", "ebfb69b427ea80fe" ),
+ array( "http://hvo.wr.usgs.gov/kilauea/update/deformation.html", "39b50c3ed970f46c" ),
+ array( "http://hvo.wr.usgs.gov/kilauea/update/images.html", "5b9b177aa3eb3e8a" ),
+ array( "http://hvo.wr.usgs.gov/kilauea/update/maps.html", "6510063ecf4ec903" ),
+ array( "http://hvo.wr.usgs.gov/volcanowatch/current_issue.html", "2b3bbd2c00797c7a" ),
+ array( "http://neo.jpl.nasa.gov/risk/", "f1d6204ff5cb4aa7" ),
+ array( "http://norvig.com/21-days.html", "4836e27ccf099f38" ),
+ array( "http://primes.utm.edu/curios/home.php", "82efbb0dd073b44d" ),
+ array( "http://slashdot.org/", "4a80c282ffd7d4c6" ),
+ array( "http://tux.wr.usgs.gov/Maps/155.25-19.5.html", "305d1a9c9ee43bdf" ),
+ array( "http://volcano.wr.usgs.gov/kilaueastatus.php", "15c366948ffc6997" ),
+ array( "http://www.avo.alaska.edu/activity/Redoubt.php", "80153ae218916e7b" ),
+ array( "http://www.dilbert.com/fast/", "fa23e2bdf9e2a9e1" ),
+ array( "http://www.fourmilab.ch/gravitation/orbits/", "d47e8d8a2333c6de" ),
+ array( "http://www.fpoa.net/", "7e128095f688b056" ),
+ array( "http://www.ioccc.org/index.html", "2f5356890efcedab" ),
+ array( "http://www.isthe.com/cgi-bin/number.cgi", "95c2b383014f55c5" ),
+ array( "http://www.isthe.com/chongo/bio.html", "4727a5339ce6070f" ),
+ array( "http://www.isthe.com/chongo/index.html", "b0555ecd575108e9" ),
+ array( "http://www.isthe.com/chongo/src/calc/lucas-calc", "48d785770bb4af37" ),
+ array( "http://www.isthe.com/chongo/tech/astro/venus2004.html", "09d4701c12af02b1" ),
+ array( "http://www.isthe.com/chongo/tech/astro/vita.html", "79f031e78f3cf62e" ),
+ array( "http://www.isthe.com/chongo/tech/comp/c/expert.html", "52a1ee85db1b5a94" ),
+ array( "http://www.isthe.com/chongo/tech/comp/calc/index.html", "6bd95b2eb37fa6b8" ),
+ array( "http://www.isthe.com/chongo/tech/comp/fnv/index.html", "74971b7077aef85d" ),
+ array( "http://www.isthe.com/chongo/tech/math/number/howhigh.html", "b4e4fae2ffcc1aad" ),
+ array( "http://www.isthe.com/chongo/tech/math/number/number.html", "2bd48bd898b8f63a" ),
+ array( "http://www.isthe.com/chongo/tech/math/prime/mersenne.html", "e9966ac1556257f6" ),
+ array( "http://www.isthe.com/chongo/tech/math/prime/mersenne.html#largest", "92a3d1cd078ba293" ),
+ array( "http://www.lavarnd.org/cgi-bin/corpspeak.cgi", "f81175a482e20ab8" ),
+ array( "http://www.lavarnd.org/cgi-bin/haiku.cgi", "5bbb3de722e73048" ),
+ array( "http://www.lavarnd.org/cgi-bin/rand-none.cgi", "6b4f363492b9f2be" ),
+ array( "http://www.lavarnd.org/cgi-bin/randdist.cgi", "c2d559df73d59875" ),
+ array( "http://www.lavarnd.org/index.html", "f75f62284bc7a8c2" ),
+ array( "http://www.lavarnd.org/what/nist-test.html", "da8dd8e116a9f1cc" ),
+ array( "http://www.macosxhints.com/", "bdc1e6ab76057885" ),
+ array( "http://www.mellis.com/", "fec6a4238a1224a0" ),
+ array( "http://www.nature.nps.gov/air/webcams/parks/havoso2alert/havoalert.cfm", "c03f40f3223e290e" ),
+ array( "http://www.nature.nps.gov/air/webcams/parks/havoso2alert/timelines_24.cfm", "1ed21673466ffda9" ),
+ array( "http://www.paulnoll.com/", "df70f906bb0dd2af" ),
+ array( "http://www.pepysdiary.com/", "f3dcda369f2af666" ),
+ array( "http://www.sciencenews.org/index/home/activity/view", "9ebb11573cdcebde" ),
+ array( "http://www.skyandtelescope.com/", "81c72d9077fedca0" ),
+ array( "http://www.sput.nl/~rob/sirius.html", "0ec074a31be5fb15" ),
+ array( "http://www.systemexperts.com/", "2a8b3280b6c48f20" ),
+ array( "http://www.tq-international.com/phpBB3/index.php", "fd31777513309344" ),
+ array( "http://www.travelquesttours.com/index.htm", "194534a86ad006b6" ),
+ array( "http://www.wunderground.com/global/stations/89606.html", "3be6fdf46e0cfe12" ),
+ array( R10("21701"), "017cc137a07eb057" ),
+ array( R10("M21701"), "9428fc6e7d26b54d" ),
+ array( R10("2^21701-1"), "9aaa2e3603ef8ad7" ),
+ array( R10("\x54\xc5"), "82c6d3f3a0ccdf7d" ),
+ array( R10("\xc5\x54"), "c86eeea00cf09b65" ),
+ array( R10("23209"), "705f8189dbb58299" ),
+ array( R10("M23209"), "415a7f554391ca69" ),
+ array( R10("2^23209-1"), "cfe3d49fa2bdc555" ),
+ array( R10("\x5a\xa9"), "f0f9c56039b25191" ),
+ array( R10("\xa9\x5a"), "7075cb6abd1d32d9" ),
+ array( R10("391581216093"), "43c94e2c8b277509" ),
+ array( R10("391581*2^216093-1"), "3cbfd4e4ea670359" ),
+ array( R10("\x05\xf9\x9d\x03\x4c\x81"), "c05887810f4d019d" ),
+ array( R10("FEDCBA9876543210"), "14468ff93ac22dc5" ),
+ array( R10("\xfe\xdc\xba\x98\x76\x54\x32\x10"), "ebed699589d99c05" ),
+ array( R10("EFCDAB8967452301"), "6d99f6df321ca5d5" ),
+ array( R10("\xef\xcd\xab\x89\x67\x45\x23\x01"), "0cd410d08c36d625" ),
+ array( R10("0123456789ABCDEF"), "ef1b2a2c86831d35" ),
+ array( R10("\x01\x23\x45\x67\x89\xab\xcd\xef"), "3b349c4d69ee5f05" ),
+ array( R10("1032547698BADCFE"), "55248ce88f45f035" ),
+ array( R10("\x10\x32\x54\x76\x98\xba\xdc\xfe"), "aa69ca6a18a4c885" ),
+ array( R500("\x00"), "1fe3fce62bd816b5" ),
+ array( R500("\x07"), "0289a488a8df69d9" ),
+ array( R500("~"), "15e96e1613df98b5" ),
+ array( R500("\x7f"), "e6be57375ad89b99" ),
+);
+
+$i = 0;
+$pass = true;
+foreach($tests as $test) {
+ $result = hash('fnv164', $test[0]);
+ if ($result != $test[1]) {
+ echo "Iteration " . $i . " failed - expected '" . $test[1] . "', got '" . $result . "' for '" . $test[1] . "'\n";
+ $pass = false;
+ }
+ $i++;
+}
+
+if($pass) {
+ echo "PASS";
+}
+?>
+--EXPECT--
+PASS