Skip to content
Projetos

embetrix/stm32mp-sign-tool

Ver no GitHub

Sobre

The stm32mp-sign-tool is an utility for signing and verifying firmware images compatible with STM32MP MPUs

Design e mídia

Como estes números são medidos

O que você pode fazer

  • STM32MP15x - v1 - Signing and verification
  • STM32MP13x - v2.0 - Not supported
  • STM32MP23x, STM32MP25x - v2.2 - Signing and verification
  • STM32MP21x - v2.3 - Not supported

Crescimento medido de estrelas

em 24 h
0
em 7 dias
Coletando histórico
em 15 dias
Coletando histórico
em 1 mês
Coletando histórico

Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.

README.md

Original

stm32mp-sign-tool

pipeline status

stm32mp-sign-tool signs STM32MP firmware images with ECDSA and verifies the resulting signatures. It is a lightweight, open-source alternative to STM32_SigningTool_CLI that does not require the full STM32CubeProgrammer installation.

Contents

Supported devices and features

Platform STM32 header Support
STM32MP15x v1 Signing and verification
STM32MP13x v2.0 Not supported
STM32MP23x, STM32MP25x v2.2 Signing and verification
STM32MP21x v2.3 Not supported
  • ECDSA with NIST P-256 or brainpoolP256t1 keys.
  • Private keys from PEM files or PKCS#11 tokens, including HSMs.
  • Automatic header-version detection and verification after signing.
  • Public-key hash export for v1 and public-key table hash export for v2.2.

Disclaimer: This tool is developed from the public specification of the STM32 header format. It does not use reverse engineering or incorporate any proprietary code. It does not support all the features of the official ST Tools. Use this tool with care. It is not affiliated with or endorsed by STMicroelectronics.

Build, test and install

Requirements

  • A C++17 compiler and a build tool such as Make.
  • CMake.
  • OpenSSL 3.0 or newer, including development headers.
  • For PKCS#11 signing: an OpenSSL PKCS#11 provider and the token's PKCS#11 module.
  • For the test suite: Python 3, OpenSC tools, SoftHSM2 and the PKCS#11 provider.

On Ubuntu, install the build dependencies:

sudo apt-get update
sudo apt-get install -y build-essential cmake openssl libssl-dev

For the test suite, also install:

sudo apt-get install -y python3 softhsm2 opensc pkcs11-provider

Build

From the repository root, create a separate build directory:

mkdir -p build
cd build
cmake ..
cmake --build .

The executable is created in build/. Before installation, run it as ./stm32mp-sign-tool from that directory.

Test

From the build directory:

ctest -V

The suite covers v1 and v2.2 signing, header validation and SoftHSM signing.

Install

From the build directory:

sudo cmake --build . --target install

The examples below assume the installed stm32mp-sign-tool is on your PATH.

Sign firmware images

The input must already contain a supported STM32 header. Signing automatically verifies the resulting signature before writing the output. The CLI does not provide a separate verification command.

STM32MP15x (header v1)

Generate a private key and sign an existing image:

openssl ecparam -name prime256v1 -genkey -out private_key.pem

stm32mp-sign-tool -k private_key.pem \
    -i image.stm32 -o image.stm32.signed

To use brainpool instead, generate the key with -name brainpoolP256t1.

STM32MP23x and STM32MP25x (header v2.2)

Provide exactly eight distinct public keys after one -K option, in table order. Select the signing key with -x, using an index from 0 to 7. The private key supplied with -k must match that table entry.

To create a new set of eight key pairs:

for index in 0 1 2 3 4 5 6 7
do
    openssl ecparam -name prime256v1 -genkey -out "private_key_$index.pem"
    openssl pkey -in "private_key_$index.pem" -pubout -out "public_key_$index.pem"
done

Sign with the private key at index 3 and export the public-key table hash:

stm32mp-sign-tool -k private_key_3.pem \
    -K public_key_0.pem public_key_1.pem \
       public_key_2.pem public_key_3.pem \
       public_key_4.pem public_key_5.pem \
       public_key_6.pem public_key_7.pem \
    -x 3 -i image_v2_2.stm32 -o signed_image_v2_2.stm32 \
    -h public_key_table_hash.bin

Duplicate public keys are rejected. Keep the table in the same order used to calculate the device's provisioned OTP table hash: changing a key or its position changes the resulting hash.

Encrypted private keys

Add -p "your-passphrase" to supply the private-key password. Omitting -p leaves password prompting to OpenSSL. -p "" explicitly supplies an empty password.

Sign with a PKCS#11 token

Install the OpenSSL PKCS#11 provider and your token's PKCS#11 module. Replace the module path and PIN below with values for your token, which must already be initialized.

Generate a key pair on the token:

PKCS11_MODULE=/path/to/vendor-pkcs11.so

pkcs11-tool --module "$PKCS11_MODULE" --pin "YOUR_PIN" \
    --keypairgen --key-type EC:prime256v1 --id 1 --label signing-key

Sign a v1 image using the private key's URI:

stm32mp-sign-tool -k "pkcs11:object=signing-key;type=private" \
    -m "$PKCS11_MODULE" -p "YOUR_PIN" \
    -i image.stm32 -o image.stm32.signed

For v2.2, also supply -K and -x as in the v2.2 example. Both -k and -K accept PKCS#11 URIs. A public-key descriptor can be written as pkcs11:object=signing-key;type=public. The selected public key must match the private signing key on the token.

Export public-key hashes

Use -h to write a binary hash file while signing an image. To export only the hash, leave out -i.

Header v1: single-key hash

Export SHA256(public_key) from a PEM private key:

stm32mp-sign-tool -k private_key.pem -h public_key_hash.bin

Or export it from a token key, using the module path configured above:

stm32mp-sign-tool -k "pkcs11:object=signing-key;type=private" \
    -m "$PKCS11_MODULE" -p "YOUR_PIN" -h public_key_hash.bin

Header v2.2: public-key table hash

For v2.2, -h exports the 32-byte SHA-256 hash of the eight-entry public-key hash table. Each entry is SHA256(algorithm_le32 || raw_public_key).

To export the table hash without signing an image:

stm32mp-sign-tool -k private_key_0.pem \
    -K public_key_0.pem public_key_1.pem \
       public_key_2.pem public_key_3.pem \
       public_key_4.pem public_key_5.pem \
       public_key_6.pem public_key_7.pem \
    -x 0 -h public_key_table_hash.bin

The CLI still requires -k and -x for this command, although table-hash generation only loads the public keys. Without an input image, supplying -K and -x selects table-hash export.

Command-line reference

Option Description
-k KEY Private-key PEM file or PKCS#11 URI. Required.
-i IMAGE Input image with an STM32 header. Omit for hash-only export.
-o IMAGE Signed output image. Missing parent directories are created.
-K KEY0 … KEY7 Eight public-key PEM files or PKCS#11 URIs, in table order. Use with -x.
-x INDEX Selected public-key index, from 0 to 7. Use with -K.
-p PASSWORD Private-key passphrase or token PIN.
-m MODULE Path to the token's PKCS#11 module.
-h FILE Binary public-key hash output. This option is not a help flag.
-v Verbose output.

For v1 input images, -K and -x are ignored with a warning.

Image handling and limitations

  • If -o is omitted, signing and verification happen in memory. No signed image is saved.
  • Signing rounds the declared payload length up to a multiple of 32 bytes, inserting zero bytes before any trailing data.
  • For v2.2, signing rebuilds the authentication extension and normalizes the padding flag, extension length and padding type.
  • Existing v2.2 decryption metadata is preserved. The tool does not encrypt or decrypt the payload.
  • The v2.2 non-secure payload metadata and trailing data are preserved. Bytes beyond the declared payload are not authenticated. v2.2 verification emits a warning when they are present.

License

This project is licensed under the terms of the GNU General Public License v3 (GPLv3). You are free to use, modify and distribute this software under the conditions outlined in the GPLv3 license.

For more information about the GPLv3 license, refer to the LICENSE file in this repository or visit GNU's official page.

Contributor License Agreement (CLA)

By submitting a pull request to this repository, you agree to the following terms:

  1. You certify that your contribution is your original work or that you have the necessary rights to submit it.
  2. You grant the project maintainers a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license to:
    • Use, modify, sublicense and distribute your contribution under the terms of the GPLv3.
    • Use, modify, sublicense and distribute your contribution under alternative licenses, including commercial licenses.
  3. You understand that you retain the copyright to your contribution but agree it may be relicensed under these terms.

Explore projetos relacionados

Carregando…