MASTR is a security-focused project designed to establish a secure communication channel between a host system and a hardware token. It utilizes a three-phase protocol to ensure mutual attestation, secure channel establishment, and runtime integrity verification.
The MASTR protocol is divided into three distinct phases:
This initial, one-time pairing process establishes a trusted relationship between the host and the token.
- Key Generation: Both the host and the token generate a new, persistent ECDSA keypair.
- Public Key Exchange: The host and token exchange their public keys.
- Golden Hash: The host generates a "golden hash" of its boot file and shares it with the token. This hash represents the known-good state of the host's software.
This phase is performed on every boot to establish a secure session.
- Ephemeral Key Generation: The host and token each generate an ephemeral ECDH keypair.
- Signed Key Exchange: They exchange their ephemeral public keys, signing them with their persistent private keys from the pairing phase.
- Signature Verification: Each party verifies the signature on the received ephemeral public key using the other's stored persistent public key.
- Secure Secret Derivation: A shared secret is derived using the ECDH algorithm.
- Session Key Generation: A KDF (Key Derivation Function) is used to generate an AES-128 session key from the shared secret.
- Channel Verification: The channel is verified with an encrypted ping-pong exchange.
This phase ensures the host is running the correct software before allowing it to boot.
- Integrity Challenge: The token sends a random nonce to the host.
- Hash Calculation: The host calculates a hash of its current boot file.
- Signed Response: The host signs the hash and the nonce with its persistent private key and sends the signature and hash to the token.
- Verification: The token verifies the signature and compares the received hash with the stored "golden hash".
- Boot Signal: If the verification is successful, the token sends a
T2H_BOOT_OKsignal to the host; otherwise, it sendsT2H_INTEGRITY_FAIL_HALT.
After a successful boot, the host sends periodic heartbeat messages to the token to maintain the session.
The system will shut down under the following conditions:
- A protocol phase is not completed within 30 seconds.
- Either the host or token sends a "no-go" signal.
- The
T2H_BOOT_OKsignal is not received within 2 minutes of starting the attestation process. - The heartbeat timeout occurs more than 3 times.
- Raspberry Pi Pico SDK
- CMake (version 3.13 or later)
- ARM GCC Compiler
-
Create a build directory:
mkdir build cd build -
Configure for your board:
-
For Raspberry Pi Pico (RP2040):
cmake .. -DPICO_BOARD=pico
-
For Raspberry Pi Pico W (RP2040 with WiFi):
cmake .. -DPICO_BOARD=picow
-
For a generic RP2350 board:
cmake .. -DPICO_PLATFORM=rp2350
-
-
Build the project:
make
- Connect your Pico board to your computer while holding the
BOOTSELbutton. - Drag and drop the
mastr.uf2file from thebuilddirectory onto theRPI-RP2mass storage device.
The project uses the Unity test framework. The tests are located in the test directory.
- Navigate to the build directory:
cd build - Build the test runner:
make test_runner - Run the tests:
ctest
.png)

