This source file includes following definitions.
- PHP_CRC32Init
- PHP_CRC32Update
- PHP_CRC32BUpdate
- PHP_CRC32Final
- PHP_CRC32BFinal
- PHP_CRC32Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #include "php_hash.h"
23 #include "php_hash_crc32.h"
24 #include "php_hash_crc32_tables.h"
25
26 PHP_HASH_API void PHP_CRC32Init(PHP_CRC32_CTX *context)
27 {
28 context->state = ~0;
29 }
30
31 PHP_HASH_API void PHP_CRC32Update(PHP_CRC32_CTX *context, const unsigned char *input, size_t len)
32 {
33 size_t i;
34
35 for (i = 0; i < len; ++i) {
36 context->state = (context->state << 8) ^ crc32_table[(context->state >> 24) ^ (input[i] & 0xff)];
37 }
38 }
39
40 PHP_HASH_API void PHP_CRC32BUpdate(PHP_CRC32_CTX *context, const unsigned char *input, size_t len)
41 {
42 size_t i;
43
44 for (i = 0; i < len; ++i) {
45 context->state = (context->state >> 8) ^ crc32b_table[(context->state ^ input[i]) & 0xff];
46 }
47 }
48
49 PHP_HASH_API void PHP_CRC32Final(unsigned char digest[4], PHP_CRC32_CTX *context)
50 {
51 context->state=~context->state;
52 digest[3] = (unsigned char) ((context->state >> 24) & 0xff);
53 digest[2] = (unsigned char) ((context->state >> 16) & 0xff);
54 digest[1] = (unsigned char) ((context->state >> 8) & 0xff);
55 digest[0] = (unsigned char) (context->state & 0xff);
56 context->state = 0;
57 }
58
59 PHP_HASH_API void PHP_CRC32BFinal(unsigned char digest[4], PHP_CRC32_CTX *context)
60 {
61 context->state=~context->state;
62 digest[0] = (unsigned char) ((context->state >> 24) & 0xff);
63 digest[1] = (unsigned char) ((context->state >> 16) & 0xff);
64 digest[2] = (unsigned char) ((context->state >> 8) & 0xff);
65 digest[3] = (unsigned char) (context->state & 0xff);
66 context->state = 0;
67 }
68
69 PHP_HASH_API int PHP_CRC32Copy(const php_hash_ops *ops, PHP_CRC32_CTX *orig_context, PHP_CRC32_CTX *copy_context)
70 {
71 copy_context->state = orig_context->state;
72 return SUCCESS;
73 }
74
75 const php_hash_ops php_hash_crc32_ops = {
76 (php_hash_init_func_t) PHP_CRC32Init,
77 (php_hash_update_func_t) PHP_CRC32Update,
78 (php_hash_final_func_t) PHP_CRC32Final,
79 (php_hash_copy_func_t) PHP_CRC32Copy,
80 4,
81 4,
82 sizeof(PHP_CRC32_CTX)
83 };
84
85 const php_hash_ops php_hash_crc32b_ops = {
86 (php_hash_init_func_t) PHP_CRC32Init,
87 (php_hash_update_func_t) PHP_CRC32BUpdate,
88 (php_hash_final_func_t) PHP_CRC32BFinal,
89 (php_hash_copy_func_t) PHP_CRC32Copy,
90 4,
91 4,
92 sizeof(PHP_CRC32_CTX)
93 };
94
95
96
97
98
99
100
101
102