wallet-core/node_modules/browserify-aes/streamCipher.js

28 lines
659 B
JavaScript
Raw Normal View History

2017-05-03 15:35:00 +02:00
var aes = require('./aes')
2017-12-10 21:51:33 +01:00
var Buffer = require('safe-buffer').Buffer
2017-05-03 15:35:00 +02:00
var Transform = require('cipher-base')
var inherits = require('inherits')
function StreamCipher (mode, key, iv, decrypt) {
Transform.call(this)
2017-12-10 21:51:33 +01:00
2017-05-03 15:35:00 +02:00
this._cipher = new aes.AES(key)
2017-12-10 21:51:33 +01:00
this._prev = Buffer.from(iv)
this._cache = Buffer.allocUnsafe(0)
this._secCache = Buffer.allocUnsafe(0)
2017-05-03 15:35:00 +02:00
this._decrypt = decrypt
this._mode = mode
}
2017-12-10 21:51:33 +01:00
inherits(StreamCipher, Transform)
2017-05-03 15:35:00 +02:00
StreamCipher.prototype._update = function (chunk) {
return this._mode.encrypt(this, chunk, this._decrypt)
}
2017-12-10 21:51:33 +01:00
2017-05-03 15:35:00 +02:00
StreamCipher.prototype._final = function () {
this._cipher.scrub()
}
2017-12-10 21:51:33 +01:00
module.exports = StreamCipher