1 //-----------------------------------------------------------------------------
2 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // See LICENSE.txt for the text of the license.
15 //-----------------------------------------------------------------------------
17 //-----------------------------------------------------------------------------
23 #define CRC16_POLY_CCITT 0x1021
24 #define CRC16_POLY_KERMIT 0x8408
25 #define CRC16_POLY_LEGIC 0xc6c6 //0x6363
26 #define CRC16_POLY_LEGIC_16 0x002d
27 #define CRC16_POLY_DNP 0x3d65
29 #define X25_CRC_CHECK ((uint16_t)(~0xF0B8 & 0xFFFF)) // use this for checking of a correct crc
48 uint16_t update_crc16_ex(uint16_t crc
, uint8_t c
, uint16_t polynomial
);
49 uint16_t update_crc16(uint16_t crc
, uint8_t c
);
50 uint16_t Crc16(uint8_t const *d
, size_t length
, uint16_t remainder
, uint16_t polynomial
, bool refin
, bool refout
);
52 uint16_t Crc16ex(CrcType_t ct
, const uint8_t *d
, size_t n
);
53 void compute_crc(CrcType_t ct
, const uint8_t *d
, size_t n
, uint8_t *first
, uint8_t *second
);
54 bool check_crc(CrcType_t ct
, const uint8_t *d
, size_t n
);
56 // Calculate CRC-16/CCITT-FALSE
57 uint16_t crc16_ccitt(uint8_t const *d
, size_t n
);
59 // Calculate CRC-16/KERMIT (FDX-B ISO11784/85) LF
60 uint16_t crc16_fdxb(uint8_t const *d
, size_t n
);
62 // Calculate CRC-16/KERMIT
63 uint16_t crc16_kermit(uint8_t const *d
, size_t n
);
65 // Calculate CRC-16/XMODEM (FeliCa)
66 uint16_t crc16_xmodem(uint8_t const *d
, size_t n
);
68 // Calculate CRC-16/X25 (ISO15693, ISO14443 CRC-B,ISO/IEC 13239)
69 uint16_t crc16_x25(uint8_t const *d
, size_t n
);
71 // Calculate CRC-16/CRC-A (ISO14443 CRC-A)
72 uint16_t crc16_a(uint8_t const *d
, size_t n
);
74 // Calculate CRC-16/iCLASS
75 uint16_t crc16_iclass(uint8_t const *d
, size_t n
);
77 // Calculate CRC-16/Legic
78 // the initial_value is based on the previous legic_Crc8 of the UID.
79 // ie: uidcrc = 0x78 then initial_value == 0x7878
80 uint16_t crc16_legic(uint8_t const *d
, size_t n
, uint8_t uidcrc
);
82 // Calculate CRC-16/ Philips.
83 uint16_t crc16_philips(uint8_t const *d
, size_t n
);
85 // table implementation
86 void init_table(CrcType_t crctype
);
87 void reset_table(void);
88 void generate_table(uint16_t polynomial
, bool refin
);
89 uint16_t crc16_fast(uint8_t const *d
, size_t n
, uint16_t initval
, bool refin
, bool refout
);