MimiBoot-Mu source on GitHub

Security

From docs/SECURITY.md in the repository.

What MimiBoot-Mu protects, against whom, how, and where it stops. Read this before you rely on it in a product. Everything below says which chips it holds for; status says what has actually run.

Who it defends against

Attacker Can MimiBoot-Mu’s answer
Code running in the app (a bug in your firmware, exploited) Write the slots, the boot log and the config; call the flash controller directly Signed images only, hash every boot; rollback floors kept in flash the app can’t write; the bootloader region locked before the app starts (nRF)
Someone on the console UART Type commands, upload images Console lock: changes need a signed challenge (CONSOLE_AUTH)
Someone with a debug probe Read and write everything, halt the CPU Not the bootloader’s job alone: lock the debug port (DEBUG_LOCK on nRF, mbtool provision for the persistent steps)
Someone with a glitcher (voltage, clock, EM) Skip an instruction or two Not defended yet (see “Known gaps”)

Out of scope: secrets in the app (MimiBoot holds none), side channels on the signing machine, a compromised build machine or signing key.

Who decides what runs

The code execution authority is whoever holds a private key whose public half is in the build’s KEYS file.

To check whether a given image may run on a board:

python tools/mbtool.py info app.mimg --pub keys/mimiboot.pub

It prints the signature check, the security version and the target. Compare the security version with the board’s floor (log on the console, or mb_client_status() in the app).

What is checked before an image starts

  1. The header: magic, version, CRC, sizes inside the slot.
  2. Built for this chip (target), startable here (architecture, load type).
  3. A/B images: security_version not below the rollback floor. Golden: not older than the golden version already accepted.
  4. The signature (every boot when signatures are required).
  5. The SHA-256 of the whole payload (BOOT_VERIFY=every-boot; once and never trade this for speed and are refused together with required signatures).

A failure marks the slot bad with the reason and the next candidate is tried (the other A/B slot, then golden).

Post-quantum signatures (LMS)

With LMS on, images can be signed with LMS (RFC 8554, NIST SP 800-208), a hash-based scheme: forging a signature means breaking SHA-256, which a quantum computer doesn’t do. CNSA 2.0 names LMS for firmware signing, and it is on the EU’s agreed-mechanisms list.

python tools/mbtool.py keygen --type lms --out keys/pq      # H10 / W4: 1024 signatures
python tools/mbtool.py pack app.elf -o app.mimg --key keys/pq.key ...

Put keys/pq.pub in the KEYS file. With SIGNATURES off and LMS on, the bootloader holds no Ed25519 code at all, and nothing a quantum computer could forge gets an image started. If Ed25519 or P-256 keys stay in KEYS next to the LMS ones, an image signed with either kind boots, so a quantum attacker would simply forge the classical one; the configurator warns about that mix.

What is kept, and where:

LMS keys are stateful. Each signature uses up one of the key’s one-time keys, and signing two different images with the same one gives the key away. mbtool keeps the next unused leaf in the key file and writes it to disk (synced) before a signature leaves; a crash between the two wastes a leaf and never reuses one. What it can’t stop:

Keep one key file in one place, and back up the public key and a record of what was signed, not the private file. A key signs 2^H images (1024 with the default H10), then mbtool refuses; make the next key before that and ship it in a bootloader update, or keep a second LMS key in KEYS from the start.

What stays classical: console unlock (CONSOLE_AUTH), signed configs (CFG_SIGNED) and revocation statements (REVOKE_KEYS) use Ed25519, so they need SIGNATURES on. An LMS key can be revoked like any other (by its key id).

Single-level LMS only, no HSS trees of trees. One-level HSS public keys and signatures from other tools (hash-sigs, pyhsslms) are read by mbtool.

Rollback floors

An image’s security_version (mbtool pack --secver N) is a promise: once a version-N image is confirmed, nothing below N boots again. The floor and the newest golden version live in two places:

The floor that counts is the higher of the two. boot <slot> force on the console doesn’t get past it, and neither does ramboot when signatures are required.

The store takes the last two erase units of the bootloader region when they are small (8 KB or less: nRF, SAM D, STM32 F0/F1/F3/G0/G4/L4). When one unit fills up, its contents are compacted into the other:

The new unit’s first entry, a generation number, is written last. It is the commit, and only after it is the old unit erased. A power cut anywhere leaves either the old unit or the complete new one in force (the host tests cut power at every step).

Parts with big sectors (STM32 F2/F4/F7) keep one append-only unit of 16 KB or more: over a thousand entries. When that is full, the floors stay where they are and the log copy carries on.

Revoking a signing key

Keys are compiled in, so that nothing in flash can add one. The other side of that: a key that leaks would stay trusted until every board got a new bootloader. With REVOKE_KEYS a board can drop one of its keys in the field:

Encrypted images

With ENCRYPTED_IMAGES an update file can be kept private on its way to the board. The scheme is MCUboot’s, so imgtool and MimiBoot agree on it:

mbtool keygen --type x25519 makes a board key: board.key goes into the build as ENC_KEY, and mbtool pack --encrypt board.pub encrypts for it.

MimiBoot decrypts while the image comes in, over the console (mbtool install) or SMP:

What this protects: update files, the link they travel over, and anywhere the files sit before they reach the board.

What it doesn’t protect:

Limits:

On the device, AES is BearSSL’s constant-time bitsliced code (MIT, adapted to encryption only). X25519 is a Montgomery ladder on the same field arithmetic as Ed25519: branch-free, a fixed 255 steps, conditional swaps by mask. An all-zero shared secret (a low-order point) is refused. The tag is compared in constant time.

Being branch-free isn’t the same as taking constant time. It also depends on the multiply instructions:

So on a Cortex-M3 the configurator requires CONSOLE_AUTH with encrypted images: only someone who has unlocked the console can send envelopes to time.

Measured boot (boot record)

With BOOT_RECORD, an image that asks for it (an MB_BOOT_RECORD_BUFFER in its RAM, see include/mimiboot/mb_record.h; mbtool puts its address in the header) gets a record of what held on this boot. MimiBoot writes it after every check has passed, right before the jump. It says:

A server that knows which bootloader and image a board should run can recompute the measurement and compare. The QEMU test does exactly that.

It’s a report, not attestation. Nothing in it is signed by the device, and the image can change the record after it starts, so it is as trustworthy as the image passing it on. Proper attestation needs a device secret the app can’t read (DICE-style), which these chips don’t give MimiBoot in a form it can hide.

Updating the bootloader itself (two-stage)

A one-stage MimiBoot can’t replace itself: a bug in it is fixed with a debug probe. With TWO_STAGE it is split in two:

A new stage 1 goes into the copy that isn’t running (mbtool loader <build dir>, which asks the board which one runs). On the next boot, stage 0 starts a copy only if all of this holds:

Then, between two usable copies: one that hasn’t failed, then the higher version, then one known to work. A copy is known to work once it has got as far as starting an image (it writes that into the store just before the launch). A copy that hasn’t yet is on trial: every boot of it is recorded before it runs, and after 3 boots without getting that far it is passed over and the other copy starts. Once a copy with security version N has worked, no copy below N starts again.

Stage 0 is built so its own records can’t brick the board:

What it doesn’t do:

Two-stage builds need about 100 KB for stage 0 and the two copies, so parts with 192 KB of flash or more. On STM32 F4/F7, whose sectors grow to 128 or 256 KB, every region takes whole sectors: there it fits A/B but not A/B plus golden.

Protection per chip

Chip Bootloader region vs the app Debug port Persistent steps (mbtool provision)
nRF51 BOOT_LOCK: MPU PROTENSET until reset UICR readback protection nrfjprog --rbp ALL
nRF52805/810/811/832 BOOT_LOCK: BPROT until reset, also in debug mode DEBUG_LOCK (newer silicon), UICR.APPROTECT nrfjprog --rbp ALL
nRF52820/833/840 BOOT_LOCK: an ACL region until reset as above as above
STM32 option bytes: WRP on the bootloader’s sectors RDP level 1 (reversible), level 2 (forever) prints the CubeProgrammer commands
SAM D21/D51 BOOTPROT fuse Security Bit prints the OpenOCD commands; refuses when BOOTPROT can’t cover the region exactly
AVR (Lite) lock bits BLB1 (SPM can’t write the boot section) lock bits LB prints the avrdude command
RP2040 nothing on the chip can do it can’t be disabled none
RP2350 secure boot needs OTP (irreversible): not automated OTP see the RP2350 datasheet

Notes:

The console

The console is powerful by design: it uploads images, edits the config and marks images good or bad. On a product:

unlock prints a 32-byte challenge; mbtool signs "MimiBoot console unlock v1\0" || target || challenge with the key given by --unlock-key (or MB_UNLOCK_KEY) and sends the signature back. The keys come from UNLOCK_KEYS (one per line, mbtool keygen), or the image keys if that is empty; a separate key is better, so the image signing key never has to be on the bench. The domain prefix means an unlock signature can never be mistaken for an image signature, or the other way round. Each wrong answer costs a growing delay; after five the console stays locked until a reset.

mcumgr (SMP)

With SMP on, the same UART also speaks the Simple Management Protocol, so Zephyr’s tools (mcumgr, smpmgr, smpclient) can list, upload, test, confirm and erase images. It is the console by another route, and held to the same rules:

The challenge comes from the hardware RNG on nRF. Other chips don’t have one wired up yet: there it is a hash of the boot count, a session counter and the clock, which is unique but predictable to someone who can also reset the boot log. Treat CONSOLE_AUTH on those chips as a guard against casual access, not against an attacker who already controls the flash.

The running system (OS hooks)

The image that runs can ask the bootloader for things (os-integration.html), through the boot log in flash or a mailbox in RAM. Neither is a privilege: any code running on the chip can write both. What they can ask for is limited to what the boot log’s requests already allowed (the menu, an entry or slot once, flash mode, the ROM loader, a preferred A/B image), each request is checked by the same code whichever way it came, and an image asked for still has to pass its signature, hash and rollback floor. A mailbox counts only when it carries the id of the image in whose buffer it lies and a good CRC, and it is used once. A rollback through mb_client_set_active only reaches a confirmed image at or above the floor.

Faults

A HardFault or NMI in the bootloader (a flash ECC error, a bus error reading a damaged slot, a bug) resets the chip instead of hanging. If the fault happened while an image was being checked, a note in RAM that survives the reset names the slot, and the next boot marks it bad (CPU fault while checking) and falls back.

Cryptography

Mechanism Used for
Ed25519 (RFC 8032) image signatures, console unlock, signed config
ECDSA P-256 (FIPS 186, ECDSA) image signatures: MimiBoot images and imgtool ecdsa-p256 Zephyr images
LMS (RFC 8554, SP 800-208, LMS) image signatures, post-quantum: SHA-256 and SHA-256/192, H5 to H25, W1 to W8
SHA-256 payload hashes, the digest ECDSA signs, LMS; Ed25519 uses SHA-512 internally
X25519 (RFC 7748), HKDF / HMAC-SHA256 (RFC 5869 / 4231), AES-128/256-CTR (FIPS 197, SP 800-38A) encrypted images (ENCRYPTED_IMAGES): MCUboot’s ECIES-X25519 envelope
CRC-32 corruption checks only (headers, log, config, upload frames, the Lite core): not a security mechanism

Ed25519 isn’t on the EU’s ECCG agreed-mechanisms list (ECDSA P-256 and LMS are); ETSI TS 119 312 recommends it. The verifier is tested against RFC 8032’s vectors and all 210 of Project Wycheproof’s: every valid signature verifies, every invalid one (malleable S, non-canonical encodings, truncated or padded signatures, wrong keys) is refused. Of the 29 cases Wycheproof leaves to the implementation (small-order and mixed-order public keys), all are accepted: the check is cofactorless. That matters only when an attacker picks the public key, and here the keys are compiled in.

ECDSA P-256 is on the ECCG list. The arithmetic is micro-ecc v1.2 (BSD 2-clause, third_party/micro-ecc, unmodified, portable C). Against Wycheproof’s 262 P-256 vectors every invalid signature is refused and every valid one accepted except two: signatures built so that micro-ecc’s combined multiplication passes through the point at infinity (tcId 60) or an extreme intermediate value (tcId 210). Those are false rejects, never false accepts, and an honest signer hits them with probability about 2^-256; the test pins them so any change shows. mbtool’s own P-256 signer (tools/mb_p256.py, RFC 6979 deterministic nonces) gets all 262 right and matches RFC 6979’s published test vector.

The LMS verifier is checked against RFC 8554’s test cases (each level of the two-level examples on its own) and NIST’s ACVP-Server LMS vectors (sigVer, including the ones that must fail, and sigGen), and against signatures from pyhsslms, an independent implementation, for the parameter sets the published vectors don’t cover. Every vector that verifies is then broken in eight ways (a flipped bit in the leaf index, the type codes, the randomizer, a chain value and the path; a changed message; a wrong length; a read error; a leaf index past the tree; another key) and each is refused. mbtool’s signer (tools/mb_lms.py) derives keys as RFC 8554 Appendix A says, matches the RFC’s and ACVP’s key-generation vectors, and its signatures verify in pyhsslms.

The encryption primitives are checked against their published vectors:

Each vector was also run through pyca/cryptography before it went into the tests. Envelopes made by imgtool (AES-128 and AES-256) and by mbtool open on the device code, and every flipped envelope byte is refused. mbtool’s own implementation (tools/mb_enc.py, plain Python) is checked against pyca/cryptography and imgtool.

The AVR Lite core does no cryptography at all.

Glitches (fault injection)

With FAULT_HARDENING (on by default):

So skipping one check is no longer enough: the glitch has to land twice, at two places in the code. That raises the bar; it isn’t glitch-proof. Real resistance needs the chip’s own countermeasures (and a random delay, which needs a hardware RNG: not yet).

Known gaps

Reporting a problem

Open an issue on the repository. For something you’d rather not post in public, say so in a short issue without the details and ask for a private channel.