Skip to content
Permalink
Browse files

package: use buffer-xor

  • Loading branch information...
dcousens committed May 21, 2015
1 parent 7df24ee commit f2499ca7ffddf9cd2f7f21701c4b963e328b2d53
Showing with 35 additions and 28 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 authCipher.js
  3. +6 −1 modes/cbc.js
  4. +5 −1 modes/cfb.js
  5. +17 −14 modes/ctr.js
  6. +4 −1 modes/ofb.js
  7. +1 −0 package.json
  8. +0 −10 xor.js
@@ -0,0 +1 @@
node_modules
@@ -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

@@ -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)
}
@@ -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) {
@@ -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)
}
@@ -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)
@@ -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"
},
10 xor.js

This file was deleted.

0 comments on commit f2499ca

Please sign in to comment.
You can’t perform that action at this time.