php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
hash_adler32.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Michael Wallner <mike@php.net> |
14 | Sara Golemon <pollita@php.net> |
15 +----------------------------------------------------------------------+
16*/
17
18#include "php_hash.h"
19#include "php_hash_adler32.h"
20
25
26PHP_HASH_API void PHP_ADLER32Update(PHP_ADLER32_CTX *context, const unsigned char *input, size_t len)
27{
28 uint32_t s[2];
29
30 s[0] = context->state & 0xffff;
31 s[1] = (context->state >> 16) & 0xffff;
32 for (size_t i = 0; i < len; ++i) {
33 s[0] += input[i];
34 s[1] += s[0];
35 if (s[1]>=0x7fffffff)
36 {
37 s[0] = s[0] % 65521;
38 s[1] = s[1] % 65521;
39 }
40 }
41 s[0] = s[0] % 65521;
42 s[1] = s[1] % 65521;
43 context->state = s[0] + (s[1] << 16);
44}
45
47{
48 digest[0] = (unsigned char) ((context->state >> 24) & 0xff);
49 digest[1] = (unsigned char) ((context->state >> 16) & 0xff);
50 digest[2] = (unsigned char) ((context->state >> 8) & 0xff);
51 digest[3] = (unsigned char) (context->state & 0xff);
52 context->state = 0;
53}
54
56{
57 copy_context->state = orig_context->state;
58 return SUCCESS;
59}
60
size_t len
Definition apprentice.c:174
char s[4]
Definition cdf.c:77
const php_stream_filter_ops * ops
Definition filters.c:1899
PHP_HASH_API zend_result php_hash_serialize(const php_hashcontext_object *hash, zend_long *magic, zval *zv)
Definition hash.c:334
PHP_HASH_API int php_hash_unserialize(php_hashcontext_object *hash, zend_long magic, const zval *zv)
Definition hash.c:345
PHP_HASH_API zend_result PHP_ADLER32Copy(const php_hash_ops *ops, const PHP_ADLER32_CTX *orig_context, PHP_ADLER32_CTX *copy_context)
const php_hash_ops php_hash_adler32_ops
PHP_HASH_API void PHP_ADLER32Update(PHP_ADLER32_CTX *context, const unsigned char *input, size_t len)
PHP_HASH_API void PHP_ADLER32Init(PHP_ADLER32_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
PHP_HASH_API void PHP_ADLER32Final(unsigned char digest[4], PHP_ADLER32_CTX *context)
#define SUCCESS
Definition hash_sha3.c:261
void(* php_hash_final_func_t)(unsigned char *digest, void *context)
Definition php_hash.h:36
zend_result(* php_hash_copy_func_t)(const void *ops, const void *orig_context, void *dest_context)
Definition php_hash.h:37
void(* php_hash_init_func_t)(void *context, HashTable *args)
Definition php_hash.h:34
void(* php_hash_update_func_t)(void *context, const unsigned char *buf, size_t count)
Definition php_hash.h:35
#define PHP_HASH_API
Definition php_hash.h:144
struct _php_hash_ops php_hash_ops
#define PHP_ADLER32_SPEC
Definition dce.c:49
zval * args
#define ZEND_ATTRIBUTE_UNUSED
struct _zend_array HashTable
Definition zend_types.h:386
ZEND_RESULT_CODE zend_result
Definition zend_types.h:64