# afdursun/kyber-pake-c architecture

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

- Interactive diagram: https://gitdiagram.com/afdursun/kyber-pake-c
- Repository: https://github.com/afdursun/kyber-pake-c

## Overview

Kyber.PAKE extends Kyber’s lattice-based key encapsulation with password-based authentication, explicit mutual authentication, and a shared session key. The documented user-to-result workflow is a four-stage exchange—client C0, server S0, client C1, server S1—across three flows. The sampled protocol source shows password-derived polynomial material, Kyber key/ciphertext operations, and verification; the README documents the phase sequence. The graph also includes the CPA-Kyber and arithmetic/hash layers. S1’s implementation details and some protocol transitions are not visible in the excerpts, so those links are documented rather than inferred from code.

Main entry points: [`indcpa.c`](https://github.com/afdursun/kyber-pake-c/blob/main/indcpa.c) (CPA Encryption), [`kyber-pake.c`](https://github.com/afdursun/kyber-pake-c/blob/main/kyber-pake.c) (Client C0), [`poly.c`](https://github.com/afdursun/kyber-pake-c/blob/main/poly.c) (Polynomial Ops), [`symmetric.h`](https://github.com/afdursun/kyber-pake-c/blob/main/symmetric.h) (Symmetric API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_protocol["PAKE Protocol"]
  node_c0["Client C0<br/>[kyber-pake.c]"]
  node_s0["Server S0<br/>[kyber-pake.c]"]
  node_c1["Client C1<br/>[kyber-pake.c]"]
  node_s1["Server S1<br/>[kyber-pake.c]"]
  node_password["Password Mapping<br/>[kyber-pake.c]"]
end

subgraph group_kem["Kyber KEM"]
  node_indcpa["CPA Encryption<br/>[indcpa.c]"]
  node_kemops["KEM Operations<br/>[kyber-pake.c]"]
end

subgraph group_math["Lattice Arithmetic"]
  node_polynomial["Polynomial Ops<br/>[poly.c]"]
  node_vectors["Polynomial Vectors<br/>[polyvec.c]"]
  node_ntt["NTT Arithmetic<br/>[ntt.c]"]
  node_reduction["Modular Reduction<br/>[reduce.c]"]
  node_noise["Noise Sampling<br/>[cbd.c]"]
end

subgraph group_crypto["Crypto Primitives"]
  node_symmetric["Symmetric API<br/>[symmetric.h]"]
  node_shake["SHAKE / SHA-3<br/>[fips202.c]"]
  node_aes["AES-CTR<br/>[aes256ctr.c]"]
  node_sha2["SHA-2<br/>[sha256.c]"]
  node_rng["Random Bytes<br/>[randombytes.c]"]
  node_verify["Verification<br/>[verify.c]"]
end

node_client(("Client"))
node_server(("Server"))

node_client -->|"starts exchange"| node_c0
node_c0 -->|"sends flow"| node_server
node_server -->|"handles flow"| node_s0
node_s0 -->|"sends flow"| node_client
node_client -->|"continues exchange"| node_c1
node_c1 -->|"sends flow"| node_server
node_server -->|"handles flow"| node_s1
node_c0 -->|"derives password material"| node_password
node_c0 -->|"requests random bytes"| node_rng
node_c0 -->|"generates CPA keypair"| node_indcpa
node_s0 -->|"encapsulates key"| node_kemops
node_c1 -->|"decapsulates key"| node_kemops
node_c1 -->|"checks received data"| node_verify
node_kemops -->|"encrypts and decrypts"| node_indcpa
node_indcpa -->|"uses polynomial ops"| node_polynomial
node_indcpa -->|"uses vector ops"| node_vectors
node_indcpa -->|"uses symmetric API"| node_symmetric
node_indcpa -->|"samples key seed"| node_rng
node_polynomial -->|"transforms coefficients"| node_ntt
node_polynomial -->|"samples coefficients"| node_noise
node_polynomial -->|"uses PRF"| node_symmetric
node_vectors -->|"operates on polynomials"| node_polynomial
node_ntt -->|"reduces values"| node_reduction
node_symmetric -->|"selects SHAKE backend"| node_shake
node_symmetric -->|"selects AES backend"| node_aes
node_symmetric -->|"selects SHA-2 backend"| node_sha2

click node_c0 "https://github.com/afdursun/kyber-pake-c/blob/main/kyber-pake.c"
click node_s0 "https://github.com/afdursun/kyber-pake-c/blob/main/kyber-pake.c"
click node_c1 "https://github.com/afdursun/kyber-pake-c/blob/main/kyber-pake.c"
click node_s1 "https://github.com/afdursun/kyber-pake-c/blob/main/kyber-pake.c"
click node_password "https://github.com/afdursun/kyber-pake-c/blob/main/kyber-pake.c"
click node_indcpa "https://github.com/afdursun/kyber-pake-c/blob/main/indcpa.c"
click node_kemops "https://github.com/afdursun/kyber-pake-c/blob/main/kyber-pake.c"
click node_polynomial "https://github.com/afdursun/kyber-pake-c/blob/main/poly.c"
click node_vectors "https://github.com/afdursun/kyber-pake-c/blob/main/polyvec.c"
click node_ntt "https://github.com/afdursun/kyber-pake-c/blob/main/ntt.c"
click node_reduction "https://github.com/afdursun/kyber-pake-c/blob/main/reduce.c"
click node_noise "https://github.com/afdursun/kyber-pake-c/blob/main/cbd.c"
click node_symmetric "https://github.com/afdursun/kyber-pake-c/blob/main/symmetric.h"
click node_shake "https://github.com/afdursun/kyber-pake-c/blob/main/fips202.c"
click node_aes "https://github.com/afdursun/kyber-pake-c/blob/main/aes256ctr.c"
click node_sha2 "https://github.com/afdursun/kyber-pake-c/blob/main/sha256.c"
click node_rng "https://github.com/afdursun/kyber-pake-c/blob/main/randombytes.c"
click node_verify "https://github.com/afdursun/kyber-pake-c/blob/main/verify.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_c0,node_s0,node_c1,node_s1,node_password,node_client toneBlue
class node_indcpa,node_kemops toneAmber
class node_polynomial,node_vectors,node_ntt,node_reduction,node_noise,node_server toneMint
class node_symmetric,node_shake,node_aes,node_sha2,node_rng,node_verify toneRose
```

## Components

### PAKE Protocol

- [Client C0](https://github.com/afdursun/kyber-pake-c/blob/main/kyber-pake.c): `kyber-pake.c`
- [Server S0](https://github.com/afdursun/kyber-pake-c/blob/main/kyber-pake.c): `kyber-pake.c`
- [Client C1](https://github.com/afdursun/kyber-pake-c/blob/main/kyber-pake.c): `kyber-pake.c`
- [Server S1](https://github.com/afdursun/kyber-pake-c/blob/main/kyber-pake.c): `kyber-pake.c`
- [Password Mapping](https://github.com/afdursun/kyber-pake-c/blob/main/kyber-pake.c): `kyber-pake.c`

### Kyber KEM

- [CPA Encryption](https://github.com/afdursun/kyber-pake-c/blob/main/indcpa.c): `indcpa.c`
- [KEM Operations](https://github.com/afdursun/kyber-pake-c/blob/main/kyber-pake.c): `kyber-pake.c`

### Lattice Arithmetic

- [Polynomial Ops](https://github.com/afdursun/kyber-pake-c/blob/main/poly.c): `poly.c`
- [Polynomial Vectors](https://github.com/afdursun/kyber-pake-c/blob/main/polyvec.c): `polyvec.c`
- [NTT Arithmetic](https://github.com/afdursun/kyber-pake-c/blob/main/ntt.c): `ntt.c`
- [Modular Reduction](https://github.com/afdursun/kyber-pake-c/blob/main/reduce.c): `reduce.c`
- [Noise Sampling](https://github.com/afdursun/kyber-pake-c/blob/main/cbd.c): `cbd.c`

### Crypto Primitives

- [Symmetric API](https://github.com/afdursun/kyber-pake-c/blob/main/symmetric.h): `symmetric.h`
- [SHAKE / SHA-3](https://github.com/afdursun/kyber-pake-c/blob/main/fips202.c): `fips202.c`
- [AES-CTR](https://github.com/afdursun/kyber-pake-c/blob/main/aes256ctr.c): `aes256ctr.c`
- [SHA-2](https://github.com/afdursun/kyber-pake-c/blob/main/sha256.c): `sha256.c`
- [Random Bytes](https://github.com/afdursun/kyber-pake-c/blob/main/randombytes.c): `randombytes.c`
- [Verification](https://github.com/afdursun/kyber-pake-c/blob/main/verify.c): `verify.c`

### Other components

- **Client**
- **Server**

## Connections

- Client → Client C0: starts exchange (evidence: `README.md`)
- Client C0 → Server: sends flow (evidence: `README.md`)
- Server → Server S0: handles flow (evidence: `README.md`)
- Server S0 → Client: sends flow (evidence: `README.md`)
- Client → Client C1: continues exchange (evidence: `README.md`)
- Client C1 → Server: sends flow (evidence: `README.md`)
- Server → Server S1: handles flow (evidence: `README.md`)
- Client C0 → Password Mapping: derives password material (evidence: `kyber-pake.c`)
- Client C0 → Random Bytes: requests random bytes (evidence: `kyber-pake.c`)
- Client C0 → CPA Encryption: generates CPA keypair (evidence: `kyber-pake.c`)
- Server S0 → KEM Operations: encapsulates key (evidence: `kyber-pake.c`)
- Client C1 → KEM Operations: decapsulates key (evidence: `kyber-pake.c`)
- Client C1 → Verification: checks received data (evidence: `kyber-pake.c`)
- KEM Operations → CPA Encryption: encrypts and decrypts (evidence: `kyber-pake.c`)
- CPA Encryption → Polynomial Ops: uses polynomial ops (evidence: `indcpa.c`)
- CPA Encryption → Polynomial Vectors: uses vector ops (evidence: `indcpa.c`)
- CPA Encryption → Symmetric API: uses symmetric API (evidence: `indcpa.c`)
- CPA Encryption → Random Bytes: samples key seed (evidence: `indcpa.c`)
- Polynomial Ops → NTT Arithmetic: transforms coefficients (evidence: `poly.c`)
- Polynomial Ops → Noise Sampling: samples coefficients (evidence: `poly.c`)
- Polynomial Ops → Symmetric API: uses PRF (evidence: `poly.c`)
- Polynomial Vectors → Polynomial Ops: operates on polynomials (evidence: `polyvec.c`)
- NTT Arithmetic → Modular Reduction: reduces values (evidence: `ntt.c`)
- Symmetric API → SHAKE / SHA-3: selects SHAKE backend
- Symmetric API → AES-CTR: selects AES backend
- Symmetric API → SHA-2: selects SHA-2 backend (evidence: `symmetric.h`)
