]> cvs.zerfleddert.de Git - proxmark3-svn/blame - common/iso14443_crc.c
Add forgotten file
[proxmark3-svn] / common / iso14443_crc.c
CommitLineData
6658905f 1//-----------------------------------------------------------------------------\r
2// Routines to compute the CRCs (two different flavours, just for confusion)\r
3// required for ISO 14443, swiped directly from the spec.\r
4//-----------------------------------------------------------------------------\r
5\r
6#define CRC_14443_A 0x6363 /* ITU-V.41 */\r
fb25b483 7#define CRC_14443_B 0xFFFF /* ISO/IEC 13239 (formerly ISO/IEC 3309) */\r
6658905f 8\r
9static unsigned short UpdateCrc14443(unsigned char ch, unsigned short *lpwCrc)\r
10{\r
11 ch = (ch ^ (unsigned char) ((*lpwCrc) & 0x00FF));\r
12 ch = (ch ^ (ch << 4));\r
13 *lpwCrc = (*lpwCrc >> 8) ^ ((unsigned short) ch << 8) ^\r
14 ((unsigned short) ch << 3) ^ ((unsigned short) ch >> 4);\r
15 return (*lpwCrc);\r
16}\r
17\r
18static void ComputeCrc14443(int CrcType, BYTE *Data, int Length,\r
19 BYTE *TransmitFirst, BYTE *TransmitSecond)\r
20{\r
21 unsigned char chBlock;\r
22 unsigned short wCrc=CrcType;\r
23\r
24 do {\r
25 chBlock = *Data++;\r
26 UpdateCrc14443(chBlock, &wCrc);\r
27 } while (--Length);\r
28\r
29 if (CrcType == CRC_14443_B)\r
30 wCrc = ~wCrc; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */\r
31\r
32 *TransmitFirst = (BYTE) (wCrc & 0xFF);\r
33 *TransmitSecond = (BYTE) ((wCrc >> 8) & 0xFF);\r
34 return;\r
35}\r
Impressum, Datenschutz