Try it like this... (I need to fix shift rows probably)
This commit is contained in:
44
main.cpp
44
main.cpp
@@ -43,51 +43,50 @@ traces_vector_t load_traces()
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const int faultpos = 1;
|
||||
traces_vector_t traces = load_traces();
|
||||
aes_col_vector_t deltas = aes_col_vector_t(256, aes_col());
|
||||
for (int i = 0;i < 256;i++)
|
||||
{
|
||||
deltas[i].column[faultpos] = i;
|
||||
AES::mix_column(deltas[i].column);
|
||||
}
|
||||
|
||||
aes_col key;
|
||||
set<aes_col> candidates;
|
||||
for (int i = 0;i < no_traces;i++)
|
||||
{
|
||||
trace current_master = traces[i];
|
||||
AES::r_shift_rows(current_master.ciphertext);
|
||||
AES::r_shift_rows(current_master.faultytext);
|
||||
cout << i;
|
||||
cout.flush();
|
||||
set<aes_col> round_candidates;
|
||||
for (int k0 = 0;k0 < 256;k0++)
|
||||
{
|
||||
key.column[0] = k0;
|
||||
for (int k1 = 0;k1 < 256;k1++)
|
||||
{
|
||||
key.column[1] = k1;
|
||||
for (int k2 = 0;k2 < 256;k2++)
|
||||
{
|
||||
key.column[2] = k2;
|
||||
for (int k3 = 0;k3 < 256;k3++)
|
||||
{
|
||||
key.column[0] = k0;
|
||||
key.column[1] = k1;
|
||||
key.column[2] = k2;
|
||||
key.column[3] = k3;
|
||||
if (i > 0 && round_candidates.find(key) == round_candidates.end())
|
||||
continue;
|
||||
trace current = current_master;
|
||||
aes_col diff;
|
||||
trace current = traces[i];
|
||||
AES::shift_rows(current.ciphertext);
|
||||
AES::shift_rows(current.faultytext);
|
||||
for (int j = 0;j < 4;j++)
|
||||
{
|
||||
current.ciphertext[j] = AES::inv_sbox[current.ciphertext[j] ^ key.column[j]];
|
||||
current.faultytext[j] = AES::inv_sbox[current.faultytext[j] ^ key.column[j]];
|
||||
current.ciphertext[j] = AES::r_sbox[current.ciphertext[j] ^ key.column[j]];
|
||||
current.faultytext[j] = AES::r_sbox[current.faultytext[j] ^ key.column[j]];
|
||||
diff.column[j] = current.ciphertext[j] ^ current.faultytext[j];
|
||||
}
|
||||
for (int delta = 0;delta < 256;delta++)
|
||||
AES::r_mix_column(diff.column);
|
||||
int zero_bytes = 0;
|
||||
for (int j = 0;j < 4;j++)
|
||||
{
|
||||
if (diff == deltas[delta])
|
||||
{
|
||||
round_candidates.insert(key);
|
||||
break;
|
||||
}
|
||||
if (diff.column[i] == 0)
|
||||
zero_bytes++;
|
||||
}
|
||||
if (zero_bytes >= 3)
|
||||
{
|
||||
round_candidates.insert(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,7 +110,8 @@ int main(int argc, char **argv)
|
||||
}
|
||||
else if (candidates.size() == 0)
|
||||
{
|
||||
cout << endl << "Error!" << endl;
|
||||
cout << " -> " << candidates.size() << endl;
|
||||
cout << "Error!" << endl;
|
||||
break;
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user