Hi @jpthibault , as suggested I have made the simpleserial.c file as follows,
#include "hal.h"
#include "simpleserial.h"
#include <stdint.h>
#include <stdlib.h>
uint8_t get_pt(uint8_t* pt1, uint8_t len)
{
//unsigned char pt[16] = {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,0x00, 0xff, 0x00, 0xff,0x00, 0xff, 0x00, 0xff};
//unsigned char pt[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00};
unsigned char pt[16] = {0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00,0x11, 0x00, 0x11, 0x00,0x11, 0x00, 0x11, 0x00};
trigger_high();
simpleserial_put('r', 16, pt); //value returned from the target
trigger_low();
return 0x00;
}
uint8_t reset(uint8_t* x, uint8_t len)
{
return 0x00;
}
int main(void)
{
platform_init();
init_uart();
trigger_setup();
simpleserial_init();
simpleserial_addcmd('p', 16, get_pt); //plaintext is 64bits and key is 128 bits
simpleserial_addcmd('x', 0, reset);
while(1)
simpleserial_get();
}
-
I tried hard coding pt values inside the get_pt function with following values,
a) unsigned char pt[16] = {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,0x00, 0xff, 0x00, 0xff,0x00, 0xff, 0x00, 0xff};
b) unsigned char pt[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00};
c) unsigned char pt[16] = {0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00,0x11, 0x00, 0x11, 0x00,0x11, 0x00, 0x11, 0x00};
-
I didn’t hard code the pt value instead, I gave it through the jupyter notebook generated by ktp function.
In both the scenarios, I can read the pt as it is, which means I hope the simpleserial communication is working fine.
In jupyter notebook through the following commands, I can read the same pt value as hard coded/given trough jupyter notebook with same traces when plotted(no much difference).
trace3=cw.capture_trace(scope,target,text)
ct=trace3.textout
Following is the .ipynb file used:
import chipwhisperer as cw
scope = cw.scope()
scope.default_setup()
scope.adc.samples=95000
SCOPETYPE = 'OPENADC'
#PLATFORM = 'CWLITEXMEGA'
#CRYPTO_TARGET = 'AVRCRYPTOLIB'
VERSION = 'HARDWARE'
target=cw.target(scope, cw.targets.SimpleSerial)
%%bash -s "$PLATFORM" "$CRYPTO_TARGET"
cd ../hardware/victims/firmware/simpleserial-communication-check
make PLATFORM=CWLITEXMEGA CRYPTO_TARGET=AVRCRYPTOLIB SS_VER=SS_VER_1_1
cw.program_target(scope, cw.programmers.XMEGAProgrammer,"../hardware/victims/firmware/simpleserial-communication-check/simpleserial-comm-CWLITEXMEGA.hex" )
print(target.read())
#to set text length as 8/16 byte
ktp=cw.ktp.Basic()
#ktp.text_len=16
key,text=ktp.next()
from tqdm import tnrange
import numpy as np
import time
trace3=cw.capture_trace(scope,target,text)
ct=trace3.textout
%matplotlib notebook
import matplotlib.pylab as plt
plt.plot(trace3[0])
plt.show()
ct
I have attached the screenshot of the captured trace