From ac88c435f637fbf82949565a9be6443b4f84f746 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 9 Apr 2019 10:12:15 +0200 Subject: [PATCH] remove old iso14443crc.c, fully replaced by crc16.c functions. --- armsrc/iso14443a.h | 2 +- armsrc/mifarecmd.h | 1 - armsrc/mifaredesfire.h | 1 - armsrc/mifaresim.c | 1 - armsrc/mifaresim.h | 4 ++++ armsrc/mifaresniff.c | 8 ++++++-- armsrc/mifaresniff.h | 1 - armsrc/mifareutil.h | 1 - client/cmdanalyse.c | 20 +++++++++---------- client/cmdhf14a.h | 1 - client/cmdhf15.c | 17 +++++++++++----- client/cmdhffelica.h | 1 - client/cmdhficlass.h | 2 +- client/cmdhfmf.h | 1 - client/cmdhfmfdes.h | 1 - client/scripting.c | 2 +- common/crc16.c | 4 ++-- common/crc16.h | 4 ++-- common/iso14443crc.c | 44 ------------------------------------------ common/iso14443crc.h | 19 ------------------ 20 files changed, 39 insertions(+), 96 deletions(-) delete mode 100644 common/iso14443crc.c delete mode 100644 common/iso14443crc.h diff --git a/armsrc/iso14443a.h b/armsrc/iso14443a.h index 254d8eded..ae3491825 100644 --- a/armsrc/iso14443a.h +++ b/armsrc/iso14443a.h @@ -104,7 +104,7 @@ typedef struct { #endif #ifndef CheckCrc14A -# define CheckCrc14A(data, len) check_crc(CRC_14443_A, (data), (len)) +# define CheckCrc14A(data, len) check_crc(CRC_14443_A, (data), (len)) #endif void GetParity(const uint8_t *pbtCmd, uint16_t len, uint8_t *par); diff --git a/armsrc/mifarecmd.h b/armsrc/mifarecmd.h index 51ed76ca5..5e4a5cf97 100644 --- a/armsrc/mifarecmd.h +++ b/armsrc/mifarecmd.h @@ -17,7 +17,6 @@ #include "apps.h" #include "util.h" #include "string.h" -#include "iso14443crc.h" #include "iso14443a.h" #include "crapto1/crapto1.h" #include "mifareutil.h" diff --git a/armsrc/mifaredesfire.h b/armsrc/mifaredesfire.h index 40c623ef9..7547dfcb2 100644 --- a/armsrc/mifaredesfire.h +++ b/armsrc/mifaredesfire.h @@ -6,7 +6,6 @@ #include "apps.h" #include "string.h" #include "BigBuf.h" -#include "iso14443crc.h" #include "iso14443a.h" #include "desfire_key.h" #include "mifareutil.h" diff --git a/armsrc/mifaresim.c b/armsrc/mifaresim.c index c6edeba43..9cfb238f6 100644 --- a/armsrc/mifaresim.c +++ b/armsrc/mifaresim.c @@ -22,7 +22,6 @@ #include "iso14443a.h" #include "mifaresim.h" -#include "iso14443crc.h" #include "crapto1/crapto1.h" #include "BigBuf.h" #include "string.h" diff --git a/armsrc/mifaresim.h b/armsrc/mifaresim.h index 65eabdf68..cbd5a4108 100644 --- a/armsrc/mifaresim.h +++ b/armsrc/mifaresim.h @@ -15,6 +15,10 @@ #include +#ifndef CheckCrc14A +# define CheckCrc14A(data, len) check_crc(CRC_14443_A, (data), (len)) +#endif + void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *datain); #define AC_DATA_READ 0 diff --git a/armsrc/mifaresniff.c b/armsrc/mifaresniff.c index 0e75aac35..317d67547 100644 --- a/armsrc/mifaresniff.c +++ b/armsrc/mifaresniff.c @@ -10,6 +10,10 @@ #include "mifaresniff.h" +#ifndef CheckCrc14A +# define CheckCrc14A(data, len) check_crc(CRC_14443_A, (data), (len)) +#endif + //static int sniffState = SNF_INIT; static uint8_t sniffUIDType = 0; static uint8_t sniffUID[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -229,7 +233,7 @@ bool RAMFUNC MfSniffLogic(const uint8_t *data, uint16_t len, uint8_t *parity, ui if ( !reader ) break; if ( len != 9 ) break; - if ( !CheckCrc14443(CRC_14443_A, data, 9)) break; + if ( !CheckCrc14A(data, 9)) break; if ( data[1] != 0x70 ) break; Dbprintf("[!] UID | %x", data[0]); @@ -266,7 +270,7 @@ bool RAMFUNC MfSniffLogic(const uint8_t *data, uint16_t len, uint8_t *parity, ui } case SNF_SAK:{ // SAK from card? - if ((!reader) && (len == 3) && (CheckCrc14443(CRC_14443_A, data, 3))) { + if ((!reader) && (len == 3) && (CheckCrc14A(data, 3))) { sniffSAK = data[0]; // CL2 UID part to be expected if (( sniffSAK == 0x04) && (sniffUIDType == SNF_UID_4)) { diff --git a/armsrc/mifaresniff.h b/armsrc/mifaresniff.h index 9b5cb8609..198d14daf 100644 --- a/armsrc/mifaresniff.h +++ b/armsrc/mifaresniff.h @@ -15,7 +15,6 @@ #include "apps.h" #include "util.h" #include "string.h" -#include "iso14443crc.h" #include "iso14443a.h" #include "crapto1/crapto1.h" #include "mifareutil.h" diff --git a/armsrc/mifareutil.h b/armsrc/mifareutil.h index 570af2629..38494ceb0 100644 --- a/armsrc/mifareutil.h +++ b/armsrc/mifareutil.h @@ -17,7 +17,6 @@ #include "parity.h" #include "util.h" #include "string.h" -#include "iso14443crc.h" #include "iso14443a.h" #include "crapto1/crapto1.h" #include "des.h" diff --git a/client/cmdanalyse.c b/client/cmdanalyse.c index 3bd3f08cb..c04ca2a3b 100644 --- a/client/cmdanalyse.c +++ b/client/cmdanalyse.c @@ -300,7 +300,7 @@ int CmdAnalyseCRC(const char *Cmd) { // ISO14443 crc B compute_crc(CRC_14443_B, data, len, &b1, &b2); uint16_t crcBB_1 = b1 << 8 | b2; - uint16_t bbb = Crc(CRC_14443_B, data, len); + uint16_t bbb = Crc16ex(CRC_14443_B, data, len); PrintAndLogEx(NORMAL, "ISO14443 crc B | %04x == %04x \n", crcBB_1, bbb); @@ -321,40 +321,40 @@ int CmdAnalyseCRC(const char *Cmd) { PrintAndLogEx(NORMAL, "CRC16 based\n\n"); // input from commandline - PrintAndLogEx(NORMAL, "CCITT | %X (29B1 expected)", Crc(CRC_CCITT, dataStr, sizeof(dataStr))); + PrintAndLogEx(NORMAL, "CCITT | %X (29B1 expected)", Crc16ex(CRC_CCITT, dataStr, sizeof(dataStr))); uint8_t poll[] = {0xb2, 0x4d, 0x12, 0x01, 0x01, 0x2e, 0x3d, 0x17, 0x26, 0x47, 0x80, 0x95, 0x00, 0xf1, 0x00, 0x00, 0x00, 0x01, 0x43, 0x00, 0xb3, 0x7f}; - PrintAndLogEx(NORMAL, "FeliCa | %04X (B37F expected)", Crc(CRC_FELICA, poll + 2, sizeof(poll) - 4)); - PrintAndLogEx(NORMAL, "FeliCa | %04X (0000 expected)", Crc(CRC_FELICA, poll + 2, sizeof(poll) - 2)); + PrintAndLogEx(NORMAL, "FeliCa | %04X (B37F expected)", Crc16ex(CRC_FELICA, poll + 2, sizeof(poll) - 4)); + PrintAndLogEx(NORMAL, "FeliCa | %04X (0000 expected)", Crc16ex(CRC_FELICA, poll + 2, sizeof(poll) - 2)); uint8_t sel_corr[] = { 0x40, 0xe1, 0xe1, 0xff, 0xfe, 0x5f, 0x02, 0x3c, 0x43, 0x01}; - PrintAndLogEx(NORMAL, "iCLASS | %04x (0143 expected)", Crc(CRC_ICLASS, sel_corr, sizeof(sel_corr) - 2)); + PrintAndLogEx(NORMAL, "iCLASS | %04x (0143 expected)", Crc16ex(CRC_ICLASS, sel_corr, sizeof(sel_corr) - 2)); PrintAndLogEx(NORMAL, "---------------------------------------------------------------\n\n\n"); // ISO14443 crc A compute_crc(CRC_14443_A, dataStr, sizeof(dataStr), &b1, &b2); uint16_t crcAA = b1 << 8 | b2; - PrintAndLogEx(NORMAL, "ISO14443 crc A | %04x or %04x (BF05 expected)\n", crcAA, Crc(CRC_14443_A, dataStr, sizeof(dataStr))); + PrintAndLogEx(NORMAL, "ISO14443 crc A | %04x or %04x (BF05 expected)\n", crcAA, Crc16ex(CRC_14443_A, dataStr, sizeof(dataStr))); // ISO14443 crc B compute_crc(CRC_14443_B, dataStr, sizeof(dataStr), &b1, &b2); uint16_t crcBB = b1 << 8 | b2; - PrintAndLogEx(NORMAL, "ISO14443 crc B | %04x or %04x (906E expected)\n", crcBB, Crc(CRC_14443_B, dataStr, sizeof(dataStr))); + PrintAndLogEx(NORMAL, "ISO14443 crc B | %04x or %04x (906E expected)\n", crcBB, Crc16ex(CRC_14443_B, dataStr, sizeof(dataStr))); // ISO15693 crc (x.25) compute_crc(CRC_15693, dataStr, sizeof(dataStr), &b1, &b2); uint16_t crcCC = b1 << 8 | b2; - PrintAndLogEx(NORMAL, "ISO15693 crc X25| %04x or %04x (906E expected)\n", crcCC, Crc(CRC_15693, dataStr, sizeof(dataStr))); + PrintAndLogEx(NORMAL, "ISO15693 crc X25| %04x or %04x (906E expected)\n", crcCC, Crc16ex(CRC_15693, dataStr, sizeof(dataStr))); // ICLASS compute_crc(CRC_ICLASS, dataStr, sizeof(dataStr), &b1, &b2); uint16_t crcDD = b1 << 8 | b2; - PrintAndLogEx(NORMAL, "ICLASS crc | %04x or %04x\n", crcDD, Crc(CRC_ICLASS, dataStr, sizeof(dataStr))); + PrintAndLogEx(NORMAL, "ICLASS crc | %04x or %04x\n", crcDD, Crc16ex(CRC_ICLASS, dataStr, sizeof(dataStr))); // FeliCa compute_crc(CRC_FELICA, dataStr, sizeof(dataStr), &b1, &b2); uint16_t crcEE = b1 << 8 | b2; - PrintAndLogEx(NORMAL, "FeliCa | %04x or %04x (31C3 expected)\n", crcEE, Crc(CRC_FELICA, dataStr, sizeof(dataStr))); + PrintAndLogEx(NORMAL, "FeliCa | %04x or %04x (31C3 expected)\n", crcEE, Crc16ex(CRC_FELICA, dataStr, sizeof(dataStr))); free(data); return 0; diff --git a/client/cmdhf14a.h b/client/cmdhf14a.h index e218a398f..263bb7e9f 100644 --- a/client/cmdhf14a.h +++ b/client/cmdhf14a.h @@ -24,7 +24,6 @@ #include "util.h" #include "cmdparser.h" #include "cmdmain.h" -#include "iso14443crc.h" #include "mifare.h" #include "cmdhfmf.h" #include "cmdhfmfu.h" diff --git a/client/cmdhf15.c b/client/cmdhf15.c index 25126f693..51f7a0654 100644 --- a/client/cmdhf15.c +++ b/client/cmdhf15.c @@ -29,12 +29,19 @@ #define Logic1 Iso15693Logic1 #define FrameEOF Iso15693FrameEOF -#define Crc15(data, len) Crc(CRC_15693, (data), (len)) -#define CheckCrc15(data, len) check_crc(CRC_15693, (data), (len)) -#define AddCrc15(data, len) compute_crc(CRC_15693, (data), (len), (data)+(len), (data)+(len)+1) - -#define sprintUID(target, uid) Iso15693sprintUID((target), (uid)) +#ifndef Crc15 +# define Crc15(data, len) Crc16ex(CRC_15693, (data), (len)) +#endif +#ifndef CheckCrc15 +# define CheckCrc15(data, len) check_crc(CRC_15693, (data), (len)) +#endif +#ifndef AddCrc15 +#define AddCrc15(data, len) compute_crc(CRC_15693, (data), (len), (data)+(len), (data)+(len)+1) +#endif +#ifndef sprintUID +# define sprintUID(target, uid) Iso15693sprintUID((target), (uid)) +#endif // structure and database for uid -> tagtype lookups typedef struct { uint64_t uid; diff --git a/client/cmdhffelica.h b/client/cmdhffelica.h index 6eeb5b44f..9dfd78b0b 100644 --- a/client/cmdhffelica.h +++ b/client/cmdhffelica.h @@ -22,7 +22,6 @@ #include "util.h" #include "cmdparser.h" #include "comms.h" // getfromdevice -#include "iso14443crc.h" #include "cmdhf.h" // list cmd #include "mifare.h" // felica_card_select_t struct diff --git a/client/cmdhficlass.h b/client/cmdhficlass.h index 01dfd0076..616a7d312 100644 --- a/client/cmdhficlass.h +++ b/client/cmdhficlass.h @@ -15,7 +15,7 @@ #include #include #include -#include "iso14443crc.h" // Can also be used for iClass, using 0xE012 as CRC-type +//#include "iso14443crc.h" // Can also be used for iClass, using 0xE012 as CRC-type #include "proxmark3.h" #include "ui.h" #include "cmdparser.h" diff --git a/client/cmdhfmf.h b/client/cmdhfmf.h index 0e471580b..6de87291f 100644 --- a/client/cmdhfmf.h +++ b/client/cmdhfmf.h @@ -18,7 +18,6 @@ #include #include #include "proxmark3.h" -#include "iso14443crc.h" #include "ui.h" #include "cmdparser.h" #include "common.h" diff --git a/client/cmdhfmfdes.h b/client/cmdhfmfdes.h index 774a2f3e3..dff5294a5 100644 --- a/client/cmdhfmfdes.h +++ b/client/cmdhfmfdes.h @@ -18,7 +18,6 @@ #include "proxmark3.h" #include "../include/common.h" #include "../include/mifare.h" -#include "iso14443crc.h" #include "ui.h" #include "cmdparser.h" #include "util.h" diff --git a/client/scripting.c b/client/scripting.c index 9c84bbf93..ed692c728 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -467,7 +467,7 @@ static int l_crc16(lua_State *L) { size_t size; const char *p_str = luaL_checklstring(L, 1, &size); - uint16_t checksum = Crc(CRC_CCITT, (uint8_t *) p_str, size); + uint16_t checksum = Crc16ex(CRC_CCITT, (uint8_t *) p_str, size); lua_pushunsigned(L, checksum); return 1; } diff --git a/common/crc16.c b/common/crc16.c index 1396c0fe8..89afdf02c 100644 --- a/common/crc16.c +++ b/common/crc16.c @@ -129,7 +129,7 @@ uint16_t update_crc16(uint16_t crc, uint8_t c) { } // two ways. msb or lsb loop. -uint16_t crc16(uint8_t const *d, size_t length, uint16_t remainder, uint16_t polynomial, bool refin, bool refout) { +uint16_t Crc16(uint8_t const *d, size_t length, uint16_t remainder, uint16_t polynomial, bool refin, bool refout) { if (length == 0) return (~remainder); @@ -191,7 +191,7 @@ void compute_crc(CrcType_t ct, const uint8_t *d, size_t n, uint8_t *first, uint8 *first = (crc & 0xFF); *second = ((crc >> 8) & 0xFF); } -uint16_t Crc(CrcType_t ct, const uint8_t *d, size_t n) { +uint16_t Crc16ex(CrcType_t ct, const uint8_t *d, size_t n) { // can't calc a crc on less than 3 byte. (1byte + 2 crc bytes) if (n < 3) return 0; diff --git a/common/crc16.h b/common/crc16.h index 843cc07e5..c5c486df9 100644 --- a/common/crc16.h +++ b/common/crc16.h @@ -32,9 +32,9 @@ typedef enum { uint16_t update_crc16_ex(uint16_t crc, uint8_t c, uint16_t polynomial); uint16_t update_crc16(uint16_t crc, uint8_t c); -uint16_t crc16(uint8_t const *d, size_t length, uint16_t remainder, uint16_t polynomial, bool refin, bool refout); +uint16_t Crc16(uint8_t const *d, size_t length, uint16_t remainder, uint16_t polynomial, bool refin, bool refout); -uint16_t Crc(CrcType_t ct, const uint8_t *d, size_t n); +uint16_t Crc16ex(CrcType_t ct, const uint8_t *d, size_t n); void compute_crc(CrcType_t ct, const uint8_t *d, size_t n, uint8_t *first, uint8_t *second); bool check_crc(CrcType_t ct, const uint8_t *d, size_t n); diff --git a/common/iso14443crc.c b/common/iso14443crc.c deleted file mode 100644 index d0884cf39..000000000 --- a/common/iso14443crc.c +++ /dev/null @@ -1,44 +0,0 @@ -//----------------------------------------------------------------------------- -// 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" - - -uint16_t UpdateCrc14443(uint8_t b, uint16_t *crc) { - b = (b ^ (uint8_t)((*crc) & 0x00FF)); - b = (b ^ (b << 4)); - *crc = (*crc >> 8) ^ ((uint16_t) b << 8) ^ ((uint16_t) b << 3) ^ ((uint16_t) b >> 4); - return (*crc); -} - -void ComputeCrc14443(uint16_t CrcType, const uint8_t *data, int length, - uint8_t *TransmitFirst, uint8_t *TransmitSecond) { - uint8_t b; - uint16_t crc = CrcType; - - do { - b = *data++; - UpdateCrc14443(b, &crc); - } while (--length); - - if (CrcType == CRC_14443_B) - crc = ~crc; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */ - - *TransmitFirst = (uint8_t)(crc & 0xFF); - *TransmitSecond = (uint8_t)((crc >> 8) & 0xFF); - return; -} - -bool CheckCrc14443(uint16_t CrcType, const uint8_t *data, int length) { - if (length < 3) return false; - uint8_t b1, b2; - ComputeCrc14443(CrcType, data, length - 2, &b1, &b2); - if ((b1 == data[length - 2]) && (b2 == data[length - 1])) - return true; - return false; -} diff --git a/common/iso14443crc.h b/common/iso14443crc.h deleted file mode 100644 index 36c4be2f6..000000000 --- a/common/iso14443crc.h +++ /dev/null @@ -1,19 +0,0 @@ -//----------------------------------------------------------------------------- -// 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. -//----------------------------------------------------------------------------- - -#ifndef __ISO14443CRC_H -#define __ISO14443CRC_H -#include "common.h" - -//----------------------------------------------------------------------------- -// Routines to compute the CRCs (two different flavours, just for confusion) -// required for ISO 14443, swiped directly from the spec. - -uint16_t UpdateCrc14443(uint8_t b, uint16_t *crc); - -#endif