This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccountGUI/node_modulesOLD/browserify-aes/modes/cfb.js

34 lines
869 B
JavaScript
Raw Normal View History

2019-08-11 18:48:02 +00:00
var Buffer = require('safe-buffer').Buffer
var xor = require('buffer-xor')
function encryptStart (self, data, decrypt) {
var len = data.length
var out = xor(data, self._cache)
self._cache = self._cache.slice(len)
self._prev = Buffer.concat([self._prev, decrypt ? data : out])
return out
}
exports.encrypt = function (self, data, decrypt) {
var out = Buffer.allocUnsafe(0)
var len
while (data.length) {
if (self._cache.length === 0) {
self._cache = self._cipher.encryptBlock(self._prev)
self._prev = Buffer.allocUnsafe(0)
}
if (self._cache.length <= data.length) {
len = self._cache.length
out = Buffer.concat([out, encryptStart(self, data.slice(0, len), decrypt)])
data = data.slice(len)
} else {
out = Buffer.concat([out, encryptStart(self, data, decrypt)])
break
}
}
return out
}