]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/nonce2key/nonce2key.c
CHG: 'lf awid brute' - extra check if device gotten offline
[proxmark3-svn] / client / nonce2key / nonce2key.c
index 727f241d7d9c7f53f87cb80ebd19fe355a2b1808..3d3d1e374976cc2cd159633a8bf43a8534ca4900 100644 (file)
@@ -97,7 +97,6 @@ int nonce2key_ex(uint8_t blockno, uint8_t keytype, uint32_t uid, uint32_t nt, ui
        state = lfsr_common_prefix_ex(nr, ks3x);
 
        if (!state) {
-               key_count = 0;
                PrintAndLog("Failed getting states");
                return 1;
        }
@@ -117,7 +116,6 @@ int nonce2key_ex(uint8_t blockno, uint8_t keytype, uint32_t uid, uint32_t nt, ui
        
        // first call to this function.  clear all other stuff and set new found states.
        if (last_keylist == NULL) {
-               key_count = 0;
                free(last_keylist);
                last_keylist = state_s;
                PrintAndLog("parity is all zero, testing special attack. First call, this attack needs at least two calls. Hold on...");                
@@ -147,9 +145,11 @@ int nonce2key_ex(uint8_t blockno, uint8_t keytype, uint32_t uid, uint32_t nt, ui
        printf("key_count: %d\n", key_count);
        if ( key_count == 0 ){
                free(state);
+               state = NULL;
                return 0;
        }
        
+       uint8_t retval = 1;
        // Validate all key candidates with testing each of them with mfCheckKeys
        uint8_t keyBlock[6] = {0,0,0,0,0,0};
        uint64_t key64;
@@ -159,13 +159,17 @@ int nonce2key_ex(uint8_t blockno, uint8_t keytype, uint32_t uid, uint32_t nt, ui
                key64 = 0;
                if (!mfCheckKeys(blockno, keytype, false, 1, keyBlock, &key64)) {
                        *key = key64;
-                       free(last_keylist);
-                       last_keylist = NULL;
-                       free(state);
-                       return 0;
+                       retval = 0;
+                       goto out;
                }
-       }       
-       return 1;
+       }
+       
+out:
+       free(last_keylist);
+       last_keylist = NULL;
+       free(state);
+       state = NULL;
+       return retval;
 }
 
 // 32 bit recover key from 2 nonces
Impressum, Datenschutz