]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/nonce2key/crapto1.c
Fixed: hf mf sim failed on fast reader responses
[proxmark3-svn] / client / nonce2key / crapto1.c
index fc878a0deb83eef6e5034ee0d3d0166fe870ec8f..6c0fcafa09ef6bb9c038a6f593de93a0495d9400 100644 (file)
@@ -95,32 +95,6 @@ static void bucket_sort_intersect(uint32_t* const estart, uint32_t* const estop,
                }\r
 }\r
 \r
-\r
-static void quicksort(uint32_t* const start, uint32_t* const stop)\r
-{\r
-       uint32_t *it = start + 1, *rit = stop;\r
-\r
-       if(it > rit)\r
-               return;\r
-\r
-       while(it < rit)\r
-               if(*it <= *start)\r
-                       ++it;\r
-               else if(*rit > *start)\r
-                       --rit;\r
-               else\r
-                       *it ^= (*it ^= *rit, *rit ^= *it);\r
-\r
-       if(*rit >= *start)\r
-               --rit;\r
-       if(rit != start)\r
-               *rit ^= (*rit ^= *start, *start ^= *rit);\r
-\r
-       quicksort(start, rit - 1);\r
-       quicksort(rit + 1, stop);\r
-}\r
-\r
-\r
 /** binsearch\r
  * Binary search for the first occurence of *stop's MSB in sorted [start,stop]\r
  */\r
@@ -507,7 +481,7 @@ uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd)
  */\r
 static struct Crypto1State*\r
 brute_top(uint32_t prefix, uint32_t rresp, unsigned char parities[8][8],\r
-          uint32_t odd, uint32_t even, struct Crypto1State* sl)\r
+          uint32_t odd, uint32_t even, struct Crypto1State* sl, uint8_t no_chk)\r
 {\r
        struct Crypto1State s;\r
        uint32_t ks1, nr, ks2, rr, ks3, good, c;\r
@@ -525,6 +499,9 @@ brute_top(uint32_t prefix, uint32_t rresp, unsigned char parities[8][8],
                \r
                sl->odd = s.odd;\r
                sl->even = s.even;\r
+               \r
+               if (no_chk)\r
+                       break;\r
        \r
                ks1 = crypto1_word(&s, prefix | c << 5, 1);\r
                ks2 = crypto1_word(&s,0,0);\r
@@ -557,7 +534,7 @@ brute_top(uint32_t prefix, uint32_t rresp, unsigned char parities[8][8],
  * tag nonce was fed in\r
  */\r
 struct Crypto1State*\r
-lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8])\r
+lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8], uint8_t no_par)\r
 {\r
        struct Crypto1State *statelist, *s;\r
        uint32_t *odd, *even, *o, *e, top;\r
@@ -565,21 +542,26 @@ lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8])
        odd = lfsr_prefix_ks(ks, 1);\r
        even = lfsr_prefix_ks(ks, 0);\r
 \r
-       statelist = malloc((sizeof *statelist) << 20);\r
+       statelist = malloc((sizeof *statelist) << 21);  //how large should be? \r
        if(!statelist || !odd || !even)\r
+       {\r
+                               free(statelist);\r
+                               free(odd);\r
+                               free(even);\r
                 return 0;\r
-\r
+       }\r
 \r
        s = statelist;\r
-       for(o = odd; *o != 0xffffffff; ++o)\r
-               for(e = even; *e != 0xffffffff; ++e)\r
+       for(o = odd; *o != -1; ++o)\r
+               for(e = even; *e != -1; ++e)\r
                        for(top = 0; top < 64; ++top) {\r
                                *o = (*o & 0x1fffff) | (top << 21);\r
                                *e = (*e & 0x1fffff) | (top >> 3) << 21;\r
-                               s = brute_top(pfx, rr, par, *o, *e, s);\r
+                               s = brute_top(pfx, rr, par, *o, *e, s, no_par);\r
                        }\r
 \r
-       s->odd = s->even = 0;\r
+       s->odd = s->even = -1;  \r
+       //printf("state count = %d\n",s-statelist);\r
 \r
        free(odd);\r
        free(even);\r
Impressum, Datenschutz