Skip to content
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 trigger source command #303

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions capture/capture_aes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import util.helpers as helpers
from target.communication.sca_aes_commands import OTAES
from target.communication.sca_prng_commands import OTPRNG
from target.communication.sca_trigger_commands import OTTRIGGER
from target.targets import Target, TargetConfig
from util import check_version
from util import data_generator as dg
Expand Down Expand Up @@ -149,25 +150,41 @@ def setup(cfg: dict, project: Path):
return target, scope, project


def configure_cipher(cfg, target, capture_cfg) -> OTAES:
""" Configure the AES cipher.
Establish communication with the AES cipher and configure the seed.
def establish_communication(target, capture_cfg: CaptureConfig):
""" Establish communication with the target device.
Args:
cfg: The project config.
target: The OT target.
capture_cfg: The capture config.
Returns:
The communication interface to the AES cipher.
ot_aes: The communication interface to the AES SCA application.
ot_prng: The communication interface to the PRNG SCA application.
ot_trig: The communication interface to the SCA trigger.
"""
# Create communication interface to OT AES.
ot_aes = OTAES(target=target, protocol=capture_cfg.protocol)

# Create communication interface to OT PRNG.
ot_prng = OTPRNG(target=target, protocol=capture_cfg.protocol)

# Create communication interface to SCA trigger.
ot_trig = OTTRIGGER(target=target, protocol=capture_cfg.protocol)

return ot_aes, ot_prng, ot_trig


def configure_cipher(cfg, capture_cfg, ot_aes, ot_prng):
""" Configure the AES cipher.
Establish communication with the AES cipher and configure the seed.
Args:
cfg: The project config.
capture_cfg: The capture config.
ot_aes: The communication interface to the AES SCA application.
ot_prng: The communication interface to the PRNG SCA application.
"""
# Configure PRNGs.
# Seed the software LFSR used for initial key masking and additionally
# turning off the masking when '0'.
Expand All @@ -180,8 +197,6 @@ def configure_cipher(cfg, target, capture_cfg) -> OTAES:
# Seed the target's PRNG.
ot_prng.seed_prng(cfg["test"]["batch_prng_seed"].to_bytes(4, "little"))

return ot_aes


def generate_ref_crypto(sample_fixed, mode, key, plaintext):
""" Generate cipher material for the encryption.
Expand Down Expand Up @@ -413,8 +428,18 @@ def main(argv=None):
port = cfg["target"].get("port"))
logger.info(f"Setting up capture {capture_cfg.capture_mode} batch={capture_cfg.batch_mode}...")

# Open communication with target.
ot_aes, ot_prng, ot_trig = establish_communication(target, capture_cfg)

# Configure cipher.
ot_aes = configure_cipher(cfg, target, capture_cfg)
configure_cipher(cfg, capture_cfg, ot_aes, ot_prng)

# Configure trigger source.
# 0 for HW, 1 for SW.
trigger_source = 1
if "hw" in cfg["target"].get("trigger"):
trigger_source = 0
ot_trig.select_trigger(trigger_source)

# Capture traces.
capture(scope, ot_aes, capture_cfg, project, target)
Expand Down
49 changes: 37 additions & 12 deletions capture/capture_kmac.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import util.helpers as helpers
from target.communication.sca_kmac_commands import OTKMAC
from target.communication.sca_prng_commands import OTPRNG
from target.communication.sca_trigger_commands import OTTRIGGER
from target.targets import Target, TargetConfig
from util import check_version
from util import data_generator as dg
Expand Down Expand Up @@ -153,22 +154,41 @@ def setup(cfg: dict, project: Path):
return target, scope, project


def configure_cipher(cfg, target, capture_cfg) -> OTKMAC:
""" Configure the KMAC cipher.
Establish communication with the KMAC cipher and configure the seed.
def establish_communication(target, capture_cfg: CaptureConfig):
""" Establish communication with the target device.
Args:
cfg: The project config.
target: The OT target.
capture_cfg: The capture config.
Returns:
The communication interface to the KMAC cipher.
ot_kmac: The communication interface to the KMAC SCA application.
ot_prng: The communication interface to the PRNG SCA application.
ot_trig: The communication interface to the SCA trigger.
"""
# Create communication interface to OT KMAC.
ot_kmac = OTKMAC(target=target, protocol=capture_cfg.protocol)

# Create communication interface to OT PRNG.
ot_prng = OTPRNG(target=target, protocol=capture_cfg.protocol)

# Create communication interface to SCA trigger.
ot_trig = OTTRIGGER(target=target, protocol=capture_cfg.protocol)

return ot_kmac, ot_prng, ot_trig


def configure_cipher(cfg, capture_cfg, ot_kmac, ot_prng):
""" Configure the KMAC cipher.
Establish communication with the KMAC cipher and configure the seed.
Args:
cfg: The project config.
capture_cfg: The capture config.
ot_kmac: The communication interface to the KMAC SCA application.
ot_prng: The communication interface to the PRNG SCA application.
"""
# Check if we want to run KMAC SCA for FPGA or discrete. On the FPGA, we
# can use functionality helping us to capture cleaner traces.
fpga_mode_bit = 0
Expand All @@ -177,9 +197,6 @@ def configure_cipher(cfg, target, capture_cfg) -> OTKMAC:
# Initialize KMAC on the target.
ot_kmac.init(fpga_mode_bit)

# Create communication interface to OT PRNG.
ot_prng = OTPRNG(target=target, protocol=capture_cfg.protocol)

# Configure PRNGs.
# Seed the software LFSR used for initial key masking.
ot_kmac.write_lfsr_seed(cfg["test"]["lfsr_seed"].to_bytes(4, "little"))
Expand All @@ -192,8 +209,6 @@ def configure_cipher(cfg, target, capture_cfg) -> OTKMAC:
# Seed the target's PRNG.
ot_prng.seed_prng(cfg["test"]["batch_prng_seed"].to_bytes(4, "little"))

return ot_kmac


def generate_ref_crypto(sample_fixed, mode, batch, key, key_fixed, plaintext,
plaintext_fixed, key_length):
Expand Down Expand Up @@ -455,8 +470,18 @@ def main(argv=None):
port = cfg["target"].get("port"))
logger.info(f"Setting up capture {capture_cfg.capture_mode} batch={capture_cfg.batch_mode}...")

# Open communication with target.
ot_kmac, ot_prng, ot_trig = establish_communication(target, capture_cfg)

# Configure cipher.
ot_kmac = configure_cipher(cfg, target, capture_cfg)
configure_cipher(cfg, capture_cfg, ot_kmac, ot_prng)

# Configure trigger source.
# 0 for HW, 1 for SW.
trigger_source = 1
if "hw" in cfg["target"].get("trigger"):
trigger_source = 0
ot_trig.select_trigger(trigger_source)

# Capture traces.
capture(scope, ot_kmac, capture_cfg, project, target)
Expand Down
44 changes: 36 additions & 8 deletions capture/capture_otbn.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import util.helpers as helpers
from target.communication.sca_otbn_commands import OTOTBNVERT
from target.communication.sca_trigger_commands import OTTRIGGER
from target.targets import Target, TargetConfig
from util import check_version
from util import data_generator as dg
Expand Down Expand Up @@ -178,8 +179,28 @@ def setup(cfg: dict, project: Path):
return target, scope, project


def configure_cipher(cfg: dict, target,
capture_cfg: CaptureConfig) -> OTOTBNVERT:
def establish_communication(target, capture_cfg: CaptureConfig):
""" Establish communication with the target device.
Args:
target: The OT target.
curve_cfg: The capture config
Returns:
ot_otbn_vert: The communication interface to the OTBN app.
ot_trig: The communication interface to the SCA trigger.
"""
# Create communication interface to OTBN.
ot_otbn_vert = OTOTBNVERT(target=target, protocol=capture_cfg.protocol)

# Create communication interface to SCA trigger.
ot_trig = OTTRIGGER(target=target, protocol=capture_cfg.protocol)

return ot_otbn_vert, ot_trig


def configure_cipher(cfg: dict, target, capture_cfg: CaptureConfig,
ot_otbn_vert) -> OTOTBNVERT:
""" Configure the OTBN app.
Establish communication with the OTBN keygen app and configure the seed.
Expand All @@ -189,14 +210,11 @@ def configure_cipher(cfg: dict, target,
target: The OT target.
curve_cfg: The curve config.
capture_cfg: The configuration of the capture.
ot_otbn_vert: The communication interface to the OTBN app.
Returns:
ot_otbn_vert: The communication interface to the OTBN app.
curve_cfg: The curve configuration values.
"""
# Create communication interface to OTBN.
ot_otbn_vert = OTOTBNVERT(target=target, protocol=capture_cfg.protocol)

# Seed host's PRNG.
random.seed(cfg["test"]["batch_prng_seed"])

Expand Down Expand Up @@ -286,7 +304,7 @@ def configure_cipher(cfg: dict, target,
capture_cfg.expected_fixed_output = pow(k_fixed_int, -1,
curve_cfg.curve_order_n)

return ot_otbn_vert, curve_cfg
return curve_cfg


def generate_ref_crypto_keygen(cfg: dict, sample_fixed, curve_cfg: CurveConfig,
Expand Down Expand Up @@ -717,8 +735,18 @@ def main(argv=None):
f"Setting up capture {capture_cfg.capture_mode} batch={capture_cfg.batch_mode}..."
)

# Open communication with target.
ot_otbn_vert, ot_trig = establish_communication(target, capture_cfg)

# Configure cipher.
ot_otbn_vert, curve_cfg = configure_cipher(cfg, target, capture_cfg)
curve_cfg = configure_cipher(cfg, target, capture_cfg, ot_otbn_vert)

# Configure trigger source.
# 0 for HW, 1 for SW.
trigger_source = 1
if "hw" in cfg["target"].get("trigger"):
trigger_source = 0
ot_trig.select_trigger(trigger_source)

# Capture traces.
if mode == "keygen":
Expand Down
43 changes: 34 additions & 9 deletions capture/capture_sha3.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import util.helpers as helpers
from target.communication.sca_prng_commands import OTPRNG
from target.communication.sca_sha3_commands import OTSHA3
from target.communication.sca_trigger_commands import OTTRIGGER
from target.targets import Target, TargetConfig
from util import check_version
from util import data_generator as dg
Expand Down Expand Up @@ -138,25 +139,41 @@ def setup(cfg: dict, project: Path):
return target, scope, project


def configure_cipher(cfg, target, capture_cfg) -> OTSHA3:
""" Configure the SHA3 cipher.

Establish communication with the SHA3 cipher and configure the seed and mask.
def establish_communication(target, capture_cfg: CaptureConfig):
""" Establish communication with the target device.

Args:
cfg: The project config.
target: The OT target.
capture_cfg: The capture config.

Returns:
The communication interface to the SHA3 cipher.
ot_sha3: The communication interface to the SHA3 SCA application.
ot_prng: The communication interface to the PRNG SCA application.
ot_trig: The communication interface to the SCA trigger.
"""
# Create communication interface to OT SHA3.
ot_sha3 = OTSHA3(target=target, protocol=capture_cfg.protocol)

# Create communication interface to SCA trigger.
ot_trig = OTTRIGGER(target=target, protocol=capture_cfg.protocol)

# Create communication interface to OT PRNG.
ot_prng = OTPRNG(target=target, protocol=capture_cfg.protocol)

return ot_sha3, ot_prng, ot_trig


def configure_cipher(cfg, capture_cfg, ot_sha3, ot_prng):
""" Configure the SHA3 cipher.

Establish communication with the SHA3 cipher and configure the seed and mask.

Args:
cfg: The project config.
capture_cfg: The capture config.
ot_sha3: The communication interface to the SHA3 SCA application.
ot_prng: The communication interface to the PRNG SCA application.
"""
# Check if we want to run KMAC SCA for FPGA or discrete. On the FPGA, we
# can use functionality helping us to capture cleaner traces.
fpga_mode_bit = 0
Expand All @@ -183,8 +200,6 @@ def configure_cipher(cfg, target, capture_cfg) -> OTSHA3:
# Seed the target's PRNG.
ot_prng.seed_prng(cfg["test"]["batch_prng_seed"].to_bytes(4, "little"))

return ot_sha3


def generate_ref_crypto(sample_fixed, mode, batch, plaintext,
plaintext_fixed, text_len_bytes):
Expand Down Expand Up @@ -427,8 +442,18 @@ def main(argv=None):
port = cfg["target"].get("port"))
logger.info(f"Setting up capture {capture_cfg.capture_mode} batch={capture_cfg.batch_mode}...")

# Open communication with target.
ot_sha3, ot_prng, ot_trig = establish_communication(target, capture_cfg)

# Configure cipher.
ot_sha3 = configure_cipher(cfg, target, capture_cfg)
configure_cipher(cfg, capture_cfg, ot_sha3, ot_prng)

# Configure trigger source.
# 0 for HW, 1 for SW.
trigger_source = 1
if "hw" in cfg["target"].get("trigger"):
trigger_source = 0
ot_trig.select_trigger(trigger_source)

# Capture traces.
capture(scope, ot_sha3, capture_cfg, project, target)
Expand Down
4 changes: 4 additions & 0 deletions capture/configs/aes_sca_chip.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ target:
output_len_bytes: 16
protocol: "ujson"
port: "/dev/ttyUSB1"
# Trigger source.
# hw: Precise, hardware-generated trigger - FPGA only.
# sw: Fully software-controlled trigger.
trigger: "sw"
waverunner:
waverunner_ip: 100.107.71.10
num_segments: 20
Expand Down
4 changes: 4 additions & 0 deletions capture/configs/aes_sca_cw305.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ target:
baudrate: 115200
output_len_bytes: 16
protocol: "simpleserial"
# Trigger source.
# hw: Precise, hardware-generated trigger - FPGA only.
# sw: Fully software-controlled trigger.
trigger: "hw"
husky:
sampling_rate: 200000000
num_segments: 80
Expand Down
4 changes: 4 additions & 0 deletions capture/configs/aes_sca_cw310.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ target:
protocol: "simpleserial"
# protocol: "ujson"
# port: "/dev/ttyACM4"
# Trigger source.
# hw: Precise, hardware-generated trigger - FPGA only.
# sw: Fully software-controlled trigger.
trigger: "hw"
husky:
sampling_rate: 200000000
num_segments: 20
Expand Down
4 changes: 4 additions & 0 deletions capture/configs/kmac_sca_cw310.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ target:
protocol: "simpleserial"
# protocol: "ujson"
# port: "/dev/ttyACM1"
# Trigger source.
# hw: Precise, hardware-generated trigger - FPGA only.
# sw: Fully software-controlled trigger.
trigger: "hw"
husky:
sampling_rate: 200000000
num_segments: 20
Expand Down
Loading
Loading