[Pkg-javascript-commits] [node-browserify-aes] 56/92: just pull in md5
Bastien Roucariès
rouca at moszumanska.debian.org
Sun Jun 4 09:35:19 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-browserify-aes.
commit 7515edbf3024dcbafed089b4530faae137732ae9
Author: Calvin Metcalf <calvin.metcalf at state.ma.us>
Date: Sun Jan 18 10:51:03 2015 -0500
just pull in md5
---
EVP_BytesToKey.js | 21 ++++++++++-------
browser.js | 5 ++--
decrypter.js | 69 ++++++++++++++++++++++++++----------------------------
encrypter.js | 70 +++++++++++++++++++++++++++----------------------------
inject.js | 14 -----------
test/index.js | 16 ++++++-------
6 files changed, 90 insertions(+), 105 deletions(-)
diff --git a/EVP_BytesToKey.js b/EVP_BytesToKey.js
index 16f1ae5..c55cbe3 100644
--- a/EVP_BytesToKey.js
+++ b/EVP_BytesToKey.js
@@ -1,5 +1,9 @@
-
-module.exports = function (crypto, password, keyLen, ivLen) {
+var md5 = require('create-hash/md5');
+module.exports = EVP_BytesToKey;
+function EVP_BytesToKey(password, keyLen, ivLen) {
+ if (!Buffer.isBuffer(password)) {
+ password = new Buffer(password, 'binary');
+ }
keyLen = keyLen/8;
ivLen = ivLen || 0;
var ki = 0;
@@ -7,15 +11,16 @@ module.exports = function (crypto, password, keyLen, ivLen) {
var key = new Buffer(keyLen);
var iv = new Buffer(ivLen);
var addmd = 0;
- var md, md_buf;
+ var md_buf;
var i;
+ var bufs = [];
while (true) {
- md = crypto.createHash('md5');
if(addmd++ > 0) {
- md.update(md_buf);
+ bufs.push(md_buf);
}
- md.update(password);
- md_buf = md.digest();
+ bufs.push(password);
+ md_buf = md5(Buffer.concat(bufs));
+ bufs = [];
i = 0;
if(keyLen > 0) {
while(true) {
@@ -54,4 +59,4 @@ module.exports = function (crypto, password, keyLen, ivLen) {
key: key,
iv: iv
};
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/browser.js b/browser.js
index c6ff0eb..e9cbf4b 100644
--- a/browser.js
+++ b/browser.js
@@ -1,8 +1,7 @@
-var crypto = {createHash: require('create-hash')};
-var ciphers = require('./encrypter')(crypto);
+var ciphers = require('./encrypter');
exports.createCipher = exports.Cipher = ciphers.createCipher;
exports.createCipheriv = exports.Cipheriv = ciphers.createCipheriv;
-var deciphers = require('./decrypter')(crypto);
+var deciphers = require('./decrypter');
exports.createDecipher = exports.Decipher = deciphers.createDecipher;
exports.createDecipheriv = exports.Decipheriv = deciphers.createDecipheriv;
var modes = require('./modes');
diff --git a/decrypter.js b/decrypter.js
index 525207f..4942b4d 100644
--- a/decrypter.js
+++ b/decrypter.js
@@ -99,42 +99,39 @@ var modelist = {
GCM: require('./modes/ctr')
};
-module.exports = function (crypto) {
- function createDecipheriv(suite, password, iv) {
- var config = modes[suite.toLowerCase()];
- if (!config) {
- throw new TypeError('invalid suite type');
- }
- if (typeof iv === 'string') {
- iv = new Buffer(iv);
- }
- if (typeof password === 'string') {
- password = new Buffer(password);
- }
- if (password.length !== config.key/8) {
- throw new TypeError('invalid key length ' + password.length);
- }
- if (iv.length !== config.iv) {
- throw new TypeError('invalid iv length ' + iv.length);
- }
- if (config.type === 'stream') {
- return new StreamCipher(modelist[config.mode], password, iv, true);
- } else if (config.type === 'auth') {
- return new AuthCipher(modelist[config.mode], password, iv, true);
- }
- return new Decipher(modelist[config.mode], password, iv);
+
+function createDecipheriv(suite, password, iv) {
+ var config = modes[suite.toLowerCase()];
+ if (!config) {
+ throw new TypeError('invalid suite type');
+ }
+ if (typeof iv === 'string') {
+ iv = new Buffer(iv);
}
+ if (typeof password === 'string') {
+ password = new Buffer(password);
+ }
+ if (password.length !== config.key/8) {
+ throw new TypeError('invalid key length ' + password.length);
+ }
+ if (iv.length !== config.iv) {
+ throw new TypeError('invalid iv length ' + iv.length);
+ }
+ if (config.type === 'stream') {
+ return new StreamCipher(modelist[config.mode], password, iv, true);
+ } else if (config.type === 'auth') {
+ return new AuthCipher(modelist[config.mode], password, iv, true);
+ }
+ return new Decipher(modelist[config.mode], password, iv);
+}
- function createDecipher (suite, password) {
- var config = modes[suite.toLowerCase()];
- if (!config) {
- throw new TypeError('invalid suite type');
- }
- var keys = ebtk(crypto, password, config.key, config.iv);
- return createDecipheriv(suite, keys.key, keys.iv);
+function createDecipher (suite, password) {
+ var config = modes[suite.toLowerCase()];
+ if (!config) {
+ throw new TypeError('invalid suite type');
}
- return {
- createDecipher: createDecipher,
- createDecipheriv: createDecipheriv
- };
-};
+ var keys = ebtk(password, config.key, config.iv);
+ return createDecipheriv(suite, keys.key, keys.iv);
+}
+exports.createDecipher = createDecipher;
+exports.createDecipheriv = createDecipheriv;
\ No newline at end of file
diff --git a/encrypter.js b/encrypter.js
index dbaf663..4212b3e 100644
--- a/encrypter.js
+++ b/encrypter.js
@@ -83,41 +83,39 @@ var modelist = {
CTR: require('./modes/ctr'),
GCM: require('./modes/ctr')
};
-module.exports = function (crypto) {
- function createCipheriv(suite, password, iv) {
- var config = modes[suite.toLowerCase()];
- if (!config) {
- throw new TypeError('invalid suite type');
- }
- if (typeof iv === 'string') {
- iv = new Buffer(iv);
- }
- if (typeof password === 'string') {
- password = new Buffer(password);
- }
- if (password.length !== config.key/8) {
- throw new TypeError('invalid key length ' + password.length);
- }
- if (iv.length !== config.iv) {
- throw new TypeError('invalid iv length ' + iv.length);
- }
- if (config.type === 'stream') {
- return new StreamCipher(modelist[config.mode], password, iv);
- } else if (config.type === 'auth') {
- return new AuthCipher(modelist[config.mode], password, iv);
- }
- return new Cipher(modelist[config.mode], password, iv);
+
+function createCipheriv(suite, password, iv) {
+ var config = modes[suite.toLowerCase()];
+ if (!config) {
+ throw new TypeError('invalid suite type');
}
- function createCipher (suite, password) {
- var config = modes[suite.toLowerCase()];
- if (!config) {
- throw new TypeError('invalid suite type');
- }
- var keys = ebtk(crypto, password, config.key, config.iv);
- return createCipheriv(suite, keys.key, keys.iv);
+ if (typeof iv === 'string') {
+ iv = new Buffer(iv);
}
- return {
- createCipher: createCipher,
- createCipheriv: createCipheriv
- };
-};
+ if (typeof password === 'string') {
+ password = new Buffer(password);
+ }
+ if (password.length !== config.key/8) {
+ throw new TypeError('invalid key length ' + password.length);
+ }
+ if (iv.length !== config.iv) {
+ throw new TypeError('invalid iv length ' + iv.length);
+ }
+ if (config.type === 'stream') {
+ return new StreamCipher(modelist[config.mode], password, iv);
+ } else if (config.type === 'auth') {
+ return new AuthCipher(modelist[config.mode], password, iv);
+ }
+ return new Cipher(modelist[config.mode], password, iv);
+}
+function createCipher (suite, password) {
+ var config = modes[suite.toLowerCase()];
+ if (!config) {
+ throw new TypeError('invalid suite type');
+ }
+ var keys = ebtk(password, config.key, config.iv);
+ return createCipheriv(suite, keys.key, keys.iv);
+}
+
+exports.createCipheriv = createCipheriv;
+exports.createCipher = createCipher;
\ No newline at end of file
diff --git a/inject.js b/inject.js
deleted file mode 100644
index 6a49282..0000000
--- a/inject.js
+++ /dev/null
@@ -1,14 +0,0 @@
-module.exports = function (crypto, exports) {
- exports = exports || {};
- var ciphers = require('./encrypter')(crypto);
- exports.createCipher = exports.Cipher = ciphers.createCipher;
- exports.createCipheriv = exports.Cipheriv = ciphers.createCipheriv;
- var deciphers = require('./decrypter')(crypto);
- exports.createDecipher = exports.Decipher = deciphers.createDecipher;
- exports.createDecipheriv = exports.Decipheriv = deciphers.createDecipheriv;
- var modes = require('./modes');
- function getCiphers () {
- return Object.keys(modes);
- }
- exports.listCiphers = exports.getCiphers = getCiphers;
-};
diff --git a/test/index.js b/test/index.js
index a275768..3c9d8ee 100644
--- a/test/index.js
+++ b/test/index.js
@@ -107,8 +107,8 @@ fixtures.forEach(function (fixture, i) {
} else {
t.plan(2);
}
- var suite = crypto.createCipheriv(cipher, ebtk(_crypto, fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
- var suite2 = _crypto.createCipheriv(cipher, ebtk(_crypto, fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
+ var suite = crypto.createCipheriv(cipher, ebtk(fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
+ var suite2 = _crypto.createCipheriv(cipher, ebtk(fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var buf = new Buffer('');
var buf2 = new Buffer('');
suite.on('data', function (d) {
@@ -147,8 +147,8 @@ fixtures.forEach(function (fixture, i) {
} else {
t.plan(4);
}
- var suite = crypto.createCipheriv(cipher, ebtk(_crypto, fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
- var suite2 = _crypto.createCipheriv(cipher, ebtk(_crypto, fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
+ var suite = crypto.createCipheriv(cipher, ebtk(fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
+ var suite2 = _crypto.createCipheriv(cipher, ebtk(fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var buf = new Buffer('');
var buf2 = new Buffer('');
var inbuf = new Buffer(fixture.text);
@@ -174,9 +174,9 @@ fixtures.forEach(function (fixture, i) {
});
test('fixture ' + i + ' ' + cipher + '-iv-decrypt', function (t) {
t.plan(2);
- var suite = crypto.createDecipheriv(cipher, ebtk(_crypto, fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
+ var suite = crypto.createDecipheriv(cipher, ebtk(fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var buf = new Buffer('');
- var suite2 = _crypto.createDecipheriv(cipher, ebtk(_crypto, fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
+ var suite2 = _crypto.createDecipheriv(cipher, ebtk(fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var buf2 = new Buffer('');
suite.on('data', function (d) {
buf = Buffer.concat([buf, d]);
@@ -208,9 +208,9 @@ fixtures.forEach(function (fixture, i) {
});
test('fixture ' + i + ' ' + cipher + '-decrypt-legacy', function (t) {
t.plan(4);
- var suite = crypto.createDecipheriv(cipher, ebtk(_crypto, fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
+ var suite = crypto.createDecipheriv(cipher, ebtk(fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var buf = new Buffer('');
- var suite2 = _crypto.createDecipheriv(cipher, ebtk(_crypto, fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
+ var suite2 = _crypto.createDecipheriv(cipher, ebtk(fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var buf2 = new Buffer('');
var inbuf = new Buffer(fixture.results.cipherivs[cipher], 'hex');
var mid = ~~(inbuf.length/2);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-browserify-aes.git
More information about the Pkg-javascript-commits
mailing list