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