@@ -771,6 +771,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
771771 // Read command
772772 while (!command_processed ) {
773773 if (!is_encrypted ) {
774+ crypto1_reset (& emulator -> crypto );
774775 memcpy (plain_data , tx_rx -> rx_data , tx_rx -> rx_bits / 8 );
775776 } else {
776777 if (!furi_hal_nfc_tx_rx (tx_rx , 300 )) {
@@ -803,7 +804,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
803804 access_key = MfClassicKeyB ;
804805 }
805806
806- uint32_t nonce = prng_successor (DWT -> CYCCNT , 32 );
807+ uint32_t nonce = prng_successor (DWT -> CYCCNT , 32 ) ^ 0xAA ;
807808 uint8_t nt [4 ];
808809 uint8_t nt_keystream [4 ];
809810 nfc_util_num2bytes (nonce , 4 , nt );
@@ -858,7 +859,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
858859 uint32_t cardRr = ar ^ crypto1_word (& emulator -> crypto , 0 , 0 );
859860 if (cardRr != prng_successor (nonce , 64 )) {
860861 FURI_LOG_T (TAG , "Wrong AUTH! %08X != %08X" , cardRr , prng_successor (nonce , 64 ));
861- // Don't send NACK, as tag don 't send it
862+ // Don't send NACK, as the tag doesn 't send it
862863 command_processed = true;
863864 break ;
864865 }
@@ -897,7 +898,18 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
897898 } else {
898899 if (!mf_classic_is_allowed_access (
899900 emulator , block , access_key , MfClassicActionDataRead )) {
900- memset (block_data , 0 , 16 );
901+ // Send NACK
902+ uint8_t nack = 0x04 ;
903+ if (is_encrypted ) {
904+ mf_crypto1_encrypt (
905+ & emulator -> crypto , NULL , & nack , 4 , tx_rx -> tx_data , tx_rx -> tx_parity );
906+ } else {
907+ tx_rx -> tx_data [0 ] = nack ;
908+ }
909+ tx_rx -> tx_rx_type = FuriHalNfcTxRxTransparent ;
910+ tx_rx -> tx_bits = 4 ;
911+ furi_hal_nfc_tx_rx (tx_rx , 300 );
912+ break ;
901913 }
902914 }
903915 nfca_append_crc16 (block_data , 16 );
0 commit comments