static inline void extend_table_simple(uint32_t *tbl, uint32_t **end, int bit)\r
{\r
for(*tbl <<= 1; tbl <= *end; *++tbl <<= 1)\r
- if(filter(*tbl) ^ filter(*tbl | 1))\r
+ if(filter(*tbl) ^ filter(*tbl | 1)) {\r
*tbl |= filter(*tbl) ^ bit;\r
- else if(filter(*tbl) == bit) {\r
+ } else if(filter(*tbl) == bit) {\r
*++*end = *++tbl;\r
*tbl = tbl[-1] | 1;\r
} else\r
static uint32_t fastfwd[2][8] = {\r
{ 0, 0x4BC53, 0xECB1, 0x450E2, 0x25E29, 0x6E27A, 0x2B298, 0x60ECB},\r
{ 0, 0x1D962, 0x4BC53, 0x56531, 0xECB1, 0x135D3, 0x450E2, 0x58980}};\r
+\r
+\r
/** lfsr_prefix_ks\r
*\r
* Is an exported helper function from the common prefix attack\r
/** check_pfx_parity\r
* helper function which eliminates possible secret states using parity bits\r
*/\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
+static struct Crypto1State* check_pfx_parity(uint32_t prefix, uint32_t rresp, uint8_t parities[8][8], uint32_t odd, uint32_t even, struct Crypto1State* sl)\r
{\r
uint32_t ks1, nr, ks2, rr, ks3, c, good = 1;\r
\r
\r
/** lfsr_common_prefix\r
* Implentation of the common prefix attack.\r
+ * Requires the 28 bit constant prefix used as reader nonce (pfx)\r
+ * The reader response used (rr)\r
+ * The keystream used to encrypt the observed NACK's (ks)\r
+ * The parity bits (par)\r
+ * 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])\r
+struct Crypto1State* lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8])\r
{\r
struct Crypto1State *statelist, *s;\r
uint32_t *odd, *even, *o, *e, top;\r
s = statelist = malloc((sizeof *statelist) << 20);\r
if(!s || !odd || !even) {\r
free(statelist);\r
- statelist = 0;\r
- goto out;\r
+ free(odd);\r
+ free(even);\r
+ return 0;\r
}\r
\r
for(o = odd; *o + 1; ++o)\r
}\r
\r
s->odd = s->even = 0;\r
-out:\r
- free(odd);\r
- free(even);\r
+\r
return statelist;\r
}\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
+ Copyright (C) 2008-2014 bla <blapost@gmail.com>\r
*/\r
#include "crapto1.h"\r
#include <stdlib.h>\r
/** extend_table_simple\r
* using a bit of the keystream extend the table of possible lfsr states\r
*/\r
-static inline void\r
-extend_table_simple(uint32_t *tbl, uint32_t **end, int bit)\r
+static inline void extend_table_simple(uint32_t *tbl, uint32_t **end, int bit)\r
{\r
for(*tbl <<= 1; tbl <= *end; *++tbl <<= 1)\r
if(filter(*tbl) ^ filter(*tbl | 1)) {\r