]> granicus.if.org Git - php/commitdiff
- add adler32
authorMichael Wallner <mike@php.net>
Fri, 25 Nov 2005 23:12:44 +0000 (23:12 +0000)
committerMichael Wallner <mike@php.net>
Fri, 25 Nov 2005 23:12:44 +0000 (23:12 +0000)
ext/hash/config.m4
ext/hash/config.w32
ext/hash/hash.c
ext/hash/hash_adler32.c [new file with mode: 0644]
ext/hash/package.xml
ext/hash/php_hash.h
ext/hash/php_hash_adler32.h [new file with mode: 0644]

index af7dc3e9a59e41e14ea8c6d2a411d62c810002bc..123f272695b5a60f1b7794c79ba2ea83fc4ab7a8 100644 (file)
@@ -6,8 +6,15 @@ PHP_ARG_ENABLE(hash, whether to enable hash support,
 
 if test "$PHP_HASH" != "no"; then
   AC_DEFINE(HAVE_HASH_EXT,1,[Have HASH Extension])
-  PHP_NEW_EXTENSION(hash, 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, $ext_shared)
+  
+  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"
+  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_NEW_EXTENSION(hash, $EXT_HASH_SOURCES, $ext_shared)
   ifdef([PHP_INSTALL_HEADERS], [
-       PHP_INSTALL_HEADERS(ext/hash, 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_INSTALL_HEADERS(ext/hash, $EXT_HASH_HEADERS)
   ])
 fi
index db15dbb6738087c2b8be56d5db81513af3575446..d490d92950ef71eb2a4bd9a782dcb8e5d0558350 100644 (file)
@@ -5,6 +5,8 @@ ARG_ENABLE("hash", "enable hash support", "no");
 
 if (PHP_HASH != "no") {
        AC_DEFINE('HAVE_HASH_EXT', 1);
-       EXTENSION("hash", "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");
+       EXTENSION("hash", "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");
 }
 
index 63b5e903e6fec48f078ed0d44888e00dda68e7a5..4408ba42ea343d63bd36896735ca934ab97ceee2 100644 (file)
@@ -398,7 +398,7 @@ PHP_MINIT_FUNCTION(hash)
 {
        php_hash_le_hash = zend_register_list_destructors_ex(php_hash_dtor, NULL, PHP_HASH_RESNAME, module_number);
 
-       zend_hash_init(&php_hash_hashtable, 30, NULL, NULL, 1);
+       zend_hash_init(&php_hash_hashtable, 35, NULL, NULL, 1);
 
        php_hash_register_algo("md5",                   &php_hash_md5_ops);
        php_hash_register_algo("sha1",                  &php_hash_sha1_ops);
@@ -416,6 +416,7 @@ PHP_MINIT_FUNCTION(hash)
        php_hash_register_algo("tiger192,4",    &php_hash_4tiger192_ops);
        php_hash_register_algo("snefru",                &php_hash_snefru_ops);
        php_hash_register_algo("gost",                  &php_hash_gost_ops);
+       php_hash_register_algo("adler32",               &php_hash_adler32_ops);
 
        PHP_HASH_HAVAL_REGISTER(3,128);
        PHP_HASH_HAVAL_REGISTER(3,160);
diff --git a/ext/hash/hash_adler32.c b/ext/hash/hash_adler32.c
new file mode 100644 (file)
index 0000000..48d262b
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+  +----------------------------------------------------------------------+
+  | PHP Version 5                                                        |
+  +----------------------------------------------------------------------+
+  | Copyright (c) 1997-2005 The PHP Group                                |
+  +----------------------------------------------------------------------+
+  | This source file is subject to version 3.0 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_0.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.               |
+  +----------------------------------------------------------------------+
+  | Authors: Michael Wallner <mike@php.net>                              |
+  |          Sara Golemon <pollita@php.net>                              |
+  +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#include "php_hash.h"
+#include "php_hash_adler32.h"
+
+PHP_HASH_API PHP_ADLER32Init(PHP_ADLER32_CTX *context)
+{
+       context->state = 1;
+}
+
+PHP_HASH_API PHP_ADLER32Update(PHP_ADLER32_CTX *context, const unsigned char *input, size_t len)
+{
+       php_uint32 i, s[2] = { context->state & 0xffff, (context->state >> 16) & 0xffff };
+       
+       for (i = 0; i < len; ++i) {
+               s[0] = (s[0] + input[i]) % 65521;
+               s[1] = (s[1] + s[0]) % 65521;
+       }
+       context->state = s[0] + (s[1] << 16);
+}
+
+PHP_HASH_API PHP_ADLER32Final(unsigned char digest[4], PHP_ADLER32_CTX *context)
+{
+       digest[3] = (unsigned char) ((context->state >> 24) & 0xff);
+       digest[2] = (unsigned char) ((context->state >> 16) & 0xff);
+       digest[1] = (unsigned char) ((context->state >> 8) & 0xff);
+       digest[0] = (unsigned char) (context->state & 0xff);
+       context->state = 0;
+}
+
+php_hash_ops php_hash_adler32_ops = {
+       (php_hash_init_func_t) PHP_ADLER32Init,
+       (php_hash_update_func_t) PHP_ADLER32Update,
+       (php_hash_final_func_t) PHP_ADLER32Final,
+       4, /* what to say here? */
+       4,
+       sizeof(PHP_ADLER32_CTX)
+};
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
index 76aef7d72e5f777cc38bd5eda8e1b5c8095dbed5..8fbd9dd6db0f28bab641012e4f481b92ebc2744f 100644 (file)
@@ -30,7 +30,7 @@ Initial Release
  * sha1, sha256, sha384, sha512
  * ripemd128, ripemd160
  * tiger128, tiger160, tiger192
- * gost, snefru, whirlpool
+ * adler32, gost, snefru, whirlpool
    </notes>
   </release>
 
@@ -57,6 +57,8 @@ Initial Release
    <file role="src" name="hash_gost.c"/>
    <file role="src" name="php_hash_gost.h"/>
    <file role="src" name="php_hash_gost_tables.h"/>
+   <file role="src" name="hash_adler32.c"/>
+   <file role="src" name="php_hash_adler32.h"/>
    <file role="doc" name="README"/>
    <dir role="test" name="tests">
     <file role="test" name="hmac-md5.phpt"/>
index 6e23bfedf9bc433953c42effb6522c40adb35d4a..1f11d4fb4a1731570ebe9abc566ddf03dd61ebfe 100644 (file)
@@ -67,6 +67,7 @@ extern php_hash_ops php_hash_4tiger160_ops;
 extern php_hash_ops php_hash_4tiger192_ops;
 extern php_hash_ops php_hash_snefru_ops;
 extern php_hash_ops php_hash_gost_ops;
+extern php_hash_ops php_hash_adler32_ops;
 
 #define PHP_HASH_HAVAL_OPS(p,b)        extern php_hash_ops php_hash_##p##haval##b##_ops;
 
@@ -104,7 +105,7 @@ extern zend_module_entry hash_module_entry;
 PHP_HASH_API php_hash_ops *php_hash_fetch_ops(const char *algo, int algo_len);
 PHP_HASH_API void php_hash_register_algo(const char *algo, php_hash_ops *ops);
 
-static inline void php_hash_bin2hex(char *out, unsigned char *in, int in_len)
+static inline void php_hash_bin2hex(char *out, const unsigned char *in, int in_len)
 {
        static const char hexits[16] = "0123456789abcdef";
        int i;
diff --git a/ext/hash/php_hash_adler32.h b/ext/hash/php_hash_adler32.h
new file mode 100644 (file)
index 0000000..27bddbb
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+   +----------------------------------------------------------------------+
+   | PHP Version 5                                                        |
+   +----------------------------------------------------------------------+
+   | Copyright (c) 1997-2005 The PHP Group                                |
+   +----------------------------------------------------------------------+
+   | This source file is subject to version 3.0 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_0.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 Wallner <mike@php.net>                               |
+   +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#ifndef PHP_HASH_ADLER32_H
+#define PHP_HASH_ADLER32_H
+
+#include "ext/standard/basic_functions.h"
+
+typedef struct {
+       php_uint32 state;
+} PHP_ADLER32_CTX;
+
+PHP_HASH_API PHP_ADLER32Init(PHP_ADLER32_CTX *context);
+PHP_HASH_API PHP_ADLER32Update(PHP_ADLER32_CTX *context, const unsigned char *input, size_t len);
+PHP_HASH_API PHP_ADLER32Final(unsigned char digest[4], PHP_ADLER32_CTX *context);
+
+#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */