Encrypting a text with AES on CW305

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```
  1. Have you set J16 to 0 and K16 to 1, as instructed in our notebook?
  2. On the CW305, are LED7 (red) and LED5 (green), between the CLKIN and CLKOUT SMAs, both blinking?
  3. What does the CW305’s VCC-INT 7-segment display show?
  4. If you run our CW305 notebook as-is, does it work?
  1. I don’t know how the set the J16 to 0 and K16 to 1. I thought the code that you provided do that.
  2. yes they are
  3. 1.01
  4. yes I run all the code as I showed you and it works fine the only problem is the result from the cipher text it’s all zero

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:

  • J16 = 0
  • K16 = 1

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"