X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/9492e0b0986a557afe1c85f08fd02a7fb979f536..a1d17964a218f65acb20b3ff4c651a228d54c7b4:/client/nonce2key/crapto1.c diff --git a/client/nonce2key/crapto1.c b/client/nonce2key/crapto1.c index fc878a0d..6c0fcafa 100644 --- a/client/nonce2key/crapto1.c +++ b/client/nonce2key/crapto1.c @@ -95,32 +95,6 @@ static void bucket_sort_intersect(uint32_t* const estart, uint32_t* const estop, } } - -static void quicksort(uint32_t* const start, uint32_t* const stop) -{ - uint32_t *it = start + 1, *rit = stop; - - if(it > rit) - return; - - while(it < rit) - if(*it <= *start) - ++it; - else if(*rit > *start) - --rit; - else - *it ^= (*it ^= *rit, *rit ^= *it); - - if(*rit >= *start) - --rit; - if(rit != start) - *rit ^= (*rit ^= *start, *start ^= *rit); - - quicksort(start, rit - 1); - quicksort(rit + 1, stop); -} - - /** binsearch * Binary search for the first occurence of *stop's MSB in sorted [start,stop] */ @@ -507,7 +481,7 @@ uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd) */ static struct Crypto1State* brute_top(uint32_t prefix, uint32_t rresp, unsigned char parities[8][8], - uint32_t odd, uint32_t even, struct Crypto1State* sl) + uint32_t odd, uint32_t even, struct Crypto1State* sl, uint8_t no_chk) { struct Crypto1State s; uint32_t ks1, nr, ks2, rr, ks3, good, c; @@ -525,6 +499,9 @@ brute_top(uint32_t prefix, uint32_t rresp, unsigned char parities[8][8], sl->odd = s.odd; sl->even = s.even; + + if (no_chk) + break; ks1 = crypto1_word(&s, prefix | c << 5, 1); ks2 = crypto1_word(&s,0,0); @@ -557,7 +534,7 @@ brute_top(uint32_t prefix, uint32_t rresp, unsigned char parities[8][8], * 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]) +lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8], uint8_t no_par) { struct Crypto1State *statelist, *s; uint32_t *odd, *even, *o, *e, top; @@ -565,21 +542,26 @@ lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8]) odd = lfsr_prefix_ks(ks, 1); even = lfsr_prefix_ks(ks, 0); - statelist = malloc((sizeof *statelist) << 20); + statelist = malloc((sizeof *statelist) << 21); //how large should be? if(!statelist || !odd || !even) + { + free(statelist); + free(odd); + free(even); return 0; - + } s = statelist; - for(o = odd; *o != 0xffffffff; ++o) - for(e = even; *e != 0xffffffff; ++e) + for(o = odd; *o != -1; ++o) + for(e = even; *e != -1; ++e) for(top = 0; top < 64; ++top) { *o = (*o & 0x1fffff) | (top << 21); *e = (*e & 0x1fffff) | (top >> 3) << 21; - s = brute_top(pfx, rr, par, *o, *e, s); + s = brute_top(pfx, rr, par, *o, *e, s, no_par); } - s->odd = s->even = 0; + s->odd = s->even = -1; + //printf("state count = %d\n",s-statelist); free(odd); free(even);