mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 13:23:51 -07:00
wrong param name. thanks @annplusplus for finding it
This commit is contained in:
parent
ae80614a1a
commit
5a5bb22ef6
1 changed files with 66 additions and 27 deletions
|
@ -21,24 +21,49 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "parity.h"
|
#include "parity.h"
|
||||||
|
|
||||||
#if !defined LOWMEM && defined __GNUC__
|
|
||||||
static uint8_t filterlut[1 << 20];
|
#if !defined LOWMEM
|
||||||
static void __attribute__((constructor)) fill_lut(void) {
|
#define CONSTRUCTOR
|
||||||
uint32_t i;
|
static uint8_t filterlut[0x100000];
|
||||||
for (i = 0; i < 1 << 20; ++i)
|
static uint8_t uc_evenparity32_lut[0x10E100A];
|
||||||
filterlut[i] = filter(i);
|
|
||||||
}
|
// GUNC
|
||||||
#define filter(x) (filterlut[(x) & 0xfffff])
|
#if defined __GNUC__
|
||||||
|
#undef CONSTRUCTOR
|
||||||
|
#define CONSTRUCTOR __attribute__((constructor))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** update_contribution
|
static void CONSTRUCTOR init_lut(void) {
|
||||||
* helper, calculates the partial linear feedback contributions and puts in MSB
|
|
||||||
|
for (uint32_t i = 0; i < 1 << 20; ++i) {
|
||||||
|
filterlut[i] = filter(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < 0x10E100A; i++) {
|
||||||
|
uc_evenparity32_lut[i] = evenparity32(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MSVC
|
||||||
|
#if defined _MSC_VER
|
||||||
|
|
||||||
|
typedef void(__cdecl* PF)(void);
|
||||||
|
#pragma section(".CRT$XCG", read)
|
||||||
|
__declspec(allocate(".CRT$XCG")) PF f[] = { init_lut };
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define filter(x) (filterlut[(x) & 0xfffff])
|
||||||
|
#define even32(x) (uc_evenparity32_lut[(x)])
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** update_contribution helper,
|
||||||
|
* calculates the partial linear feedback contributions and puts in MSB
|
||||||
*/
|
*/
|
||||||
static inline void update_contribution(uint32_t *item, const uint32_t mask1, const uint32_t mask2) {
|
static inline void update_contribution(uint32_t *item, const uint32_t mask1, const uint32_t mask2) {
|
||||||
uint32_t p = *item >> 25;
|
uint32_t p = *item >> 25;
|
||||||
|
p = p << 1 | (even32(*item & mask1));
|
||||||
p = p << 1 | (evenparity32(*item & mask1));
|
p = p << 1 | (even32(*item & mask2));
|
||||||
p = p << 1 | (evenparity32(*item & mask2));
|
|
||||||
*item = p << 24 | (*item & 0xffffff);
|
*item = p << 24 | (*item & 0xffffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,33 +71,43 @@ static inline void update_contribution(uint32_t *item, const uint32_t mask1, con
|
||||||
* using a bit of the keystream extend the table of possible lfsr states
|
* using a bit of the keystream extend the table of possible lfsr states
|
||||||
*/
|
*/
|
||||||
static inline void extend_table(uint32_t *tbl, uint32_t **end, int bit, int m1, int m2, uint32_t in) {
|
static inline void extend_table(uint32_t *tbl, uint32_t **end, int bit, int m1, int m2, uint32_t in) {
|
||||||
|
register uint8_t tbl_filter;
|
||||||
in <<= 24;
|
in <<= 24;
|
||||||
for (*tbl <<= 1; tbl <= *end; *++tbl <<= 1)
|
for (*tbl <<= 1; tbl <= *end; *++tbl <<= 1) {
|
||||||
if (filter(*tbl) ^ filter(*tbl | 1)) {
|
tbl_filter = filter(*tbl);
|
||||||
*tbl |= filter(*tbl) ^ bit;
|
if (tbl_filter ^ filter(*tbl | 1)) {
|
||||||
|
*tbl |= tbl_filter ^ bit;
|
||||||
update_contribution(tbl, m1, m2);
|
update_contribution(tbl, m1, m2);
|
||||||
*tbl ^= in;
|
*tbl ^= in;
|
||||||
} else if (filter(*tbl) == bit) {
|
}
|
||||||
|
else if (tbl_filter == bit) {
|
||||||
*++*end = tbl[1];
|
*++*end = tbl[1];
|
||||||
tbl[1] = tbl[0] | 1;
|
tbl[1] = tbl[0] | 1;
|
||||||
update_contribution(tbl, m1, m2);
|
update_contribution(tbl, m1, m2);
|
||||||
*tbl++ ^= in;
|
*tbl++ ^= in;
|
||||||
update_contribution(tbl, m1, m2);
|
update_contribution(tbl, m1, m2);
|
||||||
*tbl ^= in;
|
*tbl ^= in;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
*tbl-- = *(*end)--;
|
*tbl-- = *(*end)--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** extend_table_simple
|
/** extend_table_simple
|
||||||
* using a bit of the keystream extend the table of possible lfsr states
|
* using a bit of the keystream extend the table of possible lfsr states
|
||||||
*/
|
*/
|
||||||
static inline void extend_table_simple(uint32_t *tbl, uint32_t **end, int bit) {
|
static inline void extend_table_simple(uint32_t *tbl, uint32_t **end, int bit) {
|
||||||
|
register uint8_t tbl_filter;
|
||||||
for (*tbl <<= 1; tbl <= *end; *++tbl <<= 1) {
|
for (*tbl <<= 1; tbl <= *end; *++tbl <<= 1) {
|
||||||
if (filter(*tbl) ^ filter(*tbl | 1)) { // replace
|
tbl_filter = filter(*tbl);
|
||||||
*tbl |= filter(*tbl) ^ bit;
|
if (tbl_filter ^ filter(*tbl | 1)) { // replace
|
||||||
} else if (filter(*tbl) == bit) { // insert
|
*tbl |= tbl_filter ^ bit;
|
||||||
|
}
|
||||||
|
else if (tbl_filter == bit) { // insert
|
||||||
*++*end = *++tbl;
|
*++*end = *++tbl;
|
||||||
*tbl = tbl[-1] | 1;
|
*tbl = tbl[-1] | 1;
|
||||||
} else { // drop
|
}
|
||||||
|
else { // drop
|
||||||
*tbl-- = *(*end)--;
|
*tbl-- = *(*end)--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,10 +123,10 @@ recover(uint32_t *o_head, uint32_t *o_tail, uint32_t oks,
|
||||||
|
|
||||||
if (rem == -1) {
|
if (rem == -1) {
|
||||||
for (uint32_t *e = e_head; e <= e_tail; ++e) {
|
for (uint32_t *e = e_head; e <= e_tail; ++e) {
|
||||||
*e = *e << 1 ^ (evenparity32(*e & LF_POLY_EVEN)) ^ (!!(in & 4));
|
*e = *e << 1 ^ (even32(*e & LF_POLY_EVEN)) ^ (!!(in & 4));
|
||||||
for (uint32_t *o = o_head; o <= o_tail; ++o, ++sl) {
|
for (uint32_t *o = o_head; o <= o_tail; ++o, ++sl) {
|
||||||
sl->even = *o;
|
sl->even = *o;
|
||||||
sl->odd = *e ^ (evenparity32(*o & LF_POLY_ODD));
|
sl->odd = *e ^ (even32(*o & LF_POLY_ODD));
|
||||||
sl[1].odd = sl[1].even = 0;
|
sl[1].odd = sl[1].even = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +168,7 @@ struct Crypto1State *lfsr_recovery32(uint32_t ks2, uint32_t in) {
|
||||||
struct Crypto1State *statelist;
|
struct Crypto1State *statelist;
|
||||||
uint32_t *odd_head = 0, *odd_tail = 0, oks = 0;
|
uint32_t *odd_head = 0, *odd_tail = 0, oks = 0;
|
||||||
uint32_t *even_head = 0, *even_tail = 0, eks = 0;
|
uint32_t *even_head = 0, *even_tail = 0, eks = 0;
|
||||||
int i;
|
register int i;
|
||||||
|
|
||||||
// split the keystream into an odd and even part
|
// split the keystream into an odd and even part
|
||||||
for (i = 31; i >= 0; i -= 2)
|
for (i = 31; i >= 0; i -= 2)
|
||||||
|
@ -165,10 +200,14 @@ struct Crypto1State *lfsr_recovery32(uint32_t ks2, uint32_t in) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize statelists: add all possible states which would result into the rightmost 2 bits of the keystream
|
// initialize statelists: add all possible states which would result into the rightmost 2 bits of the keystream
|
||||||
|
uint8_t oks_b1 = oks & 1;
|
||||||
|
uint8_t eks_b1 = eks & 1;
|
||||||
|
register uint8_t tbl_filter;
|
||||||
for (i = 1 << 20; i >= 0; --i) {
|
for (i = 1 << 20; i >= 0; --i) {
|
||||||
if (filter(i) == (oks & 1))
|
tbl_filter = filter(i);
|
||||||
|
if (tbl_filter == oks_b1)
|
||||||
*++odd_tail = i;
|
*++odd_tail = i;
|
||||||
if (filter(i) == (eks & 1))
|
if (tbl_filter == eks_b1)
|
||||||
*++even_tail = i;
|
*++even_tail = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue