mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
hf mf isen: add nt indexes
This commit is contained in:
parent
153064ddfa
commit
fb0b448c4f
4 changed files with 22 additions and 12 deletions
|
@ -183,20 +183,22 @@ int mifare_classic_authex_cmd(struct Crypto1State *pcs, uint32_t uid, uint8_t bl
|
||||||
uint32_t nr32 = nr[0] << 24 | nr[1] << 16 | nr[2] << 8 | nr[3];
|
uint32_t nr32 = nr[0] << 24 | nr[1] << 16 | nr[2] << 8 | nr[3];
|
||||||
if (g_dbglevel >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
if (!isNested) {
|
if (!isNested) {
|
||||||
Dbprintf("auth cmd: %02x %02x | uid: %08x | nr: %08x %s| nt: %08x %s| par: %i%i%i%i %s",
|
Dbprintf("auth cmd: %02x %02x | uid: %08x | nr: %08x %s| nt: %08x %s %5i| par: %i%i%i%i %s",
|
||||||
cmd, blockNo, uid,
|
cmd, blockNo, uid,
|
||||||
nr32, validate_prng_nonce(nr32) ? "@" : " ",
|
nr32, validate_prng_nonce(nr32) ? "@" : " ",
|
||||||
nt, validate_prng_nonce(nt) ? "@" : " ",
|
nt, validate_prng_nonce(nt) ? "@idx" : " idx",
|
||||||
|
validate_prng_nonce(nt) ? nonce16_index(nt >> 16) : -1,
|
||||||
(receivedAnswerPar[0] >> 7) & 1,
|
(receivedAnswerPar[0] >> 7) & 1,
|
||||||
(receivedAnswerPar[0] >> 6) & 1,
|
(receivedAnswerPar[0] >> 6) & 1,
|
||||||
(receivedAnswerPar[0] >> 5) & 1,
|
(receivedAnswerPar[0] >> 5) & 1,
|
||||||
(receivedAnswerPar[0] >> 4) & 1,
|
(receivedAnswerPar[0] >> 4) & 1,
|
||||||
validate_parity_nonce(nt, receivedAnswerPar[0], nt) ? "ok " : "bad");
|
validate_parity_nonce(nt, receivedAnswerPar[0], nt) ? "ok " : "bad");
|
||||||
} else {
|
} else {
|
||||||
Dbprintf("auth nested cmd: %02x %02x | uid: %08x | nr: %08x %s| nt: %08x %s| par: %i%i%i%i %s| ntenc: %08x %s| parerr: %i%i%i%i",
|
Dbprintf("auth nested cmd: %02x %02x | uid: %08x | nr: %08x %s| nt: %08x %s %5i| par: %i%i%i%i %s| ntenc: %08x %s| parerr: %i%i%i%i",
|
||||||
cmd, blockNo, uid,
|
cmd, blockNo, uid,
|
||||||
nr32, validate_prng_nonce(nr32) ? "@" : " ",
|
nr32, validate_prng_nonce(nr32) ? "@" : " ",
|
||||||
nt, validate_prng_nonce(nt) ? "@" : " ",
|
nt, validate_prng_nonce(nt) ? "@idx" : " idx",
|
||||||
|
validate_prng_nonce(nt) ? nonce16_index(nt >> 16) : -1,
|
||||||
(receivedAnswerPar[0] >> 7) & 1,
|
(receivedAnswerPar[0] >> 7) & 1,
|
||||||
(receivedAnswerPar[0] >> 6) & 1,
|
(receivedAnswerPar[0] >> 6) & 1,
|
||||||
(receivedAnswerPar[0] >> 5) & 1,
|
(receivedAnswerPar[0] >> 5) & 1,
|
||||||
|
@ -947,13 +949,9 @@ bool validate_parity_nonce(uint32_t ntenc, uint8_t ntparenc, uint32_t nt) {
|
||||||
(((ntpar >> 1) & 1) == oddparity8((nt>>8) & 0xFF));
|
(((ntpar >> 1) & 1) == oddparity8((nt>>8) & 0xFF));
|
||||||
}
|
}
|
||||||
|
|
||||||
int nonce_distance(uint32_t from, uint32_t to) {
|
int nonce16_distance(uint16_t x, uint16_t y) {
|
||||||
if (!validate_prng_nonce(from) || !validate_prng_nonce(to))
|
if (x == y)
|
||||||
return -1;
|
|
||||||
if (from == to)
|
|
||||||
return 0;
|
return 0;
|
||||||
uint16_t x = from;
|
|
||||||
uint16_t y = to;
|
|
||||||
x = (x & 0xff) << 8 | x >> 8;
|
x = (x & 0xff) << 8 | x >> 8;
|
||||||
y = (y & 0xff) << 8 | y >> 8;
|
y = (y & 0xff) << 8 | y >> 8;
|
||||||
uint16_t i = 1;
|
uint16_t i = 1;
|
||||||
|
@ -965,3 +963,13 @@ int nonce_distance(uint32_t from, uint32_t to) {
|
||||||
// never reached
|
// never reached
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int nonce_distance(uint32_t from, uint32_t to) {
|
||||||
|
if (!validate_prng_nonce(from) || !validate_prng_nonce(to))
|
||||||
|
return -1;
|
||||||
|
return nonce16_distance(from >> 16, to >> 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
int nonce16_index(uint16_t nt) {
|
||||||
|
return nonce16_distance(0x0100, nt) + 1;
|
||||||
|
}
|
||||||
|
|
|
@ -125,4 +125,6 @@ bool emlCheckValBl(int blockNum);
|
||||||
bool validate_prng_nonce(uint32_t nonce);
|
bool validate_prng_nonce(uint32_t nonce);
|
||||||
bool validate_parity_nonce(uint32_t ntenc, uint8_t ntparenc, uint32_t nt);
|
bool validate_parity_nonce(uint32_t ntenc, uint8_t ntparenc, uint32_t nt);
|
||||||
int nonce_distance(uint32_t from, uint32_t to);
|
int nonce_distance(uint32_t from, uint32_t to);
|
||||||
|
int nonce16_distance(uint16_t x, uint16_t y);
|
||||||
|
int nonce16_index(uint16_t nt);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2068,7 +2068,7 @@ void annotateMifare(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize,
|
||||||
AuthData.nt = bytes_to_num(cmd, 4);
|
AuthData.nt = bytes_to_num(cmd, 4);
|
||||||
AuthData.nt_enc_par = 0;
|
AuthData.nt_enc_par = 0;
|
||||||
if (validate_prng_nonce(AuthData.nt)) {
|
if (validate_prng_nonce(AuthData.nt)) {
|
||||||
snprintf(exp, size, "AUTH: nt (lfsr16 index %i)", nonce_distance(0x0100, AuthData.nt));
|
snprintf(exp, size, "AUTH: nt (lfsr16 index %i)", nonce_distance(0, AuthData.nt));
|
||||||
} else {
|
} else {
|
||||||
snprintf(exp, size, "AUTH: nt");
|
snprintf(exp, size, "AUTH: nt");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1450,7 +1450,7 @@ int detect_classic_static_encrypted_nonce_ex(uint8_t block_no, uint8_t key_type,
|
||||||
(ntencpar >> 3) & 1, (ntencpar >> 2) & 1, (ntencpar >> 1) & 1,
|
(ntencpar >> 3) & 1, (ntencpar >> 2) & 1, (ntencpar >> 1) & 1,
|
||||||
ks, nt,
|
ks, nt,
|
||||||
oddparity8((nt>>24) & 0xFF), oddparity8((nt>>16) & 0xFF), oddparity8((nt>>8) & 0xFF), oddparity8(nt & 0xFF),
|
oddparity8((nt>>24) & 0xFF), oddparity8((nt>>16) & 0xFF), oddparity8((nt>>8) & 0xFF), oddparity8(nt & 0xFF),
|
||||||
nonce_distance(0x0100, nt));
|
nonce_distance(0, nt));
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(INFO, "nTenc " _GREEN_("%08x") " par {" _YELLOW_("%i%i%i%i") "}=" _YELLOW_("%i%i%ix") " | ks " _YELLOW_("%08x") " | nT " _YELLOW_("%08x") " par " _YELLOW_("%i%i%i%i") " | " _RED_("not lfsr16") " (wrong key)",
|
PrintAndLogEx(INFO, "nTenc " _GREEN_("%08x") " par {" _YELLOW_("%i%i%i%i") "}=" _YELLOW_("%i%i%ix") " | ks " _YELLOW_("%08x") " | nT " _YELLOW_("%08x") " par " _YELLOW_("%i%i%i%i") " | " _RED_("not lfsr16") " (wrong key)",
|
||||||
ntenc,
|
ntenc,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue