diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index d02ad8850..60bc0cd70 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -2606,7 +2606,7 @@ void DetectNACKbug() { // Test if the action was cancelled if(BUTTON_PRESS()) { - isOK = -1; + isOK = 99; break; } @@ -2675,7 +2675,7 @@ void DetectNACKbug() { unexpected_random++; if (unexpected_random > MAX_UNEXPECTED_RANDOM) { // Card has an unpredictable PRNG. Give up - isOK = -3; + isOK = 98; break; } else { if (sync_cycles <= 0) { @@ -2687,7 +2687,7 @@ void DetectNACKbug() { } if (++sync_tries > MAX_SYNC_TRIES) { - isOK = -4; // Card's PRNG runs at an unexpected frequency or resets unexpectedly + isOK = 97; // Card's PRNG runs at an unexpected frequency or resets unexpectedly break; } @@ -2697,7 +2697,7 @@ void DetectNACKbug() { sync_cycles += PRNG_SEQUENCE_LENGTH; if (sync_cycles > PRNG_SEQUENCE_LENGTH * 2 ) { - isOK = -4; // Card's PRNG runs at an unexpected frequency or resets unexpectedly + isOK = 96; // Card's PRNG runs at an unexpected frequency or resets unexpectedly break; } diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index 17a745f45..27e4d3879 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -166,6 +166,7 @@ int usage_hf_14a_info(void){ PrintAndLog("This command makes more extensive tests against a ISO14443a tag in order to collect information"); PrintAndLog("Usage: hf 14a info [h|s]"); PrintAndLog(" s silent (no messages)"); + PrintAndLog(" n test for nack bug"); return 0; } @@ -274,6 +275,8 @@ int CmdHF14AInfo(const char *Cmd) { if (Cmd[0] == 'h' || Cmd[0] == 'H') return usage_hf_14a_info(); bool silent = (Cmd[0] == 's' || Cmd[0] == 'S'); + bool do_nack_test = (Cmd[0] == 'n' || Cmd[0] == 'N'); + UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0}}; clearCommandBuffer(); SendCommand(&c); @@ -494,7 +497,10 @@ int CmdHF14AInfo(const char *Cmd) { if ( detect_classic_prng() ) PrintAndLog("Prng detection: WEAK"); else - PrintAndLog("Prng detection: HARDEND (hardnested)"); + PrintAndLog("Prng detection: HARDEND (hardnested)"); + + if ( do_nack_test ) + detect_classic_nackbug(silent); } return select_status; diff --git a/client/mifarehost.c b/client/mifarehost.c index 82f62a016..3258aea0b 100644 --- a/client/mifarehost.c +++ b/client/mifarehost.c @@ -890,13 +890,15 @@ int detect_classic_nackbug(bool verbose){ PrintAndLog("Num of received NACK : %u", nacks); } switch( ok ) { - case -1 : if (verbose) PrintAndLog("Button pressed. Aborted."); return 0; - case -3 : if (verbose) PrintAndLog("Card random number generator is not predictable)."); return 0; - case -4 : if (verbose) { + case 99 : if (verbose) PrintAndLog("Button pressed. Aborted."); return 0; + case 96 : + case 98 : if (verbose) PrintAndLog("Card random number generator is not predictable)."); return 0; + case 97 : if (verbose) { PrintAndLog("Card random number generator seems to be based on the well-known generating polynomial"); PrintAndLog("with 16 effective bits only, but shows unexpected behavior, try again."); return 0; } + case 2 : PrintAndLog("Always leak NACK detected"); return 3; case 1 : PrintAndLog("NACK bug detected"); return 1; case 0 : PrintAndLog("No NACK bug detected"); return 2;