Quantum-Resistant-Module-Lattice-Cryptography

πŸ›‘οΈ PQ-BANK: Quantum-Resistant Wallet & Key Management System (Lattice Based Cryptography)

GitHub Stars Rust PQC License

A Modern Demonstration of Module-Lattice Cryptography in Rust

A demonstration of lattice-based Post-Quantum Cryptography (PQC) β€” Kyber KEM for key exchange and Dilithium for signatures β€” combined with modern symmetric envelopes, secure wallet storage, and a tamper-proof audit chain. Built in Rust with an eframe/egui GUI and a local server thread for realistic workflows.


Image

Image

Image

Image


✨ Executive summary

PQ-BANK is a real-world Rust application demonstrating how to protect banking records, transaction payloads and crypto wallets against future quantum threats using lattice-based PQC (Kyber + Dilithium), AEAD envelopes (XChaCha20-Poly1305) and secure key handling patterns with a polished GUI and auditability baked in.


Table of contents

  1. Motivation & Value
  2. Architecture & Components
  3. Cryptography Deep-Dive (intuitive + technical)
    • PQC: what & why
    • Lattice-based cryptography (intuitive)
    • Kyber (KEM) & Dilithium (signatures) β€” how we use them
    • Hybrid envelope pattern (HKDF + XChaCha20-Poly1305)
    • Password/wallet protection (Argon2id)
  4. Threat model & security considerations
  5. Project layout & files to include in repo
  6. Quickstart: build & run (copy-paste commands)
  7. How to test & example inputs
  8. Developer notes: extend to production
  9. FAQ / common troubleshooting
  10. License & contribution

Motivation & Value

Quantum computers pose a threat to common asymmetric cryptography (RSA, ECC). Organisations that handle financial or identity data must be crypto-agile and begin integrating PQC now. This project demonstrates practical engineering, showcasing how PQC primitives integrate into a secure application stack, how to combine them with symmetric primitives, and how to enhance user experience and auditability through cryptography.


Architecture & Components

Image

Key flows:


Cryptography deep-dive β€” intuitive + technical

This section explains the primitives, why they were chosen, and how they’re applied.

1) Post-Quantum Cryptography (PQC) β€” what & why (intuitive)

Image


2) Lattice-Based Cryptography

Analogy: imagine trying to find the smallest indentation in a huge, noisy multi-dimensional mattress β€” that’s computationally expensive, and quantum computers don’t give an arithmetic shortcut as they do for factoring.

Image


3) Kyber (KEM) β€” how it’s used

Why KEM? It provides forward secrecy per session and avoids classical Diffie–Hellman constructs that are not quantum-safe.


4) Dilithium (Signatures) β€” how it’s used

Why Dilithium? It provides strong post-quantum message integrity and non-repudiation.


5) Hybrid envelope: HKDF + XChaCha20-Poly1305

We follow the envelope pattern:

  1. shared_secret (Kyber) β†’ session_key by HKDF(SHA256).
  2. session_key (32 bytes) used with XChaCha20-Poly1305 AEAD:

    • Nonce: 24 bytes (random XNonce).
    • Ciphertext = AEAD.encrypt(nonce, plaintext, associated_data)
    • Store nonce||ct + metadata in encrypted envelope.

Why this approach?


6) Password & wallet protection (Argon2id + salt)


Threat model & security considerations

Assumptions

Adversary capabilities considered

What this design defends

Limitations / what we do NOT claim


Project layout & files to include in the repo

pqbank/
β”œβ”€ Cargo.toml                # dependency manifest (stable versions only)
β”œβ”€ README.md                 # this file
β”œβ”€ LICENSE
β”œβ”€ .gitignore
β”œβ”€ src/
   β”œβ”€ main.rs                # GUI, app lifecycle, server thread
   └─ wallet.rs              # wallet creation, encrypt/decrypt API

IMPORTANT: add storage/ to .gitignore. Runtime files are created under storage/ only.


Quickstart β€” build & run (copy-paste)

Tested on Rust 1.91.1 (MSVC toolchain on Windows recommended).

# 1. clone
git clone https://github.com/<your-username>/pqbank.git
cd pqbank

# 2. ensure Cargo.toml uses stable versions (no -rc)
# (the repo already contains a tested Cargo.toml)

# 3. clean then build
cargo clean
cargo build --release

# 4. run (GUI)
# Linux / macOS
./target/release/pqbank

# Windows (PowerShell)
.\target\release\pqbank.exe

When launched:


How to test & example inputs

1. Create a wallet (Wallet Manager)

2. Unlock the wallet

3. Send a transaction

4. Upload a sample file

5. Verify logs


Example data formats

Transaction JSON

{
  "amount": 2500,
  "currency": "INR",
  "sender": "sumit_demo",
  "receiver": "ACC5566778899",
  "timestamp": "2025-12-10T14:32:12+05:30"
}

Encrypted envelope (stored on server) β€” conceptual

{
  "id": "file-uuid",
  "nonce": "<base64>",
  "ciphertext": "<base64>",
  "signature": "<base64>",
  "signer_pubkey": "<b64>",
  "meta": { "filename": "receipt.csv", "uploaded_at": "..." }
}

Developer notes β€” how to extend to production (roadmap for reviewers)

A recruiter reading this will want to know you understand the gaps. Suggested roadmap:

  1. Replace local server thread with axum/quinn server (mutual auth + QUIC).
  2. HSM / TPM: move server private keys into hardware keystore (TPM sealed keys or cloud KMS).
  3. Auth layer: OAuth2 / OpenID Connect for users; integrate CSRF/XSRF protections for web clients.
  4. Persistent DB: Postgres for metadata; object store for blobs (S3). Use envelope encryption; only store ciphertext.
  5. TLS / mTLS + hardened networking: apply DDoS protections, rate limiting, TLS cert rotation.
  6. CI/CD + SCA: run cargo audit, clippy, fmt, unit tests, fuzz tests.
  7. Third-party crypto audit + formal verification before any real funds.
  8. Key rotation & backup strategy + secure escrow for emergency recovery.

FAQ & Troubleshooting

Q: I see build errors on Windows related to winapi or eframe

Ans: Make sure Cargo.toml pins eframe = "0.24.1" and includes a winapi override enabling "winuser" features (the repo provides a tested Cargo.toml). Run cargo clean then cargo build.

Q: Why store server keys locally?

Ans: This is a demo. In production, use an HSM or KMS.

Q: Is this production ready?

Ans: No, it demonstrates design and implementation patterns. Production requires audits, HSMs, hardened auth and deployment.


Contributing / Code of Conduct

Contributions welcome! If you contribute:


License

MIT License β€” see LICENSE for full text.