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\r
* using a bit of the keystream extend the table of possible lfsr states\r
*/\r
-static inline void extend_table(uint32_t *tbl, uint32_t **end, int bit, int m1, int m2, uint32_t in)\r
+static inline void\r
+extend_table(uint32_t *tbl, uint32_t **end, int bit, int m1, int m2, uint32_t in)\r
{\r
in <<= 24;\r
for(*tbl <<= 1; tbl <= *end; *++tbl <<= 1)\r
uint32_t *even_head = 0, *even_tail = 0, eks = 0;\r
int i;\r
\r
+ // split the keystream into an odd and even part\r
for(i = 31; i >= 0; i -= 2)\r
oks = oks << 1 | BEBIT(ks2, i);\r
for(i = 30; i >= 0; i -= 2)\r
\r
statelist->odd = statelist->even = 0;\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
*++odd_tail = i;\r
*++even_tail = i;\r
}\r
\r
+ // extend the statelists. Look at the next 8 Bits of the keystream (4 Bit each odd and even):\r
for(i = 0; i < 4; i++) {\r
extend_table_simple(odd_head, &odd_tail, (oks >>= 1) & 1);\r
extend_table_simple(even_head, &even_tail, (eks >>= 1) & 1);\r
}\r
\r
+ // the statelists now contain all states which could have generated the last 10 Bits of the keystream.\r
+ // 22 bits to go to recover 32 bits in total. From now on, we need to take the "in"\r
+ // parameter into account.\r
in = (in >> 16 & 0xff) | (in << 16) | (in & 0xff00);\r
recover(odd_head, odd_tail, oks,\r
even_head, even_tail, eks, 11, statelist, in << 1);\r
* encrypt the NACK which is observed when varying only the 3 last bits of Nr\r
* only correct iff [NR_3] ^ NR_3 does not depend on Nr_3\r
*/\r
- // TO VERIFY \r
uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd)\r
{\r
uint32_t *candidates = malloc(4 << 10);\r
+ if(!candidates) return 0;\r
+ \r
uint32_t c, entry;\r
int size = 0, i, good;\r
\r
- if(!candidates)\r
- return 0;\r
-\r
for(i = 0; i < 1 << 21; ++i) {\r
for(c = 0, good = 1; good && c < 8; ++c) {\r
entry = i ^ fastfwd[isodd][c];\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
return sl + good;\r
}\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
* 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
+\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
odd = lfsr_prefix_ks(ks, 1);\r
even = lfsr_prefix_ks(ks, 0);\r
\r
- s = statelist = malloc((sizeof *statelist) << 20);\r
+ s = statelist = malloc((sizeof *statelist) << 21);\r
if(!s || !odd || !even) {\r
free(statelist);\r
free(odd);\r
\r
free(odd);\r
free(even);\r
-\r
return statelist;\r
-}\r
+}
\ No newline at end of file
struct Crypto1State* lfsr_recovery32(uint32_t ks2, uint32_t in);
struct Crypto1State* lfsr_recovery64(uint32_t ks2, uint32_t ks3);
uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd);
-struct Crypto1State*
-lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8]);
+struct Crypto1State* lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8]);
uint8_t lfsr_rollback_bit(struct Crypto1State* s, uint32_t in, int fb);
uint8_t lfsr_rollback_byte(struct Crypto1State* s, uint32_t in, int fb);
x ^= x >> 4;
return BIT(0x6996, x & 0xf);
#else
- asm( "movl %1, %%eax\n"
+ __asm__( "movl %1, %%eax\n"
"mov %%ax, %%cx\n"
"shrl $0x10, %%eax\n"
"xor %%ax, %%cx\n"
odd = lfsr_prefix_ks(ks, 1);\r
even = lfsr_prefix_ks(ks, 0);\r
\r
- s = statelist = malloc((sizeof *statelist) << 20);\r
+ s = statelist = malloc((sizeof *statelist) << 21);\r
if(!s || !odd || !even) {\r
free(statelist);\r
free(odd);\r
struct Crypto1State* lfsr_recovery64(uint32_t ks2, uint32_t ks3);
uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd);
struct Crypto1State* lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8]);
-struct Crypto1State* lfsr_common_prefix_ex(uint32_t pfx, uint8_t ks[8], uint8_t par[8][8]);
uint8_t lfsr_rollback_bit(struct Crypto1State* s, uint32_t in, int fb);
uint8_t lfsr_rollback_byte(struct Crypto1State* s, uint32_t in, int fb);
x ^= x >> 4;
return BIT(0x6996, x & 0xf);
#else
- __asm__( "movl %1, %%eax\n"
+ __asm__( "movl %1, %%eax\n"
"mov %%ax, %%cx\n"
"shrl $0x10, %%eax\n"
"xor %%ax, %%cx\n"
state = lfsr_common_prefix(nr, rr, ks3x, par);
lfsr_rollback_word(state, uid^nt, 0);
crypto1_get_lfsr(state, key);
+ printf("\nkey recovered: %012"llx"\n\n",key);
crypto1_destroy(state);
return 0;
}
for (i = 7; i >= 0; --i)\r
ret |= lfsr_rollback_bit(s, BIT(in, i), fb) << i;\r
*/\r
-\r
+// unfold loop 20160112\r
uint8_t ret = 0;\r
ret |= lfsr_rollback_bit(s, BIT(in, 7), fb) << 7;\r
ret |= lfsr_rollback_bit(s, BIT(in, 6), fb) << 6;\r
for (i = 31; i >= 0; --i)\r
ret |= lfsr_rollback_bit(s, BEBIT(in, i), fb) << (i ^ 24);\r
*/\r
- \r
+// unfold loop 20160112\r
uint32_t ret = 0;\r
ret |= lfsr_rollback_bit(s, BEBIT(in, 31), fb) << (31 ^ 24);\r
ret |= lfsr_rollback_bit(s, BEBIT(in, 30), fb) << (30 ^ 24);\r
ret |= lfsr_rollback_bit(s, BEBIT(in, 2), fb) << (2 ^ 24);\r
ret |= lfsr_rollback_bit(s, BEBIT(in, 1), fb) << (1 ^ 24);\r
ret |= lfsr_rollback_bit(s, BEBIT(in, 0), fb) << (0 ^ 24);\r
- \r
return ret;\r
}\r
\r
uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd)\r
{\r
uint32_t *candidates = malloc(4 << 10);\r
+ if(!candidates) return 0;\r
+ \r
uint32_t c, entry;\r
int size = 0, i, good;\r
\r
- if(!candidates)\r
- return 0;\r
-\r
for(i = 0; i < 1 << 21; ++i) {\r
for(c = 0, good = 1; good && c < 8; ++c) {\r
entry = i ^ fastfwd[isodd][c];\r
return sl + good;\r
} \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
* It returns a zero terminated list of possible cipher states after the\r
* tag nonce was fed in\r
*/\r
+\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
odd = lfsr_prefix_ks(ks, 1);\r
even = lfsr_prefix_ks(ks, 0);\r
\r
- s = statelist = malloc((sizeof *statelist) << 20);\r
+ s = statelist = malloc((sizeof *statelist) << 21);\r
if(!s || !odd || !even) {\r
free(statelist);\r
free(odd);\r
\r
free(odd);\r
free(even);\r
-\r
return statelist;\r
-}\r
+}
\ No newline at end of file
struct Crypto1State* lfsr_recovery32(uint32_t ks2, uint32_t in);
struct Crypto1State* lfsr_recovery64(uint32_t ks2, uint32_t ks3);
uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd);
-struct Crypto1State*
-lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8]);
+struct Crypto1State* lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8]);
uint8_t lfsr_rollback_bit(struct Crypto1State* s, uint32_t in, int fb);
uint8_t lfsr_rollback_byte(struct Crypto1State* s, uint32_t in, int fb);
for (i = 0; i < 8; ++i)
ret |= crypto1_bit(s, BIT(in, i), is_encrypted) << i;
*/
- // unfold loop
+// unfold loop 20161012
uint8_t ret = 0;
ret |= crypto1_bit(s, BIT(in, 0), is_encrypted) << 0;
ret |= crypto1_bit(s, BIT(in, 1), is_encrypted) << 1;
for (i = 0; i < 32; ++i)
ret |= crypto1_bit(s, BEBIT(in, i), is_encrypted) << (i ^ 24);
*/
+//unfold loop 2016012
uint32_t ret = 0;
ret |= crypto1_bit(s, BEBIT(in, 0), is_encrypted) << (0 ^ 24);
ret |= crypto1_bit(s, BEBIT(in, 1), is_encrypted) << (1 ^ 24);
for (i = 7; i >= 0; --i)\r
ret |= lfsr_rollback_bit(s, BIT(in, i), fb) << i;\r
*/\r
-\r
+// unfold loop 20160112\r
uint8_t ret = 0;\r
ret |= lfsr_rollback_bit(s, BIT(in, 7), fb) << 7;\r
ret |= lfsr_rollback_bit(s, BIT(in, 6), fb) << 6;\r
for (i = 31; i >= 0; --i)\r
ret |= lfsr_rollback_bit(s, BEBIT(in, i), fb) << (i ^ 24);\r
*/\r
- \r
+// unfold loop 20160112\r
uint32_t ret = 0;\r
ret |= lfsr_rollback_bit(s, BEBIT(in, 31), fb) << (31 ^ 24);\r
ret |= lfsr_rollback_bit(s, BEBIT(in, 30), fb) << (30 ^ 24);\r
ret |= lfsr_rollback_bit(s, BEBIT(in, 2), fb) << (2 ^ 24);\r
ret |= lfsr_rollback_bit(s, BEBIT(in, 1), fb) << (1 ^ 24);\r
ret |= lfsr_rollback_bit(s, BEBIT(in, 0), fb) << (0 ^ 24);\r
- \r
return ret;\r
}\r
\r
uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd)\r
{\r
uint32_t *candidates = malloc(4 << 10);\r
+ if(!candidates) return 0;\r
+ \r
uint32_t c, entry;\r
int size = 0, i, good;\r
\r
- if(!candidates)\r
- return 0;\r
-\r
for(i = 0; i < 1 << 21; ++i) {\r
for(c = 0, good = 1; good && c < 8; ++c) {\r
entry = i ^ fastfwd[isodd][c];\r
return sl + good;\r
} \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
* It returns a zero terminated list of possible cipher states after the\r
* tag nonce was fed in\r
*/\r
+\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
odd = lfsr_prefix_ks(ks, 1);\r
even = lfsr_prefix_ks(ks, 0);\r
\r
- s = statelist = malloc((sizeof *statelist) << 20);\r
+ s = statelist = malloc((sizeof *statelist) << 21);\r
if(!s || !odd || !even) {\r
free(statelist);\r
free(odd);\r
\r
free(odd);\r
free(even);\r
-\r
return statelist;\r
-}\r
+}
\ No newline at end of file
struct Crypto1State* lfsr_recovery64(uint32_t ks2, uint32_t ks3);
uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd);
struct Crypto1State* lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8]);
-struct Crypto1State* lfsr_common_prefix_ex(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8]);
-
uint8_t lfsr_rollback_bit(struct Crypto1State* s, uint32_t in, int fb);
uint8_t lfsr_rollback_byte(struct Crypto1State* s, uint32_t in, int fb);
x ^= x >> 4;
return BIT(0x6996, x & 0xf);
#else
- __asm__( "movl %1, %%eax\n"
+ __asm__( "movl %1, %%eax\n"
"mov %%ax, %%cx\n"
"shrl $0x10, %%eax\n"
"xor %%ax, %%cx\n"
for (i = 0; i < 8; ++i)
ret |= crypto1_bit(s, BIT(in, i), is_encrypted) << i;
*/
- // unfold loop
+// unfold loop 20161012
uint8_t ret = 0;
ret |= crypto1_bit(s, BIT(in, 0), is_encrypted) << 0;
ret |= crypto1_bit(s, BIT(in, 1), is_encrypted) << 1;
for (i = 0; i < 32; ++i)
ret |= crypto1_bit(s, BEBIT(in, i), is_encrypted) << (i ^ 24);
*/
+//unfold loop 2016012
uint32_t ret = 0;
ret |= crypto1_bit(s, BEBIT(in, 0), is_encrypted) << (0 ^ 24);
ret |= crypto1_bit(s, BEBIT(in, 1), is_encrypted) << (1 ^ 24);