]> cvs.zerfleddert.de Git - proxmark3-svn/blame - common/crc.c
remove some straggling files and fix paths in cockpit batch files
[proxmark3-svn] / common / crc.c
CommitLineData
68d9d60a 1/*
2 * crc.c
3 *
4 * Generic CRC calculation code.
5 *
6 */
7
8#include "crc.h"
9
10void crc_init(crc_t *crc, int order, uint32_t polynom, uint32_t initial_value, uint32_t final_xor)
11{
12 crc->order = order;
13 crc->polynom = polynom;
14 crc->initial_value = initial_value;
15 crc->final_xor = final_xor;
16 crc->mask = (1L<<order)-1;
17 crc_clear(crc);
18}
19
20void crc_update(crc_t *crc, uint32_t data, int data_width)
21{
22 int i;
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;
28 }
29 data >>= 1;
30 }
31}
32
33void crc_clear(crc_t *crc)
34{
35 crc->state = crc->initial_value & crc->mask;
36}
37
38uint32_t crc_finish(crc_t *crc)
39{
40 return ( crc->state ^ crc->final_xor ) & crc->mask;
41}
Impressum, Datenschutz