#include "iso14443a.h"\r
#include "crapto1.h"\r
#include "mifareutil.h"\r
+#include "parity.h"\r
#include "des.h"\r
\r
int MF_DBGLEVEL = MF_DBG_ALL;\r
data[i] = crypto1_byte(pcs, 0x00, 0) ^ data[i];\r
if((i&0x0007) == 0) \r
par[i>>3] = 0;\r
- par[i>>3] |= (((filter(pcs->odd) ^ oddparity(bt)) & 0x01)<<(7-(i&0x0007)));\r
+ par[i>>3] |= (((filter(pcs->odd) ^ oddparity8(bt)) & 0x01)<<(7-(i&0x0007)));\r
} \r
return;\r
}\r
for (pos = 0; pos < 4; pos++)\r
{\r
ecmd[pos] = crypto1_byte(pcs, 0x00, 0) ^ dcmd[pos];\r
- par[0] |= (((filter(pcs->odd) ^ oddparity(dcmd[pos])) & 0x01) << (7-pos));\r
+ par[0] |= (((filter(pcs->odd) ^ oddparity8(dcmd[pos])) & 0x01) << (7-pos));\r
} \r
\r
ReaderTransmitPar(ecmd, sizeof(ecmd), par, timing);\r
uint32_t pos;\r
uint8_t tmp4[4];\r
uint8_t par[1] = {0x00};\r
- byte_t nr[4];\r
+\r
+ // "random" reader nonce:\r
+ byte_t nr[4] = {0x55, 0x41, 0x49, 0x92};\r
+ //byte_t nr[4] = {0x01, 0x01, 0x01, 0x01};\r
+ \r
uint32_t nt, ntpp; // Supplied tag nonce\r
\r
uint8_t mf_nr_ar[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };\r
if (MF_DBGLEVEL >= 4) Dbprintf("rand tag nonce len: %x", len); \r
if (len != 4) return 1;\r
\r
- // "random" reader nonce:\r
- nr[0] = 0x55;\r
- nr[1] = 0x41;\r
- nr[2] = 0x49;\r
- nr[3] = 0x92; \r
- \r
// Save the tag nonce (nt)\r
nt = bytes_to_num(receivedAnswer, 4);\r
\r
for (pos = 0; pos < 4; pos++)\r
{\r
mf_nr_ar[pos] = crypto1_byte(pcs, nr[pos], 0) ^ nr[pos];\r
- par[0] |= (((filter(pcs->odd) ^ oddparity(nr[pos])) & 0x01) << (7-pos));\r
+ par[0] |= (((filter(pcs->odd) ^ oddparity8(nr[pos])) & 0x01) << (7-pos));\r
} \r
\r
// Skip 32 bits in pseudo random generator\r
{\r
nt = prng_successor(nt,8);\r
mf_nr_ar[pos] = crypto1_byte(pcs,0x00,0) ^ (nt & 0xff);\r
- par[0] |= (((filter(pcs->odd) ^ oddparity(nt & 0xff)) & 0x01) << (7-pos));\r
+ par[0] |= (((filter(pcs->odd) ^ oddparity8(nt & 0xff)) & 0x01) << (7-pos));\r
} \r
\r
// Transmit reader nonce and reader answer\r
if (MF_DBGLEVEL >= MF_DBG_EXTENDED)\r
Dbprintf("EV1 Auth : %02x%02x%02x%02x", key[0], key[1], key[2], key[3]);\r
len = mifare_sendcmd(0x1B, key, sizeof(key), resp, respPar, NULL);\r
- //len = mifare_sendcmd_short_mfuev1auth(NULL, 0, 0x1B, key, resp, respPar, NULL);\r
+\r
if (len != 4) {\r
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Cmd Error: %02x %u", resp[0], len);\r
return 0;\r
for (pos = 0; pos < 18; pos++)\r
{\r
d_block_enc[pos] = crypto1_byte(pcs, 0x00, 0) ^ d_block[pos];\r
- par[pos>>3] |= (((filter(pcs->odd) ^ oddparity(d_block[pos])) & 0x01) << (7 - (pos&0x0007)));\r
+ par[pos>>3] |= (((filter(pcs->odd) ^ oddparity8(d_block[pos])) & 0x01) << (7 - (pos&0x0007)));\r
} \r
\r
ReaderTransmitPar(d_block_enc, sizeof(d_block_enc), par, NULL);\r
}\r
return 0;\r
}\r
-\r
-int mifare_classic_halt(struct Crypto1State *pcs, uint32_t uid) \r
-{\r
+int mifare_classic_halt_ex(struct Crypto1State *pcs) {\r
uint16_t len; \r
- uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];\r
- uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];\r
+ uint8_t receivedAnswer[4];\r
+ uint8_t receivedAnswerPar[4];\r
\r
len = mifare_sendcmd_short(pcs, pcs == NULL ? false:true, 0x50, 0x00, receivedAnswer, receivedAnswerPar, NULL);\r
if (len != 0) {\r
- if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
- Dbprintf("halt error. response len: %x", len); \r
+ if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("halt error. response len: %x", len); \r
return 1;\r
}\r
-\r
return 0;\r
}\r
+int mifare_classic_halt(struct Crypto1State *pcs, uint32_t uid) {\r
+ return mifare_classic_halt_ex(pcs);\r
+}\r
\r
int mifare_ultra_halt()\r
{\r
\r
// work with emulator memory\r
void emlSetMem(uint8_t *data, int blockNum, int blocksCount) {\r
+ emlSetMem_xt(data, blockNum, blocksCount, 16);\r
+}\r
+\r
+void emlSetMem_xt(uint8_t *data, int blockNum, int blocksCount, int blockBtWidth) {\r
uint8_t* emCARD = BigBuf_get_EM_addr();\r
- memcpy(emCARD + blockNum * 16, data, blocksCount * 16);\r
+ memcpy(emCARD + blockNum * blockBtWidth, data, blocksCount * blockBtWidth);\r
}\r
\r
void emlGetMem(uint8_t *data, int blockNum, int blocksCount) {\r