wallet-core/node_modules/browserify-aes/modes/cfb8.js

26 lines
518 B
JavaScript
Raw Normal View History

2017-12-10 21:51:33 +01:00
var Buffer = require('safe-buffer').Buffer
2017-05-03 15:35:00 +02:00
function encryptByte (self, byteParam, decrypt) {
var pad = self._cipher.encryptBlock(self._prev)
var out = pad[0] ^ byteParam
2017-12-10 21:51:33 +01:00
self._prev = Buffer.concat([
self._prev.slice(1),
Buffer.from([decrypt ? byteParam : out])
])
2017-05-03 15:35:00 +02:00
return out
}
2017-12-10 21:51:33 +01:00
2017-05-03 15:35:00 +02:00
exports.encrypt = function (self, chunk, decrypt) {
var len = chunk.length
2017-12-10 21:51:33 +01:00
var out = Buffer.allocUnsafe(len)
2017-05-03 15:35:00 +02:00
var i = -1
2017-12-10 21:51:33 +01:00
2017-05-03 15:35:00 +02:00
while (++i < len) {
out[i] = encryptByte(self, chunk[i], decrypt)
}
2017-12-10 21:51:33 +01:00
2017-05-03 15:35:00 +02:00
return out
}