@@ -3128,82 +3128,82 @@ void MifareHasStaticEncryptedNonce(uint8_t block_no, uint8_t key_type, uint8_t *
31283128 };
31293129 first_nt_counter ++ ;
31303130 } else for (uint8_t i = 0 ; i < nr_nested ; i ++ ) {
3131- if (need_first_auth ) {
3132- cuid = 0 ;
3131+ if (need_first_auth ) {
3132+ cuid = 0 ;
31333133
3134- if (hardreset ) {
3134+ if (hardreset ) {
3135+ if (g_dbglevel >= DBG_EXTENDED ) {
3136+ Dbprintf ("RF reset" );
3137+ }
3138+ // some cards need longer than mf_reset_card() to see effect on nT
3139+ FpgaWriteConfWord (FPGA_MAJOR_MODE_OFF );
3140+ SpinDelay (150 );
3141+ iso14443a_setup (FPGA_HF_ISO14443A_READER_LISTEN );
3142+ }
31353143 if (g_dbglevel >= DBG_EXTENDED ) {
3136- Dbprintf ("RF reset " );
3144+ Dbprintf ("select " );
31373145 }
3138- // some cards need longer than mf_reset_card() to see effect on nT
3139- FpgaWriteConfWord (FPGA_MAJOR_MODE_OFF );
3140- SpinDelay (150 );
3141- iso14443a_setup (FPGA_HF_ISO14443A_READER_LISTEN );
3142- }
3143- if (g_dbglevel >= DBG_EXTENDED ) {
3144- Dbprintf ("select" );
3145- }
3146- if (iso14443a_select_card (NULL , NULL , & cuid , true, 0 , true) == false) {
3147- retval = PM3_ESOFT ;
3148- goto OUT ;
3149- }
3150- if (mifare_classic_authex_cmd (pcs , cuid , block_no , key_auth_cmd , ui64key , AUTH_FIRST , & nt_first , NULL , NULL , NULL , corruptnrar , corruptnrarparity )) {
3151- if (g_dbglevel >= DBG_ERROR ) Dbprintf ("Auth error" );
3152- retval = PM3_ESOFT ;
3153- goto OUT ;
3154- };
3155- is_last_auth_first_auth = true;
3156- first_nt_counter ++ ;
3157- if ((first_nt_counter > 1 ) && (old_nt_first == nt_first )) {
3158- first_nt_repetition_counter ++ ;
3159- }
3160- old_nt_first = nt_first ;
3161- if (!reset && !hardreset ) {
3162- need_first_auth = false;
3163- }
3164- if (addread ) {
3165- uint8_t dataread [16 ] = {0x00 };
3166- mifare_classic_readblock (pcs , block_no , dataread );
3167- }
3168- if (addauth ) {
3169- if (mifare_classic_authex_cmd (pcs , cuid , block_no , key_auth_cmd , ui64key , AUTH_NESTED , & nt , NULL , NULL , NULL , false, false)) {
3146+ if (iso14443a_select_card (NULL , NULL , & cuid , true, 0 , true) == false) {
3147+ retval = PM3_ESOFT ;
3148+ goto OUT ;
3149+ }
3150+ if (mifare_classic_authex_cmd (pcs , cuid , block_no , key_auth_cmd , ui64key , AUTH_FIRST , & nt_first , NULL , NULL , NULL , corruptnrar , corruptnrarparity )) {
31703151 if (g_dbglevel >= DBG_ERROR ) Dbprintf ("Auth error" );
31713152 retval = PM3_ESOFT ;
31723153 goto OUT ;
3173- } else if (g_dbglevel >= DBG_EXTENDED ) {
3174- Dbprintf ("Nonce distance: %5i (first nonce <> nested nonce)" , nonce_distance (nt_first , nt ));
3154+ };
3155+ is_last_auth_first_auth = true;
3156+ first_nt_counter ++ ;
3157+ if ((first_nt_counter > 1 ) && (old_nt_first == nt_first )) {
3158+ first_nt_repetition_counter ++ ;
3159+ }
3160+ old_nt_first = nt_first ;
3161+ if (!reset && !hardreset ) {
3162+ need_first_auth = false;
31753163 }
3176- is_last_auth_first_auth = false;
3177- if (nt == nt_first ) {
3178- first_and_nested_nt_repetition_counter ++ ;
3164+ if (addread ) {
3165+ uint8_t dataread [16 ] = {0x00 };
3166+ mifare_classic_readblock (pcs , block_no , dataread );
3167+ }
3168+ if (addauth ) {
3169+ if (mifare_classic_authex_cmd (pcs , cuid , block_no , key_auth_cmd , ui64key , AUTH_NESTED , & nt , NULL , NULL , NULL , false, false)) {
3170+ if (g_dbglevel >= DBG_ERROR ) Dbprintf ("Auth error" );
3171+ retval = PM3_ESOFT ;
3172+ goto OUT ;
3173+ } else if (g_dbglevel >= DBG_EXTENDED ) {
3174+ Dbprintf ("Nonce distance: %5i (first nonce <> nested nonce)" , nonce_distance (nt_first , nt ));
3175+ }
3176+ is_last_auth_first_auth = false;
3177+ if (nt == nt_first ) {
3178+ first_and_nested_nt_repetition_counter ++ ;
3179+ }
3180+ old_nt = nt ;
31793181 }
3180- old_nt = nt ;
31813182 }
3182- }
31833183
3184- nt = 0 ;
3185- ntenc = 0 ;
3186- if (mifare_classic_authex_cmd (pcs , cuid , incblk2 ? block_no_nested + (i * 4 ) : block_no_nested , key_auth_cmd_nested , ui64key_nested , AUTH_NESTED , & nt , & ntenc , & ntencpar , NULL , false, false)) {
3187- if (g_dbglevel >= DBG_ERROR ) Dbprintf ("Nested auth error" );
3188- need_first_auth = true;
3189- } else if (g_dbglevel >= DBG_EXTENDED ) {
3190- if (is_last_auth_first_auth ) {
3191- Dbprintf ("Nonce distance: %5i (first nonce <> nested nonce)" , nonce_distance (nt_first , nt ));
3192- } else {
3193- Dbprintf ("Nonce distance: %5i" , nonce_distance (old_nt , nt ));
3184+ nt = 0 ;
3185+ ntenc = 0 ;
3186+ if (mifare_classic_authex_cmd (pcs , cuid , incblk2 ? block_no_nested + (i * 4 ) : block_no_nested , key_auth_cmd_nested , ui64key_nested , AUTH_NESTED , & nt , & ntenc , & ntencpar , NULL , false, false)) {
3187+ if (g_dbglevel >= DBG_ERROR ) Dbprintf ("Nested auth error" );
3188+ need_first_auth = true;
3189+ } else if (g_dbglevel >= DBG_EXTENDED ) {
3190+ if (is_last_auth_first_auth ) {
3191+ Dbprintf ("Nonce distance: %5i (first nonce <> nested nonce)" , nonce_distance (nt_first , nt ));
3192+ } else {
3193+ Dbprintf ("Nonce distance: %5i" , nonce_distance (old_nt , nt ));
3194+ }
31943195 }
3196+ nested_nt_session_counter ++ ;
3197+ is_last_auth_first_auth = false;
3198+ old_nt = nt ;
3199+ if (nt == nt_first ) {
3200+ first_and_nested_nt_repetition_counter ++ ;
3201+ }
3202+ if ((nested_nt_session_counter > 1 ) && (oldntenc == ntenc )) {
3203+ nested_nt_repetition_counter ++ ;
3204+ }
3205+ oldntenc = ntenc ;
31953206 }
3196- nested_nt_session_counter ++ ;
3197- is_last_auth_first_auth = false;
3198- old_nt = nt ;
3199- if (nt == nt_first ) {
3200- first_and_nested_nt_repetition_counter ++ ;
3201- }
3202- if ((nested_nt_session_counter > 1 ) && (oldntenc == ntenc )) {
3203- nested_nt_repetition_counter ++ ;
3204- }
3205- oldntenc = ntenc ;
3206- }
32073207
32083208 data [1 ] = (cuid >> 24 ) & 0xFF ;
32093209 data [2 ] = (cuid >> 16 ) & 0xFF ;
0 commit comments