From f2e5e40c2c88cb7fb6d34d9a477e08d91b69ce05 Mon Sep 17 00:00:00 2001 From: Pascal Nasahl Date: Mon, 29 Jan 2024 10:09:27 +0000 Subject: [PATCH] [capture] Add trigger source command This PR adds the SCA trigger source command to the capture scripts. Needed to start penetration tests at ASIC as there is no HW trigger available. Signed-off-by: Pascal Nasahl --- capture/capture_aes.py | 43 ++++++++++++++---- capture/capture_kmac.py | 43 ++++++++++++++---- capture/capture_otbn.py | 44 +++++++++++++++---- capture/capture_sha3.py | 43 ++++++++++++++---- capture/configs/aes_sca_cw305.yaml | 4 ++ capture/configs/aes_sca_cw310.yaml | 4 ++ capture/configs/kmac_sca_cw310.yaml | 4 ++ .../otbn_vertical_keygen_sca_cw310.yaml | 4 ++ .../otbn_vertical_modinv_sca_cw310.yaml | 4 ++ capture/configs/sha3_sca_cw310.yaml | 4 ++ capture/configs/sha3_sca_cw310_masks_off.yaml | 4 ++ ci/cfg/ci_aes_sca_fvsr_cw305.yaml | 4 ++ ci/cfg/ci_aes_sca_fvsr_cw310.yaml | 4 ++ ci/cfg/ci_aes_sca_random_cw305.yaml | 4 ++ ci/cfg/ci_aes_sca_random_cw310.yaml | 4 ++ ci/cfg/ci_ibex_fi_vcc_dummy.yaml | 4 ++ .../ci_kmac_sca_fvsr_cw310_simpleserial.yaml | 4 ++ ci/cfg/ci_kmac_sca_fvsr_cw310_ujson.yaml | 4 ++ ...ci_kmac_sca_random_cw310_simpleserial.yaml | 4 ++ ci/cfg/ci_kmac_sca_random_cw310_ujson.yaml | 4 ++ .../ci_sha3_sca_fvsr_cw310_simpleserial.yaml | 4 ++ ci/cfg/ci_sha3_sca_fvsr_cw310_ujson.yaml | 4 ++ ...ci_sha3_sca_random_cw310_simpleserial.yaml | 4 ++ ci/cfg/ci_sha3_sca_random_cw310_ujson.yaml | 4 ++ target/communication/sca_trigger_commands.py | 40 +++++++++++++++++ 25 files changed, 258 insertions(+), 35 deletions(-) create mode 100644 target/communication/sca_trigger_commands.py diff --git a/capture/capture_aes.py b/capture/capture_aes.py index 3f1b8546a..92c69576b 100755 --- a/capture/capture_aes.py +++ b/capture/capture_aes.py @@ -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 @@ -149,18 +150,17 @@ 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) @@ -168,6 +168,23 @@ def configure_cipher(cfg, target, capture_cfg) -> OTAES: # 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'. @@ -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. @@ -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) diff --git a/capture/capture_kmac.py b/capture/capture_kmac.py index 179abaaf3..7d4054cd6 100755 --- a/capture/capture_kmac.py +++ b/capture/capture_kmac.py @@ -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 @@ -153,18 +154,17 @@ 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) @@ -172,6 +172,23 @@ def configure_cipher(cfg, target, capture_cfg) -> OTKMAC: # 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. + """ # Configure PRNGs. # Seed the software LFSR used for initial key masking. ot_kmac.write_lfsr_seed(cfg["test"]["lfsr_seed"].to_bytes(4, "little")) @@ -184,8 +201,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): @@ -447,8 +462,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) diff --git a/capture/capture_otbn.py b/capture/capture_otbn.py index d08ea8635..29cff4f7a 100755 --- a/capture/capture_otbn.py +++ b/capture/capture_otbn.py @@ -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 @@ -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. @@ -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"]) @@ -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, @@ -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": diff --git a/capture/capture_sha3.py b/capture/capture_sha3.py index 04bc3b6d4..cbb7d2a00 100755 --- a/capture/capture_sha3.py +++ b/capture/capture_sha3.py @@ -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 @@ -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. + """ if cfg["test"]["masks_off"] is True: logger.info("Configure device to use constant, fast entropy!") ot_sha3.set_mask_off() @@ -175,8 +192,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): @@ -419,8 +434,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) diff --git a/capture/configs/aes_sca_cw305.yaml b/capture/configs/aes_sca_cw305.yaml index a504e0b67..2af5b9ebd 100644 --- a/capture/configs/aes_sca_cw305.yaml +++ b/capture/configs/aes_sca_cw305.yaml @@ -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 diff --git a/capture/configs/aes_sca_cw310.yaml b/capture/configs/aes_sca_cw310.yaml index 51af021d0..23ca947b7 100644 --- a/capture/configs/aes_sca_cw310.yaml +++ b/capture/configs/aes_sca_cw310.yaml @@ -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 diff --git a/capture/configs/kmac_sca_cw310.yaml b/capture/configs/kmac_sca_cw310.yaml index a5be6bcf6..e1b0d1a15 100644 --- a/capture/configs/kmac_sca_cw310.yaml +++ b/capture/configs/kmac_sca_cw310.yaml @@ -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 diff --git a/capture/configs/otbn_vertical_keygen_sca_cw310.yaml b/capture/configs/otbn_vertical_keygen_sca_cw310.yaml index f80dbd1e9..85dbe96ef 100644 --- a/capture/configs/otbn_vertical_keygen_sca_cw310.yaml +++ b/capture/configs/otbn_vertical_keygen_sca_cw310.yaml @@ -11,6 +11,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 diff --git a/capture/configs/otbn_vertical_modinv_sca_cw310.yaml b/capture/configs/otbn_vertical_modinv_sca_cw310.yaml index 47df6388d..2a54bc51d 100644 --- a/capture/configs/otbn_vertical_modinv_sca_cw310.yaml +++ b/capture/configs/otbn_vertical_modinv_sca_cw310.yaml @@ -11,6 +11,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 diff --git a/capture/configs/sha3_sca_cw310.yaml b/capture/configs/sha3_sca_cw310.yaml index 10c6fc25e..ca6747229 100644 --- a/capture/configs/sha3_sca_cw310.yaml +++ b/capture/configs/sha3_sca_cw310.yaml @@ -11,6 +11,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: samling_rate: 200000000 num_segments: 20 diff --git a/capture/configs/sha3_sca_cw310_masks_off.yaml b/capture/configs/sha3_sca_cw310_masks_off.yaml index d334f284b..d892cffcd 100644 --- a/capture/configs/sha3_sca_cw310_masks_off.yaml +++ b/capture/configs/sha3_sca_cw310_masks_off.yaml @@ -11,6 +11,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: samling_rate: 200000000 num_segments: 20 diff --git a/ci/cfg/ci_aes_sca_fvsr_cw305.yaml b/ci/cfg/ci_aes_sca_fvsr_cw305.yaml index a2f669272..d37f6a0fb 100644 --- a/ci/cfg/ci_aes_sca_fvsr_cw305.yaml +++ b/ci/cfg/ci_aes_sca_fvsr_cw305.yaml @@ -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 diff --git a/ci/cfg/ci_aes_sca_fvsr_cw310.yaml b/ci/cfg/ci_aes_sca_fvsr_cw310.yaml index 76d3629ef..df24a4e91 100644 --- a/ci/cfg/ci_aes_sca_fvsr_cw310.yaml +++ b/ci/cfg/ci_aes_sca_fvsr_cw310.yaml @@ -10,6 +10,10 @@ target: output_len_bytes: 16 # protocol: "ujson" protocol: "simpleserial" + # Trigger source. + # hw: Precise, hardware-generated trigger - FPGA only. + # sw: Fully software-controlled trigger. + trigger: "hw" husky: sampling_rate: 200000000 num_segments: 20 diff --git a/ci/cfg/ci_aes_sca_random_cw305.yaml b/ci/cfg/ci_aes_sca_random_cw305.yaml index 46e446248..c3fbff5c8 100644 --- a/ci/cfg/ci_aes_sca_random_cw305.yaml +++ b/ci/cfg/ci_aes_sca_random_cw305.yaml @@ -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 diff --git a/ci/cfg/ci_aes_sca_random_cw310.yaml b/ci/cfg/ci_aes_sca_random_cw310.yaml index 87a3a4d3f..24fe1ac69 100644 --- a/ci/cfg/ci_aes_sca_random_cw310.yaml +++ b/ci/cfg/ci_aes_sca_random_cw310.yaml @@ -10,6 +10,10 @@ target: output_len_bytes: 16 # protocol: "ujson" protocol: "simpleserial" + # Trigger source. + # hw: Precise, hardware-generated trigger - FPGA only. + # sw: Fully software-controlled trigger. + trigger: "hw" husky: sampling_rate: 200000000 num_segments: 20 diff --git a/ci/cfg/ci_ibex_fi_vcc_dummy.yaml b/ci/cfg/ci_ibex_fi_vcc_dummy.yaml index 3f9678d61..fc8416793 100644 --- a/ci/cfg/ci_ibex_fi_vcc_dummy.yaml +++ b/ci/cfg/ci_ibex_fi_vcc_dummy.yaml @@ -9,6 +9,10 @@ target: baudrate: 115200 protocol: "ujson" port: "/dev/ttyACM_CW310_1" + # Trigger source. + # hw: Precise, hardware-generated trigger - FPGA only. + # sw: Fully software-controlled trigger. + trigger: "hw" fisetup: fi_gear: "dummy" fi_type: "voltage_glitch" diff --git a/ci/cfg/ci_kmac_sca_fvsr_cw310_simpleserial.yaml b/ci/cfg/ci_kmac_sca_fvsr_cw310_simpleserial.yaml index fd6cfc696..8076be0e4 100644 --- a/ci/cfg/ci_kmac_sca_fvsr_cw310_simpleserial.yaml +++ b/ci/cfg/ci_kmac_sca_fvsr_cw310_simpleserial.yaml @@ -12,6 +12,10 @@ target: protocol: "simpleserial" # protocol: "ujson" # port: "/dev/ttyACM_CW310_1" + # Trigger source. + # hw: Precise, hardware-generated trigger - FPGA only. + # sw: Fully software-controlled trigger. + trigger: "hw" husky: sampling_rate: 200000000 num_segments: 20 diff --git a/ci/cfg/ci_kmac_sca_fvsr_cw310_ujson.yaml b/ci/cfg/ci_kmac_sca_fvsr_cw310_ujson.yaml index a8cafd864..f9f0d22be 100644 --- a/ci/cfg/ci_kmac_sca_fvsr_cw310_ujson.yaml +++ b/ci/cfg/ci_kmac_sca_fvsr_cw310_ujson.yaml @@ -12,6 +12,10 @@ target: # protocol: "simpleserial" protocol: "ujson" port: "/dev/ttyACM_CW310_1" + # Trigger source. + # hw: Precise, hardware-generated trigger - FPGA only. + # sw: Fully software-controlled trigger. + trigger: "hw" husky: sampling_rate: 200000000 num_segments: 20 diff --git a/ci/cfg/ci_kmac_sca_random_cw310_simpleserial.yaml b/ci/cfg/ci_kmac_sca_random_cw310_simpleserial.yaml index 214d4f70c..22593a54c 100644 --- a/ci/cfg/ci_kmac_sca_random_cw310_simpleserial.yaml +++ b/ci/cfg/ci_kmac_sca_random_cw310_simpleserial.yaml @@ -12,6 +12,10 @@ target: protocol: "simpleserial" # protocol: "ujson" # port: "/dev/ttyACM_CW310_1" + # Trigger source. + # hw: Precise, hardware-generated trigger - FPGA only. + # sw: Fully software-controlled trigger. + trigger: "hw" husky: sampling_rate: 200000000 num_segments: 1 diff --git a/ci/cfg/ci_kmac_sca_random_cw310_ujson.yaml b/ci/cfg/ci_kmac_sca_random_cw310_ujson.yaml index 57d0f7d47..fc99ed443 100644 --- a/ci/cfg/ci_kmac_sca_random_cw310_ujson.yaml +++ b/ci/cfg/ci_kmac_sca_random_cw310_ujson.yaml @@ -12,6 +12,10 @@ target: # protocol: "simpleserial" protocol: "ujson" port: "/dev/ttyACM_CW310_1" + # Trigger source. + # hw: Precise, hardware-generated trigger - FPGA only. + # sw: Fully software-controlled trigger. + trigger: "hw" husky: sampling_rate: 200000000 num_segments: 1 diff --git a/ci/cfg/ci_sha3_sca_fvsr_cw310_simpleserial.yaml b/ci/cfg/ci_sha3_sca_fvsr_cw310_simpleserial.yaml index 0b28e56bc..0ab645608 100644 --- a/ci/cfg/ci_sha3_sca_fvsr_cw310_simpleserial.yaml +++ b/ci/cfg/ci_sha3_sca_fvsr_cw310_simpleserial.yaml @@ -11,6 +11,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: samling_rate: 200000000 num_segments: 20 diff --git a/ci/cfg/ci_sha3_sca_fvsr_cw310_ujson.yaml b/ci/cfg/ci_sha3_sca_fvsr_cw310_ujson.yaml index e80ef9ac6..d431b849d 100644 --- a/ci/cfg/ci_sha3_sca_fvsr_cw310_ujson.yaml +++ b/ci/cfg/ci_sha3_sca_fvsr_cw310_ujson.yaml @@ -11,6 +11,10 @@ target: # protocol: "simpleserial" protocol: "ujson" port: "/dev/ttyACM_CW310_1" + # Trigger source. + # hw: Precise, hardware-generated trigger - FPGA only. + # sw: Fully software-controlled trigger. + trigger: "hw" husky: samling_rate: 200000000 num_segments: 20 diff --git a/ci/cfg/ci_sha3_sca_random_cw310_simpleserial.yaml b/ci/cfg/ci_sha3_sca_random_cw310_simpleserial.yaml index 91f3fb623..c6a41b974 100644 --- a/ci/cfg/ci_sha3_sca_random_cw310_simpleserial.yaml +++ b/ci/cfg/ci_sha3_sca_random_cw310_simpleserial.yaml @@ -11,6 +11,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: samling_rate: 200000000 num_segments: 1 diff --git a/ci/cfg/ci_sha3_sca_random_cw310_ujson.yaml b/ci/cfg/ci_sha3_sca_random_cw310_ujson.yaml index d59b1c967..ef3d52e16 100644 --- a/ci/cfg/ci_sha3_sca_random_cw310_ujson.yaml +++ b/ci/cfg/ci_sha3_sca_random_cw310_ujson.yaml @@ -11,6 +11,10 @@ target: # protocol: "simpleserial" protocol: "ujson" port: "/dev/ttyACM_CW310_1" + # Trigger source. + # hw: Precise, hardware-generated trigger - FPGA only. + # sw: Fully software-controlled trigger. + trigger: "hw" husky: samling_rate: 200000000 num_segments: 1 diff --git a/target/communication/sca_trigger_commands.py b/target/communication/sca_trigger_commands.py new file mode 100644 index 000000000..cbec0574b --- /dev/null +++ b/target/communication/sca_trigger_commands.py @@ -0,0 +1,40 @@ +# Copyright lowRISC contributors. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 +"""Communication interface for the SHA3 SCA application on OpenTitan. + +Communication with OpenTitan either happens over simpleserial or the uJson +command interface. +""" +import json +import time +from typing import Optional + + +class OTTRIGGER: + def __init__(self, target, protocol: str) -> None: + self.target = target + self.simple_serial = True + if protocol == "ujson": + self.simple_serial = False + + def select_trigger(self, trigger_source: Optional[int] = 0): + """ Select the trigger source for SCA. + Args: + trigger_source: + - 0: Precise, hardware-generated trigger - FPGA only. + - 1: Fully software-controlled trigger. + """ + if self.simple_serial: + self.target.write("t", bytearray([trigger_source])) + else: + # TODO: without the delay, the device uJSON command handler program + # does not recognize the commands. Tracked in issue #256. + time.sleep(0.01) + self.target.write(json.dumps("TriggerSca").encode("ascii")) + # DisableMasking command. + self.target.write(json.dumps("SelectTriggerSource").encode("ascii")) + # Source payload. + time.sleep(0.01) + src = {"source": [trigger_source]} + self.target.write(json.dumps(src).encode("ascii"))