wolfBoot/tools/keytools
Daniele Lacamera 74b8fc0664 F-5131: fix stale delta inverse-patch offset when cert chain expands header
base_diff() captured patch_inv_off = len3 + CMD.header_sz before calling
make_header_delta(), which signs the delta image via make_header_ex(is_diff=1).
When a certificate chain is present, the delta (is_diff=1) header needs ~72
more bytes than the non-delta header for the four delta TLVs plus the base-hash
TLV. For a window of cert-chain sizes, header_required_size(is_diff=0) still fit
the current CMD.header_sz while header_required_size(is_diff=1) did not, so
make_header_ex(is_diff=1) grew CMD.header_sz to the next power of two *after*
patch_inv_off was captured. The HDR_IMG_DELTA_INVERSE TLV then encoded a stale,
too-small offset; the bootloader (update_flash.c) uses it as a raw byte offset
into the update partition to locate the inverse patch, so rollback read from the
wrong offset and failed.

Resolve the is_diff=1 header-size expansion (same logic as make_header_ex)
before computing patch_inv_off. Add unit-sign-delta-cert-inv-off.py, which signs
an ed25519 delta with a 300-byte chain (inside the triggering window) and
asserts the inverse patch is the trailing HDR_IMG_DELTA_INVERSE_SIZE bytes of
the file; it fails before this fix.
2026-06-09 15:52:07 +02:00
..
otp Preparing release v2.8.0 + update copyright 2026-04-16 13:11:56 +02:00
Makefile Update wolfssl submodule to latest master 2026-05-18 23:02:54 -07:00
README.md
keygen.c Continue the ML-DSA renaming 2026-05-19 11:21:20 -07:00
keygen.py Preparing release v2.8.0 + update copyright 2026-04-16 13:11:56 +02:00
sign.c F-5131: fix stale delta inverse-patch offset when cert chain expands header 2026-06-09 15:52:07 +02:00
sign.py F-5352: emit 4-byte delta size TLVs from Python signer 2026-06-09 15:50:48 +02:00
user_settings.h Continue the ML-DSA renaming 2026-05-19 11:21:20 -07:00
wolfBootKeyTools.sln
wolfBootKeygenTool.vcxproj Update wolfssl submodule to latest master 2026-05-18 23:02:54 -07:00
wolfBootSignTool.vcxproj Update wolfssl submodule to latest master 2026-05-18 23:02:54 -07:00

README.md

Key Tools for signing and key generation

Sign

See code file ./tools/keytools/sign.c and documentation in docs/Signing.md.

KeyGen and KeyStore

See code file ./tools/keytools/keygen.c and documentation docs/keystore.md.

Flash OTP Keystore Generation, Primer, Startup

See documentation docs/flash-OTP.md.

Keystore Generation

Pack public keys into a single binary (otp.bin) formatted the way wolfBoot expects for provisioning the devices OTP/NVM keystore. No signing, no encryption—just a correctly laid-out image with a header plus fixed-size "slots" for each key.

See code file ./tools/keytools/otp/otp-keystore-gen.c

Flash OTP Primer

See code file ./tools/keytools/otp/otp-keystore-primer.c

Flash OTP Startup

See code file ./tools/keytools/otp/startup.c

Quick Start (Linux)

make wolfboot_signing_private_key.der SIGN=ED25519

# or

./tools/keytools/keygen --ed25519 -g wolfboot_signing_private_key.der

Note the above example is a basic case where a single key is generated. The tool supports multiple keys both with [-g privkey] and [-i pubkey] parameters.

See the local docs docs/keystore.md and the wolfBoot Keystore section of the manual for additional details.

Debugging and Development

DEBUG_SIGNTOOL

Enables additional diagnostic messages that may be useful during development and initial bring-up.

WOLFBOOT_SHOW_INCLUDE

Enables compile-time verbosity to indicate which user_settings.h file is being used.