Skip to content

Latest commit

 

History

History
215 lines (167 loc) · 4.83 KB

File metadata and controls

215 lines (167 loc) · 4.83 KB

ZKP Authentication System - C++ Implementation

High-performance C++ implementation of the Chaum-Pedersen Zero-Knowledge Proof authentication system.

Features

  • Fast cryptographic operations using Crypto++
  • 2048-bit safe prime generation
  • SQLite database for user storage
  • RESTful API server using cpp-httplib
  • Low memory footprint (~20MB)
  • Optimal performance for evaluations and integrations

Prerequisites

Ubuntu/Debian

sudo apt-get update
sudo apt-get install -y \
    build-essential \
    cmake \
    libcrypto++-dev \
    libsqlite3-dev \
    libcatch2-dev \
    pkg-config

Fedora/RHEL

sudo dnf install -y \
    gcc-c++ \
    cmake \
    cryptopp-devel \
    sqlite-devel \
    catch-devel \
    pkg-config

Build Instructions

# From the cpp directory
mkdir build && cd build
cmake ..
make -j$(nproc)

This will create:

  • auth_server - Authentication server
  • auth_client - CLI client
  • test_zkp - Test suite (if Catch2 is installed)

Usage

Start the Server

cd build
./auth_server

# With custom options
./auth_server --port 9000 --db custom_users.db

Use the Client

# Register a user
./auth_client register alice password123

# Authenticate
./auth_client login alice password123

# Verify session token
./auth_client verify <token>

# Connect to custom server
./auth_client register alice password --host 192.168.1.100 --port 9000

Run Tests

./test_zkp

# Or using CTest
ctest --output-on-failure

Project Structure

cpp/
├── CMakeLists.txt           # Build configuration
├── src/                     # Source code
│   ├── zkp/                 # Zero-knowledge proof implementation
│   │   ├── chaum_pedersen.hpp
│   │   └── chaum_pedersen.cpp
│   ├── db/                  # Database layer
│   │   ├── user_database.hpp
│   │   └── user_database.cpp
│   ├── server/              # HTTP server
│   │   ├── auth_server.hpp
│   │   ├── auth_server.cpp
│   │   └── main.cpp
│   └── client/              # CLI client
│       └── cli_client.cpp
├── tests/                   # Test suite
│   └── test_zkp.cpp
└── third_party/             # Header-only libraries
    ├── httplib.h
    └── nlohmann/
        └── json.hpp

API Endpoints

  • GET /params - Retrieve group parameters (hex)
  • POST /register - Register by submitting client-computed y1, y2, salt
  • POST /challenge - Obtain a one-time nonce
  • POST /authenticate - Submit {a1, a2, s, nonce} to authenticate
  • GET /verify - Verify session token

See ../docs/API.md for complete API documentation.

Performance

  • Parameter Generation: ~1 second (one-time on startup)
  • Registration: ~0.1 seconds per user
  • Authentication: ~0.1 seconds per request
  • Throughput: ~500 requests/second (concurrent)
  • Memory: ~20 MB resident

Security Features

  1. 2048-bit Safe Primes: p = 2q + 1
  2. Cryptographically Secure RNG: AutoSeededRandomPool
  3. SHA-256 Hashing: For password derivation and challenges
  4. Timestamp Validation: 5-minute window prevents replay attacks
  5. Session Management: 1-hour expiry with secure tokens
  6. Zero-Knowledge: Server never learns passwords

Compilation Flags

The project uses:

  • C++17 standard
  • -Wall -Wextra for warnings
  • Link-time optimization when available

Deployment

Binary Deployment

# Build release version
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)

# Deploy binary
cp auth_server /usr/local/bin/

Docker Deployment

FROM ubuntu:22.04
RUN apt-get update && apt-get install -y libcrypto++ libsqlite3
COPY build/auth_server /app/
WORKDIR /app
CMD ["./auth_server", "--port", "8080"]

Troubleshooting

Build Errors

Problem: Package 'libcrypto++' not found

sudo apt-get install libcrypto++-dev

Problem: fatal error: httplib.h: No such file or directory

cd third_party
curl -L -o httplib.h https://raw.githubusercontent.com/yhirose/cpp-httplib/master/httplib.h

Problem: CMake can't find libraries

# Make sure pkg-config is installed
sudo apt-get install pkg-config

Runtime Errors

Problem: error while loading shared libraries: libcryptopp.so

sudo ldconfig

Problem: Server crashes on startup

  • Check if port 8080 is already in use
  • Ensure write permissions for database file

See Also

  • Python Implementation: ../python/README.md
  • ZKP Theory: ../docs/ZKP_THEORY.md
  • API Documentation: ../docs/API.md
  • Quick Start Guide: ../QUICKSTART.md

References