]> cvs.zerfleddert.de Git - proxmark3-svn/blob - common/iso14443crc.c
Added Indala cloning. Fixed HID cloning bug
[proxmark3-svn] / common / iso14443crc.c
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
4 // the license.
5 //-----------------------------------------------------------------------------
6 // ISO14443 CRC calculation code.
7 //-----------------------------------------------------------------------------
8
9 #include "iso14443crc.h"
10
11 static unsigned short UpdateCrc14443(unsigned char ch, unsigned short *lpwCrc)
12 {
13 ch = (ch ^ (unsigned char) ((*lpwCrc) & 0x00FF));
14 ch = (ch ^ (ch << 4));
15 *lpwCrc = (*lpwCrc >> 8) ^ ((unsigned short) ch << 8) ^
16 ((unsigned short) ch << 3) ^ ((unsigned short) ch >> 4);
17 return (*lpwCrc);
18 }
19
20 void ComputeCrc14443(int CrcType,
21 unsigned char *Data, int Length,
22 unsigned char *TransmitFirst,
23 unsigned char *TransmitSecond)
24 {
25 unsigned char chBlock;
26 unsigned short wCrc=CrcType;
27
28 do {
29 chBlock = *Data++;
30 UpdateCrc14443(chBlock, &wCrc);
31 } while (--Length);
32
33 if (CrcType == CRC_14443_B)
34 wCrc = ~wCrc; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
35
36 *TransmitFirst = (unsigned char) (wCrc & 0xFF);
37 *TransmitSecond = (unsigned char) ((wCrc >> 8) & 0xFF);
38 return;
39 }
Impressum, Datenschutz