Skip to content

Adding a target ​

A target is one device of one vendor: targets/<vendor>/<model>.sh. Its first line is # DESC: <one line>, which bin/hww list shows. It's sourced by bin/hww with these set:

variablemeaning
TARGET<vendor>/<model>
VERSIONthe release being verified, as the vendor numbers it
RUNwork/runs/<target>/<version>: everything of this run
RESULTSresults/<target>/<version>: what gets committed
HWW_ROOT, HWW_WORK, HWW_JOBS, DOCKERsee lib/common.sh

and it defines one function per step, plus t_releases:

functionmust produce
t_releasesprint the published versions, one per line
t_fetch$RUN/published/image.bin (the image as distributed), $RUN/published/published.json with at least url, sha256, and source_commit when the vendor names one
t_sourcethe checkout, and $RUN/source.json (repo, tag, commit). Fail if the tag doesn't resolve to the commit the vendor names
t_buildthe vendor's own build, unmodified, then the instrumented rebuild and $RUN/build/bundle/ (see below)
t_extract$RUN/extract/image.json (code_addr, code_len, rebuild_identical, cpu, header checks), code.bin, unsigned.bin, and firmware.elf (the transplant)
t_verifyusually hwwpy verify --run "$RUN" --cverif "$(cverif_bin)" --jobs "$HWW_JOBS"
t_reportusually hwwpy report --run "$RUN" --out "$RESULTS" --target "$TARGET" --version "$VERSION"

A target may also set CT_SPECS: the constant-time specs (ct/<name>.ct, see constant-time.md) whose marks apply to its firmware.

Shared steps of a vendor go in targets/<vendor>/common.sh (see targets/trezor/).

The source bundle ​

The instrumented rebuild runs in the vendor's build environment (usually the Docker image their reproducible-build script leaves behind) with this repository's lib/container mounted read-only at /hww-lib and an output directory at /hww:

sh
mkdir -p /hww/cclog /hww/ccwrap
for t in arm-none-eabi-gcc arm-none-eabi-ar; do ln -s /hww-lib/ccwrap.sh /hww/ccwrap/$t; done
export HWW_CCLOG=/hww/cclog PATH=/hww/ccwrap:$PATH
<the vendor's build command>
unset HWW_CCLOG
python3 -I /hww-lib/export_bundle.py --log /hww/cclog --elf <the firmware ELF> --out /hww/bundle

Wrap every compiler name the build calls by name (arm-none-eabi-gcc, sometimes arm-none-eabi-cc or a versioned name). If the build calls the compiler by absolute path, or has its own compile database, pass it with --compdb (JSON compile_commands format). export_bundle.py needs a logged link of the ELF to work out which units were linked; if there is none (a link driven by another tool), it takes every unit it saw, and the verification then needs care: units of other programs (bootloader, tests) must be left out.

The rebuilt firmware must be byte-identical to the vendor build's (compare and fail otherwise): the bundle then describes the published image exactly.

The image ​

lib/hww/fwimage.py holds the parsers for vendor image formats. A parser takes the published file apart into the header facts, unsigned.bin (signatures zeroed: what a local build gives) and code.bin (what runs, at code_addr). It should check every hash the signed header commits to.

fwimage.py transplant then writes the rebuilt ELF with the published bytes in every loadable section. It fails when a section lies outside the published code, and lists the published bytes no section covers (they must be accounted for: erased flash is fine, anything else isn't).

When the build doesn't reproduce ​

Transplant still works: cverif then proves the build's functions against the published bytes at the build's addresses, and anything that moved fails to prove. If addresses moved, verify the raw code.bin with cverif --discover and the bundle's sources, which recovers the functions from the image itself. Say which was done in the results.

Results ​

results/<target>/<version>/ is written by report.py. A hand-written findings.md next to it holds the triage of each mismatch (and anything else learned); the README links it. Don't commit work/.

Each result records the cverif that verified it (summary.json → cverif: version, work limit, deadline, as the verify step ran them). When tools/cverif.pin moves to a new release, bin/hww stale lists the results to re-run, and the results index and site mark them.

Results are produced by scripts anyone can re-run. MIT licensed.