]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/nonce2key/crapto1.c
Merge branch 'master' of https://github.com/Proxmark/proxmark3
[proxmark3-svn] / client / nonce2key / crapto1.c
index 1d7441c7fee996bc34ba9b783b8713b8efacbc54..13c4c063af078fb4d155b7f227d26eda6b8fa9c9 100644 (file)
@@ -251,7 +251,6 @@ struct Crypto1State* lfsr_recovery32(uint32_t ks2, uint32_t in)
                        }\r
                }\r
 \r
-\r
        // initialize statelists: add all possible states which would result into the rightmost 2 bits of the keystream\r
        for(i = 1 << 20; i >= 0; --i) {\r
                if(filter(i) == (oks & 1))\r
@@ -272,9 +271,7 @@ struct Crypto1State* lfsr_recovery32(uint32_t ks2, uint32_t in)
 \r
        in = (in >> 16 & 0xff) | (in << 16) | (in & 0xff00);            // Byte swapping\r
 \r
-       recover(odd_head, odd_tail, oks,\r
-               even_head, even_tail, eks, 11, statelist, in << 1, bucket);\r
-\r
+       recover(odd_head, odd_tail, oks, even_head, even_tail, eks, 11, statelist, in << 1, bucket);\r
 \r
 out:\r
        free(odd_head);\r
@@ -536,8 +533,7 @@ brute_top(uint32_t prefix, uint32_t rresp, unsigned char parities[8][8],
  * It returns a zero terminated list of possible cipher states after the\r
  * 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], uint8_t no_par)\r
+struct Crypto1State* 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
@@ -548,10 +544,10 @@ lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8],
        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
+               free(statelist);\r
+               free(odd);\r
+               free(even);\r
+               return 0;\r
        }\r
 \r
        s = statelist;\r
@@ -571,3 +567,66 @@ lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8],
 \r
        return statelist;\r
 }\r
+\r
+/*\r
+struct Crypto1State* lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8], uint8_t no_par, uint32_t nt, uint32_t uid)\r
+{\r
+    long long int amount = 0;\r
+    struct Crypto1State *statelist, *s;\r
+    uint32_t *odd, *even, *o, *e, top;\r
+\r
+    odd = lfsr_prefix_ks(ks, 1);\r
+    even = lfsr_prefix_ks(ks, 0);\r
+\r
+    s = statelist = malloc((sizeof *statelist) << 20);\r
+    if(!s || !odd || !even) {\r
+               free(odd);\r
+               free(even);\r
+               free(statelist);\r
+               return 0;\r
+    }\r
+\r
+    char filename[50] = "archivo.txt";\r
+    sprintf(filename, "logs/%x.txt", nt);\r
+    PrintAndLog("Name: %s\n", filename);\r
+    FILE *file = fopen(filename,"w+");\r
+       if ( !file ) {\r
+               s->odd = s->even = 0;\r
+               free(odd);\r
+               free(even);\r
+               PrintAndLog("Failed to create file");\r
+               return 0;\r
+       }\r
+    PrintAndLog("Creating file... ");\r
+       uint32_t xored = uid^nt;\r
+       \r
+    int lastOdd = 0;\r
+    for(o = odd; *o + 1; ++o)\r
+        for(e = even; *e + 1; ++e)\r
+            for(top = 0; top < 64; ++top) {\r
+                *o += 1 << 21;\r
+                *e += (!(top & 7) + 1) << 21;\r
+\r
+                //added by MG\r
+                if(lastOdd != statelist->odd){\r
+                                       // Here I create a temporal crypto1 state, \r
+                                       // where I load the odd and even state and work with it,\r
+                                       // in order not to interfere with regular mechanism, This is what I save to file\r
+                                       struct Crypto1State *state;\r
+                    lastOdd = state->odd = statelist->odd; state->even = statelist->even;\r
+                    lfsr_rollback_word(state,xored,0);\r
+                    fprintf(file,"%x %x \n",state->odd,state->even);\r
+                    amount++;\r
+                }\r
+                //s = check_pfx_parity(pfx, rr, par, *o, *e, s); //This is not useful at all when attacking chineese cards\r
+                               s = brute_top(pfx, rr, par, *o, *e, s, no_par); \r
+            }\r
+\r
+       PrintAndLog("File created, amount %u\n",amount);\r
+       fclose(file);\r
+       s->odd = s->even = 0;\r
+       free(odd);\r
+       free(even);\r
+    return statelist;\r
+}\r
+ */\r
Impressum, Datenschutz