From 2b2bde119879875ce1e0db85da3200ad70c7c779 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Sat, 19 Jul 2014 11:17:09 -0700 Subject: [PATCH 001/217] update sha.js to 2.1.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d9cb0cf..0ac5783 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "dependencies": { "ripemd160": "0.2.0", - "sha.js": "2.1.4" + "sha.js": "2.1.6" }, "devDependencies": { "tape": "~2.3.2", From fcf43d806e629fff64bed2db2829c44c6fa80523 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Sat, 19 Jul 2014 11:17:18 -0700 Subject: [PATCH 002/217] 2.1.10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0ac5783..5a05f25 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "2.1.9", + "version": "2.1.10", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From b8695c478baa705e18cc7130be3af6c679ae0bf7 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Tue, 22 Jul 2014 11:42:48 -0700 Subject: [PATCH 003/217] Remove Math.random RNG as it is not cryptographically secure --- rng.js | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/rng.js b/rng.js index ac153f2..8c39ef3 100644 --- a/rng.js +++ b/rng.js @@ -1,33 +1,10 @@ -// Original code adapted from Robert Kieffer. -// details at https://github.com/broofa/node-uuid - - (function() { - var _global = this; - - var mathRNG, whatwgRNG; - - // NOTE: Math.random() does not guarantee "cryptographic quality" - mathRNG = function(size) { - var bytes = new Buffer(size); - var r; - - for (var i = 0, r; i < size; i++) { - if ((i & 0x03) == 0) r = Math.random() * 0x100000000; - bytes[i] = r >>> ((i & 0x03) << 3) & 0xff; - } - + module.exports = function(size) { + var bytes = new Buffer(size); //in browserify, this is an extended Uint8Array + /* This will not work in older browsers. + * See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues + */ + crypto.getRandomValues(bytes); return bytes; } - - if (_global.crypto && crypto.getRandomValues) { - whatwgRNG = function(size) { - var bytes = new Buffer(size); //in browserify, this is an extended Uint8Array - crypto.getRandomValues(bytes); - return bytes; - } - } - - module.exports = whatwgRNG || mathRNG; - }()) From a7bc39a3cfa8d7b63fd59a18ea5aa26b0aab6ac5 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 22 Jul 2014 14:42:21 -0700 Subject: [PATCH 004/217] 2.1.11 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5a05f25..4dcd5f8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "2.1.10", + "version": "2.1.11", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From c4fdb884482c930e6c08f350651bf23fdfeedcd2 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 22 Jul 2014 14:43:09 -0700 Subject: [PATCH 005/217] 3.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5a05f25..54a6e0d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "2.1.10", + "version": "3.0.0", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 892a0aa3488720e3e66491a150726a159a8b7ac5 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Thu, 24 Jul 2014 03:31:31 -0700 Subject: [PATCH 006/217] update sha.js to 2.1.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 54a6e0d..9763ae0 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "dependencies": { "ripemd160": "0.2.0", - "sha.js": "2.1.6" + "sha.js": "2.1.7" }, "devDependencies": { "tape": "~2.3.2", From 6eeab264fc7406490c5f6d62f137d2083affa52e Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Thu, 24 Jul 2014 03:31:36 -0700 Subject: [PATCH 007/217] 3.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9763ae0..b5ba428 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.0.0", + "version": "3.0.1", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From e50f7c34cce42ecdccb459833f3b6d734f70c5d1 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Sun, 31 Aug 2014 09:58:27 -0700 Subject: [PATCH 008/217] update sha.js@2.1.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b5ba428..c40ab4c 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "dependencies": { "ripemd160": "0.2.0", - "sha.js": "2.1.7" + "sha.js": "2.1.8" }, "devDependencies": { "tape": "~2.3.2", From a460a9c96697b1eb6a7a9db425029fd32b05019b Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Sun, 31 Aug 2014 09:58:40 -0700 Subject: [PATCH 009/217] 3.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c40ab4c..f106964 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.0.1", + "version": "3.0.2", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 3639b9d47e14040aa243b247bd0e0f832b4f6d98 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Thu, 18 Sep 2014 12:38:13 +0300 Subject: [PATCH 010/217] use sha.js@2.2.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f106964..e489c50 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "dependencies": { "ripemd160": "0.2.0", - "sha.js": "2.1.8" + "sha.js": "2.2.6" }, "devDependencies": { "tape": "~2.3.2", From 6addde8211cde43ef04ea7d2f9a6e09a2ce6b074 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Thu, 18 Sep 2014 12:38:17 +0300 Subject: [PATCH 011/217] 3.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e489c50..638d96f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.0.2", + "version": "3.0.3", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From d58beeb646224807f5c0c2a585c4b5139f6b640a Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Thu, 18 Sep 2014 12:41:58 +0300 Subject: [PATCH 012/217] 3.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e489c50..bc84ebc 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.0.2", + "version": "3.1.0", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 1ff98017ec17a393ed24d7ef74e478a65101dcb5 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 17 Sep 2014 01:39:50 +1000 Subject: [PATCH 013/217] sha512: add sha512 from sha.js --- create-hmac.js | 6 ++++-- index.js | 2 +- readme.markdown | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/create-hmac.js b/create-hmac.js index ebef0a2..65e6e65 100644 --- a/create-hmac.js +++ b/create-hmac.js @@ -1,7 +1,7 @@ var createHash = require('./create-hash') -var blocksize = 64 -var zeroBuffer = new Buffer(blocksize); zeroBuffer.fill(0) +var zeroBuffer = new Buffer(128) +zeroBuffer.fill(0) module.exports = Hmac @@ -10,6 +10,8 @@ function 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) { diff --git a/index.js b/index.js index 752ef4d..45b1d34 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,7 @@ function each(a, f) { } exports.getHashes = function () { - return ['sha1', 'sha256', 'md5', 'rmd160'] + return ['sha1', 'sha256', 'sha512', 'md5', 'rmd160'] } diff --git a/readme.markdown b/readme.markdown index 75b83ce..6a00282 100644 --- a/readme.markdown +++ b/readme.markdown @@ -11,8 +11,8 @@ in pure javascript so that it can run in the browser. Here is the subset that is currently implemented: -* createHash (sha1, sha256, md5, rmd160) -* createHmac (sha1, sha256, md5) +* createHash (sha1, sha256, sha512, md5, rmd160) +* createHmac (sha1, sha256, sha512, md5) * pbkdf2 * pbkdf2Sync * randomBytes From a5cf35baecd8e661333c78b614ed13379ec70043 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Mon, 22 Sep 2014 11:11:12 +0300 Subject: [PATCH 014/217] 3.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bc84ebc..58f8385 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.1.0", + "version": "3.2.0", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 5dbe10a0547846ccc0c05a0cae5e49d2a4f5fc00 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 17 Sep 2014 02:12:31 +1000 Subject: [PATCH 015/217] pbkdf2: use pbkdf2-compat 2.0.0 --- index.js | 3 +- package.json | 1 + pbkdf2.js | 80 ++++------------------------------------------------ 3 files changed, 7 insertions(+), 77 deletions(-) diff --git a/index.js b/index.js index 45b1d34..54efb88 100644 --- a/index.js +++ b/index.js @@ -30,10 +30,9 @@ function each(a, f) { exports.getHashes = function () { return ['sha1', 'sha256', 'sha512', 'md5', 'rmd160'] - } -var p = require('./pbkdf2')(exports.createHmac) +var p = require('./pbkdf2')(exports) exports.pbkdf2 = p.pbkdf2 exports.pbkdf2Sync = p.pbkdf2Sync diff --git a/package.json b/package.json index 58f8385..9c2f25d 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "node": "*" }, "dependencies": { + "pbkdf2-compat": "2.0.0", "ripemd160": "0.2.0", "sha.js": "2.2.6" }, diff --git a/pbkdf2.js b/pbkdf2.js index 0ead40e..33753e9 100644 --- a/pbkdf2.js +++ b/pbkdf2.js @@ -1,82 +1,12 @@ -// JavaScript PBKDF2 Implementation -// Based on http://git.io/qsv2zw -// Licensed under LGPL v3 -// Copyright (c) 2013 jduncanator +var pbkdf2Export = require('pbkdf2-compat').__pbkdf2Export -var blocksize = 64 -var zeroBuffer = new Buffer(blocksize); zeroBuffer.fill(0) - -module.exports = function (createHmac, exports) { +module.exports = function (crypto, exports) { exports = exports || {} - exports.pbkdf2 = function(password, salt, iterations, keylen, cb) { - if('function' !== typeof cb) - throw new Error('No callback provided to pbkdf2'); - setTimeout(function () { - cb(null, exports.pbkdf2Sync(password, salt, iterations, keylen)) - }) - } - - exports.pbkdf2Sync = function(key, salt, iterations, keylen) { - if('number' !== typeof iterations) - throw new TypeError('Iterations not a number') - if(iterations < 0) - throw new TypeError('Bad iterations') - if('number' !== typeof keylen) - throw new TypeError('Key length not a number') - if(keylen < 0) - throw new TypeError('Bad key length') - - //stretch key to the correct length that hmac wants it, - //otherwise this will happen every time hmac is called - //twice per iteration. - var 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 HMAC; - var cplen, p = 0, i = 1, itmp = new Buffer(4), digtmp; - var out = new Buffer(keylen); - out.fill(0); - while(keylen) { - if(keylen > 20) - cplen = 20; - else - cplen = keylen; - - /* We are unlikely to ever use more than 256 blocks (5120 bits!) - * but just in case... - */ - itmp[0] = (i >> 24) & 0xff; - itmp[1] = (i >> 16) & 0xff; - itmp[2] = (i >> 8) & 0xff; - itmp[3] = i & 0xff; - - HMAC = createHmac('sha1', key); - HMAC.update(salt) - HMAC.update(itmp); - digtmp = HMAC.digest(); - digtmp.copy(out, p, 0, cplen); - - for(var j = 1; j < iterations; j++) { - HMAC = createHmac('sha1', key); - HMAC.update(digtmp); - digtmp = HMAC.digest(); - for(var k = 0; k < cplen; k++) { - out[k] ^= digtmp[k]; - } - } - keylen -= cplen; - i++; - p += cplen; - } + var exported = pbkdf2Export(crypto) - return out; - } + exports.pbkdf2 = exported.pbkdf2 + exports.pbkdf2Sync = exported.pbkdf2Sync return exports } From 080b93070b9060e0a91671077cf4706f5658815c Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Wed, 24 Sep 2014 12:27:05 +0300 Subject: [PATCH 016/217] 3.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9c2f25d..ea21d57 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.2.0", + "version": "3.2.1", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 64914fae33c4fd9891a1ecb7d2b76269c67fa15f Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Wed, 24 Sep 2014 13:28:34 +0300 Subject: [PATCH 017/217] work in node, and have more helpful error message --- rng.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/rng.js b/rng.js index 8c39ef3..e0d2313 100644 --- a/rng.js +++ b/rng.js @@ -1,10 +1,27 @@ (function() { + var g = ('undefined' === typeof window ? global : window) || {} + var foolBrowserify = require + _crypto = ( + g.crypto || g.msCrypto || foolBrowserify('crypto') + ) module.exports = function(size) { - var bytes = new Buffer(size); //in browserify, this is an extended Uint8Array - /* This will not work in older browsers. - * See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues - */ - crypto.getRandomValues(bytes); - return bytes; + // Modern Browsers + if(_crypto.getRandomValues) { + var bytes = new Buffer(size); //in browserify, this is an extended Uint8Array + /* This will not work in older browsers. + * See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues + */ + + _crypto.getRandomValues + return bytes; + } + else if (_crypto.randomBytes) { + return _crypto.randomBytes(size) + } + else + throw new Error( + 'secure random number generation not supported by this browser\n'+ + 'use chrome, FireFox or Internet Explorer 11' + ) } }()) From 95ac33b9201f7cbc27cee95516bae66ebc6a83b6 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Wed, 24 Sep 2014 13:40:43 +0300 Subject: [PATCH 018/217] drop 0.8 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3079f62..7a589da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ language: node_js node_js: - - 0.8 - "0.10" From ce9bf42a00c323fd3f84e33c1ca60e0271dde1e9 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Wed, 24 Sep 2014 13:44:53 +0300 Subject: [PATCH 019/217] 3.2.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ea21d57..b80cea4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.2.1", + "version": "3.2.2", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 0f9c39cd6a6cd705b901482e186fac619768b8f3 Mon Sep 17 00:00:00 2001 From: Christian Kaatz Date: Wed, 24 Sep 2014 17:14:28 +0200 Subject: [PATCH 020/217] bump pbkdf2-compat version to accomodate a dependency fix there --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b80cea4..fe135d7 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "node": "*" }, "dependencies": { - "pbkdf2-compat": "2.0.0", + "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", "sha.js": "2.2.6" }, From 3b8d46cac706fea2551a0367732b6643a729bb7c Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Wed, 24 Sep 2014 22:22:42 +0300 Subject: [PATCH 021/217] 3.2.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fe135d7..0ce119c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.2.2", + "version": "3.2.3", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 3267955e1df7edd1680e52aeede9a89506ed2464 Mon Sep 17 00:00:00 2001 From: Alex Layton Date: Wed, 24 Sep 2014 20:07:03 -0400 Subject: [PATCH 022/217] Fix rng.js for modern browsers getRandomValues was not being called, and an array of zeros was being returned. --- rng.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rng.js b/rng.js index e0d2313..d5cff24 100644 --- a/rng.js +++ b/rng.js @@ -12,7 +12,7 @@ * See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues */ - _crypto.getRandomValues + _crypto.getRandomValues(bytes); return bytes; } else if (_crypto.randomBytes) { From c31b9d711d3e2603c6587cb00d1f64c9a559d4d4 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Thu, 25 Sep 2014 03:30:04 +0300 Subject: [PATCH 023/217] 3.2.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0ce119c..4ff443f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.2.3", + "version": "3.2.4", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 72336c9fc0df931c3199ee07d84d1faa4c1b2b77 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Fri, 26 Sep 2014 00:00:57 +0300 Subject: [PATCH 024/217] catch horrible mistakes that break the rng, like if it returns all zeros --- test/random-bytes.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/random-bytes.js b/test/random-bytes.js index eda9ed7..cf61421 100644 --- a/test/random-bytes.js +++ b/test/random-bytes.js @@ -13,4 +13,29 @@ test('randomBytes', function (t) { }); }); +test('randomBytes seem random', function (t) { + + var L = 1000 + var b = crypto.randomBytes(L) + + var mean = [].reduce.call(b, function (a, b) { return a + b}, 0) / L + + // test that the random numbers are plausably random. + // Math.random() will pass this, but this will catch + // terrible mistakes such as this blunder: + // https://github.com/dominictarr/crypto-browserify/commit/3267955e1df7edd1680e52aeede9a89506ed2464#commitcomment-7916835 + + // this doesn't check that the bytes are in a random *order* + // but it's better than nothing. + + var expected = 256/2 + var smean = Math.sqrt(mean) + + t.ok(mean < expected + smean) + t.ok(mean > expected - smean) + + t.end() + +}) + From a9b55a8aaaf42e274c4ed5a53b628030955a0ba1 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Fri, 26 Sep 2014 00:26:22 +0300 Subject: [PATCH 025/217] use Buffer.isBuffer(b) to test that randomBytes returns a buffer, not instanceof --- test/random-bytes.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/random-bytes.js b/test/random-bytes.js index cf61421..4cc34f3 100644 --- a/test/random-bytes.js +++ b/test/random-bytes.js @@ -4,11 +4,11 @@ var crypto = require('../') test('randomBytes', function (t) { t.plan(5); t.equal(crypto.randomBytes(10).length, 10); - t.ok(crypto.randomBytes(10) instanceof Buffer); + t.ok(Buffer.isBuffer(crypto.randomBytes(10))) crypto.randomBytes(10, function(ex, bytes) { t.error(ex); t.equal(bytes.length, 10); - t.ok(bytes instanceof Buffer); + t.ok(Buffer.isBuffer(bytes)) t.end(); }); }); @@ -30,7 +30,7 @@ test('randomBytes seem random', function (t) { var expected = 256/2 var smean = Math.sqrt(mean) - + console.log(expected - smean, mean, expected + smean) t.ok(mean < expected + smean) t.ok(mean > expected - smean) From 7014a90294e963fef06f3a3bb5266c94d870ab9d Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Fri, 26 Sep 2014 00:26:39 +0300 Subject: [PATCH 026/217] fix testling glob --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ff443f..1b33b86 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "hash-test-vectors": "~1.3.0" }, "testling": { - "files": "test/*.js-", + "files": "test/*.js", "browsers": [ "ie/latest", "chrome/latest", From 57407fc5d42864e4b112e5d1686a2a618691250c Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Fri, 26 Sep 2014 00:26:46 +0300 Subject: [PATCH 027/217] 3.2.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1b33b86..6679122 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.2.4", + "version": "3.2.5", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From f2ab273a44fa61b25dc2e2c4aa2043c0709d26ea Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Fri, 26 Sep 2014 00:49:28 +0300 Subject: [PATCH 028/217] fix for testling --- test/random-bytes.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/random-bytes.js b/test/random-bytes.js index 4cc34f3..7b558a5 100644 --- a/test/random-bytes.js +++ b/test/random-bytes.js @@ -30,7 +30,8 @@ test('randomBytes seem random', function (t) { var expected = 256/2 var smean = Math.sqrt(mean) - console.log(expected - smean, mean, expected + smean) + //console.log doesn't work right on testling, *grumble grumble* + console.log(JSON.stringify([expected - smean, mean, expected + smean])) t.ok(mean < expected + smean) t.ok(mean > expected - smean) From 9284566e7e8e468c0d30bf946ed8342494836c8d Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Fri, 26 Sep 2014 01:18:48 +0300 Subject: [PATCH 029/217] if rng is not available, other features should still work --- rng.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rng.js b/rng.js index d5cff24..e69a95a 100644 --- a/rng.js +++ b/rng.js @@ -1,6 +1,8 @@ (function() { var g = ('undefined' === typeof window ? global : window) || {} - var foolBrowserify = require + var foolBrowserify = function (r) { + try { return require(r) } catch (_) { } + } _crypto = ( g.crypto || g.msCrypto || foolBrowserify('crypto') ) From 9bf8520aca58d710e0b7ec54942eb1ba78a0693f Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Fri, 3 Oct 2014 13:10:07 -0200 Subject: [PATCH 030/217] test that the error message is right, or a buffer is returned --- test/random-bytes.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/random-bytes.js b/test/random-bytes.js index 7b558a5..417f2db 100644 --- a/test/random-bytes.js +++ b/test/random-bytes.js @@ -1,6 +1,19 @@ var test = require('tape') var crypto = require('../') +test('get error message', function (t) { + + try { + var b = crypto.randomBytes(10) + t.ok(Buffer.isBuffer(b)) + t.end() + } catch (err) { + t.ok(/not supported/.test(err.message), '"not supported" is in error message') + t.end() + } + +}) + test('randomBytes', function (t) { t.plan(5); t.equal(crypto.randomBytes(10).length, 10); From 504ff17dd8c522b32818b3bf3b25fb9dc7edf77e Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Fri, 3 Oct 2014 13:10:36 -0200 Subject: [PATCH 031/217] ensure a helpful error message in browsers without randomValues --- rng.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rng.js b/rng.js index e69a95a..a21b587 100644 --- a/rng.js +++ b/rng.js @@ -4,7 +4,7 @@ try { return require(r) } catch (_) { } } _crypto = ( - g.crypto || g.msCrypto || foolBrowserify('crypto') + g.crypto || g.msCrypto || foolBrowserify('crypto') || {} ) module.exports = function(size) { // Modern Browsers From 4997928aec9cb52b0dd49688b96fbdb96399e172 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Fri, 3 Oct 2014 13:10:43 -0200 Subject: [PATCH 032/217] 3.2.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6679122..91d070b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.2.5", + "version": "3.2.6", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From c72a10168861e844ef3f792bf4d3fb26250849a8 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 9 Oct 2014 13:46:16 +0200 Subject: [PATCH 033/217] improve way native modules are handled fixes webpack/node-libs-browser#15 --- package.json | 3 +++ rng.js | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 91d070b..9600967 100644 --- a/package.json +++ b/package.json @@ -34,5 +34,8 @@ ] }, "optionalDependencies": {}, + "browser": { + "crypto": false + }, "license": "MIT" } diff --git a/rng.js b/rng.js index a21b587..0f140bb 100644 --- a/rng.js +++ b/rng.js @@ -1,10 +1,7 @@ (function() { var g = ('undefined' === typeof window ? global : window) || {} - var foolBrowserify = function (r) { - try { return require(r) } catch (_) { } - } _crypto = ( - g.crypto || g.msCrypto || foolBrowserify('crypto') || {} + g.crypto || g.msCrypto || require('crypto') ) module.exports = function(size) { // Modern Browsers From ceed76c0a9270469fbea4916327f3e2750537225 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Thu, 9 Oct 2014 10:19:43 -0200 Subject: [PATCH 034/217] 3.2.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9600967..d2e1daf 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.2.6", + "version": "3.2.7", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 6698379a3df5a2b4229224f267ea0cb57d0d3bca Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 15 Oct 2014 17:30:58 -0400 Subject: [PATCH 035/217] aes --- index.js | 6 +----- package.json | 3 ++- test/aes.js | 6 ++++++ 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 test/aes.js diff --git a/index.js b/index.js index 54efb88..c2ab2c5 100644 --- a/index.js +++ b/index.js @@ -35,14 +35,10 @@ exports.getHashes = function () { var p = require('./pbkdf2')(exports) exports.pbkdf2 = p.pbkdf2 exports.pbkdf2Sync = p.pbkdf2Sync - +require('browserify-aes').__browserify(exports, module.exports); // the least I can do is make error messages for the rest of the node.js/crypto api. each(['createCredentials' -, 'createCipher' -, 'createCipheriv' -, 'createDecipher' -, 'createDecipheriv' , 'createSign' , 'createVerify' , 'createDiffieHellman' diff --git a/package.json b/package.json index d2e1daf..6d5a025 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "dependencies": { "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", - "sha.js": "2.2.6" + "sha.js": "2.2.6", + "browserify-aes": "0.0.0" }, "devDependencies": { "tape": "~2.3.2", diff --git a/test/aes.js b/test/aes.js new file mode 100644 index 0000000..0b108af --- /dev/null +++ b/test/aes.js @@ -0,0 +1,6 @@ +var test = require('tape'); + +test('ciphers', function (t) { + t.ok(require('../').listCiphers().length); + t.end(); +}); \ No newline at end of file From 4f33a405a44eb802cd6967fb71334a2ab1174e9d Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 16 Oct 2014 09:54:50 -0400 Subject: [PATCH 036/217] bump aes, add tests --- package.json | 2 +- test/aes.js | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 6d5a025..be0f21f 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", "sha.js": "2.2.6", - "browserify-aes": "0.0.0" + "browserify-aes": "0.1.0" }, "devDependencies": { "tape": "~2.3.2", diff --git a/test/aes.js b/test/aes.js index 0b108af..090b27e 100644 --- a/test/aes.js +++ b/test/aes.js @@ -1,6 +1,18 @@ var test = require('tape'); - +var crypto = require('../'); test('ciphers', function (t) { - t.ok(require('../').listCiphers().length); - t.end(); + crypto.listCiphers().forEach(function (cipher) { + t.test(cipher, function (t) { + t.plan(1); + var data = crypto.randomBytes(562); + var password = crypto.randomBytes(20); + var crypter = crypto.createCipher(cipher, password); + var decrypter = crypto.createDecipher(cipher, password); + var out = []; + out.push(decrypter.update(crypter.update(data))); + out.push(decrypter.update(crypter.final())); + out.push(decrypter.final()); + t.equals(data.toString('hex'), Buffer.concat(out).toString('hex')); + }); + }); }); \ No newline at end of file From 5fd6d41ff2f60773cd94a66f429e2523a432d7bb Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 16 Oct 2014 10:25:51 -0400 Subject: [PATCH 037/217] update readme --- readme.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.markdown b/readme.markdown index 6a00282..cde8966 100644 --- a/readme.markdown +++ b/readme.markdown @@ -16,14 +16,14 @@ Here is the subset that is currently implemented: * pbkdf2 * pbkdf2Sync * randomBytes +* createCipher (aes) +* createDecipher (aes) ## TODO The highest priority unimplemented features are * createDiffieHelman -* createCipher (aes) -* createDecipher (aes) * createSign (rsa) * createVerify (rsa) From 1827a0351cee649322a9c893bba01e03075ab7e5 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 16 Oct 2014 15:10:59 -0400 Subject: [PATCH 038/217] update browserify-aes for ctr and ofb --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index be0f21f..8a591a2 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", "sha.js": "2.2.6", - "browserify-aes": "0.1.0" + "browserify-aes": "0.2.0" }, "devDependencies": { "tape": "~2.3.2", From 66f9f2c6400d303675049558cc5fe9a1e7db894b Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 16 Oct 2014 18:35:47 -0400 Subject: [PATCH 039/217] bump to 0.2.1 for ctr typo --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8a591a2..41d543e 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", "sha.js": "2.2.6", - "browserify-aes": "0.2.0" + "browserify-aes": "0.2.1" }, "devDependencies": { "tape": "~2.3.2", From b7f0194b92cf91b7ca6653ad9c56d7b896a18a46 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Fri, 17 Oct 2014 08:54:21 -0400 Subject: [PATCH 040/217] bump to 0.2.2 which was reorginized and has some more tests --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 41d543e..652b006 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", "sha.js": "2.2.6", - "browserify-aes": "0.2.1" + "browserify-aes": "0.2.2" }, "devDependencies": { "tape": "~2.3.2", From 1aef109a1d959248229eb0036a6795c0db96d32d Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Mon, 20 Oct 2014 12:10:40 +0000 Subject: [PATCH 041/217] avoid circular dependency in pbkdf2-compat --- pbkdf2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pbkdf2.js b/pbkdf2.js index 33753e9..88382f4 100644 --- a/pbkdf2.js +++ b/pbkdf2.js @@ -1,4 +1,4 @@ -var pbkdf2Export = require('pbkdf2-compat').__pbkdf2Export +var pbkdf2Export = require('pbkdf2-compat/pbkdf2') module.exports = function (crypto, exports) { exports = exports || {} From bbf4bce8d6f9ec644f8b158111793be72aa123af Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Mon, 20 Oct 2014 12:19:35 +0000 Subject: [PATCH 042/217] 3.2.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d2e1daf..ecfcb41 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.2.7", + "version": "3.2.8", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From da3cc52b78c1b4c149539071f207b4ff124dfc52 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 28 Oct 2014 16:13:24 -0400 Subject: [PATCH 043/217] bump aes version to 0.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 652b006..53a25bf 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", "sha.js": "2.2.6", - "browserify-aes": "0.2.2" + "browserify-aes": "0.4.0" }, "devDependencies": { "tape": "~2.3.2", From 1e0f0533afa73df1f6bb2dadf7e0e2d684566da3 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 28 Oct 2014 16:13:39 -0400 Subject: [PATCH 044/217] link directly to dependency injector for aes --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index c2ab2c5..3283c28 100644 --- a/index.js +++ b/index.js @@ -35,7 +35,7 @@ exports.getHashes = function () { var p = require('./pbkdf2')(exports) exports.pbkdf2 = p.pbkdf2 exports.pbkdf2Sync = p.pbkdf2Sync -require('browserify-aes').__browserify(exports, module.exports); +require('browserify-aes/inject')(exports, module.exports); // the least I can do is make error messages for the rest of the node.js/crypto api. each(['createCredentials' From 0f1821f6233548f632de2b5658c895fa7a8e3d3d Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Sat, 1 Nov 2014 16:54:01 +0100 Subject: [PATCH 045/217] 3.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f1d933c..0c93704 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.2.8", + "version": "3.3.0", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From e19db42f8d139c78bfd540910ebe8352c0f9b645 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 4 Nov 2014 10:30:32 -0500 Subject: [PATCH 046/217] diffie-hellman --- index.js | 3 +-- package.json | 3 ++- readme.markdown | 2 +- test/dh.js | 24 ++++++++++++++++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 test/dh.js diff --git a/index.js b/index.js index 3283c28..ae902f4 100644 --- a/index.js +++ b/index.js @@ -36,12 +36,11 @@ var p = require('./pbkdf2')(exports) exports.pbkdf2 = p.pbkdf2 exports.pbkdf2Sync = p.pbkdf2Sync require('browserify-aes/inject')(exports, module.exports); - +require('diffie-hellman/inject')(exports, module.exports); // the least I can do is make error messages for the rest of the node.js/crypto api. each(['createCredentials' , 'createSign' , 'createVerify' -, 'createDiffieHellman' ], function (name) { exports[name] = function () { error('sorry,', name, 'is not implemented yet') diff --git a/package.json b/package.json index 0c93704..2bae1b9 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", "sha.js": "2.2.6", - "browserify-aes": "0.4.0" + "browserify-aes": "0.4.0", + "diffie-hellman": "1.0.3" }, "devDependencies": { "tape": "~2.3.2", diff --git a/readme.markdown b/readme.markdown index cde8966..f634fa6 100644 --- a/readme.markdown +++ b/readme.markdown @@ -18,12 +18,12 @@ Here is the subset that is currently implemented: * randomBytes * createCipher (aes) * createDecipher (aes) +* createDiffieHelman ## TODO The highest priority unimplemented features are -* createDiffieHelman * createSign (rsa) * createVerify (rsa) diff --git a/test/dh.js b/test/dh.js new file mode 100644 index 0000000..33a9576 --- /dev/null +++ b/test/dh.js @@ -0,0 +1,24 @@ +var test = require('tape'); +var crypto = require('../'); +test('diffie-hellman', function (t) { + [ + 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16'/*, 'modp17', 'modp18'*/ + ].forEach(function (mod) { + t.test(mod, function (t){ + t.plan(3); + var dh1 = crypto.getDiffieHellman(mod); + var p1 = dh1.getPrime().toString('hex'); + dh1.generateKeys(); + var dh2 = crypto.getDiffieHellman(mod); + var p2 = dh2.getPrime().toString('hex'); + dh2.generateKeys(); + t.equals(p1, p2, 'equal primes'); + var pubk1 = dh1.getPublicKey(); + var pubk2 = dh2.getPublicKey(); + t.notEquals(pubk1, pubk2, 'diff public keys'); + var pub1 = dh1.computeSecret(pubk2).toString('hex'); + var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex'); + t.equals(pub1, pub2, 'equal secrets'); + }); + }); +}); \ No newline at end of file From b0ae39e5f2076a35d9c48840a2e791b62f7cb43a Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 5 Nov 2014 09:44:11 -0500 Subject: [PATCH 047/217] generate primes --- package.json | 2 +- test/dh.js | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2bae1b9..b9decfb 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "ripemd160": "0.2.0", "sha.js": "2.2.6", "browserify-aes": "0.4.0", - "diffie-hellman": "1.0.3" + "diffie-hellman": "1.1.0" }, "devDependencies": { "tape": "~2.3.2", diff --git a/test/dh.js b/test/dh.js index 33a9576..e7259ef 100644 --- a/test/dh.js +++ b/test/dh.js @@ -1,6 +1,6 @@ var test = require('tape'); var crypto = require('../'); -test('diffie-hellman', function (t) { +test('diffie-hellman mod groups', function (t) { [ 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16'/*, 'modp17', 'modp18'*/ ].forEach(function (mod) { @@ -21,4 +21,27 @@ test('diffie-hellman', function (t) { t.equals(pub1, pub2, 'equal secrets'); }); }); +}); +test('diffie-hellman key lengths', function (t) { + [ + 64, 65, 192, 224, 256, 386, 512, 1024, 2048 + ].forEach(function (len) { + t.test('' + len, function (t){ + t.plan(3); + var dh2 = crypto.createDiffieHellman(len); + var prime2 = dh2.getPrime(); + var p2 = prime2.toString('hex'); + var dh1 = crypto.createDiffieHellman(prime2); + var p1 = dh1.getPrime().toString('hex'); + dh1.generateKeys(); + dh2.generateKeys(); + t.equals(p1, p2, 'equal primes'); + var pubk1 = dh1.getPublicKey(); + var pubk2 = dh2.getPublicKey(); + t.notEquals(pubk1, pubk2, 'diff public keys'); + var pub1 = dh1.computeSecret(pubk2).toString('hex'); + var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex'); + t.equals(pub1, pub2, 'equal secrets'); + }); + }); }); \ No newline at end of file From a6fd6ea0de8e64ace94688db22f3ea08fbe6f51a Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Fri, 7 Nov 2014 07:55:36 -0500 Subject: [PATCH 048/217] fix modp17 and modp18 --- package.json | 2 +- test/dh.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b9decfb..05e2f19 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "ripemd160": "0.2.0", "sha.js": "2.2.6", "browserify-aes": "0.4.0", - "diffie-hellman": "1.1.0" + "diffie-hellman": "1.1.1" }, "devDependencies": { "tape": "~2.3.2", diff --git a/test/dh.js b/test/dh.js index e7259ef..6bacc05 100644 --- a/test/dh.js +++ b/test/dh.js @@ -2,7 +2,7 @@ var test = require('tape'); var crypto = require('../'); test('diffie-hellman mod groups', function (t) { [ - 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16'/*, 'modp17', 'modp18'*/ + 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16', 'modp17', 'modp18' ].forEach(function (mod) { t.test(mod, function (t){ t.plan(3); From 893bd44bc78958b54345f693668ffd84ac0f0c45 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Fri, 7 Nov 2014 08:31:31 -0500 Subject: [PATCH 049/217] same methods as node --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 05e2f19..bbfb891 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "ripemd160": "0.2.0", "sha.js": "2.2.6", "browserify-aes": "0.4.0", - "diffie-hellman": "1.1.1" + "diffie-hellman": "1.1.2" }, "devDependencies": { "tape": "~2.3.2", From 9856a51118f7184197e0c152742b170d8e4d188d Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Sat, 8 Nov 2014 01:34:19 +0100 Subject: [PATCH 050/217] adapt @calvinmetcalf's dh test to check node and crypto-browserify are fully compatible --- test/node/dh.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/node/dh.js diff --git a/test/node/dh.js b/test/node/dh.js new file mode 100644 index 0000000..f79431c --- /dev/null +++ b/test/node/dh.js @@ -0,0 +1,51 @@ +var test = require('tape'); +var cryptoB = require('../../'); +var crypto = require('crypto') + +test('diffie-hellman mod groups', function (t) { + [ + 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16', 'modp17', 'modp18' + ].forEach(function (mod) { + t.test(mod, function (t){ + t.plan(3); + var dh1 = cryptoB.getDiffieHellman(mod); + var p1 = dh1.getPrime().toString('hex'); + dh1.generateKeys(); + + var dh2 = crypto.getDiffieHellman(mod); + var p2 = dh2.getPrime().toString('hex'); + dh2.generateKeys(); + t.equals(p1, p2, 'equal primes'); + var pubk1 = dh1.getPublicKey(); + var pubk2 = dh2.getPublicKey(); + t.notEquals(pubk1, pubk2, 'diff public keys'); + var pub1 = dh1.computeSecret(pubk2).toString('hex'); + var pub2 = dh2.computeSecret(pubk1).toString('hex'); + t.equals(pub1, pub2, 'equal secrets'); + }); + }); +}); + +test('diffie-hellman key lengths', function (t) { + [ + 64, 65, 192, 224, 256, 386, 512, 1024, 2048 + ].forEach(function (len) { + t.test('' + len, function (t){ + t.plan(3); + var dh2 = cryptoB.createDiffieHellman(len); + var prime2 = dh2.getPrime(); + var p2 = prime2.toString('hex'); + var dh1 = crypto.createDiffieHellman(prime2); + var p1 = dh1.getPrime().toString('hex'); + dh1.generateKeys(); + dh2.generateKeys(); + t.equals(p1, p2, 'equal primes'); + var pubk1 = dh1.getPublicKey(); + var pubk2 = dh2.getPublicKey(); + t.notEquals(pubk1, pubk2, 'diff public keys'); + var pub1 = dh1.computeSecret(pubk2).toString('hex'); + var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex'); + t.equals(pub1, pub2, 'equal secrets'); + }); + }); +}); From 8b0c051b7aee3d77af327628278f34b5771181f1 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Sat, 8 Nov 2014 01:34:44 +0100 Subject: [PATCH 051/217] have some tests just for node --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bbfb891..af805b5 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "url": "git://github.com/dominictarr/crypto-browserify.git" }, "scripts": { - "test": "set -e; for t in test/*.js; do node $t; done" + "test": "set -e; for t in test/node/*.js test/*.js; do node $t; done" }, "engines": { "node": "*" From 801247693beeb43f6096e557042e0df68656cb5e Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 11 Nov 2014 18:53:45 -0500 Subject: [PATCH 052/217] more modes of operation --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0c93704..cc2639d 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", "sha.js": "2.2.6", - "browserify-aes": "0.4.0" + "browserify-aes": "0.6.0" }, "devDependencies": { "tape": "~2.3.2", From 3b6d236ddc06b4411d7faa85d5fa0432b1423b3b Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 12 Nov 2014 08:26:20 -0500 Subject: [PATCH 053/217] working tests --- test/aes.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/aes.js b/test/aes.js index 090b27e..cf516a5 100644 --- a/test/aes.js +++ b/test/aes.js @@ -11,6 +11,9 @@ test('ciphers', function (t) { var out = []; out.push(decrypter.update(crypter.update(data))); out.push(decrypter.update(crypter.final())); + if (cipher.indexOf('gcm') > -1) { + decrypter.setAuthTag(crypter.getAuthTag()); + } out.push(decrypter.final()); t.equals(data.toString('hex'), Buffer.concat(out).toString('hex')); }); From 30d96df5f6cdbe8ecdb4e7ef584a218ba3e302e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20Schw=C3=B6rer?= Date: Thu, 13 Nov 2014 00:13:39 +0100 Subject: [PATCH 054/217] use local var for _crypto this fixes a problem "undefined var _crypto" i have when using this with webpack --- rng.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rng.js b/rng.js index 0f140bb..9f9df6d 100644 --- a/rng.js +++ b/rng.js @@ -1,5 +1,5 @@ (function() { - var g = ('undefined' === typeof window ? global : window) || {} + var g = ('undefined' === typeof window ? global : window) || {}, _crypto = ( g.crypto || g.msCrypto || require('crypto') ) From 4effea2606eafdde530f30270f398fb74fb9e4b5 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 16 Nov 2014 11:50:30 -0500 Subject: [PATCH 055/217] add sign/verify --- index.js | 4 +--- package.json | 5 +++-- readme.markdown | 4 ++-- test/sign.js | 28 ++++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 test/sign.js diff --git a/index.js b/index.js index 3283c28..65e29d8 100644 --- a/index.js +++ b/index.js @@ -36,11 +36,9 @@ var p = require('./pbkdf2')(exports) exports.pbkdf2 = p.pbkdf2 exports.pbkdf2Sync = p.pbkdf2Sync require('browserify-aes/inject')(exports, module.exports); - +require('browserify-sign/inject')(module.exports, exports); // the least I can do is make error messages for the rest of the node.js/crypto api. each(['createCredentials' -, 'createSign' -, 'createVerify' , 'createDiffieHellman' ], function (name) { exports[name] = function () { diff --git a/package.json b/package.json index 0c93704..8bdd10b 100644 --- a/package.json +++ b/package.json @@ -15,10 +15,11 @@ "node": "*" }, "dependencies": { + "browserify-aes": "0.4.0", + "browserify-sign": "2.4.0", "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", - "sha.js": "2.2.6", - "browserify-aes": "0.4.0" + "sha.js": "2.2.6" }, "devDependencies": { "tape": "~2.3.2", diff --git a/readme.markdown b/readme.markdown index cde8966..114609e 100644 --- a/readme.markdown +++ b/readme.markdown @@ -18,14 +18,14 @@ Here is the subset that is currently implemented: * randomBytes * createCipher (aes) * createDecipher (aes) +* createSign (rsa, ecdsa) +* createVerify (rsa, ecdsa) ## TODO The highest priority unimplemented features are * createDiffieHelman -* createSign (rsa) -* createVerify (rsa) ## contributions diff --git a/test/sign.js b/test/sign.js new file mode 100644 index 0000000..1dacc89 --- /dev/null +++ b/test/sign.js @@ -0,0 +1,28 @@ +var test = require('tape'); +var crypto = require('../'); +var rsa = { + "private": "2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a", + "public": "2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a" +}; +var ec = { + "private": "2d2d2d2d2d424547494e2045432050524956415445204b45592d2d2d2d2d0a4d485143415145454944463658763853762f2f77475557442b6337383070704772553051645a5743417a78415150515838722f756f416347425375424241414b0a6f55514451674145495a656f7744796c6c73344b2f7766426a4f313862596f37674778386e595152696a6134652f71454d696b4f484a616937676565557265550a7235586b792f4178377332644774656773504e7350674765354d705176673d3d0a2d2d2d2d2d454e442045432050524956415445204b45592d2d2d2d2d0a", + "public": "2d2d2d2d2d424547494e205055424c4943204b45592d2d2d2d2d0a4d465977454159484b6f5a497a6a3043415159464b34454541416f4451674145495a656f7744796c6c73344b2f7766426a4f313862596f37674778386e5951520a696a6134652f71454d696b4f484a616937676565557265557235586b792f4178377332644774656773504e7350674765354d705176673d3d0a2d2d2d2d2d454e44205055424c4943204b45592d2d2d2d2d0a" +}; + +rsa.private = new Buffer(rsa.private, 'hex'); +rsa.public = new Buffer(rsa.public, 'hex'); +ec.private = new Buffer(rsa.private, 'hex'); +ec.public = new Buffer(rsa.public, 'hex'); +function testit(keys, message, scheme) { + var pub = keys.public; + var priv = keys.private; + test(message.toString(), function (t) { + t.plan(1); + var mySign = crypto.createSign(scheme); + var mySig = mySign.update(message).sign(priv); + var myVer = crypto.createVerify(scheme); + t.ok(myVer.update(message).verify(pub, mySig), 'validates'); + }); +} +testit(rsa, new Buffer('rsa with sha256'), 'RSA-SHA256'); +testit(ec, new Buffer('ec with sha1'), 'ecdsa-with-SHA1'); \ No newline at end of file From b49e9f21ec33fedd2af440d8d8824decebbd8580 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 16 Nov 2014 14:54:33 -0500 Subject: [PATCH 056/217] bump dh version, tweak tests --- package.json | 2 +- test/dh.js | 6 +++--- test/node/dh.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index af805b5..6761956 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "ripemd160": "0.2.0", "sha.js": "2.2.6", "browserify-aes": "0.4.0", - "diffie-hellman": "1.1.2" + "diffie-hellman": "2.0.0" }, "devDependencies": { "tape": "~2.3.2", diff --git a/test/dh.js b/test/dh.js index 6bacc05..fea0767 100644 --- a/test/dh.js +++ b/test/dh.js @@ -2,7 +2,7 @@ var test = require('tape'); var crypto = require('../'); test('diffie-hellman mod groups', function (t) { [ - 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16', 'modp17', 'modp18' + 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16' ].forEach(function (mod) { t.test(mod, function (t){ t.plan(3); @@ -24,7 +24,7 @@ test('diffie-hellman mod groups', function (t) { }); test('diffie-hellman key lengths', function (t) { [ - 64, 65, 192, 224, 256, 386, 512, 1024, 2048 + 64, 65, 192 ].forEach(function (len) { t.test('' + len, function (t){ t.plan(3); @@ -44,4 +44,4 @@ test('diffie-hellman key lengths', function (t) { t.equals(pub1, pub2, 'equal secrets'); }); }); -}); \ No newline at end of file +}); diff --git a/test/node/dh.js b/test/node/dh.js index f79431c..139a923 100644 --- a/test/node/dh.js +++ b/test/node/dh.js @@ -4,7 +4,7 @@ var crypto = require('crypto') test('diffie-hellman mod groups', function (t) { [ - 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16', 'modp17', 'modp18' + 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16' ].forEach(function (mod) { t.test(mod, function (t){ t.plan(3); @@ -28,7 +28,7 @@ test('diffie-hellman mod groups', function (t) { test('diffie-hellman key lengths', function (t) { [ - 64, 65, 192, 224, 256, 386, 512, 1024, 2048 + 64, 65, 192 ].forEach(function (len) { t.test('' + len, function (t){ t.plan(3); From c6f87a09f6bb0559689077f1cc96f3c790e76da3 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 16 Nov 2014 15:28:04 -0500 Subject: [PATCH 057/217] specify gen --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6761956..42b7957 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "ripemd160": "0.2.0", "sha.js": "2.2.6", "browserify-aes": "0.4.0", - "diffie-hellman": "2.0.0" + "diffie-hellman": "2.1.0" }, "devDependencies": { "tape": "~2.3.2", From f20cc52dc89ebd0267b15df410d2d8b2a2b30691 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 16 Nov 2014 15:36:49 -0500 Subject: [PATCH 058/217] optimization for gen 5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 42b7957..2055ab6 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "ripemd160": "0.2.0", "sha.js": "2.2.6", "browserify-aes": "0.4.0", - "diffie-hellman": "2.1.0" + "diffie-hellman": "2.2.0" }, "devDependencies": { "tape": "~2.3.2", From 1d0b78cec10d9df0bd1c2c77e92cd357f649aa9f Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 17 Nov 2014 08:57:50 -0500 Subject: [PATCH 059/217] streams for hashes --- create-hash.js | 100 +++++++++++++++++++++++++++++++++----------- test/create-hash.js | 10 ++++- 2 files changed, 84 insertions(+), 26 deletions(-) diff --git a/create-hash.js b/create-hash.js index f826f30..83a344c 100644 --- a/create-hash.js +++ b/create-hash.js @@ -1,30 +1,82 @@ var createHash = require('sha.js') -var md5 = toConstructor(require('./md5')) -var rmd160 = toConstructor(require('ripemd160')) - -function toConstructor (fn) { - return function () { - var buffers = [] - var m= { - update: function (data, enc) { - if(!Buffer.isBuffer(data)) data = new Buffer(data, enc) - buffers.push(data) - return this - }, - digest: function (enc) { - var buf = Buffer.concat(buffers) - var r = fn(buf) - buffers = null - return enc ? r.toString(enc) : r - } - } - return m +var md5 = require('./md5') +var rmd160 = require('ripemd160') +var Transform = require('stream').Transform; +var inherits = require('util').inherits + +module.exports = function (alg) { + if('md5' === alg) return new HashNoConstructor(md5) + if('rmd160' === alg) return new HashNoConstructor(rmd160) + return new Hash(createHash(alg)) +} +inherits(HashNoConstructor, Transform) + +function HashNoConstructor(hash) { + Transform.call(this); + this._hash = hash + this.buffers = [] +} + +HashNoConstructor.prototype._transform = function (data, _, done) { + this.buffers.push(data) + done() +} +HashNoConstructor.prototype._flush = function (done) { + var buf = Buffer.concat(this.buffers) + var r = this._hash(buf) + this.buffers = null + this.push(r) + done() +} +HashNoConstructor.prototype.update = function (data, enc) { + this.write(data, enc) + return this +} + +HashNoConstructor.prototype.digest = function (enc) { + this.end() + var outData = new Buffer('') + var chunk + while ((chunk = this.read())) { + outData = Buffer.concat([outData, chunk]) + } + if (enc) { + outData = outData.toString(enc) } + return outData } -module.exports = function (alg) { - if('md5' === alg) return new md5() - if('rmd160' === alg) return new rmd160() - return createHash(alg) +inherits(Hash, Transform) + +function Hash(hash) { + Transform.call(this); + this._hash = hash +} + +Hash.prototype._transform = function (data, _, done) { + this._hash.update(data) + done() +} +Hash.prototype._flush = function (done) { + this.push(this._hash.digest()) + this._hash = null + done() +} +Hash.prototype.update = function (data, enc) { + this.write(data, enc) + return this +} + +Hash.prototype.digest = function (enc) { + this.end() + var outData = new Buffer('') + var chunk + while ((chunk = this.read())) { + outData = Buffer.concat([outData, chunk]) + } + if (enc) { + outData = outData.toString(enc) + } + return outData } diff --git a/test/create-hash.js b/test/create-hash.js index 60a5e74..bbe1174 100644 --- a/test/create-hash.js +++ b/test/create-hash.js @@ -9,7 +9,6 @@ var createHash = require('../create-hash') algorithms.forEach(function (algorithm) { test('test ' + algorithm + ' against test vectors', function (t) { - vectors.forEach(function (obj, i) { var input = new Buffer(obj.input, 'base64') var node = obj[algorithm] @@ -25,7 +24,14 @@ algorithms.forEach(function (algorithm) { t.equal(js, node, algorithm + '(testVector['+i+'], '+encoding+') == ' + node) }) }); - + vectors.forEach(function (obj, i) { + var input = new Buffer(obj.input, 'base64') + var node = obj[algorithm] + var hash = createHash(algorithm); + hash.end(input) + var js = hash.read().toString('hex') + t.equal(js, node, algorithm + '(testVector['+i+']) == ' + node) + }) t.end() }) }); From c6e6eaeaba66efddc13e660a7049cff7966484b0 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 17 Nov 2014 09:04:05 -0500 Subject: [PATCH 060/217] hmac as stream --- create-hmac.js | 32 +++++++++++++++++++++++++++----- test/create-hmac.js | 13 +++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/create-hmac.js b/create-hmac.js index 65e6e65..cdc9f9c 100644 --- a/create-hmac.js +++ b/create-hmac.js @@ -1,12 +1,15 @@ var createHash = require('./create-hash') - +var Transform = require('stream').Transform; +var inherits = require('util').inherits var zeroBuffer = new Buffer(128) zeroBuffer.fill(0) module.exports = Hmac - +inherits(Hmac, Transform) function Hmac (alg, key) { if(!(this instanceof Hmac)) return new Hmac(alg, key) + + Transform.call(this) this._opad = opad this._alg = alg @@ -32,12 +35,31 @@ function Hmac (alg, key) { } Hmac.prototype.update = function (data, enc) { - this._hash.update(data, enc) + this.write(data, enc) return this } -Hmac.prototype.digest = function (enc) { +Hmac.prototype._transform = function (data, _, next) { + this._hash.update(data) + next() +} + +Hmac.prototype._flush = function (next) { var h = this._hash.digest() - return createHash(this._alg).update(this._opad).update(h).digest(enc) + this.push(createHash(this._alg).update(this._opad).update(h).digest()) + next() +} + +Hmac.prototype.digest = function (enc) { + this.end() + var outData = new Buffer('') + var chunk + while ((chunk = this.read())) { + outData = Buffer.concat([outData, chunk]) + } + if (enc) { + outData = outData.toString(enc) + } + return outData } diff --git a/test/create-hmac.js b/test/create-hmac.js index 9076000..253c046 100644 --- a/test/create-hmac.js +++ b/test/create-hmac.js @@ -18,6 +18,19 @@ algorithms.forEach(function (alg) { t.end() }) + test('hmac('+alg+')', function (t) { + vectors.forEach(function (input, i) { + var hmac = createHmac(alg, new Buffer(input.key, 'hex')) + + hmac.end(input.data, 'hex') + var output = hmac.read() + + output = input.truncate ? output.slice(0, input.truncate) : output + t.equal(output.toString('hex'), input[alg]) + }) + t.end() + }) + }) From a4ed53349155cdd9ffaa683756d4ef6790102eee Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Mon, 17 Nov 2014 17:13:54 +0100 Subject: [PATCH 061/217] 3.4.0 --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index d9a1193..e882442 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.3.0", + "version": "3.4.0", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", @@ -19,7 +19,6 @@ "browserify-sign": "2.4.0", "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", - "browserify-aes": "0.4.0", "diffie-hellman": "2.2.0" }, "devDependencies": { From 5efa463d3fbc4c0db9567243855f04e6e1f9125a Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Mon, 17 Nov 2014 21:36:46 +0100 Subject: [PATCH 062/217] put sha.js back in the deps --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e882442..6883cab 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "browserify-sign": "2.4.0", "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", - "diffie-hellman": "2.2.0" + "diffie-hellman": "2.2.0", + "sha.js": "~2.2.7" }, "devDependencies": { "tape": "~2.3.2", @@ -40,4 +41,4 @@ "crypto": false }, "license": "MIT" -} +} \ No newline at end of file From 78ccc68d28bcb4ef505e3159bbe9de395e1cccc1 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Mon, 17 Nov 2014 21:37:28 +0100 Subject: [PATCH 063/217] 3.4.1 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6883cab..9a499d3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.4.0", + "version": "3.4.1", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", @@ -41,4 +41,4 @@ "crypto": false }, "license": "MIT" -} \ No newline at end of file +} From ce2593913cbd98f55bbfa480004cd2dfcebea232 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Mon, 17 Nov 2014 21:55:36 +0100 Subject: [PATCH 064/217] check deps are correct before publish; and that tests pass --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9a499d3..55fee80 100644 --- a/package.json +++ b/package.json @@ -2,14 +2,15 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.4.1", + "version": "3.4.2", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", "url": "git://github.com/dominictarr/crypto-browserify.git" }, "scripts": { - "test": "set -e; for t in test/node/*.js test/*.js; do node $t; done" + "test": "set -e; for t in test/node/*.js test/*.js; do node $t; done", + "prepublish": "npm ls && npm test" }, "engines": { "node": "*" From 347471d85c797ebe239b3604e57e05e01de0e7a0 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Mon, 17 Nov 2014 21:55:45 +0100 Subject: [PATCH 065/217] 3.4.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 55fee80..bfb16aa 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.4.2", + "version": "3.4.3", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From e919d2ffe0e4304a4114137453996992d84e53bd Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 18 Nov 2014 12:28:32 +0100 Subject: [PATCH 066/217] update sha.js --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bfb16aa..5447bc9 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", "diffie-hellman": "2.2.0", - "sha.js": "~2.2.7" + "sha.js": "2.2.7" }, "devDependencies": { "tape": "~2.3.2", From 5b7613df38003741fe6e4f8580784886ce8d4239 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 18 Nov 2014 14:41:03 +0100 Subject: [PATCH 067/217] everything should use strict --- create-hash.js | 1 + create-hmac.js | 1 + helpers.js | 1 + index.js | 1 + md5.js | 1 + pbkdf2.js | 1 + rng.js | 7 +++++-- 7 files changed, 11 insertions(+), 2 deletions(-) diff --git a/create-hash.js b/create-hash.js index 83a344c..f7d3c90 100644 --- a/create-hash.js +++ b/create-hash.js @@ -1,3 +1,4 @@ +'use strict'; var createHash = require('sha.js') var md5 = require('./md5') diff --git a/create-hmac.js b/create-hmac.js index cdc9f9c..f65a4c0 100644 --- a/create-hmac.js +++ b/create-hmac.js @@ -1,3 +1,4 @@ +'use strict'; var createHash = require('./create-hash') var Transform = require('stream').Transform; var inherits = require('util').inherits diff --git a/helpers.js b/helpers.js index b9e1ed0..cd2e6ca 100644 --- a/helpers.js +++ b/helpers.js @@ -1,3 +1,4 @@ +'use strict'; var intSize = 4; var zeroBuffer = new Buffer(intSize); zeroBuffer.fill(0); var chrsz = 8; diff --git a/index.js b/index.js index 7218b1c..924e9ab 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +'use strict'; var rng = require('./rng') function error () { diff --git a/md5.js b/md5.js index 92067a0..550e788 100644 --- a/md5.js +++ b/md5.js @@ -1,3 +1,4 @@ +'use strict'; /* * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message * Digest Algorithm, as defined in RFC 1321. diff --git a/pbkdf2.js b/pbkdf2.js index 88382f4..0453509 100644 --- a/pbkdf2.js +++ b/pbkdf2.js @@ -1,3 +1,4 @@ +'use strict'; var pbkdf2Export = require('pbkdf2-compat/pbkdf2') module.exports = function (crypto, exports) { diff --git a/rng.js b/rng.js index 9f9df6d..f113eea 100644 --- a/rng.js +++ b/rng.js @@ -1,6 +1,9 @@ +'use strict'; (function() { - var g = ('undefined' === typeof window ? global : window) || {}, + var g = ('undefined' === typeof window ? global : window) || {} _crypto = ( + var g = ('undefined' === typeof window ? global : window) || {} + var _crypto = ( g.crypto || g.msCrypto || require('crypto') ) module.exports = function(size) { @@ -10,7 +13,7 @@ /* This will not work in older browsers. * See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues */ - + _crypto.getRandomValues(bytes); return bytes; } From e53567cfd45add62d715acf7a4b1a93db3757e45 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 18 Nov 2014 14:41:53 +0100 Subject: [PATCH 068/217] use sha.js@2.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5447bc9..3b382bd 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", "diffie-hellman": "2.2.0", - "sha.js": "2.2.7" + "sha.js": "2.3.0" }, "devDependencies": { "tape": "~2.3.2", From c5deca0990b70181e3a09aba564d2b80633596be Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 18 Nov 2014 14:42:57 +0100 Subject: [PATCH 069/217] document the new hash algorithms added in sha.js@2.3.0 --- readme.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.markdown b/readme.markdown index b4ea092..59b2987 100644 --- a/readme.markdown +++ b/readme.markdown @@ -11,8 +11,8 @@ in pure javascript so that it can run in the browser. Here is the subset that is currently implemented: -* createHash (sha1, sha256, sha512, md5, rmd160) -* createHmac (sha1, sha256, sha512, md5) +* createHash (sha1, sha224, sha256, sha384, sha512, md5, rmd160) +* createHmac (sha1, sha224, sha256, sha384, sha512, md5, rmd160) * pbkdf2 * pbkdf2Sync * randomBytes From 6e888842f8d10bd03d793be3e2cb570c361a22c8 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 18 Nov 2014 14:45:22 +0100 Subject: [PATCH 070/217] fix merge error --- rng.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/rng.js b/rng.js index f113eea..7c0929f 100644 --- a/rng.js +++ b/rng.js @@ -1,7 +1,5 @@ 'use strict'; (function() { - var g = ('undefined' === typeof window ? global : window) || {} - _crypto = ( var g = ('undefined' === typeof window ? global : window) || {} var _crypto = ( g.crypto || g.msCrypto || require('crypto') From 8dcb2178a9af5575284eb238d6766c85c0c85f30 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 18 Nov 2014 15:48:06 +0100 Subject: [PATCH 071/217] return correct list of supported hashes in gethashes --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 924e9ab..6a0a6e5 100644 --- a/index.js +++ b/index.js @@ -30,7 +30,7 @@ function each(a, f) { } exports.getHashes = function () { - return ['sha1', 'sha256', 'sha512', 'md5', 'rmd160'] + return ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'] } var p = require('./pbkdf2')(exports) From 837c98a76ad99fe71e18ea36cbcb383dc81e3187 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 18 Nov 2014 16:02:42 +0100 Subject: [PATCH 072/217] 64 bit blocklength for sha512 and sha384 --- create-hmac.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/create-hmac.js b/create-hmac.js index f65a4c0..d9fe4df 100644 --- a/create-hmac.js +++ b/create-hmac.js @@ -14,7 +14,8 @@ function Hmac (alg, key) { this._opad = opad this._alg = alg - var blocksize = (alg === 'sha512') ? 128 : 64 + console.log(alg) + var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64 key = this._key = !Buffer.isBuffer(key) ? new Buffer(key) : key From 22729be29e5fe0ba24470235389d4388b3d429ff Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 18 Nov 2014 16:35:23 +0100 Subject: [PATCH 073/217] remove console.log --- create-hmac.js | 1 - 1 file changed, 1 deletion(-) diff --git a/create-hmac.js b/create-hmac.js index d9fe4df..6d2007e 100644 --- a/create-hmac.js +++ b/create-hmac.js @@ -14,7 +14,6 @@ function Hmac (alg, key) { this._opad = opad this._alg = alg - console.log(alg) var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64 key = this._key = !Buffer.isBuffer(key) ? new Buffer(key) : key From ac5898855fa3ec16e0a75c71dbd4b5a6e528a7f0 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 25 Nov 2014 08:05:18 -0500 Subject: [PATCH 074/217] ecdh --- index.js | 3 ++- package.json | 3 ++- readme.markdown | 2 ++ test/ecdh.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 test/ecdh.js diff --git a/index.js b/index.js index 7218b1c..0ebf58d 100644 --- a/index.js +++ b/index.js @@ -38,10 +38,11 @@ exports.pbkdf2Sync = p.pbkdf2Sync require('browserify-aes/inject')(exports, module.exports); require('browserify-sign/inject')(module.exports, exports); require('diffie-hellman/inject')(exports, module.exports); +require('create-ecdh/inject')(module.exports, exports); // the least I can do is make error messages for the rest of the node.js/crypto api. each([ - 'createCredentials', + 'createCredentials', 'publicEncrypt', 'privateDecrypt' ], function (name) { exports[name] = function () { error('sorry,', name, 'is not implemented yet') diff --git a/package.json b/package.json index bfb16aa..d2d5c38 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,10 @@ "dependencies": { "browserify-aes": "0.4.0", "browserify-sign": "2.4.0", + "create-ecdh": "1.0.0", + "diffie-hellman": "2.2.0", "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", - "diffie-hellman": "2.2.0", "sha.js": "~2.2.7" }, "devDependencies": { diff --git a/readme.markdown b/readme.markdown index b4ea092..e326cf0 100644 --- a/readme.markdown +++ b/readme.markdown @@ -19,12 +19,14 @@ Here is the subset that is currently implemented: * createCipher (aes) * createDecipher (aes) * createDiffieHellman +* createECDH (secp256k1) ## todo these features from node's `crypto` are still unimplemented. * createCredentials +* publicEncrypt/privateDecrypt ## contributions diff --git a/test/ecdh.js b/test/ecdh.js new file mode 100644 index 0000000..6819d13 --- /dev/null +++ b/test/ecdh.js @@ -0,0 +1,55 @@ +var mods = [ + 'secp256k1' +]; +var test = require('tape'); +var crypto = require('../'); +test('createECDH', function (t) { +mods.forEach(function (mod) { + t.test(mod + ' uncompressed', function (t){ + t.plan(2); + var dh1 = crypto.createECDH(mod); + dh1.generateKeys(); + var dh2 = crypto.createECDH(mod); + dh2.generateKeys(); + var pubk1 = dh1.getPublicKey(); + var pubk2 = dh2.getPublicKey(); + t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys'); + var pub1 = dh1.computeSecret(pubk2).toString('hex'); + var pub2 = dh2.computeSecret(pubk1).toString('hex'); + t.equals(pub1, pub2, 'equal secrets'); + }); + t.test(mod + ' compressed', function (t){ + t.plan(2); + var dh1 = crypto.createECDH(mod); + dh1.generateKeys(); + var dh2 = crypto.createECDH(mod); + dh2.generateKeys(); + var pubk1 = dh1.getPublicKey(null, 'compressed'); + var pubk2 = dh2.getPublicKey(null, 'compressed'); + t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys'); + var pub1 = dh1.computeSecret(pubk2).toString('hex'); + var pub2 = dh2.computeSecret(pubk1).toString('hex'); + t.equals(pub1, pub2, 'equal secrets'); + }); + t.test(mod + ' set stuff', function (t){ + t.plan(5); + var dh1 = crypto.createECDH(mod); + var dh2 = crypto.createECDH(mod); + dh1.generateKeys(); + dh2.generateKeys(); + dh1.setPrivateKey(dh2.getPrivateKey()); + dh1.setPublicKey(dh2.getPublicKey()); + var priv1 = dh1.getPrivateKey('hex'); + var priv2 = dh2.getPrivateKey('hex'); + t.equals(priv1, priv2, 'same private key'); + var pubk1 = dh1.getPublicKey(); + var pubk2 = dh2.getPublicKey(); + t.equals(pubk1.toString('hex'), pubk2.toString('hex'), 'same public keys, uncompressed'); + t.equals(dh1.getPublicKey('hex', 'compressed'), dh2.getPublicKey('hex', 'compressed'), 'same public keys compressed'); + t.equals(dh1.getPublicKey('hex', 'hybrid'), dh2.getPublicKey('hex', 'hybrid'), 'same public keys hybrid'); + var pub1 = dh1.computeSecret(pubk2).toString('hex'); + var pub2 = dh2.computeSecret(pubk1).toString('hex'); + t.equals(pub1, pub2, 'equal secrets'); + }); + }); +}); \ No newline at end of file From 60aedbfee463a4ab67476f0b1f2eb4e8c14a81dc Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 25 Nov 2014 08:11:23 -0500 Subject: [PATCH 075/217] add signs back into readme, and to into getHashes --- index.js | 4 ++-- readme.markdown | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7218b1c..f996388 100644 --- a/index.js +++ b/index.js @@ -27,9 +27,9 @@ function each(a, f) { for(var i in a) f(a[i], i) } - +var hashes = ['sha1', 'sha256', 'sha512', 'md5', 'rmd160'].concat(Object.keys(require('browserify-sign/algos'))) exports.getHashes = function () { - return ['sha1', 'sha256', 'sha512', 'md5', 'rmd160'] + return hashes; } var p = require('./pbkdf2')(exports) diff --git a/readme.markdown b/readme.markdown index b4ea092..bdcfa7a 100644 --- a/readme.markdown +++ b/readme.markdown @@ -19,6 +19,9 @@ Here is the subset that is currently implemented: * createCipher (aes) * createDecipher (aes) * createDiffieHellman +* createSign (rsa, ecdsa) +* createVerify (rsa, ecdsa) + ## todo From c0f57c21c38e7a56537257354838ce75772b0e54 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 25 Nov 2014 08:13:32 -0500 Subject: [PATCH 076/217] update tests --- test/create-hash.js | 2 +- test/create-hmac.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/create-hash.js b/test/create-hash.js index bbe1174..e01601b 100644 --- a/test/create-hash.js +++ b/test/create-hash.js @@ -1,7 +1,7 @@ var fs = require('fs') var test = require('tape') -var algorithms = require('../').getHashes() +var algorithms = ['sha1', 'sha256', 'sha512', 'md5', 'rmd160'] var encodings = [/*'binary',*/ 'hex', 'base64']; var vectors = require('hash-test-vectors') diff --git a/test/create-hmac.js b/test/create-hmac.js index 253c046..19d349a 100644 --- a/test/create-hmac.js +++ b/test/create-hmac.js @@ -1,7 +1,7 @@ var test = require('tape') -var algorithms = require('../').getHashes() +var algorithms = ['sha1', 'sha256', 'sha512', 'md5', 'rmd160'] var vectors = require('hash-test-vectors/hmac') var createHmac = require('../create-hmac') From 0edd9e37a498721a0f06a3bbdef6e7082deb6951 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 25 Nov 2014 08:17:32 -0500 Subject: [PATCH 077/217] do not change other deps --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7e45e9a..cb120cb 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,8 @@ "browserify-sign": "2.4.0", "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", - "sha.js": "2.2.6", - "diffie-hellman": "2.2.0" + "diffie-hellman": "2.2.0", + "sha.js": "~2.2.7" }, "devDependencies": { "tape": "~2.3.2", From 230b3ca29b4cdf3819ae378586430ebb772988a1 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Wed, 26 Nov 2014 11:33:38 +0100 Subject: [PATCH 078/217] 3.5.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3b382bd..8fe22b3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.4.3", + "version": "3.5.0", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From fb1d36ba4efbc6a75d6ab04e6695f2137f515456 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Wed, 26 Nov 2014 11:45:09 +0100 Subject: [PATCH 079/217] 3.5.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 152552a..16fa6cb 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.5.0", + "version": "3.5.1", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 6602891ba0e28b6e0979443e85a73dba8c010bb8 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Wed, 26 Nov 2014 11:51:06 +0100 Subject: [PATCH 080/217] 3.6.0 --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 489aa54..6769121 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.5.1", + "version": "3.6.0", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", @@ -22,7 +22,6 @@ "diffie-hellman": "2.2.0", "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", - "diffie-hellman": "2.2.0", "sha.js": "2.3.0" }, "devDependencies": { From a87f4f14944aad8b3aa130d65d226eac8c6a6bc2 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 25 Nov 2014 15:02:01 -0500 Subject: [PATCH 081/217] update sign to 2.5.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6769121..67f36d0 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,9 @@ }, "dependencies": { "browserify-aes": "0.6.0", - "browserify-sign": "2.4.0", "create-ecdh": "1.0.0", "diffie-hellman": "2.2.0", + "browserify-sign": "2.5.1", "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", "sha.js": "2.3.0" From 5142c60952688315c45382d9f3a6e79de12265b7 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 9 Dec 2014 15:20:28 -0800 Subject: [PATCH 082/217] 3.6.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 67f36d0..868c375 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.6.0", + "version": "3.6.1", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 9b1cf112070f4205267039e66755a6f015853e8e Mon Sep 17 00:00:00 2001 From: Paul Ledbetter Date: Mon, 15 Dec 2014 21:12:47 +0000 Subject: [PATCH 083/217] Implement pseudoRandomBytes. Provide the same interface as rng, but fallback to pseudoRandomBytes on node. --- index.js | 12 +++++++++++- prng.js | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 prng.js diff --git a/index.js b/index.js index a5b2c9f..53162bf 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ 'use strict'; -var rng = require('./rng') +var rng = exports.rng = require('./rng') +var prng = exports.prng = require('./prng'); function error () { var m = [].slice.call(arguments).join(' ') @@ -23,6 +24,15 @@ exports.randomBytes = function(size, callback) { return new Buffer(rng(size)) } } +exports.pseudoRandomBytes = function(size, callback) { + if (callback && callback.call) { + try { + callback.call(this, undefined, new Buffer(prng(size))) + } catch (err) { callback(err) } + } else { + return new Buffer(prng(size)) + } +} function each(a, f) { for(var i in a) diff --git a/prng.js b/prng.js new file mode 100644 index 0000000..3fa46cc --- /dev/null +++ b/prng.js @@ -0,0 +1,27 @@ +'use strict'; +(function() { + var g = ('undefined' === typeof window ? global : window) || {} + var _crypto = ( + g.crypto || g.msCrypto || require('crypto') + ) + module.exports = function(size) { + // Modern Browsers + if(_crypto.getRandomValues) { + var bytes = new Buffer(size); //in browserify, this is an extended Uint8Array + /* This will not work in older browsers. + * See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues + */ + + _crypto.getRandomValues(bytes); + return bytes; + } + else if (_crypto.pseudoRandomBytes) { + return _crypto.pseudoRandomBytes(size) + } + else + throw new Error( + 'pseudo random number generation not yet implemented for this browser\n'+ + 'use chrome, FireFox or Internet Explorer 11' + ) + } +}()) From f927c673f193e31a7ad22dda02097e64702b6d01 Mon Sep 17 00:00:00 2001 From: Paul Ledbetter Date: Tue, 16 Dec 2014 21:12:58 +0000 Subject: [PATCH 084/217] Add pseudoRandomBytes to random-bytes test suite. --- test/random-bytes.js | 105 ++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 50 deletions(-) diff --git a/test/random-bytes.js b/test/random-bytes.js index 417f2db..ccb4dd7 100644 --- a/test/random-bytes.js +++ b/test/random-bytes.js @@ -1,55 +1,60 @@ var test = require('tape') var crypto = require('../') -test('get error message', function (t) { - - try { - var b = crypto.randomBytes(10) - t.ok(Buffer.isBuffer(b)) - t.end() - } catch (err) { - t.ok(/not supported/.test(err.message), '"not supported" is in error message') - t.end() - } - -}) - -test('randomBytes', function (t) { - t.plan(5); - t.equal(crypto.randomBytes(10).length, 10); - t.ok(Buffer.isBuffer(crypto.randomBytes(10))) - crypto.randomBytes(10, function(ex, bytes) { - t.error(ex); - t.equal(bytes.length, 10); - t.ok(Buffer.isBuffer(bytes)) - t.end(); +var randomBytesFunctions = ['randomBytes', 'pseudoRandomBytes']; +for (var idx in randomBytesFunctions) { + // Both randomBytes and pseudoRandomBytes should provide the same interface + var randomBytesName = randomBytesFunctions[idx]; + var randomBytes = crypto[randomBytesName] + test('get error message', function (t) { + + try { + var b = randomBytes(10) + t.ok(Buffer.isBuffer(b)) + t.end() + } catch (err) { + t.ok(/not supported/.test(err.message), '"not supported" is in error message') + t.end() + } + + }) + + test(randomBytesName, function (t) { + t.plan(5); + t.equal(randomBytes(10).length, 10); + t.ok(Buffer.isBuffer(randomBytes(10))) + randomBytes(10, function(ex, bytes) { + t.error(ex); + t.equal(bytes.length, 10); + t.ok(Buffer.isBuffer(bytes)) + t.end(); + }); }); -}); - -test('randomBytes seem random', function (t) { - - var L = 1000 - var b = crypto.randomBytes(L) - - var mean = [].reduce.call(b, function (a, b) { return a + b}, 0) / L - - // test that the random numbers are plausably random. - // Math.random() will pass this, but this will catch - // terrible mistakes such as this blunder: - // https://github.com/dominictarr/crypto-browserify/commit/3267955e1df7edd1680e52aeede9a89506ed2464#commitcomment-7916835 - - // this doesn't check that the bytes are in a random *order* - // but it's better than nothing. - - var expected = 256/2 - var smean = Math.sqrt(mean) - //console.log doesn't work right on testling, *grumble grumble* - console.log(JSON.stringify([expected - smean, mean, expected + smean])) - t.ok(mean < expected + smean) - t.ok(mean > expected - smean) - - t.end() - -}) - + + test(randomBytesName + ' seem random', function (t) { + + var L = 1000 + var b = randomBytes(L) + + var mean = [].reduce.call(b, function (a, b) { return a + b}, 0) / L + + // test that the random numbers are plausably random. + // Math.random() will pass this, but this will catch + // terrible mistakes such as this blunder: + // https://github.com/dominictarr/crypto-browserify/commit/3267955e1df7edd1680e52aeede9a89506ed2464#commitcomment-7916835 + + // this doesn't check that the bytes are in a random *order* + // but it's better than nothing. + + var expected = 256/2 + var smean = Math.sqrt(mean) + //console.log doesn't work right on testling, *grumble grumble* + console.log(JSON.stringify([expected - smean, mean, expected + smean])) + t.ok(mean < expected + smean) + t.ok(mean > expected - smean) + + t.end() + + }) +} From 969a5e045558e2b43465d2b81fb9c375e64e64c7 Mon Sep 17 00:00:00 2001 From: Paul Ledbetter Date: Tue, 16 Dec 2014 21:13:51 +0000 Subject: [PATCH 085/217] Remove extra new Buffer in randomBytes functions. --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 53162bf..18ef342 100644 --- a/index.js +++ b/index.js @@ -18,19 +18,19 @@ exports.createHmac = require('./create-hmac') exports.randomBytes = function(size, callback) { if (callback && callback.call) { try { - callback.call(this, undefined, new Buffer(rng(size))) + callback.call(this, undefined, rng(size)) } catch (err) { callback(err) } } else { - return new Buffer(rng(size)) + return rng(size) } } exports.pseudoRandomBytes = function(size, callback) { if (callback && callback.call) { try { - callback.call(this, undefined, new Buffer(prng(size))) + callback.call(this, undefined, prng(size)) } catch (err) { callback(err) } } else { - return new Buffer(prng(size)) + return prng(size) } } From 845cbaa8e2370641b15159300c523a454efd57d0 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 18 Dec 2014 16:42:39 -0500 Subject: [PATCH 086/217] publicEncrypt and privateDecrypt --- index.js | 3 ++- package.json | 3 ++- readme.markdown | 2 +- test/public-encrypt.js | 23 +++++++++++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 test/public-encrypt.js diff --git a/index.js b/index.js index a5b2c9f..b4ffb43 100644 --- a/index.js +++ b/index.js @@ -40,10 +40,11 @@ require('browserify-aes/inject')(exports, module.exports); require('browserify-sign/inject')(module.exports, exports); require('diffie-hellman/inject')(exports, module.exports); require('create-ecdh/inject')(module.exports, exports); +require('public-encrypt/inject')(module.exports, exports); // the least I can do is make error messages for the rest of the node.js/crypto api. each([ - 'createCredentials', 'publicEncrypt', 'privateDecrypt' + 'createCredentials' ], function (name) { exports[name] = function () { error('sorry,', name, 'is not implemented yet') diff --git a/package.json b/package.json index 868c375..40d56ac 100644 --- a/package.json +++ b/package.json @@ -17,10 +17,11 @@ }, "dependencies": { "browserify-aes": "0.6.0", + "browserify-sign": "2.5.1", "create-ecdh": "1.0.0", "diffie-hellman": "2.2.0", - "browserify-sign": "2.5.1", "pbkdf2-compat": "2.0.1", + "public-encrypt": "1.0.1", "ripemd160": "0.2.0", "sha.js": "2.3.0" }, diff --git a/readme.markdown b/readme.markdown index 2cbf4c5..dcae5ae 100644 --- a/readme.markdown +++ b/readme.markdown @@ -22,13 +22,13 @@ Here is the subset that is currently implemented: * createSign (rsa, ecdsa) * createVerify (rsa, ecdsa) * createECDH (secp256k1) +* publicEncrypt/privateDecrypt (rsa) ## todo these features from node's `crypto` are still unimplemented. * createCredentials -* publicEncrypt/privateDecrypt ## contributions diff --git a/test/public-encrypt.js b/test/public-encrypt.js new file mode 100644 index 0000000..1a5cb62 --- /dev/null +++ b/test/public-encrypt.js @@ -0,0 +1,23 @@ +var test = require('tape'); +var crypto = require('../'); +var rsa = { + "private": "2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a", + "public": "2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a" +}; + +rsa.private = new Buffer(rsa.private, 'hex'); +rsa.public = new Buffer(rsa.public, 'hex'); +var encrypted = '0bcd6462ad7a563be2d42b0b73e0b0a163886304e7723b025f97605144fe1781e84acdc4031327d6bccd67fe13183e8fbdc8c5fe947b49d011ce3ebb08b11e83b87a77328ca57ee77cfdc78743b0749366643d7a21b2abcd4aa32dee9832938445540ee3007b7a70191c8dc9ff2ad76fe8dfaa5362d9d2c4b31a67b816d7b7970a293cb95bf3437a301bedb9f431b7075aa2f9df77b4385bea2a37982beda467260b384a58258b5eb4e36a0e0bf7dff83589636f5f97bf542084f0f76868c9f3f989a27fee5b8cd2bfee0bae1eae958df7c3184e5a40fda101196214f371606feca4330b221f30577804bbd4f61578a84e85dcd298849f509e630d275280'; +test('publicEncrypt/privateDecrypt', function (t) { + t.test('can decrypt', function (t) { + t.plan(1); + // note encryption is ranomized so can't test to see if they encrypt the same + t.equals(crypto.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly'); + }); + t.test('can round trip', function (t) { + t.plan(1); + var msg = 'this is a message'; + // note encryption is ranomized so can't test to see if they encrypt the same + t.equals(crypto.privateDecrypt(rsa.private, crypto.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it'); + }); +}); \ No newline at end of file From 9a840d736eb0d3ff727af4db813f14cd43588c25 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 18 Dec 2014 16:59:38 -0500 Subject: [PATCH 087/217] upgrade aes to check padding --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 868c375..73e8170 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "node": "*" }, "dependencies": { - "browserify-aes": "0.6.0", + "browserify-aes": "0.6.1", "create-ecdh": "1.0.0", "diffie-hellman": "2.2.0", "browserify-sign": "2.5.1", From ae131a16d5ea90488710eb3ad3b845d92c5283b5 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 18 Dec 2014 17:01:29 -0500 Subject: [PATCH 088/217] upgrade browserify-sign to handle dsa signatures --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 868c375..2555109 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "browserify-aes": "0.6.0", "create-ecdh": "1.0.0", "diffie-hellman": "2.2.0", - "browserify-sign": "2.5.1", + "browserify-sign": "2.6.0", "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", "sha.js": "2.3.0" From 7e2fe95bcb063b581ad457096e8f1b00d278e11a Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Thu, 18 Dec 2014 14:22:54 -1000 Subject: [PATCH 089/217] 3.7.0 --- package.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/package.json b/package.json index 762a073..05c9916 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.6.1", + "version": "3.7.0", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", @@ -20,8 +20,6 @@ "create-ecdh": "1.0.0", "diffie-hellman": "2.2.0", "browserify-sign": "2.6.0", - "create-ecdh": "1.0.0", - "diffie-hellman": "2.2.0", "pbkdf2-compat": "2.0.1", "public-encrypt": "1.0.1", "ripemd160": "0.2.0", From 6634a7a8bae5202d790e93583ab53820f4867738 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Fri, 19 Dec 2014 11:39:04 -0500 Subject: [PATCH 090/217] upgrade sign to remove circular dependency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2555109..ffbd20a 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "browserify-aes": "0.6.0", "create-ecdh": "1.0.0", "diffie-hellman": "2.2.0", - "browserify-sign": "2.6.0", + "browserify-sign": "2.6.1", "pbkdf2-compat": "2.0.1", "ripemd160": "0.2.0", "sha.js": "2.3.0" From 0a9f86cde555ce44442b09999a8c7f1b35a14a74 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Fri, 19 Dec 2014 11:48:17 -0500 Subject: [PATCH 091/217] add back in sha224 and ssh384 hashes to listHashes` --- index.js | 2 +- test/create-hash.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a5b2c9f..17e4f5d 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,7 @@ function each(a, f) { for(var i in a) f(a[i], i) } -var hashes = ['sha1', 'sha256', 'sha512', 'md5', 'rmd160'].concat(Object.keys(require('browserify-sign/algos'))) +var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(Object.keys(require('browserify-sign/algos'))) exports.getHashes = function () { return hashes; } diff --git a/test/create-hash.js b/test/create-hash.js index e01601b..03b025f 100644 --- a/test/create-hash.js +++ b/test/create-hash.js @@ -1,7 +1,7 @@ var fs = require('fs') var test = require('tape') -var algorithms = ['sha1', 'sha256', 'sha512', 'md5', 'rmd160'] +var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'] var encodings = [/*'binary',*/ 'hex', 'base64']; var vectors = require('hash-test-vectors') From 9f6c244e4baed7dba68f5aca2de2e375ab5e508d Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Mon, 22 Dec 2014 11:09:43 +1300 Subject: [PATCH 092/217] 3.7.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2cbd45a..fee9234 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.7.0", + "version": "3.7.1", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 87efc3e7714b698b8d6fa00ddcdd8d30ee5077f3 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 22 Dec 2014 16:22:32 -0500 Subject: [PATCH 093/217] update sign/publicEncrypt to use blinding --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fee9234..d6dfa52 100644 --- a/package.json +++ b/package.json @@ -19,9 +19,9 @@ "browserify-aes": "0.6.1", "create-ecdh": "1.0.0", "diffie-hellman": "2.2.0", - "browserify-sign": "2.6.1", + "browserify-sign": "2.7.0", "pbkdf2-compat": "2.0.1", - "public-encrypt": "1.0.1", + "public-encrypt": "1.1.0", "ripemd160": "0.2.0", "sha.js": "2.3.0" }, From 4c4bb09da9f93d87fd4c7e1cefdd60d7a33c5135 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 23 Dec 2014 16:42:16 +1300 Subject: [PATCH 094/217] 3.7.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d6dfa52..bdfd596 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.7.1", + "version": "3.7.2", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 44ad3caff87f1db1bf2f4e267ef217d4e9c8edd9 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 23 Dec 2014 10:34:12 -0500 Subject: [PATCH 095/217] 3.8.0 upgrade aes to use autoPadding and for legacy methods to skip the stream --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bdfd596..f511777 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.7.2", + "version": "3.8.0", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", @@ -16,7 +16,7 @@ "node": "*" }, "dependencies": { - "browserify-aes": "0.6.1", + "browserify-aes": "0.7.2", "create-ecdh": "1.0.0", "diffie-hellman": "2.2.0", "browserify-sign": "2.7.0", From be7c55239558c65db5d1bcf01bfb75882b3ed070 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sat, 3 Jan 2015 08:53:53 -0500 Subject: [PATCH 096/217] 3.8.1 fix big number dependencies to all have the same range --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index f511777..23c19df 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.8.0", + "version": "3.8.1", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", @@ -17,9 +17,9 @@ }, "dependencies": { "browserify-aes": "0.7.2", - "create-ecdh": "1.0.0", - "diffie-hellman": "2.2.0", - "browserify-sign": "2.7.0", + "create-ecdh": "1.0.1", + "diffie-hellman": "2.2.2", + "browserify-sign": "2.7.1", "pbkdf2-compat": "2.0.1", "public-encrypt": "1.1.0", "ripemd160": "0.2.0", From 7403f564f1998b49ae568a391a09e89edc229061 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 4 Jan 2015 10:07:10 -0500 Subject: [PATCH 097/217] case insensitive cipher names --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 23c19df..be9f7df 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "node": "*" }, "dependencies": { - "browserify-aes": "0.7.2", + "browserify-aes": "0.7.3", "create-ecdh": "1.0.1", "diffie-hellman": "2.2.2", "browserify-sign": "2.7.1", From 538308585fa868cfae7ae8a20e32743778c6addf Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 4 Jan 2015 10:28:20 -0500 Subject: [PATCH 098/217] 3.8.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index be9f7df..2701907 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.8.1", + "version": "3.8.2", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 6862dae4e0d6d5731341b0c9c97115876e269833 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 4 Jan 2015 13:32:32 -0500 Subject: [PATCH 099/217] add getCiphers --- package.json | 2 +- test/aes.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 2701907..9a80c06 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "node": "*" }, "dependencies": { - "browserify-aes": "0.7.3", + "browserify-aes": "0.8.0", "create-ecdh": "1.0.1", "diffie-hellman": "2.2.2", "browserify-sign": "2.7.1", diff --git a/test/aes.js b/test/aes.js index cf516a5..bff0dc0 100644 --- a/test/aes.js +++ b/test/aes.js @@ -18,4 +18,8 @@ test('ciphers', function (t) { t.equals(data.toString('hex'), Buffer.concat(out).toString('hex')); }); }); +}); +test('getCiphers', function (t) { + t.plan(1); + t.ok(crypto.getCiphers().length, 'get ciphers returns an array'); }); \ No newline at end of file From 75bd305d4e917684c456e54b329af08da5f3e56b Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 4 Jan 2015 13:33:37 -0500 Subject: [PATCH 100/217] 3.8.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9a80c06..dc1d800 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "partial implementation of crypto for the browser", - "version": "3.8.2", + "version": "3.8.3", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 52b4aff1903a9d64c9a095024635229616de99d6 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 5 Jan 2015 09:57:10 -0500 Subject: [PATCH 101/217] update readme to remove the testling badge, change the wording re how much is done and add psudoRandomBytes --- readme.markdown | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/readme.markdown b/readme.markdown index dcae5ae..0cc75df 100644 --- a/readme.markdown +++ b/readme.markdown @@ -1,11 +1,9 @@ # crypto-browserify -A (partial) port of node's `crypto` module to the browser. +A port of node's `crypto` module to the browser. [![travis](https://secure.travis-ci.org/dominictarr/crypto-browserify.png?branch=master)](https://travis-ci.org/dominictarr/crypto-browserify) -[![browser support](http://ci.testling.com/dominictarr/crypto-browserify.png)](http://ci.testling.com/dominictarr/crypto-browserify) - The goal of this module is to reimplement node's crypto module, in pure javascript so that it can run in the browser. @@ -16,6 +14,7 @@ Here is the subset that is currently implemented: * pbkdf2 * pbkdf2Sync * randomBytes +* pseudoRandomBytes * createCipher (aes) * createDecipher (aes) * createDiffieHellman From c9a6ca09f6c5516055f8e39112aac347845f72f7 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 5 Jan 2015 11:18:44 -0500 Subject: [PATCH 102/217] and update package.json as well --- package.json | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/package.json b/package.json index dc1d800..c7e9ce3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", - "description": "partial implementation of crypto for the browser", + "description": "implementation of crypto for the browser", "version": "3.8.3", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { @@ -29,16 +29,6 @@ "tape": "~2.3.2", "hash-test-vectors": "~1.3.0" }, - "testling": { - "files": "test/*.js", - "browsers": [ - "ie/latest", - "chrome/latest", - "firefox/latest", - "safari/latest", - "opera/latest" - ] - }, "optionalDependencies": {}, "browser": { "crypto": false From f15aae3aaa18f201b55816576c2acc22bdab9e97 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 5 Jan 2015 11:16:30 -0500 Subject: [PATCH 103/217] add aliases for hash, hmac, verify, sign, cipher[iv], decipher[iv] --- index.js | 4 ++-- package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 174866b..c2938b0 100644 --- a/index.js +++ b/index.js @@ -11,9 +11,9 @@ function error () { ].join('\n')) } -exports.createHash = require('./create-hash') +exports.createHash = exports.Hash = require('./create-hash') -exports.createHmac = require('./create-hmac') +exports.createHmac = exports.Hmac = require('./create-hmac') exports.randomBytes = function(size, callback) { if (callback && callback.call) { diff --git a/package.json b/package.json index c7e9ce3..ec58cc5 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,10 @@ "node": "*" }, "dependencies": { - "browserify-aes": "0.8.0", + "browserify-aes": "0.8.1", "create-ecdh": "1.0.1", "diffie-hellman": "2.2.2", - "browserify-sign": "2.7.1", + "browserify-sign": "2.7.2", "pbkdf2-compat": "2.0.1", "public-encrypt": "1.1.0", "ripemd160": "0.2.0", From df0180c7dc6213e8158ef84a84b5c1208dda0b8a Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 5 Jan 2015 18:59:27 -0500 Subject: [PATCH 104/217] 3.9.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ec58cc5..d675ce1 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.8.3", + "version": "3.9.0", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 700e34f22a7ed699d1d001e19fc90922776a8adb Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 6 Jan 2015 08:04:09 -0500 Subject: [PATCH 105/217] bn.js to 1.0.0 in all deps --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index d675ce1..39e170f 100644 --- a/package.json +++ b/package.json @@ -17,11 +17,11 @@ }, "dependencies": { "browserify-aes": "0.8.1", - "create-ecdh": "1.0.1", - "diffie-hellman": "2.2.2", - "browserify-sign": "2.7.2", + "create-ecdh": "1.0.3", + "diffie-hellman": "2.2.3", + "browserify-sign": "2.7.5", "pbkdf2-compat": "2.0.1", - "public-encrypt": "1.1.0", + "public-encrypt": "1.1.2", "ripemd160": "0.2.0", "sha.js": "2.3.0" }, From c38b4927bf491a08c3176ac979da5c0dc1c9d5e6 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Fri, 9 Jan 2015 19:44:14 -0500 Subject: [PATCH 106/217] 3.9.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 39e170f..f38f19e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.9.0", + "version": "3.9.1", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From a230261d3f3c2d60e436388ef7b9f958b8bc590a Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Mon, 12 Jan 2015 00:27:03 +1300 Subject: [PATCH 107/217] update sha.js to 3.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f38f19e..0b00c7d 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "pbkdf2-compat": "2.0.1", "public-encrypt": "1.1.2", "ripemd160": "0.2.0", - "sha.js": "2.3.0" + "sha.js": "2.3.1" }, "devDependencies": { "tape": "~2.3.2", From 17a43770bb7b34c4bb76b8c1746c51c6a9675826 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 11 Jan 2015 11:31:35 -0500 Subject: [PATCH 108/217] 3.9.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0b00c7d..ced77b1 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.9.1", + "version": "3.9.2", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 84320b9ef77234937d0125bdb816868c9f266911 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Mon, 12 Jan 2015 21:42:19 +1300 Subject: [PATCH 109/217] update sha.js to 2.3.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ced77b1..2e302aa 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "pbkdf2-compat": "2.0.1", "public-encrypt": "1.1.2", "ripemd160": "0.2.0", - "sha.js": "2.3.1" + "sha.js": "2.3.2" }, "devDependencies": { "tape": "~2.3.2", From 4fd75cfc7d9f07363f3f3aa7752fd820aab37892 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 12 Jan 2015 08:56:43 -0500 Subject: [PATCH 110/217] use inherits instead of util --- create-hash.js | 2 +- create-hmac.js | 2 +- package.json | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/create-hash.js b/create-hash.js index f7d3c90..f0488b2 100644 --- a/create-hash.js +++ b/create-hash.js @@ -4,7 +4,7 @@ var createHash = require('sha.js') var md5 = require('./md5') var rmd160 = require('ripemd160') var Transform = require('stream').Transform; -var inherits = require('util').inherits +var inherits = require('inherits') module.exports = function (alg) { if('md5' === alg) return new HashNoConstructor(md5) diff --git a/create-hmac.js b/create-hmac.js index 6d2007e..b1d9337 100644 --- a/create-hmac.js +++ b/create-hmac.js @@ -1,7 +1,7 @@ 'use strict'; var createHash = require('./create-hash') var Transform = require('stream').Transform; -var inherits = require('util').inherits +var inherits = require('inherits') var zeroBuffer = new Buffer(128) zeroBuffer.fill(0) diff --git a/package.json b/package.json index ced77b1..88c408b 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "create-ecdh": "1.0.3", "diffie-hellman": "2.2.3", "browserify-sign": "2.7.5", + "inherits": "^2.0.1", "pbkdf2-compat": "2.0.1", "public-encrypt": "1.1.2", "ripemd160": "0.2.0", From 724fd875f71067c88401515e2f4d6e8b4b5b8982 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 12 Jan 2015 11:57:25 -0500 Subject: [PATCH 111/217] test against node 0.11.x --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7a589da..05d299e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ language: node_js node_js: - "0.10" - + - "0.11" From 6cb3dabdac1f17b7014d7354a303df891e585f0e Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 13 Jan 2015 08:12:53 +1300 Subject: [PATCH 112/217] update sha.js to 2.3.4 - performance improvements for sha1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2e302aa..11beb02 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "pbkdf2-compat": "2.0.1", "public-encrypt": "1.1.2", "ripemd160": "0.2.0", - "sha.js": "2.3.2" + "sha.js": "2.3.4" }, "devDependencies": { "tape": "~2.3.2", From d95c99bd948180b750bd0dd980736372332bedd0 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 12 Jan 2015 15:48:43 -0500 Subject: [PATCH 113/217] 3.9.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 11beb02..3a29fd7 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.9.2", + "version": "3.9.3", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 8146d4001cf551cdabe883525f47648a0443e102 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 12 Jan 2015 08:56:43 -0500 Subject: [PATCH 114/217] upgrade browserify-sign to use determanistic k --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3a29fd7..8bbfa44 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "browserify-aes": "0.8.1", "create-ecdh": "1.0.3", "diffie-hellman": "2.2.3", - "browserify-sign": "2.7.5", + "browserify-sign": "2.8.0", "pbkdf2-compat": "2.0.1", "public-encrypt": "1.1.2", "ripemd160": "0.2.0", From db1ac5ed9a4f445652ada8943c8dbb429d586fbc Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 12 Jan 2015 18:34:43 -0500 Subject: [PATCH 115/217] 3.9.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8bbfa44..6efa7d3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.9.3", + "version": "3.9.4", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 2863c3361487a67668d8226ac090231305ce6278 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Wed, 14 Jan 2015 10:41:55 +1300 Subject: [PATCH 116/217] 3.9.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1673e31..666580b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.9.4", + "version": "3.9.5", "homepage": "https://github.com/dominictarr/crypto-browserify", "repository": { "type": "git", From 5ecac4664cae1d5ba73d2656de2dfcbc2abe3872 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Wed, 14 Jan 2015 10:45:09 +1300 Subject: [PATCH 117/217] update sha.js to 2.3.5 - optimization for sha256/512 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 666580b..ddfa88b 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "pbkdf2-compat": "2.0.1", "public-encrypt": "1.1.2", "ripemd160": "0.2.0", - "sha.js": "2.3.4" + "sha.js": "2.3.5" }, "devDependencies": { "tape": "~2.3.2", From e85f60d9b6c42b4c93b601895cb1da43296985bf Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Wed, 14 Jan 2015 20:00:12 +1300 Subject: [PATCH 118/217] transfer to crypto-browserify org --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index ddfa88b..f6bf9c5 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,10 @@ "name": "crypto-browserify", "description": "implementation of crypto for the browser", "version": "3.9.5", - "homepage": "https://github.com/dominictarr/crypto-browserify", + "homepage": "https://github.com/crypto-browserify/crypto-browserify", "repository": { "type": "git", - "url": "git://github.com/dominictarr/crypto-browserify.git" + "url": "git://github.com/crypto-browserify/crypto-browserify.git" }, "scripts": { "test": "set -e; for t in test/node/*.js test/*.js; do node $t; done", @@ -24,11 +24,11 @@ "pbkdf2-compat": "2.0.1", "public-encrypt": "1.1.2", "ripemd160": "0.2.0", - "sha.js": "2.3.5" + "sha.js": "2.3.6" }, "devDependencies": { "tape": "~2.3.2", - "hash-test-vectors": "~1.3.0" + "hash-test-vectors": "~1.3.2" }, "optionalDependencies": {}, "browser": { From a060b2b41b840a8ae50ec6041302fe58f9b580e8 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Wed, 14 Jan 2015 21:53:38 +1300 Subject: [PATCH 119/217] 3.9.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f6bf9c5..8f5a2bd 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.9.5", + "version": "3.9.6", "homepage": "https://github.com/crypto-browserify/crypto-browserify", "repository": { "type": "git", From ca6d693c6462e8e698531ccc4c2e948b8f802a11 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 14 Jan 2015 08:21:06 -0500 Subject: [PATCH 120/217] pull out hashes and hmacs --- create-hash.js | 83 ----------------------- create-hmac.js | 66 ------------------- helpers.js | 35 ---------- index.js | 4 +- md5.js | 156 -------------------------------------------- package.json | 8 +-- test/create-hash.js | 2 +- test/create-hmac.js | 4 +- 8 files changed, 9 insertions(+), 349 deletions(-) delete mode 100644 create-hash.js delete mode 100644 create-hmac.js delete mode 100644 helpers.js delete mode 100644 md5.js diff --git a/create-hash.js b/create-hash.js deleted file mode 100644 index f0488b2..0000000 --- a/create-hash.js +++ /dev/null @@ -1,83 +0,0 @@ -'use strict'; -var createHash = require('sha.js') - -var md5 = require('./md5') -var rmd160 = require('ripemd160') -var Transform = require('stream').Transform; -var inherits = require('inherits') - -module.exports = function (alg) { - if('md5' === alg) return new HashNoConstructor(md5) - if('rmd160' === alg) return new HashNoConstructor(rmd160) - return new Hash(createHash(alg)) -} -inherits(HashNoConstructor, Transform) - -function HashNoConstructor(hash) { - Transform.call(this); - this._hash = hash - this.buffers = [] -} - -HashNoConstructor.prototype._transform = function (data, _, done) { - this.buffers.push(data) - done() -} -HashNoConstructor.prototype._flush = function (done) { - var buf = Buffer.concat(this.buffers) - var r = this._hash(buf) - this.buffers = null - this.push(r) - done() -} -HashNoConstructor.prototype.update = function (data, enc) { - this.write(data, enc) - return this -} - -HashNoConstructor.prototype.digest = function (enc) { - this.end() - var outData = new Buffer('') - var chunk - while ((chunk = this.read())) { - outData = Buffer.concat([outData, chunk]) - } - if (enc) { - outData = outData.toString(enc) - } - return outData -} - -inherits(Hash, Transform) - -function Hash(hash) { - Transform.call(this); - this._hash = hash -} - -Hash.prototype._transform = function (data, _, done) { - this._hash.update(data) - done() -} -Hash.prototype._flush = function (done) { - this.push(this._hash.digest()) - this._hash = null - done() -} -Hash.prototype.update = function (data, enc) { - this.write(data, enc) - return this -} - -Hash.prototype.digest = function (enc) { - this.end() - var outData = new Buffer('') - var chunk - while ((chunk = this.read())) { - outData = Buffer.concat([outData, chunk]) - } - if (enc) { - outData = outData.toString(enc) - } - return outData -} diff --git a/create-hmac.js b/create-hmac.js deleted file mode 100644 index b1d9337..0000000 --- a/create-hmac.js +++ /dev/null @@ -1,66 +0,0 @@ -'use strict'; -var createHash = require('./create-hash') -var Transform = require('stream').Transform; -var inherits = require('inherits') -var zeroBuffer = new Buffer(128) -zeroBuffer.fill(0) - -module.exports = Hmac -inherits(Hmac, Transform) -function Hmac (alg, key) { - if(!(this instanceof Hmac)) return new Hmac(alg, key) - - Transform.call(this) - this._opad = opad - this._alg = alg - - var blocksize = (alg === 'sha512' || alg === 'sha384') ? 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.write(data, enc) - return this -} - -Hmac.prototype._transform = function (data, _, next) { - this._hash.update(data) - next() -} - -Hmac.prototype._flush = function (next) { - var h = this._hash.digest() - this.push(createHash(this._alg).update(this._opad).update(h).digest()) - next() -} - -Hmac.prototype.digest = function (enc) { - this.end() - var outData = new Buffer('') - var chunk - while ((chunk = this.read())) { - outData = Buffer.concat([outData, chunk]) - } - if (enc) { - outData = outData.toString(enc) - } - return outData -} - diff --git a/helpers.js b/helpers.js deleted file mode 100644 index cd2e6ca..0000000 --- a/helpers.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict'; -var intSize = 4; -var zeroBuffer = new Buffer(intSize); zeroBuffer.fill(0); -var chrsz = 8; - -function toArray(buf, bigEndian) { - if ((buf.length % intSize) !== 0) { - var len = buf.length + (intSize - (buf.length % intSize)); - buf = Buffer.concat([buf, zeroBuffer], len); - } - - var arr = []; - var fn = bigEndian ? buf.readInt32BE : buf.readInt32LE; - for (var i = 0; i < buf.length; i += intSize) { - arr.push(fn.call(buf, i)); - } - return arr; -} - -function toBuffer(arr, size, bigEndian) { - var buf = new Buffer(size); - var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE; - for (var i = 0; i < arr.length; i++) { - fn.call(buf, arr[i], i * 4, true); - } - return buf; -} - -function hash(buf, fn, hashSize, bigEndian) { - if (!Buffer.isBuffer(buf)) buf = new Buffer(buf); - var arr = fn(toArray(buf, bigEndian), buf.length * chrsz); - return toBuffer(arr, hashSize, bigEndian); -} - -module.exports = { hash: hash }; diff --git a/index.js b/index.js index c2938b0..8bade59 100644 --- a/index.js +++ b/index.js @@ -11,9 +11,9 @@ function error () { ].join('\n')) } -exports.createHash = exports.Hash = require('./create-hash') +exports.createHash = exports.Hash = require('create-hash') -exports.createHmac = exports.Hmac = require('./create-hmac') +exports.createHmac = exports.Hmac = require('create-hmac') exports.randomBytes = function(size, callback) { if (callback && callback.call) { diff --git a/md5.js b/md5.js deleted file mode 100644 index 550e788..0000000 --- a/md5.js +++ /dev/null @@ -1,156 +0,0 @@ -'use strict'; -/* - * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message - * Digest Algorithm, as defined in RFC 1321. - * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002. - * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet - * Distributed under the BSD License - * See http://pajhome.org.uk/crypt/md5 for more info. - */ - -var helpers = require('./helpers'); - -/* - * Calculate the MD5 of an array of little-endian words, and a bit length - */ -function core_md5(x, len) -{ - /* append padding */ - x[len >> 5] |= 0x80 << ((len) % 32); - x[(((len + 64) >>> 9) << 4) + 14] = len; - - var a = 1732584193; - var b = -271733879; - var c = -1732584194; - var d = 271733878; - - for(var i = 0; i < x.length; i += 16) - { - var olda = a; - var oldb = b; - var oldc = c; - var oldd = d; - - a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); - d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); - c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); - b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); - a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); - d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426); - c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341); - b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983); - a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416); - d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417); - c = md5_ff(c, d, a, b, x[i+10], 17, -42063); - b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162); - a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); - d = md5_ff(d, a, b, c, x[i+13], 12, -40341101); - c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290); - b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329); - - a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); - d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); - c = md5_gg(c, d, a, b, x[i+11], 14, 643717713); - b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); - a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); - d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083); - c = md5_gg(c, d, a, b, x[i+15], 14, -660478335); - b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848); - a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438); - d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690); - c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961); - b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); - a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); - d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784); - c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473); - b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734); - - a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558); - d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463); - c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562); - b = md5_hh(b, c, d, a, x[i+14], 23, -35309556); - a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060); - d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353); - c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632); - b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640); - a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174); - d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222); - c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979); - b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189); - a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487); - d = md5_hh(d, a, b, c, x[i+12], 11, -421815835); - c = md5_hh(c, d, a, b, x[i+15], 16, 530742520); - b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651); - - a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844); - d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415); - c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905); - b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055); - a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571); - d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606); - c = md5_ii(c, d, a, b, x[i+10], 15, -1051523); - b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799); - a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359); - d = md5_ii(d, a, b, c, x[i+15], 10, -30611744); - c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380); - b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649); - a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070); - d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379); - c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259); - b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551); - - a = safe_add(a, olda); - b = safe_add(b, oldb); - c = safe_add(c, oldc); - d = safe_add(d, oldd); - } - return Array(a, b, c, d); - -} - -/* - * These functions implement the four basic operations the algorithm uses. - */ -function md5_cmn(q, a, b, x, s, t) -{ - return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b); -} -function md5_ff(a, b, c, d, x, s, t) -{ - return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); -} -function md5_gg(a, b, c, d, x, s, t) -{ - return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); -} -function md5_hh(a, b, c, d, x, s, t) -{ - return md5_cmn(b ^ c ^ d, a, b, x, s, t); -} -function md5_ii(a, b, c, d, x, s, t) -{ - return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); -} - -/* - * Add integers, wrapping at 2^32. This uses 16-bit operations internally - * to work around bugs in some JS interpreters. - */ -function safe_add(x, y) -{ - var lsw = (x & 0xFFFF) + (y & 0xFFFF); - var msw = (x >> 16) + (y >> 16) + (lsw >> 16); - return (msw << 16) | (lsw & 0xFFFF); -} - -/* - * Bitwise rotate a 32-bit number to the left. - */ -function bit_rol(num, cnt) -{ - return (num << cnt) | (num >>> (32 - cnt)); -} - -module.exports = function md5(buf) { - return helpers.hash(buf, core_md5, 16); -}; diff --git a/package.json b/package.json index 8f5a2bd..6af226a 100644 --- a/package.json +++ b/package.json @@ -17,14 +17,14 @@ }, "dependencies": { "browserify-aes": "0.8.1", + "browserify-sign": "2.8.0", "create-ecdh": "1.0.3", + "create-hash": "^1.0.1", + "create-hmac": "^1.0.0", "diffie-hellman": "2.2.3", - "browserify-sign": "2.8.0", "inherits": "^2.0.1", "pbkdf2-compat": "2.0.1", - "public-encrypt": "1.1.2", - "ripemd160": "0.2.0", - "sha.js": "2.3.6" + "public-encrypt": "1.1.2" }, "devDependencies": { "tape": "~2.3.2", diff --git a/test/create-hash.js b/test/create-hash.js index 03b025f..a2a2cf2 100644 --- a/test/create-hash.js +++ b/test/create-hash.js @@ -5,7 +5,7 @@ var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160 var encodings = [/*'binary',*/ 'hex', 'base64']; var vectors = require('hash-test-vectors') -var createHash = require('../create-hash') +var createHash = require('../').createHash algorithms.forEach(function (algorithm) { test('test ' + algorithm + ' against test vectors', function (t) { diff --git a/test/create-hmac.js b/test/create-hmac.js index 19d349a..0975f84 100644 --- a/test/create-hmac.js +++ b/test/create-hmac.js @@ -1,9 +1,9 @@ var test = require('tape') -var algorithms = ['sha1', 'sha256', 'sha512', 'md5', 'rmd160'] +var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'] var vectors = require('hash-test-vectors/hmac') -var createHmac = require('../create-hmac') +var createHmac = require('../').createHmac algorithms.forEach(function (alg) { From 4455ed436aa61dd81f7c5d3514fbcfbdf566cba5 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 14 Jan 2015 10:21:01 -0500 Subject: [PATCH 121/217] update create-hmac and create-hash to default to native --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6af226a..fb146f4 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "browserify-aes": "0.8.1", "browserify-sign": "2.8.0", "create-ecdh": "1.0.3", - "create-hash": "^1.0.1", - "create-hmac": "^1.0.0", + "create-hash": "^1.0.2", + "create-hmac": "^1.0.2", "diffie-hellman": "2.2.3", "inherits": "^2.0.1", "pbkdf2-compat": "2.0.1", From 26646d1042bb8d46f1ed23ef2612ce177ea31d00 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Fri, 16 Jan 2015 11:56:30 -0500 Subject: [PATCH 122/217] test both imported version and one with this library --- package.json | 4 ++-- test/create-hash.js | 55 ++++++++++++++++++++++-------------------- test/create-hmac.js | 58 +++++++++++++++++++++++---------------------- 3 files changed, 61 insertions(+), 56 deletions(-) diff --git a/package.json b/package.json index fb146f4..f564cb0 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "browserify-aes": "0.8.1", "browserify-sign": "2.8.0", "create-ecdh": "1.0.3", - "create-hash": "^1.0.2", - "create-hmac": "^1.0.2", + "create-hash": "^1.1.0", + "create-hmac": "^1.1.0", "diffie-hellman": "2.2.3", "inherits": "^2.0.1", "pbkdf2-compat": "2.0.1", diff --git a/test/create-hash.js b/test/create-hash.js index a2a2cf2..6912ff7 100644 --- a/test/create-hash.js +++ b/test/create-hash.js @@ -4,35 +4,38 @@ var test = require('tape') var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'] var encodings = [/*'binary',*/ 'hex', 'base64']; var vectors = require('hash-test-vectors') +testLib('createHash in crypto-browserify',require('../').createHash); +testLib('create-hash/browser',require('create-hash/browser')); +function testLib(name, createHash) { + test(name, function (t){ + algorithms.forEach(function (algorithm) { + t.test('test ' + algorithm + ' against test vectors', function (t) { + vectors.forEach(function (obj, i) { + var input = new Buffer(obj.input, 'base64') + var node = obj[algorithm] + var js = createHash(algorithm).update(input).digest('hex') + t.equal(js, node, algorithm + '(testVector['+i+']) == ' + node) + }) -var createHash = require('../').createHash - -algorithms.forEach(function (algorithm) { - test('test ' + algorithm + ' against test vectors', function (t) { - vectors.forEach(function (obj, i) { - var input = new Buffer(obj.input, 'base64') - var node = obj[algorithm] - var js = createHash(algorithm).update(input).digest('hex') - t.equal(js, node, algorithm + '(testVector['+i+']) == ' + node) - }) - - encodings.forEach(function (encoding) { + encodings.forEach(function (encoding) { + vectors.forEach(function (obj, i) { + var input = new Buffer(obj.input, 'base64').toString(encoding) + var node = obj[algorithm] + var js = createHash(algorithm).update(input, encoding).digest('hex') + t.equal(js, node, algorithm + '(testVector['+i+'], '+encoding+') == ' + node) + }) + }); vectors.forEach(function (obj, i) { - var input = new Buffer(obj.input, 'base64').toString(encoding) + var input = new Buffer(obj.input, 'base64') var node = obj[algorithm] - var js = createHash(algorithm).update(input, encoding).digest('hex') - t.equal(js, node, algorithm + '(testVector['+i+'], '+encoding+') == ' + node) + var hash = createHash(algorithm); + hash.end(input) + var js = hash.read().toString('hex') + t.equal(js, node, algorithm + '(testVector['+i+']) == ' + node) }) + t.end() + }) }); - vectors.forEach(function (obj, i) { - var input = new Buffer(obj.input, 'base64') - var node = obj[algorithm] - var hash = createHash(algorithm); - hash.end(input) - var js = hash.read().toString('hex') - t.equal(js, node, algorithm + '(testVector['+i+']) == ' + node) - }) - t.end() - }) -}); + }); +} \ No newline at end of file diff --git a/test/create-hmac.js b/test/create-hmac.js index 0975f84..814b573 100644 --- a/test/create-hmac.js +++ b/test/create-hmac.js @@ -3,35 +3,37 @@ var test = require('tape') var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'] var vectors = require('hash-test-vectors/hmac') -var createHmac = require('../').createHmac +testLib('createHmac in crypto-browserify',require('../').createHmac); +testLib('create-hmac/browser',require('create-hmac/browser')); +function testLib(name, createHmac) { + test(name, function (t){ + algorithms.forEach(function (alg) { + + t.test('hmac('+alg+')', function (t) { + vectors.forEach(function (input, i) { + var output = createHmac(alg, new Buffer(input.key, 'hex')) + .update(input.data, 'hex').digest() + + output = input.truncate ? output.slice(0, input.truncate) : output + t.equal(output.toString('hex'), input[alg]) + }) + t.end() + }) + + t.test('hmac('+alg+')', function (t) { + vectors.forEach(function (input, i) { + var hmac = createHmac(alg, new Buffer(input.key, 'hex')) + + hmac.end(input.data, 'hex') + var output = hmac.read() + + output = input.truncate ? output.slice(0, input.truncate) : output + t.equal(output.toString('hex'), input[alg]) + }) + t.end() + }) -algorithms.forEach(function (alg) { - - test('hmac('+alg+')', function (t) { - vectors.forEach(function (input, i) { - var output = createHmac(alg, new Buffer(input.key, 'hex')) - .update(input.data, 'hex').digest() - - output = input.truncate ? output.slice(0, input.truncate) : output - t.equal(output.toString('hex'), input[alg]) - }) - t.end() - }) - - test('hmac('+alg+')', function (t) { - vectors.forEach(function (input, i) { - var hmac = createHmac(alg, new Buffer(input.key, 'hex')) - - hmac.end(input.data, 'hex') - var output = hmac.read() - - output = input.truncate ? output.slice(0, input.truncate) : output - t.equal(output.toString('hex'), input[alg]) }) - t.end() }) -}) - - - +} From 1c23955a6d59bacae7bc543c55f8be19cd913234 Mon Sep 17 00:00:00 2001 From: Forbes Lindesay Date: Sun, 18 Jan 2015 00:20:47 +0000 Subject: [PATCH 123/217] Handle errors in callbacks given to `randomBytes` --- index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index c2938b0..648c3b4 100644 --- a/index.js +++ b/index.js @@ -17,18 +17,26 @@ exports.createHmac = exports.Hmac = require('./create-hmac') exports.randomBytes = function(size, callback) { if (callback && callback.call) { + var res; try { - callback.call(this, undefined, rng(size)) - } catch (err) { callback(err) } + res = rng(size) + } catch (err) { + return callback(err) + } + callback.call(this, undefined, res) } else { return rng(size) } } exports.pseudoRandomBytes = function(size, callback) { if (callback && callback.call) { + var res; try { - callback.call(this, undefined, prng(size)) - } catch (err) { callback(err) } + res = prng(size) + } catch (err) { + return callback(err) + } + callback.call(this, undefined, res) } else { return prng(size) } From c08a8ea93a6175da0889a50d20f9e32c61664ff8 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 19 Jan 2015 08:21:40 -0500 Subject: [PATCH 124/217] 3.9.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f564cb0..ce72400 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.9.6", + "version": "3.9.7", "homepage": "https://github.com/crypto-browserify/crypto-browserify", "repository": { "type": "git", From 20196dbdab79b9016c14eb2ecf9e96fe3b5ede7a Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 18 Jan 2015 11:44:08 -0500 Subject: [PATCH 125/217] pull out random bytes --- index.js | 15 +-------------- package.json | 3 ++- rng.js | 27 --------------------------- test/random-bytes.js | 8 ++++---- 4 files changed, 7 insertions(+), 46 deletions(-) delete mode 100644 rng.js diff --git a/index.js b/index.js index db77ebe..807d3ac 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ 'use strict'; -var rng = exports.rng = require('./rng') +exports.randomBytes = exports.rng = require('randombytes') var prng = exports.prng = require('./prng'); function error () { @@ -15,19 +15,6 @@ exports.createHash = exports.Hash = require('create-hash') exports.createHmac = exports.Hmac = require('create-hmac') -exports.randomBytes = function(size, callback) { - if (callback && callback.call) { - var res; - try { - res = rng(size) - } catch (err) { - return callback(err) - } - callback.call(this, undefined, res) - } else { - return rng(size) - } -} exports.pseudoRandomBytes = function(size, callback) { if (callback && callback.call) { var res; diff --git a/package.json b/package.json index ce72400..a14b2c7 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "diffie-hellman": "2.2.3", "inherits": "^2.0.1", "pbkdf2-compat": "2.0.1", - "public-encrypt": "1.1.2" + "public-encrypt": "1.1.2", + "randombytes": "^2.0.0" }, "devDependencies": { "tape": "~2.3.2", diff --git a/rng.js b/rng.js deleted file mode 100644 index 7c0929f..0000000 --- a/rng.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; -(function() { - var g = ('undefined' === typeof window ? global : window) || {} - var _crypto = ( - g.crypto || g.msCrypto || require('crypto') - ) - module.exports = function(size) { - // Modern Browsers - if(_crypto.getRandomValues) { - var bytes = new Buffer(size); //in browserify, this is an extended Uint8Array - /* This will not work in older browsers. - * See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues - */ - - _crypto.getRandomValues(bytes); - return bytes; - } - else if (_crypto.randomBytes) { - return _crypto.randomBytes(size) - } - else - throw new Error( - 'secure random number generation not supported by this browser\n'+ - 'use chrome, FireFox or Internet Explorer 11' - ) - } -}()) diff --git a/test/random-bytes.js b/test/random-bytes.js index ccb4dd7..4ea7e8e 100644 --- a/test/random-bytes.js +++ b/test/random-bytes.js @@ -1,11 +1,11 @@ var test = require('tape') var crypto = require('../') - -var randomBytesFunctions = ['randomBytes', 'pseudoRandomBytes']; +var randomBytes = require('randombytes') +var randomBytesFunctions = [['randomBytes',randomBytes], ['pseudoRandomBytes', crypto.pseudoRandomBytes]]; for (var idx in randomBytesFunctions) { // Both randomBytes and pseudoRandomBytes should provide the same interface - var randomBytesName = randomBytesFunctions[idx]; - var randomBytes = crypto[randomBytesName] + var randomBytesName = randomBytesFunctions[idx][0]; + var randomBytes = randomBytesFunctions[idx][1]; test('get error message', function (t) { try { From 962685c12df6f603d8acc230f2cf0519e336e55d Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 19 Jan 2015 08:37:53 -0500 Subject: [PATCH 126/217] simplify tests --- test/random-bytes.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/random-bytes.js b/test/random-bytes.js index 4ea7e8e..0ee2f93 100644 --- a/test/random-bytes.js +++ b/test/random-bytes.js @@ -1,11 +1,13 @@ var test = require('tape') var crypto = require('../') var randomBytes = require('randombytes') -var randomBytesFunctions = [['randomBytes',randomBytes], ['pseudoRandomBytes', crypto.pseudoRandomBytes]]; -for (var idx in randomBytesFunctions) { +var randomBytesFunctions = { + randomBytes: randomBytes, + pseudoRandomBytes: crypto.pseudoRandomBytes +} +for (var randomBytesName in randomBytesFunctions) { // Both randomBytes and pseudoRandomBytes should provide the same interface - var randomBytesName = randomBytesFunctions[idx][0]; - var randomBytes = randomBytesFunctions[idx][1]; + var randomBytes = randomBytesFunctions[randomBytesName]; test('get error message', function (t) { try { From 8796866647b48b1f3c40c1ff507f3cc75d3ba64f Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 20 Jan 2015 07:54:13 -0500 Subject: [PATCH 127/217] 3.9.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a14b2c7..74a229c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.9.7", + "version": "3.9.8", "homepage": "https://github.com/crypto-browserify/crypto-browserify", "repository": { "type": "git", From 75431f460b9f4b53ced2066f0918f1655029c5de Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 20 Jan 2015 08:12:10 -0500 Subject: [PATCH 128/217] pull out aes --- index.js | 18 +++++++++++++++++- package.json | 2 +- test/aes.js | 22 +++++++++++++++++++--- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 807d3ac..c7dd2bd 100644 --- a/index.js +++ b/index.js @@ -41,7 +41,23 @@ exports.getHashes = function () { var p = require('./pbkdf2')(exports) exports.pbkdf2 = p.pbkdf2 exports.pbkdf2Sync = p.pbkdf2Sync -require('browserify-aes/inject')(exports, module.exports); + +var aes = require('browserify-aes'); +[ + 'Cipher', + 'createCipher', + 'Cipheriv', + 'createCipheriv', + 'Decipher', + 'createDecipher', + 'Decipheriv', + 'createDecipheriv', + 'getCiphers', + 'listCiphers' +].forEach(function (key) { + exports[key] = aes[key]; +}) + require('browserify-sign/inject')(module.exports, exports); require('diffie-hellman/inject')(exports, module.exports); require('create-ecdh/inject')(module.exports, exports); diff --git a/package.json b/package.json index 74a229c..f935e01 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "node": "*" }, "dependencies": { - "browserify-aes": "0.8.1", + "browserify-aes": "^1.0.0", "browserify-sign": "2.8.0", "create-ecdh": "1.0.3", "create-hash": "^1.1.0", diff --git a/test/aes.js b/test/aes.js index bff0dc0..206ddd7 100644 --- a/test/aes.js +++ b/test/aes.js @@ -1,11 +1,12 @@ var test = require('tape'); -var crypto = require('../'); +var crypto = require('browserify-aes/browser'); +var randomBytes = require('randombytes'); test('ciphers', function (t) { crypto.listCiphers().forEach(function (cipher) { t.test(cipher, function (t) { t.plan(1); - var data = crypto.randomBytes(562); - var password = crypto.randomBytes(20); + var data = randomBytes(562); + var password = randomBytes(20); var crypter = crypto.createCipher(cipher, password); var decrypter = crypto.createDecipher(cipher, password); var out = []; @@ -22,4 +23,19 @@ test('ciphers', function (t) { test('getCiphers', function (t) { t.plan(1); t.ok(crypto.getCiphers().length, 'get ciphers returns an array'); +}); +test('through crypto browserify works', function (t) { + t.plan(2); + var crypto = require('../'); + var cipher = 'aes-128-ctr'; + var data = randomBytes(562); + var password = randomBytes(20); + var crypter = crypto.createCipher(cipher, password); + var decrypter = crypto.createDecipher(cipher, password); + var out = []; + out.push(decrypter.update(crypter.update(data))); + out.push(decrypter.update(crypter.final())); + out.push(decrypter.final()); + t.equals(data.toString('hex'), Buffer.concat(out).toString('hex')); + t.ok(crypto.getCiphers().length, 'get ciphers returns an array'); }); \ No newline at end of file From b2a8bb9e55ef724b5196c9e26f772ba96a0ea9e0 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 21 Jan 2015 06:04:00 -0500 Subject: [PATCH 129/217] 3.9.9 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f935e01..704d0c3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.9.8", + "version": "3.9.9", "homepage": "https://github.com/crypto-browserify/crypto-browserify", "repository": { "type": "git", From af321bb1550eeb89d9060ab19ce7e9ea29d5c1a4 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Fri, 23 Jan 2015 18:09:49 -0500 Subject: [PATCH 130/217] make prng/pseudorandombytes an alias for rng/randombytes --- index.js | 18 ++---------------- prng.js | 27 --------------------------- 2 files changed, 2 insertions(+), 43 deletions(-) delete mode 100644 prng.js diff --git a/index.js b/index.js index c7dd2bd..1bf8107 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ 'use strict'; -exports.randomBytes = exports.rng = require('randombytes') -var prng = exports.prng = require('./prng'); + +exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes') function error () { var m = [].slice.call(arguments).join(' ') @@ -15,20 +15,6 @@ exports.createHash = exports.Hash = require('create-hash') exports.createHmac = exports.Hmac = require('create-hmac') -exports.pseudoRandomBytes = function(size, callback) { - if (callback && callback.call) { - var res; - try { - res = prng(size) - } catch (err) { - return callback(err) - } - callback.call(this, undefined, res) - } else { - return prng(size) - } -} - function each(a, f) { for(var i in a) f(a[i], i) diff --git a/prng.js b/prng.js deleted file mode 100644 index 3fa46cc..0000000 --- a/prng.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; -(function() { - var g = ('undefined' === typeof window ? global : window) || {} - var _crypto = ( - g.crypto || g.msCrypto || require('crypto') - ) - module.exports = function(size) { - // Modern Browsers - if(_crypto.getRandomValues) { - var bytes = new Buffer(size); //in browserify, this is an extended Uint8Array - /* This will not work in older browsers. - * See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues - */ - - _crypto.getRandomValues(bytes); - return bytes; - } - else if (_crypto.pseudoRandomBytes) { - return _crypto.pseudoRandomBytes(size) - } - else - throw new Error( - 'pseudo random number generation not yet implemented for this browser\n'+ - 'use chrome, FireFox or Internet Explorer 11' - ) - } -}()) From a96c30c3ec14aafdb70887f068a1d55a3c28c182 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 26 Jan 2015 09:30:29 -0500 Subject: [PATCH 131/217] 3.9.10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 704d0c3..6cf89c0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.9.9", + "version": "3.9.10", "homepage": "https://github.com/crypto-browserify/crypto-browserify", "repository": { "type": "git", From b2c4ecc71fe05d27cbae7b4c51e587d5a7606197 Mon Sep 17 00:00:00 2001 From: Forbes Lindesay Date: Wed, 28 Jan 2015 15:31:34 +0000 Subject: [PATCH 132/217] Fix travis icon --- readme.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index 0cc75df..336447c 100644 --- a/readme.markdown +++ b/readme.markdown @@ -2,7 +2,7 @@ A port of node's `crypto` module to the browser. -[![travis](https://secure.travis-ci.org/dominictarr/crypto-browserify.png?branch=master)](https://travis-ci.org/dominictarr/crypto-browserify) +[![travis](https://img.shields.io/travis/crypto-browserify/crypto-browserify/master.svg?style=flat)](https://travis-ci.org/crypto-browserify/crypto-browserify) The goal of this module is to reimplement node's crypto module, in pure javascript so that it can run in the browser. From 2685e3ead44702be132a2b8eee6eb0934029780c Mon Sep 17 00:00:00 2001 From: Forbes Lindesay Date: Thu, 29 Jan 2015 11:39:36 +0000 Subject: [PATCH 133/217] Simplify reporting of un-implemented methods and add privateEncrypt/publicDecrypt --- index.js | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 1bf8107..8788c9e 100644 --- a/index.js +++ b/index.js @@ -2,23 +2,10 @@ exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes') -function error () { - var m = [].slice.call(arguments).join(' ') - throw new Error([ - m, - 'we accept pull requests', - 'http://github.com/dominictarr/crypto-browserify' - ].join('\n')) -} - exports.createHash = exports.Hash = require('create-hash') exports.createHmac = exports.Hmac = require('create-hmac') -function each(a, f) { - for(var i in a) - f(a[i], i) -} var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(Object.keys(require('browserify-sign/algos'))) exports.getHashes = function () { return hashes; @@ -50,10 +37,16 @@ require('create-ecdh/inject')(module.exports, exports); require('public-encrypt/inject')(module.exports, exports); // the least I can do is make error messages for the rest of the node.js/crypto api. -each([ - 'createCredentials' -], function (name) { +[ + 'createCredentials', + 'privateEncrypt', + 'publicDecrypt' +].forEach(function (name) { exports[name] = function () { - error('sorry,', name, 'is not implemented yet') + throw new Error([ + 'sorry, ' + name + ' is not implemented yet', + 'we accept pull requests', + 'https://github.com/crypto-browserify/crypto-browserify' + ].join('\n')); } }) From 1efee1790e4f66894c3476c4b00d2300dc4eadf6 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 21 Jan 2015 07:12:16 -0500 Subject: [PATCH 134/217] pull out diffie-hellman --- index.js | 12 +++++++++++- package.json | 2 +- test/dh.js | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 1bf8107..5755352 100644 --- a/index.js +++ b/index.js @@ -44,8 +44,18 @@ var aes = require('browserify-aes'); exports[key] = aes[key]; }) +var dh = require('diffie-hellman'); +[ + 'DiffieHellmanGroup', + 'createDiffieHellmanGroup', + 'getDiffieHellman', + 'createDiffieHellman', + 'DiffieHellman' +].forEach(function (key) { + exports[key] = dh[key]; +}) + require('browserify-sign/inject')(module.exports, exports); -require('diffie-hellman/inject')(exports, module.exports); require('create-ecdh/inject')(module.exports, exports); require('public-encrypt/inject')(module.exports, exports); diff --git a/package.json b/package.json index 6cf89c0..b4d59a2 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "create-ecdh": "1.0.3", "create-hash": "^1.1.0", "create-hmac": "^1.1.0", - "diffie-hellman": "2.2.3", + "diffie-hellman": "^3.0.1", "inherits": "^2.0.1", "pbkdf2-compat": "2.0.1", "public-encrypt": "1.1.2", diff --git a/test/dh.js b/test/dh.js index fea0767..8ce85d6 100644 --- a/test/dh.js +++ b/test/dh.js @@ -1,5 +1,5 @@ var test = require('tape'); -var crypto = require('../'); +var crypto = require('diffie-hellman/browser'); test('diffie-hellman mod groups', function (t) { [ 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16' From dbd16c6148f8313e43e46fe8071e20827a74efc0 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 29 Jan 2015 08:59:39 -0500 Subject: [PATCH 135/217] 3.9.11 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b4d59a2..721f9fb 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.9.10", + "version": "3.9.11", "homepage": "https://github.com/crypto-browserify/crypto-browserify", "repository": { "type": "git", From 61056c06a520494d2c1781d6f9eb089bc1e38dc9 Mon Sep 17 00:00:00 2001 From: Forbes Lindesay Date: Thu, 29 Jan 2015 12:08:53 +0000 Subject: [PATCH 136/217] Modularize pbkdf2-compat --- index.js | 2 +- package.json | 2 +- pbkdf2.js | 13 ------------- test/pbkdf2.js | 4 ++-- 4 files changed, 4 insertions(+), 17 deletions(-) delete mode 100644 pbkdf2.js diff --git a/index.js b/index.js index 48e67c1..65ccdeb 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ exports.getHashes = function () { return hashes; } -var p = require('./pbkdf2')(exports) +var p = require('pbkdf2-compat') exports.pbkdf2 = p.pbkdf2 exports.pbkdf2Sync = p.pbkdf2Sync diff --git a/package.json b/package.json index 721f9fb..d0459a5 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "create-hmac": "^1.1.0", "diffie-hellman": "^3.0.1", "inherits": "^2.0.1", - "pbkdf2-compat": "2.0.1", + "pbkdf2-compat": "^3.0.1", "public-encrypt": "1.1.2", "randombytes": "^2.0.0" }, diff --git a/pbkdf2.js b/pbkdf2.js deleted file mode 100644 index 0453509..0000000 --- a/pbkdf2.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; -var pbkdf2Export = require('pbkdf2-compat/pbkdf2') - -module.exports = function (crypto, exports) { - exports = exports || {} - - var exported = pbkdf2Export(crypto) - - exports.pbkdf2 = exported.pbkdf2 - exports.pbkdf2Sync = exported.pbkdf2Sync - - return exports -} diff --git a/test/pbkdf2.js b/test/pbkdf2.js index fc26900..7c361bd 100644 --- a/test/pbkdf2.js +++ b/test/pbkdf2.js @@ -1,6 +1,6 @@ var tape = require('tape') -var pbkdf2Sync = require('../').pbkdf2Sync +var crypto = require('pbkdf2-compat/browser') var vectors = require('hash-test-vectors/pbkdf2') @@ -9,7 +9,7 @@ tape('pbkdf2', function (t) { //skip inputs that will take way too long if(input.iterations > 10000) return - var key = pbkdf2Sync(input.password, input.salt, input.iterations, input.length) + var key = crypto.pbkdf2Sync(input.password, input.salt, input.iterations, input.length) if(key.toString('hex') !== input.sha1) console.log(input) From e896146a4e99b8efffe1119fe6b28f5d34f48341 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 2 Feb 2015 08:11:49 -0500 Subject: [PATCH 137/217] 3.9.12 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d0459a5..3e2a1ba 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.9.11", + "version": "3.9.12", "homepage": "https://github.com/crypto-browserify/crypto-browserify", "repository": { "type": "git", From 882de00bf77c296ffc2505d612c31b69d8265c4b Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 12 Feb 2015 08:59:14 -0500 Subject: [PATCH 138/217] modularize ecdh --- index.js | 6 ++++-- package.json | 2 +- test/ecdh.js | 20 ++++++++++++-------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 65ccdeb..06d3b48 100644 --- a/index.js +++ b/index.js @@ -43,8 +43,10 @@ var dh = require('diffie-hellman'); }) require('browserify-sign/inject')(module.exports, exports); -require('create-ecdh/inject')(module.exports, exports); -require('public-encrypt/inject')(module.exports, exports); + +exports.createECDH = require('create-ecdh'); + +var publicEncrypt = require('public-encrypt'); // the least I can do is make error messages for the rest of the node.js/crypto api. [ diff --git a/package.json b/package.json index 3e2a1ba..a0f5d07 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "dependencies": { "browserify-aes": "^1.0.0", "browserify-sign": "2.8.0", - "create-ecdh": "1.0.3", + "create-ecdh": "^2.0.0", "create-hash": "^1.1.0", "create-hmac": "^1.1.0", "diffie-hellman": "^3.0.1", diff --git a/test/ecdh.js b/test/ecdh.js index 6819d13..0a11e8e 100644 --- a/test/ecdh.js +++ b/test/ecdh.js @@ -1,15 +1,19 @@ var mods = [ - 'secp256k1' + 'secp256k1', + 'secp224r1', + 'prime256v1', + 'prime192v1' ]; var test = require('tape'); -var crypto = require('../'); +var createECDH1 = require('../').createECDH; +var createECDH2 = require('create-ecdh/browser'); test('createECDH', function (t) { mods.forEach(function (mod) { t.test(mod + ' uncompressed', function (t){ t.plan(2); - var dh1 = crypto.createECDH(mod); + var dh1 = createECDH1(mod); dh1.generateKeys(); - var dh2 = crypto.createECDH(mod); + var dh2 = createECDH2(mod); dh2.generateKeys(); var pubk1 = dh1.getPublicKey(); var pubk2 = dh2.getPublicKey(); @@ -20,9 +24,9 @@ mods.forEach(function (mod) { }); t.test(mod + ' compressed', function (t){ t.plan(2); - var dh1 = crypto.createECDH(mod); + var dh1 = createECDH1(mod); dh1.generateKeys(); - var dh2 = crypto.createECDH(mod); + var dh2 = createECDH2(mod); dh2.generateKeys(); var pubk1 = dh1.getPublicKey(null, 'compressed'); var pubk2 = dh2.getPublicKey(null, 'compressed'); @@ -33,8 +37,8 @@ mods.forEach(function (mod) { }); t.test(mod + ' set stuff', function (t){ t.plan(5); - var dh1 = crypto.createECDH(mod); - var dh2 = crypto.createECDH(mod); + var dh1 = createECDH1(mod); + var dh2 = createECDH2(mod); dh1.generateKeys(); dh2.generateKeys(); dh1.setPrivateKey(dh2.getPrivateKey()); From 681984a197475e7ab31bd656194aa24d13b2662d Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 12 Feb 2015 08:59:46 -0500 Subject: [PATCH 139/217] modularize publicEncrypt --- index.js | 15 +++++++++++---- package.json | 2 +- test/public-encrypt.js | 26 ++++++++++++++++++++------ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 06d3b48..e39a004 100644 --- a/index.js +++ b/index.js @@ -44,15 +44,22 @@ var dh = require('diffie-hellman'); require('browserify-sign/inject')(module.exports, exports); -exports.createECDH = require('create-ecdh'); +exports.createECDH = require('create-ecdh') var publicEncrypt = require('public-encrypt'); -// the least I can do is make error messages for the rest of the node.js/crypto api. [ - 'createCredentials', + 'publicEncrypt', 'privateEncrypt', - 'publicDecrypt' + 'publicDecrypt', + 'privateDecrypt' +].forEach(function (key) { + exports[key] = publicEncrypt[key]; +}) + +// the least I can do is make error messages for the rest of the node.js/crypto api. +;[ + 'createCredentials' ].forEach(function (name) { exports[name] = function () { throw new Error([ diff --git a/package.json b/package.json index a0f5d07..aff8410 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "diffie-hellman": "^3.0.1", "inherits": "^2.0.1", "pbkdf2-compat": "^3.0.1", - "public-encrypt": "1.1.2", + "public-encrypt": "^2.0.0", "randombytes": "^2.0.0" }, "devDependencies": { diff --git a/test/public-encrypt.js b/test/public-encrypt.js index 1a5cb62..927c0f5 100644 --- a/test/public-encrypt.js +++ b/test/public-encrypt.js @@ -1,23 +1,37 @@ var test = require('tape'); -var crypto = require('../'); +var crypto1 = require('../'); var rsa = { "private": "2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a", "public": "2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a" }; - +var crypto2 = require('public-encrypt/browser'); rsa.private = new Buffer(rsa.private, 'hex'); rsa.public = new Buffer(rsa.public, 'hex'); var encrypted = '0bcd6462ad7a563be2d42b0b73e0b0a163886304e7723b025f97605144fe1781e84acdc4031327d6bccd67fe13183e8fbdc8c5fe947b49d011ce3ebb08b11e83b87a77328ca57ee77cfdc78743b0749366643d7a21b2abcd4aa32dee9832938445540ee3007b7a70191c8dc9ff2ad76fe8dfaa5362d9d2c4b31a67b816d7b7970a293cb95bf3437a301bedb9f431b7075aa2f9df77b4385bea2a37982beda467260b384a58258b5eb4e36a0e0bf7dff83589636f5f97bf542084f0f76868c9f3f989a27fee5b8cd2bfee0bae1eae958df7c3184e5a40fda101196214f371606feca4330b221f30577804bbd4f61578a84e85dcd298849f509e630d275280'; test('publicEncrypt/privateDecrypt', function (t) { t.test('can decrypt', function (t) { - t.plan(1); + t.plan(2); + // note encryption is ranomized so can't test to see if they encrypt the same + t.equals(crypto1.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly'); + t.equals(crypto2.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly'); + + }); + t.test('can round trip', function (t) { + t.plan(2); + var msg = 'this is a message'; // note encryption is ranomized so can't test to see if they encrypt the same - t.equals(crypto.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly'); + t.equals(crypto1.privateDecrypt(rsa.private, crypto2.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it'); + t.equals(crypto2.privateDecrypt(rsa.private, crypto1.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it'); + }); +}); +test('privateEncrypt/publicDecrypt', function (t) { t.test('can round trip', function (t) { - t.plan(1); + t.plan(2); var msg = 'this is a message'; // note encryption is ranomized so can't test to see if they encrypt the same - t.equals(crypto.privateDecrypt(rsa.private, crypto.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it'); + t.equals(crypto1.publicDecrypt(rsa.public, crypto2.privateEncrypt(rsa.private, new Buffer(msg))).toString(), msg, 'round trip it'); + t.equals(crypto2.publicDecrypt(rsa.public, crypto1.privateEncrypt(rsa.private, new Buffer(msg))).toString(), msg, 'round trip it'); + }); }); \ No newline at end of file From 3f7ba7ec29213f04b0bad60a4bd39a706873b293 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 12 Feb 2015 09:00:12 -0500 Subject: [PATCH 140/217] more test targets --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 05d299e..737e035 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,3 +2,5 @@ language: node_js node_js: - "0.10" - "0.11" + - "0.12" + - "iojs" \ No newline at end of file From b3e9dcaa517b58b942e40335896421ffa658b68b Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 23 Feb 2015 16:17:29 -0500 Subject: [PATCH 141/217] 3.9.13 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aff8410..ba0c06d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.9.12", + "version": "3.9.13", "homepage": "https://github.com/crypto-browserify/crypto-browserify", "repository": { "type": "git", From 353d1cf49d9193530f2d70b8aa418cce7cf500fd Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 13 Apr 2015 12:45:47 -0400 Subject: [PATCH 142/217] modularize browserify-sign and update test --- index.js | 10 +++++++++- package.json | 2 +- test/sign.js | 43 ++++++++++++++++++++++++++++++++++--------- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index e39a004..f634fdf 100644 --- a/index.js +++ b/index.js @@ -42,7 +42,15 @@ var dh = require('diffie-hellman'); exports[key] = dh[key]; }) -require('browserify-sign/inject')(module.exports, exports); +var sign = require('browserify-sign'); +[ + 'createSign', + 'Sign', + 'createVerify', + 'Verify' +].forEach(function (key) { + exports[key] = sign[key]; +}) exports.createECDH = require('create-ecdh') diff --git a/package.json b/package.json index ba0c06d..4b68223 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ }, "dependencies": { "browserify-aes": "^1.0.0", - "browserify-sign": "2.8.0", + "browserify-sign": "^3.0.1", "create-ecdh": "^2.0.0", "create-hash": "^1.1.0", "create-hmac": "^1.1.0", diff --git a/test/sign.js b/test/sign.js index 1dacc89..39b0ef1 100644 --- a/test/sign.js +++ b/test/sign.js @@ -1,5 +1,7 @@ var test = require('tape'); -var crypto = require('../'); +var nodeCrypto = require('../'); +var ourCrypto = require('browserify-sign/browser'); + var rsa = { "private": "2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a", "public": "2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a" @@ -11,18 +13,41 @@ var ec = { rsa.private = new Buffer(rsa.private, 'hex'); rsa.public = new Buffer(rsa.public, 'hex'); -ec.private = new Buffer(rsa.private, 'hex'); -ec.public = new Buffer(rsa.public, 'hex'); +ec.private = new Buffer(ec.private, 'hex'); +ec.public = new Buffer(ec.public, 'hex'); function testit(keys, message, scheme) { var pub = keys.public; var priv = keys.private; test(message.toString(), function (t) { - t.plan(1); - var mySign = crypto.createSign(scheme); - var mySig = mySign.update(message).sign(priv); - var myVer = crypto.createVerify(scheme); - t.ok(myVer.update(message).verify(pub, mySig), 'validates'); + t.test('js sign and verify', function (t) { + t.plan(t); + var mySign = ourCrypto.createSign(scheme); + var mySig = mySign.update(message).sign(priv); + var myVer = ourCrypto.createVerify(scheme); + t.ok(myVer.update(message).verify(pub, mySig), 'validates'); + }); + t.test('node sign and verify', function (t) { + t.plan(t); + var mySign = nodeCrypto.createSign(scheme); + var mySig = mySign.update(message).sign(priv); + var myVer = nodeCrypto.createVerify(scheme); + t.ok(myVer.update(message).verify(pub, mySig), 'validates'); + }); + t.test('node sign and js verify', function (t) { + t.plan(t); + var mySign = nodeCrypto.createSign(scheme); + var mySig = mySign.update(message).sign(priv); + var myVer = ourCrypto.createVerify(scheme); + t.ok(myVer.update(message).verify(pub, mySig), 'validates'); + }); + t.test('js sign and node verify', function (t) { + t.plan(t); + var mySign = ourCrypto.createSign(scheme); + var mySig = mySign.update(message).sign(priv); + var myVer = nodeCrypto.createVerify(scheme); + t.ok(myVer.update(message).verify(pub, mySig), 'validates'); + }); }); } testit(rsa, new Buffer('rsa with sha256'), 'RSA-SHA256'); -testit(ec, new Buffer('ec with sha1'), 'ecdsa-with-SHA1'); \ No newline at end of file +testit(ec, new Buffer('ec with sha1'), 'ecdsa-with-SHA1'); From 8e87aa34870e5bd598535779874558a972487c75 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 16 Apr 2015 13:49:15 +1000 Subject: [PATCH 143/217] use pbkdf2 over pbkdf2-compat --- index.js | 2 +- package.json | 2 +- test/pbkdf2.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index f634fdf..67908ba 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ exports.getHashes = function () { return hashes; } -var p = require('pbkdf2-compat') +var p = require('pbkdf2') exports.pbkdf2 = p.pbkdf2 exports.pbkdf2Sync = p.pbkdf2Sync diff --git a/package.json b/package.json index 4b68223..f86ea05 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "create-hmac": "^1.1.0", "diffie-hellman": "^3.0.1", "inherits": "^2.0.1", - "pbkdf2-compat": "^3.0.1", + "pbkdf2": "^3.0.3", "public-encrypt": "^2.0.0", "randombytes": "^2.0.0" }, diff --git a/test/pbkdf2.js b/test/pbkdf2.js index 7c361bd..c86dc87 100644 --- a/test/pbkdf2.js +++ b/test/pbkdf2.js @@ -1,6 +1,6 @@ var tape = require('tape') -var crypto = require('pbkdf2-compat/browser') +var crypto = require('pbkdf2/browser') var vectors = require('hash-test-vectors/pbkdf2') From 7ac9b42974526f0b7fe1714c1dac970eb7c0ef3c Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 16 Apr 2015 08:52:19 -0400 Subject: [PATCH 144/217] 3.9.14 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f86ea05..95ca56d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.9.13", + "version": "3.9.14", "homepage": "https://github.com/crypto-browserify/crypto-browserify", "repository": { "type": "git", From 72e6c6272af8f2461cf885b5e22c11abc70bd599 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 13 Aug 2015 15:12:44 +1000 Subject: [PATCH 145/217] add standard 5.0.0 --- .travis.yml | 7 ++- example/test.js | 2 +- index.js | 32 ++++++----- package.json | 11 ++-- test/aes.js | 71 +++++++++++++------------ test/create-hash.js | 39 +++++++------- test/create-hmac.js | 18 +++---- test/dh.js | 84 ++++++++++++++--------------- test/ecdh.js | 117 +++++++++++++++++++++-------------------- test/node/dh.js | 82 ++++++++++++++--------------- test/pbkdf2.js | 10 ++-- test/public-encrypt.js | 52 +++++++++--------- test/random-bytes.js | 54 +++++++++---------- test/sign.js | 96 +++++++++++++++++---------------- 14 files changed, 347 insertions(+), 328 deletions(-) diff --git a/.travis.yml b/.travis.yml index 737e035..1f1ec66 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,11 @@ +sudo: false language: node_js node_js: - "0.10" - "0.11" - "0.12" - - "iojs" \ No newline at end of file + - "iojs" +env: + - TEST_SUITE=standard + - TEST_SUITE=unit +script: "npm run-script $TEST_SUITE" diff --git a/example/test.js b/example/test.js index f1b0e4a..0b76c01 100644 --- a/example/test.js +++ b/example/test.js @@ -1,4 +1,4 @@ var crypto = require('crypto') var abc = crypto.createHash('sha1').update('abc').digest('hex') console.log(abc) -//require('hello').inlineCall().call2() +// require('hello').inlineCall().call2() diff --git a/index.js b/index.js index 67908ba..3bc3e0c 100644 --- a/index.js +++ b/index.js @@ -1,22 +1,20 @@ -'use strict'; +'use strict' exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes') - exports.createHash = exports.Hash = require('create-hash') - exports.createHmac = exports.Hmac = require('create-hmac') var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(Object.keys(require('browserify-sign/algos'))) exports.getHashes = function () { - return hashes; + return hashes } var p = require('pbkdf2') exports.pbkdf2 = p.pbkdf2 exports.pbkdf2Sync = p.pbkdf2Sync -var aes = require('browserify-aes'); -[ +var aes = require('browserify-aes') +;[ 'Cipher', 'createCipher', 'Cipheriv', @@ -28,41 +26,41 @@ var aes = require('browserify-aes'); 'getCiphers', 'listCiphers' ].forEach(function (key) { - exports[key] = aes[key]; + exports[key] = aes[key] }) -var dh = require('diffie-hellman'); -[ +var dh = require('diffie-hellman') +;[ 'DiffieHellmanGroup', 'createDiffieHellmanGroup', 'getDiffieHellman', 'createDiffieHellman', 'DiffieHellman' ].forEach(function (key) { - exports[key] = dh[key]; + exports[key] = dh[key] }) -var sign = require('browserify-sign'); -[ +var sign = require('browserify-sign') +;[ 'createSign', 'Sign', 'createVerify', 'Verify' ].forEach(function (key) { - exports[key] = sign[key]; + exports[key] = sign[key] }) exports.createECDH = require('create-ecdh') -var publicEncrypt = require('public-encrypt'); +var publicEncrypt = require('public-encrypt') -[ +;[ 'publicEncrypt', 'privateEncrypt', 'publicDecrypt', 'privateDecrypt' ].forEach(function (key) { - exports[key] = publicEncrypt[key]; + exports[key] = publicEncrypt[key] }) // the least I can do is make error messages for the rest of the node.js/crypto api. @@ -74,6 +72,6 @@ var publicEncrypt = require('public-encrypt'); 'sorry, ' + name + ' is not implemented yet', 'we accept pull requests', 'https://github.com/crypto-browserify/crypto-browserify' - ].join('\n')); + ].join('\n')) } }) diff --git a/package.json b/package.json index 95ca56d..7a1acd8 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,10 @@ "url": "git://github.com/crypto-browserify/crypto-browserify.git" }, "scripts": { - "test": "set -e; for t in test/node/*.js test/*.js; do node $t; done", - "prepublish": "npm ls && npm test" + "prepublish": "npm ls && npm test", + "standard": "standard", + "test": "npm run standard && npm run unit", + "unit": "set -e; for t in test/node/*.js test/*.js; do node $t; done" }, "engines": { "node": "*" @@ -28,8 +30,9 @@ "randombytes": "^2.0.0" }, "devDependencies": { - "tape": "~2.3.2", - "hash-test-vectors": "~1.3.2" + "hash-test-vectors": "~1.3.2", + "standard": "^5.0.2", + "tape": "~2.3.2" }, "optionalDependencies": {}, "browser": { diff --git a/test/aes.js b/test/aes.js index 206ddd7..2cbc366 100644 --- a/test/aes.js +++ b/test/aes.js @@ -1,41 +1,44 @@ -var test = require('tape'); -var crypto = require('browserify-aes/browser'); -var randomBytes = require('randombytes'); +var test = require('tape') +var crypto = require('browserify-aes/browser') +var randomBytes = require('randombytes') + test('ciphers', function (t) { crypto.listCiphers().forEach(function (cipher) { t.test(cipher, function (t) { - t.plan(1); - var data = randomBytes(562); - var password = randomBytes(20); - var crypter = crypto.createCipher(cipher, password); - var decrypter = crypto.createDecipher(cipher, password); - var out = []; - out.push(decrypter.update(crypter.update(data))); - out.push(decrypter.update(crypter.final())); + t.plan(1) + var data = randomBytes(562) + var password = randomBytes(20) + var crypter = crypto.createCipher(cipher, password) + var decrypter = crypto.createDecipher(cipher, password) + var out = [] + out.push(decrypter.update(crypter.update(data))) + out.push(decrypter.update(crypter.final())) if (cipher.indexOf('gcm') > -1) { - decrypter.setAuthTag(crypter.getAuthTag()); + decrypter.setAuthTag(crypter.getAuthTag()) } - out.push(decrypter.final()); - t.equals(data.toString('hex'), Buffer.concat(out).toString('hex')); - }); - }); -}); + out.push(decrypter.final()) + t.equals(data.toString('hex'), Buffer.concat(out).toString('hex')) + }) + }) +}) + test('getCiphers', function (t) { - t.plan(1); - t.ok(crypto.getCiphers().length, 'get ciphers returns an array'); -}); + t.plan(1) + t.ok(crypto.getCiphers().length, 'get ciphers returns an array') +}) + test('through crypto browserify works', function (t) { - t.plan(2); - var crypto = require('../'); - var cipher = 'aes-128-ctr'; - var data = randomBytes(562); - var password = randomBytes(20); - var crypter = crypto.createCipher(cipher, password); - var decrypter = crypto.createDecipher(cipher, password); - var out = []; - out.push(decrypter.update(crypter.update(data))); - out.push(decrypter.update(crypter.final())); - out.push(decrypter.final()); - t.equals(data.toString('hex'), Buffer.concat(out).toString('hex')); - t.ok(crypto.getCiphers().length, 'get ciphers returns an array'); -}); \ No newline at end of file + t.plan(2) + var crypto = require('../') + var cipher = 'aes-128-ctr' + var data = randomBytes(562) + var password = randomBytes(20) + var crypter = crypto.createCipher(cipher, password) + var decrypter = crypto.createDecipher(cipher, password) + var out = [] + out.push(decrypter.update(crypter.update(data))) + out.push(decrypter.update(crypter.final())) + out.push(decrypter.final()) + t.equals(data.toString('hex'), Buffer.concat(out).toString('hex')) + t.ok(crypto.getCiphers().length, 'get ciphers returns an array') +}) diff --git a/test/create-hash.js b/test/create-hash.js index 6912ff7..02c9106 100644 --- a/test/create-hash.js +++ b/test/create-hash.js @@ -1,41 +1,42 @@ -var fs = require('fs') var test = require('tape') var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'] -var encodings = [/*'binary',*/ 'hex', 'base64']; +var encodings = ['hex', 'base64'] // FIXME: test binary var vectors = require('hash-test-vectors') -testLib('createHash in crypto-browserify',require('../').createHash); -testLib('create-hash/browser',require('create-hash/browser')); -function testLib(name, createHash) { - test(name, function (t){ + +testLib('createHash in crypto-browserify', require('../').createHash) +testLib('create-hash/browser', require('create-hash/browser')) + +function testLib (name, createHash) { + test(name, function (t) { algorithms.forEach(function (algorithm) { t.test('test ' + algorithm + ' against test vectors', function (t) { vectors.forEach(function (obj, i) { var input = new Buffer(obj.input, 'base64') var node = obj[algorithm] var js = createHash(algorithm).update(input).digest('hex') - t.equal(js, node, algorithm + '(testVector['+i+']) == ' + node) + t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node) }) encodings.forEach(function (encoding) { - vectors.forEach(function (obj, i) { - var input = new Buffer(obj.input, 'base64').toString(encoding) - var node = obj[algorithm] - var js = createHash(algorithm).update(input, encoding).digest('hex') - t.equal(js, node, algorithm + '(testVector['+i+'], '+encoding+') == ' + node) - }) - }); + vectors.forEach(function (obj, i) { + var input = new Buffer(obj.input, 'base64').toString(encoding) + var node = obj[algorithm] + var js = createHash(algorithm).update(input, encoding).digest('hex') + t.equal(js, node, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + node) + }) + }) vectors.forEach(function (obj, i) { var input = new Buffer(obj.input, 'base64') var node = obj[algorithm] - var hash = createHash(algorithm); + var hash = createHash(algorithm) hash.end(input) var js = hash.read().toString('hex') - t.equal(js, node, algorithm + '(testVector['+i+']) == ' + node) + t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node) }) t.end() }) - }); + }) - }); -} \ No newline at end of file + }) +} diff --git a/test/create-hmac.js b/test/create-hmac.js index 814b573..1c7ec2f 100644 --- a/test/create-hmac.js +++ b/test/create-hmac.js @@ -1,18 +1,17 @@ - var test = require('tape') var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'] var vectors = require('hash-test-vectors/hmac') -testLib('createHmac in crypto-browserify',require('../').createHmac); -testLib('create-hmac/browser',require('create-hmac/browser')); -function testLib(name, createHmac) { - test(name, function (t){ - algorithms.forEach(function (alg) { +testLib('createHmac in crypto-browserify', require('../').createHmac) +testLib('create-hmac/browser', require('create-hmac/browser')) - t.test('hmac('+alg+')', function (t) { +function testLib (name, createHmac) { + test(name, function (t) { + algorithms.forEach(function (alg) { + t.test('hmac(' + alg + ')', function (t) { vectors.forEach(function (input, i) { var output = createHmac(alg, new Buffer(input.key, 'hex')) - .update(input.data, 'hex').digest() + .update(input.data, 'hex').digest() output = input.truncate ? output.slice(0, input.truncate) : output t.equal(output.toString('hex'), input[alg]) @@ -20,7 +19,7 @@ function testLib(name, createHmac) { t.end() }) - t.test('hmac('+alg+')', function (t) { + t.test('hmac(' + alg + ')', function (t) { vectors.forEach(function (input, i) { var hmac = createHmac(alg, new Buffer(input.key, 'hex')) @@ -35,5 +34,4 @@ function testLib(name, createHmac) { }) }) - } diff --git a/test/dh.js b/test/dh.js index 8ce85d6..61fd074 100644 --- a/test/dh.js +++ b/test/dh.js @@ -1,47 +1,49 @@ -var test = require('tape'); -var crypto = require('diffie-hellman/browser'); +var test = require('tape') +var crypto = require('diffie-hellman/browser') + test('diffie-hellman mod groups', function (t) { [ - 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16' + 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16' ].forEach(function (mod) { - t.test(mod, function (t){ - t.plan(3); - var dh1 = crypto.getDiffieHellman(mod); - var p1 = dh1.getPrime().toString('hex'); - dh1.generateKeys(); - var dh2 = crypto.getDiffieHellman(mod); - var p2 = dh2.getPrime().toString('hex'); - dh2.generateKeys(); - t.equals(p1, p2, 'equal primes'); - var pubk1 = dh1.getPublicKey(); - var pubk2 = dh2.getPublicKey(); - t.notEquals(pubk1, pubk2, 'diff public keys'); - var pub1 = dh1.computeSecret(pubk2).toString('hex'); - var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex'); - t.equals(pub1, pub2, 'equal secrets'); - }); - }); -}); + t.test(mod, function (t) { + t.plan(3) + var dh1 = crypto.getDiffieHellman(mod) + var p1 = dh1.getPrime().toString('hex') + dh1.generateKeys() + var dh2 = crypto.getDiffieHellman(mod) + var p2 = dh2.getPrime().toString('hex') + dh2.generateKeys() + t.equals(p1, p2, 'equal primes') + var pubk1 = dh1.getPublicKey() + var pubk2 = dh2.getPublicKey() + t.notEquals(pubk1, pubk2, 'diff public keys') + var pub1 = dh1.computeSecret(pubk2).toString('hex') + var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex') + t.equals(pub1, pub2, 'equal secrets') + }) + }) +}) + test('diffie-hellman key lengths', function (t) { [ - 64, 65, 192 + 64, 65, 192 ].forEach(function (len) { - t.test('' + len, function (t){ - t.plan(3); - var dh2 = crypto.createDiffieHellman(len); - var prime2 = dh2.getPrime(); - var p2 = prime2.toString('hex'); - var dh1 = crypto.createDiffieHellman(prime2); - var p1 = dh1.getPrime().toString('hex'); - dh1.generateKeys(); - dh2.generateKeys(); - t.equals(p1, p2, 'equal primes'); - var pubk1 = dh1.getPublicKey(); - var pubk2 = dh2.getPublicKey(); - t.notEquals(pubk1, pubk2, 'diff public keys'); - var pub1 = dh1.computeSecret(pubk2).toString('hex'); - var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex'); - t.equals(pub1, pub2, 'equal secrets'); - }); - }); -}); + t.test('' + len, function (t) { + t.plan(3) + var dh2 = crypto.createDiffieHellman(len) + var prime2 = dh2.getPrime() + var p2 = prime2.toString('hex') + var dh1 = crypto.createDiffieHellman(prime2) + var p1 = dh1.getPrime().toString('hex') + dh1.generateKeys() + dh2.generateKeys() + t.equals(p1, p2, 'equal primes') + var pubk1 = dh1.getPublicKey() + var pubk2 = dh2.getPublicKey() + t.notEquals(pubk1, pubk2, 'diff public keys') + var pub1 = dh1.computeSecret(pubk2).toString('hex') + var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex') + t.equals(pub1, pub2, 'equal secrets') + }) + }) +}) diff --git a/test/ecdh.js b/test/ecdh.js index 0a11e8e..ad37c56 100644 --- a/test/ecdh.js +++ b/test/ecdh.js @@ -1,59 +1,62 @@ var mods = [ - 'secp256k1', - 'secp224r1', - 'prime256v1', - 'prime192v1' -]; -var test = require('tape'); -var createECDH1 = require('../').createECDH; -var createECDH2 = require('create-ecdh/browser'); + 'secp256k1', + 'secp224r1', + 'prime256v1', + 'prime192v1' +] +var test = require('tape') +var createECDH1 = require('../').createECDH +var createECDH2 = require('create-ecdh/browser') + test('createECDH', function (t) { -mods.forEach(function (mod) { - t.test(mod + ' uncompressed', function (t){ - t.plan(2); - var dh1 = createECDH1(mod); - dh1.generateKeys(); - var dh2 = createECDH2(mod); - dh2.generateKeys(); - var pubk1 = dh1.getPublicKey(); - var pubk2 = dh2.getPublicKey(); - t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys'); - var pub1 = dh1.computeSecret(pubk2).toString('hex'); - var pub2 = dh2.computeSecret(pubk1).toString('hex'); - t.equals(pub1, pub2, 'equal secrets'); - }); - t.test(mod + ' compressed', function (t){ - t.plan(2); - var dh1 = createECDH1(mod); - dh1.generateKeys(); - var dh2 = createECDH2(mod); - dh2.generateKeys(); - var pubk1 = dh1.getPublicKey(null, 'compressed'); - var pubk2 = dh2.getPublicKey(null, 'compressed'); - t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys'); - var pub1 = dh1.computeSecret(pubk2).toString('hex'); - var pub2 = dh2.computeSecret(pubk1).toString('hex'); - t.equals(pub1, pub2, 'equal secrets'); - }); - t.test(mod + ' set stuff', function (t){ - t.plan(5); - var dh1 = createECDH1(mod); - var dh2 = createECDH2(mod); - dh1.generateKeys(); - dh2.generateKeys(); - dh1.setPrivateKey(dh2.getPrivateKey()); - dh1.setPublicKey(dh2.getPublicKey()); - var priv1 = dh1.getPrivateKey('hex'); - var priv2 = dh2.getPrivateKey('hex'); - t.equals(priv1, priv2, 'same private key'); - var pubk1 = dh1.getPublicKey(); - var pubk2 = dh2.getPublicKey(); - t.equals(pubk1.toString('hex'), pubk2.toString('hex'), 'same public keys, uncompressed'); - t.equals(dh1.getPublicKey('hex', 'compressed'), dh2.getPublicKey('hex', 'compressed'), 'same public keys compressed'); - t.equals(dh1.getPublicKey('hex', 'hybrid'), dh2.getPublicKey('hex', 'hybrid'), 'same public keys hybrid'); - var pub1 = dh1.computeSecret(pubk2).toString('hex'); - var pub2 = dh2.computeSecret(pubk1).toString('hex'); - t.equals(pub1, pub2, 'equal secrets'); - }); - }); -}); \ No newline at end of file + mods.forEach(function (mod) { + t.test(mod + ' uncompressed', function (t) { + t.plan(2) + var dh1 = createECDH1(mod) + dh1.generateKeys() + var dh2 = createECDH2(mod) + dh2.generateKeys() + var pubk1 = dh1.getPublicKey() + var pubk2 = dh2.getPublicKey() + t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys') + var pub1 = dh1.computeSecret(pubk2).toString('hex') + var pub2 = dh2.computeSecret(pubk1).toString('hex') + t.equals(pub1, pub2, 'equal secrets') + }) + + t.test(mod + ' compressed', function (t) { + t.plan(2) + var dh1 = createECDH1(mod) + dh1.generateKeys() + var dh2 = createECDH2(mod) + dh2.generateKeys() + var pubk1 = dh1.getPublicKey(null, 'compressed') + var pubk2 = dh2.getPublicKey(null, 'compressed') + t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys') + var pub1 = dh1.computeSecret(pubk2).toString('hex') + var pub2 = dh2.computeSecret(pubk1).toString('hex') + t.equals(pub1, pub2, 'equal secrets') + }) + + t.test(mod + ' set stuff', function (t) { + t.plan(5) + var dh1 = createECDH1(mod) + var dh2 = createECDH2(mod) + dh1.generateKeys() + dh2.generateKeys() + dh1.setPrivateKey(dh2.getPrivateKey()) + dh1.setPublicKey(dh2.getPublicKey()) + var priv1 = dh1.getPrivateKey('hex') + var priv2 = dh2.getPrivateKey('hex') + t.equals(priv1, priv2, 'same private key') + var pubk1 = dh1.getPublicKey() + var pubk2 = dh2.getPublicKey() + t.equals(pubk1.toString('hex'), pubk2.toString('hex'), 'same public keys, uncompressed') + t.equals(dh1.getPublicKey('hex', 'compressed'), dh2.getPublicKey('hex', 'compressed'), 'same public keys compressed') + t.equals(dh1.getPublicKey('hex', 'hybrid'), dh2.getPublicKey('hex', 'hybrid'), 'same public keys hybrid') + var pub1 = dh1.computeSecret(pubk2).toString('hex') + var pub2 = dh2.computeSecret(pubk1).toString('hex') + t.equals(pub1, pub2, 'equal secrets') + }) + }) +}) diff --git a/test/node/dh.js b/test/node/dh.js index 139a923..0b3aa71 100644 --- a/test/node/dh.js +++ b/test/node/dh.js @@ -1,51 +1,51 @@ -var test = require('tape'); -var cryptoB = require('../../'); +var test = require('tape') +var cryptoB = require('../../') var crypto = require('crypto') test('diffie-hellman mod groups', function (t) { [ - 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16' + 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16' ].forEach(function (mod) { - t.test(mod, function (t){ - t.plan(3); - var dh1 = cryptoB.getDiffieHellman(mod); - var p1 = dh1.getPrime().toString('hex'); - dh1.generateKeys(); + t.test(mod, function (t) { + t.plan(3) + var dh1 = cryptoB.getDiffieHellman(mod) + var p1 = dh1.getPrime().toString('hex') + dh1.generateKeys() - var dh2 = crypto.getDiffieHellman(mod); - var p2 = dh2.getPrime().toString('hex'); - dh2.generateKeys(); - t.equals(p1, p2, 'equal primes'); - var pubk1 = dh1.getPublicKey(); - var pubk2 = dh2.getPublicKey(); - t.notEquals(pubk1, pubk2, 'diff public keys'); - var pub1 = dh1.computeSecret(pubk2).toString('hex'); - var pub2 = dh2.computeSecret(pubk1).toString('hex'); - t.equals(pub1, pub2, 'equal secrets'); - }); - }); -}); + var dh2 = crypto.getDiffieHellman(mod) + var p2 = dh2.getPrime().toString('hex') + dh2.generateKeys() + t.equals(p1, p2, 'equal primes') + var pubk1 = dh1.getPublicKey() + var pubk2 = dh2.getPublicKey() + t.notEquals(pubk1, pubk2, 'diff public keys') + var pub1 = dh1.computeSecret(pubk2).toString('hex') + var pub2 = dh2.computeSecret(pubk1).toString('hex') + t.equals(pub1, pub2, 'equal secrets') + }) + }) +}) test('diffie-hellman key lengths', function (t) { [ - 64, 65, 192 + 64, 65, 192 ].forEach(function (len) { - t.test('' + len, function (t){ - t.plan(3); - var dh2 = cryptoB.createDiffieHellman(len); - var prime2 = dh2.getPrime(); - var p2 = prime2.toString('hex'); - var dh1 = crypto.createDiffieHellman(prime2); - var p1 = dh1.getPrime().toString('hex'); - dh1.generateKeys(); - dh2.generateKeys(); - t.equals(p1, p2, 'equal primes'); - var pubk1 = dh1.getPublicKey(); - var pubk2 = dh2.getPublicKey(); - t.notEquals(pubk1, pubk2, 'diff public keys'); - var pub1 = dh1.computeSecret(pubk2).toString('hex'); - var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex'); - t.equals(pub1, pub2, 'equal secrets'); - }); - }); -}); + t.test('' + len, function (t) { + t.plan(3) + var dh2 = cryptoB.createDiffieHellman(len) + var prime2 = dh2.getPrime() + var p2 = prime2.toString('hex') + var dh1 = crypto.createDiffieHellman(prime2) + var p1 = dh1.getPrime().toString('hex') + dh1.generateKeys() + dh2.generateKeys() + t.equals(p1, p2, 'equal primes') + var pubk1 = dh1.getPublicKey() + var pubk2 = dh2.getPublicKey() + t.notEquals(pubk1, pubk2, 'diff public keys') + var pub1 = dh1.computeSecret(pubk2).toString('hex') + var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex') + t.equals(pub1, pub2, 'equal secrets') + }) + }) +}) diff --git a/test/pbkdf2.js b/test/pbkdf2.js index c86dc87..084014e 100644 --- a/test/pbkdf2.js +++ b/test/pbkdf2.js @@ -1,4 +1,3 @@ - var tape = require('tape') var crypto = require('pbkdf2/browser') @@ -6,17 +5,16 @@ var vectors = require('hash-test-vectors/pbkdf2') tape('pbkdf2', function (t) { vectors.forEach(function (input) { - //skip inputs that will take way too long - if(input.iterations > 10000) return + // skip inputs that will take way too long + if (input.iterations > 10000) return var key = crypto.pbkdf2Sync(input.password, input.salt, input.iterations, input.length) - if(key.toString('hex') !== input.sha1) + if (key.toString('hex') !== input.sha1) { console.log(input) + } t.equal(key.toString('hex'), input.sha1) - - }) t.end() diff --git a/test/public-encrypt.js b/test/public-encrypt.js index 927c0f5..5ebb3cd 100644 --- a/test/public-encrypt.js +++ b/test/public-encrypt.js @@ -1,37 +1,39 @@ -var test = require('tape'); -var crypto1 = require('../'); +var test = require('tape') +var crypto1 = require('../') var rsa = { - "private": "2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a", - "public": "2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a" -}; -var crypto2 = require('public-encrypt/browser'); -rsa.private = new Buffer(rsa.private, 'hex'); -rsa.public = new Buffer(rsa.public, 'hex'); -var encrypted = '0bcd6462ad7a563be2d42b0b73e0b0a163886304e7723b025f97605144fe1781e84acdc4031327d6bccd67fe13183e8fbdc8c5fe947b49d011ce3ebb08b11e83b87a77328ca57ee77cfdc78743b0749366643d7a21b2abcd4aa32dee9832938445540ee3007b7a70191c8dc9ff2ad76fe8dfaa5362d9d2c4b31a67b816d7b7970a293cb95bf3437a301bedb9f431b7075aa2f9df77b4385bea2a37982beda467260b384a58258b5eb4e36a0e0bf7dff83589636f5f97bf542084f0f76868c9f3f989a27fee5b8cd2bfee0bae1eae958df7c3184e5a40fda101196214f371606feca4330b221f30577804bbd4f61578a84e85dcd298849f509e630d275280'; + 'private': '2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a', + 'public': '2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a' +} +var crypto2 = require('public-encrypt/browser') +rsa.private = new Buffer(rsa.private, 'hex') +rsa.public = new Buffer(rsa.public, 'hex') +var encrypted = '0bcd6462ad7a563be2d42b0b73e0b0a163886304e7723b025f97605144fe1781e84acdc4031327d6bccd67fe13183e8fbdc8c5fe947b49d011ce3ebb08b11e83b87a77328ca57ee77cfdc78743b0749366643d7a21b2abcd4aa32dee9832938445540ee3007b7a70191c8dc9ff2ad76fe8dfaa5362d9d2c4b31a67b816d7b7970a293cb95bf3437a301bedb9f431b7075aa2f9df77b4385bea2a37982beda467260b384a58258b5eb4e36a0e0bf7dff83589636f5f97bf542084f0f76868c9f3f989a27fee5b8cd2bfee0bae1eae958df7c3184e5a40fda101196214f371606feca4330b221f30577804bbd4f61578a84e85dcd298849f509e630d275280' + test('publicEncrypt/privateDecrypt', function (t) { t.test('can decrypt', function (t) { - t.plan(2); + t.plan(2) // note encryption is ranomized so can't test to see if they encrypt the same - t.equals(crypto1.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly'); - t.equals(crypto2.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly'); + t.equals(crypto1.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly') + t.equals(crypto2.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly') - }); + }) t.test('can round trip', function (t) { - t.plan(2); - var msg = 'this is a message'; + t.plan(2) + var msg = 'this is a message' // note encryption is ranomized so can't test to see if they encrypt the same - t.equals(crypto1.privateDecrypt(rsa.private, crypto2.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it'); - t.equals(crypto2.privateDecrypt(rsa.private, crypto1.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it'); + t.equals(crypto1.privateDecrypt(rsa.private, crypto2.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it') + t.equals(crypto2.privateDecrypt(rsa.private, crypto1.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it') + + }) +}) - }); -}); test('privateEncrypt/publicDecrypt', function (t) { t.test('can round trip', function (t) { - t.plan(2); - var msg = 'this is a message'; + t.plan(2) + var msg = 'this is a message' // note encryption is ranomized so can't test to see if they encrypt the same - t.equals(crypto1.publicDecrypt(rsa.public, crypto2.privateEncrypt(rsa.private, new Buffer(msg))).toString(), msg, 'round trip it'); - t.equals(crypto2.publicDecrypt(rsa.public, crypto1.privateEncrypt(rsa.private, new Buffer(msg))).toString(), msg, 'round trip it'); + t.equals(crypto1.publicDecrypt(rsa.public, crypto2.privateEncrypt(rsa.private, new Buffer(msg))).toString(), msg, 'round trip it') + t.equals(crypto2.publicDecrypt(rsa.public, crypto1.privateEncrypt(rsa.private, new Buffer(msg))).toString(), msg, 'round trip it') - }); -}); \ No newline at end of file + }) +}) diff --git a/test/random-bytes.js b/test/random-bytes.js index 0ee2f93..0036265 100644 --- a/test/random-bytes.js +++ b/test/random-bytes.js @@ -1,15 +1,16 @@ var test = require('tape') var crypto = require('../') -var randomBytes = require('randombytes') + var randomBytesFunctions = { - randomBytes: randomBytes, + randomBytes: require('randombytes'), pseudoRandomBytes: crypto.pseudoRandomBytes } + for (var randomBytesName in randomBytesFunctions) { // Both randomBytes and pseudoRandomBytes should provide the same interface - var randomBytes = randomBytesFunctions[randomBytesName]; + var randomBytes = randomBytesFunctions[randomBytesName] + test('get error message', function (t) { - try { var b = randomBytes(10) t.ok(Buffer.isBuffer(b)) @@ -18,45 +19,44 @@ for (var randomBytesName in randomBytesFunctions) { t.ok(/not supported/.test(err.message), '"not supported" is in error message') t.end() } - + }) - + test(randomBytesName, function (t) { - t.plan(5); - t.equal(randomBytes(10).length, 10); - t.ok(Buffer.isBuffer(randomBytes(10))) - randomBytes(10, function(ex, bytes) { - t.error(ex); - t.equal(bytes.length, 10); - t.ok(Buffer.isBuffer(bytes)) - t.end(); - }); - }); - + t.plan(5) + t.equal(randomBytes(10).length, 10) + t.ok(Buffer.isBuffer(randomBytes(10))) + randomBytes(10, function (ex, bytes) { + t.error(ex) + t.equal(bytes.length, 10) + t.ok(Buffer.isBuffer(bytes)) + t.end() + }) + }) + test(randomBytesName + ' seem random', function (t) { - var L = 1000 var b = randomBytes(L) - + var mean = [].reduce.call(b, function (a, b) { return a + b}, 0) / L - + // test that the random numbers are plausably random. // Math.random() will pass this, but this will catch // terrible mistakes such as this blunder: // https://github.com/dominictarr/crypto-browserify/commit/3267955e1df7edd1680e52aeede9a89506ed2464#commitcomment-7916835 - + // this doesn't check that the bytes are in a random *order* // but it's better than nothing. - - var expected = 256/2 + + var expected = 256 / 2 var smean = Math.sqrt(mean) - //console.log doesn't work right on testling, *grumble grumble* + + // console.log doesn't work right on testling, *grumble grumble* console.log(JSON.stringify([expected - smean, mean, expected + smean])) t.ok(mean < expected + smean) t.ok(mean > expected - smean) - + t.end() - + }) } - diff --git a/test/sign.js b/test/sign.js index 39b0ef1..7d67685 100644 --- a/test/sign.js +++ b/test/sign.js @@ -1,53 +1,59 @@ -var test = require('tape'); -var nodeCrypto = require('../'); -var ourCrypto = require('browserify-sign/browser'); +var test = require('tape') +var nodeCrypto = require('../') +var ourCrypto = require('browserify-sign/browser') var rsa = { - "private": "2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a", - "public": "2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a" -}; + 'private': '2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a', + 'public': '2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a' +} + var ec = { - "private": "2d2d2d2d2d424547494e2045432050524956415445204b45592d2d2d2d2d0a4d485143415145454944463658763853762f2f77475557442b6337383070704772553051645a5743417a78415150515838722f756f416347425375424241414b0a6f55514451674145495a656f7744796c6c73344b2f7766426a4f313862596f37674778386e595152696a6134652f71454d696b4f484a616937676565557265550a7235586b792f4178377332644774656773504e7350674765354d705176673d3d0a2d2d2d2d2d454e442045432050524956415445204b45592d2d2d2d2d0a", - "public": "2d2d2d2d2d424547494e205055424c4943204b45592d2d2d2d2d0a4d465977454159484b6f5a497a6a3043415159464b34454541416f4451674145495a656f7744796c6c73344b2f7766426a4f313862596f37674778386e5951520a696a6134652f71454d696b4f484a616937676565557265557235586b792f4178377332644774656773504e7350674765354d705176673d3d0a2d2d2d2d2d454e44205055424c4943204b45592d2d2d2d2d0a" -}; - -rsa.private = new Buffer(rsa.private, 'hex'); -rsa.public = new Buffer(rsa.public, 'hex'); -ec.private = new Buffer(ec.private, 'hex'); -ec.public = new Buffer(ec.public, 'hex'); -function testit(keys, message, scheme) { - var pub = keys.public; - var priv = keys.private; - test(message.toString(), function (t) { + 'private': '2d2d2d2d2d424547494e2045432050524956415445204b45592d2d2d2d2d0a4d485143415145454944463658763853762f2f77475557442b6337383070704772553051645a5743417a78415150515838722f756f416347425375424241414b0a6f55514451674145495a656f7744796c6c73344b2f7766426a4f313862596f37674778386e595152696a6134652f71454d696b4f484a616937676565557265550a7235586b792f4178377332644774656773504e7350674765354d705176673d3d0a2d2d2d2d2d454e442045432050524956415445204b45592d2d2d2d2d0a', + 'public': '2d2d2d2d2d424547494e205055424c4943204b45592d2d2d2d2d0a4d465977454159484b6f5a497a6a3043415159464b34454541416f4451674145495a656f7744796c6c73344b2f7766426a4f313862596f37674778386e5951520a696a6134652f71454d696b4f484a616937676565557265557235586b792f4178377332644774656773504e7350674765354d705176673d3d0a2d2d2d2d2d454e44205055424c4943204b45592d2d2d2d2d0a' +} + +rsa.private = new Buffer(rsa.private, 'hex') +rsa.public = new Buffer(rsa.public, 'hex') +ec.private = new Buffer(ec.private, 'hex') +ec.public = new Buffer(ec.public, 'hex') + +function testit (keys, message, scheme) { + var pub = keys.public + var priv = keys.private + test(message.toString(), function (t) { t.test('js sign and verify', function (t) { - t.plan(t); - var mySign = ourCrypto.createSign(scheme); - var mySig = mySign.update(message).sign(priv); - var myVer = ourCrypto.createVerify(scheme); - t.ok(myVer.update(message).verify(pub, mySig), 'validates'); - }); + t.plan(t) + var mySign = ourCrypto.createSign(scheme) + var mySig = mySign.update(message).sign(priv) + var myVer = ourCrypto.createVerify(scheme) + t.ok(myVer.update(message).verify(pub, mySig), 'validates') + }) + t.test('node sign and verify', function (t) { - t.plan(t); - var mySign = nodeCrypto.createSign(scheme); - var mySig = mySign.update(message).sign(priv); - var myVer = nodeCrypto.createVerify(scheme); - t.ok(myVer.update(message).verify(pub, mySig), 'validates'); - }); + t.plan(t) + var mySign = nodeCrypto.createSign(scheme) + var mySig = mySign.update(message).sign(priv) + var myVer = nodeCrypto.createVerify(scheme) + t.ok(myVer.update(message).verify(pub, mySig), 'validates') + }) + t.test('node sign and js verify', function (t) { - t.plan(t); - var mySign = nodeCrypto.createSign(scheme); - var mySig = mySign.update(message).sign(priv); - var myVer = ourCrypto.createVerify(scheme); - t.ok(myVer.update(message).verify(pub, mySig), 'validates'); - }); + t.plan(t) + var mySign = nodeCrypto.createSign(scheme) + var mySig = mySign.update(message).sign(priv) + var myVer = ourCrypto.createVerify(scheme) + t.ok(myVer.update(message).verify(pub, mySig), 'validates') + }) + t.test('js sign and node verify', function (t) { - t.plan(t); - var mySign = ourCrypto.createSign(scheme); - var mySig = mySign.update(message).sign(priv); - var myVer = nodeCrypto.createVerify(scheme); - t.ok(myVer.update(message).verify(pub, mySig), 'validates'); - }); - }); + t.plan(t) + var mySign = ourCrypto.createSign(scheme) + var mySig = mySign.update(message).sign(priv) + var myVer = nodeCrypto.createVerify(scheme) + t.ok(myVer.update(message).verify(pub, mySig), 'validates') + }) + }) } -testit(rsa, new Buffer('rsa with sha256'), 'RSA-SHA256'); -testit(ec, new Buffer('ec with sha1'), 'ecdsa-with-SHA1'); + +testit(rsa, new Buffer('rsa with sha256'), 'RSA-SHA256') +testit(ec, new Buffer('ec with sha1'), 'ecdsa-with-SHA1') From d2704b21da0c5971ce95329510ffcc5b5c536e46 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 13 Aug 2015 15:13:03 +1000 Subject: [PATCH 146/217] add standard badge --- readme.markdown => README.md | 1 + 1 file changed, 1 insertion(+) rename readme.markdown => README.md (92%) diff --git a/readme.markdown b/README.md similarity index 92% rename from readme.markdown rename to README.md index 336447c..05044e1 100644 --- a/readme.markdown +++ b/README.md @@ -3,6 +3,7 @@ A port of node's `crypto` module to the browser. [![travis](https://img.shields.io/travis/crypto-browserify/crypto-browserify/master.svg?style=flat)](https://travis-ci.org/crypto-browserify/crypto-browserify) +[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard) The goal of this module is to reimplement node's crypto module, in pure javascript so that it can run in the browser. From 24732d41162bec0b0da7f5c58bf02a81073dab94 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 27 Sep 2015 14:45:46 -0400 Subject: [PATCH 147/217] add des --- index.js | 2 +- package.json | 2 +- test/aes.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 3bc3e0c..ea632aa 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ var p = require('pbkdf2') exports.pbkdf2 = p.pbkdf2 exports.pbkdf2Sync = p.pbkdf2Sync -var aes = require('browserify-aes') +var aes = require('browserify-cipher') ;[ 'Cipher', 'createCipher', diff --git a/package.json b/package.json index 7a1acd8..87f9a13 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "node": "*" }, "dependencies": { - "browserify-aes": "^1.0.0", + "browserify-cipher": "^1.0.0", "browserify-sign": "^3.0.1", "create-ecdh": "^2.0.0", "create-hash": "^1.1.0", diff --git a/test/aes.js b/test/aes.js index 2cbc366..1c329da 100644 --- a/test/aes.js +++ b/test/aes.js @@ -1,5 +1,5 @@ var test = require('tape') -var crypto = require('browserify-aes/browser') +var crypto = require('browserify-cipher/browser') var randomBytes = require('randombytes') test('ciphers', function (t) { From 7b5a759eaf6afc999c00534645887326a22f91ed Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 27 Sep 2015 14:48:23 -0400 Subject: [PATCH 148/217] standard formating --- test/create-hash.js | 1 - test/create-hmac.js | 1 - test/public-encrypt.js | 3 --- test/random-bytes.js | 4 +--- 4 files changed, 1 insertion(+), 8 deletions(-) diff --git a/test/create-hash.js b/test/create-hash.js index 02c9106..fa85dea 100644 --- a/test/create-hash.js +++ b/test/create-hash.js @@ -37,6 +37,5 @@ function testLib (name, createHash) { t.end() }) }) - }) } diff --git a/test/create-hmac.js b/test/create-hmac.js index 1c7ec2f..faa92f6 100644 --- a/test/create-hmac.js +++ b/test/create-hmac.js @@ -31,7 +31,6 @@ function testLib (name, createHmac) { }) t.end() }) - }) }) } diff --git a/test/public-encrypt.js b/test/public-encrypt.js index 5ebb3cd..edb435c 100644 --- a/test/public-encrypt.js +++ b/test/public-encrypt.js @@ -15,7 +15,6 @@ test('publicEncrypt/privateDecrypt', function (t) { // note encryption is ranomized so can't test to see if they encrypt the same t.equals(crypto1.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly') t.equals(crypto2.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly') - }) t.test('can round trip', function (t) { t.plan(2) @@ -23,7 +22,6 @@ test('publicEncrypt/privateDecrypt', function (t) { // note encryption is ranomized so can't test to see if they encrypt the same t.equals(crypto1.privateDecrypt(rsa.private, crypto2.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it') t.equals(crypto2.privateDecrypt(rsa.private, crypto1.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it') - }) }) @@ -34,6 +32,5 @@ test('privateEncrypt/publicDecrypt', function (t) { // note encryption is ranomized so can't test to see if they encrypt the same t.equals(crypto1.publicDecrypt(rsa.public, crypto2.privateEncrypt(rsa.private, new Buffer(msg))).toString(), msg, 'round trip it') t.equals(crypto2.publicDecrypt(rsa.public, crypto1.privateEncrypt(rsa.private, new Buffer(msg))).toString(), msg, 'round trip it') - }) }) diff --git a/test/random-bytes.js b/test/random-bytes.js index 0036265..398af24 100644 --- a/test/random-bytes.js +++ b/test/random-bytes.js @@ -19,7 +19,6 @@ for (var randomBytesName in randomBytesFunctions) { t.ok(/not supported/.test(err.message), '"not supported" is in error message') t.end() } - }) test(randomBytesName, function (t) { @@ -38,7 +37,7 @@ for (var randomBytesName in randomBytesFunctions) { var L = 1000 var b = randomBytes(L) - var mean = [].reduce.call(b, function (a, b) { return a + b}, 0) / L + var mean = [].reduce.call(b, function (a, b) { return a + b }, 0) / L // test that the random numbers are plausably random. // Math.random() will pass this, but this will catch @@ -57,6 +56,5 @@ for (var randomBytesName in randomBytesFunctions) { t.ok(mean > expected - smean) t.end() - }) } From 0d36370d453d663552f5d4a522aec3c27cc0557f Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Mon, 28 Sep 2015 09:30:24 +1000 Subject: [PATCH 149/217] 3.10.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 87f9a13..3450407 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.9.14", + "version": "3.10.0", "homepage": "https://github.com/crypto-browserify/crypto-browserify", "repository": { "type": "git", From 87de1deffe13b44d4e12e178a9318d7e501f8637 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sat, 3 Oct 2015 15:06:26 -0400 Subject: [PATCH 150/217] add zuul and browser tests --- .travis.yml | 37 ++++++++++++++++++++++++++++++++++--- .zuul.yml | 1 + package.json | 6 ++++-- test/index.js | 11 +++++++++++ 4 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 .zuul.yml create mode 100644 test/index.js diff --git a/.travis.yml b/.travis.yml index 1f1ec66..ccb9a2d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,38 @@ node_js: - "0.11" - "0.12" - "iojs" -env: - - TEST_SUITE=standard - - TEST_SUITE=unit +matrix: + include: + - node_js: '0.10' + env: TEST_SUITE=unit + - node_js: '0.11' + env: TEST_SUITE=unit + - node_js: '0.12' + env: TEST_SUITE=unit + - node_js: 'iojs' + env: TEST_SUITE=unit + - node_js: 'iojs' + env: TEST_SUITE=standard + - node_js: 'iojs' + env: TEST_SUITE=browser + - node_js: 'iojs' + env: TEST_SUITE=browser BROWSER_NAME=opera BROWSER_VERSION="11..latest" + - node_js: 'iojs' + env: TEST_SUITE=browser BROWSER_NAME=ie BROWSER_VERSION="9..latest" + - node_js: 'iojs' + env: TEST_SUITE=browser BROWSER_NAME=chrome BROWSER_VERSION="41..beta" + - node_js: 'iojs' + env: TEST_SUITE=browser BROWSER_NAME=firefox BROWSER_VERSION="36..latest" + - node_js: 'iojs' + env: TEST_SUITE=browser BROWSER_NAME=ipad BROWSER_VERSION="8.2" + - node_js: 'iojs' + env: TEST_SUITE=browser BROWSER_NAME=iphone BROWSER_VERSION="8.2" + - node_js: 'iojs' + env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="5..latest" + - node_js: 'iojs' + env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="4.0..latest" script: "npm run-script $TEST_SUITE" +env: + global: + - secure: YHNUDQmx/WiW3gmDcRCfb6KLDeio7Mr5tqPY2kHPdZlBSytsQjNk75ytM4U6Cu8Uk8iEIoj/aFlxiVMpJNA8J4QSUyW/YkbVaIz0+1oywoV0Ht8aRBfZ1jvXfX6789+1Q9c4xaMkYYbJpXSh9JcirsiwmqWd4+IDd7hcESodsDQ= + - secure: Nhj5yejKZxUbtHGZta+GjYWqXGaOZB7ainTkOuGcpXM+OwwjeDpYlTBrwS90Q7hqens7KXVzQM09aDbadpsDCsOo1nyaEigMtomAorZ1UC1CpEoVz1ZuikF9bEhb+/7M9pzuL1fX+Ke9Dx4mPPeb8sf/2SrAu1RqXkSwZV/duAc= diff --git a/.zuul.yml b/.zuul.yml new file mode 100644 index 0000000..96d9cfb --- /dev/null +++ b/.zuul.yml @@ -0,0 +1 @@ +ui: tape diff --git a/package.json b/package.json index 3450407..e864595 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "prepublish": "npm ls && npm test", "standard": "standard", "test": "npm run standard && npm run unit", - "unit": "set -e; for t in test/node/*.js test/*.js; do node $t; done" + "unit": "node test/", + "browser": "zuul --browser-version $BROWSER_VERSION --browser-name $BROWSER_NAME -- test/index.js" }, "engines": { "node": "*" @@ -32,7 +33,8 @@ "devDependencies": { "hash-test-vectors": "~1.3.2", "standard": "^5.0.2", - "tape": "~2.3.2" + "tape": "~2.3.2", + "zuul": "^3.6.0" }, "optionalDependencies": {}, "browser": { diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..5491283 --- /dev/null +++ b/test/index.js @@ -0,0 +1,11 @@ +require('./aes') +require('./create-hash') +require('./create-hmac') +if (!process.browser) { + require('./dh') +} +require('./ecdh') +require('./pbkdf2') +require('./public-encrypt') +require('./random-bytes') +require('./sign') From 934a256a04972820df5a1a762cda463ab24d2ac7 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sat, 3 Oct 2015 15:06:36 -0400 Subject: [PATCH 151/217] break up tests a little more --- test/aes.js | 32 ++++++++------- test/create-hash.js | 44 ++++++++++----------- test/create-hmac.js | 36 ++++++++--------- test/ecdh.js | 94 ++++++++++++++++++++++----------------------- 4 files changed, 99 insertions(+), 107 deletions(-) diff --git a/test/aes.js b/test/aes.js index 1c329da..d227870 100644 --- a/test/aes.js +++ b/test/aes.js @@ -2,23 +2,21 @@ var test = require('tape') var crypto = require('browserify-cipher/browser') var randomBytes = require('randombytes') -test('ciphers', function (t) { - crypto.listCiphers().forEach(function (cipher) { - t.test(cipher, function (t) { - t.plan(1) - var data = randomBytes(562) - var password = randomBytes(20) - var crypter = crypto.createCipher(cipher, password) - var decrypter = crypto.createDecipher(cipher, password) - var out = [] - out.push(decrypter.update(crypter.update(data))) - out.push(decrypter.update(crypter.final())) - if (cipher.indexOf('gcm') > -1) { - decrypter.setAuthTag(crypter.getAuthTag()) - } - out.push(decrypter.final()) - t.equals(data.toString('hex'), Buffer.concat(out).toString('hex')) - }) +crypto.listCiphers().forEach(function (cipher) { + test('ciphers: ' + cipher, function (t) { + t.plan(1) + var data = randomBytes(562) + var password = randomBytes(20) + var crypter = crypto.createCipher(cipher, password) + var decrypter = crypto.createDecipher(cipher, password) + var out = [] + out.push(decrypter.update(crypter.update(data))) + out.push(decrypter.update(crypter.final())) + if (cipher.indexOf('gcm') > -1) { + decrypter.setAuthTag(crypter.getAuthTag()) + } + out.push(decrypter.final()) + t.equals(data.toString('hex'), Buffer.concat(out).toString('hex')) }) }) diff --git a/test/create-hash.js b/test/create-hash.js index fa85dea..f5fa014 100644 --- a/test/create-hash.js +++ b/test/create-hash.js @@ -8,34 +8,32 @@ testLib('createHash in crypto-browserify', require('../').createHash) testLib('create-hash/browser', require('create-hash/browser')) function testLib (name, createHash) { - test(name, function (t) { - algorithms.forEach(function (algorithm) { - t.test('test ' + algorithm + ' against test vectors', function (t) { - vectors.forEach(function (obj, i) { - var input = new Buffer(obj.input, 'base64') - var node = obj[algorithm] - var js = createHash(algorithm).update(input).digest('hex') - t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node) - }) + algorithms.forEach(function (algorithm) { + test(name + ' test ' + algorithm + ' against test vectors', function (t) { + vectors.forEach(function (obj, i) { + var input = new Buffer(obj.input, 'base64') + var node = obj[algorithm] + var js = createHash(algorithm).update(input).digest('hex') + t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node) + }) - encodings.forEach(function (encoding) { - vectors.forEach(function (obj, i) { - var input = new Buffer(obj.input, 'base64').toString(encoding) - var node = obj[algorithm] - var js = createHash(algorithm).update(input, encoding).digest('hex') - t.equal(js, node, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + node) - }) - }) + encodings.forEach(function (encoding) { vectors.forEach(function (obj, i) { - var input = new Buffer(obj.input, 'base64') + var input = new Buffer(obj.input, 'base64').toString(encoding) var node = obj[algorithm] - var hash = createHash(algorithm) - hash.end(input) - var js = hash.read().toString('hex') - t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node) + var js = createHash(algorithm).update(input, encoding).digest('hex') + t.equal(js, node, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + node) }) - t.end() }) + vectors.forEach(function (obj, i) { + var input = new Buffer(obj.input, 'base64') + var node = obj[algorithm] + var hash = createHash(algorithm) + hash.end(input) + var js = hash.read().toString('hex') + t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node) + }) + t.end() }) }) } diff --git a/test/create-hmac.js b/test/create-hmac.js index faa92f6..5b653bb 100644 --- a/test/create-hmac.js +++ b/test/create-hmac.js @@ -6,31 +6,29 @@ testLib('createHmac in crypto-browserify', require('../').createHmac) testLib('create-hmac/browser', require('create-hmac/browser')) function testLib (name, createHmac) { - test(name, function (t) { - algorithms.forEach(function (alg) { - t.test('hmac(' + alg + ')', function (t) { - vectors.forEach(function (input, i) { - var output = createHmac(alg, new Buffer(input.key, 'hex')) - .update(input.data, 'hex').digest() + algorithms.forEach(function (alg) { + test(name + ' hmac(' + alg + ')', function (t) { + vectors.forEach(function (input, i) { + var output = createHmac(alg, new Buffer(input.key, 'hex')) + .update(input.data, 'hex').digest() - output = input.truncate ? output.slice(0, input.truncate) : output - t.equal(output.toString('hex'), input[alg]) - }) - t.end() + output = input.truncate ? output.slice(0, input.truncate) : output + t.equal(output.toString('hex'), input[alg]) }) + t.end() + }) - t.test('hmac(' + alg + ')', function (t) { - vectors.forEach(function (input, i) { - var hmac = createHmac(alg, new Buffer(input.key, 'hex')) + test('hmac(' + alg + ')', function (t) { + vectors.forEach(function (input, i) { + var hmac = createHmac(alg, new Buffer(input.key, 'hex')) - hmac.end(input.data, 'hex') - var output = hmac.read() + hmac.end(input.data, 'hex') + var output = hmac.read() - output = input.truncate ? output.slice(0, input.truncate) : output - t.equal(output.toString('hex'), input[alg]) - }) - t.end() + output = input.truncate ? output.slice(0, input.truncate) : output + t.equal(output.toString('hex'), input[alg]) }) + t.end() }) }) } diff --git a/test/ecdh.js b/test/ecdh.js index ad37c56..368000a 100644 --- a/test/ecdh.js +++ b/test/ecdh.js @@ -8,55 +8,53 @@ var test = require('tape') var createECDH1 = require('../').createECDH var createECDH2 = require('create-ecdh/browser') -test('createECDH', function (t) { - mods.forEach(function (mod) { - t.test(mod + ' uncompressed', function (t) { - t.plan(2) - var dh1 = createECDH1(mod) - dh1.generateKeys() - var dh2 = createECDH2(mod) - dh2.generateKeys() - var pubk1 = dh1.getPublicKey() - var pubk2 = dh2.getPublicKey() - t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys') - var pub1 = dh1.computeSecret(pubk2).toString('hex') - var pub2 = dh2.computeSecret(pubk1).toString('hex') - t.equals(pub1, pub2, 'equal secrets') - }) +mods.forEach(function (mod) { + test('createECDH: ' + mod + ' uncompressed', function (t) { + t.plan(2) + var dh1 = createECDH1(mod) + dh1.generateKeys() + var dh2 = createECDH2(mod) + dh2.generateKeys() + var pubk1 = dh1.getPublicKey() + var pubk2 = dh2.getPublicKey() + t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys') + var pub1 = dh1.computeSecret(pubk2).toString('hex') + var pub2 = dh2.computeSecret(pubk1).toString('hex') + t.equals(pub1, pub2, 'equal secrets') + }) - t.test(mod + ' compressed', function (t) { - t.plan(2) - var dh1 = createECDH1(mod) - dh1.generateKeys() - var dh2 = createECDH2(mod) - dh2.generateKeys() - var pubk1 = dh1.getPublicKey(null, 'compressed') - var pubk2 = dh2.getPublicKey(null, 'compressed') - t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys') - var pub1 = dh1.computeSecret(pubk2).toString('hex') - var pub2 = dh2.computeSecret(pubk1).toString('hex') - t.equals(pub1, pub2, 'equal secrets') - }) + test('createECDH: ' + mod + ' compressed', function (t) { + t.plan(2) + var dh1 = createECDH1(mod) + dh1.generateKeys() + var dh2 = createECDH2(mod) + dh2.generateKeys() + var pubk1 = dh1.getPublicKey(null, 'compressed') + var pubk2 = dh2.getPublicKey(null, 'compressed') + t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys') + var pub1 = dh1.computeSecret(pubk2).toString('hex') + var pub2 = dh2.computeSecret(pubk1).toString('hex') + t.equals(pub1, pub2, 'equal secrets') + }) - t.test(mod + ' set stuff', function (t) { - t.plan(5) - var dh1 = createECDH1(mod) - var dh2 = createECDH2(mod) - dh1.generateKeys() - dh2.generateKeys() - dh1.setPrivateKey(dh2.getPrivateKey()) - dh1.setPublicKey(dh2.getPublicKey()) - var priv1 = dh1.getPrivateKey('hex') - var priv2 = dh2.getPrivateKey('hex') - t.equals(priv1, priv2, 'same private key') - var pubk1 = dh1.getPublicKey() - var pubk2 = dh2.getPublicKey() - t.equals(pubk1.toString('hex'), pubk2.toString('hex'), 'same public keys, uncompressed') - t.equals(dh1.getPublicKey('hex', 'compressed'), dh2.getPublicKey('hex', 'compressed'), 'same public keys compressed') - t.equals(dh1.getPublicKey('hex', 'hybrid'), dh2.getPublicKey('hex', 'hybrid'), 'same public keys hybrid') - var pub1 = dh1.computeSecret(pubk2).toString('hex') - var pub2 = dh2.computeSecret(pubk1).toString('hex') - t.equals(pub1, pub2, 'equal secrets') - }) + test('createECDH: ' + mod + ' set stuff', function (t) { + t.plan(5) + var dh1 = createECDH1(mod) + var dh2 = createECDH2(mod) + dh1.generateKeys() + dh2.generateKeys() + dh1.setPrivateKey(dh2.getPrivateKey()) + dh1.setPublicKey(dh2.getPublicKey()) + var priv1 = dh1.getPrivateKey('hex') + var priv2 = dh2.getPrivateKey('hex') + t.equals(priv1, priv2, 'same private key') + var pubk1 = dh1.getPublicKey() + var pubk2 = dh2.getPublicKey() + t.equals(pubk1.toString('hex'), pubk2.toString('hex'), 'same public keys, uncompressed') + t.equals(dh1.getPublicKey('hex', 'compressed'), dh2.getPublicKey('hex', 'compressed'), 'same public keys compressed') + t.equals(dh1.getPublicKey('hex', 'hybrid'), dh2.getPublicKey('hex', 'hybrid'), 'same public keys hybrid') + var pub1 = dh1.computeSecret(pubk2).toString('hex') + var pub2 = dh2.computeSecret(pubk1).toString('hex') + t.equals(pub1, pub2, 'equal secrets') }) }) From bbe18beee4d98a6a204eb001b09e04c80e600499 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sat, 3 Oct 2015 15:27:25 -0400 Subject: [PATCH 152/217] rm extra tests --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index ccb9a2d..8d425e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,5 @@ sudo: false language: node_js -node_js: - - "0.10" - - "0.11" - - "0.12" - - "iojs" matrix: include: - node_js: '0.10' From 827777eac085b28eed9458dd5573fec7af38f9a8 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sat, 3 Oct 2015 15:32:32 -0400 Subject: [PATCH 153/217] rm extra browser test --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8d425e6..d707b7e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,6 @@ matrix: env: TEST_SUITE=unit - node_js: 'iojs' env: TEST_SUITE=standard - - node_js: 'iojs' - env: TEST_SUITE=browser - node_js: 'iojs' env: TEST_SUITE=browser BROWSER_NAME=opera BROWSER_VERSION="11..latest" - node_js: 'iojs' From 94c6a8b036e9b39e7becb99e77427625cb0d6e5f Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sat, 3 Oct 2015 15:53:53 -0400 Subject: [PATCH 154/217] rm prepublish --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index e864595..2842801 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "url": "git://github.com/crypto-browserify/crypto-browserify.git" }, "scripts": { - "prepublish": "npm ls && npm test", "standard": "standard", "test": "npm run standard && npm run unit", "unit": "node test/", From f2ce23882745075976b71323bbe233a12cfc6457 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 4 Oct 2015 09:07:02 -0400 Subject: [PATCH 155/217] asyncize the hash and hmac tests so they report back more frequently --- test/create-hash.js | 49 +++++++++++++++++++++++++-------------------- test/create-hmac.js | 22 ++++++++++++++------ 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/test/create-hash.js b/test/create-hash.js index f5fa014..9525c21 100644 --- a/test/create-hash.js +++ b/test/create-hash.js @@ -9,31 +9,36 @@ testLib('create-hash/browser', require('create-hash/browser')) function testLib (name, createHash) { algorithms.forEach(function (algorithm) { - test(name + ' test ' + algorithm + ' against test vectors', function (t) { - vectors.forEach(function (obj, i) { - var input = new Buffer(obj.input, 'base64') - var node = obj[algorithm] - var js = createHash(algorithm).update(input).digest('hex') - t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node) - }) + runTest(name, createHash, algorithm) + }) +} +function runTest (name, createHash, algorithm) { + test(name + ' test ' + algorithm + ' against test vectors', function (t) { + run(0) + function run (i) { + if (i >= vectors.length) { + return t.end() + } + var obj = vectors[i] + + var input = new Buffer(obj.input, 'base64') + var node = obj[algorithm] + var js = createHash(algorithm).update(input).digest('hex') + t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node) encodings.forEach(function (encoding) { - vectors.forEach(function (obj, i) { - var input = new Buffer(obj.input, 'base64').toString(encoding) - var node = obj[algorithm] - var js = createHash(algorithm).update(input, encoding).digest('hex') - t.equal(js, node, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + node) - }) - }) - vectors.forEach(function (obj, i) { - var input = new Buffer(obj.input, 'base64') + var input = new Buffer(obj.input, 'base64').toString(encoding) var node = obj[algorithm] - var hash = createHash(algorithm) - hash.end(input) - var js = hash.read().toString('hex') - t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node) + var js = createHash(algorithm).update(input, encoding).digest('hex') + t.equal(js, node, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + node) }) - t.end() - }) + input = new Buffer(obj.input, 'base64') + node = obj[algorithm] + var hash = createHash(algorithm) + hash.end(input) + js = hash.read().toString('hex') + t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node) + setTimeout(run, 0, i + 1) + } }) } diff --git a/test/create-hmac.js b/test/create-hmac.js index 5b653bb..e9f091b 100644 --- a/test/create-hmac.js +++ b/test/create-hmac.js @@ -8,18 +8,28 @@ testLib('create-hmac/browser', require('create-hmac/browser')) function testLib (name, createHmac) { algorithms.forEach(function (alg) { test(name + ' hmac(' + alg + ')', function (t) { - vectors.forEach(function (input, i) { + run(0) + function run (i) { + if (i >= vectors.length) { + return t.end() + } + var input = vectors[i] var output = createHmac(alg, new Buffer(input.key, 'hex')) .update(input.data, 'hex').digest() output = input.truncate ? output.slice(0, input.truncate) : output t.equal(output.toString('hex'), input[alg]) - }) - t.end() + setTimeout(run, 0, i + 1) + } }) test('hmac(' + alg + ')', function (t) { - vectors.forEach(function (input, i) { + run(0) + function run (i) { + if (i >= vectors.length) { + return t.end() + } + var input = vectors[i] var hmac = createHmac(alg, new Buffer(input.key, 'hex')) hmac.end(input.data, 'hex') @@ -27,8 +37,8 @@ function testLib (name, createHmac) { output = input.truncate ? output.slice(0, input.truncate) : output t.equal(output.toString('hex'), input[alg]) - }) - t.end() + setTimeout(run, 0, i + 1) + } }) }) } From 80fa88651ad7dfe115427b237fe6385656ea526e Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 4 Oct 2015 09:41:59 -0400 Subject: [PATCH 156/217] less older browsers --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d707b7e..3801bb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,9 +17,9 @@ matrix: - node_js: 'iojs' env: TEST_SUITE=browser BROWSER_NAME=ie BROWSER_VERSION="9..latest" - node_js: 'iojs' - env: TEST_SUITE=browser BROWSER_NAME=chrome BROWSER_VERSION="41..beta" + env: TEST_SUITE=browser BROWSER_NAME=chrome BROWSER_VERSION="44..beta" - node_js: 'iojs' - env: TEST_SUITE=browser BROWSER_NAME=firefox BROWSER_VERSION="36..latest" + env: TEST_SUITE=browser BROWSER_NAME=firefox BROWSER_VERSION="40..latest" - node_js: 'iojs' env: TEST_SUITE=browser BROWSER_NAME=ipad BROWSER_VERSION="8.2" - node_js: 'iojs' From 70bbebf6857bba05be1ab1d980d7990357238cb6 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 4 Oct 2015 09:47:02 -0400 Subject: [PATCH 157/217] we apparenlty do not support opera --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3801bb0..0e5a8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,6 @@ matrix: env: TEST_SUITE=unit - node_js: 'iojs' env: TEST_SUITE=standard - - node_js: 'iojs' - env: TEST_SUITE=browser BROWSER_NAME=opera BROWSER_VERSION="11..latest" - node_js: 'iojs' env: TEST_SUITE=browser BROWSER_NAME=ie BROWSER_VERSION="9..latest" - node_js: 'iojs' From 6aebafa13e916cc4b1eaeaf44104e0e02ba79ff9 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 4 Oct 2015 09:47:11 -0400 Subject: [PATCH 158/217] reduce test output size --- test/create-hash.js | 12 +++++++++--- test/create-hmac.js | 10 ++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/test/create-hash.js b/test/create-hash.js index 9525c21..33532fd 100644 --- a/test/create-hash.js +++ b/test/create-hash.js @@ -24,20 +24,26 @@ function runTest (name, createHash, algorithm) { var input = new Buffer(obj.input, 'base64') var node = obj[algorithm] var js = createHash(algorithm).update(input).digest('hex') - t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node) + if (js !== node) { + t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node) + } encodings.forEach(function (encoding) { var input = new Buffer(obj.input, 'base64').toString(encoding) var node = obj[algorithm] var js = createHash(algorithm).update(input, encoding).digest('hex') - t.equal(js, node, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + node) + if (js !== node) { + t.equal(js, node, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + node) + } }) input = new Buffer(obj.input, 'base64') node = obj[algorithm] var hash = createHash(algorithm) hash.end(input) js = hash.read().toString('hex') - t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node) + if (js !== node) { + t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node) + } setTimeout(run, 0, i + 1) } }) diff --git a/test/create-hmac.js b/test/create-hmac.js index e9f091b..08488ab 100644 --- a/test/create-hmac.js +++ b/test/create-hmac.js @@ -18,7 +18,10 @@ function testLib (name, createHmac) { .update(input.data, 'hex').digest() output = input.truncate ? output.slice(0, input.truncate) : output - t.equal(output.toString('hex'), input[alg]) + output = output.toString('hex') + if (output !== input[alg]) { + t.equal(output, input[alg]) + } setTimeout(run, 0, i + 1) } }) @@ -36,7 +39,10 @@ function testLib (name, createHmac) { var output = hmac.read() output = input.truncate ? output.slice(0, input.truncate) : output - t.equal(output.toString('hex'), input[alg]) + output = output.toString('hex') + if (output !== input[alg]) { + t.equal(output, input[alg]) + } setTimeout(run, 0, i + 1) } }) From 2a12b8739fa101a3928e4d55b46de850f2c8575d Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 4 Oct 2015 09:57:48 -0400 Subject: [PATCH 159/217] ie 9 does not support cryptographically secure random number generator --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0e5a8b4..1938c74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ matrix: - node_js: 'iojs' env: TEST_SUITE=standard - node_js: 'iojs' - env: TEST_SUITE=browser BROWSER_NAME=ie BROWSER_VERSION="9..latest" + env: TEST_SUITE=browser BROWSER_NAME=ie BROWSER_VERSION="10..latest" - node_js: 'iojs' env: TEST_SUITE=browser BROWSER_NAME=chrome BROWSER_VERSION="44..beta" - node_js: 'iojs' From 2d48880c47ec53fc0c7eaff33d13136114ee241d Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 4 Oct 2015 15:35:26 -0400 Subject: [PATCH 160/217] no ie 10 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1938c74..875754f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ matrix: - node_js: 'iojs' env: TEST_SUITE=standard - node_js: 'iojs' - env: TEST_SUITE=browser BROWSER_NAME=ie BROWSER_VERSION="10..latest" + env: TEST_SUITE=browser BROWSER_NAME=ie BROWSER_VERSION="11..latest" - node_js: 'iojs' env: TEST_SUITE=browser BROWSER_NAME=chrome BROWSER_VERSION="44..beta" - node_js: 'iojs' From 2f5164c949184c68b845f9a65443f48864be5df3 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 4 Oct 2015 15:38:17 -0400 Subject: [PATCH 161/217] use bundled crypto --- test/ecdh.js | 3 +++ test/public-encrypt.js | 3 +++ test/sign.js | 3 +++ 3 files changed, 9 insertions(+) diff --git a/test/ecdh.js b/test/ecdh.js index 368000a..1921e84 100644 --- a/test/ecdh.js +++ b/test/ecdh.js @@ -6,6 +6,9 @@ var mods = [ ] var test = require('tape') var createECDH1 = require('../').createECDH +if (process.browser && typeof createECDH1 !== 'function') { + createECDH1 = require('crypto').createECDH +} var createECDH2 = require('create-ecdh/browser') mods.forEach(function (mod) { diff --git a/test/public-encrypt.js b/test/public-encrypt.js index edb435c..5d7a1a7 100644 --- a/test/public-encrypt.js +++ b/test/public-encrypt.js @@ -1,5 +1,8 @@ var test = require('tape') var crypto1 = require('../') +if (process.browser && typeof crypto1.privateDecrypt !== 'function') { + crypto1 = require('crypto') +} var rsa = { 'private': '2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a', 'public': '2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a' diff --git a/test/sign.js b/test/sign.js index 7d67685..f7ea2ce 100644 --- a/test/sign.js +++ b/test/sign.js @@ -1,5 +1,8 @@ var test = require('tape') var nodeCrypto = require('../') +if (process.browser && typeof nodeCrypto === 'undefined') { + nodeCrypto = require('crypto') +} var ourCrypto = require('browserify-sign/browser') var rsa = { From 184f7c183ef5f51d54c9aef880c74ccffbb9c756 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 4 Oct 2015 15:55:26 -0400 Subject: [PATCH 162/217] include browserify? --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 2842801..935453b 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "randombytes": "^2.0.0" }, "devDependencies": { + "browserify": "^11.2.0", "hash-test-vectors": "~1.3.2", "standard": "^5.0.2", "tape": "~2.3.2", From e433b13beb398fe7346db279cd23d4c3eeb9045f Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 4 Oct 2015 16:22:11 -0400 Subject: [PATCH 163/217] undo conditional imports --- test/ecdh.js | 6 ++---- test/public-encrypt.js | 3 --- test/sign.js | 3 --- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/test/ecdh.js b/test/ecdh.js index 1921e84..86b5aed 100644 --- a/test/ecdh.js +++ b/test/ecdh.js @@ -5,10 +5,8 @@ var mods = [ 'prime192v1' ] var test = require('tape') -var createECDH1 = require('../').createECDH -if (process.browser && typeof createECDH1 !== 'function') { - createECDH1 = require('crypto').createECDH -} +var _crypto = require('../') +var createECDH1 = _crypto.createECDH var createECDH2 = require('create-ecdh/browser') mods.forEach(function (mod) { diff --git a/test/public-encrypt.js b/test/public-encrypt.js index 5d7a1a7..edb435c 100644 --- a/test/public-encrypt.js +++ b/test/public-encrypt.js @@ -1,8 +1,5 @@ var test = require('tape') var crypto1 = require('../') -if (process.browser && typeof crypto1.privateDecrypt !== 'function') { - crypto1 = require('crypto') -} var rsa = { 'private': '2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a', 'public': '2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a' diff --git a/test/sign.js b/test/sign.js index f7ea2ce..7d67685 100644 --- a/test/sign.js +++ b/test/sign.js @@ -1,8 +1,5 @@ var test = require('tape') var nodeCrypto = require('../') -if (process.browser && typeof nodeCrypto === 'undefined') { - nodeCrypto = require('crypto') -} var ourCrypto = require('browserify-sign/browser') var rsa = { From a20441af8cca28ce42c5da07dfa167579da7aafc Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 4 Oct 2015 16:22:24 -0400 Subject: [PATCH 164/217] test against modified create-ecdh --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 935453b..49b029a 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "dependencies": { "browserify-cipher": "^1.0.0", "browserify-sign": "^3.0.1", - "create-ecdh": "^2.0.0", + "create-ecdh": "crypto-browserify/create-ecdh#browser-field", "create-hash": "^1.1.0", "create-hmac": "^1.1.0", "diffie-hellman": "^3.0.1", @@ -30,7 +30,6 @@ "randombytes": "^2.0.0" }, "devDependencies": { - "browserify": "^11.2.0", "hash-test-vectors": "~1.3.2", "standard": "^5.0.2", "tape": "~2.3.2", From 2bfbd63cc5b7ef0d400ce6a5b3a801469349520d Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 4 Oct 2015 16:28:19 -0400 Subject: [PATCH 165/217] correct repo --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 49b029a..b7576c3 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "dependencies": { "browserify-cipher": "^1.0.0", "browserify-sign": "^3.0.1", - "create-ecdh": "crypto-browserify/create-ecdh#browser-field", + "create-ecdh": "crypto-browserify/createECDH#browser-field", "create-hash": "^1.1.0", "create-hmac": "^1.1.0", "diffie-hellman": "^3.0.1", From bd73ac45378abb7f0bd8d2fa3531d3b070f69cdd Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 4 Oct 2015 16:43:42 -0400 Subject: [PATCH 166/217] node 4 --- .travis.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 875754f..2928a6b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,23 +8,23 @@ matrix: env: TEST_SUITE=unit - node_js: '0.12' env: TEST_SUITE=unit - - node_js: 'iojs' + - node_js: '4' env: TEST_SUITE=unit - - node_js: 'iojs' + - node_js: '4' env: TEST_SUITE=standard - - node_js: 'iojs' + - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=ie BROWSER_VERSION="11..latest" - - node_js: 'iojs' + - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=chrome BROWSER_VERSION="44..beta" - - node_js: 'iojs' + - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=firefox BROWSER_VERSION="40..latest" - - node_js: 'iojs' + - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=ipad BROWSER_VERSION="8.2" - - node_js: 'iojs' + - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=iphone BROWSER_VERSION="8.2" - - node_js: 'iojs' + - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="5..latest" - - node_js: 'iojs' + - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="4.0..latest" script: "npm run-script $TEST_SUITE" env: From 0da8081f75082ea96ca5efd5670e328e8a5042ea Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Sun, 4 Oct 2015 17:37:59 -0400 Subject: [PATCH 167/217] update ecdh --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b7576c3..f2b086b 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "dependencies": { "browserify-cipher": "^1.0.0", "browserify-sign": "^3.0.1", - "create-ecdh": "crypto-browserify/createECDH#browser-field", + "create-ecdh": "^2.0.2", "create-hash": "^1.1.0", "create-hmac": "^1.1.0", "diffie-hellman": "^3.0.1", From 59dc906efd28c26029fa0a408afb96404fccb332 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 5 Oct 2015 08:01:18 -0400 Subject: [PATCH 168/217] safari 5 does not support random data --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2928a6b..7fbfdc7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,7 @@ matrix: - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=iphone BROWSER_VERSION="8.2" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="5..latest" + env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="6..latest" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="4.0..latest" script: "npm run-script $TEST_SUITE" From 8009185257346c0473edde6b11ceb9da7da83386 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 5 Oct 2015 08:07:10 -0400 Subject: [PATCH 169/217] saucelabs badge --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 05044e1..2827aeb 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ A port of node's `crypto` module to the browser. [![travis](https://img.shields.io/travis/crypto-browserify/crypto-browserify/master.svg?style=flat)](https://travis-ci.org/crypto-browserify/crypto-browserify) [![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard) +[![Sauce Test Status](https://saucelabs.com/browser-matrix/crypto-browserify.svg)](https://saucelabs.com/u/crypto-browserify) The goal of this module is to reimplement node's crypto module, in pure javascript so that it can run in the browser. @@ -46,5 +47,3 @@ and post comments if you do. ## License MIT - - From ded21dd71a0181ba0649b3f6f0d53261c0c5fae5 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 5 Oct 2015 08:10:42 -0400 Subject: [PATCH 170/217] tweak the versions --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7fbfdc7..4e963e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,13 +19,15 @@ matrix: - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=firefox BROWSER_VERSION="40..latest" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=ipad BROWSER_VERSION="8.2" + env: TEST_SUITE=browser BROWSER_NAME=ipad BROWSER_VERSION="6..latest" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=iphone BROWSER_VERSION="8.2" + env: TEST_SUITE=browser BROWSER_NAME=iphone BROWSER_VERSION="6..latest" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="6..latest" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="4.0..latest" + - node_js: '4' + env: TEST_SUITE=browser BROWSER_NAME=microsoftedge BROWSER_VERSION="20..latest" script: "npm run-script $TEST_SUITE" env: global: From 9ec241b313791a13a662142e7d82c7770109b628 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 5 Oct 2015 08:11:56 -0400 Subject: [PATCH 171/217] show badge for master branch --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2827aeb..9b0c03b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A port of node's `crypto` module to the browser. -[![travis](https://img.shields.io/travis/crypto-browserify/crypto-browserify/master.svg?style=flat)](https://travis-ci.org/crypto-browserify/crypto-browserify) +[![Build Status](https://travis-ci.org/crypto-browserify/crypto-browserify.svg?branch=master)](https://travis-ci.org/crypto-browserify/crypto-browserify) [![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard) [![Sauce Test Status](https://saucelabs.com/browser-matrix/crypto-browserify.svg)](https://saucelabs.com/u/crypto-browserify) From a3f75735deaf596c864467a62b1b9339ff867173 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 5 Oct 2015 08:25:30 -0400 Subject: [PATCH 172/217] tweak version --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4e963e0..83b55f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,15 +17,15 @@ matrix: - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=chrome BROWSER_VERSION="44..beta" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=firefox BROWSER_VERSION="40..latest" + env: TEST_SUITE=browser BROWSER_NAME=firefox BROWSER_VERSION="40..beta" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=ipad BROWSER_VERSION="6..latest" + env: TEST_SUITE=browser BROWSER_NAME=ipad BROWSER_VERSION="6.0..latest" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=iphone BROWSER_VERSION="6..latest" + env: TEST_SUITE=browser BROWSER_NAME=iphone BROWSER_VERSION="6.0..latest" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="6..latest" + env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="6.0..latest" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="4.0..latest" + env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="4.4..latest" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=microsoftedge BROWSER_VERSION="20..latest" script: "npm run-script $TEST_SUITE" From 87ef044b4b631533ded823817a659f0ef7d41419 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 5 Oct 2015 08:54:08 -0400 Subject: [PATCH 173/217] tweak versions again --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 83b55f3..7a26221 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,13 +17,13 @@ matrix: - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=chrome BROWSER_VERSION="44..beta" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=firefox BROWSER_VERSION="40..beta" + env: TEST_SUITE=browser BROWSER_NAME=firefox BROWSER_VERSION="40..latest" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=ipad BROWSER_VERSION="6.0..latest" + env: TEST_SUITE=browser BROWSER_NAME=ipad BROWSER_VERSION="8.0..latest" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=iphone BROWSER_VERSION="6.0..latest" + env: TEST_SUITE=browser BROWSER_NAME=iphone BROWSER_VERSION="8.0..latest" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="6.0..latest" + env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="6..latest" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="4.4..latest" - node_js: '4' From 5bc6f8a55d710295c12e9978607319df56976966 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 5 Oct 2015 09:18:33 -0400 Subject: [PATCH 174/217] microsoft edge seems not to work --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7a26221..fb2e279 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,8 +26,6 @@ matrix: env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="6..latest" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="4.4..latest" - - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=microsoftedge BROWSER_VERSION="20..latest" script: "npm run-script $TEST_SUITE" env: global: From ca4936d53feaef01b6e44c75337c7d62eeb786d7 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 5 Oct 2015 10:19:47 -0400 Subject: [PATCH 175/217] bump to retrigger new build --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index fb2e279..11770e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,5 +29,5 @@ matrix: script: "npm run-script $TEST_SUITE" env: global: - - secure: YHNUDQmx/WiW3gmDcRCfb6KLDeio7Mr5tqPY2kHPdZlBSytsQjNk75ytM4U6Cu8Uk8iEIoj/aFlxiVMpJNA8J4QSUyW/YkbVaIz0+1oywoV0Ht8aRBfZ1jvXfX6789+1Q9c4xaMkYYbJpXSh9JcirsiwmqWd4+IDd7hcESodsDQ= - - secure: Nhj5yejKZxUbtHGZta+GjYWqXGaOZB7ainTkOuGcpXM+OwwjeDpYlTBrwS90Q7hqens7KXVzQM09aDbadpsDCsOo1nyaEigMtomAorZ1UC1CpEoVz1ZuikF9bEhb+/7M9pzuL1fX+Ke9Dx4mPPeb8sf/2SrAu1RqXkSwZV/duAc= + - secure: YHNUDQmx/WiW3gmDcRCfb6KLDeio7Mr5tqPY2kHPdZlBSytsQjNk75ytM4U6Cu8Uk8iEIoj/aFlxiVMpJNA8J4QSUyW/YkbVaIz0+1oywoV0Ht8aRBfZ1jvXfX6789+1Q9c4xaMkYYbJpXSh9JcirsiwmqWd4+IDd7hcESodsDQ= + - secure: Nhj5yejKZxUbtHGZta+GjYWqXGaOZB7ainTkOuGcpXM+OwwjeDpYlTBrwS90Q7hqens7KXVzQM09aDbadpsDCsOo1nyaEigMtomAorZ1UC1CpEoVz1ZuikF9bEhb+/7M9pzuL1fX+Ke9Dx4mPPeb8sf/2SrAu1RqXkSwZV/duAc= From cc51573d48e92ed06734d37ee0f5ec5c459249a8 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 5 Oct 2015 10:51:06 -0400 Subject: [PATCH 176/217] Revert "microsoft edge seems not to work" This reverts commit 5bc6f8a55d710295c12e9978607319df56976966. --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 11770e3..107e347 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,8 @@ matrix: env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="6..latest" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="4.4..latest" + - node_js: '4' + env: TEST_SUITE=browser BROWSER_NAME=microsoftedge BROWSER_VERSION="20..latest" script: "npm run-script $TEST_SUITE" env: global: From 04b0a6c468eb74141dda60345278d65af055550d Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 5 Oct 2015 10:51:32 -0400 Subject: [PATCH 177/217] Revert "Revert "microsoft edge seems not to work"" This reverts commit cc51573d48e92ed06734d37ee0f5ec5c459249a8. --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 107e347..11770e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,8 +26,6 @@ matrix: env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="6..latest" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="4.4..latest" - - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=microsoftedge BROWSER_VERSION="20..latest" script: "npm run-script $TEST_SUITE" env: global: From 95bb6dbf39282bfc578e742f475cd798bbcdef44 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 5 Oct 2015 10:51:39 -0400 Subject: [PATCH 178/217] Revert "bump to retrigger new build" This reverts commit ca4936d53feaef01b6e44c75337c7d62eeb786d7. --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 11770e3..fb2e279 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,5 +29,5 @@ matrix: script: "npm run-script $TEST_SUITE" env: global: - - secure: YHNUDQmx/WiW3gmDcRCfb6KLDeio7Mr5tqPY2kHPdZlBSytsQjNk75ytM4U6Cu8Uk8iEIoj/aFlxiVMpJNA8J4QSUyW/YkbVaIz0+1oywoV0Ht8aRBfZ1jvXfX6789+1Q9c4xaMkYYbJpXSh9JcirsiwmqWd4+IDd7hcESodsDQ= - - secure: Nhj5yejKZxUbtHGZta+GjYWqXGaOZB7ainTkOuGcpXM+OwwjeDpYlTBrwS90Q7hqens7KXVzQM09aDbadpsDCsOo1nyaEigMtomAorZ1UC1CpEoVz1ZuikF9bEhb+/7M9pzuL1fX+Ke9Dx4mPPeb8sf/2SrAu1RqXkSwZV/duAc= + - secure: YHNUDQmx/WiW3gmDcRCfb6KLDeio7Mr5tqPY2kHPdZlBSytsQjNk75ytM4U6Cu8Uk8iEIoj/aFlxiVMpJNA8J4QSUyW/YkbVaIz0+1oywoV0Ht8aRBfZ1jvXfX6789+1Q9c4xaMkYYbJpXSh9JcirsiwmqWd4+IDd7hcESodsDQ= + - secure: Nhj5yejKZxUbtHGZta+GjYWqXGaOZB7ainTkOuGcpXM+OwwjeDpYlTBrwS90Q7hqens7KXVzQM09aDbadpsDCsOo1nyaEigMtomAorZ1UC1CpEoVz1ZuikF9bEhb+/7M9pzuL1fX+Ke9Dx4mPPeb8sf/2SrAu1RqXkSwZV/duAc= From 6c6664d57dbf483d2fa218268828a5a3e8e2d194 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 7 Oct 2015 05:32:24 -0400 Subject: [PATCH 179/217] add back old android --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fb2e279..56178b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,7 @@ matrix: - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="6..latest" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="4.4..latest" + env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="4.0..latest" script: "npm run-script $TEST_SUITE" env: global: From 6373a97f8fe8bc5c4f6ea1d16eac93b43b3730b8 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 7 Oct 2015 15:48:46 -0400 Subject: [PATCH 180/217] reactivate older browsers --- .travis.yml | 6 ++++-- package.json | 1 + test/aes.js | 43 +++++++++++++++++++++++++------------------ test/index.js | 17 ++++++++++++----- 4 files changed, 42 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index 56178b5..a17da7e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ matrix: - node_js: '4' env: TEST_SUITE=standard - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=ie BROWSER_VERSION="11..latest" + env: TEST_SUITE=browser BROWSER_NAME=ie BROWSER_VERSION="9..latest" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=chrome BROWSER_VERSION="44..beta" - node_js: '4' @@ -23,9 +23,11 @@ matrix: - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=iphone BROWSER_VERSION="8.0..latest" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="6..latest" + env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="5..latest" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="4.0..latest" + - node_js: '4' + env: TEST_SUITE=browser BROWSER_NAME=opera BROWSER_VERSION="11..latest" script: "npm run-script $TEST_SUITE" env: global: diff --git a/package.json b/package.json index f2b086b..14c0746 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ }, "devDependencies": { "hash-test-vectors": "~1.3.2", + "pseudorandombytes": "^2.0.0", "standard": "^5.0.2", "tape": "~2.3.2", "zuul": "^3.6.0" diff --git a/test/aes.js b/test/aes.js index d227870..916a019 100644 --- a/test/aes.js +++ b/test/aes.js @@ -1,25 +1,32 @@ var test = require('tape') var crypto = require('browserify-cipher/browser') -var randomBytes = require('randombytes') +var randomBytes = require('pseudorandombytes') -crypto.listCiphers().forEach(function (cipher) { - test('ciphers: ' + cipher, function (t) { - t.plan(1) - var data = randomBytes(562) - var password = randomBytes(20) - var crypter = crypto.createCipher(cipher, password) - var decrypter = crypto.createDecipher(cipher, password) - var out = [] - out.push(decrypter.update(crypter.update(data))) - out.push(decrypter.update(crypter.final())) - if (cipher.indexOf('gcm') > -1) { - decrypter.setAuthTag(crypter.getAuthTag()) - } - out.push(decrypter.final()) - t.equals(data.toString('hex'), Buffer.concat(out).toString('hex')) +function runIt (i) { + crypto.listCiphers().forEach(function (cipher) { + test('run: ' + i, function (t) { + t.test('ciphers: ' + cipher, function (t) { + t.plan(1) + var data = randomBytes(562) + var password = randomBytes(20) + var crypter = crypto.createCipher(cipher, password) + var decrypter = crypto.createDecipher(cipher, password) + var out = [] + out.push(decrypter.update(crypter.update(data))) + out.push(decrypter.update(crypter.final())) + if (cipher.indexOf('gcm') > -1) { + decrypter.setAuthTag(crypter.getAuthTag()) + } + out.push(decrypter.final()) + t.equals(data.toString('hex'), Buffer.concat(out).toString('hex')) + }) + }) }) -}) - + if (i < 4) { + setTimeout(runIt, 0, i + 1) + } +} +runIt(1) test('getCiphers', function (t) { t.plan(1) t.ok(crypto.getCiphers().length, 'get ciphers returns an array') diff --git a/test/index.js b/test/index.js index 5491283..0a9d290 100644 --- a/test/index.js +++ b/test/index.js @@ -1,11 +1,18 @@ -require('./aes') + require('./create-hash') require('./create-hmac') if (!process.browser) { require('./dh') } -require('./ecdh') + require('./pbkdf2') -require('./public-encrypt') -require('./random-bytes') -require('./sign') +try { + require('randombytes')(8) + require('./ecdh') + require('./public-encrypt') + require('./random-bytes') + require('./sign') +} catch (e) { + console.log('no secure rng avaiable') +} +require('./aes') From ddd78535f5a2d1a279fb5724ad756192fc5703f5 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 8 Oct 2015 11:09:56 -0400 Subject: [PATCH 181/217] no ie 9 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a17da7e..f3a4555 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ matrix: - node_js: '4' env: TEST_SUITE=standard - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=ie BROWSER_VERSION="9..latest" + env: TEST_SUITE=browser BROWSER_NAME=ie BROWSER_VERSION="10..latest" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=chrome BROWSER_VERSION="44..beta" - node_js: '4' From 35a611d98132b699250baf3881ef8927579cff84 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 8 Oct 2015 14:22:18 -0400 Subject: [PATCH 182/217] no opera --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f3a4555..cbb4b5b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,8 +26,6 @@ matrix: env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="5..latest" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="4.0..latest" - - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=opera BROWSER_VERSION="11..latest" script: "npm run-script $TEST_SUITE" env: global: From 3b645f7b2ef0c012f33b94c199949124b569939b Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 12 Oct 2015 15:24:54 -0400 Subject: [PATCH 183/217] rm ipad --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index cbb4b5b..1fe31b8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,8 +18,6 @@ matrix: env: TEST_SUITE=browser BROWSER_NAME=chrome BROWSER_VERSION="44..beta" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=firefox BROWSER_VERSION="40..latest" - - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=ipad BROWSER_VERSION="8.0..latest" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=iphone BROWSER_VERSION="8.0..latest" - node_js: '4' From 00a13a2f942004b2d8c155323f56f8296c044ce4 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 2 Nov 2015 09:22:29 -0500 Subject: [PATCH 184/217] bump dependencies for use with bn.js 4.1.1 --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 14c0746..93cf478 100644 --- a/package.json +++ b/package.json @@ -19,14 +19,14 @@ }, "dependencies": { "browserify-cipher": "^1.0.0", - "browserify-sign": "^3.0.1", - "create-ecdh": "^2.0.2", + "browserify-sign": "^4.0.0", + "create-ecdh": "^4.0.0", "create-hash": "^1.1.0", "create-hmac": "^1.1.0", - "diffie-hellman": "^3.0.1", + "diffie-hellman": "^5.0.0", "inherits": "^2.0.1", "pbkdf2": "^3.0.3", - "public-encrypt": "^2.0.0", + "public-encrypt": "^4.0.0", "randombytes": "^2.0.0" }, "devDependencies": { From 9ab58cd04776a3bc4b405fac0d9bd5ead2b9f5ad Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 3 Nov 2015 08:40:44 -0500 Subject: [PATCH 185/217] 3.11.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 93cf478..f36f2e5 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.10.0", + "version": "3.11.0", "homepage": "https://github.com/crypto-browserify/crypto-browserify", "repository": { "type": "git", From eea13e59d89978d0d8fb5b237bcead3dfd9add5e Mon Sep 17 00:00:00 2001 From: Arturo Jain Date: Mon, 14 Dec 2015 09:39:55 -0600 Subject: [PATCH 186/217] add privateEncrypt/publicDecrypt to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9b0c03b..1b9cf3b 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Here is the subset that is currently implemented: * createVerify (rsa, ecdsa) * createECDH (secp256k1) * publicEncrypt/privateDecrypt (rsa) +* privateEncrypt/publicDecrypt (rsa) ## todo From 6cb4e9d6caf70df5843eea87a64ef42f25d7100c Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 11 Apr 2017 11:44:35 -0400 Subject: [PATCH 187/217] crypto.constants are missing #159 (#164) * crypto.constants are missing #159 According to https://nodejs.org/dist/latest-v6.x/docs/api/crypto.html#crypto_crypto_constants I should be able to use crypto.constants.RSA_PKCS1_OAEP_PADDING with privateDecrypt. Instead of using the constant I used it's value (4) instead and it works fine. For now this includes only the constants of `Other OpenSSL Constants` * update the tests * further update tests --- .travis.yml | 10 +++------- index.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1fe31b8..8f7bb60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,6 @@ sudo: false language: node_js matrix: include: - - node_js: '0.10' - env: TEST_SUITE=unit - node_js: '0.11' env: TEST_SUITE=unit - node_js: '0.12' @@ -15,15 +13,13 @@ matrix: - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=ie BROWSER_VERSION="10..latest" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=chrome BROWSER_VERSION="44..beta" - - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=firefox BROWSER_VERSION="40..latest" + env: TEST_SUITE=browser BROWSER_NAME=chrome BROWSER_VERSION="-2..beta" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=iphone BROWSER_VERSION="8.0..latest" + env: TEST_SUITE=browser BROWSER_NAME=firefox BROWSER_VERSION="-2..latest" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="5..latest" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="4.0..latest" + env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="5.0..latest" script: "npm run-script $TEST_SUITE" env: global: diff --git a/index.js b/index.js index ea632aa..46d4459 100644 --- a/index.js +++ b/index.js @@ -75,3 +75,22 @@ var publicEncrypt = require('public-encrypt') ].join('\n')) } }) + +exports.constants = { + 'DH_CHECK_P_NOT_SAFE_PRIME': 2, + 'DH_CHECK_P_NOT_PRIME': 1, + 'DH_UNABLE_TO_CHECK_GENERATOR': 4, + 'DH_NOT_SUITABLE_GENERATOR': 8, + 'NPN_ENABLED': 1, + 'ALPN_ENABLED': 1, + 'RSA_PKCS1_PADDING': 1, + 'RSA_SSLV23_PADDING': 2, + 'RSA_NO_PADDING': 3, + 'RSA_PKCS1_OAEP_PADDING': 4, + 'RSA_X931_PADDING': 5, + 'RSA_PKCS1_PSS_PADDING': 6, + 'POINT_CONVERSION_COMPRESSED': 2, + 'POINT_CONVERSION_UNCOMPRESSED': 4, + 'POINT_CONVERSION_HYBRID': 6 +} + From 966e121383231afb503ad8064cb3ab231916a585 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 5 Jul 2017 09:07:21 -0400 Subject: [PATCH 188/217] more explicit exports --- index.js | 100 ++++++++++++++++++++++++++----------------------------- 1 file changed, 48 insertions(+), 52 deletions(-) diff --git a/index.js b/index.js index 46d4459..3b48da3 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,9 @@ exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = r exports.createHash = exports.Hash = require('create-hash') exports.createHmac = exports.Hmac = require('create-hmac') -var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(Object.keys(require('browserify-sign/algos'))) +var algos = require('browserify-sign/algos') +var algoKeys = Object.keys(algos) +var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(algoKeys) exports.getHashes = function () { return hashes } @@ -14,67 +16,62 @@ exports.pbkdf2 = p.pbkdf2 exports.pbkdf2Sync = p.pbkdf2Sync var aes = require('browserify-cipher') -;[ - 'Cipher', - 'createCipher', - 'Cipheriv', - 'createCipheriv', - 'Decipher', - 'createDecipher', - 'Decipheriv', - 'createDecipheriv', - 'getCiphers', - 'listCiphers' -].forEach(function (key) { - exports[key] = aes[key] -}) + +exports.Cipher = aes.Cipher +exports.createCipher = aes.createCipher +exports.Cipheriv = aes.Cipheriv +exports.createCipheriv = aes.createCipheriv +exports.Decipher = aes.Decipher +exports.createDecipher = aes.createDecipher +exports.Decipheriv = aes.Decipheriv +exports.createDecipheriv = aes.createDecipheriv +exports.getCiphers = aes.getCiphers +exports.listCiphers = aes.listCiphers var dh = require('diffie-hellman') -;[ - 'DiffieHellmanGroup', - 'createDiffieHellmanGroup', - 'getDiffieHellman', - 'createDiffieHellman', - 'DiffieHellman' -].forEach(function (key) { - exports[key] = dh[key] -}) + +exports.DiffieHellmanGroup = dh.DiffieHellmanGroup +exports.createDiffieHellmanGroup = dh.createDiffieHellmanGroup +exports.getDiffieHellman = dh.getDiffieHellman +exports.createDiffieHellman = dh.createDiffieHellman +exports.DiffieHellman = dh.DiffieHellman var sign = require('browserify-sign') -;[ - 'createSign', - 'Sign', - 'createVerify', - 'Verify' -].forEach(function (key) { - exports[key] = sign[key] -}) + +exports.createSign = sign.createSign +exports.Sign = sign.Sign +exports.createVerify = sign.createVerify +exports.Verify = sign.Verify exports.createECDH = require('create-ecdh') var publicEncrypt = require('public-encrypt') -;[ - 'publicEncrypt', - 'privateEncrypt', - 'publicDecrypt', - 'privateDecrypt' -].forEach(function (key) { - exports[key] = publicEncrypt[key] -}) +exports.publicEncrypt = publicEncrypt.publicEncrypt +exports.privateEncrypt = publicEncrypt.privateEncrypt +exports.publicDecrypt = publicEncrypt.publicDecrypt +exports.privateDecrypt = publicEncrypt.privateDecrypt // the least I can do is make error messages for the rest of the node.js/crypto api. -;[ - 'createCredentials' -].forEach(function (name) { - exports[name] = function () { - throw new Error([ - 'sorry, ' + name + ' is not implemented yet', - 'we accept pull requests', - 'https://github.com/crypto-browserify/crypto-browserify' - ].join('\n')) - } -}) +// ;[ +// 'createCredentials' +// ].forEach(function (name) { +// exports[name] = function () { +// throw new Error([ +// 'sorry, ' + name + ' is not implemented yet', +// 'we accept pull requests', +// 'https://github.com/crypto-browserify/crypto-browserify' +// ].join('\n')) +// } +// }) + +exports.createCredentials = function () { + throw new Error([ + 'sorry, createCredentials is not implemented yet', + 'we accept pull requests', + 'https://github.com/crypto-browserify/crypto-browserify' + ].join('\n')) +} exports.constants = { 'DH_CHECK_P_NOT_SAFE_PRIME': 2, @@ -93,4 +90,3 @@ exports.constants = { 'POINT_CONVERSION_UNCOMPRESSED': 4, 'POINT_CONVERSION_HYBRID': 6 } - From f680d26645cddac082dd14c200cb3764c4abcaef Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 11 Jul 2017 09:32:16 -0400 Subject: [PATCH 189/217] 3.11.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f36f2e5..d7fe9a4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.11.0", + "version": "3.11.1", "homepage": "https://github.com/crypto-browserify/crypto-browserify", "repository": { "type": "git", From cc6d57ed48f8847ed2e6446a6029c779ffc55082 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 5 Jul 2017 09:07:21 -0400 Subject: [PATCH 190/217] more explicit exports --- index.js | 100 ++++++++++++++++++++++++++----------------------------- 1 file changed, 48 insertions(+), 52 deletions(-) diff --git a/index.js b/index.js index 46d4459..3b48da3 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,9 @@ exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = r exports.createHash = exports.Hash = require('create-hash') exports.createHmac = exports.Hmac = require('create-hmac') -var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(Object.keys(require('browserify-sign/algos'))) +var algos = require('browserify-sign/algos') +var algoKeys = Object.keys(algos) +var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(algoKeys) exports.getHashes = function () { return hashes } @@ -14,67 +16,62 @@ exports.pbkdf2 = p.pbkdf2 exports.pbkdf2Sync = p.pbkdf2Sync var aes = require('browserify-cipher') -;[ - 'Cipher', - 'createCipher', - 'Cipheriv', - 'createCipheriv', - 'Decipher', - 'createDecipher', - 'Decipheriv', - 'createDecipheriv', - 'getCiphers', - 'listCiphers' -].forEach(function (key) { - exports[key] = aes[key] -}) + +exports.Cipher = aes.Cipher +exports.createCipher = aes.createCipher +exports.Cipheriv = aes.Cipheriv +exports.createCipheriv = aes.createCipheriv +exports.Decipher = aes.Decipher +exports.createDecipher = aes.createDecipher +exports.Decipheriv = aes.Decipheriv +exports.createDecipheriv = aes.createDecipheriv +exports.getCiphers = aes.getCiphers +exports.listCiphers = aes.listCiphers var dh = require('diffie-hellman') -;[ - 'DiffieHellmanGroup', - 'createDiffieHellmanGroup', - 'getDiffieHellman', - 'createDiffieHellman', - 'DiffieHellman' -].forEach(function (key) { - exports[key] = dh[key] -}) + +exports.DiffieHellmanGroup = dh.DiffieHellmanGroup +exports.createDiffieHellmanGroup = dh.createDiffieHellmanGroup +exports.getDiffieHellman = dh.getDiffieHellman +exports.createDiffieHellman = dh.createDiffieHellman +exports.DiffieHellman = dh.DiffieHellman var sign = require('browserify-sign') -;[ - 'createSign', - 'Sign', - 'createVerify', - 'Verify' -].forEach(function (key) { - exports[key] = sign[key] -}) + +exports.createSign = sign.createSign +exports.Sign = sign.Sign +exports.createVerify = sign.createVerify +exports.Verify = sign.Verify exports.createECDH = require('create-ecdh') var publicEncrypt = require('public-encrypt') -;[ - 'publicEncrypt', - 'privateEncrypt', - 'publicDecrypt', - 'privateDecrypt' -].forEach(function (key) { - exports[key] = publicEncrypt[key] -}) +exports.publicEncrypt = publicEncrypt.publicEncrypt +exports.privateEncrypt = publicEncrypt.privateEncrypt +exports.publicDecrypt = publicEncrypt.publicDecrypt +exports.privateDecrypt = publicEncrypt.privateDecrypt // the least I can do is make error messages for the rest of the node.js/crypto api. -;[ - 'createCredentials' -].forEach(function (name) { - exports[name] = function () { - throw new Error([ - 'sorry, ' + name + ' is not implemented yet', - 'we accept pull requests', - 'https://github.com/crypto-browserify/crypto-browserify' - ].join('\n')) - } -}) +// ;[ +// 'createCredentials' +// ].forEach(function (name) { +// exports[name] = function () { +// throw new Error([ +// 'sorry, ' + name + ' is not implemented yet', +// 'we accept pull requests', +// 'https://github.com/crypto-browserify/crypto-browserify' +// ].join('\n')) +// } +// }) + +exports.createCredentials = function () { + throw new Error([ + 'sorry, createCredentials is not implemented yet', + 'we accept pull requests', + 'https://github.com/crypto-browserify/crypto-browserify' + ].join('\n')) +} exports.constants = { 'DH_CHECK_P_NOT_SAFE_PRIME': 2, @@ -93,4 +90,3 @@ exports.constants = { 'POINT_CONVERSION_UNCOMPRESSED': 4, 'POINT_CONVERSION_HYBRID': 6 } - From acd878919d8be5b6d3f7678f1708a7afafa2319d Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 11 Jul 2017 09:32:16 -0400 Subject: [PATCH 191/217] 3.11.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f36f2e5..d7fe9a4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.11.0", + "version": "3.11.1", "homepage": "https://github.com/crypto-browserify/crypto-browserify", "repository": { "type": "git", From 8c5454c49e821e9be05792cec7b59a7f82e0a0f6 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 18 Oct 2017 10:52:32 -0400 Subject: [PATCH 192/217] add rndom fill --- index.js | 5 +++++ package.json | 4 +++- test/index.js | 1 + test/random-fill.js | 53 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 test/random-fill.js diff --git a/index.js b/index.js index 3b48da3..b6d4d24 100644 --- a/index.js +++ b/index.js @@ -65,6 +65,11 @@ exports.privateDecrypt = publicEncrypt.privateDecrypt // } // }) +var rf = require('randomfill') + +exports.randomFill = rf.randomFill +exports.randomFillSync = rf.randomFillSync + exports.createCredentials = function () { throw new Error([ 'sorry, createCredentials is not implemented yet', diff --git a/package.json b/package.json index d7fe9a4..c77bec8 100644 --- a/package.json +++ b/package.json @@ -27,11 +27,13 @@ "inherits": "^2.0.1", "pbkdf2": "^3.0.3", "public-encrypt": "^4.0.0", - "randombytes": "^2.0.0" + "randombytes": "^2.0.0", + "randomfill": "^1.0.0" }, "devDependencies": { "hash-test-vectors": "~1.3.2", "pseudorandombytes": "^2.0.0", + "safe-buffer": "^5.1.1", "standard": "^5.0.2", "tape": "~2.3.2", "zuul": "^3.6.0" diff --git a/test/index.js b/test/index.js index 0a9d290..2ac7094 100644 --- a/test/index.js +++ b/test/index.js @@ -12,6 +12,7 @@ try { require('./public-encrypt') require('./random-bytes') require('./sign') + require('./random-fill') } catch (e) { console.log('no secure rng avaiable') } diff --git a/test/random-fill.js b/test/random-fill.js new file mode 100644 index 0000000..63c885a --- /dev/null +++ b/test/random-fill.js @@ -0,0 +1,53 @@ +var test = require('tape') +var crypto = require('../') +var Buffer = require('safe-buffer').Buffer + +test('get error message', function (t) { + try { + var b = crypto.randomFillSync(Buffer.alloc(10)) + t.ok(Buffer.isBuffer(b)) + t.end() + } catch (err) { + t.ok(/not supported/.test(err.message), '"not supported" is in error message') + t.end() + } +}) + +test('randomfill', function (t) { + t.plan(5) + t.equal(crypto.randomFillSync(Buffer.alloc(10)).length, 10) + t.ok(Buffer.isBuffer(crypto.randomFillSync(Buffer.alloc(10)))) + crypto.randomFill(Buffer.alloc(10), function (ex, bytes) { + t.error(ex) + t.equal(bytes.length, 10) + t.ok(Buffer.isBuffer(bytes)) + t.end() + }) +}) + +test('seems random', function (t) { + var L = 1000 + var b = crypto.randomFillSync(Buffer.alloc(L)) + + var mean = [].reduce.call(b, function (a, b) { + return a + b + }, 0) / L + + // test that the random numbers are plausably random. + // Math.random() will pass this, but this will catch + // terrible mistakes such as this blunder: + // https://github.com/dominictarr/crypto-browserify/commit/3267955e1df7edd1680e52aeede9a89506ed2464#commitcomment-7916835 + + // this doesn't check that the bytes are in a random *order* + // but it's better than nothing. + + var expected = 256 / 2 + var smean = Math.sqrt(mean) + + // console.log doesn't work right on testling, *grumble grumble* + console.log(JSON.stringify([expected - smean, mean, expected + smean])) + t.ok(mean < expected + smean) + t.ok(mean > expected - smean) + + t.end() +}) From 1c4fb9b392a4941740a83c729bfe8fab0db526e3 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 18 Oct 2017 11:15:44 -0400 Subject: [PATCH 193/217] bump randomfill --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c77bec8..d79012c 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "pbkdf2": "^3.0.3", "public-encrypt": "^4.0.0", "randombytes": "^2.0.0", - "randomfill": "^1.0.0" + "randomfill": "^1.0.1" }, "devDependencies": { "hash-test-vectors": "~1.3.2", From 66a97c74e3921dfb82fc37f29944ca88e3ba44c3 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 18 Oct 2017 11:43:52 -0400 Subject: [PATCH 194/217] bump randomfill --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d79012c..8785453 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "pbkdf2": "^3.0.3", "public-encrypt": "^4.0.0", "randombytes": "^2.0.0", - "randomfill": "^1.0.1" + "randomfill": "^1.0.2" }, "devDependencies": { "hash-test-vectors": "~1.3.2", From f38434ea59038b16dd5dcec44bf40b1464e24e67 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 18 Oct 2017 11:56:41 -0400 Subject: [PATCH 195/217] bump randomfill a 3rd time --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8785453..ed0f3d1 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "pbkdf2": "^3.0.3", "public-encrypt": "^4.0.0", "randombytes": "^2.0.0", - "randomfill": "^1.0.2" + "randomfill": "^1.0.3" }, "devDependencies": { "hash-test-vectors": "~1.3.2", From ac772395fd2896a859eb1535276c23de71c2a7a5 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 19 Oct 2017 08:37:47 -0400 Subject: [PATCH 196/217] remove old safari --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8f7bb60..26e954c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ matrix: - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=firefox BROWSER_VERSION="-2..latest" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="5..latest" + env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="6..latest" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="5.0..latest" script: "npm run-script $TEST_SUITE" From 01d5b5cb593ce5909b817a974e0f08f22175791e Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 19 Oct 2017 08:52:45 -0400 Subject: [PATCH 197/217] saucelabs aparently only goes back to 7 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 26e954c..5ad8439 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ matrix: - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=firefox BROWSER_VERSION="-2..latest" - node_js: '4' - env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="6..latest" + env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="7..latest" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="5.0..latest" script: "npm run-script $TEST_SUITE" From dcbe3bf731a438a802bf0936108a8abe055356ad Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 2 Nov 2017 11:21:18 -0400 Subject: [PATCH 198/217] 3.12.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ed0f3d1..7de383b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.11.1", + "version": "3.12.0", "homepage": "https://github.com/crypto-browserify/crypto-browserify", "repository": { "type": "git", From 9730d317e2141099b8e56d2afbaf806eb616e0a3 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 2 Nov 2017 11:21:18 -0400 Subject: [PATCH 199/217] 3.12.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ed0f3d1..7de383b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Dominic Tarr (dominictarr.com)", "name": "crypto-browserify", "description": "implementation of crypto for the browser", - "version": "3.11.1", + "version": "3.12.0", "homepage": "https://github.com/crypto-browserify/crypto-browserify", "repository": { "type": "git", From e337bfc3a55eea9d37a7e4725faeb842e0b832a0 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 3 Jan 2018 16:13:06 -0500 Subject: [PATCH 200/217] standard fix --- test/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/index.js b/test/index.js index 2ac7094..e48ee9b 100644 --- a/test/index.js +++ b/test/index.js @@ -1,4 +1,3 @@ - require('./create-hash') require('./create-hmac') if (!process.browser) { From 460a13b5bf1e4ea60dc995906ba0543f7933a32b Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 3 Jan 2018 16:13:23 -0500 Subject: [PATCH 201/217] fix debian issue (maybe) --- test/sign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sign.js b/test/sign.js index 7d67685..c91b666 100644 --- a/test/sign.js +++ b/test/sign.js @@ -56,4 +56,4 @@ function testit (keys, message, scheme) { } testit(rsa, new Buffer('rsa with sha256'), 'RSA-SHA256') -testit(ec, new Buffer('ec with sha1'), 'ecdsa-with-SHA1') +testit(ec, new Buffer('ec with sha1'), 'sha256') From 0d6fd62ea2fe901675540e8bdbacee9e392ec394 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 24 Nov 2023 22:20:19 -0800 Subject: [PATCH 202/217] [eslint] switch to eslint --- .eslintrc | 24 + .travis.yml | 2 +- example/bundle.js | 1082 +++++++++++++++++++--------------------- example/index.html | 8 +- example/test.js | 8 +- index.js | 158 +++--- package.json | 89 ++-- test/aes.js | 98 ++-- test/create-hash.js | 95 ++-- test/create-hmac.js | 105 ++-- test/dh.js | 101 ++-- test/ecdh.js | 113 ++--- test/index.js | 28 +- test/node/dh.js | 105 ++-- test/pbkdf2.js | 30 +- test/public-encrypt.js | 65 +-- test/random-bytes.js | 120 ++--- test/random-fill.js | 84 ++-- test/sign.js | 108 ++-- 19 files changed, 1246 insertions(+), 1177 deletions(-) create mode 100644 .eslintrc diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..32a354f --- /dev/null +++ b/.eslintrc @@ -0,0 +1,24 @@ +{ + "root": true, + + "extends": "@ljharb", + + "rules": { + "func-style": "off", + "multiline-comment-style": "off", + "sort-keys": "off", + }, + + "ignorePatterns": [ + "example/bundle.js", + ], + + "overrides": [ + { + "files": "example/**", + "rules": { + "no-console": "off", + }, + }, + ], +} diff --git a/.travis.yml b/.travis.yml index 5ad8439..3b77be7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ matrix: - node_js: '4' env: TEST_SUITE=unit - node_js: '4' - env: TEST_SUITE=standard + env: TEST_SUITE=lint - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=ie BROWSER_VERSION="10..latest" - node_js: '4' diff --git a/example/bundle.js b/example/bundle.js index 02698cc..479f804 100644 --- a/example/bundle.js +++ b/example/bundle.js @@ -1,419 +1,413 @@ +'use strict'; + var require = function (file, cwd) { - var resolved = require.resolve(file, cwd || '/'); - var mod = require.modules[resolved]; - if (!mod) throw new Error( - 'Failed to resolve module ' + file + ', tried ' + resolved - ); - var res = mod._cached ? mod._cached : mod(); - return res; -} + var resolved = require.resolve(file, cwd || '/'); + var mod = require.modules[resolved]; + if (!mod) { + throw new Error('Failed to resolve module ' + file + ', tried ' + resolved); + } + var res = mod._cached ? mod._cached : mod(); + return res; +}; require.paths = []; require.modules = {}; -require.extensions = [".js",".coffee"]; +require.extensions = ['.js', '.coffee']; require._core = { - 'assert': true, - 'events': true, - 'fs': true, - 'path': true, - 'vm': true + assert: true, + events: true, + fs: true, + path: true, + vm: true }; require.resolve = (function () { - return function (x, cwd) { - if (!cwd) cwd = '/'; - - if (require._core[x]) return x; - var path = require.modules.path(); - cwd = path.resolve('/', cwd); - var y = cwd || '/'; - - if (x.match(/^(?:\.\.?\/|\/)/)) { - var m = loadAsFileSync(path.resolve(y, x)) - || loadAsDirectorySync(path.resolve(y, x)); - if (m) return m; - } - - var n = loadNodeModulesSync(x, y); - if (n) return n; - - throw new Error("Cannot find module '" + x + "'"); - - function loadAsFileSync (x) { - if (require.modules[x]) { - return x; - } - - for (var i = 0; i < require.extensions.length; i++) { - var ext = require.extensions[i]; - if (require.modules[x + ext]) return x + ext; - } - } - - function loadAsDirectorySync (x) { - x = x.replace(/\/+$/, ''); - var pkgfile = x + '/package.json'; - if (require.modules[pkgfile]) { - var pkg = require.modules[pkgfile](); - var b = pkg.browserify; - if (typeof b === 'object' && b.main) { - var m = loadAsFileSync(path.resolve(x, b.main)); - if (m) return m; - } - else if (typeof b === 'string') { - var m = loadAsFileSync(path.resolve(x, b)); - if (m) return m; - } - else if (pkg.main) { - var m = loadAsFileSync(path.resolve(x, pkg.main)); - if (m) return m; - } - } - - return loadAsFileSync(x + '/index'); - } - - function loadNodeModulesSync (x, start) { - var dirs = nodeModulesPathsSync(start); - for (var i = 0; i < dirs.length; i++) { - var dir = dirs[i]; - var m = loadAsFileSync(dir + '/' + x); - if (m) return m; - var n = loadAsDirectorySync(dir + '/' + x); - if (n) return n; - } - - var m = loadAsFileSync(x); - if (m) return m; - } - - function nodeModulesPathsSync (start) { - var parts; - if (start === '/') parts = [ '' ]; - else parts = path.normalize(start).split('/'); - - var dirs = []; - for (var i = parts.length - 1; i >= 0; i--) { - if (parts[i] === 'node_modules') continue; - var dir = parts.slice(0, i + 1).join('/') + '/node_modules'; - dirs.push(dir); - } - - return dirs; - } - }; -})(); + return function (x, cwd) { + if (!cwd) { cwd = '/'; } + + if (require._core[x]) { return x; } + var path = require.modules.path(); + cwd = path.resolve('/', cwd); + var y = cwd || '/'; + + if (x.match(/^(?:\.\.?\/|\/)/)) { + var m = loadAsFileSync(path.resolve(y, x)) + || loadAsDirectorySync(path.resolve(y, x)); + if (m) { return m; } + } + + var n = loadNodeModulesSync(x, y); + if (n) { return n; } + + throw new Error("Cannot find module '" + x + "'"); + + function loadAsFileSync(x) { + if (require.modules[x]) { + return x; + } + + for (var i = 0; i < require.extensions.length; i++) { + var ext = require.extensions[i]; + if (require.modules[x + ext]) { return x + ext; } + } + } + + function loadAsDirectorySync(x) { + x = x.replace(/\/+$/, ''); + var pkgfile = x + '/package.json'; + if (require.modules[pkgfile]) { + var pkg = require.modules[pkgfile](); + var b = pkg.browserify; + if (typeof b === 'object' && b.main) { + var m = loadAsFileSync(path.resolve(x, b.main)); + if (m) { return m; } + } else if (typeof b === 'string') { + var m = loadAsFileSync(path.resolve(x, b)); + if (m) { return m; } + } else if (pkg.main) { + var m = loadAsFileSync(path.resolve(x, pkg.main)); + if (m) { return m; } + } + } + + return loadAsFileSync(x + '/index'); + } + + function loadNodeModulesSync(x, start) { + var dirs = nodeModulesPathsSync(start); + for (var i = 0; i < dirs.length; i++) { + var dir = dirs[i]; + var m = loadAsFileSync(dir + '/' + x); + if (m) { return m; } + var n = loadAsDirectorySync(dir + '/' + x); + if (n) { return n; } + } + + var m = loadAsFileSync(x); + if (m) { return m; } + } + + function nodeModulesPathsSync(start) { + var parts; + if (start === '/') { parts = ['']; } else { parts = path.normalize(start).split('/'); } + + var dirs = []; + for (var i = parts.length - 1; i >= 0; i--) { + if (parts[i] === 'node_modules') { continue; } + var dir = parts.slice(0, i + 1).join('/') + '/node_modules'; + dirs.push(dir); + } + + return dirs; + } + }; +}()); require.alias = function (from, to) { - var path = require.modules.path(); - var res = null; - try { - res = require.resolve(from + '/package.json', '/'); - } - catch (err) { - res = require.resolve(from, '/'); - } - var basedir = path.dirname(res); - - var keys = (Object.keys || function (obj) { - var res = []; - for (var key in obj) res.push(key) - return res; - })(require.modules); - - for (var i = 0; i < keys.length; i++) { - var key = keys[i]; - if (key.slice(0, basedir.length + 1) === basedir + '/') { - var f = key.slice(basedir.length); - require.modules[to + f] = require.modules[basedir + f]; - } - else if (key === basedir) { - require.modules[to] = require.modules[basedir]; - } - } + var path = require.modules.path(); + var res = null; + try { + res = require.resolve(from + '/package.json', '/'); + } catch (err) { + res = require.resolve(from, '/'); + } + var basedir = path.dirname(res); + + var keys = (Object.keys || function (obj) { + var res = []; + for (var key in obj) { res.push(key); } + return res; + })(require.modules); + + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + if (key.slice(0, basedir.length + 1) === basedir + '/') { + var f = key.slice(basedir.length); + require.modules[to + f] = require.modules[basedir + f]; + } else if (key === basedir) { + require.modules[to] = require.modules[basedir]; + } + } }; require.define = function (filename, fn) { - var dirname = require._core[filename] - ? '' - : require.modules.path().dirname(filename) - ; - - var require_ = function (file) { - return require(file, dirname) - }; - require_.resolve = function (name) { - return require.resolve(name, dirname); - }; - require_.modules = require.modules; - require_.define = require.define; - var module_ = { exports : {} }; - - require.modules[filename] = function () { - require.modules[filename]._cached = module_.exports; - fn.call( - module_.exports, - require_, - module_, - module_.exports, - dirname, - filename - ); - require.modules[filename]._cached = module_.exports; - return module_.exports; - }; -}; - -if (typeof process === 'undefined') process = {}; - -if (!process.nextTick) process.nextTick = (function () { - var queue = []; - var canPost = typeof window !== 'undefined' - && window.postMessage && window.addEventListener - ; - - if (canPost) { - window.addEventListener('message', function (ev) { - if (ev.source === window && ev.data === 'browserify-tick') { - ev.stopPropagation(); - if (queue.length > 0) { - var fn = queue.shift(); - fn(); - } - } - }, true); - } - - return function (fn) { - if (canPost) { - queue.push(fn); - window.postMessage('browserify-tick', '*'); - } - else setTimeout(fn, 0); - }; -})(); - -if (!process.title) process.title = 'browser'; - -if (!process.binding) process.binding = function (name) { - if (name === 'evals') return require('vm') - else throw new Error('No such module') + var dirname = require._core[filename] + ? '' + : require.modules.path().dirname(filename); + var require_ = function (file) { + return require(file, dirname); + }; + require_.resolve = function (name) { + return require.resolve(name, dirname); + }; + require_.modules = require.modules; + require_.define = require.define; + var module_ = { exports: {} }; + + require.modules[filename] = function () { + require.modules[filename]._cached = module_.exports; + fn.call( + module_.exports, + require_, + module_, + module_.exports, + dirname, + filename + ); + require.modules[filename]._cached = module_.exports; + return module_.exports; + }; }; -if (!process.cwd) process.cwd = function () { return '.' }; - -if (!process.env) process.env = {}; -if (!process.argv) process.argv = []; - -require.define("path", function (require, module, exports, __dirname, __filename) { -function filter (xs, fn) { - var res = []; - for (var i = 0; i < xs.length; i++) { - if (fn(xs[i], i, xs)) res.push(xs[i]); - } - return res; -} - -// resolves . and .. elements in a path array with directory names there -// must be no slashes, empty elements, or device names (c:\) in the array -// (so also no leading and trailing slashes - it does not distinguish -// relative and absolute paths) -function normalizeArray(parts, allowAboveRoot) { - // if the path tries to go above the root, `up` ends up > 0 - var up = 0; - for (var i = parts.length; i >= 0; i--) { - var last = parts[i]; - if (last == '.') { - parts.splice(i, 1); - } else if (last === '..') { - parts.splice(i, 1); - up++; - } else if (up) { - parts.splice(i, 1); - up--; - } - } - - // if the path is allowed to go above the root, restore leading ..s - if (allowAboveRoot) { - for (; up--; up) { - parts.unshift('..'); - } - } - - return parts; +if (typeof process === 'undefined') { process = {}; } + +if (!process.nextTick) { + process.nextTick = (function () { + var queue = []; + var canPost = typeof window !== 'undefined' + && window.postMessage && window.addEventListener; + if (canPost) { + window.addEventListener('message', function (ev) { + if (ev.source === window && ev.data === 'browserify-tick') { + ev.stopPropagation(); + if (queue.length > 0) { + var fn = queue.shift(); + fn(); + } + } + }, true); + } + + return function (fn) { + if (canPost) { + queue.push(fn); + window.postMessage('browserify-tick', '*'); + } else { setTimeout(fn, 0); } + }; + }()); } -// Regex to split a filename into [*, dir, basename, ext] -// posix version -var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/; +if (!process.title) { process.title = 'browser'; } -// path.resolve([from ...], to) -// posix version -exports.resolve = function() { -var resolvedPath = '', - resolvedAbsolute = false; - -for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) { - var path = (i >= 0) - ? arguments[i] - : process.cwd(); - - // Skip empty and invalid entries - if (typeof path !== 'string' || !path) { - continue; - } - - resolvedPath = path + '/' + resolvedPath; - resolvedAbsolute = path.charAt(0) === '/'; +if (!process.binding) { + process.binding = function (name) { + if (name === 'evals') { return require('vm'); } + throw new Error('No such module'); + }; } -// At this point the path should be resolved to a full absolute path, but -// handle relative paths to be safe (might happen when process.cwd() fails) - -// Normalize the path -resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { - return !!p; - }), !resolvedAbsolute).join('/'); - - return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; -}; - -// path.normalize(path) -// posix version -exports.normalize = function(path) { -var isAbsolute = path.charAt(0) === '/', - trailingSlash = path.slice(-1) === '/'; - -// Normalize the path -path = normalizeArray(filter(path.split('/'), function(p) { - return !!p; - }), !isAbsolute).join('/'); - - if (!path && !isAbsolute) { - path = '.'; - } - if (path && trailingSlash) { - path += '/'; - } - - return (isAbsolute ? '/' : '') + path; -}; - - -// posix version -exports.join = function() { - var paths = Array.prototype.slice.call(arguments, 0); - return exports.normalize(filter(paths, function(p, index) { - return p && typeof p === 'string'; - }).join('/')); -}; - - -exports.dirname = function(path) { - var dir = splitPathRe.exec(path)[1] || ''; - var isWindows = false; - if (!dir) { - // No dirname - return '.'; - } else if (dir.length === 1 || - (isWindows && dir.length <= 3 && dir.charAt(1) === ':')) { - // It is just a slash or a drive letter with a slash - return dir; - } else { - // It is a full dirname, strip trailing slash - return dir.substring(0, dir.length - 1); - } -}; - - -exports.basename = function(path, ext) { - var f = splitPathRe.exec(path)[2] || ''; - // TODO: make this comparison case-insensitive on windows? - if (ext && f.substr(-1 * ext.length) === ext) { - f = f.substr(0, f.length - ext.length); - } - return f; -}; - - -exports.extname = function(path) { - return splitPathRe.exec(path)[3] || ''; -}; +if (!process.cwd) { process.cwd = function () { return '.'; }; } + +if (!process.env) { process.env = {}; } +if (!process.argv) { process.argv = []; } + +require.define('path', function (require, module, exports, __dirname, __filename) { + function filter(xs, fn) { + var res = []; + for (var i = 0; i < xs.length; i++) { + if (fn(xs[i], i, xs)) { res.push(xs[i]); } + } + return res; + } + + // resolves . and .. elements in a path array with directory names there + // must be no slashes, empty elements, or device names (c:\) in the array + // (so also no leading and trailing slashes - it does not distinguish + // relative and absolute paths) + function normalizeArray(parts, allowAboveRoot) { + // if the path tries to go above the root, `up` ends up > 0 + var up = 0; + for (var i = parts.length; i >= 0; i--) { + var last = parts[i]; + if (last == '.') { + parts.splice(i, 1); + } else if (last === '..') { + parts.splice(i, 1); + up++; + } else if (up) { + parts.splice(i, 1); + up--; + } + } + + // if the path is allowed to go above the root, restore leading ..s + if (allowAboveRoot) { + for (; up--; up) { + parts.unshift('..'); + } + } + + return parts; + } + + // Regex to split a filename into [*, dir, basename, ext] + // posix version + var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/; + + // path.resolve([from ...], to) + // posix version + exports.resolve = function () { + var resolvedPath = '', + resolvedAbsolute = false; + + for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) { + var path = i >= 0 + ? arguments[i] + : process.cwd(); + + // Skip empty and invalid entries + if (typeof path !== 'string' || !path) { + continue; + } + + resolvedPath = path + '/' + resolvedPath; + resolvedAbsolute = path.charAt(0) === '/'; + } + + // At this point the path should be resolved to a full absolute path, but + // handle relative paths to be safe (might happen when process.cwd() fails) + + // Normalize the path + resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function (p) { + return !!p; + }), !resolvedAbsolute).join('/'); + + return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; + }; + + // path.normalize(path) + // posix version + exports.normalize = function (path) { + var isAbsolute = path.charAt(0) === '/', + trailingSlash = path.slice(-1) === '/'; + + // Normalize the path + path = normalizeArray(filter(path.split('/'), function (p) { + return !!p; + }), !isAbsolute).join('/'); + + if (!path && !isAbsolute) { + path = '.'; + } + if (path && trailingSlash) { + path += '/'; + } + + return (isAbsolute ? '/' : '') + path; + }; + + // posix version + exports.join = function () { + var paths = Array.prototype.slice.call(arguments, 0); + return exports.normalize(filter(paths, function (p, index) { + return p && typeof p === 'string'; + }).join('/')); + }; + + exports.dirname = function (path) { + var dir = splitPathRe.exec(path)[1] || ''; + var isWindows = false; + if (!dir) { + // No dirname + return '.'; + } else if ( + dir.length === 1 + || (isWindows && dir.length <= 3 && dir.charAt(1) === ':') + ) { + // It is just a slash or a drive letter with a slash + return dir; + } + // It is a full dirname, strip trailing slash + return dir.substring(0, dir.length - 1); + + }; + + exports.basename = function (path, ext) { + var f = splitPathRe.exec(path)[2] || ''; + // TODO: make this comparison case-insensitive on windows? + if (ext && f.substr(-1 * ext.length) === ext) { + f = f.substr(0, f.length - ext.length); + } + return f; + }; + + exports.extname = function (path) { + return splitPathRe.exec(path)[3] || ''; + }; }); -require.define("crypto", function (require, module, exports, __dirname, __filename) { -module.exports = require("crypto-browserify") +require.define('crypto', function (require, module, exports, __dirname, __filename) { + module.exports = require('crypto-browserify'); }); -require.define("/node_modules/crypto-browserify/package.json", function (require, module, exports, __dirname, __filename) { -module.exports = {} +require.define('/node_modules/crypto-browserify/package.json', function (require, module, exports, __dirname, __filename) { + module.exports = {}; }); -require.define("/node_modules/crypto-browserify/index.js", function (require, module, exports, __dirname, __filename) { -var sha = require('./sha') - -var algorithms = { - sha1: { - hex: sha.hex_sha1, - binary: sha.b64_sha1, - ascii: sha.str_sha1 - } -} - -function error () { - var m = [].slice.call(arguments).join(' ') - throw new Error([ - m, - 'we accept pull requests', - 'http://github.com/dominictarr/crypto-browserify' - ].join('\n')) -} - -exports.createHash = function (alg) { - alg = alg || 'sha1' - if(!algorithms[alg]) - error('algorithm:', alg, 'is not yet supported') - var s = '' - _alg = algorithms[alg] - return { - update: function (data) { - s += data - return this - }, - digest: function (enc) { - enc = enc || 'binary' - var fn - if(!(fn = _alg[enc])) - error('encoding:', enc , 'is not yet supported for algorithm', alg) - var r = fn(s) - s = null //not meant to use the hash after you've called digest. - return r - } - } -} -// the least I can do is make error messages for the rest of the node.js/crypto api. -;['createCredentials' -, 'createHmac' -, 'createCypher' -, 'createCypheriv' -, 'createDecipher' -, 'createDecipheriv' -, 'createSign' -, 'createVerify' -, 'createDeffieHellman', -, 'pbkdf2', -, 'randomBytes' ].forEach(function (name) { - exports[name] = function () { - error('sorry,', name, 'is not implemented yet') - } -}) +require.define('/node_modules/crypto-browserify/index.js', function (require, module, exports, __dirname, __filename) { + var sha = require('./sha'); + + var algorithms = { + sha1: { + hex: sha.hex_sha1, + binary: sha.b64_sha1, + ascii: sha.str_sha1 + } + }; + + function error() { + var m = Array.prototype.slice.call(arguments).join(' '); + throw new Error([ + m, + 'we accept pull requests', + 'http://github.com/dominictarr/crypto-browserify' + ].join('\n')); + } + + exports.createHash = function (alg) { + alg = alg || 'sha1'; + if (!algorithms[alg]) { error('algorithm:', alg, 'is not yet supported'); } + var s = ''; + _alg = algorithms[alg]; + return { + update: function (data) { + s += data; + return this; + }, + digest: function (enc) { + enc = enc || 'binary'; + var fn; + if (!(fn = _alg[enc])) { error('encoding:', enc, 'is not yet supported for algorithm', alg); } + var r = fn(s); + s = null; // not meant to use the hash after you've called digest. + return r; + } + }; + } + // the least I can do is make error messages for the rest of the node.js/crypto api. + ;[ + 'createCredentials', + 'createHmac', + 'createCypher', + 'createCypheriv', + 'createDecipher', + 'createDecipheriv', + 'createSign', + 'createVerify', + 'createDeffieHellman',, + 'pbkdf2',, + 'randomBytes' + ].forEach(function (name) { + exports[name] = function () { + error('sorry,', name, 'is not implemented yet'); + }; + }); }); -require.define("/node_modules/crypto-browserify/sha.js", function (require, module, exports, __dirname, __filename) { +require.define('/node_modules/crypto-browserify/sha.js', function (require, module, exports, __dirname, __filename) { /* * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined * in FIPS PUB 180-1 @@ -423,215 +417,193 @@ require.define("/node_modules/crypto-browserify/sha.js", function (require, modu * See http://pajhome.org.uk/crypt/md5 for details. */ -exports.hex_sha1 = hex_sha1; -exports.b64_sha1 = b64_sha1; -exports.str_sha1 = str_sha1; -exports.hex_hmac_sha1 = hex_hmac_sha1; -exports.b64_hmac_sha1 = b64_hmac_sha1; -exports.str_hmac_sha1 = str_hmac_sha1; + exports.hex_sha1 = hex_sha1; + exports.b64_sha1 = b64_sha1; + exports.str_sha1 = str_sha1; + exports.hex_hmac_sha1 = hex_hmac_sha1; + exports.b64_hmac_sha1 = b64_hmac_sha1; + exports.str_hmac_sha1 = str_hmac_sha1; -/* + /* * Configurable variables. You may need to tweak these to be compatible with * the server-side, but the defaults work in most cases. */ -var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ -var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */ -var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ + var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ + var b64pad = ''; /* base-64 pad character. "=" for strict RFC compliance */ + var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ -/* + /* * These are the functions you'll usually want to call * They take string arguments and return either hex or base-64 encoded strings */ -function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));} -function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));} -function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));} -function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));} -function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));} -function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));} - -/* + function hex_sha1(s) { return binb2hex(core_sha1(str2binb(s), s.length * chrsz)); } + function b64_sha1(s) { return binb2b64(core_sha1(str2binb(s), s.length * chrsz)); } + function str_sha1(s) { return binb2str(core_sha1(str2binb(s), s.length * chrsz)); } + function hex_hmac_sha1(key, data) { return binb2hex(core_hmac_sha1(key, data)); } + function b64_hmac_sha1(key, data) { return binb2b64(core_hmac_sha1(key, data)); } + function str_hmac_sha1(key, data) { return binb2str(core_hmac_sha1(key, data)); } + + /* * Perform a simple self-test to see if the VM is working */ -function sha1_vm_test() -{ - return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d"; -} + function sha1_vm_test() { + return hex_sha1('abc') == 'a9993e364706816aba3e25717850c26c9cd0d89d'; + } -/* + /* * Calculate the SHA-1 of an array of big-endian words, and a bit length */ -function core_sha1(x, len) -{ - /* append padding */ - x[len >> 5] |= 0x80 << (24 - len % 32); - x[((len + 64 >> 9) << 4) + 15] = len; - - var w = Array(80); - var a = 1732584193; - var b = -271733879; - var c = -1732584194; - var d = 271733878; - var e = -1009589776; - - for(var i = 0; i < x.length; i += 16) - { - var olda = a; - var oldb = b; - var oldc = c; - var oldd = d; - var olde = e; - - for(var j = 0; j < 80; j++) - { - if(j < 16) w[j] = x[i + j]; - else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1); - var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)), - safe_add(safe_add(e, w[j]), sha1_kt(j))); - e = d; - d = c; - c = rol(b, 30); - b = a; - a = t; - } - - a = safe_add(a, olda); - b = safe_add(b, oldb); - c = safe_add(c, oldc); - d = safe_add(d, oldd); - e = safe_add(e, olde); - } - return Array(a, b, c, d, e); - -} - -/* + function core_sha1(x, len) { + /* append padding */ + x[len >> 5] |= 0x80 << (24 - len % 32); + x[((len + 64 >> 9) << 4) + 15] = len; + + var w = Array(80); + var a = 1732584193; + var b = -271733879; + var c = -1732584194; + var d = 271733878; + var e = -1009589776; + + for (var i = 0; i < x.length; i += 16) { + var olda = a; + var oldb = b; + var oldc = c; + var oldd = d; + var olde = e; + + for (var j = 0; j < 80; j++) { + if (j < 16) { w[j] = x[i + j]; } else { w[j] = rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1); } + var t = safe_add( + safe_add(rol(a, 5), sha1_ft(j, b, c, d)), + safe_add(safe_add(e, w[j]), sha1_kt(j)) + ); + e = d; + d = c; + c = rol(b, 30); + b = a; + a = t; + } + + a = safe_add(a, olda); + b = safe_add(b, oldb); + c = safe_add(c, oldc); + d = safe_add(d, oldd); + e = safe_add(e, olde); + } + return Array(a, b, c, d, e); + + } + + /* * Perform the appropriate triplet combination function for the current * iteration */ -function sha1_ft(t, b, c, d) -{ - if(t < 20) return (b & c) | ((~b) & d); - if(t < 40) return b ^ c ^ d; - if(t < 60) return (b & c) | (b & d) | (c & d); - return b ^ c ^ d; -} - -/* + function sha1_ft(t, b, c, d) { + if (t < 20) { return (b & c) | (~b & d); } + if (t < 40) { return b ^ c ^ d; } + if (t < 60) { return (b & c) | (b & d) | (c & d); } + return b ^ c ^ d; + } + + /* * Determine the appropriate additive constant for the current iteration */ -function sha1_kt(t) -{ - return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 : - (t < 60) ? -1894007588 : -899497514; -} + function sha1_kt(t) { + return t < 20 ? 1518500249 : t < 40 ? 1859775393 + : t < 60 ? -1894007588 : -899497514; + } -/* + /* * Calculate the HMAC-SHA1 of a key and some data */ -function core_hmac_sha1(key, data) -{ - var bkey = str2binb(key); - if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz); - - var ipad = Array(16), opad = Array(16); - for(var i = 0; i < 16; i++) - { - ipad[i] = bkey[i] ^ 0x36363636; - opad[i] = bkey[i] ^ 0x5C5C5C5C; - } - - var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz); - return core_sha1(opad.concat(hash), 512 + 160); -} - -/* + function core_hmac_sha1(key, data) { + var bkey = str2binb(key); + if (bkey.length > 16) { bkey = core_sha1(bkey, key.length * chrsz); } + + var ipad = Array(16), + opad = Array(16); + for (var i = 0; i < 16; i++) { + ipad[i] = bkey[i] ^ 0x36363636; + opad[i] = bkey[i] ^ 0x5C5C5C5C; + } + + var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz); + return core_sha1(opad.concat(hash), 512 + 160); + } + + /* * Add integers, wrapping at 2^32. This uses 16-bit operations internally * to work around bugs in some JS interpreters. */ -function safe_add(x, y) -{ - var lsw = (x & 0xFFFF) + (y & 0xFFFF); - var msw = (x >> 16) + (y >> 16) + (lsw >> 16); - return (msw << 16) | (lsw & 0xFFFF); -} + function safe_add(x, y) { + var lsw = (x & 0xFFFF) + (y & 0xFFFF); + var msw = (x >> 16) + (y >> 16) + (lsw >> 16); + return (msw << 16) | (lsw & 0xFFFF); + } -/* + /* * Bitwise rotate a 32-bit number to the left. */ -function rol(num, cnt) -{ - return (num << cnt) | (num >>> (32 - cnt)); -} + function rol(num, cnt) { + return (num << cnt) | (num >>> (32 - cnt)); + } -/* + /* * Convert an 8-bit or 16-bit string to an array of big-endian words * In 8-bit function, characters >255 have their hi-byte silently ignored. */ -function str2binb(str) -{ - var bin = Array(); - var mask = (1 << chrsz) - 1; - for(var i = 0; i < str.length * chrsz; i += chrsz) - bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32); - return bin; -} - -/* + function str2binb(str) { + var bin = Array(); + var mask = (1 << chrsz) - 1; + for (var i = 0; i < str.length * chrsz; i += chrsz) { bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i % 32); } + return bin; + } + + /* * Convert an array of big-endian words to a string */ -function binb2str(bin) -{ - var str = ""; - var mask = (1 << chrsz) - 1; - for(var i = 0; i < bin.length * 32; i += chrsz) - str += String.fromCharCode((bin[i>>5] >>> (32 - chrsz - i%32)) & mask); - return str; -} - -/* + function binb2str(bin) { + var str = ''; + var mask = (1 << chrsz) - 1; + for (var i = 0; i < bin.length * 32; i += chrsz) { str += String.fromCharCode((bin[i >> 5] >>> (32 - chrsz - i % 32)) & mask); } + return str; + } + + /* * Convert an array of big-endian words to a hex string. */ -function binb2hex(binarray) -{ - var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; - var str = ""; - for(var i = 0; i < binarray.length * 4; i++) - { - str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) + - hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF); - } - return str; -} - -/* + function binb2hex(binarray) { + var hex_tab = hexcase ? '0123456789ABCDEF' : '0123456789abcdef'; + var str = ''; + for (var i = 0; i < binarray.length * 4; i++) { + str += hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8 + 4)) & 0xF) + hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8)) & 0xF); + } + return str; + } + + /* * Convert an array of big-endian words to a base-64 string */ -function binb2b64(binarray) -{ - var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - var str = ""; - for(var i = 0; i < binarray.length * 4; i += 3) - { - var triplet = (((binarray[i >> 2] >> 8 * (3 - i %4)) & 0xFF) << 16) - | (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 ) - | ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF); - for(var j = 0; j < 4; j++) - { - if(i * 8 + j * 6 > binarray.length * 32) str += b64pad; - else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F); - } - } - return str; -} - + function binb2b64(binarray) { + var tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; + var str = ''; + for (var i = 0; i < binarray.length * 4; i += 3) { + var triplet = (((binarray[i >> 2] >> 8 * (3 - i % 4)) & 0xFF) << 16) | (((binarray[i + 1 >> 2] >> 8 * (3 - (i + 1) % 4)) & 0xFF) << 8) | ((binarray[i + 2 >> 2] >> 8 * (3 - (i + 2) % 4)) & 0xFF); + for (var j = 0; j < 4; j++) { + if (i * 8 + j * 6 > binarray.length * 32) { str += b64pad; } else { str += tab.charAt((triplet >> 6 * (3 - j)) & 0x3F); } + } + } + return str; + } }); -require.define("/test.js", function (require, module, exports, __dirname, __filename) { - var crypto = require('crypto') -var abc = crypto.createHash('sha1').update('abc').digest('hex') -console.log(abc) -//require('hello').inlineCall().call2() +require.define('/test.js', function (require, module, exports, __dirname, __filename) { + var crypto = require('crypto'); + var abc = crypto.createHash('sha1').update('abc').digest('hex'); + console.log(abc); + // require('hello').inlineCall().call2() }); -require("/test.js"); +require('/test.js'); diff --git a/example/index.html b/example/index.html index 9d55c6d..7ac72a9 100644 --- a/example/index.html +++ b/example/index.html @@ -2,11 +2,11 @@ -
-  require('crypto').createHash('sha1').update('abc').digest('hex') == ''
-  
+
+		require('crypto').createHash('sha1').update('abc').digest('hex') == ''
+	
diff --git a/example/test.js b/example/test.js index 0b76c01..5a4dc1c 100644 --- a/example/test.js +++ b/example/test.js @@ -1,4 +1,6 @@ -var crypto = require('crypto') -var abc = crypto.createHash('sha1').update('abc').digest('hex') -console.log(abc) +'use strict'; + +var crypto = require('crypto'); +var abc = crypto.createHash('sha1').update('abc').digest('hex'); +console.log(abc); // require('hello').inlineCall().call2() diff --git a/index.js b/index.js index b6d4d24..233a9c7 100644 --- a/index.js +++ b/index.js @@ -1,97 +1,107 @@ -'use strict' +'use strict'; -exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes') -exports.createHash = exports.Hash = require('create-hash') -exports.createHmac = exports.Hmac = require('create-hmac') +// eslint-disable-next-line no-multi-assign +exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes'); + +// eslint-disable-next-line no-multi-assign +exports.createHash = exports.Hash = require('create-hash'); + +// eslint-disable-next-line no-multi-assign +exports.createHmac = exports.Hmac = require('create-hmac'); + +var algos = require('browserify-sign/algos'); +var algoKeys = Object.keys(algos); +var hashes = [ + 'sha1', + 'sha224', + 'sha256', + 'sha384', + 'sha512', + 'md5', + 'rmd160' +].concat(algoKeys); -var algos = require('browserify-sign/algos') -var algoKeys = Object.keys(algos) -var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(algoKeys) exports.getHashes = function () { - return hashes -} + return hashes; +}; -var p = require('pbkdf2') -exports.pbkdf2 = p.pbkdf2 -exports.pbkdf2Sync = p.pbkdf2Sync +var p = require('pbkdf2'); +exports.pbkdf2 = p.pbkdf2; +exports.pbkdf2Sync = p.pbkdf2Sync; -var aes = require('browserify-cipher') +var aes = require('browserify-cipher'); -exports.Cipher = aes.Cipher -exports.createCipher = aes.createCipher -exports.Cipheriv = aes.Cipheriv -exports.createCipheriv = aes.createCipheriv -exports.Decipher = aes.Decipher -exports.createDecipher = aes.createDecipher -exports.Decipheriv = aes.Decipheriv -exports.createDecipheriv = aes.createDecipheriv -exports.getCiphers = aes.getCiphers -exports.listCiphers = aes.listCiphers +exports.Cipher = aes.Cipher; +exports.createCipher = aes.createCipher; +exports.Cipheriv = aes.Cipheriv; +exports.createCipheriv = aes.createCipheriv; +exports.Decipher = aes.Decipher; +exports.createDecipher = aes.createDecipher; +exports.Decipheriv = aes.Decipheriv; +exports.createDecipheriv = aes.createDecipheriv; +exports.getCiphers = aes.getCiphers; +exports.listCiphers = aes.listCiphers; -var dh = require('diffie-hellman') +var dh = require('diffie-hellman'); -exports.DiffieHellmanGroup = dh.DiffieHellmanGroup -exports.createDiffieHellmanGroup = dh.createDiffieHellmanGroup -exports.getDiffieHellman = dh.getDiffieHellman -exports.createDiffieHellman = dh.createDiffieHellman -exports.DiffieHellman = dh.DiffieHellman +exports.DiffieHellmanGroup = dh.DiffieHellmanGroup; +exports.createDiffieHellmanGroup = dh.createDiffieHellmanGroup; +exports.getDiffieHellman = dh.getDiffieHellman; +exports.createDiffieHellman = dh.createDiffieHellman; +exports.DiffieHellman = dh.DiffieHellman; -var sign = require('browserify-sign') +var sign = require('browserify-sign'); -exports.createSign = sign.createSign -exports.Sign = sign.Sign -exports.createVerify = sign.createVerify -exports.Verify = sign.Verify +exports.createSign = sign.createSign; +exports.Sign = sign.Sign; +exports.createVerify = sign.createVerify; +exports.Verify = sign.Verify; -exports.createECDH = require('create-ecdh') +exports.createECDH = require('create-ecdh'); -var publicEncrypt = require('public-encrypt') +var publicEncrypt = require('public-encrypt'); -exports.publicEncrypt = publicEncrypt.publicEncrypt -exports.privateEncrypt = publicEncrypt.privateEncrypt -exports.publicDecrypt = publicEncrypt.publicDecrypt -exports.privateDecrypt = publicEncrypt.privateDecrypt +exports.publicEncrypt = publicEncrypt.publicEncrypt; +exports.privateEncrypt = publicEncrypt.privateEncrypt; +exports.publicDecrypt = publicEncrypt.publicDecrypt; +exports.privateDecrypt = publicEncrypt.privateDecrypt; // the least I can do is make error messages for the rest of the node.js/crypto api. // ;[ -// 'createCredentials' +// 'createCredentials' // ].forEach(function (name) { -// exports[name] = function () { -// throw new Error([ -// 'sorry, ' + name + ' is not implemented yet', -// 'we accept pull requests', -// 'https://github.com/crypto-browserify/crypto-browserify' -// ].join('\n')) -// } -// }) +// exports[name] = function () { +// throw new Error('sorry, ' + name + ' is not implemented yet\nwe accept pull requests\nhttps://github.com/crypto-browserify/crypto-browserify'); +// }; +// }); -var rf = require('randomfill') +var rf = require('randomfill'); -exports.randomFill = rf.randomFill -exports.randomFillSync = rf.randomFillSync +exports.randomFill = rf.randomFill; +exports.randomFillSync = rf.randomFillSync; exports.createCredentials = function () { - throw new Error([ - 'sorry, createCredentials is not implemented yet', - 'we accept pull requests', - 'https://github.com/crypto-browserify/crypto-browserify' - ].join('\n')) -} + throw new Error([ + 'sorry, createCredentials is not implemented yet', + 'we accept pull requests', + 'https://github.com/crypto-browserify/crypto-browserify' + ].join('\n')); +}; exports.constants = { - 'DH_CHECK_P_NOT_SAFE_PRIME': 2, - 'DH_CHECK_P_NOT_PRIME': 1, - 'DH_UNABLE_TO_CHECK_GENERATOR': 4, - 'DH_NOT_SUITABLE_GENERATOR': 8, - 'NPN_ENABLED': 1, - 'ALPN_ENABLED': 1, - 'RSA_PKCS1_PADDING': 1, - 'RSA_SSLV23_PADDING': 2, - 'RSA_NO_PADDING': 3, - 'RSA_PKCS1_OAEP_PADDING': 4, - 'RSA_X931_PADDING': 5, - 'RSA_PKCS1_PSS_PADDING': 6, - 'POINT_CONVERSION_COMPRESSED': 2, - 'POINT_CONVERSION_UNCOMPRESSED': 4, - 'POINT_CONVERSION_HYBRID': 6 -} + DH_CHECK_P_NOT_SAFE_PRIME: 2, + DH_CHECK_P_NOT_PRIME: 1, + DH_UNABLE_TO_CHECK_GENERATOR: 4, + DH_NOT_SUITABLE_GENERATOR: 8, + NPN_ENABLED: 1, + ALPN_ENABLED: 1, + RSA_PKCS1_PADDING: 1, + RSA_SSLV23_PADDING: 2, + RSA_NO_PADDING: 3, + RSA_PKCS1_OAEP_PADDING: 4, + RSA_X931_PADDING: 5, + RSA_PKCS1_PSS_PADDING: 6, + POINT_CONVERSION_COMPRESSED: 2, + POINT_CONVERSION_UNCOMPRESSED: 4, + POINT_CONVERSION_HYBRID: 6 +}; diff --git a/package.json b/package.json index 7de383b..e2f1155 100644 --- a/package.json +++ b/package.json @@ -1,46 +1,47 @@ { - "author": "Dominic Tarr (dominictarr.com)", - "name": "crypto-browserify", - "description": "implementation of crypto for the browser", - "version": "3.12.0", - "homepage": "https://github.com/crypto-browserify/crypto-browserify", - "repository": { - "type": "git", - "url": "git://github.com/crypto-browserify/crypto-browserify.git" - }, - "scripts": { - "standard": "standard", - "test": "npm run standard && npm run unit", - "unit": "node test/", - "browser": "zuul --browser-version $BROWSER_VERSION --browser-name $BROWSER_NAME -- test/index.js" - }, - "engines": { - "node": "*" - }, - "dependencies": { - "browserify-cipher": "^1.0.0", - "browserify-sign": "^4.0.0", - "create-ecdh": "^4.0.0", - "create-hash": "^1.1.0", - "create-hmac": "^1.1.0", - "diffie-hellman": "^5.0.0", - "inherits": "^2.0.1", - "pbkdf2": "^3.0.3", - "public-encrypt": "^4.0.0", - "randombytes": "^2.0.0", - "randomfill": "^1.0.3" - }, - "devDependencies": { - "hash-test-vectors": "~1.3.2", - "pseudorandombytes": "^2.0.0", - "safe-buffer": "^5.1.1", - "standard": "^5.0.2", - "tape": "~2.3.2", - "zuul": "^3.6.0" - }, - "optionalDependencies": {}, - "browser": { - "crypto": false - }, - "license": "MIT" + "author": "Dominic Tarr (dominictarr.com)", + "name": "crypto-browserify", + "description": "implementation of crypto for the browser", + "version": "3.12.0", + "homepage": "https://github.com/crypto-browserify/crypto-browserify", + "repository": { + "type": "git", + "url": "git://github.com/crypto-browserify/crypto-browserify.git" + }, + "scripts": { + "lint": "eslint --ext=js,mjs .", + "pretest": "npm run lint", + "test": "npm run unit", + "unit": "node test/", + "browser": "zuul --browser-version $BROWSER_VERSION --browser-name $BROWSER_NAME -- test/index.js" + }, + "engines": { + "node": "*" + }, + "dependencies": { + "browserify-cipher": "^1.0.0", + "browserify-sign": "^4.0.0", + "create-ecdh": "^4.0.0", + "create-hash": "^1.1.0", + "create-hmac": "^1.1.0", + "diffie-hellman": "^5.0.0", + "inherits": "^2.0.1", + "pbkdf2": "^3.0.3", + "public-encrypt": "^4.0.0", + "randombytes": "^2.0.0", + "randomfill": "^1.0.3" + }, + "devDependencies": { + "@ljharb/eslint-config": "^21.1.0", + "eslint": "=8.8.0", + "hash-test-vectors": "~1.3.2", + "pseudorandombytes": "^2.0.0", + "safe-buffer": "^5.1.1", + "tape": "~2.3.2", + "zuul": "^3.6.0" + }, + "browser": { + "crypto": false + }, + "license": "MIT" } diff --git a/test/aes.js b/test/aes.js index 916a019..8d72940 100644 --- a/test/aes.js +++ b/test/aes.js @@ -1,49 +1,57 @@ -var test = require('tape') -var crypto = require('browserify-cipher/browser') -var randomBytes = require('pseudorandombytes') - -function runIt (i) { - crypto.listCiphers().forEach(function (cipher) { - test('run: ' + i, function (t) { - t.test('ciphers: ' + cipher, function (t) { - t.plan(1) - var data = randomBytes(562) - var password = randomBytes(20) - var crypter = crypto.createCipher(cipher, password) - var decrypter = crypto.createDecipher(cipher, password) - var out = [] - out.push(decrypter.update(crypter.update(data))) - out.push(decrypter.update(crypter.final())) - if (cipher.indexOf('gcm') > -1) { - decrypter.setAuthTag(crypter.getAuthTag()) - } - out.push(decrypter.final()) - t.equals(data.toString('hex'), Buffer.concat(out).toString('hex')) - }) - }) - }) - if (i < 4) { - setTimeout(runIt, 0, i + 1) - } +'use strict'; + +var test = require('tape'); +var bcCrypto = require('browserify-cipher/browser'); +var bcCyphers = bcCrypto.getCiphers(); +var randomBytes = require('pseudorandombytes'); + +function runIt(i) { + bcCrypto.listCiphers().forEach(function (cipher) { + test('run: ' + i, function (t) { + t.test('ciphers: ' + cipher, function (st) { + st.plan(1); + var data = randomBytes(562); + var password = randomBytes(20); + var crypter = bcCrypto.createCipher(cipher, password); + var decrypter = bcCrypto.createDecipher(cipher, password); + var out = []; + out.push(decrypter.update(crypter.update(data))); + out.push(decrypter.update(crypter['final']())); + if (cipher.indexOf('gcm') > -1) { + decrypter.setAuthTag(crypter.getAuthTag()); + } + out.push(decrypter['final']()); + + st.equals(data.toString('hex'), Buffer.concat(out).toString('hex')); + }); + }); + }); + if (i < 4) { + setTimeout(runIt, 0, i + 1); + } } -runIt(1) + +runIt(1); + test('getCiphers', function (t) { - t.plan(1) - t.ok(crypto.getCiphers().length, 'get ciphers returns an array') -}) + t.plan(1); + t.ok(bcCyphers.length, 'get ciphers returns an array'); +}); test('through crypto browserify works', function (t) { - t.plan(2) - var crypto = require('../') - var cipher = 'aes-128-ctr' - var data = randomBytes(562) - var password = randomBytes(20) - var crypter = crypto.createCipher(cipher, password) - var decrypter = crypto.createDecipher(cipher, password) - var out = [] - out.push(decrypter.update(crypter.update(data))) - out.push(decrypter.update(crypter.final())) - out.push(decrypter.final()) - t.equals(data.toString('hex'), Buffer.concat(out).toString('hex')) - t.ok(crypto.getCiphers().length, 'get ciphers returns an array') -}) + t.plan(2); + var crypto = require('../'); // eslint-disable-line global-require + var cipher = 'aes-128-ctr'; + var data = randomBytes(562); + var password = randomBytes(20); + var crypter = crypto.createCipher(cipher, password); + var decrypter = crypto.createDecipher(cipher, password); + var out = []; + out.push(decrypter.update(crypter.update(data))); + out.push(decrypter.update(crypter['final']())); + out.push(decrypter['final']()); + + t.equals(data.toString('hex'), Buffer.concat(out).toString('hex')); + + t.ok(crypto.getCiphers().length, 'get ciphers returns an array'); +}); diff --git a/test/create-hash.js b/test/create-hash.js index 33532fd..54c7474 100644 --- a/test/create-hash.js +++ b/test/create-hash.js @@ -1,50 +1,55 @@ -var test = require('tape') +'use strict'; -var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'] -var encodings = ['hex', 'base64'] // FIXME: test binary -var vectors = require('hash-test-vectors') +var test = require('tape'); -testLib('createHash in crypto-browserify', require('../').createHash) -testLib('create-hash/browser', require('create-hash/browser')) +var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160']; +var encodings = ['hex', 'base64']; // FIXME: test binary +var vectors = require('hash-test-vectors'); -function testLib (name, createHash) { - algorithms.forEach(function (algorithm) { - runTest(name, createHash, algorithm) - }) +function runTest(name, createHash, algorithm) { + test(name + ' test ' + algorithm + ' against test vectors', function (t) { + function run(i) { + if (i >= vectors.length) { + t.end(); + return; + } + var obj = vectors[i]; + + var input = new Buffer(obj.input, 'base64'); + var node = obj[algorithm]; + var js = createHash(algorithm).update(input).digest('hex'); + if (js !== node) { + t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node); + } + + encodings.forEach(function (encoding) { + var eInput = new Buffer(obj.input, 'base64').toString(encoding); + var eNode = obj[algorithm]; + var eJS = createHash(algorithm).update(eInput, encoding).digest('hex'); + if (eJS !== eNode) { + t.equal(eJS, eNode, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + eNode); + } + }); + input = new Buffer(obj.input, 'base64'); + node = obj[algorithm]; + var hash = createHash(algorithm); + hash.end(input); + js = hash.read().toString('hex'); + if (js !== node) { + t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node); + } + setTimeout(run, 0, i + 1); + } + + run(0); + }); } -function runTest (name, createHash, algorithm) { - test(name + ' test ' + algorithm + ' against test vectors', function (t) { - run(0) - function run (i) { - if (i >= vectors.length) { - return t.end() - } - var obj = vectors[i] - - var input = new Buffer(obj.input, 'base64') - var node = obj[algorithm] - var js = createHash(algorithm).update(input).digest('hex') - if (js !== node) { - t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node) - } - - encodings.forEach(function (encoding) { - var input = new Buffer(obj.input, 'base64').toString(encoding) - var node = obj[algorithm] - var js = createHash(algorithm).update(input, encoding).digest('hex') - if (js !== node) { - t.equal(js, node, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + node) - } - }) - input = new Buffer(obj.input, 'base64') - node = obj[algorithm] - var hash = createHash(algorithm) - hash.end(input) - js = hash.read().toString('hex') - if (js !== node) { - t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node) - } - setTimeout(run, 0, i + 1) - } - }) + +function testLib(name, createHash) { + algorithms.forEach(function (algorithm) { + runTest(name, createHash, algorithm); + }); } + +testLib('createHash in crypto-browserify', require('../').createHash); +testLib('create-hash/browser', require('create-hash/browser')); diff --git a/test/create-hmac.js b/test/create-hmac.js index 08488ab..36641e4 100644 --- a/test/create-hmac.js +++ b/test/create-hmac.js @@ -1,50 +1,57 @@ -var test = require('tape') - -var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'] -var vectors = require('hash-test-vectors/hmac') -testLib('createHmac in crypto-browserify', require('../').createHmac) -testLib('create-hmac/browser', require('create-hmac/browser')) - -function testLib (name, createHmac) { - algorithms.forEach(function (alg) { - test(name + ' hmac(' + alg + ')', function (t) { - run(0) - function run (i) { - if (i >= vectors.length) { - return t.end() - } - var input = vectors[i] - var output = createHmac(alg, new Buffer(input.key, 'hex')) - .update(input.data, 'hex').digest() - - output = input.truncate ? output.slice(0, input.truncate) : output - output = output.toString('hex') - if (output !== input[alg]) { - t.equal(output, input[alg]) - } - setTimeout(run, 0, i + 1) - } - }) - - test('hmac(' + alg + ')', function (t) { - run(0) - function run (i) { - if (i >= vectors.length) { - return t.end() - } - var input = vectors[i] - var hmac = createHmac(alg, new Buffer(input.key, 'hex')) - - hmac.end(input.data, 'hex') - var output = hmac.read() - - output = input.truncate ? output.slice(0, input.truncate) : output - output = output.toString('hex') - if (output !== input[alg]) { - t.equal(output, input[alg]) - } - setTimeout(run, 0, i + 1) - } - }) - }) +'use strict'; + +var test = require('tape'); + +var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160']; +var vectors = require('hash-test-vectors/hmac'); + +function testLib(name, createHmac) { + algorithms.forEach(function (alg) { + test(name + ' hmac(' + alg + ')', function (t) { + function run(i) { + if (i >= vectors.length) { + t.end(); + return; + } + var input = vectors[i]; + var output = createHmac(alg, new Buffer(input.key, 'hex')) + .update(input.data, 'hex').digest(); + + output = input.truncate ? output.slice(0, input.truncate) : output; + output = output.toString('hex'); + if (output !== input[alg]) { + t.equal(output, input[alg]); + } + setTimeout(run, 0, i + 1); + } + + run(0); + }); + + test('hmac(' + alg + ')', function (t) { + function run(i) { + if (i >= vectors.length) { + t.end(); + return; + } + var input = vectors[i]; + var hmac = createHmac(alg, new Buffer(input.key, 'hex')); + + hmac.end(input.data, 'hex'); + var output = hmac.read(); + + output = input.truncate ? output.slice(0, input.truncate) : output; + output = output.toString('hex'); + if (output !== input[alg]) { + t.equal(output, input[alg]); + } + setTimeout(run, 0, i + 1); + } + + run(0); + }); + }); } + +testLib('createHmac in crypto-browserify', require('../').createHmac); +testLib('create-hmac/browser', require('create-hmac/browser')); diff --git a/test/dh.js b/test/dh.js index 61fd074..73dceeb 100644 --- a/test/dh.js +++ b/test/dh.js @@ -1,49 +1,60 @@ -var test = require('tape') -var crypto = require('diffie-hellman/browser') +'use strict'; + +var test = require('tape'); +var crypto = require('diffie-hellman/browser'); test('diffie-hellman mod groups', function (t) { - [ - 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16' - ].forEach(function (mod) { - t.test(mod, function (t) { - t.plan(3) - var dh1 = crypto.getDiffieHellman(mod) - var p1 = dh1.getPrime().toString('hex') - dh1.generateKeys() - var dh2 = crypto.getDiffieHellman(mod) - var p2 = dh2.getPrime().toString('hex') - dh2.generateKeys() - t.equals(p1, p2, 'equal primes') - var pubk1 = dh1.getPublicKey() - var pubk2 = dh2.getPublicKey() - t.notEquals(pubk1, pubk2, 'diff public keys') - var pub1 = dh1.computeSecret(pubk2).toString('hex') - var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex') - t.equals(pub1, pub2, 'equal secrets') - }) - }) -}) + [ + 'modp1', + 'modp2', + 'modp5', + 'modp14', + 'modp15', + 'modp16' + ].forEach(function (mod) { + t.test(mod, function (st) { + st.plan(3); + var dh1 = crypto.getDiffieHellman(mod); + var p1 = dh1.getPrime().toString('hex'); + dh1.generateKeys(); + var dh2 = crypto.getDiffieHellman(mod); + var p2 = dh2.getPrime().toString('hex'); + dh2.generateKeys(); + st.equals(p1, p2, 'equal primes'); + var pubk1 = dh1.getPublicKey(); + var pubk2 = dh2.getPublicKey(); + st.notEquals(pubk1, pubk2, 'diff public keys'); + var pub1 = dh1.computeSecret(pubk2).toString('hex'); + var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex'); + st.equals(pub1, pub2, 'equal secrets'); + }); + }); +}); test('diffie-hellman key lengths', function (t) { - [ - 64, 65, 192 - ].forEach(function (len) { - t.test('' + len, function (t) { - t.plan(3) - var dh2 = crypto.createDiffieHellman(len) - var prime2 = dh2.getPrime() - var p2 = prime2.toString('hex') - var dh1 = crypto.createDiffieHellman(prime2) - var p1 = dh1.getPrime().toString('hex') - dh1.generateKeys() - dh2.generateKeys() - t.equals(p1, p2, 'equal primes') - var pubk1 = dh1.getPublicKey() - var pubk2 = dh2.getPublicKey() - t.notEquals(pubk1, pubk2, 'diff public keys') - var pub1 = dh1.computeSecret(pubk2).toString('hex') - var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex') - t.equals(pub1, pub2, 'equal secrets') - }) - }) -}) + [ + 64, + 65, + 192 + ].forEach(function (len) { + t.test(String(len), function (st) { + st.plan(3); + var dh2 = crypto.createDiffieHellman(len); + var prime2 = dh2.getPrime(); + var p2 = prime2.toString('hex'); + var dh1 = crypto.createDiffieHellman(prime2); + var p1 = dh1.getPrime().toString('hex'); + dh1.generateKeys(); + dh2.generateKeys(); + st.equals(p1, p2, 'equal primes'); + + var pubk1 = dh1.getPublicKey(); + var pubk2 = dh2.getPublicKey(); + st.notEquals(pubk1, pubk2, 'diff public keys'); + + var pub1 = dh1.computeSecret(pubk2).toString('hex'); + var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex'); + st.equals(pub1, pub2, 'equal secrets'); + }); + }); +}); diff --git a/test/ecdh.js b/test/ecdh.js index 86b5aed..cb3f64f 100644 --- a/test/ecdh.js +++ b/test/ecdh.js @@ -1,61 +1,62 @@ +'use strict'; + var mods = [ - 'secp256k1', - 'secp224r1', - 'prime256v1', - 'prime192v1' -] -var test = require('tape') -var _crypto = require('../') -var createECDH1 = _crypto.createECDH -var createECDH2 = require('create-ecdh/browser') + 'secp256k1', + 'secp224r1', + 'prime256v1', + 'prime192v1' +]; +var test = require('tape'); +var createECDH1 = require('../').createECDH; +var createECDH2 = require('create-ecdh/browser'); mods.forEach(function (mod) { - test('createECDH: ' + mod + ' uncompressed', function (t) { - t.plan(2) - var dh1 = createECDH1(mod) - dh1.generateKeys() - var dh2 = createECDH2(mod) - dh2.generateKeys() - var pubk1 = dh1.getPublicKey() - var pubk2 = dh2.getPublicKey() - t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys') - var pub1 = dh1.computeSecret(pubk2).toString('hex') - var pub2 = dh2.computeSecret(pubk1).toString('hex') - t.equals(pub1, pub2, 'equal secrets') - }) + test('createECDH: ' + mod + ' uncompressed', function (t) { + t.plan(2); + var dh1 = createECDH1(mod); + dh1.generateKeys(); + var dh2 = createECDH2(mod); + dh2.generateKeys(); + var pubk1 = dh1.getPublicKey(); + var pubk2 = dh2.getPublicKey(); + t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys'); + var pub1 = dh1.computeSecret(pubk2).toString('hex'); + var pub2 = dh2.computeSecret(pubk1).toString('hex'); + t.equals(pub1, pub2, 'equal secrets'); + }); - test('createECDH: ' + mod + ' compressed', function (t) { - t.plan(2) - var dh1 = createECDH1(mod) - dh1.generateKeys() - var dh2 = createECDH2(mod) - dh2.generateKeys() - var pubk1 = dh1.getPublicKey(null, 'compressed') - var pubk2 = dh2.getPublicKey(null, 'compressed') - t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys') - var pub1 = dh1.computeSecret(pubk2).toString('hex') - var pub2 = dh2.computeSecret(pubk1).toString('hex') - t.equals(pub1, pub2, 'equal secrets') - }) + test('createECDH: ' + mod + ' compressed', function (t) { + t.plan(2); + var dh1 = createECDH1(mod); + dh1.generateKeys(); + var dh2 = createECDH2(mod); + dh2.generateKeys(); + var pubk1 = dh1.getPublicKey(null, 'compressed'); + var pubk2 = dh2.getPublicKey(null, 'compressed'); + t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys'); + var pub1 = dh1.computeSecret(pubk2).toString('hex'); + var pub2 = dh2.computeSecret(pubk1).toString('hex'); + t.equals(pub1, pub2, 'equal secrets'); + }); - test('createECDH: ' + mod + ' set stuff', function (t) { - t.plan(5) - var dh1 = createECDH1(mod) - var dh2 = createECDH2(mod) - dh1.generateKeys() - dh2.generateKeys() - dh1.setPrivateKey(dh2.getPrivateKey()) - dh1.setPublicKey(dh2.getPublicKey()) - var priv1 = dh1.getPrivateKey('hex') - var priv2 = dh2.getPrivateKey('hex') - t.equals(priv1, priv2, 'same private key') - var pubk1 = dh1.getPublicKey() - var pubk2 = dh2.getPublicKey() - t.equals(pubk1.toString('hex'), pubk2.toString('hex'), 'same public keys, uncompressed') - t.equals(dh1.getPublicKey('hex', 'compressed'), dh2.getPublicKey('hex', 'compressed'), 'same public keys compressed') - t.equals(dh1.getPublicKey('hex', 'hybrid'), dh2.getPublicKey('hex', 'hybrid'), 'same public keys hybrid') - var pub1 = dh1.computeSecret(pubk2).toString('hex') - var pub2 = dh2.computeSecret(pubk1).toString('hex') - t.equals(pub1, pub2, 'equal secrets') - }) -}) + test('createECDH: ' + mod + ' set stuff', function (t) { + t.plan(5); + var dh1 = createECDH1(mod); + var dh2 = createECDH2(mod); + dh1.generateKeys(); + dh2.generateKeys(); + dh1.setPrivateKey(dh2.getPrivateKey()); + dh1.setPublicKey(dh2.getPublicKey()); + var priv1 = dh1.getPrivateKey('hex'); + var priv2 = dh2.getPrivateKey('hex'); + t.equals(priv1, priv2, 'same private key'); + var pubk1 = dh1.getPublicKey(); + var pubk2 = dh2.getPublicKey(); + t.equals(pubk1.toString('hex'), pubk2.toString('hex'), 'same public keys, uncompressed'); + t.equals(dh1.getPublicKey('hex', 'compressed'), dh2.getPublicKey('hex', 'compressed'), 'same public keys compressed'); + t.equals(dh1.getPublicKey('hex', 'hybrid'), dh2.getPublicKey('hex', 'hybrid'), 'same public keys hybrid'); + var pub1 = dh1.computeSecret(pubk2).toString('hex'); + var pub2 = dh2.computeSecret(pubk1).toString('hex'); + t.equals(pub1, pub2, 'equal secrets'); + }); +}); diff --git a/test/index.js b/test/index.js index e48ee9b..4a214a2 100644 --- a/test/index.js +++ b/test/index.js @@ -1,18 +1,22 @@ -require('./create-hash') -require('./create-hmac') +'use strict'; + +/* eslint-disable global-require */ + +require('./create-hash'); +require('./create-hmac'); if (!process.browser) { - require('./dh') + require('./dh'); } -require('./pbkdf2') +require('./pbkdf2'); try { - require('randombytes')(8) - require('./ecdh') - require('./public-encrypt') - require('./random-bytes') - require('./sign') - require('./random-fill') + require('randombytes')(8); + require('./ecdh'); + require('./public-encrypt'); + require('./random-bytes'); + require('./sign'); + require('./random-fill'); } catch (e) { - console.log('no secure rng avaiable') + console.log('no secure rng avaiable'); } -require('./aes') +require('./aes'); diff --git a/test/node/dh.js b/test/node/dh.js index 0b3aa71..f395e08 100644 --- a/test/node/dh.js +++ b/test/node/dh.js @@ -1,51 +1,62 @@ -var test = require('tape') -var cryptoB = require('../../') -var crypto = require('crypto') +'use strict'; + +var test = require('tape'); +var cryptoB = require('../../'); +var crypto = require('crypto'); test('diffie-hellman mod groups', function (t) { - [ - 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16' - ].forEach(function (mod) { - t.test(mod, function (t) { - t.plan(3) - var dh1 = cryptoB.getDiffieHellman(mod) - var p1 = dh1.getPrime().toString('hex') - dh1.generateKeys() - - var dh2 = crypto.getDiffieHellman(mod) - var p2 = dh2.getPrime().toString('hex') - dh2.generateKeys() - t.equals(p1, p2, 'equal primes') - var pubk1 = dh1.getPublicKey() - var pubk2 = dh2.getPublicKey() - t.notEquals(pubk1, pubk2, 'diff public keys') - var pub1 = dh1.computeSecret(pubk2).toString('hex') - var pub2 = dh2.computeSecret(pubk1).toString('hex') - t.equals(pub1, pub2, 'equal secrets') - }) - }) -}) + [ + 'modp1', + 'modp2', + 'modp5', + 'modp14', + 'modp15', + 'modp16' + ].forEach(function (mod) { + t.test(mod, function (st) { + st.plan(3); + var dh1 = cryptoB.getDiffieHellman(mod); + var p1 = dh1.getPrime().toString('hex'); + dh1.generateKeys(); + + var dh2 = crypto.getDiffieHellman(mod); + var p2 = dh2.getPrime().toString('hex'); + dh2.generateKeys(); + st.equals(p1, p2, 'equal primes'); + + var pubk1 = dh1.getPublicKey(); + var pubk2 = dh2.getPublicKey(); + st.notEquals(pubk1, pubk2, 'diff public keys'); + + var pub1 = dh1.computeSecret(pubk2).toString('hex'); + var pub2 = dh2.computeSecret(pubk1).toString('hex'); + st.equals(pub1, pub2, 'equal secrets'); + }); + }); +}); test('diffie-hellman key lengths', function (t) { - [ - 64, 65, 192 - ].forEach(function (len) { - t.test('' + len, function (t) { - t.plan(3) - var dh2 = cryptoB.createDiffieHellman(len) - var prime2 = dh2.getPrime() - var p2 = prime2.toString('hex') - var dh1 = crypto.createDiffieHellman(prime2) - var p1 = dh1.getPrime().toString('hex') - dh1.generateKeys() - dh2.generateKeys() - t.equals(p1, p2, 'equal primes') - var pubk1 = dh1.getPublicKey() - var pubk2 = dh2.getPublicKey() - t.notEquals(pubk1, pubk2, 'diff public keys') - var pub1 = dh1.computeSecret(pubk2).toString('hex') - var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex') - t.equals(pub1, pub2, 'equal secrets') - }) - }) -}) + [ + 64, 65, 192 + ].forEach(function (len) { + t.test(String(len), function (st) { + t.plan(3); + var dh2 = cryptoB.createDiffieHellman(len); + var prime2 = dh2.getPrime(); + var p2 = prime2.toString('hex'); + var dh1 = crypto.createDiffieHellman(prime2); + var p1 = dh1.getPrime().toString('hex'); + dh1.generateKeys(); + dh2.generateKeys(); + st.equals(p1, p2, 'equal primes'); + + var pubk1 = dh1.getPublicKey(); + var pubk2 = dh2.getPublicKey(); + st.notEquals(pubk1, pubk2, 'diff public keys'); + + var pub1 = dh1.computeSecret(pubk2).toString('hex'); + var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex'); + st.equals(pub1, pub2, 'equal secrets'); + }); + }); +}); diff --git a/test/pbkdf2.js b/test/pbkdf2.js index 084014e..bd3bb9a 100644 --- a/test/pbkdf2.js +++ b/test/pbkdf2.js @@ -1,21 +1,23 @@ -var tape = require('tape') -var crypto = require('pbkdf2/browser') +'use strict'; -var vectors = require('hash-test-vectors/pbkdf2') +var tape = require('tape'); +var crypto = require('pbkdf2/browser'); + +var vectors = require('hash-test-vectors/pbkdf2'); tape('pbkdf2', function (t) { - vectors.forEach(function (input) { - // skip inputs that will take way too long - if (input.iterations > 10000) return + vectors.forEach(function (input) { + // skip inputs that will take way too long + if (input.iterations > 10000) { return; } - var key = crypto.pbkdf2Sync(input.password, input.salt, input.iterations, input.length) + var key = crypto.pbkdf2Sync(input.password, input.salt, input.iterations, input.length); - if (key.toString('hex') !== input.sha1) { - console.log(input) - } + if (key.toString('hex') !== input.sha1) { + console.log(input); + } - t.equal(key.toString('hex'), input.sha1) - }) + t.equal(key.toString('hex'), input.sha1); + }); - t.end() -}) + t.end(); +}); diff --git a/test/public-encrypt.js b/test/public-encrypt.js index edb435c..e240873 100644 --- a/test/public-encrypt.js +++ b/test/public-encrypt.js @@ -1,36 +1,39 @@ -var test = require('tape') -var crypto1 = require('../') +'use strict'; + +var test = require('tape'); +var crypto1 = require('../'); var rsa = { - 'private': '2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a', - 'public': '2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a' -} -var crypto2 = require('public-encrypt/browser') -rsa.private = new Buffer(rsa.private, 'hex') -rsa.public = new Buffer(rsa.public, 'hex') -var encrypted = '0bcd6462ad7a563be2d42b0b73e0b0a163886304e7723b025f97605144fe1781e84acdc4031327d6bccd67fe13183e8fbdc8c5fe947b49d011ce3ebb08b11e83b87a77328ca57ee77cfdc78743b0749366643d7a21b2abcd4aa32dee9832938445540ee3007b7a70191c8dc9ff2ad76fe8dfaa5362d9d2c4b31a67b816d7b7970a293cb95bf3437a301bedb9f431b7075aa2f9df77b4385bea2a37982beda467260b384a58258b5eb4e36a0e0bf7dff83589636f5f97bf542084f0f76868c9f3f989a27fee5b8cd2bfee0bae1eae958df7c3184e5a40fda101196214f371606feca4330b221f30577804bbd4f61578a84e85dcd298849f509e630d275280' + 'private': '2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a', + 'public': '2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a' +}; +var crypto2 = require('public-encrypt/browser'); +rsa['private'] = new Buffer(rsa['private'], 'hex'); +rsa['public'] = new Buffer(rsa['public'], 'hex'); + +var encrypted = '0bcd6462ad7a563be2d42b0b73e0b0a163886304e7723b025f97605144fe1781e84acdc4031327d6bccd67fe13183e8fbdc8c5fe947b49d011ce3ebb08b11e83b87a77328ca57ee77cfdc78743b0749366643d7a21b2abcd4aa32dee9832938445540ee3007b7a70191c8dc9ff2ad76fe8dfaa5362d9d2c4b31a67b816d7b7970a293cb95bf3437a301bedb9f431b7075aa2f9df77b4385bea2a37982beda467260b384a58258b5eb4e36a0e0bf7dff83589636f5f97bf542084f0f76868c9f3f989a27fee5b8cd2bfee0bae1eae958df7c3184e5a40fda101196214f371606feca4330b221f30577804bbd4f61578a84e85dcd298849f509e630d275280'; test('publicEncrypt/privateDecrypt', function (t) { - t.test('can decrypt', function (t) { - t.plan(2) - // note encryption is ranomized so can't test to see if they encrypt the same - t.equals(crypto1.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly') - t.equals(crypto2.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly') - }) - t.test('can round trip', function (t) { - t.plan(2) - var msg = 'this is a message' - // note encryption is ranomized so can't test to see if they encrypt the same - t.equals(crypto1.privateDecrypt(rsa.private, crypto2.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it') - t.equals(crypto2.privateDecrypt(rsa.private, crypto1.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it') - }) -}) + t.test('can decrypt', function (st) { + st.plan(2); + // note encryption is ranomized so can't test to see if they encrypt the same + st.equals(crypto1.privateDecrypt(rsa['private'], new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly'); + st.equals(crypto2.privateDecrypt(rsa['private'], new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly'); + }); + t.test('can round trip', function (st) { + st.plan(2); + var msg = 'this is a message'; + // note encryption is ranomized so can't test to see if they encrypt the same + st.equals(crypto1.privateDecrypt(rsa['private'], crypto2.publicEncrypt(rsa['public'], new Buffer(msg))).toString(), msg, 'round trip it'); + st.equals(crypto2.privateDecrypt(rsa['private'], crypto1.publicEncrypt(rsa['public'], new Buffer(msg))).toString(), msg, 'round trip it'); + }); +}); test('privateEncrypt/publicDecrypt', function (t) { - t.test('can round trip', function (t) { - t.plan(2) - var msg = 'this is a message' - // note encryption is ranomized so can't test to see if they encrypt the same - t.equals(crypto1.publicDecrypt(rsa.public, crypto2.privateEncrypt(rsa.private, new Buffer(msg))).toString(), msg, 'round trip it') - t.equals(crypto2.publicDecrypt(rsa.public, crypto1.privateEncrypt(rsa.private, new Buffer(msg))).toString(), msg, 'round trip it') - }) -}) + t.test('can round trip', function (st) { + st.plan(2); + var msg = 'this is a message'; + // note encryption is ranomized so can't test to see if they encrypt the same + st.equals(crypto1.publicDecrypt(rsa['public'], crypto2.privateEncrypt(rsa['private'], new Buffer(msg))).toString(), msg, 'round trip it'); + st.equals(crypto2.publicDecrypt(rsa['public'], crypto1.privateEncrypt(rsa['private'], new Buffer(msg))).toString(), msg, 'round trip it'); + }); +}); diff --git a/test/random-bytes.js b/test/random-bytes.js index 398af24..a969697 100644 --- a/test/random-bytes.js +++ b/test/random-bytes.js @@ -1,60 +1,64 @@ -var test = require('tape') -var crypto = require('../') +'use strict'; + +var test = require('tape'); +var crypto = require('../'); +var randomBytes = require('randombytes'); var randomBytesFunctions = { - randomBytes: require('randombytes'), - pseudoRandomBytes: crypto.pseudoRandomBytes -} - -for (var randomBytesName in randomBytesFunctions) { - // Both randomBytes and pseudoRandomBytes should provide the same interface - var randomBytes = randomBytesFunctions[randomBytesName] - - test('get error message', function (t) { - try { - var b = randomBytes(10) - t.ok(Buffer.isBuffer(b)) - t.end() - } catch (err) { - t.ok(/not supported/.test(err.message), '"not supported" is in error message') - t.end() - } - }) - - test(randomBytesName, function (t) { - t.plan(5) - t.equal(randomBytes(10).length, 10) - t.ok(Buffer.isBuffer(randomBytes(10))) - randomBytes(10, function (ex, bytes) { - t.error(ex) - t.equal(bytes.length, 10) - t.ok(Buffer.isBuffer(bytes)) - t.end() - }) - }) - - test(randomBytesName + ' seem random', function (t) { - var L = 1000 - var b = randomBytes(L) - - var mean = [].reduce.call(b, function (a, b) { return a + b }, 0) / L - - // test that the random numbers are plausably random. - // Math.random() will pass this, but this will catch - // terrible mistakes such as this blunder: - // https://github.com/dominictarr/crypto-browserify/commit/3267955e1df7edd1680e52aeede9a89506ed2464#commitcomment-7916835 - - // this doesn't check that the bytes are in a random *order* - // but it's better than nothing. - - var expected = 256 / 2 - var smean = Math.sqrt(mean) - - // console.log doesn't work right on testling, *grumble grumble* - console.log(JSON.stringify([expected - smean, mean, expected + smean])) - t.ok(mean < expected + smean) - t.ok(mean > expected - smean) - - t.end() - }) -} + randomBytes: randomBytes, + pseudoRandomBytes: crypto.pseudoRandomBytes +}; + +// Both randomBytes and pseudoRandomBytes should provide the same interface +Object.entries(randomBytesFunctions).forEach(function (entry) { + var randomBytesName = entry[0]; + var randomBytesFn = entry[1]; + + test('get error message', function (t) { + try { + var b = randomBytesFn(10); + t.ok(Buffer.isBuffer(b)); + t.end(); + } catch (err) { + t.ok((/not supported/).test(err.message), '"not supported" is in error message'); + t.end(); + } + }); + + test(randomBytesName, function (t) { + t.plan(5); + t.equal(randomBytesFn(10).length, 10); + t.ok(Buffer.isBuffer(randomBytesFn(10))); + randomBytesFn(10, function (ex, bytes) { + t.error(ex); + t.equal(bytes.length, 10); + t.ok(Buffer.isBuffer(bytes)); + t.end(); + }); + }); + + test(randomBytesName + ' seem random', function (t) { + var L = 1000; + var buffer = randomBytesFn(L); + + var mean = Array.prototype.reduce.call(buffer, function (a, b) { return a + b; }, 0) / L; + + // test that the random numbers are plausably random. + // Math.random() will pass this, but this will catch + // terrible mistakes such as this blunder: + // https://github.com/dominictarr/crypto-browserify/commit/3267955e1df7edd1680e52aeede9a89506ed2464#commitcomment-7916835 + + // this doesn't check that the bytes are in a random *order* + // but it's better than nothing. + + var expected = 256 / 2; + var smean = Math.sqrt(mean); + + // console.log doesn't work right on testling, *grumble grumble* + console.log(JSON.stringify([expected - smean, mean, expected + smean])); + t.ok(mean < expected + smean); + t.ok(mean > expected - smean); + + t.end(); + }); +}); diff --git a/test/random-fill.js b/test/random-fill.js index 63c885a..b54912b 100644 --- a/test/random-fill.js +++ b/test/random-fill.js @@ -1,53 +1,55 @@ -var test = require('tape') -var crypto = require('../') -var Buffer = require('safe-buffer').Buffer +'use strict'; + +var test = require('tape'); +var crypto = require('../'); +var Buffer = require('safe-buffer').Buffer; test('get error message', function (t) { - try { - var b = crypto.randomFillSync(Buffer.alloc(10)) - t.ok(Buffer.isBuffer(b)) - t.end() - } catch (err) { - t.ok(/not supported/.test(err.message), '"not supported" is in error message') - t.end() - } -}) + try { + var b = crypto.randomFillSync(Buffer.alloc(10)); + t.ok(Buffer.isBuffer(b)); + t.end(); + } catch (err) { + t.ok((/not supported/).test(err.message), '"not supported" is in error message'); + t.end(); + } +}); test('randomfill', function (t) { - t.plan(5) - t.equal(crypto.randomFillSync(Buffer.alloc(10)).length, 10) - t.ok(Buffer.isBuffer(crypto.randomFillSync(Buffer.alloc(10)))) - crypto.randomFill(Buffer.alloc(10), function (ex, bytes) { - t.error(ex) - t.equal(bytes.length, 10) - t.ok(Buffer.isBuffer(bytes)) - t.end() - }) -}) + t.plan(5); + t.equal(crypto.randomFillSync(Buffer.alloc(10)).length, 10); + t.ok(Buffer.isBuffer(crypto.randomFillSync(Buffer.alloc(10)))); + crypto.randomFill(Buffer.alloc(10), function (ex, bytes) { + t.error(ex); + t.equal(bytes.length, 10); + t.ok(Buffer.isBuffer(bytes)); + t.end(); + }); +}); test('seems random', function (t) { - var L = 1000 - var b = crypto.randomFillSync(Buffer.alloc(L)) + var L = 1000; + var buffer = crypto.randomFillSync(Buffer.alloc(L)); - var mean = [].reduce.call(b, function (a, b) { - return a + b - }, 0) / L + var mean = Array.prototype.reduce.call(buffer, function (a, b) { + return a + b; + }, 0) / L; - // test that the random numbers are plausably random. - // Math.random() will pass this, but this will catch - // terrible mistakes such as this blunder: - // https://github.com/dominictarr/crypto-browserify/commit/3267955e1df7edd1680e52aeede9a89506ed2464#commitcomment-7916835 + // test that the random numbers are plausably random. + // Math.random() will pass this, but this will catch + // terrible mistakes such as this blunder: + // https://github.com/dominictarr/crypto-browserify/commit/3267955e1df7edd1680e52aeede9a89506ed2464#commitcomment-7916835 - // this doesn't check that the bytes are in a random *order* - // but it's better than nothing. + // this doesn't check that the bytes are in a random *order* + // but it's better than nothing. - var expected = 256 / 2 - var smean = Math.sqrt(mean) + var expected = 256 / 2; + var smean = Math.sqrt(mean); - // console.log doesn't work right on testling, *grumble grumble* - console.log(JSON.stringify([expected - smean, mean, expected + smean])) - t.ok(mean < expected + smean) - t.ok(mean > expected - smean) + // console.log doesn't work right on testling, *grumble grumble* + console.log(JSON.stringify([expected - smean, mean, expected + smean])); + t.ok(mean < expected + smean); + t.ok(mean > expected - smean); - t.end() -}) + t.end(); +}); diff --git a/test/sign.js b/test/sign.js index c91b666..7e05d52 100644 --- a/test/sign.js +++ b/test/sign.js @@ -1,59 +1,61 @@ -var test = require('tape') -var nodeCrypto = require('../') -var ourCrypto = require('browserify-sign/browser') +'use strict'; + +var test = require('tape'); +var nodeCrypto = require('../'); +var ourCrypto = require('browserify-sign/browser'); var rsa = { - 'private': '2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a', - 'public': '2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a' -} + 'private': '2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a', + 'public': '2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a' +}; var ec = { - 'private': '2d2d2d2d2d424547494e2045432050524956415445204b45592d2d2d2d2d0a4d485143415145454944463658763853762f2f77475557442b6337383070704772553051645a5743417a78415150515838722f756f416347425375424241414b0a6f55514451674145495a656f7744796c6c73344b2f7766426a4f313862596f37674778386e595152696a6134652f71454d696b4f484a616937676565557265550a7235586b792f4178377332644774656773504e7350674765354d705176673d3d0a2d2d2d2d2d454e442045432050524956415445204b45592d2d2d2d2d0a', - 'public': '2d2d2d2d2d424547494e205055424c4943204b45592d2d2d2d2d0a4d465977454159484b6f5a497a6a3043415159464b34454541416f4451674145495a656f7744796c6c73344b2f7766426a4f313862596f37674778386e5951520a696a6134652f71454d696b4f484a616937676565557265557235586b792f4178377332644774656773504e7350674765354d705176673d3d0a2d2d2d2d2d454e44205055424c4943204b45592d2d2d2d2d0a' -} - -rsa.private = new Buffer(rsa.private, 'hex') -rsa.public = new Buffer(rsa.public, 'hex') -ec.private = new Buffer(ec.private, 'hex') -ec.public = new Buffer(ec.public, 'hex') - -function testit (keys, message, scheme) { - var pub = keys.public - var priv = keys.private - test(message.toString(), function (t) { - t.test('js sign and verify', function (t) { - t.plan(t) - var mySign = ourCrypto.createSign(scheme) - var mySig = mySign.update(message).sign(priv) - var myVer = ourCrypto.createVerify(scheme) - t.ok(myVer.update(message).verify(pub, mySig), 'validates') - }) - - t.test('node sign and verify', function (t) { - t.plan(t) - var mySign = nodeCrypto.createSign(scheme) - var mySig = mySign.update(message).sign(priv) - var myVer = nodeCrypto.createVerify(scheme) - t.ok(myVer.update(message).verify(pub, mySig), 'validates') - }) - - t.test('node sign and js verify', function (t) { - t.plan(t) - var mySign = nodeCrypto.createSign(scheme) - var mySig = mySign.update(message).sign(priv) - var myVer = ourCrypto.createVerify(scheme) - t.ok(myVer.update(message).verify(pub, mySig), 'validates') - }) - - t.test('js sign and node verify', function (t) { - t.plan(t) - var mySign = ourCrypto.createSign(scheme) - var mySig = mySign.update(message).sign(priv) - var myVer = nodeCrypto.createVerify(scheme) - t.ok(myVer.update(message).verify(pub, mySig), 'validates') - }) - }) + 'private': '2d2d2d2d2d424547494e2045432050524956415445204b45592d2d2d2d2d0a4d485143415145454944463658763853762f2f77475557442b6337383070704772553051645a5743417a78415150515838722f756f416347425375424241414b0a6f55514451674145495a656f7744796c6c73344b2f7766426a4f313862596f37674778386e595152696a6134652f71454d696b4f484a616937676565557265550a7235586b792f4178377332644774656773504e7350674765354d705176673d3d0a2d2d2d2d2d454e442045432050524956415445204b45592d2d2d2d2d0a', + 'public': '2d2d2d2d2d424547494e205055424c4943204b45592d2d2d2d2d0a4d465977454159484b6f5a497a6a3043415159464b34454541416f4451674145495a656f7744796c6c73344b2f7766426a4f313862596f37674778386e5951520a696a6134652f71454d696b4f484a616937676565557265557235586b792f4178377332644774656773504e7350674765354d705176673d3d0a2d2d2d2d2d454e44205055424c4943204b45592d2d2d2d2d0a' +}; + +rsa['private'] = new Buffer(rsa['private'], 'hex'); +rsa['public'] = new Buffer(rsa['public'], 'hex'); +ec['private'] = new Buffer(ec['private'], 'hex'); +ec['public'] = new Buffer(ec['public'], 'hex'); + +function testit(keys, message, scheme) { + var pub = keys['public']; + var priv = keys['private']; + test(message.toString(), function (t) { + t.test('js sign and verify', function (st) { + st.plan(1); + var mySign = ourCrypto.createSign(scheme); + var mySig = mySign.update(message).sign(priv); + var myVer = ourCrypto.createVerify(scheme); + st.ok(myVer.update(message).verify(pub, mySig), 'validates'); + }); + + t.test('node sign and verify', function (st) { + st.plan(1); + var mySign = nodeCrypto.createSign(scheme); + var mySig = mySign.update(message).sign(priv); + var myVer = nodeCrypto.createVerify(scheme); + st.ok(myVer.update(message).verify(pub, mySig), 'validates'); + }); + + t.test('node sign and js verify', function (st) { + st.plan(1); + var mySign = nodeCrypto.createSign(scheme); + var mySig = mySign.update(message).sign(priv); + var myVer = ourCrypto.createVerify(scheme); + st.ok(myVer.update(message).verify(pub, mySig), 'validates'); + }); + + t.test('js sign and node verify', function (st) { + st.plan(1); + var mySign = ourCrypto.createSign(scheme); + var mySig = mySign.update(message).sign(priv); + var myVer = nodeCrypto.createVerify(scheme); + st.ok(myVer.update(message).verify(pub, mySig), 'validates'); + }); + }); } -testit(rsa, new Buffer('rsa with sha256'), 'RSA-SHA256') -testit(ec, new Buffer('ec with sha1'), 'sha256') +testit(rsa, new Buffer('rsa with sha256'), 'RSA-SHA256'); +testit(ec, new Buffer('ec with sha1'), 'sha256'); From 7d8170e32730cfe0c60bc6eb07e61b21f7a989ac Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 24 Nov 2023 22:21:00 -0800 Subject: [PATCH 203/217] Only apps should have lockfiles --- .gitignore | 7 +++++++ .npmrc | 1 + 2 files changed, 8 insertions(+) create mode 100644 .npmrc diff --git a/.gitignore b/.gitignore index 3c3629e..c77d1b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,8 @@ +# gitignore + node_modules + +# Only apps should have lockfiles +npm-shrinkwrap.json +package-lock.json +yarn.lock diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false From e592c95f711cacf9068bcd949c7bc24a47503fc3 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 24 Nov 2023 21:57:48 -0800 Subject: [PATCH 204/217] [Dev Deps] update `safe-buffer`, `tape`, `zuul` --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index e2f1155..89c0b62 100644 --- a/package.json +++ b/package.json @@ -34,11 +34,11 @@ "devDependencies": { "@ljharb/eslint-config": "^21.1.0", "eslint": "=8.8.0", - "hash-test-vectors": "~1.3.2", + "hash-test-vectors": "^1.3.2", "pseudorandombytes": "^2.0.0", - "safe-buffer": "^5.1.1", - "tape": "~2.3.2", - "zuul": "^3.6.0" + "safe-buffer": "^5.2.1", + "tape": "^5.7.2", + "zuul": "^3.12.0" }, "browser": { "crypto": false From 575721913b78980b598e3a730679176c9922ce16 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 24 Nov 2023 22:30:16 -0800 Subject: [PATCH 205/217] [Tests] refactor so tests are not recursive --- test/aes.js | 8 ++------ test/create-hash.js | 25 ++++++------------------- test/create-hmac.js | 32 ++++++++------------------------ test/node/dh.js | 7 +++++-- 4 files changed, 21 insertions(+), 51 deletions(-) diff --git a/test/aes.js b/test/aes.js index 8d72940..02b7b9a 100644 --- a/test/aes.js +++ b/test/aes.js @@ -5,9 +5,10 @@ var bcCrypto = require('browserify-cipher/browser'); var bcCyphers = bcCrypto.getCiphers(); var randomBytes = require('pseudorandombytes'); -function runIt(i) { +for (var i = 0; i < 4; i += 1) { bcCrypto.listCiphers().forEach(function (cipher) { test('run: ' + i, function (t) { + /* eslint no-loop-func: 0 */ t.test('ciphers: ' + cipher, function (st) { st.plan(1); var data = randomBytes(562); @@ -26,13 +27,8 @@ function runIt(i) { }); }); }); - if (i < 4) { - setTimeout(runIt, 0, i + 1); - } } -runIt(1); - test('getCiphers', function (t) { t.plan(1); t.ok(bcCyphers.length, 'get ciphers returns an array'); diff --git a/test/create-hash.js b/test/create-hash.js index 54c7474..be3ef07 100644 --- a/test/create-hash.js +++ b/test/create-hash.js @@ -8,40 +8,27 @@ var vectors = require('hash-test-vectors'); function runTest(name, createHash, algorithm) { test(name + ' test ' + algorithm + ' against test vectors', function (t) { - function run(i) { - if (i >= vectors.length) { - t.end(); - return; - } - var obj = vectors[i]; - + vectors.forEach(function (obj, i) { var input = new Buffer(obj.input, 'base64'); var node = obj[algorithm]; var js = createHash(algorithm).update(input).digest('hex'); - if (js !== node) { - t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node); - } + t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node); encodings.forEach(function (encoding) { var eInput = new Buffer(obj.input, 'base64').toString(encoding); var eNode = obj[algorithm]; var eJS = createHash(algorithm).update(eInput, encoding).digest('hex'); - if (eJS !== eNode) { - t.equal(eJS, eNode, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + eNode); - } + t.equal(eJS, eNode, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + eNode); }); input = new Buffer(obj.input, 'base64'); node = obj[algorithm]; var hash = createHash(algorithm); hash.end(input); js = hash.read().toString('hex'); - if (js !== node) { - t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node); - } - setTimeout(run, 0, i + 1); - } + t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node); + }); - run(0); + t.end(); }); } diff --git a/test/create-hmac.js b/test/create-hmac.js index 36641e4..5460653 100644 --- a/test/create-hmac.js +++ b/test/create-hmac.js @@ -8,33 +8,20 @@ var vectors = require('hash-test-vectors/hmac'); function testLib(name, createHmac) { algorithms.forEach(function (alg) { test(name + ' hmac(' + alg + ')', function (t) { - function run(i) { - if (i >= vectors.length) { - t.end(); - return; - } - var input = vectors[i]; + vectors.forEach(function (input) { var output = createHmac(alg, new Buffer(input.key, 'hex')) .update(input.data, 'hex').digest(); output = input.truncate ? output.slice(0, input.truncate) : output; output = output.toString('hex'); - if (output !== input[alg]) { - t.equal(output, input[alg]); - } - setTimeout(run, 0, i + 1); - } + t.equal(output, input[alg]); + }); - run(0); + t.end(); }); test('hmac(' + alg + ')', function (t) { - function run(i) { - if (i >= vectors.length) { - t.end(); - return; - } - var input = vectors[i]; + vectors.forEach(function (input) { var hmac = createHmac(alg, new Buffer(input.key, 'hex')); hmac.end(input.data, 'hex'); @@ -42,13 +29,10 @@ function testLib(name, createHmac) { output = input.truncate ? output.slice(0, input.truncate) : output; output = output.toString('hex'); - if (output !== input[alg]) { - t.equal(output, input[alg]); - } - setTimeout(run, 0, i + 1); - } + t.equal(output, input[alg]); + }); - run(0); + t.end(); }); }); } diff --git a/test/node/dh.js b/test/node/dh.js index f395e08..dec30fa 100644 --- a/test/node/dh.js +++ b/test/node/dh.js @@ -37,10 +37,13 @@ test('diffie-hellman mod groups', function (t) { test('diffie-hellman key lengths', function (t) { [ - 64, 65, 192 + 64, + 65, + 192 ].forEach(function (len) { t.test(String(len), function (st) { - t.plan(3); + st.plan(3); + var dh2 = cryptoB.createDiffieHellman(len); var prime2 = dh2.getPrime(); var p2 = prime2.toString('hex'); From 7223ce7f15049353cd1af2978488ac72bd0e615d Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 27 Nov 2023 08:59:39 -0800 Subject: [PATCH 206/217] [meta] update repo URLs Fixes #228. --- README.md | 2 +- example/bundle.js | 6 +----- index.js | 16 ++++++---------- package.json | 4 ++-- test/random-bytes.js | 2 +- test/random-fill.js | 2 +- 6 files changed, 12 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 1b9cf3b..f93291b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A port of node's `crypto` module to the browser. -[![Build Status](https://travis-ci.org/crypto-browserify/crypto-browserify.svg?branch=master)](https://travis-ci.org/crypto-browserify/crypto-browserify) +[![Build Status](https://travis-ci.org/browserify/crypto-browserify.svg?branch=master)](https://travis-ci.org/browserify/crypto-browserify) [![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard) [![Sauce Test Status](https://saucelabs.com/browser-matrix/crypto-browserify.svg)](https://saucelabs.com/u/crypto-browserify) diff --git a/example/bundle.js b/example/bundle.js index 479f804..2bf583d 100644 --- a/example/bundle.js +++ b/example/bundle.js @@ -359,11 +359,7 @@ require.define('/node_modules/crypto-browserify/index.js', function (require, mo function error() { var m = Array.prototype.slice.call(arguments).join(' '); - throw new Error([ - m, - 'we accept pull requests', - 'http://github.com/dominictarr/crypto-browserify' - ].join('\n')); + throw new Error(m+'\nwe accept pull requests\nhttp://github.com/browserify/crypto-browserify'.join('\n')); } exports.createHash = function (alg) { diff --git a/index.js b/index.js index 233a9c7..44a2edf 100644 --- a/index.js +++ b/index.js @@ -67,12 +67,12 @@ exports.publicDecrypt = publicEncrypt.publicDecrypt; exports.privateDecrypt = publicEncrypt.privateDecrypt; // the least I can do is make error messages for the rest of the node.js/crypto api. -// ;[ -// 'createCredentials' +// [ +// 'createCredentials' // ].forEach(function (name) { -// exports[name] = function () { -// throw new Error('sorry, ' + name + ' is not implemented yet\nwe accept pull requests\nhttps://github.com/crypto-browserify/crypto-browserify'); -// }; +// exports[name] = function () { +// throw new Error('sorry, ' + name + ' is not implemented yet\nwe accept pull requests\nhttps://github.com/browserify/crypto-browserify'); +// }; // }); var rf = require('randomfill'); @@ -81,11 +81,7 @@ exports.randomFill = rf.randomFill; exports.randomFillSync = rf.randomFillSync; exports.createCredentials = function () { - throw new Error([ - 'sorry, createCredentials is not implemented yet', - 'we accept pull requests', - 'https://github.com/crypto-browserify/crypto-browserify' - ].join('\n')); + throw new Error('sorry, createCredentials is not implemented yet\nwe accept pull requests\nhttps://github.com/browserify/crypto-browserify'); }; exports.constants = { diff --git a/package.json b/package.json index 89c0b62..734bd6c 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,10 @@ "name": "crypto-browserify", "description": "implementation of crypto for the browser", "version": "3.12.0", - "homepage": "https://github.com/crypto-browserify/crypto-browserify", + "homepage": "https://github.com/browserify/crypto-browserify", "repository": { "type": "git", - "url": "git://github.com/crypto-browserify/crypto-browserify.git" + "url": "git://github.com/browserify/crypto-browserify.git" }, "scripts": { "lint": "eslint --ext=js,mjs .", diff --git a/test/random-bytes.js b/test/random-bytes.js index a969697..9c1a61a 100644 --- a/test/random-bytes.js +++ b/test/random-bytes.js @@ -46,7 +46,7 @@ Object.entries(randomBytesFunctions).forEach(function (entry) { // test that the random numbers are plausably random. // Math.random() will pass this, but this will catch // terrible mistakes such as this blunder: - // https://github.com/dominictarr/crypto-browserify/commit/3267955e1df7edd1680e52aeede9a89506ed2464#commitcomment-7916835 + // https://github.com/browserify/crypto-browserify/commit/3267955e1df7edd1680e52aeede9a89506ed2464#commitcomment-7916835 // this doesn't check that the bytes are in a random *order* // but it's better than nothing. diff --git a/test/random-fill.js b/test/random-fill.js index b54912b..03d4585 100644 --- a/test/random-fill.js +++ b/test/random-fill.js @@ -38,7 +38,7 @@ test('seems random', function (t) { // test that the random numbers are plausably random. // Math.random() will pass this, but this will catch // terrible mistakes such as this blunder: - // https://github.com/dominictarr/crypto-browserify/commit/3267955e1df7edd1680e52aeede9a89506ed2464#commitcomment-7916835 + // https://github.com/browserify/crypto-browserify/commit/3267955e1df7edd1680e52aeede9a89506ed2464#commitcomment-7916835 // this doesn't check that the bytes are in a random *order* // but it's better than nothing. From 0a9aab4645d6b6c2829ce7a029c8fcc445d3ccc1 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 27 Nov 2023 09:02:15 -0800 Subject: [PATCH 207/217] [Tests] rename test scripts to match my conventions --- .travis.yml | 6 +++--- package.json | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3b77be7..c7be687 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,11 +3,11 @@ language: node_js matrix: include: - node_js: '0.11' - env: TEST_SUITE=unit + env: TEST_SUITE=tests-only - node_js: '0.12' - env: TEST_SUITE=unit + env: TEST_SUITE=tests-only - node_js: '4' - env: TEST_SUITE=unit + env: TEST_SUITE=tests-only - node_js: '4' env: TEST_SUITE=lint - node_js: '4' diff --git a/package.json b/package.json index 734bd6c..98d8f39 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,9 @@ "scripts": { "lint": "eslint --ext=js,mjs .", "pretest": "npm run lint", - "test": "npm run unit", - "unit": "node test/", + "tests-only": "tape 'test/**/*.js'", + "test": "npm run tests-only", + "posttest": "aud --production", "browser": "zuul --browser-version $BROWSER_VERSION --browser-name $BROWSER_NAME -- test/index.js" }, "engines": { @@ -33,6 +34,7 @@ }, "devDependencies": { "@ljharb/eslint-config": "^21.1.0", + "aud": "^2.0.3", "eslint": "=8.8.0", "hash-test-vectors": "^1.3.2", "pseudorandombytes": "^2.0.0", From 1179f7c7f5c5152d45dbad34da9d3b381bd31929 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 24 Nov 2023 22:31:29 -0800 Subject: [PATCH 208/217] [Deps] update `browserify-cipher browserify-sign `, `create-ecdh`, `create-hash`, `create-hmac`, `diffie-hellman`, `inherits`, `pbkdf2`, `public-encrypt`, `randombytes`, `randomfill` --- package.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 98d8f39..2f4e9aa 100644 --- a/package.json +++ b/package.json @@ -20,17 +20,17 @@ "node": "*" }, "dependencies": { - "browserify-cipher": "^1.0.0", - "browserify-sign": "^4.0.0", - "create-ecdh": "^4.0.0", - "create-hash": "^1.1.0", - "create-hmac": "^1.1.0", - "diffie-hellman": "^5.0.0", - "inherits": "^2.0.1", - "pbkdf2": "^3.0.3", - "public-encrypt": "^4.0.0", - "randombytes": "^2.0.0", - "randomfill": "^1.0.3" + "browserify-cipher": "^1.0.1", + "browserify-sign": "^4.2.2", + "create-ecdh": "^4.0.4", + "create-hash": "^1.2.0", + "create-hmac": "^1.1.7", + "diffie-hellman": "^5.0.3", + "inherits": "^2.0.4", + "pbkdf2": "^3.1.2", + "public-encrypt": "^4.0.3", + "randombytes": "^2.1.0", + "randomfill": "^1.0.4" }, "devDependencies": { "@ljharb/eslint-config": "^21.1.0", From 33596f68f09a27f7ee66dc23388532f4193b8e59 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 27 Nov 2023 10:22:48 -0800 Subject: [PATCH 209/217] [Tests] node 17+ requires a DH key length of >= 512 --- test/node/dh.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/node/dh.js b/test/node/dh.js index dec30fa..6f7e75d 100644 --- a/test/node/dh.js +++ b/test/node/dh.js @@ -3,6 +3,7 @@ var test = require('tape'); var cryptoB = require('../../'); var crypto = require('crypto'); +var semverSatisfies = require('semver/functions/satisfies'); test('diffie-hellman mod groups', function (t) { [ @@ -39,11 +40,12 @@ test('diffie-hellman key lengths', function (t) { [ 64, 65, - 192 + 192, + 512, + 1024 ].forEach(function (len) { - t.test(String(len), function (st) { - st.plan(3); - + var modulusTooSmall = semverSatisfies(process.version, '>= 17') && len < 512; + t.test(String(len), { skip: modulusTooSmall && 'node 17+ requires a length >= 512' }, function (st) { var dh2 = cryptoB.createDiffieHellman(len); var prime2 = dh2.getPrime(); var p2 = prime2.toString('hex'); @@ -60,6 +62,8 @@ test('diffie-hellman key lengths', function (t) { var pub1 = dh1.computeSecret(pubk2).toString('hex'); var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex'); st.equals(pub1, pub2, 'equal secrets'); + + st.end(); }); }); }); From 797455f7ac00c4a1cd851e916dc545cd20b7288f Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 27 Nov 2023 11:57:34 -0800 Subject: [PATCH 210/217] =?UTF-8?q?[Tests]=20node=2017=20doesn=E2=80=99t?= =?UTF-8?q?=20support=20rmd160?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/create-hash.js | 49 +++++++++++++++++++-------------- test/create-hmac.js | 67 +++++++++++++++++++++++++++------------------ 2 files changed, 69 insertions(+), 47 deletions(-) diff --git a/test/create-hash.js b/test/create-hash.js index be3ef07..e3f0346 100644 --- a/test/create-hash.js +++ b/test/create-hash.js @@ -1,35 +1,44 @@ 'use strict'; var test = require('tape'); +var satisfies = require('semver/functions/satisfies'); var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160']; var encodings = ['hex', 'base64']; // FIXME: test binary var vectors = require('hash-test-vectors'); function runTest(name, createHash, algorithm) { - test(name + ' test ' + algorithm + ' against test vectors', function (t) { - vectors.forEach(function (obj, i) { - var input = new Buffer(obj.input, 'base64'); - var node = obj[algorithm]; - var js = createHash(algorithm).update(input).digest('hex'); - t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node); + var isUnsupported = satisfies(process.version, '^17') && ( + algorithm === 'rmd160' + || algorithm === 'hmac(rmd160)' + ); + test( + name + ' test ' + algorithm + ' against test vectors', + { skip: isUnsupported && 'this node version does not support ' + algorithm }, + function (t) { + vectors.forEach(function (obj, i) { + var input = new Buffer(obj.input, 'base64'); + var node = obj[algorithm]; + var js = createHash(algorithm).update(input).digest('hex'); + t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node); - encodings.forEach(function (encoding) { - var eInput = new Buffer(obj.input, 'base64').toString(encoding); - var eNode = obj[algorithm]; - var eJS = createHash(algorithm).update(eInput, encoding).digest('hex'); - t.equal(eJS, eNode, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + eNode); + encodings.forEach(function (encoding) { + var eInput = new Buffer(obj.input, 'base64').toString(encoding); + var eNode = obj[algorithm]; + var eJS = createHash(algorithm).update(eInput, encoding).digest('hex'); + t.equal(eJS, eNode, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + eNode); + }); + input = new Buffer(obj.input, 'base64'); + node = obj[algorithm]; + var hash = createHash(algorithm); + hash.end(input); + js = hash.read().toString('hex'); + t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node); }); - input = new Buffer(obj.input, 'base64'); - node = obj[algorithm]; - var hash = createHash(algorithm); - hash.end(input); - js = hash.read().toString('hex'); - t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node); - }); - t.end(); - }); + t.end(); + } + ); } function testLib(name, createHash) { diff --git a/test/create-hmac.js b/test/create-hmac.js index 5460653..6bb14d9 100644 --- a/test/create-hmac.js +++ b/test/create-hmac.js @@ -1,39 +1,52 @@ 'use strict'; var test = require('tape'); +var satisfies = require('semver/functions/satisfies'); var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160']; var vectors = require('hash-test-vectors/hmac'); function testLib(name, createHmac) { algorithms.forEach(function (alg) { - test(name + ' hmac(' + alg + ')', function (t) { - vectors.forEach(function (input) { - var output = createHmac(alg, new Buffer(input.key, 'hex')) - .update(input.data, 'hex').digest(); - - output = input.truncate ? output.slice(0, input.truncate) : output; - output = output.toString('hex'); - t.equal(output, input[alg]); - }); - - t.end(); - }); - - test('hmac(' + alg + ')', function (t) { - vectors.forEach(function (input) { - var hmac = createHmac(alg, new Buffer(input.key, 'hex')); - - hmac.end(input.data, 'hex'); - var output = hmac.read(); - - output = input.truncate ? output.slice(0, input.truncate) : output; - output = output.toString('hex'); - t.equal(output, input[alg]); - }); - - t.end(); - }); + var isUnsupported = satisfies(process.version, '^17') && ( + alg === 'rmd160' + || alg === 'hmac(rmd160)' + ); + test( + name + ' hmac(' + alg + ')', + { skip: isUnsupported && 'this node version does not support ' + alg }, + function (t) { + vectors.forEach(function (input) { + var output = createHmac(alg, new Buffer(input.key, 'hex')) + .update(input.data, 'hex').digest(); + + output = input.truncate ? output.slice(0, input.truncate) : output; + output = output.toString('hex'); + t.equal(output, input[alg]); + }); + + t.end(); + } + ); + + test( + 'hmac(' + alg + ')', + { skip: isUnsupported && 'this node version does not support ' + alg }, + function (t) { + vectors.forEach(function (input) { + var hmac = createHmac(alg, new Buffer(input.key, 'hex')); + + hmac.end(input.data, 'hex'); + var output = hmac.read(); + + output = input.truncate ? output.slice(0, input.truncate) : output; + output = output.toString('hex'); + t.equal(output, input[alg]); + }); + + t.end(); + } + ); }); } From 24eea0d3470928adfb96d8b6a6c6777daae1373a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 27 Nov 2023 09:04:47 -0800 Subject: [PATCH 211/217] [Tests] mostly switch to Github Actions --- .github/FUNDING.yml | 12 ++++++++++ .github/workflows/node-aught.yml | 18 +++++++++++++++ .github/workflows/node-pretest.yml | 7 ++++++ .github/workflows/node-tens.yml | 18 +++++++++++++++ .github/workflows/rebase.yml | 9 ++++++++ .github/workflows/require-allow-edits.yml | 12 ++++++++++ .travis.yml | 9 -------- README.md | 27 ++++++++++++++++++++--- package.json | 3 +++ 9 files changed, 103 insertions(+), 12 deletions(-) create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/node-aught.yml create mode 100644 .github/workflows/node-pretest.yml create mode 100644 .github/workflows/node-tens.yml create mode 100644 .github/workflows/rebase.yml create mode 100644 .github/workflows/require-allow-edits.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..40cfe2f --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: [ljharb] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: npm/crypto-browserify +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/.github/workflows/node-aught.yml b/.github/workflows/node-aught.yml new file mode 100644 index 0000000..f3cddd8 --- /dev/null +++ b/.github/workflows/node-aught.yml @@ -0,0 +1,18 @@ +name: 'Tests: node.js < 10' + +on: [pull_request, push] + +jobs: + tests: + uses: ljharb/actions/.github/workflows/node.yml@main + with: + range: '< 10' + type: minors + command: npm run tests-only + + node: + name: 'node < 10' + needs: [tests] + runs-on: ubuntu-latest + steps: + - run: 'echo tests completed' diff --git a/.github/workflows/node-pretest.yml b/.github/workflows/node-pretest.yml new file mode 100644 index 0000000..765edf7 --- /dev/null +++ b/.github/workflows/node-pretest.yml @@ -0,0 +1,7 @@ +name: 'Tests: pretest/posttest' + +on: [pull_request, push] + +jobs: + tests: + uses: ljharb/actions/.github/workflows/pretest.yml@main diff --git a/.github/workflows/node-tens.yml b/.github/workflows/node-tens.yml new file mode 100644 index 0000000..b49ceb1 --- /dev/null +++ b/.github/workflows/node-tens.yml @@ -0,0 +1,18 @@ +name: 'Tests: node.js >= 10' + +on: [pull_request, push] + +jobs: + tests: + uses: ljharb/actions/.github/workflows/node.yml@main + with: + range: '>= 10' + type: minors + command: npm run tests-only + + node: + name: 'node >= 10' + needs: [tests] + runs-on: ubuntu-latest + steps: + - run: 'echo tests completed' diff --git a/.github/workflows/rebase.yml b/.github/workflows/rebase.yml new file mode 100644 index 0000000..b9e1712 --- /dev/null +++ b/.github/workflows/rebase.yml @@ -0,0 +1,9 @@ +name: Automatic Rebase + +on: [pull_request_target] + +jobs: + _: + uses: ljharb/actions/.github/workflows/rebase.yml@main + secrets: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/require-allow-edits.yml b/.github/workflows/require-allow-edits.yml new file mode 100644 index 0000000..7b842f8 --- /dev/null +++ b/.github/workflows/require-allow-edits.yml @@ -0,0 +1,12 @@ +name: Require “Allow Edits” + +on: [pull_request_target] + +jobs: + _: + name: "Require “Allow Edits”" + + runs-on: ubuntu-latest + + steps: + - uses: ljharb/require-allow-edits@main diff --git a/.travis.yml b/.travis.yml index c7be687..6bbb3c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,15 +2,6 @@ sudo: false language: node_js matrix: include: - - node_js: '0.11' - env: TEST_SUITE=tests-only - - node_js: '0.12' - env: TEST_SUITE=tests-only - - node_js: '4' - env: TEST_SUITE=tests-only - - node_js: '4' - env: TEST_SUITE=lint - - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=ie BROWSER_VERSION="10..latest" - node_js: '4' env: TEST_SUITE=browser BROWSER_NAME=chrome BROWSER_VERSION="-2..beta" diff --git a/README.md b/README.md index f93291b..1d11cf0 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,16 @@ -# crypto-browserify +# crypto-browserify [![Version Badge][npm-version-svg]][package-url] A port of node's `crypto` module to the browser. -[![Build Status](https://travis-ci.org/browserify/crypto-browserify.svg?branch=master)](https://travis-ci.org/browserify/crypto-browserify) -[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard) +[![github actions][actions-image]][actions-url] +[![coverage][codecov-image]][codecov-url] +[![License][license-image]][license-url] +[![Downloads][downloads-image]][downloads-url] [![Sauce Test Status](https://saucelabs.com/browser-matrix/crypto-browserify.svg)](https://saucelabs.com/u/crypto-browserify) +[![npm badge][npm-badge-png]][package-url] + + The goal of this module is to reimplement node's crypto module, in pure javascript so that it can run in the browser. @@ -48,3 +53,19 @@ and post comments if you do. ## License MIT + +[package-url]: https://npmjs.org/package/crypto-browserify +[npm-version-svg]: https://versionbadg.es/browserify/crypto-browserify.svg +[deps-svg]: https://david-dm.org/browserify/crypto-browserify.svg +[deps-url]: https://david-dm.org/browserify/crypto-browserify +[dev-deps-svg]: https://david-dm.org/browserify/crypto-browserify/dev-status.svg +[dev-deps-url]: https://david-dm.org/browserify/crypto-browserify#info=devDependencies +[npm-badge-png]: https://nodei.co/npm/crypto-browserify.png?downloads=true&stars=true +[license-image]: https://img.shields.io/npm/l/crypto-browserify.svg +[license-url]: LICENSE +[downloads-image]: https://img.shields.io/npm/dm/crypto-browserify.svg +[downloads-url]: https://npm-stat.com/charts.html?package=crypto-browserify +[codecov-image]: https://codecov.io/gh/browserify/crypto-browserify/branch/main/graphs/badge.svg +[codecov-url]: https://app.codecov.io/gh/browserify/crypto-browserify/ +[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/browserify/crypto-browserify +[actions-url]: https://github.com/browserify/crypto-browserify/actions diff --git a/package.json b/package.json index 2f4e9aa..b14671b 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,9 @@ "posttest": "aud --production", "browser": "zuul --browser-version $BROWSER_VERSION --browser-name $BROWSER_NAME -- test/index.js" }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + }, "engines": { "node": "*" }, From 8ff13b0bcd16a70fa67e1e4c5a0e7e0d0b3415b4 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 27 Nov 2023 11:48:59 -0800 Subject: [PATCH 212/217] [Tests] skip `engines` check for now via readable-stream v3 and browserify-sign, we are breaking support for node < 6 at the moment --- .github/workflows/node-aught.yml | 1 + .github/workflows/node-pretest.yml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.github/workflows/node-aught.yml b/.github/workflows/node-aught.yml index f3cddd8..8c956b7 100644 --- a/.github/workflows/node-aught.yml +++ b/.github/workflows/node-aught.yml @@ -9,6 +9,7 @@ jobs: range: '< 10' type: minors command: npm run tests-only + skip-ls-check: true node: name: 'node < 10' diff --git a/.github/workflows/node-pretest.yml b/.github/workflows/node-pretest.yml index 765edf7..9f4b4f5 100644 --- a/.github/workflows/node-pretest.yml +++ b/.github/workflows/node-pretest.yml @@ -5,3 +5,5 @@ on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/pretest.yml@main + with: + skip-engines: true # see https://github.com/browserify/browserify-sign/pull/49 From 0bc31e62c8524cb27040ed5835a73211f0353d33 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 4 Mar 2024 22:02:27 -0800 Subject: [PATCH 213/217] [Dev Deps] update `aud`, `tape` --- .github/workflows/node-aught.yml | 2 +- .github/workflows/node-tens.yml | 2 +- package.json | 6 ++++-- test/create-hash.js | 2 +- test/create-hmac.js | 2 +- test/node/dh.js | 4 ++-- test/random-bytes.js | 3 ++- 7 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/node-aught.yml b/.github/workflows/node-aught.yml index 8c956b7..d6fed62 100644 --- a/.github/workflows/node-aught.yml +++ b/.github/workflows/node-aught.yml @@ -16,4 +16,4 @@ jobs: needs: [tests] runs-on: ubuntu-latest steps: - - run: 'echo tests completed' + - run: true diff --git a/.github/workflows/node-tens.yml b/.github/workflows/node-tens.yml index b49ceb1..70f55da 100644 --- a/.github/workflows/node-tens.yml +++ b/.github/workflows/node-tens.yml @@ -15,4 +15,4 @@ jobs: needs: [tests] runs-on: ubuntu-latest steps: - - run: 'echo tests completed' + - run: true diff --git a/package.json b/package.json index b14671b..19b7aa1 100644 --- a/package.json +++ b/package.json @@ -37,12 +37,14 @@ }, "devDependencies": { "@ljharb/eslint-config": "^21.1.0", - "aud": "^2.0.3", + "aud": "^2.0.4", "eslint": "=8.8.0", "hash-test-vectors": "^1.3.2", + "object.entries": "^1.1.7", "pseudorandombytes": "^2.0.0", "safe-buffer": "^5.2.1", - "tape": "^5.7.2", + "semver": "^6.3.1", + "tape": "^5.7.5", "zuul": "^3.12.0" }, "browser": { diff --git a/test/create-hash.js b/test/create-hash.js index e3f0346..dac0ef8 100644 --- a/test/create-hash.js +++ b/test/create-hash.js @@ -1,7 +1,7 @@ 'use strict'; var test = require('tape'); -var satisfies = require('semver/functions/satisfies'); +var satisfies = require('semver').satisfies; var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160']; var encodings = ['hex', 'base64']; // FIXME: test binary diff --git a/test/create-hmac.js b/test/create-hmac.js index 6bb14d9..ec81df9 100644 --- a/test/create-hmac.js +++ b/test/create-hmac.js @@ -1,7 +1,7 @@ 'use strict'; var test = require('tape'); -var satisfies = require('semver/functions/satisfies'); +var satisfies = require('semver').satisfies; var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160']; var vectors = require('hash-test-vectors/hmac'); diff --git a/test/node/dh.js b/test/node/dh.js index 6f7e75d..ae8f7d7 100644 --- a/test/node/dh.js +++ b/test/node/dh.js @@ -3,7 +3,7 @@ var test = require('tape'); var cryptoB = require('../../'); var crypto = require('crypto'); -var semverSatisfies = require('semver/functions/satisfies'); +var satisfies = require('semver').satisfies; test('diffie-hellman mod groups', function (t) { [ @@ -44,7 +44,7 @@ test('diffie-hellman key lengths', function (t) { 512, 1024 ].forEach(function (len) { - var modulusTooSmall = semverSatisfies(process.version, '>= 17') && len < 512; + var modulusTooSmall = satisfies(process.version, '>= 17') && len < 512; t.test(String(len), { skip: modulusTooSmall && 'node 17+ requires a length >= 512' }, function (st) { var dh2 = cryptoB.createDiffieHellman(len); var prime2 = dh2.getPrime(); diff --git a/test/random-bytes.js b/test/random-bytes.js index 9c1a61a..47f7535 100644 --- a/test/random-bytes.js +++ b/test/random-bytes.js @@ -3,6 +3,7 @@ var test = require('tape'); var crypto = require('../'); var randomBytes = require('randombytes'); +var entries = require('object.entries'); var randomBytesFunctions = { randomBytes: randomBytes, @@ -10,7 +11,7 @@ var randomBytesFunctions = { }; // Both randomBytes and pseudoRandomBytes should provide the same interface -Object.entries(randomBytesFunctions).forEach(function (entry) { +entries(randomBytesFunctions).forEach(function (entry) { var randomBytesName = entry[0]; var randomBytesFn = entry[1]; From 387856296eb6841e18968c4d8b4262010cead735 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 4 Mar 2024 22:21:57 -0800 Subject: [PATCH 214/217] =?UTF-8?q?[Tests]=20remove=20zuul;=20it=E2=80=99s?= =?UTF-8?q?=20dead?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .zuul.yml | 1 - package.json | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) delete mode 100644 .zuul.yml diff --git a/.zuul.yml b/.zuul.yml deleted file mode 100644 index 96d9cfb..0000000 --- a/.zuul.yml +++ /dev/null @@ -1 +0,0 @@ -ui: tape diff --git a/package.json b/package.json index 19b7aa1..3ec4929 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,7 @@ "pretest": "npm run lint", "tests-only": "tape 'test/**/*.js'", "test": "npm run tests-only", - "posttest": "aud --production", - "browser": "zuul --browser-version $BROWSER_VERSION --browser-name $BROWSER_NAME -- test/index.js" + "posttest": "aud --production" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -44,8 +43,7 @@ "pseudorandombytes": "^2.0.0", "safe-buffer": "^5.2.1", "semver": "^6.3.1", - "tape": "^5.7.5", - "zuul": "^3.12.0" + "tape": "^5.7.5" }, "browser": { "crypto": false From 0c62cf876c84ad5f83d1bf5edf7f8103857e05a4 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 4 Mar 2024 22:29:32 -0800 Subject: [PATCH 215/217] [Deps] pin `hash-base` to ~3.0, due to a breaking change See https://github.com/browserify/hash-base/pull/14#issuecomment-1978049873 --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 3ec4929..4ca41d8 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "create-hash": "^1.2.0", "create-hmac": "^1.1.7", "diffie-hellman": "^5.0.3", + "hash-base": "~3.0.4", "inherits": "^2.0.4", "pbkdf2": "^3.1.2", "public-encrypt": "^4.0.3", From da8a1a2524ac24ec8a353b10f4d13db03c10e471 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 5 Mar 2024 10:23:18 -0800 Subject: [PATCH 216/217] [Deps] update `browserify-sign` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ca41d8..dc4d5fd 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ }, "dependencies": { "browserify-cipher": "^1.0.1", - "browserify-sign": "^4.2.2", + "browserify-sign": "^4.2.3", "create-ecdh": "^4.0.4", "create-hash": "^1.2.0", "create-hmac": "^1.1.7", From 2e18bb23774608c61a983a351c64177a0289c20b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 5 Mar 2024 10:32:39 -0800 Subject: [PATCH 217/217] [meta] document support as node 0.10+ --- .github/workflows/node-aught.yml | 9 +-------- .github/workflows/node-tens.yml | 7 ------- package.json | 2 +- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/.github/workflows/node-aught.yml b/.github/workflows/node-aught.yml index d6fed62..187d841 100644 --- a/.github/workflows/node-aught.yml +++ b/.github/workflows/node-aught.yml @@ -6,14 +6,7 @@ jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: - range: '< 10' + range: '>= 0.10 < 10' type: minors command: npm run tests-only skip-ls-check: true - - node: - name: 'node < 10' - needs: [tests] - runs-on: ubuntu-latest - steps: - - run: true diff --git a/.github/workflows/node-tens.yml b/.github/workflows/node-tens.yml index 70f55da..1f55be0 100644 --- a/.github/workflows/node-tens.yml +++ b/.github/workflows/node-tens.yml @@ -9,10 +9,3 @@ jobs: range: '>= 10' type: minors command: npm run tests-only - - node: - name: 'node >= 10' - needs: [tests] - runs-on: ubuntu-latest - steps: - - run: true diff --git a/package.json b/package.json index dc4d5fd..d83ac1e 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "url": "https://github.com/sponsors/ljharb" }, "engines": { - "node": "*" + "node": ">= 0.10" }, "dependencies": { "browserify-cipher": "^1.0.1",