-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
386 lines (325 loc) · 15.2 KB
/
index.html
File metadata and controls
386 lines (325 loc) · 15.2 KB
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/5.1.3/zephyr/bootstrap.min.css" integrity="sha512-gmJFuKTEQw6aHC2cWdrmdEHYw/M/8+bfsKmsJCcQ5hoI7WoOtkQ9hs7P0fqpBGRHHqBBJMibeCfhmk8So5qYUw==" crossorigin="anonymous" referrerpolicy="no-referrer"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="style.css" />
<title>MFKDF Browser Benchmark</title>
</head>
<body>
<div class="splash-bg">
<div class="bg-image"></div>
<div class="card text-start p-0 overflow-hidden border-0">
<div class="p-4-5">
<h3>MFKDF Benchmark</h3>
<p class="mt-3 mb-3">An official browser-based benchmark for MFKDF, including threshold MFKDF and all supported factors.</p>
<a class="btn btn-success m-0 mt-0" href="#" id="start"><i class="fa fa-play"></i> Run Now</a>
<div id="progress" style="display: none;">
<div class="progress">
<div class="progress-bar" id="bar"></div>
</div>
<p id="status" class="mb-0">Starting benchmark...</p>
</div>
<div id="results" style="display: none;">
<table class="table">
<thead>
<tr>
<th><b>Results</b></th>
<th>Setup Time</th>
<th>Derive Time</th>
</tr>
</thead>
<tbody id="rows">
</tbody>
</table>
</div>
</div>
</div>
</difv>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<script src="buffer.js"></script>
<script src="mfkdf.min.js"></script>
<script>
$("#start").click(() => {
$("#start").slideUp();
$("#progress").slideDown();
run();
});
const Buffer = buffer.Buffer;
const hms1 = async (data, message) => {
const key = await window.crypto.subtle.importKey(
"raw",
data,
{
name: "HMAC",
hash: { name: "SHA-1" },
},
false,
["sign"]
);
const signature = await window.crypto.subtle.sign("HMAC", key, message);
return signature;
}
var logstr = "";
const log = (str) => {
logstr += str + "\n";
}
const out = document.getElementById('out');
const flush = () => {
console.log(logstr);
logstr = "";
}
var res = {};
const clear = () => {
logstr = "";
console.clear();
res = {};
}
const times = {};
const start = (rn, name) => {
times[rn + " " + name] = performance.now();
}
const end = (rn, name) => {
time = (performance.now() - times[rn + " " + name])
if (!res[name]) res[name] = []
res[name].push(time)
log(rn + " " + name + " " + time);
}
const mfkdf_all = async (rn) => {
rn = "mfkdf_all " + rn;
const keyPair = await window.crypto.subtle.generateKey(
{ hash: 'SHA-256', modulusLength: 2048, name: 'RSA-OAEP', publicExponent: new Uint8Array([1, 0, 1]) },
true,
['encrypt', 'decrypt']
)
const init = await mfkdf.setup.key([
await mfkdf.setup.factors.password('password')
], { kdf: 'hkdf' })
start(rn, "full")
start(rn, "setup full")
start(rn, "setup factor password")
const passwordSetup = await mfkdf.stage.factor.setup(mfkdf.setup.factors.password('password'), init.key)
end(rn, "setup factor password")
start(rn, "setup factor hmacsha1")
const hmacsha1Setup = await mfkdf.stage.factor.setup(mfkdf.setup.factors.hmacsha1(), init.key)
end(rn, "setup factor hmacsha1")
start(rn, "setup factor hotp")
const hotpSetup = await mfkdf.stage.factor.setup(mfkdf.setup.factors.hotp({ secret: Buffer.from('hello world') }), init.key)
end(rn, "setup factor hotp")
start(rn, "setup factor ooba")
const oobaSetup = await mfkdf.stage.factor.setup(mfkdf.setup.factors.ooba({ key: keyPair.publicKey, params: {} }), init.key)
end(rn, "setup factor ooba")
start(rn, "setup factor question")
const questionSetup = await mfkdf.stage.factor.setup(mfkdf.setup.factors.question('fido'), init.key)
end(rn, "setup factor question")
start(rn, "setup factor totp")
const totpSetup = await mfkdf.stage.factor.setup(mfkdf.setup.factors.totp({ secret: Buffer.from('hello world'), time: 1650430806597, window: 2920 }), init.key)
end(rn, "setup factor totp")
start(rn, "setup factor uuid")
const uuidSetup = await mfkdf.stage.factor.setup(mfkdf.setup.factors.uuid({ uuid: '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d' }), init.key)
end(rn, "setup factor uuid")
start(rn, "setup key")
const setup = await mfkdf.setup.key([
passwordSetup, hmacsha1Setup, hotpSetup, oobaSetup, questionSetup, totpSetup, uuidSetup
], { kdf: 'hkdf' })
end(rn, "setup key")
end(rn, "setup full")
const secret = setup.outputs.hmacsha1.secret
const challenge = Buffer.from(setup.policy.factors[1].params.challenge, 'hex')
const response = await hms1(secret, challenge)
const next = setup.policy.factors[3].params.next
const decrypted = await window.crypto.subtle.decrypt({ name: 'RSA-OAEP' }, keyPair.privateKey, Buffer.from(next, 'hex'))
const json = JSON.parse(Buffer.from(decrypted).toString())
const code = json.code
start(rn, "derive full")
start(rn, "derive factor password")
const password = await mfkdf.stage.factor.derive(mfkdf.derive.factors.password('password'), setup.policy.factors[0].params, setup.key)
end(rn, "derive factor password")
start(rn, "derive factor hmacsha1")
const hmacsha1 = await mfkdf.stage.factor.derive(mfkdf.derive.factors.hmacsha1(Buffer.from(response)), setup.policy.factors[1].params, setup.key)
end(rn, "derive factor hmacsha1")
start(rn, "derive factor hotp")
const hotp = await mfkdf.stage.factor.derive(mfkdf.derive.factors.hotp(365287), setup.policy.factors[2].params, setup.key)
end(rn, "derive factor hotp")
start(rn, "derive factor ooba")
const ooba = await mfkdf.stage.factor.derive(mfkdf.derive.factors.ooba(code), setup.policy.factors[3].params, setup.key)
end(rn, "derive factor ooba")
start(rn, "derive factor question")
const question = await mfkdf.stage.factor.derive(mfkdf.derive.factors.question('fido'), setup.policy.factors[4].params, setup.key)
end(rn, "derive factor question")
start(rn, "derive factor totp")
const totp = await mfkdf.stage.factor.derive(mfkdf.derive.factors.totp(528258, { time: 1650430943604 }), setup.policy.factors[5].params, setup.key)
end(rn, "derive factor totp")
start(rn, "derive factor uuid")
const uuid = await mfkdf.stage.factor.derive(mfkdf.derive.factors.uuid('9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'), setup.policy.factors[6].params, setup.key)
end(rn, "derive factor uuid")
start(rn, "derive key")
const derive = await mfkdf.derive.key(setup.policy, {
password, hmacsha1, hotp, ooba, question, totp, uuid
})
end(rn, "derive key")
end(rn, "derive full")
end(rn, "full")
log(rn + " setup " + setup.key.toString('hex'))
log(rn + " derive " + derive.key.toString('hex'))
flush()
}
const mfkdf_3 = async (rn) => {
rn = "mfkdf_3 " + rn;
const init = await mfkdf.setup.key([
await mfkdf.setup.factors.password('password')
], { kdf: 'hkdf' })
start(rn, "mfkdf_3_3 full")
start(rn, "mfkdf_3_3 setup full")
start(rn, "setup factor password")
const passwordSetup = await mfkdf.stage.factor.setup(mfkdf.setup.factors.password('password'), init.key)
end(rn, "setup factor password")
start(rn, "setup factor hotp")
const hotpSetup = await mfkdf.stage.factor.setup(mfkdf.setup.factors.hotp({ secret: Buffer.from('hello world') }), init.key)
end(rn, "setup factor hotp")
start(rn, "setup factor uuid")
const uuidSetup = await mfkdf.stage.factor.setup(mfkdf.setup.factors.uuid({ uuid: '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d' }), init.key)
end(rn, "setup factor uuid")
start(rn, "mfkdf_3_3 setup key")
const setup = await mfkdf.setup.key([
passwordSetup, hotpSetup, uuidSetup
], { kdf: 'hkdf' })
end(rn, "mfkdf_3_3 setup key")
end(rn, "mfkdf_3_3 setup full")
start(rn, "mfkdf_3_3 derive full")
start(rn, "derive factor password")
const password = await mfkdf.stage.factor.derive(mfkdf.derive.factors.password('password'), setup.policy.factors[0].params, setup.key)
end(rn, "derive factor password")
start(rn, "derive factor hotp")
const hotp = await mfkdf.stage.factor.derive(mfkdf.derive.factors.hotp(365287), setup.policy.factors[1].params, setup.key)
end(rn, "derive factor hotp")
start(rn, "derive factor uuid")
const uuid = await mfkdf.stage.factor.derive(mfkdf.derive.factors.uuid('9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'), setup.policy.factors[2].params, setup.key)
end(rn, "derive factor uuid")
start(rn, "mfkdf_3_3 derive key")
const derive = await mfkdf.derive.key(setup.policy, {
password, hotp, uuid
})
end(rn, "mfkdf_3_3 derive key")
end(rn, "mfkdf_3_3 derive full")
end(rn, "mfkdf_3_3 full")
log(rn + " setup " + setup.key.toString('hex'))
log(rn + " derive " + derive.key.toString('hex'))
flush()
}
const mfkdf_2_3 = async (rn) => {
rn = "mfkdf_2_3 " + rn;
const init = await mfkdf.setup.key([
await mfkdf.setup.factors.password('password')
], { kdf: 'hkdf' })
start(rn, "mfkdf_2_3 full")
start(rn, "mfkdf_2_3 setup full")
start(rn, "setup factor password")
const passwordSetup = await mfkdf.stage.factor.setup(mfkdf.setup.factors.password('password'), init.key)
end(rn, "setup factor password")
start(rn, "setup factor hotp")
const hotpSetup = await mfkdf.stage.factor.setup(mfkdf.setup.factors.hotp({ secret: Buffer.from('hello world') }), init.key)
end(rn, "setup factor hotp")
start(rn, "setup factor uuid")
const uuidSetup = await mfkdf.stage.factor.setup(mfkdf.setup.factors.uuid({ uuid: '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d' }), init.key)
end(rn, "setup factor uuid")
start(rn, "mfkdf_2_3 setup key")
const setup = await mfkdf.setup.key([
passwordSetup, hotpSetup, uuidSetup
], { kdf: 'hkdf', threshold: 2 })
end(rn, "mfkdf_2_3 setup key")
end(rn, "mfkdf_2_3 setup full")
start(rn, "mfkdf_2_3 derive full")
start(rn, "derive factor password")
const password = await mfkdf.stage.factor.derive(mfkdf.derive.factors.password('password'), setup.policy.factors[0].params, setup.key)
end(rn, "derive factor password")
start(rn, "derive factor hotp")
const hotp = await mfkdf.stage.factor.derive(mfkdf.derive.factors.hotp(365287), setup.policy.factors[1].params, setup.key)
end(rn, "derive factor hotp")
start(rn, "mfkdf_2_3 derive key")
const derive = await mfkdf.derive.key(setup.policy, {
password, hotp
})
end(rn, "mfkdf_2_3 derive key")
end(rn, "mfkdf_2_3 derive full")
end(rn, "mfkdf_2_3 full")
log(rn + " setup " + setup.key.toString('hex'))
log(rn + " derive " + derive.key.toString('hex'))
flush()
}
const setStatus = (txt, pct) => {
$("#status").text(txt);
$("#bar").width(pct*100 + '%');
}
const mean = array => array.reduce((a, b) => a + b) / array.length;
const run = async () => {
await mfkdf_3(0);
await mfkdf_2_3(0);
await mfkdf_all(0);
clear();
const N = 100;
for (let i = 1; i <= N; i++) {
setStatus("Testing MFKDF performance... (" + i + "/" + N + ")", i / 300);
await mfkdf_3(i);
}
for (let i = 1; i <= N; i++) {
setStatus("Testing threshold MFKDF performance... (" + i + "/" + N + ")", (i + 100) / 300);
await mfkdf_2_3(i);
}
for (let i = 1; i <= N; i++) {
setStatus("Testing factor performance... (" + i + "/" + N + ")", (i + 200) / 300);
await mfkdf_all(i);
}
$("#rows").append(`<tr>
<td>3-of-3 MFKDF</td>
<td>x̄ = ${(mean(res['mfkdf_3_3 setup full'])).toFixed(1)} ms</td>
<td>x̄ = ${(mean(res['mfkdf_3_3 derive full'])).toFixed(1)} ms</td>
</tr>`);
$("#rows").append(`<tr>
<td>2-of-3 MFKDF</td>
<td>x̄ = ${(mean(res['mfkdf_2_3 setup full'])).toFixed(1)} ms</td>
<td>x̄ = ${(mean(res['mfkdf_2_3 derive full'])).toFixed(1)} ms</td>
</tr>`);
$("#rows").append(`<tr>
<td>UUID Factor</td>
<td>x̄ = ${(mean(res['setup factor uuid'])*1000).toFixed(1)} µs</td>
<td>x̄ = ${(mean(res['derive factor uuid'])*1000).toFixed(1)} µs</td>
</tr>`);
$("#rows").append(`<tr>
<td>HMAC-SHA1 Factor</td>
<td>x̄ = ${(mean(res['setup factor hmacsha1'])*1000).toFixed(1)} µs</td>
<td>x̄ = ${(mean(res['derive factor hmacsha1'])*1000).toFixed(1)} µs</td>
</tr>`);
$("#rows").append(`<tr>
<td>Security Question Factor</td>
<td>x̄ = ${(mean(res['setup factor question'])*1000).toFixed(1)} µs</td>
<td>x̄ = ${(mean(res['derive factor question'])*1000).toFixed(1)} µs</td>
</tr>`);
$("#rows").append(`<tr>
<td>Password Factor</td>
<td>x̄ = ${(mean(res['setup factor password'])*1000).toFixed(1)} µs</td>
<td>x̄ = ${(mean(res['derive factor password'])*1000).toFixed(1)} µs</td>
</tr>`);
$("#rows").append(`<tr>
<td>HOTP Factor</td>
<td>x̄ = ${(mean(res['setup factor hotp'])*1000).toFixed(1)} µs</td>
<td>x̄ = ${(mean(res['derive factor hotp'])*1000).toFixed(1)} µs</td>
</tr>`);
$("#rows").append(`<tr>
<td>OOBA Factor</td>
<td>x̄ = ${(mean(res['setup factor ooba'])).toFixed(1)} ms</td>
<td>x̄ = ${(mean(res['derive factor ooba'])).toFixed(1)} ms</td>
</tr>`);
$("#rows").append(`<tr>
<td>TOTP Factor</td>
<td>x̄ = ${(mean(res['setup factor totp'])).toFixed(1)} ms</td>
<td>x̄ = ${(mean(res['derive factor totp'])).toFixed(1)} ms</td>
</tr>`);
$("#progress").slideUp();
$("#results").slideDown();
}
</script>
</body>
</html>