1 | ;(function (root, factory, undef) {
|
2 | if (typeof exports === "object") {
|
3 |
|
4 | module.exports = exports = factory(require("./core"), require("./cipher-core"));
|
5 | }
|
6 | else if (typeof define === "function" && define.amd) {
|
7 |
|
8 | define(["./core", "./cipher-core"], factory);
|
9 | }
|
10 | else {
|
11 |
|
12 | factory(root.CryptoJS);
|
13 | }
|
14 | }(this, function (CryptoJS) {
|
15 |
|
16 | |
17 |
|
18 |
|
19 | CryptoJS.mode.CFB = (function () {
|
20 | var CFB = CryptoJS.lib.BlockCipherMode.extend();
|
21 |
|
22 | CFB.Encryptor = CFB.extend({
|
23 | processBlock: function (words, offset) {
|
24 |
|
25 | var cipher = this._cipher;
|
26 | var blockSize = cipher.blockSize;
|
27 |
|
28 | generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
|
29 |
|
30 |
|
31 | this._prevBlock = words.slice(offset, offset + blockSize);
|
32 | }
|
33 | });
|
34 |
|
35 | CFB.Decryptor = CFB.extend({
|
36 | processBlock: function (words, offset) {
|
37 |
|
38 | var cipher = this._cipher;
|
39 | var blockSize = cipher.blockSize;
|
40 |
|
41 |
|
42 | var thisBlock = words.slice(offset, offset + blockSize);
|
43 |
|
44 | generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
|
45 |
|
46 |
|
47 | this._prevBlock = thisBlock;
|
48 | }
|
49 | });
|
50 |
|
51 | function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) {
|
52 | var keystream;
|
53 |
|
54 |
|
55 | var iv = this._iv;
|
56 |
|
57 |
|
58 | if (iv) {
|
59 | keystream = iv.slice(0);
|
60 |
|
61 |
|
62 | this._iv = undefined;
|
63 | } else {
|
64 | keystream = this._prevBlock;
|
65 | }
|
66 | cipher.encryptBlock(keystream, 0);
|
67 |
|
68 |
|
69 | for (var i = 0; i < blockSize; i++) {
|
70 | words[offset + i] ^= keystream[i];
|
71 | }
|
72 | }
|
73 |
|
74 | return CFB;
|
75 | }());
|
76 |
|
77 |
|
78 | return CryptoJS.mode.CFB;
|
79 |
|
80 | })); |
\ | No newline at end of file |