# adakhaddad/mirror_naschiphack architecture

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

- Interactive diagram: https://gitdiagram.com/adakhaddad/mirror_naschiphack
- Repository: https://github.com/adakhaddad/mirror_naschiphack

## Overview

SeBatt is a secure battery-identity proof of concept: a chip samples voltage and signs readings, while a swap station verifies the battery and its signed history. The repository tree does not contain the documented RTL, so the graph focuses on the available Python protocol model, web demo, and firmware. The web workflow is visible in the HTTP handler and demo excerpts; deeper model and firmware interactions are limited to the supplied excerpts and SOURCE INDEX references.

Main entry points: [`model/protocol.py`](https://github.com/adakhaddad/mirror_naschiphack/blob/main/model/protocol.py) (Station verifier), [`model/hmac.py`](https://github.com/adakhaddad/mirror_naschiphack/blob/main/model/hmac.py) (HMAC-SHA-256), [`model/gen_vectors.py`](https://github.com/adakhaddad/mirror_naschiphack/blob/main/model/gen_vectors.py) (Vector generator), [`fpga/fw/sebatt_fw.c`](https://github.com/adakhaddad/mirror_naschiphack/blob/main/fpga/fw/sebatt_fw.c) (MicroBlaze firmware)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_demo["Station demo"]
  node_http["HTTP API<br/>[server.py]"]
  node_demo_state["Demo simulation<br/>[demo.py]"]
end

subgraph group_protocol["Authentication model"]
  node_chip["Battery prover<br/>[protocol.py]"]
  node_station["Station verifier<br/>[protocol.py]"]
  node_wire["Wire protocol<br/>[protocol.py]"]
end

subgraph group_crypto["Cryptography and keys"]
  node_hmac["HMAC-SHA-256<br/>[hmac.py]"]
  node_sha["SHA-256<br/>[sha256.py]"]
  node_puf["Ring-oscillator PUF<br/>[ro_puf.py]"]
  node_vectors["Vector generator<br/>[gen_vectors.py]"]
end

subgraph group_firmware["FPGA firmware"]
  node_firmware["MicroBlaze firmware<br/>[sebatt_fw.c]"]
  node_uart["UART interface<br/>[sebatt_fw.c]"]
end

node_user(("Station operator"))
node_browser["Web dashboard<br/>[app.js]"]
node_fpga["FPGA board"]
node_battery(("Battery voltage source"))
node_identity_db[("Identity database")]

node_user -->|"operates"| node_browser
node_browser -.->|"sends requests"| node_http
node_http -->|"dispatches actions"| node_demo_state
node_demo_state -->|"computes tags"| node_hmac
node_chip -->|"signs samples"| node_hmac
node_station -->|"checks identity"| node_identity_db
node_station -->|"recomputes tags"| node_hmac
node_station -->|"requests authentication"| node_chip
node_station -->|"encodes messages"| node_wire
node_wire -.->|"carries requests"| node_chip
node_wire -.->|"carries responses"| node_station
node_hmac -->|"hashes messages"| node_sha
node_chip -.->|"derives key"| node_puf
node_vectors -->|"uses reference"| node_sha
node_vectors -->|"uses reference"| node_hmac
node_vectors -->|"uses protocol"| node_wire
node_battery -.->|"provides voltage"| node_firmware
node_firmware -->|"sends and receives"| node_uart
node_firmware -.->|"runs on"| node_fpga
node_uart -.->|"communicates"| node_station

click node_browser "https://github.com/adakhaddad/mirror_naschiphack/blob/main/web/static/app.js"
click node_http "https://github.com/adakhaddad/mirror_naschiphack/blob/main/web/server.py"
click node_demo_state "https://github.com/adakhaddad/mirror_naschiphack/blob/main/web/demo.py"
click node_chip "https://github.com/adakhaddad/mirror_naschiphack/blob/main/model/protocol.py"
click node_station "https://github.com/adakhaddad/mirror_naschiphack/blob/main/model/protocol.py"
click node_wire "https://github.com/adakhaddad/mirror_naschiphack/blob/main/model/protocol.py"
click node_hmac "https://github.com/adakhaddad/mirror_naschiphack/blob/main/model/hmac.py"
click node_sha "https://github.com/adakhaddad/mirror_naschiphack/blob/main/model/sha256.py"
click node_puf "https://github.com/adakhaddad/mirror_naschiphack/blob/main/model/ro_puf.py"
click node_vectors "https://github.com/adakhaddad/mirror_naschiphack/blob/main/model/gen_vectors.py"
click node_firmware "https://github.com/adakhaddad/mirror_naschiphack/blob/main/fpga/fw/sebatt_fw.c"
click node_uart "https://github.com/adakhaddad/mirror_naschiphack/blob/main/fpga/fw/sebatt_fw.c"

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_http,node_demo_state toneBlue
class node_chip,node_station,node_wire,node_identity_db toneAmber
class node_hmac,node_sha,node_puf,node_vectors toneMint
class node_firmware,node_uart toneRose
class node_user,node_fpga,node_battery toneIndigo
class node_browser toneTeal
```

## Components

### Station demo

- [HTTP API](https://github.com/adakhaddad/mirror_naschiphack/blob/main/web/server.py): `web/server.py`
- [Demo simulation](https://github.com/adakhaddad/mirror_naschiphack/blob/main/web/demo.py): `web/demo.py`

### Authentication model

- [Battery prover](https://github.com/adakhaddad/mirror_naschiphack/blob/main/model/protocol.py): `model/protocol.py`
- [Station verifier](https://github.com/adakhaddad/mirror_naschiphack/blob/main/model/protocol.py): `model/protocol.py`
- [Wire protocol](https://github.com/adakhaddad/mirror_naschiphack/blob/main/model/protocol.py): `model/protocol.py`

### Cryptography and keys

- [HMAC-SHA-256](https://github.com/adakhaddad/mirror_naschiphack/blob/main/model/hmac.py): `model/hmac.py`
- [SHA-256](https://github.com/adakhaddad/mirror_naschiphack/blob/main/model/sha256.py): `model/sha256.py`
- [Ring-oscillator PUF](https://github.com/adakhaddad/mirror_naschiphack/blob/main/model/ro_puf.py): `model/ro_puf.py`
- [Vector generator](https://github.com/adakhaddad/mirror_naschiphack/blob/main/model/gen_vectors.py): `model/gen_vectors.py`

### FPGA firmware

- [MicroBlaze firmware](https://github.com/adakhaddad/mirror_naschiphack/blob/main/fpga/fw/sebatt_fw.c): `fpga/fw/sebatt_fw.c`
- [UART interface](https://github.com/adakhaddad/mirror_naschiphack/blob/main/fpga/fw/sebatt_fw.c): `fpga/fw/sebatt_fw.c`

### Other components

- **Station operator**
- [Web dashboard](https://github.com/adakhaddad/mirror_naschiphack/blob/main/web/static/app.js): `web/static/app.js`
- **FPGA board**
- **Battery voltage source**
- **Identity database**

## Connections

- Station operator → Web dashboard: operates
- Web dashboard → HTTP API: sends requests
- HTTP API → Demo simulation: dispatches actions (evidence: `web/server.py`)
- Demo simulation → HMAC-SHA-256: computes tags (evidence: `web/demo.py`)
- Battery prover → HMAC-SHA-256: signs samples (evidence: `model/protocol.py`)
- Station verifier → Identity database: checks identity (evidence: `model/protocol.py`)
- Station verifier → HMAC-SHA-256: recomputes tags (evidence: `model/protocol.py`)
- Station verifier → Battery prover: requests authentication (evidence: `model/protocol.py`)
- Station verifier → Wire protocol: encodes messages (evidence: `model/protocol.py`)
- Wire protocol → Battery prover: carries requests (evidence: `model/protocol.py`)
- Wire protocol → Station verifier: carries responses (evidence: `model/protocol.py`)
- HMAC-SHA-256 → SHA-256: hashes messages (evidence: `model/hmac.py`)
- Battery prover → Ring-oscillator PUF: derives key (evidence: `model/protocol.py`)
- Vector generator → SHA-256: uses reference (evidence: `model/gen_vectors.py`)
- Vector generator → HMAC-SHA-256: uses reference (evidence: `model/gen_vectors.py`)
- Vector generator → Wire protocol: uses protocol (evidence: `model/gen_vectors.py`)
- Battery voltage source → MicroBlaze firmware: provides voltage
- MicroBlaze firmware → UART interface: sends and receives (evidence: `fpga/fw/sebatt_fw.c`)
- MicroBlaze firmware → FPGA board: runs on
- UART interface → Station verifier: communicates
