]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/crapto1.c
Fixed issue #36 & improved file consistency.
[proxmark3-svn] / armsrc / crapto1.c
index 9d491d1271ff1fdcda05b5ae980e1530f8d00ccc..bcd3117114147a5287eb6c0d694f21abb239d501 100644 (file)
@@ -1,21 +1,21 @@
 /*  crapto1.c\r
 \r
-    This program is free software; you can redistribute it and/or\r
-    modify it under the terms of the GNU General Public License\r
-    as published by the Free Software Foundation; either version 2\r
-    of the License, or (at your option) any later version.\r
-\r
-    This program is distributed in the hope that it will be useful,\r
-    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-    GNU General Public License for more details.\r
-\r
-    You should have received a copy of the GNU General Public License\r
-    along with this program; if not, write to the Free Software\r
-    Foundation, Inc., 51 Franklin Street, Fifth Floor,\r
-    Boston, MA  02110-1301, US$\r
-\r
-    Copyright (C) 2008-2008 bla <blapost@gmail.com>\r
+       This program is free software; you can redistribute it and/or\r
+       modify it under the terms of the GNU General Public License\r
+       as published by the Free Software Foundation; either version 2\r
+       of the License, or (at your option) any later version.\r
+\r
+       This program is distributed in the hope that it will be useful,\r
+       but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+       GNU General Public License for more details.\r
+\r
+       You should have received a copy of the GNU General Public License\r
+       along with this program; if not, write to the Free Software\r
+       Foundation, Inc., 51 Franklin Street, Fifth Floor,\r
+       Boston, MA  02110-1301, US$\r
+\r
+       Copyright (C) 2008-2008 bla <blapost@gmail.com>\r
 */\r
 #include "crapto1.h"\r
 #include <stdlib.h>\r
@@ -24,9 +24,9 @@
 static uint8_t filterlut[1 << 20];\r
 static void __attribute__((constructor)) fill_lut()\r
 {\r
-        uint32_t i;\r
-        for(i = 0; i < 1 << 20; ++i)\r
-                filterlut[i] = filter(i);\r
+       uint32_t i;\r
+       for(i = 0; i < 1 << 20; ++i)\r
+               filterlut[i] = filter(i);\r
 }\r
 #define filter(x) (filterlut[(x) & 0xfffff])\r
 #endif\r
@@ -34,6 +34,7 @@ static void __attribute__((constructor)) fill_lut()
 static void quicksort(uint32_t* const start, uint32_t* const stop)\r
 {\r
        uint32_t *it = start + 1, *rit = stop;\r
+       uint32_t tmp;\r
 \r
        if(it > rit)\r
                return;\r
@@ -43,13 +44,19 @@ static void quicksort(uint32_t* const start, uint32_t* const stop)
                        ++it;\r
                else if(*rit > *start)\r
                        --rit;\r
-               else\r
-                       *it ^= (*it ^= *rit, *rit ^= *it);\r
+               else {\r
+                       tmp = *it;\r
+                       *it = *rit;\r
+                       *rit = tmp;\r
+               }\r
 \r
        if(*rit >= *start)\r
                --rit;\r
-       if(rit != start)\r
-               *rit ^= (*rit ^= *start, *start ^= *rit);\r
+       if(rit != start) {\r
+               tmp = *rit;\r
+               *rit = *start;\r
+               *start = tmp;\r
+       }\r
 \r
        quicksort(start, rit - 1);\r
        quicksort(rit + 1, stop);\r
@@ -145,12 +152,12 @@ recover(uint32_t *o_head, uint32_t *o_tail, uint32_t oks,
                eks >>= 1;\r
                in >>= 2;\r
                extend_table(o_head, &o_tail, oks & 1, LF_POLY_EVEN << 1 | 1,\r
-                            LF_POLY_ODD << 1, 0);\r
+                                LF_POLY_ODD << 1, 0);\r
                if(o_head > o_tail)\r
                        return sl;\r
 \r
                extend_table(e_head, &e_tail, eks & 1, LF_POLY_ODD,\r
-                            LF_POLY_EVEN << 1 | 1, in & 3);\r
+                                LF_POLY_EVEN << 1 | 1, in & 3);\r
                if(e_head > e_tail)\r
                        return sl;\r
        }\r
@@ -163,7 +170,7 @@ recover(uint32_t *o_head, uint32_t *o_tail, uint32_t oks,
                        o_tail = binsearch(o_head, o = o_tail);\r
                        e_tail = binsearch(e_head, e = e_tail);\r
                        sl = recover(o_tail--, o, oks,\r
-                                    e_tail--, e, eks, rem, sl, in);\r
+                                        e_tail--, e, eks, rem, sl, in);\r
                }\r
                else if(*o_tail > *e_tail)\r
                        o_tail = binsearch(o_head, o_tail) - 1;\r
@@ -319,9 +326,12 @@ uint8_t lfsr_rollback_bit(struct Crypto1State *s, uint32_t in, int fb)
 {\r
        int out;\r
        uint8_t ret;\r
+       uint32_t tmp;\r
 \r
        s->odd &= 0xffffff;\r
-       s->odd ^= (s->odd ^= s->even, s->even ^= s->odd);\r
+       tmp = s->odd;\r
+       s->odd = s->even;\r
+       s->even = tmp;\r
 \r
        out = s->even & 1;\r
        out ^= LF_POLY_EVEN & (s->even >>= 1);\r
@@ -414,7 +424,7 @@ uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd)
  */\r
 static struct Crypto1State*\r
 check_pfx_parity(uint32_t prefix, uint32_t rresp, uint8_t parities[8][8],\r
-               uint32_t odd, uint32_t even, struct Crypto1State* sl)\r
+               uint32_t odd, uint32_t even, struct Crypto1State* sl)\r
 {\r
        uint32_t ks1, nr, ks2, rr, ks3, c, good = 1;\r
 \r
@@ -440,7 +450,7 @@ check_pfx_parity(uint32_t prefix, uint32_t rresp, uint8_t parities[8][8],
        }\r
 \r
        return sl + good;\r
-} \r
+}\r
 \r
 \r
 /** lfsr_common_prefix\r
@@ -459,7 +469,7 @@ lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8])
        if(!s || !odd || !even) {\r
                free(statelist);\r
                statelist = 0;\r
-                goto out;\r
+               goto out;\r
        }\r
 \r
        for(o = odd; *o + 1; ++o)\r
Impressum, Datenschutz