[Pkg-javascript-commits] [node-browserify-aes] 68/92: package: use buffer-xor
Bastien Roucariès
rouca at moszumanska.debian.org
Sun Jun 4 09:35:20 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 f2499ca7ffddf9cd2f7f21701c4b963e328b2d53
Author: Daniel Cousens <github at dcousens.com>
Date: Thu May 21 15:47:47 2015 +1000
package: use buffer-xor
---
.gitignore | 1 +
authCipher.js | 2 +-
modes/cbc.js | 7 ++++++-
modes/cfb.js | 6 +++++-
modes/ctr.js | 31 +++++++++++++++++--------------
modes/ofb.js | 5 ++++-
package.json | 1 +
xor.js | 10 ----------
8 files changed, 35 insertions(+), 28 deletions(-)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/authCipher.js b/authCipher.js
index ee01feb..802156c 100644
--- a/authCipher.js
+++ b/authCipher.js
@@ -2,7 +2,7 @@ var aes = require('./aes')
var Transform = require('./cipherBase')
var inherits = require('inherits')
var GHASH = require('./ghash')
-var xor = require('./xor')
+var xor = require('buffer-xor')
inherits(StreamCipher, Transform)
module.exports = StreamCipher
diff --git a/modes/cbc.js b/modes/cbc.js
index 74b6323..b133e40 100644
--- a/modes/cbc.js
+++ b/modes/cbc.js
@@ -1,12 +1,17 @@
-var xor = require('../xor')
+var xor = require('buffer-xor')
+
exports.encrypt = function (self, block) {
var data = xor(block, self._prev)
+
self._prev = self._cipher.encryptBlock(data)
return self._prev
}
+
exports.decrypt = function (self, block) {
var pad = self._prev
+
self._prev = block
var out = self._cipher.decryptBlock(block)
+
return xor(out, pad)
}
diff --git a/modes/cfb.js b/modes/cfb.js
index 62c5fa5..0bfe4fa 100644
--- a/modes/cfb.js
+++ b/modes/cfb.js
@@ -1,12 +1,15 @@
-var xor = require('../xor')
+var xor = require('buffer-xor')
+
exports.encrypt = function (self, data, decrypt) {
var out = new Buffer('')
var len
+
while (data.length) {
if (self._cache.length === 0) {
self._cache = self._cipher.encryptBlock(self._prev)
self._prev = new Buffer('')
}
+
if (self._cache.length <= data.length) {
len = self._cache.length
out = Buffer.concat([out, encryptStart(self, data.slice(0, len), decrypt)])
@@ -16,6 +19,7 @@ exports.encrypt = function (self, data, decrypt) {
break
}
}
+
return out
}
function encryptStart (self, data, decrypt) {
diff --git a/modes/ctr.js b/modes/ctr.js
index 13e1ce3..0ef2278 100644
--- a/modes/ctr.js
+++ b/modes/ctr.js
@@ -1,17 +1,5 @@
-var xor = require('../xor')
-function getBlock (self) {
- var out = self._cipher.encryptBlock(self._prev)
- incr32(self._prev)
- return out
-}
-exports.encrypt = function (self, chunk) {
- while (self._cache.length < chunk.length) {
- self._cache = Buffer.concat([self._cache, getBlock(self)])
- }
- var pad = self._cache.slice(0, chunk.length)
- self._cache = self._cache.slice(chunk.length)
- return xor(chunk, pad)
-}
+var xor = require('buffer-xor')
+
function incr32 (iv) {
var len = iv.length
var item
@@ -26,3 +14,18 @@ function incr32 (iv) {
}
}
}
+
+function getBlock (self) {
+ var out = self._cipher.encryptBlock(self._prev)
+ incr32(self._prev)
+ return out
+}
+
+exports.encrypt = function (self, chunk) {
+ while (self._cache.length < chunk.length) {
+ self._cache = Buffer.concat([self._cache, getBlock(self)])
+ }
+ var pad = self._cache.slice(0, chunk.length)
+ self._cache = self._cache.slice(chunk.length)
+ return xor(chunk, pad)
+}
diff --git a/modes/ofb.js b/modes/ofb.js
index 32a5dd5..bd87558 100644
--- a/modes/ofb.js
+++ b/modes/ofb.js
@@ -1,12 +1,15 @@
-var xor = require('../xor')
+var xor = require('buffer-xor')
+
function getBlock (self) {
self._prev = self._cipher.encryptBlock(self._prev)
return self._prev
}
+
exports.encrypt = function (self, chunk) {
while (self._cache.length < chunk.length) {
self._cache = Buffer.concat([self._cache, getBlock(self)])
}
+
var pad = self._cache.slice(0, chunk.length)
self._cache = self._cache.slice(chunk.length)
return xor(chunk, pad)
diff --git a/package.json b/package.json
index c74c87e..42dc14f 100644
--- a/package.json
+++ b/package.json
@@ -26,6 +26,7 @@
},
"homepage": "https://github.com/crypto-browserify/browserify-aes",
"dependencies": {
+ "buffer-xor": "^1.0.2",
"create-hash": "^1.1.0",
"inherits": "^2.0.1"
},
diff --git a/xor.js b/xor.js
deleted file mode 100644
index 71aa0a5..0000000
--- a/xor.js
+++ /dev/null
@@ -1,10 +0,0 @@
-module.exports = xor
-function xor (a, b) {
- var len = Math.min(a.length, b.length)
- var out = new Buffer(len)
- var i = -1
- while (++i < len) {
- out.writeUInt8(a[i] ^ b[i], i)
- }
- return out
-}
--
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