Skip to content

Commit

Permalink
[capture] Switch data generator format
Browse files Browse the repository at this point in the history
The new uJSOn based communication interfaces requires that the crypto
material is handed over in plain. Conversion from plain data to bytes
now happens directly before sending data over simpleserial.
This PR changes the data format from bytes to plain in the data generator.

Signed-off-by: Pascal Nasahl <[email protected]>
  • Loading branch information
nasahlpa committed Dec 4, 2023
1 parent f924455 commit b0ab33a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
3 changes: 2 additions & 1 deletion capture/configs/aes_sca_cw310.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ target:
target_type: cw310
fpga_bitstream: "../objs/lowrisc_systems_chip_earlgrey_cw310_0.1.bit"
force_program_bitstream: False
fw_bin: "../objs/firmware.bin"
fw_bin: "../objs/aes_serial_fpga_cw310.bin"
# fw_bin: "../objs/aes_ujson_fpga_cw310.bin"
# target_clk_mult is a hardcoded value in the bitstream. Do not change.
target_clk_mult: 0.24
target_freq: 24000000
Expand Down
3 changes: 3 additions & 0 deletions objs/aes_ujson_fpga_cw310.bin
Git LFS file not shown
56 changes: 28 additions & 28 deletions util/data_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,54 @@

class data_generator():

key_generation = bytearray([0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF1,
0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xE0, 0xF0])

text_fixed = bytearray([0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA])
text_random = bytearray([0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC])
key_fixed = bytearray([0x81, 0x1E, 0x37, 0x31, 0xB0, 0x12, 0x0A, 0x78,
0x42, 0x78, 0x1E, 0x22, 0xB2, 0x5C, 0xDD, 0xF9])
key_random = bytearray([0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53,
0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53])
key_generation = [0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF1, 0x23,
0x45, 0x67, 0x89, 0xAB, 0xCD, 0xE0, 0xF0]

text_fixed = [0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA]
text_random = [0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC]
key_fixed = [0x81, 0x1E, 0x37, 0x31, 0xB0, 0x12, 0x0A, 0x78, 0x42, 0x78,
0x1E, 0x22, 0xB2, 0x5C, 0xDD, 0xF9]
key_random = [0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53,
0x53, 0x53, 0x53, 0x53, 0x53, 0x53]

cipher_gen = AES.new(bytes(key_generation), AES.MODE_ECB)

def __init__(self):
self.cipher_gen = AES.new(bytes(self.key_generation), AES.MODE_ECB)

def set_start(self):
self.text_fixed = bytearray([0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA])
self.text_random = bytearray([0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC])
self.key_fixed = bytearray([0x81, 0x1E, 0x37, 0x31, 0xB0, 0x12, 0x0A, 0x78,
0x42, 0x78, 0x1E, 0x22, 0xB2, 0x5C, 0xDD, 0xF9])
self.key_random = bytearray([0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53,
0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53])
self.text_fixed = [0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA]
self.text_random = [0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC]
self.key_fixed = [0x81, 0x1E, 0x37, 0x31, 0xB0, 0x12, 0x0A, 0x78, 0x42,
0x78, 0x1E, 0x22, 0xB2, 0x5C, 0xDD, 0xF9]
self.key_random = [0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53,
0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53]

def advance_fixed(self):
self.text_fixed = bytearray(self.cipher_gen.encrypt(self.text_fixed))
self.text_fixed = self.cipher_gen.encrypt(bytes(self.text_fixed))

def advance_random(self):
self.text_random = bytearray(self.cipher_gen.encrypt(self.text_random))
self.key_random = bytearray(self.cipher_gen.encrypt(self.key_random))
self.text_random = self.cipher_gen.encrypt(bytes(self.text_random))
self.key_random = self.cipher_gen.encrypt(bytes(self.key_random))

def get_fixed(self):
pt = np.asarray(self.text_fixed)
key = np.asarray(self.key_fixed)
pt = self.text_fixed
key = self.key_fixed
cipher_fixed = AES.new(bytes(self.key_fixed), AES.MODE_ECB)
ct = np.asarray(bytearray(cipher_fixed.encrypt(self.text_fixed)))
ct = cipher_fixed.encrypt(bytes(self.text_fixed))
del (cipher_fixed)
self.advance_fixed()
return pt, ct, key

def get_random(self):
pt = np.asarray(self.text_random)
key = np.asarray(self.key_random)
pt = self.text_random
key = self.key_random
cipher_random = AES.new(bytes(self.key_random), AES.MODE_ECB)
ct = np.asarray(bytearray(cipher_random.encrypt(self.text_random)))
ct = cipher_random.encrypt(bytes(self.text_random))
del (cipher_random)
self.advance_random()
return pt, ct, key
Expand Down

0 comments on commit b0ab33a

Please sign in to comment.