1 | ;(function (root, factory, undef) {
|
2 | if (typeof exports === "object") {
|
3 |
|
4 | module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
|
5 | }
|
6 | else if (typeof define === "function" && define.amd) {
|
7 |
|
8 | define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
|
9 | }
|
10 | else {
|
11 |
|
12 | factory(root.CryptoJS);
|
13 | }
|
14 | }(this, function (CryptoJS) {
|
15 |
|
16 | (function () {
|
17 |
|
18 | var C = CryptoJS;
|
19 | var C_lib = C.lib;
|
20 | var StreamCipher = C_lib.StreamCipher;
|
21 | var C_algo = C.algo;
|
22 |
|
23 | |
24 |
|
25 |
|
26 | var RC4 = C_algo.RC4 = StreamCipher.extend({
|
27 | _doReset: function () {
|
28 |
|
29 | var key = this._key;
|
30 | var keyWords = key.words;
|
31 | var keySigBytes = key.sigBytes;
|
32 |
|
33 |
|
34 | var S = this._S = [];
|
35 | for (var i = 0; i < 256; i++) {
|
36 | S[i] = i;
|
37 | }
|
38 |
|
39 |
|
40 | for (var i = 0, j = 0; i < 256; i++) {
|
41 | var keyByteIndex = i % keySigBytes;
|
42 | var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff;
|
43 |
|
44 | j = (j + S[i] + keyByte) % 256;
|
45 |
|
46 |
|
47 | var t = S[i];
|
48 | S[i] = S[j];
|
49 | S[j] = t;
|
50 | }
|
51 |
|
52 |
|
53 | this._i = this._j = 0;
|
54 | },
|
55 |
|
56 | _doProcessBlock: function (M, offset) {
|
57 | M[offset] ^= generateKeystreamWord.call(this);
|
58 | },
|
59 |
|
60 | keySize: 256/32,
|
61 |
|
62 | ivSize: 0
|
63 | });
|
64 |
|
65 | function generateKeystreamWord() {
|
66 |
|
67 | var S = this._S;
|
68 | var i = this._i;
|
69 | var j = this._j;
|
70 |
|
71 |
|
72 | var keystreamWord = 0;
|
73 | for (var n = 0; n < 4; n++) {
|
74 | i = (i + 1) % 256;
|
75 | j = (j + S[i]) % 256;
|
76 |
|
77 |
|
78 | var t = S[i];
|
79 | S[i] = S[j];
|
80 | S[j] = t;
|
81 |
|
82 | keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8);
|
83 | }
|
84 |
|
85 |
|
86 | this._i = i;
|
87 | this._j = j;
|
88 |
|
89 | return keystreamWord;
|
90 | }
|
91 |
|
92 | |
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | C.RC4 = StreamCipher._createHelper(RC4);
|
101 |
|
102 | |
103 |
|
104 |
|
105 | var RC4Drop = C_algo.RC4Drop = RC4.extend({
|
106 | |
107 |
|
108 |
|
109 |
|
110 |
|
111 | cfg: RC4.cfg.extend({
|
112 | drop: 192
|
113 | }),
|
114 |
|
115 | _doReset: function () {
|
116 | RC4._doReset.call(this);
|
117 |
|
118 |
|
119 | for (var i = this.cfg.drop; i > 0; i--) {
|
120 | generateKeystreamWord.call(this);
|
121 | }
|
122 | }
|
123 | });
|
124 |
|
125 | |
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 | C.RC4Drop = StreamCipher._createHelper(RC4Drop);
|
134 | }());
|
135 |
|
136 |
|
137 | return CryptoJS.RC4;
|
138 |
|
139 | })); |
\ | No newline at end of file |