Skip to content

Commit 26f2a89

Browse files
author
Sebastian Bantel
committed
feat: support signing with external signature
- add option to create hash to sign - add option to create signed image using public key and external signature file (DER format or raw) - add option to create public key hash from public key file - update tests to cover new functionality - update usage instructions
1 parent b85320a commit 26f2a89

3 files changed

Lines changed: 505 additions & 69 deletions

File tree

README.md

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ It uses ECDSA (Elliptic Curve Digital Signature Algorithm) to ensure the integri
1414

1515
- Sign/Verify firmware images with ECDSA (NIST P-256 or brainpool 256).
1616
- Support for HSM Token (PKCS#11).
17+
- Support for separate public key usage (private key only needed for signing).
18+
- Two-step signing workflow for external signing (HSM, remote signing, etc.).
19+
- Automatic DER signature format parsing (compatible with OpenSSL output).
20+
- Generate public key hash from either private or public key.
1721
- Currently supports only STM32MP15x MPU firmware image headers.
1822

1923
## Requirements
@@ -69,6 +73,26 @@ Sign a firmware image using the following command:
6973
stm32mp-sign-tool -k <private_key_file> -i <image.stm32> -o <image.stm32.signed>
7074
```
7175

76+
Create sha256 to sign from image
77+
78+
```sh
79+
stm32mp-sign-tool -u <public_key_file> -i <image.stm32> -s <image-sha256.bin>
80+
```
81+
82+
Sign image eg. with openssl
83+
84+
```sh
85+
openssl pkeyutl -sign -inkey <private_key_file> -passin pass:<> -in <image-sha256.bin> -out <signature.der>
86+
```
87+
88+
Apply the signature to create the signed image
89+
90+
```sh
91+
stm32mp-sign-tool -u <public_key_file> -i <image.stm32> -d <signature.der> -o <image.stm32.signed>
92+
```
93+
94+
The tool automatically handles both DER-encoded signatures (from OpenSSL) and raw 64-byte signatures.
95+
7296
### Sign a Firmware Image using a HSM Token
7397

7498
Generate an ECDSA key:
@@ -85,15 +109,38 @@ stm32mp-sign-tool -v -k "pkcs11:object=<KeyLabel>" -p <pin> -i <image.stm32> -o
85109

86110
### Generating the public key hashes
87111

112+
From a private key:
113+
88114
```sh
89-
stm32mp-sign-tool -v -k <private_key_file> -h <hash output>
115+
stm32mp-sign-tool -v -k <private_key_file> -h <hash_output>
90116
```
91-
or
117+
118+
From a public key:
92119

93120
```sh
94-
stm32mp-sign-tool -v -k "pkcs11:object=<KeyLabel>" -p <pin> -h <hash output>
121+
stm32mp-sign-tool -u <public_key_file> -h <hash_output>
95122
```
96123

124+
Or with PKCS#11:
125+
126+
```sh
127+
stm32mp-sign-tool -k "pkcs11:object=<KeyLabel>" -p <pin> -h <hash_output>
128+
```
129+
130+
## Command Line Options
131+
132+
- `-k` - Private key file or PKCS#11 URI (required for signing)
133+
- `-u` - Public key file
134+
- `-p` - Passphrase or PIN for private key
135+
- `-v` - Verbose mode
136+
- `-i` - Input image file to sign
137+
- `-o` - Output signed image file
138+
- `-h` - Output file for public key hash
139+
- `-s` - Output file for hash to sign
140+
- `-d` - Input signature file
141+
142+
**Note:** The `-d` option accepts both DER-encoded signatures (standard OpenSSL output) and raw 64-byte signatures.
143+
97144
## License
98145

99146
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.

0 commit comments

Comments
 (0)