A (mostly) rust re-implementation of Emill/P256-Cortex-M4.
Rust 1.88.0 stabilized the naked_asm macro which allows for this to be compiled without any additional tooling. No build.rs script or external assembler required.
This is not yet complete, it lacks interoperability with other targets (via RustCrypto traits or compile-time switches). See ycrypto/p256-cortex-m4 for an interoperable solution.
This lacks the configurability of the original source because rust features are less powerful than C pre-processor macros. Use ycrypto/p256-cortex-m4-sys if you require configurability.
As measured on a STM32WLE5.
| Implementation | Signing Cycles (appx) | Verify Cycles (appx) | Flash Size (appx) |
|---|---|---|---|
| Hardware PKA | 5,211,859 | 10,516,860 | 1,582 B |
| RustCrypto | 7,856,436 | 14,303,277 | 49 kiB |
p256-cm4 |
442,754 | 1,225,746 | 10 kiB |
Since qemu-decode requires std, compiling it for thumbv7em-none-eabi spits out a lot of errors which massively slows down rust-analyzer if you
try to change the compilation target for p256-cm4 and testsuite.
By default, VSCode configures rust-analyzer to run cargo on the entire workspace. However, to prevent rust-analyzer from trying to compile packages
for targets they are not intended to compile for, you can open an individual project (e.g. code p256-cm4/ or code testsuite/) and set
the following settings in your .vscode/config.json:
{
"rust-analyzer.check.workspace": false,
"rust-analyzer.cargo.target": "thumbv7em-none-eabi"
}Install qemu-system-arm (tested to work with qemu-system-arm 8.2.2).
DEFMT_LOG=trace cargo test -p testsuite --target thumbv7em-none-eabi- Install a debugger (we recommend probe-rs-tools)
- Update
memory.xto match your target device - Update the runner in
.cargo/config.toml - Run the command from the Testing section.
Usually, you'll want rtt logs instead of semihosting logs when running on real hardware. To get those, you can enable the rtt feature.
An example change, when running on an STM32H723ZGTx:
.cargo/config.toml:
[target.thumbv7em-none-eabi]
-runner = "cargo run -p qemu-decode --"
+runner = "probe-rs run --chip STM32H723ZGTx"memory.x:
-/* Memory for the LM3S6965EVB */
+/* Memory for STM32H723ZGTx (running from RAM) */
MEMORY
{
- FLASH : ORIGIN = 0x00000000, LENGTH = 256k
- RAM : ORIGIN = 0x20000000, LENGTH = 64k
+ DTCM : ORIGIN = 0x20000000, LENGTH = 128K
+ AXISRAM : ORIGIN = 0x24000000, LENGTH = 128K + 192K
}
+# Region alias to run from RAM
+REGION_ALIAS(FLASH, AXISRAM);
+REGION_ALIAS(RAM, DTCM);Command:
DEFMT_LOG=trace cargo test -p testsuite --target thumbv7em-none-eabi --features rtt