X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/8130eba4d127d1093f55334998f25230f0731a92..59152dcb05df24432f711e7032b9c9cf6050ec47:/armsrc/crapto1.c diff --git a/armsrc/crapto1.c b/armsrc/crapto1.c index 627cce4f..e2058651 100644 --- a/armsrc/crapto1.c +++ b/armsrc/crapto1.c @@ -24,9 +24,9 @@ static uint8_t filterlut[1 << 20]; static void __attribute__((constructor)) fill_lut() { - uint32_t i; - for(i = 0; i < 1 << 20; ++i) - filterlut[i] = filter(i); + uint32_t i; + for(i = 0; i < 1 << 20; ++i) + filterlut[i] = filter(i); } #define filter(x) (filterlut[(x) & 0xfffff]) #endif @@ -419,10 +419,11 @@ static uint16_t *dist = 0; int nonce_distance(uint32_t from, uint32_t to) { uint16_t x, i; - if(!dist) { + // generate distance lookup table + if (!dist) { dist = malloc(2 << 16); - if(!dist) - return -1; + if (!dist) return -1; + for (x = i = 1; i; ++i) { dist[(x & 0xff) << 8 | x >> 8] = i; x = x >> 1 | (x ^ x >> 2 ^ x >> 3 ^ x >> 5) << 15; @@ -446,7 +447,7 @@ static uint32_t fastfwd[2][8] = { * encrypt the NACK which is observed when varying only the 3 last bits of Nr * only correct iff [NR_3] ^ NR_3 does not depend on Nr_3 */ -uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd) +uint32_t* lfsr_prefix_ks(uint8_t ks[8], int isodd) { uint32_t *candidates = malloc(4 << 10); if(!candidates) return 0; @@ -509,7 +510,6 @@ 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; @@ -521,9 +521,8 @@ struct Crypto1State* lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8] s = statelist = malloc((sizeof *statelist) << 21); if(!s || !odd || !even) { free(statelist); - free(odd); - free(even); - return 0; + statelist = 0; + goto out; } for(o = odd; *o + 1; ++o) @@ -535,7 +534,7 @@ struct Crypto1State* lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8] } s->odd = s->even = 0; - +out: free(odd); free(even); return statelist;