This repository contains the firmware implementation of a Hardware Security Module (HSM) designed for the MITRE 2026 eCTF competition by team PESU2 (Fl@gN0tF0uND).
The system provides authenticated file storage, encrypted inter-device transfer, and hierarchical group-based access control. The architecture combines layered cryptography, strict memory protections, watchdog enforcement, and fault-resistance mechanisms to ensure confidentiality, integrity, and controlled execution under adversarial conditions.
A full design explanation is available in the accompanying design document.
- MCU: TI MSP-LITO-L2228
- Flash: 256 KB
- SRAM: 32 KB
- Architecture: ARM Cortex-M0+
- Hardware Peripherals Used:
- TRNG
- Timers
- UART (control + transfer interfaces)
- Independent Watchdog (IWDT)
- Windowed Watchdog (WWDT)
- AES accelerator (AESADV)
firmware/- Source code to build the firmwareMakefile- This makefile is invoked by the eCTF tools when creating an HSM.Dockerfile- Describes the build environment used by eCTF build tools.secrets_to_c_header.py- Python file to convert from global secrets to firmware-parsable header fileinc/- Directory with c header filessrc/- Directory with c source filesfirmware.ld- Defines memory layout of built firmware
ectf26_design/- Pip-installable module for generating secretssrc/- Secrets gen source codegen_secrets.py- Generates shared secrets
pyproject.toml- File that tells pip how to install this module
Makefile- Helper script to simplify repetitive build stepsPESU2 eCTF Design Document.pdf- Design document describing the architecture and implementation of the HSM firmware
The following dependencies are required to build the firmware and interact with the HSM on the host machine:
- Docker (for building firmware in a containerized environment)
- Python 3 (for generating secrets and converting them to header files)
- eCTF host tools (for flashing the firmware and interacting with the HSM)
These dependencies are installed in the Docker container used for building the firmware, as defined in the Dockerfile:
- TI MSPM0 SDK
- TI-Clang
- python-cryptography (for key derivation and encryption during provisioning)
- wolfSSL (for cryptographic primitives used in firmware)
- micro-ECC (for ECDH and ECDSA operations in firmware)
The Makefile consists of the following build options which can be configured.
- HAVE_AESADV_AESGCM: Enables use of the AES accelerator for file encryption and decryption.
- RANDOMIZE_STACK: Randomizes the stack pointer on reset to increase resilience against stack-based attacks.
- BENCHMARK_STACK_USAGE: Measures runtime stack usage using a watermark.
- BENCHMARK_MAX_JITTER: Forces jitter duration to the maximum value for testing timing overhead.
- ENABLE_IWDT: Enables the Independent Watchdog Timer for fault detection.
- ENABLE_WWDT: Enables the Windowed Watchdog Timer for additional fault detection.
- DEBUG_PRINT_STATUS: Enables debug prints for status updates (disabled by default for performance and security).
- DISABLE_SWD: Disables the Serial Wire Debug interface for increased security
The defaults are shown below:
CFLAGS += -DHAVE_AESADV_AESGCM
CFLAGS += -DRANDOMIZE_STACK
# CFLAGS += -DBENCHMARK_STACK_USAGE
# CFLAGS += -DBENCHMARK_MAX_JITTER
CFLAGS += -DENABLE_IWDT
CFLAGS += -DENABLE_WWDT
# CFLAGS += -DDEBUG_PRINT_STATUS
CFLAGS += -DDISABLE_SWDRun the following commands to build the firmware image. The first command generates the necessary secrets, and the subsequent commands build the firmware in a Docker container.
# Generate secrets, storing them in the file `global.secrets` and
# defining the valid groups as 1, 2, 3, 0x1111 (4369)
uv pip install -e ./ectf26_design
uv run secrets ./global.secrets 1 2 3 0x1111
# Build the docker container
docker build -t build-hsm ./firmware
# Build an HSM in a Docker container
docker run --rm -v ./firmware:/hsm -v ./global.secrets:/secrets/global.secrets:ro -v ./build:/out -e HSM_PIN='abc123' -e PERMISSIONS='1234=R--:4321=RWC' build-hsmMore detailed build instructions can be found here
The resulting firmware image will be located in the build/ directory.
To flash the firmware and interact with the HSM, use the eCTF host tools.
The Independent Watchdog Timer (IWDT) continues to run even in the bootloader and prevents flashing new firmware until the board is power cycled. Follow these steps to disable the IWDT:
- Reset to bootloader
- Send the erase command via uvx host tools within 3s (before the IWDT triggers a reset)
- Power cycle the board
The IWDT should now be disabled.
The HSM enforces authenticated file storage using layered encryption and signature verification. Each file is encrypted with a randomly generated File Encryption Key (FEK), which is wrapped under group-derived keys using ECDH and HKDF. Files are additionally protected with integrity authentication, and inter-device transfers use challenge–response authentication based on shared secrets. Group-based permissions govern read, write, and receive capabilities each enforced by the existence of the corresponding asymmetric keys.
All private key material embedded in firmware is encrypted under a PIN-derived key, and neither the PIN nor the PIN-derived key are stored in firmware.
The firmware incorporates multiple defensive layers:
- MPU-enforced memory protections (flash read-only, RAM non-executable, file region non-executable)
- Stack pointer randomization on reset to mitigate stack-based attacks
- Stack canaries to detect stack overflows
- Independent and windowed watchdog enforcement
- Fail-closed reset policy on integrity or state violations
- Hardened security checks and constant-time comparisons
- Secure key derivation and authenticated encryption
- Zeroization of sensitive material after use