[Pkg-javascript-commits] [node-browserify-aes] 80/92: break out evp

Bastien Roucariès rouca at moszumanska.debian.org
Sun Jun 4 09:35:22 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 24094b5dc2483ca73b576c636b265023854941ee
Author: Calvin Metcalf <calvin.metcalf at gmail.com>
Date:   Sun Sep 27 10:46:01 2015 -0400

    break out evp
---
 EVP_BytesToKey.js | 62 -------------------------------------------------------
 decrypter.js      |  4 ++--
 encrypter.js      |  4 ++--
 package.json      |  1 +
 test/index.js     | 18 ++++++++--------
 5 files changed, 14 insertions(+), 75 deletions(-)

diff --git a/EVP_BytesToKey.js b/EVP_BytesToKey.js
deleted file mode 100644
index 0788128..0000000
--- a/EVP_BytesToKey.js
+++ /dev/null
@@ -1,62 +0,0 @@
-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
-  var ii = 0
-  var key = new Buffer(keyLen)
-  var iv = new Buffer(ivLen)
-  var addmd = 0
-  var md_buf
-  var i
-  var bufs = []
-  while (true) {
-    if (addmd++ > 0) {
-      bufs.push(md_buf)
-    }
-    bufs.push(password)
-    md_buf = md5(Buffer.concat(bufs))
-    bufs = []
-    i = 0
-    if (keyLen > 0) {
-      while (true) {
-        if (keyLen === 0) {
-          break
-        }
-        if (i === md_buf.length) {
-          break
-        }
-        key[ki++] = md_buf[i]
-        keyLen--
-        i++
-      }
-    }
-    if (ivLen > 0 && i !== md_buf.length) {
-      while (true) {
-        if (ivLen === 0) {
-          break
-        }
-        if (i === md_buf.length) {
-          break
-        }
-        iv[ii++] = md_buf[i]
-        ivLen--
-        i++
-      }
-    }
-    if (keyLen === 0 && ivLen === 0) {
-      break
-    }
-  }
-  for (i = 0; i < md_buf.length; i++) {
-    md_buf[i] = 0
-  }
-  return {
-    key: key,
-    iv: iv
-  }
-}
diff --git a/decrypter.js b/decrypter.js
index 1a02d5b..6e6f51d 100644
--- a/decrypter.js
+++ b/decrypter.js
@@ -4,7 +4,7 @@ var inherits = require('inherits')
 var modes = require('./modes')
 var StreamCipher = require('./streamCipher')
 var AuthCipher = require('./authCipher')
-var ebtk = require('./EVP_BytesToKey')
+var ebtk = require('evp_bytestokey')
 
 inherits(Decipher, Transform)
 function Decipher (mode, key, iv) {
@@ -129,7 +129,7 @@ function createDecipher (suite, password) {
   if (!config) {
     throw new TypeError('invalid suite type')
   }
-  var keys = ebtk(password, config.key, config.iv)
+  var keys = ebtk(password, false, config.key, config.iv)
   return createDecipheriv(suite, keys.key, keys.iv)
 }
 exports.createDecipher = createDecipher
diff --git a/encrypter.js b/encrypter.js
index de0fc8b..046cde5 100644
--- a/encrypter.js
+++ b/encrypter.js
@@ -2,7 +2,7 @@ var aes = require('./aes')
 var Transform = require('cipher-base')
 var inherits = require('inherits')
 var modes = require('./modes')
-var ebtk = require('./EVP_BytesToKey')
+var ebtk = require('evp_bytestokey')
 var StreamCipher = require('./streamCipher')
 var AuthCipher = require('./authCipher')
 inherits(Cipher, Transform)
@@ -113,7 +113,7 @@ function createCipher (suite, password) {
   if (!config) {
     throw new TypeError('invalid suite type')
   }
-  var keys = ebtk(password, config.key, config.iv)
+  var keys = ebtk(password, false, config.key, config.iv)
   return createCipheriv(suite, keys.key, keys.iv)
 }
 
diff --git a/package.json b/package.json
index 2b7c98d..4268ab2 100644
--- a/package.json
+++ b/package.json
@@ -29,6 +29,7 @@
     "buffer-xor": "^1.0.2",
     "cipher-base": "^1.0.0",
     "create-hash": "^1.1.0",
+    "evp_bytestokey": "^1.0.0",
     "inherits": "^2.0.1"
   },
   "devDependencies": {
diff --git a/test/index.js b/test/index.js
index 4cbcaf6..af54547 100644
--- a/test/index.js
+++ b/test/index.js
@@ -4,7 +4,7 @@ var _crypto = require('crypto')
 var crypto = require('../browser.js')
 var modes = require('../modes')
 var types = Object.keys(modes)
-var ebtk = require('../EVP_BytesToKey')
+var ebtk = require('evp_bytestokey')
 function isGCM (cipher) {
   return modes[cipher].mode === 'GCM'
 }
@@ -106,8 +106,8 @@ fixtures.forEach(function (fixture, i) {
       } else {
         t.plan(2)
       }
-      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 suite = crypto.createCipheriv(cipher, ebtk(fixture.password, false, 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, false, 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) {
@@ -146,8 +146,8 @@ fixtures.forEach(function (fixture, i) {
       } else {
         t.plan(4)
       }
-      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 suite = crypto.createCipheriv(cipher, ebtk(fixture.password, false, 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, false, 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)
@@ -173,9 +173,9 @@ fixtures.forEach(function (fixture, i) {
     })
     test('fixture ' + i + ' ' + cipher + '-iv-decrypt', function (t) {
       t.plan(2)
-      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 suite = crypto.createDecipheriv(cipher, ebtk(fixture.password, false, 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(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, false, 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])
@@ -207,9 +207,9 @@ fixtures.forEach(function (fixture, i) {
     })
     test('fixture ' + i + ' ' + cipher + '-decrypt-legacy', function (t) {
       t.plan(4)
-      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 suite = crypto.createDecipheriv(cipher, ebtk(fixture.password, false, 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(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, false, 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