Back to index

php5  5.3.10
hash_adler32.c
Go to the documentation of this file.
00001 /*
00002   +----------------------------------------------------------------------+
00003   | PHP Version 5                                                        |
00004   +----------------------------------------------------------------------+
00005   | Copyright (c) 1997-2012 The PHP Group                                |
00006   +----------------------------------------------------------------------+
00007   | This source file is subject to version 3.01 of the PHP license,      |
00008   | that is bundled with this package in the file LICENSE, and is        |
00009   | available through the world-wide-web at the following url:           |
00010   | http://www.php.net/license/3_01.txt                                  |
00011   | If you did not receive a copy of the PHP license and are unable to   |
00012   | obtain it through the world-wide-web, please send a note to          |
00013   | license@php.net so we can mail you a copy immediately.               |
00014   +----------------------------------------------------------------------+
00015   | Authors: Michael Wallner <mike@php.net>                              |
00016   |          Sara Golemon <pollita@php.net>                              |
00017   +----------------------------------------------------------------------+
00018 */
00019 
00020 /* $Id: hash_adler32.c 321634 2012-01-01 13:15:04Z felipe $ */
00021 
00022 #include "php_hash.h"
00023 #include "php_hash_adler32.h"
00024 
00025 PHP_HASH_API void PHP_ADLER32Init(PHP_ADLER32_CTX *context)
00026 {
00027        context->state = 1;
00028 }
00029 
00030 PHP_HASH_API void PHP_ADLER32Update(PHP_ADLER32_CTX *context, const unsigned char *input, size_t len)
00031 {
00032        php_hash_uint32 i, s[2];
00033        
00034        s[0] = context->state & 0xffff;
00035        s[1] = (context->state >> 16) & 0xffff;
00036        for (i = 0; i < len; ++i) {
00037               s[0] = (s[0] + input[i]) % 65521;
00038               s[1] = (s[1] + s[0]) % 65521;
00039        }
00040        context->state = s[0] + (s[1] << 16);
00041 }
00042 
00043 PHP_HASH_API void PHP_ADLER32Final(unsigned char digest[4], PHP_ADLER32_CTX *context)
00044 {
00045        digest[0] = (unsigned char) ((context->state >> 24) & 0xff);
00046        digest[1] = (unsigned char) ((context->state >> 16) & 0xff);
00047        digest[2] = (unsigned char) ((context->state >> 8) & 0xff);
00048        digest[3] = (unsigned char) (context->state & 0xff);
00049        context->state = 0;
00050 }
00051 
00052 PHP_HASH_API int PHP_ADLER32Copy(const php_hash_ops *ops, PHP_ADLER32_CTX *orig_context, PHP_ADLER32_CTX *copy_context)
00053 {
00054        copy_context->state = orig_context->state;
00055        return SUCCESS;
00056 }
00057 
00058 const php_hash_ops php_hash_adler32_ops = {
00059        (php_hash_init_func_t) PHP_ADLER32Init,
00060        (php_hash_update_func_t) PHP_ADLER32Update,
00061        (php_hash_final_func_t) PHP_ADLER32Final,
00062        (php_hash_copy_func_t) PHP_ADLER32Copy,
00063        4, /* what to say here? */
00064        4,
00065        sizeof(PHP_ADLER32_CTX)
00066 };
00067 
00068 /*
00069  * Local variables:
00070  * tab-width: 4
00071  * c-basic-offset: 4
00072  * End:
00073  * vim600: sw=4 ts=4 fdm=marker
00074  * vim<600: sw=4 ts=4
00075  */