php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
hash_crc32.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_crc32.h"
22
27
28PHP_HASH_API void PHP_CRC32Update(PHP_CRC32_CTX *context, const unsigned char *input, size_t len)
29{
30 size_t i = 0;
31
32#if defined(ZEND_INTRIN_SSE4_2_PCLMUL_NATIVE) || defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER)
33 i += crc32_x86_simd_update(X86_CRC32, &context->state, input, len);
34#endif
35
36 for (; i < len; ++i) {
37 context->state = (context->state << 8) ^ crc32_table[(context->state >> 24) ^ (input[i] & 0xff)];
38 }
39}
40
41PHP_HASH_API void PHP_CRC32BUpdate(PHP_CRC32_CTX *context, const unsigned char *input, size_t len)
42{
43 size_t i = 0;
44
45#if defined(ZEND_INTRIN_SSE4_2_PCLMUL_NATIVE) || defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER)
46 i += crc32_x86_simd_update(X86_CRC32B, &context->state, input, len);
47#endif
48
49 for (; i < len; ++i) {
50 context->state = (context->state >> 8) ^ crc32b_table[(context->state ^ input[i]) & 0xff];
51 }
52}
53
54PHP_HASH_API void PHP_CRC32CUpdate(PHP_CRC32_CTX *context, const unsigned char *input, size_t len)
55{
56 size_t i = 0;
57
58#if defined(ZEND_INTRIN_SSE4_2_PCLMUL_NATIVE) || defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER)
59 i += crc32_x86_simd_update(X86_CRC32C, &context->state, input, len);
60#endif
61
62 for (; i < len; ++i) {
63 context->state = (context->state >> 8) ^ crc32c_table[(context->state ^ input[i]) & 0xff];
64 }
65}
66
67PHP_HASH_API void PHP_CRC32LEFinal(unsigned char digest[4], PHP_CRC32_CTX *context)
68{
69 context->state=~context->state;
70 digest[3] = (unsigned char) ((context->state >> 24) & 0xff);
71 digest[2] = (unsigned char) ((context->state >> 16) & 0xff);
72 digest[1] = (unsigned char) ((context->state >> 8) & 0xff);
73 digest[0] = (unsigned char) (context->state & 0xff);
74 context->state = 0;
75}
76
77PHP_HASH_API void PHP_CRC32BEFinal(unsigned char digest[4], PHP_CRC32_CTX *context)
78{
79 context->state=~context->state;
80 digest[0] = (unsigned char) ((context->state >> 24) & 0xff);
81 digest[1] = (unsigned char) ((context->state >> 16) & 0xff);
82 digest[2] = (unsigned char) ((context->state >> 8) & 0xff);
83 digest[3] = (unsigned char) (context->state & 0xff);
84 context->state = 0;
85}
86
88{
89 copy_context->state = orig_context->state;
90 return SUCCESS;
91}
92
107
122
size_t len
Definition apprentice.c:174
@ X86_CRC32C
Definition crc32_x86.h:34
@ X86_CRC32
Definition crc32_x86.h:24
@ X86_CRC32B
Definition crc32_x86.h:29
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 void PHP_CRC32BUpdate(PHP_CRC32_CTX *context, const unsigned char *input, size_t len)
Definition hash_crc32.c:41
PHP_HASH_API void PHP_CRC32BEFinal(unsigned char digest[4], PHP_CRC32_CTX *context)
Definition hash_crc32.c:77
PHP_HASH_API void PHP_CRC32Update(PHP_CRC32_CTX *context, const unsigned char *input, size_t len)
Definition hash_crc32.c:28
PHP_HASH_API void PHP_CRC32LEFinal(unsigned char digest[4], PHP_CRC32_CTX *context)
Definition hash_crc32.c:67
PHP_HASH_API zend_result PHP_CRC32Copy(const php_hash_ops *ops, const PHP_CRC32_CTX *orig_context, PHP_CRC32_CTX *copy_context)
Definition hash_crc32.c:87
const php_hash_ops php_hash_crc32c_ops
Definition hash_crc32.c:123
PHP_HASH_API void PHP_CRC32CUpdate(PHP_CRC32_CTX *context, const unsigned char *input, size_t len)
Definition hash_crc32.c:54
PHP_HASH_API void PHP_CRC32Init(PHP_CRC32_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
Definition hash_crc32.c:23
const php_hash_ops php_hash_crc32b_ops
Definition hash_crc32.c:108
const php_hash_ops php_hash_crc32_ops
Definition hash_crc32.c:93
#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_CRC32_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