Commit 5c34e1e3 authored by YUSHIQIAN's avatar YUSHIQIAN

pick two best, suceed for 6956 experiments

parent c12bc361
......@@ -98,9 +98,6 @@ main (int argc, char **argv)
int target_bit; /* Index of target bit. */
int target_sbox; /* Index of target SBox. */
printf("%f\n", pow(4 * nBest, nBytes));
uint64_t subkey[][9] = {{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}}; /* subkey 48 bits for every round */
/************************************************************************/
/* Before doing anything else, check the correctness of the DES library */
/************************************************************************/
......@@ -158,7 +155,6 @@ main (int argc, char **argv)
int i = 0;
int j = 0;
int k = 0;
for (i = 1; i <= 32; i++) /* for all 32 target bits of L15 */
{
......@@ -184,7 +180,7 @@ main (int argc, char **argv)
sbox_idx[target_sbox-1]++;
}
printf ("end.....%d\n", sbox_idx[target_sbox-1]);
/*printf ("end.....%d\n", sbox_idx[target_sbox-1]); */
} /* end of 32 bits */
......@@ -207,40 +203,61 @@ main (int argc, char **argv)
ordered_best_idx[i][2*j],ordered_best_idx[i][2*j+1]);
}
printf("print end\n");
for (j = 0; j < 4 * nBest; j = j + 2) /* for every best key guess of every target key */
{
for (k = 0; k < (int)pow(4 * nBest, i); k++)
{
subkey[j*(int)pow(4 * nBest, i) + k][i+1] = subkey[k][i] | ((uint64_t)ordered_best_guess[i][j] << ((nBytes-i-1) * nBits));
}
}
/*printf("print end\n");*/
}
printf("check if the round key is right\n");
/*printf("check if the round key is right\n");*/
uint64_t key; /* 64 bits secret key */
uint64_t ks[16]; /* Key schedule (array of 16 round keys) */
uint64_t subkey = 0;
key = tr_key (ctx); /* Extract 64 bits secret key from context */
des_ks (ks, key); /* Compute key schedule */
printf ("the right round key is 0x%llx\n", ks[15]);
for (i = 0; i < (int)pow(4*nBest, 8); i++)
{
if (subkey[i][nBytes] == ks[15])
{
/* If guessed 16th round key matches actual 16th round key */
printf ("We got it!!! the secret key is 0x%llx\n", subkey[i][nBytes]); /* Cheers */
break;
}
/*
else
{
printf ("Too bad...\n");
/*printf ("the right round key is 0x%llx\n", ks[15]);*/
for (i = 0; i < nBytes; i++){
sbox_idx[i] = 0;
}
for (sbox_idx[0] = 0; sbox_idx[0] < 4*nBest; sbox_idx[0]++){
for (sbox_idx[1] = 0; sbox_idx[1] < 4*nBest; sbox_idx[1]++){
for (sbox_idx[2] = 0; sbox_idx[2] < 4*nBest; sbox_idx[2]++){
for (sbox_idx[3] = 0; sbox_idx[3] < 4*nBest; sbox_idx[3]++){
for (sbox_idx[4] = 0; sbox_idx[4] < 4*nBest; sbox_idx[4]++){
for (sbox_idx[5] = 0; sbox_idx[5] < 4*nBest; sbox_idx[5]++){
for (sbox_idx[6] = 0; sbox_idx[6] < 4*nBest; sbox_idx[6]++){
for (sbox_idx[7] = 0; sbox_idx[7] < 4*nBest; sbox_idx[7]++){
subkey =
((uint64_t)ordered_best_guess[0][sbox_idx[0]] << ((nBytes-0-1) * nBits))
| ((uint64_t)ordered_best_guess[1][sbox_idx[1]] << ((nBytes-1-1) * nBits))
| ((uint64_t)ordered_best_guess[2][sbox_idx[2]] << ((nBytes-2-1) * nBits))
| ((uint64_t)ordered_best_guess[3][sbox_idx[3]] << ((nBytes-3-1) * nBits))
| ((uint64_t)ordered_best_guess[4][sbox_idx[4]] << ((nBytes-4-1) * nBits))
| ((uint64_t)ordered_best_guess[5][sbox_idx[5]] << ((nBytes-5-1) * nBits))
| ((uint64_t)ordered_best_guess[6][sbox_idx[6]] << ((nBytes-6-1) * nBits))
| ((uint64_t)ordered_best_guess[7][sbox_idx[7]] << ((nBytes-7-1) * nBits));
if (subkey == ks[15])
{
/* If guessed 16th round key matches actual 16th round key */
printf ("We got it!!! the secret key is 0x%llx\n", subkey); /* Cheers */
/*************************
* Free allocated traces *
*************************/
for (g = 0; g < 64; g++) /* For all guesses for 6-bits subkey */
{
tr_free_trace (ctx, dpa[g]);
}
tr_free (ctx); /* Free traces context */
return 0; /* Exits with "everything went fine" status. */
}
}
}
}
}
}
}
}
*/
}
}
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment