|
| 1 | +# Post-quantum on both clusters of the NXP i.MX95 |
| 2 | + |
| 3 | +A two-pane demo on a single screen, running entirely on a Toradex SMARC iMX95: |
| 4 | + |
| 5 | +| pane | what it shows | |
| 6 | +|---|---| |
| 7 | +| **left** | wolfCrypt ML-KEM / ML-DSA benchmarks in a container on the six Cortex-A55 cores, under Torizon OS | |
| 8 | +| **right** | wolfBoot performing **ML-DSA-87 verified boot** of the Cortex-M7, with its console relayed to Linux | |
| 9 | + |
| 10 | +The point of the pairing: the same post-quantum algorithms, at the same security |
| 11 | +level, on two very different cores of one SoC - a Linux application cluster and |
| 12 | +a bare-metal real-time core. |
| 13 | + |
| 14 | +## Measured on hardware |
| 15 | + |
| 16 | +Cortex-M7 at 800 MHz, DWT cycle counter, caches enabled: |
| 17 | + |
| 18 | +| | wolfBoot text | verify + boot | at 800 MHz | |
| 19 | +|---|---|---|---| |
| 20 | +| ECDSA P-256 | 22,548 B | 1,741,288 cycles | 2.177 ms | |
| 21 | +| **ML-DSA-87** | **21,608 B** | **4,201,179 cycles** | **5.251 ms** | |
| 22 | +| ML-DSA-87, Zephyr payload | 21,608 B | 5,916,540 cycles | 7.396 ms | |
| 23 | + |
| 24 | +Two results worth calling out. **Post-quantum verified boot costs 5.25 ms** - |
| 25 | +2.4x the cycles of ECDSA P-256 and irrelevant against any real boot time. And |
| 26 | +the **ML-DSA-87 bootloader is 940 bytes smaller than the ECDSA one**: ML-DSA |
| 27 | +verification is SHAKE plus polynomial arithmetic and never pulls in the |
| 28 | +big-integer math P-256 needs, so for a verify-only workload post-quantum can |
| 29 | +cost *less* flash. |
| 30 | + |
| 31 | +Verification also scales far better than payload size suggests - 1,004 B to |
| 32 | +54,080 B is **54x the payload for 1.41x the verify**, because the lattice |
| 33 | +signature check is a fixed cost and only the hash grows. |
| 34 | + |
| 35 | +> The M7's I- and D-caches are **disabled out of reset**. Any i.MX95 M7 |
| 36 | +> benchmark taken without enabling them is wrong by one to two orders of |
| 37 | +> magnitude - we measured SHA-256 at 1.1 MiB/s before enabling them and |
| 38 | +> 29.2 MiB/s after. |
| 39 | +
|
| 40 | +## Layout |
| 41 | + |
| 42 | +``` |
| 43 | +container/ wolfCrypt PQC benchmark container for the A55 cluster (left pane) |
| 44 | +m7/ Zephyr RPMsg payload wolfBoot verifies and boots (right pane) |
| 45 | +demo/ board-side orchestration and the two-pane renderer |
| 46 | +gallery/ Torizon Demo Gallery submission: compose file and partner metadata |
| 47 | +tools/ memtool - mmap-based /dev/mem access for the M7 console |
| 48 | +charts/ the measured figures, as images |
| 49 | +``` |
| 50 | + |
| 51 | +## Requirements |
| 52 | + |
| 53 | +- Toradex SMARC iMX95 (or another i.MX95 board) running Torizon OS |
| 54 | +- wolfBoot with the `imx95_m7` target |
| 55 | +- A Zephyr workspace (4.4.0 or newer) and an `arm-none-eabi` toolchain |
| 56 | +- Docker on the board (Torizon ships it) |
| 57 | + |
| 58 | +## Building |
| 59 | + |
| 60 | +**1. wolfBoot for the M7**, signing with ML-DSA-87: |
| 61 | + |
| 62 | +```sh |
| 63 | +cp config/examples/imx95-m7.config .config |
| 64 | +make SIGN=ML_DSA ML_DSA_LEVEL=5 IMAGE_SIGNATURE_SIZE=4627 DEBUG_UART=1 |
| 65 | +``` |
| 66 | + |
| 67 | +`DEBUG_UART=1` is what makes wolfBoot write its verification log to the |
| 68 | +shared-memory console the right pane reads. |
| 69 | + |
| 70 | +**2. The Zephyr payload:** |
| 71 | + |
| 72 | +```sh |
| 73 | +cd m7 && ZEPHYR_BASE=~/zephyrproject/zephyr ./build.sh |
| 74 | +``` |
| 75 | + |
| 76 | +Then sign it with the same key wolfBoot was built with: |
| 77 | + |
| 78 | +```sh |
| 79 | +IMAGE_HEADER_SIZE=12288 ML_DSA_LEVEL=5 ./tools/keytools/sign --ml_dsa --sha256 \ |
| 80 | + m7/build/zephyr/payload.bin wolfboot_signing_private_key.der 1 |
| 81 | +``` |
| 82 | + |
| 83 | +**3. The benchmark container:** |
| 84 | + |
| 85 | +```sh |
| 86 | +cd container && WOLFSSL_REPO=/path/to/wolfssl ./build-aarch64.sh all && ./build-image.sh |
| 87 | +``` |
| 88 | + |
| 89 | +## Running |
| 90 | + |
| 91 | +```sh |
| 92 | +BOARD=torizon@<board-ip> WOLFBOOT=/path/to/wolfboot ./demo/stage.sh |
| 93 | +``` |
| 94 | + |
| 95 | +then on the board: |
| 96 | + |
| 97 | +```sh |
| 98 | +sudo bash ~/demo/demo-run.sh /dev/tty1 # /dev/tty1 is the HDMI console |
| 99 | +``` |
| 100 | + |
| 101 | +Omit the argument to render on the current terminal instead. |
| 102 | + |
| 103 | +### Starting it automatically |
| 104 | + |
| 105 | +Because replaying the demo means power-cycling the board (see below), running it |
| 106 | +by hand also means logging back in afterwards, over a network link that does not |
| 107 | +always come up. Installing the unit makes cutting and restoring power the entire |
| 108 | +replay: |
| 109 | + |
| 110 | +```sh |
| 111 | +sudo bash ~/demo/install-autostart.sh # enable |
| 112 | +sudo bash ~/demo/install-autostart.sh --off # disable, restore the getty |
| 113 | +``` |
| 114 | + |
| 115 | +It takes tty1 from `getty@tty1`, so the HDMI console is the demo rather than a |
| 116 | +login prompt. |
| 117 | + |
| 118 | +### Reading the verify log over RPMsg |
| 119 | + |
| 120 | +The right pane does not need this, but the same log can be read as an ordinary |
| 121 | +Linux tty: |
| 122 | + |
| 123 | +```sh |
| 124 | +sudo bash ~/demo/m7-rpmsg-log.sh |
| 125 | +``` |
| 126 | + |
| 127 | +Order matters. The payload relays the whole console ring as soon as its endpoint |
| 128 | +has a destination address, which the host supplies while binding the channel - |
| 129 | +strictly before `/dev/ttyRPMSG*` exists. No reader can be attached for that first |
| 130 | +pass, and the log it sends is discarded by a tty nobody has open. The payload |
| 131 | +therefore treats any byte written to the tty as a request to rewind and send the |
| 132 | +log again, so the script attaches a reader first and then pokes. |
| 133 | + |
| 134 | +## Notes that will save you time |
| 135 | + |
| 136 | +**The M7 starts once per Linux boot.** `echo stop > .../state` fails on this BSP |
| 137 | +with "Interrupted system call" and the core stays running, so replaying the boot |
| 138 | +means a real power cycle of the board - not a restart. Plan the demo around |
| 139 | +that. |
| 140 | + |
| 141 | +**The payload is not the upstream `openamp_rsc_table` sample, deliberately.** |
| 142 | +That sample assumes Linux loaded *its* ELF: the remote declares vrings with |
| 143 | +`da = FW_RSC_ADDR_ANY` and Linux writes the resolved addresses and the virtio |
| 144 | +status back into the resource table it loaded. Here Linux loads **wolfBoot**, so |
| 145 | +those values land in wolfBoot's table while the sample polls its own - and it |
| 146 | +waits forever in `rproc_virtio_wait_remote_ready()`. This payload uses fixed |
| 147 | +vring addresses matching wolfBoot's table and skips the wait, because there is |
| 148 | +nothing to wait for: Linux registers virtio0 before it releases the core. |
| 149 | + |
| 150 | +**The right pane reads the console ring directly, not `rpmsg_tty`.** wolfBoot |
| 151 | +writes its log before any RPMsg endpoint exists, so the ring is the only source |
| 152 | +that contains the verification output - and reading it needs no driver, no |
| 153 | +endpoint binding and no module load. |
| 154 | + |
| 155 | +**Nothing may sit unflushed in the page cache.** The replay beat is a hard power |
| 156 | +cut, so a file written seconds earlier is simply gone after the next cycle - a |
| 157 | +staged payload, or the autostart unit, silently reverts to what was there |
| 158 | +before. `stage.sh` and `install-autostart.sh` both `sync`; verify a hand-copied |
| 159 | +payload with `md5sum` rather than a timestamp. |
| 160 | + |
| 161 | +**Torizon has no tmux**, and its rootfs is read-only OSTree, so there is nothing |
| 162 | +to install. `demo/twopane.py` renders two fixed columns with a full redraw |
| 163 | +instead. |
| 164 | + |
| 165 | +**Do not quote the benchmark's "Cycles per byte" or "Cycles/op" columns on an |
| 166 | +A55.** They derive from the 24 MHz generic timer rather than the 1.8 GHz core |
| 167 | +clock and are wrong by roughly 75x. Use ops/sec and MB/s, or pass |
| 168 | +`-freq 1800000000`. The demo renderer strips those columns for this reason. |
| 169 | + |
| 170 | +**The AHAB containers are unsigned, and the module is an open part.** The boot |
| 171 | +ROM checks each image against the SHA-384 held in the container, which is an |
| 172 | +integrity check, not an authenticity one. The signature block is a 16-byte stub |
| 173 | +with its SRK-table, certificate and signature offsets all zero, and the ROM does |
| 174 | +not check it. What is cryptographically verified here is what **wolfBoot** |
| 175 | +verifies: the Linux FIT and the Cortex-M7's Zephyr payload, both with ML-DSA-87. |
| 176 | +Anchoring the chain below wolfBoot means signing the containers - which needs no |
| 177 | +fuses - and then burning the OEM SRK hash and closing the part, which does and is |
| 178 | +irreversible. See *Signing the containers* in [docs/BUILD.md](docs/BUILD.md) and |
| 179 | +*Where the root of trust sits* in |
| 180 | +[docs/BOOT-WALKTHROUGH.md](docs/BOOT-WALKTHROUGH.md). |
| 181 | + |
| 182 | +## Documentation |
| 183 | + |
| 184 | +- [docs/BUILD.md](docs/BUILD.md) - building the demo from a stock module, end to end |
| 185 | +- [docs/BOOT-WALKTHROUGH.md](docs/BOOT-WALKTHROUGH.md) - the boot explained stage by stage, and how to switch between the stock and wolfBoot chains |
| 186 | + |
| 187 | +## Tools |
| 188 | + |
| 189 | +- `tools/ahab-extract.py` - list or extract the images in an AHAB container set |
| 190 | +- `tools/ahab-pack-container2.sh` - build container 2 (BL31, BL33, OP-TEE) into a boot image |
| 191 | +- `tools/ahab-replace-spl.py` - put a wolfBoot stage 1 in the U-Boot SPL slot |
| 192 | +- `tools/emmc-write-boot.sh` - write and verify an eMMC boot partition over ssh |
| 193 | +- `tools/emmc-select-boot.sh` - choose which boot partition the boot ROM loads |
| 194 | + |
| 195 | +## Support |
| 196 | + |
| 197 | +wolfSSL is dual licensed under GPLv3 or a commercial license. Questions: |
| 198 | +support@wolfssl.com |
0 commit comments