This is an educational implementation of a zero-knowledge proof (ZKP) system for discrete logarithms, based on the Schnorr identification protocol. This code demonstrates how a prover can convince a verifier that they know a secret value x
(the discrete logarithm) without revealing x
itself.
This is my solution to https://hackmd.io/@gubsheep/Hy57lluOs
Discrete Logarithm Problem: Given values g
, y
, and p
, find x
such that y = g^x mod p
. This is computationally difficult for large primes p
.
Zero-Knowledge Proof: A method where one party (prover) proves to another party (verifier) that they know a value x
without conveying any information about x
apart from the fact that they know it.
This implementation has several limitations that make it educational but not suitable for production use:
-
1-bit Challenge: With only a single-bit challenge, an impersonator has a 50% chance of successfully creating a valid proof without knowing
x
(whenb = 0
). A secure implementation would use multiple rounds or a larger challenge space. -
Key Size: The prime
p
is relatively small. For real-world applications, much larger primes would be needed. -
Random Number Generation: While
/dev/urandom
is used, a production system would need more careful treatment of randomness.
gcc -o zkp zkp.c
./zkp