CHG: my idea of malloc and free for bucketsort didn't work so well. Back to the original.

This commit is contained in:
iceman1001 2016-02-10 21:44:32 +01:00
commit df4ee66ea9
3 changed files with 11 additions and 24 deletions

View file

@ -158,7 +158,14 @@ struct Crypto1State* lfsr_recovery32(uint32_t ks2, uint32_t in)
// allocate memory for out of place bucket_sort // allocate memory for out of place bucket_sort
bucket_array_t bucket; 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 // initialize statelists: add all possible states which would result into the rightmost 2 bits of the keystream
for(i = 1 << 20; i >= 0; --i) { for(i = 1 << 20; i >= 0; --i) {
@ -183,7 +190,9 @@ struct Crypto1State* lfsr_recovery32(uint32_t ks2, uint32_t in)
out: out:
free(odd_head); free(odd_head);
free(even_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; return statelist;
} }

View file

@ -1,23 +1,5 @@
#include "bucketsort.h" #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, void bucket_sort_intersect(uint32_t* const estart, uint32_t* const estop,
uint32_t* const ostart, uint32_t* const ostop, uint32_t* const ostart, uint32_t* const ostop,
bucket_info_t *bucket_info, bucket_array_t bucket) bucket_info_t *bucket_info, bucket_array_t bucket)

View file

@ -1,7 +1,6 @@
#ifndef BUCKETSORT_H__ #ifndef BUCKETSORT_H__
#define BUCKETSORT_H__ #define BUCKETSORT_H__
#include <stdint.h> #include <stdint.h>
#include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
typedef struct bucket { typedef struct bucket {
uint32_t *head; uint32_t *head;
@ -17,9 +16,6 @@ typedef struct bucket_info {
uint32_t numbuckets; uint32_t numbuckets;
} bucket_info_t; } 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, void bucket_sort_intersect(uint32_t* const estart, uint32_t* const estop,
uint32_t* const ostart, uint32_t* const ostop, uint32_t* const ostart, uint32_t* const ostop,
bucket_info_t *bucket_info, bucket_array_t bucket); bucket_info_t *bucket_info, bucket_array_t bucket);