| Crates.io | chaum-pedersen-zkp |
| lib.rs | chaum-pedersen-zkp |
| version | 1.0.0 |
| created_at | 2025-11-28 05:59:02.295686+00 |
| updated_at | 2025-11-28 05:59:02.295686+00 |
| description | Chaum-Pedersen zero-knowledge protocol implementation |
| homepage | https://github.com/kobby-pentangeli/chaum-pedersen-zkp |
| repository | https://github.com/kobby-pentangeli/chaum-pedersen-zkp |
| max_upload_size | |
| id | 1954890 |
| size | 339,717 |
Rust implementation of the Chaum-Pedersen Zero-Knowledge Proof protocol for password-based authentication without storing passwords.
This implementation allows a prover (client) to demonstrate knowledge of a secret discrete logarithm x such that y1 = g^x and y2 = h^x without revealing x to the verifier (server). The server never stores passwords, only public statements (y1, y2).
Key Features:
src/
├── primitives/ # Core cryptographic primitives
│ ├── ristretto.rs # Ristretto255 group implementation
│ ├── rng.rs # Secure random number generator
│ ├── gadgets.rs # Parameters, Statement, Witness, Proof
│ └── transcript.rs # Fiat-Shamir transform
├── prover/ # Client-side proof generation
├── verifier/ # Server-side proof verification
│ ├── config.rs # Configuration with .env support
│ ├── service.rs # gRPC service implementation
│ ├── batch.rs # Batch verification
│ └── state.rs # Server state management
└── bin/
├── client.rs # Interactive CLI client (prover)
└── server.rs # Interactive gRPC server (verifier)
Required:
protoc)Install protoc:
# macOS
brew install protobuf
# Ubuntu/Debian
sudo apt-get install protobuf-compiler
# Arch Linux
sudo pacman -S protobuf
# Windows
choco install protoc
# Clone repository
git clone https://github.com/kobby-pentangeli/chaum-pedersen-zkp.git
cd chaum-pedersen-zkp
# Build all features (server + client)
cargo build --release --all-features
# Build library only
cargo build --release
# Build server only
cargo build --release --bin server --features server
# Build client only
cargo build --release --bin client --features client
Basic protocol usage:
cargo run --example hello_world
Authentication system simulation:
cargo run --example auth_system
The server provides an interactive REPL for monitoring and management while handling gRPC requests.
Start the server:
cargo run --release --bin server --features server
With custom options:
cargo run --release --bin server --features server -- \
--host 0.0.0.0 \
--port 50051 \
--rate-limit 100 \
--rate-burst 50 \
--metrics
Server REPL commands:
+---------------------------------------------------------+
| Chaum-Pedersen ZKP Authentication Server |
+---------------------------------------------------------+
Server starting on 127.0.0.1:50051
Rate limit: 100 req/min, burst: 50
Metrics: disabled
Health check: enabled
Type /help for available commands or /quit to exit
zkp-server@127.0.0.1:50051> /help
Available Commands:
/status - Show server status and configuration
/users - List registered users count
/sessions - List active sessions count
/challenges - List pending challenges count
/cleanup - Force cleanup of expired state
/help - Show this help message
/quit or /exit - Initiate graceful shutdown
Environment variables (optional):
SERVER_HOST=127.0.0.1 # Bind address
SERVER_PORT=50051 # gRPC port
METRICS_ENABLED=true # Enable Prometheus metrics
METRICS_PORT=9090 # Metrics endpoint port
RATE_LIMIT_RPM=100 # Requests per minute
RATE_LIMIT_BURST=50 # Burst capacity
The client provides an interactive REPL for registration and authentication.
Start the client:
cargo run --release --bin client --features client
Connect to custom server:
cargo run --release --bin client --features client -- --server http://192.168.1.100:50051
Client REPL commands:
+---------------------------------------------------------+
| Chaum-Pedersen ZKP Authentication Client |
+---------------------------------------------------------+
Connecting to http://127.0.0.1:50051...
Connected successfully
Type /help for available commands or /quit to exit
zkp-client@http://127.0.0.1:50051> /help
Available Commands:
/register <user> <pass> - Register a new user
/login <user> <pass> - Authenticate (prove knowledge of password)
/batch-register <u1,u2> <p1,p2> - Batch register multiple users
/batch-login <u1,u2> <p1,p2> - Batch authenticate multiple users
/status - Show connection status
/help - Show this help message
/quit or /exit - Exit gracefully
Examples:
/register alice secretpass123
/login alice secretpass123
/batch-register alice,bob pass1,pass2
/batch-login alice,bob pass1,pass2
Example session:
zkp-client@http://127.0.0.1:50051> /register alice mypassword
Registered: User 'alice' registered
zkp-client@http://127.0.0.1:50051> /login alice mypassword
Challenge received, expires: 1732409876
Authenticated: Proof verified successfully
Session token: a1b2c3d4e5f6...
zkp-client@http://127.0.0.1:50051> /batch-register bob,charlie pass1,pass2
Registering 2 users...
[OK] bob: User 'bob' registered
[OK] charlie: User 'charlie' registered
Batch complete: 2/2 registered
zkp-client@http://127.0.0.1:50051> /quit
Goodbye!
# Format with `rustfmt.toml`
cargo +nightly fmt
# Linting
cargo clippy --all-targets --all-features
# Testing
cargo test --all-features
# Testing with progress output (useful for long-running batch tests)
cargo test --all-features -- --nocapture
# Benchmarking
# Run all benchmarks
cargo bench
# Specific benchmark
cargo bench ristretto_proof_generation
# Fuzzing
# Install fuzzer (requires nightly)
cargo install cargo-fuzz
# Fuzz proof deserialization
cargo +nightly fuzz run fuzz_proof_deserialization
# Run for 10 minutes
cargo +nightly fuzz run fuzz_proof_deserialization -- -max_total_time=600
# Use multiple cores
cargo +nightly fuzz run fuzz_proof_deserialization -- -jobs=4
use chaum_pedersen::{
Ristretto255, SecureRng, Parameters, Witness, Statement,
Prover, Verifier, Transcript
};
// Setup parameters
let params = Parameters::new();
let mut rng = SecureRng::new();
// Prover: Generate secret and create statement
let x = Ristretto255::random_scalar(&mut rng);
let witness = Witness::new(x);
let statement = Statement::from_witness(¶ms, &witness);
// Prover: Generate proof (Fiat-Shamir)
let mut transcript = Transcript::new();
let proof = Prover::new(params.clone(), witness)
.prove_with_transcript(&mut rng, &mut transcript)
.unwrap();
// Verifier: Verify the proof
let mut verify_transcript = Transcript::new();
let verifier = Verifier::new(params, statement);
assert!(verifier.verify_with_transcript(&proof, &mut verify_transcript).is_ok());
use chaum_pedersen::Proof;
// Prover: Commitment phase
let prover = Prover::new(params.clone(), witness);
let (commitment, nonce) = prover.commit(&mut rng);
// Verifier: Challenge (can be sent over network)
let challenge = Ristretto255::random_scalar(&mut rng);
// Prover: Response phase
let response = prover.respond(&nonce, &challenge);
let proof = Proof::new(commitment, response);
// Verifier: Verification
let verifier = Verifier::new(params, statement);
assert!(verifier.verify_response(&challenge, &proof).is_ok());
Batch verification provides 30-50% better performance when verifying multiple proofs:
use chaum_pedersen::BatchVerifier;
// Create batch verifier
let mut batch_verifier = BatchVerifier::new();
// Add multiple proofs to batch
for i in 0..10 {
let x = Ristretto255::random_scalar(&mut rng);
let witness = Witness::new(x);
let prover = Prover::new(params.clone(), witness);
let statement = prover.statement().clone();
let mut transcript = Transcript::new();
transcript.append_context(format!("user-{}", i).as_bytes());
let proof = prover.prove_with_transcript(&mut rng, &mut transcript).unwrap();
// Add to batch with context binding
batch_verifier.add_with_context(
params.clone(),
statement,
proof,
Some(format!("user-{}", i).into_bytes())
).unwrap();
}
// Verify entire batch at once (single multi-scalar multiplication)
let results = batch_verifier.verify(&mut rng).unwrap();
// Check individual results
for (i, result) in results.iter().enumerate() {
assert!(result.is_ok(), "Proof {} should be valid", i);
}
[features]
default = []
grpc = ["tonic", "prost", "tokio"] # gRPC support
server = ["grpc", "tonic-health", "tower", "metrics", "crossterm", "clap", "tracing"]
client = ["grpc", "clap", "argon2", "crossterm", "tracing"]
Build examples:
# Library only (no network)
cargo build
# Server with gRPC
cargo build --features server
# Client with gRPC
cargo build --features client
# Both
cargo build --all-features
Contributions welcome! Please:
cargo test --all-featurescargo clippy --all-features -- -D warningscargo +nightly fmtLicensed under either of:
at your option.
Built with: