[Pkg-javascript-commits] [node-evp-bytestokey] 01/07: first

Bastien Roucariès rouca at moszumanska.debian.org
Sat May 27 14:09:29 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-evp-bytestokey.

commit 563bd30d95a7771ff0a18afc82cf92ed18f008d3
Author: Calvin Metcalf <calvin.metcalf at gmail.com>
Date:   Sun Sep 27 10:44:10 2015 -0400

    first
---
 index.js     | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 package.json | 31 +++++++++++++++++++++++++++
 readme.md    | 13 ++++++++++++
 test.js      | 19 +++++++++++++++++
 4 files changed, 131 insertions(+)

diff --git a/index.js b/index.js
new file mode 100644
index 0000000..25fbc9c
--- /dev/null
+++ b/index.js
@@ -0,0 +1,68 @@
+var md5 = require('create-hash/md5')
+module.exports = EVP_BytesToKey
+function EVP_BytesToKey (password, salt, keyLen, ivLen) {
+  if (!Buffer.isBuffer(password)) {
+    password = new Buffer(password, 'binary')
+  }
+  if (salt && !Buffer.isBuffer(salt)) {
+    salt = new Buffer(salt, '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)
+    if (salt) {
+      bufs.push(salt)
+    }
+    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/package.json b/package.json
new file mode 100644
index 0000000..e9e96b8
--- /dev/null
+++ b/package.json
@@ -0,0 +1,31 @@
+{
+  "name": "evp_bytestokey",
+  "version": "1.0.0",
+  "description": "he super secure key derivation algorithm from openssl",
+  "main": "index.js",
+  "scripts": {
+    "test": "standard && node test.js | tspec"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/crypto-browserify/EVP_BytesToKey.git"
+  },
+  "keywords": [
+    "crypto",
+    "openssl"
+  ],
+  "author": "Calvin Metcalf <calvin.metcalf at gmail.com>",
+  "license": "MIT",
+  "bugs": {
+    "url": "https://github.com/crypto-browserify/EVP_BytesToKey/issues"
+  },
+  "homepage": "https://github.com/crypto-browserify/EVP_BytesToKey",
+  "dependencies": {
+    "create-hash": "^1.1.1"
+  },
+  "devDependencies": {
+    "standard": "^5.3.1",
+    "tap-spec": "^4.1.0",
+    "tape": "^4.2.0"
+  }
+}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..86234db
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,13 @@
+EVP_BytesToKey
+===
+
+The super secure [key derivation algorithm from openssl](https://wiki.openssl.org/index.php/Manual:EVP_BytesToKey(3)) (spoiler alert not actually secure, only every use it for compatibility reasons).
+
+Api:
+===
+
+```js
+var result = EVP_BytesToKey('password', 'salt', keyLen, ivLen);
+Buffer.isBuffer(result.password); // true
+Buffer.isBuffer(result.iv); // true
+```
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..a638fa0
--- /dev/null
+++ b/test.js
@@ -0,0 +1,19 @@
+var test = require('tape')
+var evp = require('./')
+var crypto = require('crypto')
+
+function runTest (password) {
+  test('password: ' + password, function (t) {
+    t.plan(1)
+    var keys = evp(password, false, 256, 16)
+    var nodeCipher = crypto.createCipher('aes-256-ctr', password)
+    var ourCipher = crypto.createCipheriv('aes-256-ctr', keys.key, keys.iv)
+    var nodeOut = nodeCipher.update('foooooo')
+    var ourOut = ourCipher.update('foooooo')
+    t.equals(nodeOut.toString('hex'), ourOut.toString('hex'))
+  })
+}
+runTest('password')
+runTest('ふっかつ あきる すぶり はやい つける まゆげ たんさん みんぞく ねほりはほり せまい たいまつばな ひはん')
+runTest('Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍A̴̵̜̰͔ͫ͗͢L̠ͨͧͩ͘G̴̻͈͍͔̹̑͗̎̅͛́Ǫ̵̹̻̝̳͂̌̌͘!͖̬̰̙̗̿̋ͥͥ̂ͣ̐́́͜͞')
+runTest('💩')

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-evp-bytestokey.git



More information about the Pkg-javascript-commits mailing list