|
| 1 | +# STM32Cube |
| 2 | + |
| 3 | +wolfCOSE ships as an STM32Cube pack, `I-CUBE-wolfCOSE`, so it drops into any |
| 4 | +STM32CubeMX or STM32CubeIDE project without manual source integration. The pack |
| 5 | +provides wolfCOSE as an STM32 middleware and uses the wolfSSL pack |
| 6 | +(`I-CUBE-wolfSSL`) for all cryptography. |
| 7 | + |
| 8 | +Supported cores: Cortex-M0, M0+, M3, M4, M7, M23, M33, M55, and STM32MP1. |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | + |
| 12 | +- STM32CubeMX, plus STM32CubeIDE or another toolchain to build. |
| 13 | +- The wolfSSL pack, `I-CUBE-wolfSSL` 5.9.2 or later. wolfCOSE depends on |
| 14 | + wolfCrypt for hashing, signing, and AEAD. |
| 15 | +- A board with a hardware RNG and a UART for console output. |
| 16 | + |
| 17 | +## Install the packs |
| 18 | + |
| 19 | +1. Download the wolfSSL pack |
| 20 | + ([I-CUBE-wolfSSL.pack](https://www.wolfssl.com/files/ide/I-CUBE-wolfSSL.pack)) |
| 21 | + and the wolfCOSE pack |
| 22 | + ([I-CUBE-wolfCOSE.pack](https://www.wolfssl.com/files/ide/I-CUBE-wolfCOSE.pack)). |
| 23 | +2. In STM32CubeMX, open `Help`, `Manage embedded software packages`, |
| 24 | + `From Local...`, and install the wolfSSL pack first, then the wolfCOSE pack. |
| 25 | + |
| 26 | +## Add wolfCOSE to a project |
| 27 | + |
| 28 | +1. Open or create a project `.ioc` for your board. |
| 29 | +2. Enable the RNG peripheral under `Pinout & Configuration`, `Security`, `RNG`. |
| 30 | + Signing needs entropy, and `wc_GenerateSeed()` fails without it. |
| 31 | +3. Open `Software Packs`, `Select Components`. |
| 32 | +4. Enable `wolfSSL` `wolfCrypt` `Core` and `wolfCOSE` `Core`. To run the |
| 33 | + on device self test, also enable `wolfCOSE` `Test`. |
| 34 | +5. In the `Software Packs` configuration category, enable each pack. |
| 35 | +6. Generate code and build with your toolchain. |
| 36 | + |
| 37 | +## Configure algorithms |
| 38 | + |
| 39 | +wolfCOSE reads its configuration from the wolfSSL `user_settings.h`, included |
| 40 | +before `wolfcose/settings.h`. Enable the wolfCrypt features that match the COSE |
| 41 | +algorithms you use: |
| 42 | + |
| 43 | +- ES256: `HAVE_ECC`, `WOLFSSL_SHA256` |
| 44 | +- ES384 or ES512: add `WOLFSSL_SHA384` or `WOLFSSL_SHA512` |
| 45 | +- ML-DSA (RFC 9964): `WOLFSSL_HAVE_MLDSA` |
| 46 | +- Encrypt0 AEAD: `HAVE_AESGCM`, or `HAVE_CHACHA` with `HAVE_POLY1305` |
| 47 | +- MAC0: HMAC, which is on by default with SHA support |
| 48 | + |
| 49 | +If a required wolfCrypt feature is missing, `wolfcose/settings.h` raises a |
| 50 | +compile error naming it. |
| 51 | + |
| 52 | +## Run on a device |
| 53 | + |
| 54 | +The `Test` component builds `wolfcose_test.c`, a self test that runs a |
| 55 | +`COSE_Sign1` sign and verify and reports the result over your configured |
| 56 | +console. Call `wolfCOSETest()` from your application once `main` has initialized |
| 57 | +the clocks and console. |
| 58 | + |
| 59 | +A ready to run example for the NUCLEO-H563ZI board lives in |
| 60 | +[wolfssl-examples-stm32](https://github.com/wolfSSL/wolfssl-examples-stm32), |
| 61 | +with a pre-configured `.ioc`: install the packs, open the `.ioc`, generate, |
| 62 | +add the glue and software-crypto config from that example's README, build, |
| 63 | +flash, and watch the console. |
| 64 | + |
| 65 | +Verified on NUCLEO-H563ZI hardware, the console prints: |
| 66 | + |
| 67 | +``` |
| 68 | +== wolfCOSE NUCLEO-H563ZI == |
| 69 | +Running wolfCOSE test (COSE_Sign1 ES256)... |
| 70 | +wolfCOSE test: PASS (COSE_Sign1 99 bytes) |
| 71 | +``` |
| 72 | + |
| 73 | +## Notes |
| 74 | + |
| 75 | +- Only pack source is kept in the repository. The built pack is posted at |
| 76 | + [wolfssl.com/files/ide/I-CUBE-wolfCOSE.pack](https://www.wolfssl.com/files/ide/I-CUBE-wolfCOSE.pack). |
| 77 | +- On some STM32 families the wolfSSL pack enables hardware hash and RNG by |
| 78 | + default. If a build reports a missing HAL module or hash symbol, enable the |
| 79 | + matching peripheral in the `.ioc`, or select software crypto with |
| 80 | + `NO_STM32_HASH` and `NO_STM32_RNG` in the generated |
| 81 | + `wolfSSL.I-CUBE-wolfSSL_conf.h`. On the STM32H5 the hardware hash block |
| 82 | + references a HAL enum that does not exist, so software crypto is required |
| 83 | + there; the |
| 84 | + [NUCLEO-H563ZI example](https://github.com/wolfSSL/wolfssl-examples-stm32/tree/master/wolfCOSE-STM32-Example) |
| 85 | + shows the exact edit. |
0 commit comments