Allow debug prints when isNested == AUTH_NESTED and ntencptr == NULL

This commit is contained in:
nffq
2026-03-28 09:40:08 +01:00
committed by Philippe Teuwen
parent 83779ead7d
commit bc1b560add
+22 -28
View File
@@ -212,35 +212,24 @@ int mifare_classic_authex_cmd(struct Crypto1State *pcs, uint32_t uid, uint8_t bl
}
// Save the tag nonce (nt)
uint32_t nt = bytes_to_num(receivedAnswer, 4);
if (ntencptr) {
*ntencptr = nt;
}
if (ntencparptr) {
*ntencparptr = receivedAnswerPar[0];
}
// ----------------------------- crypto1 create
if (isNested) {
crypto1_deinit(pcs);
}
uint32_t nt = bytes_to_num(receivedAnswer, 4),
ntenc = nt;
// Init cipher with key
crypto1_init(pcs, ui64Key);
if (isNested == AUTH_NESTED) {
// decrypt nt with help of new key
nt = crypto1_word(pcs, nt ^ uid, 1) ^ nt;
// decrypt ntenc with help of new key
nt = crypto1_word(pcs, ntenc ^ uid, 1) ^ ntenc;
} else {
// Load (plain) uid^nt into the cipher
crypto1_word(pcs, nt ^ uid, 0);
}
// some statistic
// if (!ntptr && (g_dbglevel >= DBG_EXTENDED))
uint32_t nr32 = nr[0] << 24 | nr[1] << 16 | nr[2] << 8 | nr[3];
if (g_dbglevel >= DBG_EXTENDED) {
uint32_t nr32 = nr[0] << 24 | nr[1] << 16 | nr[2] << 8 | nr[3];
if (isNested == AUTH_FIRST) {
Dbprintf("auth cmd: %02x %02x | uid: %08x | nr: %08x %s| nt: %08x %s %5i| par: %i%i%i%i %s",
cmd, blockNo, uid,
@@ -253,9 +242,7 @@ int mifare_classic_authex_cmd(struct Crypto1State *pcs, uint32_t uid, uint8_t bl
(receivedAnswerPar[0] >> 4) & 1,
validate_parity_nonce(nt, receivedAnswerPar[0], nt) ? "ok " : "bad");
} else {
if (ntencptr) {
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",
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,
nr32, validate_prng_nonce(nr32) ? "@" : " ",
nt, validate_prng_nonce(nt) ? "@idx" : " idx",
@@ -264,20 +251,27 @@ int mifare_classic_authex_cmd(struct Crypto1State *pcs, uint32_t uid, uint8_t bl
(receivedAnswerPar[0] >> 6) & 1,
(receivedAnswerPar[0] >> 5) & 1,
(receivedAnswerPar[0] >> 4) & 1,
validate_parity_nonce(*ntencptr, receivedAnswerPar[0], nt) ? "ok " : "bad",
*ntencptr, validate_prng_nonce(*ntencptr) ? "@" : " ",
((receivedAnswerPar[0] >> 7) & 1) ^ oddparity8((*ntencptr >> 24) & 0xFF),
((receivedAnswerPar[0] >> 6) & 1) ^ oddparity8((*ntencptr >> 16) & 0xFF),
((receivedAnswerPar[0] >> 5) & 1) ^ oddparity8((*ntencptr >> 8) & 0xFF),
((receivedAnswerPar[0] >> 4) & 1) ^ oddparity8((*ntencptr >> 0) & 0xFF)
);
}
validate_parity_nonce(ntenc, receivedAnswerPar[0], nt) ? "ok " : "bad",
ntenc, validate_prng_nonce(ntenc) ? "@" : " ",
((receivedAnswerPar[0] >> 7) & 1) ^ oddparity8((ntenc >> 24) & 0xFF),
((receivedAnswerPar[0] >> 6) & 1) ^ oddparity8((ntenc >> 16) & 0xFF),
((receivedAnswerPar[0] >> 5) & 1) ^ oddparity8((ntenc >> 8) & 0xFF),
((receivedAnswerPar[0] >> 4) & 1) ^ oddparity8((ntenc >> 0) & 0xFF));
}
}
// save Nt
if (ntptr) {
*ntptr = nt;
}
// save encrypted Nt
if (ntencptr) {
*ntencptr = ntenc;
}
// save encrypted Nt parity
if (ntencparptr) {
*ntencparptr = receivedAnswerPar[0];
}
// Generate (encrypted) nr+parity by loading it into the cipher (Nr)
uint32_t pos;