- Python 48.5%
- C 32.7%
- Verilog 16%
- Makefile 1.2%
- Shell 0.9%
- Other 0.7%
| docs | ||
| firmware | ||
| host | ||
| rtl | ||
| sim | ||
| soc | ||
| tests | ||
| tools | ||
| .gitignore | ||
| CLAUDE.md | ||
| device.pub | ||
| Makefile | ||
| README.md | ||
| requirements.txt | ||
| tee-fsm.svg | ||
fpga-bio-tee
A fingerprint authentication system for the Icepi Zero (Lattice ECP5). Enrollment and matching run on the device. A host sends a nonce over USB; after a local verification gesture and a fingerprint match, the device signs the nonce and result with Ed25519. The key and enrolled templates are stored on microSD.
Status: built and tested in simulation; board bring-up is still pending. The biometric thresholds have been tuned on synthetic fingerprints.
Design
The trust boundary is the USB mailbox. It accepts fixed-size identity, authentication and cancellation requests, and exposes the validated operation and nonce to the CPU. The USB transport has no access to system memory. UART, CPU debug access and the BIOS console are disabled in the SoC build.
| Component | Implementation |
|---|---|
| SoC | VexRiscv CPU at 50 MHz, LiteX buses and peripherals, SDRAM, SPI flash boot |
| Host interface | USB full-speed CDC-ACM transport and a hardware request/reply mailbox |
| Capture | OV7670 at 320 × 240; FPGA logic extracts luma and writes frames to SDRAM by DMA |
| Extraction | Integer normalization, ridge orientation and segmentation, Gabor enhancement, Zhang–Suen thinning, minutiae extraction |
| Matching | Minutiae neighbourhood descriptors, alignment hypotheses, least-squares refinement and overlap scoring |
| Gabor accelerator | Verilog engine with a software implementation for comparison and fallback |
| Entropy | Ring oscillators, firmware health tests and SHA-512 conditioning |
| Storage | Device seed and up to 32 templates, with checksums and commit records |
Enrollment collects five usable samples and requires at least one matching pair before storing a template. Authentication waits up to 30 seconds for the verification gesture and a matching finger. Failed touches can be retried within that window; individual failures are not sent to the host. See the firmware state diagram and state machine.
Build and test
The build uses the OSS CAD Suite (Yosys, nextpnr-ecp5, Icarus Verilog,
Verilator and SymbiYosys), RISC-V GCC (riscv64-elf-gcc), Python ≥ 3.10,
and libevent and json-c development libraries for the simulator. Card
image tests also need sfdisk (util-linux) and mkfs.fat/fsck.fat
(dosfstools). Dependency setup requires network access.
export OSS_CAD_SUITE=/path/to/oss-cad-suite
make deps # pinned LiteX sources in deps/, Python packages in .venv/
make test # native firmware, RTL and host-client tests
make soc # bitstream and BIOS: build/soc/gateware/icepi_zero.bit
make firmware # build/firmware/tee.bin and tee.fbi; requires make soc
make formal # bounded mailbox checks and cover traces
make sim # build the SoC simulation and its firmware
make test-sim # drive the simulated device through the host client
The default toolchain path is /opt/oss-cad-suite. Set BUILD=... to use
another build directory, or USB_PORT=1 to build for
the board's other direct USB port. For firmware development without place
and route, run make soc-software before make firmware.
These targets use builds, simulations and card image files. Programming the board and preparing a physical card are separate steps below.
Validation
| Target | Coverage |
|---|---|
make test |
TRNG health-test cutoffs; SPI card initialization, CRCs, storage faults and recovery; mailbox, USB, camera and Gabor RTL; firmware state transitions; host signature and nonce checks |
make formal |
Mailbox properties to 120 cycles, with reduced timeouts and write data constrained to 0/1; cover traces to 60 cycles |
make test-sim |
Firmware on VexRiscv with a camera model, panel controls, LED timing and the host client |
The native TEE and SoC tests use tests/bio_stub.c: simulated fingers are
numeric IDs. These tests exercise enrollment, storage and authentication
control flow. Fingerprint accuracy needs separate measurements with camera
images. The SoC simulation also replaces USB with TCP, entropy with a fixed
sequence, and card storage with RAM; USB has its own RTL tests.
For extended fuzzing, formal analysis, timing and clock-domain checks, warning classification, and accelerator comparisons:
.venv/bin/python tools/gather_evidence.py --quick
This writes logs, source and artifact hashes, a Markdown report and JSON
results under evidence/. See validation runs for
suite selection, output files and hardware checks.
Installation
Use a trusted computer for programming and initial pairing. These steps have not yet been tested on the board.
The pins are those of board revisions v1.2–v1.4 (printed on the board); v1.0 and v1.1 have other USB and LED pins. Use one USB cable at a time: the board joins the 5 V of all three ports directly.
Write the firmware and bitstream to SPI flash through the FTDI port (J5), in that order. Keep reset suppressed between writes so the new BIOS cannot boot firmware built for a different SoC:
openFPGALoader -b icepi-zero --write-flash --skip-reset --verify --offset 0x100000 --file-type bin build/firmware/tee.fbi
openFPGALoader -b icepi-zero --write-flash --skip-reset --verify build/soc/gateware/icepi_zero.bit
Then unplug J5 and connect the host to USB port 0 (J3) alone to boot from flash.
Prepare a spare card of at least 64 MiB. This erases the whole card. The script checks that it is removable and unmounted, then asks for the device path to be typed before writing:
sudo python3 tools/sdcard_format.py /dev/sdX
The card contains a private store partition and a FAT32 partition labelled
BIOTEE. The device creates its key on first boot with a prepared card.
Keep the FTDI port disconnected during use; access to it allows the design
to be replaced.
Use
.venv/bin/python host/auth_client.py --port /dev/ttyACM0 --identity my-device.pub pair
.venv/bin/python host/auth_client.py --port /dev/ttyACM0 --identity my-device.pub authenticate
Choose a new identity file when pairing your device. pair pins its public
key and refuses to replace an existing key. authenticate sends a fresh
nonce, waits for verification, and exits 0 for a verified match, 1 for
another verified outcome, or 2 for a communication or verification error.
| Gesture | Effect |
|---|---|
| Button 0, or switch left then centre | one enrollment touch; five usable samples with a matching pair complete a template |
| Button 1, or switch right then centre | one verification touch, while a request waits |
| Both buttons for 5 s | erase all templates (the key stays) |
| LED | Shows |
|---|---|
| 0 | enroll: on while capturing, then slow × 3 (touch kept) or fast × 3 (failed) |
| 1 | enrollment progress: a fast blink per retained sample; slow, fast, slow, fast when stored |
| 2 | host traffic |
| 3 | the camera answers |
| 4 | verify: on while a request waits, then slow × 3 (match) or fast × 3 |
For manual performance trials (Bash 5 and GNU date):
bash tools/collect_trials.sh trials.csv
Press Enter to start and stop timing, then enter the observed and expected
results (p for pass, f for fail). Follow the pause/resume prompts for the
next trial; Ctrl+C exits. Each completed trial is saved with UTC timestamps
and elapsed milliseconds. Existing files are not overwritten. These are
manual wall-clock measurements and include human reaction time.
Wiring
All FPGA pins are 3.3 V. Header pins (Raspberry Pi numbering):
| Camera | Pin (GPIO) | Camera | Pin (GPIO) | |
|---|---|---|---|---|
| 3.3V / GND | 1 / 6 | XCLK | 7 (4) | |
| SIOD / SIOC | 3 (2) / 5 (3) | PCLK / HREF / VSYNC | 11 (17) / 13 (27) / 15 (22) | |
| D7 … D0 | 29, 31, 32, 33, 35, 36, 37, 38 (5, 6, 12, 13, 19, 16, 26, 20) | RESET / PWDN | 16 (23) / 18 (24) | |
| Light: LED + 220 Ω | 22 (25) to GND |
The switch (optional, SPDT centre-off): common to pin 20 (GND), left to
pin 19 (GPIO 10), right to pin 23 (GPIO 11). The host connects to USB
port 0 (USB_PORT=1: port 1), never the FTDI port.
Protocol
| Request, 40 bytes | Reply, 136 bytes |
|---|---|
BTA1 |
BTR1 |
| operation: 1 identity, 2 authenticate, 3 cancel | operation, status, 2 zero bytes |
| 3 zero bytes | the nonce (zero for identity) |
| nonce, 32 bytes (zero unless authenticating) | public key, 32 bytes |
| Ed25519 signature, 64 bytes (zero for identity) |
Statuses: 0 match, 2 timeout, 3 cancelled, 4 sensor unavailable, 5 nothing
enrolled, 6 no key, 7 busy (1 is reserved). The signature covers
"BIOTEE-AUTH-v1\0" | nonce | status; the host accepts only status 0 with
a valid signature from the pinned key.
Limits
- The CPU, firmware and gateware are trusted. The mailbox restricts host access; the CPU can read the key and templates.
- The card is not encrypted: whoever has it has the device key.
- No secure boot: the FTDI/JTAG port can load any design.
- Capture quality, biometric error rates and TRNG entropy still need board measurements.
Layout
rtl/ Verilog: mailbox, USB transport, camera, Gabor engine, TRNG
soc/ biotee_soc.py: LiteX builds the SoC around rtl/
sim/ the SoC in Verilator, with a camera model and a TRNG stand-in
firmware/ core/ (TEE, store, keys, templates, pipeline), platform/ (drivers)
host/ auth_client.py
tests/ rtl/ (Icarus testbenches), formal/ (SymbiYosys), native and SoC tests
tools/ dependency setup, card formatting, fixed tables, validation, trials
docs/ extended validation instructions
External code
Copied into this repository:
| Path | Source | Licence | Changes |
|---|---|---|---|
firmware/vendor/ed25519/ |
orlp/ed25519 @ b1f19fa — Ed25519 signing and SHA-512 |
zlib | none (a subset of the files) |
rtl/vendor/usb_cdc/ |
ulixxe/usb_cdc @ 6798bf4 — USB full-speed CDC-ACM device |
MIT | usb_cdc.v, bulk_endp.v: expose the IN FIFO's empty flag; reset the bulk FIFOs while unconfigured (marked fpga-bio-tee:) |
tests/rtl/vendor/usb_cdc/ |
the same repository's testbench tasks (examples/common/hdl) |
MIT | none |
Fetched by make deps, at the commits in tools/setup_deps.sh:
| Package | What it does here |
|---|---|
| VexRiscv (via pythondata-cpu-vexriscv) | the soft CPU |
| LiteX, Migen | builds the SoC: buses, CSRs, timer, GPIO, SPI and I²C masters, BIOS, simulator |
| LiteDRAM, LiteSPI | SDRAM controller, SPI flash |
| litex-boards | the Icepi Zero's pins and clock |
| picolibc, compiler-rt | the firmware's C library and runtime |
| cryptography, pyserial | the host client |
Started from external code: soc/biotee_soc.py from litex-boards' Icepi
Zero target, firmware/linker.ld from LiteX's demo, sim/modules/panel/panel.c
from LiteX's serial2tcp simulator module.