view scripts/minifier/otr/dsa-webworker.js @ 161:4fe61dcd856e

flatpak: update build-manifest to retrieve dependencies without initial download phase: - dependencies are now entirely retrieved from the installation, and requirement are build from there. The source package is currently always used, and it is now possible to use PYTHON_DEP_PREINSTALL to add extra packages or use a specific version of a package. - fixed insertion of `release_elt` for dev version at the right location. - `branch` is not set anymore for stable versions. - libxslt is not added anymore as it is part of freedesktop runtime - flathub share-modules is now used for Python 2
author Goffi <goffi@goffi.org>
date Fri, 23 Aug 2019 16:41:05 +0200
parents 1596660ddf72
children
line wrap: on
line source

;(function (root) {
  "use strict";

  root.OTR = {}
  root.DSA = {}
  root.crypto = {
    randomBytes: function () {
      throw new Error("Haven't seeded yet.")
    }
  }

  // default imports
  var imports = [
      'vendor/salsa20.js'
    , 'vendor/bigint.js'
    , 'vendor/crypto.js'
    , 'vendor/eventemitter.js'
    , 'lib/const.js'
    , 'lib/helpers.js'
    , 'lib/dsa.js'
  ]

  function sendMsg(type, val) {
    postMessage({ type: type, val: val })
  }

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

    if (data.imports) imports = data.imports
    importScripts.apply(root, imports);

    // use salsa20 since there's no prng in webworkers
    var state = new root.Salsa20(data.seed.slice(0, 32), data.seed.slice(32))
    root.crypto.randomBytes = function (n) {
      return state.getBytes(n)
    }

    if (data.debug) sendMsg('debug', 'DSA key creation started')
    var dsa
    try {
      dsa = new root.DSA()
    } catch (e) {
      if (data.debug) sendMsg('debug', e.toString())
      return
    }
    if (data.debug) sendMsg('debug', 'DSA key creation finished')

    sendMsg('data', dsa.packPrivate())
  }

}(this))