]> git.zerfleddert.de Git - proxmark3-svn/blob - common/iso14443crc.c
250a4ee500eaac62d4e66c2d53e18ac95079b04e
[proxmark3-svn] / common / iso14443crc.c
1 #include "iso14443crc.h"
2
3 static unsigned short UpdateCrc14443(unsigned char ch, unsigned short *lpwCrc)
4 {
5 ch = (ch ^ (unsigned char) ((*lpwCrc) & 0x00FF));
6 ch = (ch ^ (ch << 4));
7 *lpwCrc = (*lpwCrc >> 8) ^ ((unsigned short) ch << 8) ^
8 ((unsigned short) ch << 3) ^ ((unsigned short) ch >> 4);
9 return (*lpwCrc);
10 }
11
12 void ComputeCrc14443(int CrcType,
13 unsigned char *Data, int Length,
14 unsigned char *TransmitFirst,
15 unsigned char *TransmitSecond)
16 {
17 unsigned char chBlock;
18 unsigned short wCrc=CrcType;
19
20 do {
21 chBlock = *Data++;
22 UpdateCrc14443(chBlock, &wCrc);
23 } while (--Length);
24
25 if (CrcType == CRC_14443_B)
26 wCrc = ~wCrc; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
27
28 *TransmitFirst = (unsigned char) (wCrc & 0xFF);
29 *TransmitSecond = (unsigned char) ((wCrc >> 8) & 0xFF);
30 return;
31 }
Impressum, Datenschutz