# panosvl/lattice-ibe-optimizations architecture

> Architecture diagram of the GitHub repository panosvl/lattice-ibe-optimizations, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/panosvl/lattice-ibe-optimizations
- Repository: https://github.com/panosvl/lattice-ibe-optimizations

## Overview

1. **Repository shape**
   This is a small, self-contained C++ proof-of-concept for an identity-based encryption (IBE) scheme over NTRU lattices. It is not a multi-service system; the architecture is a single executable built from a handful of math-heavy source files.

2. **Build and runtime boundary**
   The project is built with `Makefile` into a single program named `IBE`. The runtime expects a Unix-like environment with `g++`, and the code links against **GMP** and **NTL** for big integers / number theory primitives. Those libraries are external dependencies that materially shape the implementation.

3. **Configuration layer**
   `params.h` is the main compile-time configuration boundary. The README says the key tunables are `N0` and `q0`, which means the system’s dimensions and modulus are fixed at compile time rather than loaded dynamically.

4. **Core algebra subsystem**
   `Algebra.cc/.h` is the foundational math layer. It likely defines the polynomial / ring arithmetic and other lattice-algebra operations used throughout the scheme. In an architecture diagram, this is the lowest-level internal dependency that everything else builds on.

5. **FFT acceleration subsystem**
   `FFT.cc/.h` provides the fast transform machinery used to accelerate polynomial multiplication or related ring operations. This sits alongside the algebra layer and is likely called by the arithmetic routines and scheme implementation when efficiency matters.

6. **Randomness and sampling subsystem**
   `Random.cc/.h` and `Sampling.cc/.h` form the stochastic side of the implementation. `Random` is the entropy source / PRNG wrapper, while `Sampling` likely implements the discrete distributions required by lattice cryptography, such as short-vector or Gaussian-like sampling.

7. **Scheme logic**
   `Scheme.cc/.h` is the main cryptographic protocol layer. This is where the IBE-specific operations are assembled: setup, identity-based key extraction, encryption, and decryption. It depends on algebra, FFT, random, and sampling rather than the other way around.

8. **Top-level executable**
   `IBE.cc` is the entry point / driver. It likely wires together parameter initialization, setup, test vectors or demonstrations, and invokes the scheme operations. In architectural terms, it is the application shell around the cryptographic core.

9. **Input/output boundary**
   `io.cc/.h` is a utility layer for reading/writing values, vectors, or scheme artifacts. It is not the main business logic, but it forms the boundary between internal cryptographic objects and external representation.

10. **Data flow through the system**
   The typical flow is: compile-time parameters from `params.h` define the lattice instance; `IBE.cc` drives execution; `Scheme` calls into `Sampling` and `Random` to generate secrets or masks; `Scheme` and `Algebra` use `FFT`-accelerated arithmetic to manipulate lattice elements; results are emitted through `io`.

11. **Architectural boundaries to draw**
   For a diagram, the most important separation is between:
   - **Driver / executable** (`IBE.cc`)
   - **Protocol layer** (`Scheme`)
   - **Mathematical primitives** (`Algebra`, `FFT`)
   - **Randomness / sampling** (`Random`, `Sampling`)
   - **Serialization / I/O** (`io`)
   - **Static configuration** (`params.h`)
   External libraries (**GMP**, **NTL**) sit beneath the math layer as foundational dependencies.

12. **Practical characterization**
   This is a research implementation, not production crypto infrastructure. There are no network services, databases, or background workers; the architecture is a deterministic computation pipeline with a heavy reliance on numerical libraries and fixed parameters.

Main entry points: [`Algebra.cc`](https://github.com/panosvl/lattice-ibe-optimizations/blob/master/Algebra.cc) (Algebra), [`Scheme.cc`](https://github.com/panosvl/lattice-ibe-optimizations/blob/master/Scheme.cc) (Scheme), [`IBE.cc`](https://github.com/panosvl/lattice-ibe-optimizations/blob/master/IBE.cc) (IBE), [`FFT.cc`](https://github.com/panosvl/lattice-ibe-optimizations/blob/master/FFT.cc) (FFT)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_build["Build & entry"]
  node_n_make["Makefile<br/>build"]
  node_n_ibe["IBE<br/>driver<br/>[IBE.cc]"]
end

subgraph group_g_proto["IBE protocol"]
  node_n_scheme["Scheme<br/>protocol<br/>[Scheme.cc]"]
  node_n_setup(("Setup<br/>scheme-stage"))
  node_n_keygen(("Key extract<br/>scheme-stage"))
  node_n_encrypt(("Encrypt<br/>scheme-stage"))
  node_n_decrypt(("Decrypt<br/>scheme-stage"))
end

subgraph group_g_math["Math core"]
  node_n_alg["Algebra<br/>lattice math<br/>[Algebra.cc]"]
  node_n_fft["FFT<br/>accelerator<br/>[FFT.cc]"]
end

subgraph group_g_rand["Randomness"]
  node_n_random["Random<br/>rng<br/>[Random.cc]"]
  node_n_sampling["Sampling<br/>sampler<br/>[Sampling.cc]"]
end

subgraph group_g_support["Support"]
  node_n_params["params<br/>config<br/>[params.h]"]
  node_n_io["I/O<br/>serialization<br/>[io.cc]"]
end

subgraph group_g_ext["External libs"]
  node_n_gmp["GMP<br/>external bigint"]
  node_n_ntl["NTL<br/>external ntt"]
end

node_n_make -->|"builds"| node_n_ibe
node_n_ibe -->|"uses"| node_n_params
node_n_ibe -->|"drives"| node_n_scheme
node_n_ibe -->|"formats"| node_n_io
node_n_scheme -->|"contains"| node_n_setup
node_n_scheme -->|"contains"| node_n_keygen
node_n_scheme -->|"contains"| node_n_encrypt
node_n_scheme -->|"contains"| node_n_decrypt
node_n_setup -->|"uses"| node_n_alg
node_n_keygen -->|"uses"| node_n_sampling
node_n_encrypt -->|"uses"| node_n_random
node_n_encrypt -->|"uses"| node_n_sampling
node_n_encrypt -->|"accelerates"| node_n_fft
node_n_decrypt -->|"uses"| node_n_alg
node_n_alg -->|"delegates"| node_n_fft
node_n_alg -->|"depends on"| node_n_gmp
node_n_alg -->|"depends on"| node_n_ntl
node_n_fft -->|"depends on"| node_n_ntl
node_n_random -->|"depends on"| node_n_gmp
node_n_sampling -->|"depends on"| node_n_random
node_n_io -->|"serializes"| node_n_alg

click node_n_make "https://github.com/panosvl/lattice-ibe-optimizations/tree/master/Makefile"
click node_n_ibe "https://github.com/panosvl/lattice-ibe-optimizations/blob/master/IBE.cc"
click node_n_params "https://github.com/panosvl/lattice-ibe-optimizations/blob/master/params.h"
click node_n_io "https://github.com/panosvl/lattice-ibe-optimizations/blob/master/io.cc"
click node_n_scheme "https://github.com/panosvl/lattice-ibe-optimizations/blob/master/Scheme.cc"
click node_n_alg "https://github.com/panosvl/lattice-ibe-optimizations/blob/master/Algebra.cc"
click node_n_fft "https://github.com/panosvl/lattice-ibe-optimizations/blob/master/FFT.cc"
click node_n_random "https://github.com/panosvl/lattice-ibe-optimizations/blob/master/Random.cc"
click node_n_sampling "https://github.com/panosvl/lattice-ibe-optimizations/blob/master/Sampling.cc"

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_n_make,node_n_ibe toneBlue
class node_n_scheme,node_n_setup,node_n_keygen,node_n_encrypt,node_n_decrypt toneAmber
class node_n_alg,node_n_fft toneMint
class node_n_random,node_n_sampling toneRose
class node_n_params,node_n_io toneIndigo
class node_n_gmp,node_n_ntl toneTeal
```

## Components

### Build & entry

Compilation target and executable entry point

- [Makefile](https://github.com/panosvl/lattice-ibe-optimizations/tree/master/Makefile): build · Builds the single IBE executable and wires source dependencies · `Makefile`
- [IBE](https://github.com/panosvl/lattice-ibe-optimizations/blob/master/IBE.cc): driver · Program entry point and top-level execution flow · `IBE.cc`

### IBE protocol

High-level cryptographic operations

- [Scheme](https://github.com/panosvl/lattice-ibe-optimizations/blob/master/Scheme.cc): protocol · Main IBE protocol layer coordinating setup, key extraction, encryption, and decryption · `Scheme.cc`
- **Setup**: scheme-stage · Initializes public parameters and master secrets
- **Key extract**: scheme-stage · Derives identity-bound private keys
- **Encrypt**: scheme-stage · Encodes plaintexts into ciphertexts for an identity
- **Decrypt**: scheme-stage · Recovers plaintexts from ciphertexts using identity keys

### Math core

Lattice and polynomial arithmetic

- [Algebra](https://github.com/panosvl/lattice-ibe-optimizations/blob/master/Algebra.cc): lattice math · Core polynomial and ring arithmetic primitives · `Algebra.cc`
- [FFT](https://github.com/panosvl/lattice-ibe-optimizations/blob/master/FFT.cc): accelerator · Fast transform machinery for polynomial operations · `FFT.cc`

### Randomness

Entropy and discrete sampling

- [Random](https://github.com/panosvl/lattice-ibe-optimizations/blob/master/Random.cc): rng · Entropy source and pseudorandom generation wrapper · `Random.cc`
- [Sampling](https://github.com/panosvl/lattice-ibe-optimizations/blob/master/Sampling.cc): sampler · Discrete sampling routines for lattice cryptography · `Sampling.cc`

### Support

Configuration and I/O boundary

- [params](https://github.com/panosvl/lattice-ibe-optimizations/blob/master/params.h): config · Compile-time lattice parameters and scheme tunables · `params.h`
- [I/O](https://github.com/panosvl/lattice-ibe-optimizations/blob/master/io.cc): serialization · Reads and writes scheme values and artifacts · `io.cc`

### External libs

Foundational third-party number theory dependencies

- **GMP**: external bigint · Big integer arithmetic dependency
- **NTL**: external ntt · Number theory and polynomial algebra dependency

## Connections

- Makefile → IBE: builds · Compiles the executable from the source files
- IBE → params: uses · Runs with fixed compile-time dimensions and modulus
- IBE → Scheme: drives · Main driver invokes the cryptographic workflow
- IBE → I/O: formats · Uses I/O helpers for external representation
- Scheme → Setup: contains · Protocol setup stage
- Scheme → Key extract: contains · Identity key extraction stage
- Scheme → Encrypt: contains · Encryption stage
- Scheme → Decrypt: contains · Decryption stage
- Setup → Algebra: uses · Builds scheme objects from core arithmetic
- Key extract → Sampling: uses · Samples secret material
- Encrypt → Random: uses · Generates randomness and masks
- Encrypt → Sampling: uses · Samples noise and short vectors
- Encrypt → FFT: accelerates · Uses fast transforms for polynomial multiplication
- Decrypt → Algebra: uses · Applies ring arithmetic during recovery
- Algebra → FFT: delegates · Relies on FFT-backed polynomial operations
- Algebra → GMP: depends on · Uses big integer support
- Algebra → NTL: depends on · Uses number theory primitives
- FFT → NTL: depends on · Builds on NTL polynomial machinery
- Random → GMP: depends on · Uses external big integer support where needed
- Sampling → Random: depends on · Draws entropy from the RNG layer
- I/O → Algebra: serializes · Converts algebraic objects to and from text or binary forms
