-
Notifications
You must be signed in to change notification settings - Fork 576
/
stream_cipher.js
40 lines (32 loc) · 1.1 KB
/
stream_cipher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
// Copyright 2014-2017 browserify-aes contributors. All rights reserved. MIT license.
// Copyright 2013 Maxwell Krohn. All rights reserved. MIT license.
// Copyright 2009-2013 Jeff Mott. All rights reserved. MIT license.
import { Buffer } from "../../../buffer.ts";
import * as aes from "./aes.js";
import Transform from "../cipher_base.js";
export function StreamCipher(mode, key, iv, decrypt) {
Transform.call(this);
this._cipher = new aes.AES(key);
this._prev = Buffer.from(iv);
this._cache = Buffer.allocUnsafe(0);
this._secCache = Buffer.allocUnsafe(0);
this._decrypt = decrypt;
this._mode = mode;
}
// StreamCipher inherits Transform
StreamCipher.prototype = Object.create(Transform.prototype, {
constructor: {
value: StreamCipher,
enumerable: false,
writable: true,
configurable: true,
},
});
StreamCipher.prototype._update = function (chunk) {
return this._mode.encrypt(this, chunk, this._decrypt);
};
StreamCipher.prototype._final = function () {
this._cipher.scrub();
};
export default StreamCipher;