name: implementing-zero-knowledge-proof-for-authentication description: Zero-Knowledge Proofs (ZKPs) allow a prover to demonstrate knowledge of a secret (such as a password or private key) without revealing the secret itself. This skill implements the Schnorr identificati domain: cybersecurity subdomain: cryptography tags:
- cryptography
- zero-knowledge-proof
- authentication
- privacy
- zkp version: '1.0' author: mahipal license: Apache-2.0 nist_csf:
- PR.DS-01
- PR.DS-02
- PR.DS-10
Implementing Zero-Knowledge Proof for Authentication
Overview
Zero-Knowledge Proofs (ZKPs) allow a prover to demonstrate knowledge of a secret (such as a password or private key) without revealing the secret itself. This skill implements the Schnorr identification protocol and a simplified ZKPP (Zero-Knowledge Password Proof) using the discrete logarithm problem, enabling authentication where the server never learns the user's password.
When to Use
- When deploying or configuring implementing zero knowledge proof for authentication capabilities in your environment
- When establishing security controls aligned to compliance requirements
- When building or improving security architecture for this domain
- When conducting security assessments that require this implementation
Common Misconfigurations & Verification
- Predictable challenge / nonce reuse: in Schnorr, reusing the commitment randomness
racross two challenges leaks the secretxviax = (s1 - s2)/(c1 - c2). Generaterfrom a CSPRNG per proof and never reuse it. Verify two runs produce differenttvalues. - Weak Fiat-Shamir transcript: the non-interactive challenge must hash the full transcript including the public key and commitment (
c = H(g, y, t, msg)), not justt— otherwise proofs are forgeable or transferable. Use a collision-resistant hash. - Verifier-chosen challenge skipped / replay: without binding to a fresh server nonce or message, a captured transcript can be replayed. Include a server-supplied challenge or message and reject duplicates.
- Insecure group parameters: use a safe prime
pand prime-order subgroupq; validate thatylies in the correct subgroup to avoid small-subgroup attacks. - Secret transmitted or logged: confirm the server never receives or stores
x. - Mandatory tests: (1) honest prover always verifies (completeness); (2) a random/forged response without
xfails verification (soundness); (3) the server transcript never contains the secret (zero-knowledge); (4) repeated authentications yield distinct transcripts; (5) a replayed transcript is rejected.
Prerequisites
- Familiarity with cryptography concepts and tools
- Access to a test or lab environment for safe execution
- Python 3.8+ with required dependencies installed
- Appropriate authorization for any testing activities
Objectives
- Implement Schnorr's identification protocol for ZKP authentication
- Build a non-interactive ZKP using Fiat-Shamir heuristic
- Implement zero-knowledge password proof (ZKPP)
- Demonstrate completeness, soundness, and zero-knowledge properties
- Compare ZKP authentication with traditional password verification
Key Concepts
ZKP Properties
| Property | Description |
|---|---|
| Completeness | Honest prover always convinces honest verifier |
| Soundness | Dishonest prover cannot convince verifier (except negligible probability) |
| Zero-Knowledge | Verifier learns nothing beyond the statement's truth |
Schnorr Protocol
- Setup: Public generator g, prime p, q (order of g)
- Registration: Prover computes y = g^x mod p (public key from secret x)
- Commitment: Prover sends t = g^r mod p (random r)
- Challenge: Verifier sends random c
- Response: Prover sends s = r + c*x mod q
- Verify: Check g^s == t * y^c mod p
Security Considerations
- Use cryptographically secure random number generators
- Challenge must be unpredictable (from verifier's perspective)
- For non-interactive proofs, use Fiat-Shamir with collision-resistant hash
- ZKP alone does not provide forward secrecy; combine with TLS
Validation Criteria
- Honest prover always verifies successfully (completeness)
- Random response without secret does not verify (soundness)
- Server never receives the secret value
- Non-interactive proof is verifiable offline
- Multiple authentications produce different transcripts
- Protocol resists replay attacks