-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[capture] Add uJSON support #218
Conversation
ddac48f
to
de8bebd
Compare
capture/lib/ot_communication.py
Outdated
def _ujson_aes_sca_cmd(self): | ||
# TODO: without the delay, the device uJSON command handler program | ||
# does not recognize the commands. | ||
time.sleep(0.2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@milesdai is there a way to avoid this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a quick update: I'm working on reproducing this bug. Should I be running something like ./capture_aes.py -c configs/aes_sca_cw310.yaml -p test_project
to test this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactely. Please change the configs/aes_sca_cw310.yaml
as mentioned above, build the firmware from the PR linked above, and run ./capture_aes.py -c configs/aes_sca_cw310.yaml -p test_project
. However, if you don't have a ChipWhisperer Husky, the capture script fails.
I'll create a small POC script for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a small POC script:
#!/usr/bin/env python3
# Copyright lowRISC contributors.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
from lib.ot_communication import OTAES, OTPRNG, OTUART
# Establish UART for uJSON command interface. Returns None for simpleserial.
ot_uart = OTUART(protocol="ujson", port="/dev/ttyACM4")
# Create communication interface to OT AES.
ot_aes = OTAES(target=None, protocol="ujson", port=ot_uart.uart)
# Set the key.
key = [0x81, 0x1E, 0x37, 0x31, 0xB0, 0x12, 0x0A, 0x78, 0x42, 0x78, 0x1E, 0x22, 0xB2, 0x5C, 0xDD, 0xF9]
ot_aes.key_set(key)
# Start encryption.
text = [0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA]
ot_aes.single_encrypt(text)
# Read ciphertext.
print(ot_aes.read_ciphertext(16))
Please place this script into the capture/
folder, transfer the firmware to the device, adapt the port (e.g., "/dev/ttyACM4"
) in the script, and start it. You should receive the ciphertext.
When I now remove all time.sleep
commands in ot_communication.py
, I do not receive a ciphertext. I did some printf
debugging on the device, it seems that when sending two commands subsequently, the latter is not received by the command handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the test script! I'm able to reproduce the problem you're describing. I'm still looking into this, but so far, this sounds a lot like a flow control issue. The firmware enables software-based flow control through OTTF, so I've tried enabling SW flow control on the Python side as well with the xonxoff=True
flag, but no luck so far.
I'm going to take a closer look at this, but in the meanwhile, I've found that I can reduce the sleep time to about 10 ms instead of 200. If we don't want to block the PR on this, maybe that can help your throughput a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @milesdai! I'll decrease the timeout and merge the PR for now.
Please let me know if I can help you with debugging, for us a fast communication is really important as we want to trigger AES executions as fast as possible to achieve high capture rates.
de8bebd
to
8ced117
Compare
As discussed with @milesdai , capture rate is still quite low as there seems to be an issue with the communication protocol. Miles will be working on a fix. Capture rates for AES random batch drops from 934.27 traces/s to 350.40 traces/s. |
21dfe61
to
69e60c4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @nasahlpa , the PR looks mostly good but especially in data_generator.py
there seem to be changes not related to this PR.
2c69265
to
080026e
Compare
Thanks for the feedback @vogelpi, I've addressed your comments. |
080026e
to
b0ab33a
Compare
This PR enables communication with the OT AES over uJSON. Signed-off-by: Pascal Nasahl <[email protected]>
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]>
b0ab33a
to
ffbdd90
Compare
This is probably not a problem. If we increase |
|
||
def fvsr_key_set(self, key): | ||
def fvsr_key_set(self, key, key_length: Optional[int] = 16): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this function is not used anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right. However, as the AES SCA uJSON handler at the OT device implements the FvsrKeySet command, the handler is provided here. If we don't need the FvsrKeySet command at the OT device, we should remove it there and also here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested this PR and all captures work well with my setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Related to that, aren't the number of segments automatically determined by Husky? I thought this was required to always completely fill the sample memory in Husky before reading it out in batch mode. Do we manually set the number of segments somewhere now? |
That used to be the case. Now it's just specified in the configuration file. For this reason we also sometimes get more measurements than we ask for (e.g. if num_segments = 40, num_traces = 100, the script will take 120 measurements) |
Ah, thanks for getting back! This makes sense. We should probably add a check in case num_segements * num_samples is bigger than the sample memory. Pascal said to take care of this. |
Similar to lowRISC#218, this PR enables uJSON support for capturing KMAC traces. The device command handler code can be found in #20563. Signed-off-by: Pascal Nasahl <[email protected]>
Similar to lowRISC#218, this PR enables uJSON support for capturing KMAC traces. The device command handler code can be found in #20563. Signed-off-by: Pascal Nasahl <[email protected]>
Similar to lowRISC#218, this PR enables uJSON support for capturing KMAC traces. The device command handler code can be found in #20563. Signed-off-by: Pascal Nasahl <[email protected]>
Similar to lowRISC#218, this PR enables uJSON support for capturing KMAC traces. The device command handler code can be found in #20563. Closes lowRISC#238 Signed-off-by: Pascal Nasahl <[email protected]>
Similar to lowRISC#218, this PR enables uJSON support for capturing KMAC traces. The device command handler code can be found in #20563. Closes lowRISC#238 Signed-off-by: Pascal Nasahl <[email protected]>
Similar to lowRISC#218, this PR enables uJSON support for capturing KMAC traces. The device command handler code can be found in #20563. Closes lowRISC#238 Signed-off-by: Pascal Nasahl <[email protected]>
Similar to lowRISC#218, this PR enables uJSON support for capturing KMAC traces. The device command handler code can be found in #20563. Closes lowRISC#238 Signed-off-by: Pascal Nasahl <[email protected]>
Similar to #218, this PR enables uJSON support for capturing KMAC traces. The device command handler code can be found in #20563. Closes #238 Signed-off-by: Pascal Nasahl <[email protected]>
Similar to lowRISC#218 , this PR enables uJSON support for capturing SHA3 traces. The device command handler code can be found in #20593. Signed-off-by: Pascal Nasahl <[email protected]>
Similar to lowRISC#218 , this PR enables uJSON support for capturing SHA3 traces. The device command handler code can be found in #20593. Signed-off-by: Pascal Nasahl <[email protected]>
Similar to #218 , this PR enables uJSON support for capturing SHA3 traces. The device command handler code can be found in #20593. Signed-off-by: Pascal Nasahl <[email protected]>
This PR enables communication with the OT AES over uJSON.
How to use:
capture/configs/aes_sca_cw310.yaml
target
change:protocol: "ujson"
port: "/dev/ttyACM4"
(adapt the port accordingly, needs to be UART of CW310)fw_bin: "../objs/aes_ujson_fpga_cw310.bin"
Device code is located in PR#20386.