Commit 1a6b0990 authored by YUSHIQIAN's avatar YUSHIQIAN

move labi into timing_attack_DES

parent a1d9812c
File deleted
File deleted
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -93,6 +93,17 @@ des_p_ta (uint64_t val)
}
res = set_bit (k, res);
}
else
{
for (j = 1; j <= 32; j++)
{
if (p_table[j - 1] == i) /* C array index starts at 0, not 1 */
{
k = j;
}
}
res = unset_bit (k, res);
}
}
return res;
}
......
......@@ -99,17 +99,16 @@ main (int argc, char **argv)
n /* Number of experiments to use. */
);
int iEnc = 0; /* index of times of DES encrytion experiments */
int nBytes = 4; /* number of sboxes */
int nBest = 2; /* choose 4 best pcc */
int nBits = 8/nBytes*6;
int iEnc = 0; /* index of times of DES encrytion experiments */
int iByte = 0;
uint64_t r15; /* Right half of 15 round. */
uint64_t tmpExpR = 0x0ULL;
int *hw[nBytes]; /* haming weight of input (4 bits) of permutation*/
for (iByte=0; iByte<nBytes; iByte++){
hw[iByte] = malloc(n * sizeof (int));
}
double hw; /* haming weight of input (4 bits) of permutation*/
/*****************************************************************************
* Compute the Hamming weight of output of each SBox during last *
......@@ -117,7 +116,6 @@ main (int argc, char **argv)
*****************************************************************************/
pcc_context ctx;
int keyCandidates = pow(2, nBits);
int nBest = 2; /* choose 4 best pcc */
double pcc[keyCandidates];
int idxKey[keyCandidates];
uint64_t ikey = 0;
......@@ -136,7 +134,6 @@ main (int argc, char **argv)
for (iEnc = 0; iEnc < n; iEnc++){ /* for every experiment */
pcc_insert_x (ctx, t[iEnc]);
/*printf ("realtime: %f, hw: ", t[iEnc]);*/
/* Undoes the final permutation on cipher text of n-th experiment. */
r16l16 = des_ip (ct[iEnc]);
......@@ -147,9 +144,8 @@ main (int argc, char **argv)
for (ikey = 0; ikey < keyCandidates; ikey++){ /* for every key guesss 0~63 */
sbo = des_sboxes (tmpExpR ^ (ikey << ((nBytes - iByte - 1)*nBits)));
hw[iByte][iEnc] = hamming_weight ((sbo >> (nBytes - iByte - 1)*8/nBytes*4) & 255);
/*printf ("%d-", hw[iByte][iEnc]);*/
pcc_insert_y (ctx, ikey, (double)hw[iByte][iEnc]);
hw = hamming_weight ((sbo >> (nBytes - iByte - 1)*8/nBytes*4) & (int)(pow(2, 8/nBytes*4)-1));
pcc_insert_y (ctx, ikey, hw);
} /* ikey */
/*printf("\n"); */
} /* iEnc */
......@@ -178,29 +174,17 @@ main (int argc, char **argv)
}
}
/*printf("print key pcc===========");
for (ikey = 0; ikey < 10; ikey++){
printf("PCC(X, Y%llu) = %lf\n", (uint64_t)idxKey[ikey], pcc[ikey]);
}
printf("======");*/
int j = 0;
for (i = 0; i < nBest; i++){
for (j = 0; j < (int)pow(nBest, iByte); j++)
{
subkey[i*(int)pow(nBest, iByte) + j][iByte+1] = subkey[j][iByte] | ((uint64_t)idxKey[i] << ((nBytes-iByte-1) * nBits));
/*printf("PCC(X, Y%llu) = %lf\n", (uint64_t)idxKey[i], pcc[i]);*/
}
}
pcc_free (ctx);
}/*iByte*/
for (iByte=0; iByte<nBytes; iByte++){
free (hw[iByte]);
}
/************************************
* Compute and print average timing *
************************************/
......
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