Merge remote-tracking branch 'upstream/master' into hf_mf_sim

This commit is contained in:
vratiskol 2019-03-18 23:52:39 +01:00
commit efa03a1e55
6 changed files with 23 additions and 17 deletions

View file

@ -233,7 +233,7 @@ static char *getTagInfo_15(uint8_t *uid) {
int i = 0, best = -1; int i = 0, best = -1;
memcpy(&myuid, uid, sizeof(uint64_t)); memcpy(&myuid, uid, sizeof(uint64_t));
while (uidmapping[i].mask > 0) { while (uidmapping[i].mask > 0) {
mask = (~0LL) << (64 - uidmapping[i].mask); mask = (~0ULL) << (64 - uidmapping[i].mask);
if ((myuid & mask) == uidmapping[i].uid) { if ((myuid & mask) == uidmapping[i].uid) {
if (best == -1) { if (best == -1) {
best = i; best = i;

View file

@ -367,7 +367,7 @@ static uint16_t PartialSumProperty(uint32_t state, odd_even_t odd_even) {
uint32_t st = state; uint32_t st = state;
uint16_t part_sum = 0; uint16_t part_sum = 0;
if (odd_even == ODD_STATE) { if (odd_even == ODD_STATE) {
for (uint16_t i = 0; i < 4; i++) { for (uint16_t i = 0; i < 5; i++) {
part_sum ^= filter(st); part_sum ^= filter(st);
st = (st << 1) | ((j >> (3 - i)) & 0x01) ; st = (st << 1) | ((j >> (3 - i)) & 0x01) ;
} }
@ -1013,7 +1013,8 @@ static bool shrink_key_space(float *brute_forces) {
//iceman 2018 //iceman 2018
return ((hardnested_stage & CHECK_2ND_BYTES) && return ((hardnested_stage & CHECK_2ND_BYTES) &&
reduction_rate >= 0.0 && reduction_rate >= 0.0 &&
(reduction_rate < brute_force_per_second * (float)sample_period / 1000.0 || *brute_forces < 0x1F00000000)); (reduction_rate < brute_force_per_second * (float)sample_period / 1000.0 || *brute_forces < 0xF00000));
} }

View file

@ -315,7 +315,7 @@ int exec_crypto_test(bool verbose) {
unsigned int kl = keylengths[i]; unsigned int kl = keylengths[i];
ret = test_genkey(kl, message, kl / 8, verbose); ret = test_genkey(kl, message, kl / 8, verbose);
if (ret) { if (ret) {
fprintf(stderr, "Crypto generate key[%d] test: failed\n", kl); fprintf(stderr, "Crypto generate key[%u] test: failed\n", kl);
return ret; return ret;
} }
} }

View file

@ -64,9 +64,9 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs,
} }
fprintf(stdout, "%d: V 0x%08x P 0x%08x (0x%08x->0x%08x) [%c%c%c] @0x%x\n", fprintf(stdout, "%d: V 0x%08x P 0x%08x (0x%08x->0x%08x) [%c%c%c] @0x%x\n",
i, vaddr, paddr, filesz, memsz, i, vaddr, paddr, filesz, memsz,
flags & PF_R ? 'R' : ' ', (flags & PF_R) ? 'R' : ' ',
flags & PF_W ? 'W' : ' ', (flags & PF_W) ? 'W' : ' ',
flags & PF_X ? 'X' : ' ', (flags & PF_X) ? 'X' : ' ',
offset); offset);
if (filesz != memsz) { if (filesz != memsz) {
fprintf(stderr, "Error: PHDR file size does not equal memory size\n" fprintf(stderr, "Error: PHDR file size does not equal memory size\n"
@ -179,7 +179,7 @@ static int check_segs(flash_file_t *ctx, int can_write_bl) {
// Load an ELF file and prepare it for flashing // Load an ELF file and prepare it for flashing
int flash_load(flash_file_t *ctx, const char *name, int can_write_bl) { int flash_load(flash_file_t *ctx, const char *name, int can_write_bl) {
FILE *fd = NULL; FILE *fd;
Elf32_Ehdr ehdr; Elf32_Ehdr ehdr;
Elf32_Phdr *phdrs = NULL; Elf32_Phdr *phdrs = NULL;
uint16_t num_phdrs; uint16_t num_phdrs;
@ -410,7 +410,7 @@ int flash_write(flash_file_t *ctx) {
uint32_t blocks = (length + BLOCK_SIZE - 1) / BLOCK_SIZE; uint32_t blocks = (length + BLOCK_SIZE - 1) / BLOCK_SIZE;
uint32_t end = seg->start + length; uint32_t end = seg->start + length;
fprintf(stdout, " 0x%08x..0x%08x [0x%x / %d blocks]", seg->start, end - 1, length, blocks); fprintf(stdout, " 0x%08x..0x%08x [0x%x / %u blocks]", seg->start, end - 1, length, blocks);
fflush(stdout); fflush(stdout);
int block = 0; int block = 0;
uint8_t *data = seg->data; uint8_t *data = seg->data;
@ -423,7 +423,7 @@ int flash_write(flash_file_t *ctx) {
if (write_block(baddr, data, block_size) < 0) { if (write_block(baddr, data, block_size) < 0) {
fprintf(stderr, " ERROR\n"); fprintf(stderr, " ERROR\n");
fprintf(stderr, "Error writing block %d of %d\n", block, blocks); fprintf(stderr, "Error writing block %d of %u\n", block, blocks);
return -1; return -1;
} }

View file

@ -458,16 +458,21 @@ int main(int argc, char **argv) {
if (infiles[i] == NULL) { if (infiles[i] == NULL) {
fprintf(stderr, "Error. Cannot open input file %s\n\n", infile_names[i]); fprintf(stderr, "Error. Cannot open input file %s\n\n", infile_names[i]);
free(infile_names); free(infile_names);
free(infiles);
return (EXIT_FAILURE); return (EXIT_FAILURE);
} }
} }
outfile = fopen(argv[argc - 1], "wb"); outfile = fopen(argv[argc - 1], "wb");
if (outfile == NULL) { if (outfile == NULL) {
fprintf(stderr, "Error. Cannot open output file %s\n\n", argv[argc - 1]); fprintf(stderr, "Error. Cannot open output file %s\n\n", argv[argc - 1]);
free(infile_names);
free(infiles);
return (EXIT_FAILURE); return (EXIT_FAILURE);
} }
if (generate_version_file) { if (generate_version_file) {
if (generate_fpga_version_info(infiles, infile_names, num_input_files, outfile)) { if (generate_fpga_version_info(infiles, infile_names, num_input_files, outfile)) {
free(infile_names);
free(infiles);
return (EXIT_FAILURE); return (EXIT_FAILURE);
} }
} else { } else {

View file

@ -240,7 +240,7 @@ void init_sum_bitarray(uint16_t sum_a0) {
} }
for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) { for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) {
uint32_t count = count_states(sum_a0_bitarray[odd_even]); uint32_t count = count_states(sum_a0_bitarray[odd_even]);
printf("sum_a0_bitarray[%s] has %d states (%5.2f%%)\n", odd_even == EVEN_STATE ? "even" : "odd ", count, (float)count / (1 << 24) * 100.0); printf("sum_a0_bitarray[%s] has %u states (%5.2f%%)\n", odd_even == EVEN_STATE ? "even" : "odd ", count, (float)count / (1 << 24) * 100.0);
} }
printf("done.\n"); printf("done.\n");
} }
@ -350,7 +350,7 @@ static void precalculate_bit0_bitflip_bitarrays(uint8_t const bitflip, uint16_t
for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) { for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) {
count[odd_even] = count_states(test_bitarray[odd_even]); count[odd_even] = count_states(test_bitarray[odd_even]);
if (count[odd_even] != 1 << 24) { if (count[odd_even] != 1 << 24) {
printf("Writing %d possible %s states for bitflip property %03x (%d (%1.2f%%) states eliminated)\n", printf("Writing %u possible %s states for bitflip property %03x (%d (%1.2f%%) states eliminated)\n",
count[odd_even], count[odd_even],
odd_even == EVEN_STATE ? "even" : "odd", odd_even == EVEN_STATE ? "even" : "odd",
bitflip, (1 << 24) - count[odd_even], bitflip, (1 << 24) - count[odd_even],
@ -377,7 +377,7 @@ static void precalculate_bit0_bitflip_bitarrays(uint8_t const bitflip, uint16_t
} }
count[odd_even] = count_states(test_bitarray_2nd); count[odd_even] = count_states(test_bitarray_2nd);
if (count[odd_even] != 1 << 24) { if (count[odd_even] != 1 << 24) {
printf("Writing %d possible %s states for bitflip property %03x (%d (%1.2f%%) states eliminated)\n", printf("Writing %u possible %s states for bitflip property %03x (%d (%1.2f%%) states eliminated)\n",
count[odd_even], count[odd_even],
odd_even == EVEN_STATE ? "even" : "odd", odd_even == EVEN_STATE ? "even" : "odd",
bitflip | BITFLIP_2ND_BYTE, (1 << 24) - count[odd_even], bitflip | BITFLIP_2ND_BYTE, (1 << 24) - count[odd_even],
@ -462,7 +462,7 @@ static void precalculate_bit0_bitflip_bitarrays(uint8_t const bitflip, uint16_t
for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) { for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) {
count[odd_even] = count_states(test_not_bitarray[odd_even]); count[odd_even] = count_states(test_not_bitarray[odd_even]);
if (count[odd_even] != 1 << 24) { if (count[odd_even] != 1 << 24) {
printf("Writing %d possible %s states for bitflip property %03x (%d (%1.2f%%) states eliminated)\n", printf("Writing %u possible %s states for bitflip property %03x (%d (%1.2f%%) states eliminated)\n",
count[odd_even], count[odd_even],
odd_even == EVEN_STATE ? "even" : "odd", odd_even == EVEN_STATE ? "even" : "odd",
bitflip | 0x100, (1 << 24) - count[odd_even], bitflip | 0x100, (1 << 24) - count[odd_even],
@ -489,7 +489,7 @@ static void precalculate_bit0_bitflip_bitarrays(uint8_t const bitflip, uint16_t
} }
count[odd_even] = count_states(test_bitarray_2nd); count[odd_even] = count_states(test_bitarray_2nd);
if (count[odd_even] != 1 << 24) { if (count[odd_even] != 1 << 24) {
printf("Writing %d possible %s states for bitflip property %03x (%d (%1.2f%%) states eliminated)\n", printf("Writing %u possible %s states for bitflip property %03x (%d (%1.2f%%) states eliminated)\n",
count[odd_even], count[odd_even],
odd_even == EVEN_STATE ? "even" : "odd", odd_even == EVEN_STATE ? "even" : "odd",
bitflip | 0x100 | BITFLIP_2ND_BYTE, (1 << 24) - count[odd_even], bitflip | 0x100 | BITFLIP_2ND_BYTE, (1 << 24) - count[odd_even],