mirror of
https://github.com/Proxmark/proxmark3.git
synced 2024-11-11 18:17:46 +08:00
bd20f8f478
I have kept whatever copyright notices exist. Please add your own copyright notice if you have made any nontrivial changes or additions to the code. There are several files without any attribution, currently.
39 lines
1.4 KiB
C
39 lines
1.4 KiB
C
//-----------------------------------------------------------------------------
|
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
|
// the license.
|
|
//-----------------------------------------------------------------------------
|
|
// ISO14443 CRC calculation code.
|
|
//-----------------------------------------------------------------------------
|
|
|
|
#include "iso14443crc.h"
|
|
|
|
static unsigned short UpdateCrc14443(unsigned char ch, unsigned short *lpwCrc)
|
|
{
|
|
ch = (ch ^ (unsigned char) ((*lpwCrc) & 0x00FF));
|
|
ch = (ch ^ (ch << 4));
|
|
*lpwCrc = (*lpwCrc >> 8) ^ ((unsigned short) ch << 8) ^
|
|
((unsigned short) ch << 3) ^ ((unsigned short) ch >> 4);
|
|
return (*lpwCrc);
|
|
}
|
|
|
|
void ComputeCrc14443(int CrcType,
|
|
unsigned char *Data, int Length,
|
|
unsigned char *TransmitFirst,
|
|
unsigned char *TransmitSecond)
|
|
{
|
|
unsigned char chBlock;
|
|
unsigned short wCrc=CrcType;
|
|
|
|
do {
|
|
chBlock = *Data++;
|
|
UpdateCrc14443(chBlock, &wCrc);
|
|
} while (--Length);
|
|
|
|
if (CrcType == CRC_14443_B)
|
|
wCrc = ~wCrc; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
|
|
|
|
*TransmitFirst = (unsigned char) (wCrc & 0xFF);
|
|
*TransmitSecond = (unsigned char) ((wCrc >> 8) & 0xFF);
|
|
return;
|
|
}
|