You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
423 B

4 years ago
  1. var createHash = require('create-hash')
  2. var Buffer = require('safe-buffer').Buffer
  3. module.exports = function (seed, len) {
  4. var t = Buffer.alloc(0)
  5. var i = 0
  6. var c
  7. while (t.length < len) {
  8. c = i2ops(i++)
  9. t = Buffer.concat([t, createHash('sha1').update(seed).update(c).digest()])
  10. }
  11. return t.slice(0, len)
  12. }
  13. function i2ops (c) {
  14. var out = Buffer.allocUnsafe(4)
  15. out.writeUInt32BE(c, 0)
  16. return out
  17. }