]>
git.zerfleddert.de Git - proxmark3-svn/blob - common/crc.c
4 * Generic CRC calculation code.
10 void crc_init(crc_t
*crc
, int order
, uint32_t polynom
, uint32_t initial_value
, uint32_t final_xor
)
13 crc
->polynom
= polynom
;
14 crc
->initial_value
= initial_value
;
15 crc
->final_xor
= final_xor
;
16 crc
->mask
= (1L<<order
)-1;
20 void crc_update(crc_t
*crc
, uint32_t data
, int data_width
)
23 for(i
=0; i
<data_width
; i
++) {
24 int oldstate
= crc
->state
;
25 crc
->state
= crc
->state
>> 1;
26 if( (oldstate
^data
) & 1 ) {
27 crc
->state
^= crc
->polynom
;
33 void crc_clear(crc_t
*crc
)
35 crc
->state
= crc
->initial_value
& crc
->mask
;
38 uint32_t crc_finish(crc_t
*crc
)
40 return ( crc
->state
^ crc
->final_xor
) & crc
->mask
;