Python implementation of the Chaum-Pedersen Zero-Knowledge Proof authentication system.
- Zero-Knowledge Authentication: Server verifies user identity without learning the password
- Chaum-Pedersen Protocol: Non-interactive proofs via Fiat-Shamir transform
- RESTful API: Flask-based HTTP server with session management
- CLI Client: Easy-to-use command-line interface
- Pure Python: No external cryptographic libraries needed for core ZKP operations
- Python 3.8 or higher
- pip (Python package manager)
cd python
pip install -r requirements.txtOr install in development mode:
cd python
pip install -e .# From the python directory
cd server
python main.py
# Specify custom port and database
python main.py --port 9000 --db custom_users.db
# Use 4096-bit parameters (generation mode)
python main.py --bits 4096 --params-mode generate
# Show help
python main.py --helpcd client
python cli_client.py register alice mypassword123python cli_client.py login alice mypassword123This will return a session token.
python cli_client.py verify <your-session-token>python cli_client.py register alice password --host 192.168.1.100 --port 9000
python cli_client.py login alice password --host 192.168.1.100 --port 9000cd python
pytest tests/Or with verbose output:
pytest -v tests/Same across all implementations:
GET /params- Fetch group parametersp, q, g, h(hex)POST /register- Register by submitting client-computedy1, y2, saltPOST /challenge- Request a one-timenoncefor authenticationPOST /authenticate- Submit proof{a1, a2, s, nonce}to obtain a tokenGET /verify- Verify session token
See the main API documentation in ../docs/API.md for details.
python/
├── zkp/
│ ├── __init__.py
│ └── chaum_pedersen.py # Core ZKP implementation
├── db/
│ ├── __init__.py
│ └── user_database.py # SQLite database layer
├── server/
│ ├── __init__.py
│ ├── auth_server.py # Flask REST API server
│ └── main.py # Server entry point
├── client/
│ ├── __init__.py
│ └── cli_client.py # CLI client
├── tests/
│ └── test_zkp.py # Test suite
├── requirements.txt
├── setup.py
└── README.md
- Safe Prime Generation: Uses
sympylibrary for prime number generation - HTTP Server: Uses Flask instead of cpp-httplib
- Simplicity: Pure Python implementation without external crypto libraries
- Performance: Slower prime generation but easier to understand and modify
- 2048-bit safe prime generation
- Random salt per user (256-bit)
- SHA-256 for hashing and challenge computation
- Timestamp validation (5-minute window)
- Session expiry (1 hour)
- No password storage or transmission
Initial startup may take some time (30-60 seconds) while generating the 2048-bit safe prime parameters. This is a one-time operation per server instance. For practical scenarios or use, consider:
- Pre-generating parameters and storing them
- Using smaller primes for testing (e.g., 1024-bit)
- Implementing parameter caching
# Terminal 1: Start server
cd python/server
python main.py
# Wait for "Server starting on port 8080..." message
# Terminal 2: Use client
cd python/client
# Register
python cli_client.py register alice secret123
# Output: Success: User registered successfully
# Login
python cli_client.py login alice secret123
# Output:
# Success: Authentication successful
# Token: a1b2c3d4e5f6...
# Verify
python cli_client.py verify a1b2c3d4e5f6...
# Output:
# Success: Session is valid
# Valid: True# Install in editable mode
pip install -e .
# Run server
zkp-server --port 8080
# Run client
zkp-client register alice passwordThe modular structure makes it easy to extend:
- Add new endpoints in
server/auth_server.py - Extend ZKP functionality in
zkp/chaum_pedersen.py - Add database methods in
db/user_database.py
Make sure you're running from the correct directory or install the package:
pip install -e .The first time you start the server, it generates 2048-bit safe primes which can take 30-60 seconds. This is normal and only happens once per server startup.
Make sure the server is running and listening on the correct port.
This project was developed as POC for research purposes.
- Chaum, D., & Pedersen, T. P. (1992). "Wallet databases with observers"
- Fiat, A., & Shamir, A. (1986). "How to prove yourself: Practical solutions to identification and signature problems"