-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
302 lines (249 loc) · 8.29 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<!DOCTYPE html>
<html>
<head>
<title>Schnorr's Protocol</title>
<meta charset="UTF-8">
<meta name="description" content="Interative Schnorr Protocol Demonstration">
<meta name="keywords" content="HTML,JavaScript,Interactive,Demo,Schnorr,Protocol,Zero-Knowledge,Proof,Example,Completeness,Soundness,Honest,Verifier,Prover,Demonstration,Statement,Witness,Prime,Cyclic,Group,Theory">
<meta name="author" content="Gregory Hill">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-MML-AM_CHTML' async></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
showProcessingMessages: false,
tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] }
});
</script>
<style>
html, body {
margin: 0px;
padding: 0px;
border: 0px;
}
.wrap h1 { text-align: center; }
.wrap .desc { text-align: center; margin-left: 0; padding: 10px; }
.wrap p { margin-left: 25px; }
.wrap label { margin-left: 50px; }
.wrap h2 { margin-left: 25px; }
.wrap h3 { margin-left: 50px; }
.wrap input { margin-bottom: 20px; }
.section { margin-bottom: 25px; padding: 10px; }
#diagram {
width: 80%;
height: 420px;
padding: 10px;
border: 2px solid black;
margin: 0;
margin-left: auto;
margin-right: auto;
}
.arrow {
width:100%;
}
.line {
margin-top: 8px;
width: 95%;
background: black;
height: 3px;
float: left;
}
.lbox {
width: 5%;
float: left;
}
.rbox {
width: 5%;
float: right;
}
.lbox div {
width: 0;
height: 0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-right: 20px solid black;
}
.rbox div {
width: 0;
height: 0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 20px solid black;
}
.column {
float: left;
width: 33.33%;
}
.column h4 { text-align: center; }
.column p {
text-align: center;
margin-bottom: 0px;
}
.full {
width: 100%;
margin: auto;
text-align: center;
margin-top: 20px;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="wrap">
<h1>Schnorr's Protocol</h1>
<p class="desc">A prover $P$ wants to convince a verifier $V$ of some knowledge of a discrete logarithm. The $\Sigma$-protocol (Schnorr) is a three-move protocol that exhibits the properties of zero-knowledge.</p>
<br>
<div class="section">
<h2>Parameters</h2>
<ul>
<li>Both parties hold $\langle\langle p,m,g \rangle, h \rangle$, where:</li>
<ul>
<li>$p$ is a prime number,</li>
<li>$g\in \mathbb{Z}_p^*$,</li>
<li>$h=g^w \; mod \; p$.</li>
</ul>
<li>As $G=\langle g \rangle$ is a cyclic group, $m=ord(g)=p-1$.</li>
<li>Only the prover $P$ holds $w\in \mathbb{Z}_m$ which remains secret.</li>
</ul>
<h3>Public</h3>
<div class="row"><label for="prime">p =</label>
<input id="prime" name="prime" type="number" value="11" onchange="update()"/></div>
<div class="row"><label for="gen">g =</label>
<input id="gen" name="gen" type="number" value="2" onchange="update()"/></div>
<div class="row"><label for="proof">h =</label>
<output id="proof" name="proof"></output></div>
<h3>Private</h3>
<div class="row"><label for="witness">w =</label>
<input id="witness" name="witness" type="number" value="7" onchange="update()"/>
<button onclick="generate('witness')">Generate</button></div>
</div><!-- section end -->
<div class="section">
<h2>Offer</h2>
<p>$P$ selects $t \xleftarrow{r} \mathbb{Z}_m$ and sends $y=g^t \; mod \; p$ to $V$.</p>
<div class="row"><label for="offer_t">t =</label>
<input id="offer_t" name="offer_t" type="number" value="3" onchange="update()"/>
<button onclick="generate('offer_t')">Generate</button></div>
<div class="row"><label for="offer_y">y =</label>
<output id="offer_y" name="offer_y"></output></div>
</div><!-- section end -->
<div class="section">
<h2>Challenge</h2>
<p>$V$ selects $c \xleftarrow{r} \mathbb{Z}_m$ and sends $c$ to $P$.</p>
<div class="row"><label for="challenge">c =</label>
<input id="challenge" name="challenge" type="number" value="3" onchange="update()"/>
<button onclick="generate('challenge')">Generate</button></div>
</div><!-- section end -->
<div class="section">
<h2>Response</h2>
<p>$P$ calculates $s=t+cw \; mod \; m$ and sends $s$ to $V$.</p>
<div class="row"><label for="response">s = </label>
<output id="response" name="response"></output></div>
</div><!-- section end -->
<div class="section">
<h2>Result</h2>
<p>$V$ is convinced if $g^s \; mod \; p = yh^c \; mod \; p$ as:</p>
<p style="width: 30%;">
\[
\begin{align}
g^s & = g^{t+cw} \\
& = g^t \cdot g^{wc} \\
& = g^t \cdot (g^w)^c \\
& = y \cdot h^c \\
\end{align}
\]
</p>
</div><!-- section end -->
</div><!-- wrap end -->
<h1 style="text-align: center;">Demo</h1>
<div id="diagram">
<div class="row">
<div class="column">
<h4>P</h4>
<p id="choose-t">$t \xleftarrow{r} \mathbb{Z}_m$</p>
<p id="choose-y">$y=g^t \; mod \; p$</p>
<br><br><br><br><br><br>
<p id="choose-s">$s=t+cw \; mod \; m$</p>
</div>
<div class="column">
<p id="params">$\langle\langle p,m,g \rangle, h \rangle$</p>
<br><br><br><br>
<div class="arrow">
<p id="send-y">y</p>
<div class="line"></div>
<div class="rbox"><div></div></div>
</div>
<br><br>
<div class="arrow">
<p id="send-c">c</p>
<div class="lbox"><div></div></div>
<div class="line"></div>
</div>
<br><br>
<div class="arrow">
<p id="send-s">s</p>
<div class="line"></div>
<div class="rbox"><div></div></div>
</div>
</div>
<div class="column">
<h4>V</h4>
<br><br><br><br><br><br>
<p id="choose-c">$c \xleftarrow{r} \mathbb{Z}_m$</p>
<br><br><br><br><br>
<p id="compare">$g^s = yh^c$</p>
<p id="result"></p>
</div>
</div>
</div>
<div class="full"><button onclick="calculate()">Compute</button></div>
<br><br><br>
<script>
function generate(location) {
var m = parseInt(document.getElementById("prime").value)-1;
var v = Math.floor((Math.random() * m) + 1)
document.getElementById(location).value = v;
update();
}
function update() {
var g = parseInt(document.getElementById("gen").value);
var w = parseInt(document.getElementById("witness").value);
var p = parseInt(document.getElementById("prime").value);
document.getElementById("proof").value = Math.pow(g, w)%p;
var t = parseInt(document.getElementById("offer_t").value);
document.getElementById("offer_y").value = Math.pow(g, t)%p;
var c = parseInt(document.getElementById("challenge").value);
var m = parseInt(document.getElementById("prime").value) - 1;
document.getElementById("response").value = (t+((c*w)%m));
}
// verify
function calculate() {
var t = parseInt(document.getElementById("offer_t").value);
var m = parseInt(document.getElementById("prime").value)-1;
var w = parseInt(document.getElementById("witness").value);
var g = parseInt(document.getElementById("gen").value);
var s = parseInt(document.getElementById("response").value);
var p = parseInt(document.getElementById("prime").value);
var gs = Math.pow(g,s)%p;
var y = parseInt(document.getElementById("offer_y").value);
var h = parseInt(document.getElementById("proof").value);
var c = parseInt(document.getElementById("challenge").value);
var yhc = (y * Math.pow(h,c))%p;
document.getElementById("params").innerHTML = "$\\langle\\langle "+p+","+m+","+g+" \\rangle, "+h+" \\rangle$";
document.getElementById("choose-t").innerHTML = "$"+t+" \\xleftarrow{r} \\mathbb{Z}\_{"+m+"}$";
document.getElementById("choose-y").innerHTML = "$"+y+"="+g+"^{"+t+"} \\; mod \\; "+p+"$";
document.getElementById("choose-s").innerHTML = "$"+s+"="+t+"+"+c+"\\cdot"+w+" \\; mod \\; "+m+"$";
document.getElementById("send-y").innerHTML = y;
document.getElementById("send-c").innerHTML = c;
document.getElementById("send-s").innerHTML = s;
document.getElementById("choose-c").innerHTML = "$"+c+" \\xleftarrow{r} \\mathbb{Z}\_{"+m+"}$";
document.getElementById("compare").innerHTML = "$"+g+"^"+s+" \\; mod \\; "+p+" = "+y+"\\cdot"+h+"^{"+c+"} \\; mod \\; "+p+"$<br>";
document.getElementById("compare").append("$"+gs+" = "+yhc+"$");
if (gs==yhc) document.getElementById("result").innerHTML = "<font color='green'>Convinced</font>";
else document.getElementById("result").innerHTML = "<font color='red'>Not Convinced</font>";
MathJax.Hub.Queue(['Typeset', MathJax.Hub, document.getElementById("diagram")]);
}
window.addEventListener('load', function () {
update();
}, false);
</script>
</body>
</html>