pax_global_header00006660000000000000000000000064132633765140014524gustar00rootroot0000000000000052 comment=f6e01bb8151fb53bfdccc3a6037c68e0b07127e5 createHmac-1.1.7/000077500000000000000000000000001326337651400135665ustar00rootroot00000000000000createHmac-1.1.7/.gitignore000066400000000000000000000000331326337651400155520ustar00rootroot00000000000000node_modules npm-debug.log createHmac-1.1.7/.npmignore000066400000000000000000000000101326337651400155540ustar00rootroot00000000000000test.js createHmac-1.1.7/.travis.yml000066400000000000000000000003571326337651400157040ustar00rootroot00000000000000sudo: false language: node_js before_install: - npm install npm -g node_js: - "4" - "5" - "6" - "7" matrix: include: - node_js: "7" env: TEST_SUITE=standard env: - TEST_SUITE=unit script: npm run-script $TEST_SUITE createHmac-1.1.7/LICENSE000066400000000000000000000021111326337651400145660ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2017 crypto-browserify contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. createHmac-1.1.7/README.md000066400000000000000000000020741326337651400150500ustar00rootroot00000000000000# 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', Buffer.from('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 ``` createHmac-1.1.7/browser.js000066400000000000000000000030601326337651400156060ustar00rootroot00000000000000'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 sha = require('sha.js') var ZEROS = Buffer.alloc(128) function Hmac (alg, key) { Base.call(this, 'digest') if (typeof key === 'string') { key = Buffer.from(key) } var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64 this._alg = alg this._key = key if (key.length > blocksize) { 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 = 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 = alg === 'rmd160' ? new RIPEMD160() : sha(alg) this._hash.update(ipad) } inherits(Hmac, Base) Hmac.prototype._update = function (data) { this._hash.update(data) } Hmac.prototype._final = function () { var h = this._hash.digest() var hash = this._alg === 'rmd160' ? new RIPEMD160() : sha(this._alg) return hash.update(this._opad).update(h).digest() } 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) } createHmac-1.1.7/index.js000066400000000000000000000000561326337651400152340ustar00rootroot00000000000000module.exports = require('crypto').createHmac createHmac-1.1.7/legacy.js000066400000000000000000000017111326337651400153700ustar00rootroot00000000000000'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 createHmac-1.1.7/package.json000066400000000000000000000020051326337651400160510ustar00rootroot00000000000000{ "name": "create-hmac", "version": "1.1.7", "description": "node style hmacs in the browser", "files": [ "browser.js", "index.js", "legacy.js" ], "main": "index.js", "scripts": { "standard": "standard", "test": "npm run-script standard && npm run-script unit", "unit": "node test.js | tspec" }, "repository": { "type": "git", "url": "https://github.com/crypto-browserify/createHmac.git" }, "keywords": [ "crypto", "hmac" ], "author": "", "license": "MIT", "bugs": { "url": "https://github.com/crypto-browserify/createHmac/issues" }, "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", "ripemd160": "^2.0.0", "safe-buffer": "^5.0.1", "sha.js": "^2.4.8" }, "browser": "./browser.js" } createHmac-1.1.7/test.js000066400000000000000000000027501326337651400151070ustar00rootroot00000000000000var test = require('tape') var Buffer = require('safe-buffer').Buffer 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 = Buffer.from(input.key, 'hex') var inputBuffer = Buffer.from(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 = Buffer.from(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, Buffer.from(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() }) }) })