Mercurial > sat_docs
annotate scripts/minifier/otr/dsa-webworker.js @ 98:349cbfea2596
docker (prosody): restored logs in /var/log + info logs to console
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 26 Feb 2016 16:09:01 +0100 |
parents | 1596660ddf72 |
children |
rev | line source |
---|---|
12
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1 ;(function (root) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2 "use strict"; |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
4 root.OTR = {} |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
5 root.DSA = {} |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
6 root.crypto = { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
7 randomBytes: function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
8 throw new Error("Haven't seeded yet.") |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
9 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
10 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
11 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
12 // default imports |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
13 var imports = [ |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
14 'vendor/salsa20.js' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
15 , 'vendor/bigint.js' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
16 , 'vendor/crypto.js' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
17 , 'vendor/eventemitter.js' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
18 , 'lib/const.js' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 , 'lib/helpers.js' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
20 , 'lib/dsa.js' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
21 ] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
22 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
23 function sendMsg(type, val) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
24 postMessage({ type: type, val: val }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
25 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
26 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
27 onmessage = function (e) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
28 var data = e.data; |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
29 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 if (data.imports) imports = data.imports |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
31 importScripts.apply(root, imports); |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
32 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
33 // use salsa20 since there's no prng in webworkers |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
34 var state = new root.Salsa20(data.seed.slice(0, 32), data.seed.slice(32)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
35 root.crypto.randomBytes = function (n) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
36 return state.getBytes(n) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
37 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
38 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
39 if (data.debug) sendMsg('debug', 'DSA key creation started') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
40 var dsa |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
41 try { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
42 dsa = new root.DSA() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
43 } catch (e) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
44 if (data.debug) sendMsg('debug', e.toString()) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
45 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
46 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
47 if (data.debug) sendMsg('debug', 'DSA key creation finished') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
48 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
49 sendMsg('data', dsa.packPrivate()) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
50 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
51 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
52 }(this)) |