X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/a1afa550ea5b602b6d8bc69bdc6f018696b21ff0..5ebcb867a3552a36953b36653b67d4e83e5a9ab3:/tools/nonce2key/crapto1.c diff --git a/tools/nonce2key/crapto1.c b/tools/nonce2key/crapto1.c index 10dedcb5..ca2a30da 100644 --- a/tools/nonce2key/crapto1.c +++ b/tools/nonce2key/crapto1.c @@ -349,7 +349,7 @@ uint8_t lfsr_rollback_byte(struct Crypto1State *s, uint32_t in, int fb) for (i = 7; i >= 0; --i) ret |= lfsr_rollback_bit(s, BIT(in, i), fb) << i; */ - +// unfold loop 20160112 uint8_t ret = 0; ret |= lfsr_rollback_bit(s, BIT(in, 7), fb) << 7; ret |= lfsr_rollback_bit(s, BIT(in, 6), fb) << 6; @@ -372,7 +372,7 @@ uint32_t lfsr_rollback_word(struct Crypto1State *s, uint32_t in, int fb) for (i = 31; i >= 0; --i) ret |= lfsr_rollback_bit(s, BEBIT(in, i), fb) << (i ^ 24); */ - +// unfold loop 20160112 uint32_t ret = 0; ret |= lfsr_rollback_bit(s, BEBIT(in, 31), fb) << (31 ^ 24); ret |= lfsr_rollback_bit(s, BEBIT(in, 30), fb) << (30 ^ 24); @@ -409,7 +409,6 @@ uint32_t lfsr_rollback_word(struct Crypto1State *s, uint32_t in, int fb) ret |= lfsr_rollback_bit(s, BEBIT(in, 2), fb) << (2 ^ 24); ret |= lfsr_rollback_bit(s, BEBIT(in, 1), fb) << (1 ^ 24); ret |= lfsr_rollback_bit(s, BEBIT(in, 0), fb) << (0 ^ 24); - return ret; } @@ -450,12 +449,11 @@ static uint32_t fastfwd[2][8] = { uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd) { uint32_t *candidates = malloc(4 << 10); + if(!candidates) return 0; + uint32_t c, entry; int size = 0, i, good; - if(!candidates) - return 0; - for(i = 0; i < 1 << 21; ++i) { for(c = 0, good = 1; good && c < 8; ++c) { entry = i ^ fastfwd[isodd][c]; @@ -502,7 +500,6 @@ static struct Crypto1State* check_pfx_parity(uint32_t prefix, uint32_t rresp, ui return sl + good; } - /** lfsr_common_prefix * Implentation of the common prefix attack. * Requires the 28 bit constant prefix used as reader nonce (pfx) @@ -512,6 +509,7 @@ static struct Crypto1State* check_pfx_parity(uint32_t prefix, uint32_t rresp, ui * It returns a zero terminated list of possible cipher states after the * tag nonce was fed in */ + struct Crypto1State* lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8]) { struct Crypto1State *statelist, *s; @@ -520,7 +518,7 @@ struct Crypto1State* lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8] odd = lfsr_prefix_ks(ks, 1); even = lfsr_prefix_ks(ks, 0); - s = statelist = malloc((sizeof *statelist) << 20); + s = statelist = malloc((sizeof *statelist) << 21); if(!s || !odd || !even) { free(statelist); free(odd); @@ -540,6 +538,5 @@ struct Crypto1State* lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8] free(odd); free(even); - return statelist; -} +} \ No newline at end of file