X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/e0c635d19c58423d88ae698788a31c865e5554ab..8de6b69d1ef8f20c9cd7baa79590ff7a61c7254f:/client/mifarehost.c diff --git a/client/mifarehost.c b/client/mifarehost.c index fc29e10e..f34759df 100644 --- a/client/mifarehost.c +++ b/client/mifarehost.c @@ -295,9 +295,12 @@ uint32_t ks3; uint32_t uid; // serial number uint32_t nt; // tag challenge +uint32_t nt_par; uint32_t nr_enc; // encrypted reader challenge uint32_t ar_enc; // encrypted reader response +uint32_t nr_ar_par; uint32_t at_enc; // encrypted tag response +uint32_t at_par; int isTraceCardEmpty(void) { return ((traceCard[0] == 0) && (traceCard[1] == 0) && (traceCard[2] == 0) && (traceCard[3] == 0)); @@ -401,7 +404,7 @@ void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *data, int len, bool i } -int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) { +int mfTraceDecode(uint8_t *data_src, int len, uint32_t parity, bool wantSaveToEmlFile) { uint8_t data[64]; if (traceState == TRACE_ERROR) return 1; @@ -419,7 +422,13 @@ int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) { switch (traceState) { case TRACE_IDLE: - // TODO: check packet crc16! + // check packet crc16! + if ((len >= 4) && (!CheckCrc14443(CRC_14443_A, data, len))) { + PrintAndLog("dec> CRC ERROR!!!"); + AddLogLine(logHexFileName, "dec> ", "CRC ERROR!!!"); + traceState = TRACE_ERROR; // do not decrypt the next commands + return 1; + } // AUTHENTICATION if ((len ==4) && ((data[0] == 0x60) || (data[0] == 0x61))) { @@ -498,6 +507,7 @@ int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) { traceState = TRACE_AUTH2; nt = bytes_to_num(data, 4); + nt_par = parity; return 0; } else { traceState = TRACE_ERROR; @@ -511,6 +521,7 @@ int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) { nr_enc = bytes_to_num(data, 4); ar_enc = bytes_to_num(data + 4, 4); + nr_ar_par = parity; return 0; } else { traceState = TRACE_ERROR; @@ -523,6 +534,7 @@ int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) { traceState = TRACE_IDLE; at_enc = bytes_to_num(data, 4); + at_par = parity; // decode key here) if (!traceCrypto1) {