/* 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
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
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
++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
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
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
{\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
*/\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
}\r
\r
return sl + good;\r
-} \r
+}\r
\r
\r
/** lfsr_common_prefix\r
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
/* crypto1.c
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- MA 02110-1301, US
-
- Copyright (C) 2008-2008 bla <blapost@gmail.com>
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ MA 02110-1301, US
+
+ Copyright (C) 2008-2008 bla <blapost@gmail.com>
*/
#include "crapto1.h"
#include <stdlib.h>
void crypto1_destroy(struct Crypto1State *state)
{
// free(state);
- state->odd = 0;
- state->even = 0;
+ state->odd = 0;
+ state->even = 0;
}
void crypto1_get_lfsr(struct Crypto1State *state, uint64_t *lfsr)
{
uint8_t crypto1_bit(struct Crypto1State *s, uint8_t in, int is_encrypted)
{
uint32_t feedin;
+ uint32_t tmp;
uint8_t ret = filter(s->odd);
feedin = ret & !!is_encrypted;
feedin ^= LF_POLY_EVEN & s->even;
s->even = s->even << 1 | parity(feedin);
- s->odd ^= (s->odd ^= s->even, s->even ^= s->odd);
+ tmp = s->odd;
+ s->odd = s->even;
+ s->even = tmp;
return ret;
}
/* 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
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
} bucket_info[2][0x100];\r
uint32_t numbuckets;\r
} bucket_info_t;\r
- \r
+\r
\r
static void bucket_sort_intersect(uint32_t* const estart, uint32_t* const estop,\r
uint32_t* const ostart, uint32_t* const ostop,\r
uint32_t *p1, *p2;\r
uint32_t *start[2];\r
uint32_t *stop[2];\r
- \r
+\r
start[0] = estart;\r
stop[0] = estop;\r
start[1] = ostart;\r
stop[1] = ostop;\r
- \r
+\r
// init buckets to be empty\r
for (uint32_t i = 0; i < 2; i++) {\r
for (uint32_t j = 0x00; j <= 0xff; j++) {\r
bucket[i][j].bp = bucket[i][j].head;\r
}\r
}\r
- \r
+\r
// sort the lists into the buckets based on the MSB (contribution bits)\r
- for (uint32_t i = 0; i < 2; i++) { \r
+ for (uint32_t i = 0; i < 2; i++) {\r
for (p1 = start[i]; p1 <= stop[i]; p1++) {\r
uint32_t bucket_index = (*p1 & 0xff000000) >> 24;\r
*(bucket[i][bucket_index].bp++) = *p1;\r
}\r
}\r
\r
- \r
+\r
// write back intersecting buckets as sorted list.\r
// fill in bucket_info with head and tail of the bucket contents in the list and number of non-empty buckets.\r
uint32_t nonempty_bucket;\r
*p ^= in;\r
} else { // drop\r
*p-- = *(*end)--;\r
- } \r
+ }\r
}\r
- \r
+\r
}\r
\r
\r
static inline void\r
extend_table_simple(uint32_t *tbl, uint32_t **end, int bit)\r
{\r
- for(*tbl <<= 1; tbl <= *end; *++tbl <<= 1) \r
+ for(*tbl <<= 1; tbl <= *end; *++tbl <<= 1)\r
if(filter(*tbl) ^ filter(*tbl | 1)) { // replace\r
*tbl |= filter(*tbl) ^ bit;\r
} else if(filter(*tbl) == bit) { // insert\r
}\r
\r
bucket_sort_intersect(e_head, e_tail, o_head, o_tail, &bucket_info, bucket);\r
- \r
+\r
for (int i = bucket_info.numbuckets - 1; i >= 0; i--) {\r
sl = recover(bucket_info.bucket_info[1][i].head, bucket_info.bucket_info[1][i].tail, oks,\r
- bucket_info.bucket_info[0][i].head, bucket_info.bucket_info[0][i].tail, eks,\r
+ bucket_info.bucket_info[0][i].head, bucket_info.bucket_info[0][i].tail, eks,\r
rem, sl, in, bucket);\r
}\r
- \r
+\r
return sl;\r
}\r
/** lfsr_recovery\r
}\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
if(filter(i) == (oks & 1))\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
- \r
+\r
return statelist;\r
}\r
\r
void lfsr_rollback_bit(struct Crypto1State *s, uint32_t in, int fb)\r
{\r
int out;\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
*/\r
static struct Crypto1State*\r
brute_top(uint32_t prefix, uint32_t rresp, unsigned char parities[8][8],\r
- uint32_t odd, uint32_t even, struct Crypto1State* sl, uint8_t no_chk)\r
+ uint32_t odd, uint32_t even, struct Crypto1State* sl, uint8_t no_chk)\r
{\r
struct Crypto1State s;\r
uint32_t ks1, nr, ks2, rr, ks3, good, c;\r
for(c = 0; c < 8; ++c) {\r
s.odd = odd ^ fastfwd[1][c];\r
s.even = even ^ fastfwd[0][c];\r
- \r
+\r
lfsr_rollback_bit(&s, 0, 0);\r
lfsr_rollback_bit(&s, 0, 0);\r
lfsr_rollback_bit(&s, 0, 0);\r
- \r
+\r
lfsr_rollback_word(&s, 0, 0);\r
lfsr_rollback_word(&s, prefix | c << 5, 1);\r
- \r
+\r
sl->odd = s.odd;\r
sl->even = s.even;\r
- \r
+\r
if (no_chk)\r
break;\r
- \r
+\r
ks1 = crypto1_word(&s, prefix | c << 5, 1);\r
ks2 = crypto1_word(&s,0,0);\r
ks3 = crypto1_word(&s, 0,0);\r
}\r
\r
return ++sl;\r
-} \r
+}\r
\r
\r
/** lfsr_common_prefix\r
odd = lfsr_prefix_ks(ks, 1);\r
even = lfsr_prefix_ks(ks, 0);\r
\r
- statelist = malloc((sizeof *statelist) << 21); //how large should be? \r
+ 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
+ return 0;\r
}\r
\r
s = statelist;\r
s = brute_top(pfx, rr, par, *o, *e, s, no_par);\r
}\r
\r
- s->odd = s->even = -1; \r
+ s->odd = s->even = -1;\r
//printf("state count = %d\n",s-statelist);\r
\r
free(odd);\r
/* crypto1.c
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- MA 02110-1301, US
-
- Copyright (C) 2008-2008 bla <blapost@gmail.com>
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ MA 02110-1301, US
+
+ Copyright (C) 2008-2008 bla <blapost@gmail.com>
*/
#include "crapto1.h"
#include <stdlib.h>
uint8_t crypto1_bit(struct Crypto1State *s, uint8_t in, int is_encrypted)
{
uint32_t feedin;
+ uint32_t tmp;
uint8_t ret = filter(s->odd);
feedin = ret & !!is_encrypted;
feedin ^= LF_POLY_EVEN & s->even;
s->even = s->even << 1 | parity(feedin);
- s->odd ^= (s->odd ^= s->even, s->even ^= s->odd);
+ tmp = s->odd;
+ s->odd = s->even;
+ s->even = tmp;
return ret;
}
wire reader_modulation = !ssp_dout & lf_field & pck_divclk;
// No logic, straight through.
-assign pwr_oe1 = 1'b0; // not used in LF mode
+assign pwr_oe1 = 1'b0; // not used in LF mode
+assign pwr_oe3 = 1'b0; // base antenna load = 33 Ohms
+// when modulating, add another 33 Ohms and 10k Ohms in parallel:
assign pwr_oe2 = tag_modulation;
-assign pwr_oe3 = tag_modulation;
-assign pwr_oe4 = tag_modulation;
+assign pwr_oe4 = tag_modulation;
+
assign ssp_clk = cross_lo;
assign pwr_lo = reader_modulation;
assign pwr_hi = 1'b0;