]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - 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 //-----------------------------------------------------------------------------
6 #define CRC_14443_A 0x6363 /* ITU-V.41 */
7 #define CRC_14443_B 0xFFFF /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
9 static unsigned short UpdateCrc14443(unsigned char ch
, unsigned short *lpwCrc
)
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);
18 static void ComputeCrc14443(int CrcType
, unsigned char *Data
, int Length
,
19 unsigned char *TransmitFirst
, unsigned char *TransmitSecond
)
21 unsigned char chBlock
;
22 unsigned short wCrc
=CrcType
;
26 UpdateCrc14443(chBlock
, &wCrc
);
29 if (CrcType
== CRC_14443_B
)
30 wCrc
= ~wCrc
; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
32 *TransmitFirst
= (unsigned char) (wCrc
& 0xFF);
33 *TransmitSecond
= (unsigned char) ((wCrc
>> 8) & 0xFF);