I want to to collect many traces with different plain texts and key sequences, the number would be nearly 10**6. According to the given project such as simpleserial-des
, I found that only one plain text and one key sequence would be used.
My solution is as following, that is collecting different traces into one picture. But it’s not a good solution, because the number of traces will be limited by scope.adc.samples
and scope.clock.adc_src
.
uint8_t encrypt_n(uint8_t* pt)
{
uint16_t (*pts)[2];
uint16_t *keys;
uint16_t* ct;
int begin = 0;
int n = 108;
pts = create_pt_array(n);
keys = create_keys_array(n);
trigger_high();
for (int i = begin; i < n; i++) {
ct = speck_encrypt(pts[i], keys[i], 5);
}
trigger_low();
simpleserial_put('r', 16, ct);
return 0x00;
}
int main(void)
{
/*uint8_t tmp[KEY_LENGTH] = {DEFAULT_KEY};*/
platform_init();
init_uart();
trigger_setup();
/* Uncomment this to get a HELLO message for debug */
//putch('h');
//putch('e');
//putch('l');
//putch('l');
//putch('o');
//putch('\n');
simpleserial_init();
simpleserial_addcmd('k', 16, get_key);
simpleserial_addcmd('p', 16, encrypt_n);
simpleserial_addcmd('x', 0, reset);
while(1)
simpleserial_get();
}
So how to collect many traces, and put them into different pictures? I believe that something should be change in the following codes which in cw_pro_aes.ipynb
:
def capture_trace(_ignored=None):
ktp = cw.ktp.Basic()
key, text = ktp.next()
return cw.capture_trace(scope, target, text, key).wave
wave = capture_trace()
print("✔️ OK to continue!")
from tqdm.notebook import tnrange
import numpy as np
traces = []
for i in tnrange(1, desc='Capturing traces'):
key, text = ktp.next()
trace = cw.capture_trace(scope, target, text, key)
if trace is None:
continue
traces.append(trace.wave)
traces = np.array(traces)
By the way, how does ktp.next()
work? Can it load key
and text
from an existing dataset? And, how does scope, target, text, key
in cw.capture_trace(scope, target, text, key)
connect to my C function encrypt_n()
? Thanks.