3 void a_crc8m_init(a_u8 table
[0x100], a_u8 poly
)
5 for (unsigned int c
= 0; c
!= 0x100; ++c
)
7 unsigned int value
= c
;
8 for (unsigned int b
= 8; b
; --b
)
10 unsigned int sig
= A_U8_C(0x80) & value
;
12 if (sig
) { value
^= poly
; }
14 table
[c
] = (a_u8
)value
;
17 void a_crc8l_init(a_u8 table
[0x100], a_u8 poly
)
19 poly
= a_u8_rev(poly
);
20 for (unsigned int c
= 0; c
!= 0x100; ++c
)
22 unsigned int value
= c
;
23 for (unsigned int b
= 8; b
; --b
)
25 unsigned int sig
= value
& 1;
27 if (sig
) { value
^= poly
; }
29 table
[c
] = (a_u8
)value
;
32 a_u8
a_crc8(a_u8
const table
[0x100], void const *pdata
, a_size nbyte
, a_u8 value
)
34 a_byte
const *p
= (a_byte
const *)pdata
;
35 a_byte
const *q
= (a_byte
const *)pdata
+ nbyte
;
36 while (p
!= q
) { value
= table
[value
^ *p
++]; }
40 void a_crc16m_init(a_u16 table
[0x100], a_u16 poly
)
42 for (unsigned int c
= 0; c
!= 0x100; ++c
)
44 unsigned int value
= c
<< 8;
45 for (unsigned int b
= 8; b
; --b
)
47 unsigned int sig
= A_U16_C(0x8000) & value
;
49 if (sig
) { value
^= poly
; }
51 table
[c
] = (a_u16
)value
;
54 void a_crc16l_init(a_u16 table
[0x100], a_u16 poly
)
56 poly
= a_u16_rev(poly
);
57 for (unsigned int c
= 0; c
!= 0x100; ++c
)
59 unsigned int value
= c
;
60 for (unsigned int b
= 8; b
; --b
)
62 unsigned int sig
= value
& 1;
64 if (sig
) { value
^= poly
; }
66 table
[c
] = (a_u16
)value
;
69 a_u16
a_crc16m(a_u16
const table
[0x100], void const *pdata
, a_size nbyte
, a_u16 value
)
71 a_byte
const *p
= (a_byte
const *)pdata
;
72 a_byte
const *q
= (a_byte
const *)pdata
+ nbyte
;
73 while (p
!= q
) { value
= (a_u16
)((value
<< 8) ^ table
[((value
>> 8) ^ *p
++) & 0xFF]); }
76 a_u16
a_crc16l(a_u16
const table
[0x100], void const *pdata
, a_size nbyte
, a_u16 value
)
78 a_byte
const *p
= (a_byte
const *)pdata
;
79 a_byte
const *q
= (a_byte
const *)pdata
+ nbyte
;
80 while (p
!= q
) { value
= (a_u16
)((value
>> 8) ^ table
[(value
^ *p
++) & 0xFF]); }
84 void a_crc32m_init(a_u32 table
[0x100], a_u32 poly
)
86 for (a_u32 c
= 0; c
!= 0x100; ++c
)
88 a_u32 value
= c
<< 24;
89 for (unsigned int b
= 8; b
; --b
)
91 a_u32 sig
= A_U32_C(0x80000000) & value
;
93 if (sig
) { value
^= poly
; }
98 void a_crc32l_init(a_u32 table
[0x100], a_u32 poly
)
100 poly
= a_u32_rev(poly
);
101 for (unsigned int c
= 0; c
!= 0x100; ++c
)
104 for (unsigned int b
= 8; b
; --b
)
106 a_u32 sig
= value
& 1;
108 if (sig
) { value
^= poly
; }
113 a_u32
a_crc32m(a_u32
const table
[0x100], void const *pdata
, a_size nbyte
, a_u32 value
)
115 a_byte
const *p
= (a_byte
const *)pdata
;
116 a_byte
const *q
= (a_byte
const *)pdata
+ nbyte
;
117 while (p
!= q
) { value
= (value
<< 8) ^ table
[((value
>> 24) ^ *p
++) & 0xFF]; }
120 a_u32
a_crc32l(a_u32
const table
[0x100], void const *pdata
, a_size nbyte
, a_u32 value
)
122 a_byte
const *p
= (a_byte
const *)pdata
;
123 a_byte
const *q
= (a_byte
const *)pdata
+ nbyte
;
124 while (p
!= q
) { value
= (value
>> 8) ^ table
[(value
^ *p
++) & 0xFF]; }
128 void a_crc64m_init(a_u64 table
[0x100], a_u64 poly
)
130 for (a_u64 c
= 0; c
!= 0x100; ++c
)
132 a_u64 value
= c
<< 56;
133 for (unsigned int b
= 8; b
; --b
)
135 a_u64 sig
= A_U64_C(0x8000000000000000) & value
;
137 if (sig
) { value
^= poly
; }
142 void a_crc64l_init(a_u64 table
[0x100], a_u64 poly
)
144 poly
= a_u64_rev(poly
);
145 for (unsigned int c
= 0; c
!= 0x100; ++c
)
148 for (unsigned int b
= 8; b
; --b
)
150 a_u64 sig
= value
& 1;
152 if (sig
) { value
^= poly
; }
157 a_u64
a_crc64m(a_u64
const table
[0x100], void const *pdata
, a_size nbyte
, a_u64 value
)
159 a_byte
const *p
= (a_byte
const *)pdata
;
160 a_byte
const *q
= (a_byte
const *)pdata
+ nbyte
;
161 while (p
!= q
) { value
= (value
<< 8) ^ table
[((value
>> 56) ^ *p
++) & 0xFF]; }
164 a_u64
a_crc64l(a_u64
const table
[0x100], void const *pdata
, a_size nbyte
, a_u64 value
)
166 a_byte
const *p
= (a_byte
const *)pdata
;
167 a_byte
const *q
= (a_byte
const *)pdata
+ nbyte
;
168 while (p
!= q
) { value
= (value
>> 8) ^ table
[(value
^ *p
++) & 0xFF]; }