[PHP-CVS] svn: /php/php-src/trunk/ext/hash/ config.m4 hash.c hash_fnv.c php_hash.h php_hash_fnv.h tests/fnv132.phpt tests/fnv164.phpt

2010-03-23 Thread Michael Maclean
mgdm Tue, 23 Mar 2010 22:21:39 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=296691

Log:
Add FNV-1 support to ext/hash

Changed paths:
U   php/php-src/trunk/ext/hash/config.m4
U   php/php-src/trunk/ext/hash/hash.c
A   php/php-src/trunk/ext/hash/hash_fnv.c
U   php/php-src/trunk/ext/hash/php_hash.h
A   php/php-src/trunk/ext/hash/php_hash_fnv.h
A   php/php-src/trunk/ext/hash/tests/fnv132.phpt
A   php/php-src/trunk/ext/hash/tests/fnv164.phpt

Modified: php/php-src/trunk/ext/hash/config.m4
===
--- php/php-src/trunk/ext/hash/config.m4	2010-03-23 22:08:17 UTC (rev 296690)
+++ php/php-src/trunk/ext/hash/config.m4	2010-03-23 22:21:39 UTC (rev 296691)
@@ -27,11 +27,11 @@

   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], [

Modified: php/php-src/trunk/ext/hash/hash.c
===
--- php/php-src/trunk/ext/hash/hash.c	2010-03-23 22:08:17 UTC (rev 296690)
+++ php/php-src/trunk/ext/hash/hash.c	2010-03-23 22:21:39 UTC (rev 296691)
@@ -74,7 +74,11 @@
 	{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_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);

Added: php/php-src/trunk/ext/hash/hash_fnv.c
===
--- php/php-src/trunk/ext/hash/hash_fnv.c	(rev 0)
+++ php/php-src/trunk/ext/hash/hash_fnv.c	2010-03-23 22:21:39 UTC (rev 296691)
@@ -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  |
+  | lice...@php.net so we can mail you a copy immediately.   |
+  +--+
+  | Author: Michael Maclean m...@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)
+};
+
+/* 

Re: [PHP-CVS] svn: /php/php-src/trunk/ext/hash/ config.m4 hash.c hash_fnv.c php_hash.h php_hash_fnv.h tests/fnv132.phpt tests/fnv164.phpt

2010-03-23 Thread Jordi Boggiano
Heya,

+   {FNV1a32, fnv1a32, 30},
+   {FNV1a64, fnv1a64, 32},

I think those two should be FNV1A32/64, since they seem to be used to
define MHASH_* constants, and constants with lowercased letter are
really non-standard.

Other than that, as mentionned on irc, thanks for the patch, and I'd
be interested if you could run a hash benchmark [1] on it, if you have
it compiled, to see how it compares to other fast algos.

Cheers,
Jordi

[1] http://www.php.net/manual/en/function.hash.php#89574

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