1 //-----------------------------------------------------------------------------
2 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
3 // at your option, any later version. See the LICENSE.txt file for the text of
5 //-----------------------------------------------------------------------------
7 //-----------------------------------------------------------------------------
13 #define CRC16_POLY_CCITT 0x1021
14 #define CRC16_POLY_KERMIT 0x8408
15 #define CRC16_POLY_LEGIC 0xc6c6 //0x6363
16 #define CRC16_POLY_DNP 0x3d65
18 #define X25_CRC_CHECK ((uint16_t)(~0xF0B8 & 0xFFFF)) // use this for checking of a correct crc
35 uint16_t update_crc16_ex(uint16_t crc
, uint8_t c
, uint16_t polynomial
);
36 uint16_t update_crc16(uint16_t crc
, uint8_t c
);
37 uint16_t Crc16(uint8_t const *d
, size_t length
, uint16_t remainder
, uint16_t polynomial
, bool refin
, bool refout
);
39 uint16_t Crc16ex(CrcType_t ct
, const uint8_t *d
, size_t n
);
40 void compute_crc(CrcType_t ct
, const uint8_t *d
, size_t n
, uint8_t *first
, uint8_t *second
);
41 bool check_crc(CrcType_t ct
, const uint8_t *d
, size_t n
);
43 // Calculate CRC-16/CCITT-FALSE
44 uint16_t crc16_ccitt(uint8_t const *d
, size_t n
);
46 // Calculate CRC-16/KERMIT (FDX-B ISO11784/85) LF
47 uint16_t crc16_fdxb(uint8_t const *d
, size_t n
);
49 // Calculate CRC-16/KERMIT
50 uint16_t crc16_kermit(uint8_t const *d
, size_t n
);
52 // Calculate CRC-16/XMODEM (FeliCa)
53 uint16_t crc16_xmodem(uint8_t const *d
, size_t n
);
55 // Calculate CRC-16/X25 (ISO15693, ISO14443 CRC-B,ISO/IEC 13239)
56 uint16_t crc16_x25(uint8_t const *d
, size_t n
);
58 // Calculate CRC-16/CRC-A (ISO14443 CRC-A)
59 uint16_t crc16_a(uint8_t const *d
, size_t n
);
61 // Calculate CRC-16/iCLASS
62 uint16_t crc16_iclass(uint8_t const *d
, size_t n
);
64 // Calculate CRC-16/Legic
65 // the initial_value is based on the previous legic_Crc8 of the UID.
66 // ie: uidcrc = 0x78 then initial_value == 0x7878
67 uint16_t crc16_legic(uint8_t const *d
, size_t n
, uint8_t uidcrc
);
69 // table implementation
70 void init_table(CrcType_t crctype
);
71 void reset_table(void);
72 void generate_table(uint16_t polynomial
, bool refin
);
73 uint16_t crc16_fast(uint8_t const *d
, size_t n
, uint16_t initval
, bool refin
, bool refout
);