From: iceman1001 Date: Wed, 10 Feb 2016 20:44:32 +0000 (+0100) Subject: CHG: my idea of malloc and free for bucketsort didn't work so well. Back to the... X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/df4ee66ea9e0792a1ef1df00554b5224e2f1446e CHG: my idea of malloc and free for bucketsort didn't work so well. Back to the original. --- diff --git a/client/nonce2key/crapto1.c b/client/nonce2key/crapto1.c index 36e21a1c..919820e9 100644 --- a/client/nonce2key/crapto1.c +++ b/client/nonce2key/crapto1.c @@ -158,7 +158,14 @@ struct Crypto1State* lfsr_recovery32(uint32_t ks2, uint32_t in) // allocate memory for out of place bucket_sort bucket_array_t bucket; - if ( !bucket_malloc(bucket) ) goto out; + for (uint32_t i = 0; i < 2; i++) { + for (uint32_t j = 0; j <= 0xff; j++) { + bucket[i][j].head = malloc(sizeof(uint32_t)<<14); + if (!bucket[i][j].head) { + goto out; + } + } + } // initialize statelists: add all possible states which would result into the rightmost 2 bits of the keystream for(i = 1 << 20; i >= 0; --i) { @@ -183,7 +190,9 @@ struct Crypto1State* lfsr_recovery32(uint32_t ks2, uint32_t in) out: free(odd_head); free(even_head); - bucket_free(bucket); + for (uint8_t i = 0; i < 2; i++) + for (uint8_t j = 0; j <= 0xff; j++) + free(bucket[i][j].head); return statelist; } diff --git a/common/bucketsort.c b/common/bucketsort.c index c4199803..2aca2632 100644 --- a/common/bucketsort.c +++ b/common/bucketsort.c @@ -1,23 +1,5 @@ #include "bucketsort.h" -bool bucket_malloc(bucket_array_t bucket) { - for (uint32_t i = 0; i < 2; i++) { - for (uint32_t j = 0; j <= 0xff; j++) { - bucket[i][j].head = malloc(sizeof(uint32_t)<<14); - if (!bucket[i][j].head) { - return false; - } - } - } - return true; -} - -void bucket_free(bucket_array_t bucket) { - for (uint8_t i = 0; i < 2; i++) - for (uint8_t j = 0; j <= 0xff; j++) - free(bucket[i][j].head); -} - void bucket_sort_intersect(uint32_t* const estart, uint32_t* const estop, uint32_t* const ostart, uint32_t* const ostop, bucket_info_t *bucket_info, bucket_array_t bucket) diff --git a/common/bucketsort.h b/common/bucketsort.h index 399277c1..d5423aa5 100644 --- a/common/bucketsort.h +++ b/common/bucketsort.h @@ -1,7 +1,6 @@ #ifndef BUCKETSORT_H__ #define BUCKETSORT_H__ #include -#include #include typedef struct bucket { uint32_t *head; @@ -17,9 +16,6 @@ typedef struct bucket_info { uint32_t numbuckets; } bucket_info_t; - -bool bucket_malloc(bucket_array_t bucket); -void bucket_free(bucket_array_t bucket); void bucket_sort_intersect(uint32_t* const estart, uint32_t* const estop, uint32_t* const ostart, uint32_t* const ostop, bucket_info_t *bucket_info, bucket_array_t bucket);