]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/nonce2key/crapto1.c
FIX: Coverity scan fixes, hard to keep track of stringlengths while reading and...
[proxmark3-svn] / client / nonce2key / crapto1.c
index 36e21a1ce9b13ddccae09772c407c72c6095c007..626823f8022c43bc001f7d7b0c290c4a3aaa6208 100644 (file)
@@ -158,7 +158,14 @@ struct Crypto1State* lfsr_recovery32(uint32_t ks2, uint32_t in)
        // allocate memory for out of place bucket_sort\r
        bucket_array_t bucket;\r
        \r
-       if ( !bucket_malloc(bucket) ) goto out;\r
+       for (uint32_t i = 0; i < 2; i++) {\r
+               for (uint32_t j = 0; j <= 0xff; j++) {\r
+                       bucket[i][j].head = malloc(sizeof(uint32_t)<<14);\r
+                       if (!bucket[i][j].head) {\r
+                                goto out;\r
+                       }\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
@@ -181,9 +188,11 @@ struct Crypto1State* lfsr_recovery32(uint32_t ks2, uint32_t in)
        recover(odd_head, odd_tail, oks, even_head, even_tail, eks, 11, statelist, in << 1, bucket);\r
 \r
 out:\r
+       for (uint32_t i = 0; i < 2; i++)\r
+               for (uint32_t j = 0; j <= 0xff; j++)\r
+                       free(bucket[i][j].head);\r
        free(odd_head);\r
        free(even_head);\r
-       bucket_free(bucket);\r
        return statelist;\r
 }\r
 \r
@@ -477,12 +486,11 @@ struct Crypto1State* lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8]
        odd = lfsr_prefix_ks(ks, 1);\r
        even = lfsr_prefix_ks(ks, 0);\r
 \r
-       s = statelist = malloc((sizeof *statelist) << 21);\r
+       s = statelist = malloc((sizeof *statelist) << 20);\r
        if(!s || !odd || !even) {\r
                free(statelist);\r
-               free(odd);\r
-               free(even);\r
-               return 0;\r
+               statelist = 0;\r
+                goto out;\r
        }\r
 \r
        for(o = odd; *o + 1; ++o)\r
@@ -494,8 +502,8 @@ struct Crypto1State* lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8]
                        }\r
 \r
        s->odd = s->even = 0;\r
-\r
+out:\r
        free(odd);\r
        free(even);\r
        return statelist;\r
-}
\ No newline at end of file
+}\r
Impressum, Datenschutz