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 for (a_byte
const *p
= (a_byte
const *)pdata
; nbyte
; --nbyte
)
36 value
= table
[value
^ *p
++];
41 void a_crc16m_init(a_u16 table
[0x100], a_u16 poly
)
43 for (unsigned int c
= 0; c
!= 0x100; ++c
)
45 unsigned int value
= c
<< 8;
46 for (unsigned int b
= 8; b
; --b
)
48 unsigned int sig
= A_U16_C(0x8000) & value
;
50 if (sig
) { value
^= poly
; }
52 table
[c
] = (a_u16
)value
;
55 void a_crc16l_init(a_u16 table
[0x100], a_u16 poly
)
57 poly
= a_u16_rev(poly
);
58 for (unsigned int c
= 0; c
!= 0x100; ++c
)
60 unsigned int value
= c
;
61 for (unsigned int b
= 8; b
; --b
)
63 unsigned int sig
= value
& 1;
65 if (sig
) { value
^= poly
; }
67 table
[c
] = (a_u16
)value
;
70 a_u16
a_crc16m(a_u16
const table
[0x100], void const *pdata
, a_size nbyte
, a_u16 value
)
72 for (a_byte
const *p
= (a_byte
const *)pdata
; nbyte
; --nbyte
)
74 value
= (a_u16
)((value
<< 8) ^ table
[((value
>> 8) ^ *p
++) & 0xFF]);
78 a_u16
a_crc16l(a_u16
const table
[0x100], void const *pdata
, a_size nbyte
, a_u16 value
)
80 for (a_byte
const *p
= (a_byte
const *)pdata
; nbyte
; --nbyte
)
82 value
= (a_u16
)((value
>> 8) ^ table
[(value
^ *p
++) & 0xFF]);
87 void a_crc32m_init(a_u32 table
[0x100], a_u32 poly
)
89 for (a_u32 c
= 0; c
!= 0x100; ++c
)
91 a_u32 value
= c
<< 24;
92 for (unsigned int b
= 8; b
; --b
)
94 a_u32 sig
= A_U32_C(0x80000000) & value
;
96 if (sig
) { value
^= poly
; }
101 void a_crc32l_init(a_u32 table
[0x100], a_u32 poly
)
103 poly
= a_u32_rev(poly
);
104 for (unsigned int c
= 0; c
!= 0x100; ++c
)
107 for (unsigned int b
= 8; b
; --b
)
109 a_u32 sig
= value
& 1;
111 if (sig
) { value
^= poly
; }
116 a_u32
a_crc32m(a_u32
const table
[0x100], void const *pdata
, a_size nbyte
, a_u32 value
)
118 for (a_byte
const *p
= (a_byte
const *)pdata
; nbyte
; --nbyte
)
120 value
= (value
<< 8) ^ table
[((value
>> 24) ^ *p
++) & 0xFF];
124 a_u32
a_crc32l(a_u32
const table
[0x100], void const *pdata
, a_size nbyte
, a_u32 value
)
126 for (a_byte
const *p
= (a_byte
const *)pdata
; nbyte
; --nbyte
)
128 value
= (value
>> 8) ^ table
[(value
^ *p
++) & 0xFF];
133 void a_crc64m_init(a_u64 table
[0x100], a_u64 poly
)
135 for (a_u64 c
= 0; c
!= 0x100; ++c
)
137 a_u64 value
= c
<< 56;
138 for (unsigned int b
= 8; b
; --b
)
140 a_u64 sig
= A_U64_C(0x8000000000000000) & value
;
142 if (sig
) { value
^= poly
; }
147 void a_crc64l_init(a_u64 table
[0x100], a_u64 poly
)
149 poly
= a_u64_rev(poly
);
150 for (unsigned int c
= 0; c
!= 0x100; ++c
)
153 for (unsigned int b
= 8; b
; --b
)
155 a_u64 sig
= value
& 1;
157 if (sig
) { value
^= poly
; }
162 a_u64
a_crc64m(a_u64
const table
[0x100], void const *pdata
, a_size nbyte
, a_u64 value
)
164 for (a_byte
const *p
= (a_byte
const *)pdata
; nbyte
; --nbyte
)
166 value
= (value
<< 8) ^ table
[((value
>> 56) ^ *p
++) & 0xFF];
170 a_u64
a_crc64l(a_u64
const table
[0x100], void const *pdata
, a_size nbyte
, a_u64 value
)
172 for (a_byte
const *p
= (a_byte
const *)pdata
; nbyte
; --nbyte
)
174 value
= (value
>> 8) ^ table
[(value
^ *p
++) & 0xFF];