Commit 15abe4c4 authored by YUSHIQIAN's avatar YUSHIQIAN

32 bits target in one time, need to modify picking 2 best

parent 385c063f
......@@ -208,6 +208,8 @@ main (int argc, char **argv)
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, 8); i++)
{
......@@ -338,7 +340,7 @@ dpa_attack (int target_bit)
int d[64]; /* Decisions on the target bit */
float *t; /* Power trace */
float max; /* Max sample value in a trace */
float max = 0.0; /* Max sample value in a trace */
float *t0[64]; /* Power traces for the zero-sets (one per guess) */
float *t1[64]; /* Power traces for the one-sets (one per guess) */
......@@ -347,6 +349,8 @@ dpa_attack (int target_bit)
uint64_t ct; /* Ciphertext */
float tmp_dpa[800];
for (g = 0; g < 64; g++) /* For all guesses for 6-bits subkey */
{
dpa[g] = tr_new_trace (ctx); /* Allocate a DPA trace */
......@@ -386,7 +390,36 @@ dpa_attack (int target_bit)
tr_scalar_div (ctx, t0[g], t0[g], (float) (n0[g])); /* Normalize zero-set */
tr_scalar_div (ctx, t1[g], t1[g], (float) (n1[g])); /* Normalize zero-set */
tr_sub (ctx, dpa[g], t1[g], t0[g]); /* Compute one-set minus zero-set */
max = tr_max (ctx, dpa[g], &idx); /* Get max and argmax of DPA trace */
for (i = 0; i < 800; i++)
{
if (i < 555 || i > 625)
{
tmp_dpa[i] = 0.0;
}
else
{
tmp_dpa[i] = dpa[g][i];
}
}
for (ikey = 0; ikey < keyCandidates; ikey++){
for (jkey = ikey+1; jkey < keyCandidates; jkey++){
if (pcc[ikey] < pcc[jkey]){
tmp = pcc[ikey];
idxTmp = idxKey[ikey];
pcc[ikey] = pcc[jkey];
idxKey[ikey] = idxKey[jkey];
pcc[jkey] = tmp;
idxKey[jkey] = idxTmp;
}
}
}
max = tr_max (ctx, tmp_dpa, &idx); /* Get max and argmax of DPA trace */
if (max > best_max[target_bit-1] || g == 0) /* If better than current best max (or if first guess) */
{
best_max[target_bit-1] = max; /* Overwrite best max with new one */
......
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