UNPKG

1.33 kBJavaScriptView Raw
1;(function (root, factory, undef) {
2 if (typeof exports === "object") {
3 // CommonJS
4 module.exports = exports = factory(require("./core"), require("./cipher-core"));
5 }
6 else if (typeof define === "function" && define.amd) {
7 // AMD
8 define(["./core", "./cipher-core"], factory);
9 }
10 else {
11 // Global (browser)
12 factory(root.CryptoJS);
13 }
14}(this, function (CryptoJS) {
15
16 /**
17 * Output Feedback block mode.
18 */
19 CryptoJS.mode.OFB = (function () {
20 var OFB = CryptoJS.lib.BlockCipherMode.extend();
21
22 var Encryptor = OFB.Encryptor = OFB.extend({
23 processBlock: function (words, offset) {
24 // Shortcuts
25 var cipher = this._cipher
26 var blockSize = cipher.blockSize;
27 var iv = this._iv;
28 var keystream = this._keystream;
29
30 // Generate keystream
31 if (iv) {
32 keystream = this._keystream = iv.slice(0);
33
34 // Remove IV for subsequent blocks
35 this._iv = undefined;
36 }
37 cipher.encryptBlock(keystream, 0);
38
39 // Encrypt
40 for (var i = 0; i < blockSize; i++) {
41 words[offset + i] ^= keystream[i];
42 }
43 }
44 });
45
46 OFB.Decryptor = Encryptor;
47
48 return OFB;
49 }());
50
51
52 return CryptoJS.mode.OFB;
53
54}));
\No newline at end of file