Beispiel #1
0
 def get_trace_inputs(self, trace):
     result = []
     for p in trace.plaintext:
         result.append(int_to_one_hot(p, 256))
     for k in trace.key:
         result.append(int_to_one_hot(k, 256))
     return np.concatenate(result)
Beispiel #2
0
 def get_trace_leakages(self,
                        trace,
                        subkey_start_index,
                        key_hypothesis=None):
     key_byte = trace.key[
         subkey_start_index] if key_hypothesis is None else key_hypothesis
     return int_to_one_hot(hw[key_byte], num_classes=self.onehot_outputs)
Beispiel #3
0
 def get_trace_leakages(self,
                        trace,
                        subkey_start_index,
                        key_hypothesis=None):
     key_word_list = trace.key[
         subkey_start_index * self.subkey_size:(subkey_start_index + 1) *
         self.subkey_size] if key_hypothesis is None else key_hypothesis
     key_word = struct.unpack("<I", bytearray(key_word_list))[0]
     return int_to_one_hot(hw32(key_word), num_classes=self.onehot_outputs)
Beispiel #4
0
 def get_trace_leakages(self,
                        trace,
                        subkey_start_index,
                        key_hypothesis=None):
     plaintext_byte = trace.plaintext[subkey_start_index]
     key_byte = trace.key[
         subkey_start_index] if key_hypothesis is None else key_hypothesis
     return int_to_one_hot(hw[sbox[plaintext_byte ^ key_byte]],
                           self.onehot_outputs)
Beispiel #5
0
 def test_int_to_one_hot(self):
     from emma.utils.utils import int_to_one_hot
     self.assertListEqual(list(int_to_one_hot(0, 256)), [1] + [0]*255)
     self.assertListEqual(list(int_to_one_hot(0, 3)), [1, 0, 0])
     self.assertListEqual(list(int_to_one_hot(1, 3)), [0, 1, 0])
     self.assertListEqual(list(int_to_one_hot(2, 3)), [0, 0, 1])
Beispiel #6
0
 def get_trace_inputs(self, trace):
     result = []
     for p in trace.plaintext:
         result.append(int_to_one_hot(p, 256))
     result = np.concatenate(result)
     return np.concatenate((trace.signal, result))