@brix-crypto/crypto-js 0.0.1-security → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @brix-crypto/crypto-js might be problematic. Click here for more details.

Files changed (108) hide show
  1. package/.jshintrc +33 -0
  2. package/.travis.yml +15 -0
  3. package/CONTRIBUTING.md +28 -0
  4. package/LICENSE +24 -0
  5. package/README.md +273 -3
  6. package/docs/QuickStartGuide.wiki +470 -0
  7. package/package.json +45 -3
  8. package/src/aes.js +214 -0
  9. package/src/blowfish.js +451 -0
  10. package/src/cipher-core.js +877 -0
  11. package/src/core.js +796 -0
  12. package/src/enc-base64.js +116 -0
  13. package/src/enc-base64url.js +128 -0
  14. package/src/enc-utf16.js +129 -0
  15. package/src/evpkdf.js +114 -0
  16. package/src/format-hex.js +46 -0
  17. package/src/hmac.js +125 -0
  18. package/src/lib-typedarrays.js +56 -0
  19. package/src/md5.js +248 -0
  20. package/src/mode-cfb.js +60 -0
  21. package/src/mode-ctr-gladman.js +96 -0
  22. package/src/mode-ctr.js +38 -0
  23. package/src/mode-ecb.js +20 -0
  24. package/src/mode-ofb.js +34 -0
  25. package/src/pad-ansix923.js +29 -0
  26. package/src/pad-iso10126.js +24 -0
  27. package/src/pad-iso97971.js +20 -0
  28. package/src/pad-nopadding.js +10 -0
  29. package/src/pad-zeropadding.js +27 -0
  30. package/src/pbkdf2.js +125 -0
  31. package/src/rabbit-legacy.js +170 -0
  32. package/src/rabbit.js +172 -0
  33. package/src/rc4.js +119 -0
  34. package/src/ripemd160.js +247 -0
  35. package/src/sha1.js +130 -0
  36. package/src/sha224.js +60 -0
  37. package/src/sha256.js +179 -0
  38. package/src/sha3.js +306 -0
  39. package/src/sha384.js +63 -0
  40. package/src/sha512.js +306 -0
  41. package/src/tripledes.js +759 -0
  42. package/src/x64-core.js +284 -0
  43. package/test/aes-profile.js +31 -0
  44. package/test/aes-test.js +80 -0
  45. package/test/blowfish-test.js +33 -0
  46. package/test/cipher-test.js +522 -0
  47. package/test/config-test.js +51 -0
  48. package/test/des-profile.js +31 -0
  49. package/test/des-test.js +104 -0
  50. package/test/enc-base64-test.js +71 -0
  51. package/test/enc-hex-test.js +15 -0
  52. package/test/enc-latin1-test.js +15 -0
  53. package/test/enc-utf16-test.js +55 -0
  54. package/test/enc-utf8-test.js +39 -0
  55. package/test/evpkdf-profile.js +11 -0
  56. package/test/evpkdf-test.js +32 -0
  57. package/test/format-openssl-test.js +37 -0
  58. package/test/hmac-md5-profile.js +30 -0
  59. package/test/hmac-md5-test.js +59 -0
  60. package/test/hmac-sha224-test.js +59 -0
  61. package/test/hmac-sha256-test.js +59 -0
  62. package/test/hmac-sha384-test.js +59 -0
  63. package/test/hmac-sha512-test.js +59 -0
  64. package/test/kdf-openssl-test.js +15 -0
  65. package/test/lib-base-test.js +92 -0
  66. package/test/lib-cipherparams-test.js +59 -0
  67. package/test/lib-passwordbasedcipher-test.js +25 -0
  68. package/test/lib-serializablecipher-test.js +51 -0
  69. package/test/lib-typedarrays-test.js +57 -0
  70. package/test/lib-wordarray-test.js +85 -0
  71. package/test/md5-profile.js +24 -0
  72. package/test/md5-test.js +70 -0
  73. package/test/mode-cbc-test.js +49 -0
  74. package/test/mode-cfb-test.js +51 -0
  75. package/test/mode-ctr-test.js +55 -0
  76. package/test/mode-ecb-test.js +38 -0
  77. package/test/mode-ofb-test.js +50 -0
  78. package/test/pad-ansix923-test.js +28 -0
  79. package/test/pad-iso10126-test.js +50 -0
  80. package/test/pad-iso97971-test.js +35 -0
  81. package/test/pad-pkcs7-test.js +28 -0
  82. package/test/pad-zeropadding-test.js +28 -0
  83. package/test/pbkdf2-profile.js +11 -0
  84. package/test/pbkdf2-test.js +80 -0
  85. package/test/profile.html +281 -0
  86. package/test/rabbit-legacy-test.js +80 -0
  87. package/test/rabbit-profile.js +30 -0
  88. package/test/rabbit-test.js +84 -0
  89. package/test/rc4-profile.js +30 -0
  90. package/test/rc4-test.js +68 -0
  91. package/test/ripemd160-test.js +19 -0
  92. package/test/sha1-profile.js +24 -0
  93. package/test/sha1-test.js +70 -0
  94. package/test/sha224-test.js +19 -0
  95. package/test/sha256-profile.js +24 -0
  96. package/test/sha256-test.js +70 -0
  97. package/test/sha3-profile.js +24 -0
  98. package/test/sha3-test.js +69 -0
  99. package/test/sha384-test.js +54 -0
  100. package/test/sha512-profile.js +24 -0
  101. package/test/sha512-test.js +54 -0
  102. package/test/test-build.html +105 -0
  103. package/test/test.html +138 -0
  104. package/test/test1.html +63 -0
  105. package/test/tripledes-profile.js +31 -0
  106. package/test/tripledes-test.js +121 -0
  107. package/test/x64-word-test.js +99 -0
  108. package/test/x64-wordarray-test.js +38 -0
@@ -0,0 +1,56 @@
1
+ (function () {
2
+ // Check if typed arrays are supported
3
+ if (typeof ArrayBuffer != 'function') {
4
+ return;
5
+ }
6
+
7
+ // Shortcuts
8
+ var C = CryptoJS;
9
+ var C_lib = C.lib;
10
+ var WordArray = C_lib.WordArray;
11
+
12
+ // Reference original init
13
+ var superInit = WordArray.init;
14
+
15
+ // Augment WordArray.init to handle typed arrays
16
+ var subInit = WordArray.init = function (typedArray) {
17
+ // Convert buffers to uint8
18
+ if (typedArray instanceof ArrayBuffer) {
19
+ typedArray = new Uint8Array(typedArray);
20
+ }
21
+
22
+ // Convert other array views to uint8
23
+ if (
24
+ typedArray instanceof Int8Array ||
25
+ (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) ||
26
+ typedArray instanceof Int16Array ||
27
+ typedArray instanceof Uint16Array ||
28
+ typedArray instanceof Int32Array ||
29
+ typedArray instanceof Uint32Array ||
30
+ typedArray instanceof Float32Array ||
31
+ typedArray instanceof Float64Array
32
+ ) {
33
+ typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength);
34
+ }
35
+
36
+ // Handle Uint8Array
37
+ if (typedArray instanceof Uint8Array) {
38
+ // Shortcut
39
+ var typedArrayByteLength = typedArray.byteLength;
40
+
41
+ // Extract bytes
42
+ var words = [];
43
+ for (var i = 0; i < typedArrayByteLength; i++) {
44
+ words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8);
45
+ }
46
+
47
+ // Initialize this word array
48
+ superInit.call(this, words, typedArrayByteLength);
49
+ } else {
50
+ // Else call normal init
51
+ superInit.apply(this, arguments);
52
+ }
53
+ };
54
+
55
+ subInit.prototype = WordArray;
56
+ }());
package/src/md5.js ADDED
@@ -0,0 +1,248 @@
1
+ (function (Math) {
2
+ // Shortcuts
3
+ var C = CryptoJS;
4
+ var C_lib = C.lib;
5
+ var WordArray = C_lib.WordArray;
6
+ var Hasher = C_lib.Hasher;
7
+ var C_algo = C.algo;
8
+
9
+ // Constants table
10
+ var T = [];
11
+
12
+ // Compute constants
13
+ (function () {
14
+ for (var i = 0; i < 64; i++) {
15
+ T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0;
16
+ }
17
+ }());
18
+
19
+ /**
20
+ * MD5 hash algorithm.
21
+ */
22
+ var MD5 = C_algo.MD5 = Hasher.extend({
23
+ _doReset: function () {
24
+ this._hash = new WordArray.init([
25
+ 0x67452301, 0xefcdab89,
26
+ 0x98badcfe, 0x10325476
27
+ ]);
28
+ },
29
+
30
+ _doProcessBlock: function (M, offset) {
31
+ // Swap endian
32
+ for (var i = 0; i < 16; i++) {
33
+ // Shortcuts
34
+ var offset_i = offset + i;
35
+ var M_offset_i = M[offset_i];
36
+
37
+ M[offset_i] = (
38
+ (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
39
+ (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
40
+ );
41
+ }
42
+
43
+ // Shortcuts
44
+ var H = this._hash.words;
45
+
46
+ var M_offset_0 = M[offset + 0];
47
+ var M_offset_1 = M[offset + 1];
48
+ var M_offset_2 = M[offset + 2];
49
+ var M_offset_3 = M[offset + 3];
50
+ var M_offset_4 = M[offset + 4];
51
+ var M_offset_5 = M[offset + 5];
52
+ var M_offset_6 = M[offset + 6];
53
+ var M_offset_7 = M[offset + 7];
54
+ var M_offset_8 = M[offset + 8];
55
+ var M_offset_9 = M[offset + 9];
56
+ var M_offset_10 = M[offset + 10];
57
+ var M_offset_11 = M[offset + 11];
58
+ var M_offset_12 = M[offset + 12];
59
+ var M_offset_13 = M[offset + 13];
60
+ var M_offset_14 = M[offset + 14];
61
+ var M_offset_15 = M[offset + 15];
62
+
63
+ // Working variables
64
+ var a = H[0];
65
+ var b = H[1];
66
+ var c = H[2];
67
+ var d = H[3];
68
+
69
+ // Computation
70
+ a = FF(a, b, c, d, M_offset_0, 7, T[0]);
71
+ d = FF(d, a, b, c, M_offset_1, 12, T[1]);
72
+ c = FF(c, d, a, b, M_offset_2, 17, T[2]);
73
+ b = FF(b, c, d, a, M_offset_3, 22, T[3]);
74
+ a = FF(a, b, c, d, M_offset_4, 7, T[4]);
75
+ d = FF(d, a, b, c, M_offset_5, 12, T[5]);
76
+ c = FF(c, d, a, b, M_offset_6, 17, T[6]);
77
+ b = FF(b, c, d, a, M_offset_7, 22, T[7]);
78
+ a = FF(a, b, c, d, M_offset_8, 7, T[8]);
79
+ d = FF(d, a, b, c, M_offset_9, 12, T[9]);
80
+ c = FF(c, d, a, b, M_offset_10, 17, T[10]);
81
+ b = FF(b, c, d, a, M_offset_11, 22, T[11]);
82
+ a = FF(a, b, c, d, M_offset_12, 7, T[12]);
83
+ d = FF(d, a, b, c, M_offset_13, 12, T[13]);
84
+ c = FF(c, d, a, b, M_offset_14, 17, T[14]);
85
+ b = FF(b, c, d, a, M_offset_15, 22, T[15]);
86
+
87
+ a = GG(a, b, c, d, M_offset_1, 5, T[16]);
88
+ d = GG(d, a, b, c, M_offset_6, 9, T[17]);
89
+ c = GG(c, d, a, b, M_offset_11, 14, T[18]);
90
+ b = GG(b, c, d, a, M_offset_0, 20, T[19]);
91
+ a = GG(a, b, c, d, M_offset_5, 5, T[20]);
92
+ d = GG(d, a, b, c, M_offset_10, 9, T[21]);
93
+ c = GG(c, d, a, b, M_offset_15, 14, T[22]);
94
+ b = GG(b, c, d, a, M_offset_4, 20, T[23]);
95
+ a = GG(a, b, c, d, M_offset_9, 5, T[24]);
96
+ d = GG(d, a, b, c, M_offset_14, 9, T[25]);
97
+ c = GG(c, d, a, b, M_offset_3, 14, T[26]);
98
+ b = GG(b, c, d, a, M_offset_8, 20, T[27]);
99
+ a = GG(a, b, c, d, M_offset_13, 5, T[28]);
100
+ d = GG(d, a, b, c, M_offset_2, 9, T[29]);
101
+ c = GG(c, d, a, b, M_offset_7, 14, T[30]);
102
+ b = GG(b, c, d, a, M_offset_12, 20, T[31]);
103
+
104
+ a = HH(a, b, c, d, M_offset_5, 4, T[32]);
105
+ d = HH(d, a, b, c, M_offset_8, 11, T[33]);
106
+ c = HH(c, d, a, b, M_offset_11, 16, T[34]);
107
+ b = HH(b, c, d, a, M_offset_14, 23, T[35]);
108
+ a = HH(a, b, c, d, M_offset_1, 4, T[36]);
109
+ d = HH(d, a, b, c, M_offset_4, 11, T[37]);
110
+ c = HH(c, d, a, b, M_offset_7, 16, T[38]);
111
+ b = HH(b, c, d, a, M_offset_10, 23, T[39]);
112
+ a = HH(a, b, c, d, M_offset_13, 4, T[40]);
113
+ d = HH(d, a, b, c, M_offset_0, 11, T[41]);
114
+ c = HH(c, d, a, b, M_offset_3, 16, T[42]);
115
+ b = HH(b, c, d, a, M_offset_6, 23, T[43]);
116
+ a = HH(a, b, c, d, M_offset_9, 4, T[44]);
117
+ d = HH(d, a, b, c, M_offset_12, 11, T[45]);
118
+ c = HH(c, d, a, b, M_offset_15, 16, T[46]);
119
+ b = HH(b, c, d, a, M_offset_2, 23, T[47]);
120
+
121
+ a = II(a, b, c, d, M_offset_0, 6, T[48]);
122
+ d = II(d, a, b, c, M_offset_7, 10, T[49]);
123
+ c = II(c, d, a, b, M_offset_14, 15, T[50]);
124
+ b = II(b, c, d, a, M_offset_5, 21, T[51]);
125
+ a = II(a, b, c, d, M_offset_12, 6, T[52]);
126
+ d = II(d, a, b, c, M_offset_3, 10, T[53]);
127
+ c = II(c, d, a, b, M_offset_10, 15, T[54]);
128
+ b = II(b, c, d, a, M_offset_1, 21, T[55]);
129
+ a = II(a, b, c, d, M_offset_8, 6, T[56]);
130
+ d = II(d, a, b, c, M_offset_15, 10, T[57]);
131
+ c = II(c, d, a, b, M_offset_6, 15, T[58]);
132
+ b = II(b, c, d, a, M_offset_13, 21, T[59]);
133
+ a = II(a, b, c, d, M_offset_4, 6, T[60]);
134
+ d = II(d, a, b, c, M_offset_11, 10, T[61]);
135
+ c = II(c, d, a, b, M_offset_2, 15, T[62]);
136
+ b = II(b, c, d, a, M_offset_9, 21, T[63]);
137
+
138
+ // Intermediate hash value
139
+ H[0] = (H[0] + a) | 0;
140
+ H[1] = (H[1] + b) | 0;
141
+ H[2] = (H[2] + c) | 0;
142
+ H[3] = (H[3] + d) | 0;
143
+ },
144
+
145
+ _doFinalize: function () {
146
+ // Shortcuts
147
+ var data = this._data;
148
+ var dataWords = data.words;
149
+
150
+ var nBitsTotal = this._nDataBytes * 8;
151
+ var nBitsLeft = data.sigBytes * 8;
152
+
153
+ // Add padding
154
+ dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
155
+
156
+ var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000);
157
+ var nBitsTotalL = nBitsTotal;
158
+ dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = (
159
+ (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) |
160
+ (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00)
161
+ );
162
+ dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
163
+ (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) |
164
+ (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00)
165
+ );
166
+
167
+ data.sigBytes = (dataWords.length + 1) * 4;
168
+
169
+ // Hash final blocks
170
+ this._process();
171
+
172
+ // Shortcuts
173
+ var hash = this._hash;
174
+ var H = hash.words;
175
+
176
+ // Swap endian
177
+ for (var i = 0; i < 4; i++) {
178
+ // Shortcut
179
+ var H_i = H[i];
180
+
181
+ H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
182
+ (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
183
+ }
184
+
185
+ // Return final computed hash
186
+ return hash;
187
+ },
188
+
189
+ clone: function () {
190
+ var clone = Hasher.clone.call(this);
191
+ clone._hash = this._hash.clone();
192
+
193
+ return clone;
194
+ }
195
+ });
196
+
197
+ function FF(a, b, c, d, x, s, t) {
198
+ var n = a + ((b & c) | (~b & d)) + x + t;
199
+ return ((n << s) | (n >>> (32 - s))) + b;
200
+ }
201
+
202
+ function GG(a, b, c, d, x, s, t) {
203
+ var n = a + ((b & d) | (c & ~d)) + x + t;
204
+ return ((n << s) | (n >>> (32 - s))) + b;
205
+ }
206
+
207
+ function HH(a, b, c, d, x, s, t) {
208
+ var n = a + (b ^ c ^ d) + x + t;
209
+ return ((n << s) | (n >>> (32 - s))) + b;
210
+ }
211
+
212
+ function II(a, b, c, d, x, s, t) {
213
+ var n = a + (c ^ (b | ~d)) + x + t;
214
+ return ((n << s) | (n >>> (32 - s))) + b;
215
+ }
216
+
217
+ /**
218
+ * Shortcut function to the hasher's object interface.
219
+ *
220
+ * @param {WordArray|string} message The message to hash.
221
+ *
222
+ * @return {WordArray} The hash.
223
+ *
224
+ * @static
225
+ *
226
+ * @example
227
+ *
228
+ * var hash = CryptoJS.MD5('message');
229
+ * var hash = CryptoJS.MD5(wordArray);
230
+ */
231
+ C.MD5 = Hasher._createHelper(MD5);
232
+
233
+ /**
234
+ * Shortcut function to the HMAC's object interface.
235
+ *
236
+ * @param {WordArray|string} message The message to hash.
237
+ * @param {WordArray|string} key The secret key.
238
+ *
239
+ * @return {WordArray} The HMAC.
240
+ *
241
+ * @static
242
+ *
243
+ * @example
244
+ *
245
+ * var hmac = CryptoJS.HmacMD5(message, key);
246
+ */
247
+ C.HmacMD5 = Hasher._createHmacHelper(MD5);
248
+ }(Math));
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Cipher Feedback block mode.
3
+ */
4
+ CryptoJS.mode.CFB = (function () {
5
+ var CFB = CryptoJS.lib.BlockCipherMode.extend();
6
+
7
+ CFB.Encryptor = CFB.extend({
8
+ processBlock: function (words, offset) {
9
+ // Shortcuts
10
+ var cipher = this._cipher;
11
+ var blockSize = cipher.blockSize;
12
+
13
+ generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
14
+
15
+ // Remember this block to use with next block
16
+ this._prevBlock = words.slice(offset, offset + blockSize);
17
+ }
18
+ });
19
+
20
+ CFB.Decryptor = CFB.extend({
21
+ processBlock: function (words, offset) {
22
+ // Shortcuts
23
+ var cipher = this._cipher;
24
+ var blockSize = cipher.blockSize;
25
+
26
+ // Remember this block to use with next block
27
+ var thisBlock = words.slice(offset, offset + blockSize);
28
+
29
+ generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
30
+
31
+ // This block becomes the previous block
32
+ this._prevBlock = thisBlock;
33
+ }
34
+ });
35
+
36
+ function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) {
37
+ var keystream;
38
+
39
+ // Shortcut
40
+ var iv = this._iv;
41
+
42
+ // Generate keystream
43
+ if (iv) {
44
+ keystream = iv.slice(0);
45
+
46
+ // Remove IV for subsequent blocks
47
+ this._iv = undefined;
48
+ } else {
49
+ keystream = this._prevBlock;
50
+ }
51
+ cipher.encryptBlock(keystream, 0);
52
+
53
+ // Encrypt
54
+ for (var i = 0; i < blockSize; i++) {
55
+ words[offset + i] ^= keystream[i];
56
+ }
57
+ }
58
+
59
+ return CFB;
60
+ }());
@@ -0,0 +1,96 @@
1
+ /** @preserve
2
+ * Counter block mode compatible with Dr Brian Gladman fileenc.c
3
+ * derived from CryptoJS.mode.CTR
4
+ * Jan Hruby jhruby.web@gmail.com
5
+ */
6
+ CryptoJS.mode.CTRGladman = (function () {
7
+ var CTRGladman = CryptoJS.lib.BlockCipherMode.extend();
8
+
9
+ function incWord(word)
10
+ {
11
+ if (((word >> 24) & 0xff) === 0xff) { //overflow
12
+ var b1 = (word >> 16)&0xff;
13
+ var b2 = (word >> 8)&0xff;
14
+ var b3 = word & 0xff;
15
+
16
+ if (b1 === 0xff) // overflow b1
17
+ {
18
+ b1 = 0;
19
+ if (b2 === 0xff)
20
+ {
21
+ b2 = 0;
22
+ if (b3 === 0xff)
23
+ {
24
+ b3 = 0;
25
+ }
26
+ else
27
+ {
28
+ ++b3;
29
+ }
30
+ }
31
+ else
32
+ {
33
+ ++b2;
34
+ }
35
+ }
36
+ else
37
+ {
38
+ ++b1;
39
+ }
40
+
41
+ word = 0;
42
+ word += (b1 << 16);
43
+ word += (b2 << 8);
44
+ word += b3;
45
+ }
46
+ else
47
+ {
48
+ word += (0x01 << 24);
49
+ }
50
+ return word;
51
+ }
52
+
53
+ function incCounter(counter)
54
+ {
55
+ if ((counter[0] = incWord(counter[0])) === 0)
56
+ {
57
+ // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
58
+ counter[1] = incWord(counter[1]);
59
+ }
60
+ return counter;
61
+ }
62
+
63
+ var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({
64
+ processBlock: function (words, offset) {
65
+ // Shortcuts
66
+ var cipher = this._cipher
67
+ var blockSize = cipher.blockSize;
68
+ var iv = this._iv;
69
+ var counter = this._counter;
70
+
71
+ // Generate keystream
72
+ if (iv) {
73
+ counter = this._counter = iv.slice(0);
74
+
75
+ // Remove IV for subsequent blocks
76
+ this._iv = undefined;
77
+ }
78
+
79
+ incCounter(counter);
80
+
81
+ var keystream = counter.slice(0);
82
+ cipher.encryptBlock(keystream, 0);
83
+
84
+ // Encrypt
85
+ for (var i = 0; i < blockSize; i++) {
86
+ words[offset + i] ^= keystream[i];
87
+ }
88
+ }
89
+ });
90
+
91
+ CTRGladman.Decryptor = Encryptor;
92
+
93
+ return CTRGladman;
94
+ }());
95
+
96
+
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Counter block mode.
3
+ */
4
+ CryptoJS.mode.CTR = (function () {
5
+ var CTR = CryptoJS.lib.BlockCipherMode.extend();
6
+
7
+ var Encryptor = CTR.Encryptor = CTR.extend({
8
+ processBlock: function (words, offset) {
9
+ // Shortcuts
10
+ var cipher = this._cipher
11
+ var blockSize = cipher.blockSize;
12
+ var iv = this._iv;
13
+ var counter = this._counter;
14
+
15
+ // Generate keystream
16
+ if (iv) {
17
+ counter = this._counter = iv.slice(0);
18
+
19
+ // Remove IV for subsequent blocks
20
+ this._iv = undefined;
21
+ }
22
+ var keystream = counter.slice(0);
23
+ cipher.encryptBlock(keystream, 0);
24
+
25
+ // Increment counter
26
+ counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0
27
+
28
+ // Encrypt
29
+ for (var i = 0; i < blockSize; i++) {
30
+ words[offset + i] ^= keystream[i];
31
+ }
32
+ }
33
+ });
34
+
35
+ CTR.Decryptor = Encryptor;
36
+
37
+ return CTR;
38
+ }());
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Electronic Codebook block mode.
3
+ */
4
+ CryptoJS.mode.ECB = (function () {
5
+ var ECB = CryptoJS.lib.BlockCipherMode.extend();
6
+
7
+ ECB.Encryptor = ECB.extend({
8
+ processBlock: function (words, offset) {
9
+ this._cipher.encryptBlock(words, offset);
10
+ }
11
+ });
12
+
13
+ ECB.Decryptor = ECB.extend({
14
+ processBlock: function (words, offset) {
15
+ this._cipher.decryptBlock(words, offset);
16
+ }
17
+ });
18
+
19
+ return ECB;
20
+ }());
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Output Feedback block mode.
3
+ */
4
+ CryptoJS.mode.OFB = (function () {
5
+ var OFB = CryptoJS.lib.BlockCipherMode.extend();
6
+
7
+ var Encryptor = OFB.Encryptor = OFB.extend({
8
+ processBlock: function (words, offset) {
9
+ // Shortcuts
10
+ var cipher = this._cipher
11
+ var blockSize = cipher.blockSize;
12
+ var iv = this._iv;
13
+ var keystream = this._keystream;
14
+
15
+ // Generate keystream
16
+ if (iv) {
17
+ keystream = this._keystream = iv.slice(0);
18
+
19
+ // Remove IV for subsequent blocks
20
+ this._iv = undefined;
21
+ }
22
+ cipher.encryptBlock(keystream, 0);
23
+
24
+ // Encrypt
25
+ for (var i = 0; i < blockSize; i++) {
26
+ words[offset + i] ^= keystream[i];
27
+ }
28
+ }
29
+ });
30
+
31
+ OFB.Decryptor = Encryptor;
32
+
33
+ return OFB;
34
+ }());
@@ -0,0 +1,29 @@
1
+ /**
2
+ * ANSI X.923 padding strategy.
3
+ */
4
+ CryptoJS.pad.AnsiX923 = {
5
+ pad: function (data, blockSize) {
6
+ // Shortcuts
7
+ var dataSigBytes = data.sigBytes;
8
+ var blockSizeBytes = blockSize * 4;
9
+
10
+ // Count padding bytes
11
+ var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes;
12
+
13
+ // Compute last byte position
14
+ var lastBytePos = dataSigBytes + nPaddingBytes - 1;
15
+
16
+ // Pad
17
+ data.clamp();
18
+ data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8);
19
+ data.sigBytes += nPaddingBytes;
20
+ },
21
+
22
+ unpad: function (data) {
23
+ // Get number of padding bytes from last byte
24
+ var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
25
+
26
+ // Remove padding
27
+ data.sigBytes -= nPaddingBytes;
28
+ }
29
+ };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * ISO 10126 padding strategy.
3
+ */
4
+ CryptoJS.pad.Iso10126 = {
5
+ pad: function (data, blockSize) {
6
+ // Shortcut
7
+ var blockSizeBytes = blockSize * 4;
8
+
9
+ // Count padding bytes
10
+ var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
11
+
12
+ // Pad
13
+ data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)).
14
+ concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1));
15
+ },
16
+
17
+ unpad: function (data) {
18
+ // Get number of padding bytes from last byte
19
+ var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
20
+
21
+ // Remove padding
22
+ data.sigBytes -= nPaddingBytes;
23
+ }
24
+ };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * ISO/IEC 9797-1 Padding Method 2.
3
+ */
4
+ CryptoJS.pad.Iso97971 = {
5
+ pad: function (data, blockSize) {
6
+ // Add 0x80 byte
7
+ data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1));
8
+
9
+ // Zero pad the rest
10
+ CryptoJS.pad.ZeroPadding.pad(data, blockSize);
11
+ },
12
+
13
+ unpad: function (data) {
14
+ // Remove zero padding
15
+ CryptoJS.pad.ZeroPadding.unpad(data);
16
+
17
+ // Remove one more byte -- the 0x80 byte
18
+ data.sigBytes--;
19
+ }
20
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A noop padding strategy.
3
+ */
4
+ CryptoJS.pad.NoPadding = {
5
+ pad: function () {
6
+ },
7
+
8
+ unpad: function () {
9
+ }
10
+ };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Zero padding strategy.
3
+ */
4
+ CryptoJS.pad.ZeroPadding = {
5
+ pad: function (data, blockSize) {
6
+ // Shortcut
7
+ var blockSizeBytes = blockSize * 4;
8
+
9
+ // Pad
10
+ data.clamp();
11
+ data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes);
12
+ },
13
+
14
+ unpad: function (data) {
15
+ // Shortcut
16
+ var dataWords = data.words;
17
+
18
+ // Unpad
19
+ var i = data.sigBytes - 1;
20
+ for (var i = data.sigBytes - 1; i >= 0; i--) {
21
+ if (((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) {
22
+ data.sigBytes = i + 1;
23
+ break;
24
+ }
25
+ }
26
+ }
27
+ };