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
gulp_assets-1.0.0.pre.5 template/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
gulp_assets-1.0.0.pre.4 template/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
gulp_assets-1.0.0.pre.3 template/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.268 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.267 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.266 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.265 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.264 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.263 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.262 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.261 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.260 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.259 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.258 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.256 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.255 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.254 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.253 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.252 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js
smock-0.1.251 node_modules/webpack/node_modules/node-libs-browser/node_modules/crypto-browserify/create-hmac.js