# bindkey-project/bindkey-tinyesp architecture

> Architecture diagram of the GitHub repository bindkey-project/bindkey-tinyesp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bindkey-project/bindkey-tinyesp
- Repository: https://github.com/bindkey-project/bindkey-tinyesp

## Overview

BindKey’s master firmware authenticates a user, initializes access to encrypted volumes, and presents them to a host as a USB mass-storage device. For disk I/O, the USB layer uses encrypted-disk handling, which applies AES-GCM and forwards physical-media operations over SPI to the slave MCU. Secure-element and volume-table modules support key handling and volume configuration; a UART task provides the desktop control channel. The README also describes an alternate BM-Lite fingerprint path and sharing capabilities. Some runtime wiring is unsampled, so uncertain links are omitted.

Main entry points: [`src/main.rs`](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/main.rs) (Firmware boot), [`src/crypto/encrypted_disk.rs`](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/crypto/encrypted_disk.rs) (Encrypted disk), [`src/usb_emulation/fake_usb.rs`](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/usb_emulation/fake_usb.rs) (USB MSC emulation), [`src/spi_link/spi_master.rs`](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/spi_link/spi_master.rs) (SPI master transport)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_boot["Firmware and authentication"]
  node_main["Firmware boot<br/>[main.rs]"]
  node_fingerprint["R503 fingerprint"]
  node_bmlite["BM-Lite fingerprint<br/>[bmlite_if.h]"]
end

subgraph group_storage["Encrypted storage"]
  node_disk["Encrypted disk<br/>[encrypted_disk.rs]"]
  node_aes["AES-GCM<br/>[aes.rs]"]
  node_disk_crypto["Sector crypto<br/>[disk_crypto.rs]"]
  node_disk_layout["Disk layout<br/>[disk_layout.rs]"]
  node_disk_meta["Sector metadata<br/>[disk_meta.rs]"]
  node_volume_table["Volume table<br/>[volume_table.rs]"]
  node_secure_element["Secure-element operations<br/>[secure_element.rs]"]
end

subgraph group_links["Device interfaces"]
  node_software_link["UART control<br/>[task.rs]"]
  node_usb["USB MSC emulation<br/>[fake_usb.rs]"]
  node_spi_api["SPI storage API<br/>[api_spi.rs]"]
  node_spi_master["SPI master transport<br/>[spi_master.rs]"]
  node_protocol["SPI protocol<br/>[protocol.rs]"]
end

node_host(("Host PC"))
node_desktop(("Desktop software"))
node_slave["Slave MCU and media"]
node_r503_sensor["R503 sensor"]
node_bm_sensor["BM-Lite sensor"]
node_atecc["ATECC608A"]

node_host -->|"issues USB MSC I/O"| node_usb
node_main -->|"initializes and authenticates"| node_fingerprint
node_main -->|"selects alternate path"| node_bmlite
node_r503_sensor -->|"provides fingerprint input"| node_fingerprint
node_bm_sensor -->|"provides fingerprint input"| node_bmlite
node_main -->|"initializes transport"| node_spi_master
node_main -->|"loads volume table"| node_volume_table
node_main -->|"initializes session"| node_secure_element
node_atecc -->|"performs crypto operations"| node_secure_element
node_main -->|"initializes encrypted disk"| node_disk
node_main -->|"starts USB MSC"| node_usb
node_main -->|"starts UART task"| node_software_link
node_desktop -->|"sends control commands"| node_software_link
node_usb -->|"handles encrypted I/O"| node_disk
node_usb -->|"loads and flushes table"| node_volume_table
node_disk -->|"uses for sector encryption"| node_aes
node_disk -->|"delegates sector crypto"| node_disk_crypto
node_disk -->|"uses sector layout"| node_disk_layout
node_disk -->|"uses metadata"| node_disk_meta
node_disk -->|"forwards media I/O"| node_spi_api
node_volume_table -->|"uses secure-element keys"| node_secure_element
node_spi_api -->|"dispatches commands"| node_spi_master
node_spi_master -->|"frames SPI traffic"| node_protocol
node_spi_master -->|"transfers storage commands"| node_slave

click node_main "https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/main.rs"
click node_fingerprint "https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/fingerprint/fingerprint_r503.rs"
click node_bmlite "https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/fingerprint/BMLite/include/bmlite_if.h"
click node_software_link "https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/software_link/task.rs"
click node_usb "https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/usb_emulation/fake_usb.rs"
click node_spi_api "https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/spi_link/api_spi.rs"
click node_spi_master "https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/spi_link/spi_master.rs"
click node_protocol "https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/spi_link/protocol.rs"
click node_disk "https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/crypto/encrypted_disk.rs"
click node_aes "https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/crypto/aes.rs"
click node_disk_crypto "https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/crypto/disk_crypto.rs"
click node_disk_layout "https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/crypto/disk_layout.rs"
click node_disk_meta "https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/crypto/disk_meta.rs"
click node_volume_table "https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/crypto/volume_table.rs"
click node_secure_element "https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/crypto/secure_element.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_fingerprint,node_bmlite toneBlue
class node_disk,node_aes,node_disk_crypto,node_disk_layout,node_disk_meta,node_volume_table,node_secure_element toneAmber
class node_software_link,node_usb,node_spi_api,node_spi_master,node_protocol toneMint
class node_host,node_desktop,node_slave,node_r503_sensor,node_bm_sensor,node_atecc toneIndigo
```

## Components

### Firmware and authentication

- [Firmware boot](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/main.rs): `src/main.rs`
- [R503 fingerprint](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/fingerprint/fingerprint_r503.rs): `src/fingerprint/fingerprint_r503.rs`
- [BM-Lite fingerprint](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/fingerprint/BMLite/include/bmlite_if.h): `src/fingerprint/BMLite/include/bmlite_if.h`

### Encrypted storage

- [Encrypted disk](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/crypto/encrypted_disk.rs): `src/crypto/encrypted_disk.rs`
- [AES-GCM](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/crypto/aes.rs): `src/crypto/aes.rs`
- [Sector crypto](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/crypto/disk_crypto.rs): `src/crypto/disk_crypto.rs`
- [Disk layout](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/crypto/disk_layout.rs): `src/crypto/disk_layout.rs`
- [Sector metadata](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/crypto/disk_meta.rs): `src/crypto/disk_meta.rs`
- [Volume table](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/crypto/volume_table.rs): `src/crypto/volume_table.rs`
- [Secure-element operations](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/crypto/secure_element.rs): `src/crypto/secure_element.rs`

### Device interfaces

- [UART control](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/software_link/task.rs): `src/software_link/task.rs`
- [USB MSC emulation](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/usb_emulation/fake_usb.rs): `src/usb_emulation/fake_usb.rs`
- [SPI storage API](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/spi_link/api_spi.rs): `src/spi_link/api_spi.rs`
- [SPI master transport](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/spi_link/spi_master.rs): `src/spi_link/spi_master.rs`
- [SPI protocol](https://github.com/bindkey-project/bindkey-tinyesp/blob/main/src/spi_link/protocol.rs): `src/spi_link/protocol.rs`

### Other components

- **Host PC**
- **Desktop software**
- **Slave MCU and media**
- **R503 sensor**
- **BM-Lite sensor**
- **ATECC608A**

## Connections

- Host PC → USB MSC emulation: issues USB MSC I/O
- Firmware boot → R503 fingerprint: initializes and authenticates (evidence: `src/main.rs`)
- Firmware boot → BM-Lite fingerprint: selects alternate path (evidence: `src/main.rs`)
- R503 sensor → R503 fingerprint: provides fingerprint input
- BM-Lite sensor → BM-Lite fingerprint: provides fingerprint input
- Firmware boot → SPI master transport: initializes transport (evidence: `src/main.rs`)
- Firmware boot → Volume table: loads volume table (evidence: `src/main.rs`)
- Firmware boot → Secure-element operations: initializes session (evidence: `src/main.rs`)
- ATECC608A → Secure-element operations: performs crypto operations
- Firmware boot → Encrypted disk: initializes encrypted disk (evidence: `src/main.rs`)
- Firmware boot → USB MSC emulation: starts USB MSC (evidence: `src/main.rs`)
- Firmware boot → UART control: starts UART task (evidence: `src/main.rs`)
- Desktop software → UART control: sends control commands
- USB MSC emulation → Encrypted disk: handles encrypted I/O (evidence: `src/usb_emulation/fake_usb.rs`)
- USB MSC emulation → Volume table: loads and flushes table (evidence: `src/usb_emulation/fake_usb.rs`)
- Encrypted disk → AES-GCM: uses for sector encryption (evidence: `src/crypto/encrypted_disk.rs`)
- Encrypted disk → Sector crypto: delegates sector crypto (evidence: `src/crypto/encrypted_disk.rs`)
- Encrypted disk → Disk layout: uses sector layout (evidence: `src/crypto/encrypted_disk.rs`)
- Encrypted disk → Sector metadata: uses metadata (evidence: `src/crypto/encrypted_disk.rs`)
- Encrypted disk → SPI storage API: forwards media I/O
- Volume table → Secure-element operations: uses secure-element keys (evidence: `src/crypto/volume_table.rs`)
- SPI storage API → SPI master transport: dispatches commands (evidence: `src/spi_link/api_spi.rs`)
- SPI master transport → SPI protocol: frames SPI traffic (evidence: `src/spi_link/spi_master.rs`)
- SPI master transport → Slave MCU and media: transfers storage commands
