*/
void permutekey(uint8_t key[8], uint8_t dest[8])
{
-
int i;
for(i = 0 ; i < 8 ; i++)
{
(((key[1] & (0x80 >> i)) >> (7-i)) << 1) |
(((key[0] & (0x80 >> i)) >> (7-i)) << 0);
}
-
return;
}
/**
*/
int bruteforceFile(const char *filename, uint16_t keytable[])
{
-
FILE *f = fopen(filename, "rb");
if(!f) {
prnlog("Failed to read from file '%s'", filename);
if (fsize < 0) {
prnlog("Error, when getting filesize");
- fclose(f);
+ if (f) {
+ fclose(f);
+ f = NULL;
+ }
return 1;
}
uint8_t *dump = malloc(fsize);
size_t bytes_read = fread(dump, 1, fsize, f);
- fclose(f);
- if (bytes_read < fsize)
- {
+ if (f) {
+ fclose(f);
+ f = NULL;
+ }
+ if (bytes_read < fsize) {
prnlog("Error, could only read %d bytes (should be %d)",bytes_read, fsize );
}
-
uint8_t res = bruteforceDump(dump,fsize,keytable);
free(dump);
return res;