\r
\r
// Darkside attack (hf mf mifare)\r
-static uint32_t nonce2key(uint32_t uid, uint32_t nt, uint32_t nr, uint64_t par_info, uint64_t ks_info, uint64_t **keys) {\r
+static uint32_t nonce2key(uint32_t uid, uint32_t nt, uint32_t nr, uint32_t ar, uint64_t par_info, uint64_t ks_info, uint64_t **keys) {\r
struct Crypto1State *states;\r
- uint32_t i, pos, rr; //nr_diff;\r
+ uint32_t i, pos;\r
uint8_t bt, ks3x[8], par[8][8];\r
uint64_t key_recovered;\r
- static uint64_t *keylist;\r
- rr = 0;\r
+ uint64_t *keylist;\r
\r
// Reset the last three significant bits of the reader nonce\r
nr &= 0xffffff1f;\r
}\r
}\r
\r
- states = lfsr_common_prefix(nr, rr, ks3x, par, (par_info == 0));\r
+ states = lfsr_common_prefix(nr, ar, ks3x, par, (par_info == 0));\r
\r
if (states == NULL) {\r
*keys = NULL;\r
int mfDarkside(uint64_t *key)\r
{\r
uint32_t uid = 0;\r
- uint32_t nt = 0, nr = 0;\r
+ uint32_t nt = 0, nr = 0, ar = 0;\r
uint64_t par_list = 0, ks_list = 0;\r
uint64_t *keylist = NULL, *last_keylist = NULL;\r
uint32_t keycount = 0;\r
nt = (uint32_t)bytes_to_num(resp.d.asBytes + 4, 4);\r
par_list = bytes_to_num(resp.d.asBytes + 8, 8);\r
ks_list = bytes_to_num(resp.d.asBytes + 16, 8);\r
- nr = bytes_to_num(resp.d.asBytes + 24, 4);\r
+ nr = (uint32_t)bytes_to_num(resp.d.asBytes + 24, 4);\r
+ ar = (uint32_t)bytes_to_num(resp.d.asBytes + 28, 4);\r
break;\r
}\r
}\r
\r
if (par_list == 0 && c.arg[0] == true) {\r
PrintAndLog("Parity is all zero. Most likely this card sends NACK on every failed authentication.");\r
- PrintAndLog("Attack will take a few seconds longer because we need two consecutive successful runs.");\r
}\r
c.arg[0] = false;\r
\r
- keycount = nonce2key(uid, nt, nr, par_list, ks_list, &keylist);\r
+ keycount = nonce2key(uid, nt, nr, ar, par_list, ks_list, &keylist);\r
\r
if (keycount == 0) {\r
PrintAndLog("Key not found (lfsr_common_prefix list is null). Nt=%08x", nt);\r
int size = keycount - i > max_keys ? max_keys : keycount - i;\r
for (int j = 0; j < size; j++) {\r
if (par_list == 0) {\r
- num_to_bytes(last_keylist[i*max_keys + j], 6, keyBlock);\r
+ num_to_bytes(last_keylist[i*max_keys + j], 6, keyBlock+(j*6));\r
} else {\r
- num_to_bytes(keylist[i*max_keys + j], 6, keyBlock);\r
+ num_to_bytes(keylist[i*max_keys + j], 6, keyBlock+(j*6));\r
}\r
}\r
if (!mfCheckKeys(0, 0, false, size, keyBlock, key)) {\r