aboutsummaryrefslogtreecommitdiff
path: root/node_modules/create-hmac
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/create-hmac')
-rw-r--r--node_modules/create-hmac/.travis.yml4
-rw-r--r--node_modules/create-hmac/README.md20
-rw-r--r--node_modules/create-hmac/browser.js66
-rw-r--r--node_modules/create-hmac/index.js2
-rw-r--r--node_modules/create-hmac/legacy.js46
l---------node_modules/create-hmac/node_modules/.bin/sha.js1
-rw-r--r--node_modules/create-hmac/package.json18
-rw-r--r--node_modules/create-hmac/readme.md19
-rw-r--r--node_modules/create-hmac/test.js41
9 files changed, 113 insertions, 104 deletions
diff --git a/node_modules/create-hmac/.travis.yml b/node_modules/create-hmac/.travis.yml
deleted file mode 100644
index 1416d607c..000000000
--- a/node_modules/create-hmac/.travis.yml
+++ /dev/null
@@ -1,4 +0,0 @@
-language: node_js
-node_js:
- - "0.10"
- - "0.11" \ No newline at end of file
diff --git a/node_modules/create-hmac/README.md b/node_modules/create-hmac/README.md
new file mode 100644
index 000000000..73263cfa6
--- /dev/null
+++ b/node_modules/create-hmac/README.md
@@ -0,0 +1,20 @@
+# create-hmac
+
+[![NPM Package](https://img.shields.io/npm/v/create-hmac.svg?style=flat-square)](https://www.npmjs.org/package/create-hmac)
+[![Build Status](https://img.shields.io/travis/crypto-browserify/createHmac.svg?branch=master&style=flat-square)](https://travis-ci.org/crypto-browserify/createHmac)
+[![Dependency status](https://img.shields.io/david/crypto-browserify/createHmac.svg?style=flat-square)](https://david-dm.org/crypto-browserify/createHmac#info=dependencies)
+
+[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
+
+Node style HMACs for use in the browser, with native HMAC functions in node. API is the same as HMACs in node:
+
+```js
+var createHmac = require('create-hmac')
+var hmac = createHmac('sha224', new Buffer("secret key"))
+hmac.update('synchronous write') //optional encoding parameter
+hmac.digest() // synchronously get result with optional encoding parameter
+
+hmac.write('write to it as a stream')
+hmac.end() //remember it's a stream
+hmac.read() //only if you ended it as a stream though
+```
diff --git a/node_modules/create-hmac/browser.js b/node_modules/create-hmac/browser.js
index b610781b2..a5c9b61ea 100644
--- a/node_modules/create-hmac/browser.js
+++ b/node_modules/create-hmac/browser.js
@@ -1,68 +1,62 @@
-'use strict';
-var createHash = require('create-hash/browser');
+'use strict'
var inherits = require('inherits')
+var Legacy = require('./legacy')
+var Base = require('cipher-base')
+var Buffer = require('safe-buffer').Buffer
+var md5 = require('create-hash/md5')
+var RIPEMD160 = require('ripemd160')
-var Transform = require('stream').Transform
+var sha = require('sha.js')
-var ZEROS = new Buffer(128)
-ZEROS.fill(0)
+var ZEROS = Buffer.alloc(128)
-function Hmac(alg, key) {
- Transform.call(this)
- alg = alg.toLowerCase()
+function Hmac (alg, key) {
+ Base.call(this, 'digest')
if (typeof key === 'string') {
- key = new Buffer(key)
+ key = Buffer.from(key)
}
var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64
this._alg = alg
this._key = key
-
if (key.length > blocksize) {
- key = createHash(alg).update(key).digest()
-
+ var hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg)
+ key = hash.update(key).digest()
} else if (key.length < blocksize) {
key = Buffer.concat([key, ZEROS], blocksize)
}
- var ipad = this._ipad = new Buffer(blocksize)
- var opad = this._opad = new Buffer(blocksize)
+ var ipad = this._ipad = Buffer.allocUnsafe(blocksize)
+ var opad = this._opad = Buffer.allocUnsafe(blocksize)
for (var i = 0; i < blocksize; i++) {
ipad[i] = key[i] ^ 0x36
opad[i] = key[i] ^ 0x5C
}
-
- this._hash = createHash(alg).update(ipad)
+ this._hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg)
+ this._hash.update(ipad)
}
-inherits(Hmac, Transform)
+inherits(Hmac, Base)
-Hmac.prototype.update = function (data, enc) {
- this._hash.update(data, enc)
-
- return this
-}
-
-Hmac.prototype._transform = function (data, _, next) {
+Hmac.prototype._update = function (data) {
this._hash.update(data)
-
- next()
}
-Hmac.prototype._flush = function (next) {
- this.push(this.digest())
-
- next()
-}
-
-Hmac.prototype.digest = function (enc) {
+Hmac.prototype._final = function () {
var h = this._hash.digest()
-
- return createHash(this._alg).update(this._opad).update(h).digest(enc)
+ var hash = this._alg === 'rmd160' ? new RIPEMD160() : sha(this._alg)
+ return hash.update(this._opad).update(h).digest()
}
-module.exports = function createHmac(alg, key) {
+module.exports = function createHmac (alg, key) {
+ alg = alg.toLowerCase()
+ if (alg === 'rmd160' || alg === 'ripemd160') {
+ return new Hmac('rmd160', key)
+ }
+ if (alg === 'md5') {
+ return new Legacy(md5, key)
+ }
return new Hmac(alg, key)
}
diff --git a/node_modules/create-hmac/index.js b/node_modules/create-hmac/index.js
index 220908ad3..ec8c4f728 100644
--- a/node_modules/create-hmac/index.js
+++ b/node_modules/create-hmac/index.js
@@ -1 +1 @@
-module.exports = require('crypto').createHmac; \ No newline at end of file
+module.exports = require('crypto').createHmac
diff --git a/node_modules/create-hmac/legacy.js b/node_modules/create-hmac/legacy.js
new file mode 100644
index 000000000..5039c2a7a
--- /dev/null
+++ b/node_modules/create-hmac/legacy.js
@@ -0,0 +1,46 @@
+'use strict'
+var inherits = require('inherits')
+var Buffer = require('safe-buffer').Buffer
+
+var Base = require('cipher-base')
+
+var ZEROS = Buffer.alloc(128)
+var blocksize = 64
+
+function Hmac (alg, key) {
+ Base.call(this, 'digest')
+ if (typeof key === 'string') {
+ key = Buffer.from(key)
+ }
+
+ this._alg = alg
+ this._key = key
+
+ if (key.length > blocksize) {
+ key = alg(key)
+ } else if (key.length < blocksize) {
+ key = Buffer.concat([key, ZEROS], blocksize)
+ }
+
+ var ipad = this._ipad = Buffer.allocUnsafe(blocksize)
+ var opad = this._opad = Buffer.allocUnsafe(blocksize)
+
+ for (var i = 0; i < blocksize; i++) {
+ ipad[i] = key[i] ^ 0x36
+ opad[i] = key[i] ^ 0x5C
+ }
+
+ this._hash = [ipad]
+}
+
+inherits(Hmac, Base)
+
+Hmac.prototype._update = function (data) {
+ this._hash.push(data)
+}
+
+Hmac.prototype._final = function () {
+ var h = this._alg(Buffer.concat(this._hash))
+ return this._alg(Buffer.concat([this._opad, h]))
+}
+module.exports = Hmac
diff --git a/node_modules/create-hmac/node_modules/.bin/sha.js b/node_modules/create-hmac/node_modules/.bin/sha.js
new file mode 120000
index 000000000..4d6df2e5f
--- /dev/null
+++ b/node_modules/create-hmac/node_modules/.bin/sha.js
@@ -0,0 +1 @@
+../../../sha.js/bin.js \ No newline at end of file
diff --git a/node_modules/create-hmac/package.json b/node_modules/create-hmac/package.json
index f4267511c..ab116af8d 100644
--- a/node_modules/create-hmac/package.json
+++ b/node_modules/create-hmac/package.json
@@ -1,10 +1,17 @@
{
"name": "create-hmac",
- "version": "1.1.4",
+ "version": "1.1.6",
"description": "node style hmacs in the browser",
+ "files": [
+ "browser.js",
+ "index.js",
+ "legacy.js"
+ ],
"main": "index.js",
"scripts": {
- "test": "node test.js | tspec"
+ "standard": "standard",
+ "test": "npm run-script standard && npm run-script unit",
+ "unit": "node test.js | tspec"
},
"repository": {
"type": "git",
@@ -22,12 +29,17 @@
"homepage": "https://github.com/crypto-browserify/createHmac",
"devDependencies": {
"hash-test-vectors": "^1.3.2",
+ "standard": "^5.3.1",
"tap-spec": "^2.1.2",
"tape": "^3.0.3"
},
"dependencies": {
+ "cipher-base": "^1.0.3",
"create-hash": "^1.1.0",
- "inherits": "^2.0.1"
+ "inherits": "^2.0.1",
+ "ripemd160": "^2.0.0",
+ "safe-buffer": "^5.0.1",
+ "sha.js": "^2.4.8"
},
"browser": "./browser.js"
}
diff --git a/node_modules/create-hmac/readme.md b/node_modules/create-hmac/readme.md
deleted file mode 100644
index 4e8bda4df..000000000
--- a/node_modules/create-hmac/readme.md
+++ /dev/null
@@ -1,19 +0,0 @@
-create-hmac
-===
-
-[![Build Status](https://travis-ci.org/crypto-browserify/createHmac.svg)](https://travis-ci.org/crypto-browserify/createHmac)
-
-Node style hmacs for use in the browser, with native hmac functions in node. Api is the same as hmacs in node:
-
-```js
-var createHmac = require('create-hmac');
-var hmac = createHmac('sha224', new Buffer("secret key"));
-hmac.update('synchronous write'); //optional encoding parameter
-hmac.digest();// synchronously get result with optional encoding parameter
-
-hmac.write('write to it as a stream');
-hmac.end();//remember it's a stream
-hmac.read();//only if you ended it as a stream though
-```
-
-To get the JavaScript version even in node require `require('create-hmac/browser');` \ No newline at end of file
diff --git a/node_modules/create-hmac/test.js b/node_modules/create-hmac/test.js
deleted file mode 100644
index cb0cd5765..000000000
--- a/node_modules/create-hmac/test.js
+++ /dev/null
@@ -1,41 +0,0 @@
-var test = require('tape')
-
-var algorithms = ['sha1', 'sha224','sha256', 'sha384', 'sha512', 'SHA512', 'md5', 'rmd160']
-var formats = [undefined, 'base64', 'hex', 'binary']
-
-var vectors = require('hash-test-vectors/hmac')
-var createHmac = require('./browser')
-algorithms.forEach(function (alg) {
- vectors.forEach(function (input) {
- var key = new Buffer(input.key, 'hex')
- var inputBuffer = new Buffer(input.data, 'hex')
-
- formats.forEach(function (format) {
- test('hmac(' + alg + ') w/ ' + input.data.slice(0, 6) + '... as ' + format, function (t) {
- var hmac = createHmac(alg, key)
-
- var formattedInput = format ? inputBuffer.toString(format) : inputBuffer
- hmac.update(formattedInput, format)
-
- var formattedOutput = hmac.digest(format)
- var output = new Buffer(formattedOutput, format)
-
- var truncated = input.truncate ? output.slice(0, input.truncate) : output
- t.equal(truncated.toString('hex'), input[alg.toLowerCase()])
- t.end()
- })
- })
- })
-
- vectors.forEach(function (input) {
- test('hmac(' + alg + ') as stream w/ ' + input.data.slice(0, 6) + '...', function (t) {
- var hmac = createHmac(alg, new Buffer(input.key, 'hex'))
- hmac.end(input.data, 'hex')
-
- var output = hmac.read()
- var truncated = input.truncate ? output.slice(0, input.truncate) : output
- t.equal(truncated.toString('hex'), input[alg.toLowerCase()])
- t.end()
- })
- })
-})