Sha256: a64a607dcb642323a9fcd9e7ab3fe189bce6f1a658352fd6fcba84af997f7ee8

Contents?: true

Size: 1017 Bytes

Versions: 65

Compression:

Stored size: 1017 Bytes

Contents

var createHash = require('./create-hash')

var zeroBuffer = new Buffer(128)
zeroBuffer.fill(0)

module.exports = Hmac

function Hmac (alg, key) {
  if(!(this instanceof Hmac)) return new Hmac(alg, key)
  this._opad = opad
  this._alg = alg

  var blocksize = (alg === 'sha512') ? 128 : 64

  key = this._key = !Buffer.isBuffer(key) ? new Buffer(key) : key

  if(key.length > blocksize) {
    key = createHash(alg).update(key).digest()
  } else if(key.length < blocksize) {
    key = Buffer.concat([key, zeroBuffer], blocksize)
  }

  var ipad = this._ipad = new Buffer(blocksize)
  var opad = this._opad = new Buffer(blocksize)

  for(var i = 0; i < blocksize; i++) {
    ipad[i] = key[i] ^ 0x36
    opad[i] = key[i] ^ 0x5C
  }

  this._hash = createHash(alg).update(ipad)
}

Hmac.prototype.update = function (data, enc) {
  this._hash.update(data, enc)
  return this
}

Hmac.prototype.digest = function (enc) {
  var h = this._hash.digest()
  return createHash(this._alg).update(this._opad).update(h).digest(enc)
}

Version data entries

65 entries across 65 versions & 2 rubygems

Version Path
smock-0.1.231 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.230 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.229 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.228 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.227 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.226 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.225 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.224 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.9 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.223 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.222 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.221 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.220 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.219 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.218 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.217 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.216 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.215 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.214 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.213 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js