I am trying to cipher a plain text using AES128 on CW305_100t. However, it seems that there is a miscalculation or not even calculating the cipher. bellow you can see my code:
from chipwhisperer.capture.targets.CW305 import CW305
import chipwhisperer as cw
bitstream_file = r"D:\cw305_artixtarget\fpga\vivado_examples" \
r"\aes128_verilog\aes128_verilog.runs\impl_100t\cw305_top.bit"
target = cw.target(None, cw.targets.CW305, fpga_id='100t', bsfile=bitstream_file, force=True)
key = bytearray.fromhex("2b7e151628aed2a6abf7158809cf4f3c")
target.loadEncryptionKey(key)
print(f"AES key written: {key.hex()}")
plaintext = bytearray.fromhex("6bc1bee22e409f96e93d7e117393172a")
target.loadInput(plaintext)
print(f"Plaintext written: {plaintext.hex()}")
target.go()
print("Encryption triggered.")
ciphertext = target.readOutput()
print(f"Ciphertext: {ciphertext.hex()}")
However the target.readOutput() returns:Ciphertext: 00000000000000000000000000000000
Have you set up the CW305’s clocks properly? Our demo notebook teaches you how.
yes with this :
target.vccint_set(1.0)
# we only need PLL1:
target.pll.pll_enable_set(True)
target.pll.pll_outenable_set(False, 0)
target.pll.pll_outenable_set(True, 1)
target.pll.pll_outenable_set(False, 2)
# run at 10 MHz:
target.pll.pll_outfreq_set(10E6, 1)
# 1ms is plenty of idling time
target.clkusbautooff = True
target.clksleeptime = 1```
From the notebook:
Next we set all the PLLs. We enable CW305’s PLL1; this clock will feed both the target and the CW ADC. As explained here, make sure the DIP switches on the CW305 board are set as follows:
The DIP switches are above the 20-pin connector. They can’t be set by code, you have to physically move them to the correct setting.
The code you show above is different from our demo notebook; please try our notebook.
There is a line in the capture loop which checks that the encryption result is correct.
1 Like
Thank you so much for the explanation. I will try this now.
Also, the problem is I do not have the chipwhisperer card. Therefore I can’t use the scope method, so I couldn’t adapt the code from the example so I tried to use mine.
Also, I faced a problem in the loop I could find the file “projects/Tutorial_HW_CW305.cwp”. In addition, I had to remove all the scope parts in the code does this is going to effect anything?
Also this part of the code can’t be done since I can’t use scope:
import time
for i in range(5):
scope.clock.reset_adc()
time.sleep(1)
if scope.clock.adc_locked:
break
assert (scope.clock.adc_locked), "ADC failed to lock"