some dummy files in order to keep folder structure ok when compiling..

removed some comments
This commit is contained in:
iceman1001 2017-07-27 21:19:39 +02:00
parent 475a19b937
commit 5222785d69
4 changed files with 1 additions and 274 deletions

View file

@ -2190,220 +2190,6 @@ static uint16_t SumProperty(struct Crypto1State *s)
static void Tests() static void Tests()
{ {
/* #define NUM_STATISTICS 100000
uint32_t statistics_odd[17];
uint64_t statistics[257];
uint32_t statistics_even[17];
struct Crypto1State cs;
uint64_t time1 = msclock();
for (uint16_t i = 0; i < 257; i++) {
statistics[i] = 0;
}
for (uint16_t i = 0; i < 17; i++) {
statistics_odd[i] = 0;
statistics_even[i] = 0;
}
for (uint64_t i = 0; i < NUM_STATISTICS; i++) {
cs.odd = (rand() & 0xfff) << 12 | (rand() & 0xfff);
cs.even = (rand() & 0xfff) << 12 | (rand() & 0xfff);
uint16_t sum_property = SumProperty(&cs);
statistics[sum_property] += 1;
sum_property = PartialSumProperty(cs.even, EVEN_STATE);
statistics_even[sum_property]++;
sum_property = PartialSumProperty(cs.odd, ODD_STATE);
statistics_odd[sum_property]++;
if (i%(NUM_STATISTICS/100) == 0) printf(".");
}
printf("\nTests: Calculated %d Sum properties in %0.3f seconds (%0.0f calcs/second)\n", NUM_STATISTICS, ((float)msclock() - time1)/1000.0, NUM_STATISTICS/((float)msclock() - time1)*1000.0);
for (uint16_t i = 0; i < 257; i++) {
if (statistics[i] != 0) {
printf("probability[%3d] = %0.5f\n", i, (float)statistics[i]/NUM_STATISTICS);
}
}
for (uint16_t i = 0; i <= 16; i++) {
if (statistics_odd[i] != 0) {
printf("probability odd [%2d] = %0.5f\n", i, (float)statistics_odd[i]/NUM_STATISTICS);
}
}
for (uint16_t i = 0; i <= 16; i++) {
if (statistics_odd[i] != 0) {
printf("probability even [%2d] = %0.5f\n", i, (float)statistics_even[i]/NUM_STATISTICS);
}
}
*/
/* #define NUM_STATISTICS 100000000LL
uint64_t statistics_a0[257];
uint64_t statistics_a8[257][257];
struct Crypto1State cs;
uint64_t time1 = msclock();
for (uint16_t i = 0; i < 257; i++) {
statistics_a0[i] = 0;
for (uint16_t j = 0; j < 257; j++) {
statistics_a8[i][j] = 0;
}
}
for (uint64_t i = 0; i < NUM_STATISTICS; i++) {
cs.odd = (rand() & 0xfff) << 12 | (rand() & 0xfff);
cs.even = (rand() & 0xfff) << 12 | (rand() & 0xfff);
uint16_t sum_property_a0 = SumProperty(&cs);
statistics_a0[sum_property_a0]++;
uint8_t first_byte = rand() & 0xff;
crypto1_byte(&cs, first_byte, true);
uint16_t sum_property_a8 = SumProperty(&cs);
statistics_a8[sum_property_a0][sum_property_a8] += 1;
if (i%(NUM_STATISTICS/100) == 0) printf(".");
}
printf("\nTests: Probability Distribution of a8 depending on a0:\n");
printf("\n ");
for (uint16_t i = 0; i < NUM_SUMS; i++) {
printf("%7d ", sums[i]);
}
printf("\n-------------------------------------------------------------------------------------------------------------------------------------------\n");
printf("a0: ");
for (uint16_t i = 0; i < NUM_SUMS; i++) {
printf("%7.5f ", (float)statistics_a0[sums[i]] / NUM_STATISTICS);
}
printf("\n");
for (uint16_t i = 0; i < NUM_SUMS; i++) {
printf("%3d ", sums[i]);
for (uint16_t j = 0; j < NUM_SUMS; j++) {
printf("%7.5f ", (float)statistics_a8[sums[i]][sums[j]] / statistics_a0[sums[i]]);
}
printf("\n");
}
printf("\nTests: Calculated %"lld" Sum properties in %0.3f seconds (%0.0f calcs/second)\n", NUM_STATISTICS, ((float)msclock() - time1)/1000.0, NUM_STATISTICS/((float)msclock() - time1)*1000.0);
*/
/* #define NUM_STATISTICS 100000LL
uint64_t statistics_a8[257];
struct Crypto1State cs;
uint64_t time1 = msclock();
printf("\nTests: Probability Distribution of a8 depending on first byte:\n");
printf("\n ");
for (uint16_t i = 0; i < NUM_SUMS; i++) {
printf("%7d ", sums[i]);
}
printf("\n-------------------------------------------------------------------------------------------------------------------------------------------\n");
for (uint16_t first_byte = 0; first_byte < 256; first_byte++) {
for (uint16_t i = 0; i < 257; i++) {
statistics_a8[i] = 0;
}
for (uint64_t i = 0; i < NUM_STATISTICS; i++) {
cs.odd = (rand() & 0xfff) << 12 | (rand() & 0xfff);
cs.even = (rand() & 0xfff) << 12 | (rand() & 0xfff);
crypto1_byte(&cs, first_byte, true);
uint16_t sum_property_a8 = SumProperty(&cs);
statistics_a8[sum_property_a8] += 1;
}
printf("%03x ", first_byte);
for (uint16_t j = 0; j < NUM_SUMS; j++) {
printf("%7.5f ", (float)statistics_a8[sums[j]] / NUM_STATISTICS);
}
printf("\n");
}
printf("\nTests: Calculated %"lld" Sum properties in %0.3f seconds (%0.0f calcs/second)\n", NUM_STATISTICS, ((float)msclock() - time1)/1000.0, NUM_STATISTICS/((float)msclock() - time1)*1000.0);
*/
/* printf("Tests: Sum Probabilities based on Partial Sums\n");
for (uint16_t i = 0; i < 257; i++) {
statistics[i] = 0;
}
uint64_t num_states = 0;
for (uint16_t oddsum = 0; oddsum <= 16; oddsum += 2) {
for (uint16_t evensum = 0; evensum <= 16; evensum += 2) {
uint16_t sum = oddsum*(16-evensum) + (16-oddsum)*evensum;
statistics[sum] += (uint64_t)partial_statelist[oddsum].len[ODD_STATE] * partial_statelist[evensum].len[EVEN_STATE] * (1<<8);
num_states += (uint64_t)partial_statelist[oddsum].len[ODD_STATE] * partial_statelist[evensum].len[EVEN_STATE] * (1<<8);
}
}
printf("num_states = %"lld", expected %"lld"\n", num_states, (1LL<<48));
for (uint16_t i = 0; i < 257; i++) {
if (statistics[i] != 0) {
printf("probability[%3d] = %0.5f\n", i, (float)statistics[i]/num_states);
}
}
*/
/* struct Crypto1State *pcs;
pcs = crypto1_create(0xffffffffffff);
printf("\nTests: for key = 0xffffffffffff:\nSum(a0) = %d\nodd_state = 0x%06x\neven_state = 0x%06x\n",
SumProperty(pcs), pcs->odd & 0x00ffffff, pcs->even & 0x00ffffff);
crypto1_byte(pcs, (cuid >> 24) ^ best_first_bytes[0], true);
printf("After adding best first byte 0x%02x:\nSum(a8) = %d\nodd_state = 0x%06x\neven_state = 0x%06x\n",
best_first_bytes[0],
SumProperty(pcs),
pcs->odd & 0x00ffffff, pcs->even & 0x00ffffff);
//test_state_odd = pcs->odd & 0x00ffffff;
//test_state_even = pcs->even & 0x00ffffff;
crypto1_destroy(pcs);
pcs = crypto1_create(0xa0a1a2a3a4a5);
printf("Tests: for key = 0xa0a1a2a3a4a5:\nSum(a0) = %d\nodd_state = 0x%06x\neven_state = 0x%06x\n",
SumProperty(pcs), pcs->odd & 0x00ffffff, pcs->even & 0x00ffffff);
crypto1_byte(pcs, (cuid >> 24) ^ best_first_bytes[0], true);
printf("After adding best first byte 0x%02x:\nSum(a8) = %d\nodd_state = 0x%06x\neven_state = 0x%06x\n",
best_first_bytes[0],
SumProperty(pcs),
pcs->odd & 0x00ffffff, pcs->even & 0x00ffffff);
//test_state_odd = pcs->odd & 0x00ffffff;
//test_state_even = pcs->even & 0x00ffffff;
crypto1_destroy(pcs);
pcs = crypto1_create(0xa6b9aa97b955);
printf("Tests: for key = 0xa6b9aa97b955:\nSum(a0) = %d\nodd_state = 0x%06x\neven_state = 0x%06x\n",
SumProperty(pcs), pcs->odd & 0x00ffffff, pcs->even & 0x00ffffff);
crypto1_byte(pcs, (cuid >> 24) ^ best_first_bytes[0], true);
printf("After adding best first byte 0x%02x:\nSum(a8) = %d\nodd_state = 0x%06x\neven_state = 0x%06x\n",
best_first_bytes[0],
SumProperty(pcs),
pcs->odd & 0x00ffffff, pcs->even & 0x00ffffff);
test_state_odd = pcs->odd & 0x00ffffff;
test_state_even = pcs->even & 0x00ffffff;
crypto1_destroy(pcs);
*/
// printf("\nTests: Sorted First Bytes:\n");
// for (uint16_t i = 0; i < 20; i++) {
// uint8_t best_byte = best_first_bytes[i];
// //printf("#%03d Byte: %02x, n = %3d, k = %3d, Sum(a8): %3d, Confidence: %5.1f%%\n",
// printf("#%03d Byte: %02x, n = %3d, k = %3d, Sum(a8) = ", i, best_byte, nonces[best_byte].num, nonces[best_byte].Sum);
// for (uint16_t j = 0; j < 3; j++) {
// printf("%3d @ %4.1f%%, ", sums[nonces[best_byte].sum_a8_guess[j].sum_a8_idx], nonces[best_byte].sum_a8_guess[j].prob * 100.0);
// }
// printf(" %12" PRIu64 ", %12" PRIu64 ", %12" PRIu64 ", exp_brute: %12.0f\n",
// nonces[best_byte].sum_a8_guess[0].num_states,
// nonces[best_byte].sum_a8_guess[1].num_states,
// nonces[best_byte].sum_a8_guess[2].num_states,
// nonces[best_byte].expected_num_brute_force);
// }
// printf("\nTests: Actual BitFlipProperties of best byte:\n");
// printf("[%02x]:", best_first_bytes[0]);
// for (uint16_t bitflip_idx = 0; bitflip_idx < num_all_effective_bitflips; bitflip_idx++) {
// uint16_t bitflip_prop = all_effective_bitflip[bitflip_idx];
// if (nonces[best_first_bytes[0]].BitFlips[bitflip_prop]) {
// printf(" %03" PRIx16 , bitflip_prop);
// }
// }
// printf("\n");
// printf("\nTests2: Actual BitFlipProperties of first_byte_smallest_bitarray:\n");
// printf("[%02x]:", best_first_byte_smallest_bitarray);
// for (uint16_t bitflip_idx = 0; bitflip_idx < num_all_effective_bitflips; bitflip_idx++) {
// uint16_t bitflip_prop = all_effective_bitflip[bitflip_idx];
// if (nonces[best_first_byte_smallest_bitarray].BitFlips[bitflip_prop]) {
// printf(" %03" PRIx16 , bitflip_prop);
// }
// }
// printf("\n");
if (known_target_key != -1) { if (known_target_key != -1) {
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 *bitset = nonces[best_first_bytes[0]].states_bitarray[odd_even]; uint32_t *bitset = nonces[best_first_bytes[0]].states_bitarray[odd_even];
@ -2424,64 +2210,6 @@ static void Tests()
} }
} }
} }
// if (known_target_key != -1) {
// int16_t p = -1, q = -1, r = -1, s = -1;
// printf("\nTests: known target key is member of these partial sum_a0 bitsets:\n");
// for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) {
// printf("%s", odd_even==EVEN_STATE?"even:":"odd: ");
// for (uint16_t i = 0; i < NUM_PART_SUMS; i++) {
// uint32_t *bitset = part_sum_a0_bitarrays[odd_even][i];
// if (test_bit24(bitset, test_state[odd_even])) {
// printf("%d ", i);
// if (odd_even == ODD_STATE) {
// p = 2*i;
// } else {
// q = 2*i;
// }
// }
// }
// printf("\n");
// }
// printf("\nTests: known target key is member of these partial sum_a8 bitsets:\n");
// for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) {
// printf("%s", odd_even==EVEN_STATE?"even:":"odd: ");
// for (uint16_t i = 0; i < NUM_PART_SUMS; i++) {
// uint32_t *bitset = part_sum_a8_bitarrays[odd_even][i];
// if (test_bit24(bitset, test_state[odd_even])) {
// printf("%d ", i);
// if (odd_even == ODD_STATE) {
// r = 2*i;
// } else {
// s = 2*i;
// }
// }
// }
// printf("\n");
// }
// printf("Sum(a0) = p*(16-q) + (16-p)*q = %d*(16-%d) + (16-%d)*%d = %d\n", p, q, p, q, p*(16-q)+(16-p)*q);
// printf("Sum(a8) = r*(16-s) + (16-r)*s = %d*(16-%d) + (16-%d)*%d = %d\n", r, s, r, s, r*(16-s)+(16-r)*s);
// }
/* printf("\nTests: parity performance\n");
uint64_t time1p = msclock();
uint32_t par_sum = 0;
for (uint32_t i = 0; i < 100000000; i++) {
par_sum += parity(i);
}
printf("parsum oldparity = %d, time = %1.5fsec\n", par_sum, (float)(msclock() - time1p)/1000.0);
time1p = msclock();
par_sum = 0;
for (uint32_t i = 0; i < 100000000; i++) {
par_sum += evenparity32(i);
}
printf("parsum newparity = %d, time = %1.5fsec\n", par_sum, (float)(msclock() - time1p)/1000.0);
*/
} }

View file

@ -53,8 +53,7 @@ void ReceiveCommand(UsbCommand* rxcmd) {
byte_t* prx = prxcmd; byte_t* prx = prxcmd;
size_t rxlen; size_t rxlen;
while (true) { while (true) {
rxlen = sizeof(UsbCommand) - (prx-prxcmd); if (uart_receive(sp, prx, sizeof(UsbCommand) - (prx-prxcmd), &rxlen)) {
if (uart_receive(sp,prx,&rxlen)) {
prx += rxlen; prx += rxlen;
if ((prx-prxcmd) >= sizeof(UsbCommand)) { if ((prx-prxcmd) >= sizeof(UsbCommand)) {
return; return;

View file

View file