From bb27473d4c4e347c35b987315604d1edb5f664f1 Mon Sep 17 00:00:00 2001 From: Yukai Li Date: Sun, 29 Dec 2024 18:42:59 -0700 Subject: [PATCH] nfc: Move code in case any other phases are timing sensitive --- .../protocols/mf_classic/mf_classic_poller.c | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/nfc/protocols/mf_classic/mf_classic_poller.c b/lib/nfc/protocols/mf_classic/mf_classic_poller.c index 37a15515bec..86d9e383ca9 100644 --- a/lib/nfc/protocols/mf_classic/mf_classic_poller.c +++ b/lib/nfc/protocols/mf_classic/mf_classic_poller.c @@ -1897,21 +1897,22 @@ NfcCommand mf_classic_poller_handler_nested_controller(MfClassicPoller* instance dict_attack_ctx->nested_phase = MfClassicNestedPhaseDictAttack; } } - if(dict_attack_ctx->reuse_key_sector == instance->sectors_total) { - // Reset target sector to first sector whose key has not been found - for(dict_attack_ctx->reuse_key_sector = 0; - dict_attack_ctx->reuse_key_sector < instance->sectors_total && - mf_classic_nested_is_target_key_found(instance, true); - dict_attack_ctx->reuse_key_sector++) - ; - // Reset to sane value just in case we happen to have all of the keys - if(dict_attack_ctx->reuse_key_sector == instance->sectors_total) { - dict_attack_ctx->reuse_key_sector = 0; - } - } if((dict_attack_ctx->nested_phase == MfClassicNestedPhaseDictAttack || dict_attack_ctx->nested_phase == MfClassicNestedPhaseDictAttackResume) && (dict_attack_ctx->nested_target_key < dict_target_key_max)) { + if(dict_attack_ctx->reuse_key_sector == instance->sectors_total) { + // Reset target sector to first sector whose key has not been found + for(dict_attack_ctx->reuse_key_sector = 0; + dict_attack_ctx->reuse_key_sector < instance->sectors_total && + mf_classic_nested_is_target_key_found(instance, true); + dict_attack_ctx->reuse_key_sector++) + ; + // Reset to sane value just in case we happen to have all of the keys + if(dict_attack_ctx->reuse_key_sector == instance->sectors_total) { + dict_attack_ctx->reuse_key_sector = 0; + } + } + bool is_last_iter_for_hard_key = ((!is_weak) && ((dict_attack_ctx->nested_target_key % 8) == 7)); if(initial_dict_attack_iter) {