Przeglądaj źródła

1.4.2 - Minor code refactor

AloneLiberty 2 lat temu
rodzic
commit
7548828ec5

+ 1 - 1
lib/crypto1/crypto1.c

@@ -53,7 +53,7 @@ uint32_t crypto1_word(Crypto1* crypto1, uint32_t in, int is_encrypted) {
     furi_assert(crypto1);
     uint32_t out = 0;
     for(uint8_t i = 0; i < 32; i++) {
-        out |= crypto1_bit(crypto1, BEBIT(in, i), is_encrypted) << (24 ^ i);
+        out |= (uint32_t)crypto1_bit(crypto1, BEBIT(in, i), is_encrypted) << (24 ^ i);
     }
     return out;
 }

+ 2 - 1
lib/crypto1/crypto1.h

@@ -6,7 +6,8 @@
 #define LF_POLY_ODD (0x29CE5C)
 #define LF_POLY_EVEN (0x870804)
 
-#define SWAPENDIAN(x) (x = (x >> 8 & 0xff00ff) | (x & 0xff00ff) << 8, x = x >> 16 | x << 16)
+#define SWAPENDIAN(x) \
+    ((x) = ((x) >> 8 & 0xff00ff) | ((x)&0xff00ff) << 8, (x) = (x) >> 16 | (x) << 16)
 #define BEBIT(x, n) FURI_BIT(x, (n) ^ 24)
 
 void crypto1_reset(Crypto1* crypto1);

+ 4 - 4
lib/nested/nested.c

@@ -169,7 +169,7 @@ static int valid_nonce(uint32_t Nt, uint32_t NtEnc, uint32_t Ks1, const uint8_t*
                0;
 }
 
-void nonce_distance_notable(uint32_t* msb, uint32_t* lsb) {
+void nonce_distance(uint32_t* msb, uint32_t* lsb) {
     uint16_t x = 1, pos;
     uint8_t calc_ok = 0;
 
@@ -194,10 +194,10 @@ void nonce_distance_notable(uint32_t* msb, uint32_t* lsb) {
     }
 }
 
-bool validate_prng_nonce_notable(uint32_t nonce) {
+bool validate_prng_nonce(uint32_t nonce) {
     uint32_t msb = nonce >> 16;
     uint32_t lsb = nonce & 0xffff;
-    nonce_distance_notable(&msb, &lsb);
+    nonce_distance(&msb, &lsb);
     return ((65535 - msb + lsb) % 65535) == 16;
 }
 
@@ -221,7 +221,7 @@ MifareNestedNonceType nested_check_nonce_type(FuriHalNfcTxRxContext* tx_rx, uint
 
         uint32_t nt = (uint32_t)nfc_util_bytes2num(tx_rx->rx_data, 4);
         if(nt == 0) continue;
-        if(!validate_prng_nonce_notable(nt)) hardNonces++;
+        if(!validate_prng_nonce(nt)) hardNonces++;
         nonces[i] = nt;
 
         nfc_deactivate();

+ 1 - 1
mifare_nested_i.h

@@ -21,7 +21,7 @@
 #include <gui/modules/variable_item_list.h>
 #include "mifare_nested_icons.h"
 
-#define NESTED_VERSION_APP "1.4.1"
+#define NESTED_VERSION_APP "1.4.2"
 #define NESTED_GITHUB_LINK "https://github.com/AloneLiberty/FlipperNested"
 #define NESTED_RECOVER_KEYS_GITHUB_LINK "https://github.com/AloneLiberty/FlipperNestedRecovery"
 #define NESTED_NONCE_FORMAT_VERSION "3"

+ 7 - 37
mifare_nested_worker.c

@@ -707,18 +707,8 @@ void mifare_nested_worker_collect_nonces_static(MifareNestedWorker* mifare_neste
     storage_common_mkdir(storage, furi_string_get_cstr(folder_path));
     furi_string_free(folder_path);
 
-    if(!mifare_nested_worker_read_key_cache(&data, mf_data)) {
-        mifare_nested_worker->callback(
-            MifareNestedWorkerEventNeedKey, mifare_nested_worker->context);
-        nfc_deactivate();
-
-        free(mf_data);
-        free_nonces(&nonces, sector_count, 1);
-
-        return;
-    }
-
-    if(!mifare_nested_worker_check_initial_keys(
+    if(!mifare_nested_worker_read_key_cache(&data, mf_data) ||
+       !mifare_nested_worker_check_initial_keys(
            &nonces, mf_data, 1, sector_count, &key, &key_block, &found_key_type)) {
         mifare_nested_worker->callback(
             MifareNestedWorkerEventNeedKey, mifare_nested_worker->context);
@@ -873,18 +863,8 @@ void mifare_nested_worker_collect_nonces_hard(MifareNestedWorker* mifare_nested_
     storage_common_mkdir(storage, furi_string_get_cstr(folder_path));
     furi_string_free(folder_path);
 
-    if(!mifare_nested_worker_read_key_cache(&data, mf_data)) {
-        mifare_nested_worker->callback(
-            MifareNestedWorkerEventNeedKey, mifare_nested_worker->context);
-        nfc_deactivate();
-
-        free(mf_data);
-        free_nonces(&nonces, sector_count, 1);
-
-        return;
-    }
-
-    if(!mifare_nested_worker_check_initial_keys(
+    if(!mifare_nested_worker_read_key_cache(&data, mf_data) ||
+       !mifare_nested_worker_check_initial_keys(
            &nonces, mf_data, 1, sector_count, &key, &key_block, &found_key_type)) {
         mifare_nested_worker->callback(
             MifareNestedWorkerEventNeedKey, mifare_nested_worker->context);
@@ -1121,19 +1101,9 @@ void mifare_nested_worker_collect_nonces(MifareNestedWorker* mifare_nested_worke
     storage_common_mkdir(storage, furi_string_get_cstr(folder_path));
     furi_string_free(folder_path);
 
-    if(!mifare_nested_worker_read_key_cache(&data, mf_data)) {
-        mifare_nested_worker->callback(
-            MifareNestedWorkerEventNeedKey, mifare_nested_worker->context);
-        nfc_deactivate();
-
-        free(mf_data);
-        free_nonces(&nonces, sector_count, tries_count);
-
-        return;
-    }
-
-    if(!mifare_nested_worker_check_initial_keys(
-           &nonces, mf_data, 3, sector_count, &key, &key_block, &found_key_type)) {
+    if(!mifare_nested_worker_read_key_cache(&data, mf_data) ||
+       !mifare_nested_worker_check_initial_keys(
+           &nonces, mf_data, tries_count, sector_count, &key, &key_block, &found_key_type)) {
         mifare_nested_worker->callback(
             MifareNestedWorkerEventNeedKey, mifare_nested_worker->context);
         nfc_deactivate();

+ 1 - 1
scenes/mifare_nested_scene_about.c

@@ -21,7 +21,7 @@ void mifare_nested_scene_about_on_enter(void* context) {
     furi_string_cat_printf(temp_str, "\e#%s\n", "Description");
     furi_string_cat_printf(
         temp_str,
-        "Ported nested attacks\nfrom proxmark (Iceman fork)\nCurrently supported attacks:\n - nested attack\n - static nested attack\n - hard nested attack\n\n");
+        "Ported Nested attacks\nfrom Proxmark3 (Iceman fork)\nCurrently supported attacks:\n - nested attack\n - static nested attack\n - hard nested attack\n\n");
     furi_string_cat_printf(
         temp_str,
         "You will need desktop app to recover keys from collected nonces: %s\n\n",