How to use the tweetnacl.setPRNG function in tweetnacl

To help you get started, we’ve selected a few tweetnacl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MicroMinion / curvecp / src / packet-stream.js View on Github external
nacl.util = require('tweetnacl-util')
var utils = require('./utils.js')
var winston = require('winston')
var winstonWrapper = require('winston-meta-wrapper')

var HELLO_MSG = nacl.util.decodeUTF8('QvnQ5XlH')
var COOKIE_MSG = nacl.util.decodeUTF8('RL3aNMXK')
var INITIATE_MSG = nacl.util.decodeUTF8('QvnQ5XlI')
var SERVER_MSG = nacl.util.decodeUTF8('RL3aNMXM')
var CLIENT_MSG = nacl.util.decodeUTF8('QvnQ5XlM')

var HELLO_WAIT = [1000000000, 1500000000, 2250000000, 3375000000, 5062500000, 7593750000, 11390625000, 17085937500]

var MINUTE_KEY_TIMEOUT = 1000 * 60 * 2

nacl.setPRNG(function (x, n) {
  var i
  var v = crypto.randomBytes(n)
  for (i = 0; i < n; i++) x[i] = v[i]
  for (i = 0; i < v.length; i++) v[i] = 0
})

var PacketStream = function (opts) {
  if (!opts) opts = {}
  if (!opts.logger) {
    opts.logger = winston
  }
  this._log = winstonWrapper(opts.logger)
  this._log.addMeta({
    module: 'curvecp-packetstream'
  })
  opts.objectMode = false