arlolra/otr — pull request #43 by sualko (2013-10-24 10:53:28+00:00)
Title: DSA webworker

I created a webworker for the DSA key production, therefor a little change in the bigint was necessary, because a ww has no access to the window object respectively crypto. Here you have a snippet to create a key with the ww:

```javascript
if (Worker) {
//create DSA key in background

var buf;
if ((typeof crypto !== 'undefined') &&
(typeof crypto.randomBytes === 'function')
) {
try {
buf = crypto.randomBytes(40)
} catch (e) {
throw e
}
} else if ((typeof crypto !== 'undefined') &&
(typeof crypto.getRandomValues === 'function')
) {
buf = new Uint8Array(40)
crypto.getRandomValues(buf)
} else {
throw new Error('Keys should not be generated without CSPRNG.')
}

var worker = new Worker('/lib/dsa-ww.js')

worker.onmessage = function(e) {
var type = e.data.type;
var data = e.data.data;

if (type == 'debug') {
console.log(data);
} else if (type == 'data') {
$(document).trigger('dsa.otr', DSA.parsePrivate(data.key));
}
};

//start worker
worker.postMessage({buf: buf});

} else {
//fallback

var dsa = new DSA();

$(document).trigger('dsa.otr', dsa);
}
```

I don't know if we should insert these code into the lib.

Regards Klaus

P.S.: I created an Owncloud App with videochat: https://github.com/sualko/ojsxc/tree/development
But it's still beta.