cd ~

April 20, 2026

Key Management on the STM32 Flight Controller

Research

Problem Statement

In 1986, Reagan warned us about the nine most terrifying words in the English language: "I'm from the government and I'm here to help." Forty years later, embedded systems engineers have found a worthy competitor: "All drones in the swarm share the same key."

In a simple key management system for a swarm of drones, there is a single static key stored permanently in each drone, used as the main source for signing and verifying signatures of messages sent and received. This system has significant limitations: if an attacker discloses the secret key on a single drone, they gain full access to the entire system and the whole swarm becomes vulnerable.

This is why we need to use the special mechanisms that STM32 offers, combined with a different approach to per-drone key isolation, to ensure that even in the case of one malicious or compromised drone, the rest of the system is not exposed.

Ronald Reagan Image

STM32 F7 Security Features

The following security features are available on the STM32 F7 series, documented in ST's application note AN5156, Introduction to Security for STM32 MCUs (STMicroelectronics, 2021).

STM32 Series Security Features table from AN5156
STM32 F7 series highlighted; security features available per MCU family (source: AN5156)

Resources

96-bit Unique ID: generated in factory during production, based on wafer number and X/Y coordinates on wafer, guaranteeing each device has a unique ID.

Static Protection

WRP: Flash part is protected from unwanted write or erase (by sectors).
PCROP: Flash part is protected in execute-only access mode, no read or write access (by sector).
RDP: Allows locking any flash access if the debugging link is open, or removing debugging access (backup SRAM).

Dynamic Protection

MPU: Memory protection unit allows memory isolation; this is a Cortex core feature.
Tamper: Allows detection of tamper events.

Crypto HW Resources

TRNG: True random number generator.
CRYPT / AES: Symmetric encryption/decryption accelerator.
HASH: Hash computation accelerator.
CryptoLib: API implementation of symmetric/asymmetric cryptography.

Threat Model

Assumed attacker capabilities:

• Physical capture of a drone and attempt to extract key material from hardware.
• Debug interface connection to read flash or SRAM contents.
• MAVLink parser exploitation to achieve code execution on the flight controller.
• Interception and replay of MAVLink messages over the radio link.

Goal: A system in which no single drone compromise cascades into swarm-wide failure.

Proposed Key Architecture

Each STM32 flight controller stores two key values:

device_key

Derived as HMAC-SHA256(key=master_secret, data=drone_UID) and written to RDP Level 2 flash at factory provisioning. The master_secret never leaves the ground station; the STM32 has no knowledge of it and only ever receives the already-derived device_key.

Compromise of one drone's device_key reveals nothing about others: derivation is one-way and UID-specific. device_key is used exclusively for initial session key provisioning and recovery, never for continuous authentication. It is a permanent key.

session_key

Stored in TAMP-protected backup SRAM. It is per-drone: no global session key exists across the swarm, each drone has its own. It is rotated regularly (temporal key) and automatically wiped on physical enclosure breach via the TAMP feature.

Initial Session Key Configuration

The initial provisioning flow establishes session_key_0 on a drone using its device_key and a one-time nonce.

1. GS derives session_key_0: device_key = HMAC-SHA256(master_secret, UID), then session_key_0 = HMAC-SHA256(key=device_key, data=nonce).

2. GS sends encrypted payload to drone: Encrypt(device_key, session_key_0) with nonce sent in plaintext.

3. Drone decrypts and stores: decrypts using device_key from RDP Level 2 flash. session_key_0 is stored in TAMP backup SRAM.

4. Drone sends ACK signed with session_key_0: ACK(sig=HMAC-SHA256(session_key_0, ack_payload)).

5. GS verifies ACK: GS verifies HMAC using its own session_key_0 copy and confirms storage.

Initial session key configuration flow diagram between Ground Station and Drone
Fig. 1: Initial session key configuration, 5-step flow between GS and Drone

Key Rotation

Session keys are rotated regularly. The derivation routine is placed in a PCROP-protected flash sector, execute-only and unreadable even by the firmware itself. This matters because the derivation incorporates additional secret values alongside the publicly transmitted nonce R. An attacker who intercepts R sees the public input but has no visibility into what happens inside the sector.

1. GS generates nonce R and sends a signed message: MAVLink(R, sig=HMAC-SHA256(session_key_n, R)).

2. Drone verifies signature: HMAC-SHA256(session_key_current, R) is checked; message is rejected if invalid.

3. Drone derives new key locally in PCROP sector: session_key_n+1 = HMAC-SHA256(key=session_key_n, data=R).

4. Drone sends ACK signed with new session key: ACK(sig=HMAC-SHA256(session_key_n+1, ack_payload)).

5. GCS verifies ACK before switching: GCS derives the same session_key_n+1, verifies the ACK, and only then discards the old key.

The rotation protocol provides forward secrecy: compromise of any session key reveals nothing about past keys since each key is derived using a one-way function from the previous one. No key material is ever transmitted. Per-drone key isolation ensures all drones receive the same nonce R but derive completely different keys since each chain starts from a unique device_key. The ACK-before-switch rule keeps the ground station and drone always synchronized.

Accepted limitation: forward secrecy protects past keys but not future ones. If the current session key is compromised and the attacker intercepts the next nonce R, the next session key can be derived. This is mitigated by frequent rotation, the majority vote liveness system which triggers revocation before extended exposure occurs, and the key derivation algorithm placed in a PCROP-protected sector, allowing additional static private secrets to be incorporated beyond just the previous key and R, making the next key non-trivially guessable even under partial compromise.

Key rotation flow diagram between Ground Station and Drone
Fig. 2: Key rotation, 5-step forward-secret rotation protocol between GS and Drone

Compromises and Limitations

Each design choice carries an accepted trade-off.

RDP Level 2

RDP Level 2 was chosen for device_key storage for two reasons: it permanently disables the debug interface with no software bypass path, and device_key never rotates.

Accepted limitation: does not resist a well-resourced physical attacker with fault injection or decapping equipment. Accepted because the threat model excludes nation-state adversaries, per-drone key isolation ensures a single chip compromise exposes only that drone, and session_key after initialization does not rely on device_key, meaning its exposure does not disclose active session material. device_key is retained solely for initialization, re-commissioning, and revocation flows.

TAMP Protected Backup SRAM

TAMP-protected backup SRAM was chosen for session_key over RDP Level 1 flash for three reasons: RDP Level 1 does not destroy the key on physical breach (it remains readable in flash); RDP Level 1 can be downgraded to Level 0 via option byte modification, creating a bypass path; and flash write cycles are limited (unsuitable for a frequently rotated key) while TAMP backup SRAM has no such constraint.

Accepted limitation: TAMP provides no protection against software code execution attacks.

MPU

The MPU blocks unprivileged code execution from reaching session_key in backup SRAM and is already available as a Cortex-M core feature requiring no additional hardware.

Accepted limitation: privileged code execution can reconfigure or disable the MPU entirely. This is the fundamental constraint of operating without a hardware TEE boundary.

Replay protection is already built into the MAVLink v2 signature specification and was implemented as part of the HMAC-SHA256 signing work. The only missing addition is persisting the counter to flash so it survives reboots.

Accepted limitation: frequent writes introduce flash wear. Can be mitigated by writing periodically rather than per message and restoring with a safety margin on reboot.

Conclusion

Other than the proposed initial session key generation and rotation, additional mechanisms such as liveness and revocation should be considered, which require separate handling. Since we are dealing with a swarm system, drones periodically report peer connectivity and behavioral consistency to the ground station. Any revocation decision requires majority vote across the swarm rather than a single drone report.

For suspected drones, soft revocation excludes them from the next key rotation until the situation is cleared. In more extreme cases where a drone is confirmed malicious or physically compromised, it is permanently excluded.