### Setup Generic Helper Script Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca101/generators/Lab4_3 - GENERATOR.ipynb Runs a generic setup script for the ChipWhisperer environment. Ensure the path is correct for your setup. ```python %run "../../../Helper_Scripts/Setup_Generic.ipynb" ``` -------------------------------- ### Run Generic Setup Script Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/husky/10 - Husky Hardware SWD Bitbanging.ipynb Execute the generic setup script for the environment. This is a prerequisite for subsequent operations. ```python %run '/home/jpnewae/git/cw_trimmed/jupyter/Setup_Scripts/Setup_Generic.ipynb' ``` -------------------------------- ### Run Setup Script Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/fault101/Fault 2_2 - Voltage Glitching to Bypass Password.ipynb Executes a generic setup script for the notebook environment. Ensure this script is available in the specified path. ```python %run "../../Setup_Scripts/Setup_Generic.ipynb" ``` -------------------------------- ### Load Setup Notebook Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca204/CW305_ECC_part1.ipynb Executes a setup notebook to configure the environment for trace capture. This is a prerequisite for subsequent operations. ```python %run "CW305_ECC_setup.ipynb" ``` -------------------------------- ### Import ChipWhisperer and Setup Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/husky/02 - Husky Triggers.ipynb Imports the chipwhisperer library and runs a generic setup script. Ensure Setup_Generic.ipynb is in the correct relative path. ```python import chipwhisperer as cw %run "../../Setup_Scripts/Setup_Generic.ipynb" ``` -------------------------------- ### Setup Generic Jupyter Environment Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/experiments/AES_Adv_1-Different Hamming Weight Locations.ipynb Executes a setup script to configure the Jupyter environment for the experiment. This is a common setup step for ChipWhisperer notebooks. ```python %run "../Helper_Scripts/Setup_Generic.ipynb" ``` -------------------------------- ### Setup Generic Notebook Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/fault101/Fault 1_2 - Clock Glitching to Bypass Password.ipynb Executes a setup script for the ChipWhisperer environment. This is a prerequisite for programming the target and running subsequent commands. ```Python %run "../../../Setup_Scripts/Setup_Generic.ipynb" ``` -------------------------------- ### Run Generic Setup Script Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca101/generators/Lab4_1 - GENERATOR.ipynb Executes a generic setup script for Jupyter notebooks. This script likely configures the environment and initializes necessary objects for the analysis. ```python %run "../../../../jupyter/Helper_Scripts/Setup_Generic.ipynb" ``` -------------------------------- ### Setup Generic Environment Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/fault201/Lab 1_2 - 1.5 Round AES Attack.ipynb Runs a generic setup script for the ChipWhisperer environment. This script typically handles common initializations and configurations. ```python %run "../Setup_Scripts/Setup_Generic.ipynb" ``` -------------------------------- ### Hardware/Simulation Configuration Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca201/SOLN_Lab 1_1B - Resychronizing Traces with Dynamic Time Warp.ipynb Sets up configuration variables for the hardware or simulation environment. Ensure these match your target setup. ```python SCOPETYPE = 'OPENADC' PLATFORM = 'CWLITEARM' CRYPTO_TARGET = 'TINYAES128C' VERSION = 'HARDWARE' SS_VER = 'SS_VER_1_1' ``` -------------------------------- ### Platform and Trace Interface Configuration Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca205/uecc_part3_trace_sad.ipynb Sets the target platform and trace interface for the experiment. Ensure these match your hardware setup. ```python PLATFORM = 'CW308_STM32F3' TRACE_INTERFACE = 'swo' SCOPETYPE = 'OPENADC' # not supported by this notebook, but can be made to work: #PLATFORM = 'CW308_K82F' #TRACE_INTERFACE = 'parallel' ``` -------------------------------- ### Interactive Plotting Setup Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca101/Lab 6_4 - Jittery Triggering on UART.ipynb Initialize an interactive plot using HoloViews and a Pipe stream. This setup is used for dynamic data visualization during trace capture. ```python pipe = Pipe(data=[]) plot = cw.plot([1, 2, 3]) dynamic_map = hv.DynamicMap(plot, streams=[pipe]) plot ``` -------------------------------- ### Import cwtvla Convenience Module Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca203/Using CWTVLA For Easy TVLA Testing.ipynb Import the convenience submodule for easier device setup and data capture. ```python import cwtvla.cw_convenience as conv ``` -------------------------------- ### Setup Glitch Controller Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/fault101/Fault 1_4 - Authenticated AES Bootloader.ipynb Configures the glitch controller with specified groups and parameters. Ensure default_setup is off to preserve ADC settings. ```python scope.cglitch_setup(default_setup=False) # make sure default_setup is off so we don't overwrite our adc settings gc = glitch.GlitchController(groups=["success", "reset", "normal"], parameters=["width", "offset", "ext_offset"]) gc.display_stats() ``` -------------------------------- ### ChipWhisperer Scope and Target Setup Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca205/uecc_part3_trace_sad.ipynb Initializes the ChipWhisperer scope, configures generic setup, sets the trace target, and adjusts clock and gain settings. The target baud rate is also adjusted for communication. ```python # platform setup: scope = cw.scope() %run "../../Setup_Scripts/Setup_Generic.ipynb" scope.trace.target = target trace = scope.trace scope.clock.clkgen_freq = 10e6 scope.clock.clkgen_src = 'system' scope.clock.adc_mul = 1 scope.gain.setGain(19) target.baud = 38400 * 10 / 7.37 ``` -------------------------------- ### Reference AES Encryption Setup Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/Helper_Scripts/AES_differential_plotter.ipynb Initializes a reference object for AES encryption, storing input, key, and calculating all encryption states. ```python class Ref(): def __init__(self, intext, key, encrypt, blocksize=128): self.intext=bytes(intext) self.key=bytes(key) self.encrypt=encrypt self.aesstates = AesStates(len(self.key)*8, blocksize) if encrypt: self.states = self.aesstates.encryption_states(intext, key) else: raise NotImplemented ``` -------------------------------- ### Setup and Test Notebook Execution Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/Test_Notebook.ipynb This snippet sets up the testing environment by cleaning up old firmware directories and then proceeds to clear outputs in various course notebooks with specific configurations and blacklists. It also prepares the output directory for test notebooks and copies course images. ```python import os from glob import glob import tests import shutil from tests.tutorials import test_notebook, clear_outputs_in_dir from functools import partial with tests.cd('../firmware/mcu'): dirs = glob('simpleserial-base-lab*') dirs.extend(glob('glitch-simple-lab*')) dirs.extend(glob('simpleserial-aes-lab*')) for d in dirs: shutil.rmtree(d) clear_outputs_in_dir("./courses/sca101", kwargs={"SCOPETYPE": "OPENADC", "PLATFORM": "CWLITEARM", "VERSION": "HARDWARE", "SS_VER": "SS_VER_1_1"}) clear_outputs_in_dir("./courses/sca101", blacklist=r"^SOLN.*", kwargs={}) clear_outputs_in_dir("./courses/fault101", kwargs={"SCOPETYPE": "OPENADC", "PLATFORM": "CWLITEARM"}, blacklist=r".*B.*") clear_outputs_in_dir("./courses/fault101", kwargs={"SCOPETYPE": "CWNANO", "PLATFORM": "CWNANO"}, blacklist=r".*[0-9]_[0-9][^B].*") clear_outputs_in_dir("./courses/sca201", kwargs={"SCOPETYPE": "OPENADC", "PLATFORM": "CWLITEARM"}, \ blacklist=r"^(Lab.*)|(SOLN_Lab [2-9].*)|(Extending.*)") output_dir = os.path.abspath(os.path.join('..', 'tutorials')) test_notebook = partial(test_notebook, allow_errors=False, output_dir=output_dir) # make sure the images are copied over for linking try: os.mkdir(os.path.join(output_dir, 'img')) except FileExistsError: pass for course in glob('./courses/*'): for image in glob('{}/img/*'.format(course)): _, image_name = os.path.split(image) print(os.path.join(output_dir, 'img', image_name)) shutil.copyfile(image, os.path.join(output_dir, 'img', image_name)) ``` -------------------------------- ### Get Trace Segments (Simulated) Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca204/CW305_ECC_setup.ipynb Loads pre-recorded simulated traces from a .npz file. Requires the 'cwtraces' library to be installed. ```python def get_trace_segments(N=50, poi=[-6, 7, 4202, -4203], randomize_k=False, k=0, husky_timed_segments=True, step='partXXX', as_int=True): trace_segments = [] if TRACES == 'SIMULATED': # eh maybe not optimal but it works try: from cwtraces import sca204_lab_data load_traces = sca204_lab_data["get_traces"] except: print("Simulated traces require cwtraces (pip install cwtraces)") raise raws = load_traces('%s.npz' % step) for t in raws['arr_0']: trace_segments.append(Trace(t[0], t[1], t[2], None)) raws.close() print('Pre-recorded traces loaded.') return trace_segments ``` -------------------------------- ### Get Trigger Times Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/husky/06 - Husky SAD Triggering.ipynb Retrieves the trigger times from the scope, which correspond to the start of each bit processed by the point multiplication algorithm. ```python ttimes = scope.trigger.get_trigger_times() ``` -------------------------------- ### Create Shared Tutorial Output Directory Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/tests/docker/README.rst Create a directory on the host machine to share with the Docker container for storing tutorial output. Ensure it has read/write permissions. ```bash mkdir $HOME/tutorials && chmod 777 $HOME/tutorials ``` -------------------------------- ### Initialize ChipWhisperer Scope Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/husky/07 - Husky Sampling Phase.ipynb Initializes the ChipWhisperer scope and applies the default setup. This is a standard starting point for most ChipWhisperer experiments. ```python import chipwhisperer as cw scope = cw.scope() scope.default_setup() ``` -------------------------------- ### Jupyter Callback for Attack Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca101/Lab 4_3 - ChipWhisperer Analyzer CPA Attack (MAIN).ipynb Utilize the built-in ChipWhisperer Jupyter callback for a simplified attack setup. This is a convenient way to get real-time updates in a Jupyter environment. ```python import chipwhisperer as cw cb = cwa.get_jupyter_callback(attack) results = attack.run(cb, 10) ``` -------------------------------- ### Set Frequency and Get Clocks Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/husky/07 - Husky Sampling Phase.ipynb Sets the target frequency, ADC multiplier, and ADC phase, then retrieves the resulting clock values. Useful for initial setup and analysis. ```python set_freq(8e6, 2, +15) delta, adcclock, refclock = get_clocks() ``` -------------------------------- ### Set Positive ADC Offset Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca101/Lab 6_4 - Jittery Triggering on UART.ipynb Adjust the ADC offset to introduce a delay in the capture. This example sets the offset to 20000 cycles, effectively delaying the capture start. ```python # Delay capture of ADC data a certain number of cycles scope.adc.offset = 20000 ``` -------------------------------- ### Configure Target Parameters Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca101/Lab 3_1 - Large Hamming Weight Swings (MAIN).ipynb Sets up essential parameters for the target microcontroller and crypto module. These variables are used in subsequent setup scripts and compilation steps. ```python SCOPETYPE = 'OPENADC' PLATFORM = 'CW308_SAM4S' CRYPTO_TARGET = 'TINYAES128C' SS_VER = 'SS_VER_2_1' ``` -------------------------------- ### Configure Project Settings Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca201/SOLN_Lab 2_1 - CPA on 32bit AES.ipynb Sets up essential parameters for the ChipWhisperer project, including scope type, platform, and version. Ensure these match your hardware setup. ```python SCOPETYPE = 'OPENADC' PLATFORM = 'CWLITEARM' VERSION = 'HARDWARE' SS_VER = 'SS_VER_1_1' ``` -------------------------------- ### Configure Scope and Platform Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/husky/10 - Husky Hardware SWD Bitbanging.ipynb Set the scope and target platform for the demonstration. Ensure the correct platform is uncommented for your target. ```python SCOPE = 'OPENADC' PLATFORM = 'CW308_SAM4S' #PLATFORM = 'CW308_STM32F3' ``` -------------------------------- ### Build Simpleserial-Base Firmware Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca101/Lab 2_1A - Instruction Power Differences (MAIN).ipynb Navigates to the firmware directory and copies the simpleserial-base firmware. This prepares the firmware for compilation. ```bash cd ../../../firmware/mcu mkdir -p simpleserial-base-lab2 && cp -r simpleserial-base/* $_ cd simpleserial-base-lab2 ``` -------------------------------- ### Import and Install LASCAR Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca201/SOLN_Lab 2_2 - CPA on Hardware AES Implementation.ipynb Import the LASCAR library for advanced side-channel analysis. If LASCAR is not installed, this code will raise an ImportError with instructions on how to install it. ```python try: from lascar import * except Exception as e: raise ImportError("You need to install lascar at https://github.com/Ledger-Donjon/lascar") from e ``` -------------------------------- ### Initialize ChipWhisperer Project and Load Traces Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca201/Lab 1_1B - Resychronizing Traces with Dynamic Time Warp (SIMULATED).ipynb Imports necessary libraries and opens a ChipWhisperer project file. Ensure the project file path is correct. ```python import chipwhisperer as cw import numpy as np import time proj = cw.open_project("traces/Lab_Resync_WORSE.cwp") ``` -------------------------------- ### Install phoenixAES Package Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/fault201/Lab 1_3B - DFA Attack on AES.ipynb Installs the phoenixAES library required for AES operations. Run this in your Jupyter kernel environment. ```python import sys !{sys.executable} -m pip install phoenixAES ``` -------------------------------- ### Connecting and Interacting with LPC1114 via nxprog Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/faultapp1/LPC1114_Fuse_Bypass.ipynb Demonstrates how to instantiate the CWDevice, power cycle the target, enter ISP mode, and initialize the NXP Programmer. It then shows examples of reading the device's serial number and a memory block. ```python import time nxpdev = CWDevice(scope, target, print_debug=True) scope.io.target_pwr = False time.sleep(0.1) scope.io.target_pwr = True time.sleep(0.1) #Need to enter ISP mode before initializing programmer object nxpdev.isp_mode() nxpp = nxpprog.NXP_Programmer("lpc1114", nxpdev, 12000) #Examples of stuff you can do: print(nxpp.get_serial_number()) print(nxpp.read_block(0, 4)) ``` -------------------------------- ### Hardware Configuration Setup Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca101/Lab 2_1A - Instruction Power Differences (HARDWARE).ipynb Set the SCOPETYPE and PLATFORM variables to match your ChipWhisperer hardware setup. These are essential for subsequent operations. ```python SCOPETYPE = 'OPENADC' PLATFORM = 'CWLITEARM' ``` -------------------------------- ### Execute Firmware Build with Make Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca101/generators/Lab2_1B - GENERATOR.ipynb Navigate to the firmware directory and execute the make command to compile the firmware. This command takes the platform and crypto target as arguments. ```bash cd ../../../../firmware/mcu/basic-passwdcheck make PLATFORM=$1 CRYPTO_TARGET=$2 ``` -------------------------------- ### Define Target and Platform Parameters Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/experiments/Live Plotting Glitch.ipynb Sets up configuration variables for the target device and platform. These are used in subsequent commands. ```python SCOPETYPE = 'OPENADC' PLATFORM = 'CWLITEARM' CRYPTO_TARGET = 'NONE' sample_size = 5 ``` -------------------------------- ### Compile Assembly Startup File Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca101/generators/Lab2_1B - GENERATOR.ipynb Compiles the STM32F3 startup assembly file into an object file. ```bash arm-none-eabi-gcc -c -mcpu=cortex-m4 -I. -x assembler-with-cpp -mthumb -mfloat-abi=soft -fmessage-length=0 -ffunction-sections -DF_CPU=7372800 -Wa,-gstabs,-adhlns=objdir/stm32f3_startup.lst -I.././simpleserial/ -I.././hal -I.././hal/stm32f3 -I.././hal/stm32f3/CMSIS -I.././hal/stm32f3/CMSIS/core -I.././hal/stm32f3/CMSIS/device -I.././hal/stm32f4/Legacy -I.././crypto/ .././hal/stm32f3/stm32f3_startup.S -o objdir/stm32f3_startup.o ``` -------------------------------- ### Install PyJtagBS Library Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/husky/05 - Husky UserIO with JTAG Bit-Banging.ipynb Installs the PyJtagBS library from its GitHub repository using pip. This is a prerequisite for using JTAG bit-banging functionality. ```python !pip install git+https://github.com/colinoflynn/pyjtagbs.git ``` -------------------------------- ### Build and Initialize OpenOCD for Debugging Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/Debugging the CW308_STM32F3 Using ChipWhisperer.ipynb Build the firmware and then start OpenOCD in a non-interactive mode, preparing for a GDB connection. This command will run continuously until the notebook is restarted. ```bash cd ../../firmware/mcu/simpleserial-aes openocd -f ../../../../openocd/cw_openocd.cfg -c "transport select jtag" -c "ftdi vid_pid 0x2b3e $1" -f "target/stm32f3x.cfg" ``` -------------------------------- ### Get Rule Match Times Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca205/uecc_part3_trace_sad.ipynb Extracts timestamps for rule matches from raw trace data. Set rawtimes=False to get relative times. ```python times_p2 = trace.get_rule_match_times(raw, rawtimes=False, verbose=False) assert len(times_p2) == 256 ``` -------------------------------- ### Build SimpleSerial Firmware with Make Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/tests/Test CDC.ipynb Compiles the SimpleSerial firmware for a specified platform using the make utility. Ensure you are in the correct directory before running. ```bash cd ../../firmware/mcu/simpleserial-base make PLATFORM=$1 CRYPTO_TARGET=NONE SS_VER=SS_VER_2_1 ``` -------------------------------- ### Update ChipWhisperer Tutorials Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/ChipWhisperer Updating.ipynb This command updates the tutorials by backing up existing ones, pulling the latest changes, and then reapplying stashed changes. Local modifications to notebooks may be lost. ```bash %%bash mkdir -p jupyter-backup cp -rf courses demos experiments jupyter-backup git add . git stash git pull git checkout git stash pop ``` -------------------------------- ### Hardware Capture Function (Example) Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca101/Lab 2_1A - Instruction Power Differences (SIMULATED).ipynb This is an example of a capture function used in ChipWhisperer labs with hardware. It defines how to capture a trace using a scope and target, requiring firmware to be edited and uploaded. ```python def capture_trace(): ktp = cw.ktp.Basic() key, text = ktp.next() return cw.capture_trace(scope, target, text).wave ``` -------------------------------- ### Initialize Attack Parameters Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca204/CW305_ECC_part1.ipynb Sets the key 'k' for the attack and acquires traces with specific parameters. This is a prerequisite for executing the full attack. ```python k = 0x70a12c2db16845ed56ff68cfc21a472b3f04d7d6851bf6349f2d7d5b3452b38a #k = random_k() traces = get_traces(40, k, 'part1_5', full=False, samples_per_segment=530) ``` -------------------------------- ### Calculating and Printing SAD Metrics for a Specific Starting Sample Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca205/uecc_part2_notrace.ipynb Calculates and prints the maximum, average, and variance of SAD scores for a chosen starting sample point. Useful for comparing with pre-calculated best points. ```python starting_sample = 35 sads = calc_sads(avg_trace, rtraces, starting_sample) print('Max: %d (best max: %d)' % (np.max(sads), bestmax[0])) print('Avg: %d (best avg: %d)' % (np.average(sads), bestavg[0])) print('Var: %d (best var: %d)' % (np.var(sads), bestvar[0])) ``` -------------------------------- ### Printing Best SAD Starting Points Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca205/uecc_part2_notrace.ipynb Displays the calculated best starting sample points for SAD based on minimum maximum SAD score, minimum SAD variance, and minimum average SAD score. ```python print('Starting SAD point with the lowest maximum SAD score (%d): %d' % (bestmax[0], bestmax[1])) print('Starting SAD point with the lowest SAD variance (%d): %d' % (bestvar[0], bestvar[1])) print('Starting SAD point with the lowest average SAD score (%d): %d' % (bestavg[0], bestavg[1])) ``` -------------------------------- ### Initialize PhyWhisperer and Connect Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/experiments/phywhisperer-trigger.ipynb Initializes the PhyWhisperer USB connection and programs the FPGA. Sets the power source to host. ```python import phywhisperer.usb as pw phy = pw.Usb() phy.con(program_fpga=True) phy.set_power_source("host") ``` -------------------------------- ### Perform CPA Attack with Extended Trace Range Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/CW305_AES_pipelined.ipynb Executes a CPA attack on a significantly larger range of traces, demonstrating the increased number of traces required for successful analysis in a pipelined setup compared to a single-encryption setup. ```python results = do_cpa(project_split, cwa.leakage_models.pipeline_diff, trace_range=[0, 20000]) ``` -------------------------------- ### Setup Capture Options Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca101/SOLN_Lab 2_1B - Power Analysis for Password Bypass.ipynb Configure the scope type, platform, crypto target, and version for the power trace capture. These settings determine the hardware and simulation environment. ```python SCOPETYPE="OPENADC" PLATFORM='CWHUSKY' CRYPTO_TARGET='NONE' VERSION='HARDWARE' ``` -------------------------------- ### Example POI Data (Commented Out) Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca205/uecc_part1_trace.ipynb This commented-out code provides an example of what the 'pois' array might look like after calculation. Note that these values are specific to a previous run and may not be directly applicable to new trace data due to inherent jitter. ```python #pois = [[[-6, -108, -109, -110, -111, -128], [14, 15, -1, -28, -29, -38, -39, -48, -49, -59, -69, -79, -89]], [[77, 78, 257, -80, -103, -206, -215, -259], [-71, -72, -73, -74, -251, -252, -253]]] ``` -------------------------------- ### Display Target and Build Information Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca205/uecc_part3_trace_sad.ipynb Prints information about the connected PhyWhisperer, the firmware build time, and the FPGA build time. ```python # target info and buildtimes: print(trace.phywhisperer_name()) print(trace.get_fw_buildtime()) print(scope.fpga_buildtime) ``` -------------------------------- ### Redirect to Correct Setup Script Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/Helper_Scripts/Setup_Generic.ipynb This code raises an IOError to inform the user that the file has been moved and provides the new path. Update your code to use the new location. ```python raise IOError("This file was moved to Setup_Scripts/Setup_Generic.ipynb --> Please update your code") ``` -------------------------------- ### Start SAD Module Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/CW-Pro Using SAD (Analog Pattern) Trigger - Attacking AES.ipynb Initiates the SAD module for trigger detection. ```python scope.SAD.start() ``` -------------------------------- ### ChipWhisperer Tutorial Configuration Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/0 - Introduction to Jupyter Notebooks.ipynb Sets up essential configuration parameters for ChipWhisperer tutorials, including the scope type, target platform, and cryptographic target. These parameters are typically placed at the beginning of a tutorial script. ```python SCOPETYPE = 'OPENADC' PLATFORM = 'CWLITEARM' CRYPTO_TARGET = 'NONE' ``` -------------------------------- ### Retrieve and Print Trigger Times Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/husky/06 - Husky SAD Triggering.ipynb Get the timestamps of all triggers that occurred during the capture and print them. ```python ttimes = scope.trigger.get_trigger_times() print(ttimes) ``` -------------------------------- ### Import TraceWhispererExplorer Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/husky/13 - Husky TraceWhisperer Exploration.ipynb Imports the necessary TraceWhispererExplorer class from the chipwhisperer library. Ensure the library is installed. ```python from chipwhisperer.common.utils.tracewhisperer_explorer import TraceWhispererExplorer ``` -------------------------------- ### Set Scope and Platform Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/husky/11 - Husky Hardware 1-Wire Bitbanging.ipynb Defines the scope type and platform for the experiment. Ensure these match your hardware setup. ```python SCOPE = 'OPENADC' PLATFORM = 'CWHUSKY' ``` -------------------------------- ### Set 1-Wire Defaults and Print Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/husky/11 - Husky Hardware 1-Wire Bitbanging.ipynb Initializes default settings for the 1-wire bitbanger and prints the configuration. This is a preliminary step before defining specific pins. ```python scope.bitbanger.onewire.set_defaults() print(scope.bitbanger) ``` -------------------------------- ### Configure Scope and Platform Settings Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/H-Field Probe Demo 1 (with CPA).ipynb Sets up the scope type, platform, crypto target, number of traces, and correlation check flag. Adjust PLATFORM and CRYPTO_TARGET as needed for your specific hardware. ```python SCOPETYPE = 'OPENADC' PLATFORM = 'CWLITEXMEGA' CRYPTO_TARGET = 'TINYAES128C' num_traces = 50 CHECK_CORR = False ``` -------------------------------- ### Build Firmware for Target Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca101/Lab 2_1B - Power Analysis for Password Bypass (HARDWARE).ipynb Compile the firmware for the target device using make. Ensure you are in the correct directory and specify the PLATFORM and SS_VER variables. ```bash cd ../../../firmware/mcu/basic-passwdcheck make PLATFORM=$1 CRYPTO_TARGET=NONE SS_VER=$2 -j ``` -------------------------------- ### Setup Voltage Glitching Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/fault101/Fault 2_3 - Voltage Glitching to Memory Dump.ipynb Initializes the scope for voltage glitching. This function should be called before configuring glitch parameters. ```python scope.vglitch_setup('both') ``` -------------------------------- ### Initialize Target and Project for Half-Pipeline Version 2 Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/CW305_AES_pipelined.ipynb Initializes the target device and creates a ChipWhisperer project file for the half-pipeline AES implementation, specifically version 2. ```Python target.dis() target = program_target(half_pipe=2) ``` ```Python project_file = "projects/Tutorial_HW_CW305_AES_PIPELINED_HALF" + str(target.half_pipe) + ".cwp" project = cw.create_project(project_file, overwrite=True) ``` -------------------------------- ### Get FPGA Build Time Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/tests/husky_glitch_stress_test.ipynb Retrieves the build time of the FPGA firmware currently loaded on the scope. ```python scope.fpga_buildtime ``` -------------------------------- ### Initialize and Preprocess Traces with ResyncSAD Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca201/Lab 3_1B - Reverse Engineering on the AES256 Bootloader.ipynb Initializes the ResyncSAD module to preprocess traces, reducing jitter. Requires setting the 'ref_trace' and 'target_window' parameters appropriately. ```python import chipwhisperer as cw import chipwhisperer.analyzer as cwa leak_model = cwa.leakage_models.inverse_sbox_output resync = cwa.preprocessing.ResyncSAD(project) resync.enabled=True resync.ref_trace = 0 resync.target_window = (???, ???) resync.max_shift = 7000 new_proj = resync.preprocess() ``` -------------------------------- ### Get ChipWhisperer File Path Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca203/Using CWTVLA For Easy TVLA Testing.ipynb Retrieve the file path of the ChipWhisperer library, useful for debugging or configuration. ```python cw.__file__ ``` -------------------------------- ### Configure ChipWhisperer Target Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/fault201/Lab 2_1 - Fault Attack on RSA.ipynb Sets up the ChipWhisperer target platform and security settings. Ensure these match your hardware setup. ```python SCOPETYPE = 'OPENADC' PLATFORM = 'CW308_SAM4S' SS_VER='SS_VER_1_1' ``` -------------------------------- ### Configure Hardware Setup Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca101/Lab 3_3 - DPA on Firmware Implementation of AES (HARDWARE).ipynb Set the SCOPETYPE, PLATFORM, and CRYPTO_TARGET variables to match your hardware configuration. These settings are crucial for building the correct firmware and interacting with the target device. ```python SCOPETYPE = 'OPENADC' PLATFORM = 'CWLITEARM' CRYPTO_TARGET='TINYAES128C' SS_VER='SS_VER_1_1' ``` -------------------------------- ### Start GDB Session for Debugging Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/Debugging the CW308_STM32F3 Using ChipWhisperer.ipynb Initiate an interactive GDB session to debug the 'simpleserial-aes-CW308_STM32F3.elf' firmware. Connects to OpenOCD via localhost:3333, resets the target, halts, and loads the firmware. ```bash cd ../firmware/mcu/simpleserial-aes arm-none-eabi-gdb simpleserial-aes-CW308_STM32F3.elf -ex "target extended-remote localhost:3333" -ex "monitor reset halt" -ex "load" ``` -------------------------------- ### Configure ChipWhisperer Settings Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/fault101/Fault 1_3 - Clock Glitching to Memory Dump.ipynb Sets the scope type and platform for the ChipWhisperer environment. Ensure these match your hardware setup. ```python SCOPETYPE = 'OPENADC' PLATFORM = 'CWLITEARM' SS_VER="SS_VER_2_1" ``` -------------------------------- ### Configure Clock and ADC Settings Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/husky/03 - Husky Glitching.ipynb Sets up the clock generation source, frequency, and ADC mode. The ADC is configured for rising edge captures. ```python scope.clock.clkgen_src = 'system' scope.clock.clkgen_freq = 10e6 scope.clock.adc_mul = 1 scope.adc.basic_mode = "rising_edge" scope.trigger.triggers = "tio4" scope.io.hs2 = "clkgen" ``` -------------------------------- ### Check OpenOCD Version Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/Debugging the CW308_STM32F3 Using ChipWhisperer.ipynb Verify that the OpenOCD executable is installed and accessible on your system's PATH. This is a prerequisite for debugging. ```bash openocd --version ``` -------------------------------- ### Verify ChipWhisperer Imports Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/ChipWhisperer Setup Test.ipynb Run these imports to check if the ChipWhisperer Python modules are installed correctly. No exceptions should occur. ```python import chipwhisperer help(chipwhisperer) ``` -------------------------------- ### Initialize ChipWhisperer Project and Key/Text Generator Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca201/Lab 3_1A - AES256 Bootloader Attack.ipynb Creates a new ChipWhisperer project for storing traces and initializes a basic key/text generator. Overwrites existing projects if they exist. ```python project = cw.create_project("projects/Tutorial_A5", overwrite=True) ktp = cw.ktp.Basic() ``` -------------------------------- ### Setup and Data Loading for Husky Glitching Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/husky/03 - Husky Glitching.ipynb This code block sets up the environment by importing necessary libraries, defining a helper function to find transitions in data, and loading glitching data from a file. It's intended for use when a Husky scope is not already initialized. ```python try: type(scope) == 'chipwhisperer.capture.scopes.OpenADC.OpenADC' except: from bokeh.plotting import figure, show from bokeh.resources import INLINE from bokeh.io import output_notebook import numpy as np output_notebook(INLINE) def find_transitions(data, pattern): return [i for i in range(0,len(data)) if list(data[i:i+len(pattern)])==pattern] alls = np.load('../data/husky_glitch_data.npz') [glitchouts, sources, mmcm1outs, mmcm2outs, glitchgo, glitchenables] = alls['array'] STEPS = len(glitchouts) ``` -------------------------------- ### Setup Clock Frequency Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/tests/husky_glitch_stress_test.ipynb Configures the system clock to a specific frequency. This is often a prerequisite for testing specific glitch parameters. ```python setup_clock(100e6) ``` -------------------------------- ### Import Bokeh for Plotting Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca204/CW305_ECC_part1.ipynb Imports necessary components from the Bokeh library for interactive plotting. This setup is required before generating any visualizations. ```python from bokeh.plotting import figure, show from bokeh.resources import INLINE from bokeh.io import output_notebook output_notebook(INLINE) ``` -------------------------------- ### Create and Copy Firmware Directory Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca101/Lab 2_1A - Instruction Power Differences (HARDWARE).ipynb This bash command creates a new directory for the simpleserial-base code and copies the necessary files into it. Navigate into the new directory for further operations. ```bash %%bash cd ../../../firmware/mcu mkdir -p simpleserial-base-lab2 && cp -r simpleserial-base/* $_ cd simpleserial-base-lab2 ``` -------------------------------- ### Compile Firmware with Make Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/tests/Test Pro.ipynb Compiles the simpleserial-aes firmware using make, passing platform and crypto target as arguments. ```bash cd ../../firmware/mcu/simpleserial-aes make PLATFORM=$1 CRYPTO_TARGET=$2 SS_VER=$3 ``` -------------------------------- ### Uninstall PyJtagBS Library Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/husky/05 - Husky UserIO with JTAG Bit-Banging.ipynb Uninstalls the PyJtagBS library. This might be used to ensure a clean installation or to revert to a different version. ```python !pip uninstall pyjtagbs ``` -------------------------------- ### Configure Trace Platform and Target Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/courses/sca205/uecc_part1_trace.ipynb Set the trace platform, target board, and trace interface for the capture. These settings are crucial for initializing the correct hardware and communication protocols. ```python #TRACE_PLATFORM = 'CW610' # AKA PhyWhisperer TRACE_PLATFORM = 'Husky' PLATFORM = 'CW308_STM32F3' TRACE_INTERFACE = 'swo' SCOPETYPE = 'OPENADC' # other supported options: #PLATFORM = 'CWLITEARM' # not supported by this notebook, but can be made to work: #PLATFORM = 'CW308_K82F' #TRACE_INTERFACE = 'parallel' #TRACE_PLATFORM = 'CW305' ``` -------------------------------- ### Check GDB Version Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/Debugging the CW308_STM32F3 Using ChipWhisperer.ipynb Verify that the ARM GDB executable is installed and accessible on your system's PATH. This is a prerequisite for debugging. ```bash arm-none-eabi-gdb --version ``` -------------------------------- ### Initialize CPA Attack Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/CW-Pro Using SAD (Analog Pattern) Trigger - Attacking AES.ipynb Sets up the CPA attack with the sbox_output leakage model using the captured traces. ```python import chipwhisperer.analyzer as cwa leak_model = cwa.leakage_models.sbox_output attack = cwa.cpa(project, leak_model) ``` -------------------------------- ### Build Firmware using Make Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/1 - Connecting to Hardware.ipynb Builds firmware for ChipWhisperer targets using the 'make' command. Ensure the correct compiler is installed and specify your target PLATFORM. This command changes the directory to the firmware base. ```bash %%bash cd ../firmware/mcu/simpleserial-base/ make PLATFORM= CRYPTO_TARGET=NONE ``` -------------------------------- ### Capture and Get Clock Signals Source: https://github.com/newaetech/chipwhisperer-jupyter/blob/main/demos/husky/07 - Husky Sampling Phase.ipynb Calls the `get_clocks` function to capture and retrieve the ADC clock and reference clock signals. ```python delta, adcclock, refclock = get_clocks() ```