uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE] = {0x00};\r
\r
uint32_t auth1_time, auth2_time;\r
- static uint16_t delta_time;\r
+ static uint16_t delta_time = 0;\r
\r
LED_A_ON();\r
LED_C_OFF();\r
rtr--;\r
continue;\r
};\r
+ auth2_time = (delta_time) ? auth1_time + delta_time : 0;\r
\r
- if (delta_time) {\r
- auth2_time = auth1_time + delta_time;\r
- } else {\r
- auth2_time = 0;\r
- }\r
if(mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_NESTED, &nt2, &auth2_time)) {\r
if (MF_DBGLEVEL >= 1) Dbprintf("Nested: Auth2 error");\r
rtr--;\r
\r
nttmp = prng_successor(nt1, 100); //NXP Mifare is typical around 840,but for some unlicensed/compatible mifare card this can be 160\r
for (i = 101; i < 1200; i++) {\r
- nttmp = prng_successor(nttmp, 1);\r
+ nttmp = prng_successor_one(nttmp);\r
if (nttmp == nt2) break;\r
}\r
\r
\r
// nested authentication\r
auth2_time = auth1_time + delta_time;\r
+\r
len = mifare_sendcmd_short(pcs, AUTH_NESTED, 0x60 + (targetKeyType & 0x01), targetBlockNo, receivedAnswer, par, &auth2_time);\r
if (len != 4) {\r
if (MF_DBGLEVEL >= 1) Dbprintf("Nested: Auth2 error len=%d", len);\r
if (MF_DBGLEVEL >= 3) Dbprintf("Nonce#%d: Testing nt1=%08x nt2enc=%08x nt2par=%02x", i+1, nt1, nt2, par[0]);\r
\r
// Parity validity check\r
- for (j = 0; j < 4; j++) {\r
- par_array[j] = (oddparity8(receivedAnswer[j]) != ((par[0] >> (7-j)) & 0x01));\r
- }\r
+// for (j = 0; j < 4; j++) {\r
+// par_array[j] = (oddparity8(receivedAnswer[j]) != ((par[0] >> (7-j)) & 0x01));\r
+// }\r
+ par_array[0] = (oddparity8(receivedAnswer[0]) != ((par[0] >> (7-0)) & 0x01));\r
+ par_array[1] = (oddparity8(receivedAnswer[1]) != ((par[0] >> (7-1)) & 0x01));\r
+ par_array[2] = (oddparity8(receivedAnswer[2]) != ((par[0] >> (7-2)) & 0x01));\r
+ par_array[3] = (oddparity8(receivedAnswer[3]) != ((par[0] >> (7-3)) & 0x01));\r
\r
ncount = 0;\r
nttest = prng_successor(nt1, dmin - 1);\r
for (j = dmin; j < dmax + 1; j++) {\r
- nttest = prng_successor(nttest, 1);\r
+ nttest = prng_successor_one(nttest);\r
ks1 = nt2 ^ nttest;\r
\r
if (valid_nonce(nttest, nt2, ks1, par_array)){\r
// ----------------------------- crypto1 destroy\r
crypto1_destroy(pcs);\r
\r
- byte_t buf[4 + 4 * 4];\r
- memcpy(buf, &cuid, 4);\r
+ byte_t buf[4 + 4 * 4] = {0};\r
+ num_to_bytes(cuid, 4, buf);\r
memcpy(buf+4, &target_nt[0], 4);\r
memcpy(buf+8, &target_ks[0], 4);\r
memcpy(buf+12, &target_nt[1], 4);\r
int OLD_MF_DBGLEVEL = MF_DBGLEVEL; \r
MF_DBGLEVEL = MF_DBG_NONE;\r
\r
+ LEDsoff();\r
LED_A_ON();\r
- LED_B_OFF();\r
- LED_C_OFF();\r
+ \r
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
\r
if (clearTrace) \r