mgf.js 423 B

1234567891011121314151617181920
  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. }