Rewrite readnonces

This commit is contained in:
unkernet
2017-08-27 23:28:16 +03:00
parent a343a950ca
commit f028c5e4e3

View File

@ -19,24 +19,28 @@ uint32_t **space;
size_t thread_count = 1; size_t thread_count = 1;
uint64_t *readnonces(char* fname) { uint64_t *readnonces(char* fname) {
int i, j, r; int i, j;
FILE *f = fopen(fname, "r"); FILE *f = fopen(fname, "r");
if (f == NULL) {
fprintf(stderr, "Cannot open file.\n");
exit(EXIT_FAILURE);
}
uint64_t *nonces = malloc(sizeof (uint64_t) << 24); uint64_t *nonces = malloc(sizeof (uint64_t) << 24);
uint32_t byte; uint32_t nt;
char parities; char par;
for(i = 0; !feof(f); ++i) { i = 0;
for(j = nonces[i] = 0; j < 4; ++j) { while(!feof(f)){
r = fscanf(f, "%02x%c ", &byte, &parities); nonces[i] = 0;
if(r != 2) { for(j = 0; j < 32; j += 8) {
fprintf(stderr, "Input parse error pos:%ld\n", ftell(f)); if(2 != fscanf(f, "%02x%c ", &nt, &par)) {
fprintf(stderr, "Input format error at line:%d\n", i);
fflush(stderr); fflush(stderr);
abort(); exit(EXIT_FAILURE);
} }
parities = (parities == '!') ^ parity(byte); nonces[i] |= nt << j | (uint64_t)((par == '!') ^ parity(nt)) << (32 + j);
nonces[i] |= byte << 8 * j;
nonces[i] |= ((uint64_t)parities) << (32 + j * 8);
} }
i++;
} }
nonces[i] = -1; nonces[i] = -1;
fclose(f); fclose(f);