2014-07-04 20:01:23 +00:00
|
|
|
/*!
|
2016-07-05 20:52:39 +00:00
|
|
|
* Webogram v0.5.5 - messaging web application for MTProto
|
2014-07-04 20:01:23 +00:00
|
|
|
* https://github.com/zhukov/webogram
|
|
|
|
* Copyright (C) 2014 Igor Zhukov <igor.beatle@gmail.com>
|
|
|
|
* https://github.com/zhukov/webogram/blob/master/LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
importScripts(
|
2014-10-01 17:36:11 +00:00
|
|
|
'polyfill.js',
|
2014-07-04 20:01:23 +00:00
|
|
|
'bin_utils.js',
|
|
|
|
'../../vendor/jsbn/jsbn_combined.js',
|
|
|
|
'../../vendor/leemon_bigint/bigint.js',
|
|
|
|
'../../vendor/closure/long.js',
|
2014-10-23 09:33:46 +00:00
|
|
|
'../../vendor/cryptoJS/crypto.js',
|
|
|
|
'../../vendor/rusha/rusha.js'
|
2016-06-28 16:40:53 +00:00
|
|
|
)
|
2014-07-04 20:01:23 +00:00
|
|
|
|
|
|
|
onmessage = function (e) {
|
|
|
|
var taskID = e.data.taskID,
|
2016-06-28 16:40:53 +00:00
|
|
|
result
|
2014-07-04 20:01:23 +00:00
|
|
|
|
|
|
|
switch (e.data.task) {
|
|
|
|
case 'factorize':
|
2016-06-28 16:40:53 +00:00
|
|
|
result = pqPrimeFactorization(e.data.bytes)
|
|
|
|
break
|
2014-07-04 20:01:23 +00:00
|
|
|
|
|
|
|
case 'mod-pow':
|
2016-06-28 16:40:53 +00:00
|
|
|
result = bytesModPow(e.data.x, e.data.y, e.data.m)
|
|
|
|
break
|
2014-07-04 20:01:23 +00:00
|
|
|
|
|
|
|
case 'sha1-hash':
|
2016-06-28 16:40:53 +00:00
|
|
|
result = sha1HashSync(e.data.bytes)
|
|
|
|
break
|
2014-07-04 20:01:23 +00:00
|
|
|
|
|
|
|
case 'aes-encrypt':
|
2016-06-28 16:40:53 +00:00
|
|
|
result = aesEncryptSync(e.data.bytes, e.data.keyBytes, e.data.ivBytes)
|
|
|
|
break
|
2014-07-04 20:01:23 +00:00
|
|
|
|
|
|
|
case 'aes-decrypt':
|
2016-06-28 16:40:53 +00:00
|
|
|
result = aesDecryptSync(e.data.encryptedBytes, e.data.keyBytes, e.data.ivBytes)
|
|
|
|
break
|
2014-07-04 20:01:23 +00:00
|
|
|
|
|
|
|
default:
|
2016-06-28 16:40:53 +00:00
|
|
|
throw new Error('Unknown task: ' + e.data.task)
|
2014-07-04 20:01:23 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 16:40:53 +00:00
|
|
|
postMessage({taskID: taskID, result: result})
|
2014-07-04 20:01:23 +00:00
|
|
|
}
|
2014-10-30 11:20:10 +00:00
|
|
|
|
2016-06-28 16:40:53 +00:00
|
|
|
postMessage('ready')
|