@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,759 @@
1
+ (function () {
2
+ // Shortcuts
3
+ var C = CryptoJS;
4
+ var C_lib = C.lib;
5
+ var WordArray = C_lib.WordArray;
6
+ var BlockCipher = C_lib.BlockCipher;
7
+ var C_algo = C.algo;
8
+
9
+ // Permuted Choice 1 constants
10
+ var PC1 = [
11
+ 57, 49, 41, 33, 25, 17, 9, 1,
12
+ 58, 50, 42, 34, 26, 18, 10, 2,
13
+ 59, 51, 43, 35, 27, 19, 11, 3,
14
+ 60, 52, 44, 36, 63, 55, 47, 39,
15
+ 31, 23, 15, 7, 62, 54, 46, 38,
16
+ 30, 22, 14, 6, 61, 53, 45, 37,
17
+ 29, 21, 13, 5, 28, 20, 12, 4
18
+ ];
19
+
20
+ // Permuted Choice 2 constants
21
+ var PC2 = [
22
+ 14, 17, 11, 24, 1, 5,
23
+ 3, 28, 15, 6, 21, 10,
24
+ 23, 19, 12, 4, 26, 8,
25
+ 16, 7, 27, 20, 13, 2,
26
+ 41, 52, 31, 37, 47, 55,
27
+ 30, 40, 51, 45, 33, 48,
28
+ 44, 49, 39, 56, 34, 53,
29
+ 46, 42, 50, 36, 29, 32
30
+ ];
31
+
32
+ // Cumulative bit shift constants
33
+ var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28];
34
+
35
+ // SBOXes and round permutation constants
36
+ var SBOX_P = [
37
+ {
38
+ 0x0: 0x808200,
39
+ 0x10000000: 0x8000,
40
+ 0x20000000: 0x808002,
41
+ 0x30000000: 0x2,
42
+ 0x40000000: 0x200,
43
+ 0x50000000: 0x808202,
44
+ 0x60000000: 0x800202,
45
+ 0x70000000: 0x800000,
46
+ 0x80000000: 0x202,
47
+ 0x90000000: 0x800200,
48
+ 0xa0000000: 0x8200,
49
+ 0xb0000000: 0x808000,
50
+ 0xc0000000: 0x8002,
51
+ 0xd0000000: 0x800002,
52
+ 0xe0000000: 0x0,
53
+ 0xf0000000: 0x8202,
54
+ 0x8000000: 0x0,
55
+ 0x18000000: 0x808202,
56
+ 0x28000000: 0x8202,
57
+ 0x38000000: 0x8000,
58
+ 0x48000000: 0x808200,
59
+ 0x58000000: 0x200,
60
+ 0x68000000: 0x808002,
61
+ 0x78000000: 0x2,
62
+ 0x88000000: 0x800200,
63
+ 0x98000000: 0x8200,
64
+ 0xa8000000: 0x808000,
65
+ 0xb8000000: 0x800202,
66
+ 0xc8000000: 0x800002,
67
+ 0xd8000000: 0x8002,
68
+ 0xe8000000: 0x202,
69
+ 0xf8000000: 0x800000,
70
+ 0x1: 0x8000,
71
+ 0x10000001: 0x2,
72
+ 0x20000001: 0x808200,
73
+ 0x30000001: 0x800000,
74
+ 0x40000001: 0x808002,
75
+ 0x50000001: 0x8200,
76
+ 0x60000001: 0x200,
77
+ 0x70000001: 0x800202,
78
+ 0x80000001: 0x808202,
79
+ 0x90000001: 0x808000,
80
+ 0xa0000001: 0x800002,
81
+ 0xb0000001: 0x8202,
82
+ 0xc0000001: 0x202,
83
+ 0xd0000001: 0x800200,
84
+ 0xe0000001: 0x8002,
85
+ 0xf0000001: 0x0,
86
+ 0x8000001: 0x808202,
87
+ 0x18000001: 0x808000,
88
+ 0x28000001: 0x800000,
89
+ 0x38000001: 0x200,
90
+ 0x48000001: 0x8000,
91
+ 0x58000001: 0x800002,
92
+ 0x68000001: 0x2,
93
+ 0x78000001: 0x8202,
94
+ 0x88000001: 0x8002,
95
+ 0x98000001: 0x800202,
96
+ 0xa8000001: 0x202,
97
+ 0xb8000001: 0x808200,
98
+ 0xc8000001: 0x800200,
99
+ 0xd8000001: 0x0,
100
+ 0xe8000001: 0x8200,
101
+ 0xf8000001: 0x808002
102
+ },
103
+ {
104
+ 0x0: 0x40084010,
105
+ 0x1000000: 0x4000,
106
+ 0x2000000: 0x80000,
107
+ 0x3000000: 0x40080010,
108
+ 0x4000000: 0x40000010,
109
+ 0x5000000: 0x40084000,
110
+ 0x6000000: 0x40004000,
111
+ 0x7000000: 0x10,
112
+ 0x8000000: 0x84000,
113
+ 0x9000000: 0x40004010,
114
+ 0xa000000: 0x40000000,
115
+ 0xb000000: 0x84010,
116
+ 0xc000000: 0x80010,
117
+ 0xd000000: 0x0,
118
+ 0xe000000: 0x4010,
119
+ 0xf000000: 0x40080000,
120
+ 0x800000: 0x40004000,
121
+ 0x1800000: 0x84010,
122
+ 0x2800000: 0x10,
123
+ 0x3800000: 0x40004010,
124
+ 0x4800000: 0x40084010,
125
+ 0x5800000: 0x40000000,
126
+ 0x6800000: 0x80000,
127
+ 0x7800000: 0x40080010,
128
+ 0x8800000: 0x80010,
129
+ 0x9800000: 0x0,
130
+ 0xa800000: 0x4000,
131
+ 0xb800000: 0x40080000,
132
+ 0xc800000: 0x40000010,
133
+ 0xd800000: 0x84000,
134
+ 0xe800000: 0x40084000,
135
+ 0xf800000: 0x4010,
136
+ 0x10000000: 0x0,
137
+ 0x11000000: 0x40080010,
138
+ 0x12000000: 0x40004010,
139
+ 0x13000000: 0x40084000,
140
+ 0x14000000: 0x40080000,
141
+ 0x15000000: 0x10,
142
+ 0x16000000: 0x84010,
143
+ 0x17000000: 0x4000,
144
+ 0x18000000: 0x4010,
145
+ 0x19000000: 0x80000,
146
+ 0x1a000000: 0x80010,
147
+ 0x1b000000: 0x40000010,
148
+ 0x1c000000: 0x84000,
149
+ 0x1d000000: 0x40004000,
150
+ 0x1e000000: 0x40000000,
151
+ 0x1f000000: 0x40084010,
152
+ 0x10800000: 0x84010,
153
+ 0x11800000: 0x80000,
154
+ 0x12800000: 0x40080000,
155
+ 0x13800000: 0x4000,
156
+ 0x14800000: 0x40004000,
157
+ 0x15800000: 0x40084010,
158
+ 0x16800000: 0x10,
159
+ 0x17800000: 0x40000000,
160
+ 0x18800000: 0x40084000,
161
+ 0x19800000: 0x40000010,
162
+ 0x1a800000: 0x40004010,
163
+ 0x1b800000: 0x80010,
164
+ 0x1c800000: 0x0,
165
+ 0x1d800000: 0x4010,
166
+ 0x1e800000: 0x40080010,
167
+ 0x1f800000: 0x84000
168
+ },
169
+ {
170
+ 0x0: 0x104,
171
+ 0x100000: 0x0,
172
+ 0x200000: 0x4000100,
173
+ 0x300000: 0x10104,
174
+ 0x400000: 0x10004,
175
+ 0x500000: 0x4000004,
176
+ 0x600000: 0x4010104,
177
+ 0x700000: 0x4010000,
178
+ 0x800000: 0x4000000,
179
+ 0x900000: 0x4010100,
180
+ 0xa00000: 0x10100,
181
+ 0xb00000: 0x4010004,
182
+ 0xc00000: 0x4000104,
183
+ 0xd00000: 0x10000,
184
+ 0xe00000: 0x4,
185
+ 0xf00000: 0x100,
186
+ 0x80000: 0x4010100,
187
+ 0x180000: 0x4010004,
188
+ 0x280000: 0x0,
189
+ 0x380000: 0x4000100,
190
+ 0x480000: 0x4000004,
191
+ 0x580000: 0x10000,
192
+ 0x680000: 0x10004,
193
+ 0x780000: 0x104,
194
+ 0x880000: 0x4,
195
+ 0x980000: 0x100,
196
+ 0xa80000: 0x4010000,
197
+ 0xb80000: 0x10104,
198
+ 0xc80000: 0x10100,
199
+ 0xd80000: 0x4000104,
200
+ 0xe80000: 0x4010104,
201
+ 0xf80000: 0x4000000,
202
+ 0x1000000: 0x4010100,
203
+ 0x1100000: 0x10004,
204
+ 0x1200000: 0x10000,
205
+ 0x1300000: 0x4000100,
206
+ 0x1400000: 0x100,
207
+ 0x1500000: 0x4010104,
208
+ 0x1600000: 0x4000004,
209
+ 0x1700000: 0x0,
210
+ 0x1800000: 0x4000104,
211
+ 0x1900000: 0x4000000,
212
+ 0x1a00000: 0x4,
213
+ 0x1b00000: 0x10100,
214
+ 0x1c00000: 0x4010000,
215
+ 0x1d00000: 0x104,
216
+ 0x1e00000: 0x10104,
217
+ 0x1f00000: 0x4010004,
218
+ 0x1080000: 0x4000000,
219
+ 0x1180000: 0x104,
220
+ 0x1280000: 0x4010100,
221
+ 0x1380000: 0x0,
222
+ 0x1480000: 0x10004,
223
+ 0x1580000: 0x4000100,
224
+ 0x1680000: 0x100,
225
+ 0x1780000: 0x4010004,
226
+ 0x1880000: 0x10000,
227
+ 0x1980000: 0x4010104,
228
+ 0x1a80000: 0x10104,
229
+ 0x1b80000: 0x4000004,
230
+ 0x1c80000: 0x4000104,
231
+ 0x1d80000: 0x4010000,
232
+ 0x1e80000: 0x4,
233
+ 0x1f80000: 0x10100
234
+ },
235
+ {
236
+ 0x0: 0x80401000,
237
+ 0x10000: 0x80001040,
238
+ 0x20000: 0x401040,
239
+ 0x30000: 0x80400000,
240
+ 0x40000: 0x0,
241
+ 0x50000: 0x401000,
242
+ 0x60000: 0x80000040,
243
+ 0x70000: 0x400040,
244
+ 0x80000: 0x80000000,
245
+ 0x90000: 0x400000,
246
+ 0xa0000: 0x40,
247
+ 0xb0000: 0x80001000,
248
+ 0xc0000: 0x80400040,
249
+ 0xd0000: 0x1040,
250
+ 0xe0000: 0x1000,
251
+ 0xf0000: 0x80401040,
252
+ 0x8000: 0x80001040,
253
+ 0x18000: 0x40,
254
+ 0x28000: 0x80400040,
255
+ 0x38000: 0x80001000,
256
+ 0x48000: 0x401000,
257
+ 0x58000: 0x80401040,
258
+ 0x68000: 0x0,
259
+ 0x78000: 0x80400000,
260
+ 0x88000: 0x1000,
261
+ 0x98000: 0x80401000,
262
+ 0xa8000: 0x400000,
263
+ 0xb8000: 0x1040,
264
+ 0xc8000: 0x80000000,
265
+ 0xd8000: 0x400040,
266
+ 0xe8000: 0x401040,
267
+ 0xf8000: 0x80000040,
268
+ 0x100000: 0x400040,
269
+ 0x110000: 0x401000,
270
+ 0x120000: 0x80000040,
271
+ 0x130000: 0x0,
272
+ 0x140000: 0x1040,
273
+ 0x150000: 0x80400040,
274
+ 0x160000: 0x80401000,
275
+ 0x170000: 0x80001040,
276
+ 0x180000: 0x80401040,
277
+ 0x190000: 0x80000000,
278
+ 0x1a0000: 0x80400000,
279
+ 0x1b0000: 0x401040,
280
+ 0x1c0000: 0x80001000,
281
+ 0x1d0000: 0x400000,
282
+ 0x1e0000: 0x40,
283
+ 0x1f0000: 0x1000,
284
+ 0x108000: 0x80400000,
285
+ 0x118000: 0x80401040,
286
+ 0x128000: 0x0,
287
+ 0x138000: 0x401000,
288
+ 0x148000: 0x400040,
289
+ 0x158000: 0x80000000,
290
+ 0x168000: 0x80001040,
291
+ 0x178000: 0x40,
292
+ 0x188000: 0x80000040,
293
+ 0x198000: 0x1000,
294
+ 0x1a8000: 0x80001000,
295
+ 0x1b8000: 0x80400040,
296
+ 0x1c8000: 0x1040,
297
+ 0x1d8000: 0x80401000,
298
+ 0x1e8000: 0x400000,
299
+ 0x1f8000: 0x401040
300
+ },
301
+ {
302
+ 0x0: 0x80,
303
+ 0x1000: 0x1040000,
304
+ 0x2000: 0x40000,
305
+ 0x3000: 0x20000000,
306
+ 0x4000: 0x20040080,
307
+ 0x5000: 0x1000080,
308
+ 0x6000: 0x21000080,
309
+ 0x7000: 0x40080,
310
+ 0x8000: 0x1000000,
311
+ 0x9000: 0x20040000,
312
+ 0xa000: 0x20000080,
313
+ 0xb000: 0x21040080,
314
+ 0xc000: 0x21040000,
315
+ 0xd000: 0x0,
316
+ 0xe000: 0x1040080,
317
+ 0xf000: 0x21000000,
318
+ 0x800: 0x1040080,
319
+ 0x1800: 0x21000080,
320
+ 0x2800: 0x80,
321
+ 0x3800: 0x1040000,
322
+ 0x4800: 0x40000,
323
+ 0x5800: 0x20040080,
324
+ 0x6800: 0x21040000,
325
+ 0x7800: 0x20000000,
326
+ 0x8800: 0x20040000,
327
+ 0x9800: 0x0,
328
+ 0xa800: 0x21040080,
329
+ 0xb800: 0x1000080,
330
+ 0xc800: 0x20000080,
331
+ 0xd800: 0x21000000,
332
+ 0xe800: 0x1000000,
333
+ 0xf800: 0x40080,
334
+ 0x10000: 0x40000,
335
+ 0x11000: 0x80,
336
+ 0x12000: 0x20000000,
337
+ 0x13000: 0x21000080,
338
+ 0x14000: 0x1000080,
339
+ 0x15000: 0x21040000,
340
+ 0x16000: 0x20040080,
341
+ 0x17000: 0x1000000,
342
+ 0x18000: 0x21040080,
343
+ 0x19000: 0x21000000,
344
+ 0x1a000: 0x1040000,
345
+ 0x1b000: 0x20040000,
346
+ 0x1c000: 0x40080,
347
+ 0x1d000: 0x20000080,
348
+ 0x1e000: 0x0,
349
+ 0x1f000: 0x1040080,
350
+ 0x10800: 0x21000080,
351
+ 0x11800: 0x1000000,
352
+ 0x12800: 0x1040000,
353
+ 0x13800: 0x20040080,
354
+ 0x14800: 0x20000000,
355
+ 0x15800: 0x1040080,
356
+ 0x16800: 0x80,
357
+ 0x17800: 0x21040000,
358
+ 0x18800: 0x40080,
359
+ 0x19800: 0x21040080,
360
+ 0x1a800: 0x0,
361
+ 0x1b800: 0x21000000,
362
+ 0x1c800: 0x1000080,
363
+ 0x1d800: 0x40000,
364
+ 0x1e800: 0x20040000,
365
+ 0x1f800: 0x20000080
366
+ },
367
+ {
368
+ 0x0: 0x10000008,
369
+ 0x100: 0x2000,
370
+ 0x200: 0x10200000,
371
+ 0x300: 0x10202008,
372
+ 0x400: 0x10002000,
373
+ 0x500: 0x200000,
374
+ 0x600: 0x200008,
375
+ 0x700: 0x10000000,
376
+ 0x800: 0x0,
377
+ 0x900: 0x10002008,
378
+ 0xa00: 0x202000,
379
+ 0xb00: 0x8,
380
+ 0xc00: 0x10200008,
381
+ 0xd00: 0x202008,
382
+ 0xe00: 0x2008,
383
+ 0xf00: 0x10202000,
384
+ 0x80: 0x10200000,
385
+ 0x180: 0x10202008,
386
+ 0x280: 0x8,
387
+ 0x380: 0x200000,
388
+ 0x480: 0x202008,
389
+ 0x580: 0x10000008,
390
+ 0x680: 0x10002000,
391
+ 0x780: 0x2008,
392
+ 0x880: 0x200008,
393
+ 0x980: 0x2000,
394
+ 0xa80: 0x10002008,
395
+ 0xb80: 0x10200008,
396
+ 0xc80: 0x0,
397
+ 0xd80: 0x10202000,
398
+ 0xe80: 0x202000,
399
+ 0xf80: 0x10000000,
400
+ 0x1000: 0x10002000,
401
+ 0x1100: 0x10200008,
402
+ 0x1200: 0x10202008,
403
+ 0x1300: 0x2008,
404
+ 0x1400: 0x200000,
405
+ 0x1500: 0x10000000,
406
+ 0x1600: 0x10000008,
407
+ 0x1700: 0x202000,
408
+ 0x1800: 0x202008,
409
+ 0x1900: 0x0,
410
+ 0x1a00: 0x8,
411
+ 0x1b00: 0x10200000,
412
+ 0x1c00: 0x2000,
413
+ 0x1d00: 0x10002008,
414
+ 0x1e00: 0x10202000,
415
+ 0x1f00: 0x200008,
416
+ 0x1080: 0x8,
417
+ 0x1180: 0x202000,
418
+ 0x1280: 0x200000,
419
+ 0x1380: 0x10000008,
420
+ 0x1480: 0x10002000,
421
+ 0x1580: 0x2008,
422
+ 0x1680: 0x10202008,
423
+ 0x1780: 0x10200000,
424
+ 0x1880: 0x10202000,
425
+ 0x1980: 0x10200008,
426
+ 0x1a80: 0x2000,
427
+ 0x1b80: 0x202008,
428
+ 0x1c80: 0x200008,
429
+ 0x1d80: 0x0,
430
+ 0x1e80: 0x10000000,
431
+ 0x1f80: 0x10002008
432
+ },
433
+ {
434
+ 0x0: 0x100000,
435
+ 0x10: 0x2000401,
436
+ 0x20: 0x400,
437
+ 0x30: 0x100401,
438
+ 0x40: 0x2100401,
439
+ 0x50: 0x0,
440
+ 0x60: 0x1,
441
+ 0x70: 0x2100001,
442
+ 0x80: 0x2000400,
443
+ 0x90: 0x100001,
444
+ 0xa0: 0x2000001,
445
+ 0xb0: 0x2100400,
446
+ 0xc0: 0x2100000,
447
+ 0xd0: 0x401,
448
+ 0xe0: 0x100400,
449
+ 0xf0: 0x2000000,
450
+ 0x8: 0x2100001,
451
+ 0x18: 0x0,
452
+ 0x28: 0x2000401,
453
+ 0x38: 0x2100400,
454
+ 0x48: 0x100000,
455
+ 0x58: 0x2000001,
456
+ 0x68: 0x2000000,
457
+ 0x78: 0x401,
458
+ 0x88: 0x100401,
459
+ 0x98: 0x2000400,
460
+ 0xa8: 0x2100000,
461
+ 0xb8: 0x100001,
462
+ 0xc8: 0x400,
463
+ 0xd8: 0x2100401,
464
+ 0xe8: 0x1,
465
+ 0xf8: 0x100400,
466
+ 0x100: 0x2000000,
467
+ 0x110: 0x100000,
468
+ 0x120: 0x2000401,
469
+ 0x130: 0x2100001,
470
+ 0x140: 0x100001,
471
+ 0x150: 0x2000400,
472
+ 0x160: 0x2100400,
473
+ 0x170: 0x100401,
474
+ 0x180: 0x401,
475
+ 0x190: 0x2100401,
476
+ 0x1a0: 0x100400,
477
+ 0x1b0: 0x1,
478
+ 0x1c0: 0x0,
479
+ 0x1d0: 0x2100000,
480
+ 0x1e0: 0x2000001,
481
+ 0x1f0: 0x400,
482
+ 0x108: 0x100400,
483
+ 0x118: 0x2000401,
484
+ 0x128: 0x2100001,
485
+ 0x138: 0x1,
486
+ 0x148: 0x2000000,
487
+ 0x158: 0x100000,
488
+ 0x168: 0x401,
489
+ 0x178: 0x2100400,
490
+ 0x188: 0x2000001,
491
+ 0x198: 0x2100000,
492
+ 0x1a8: 0x0,
493
+ 0x1b8: 0x2100401,
494
+ 0x1c8: 0x100401,
495
+ 0x1d8: 0x400,
496
+ 0x1e8: 0x2000400,
497
+ 0x1f8: 0x100001
498
+ },
499
+ {
500
+ 0x0: 0x8000820,
501
+ 0x1: 0x20000,
502
+ 0x2: 0x8000000,
503
+ 0x3: 0x20,
504
+ 0x4: 0x20020,
505
+ 0x5: 0x8020820,
506
+ 0x6: 0x8020800,
507
+ 0x7: 0x800,
508
+ 0x8: 0x8020000,
509
+ 0x9: 0x8000800,
510
+ 0xa: 0x20800,
511
+ 0xb: 0x8020020,
512
+ 0xc: 0x820,
513
+ 0xd: 0x0,
514
+ 0xe: 0x8000020,
515
+ 0xf: 0x20820,
516
+ 0x80000000: 0x800,
517
+ 0x80000001: 0x8020820,
518
+ 0x80000002: 0x8000820,
519
+ 0x80000003: 0x8000000,
520
+ 0x80000004: 0x8020000,
521
+ 0x80000005: 0x20800,
522
+ 0x80000006: 0x20820,
523
+ 0x80000007: 0x20,
524
+ 0x80000008: 0x8000020,
525
+ 0x80000009: 0x820,
526
+ 0x8000000a: 0x20020,
527
+ 0x8000000b: 0x8020800,
528
+ 0x8000000c: 0x0,
529
+ 0x8000000d: 0x8020020,
530
+ 0x8000000e: 0x8000800,
531
+ 0x8000000f: 0x20000,
532
+ 0x10: 0x20820,
533
+ 0x11: 0x8020800,
534
+ 0x12: 0x20,
535
+ 0x13: 0x800,
536
+ 0x14: 0x8000800,
537
+ 0x15: 0x8000020,
538
+ 0x16: 0x8020020,
539
+ 0x17: 0x20000,
540
+ 0x18: 0x0,
541
+ 0x19: 0x20020,
542
+ 0x1a: 0x8020000,
543
+ 0x1b: 0x8000820,
544
+ 0x1c: 0x8020820,
545
+ 0x1d: 0x20800,
546
+ 0x1e: 0x820,
547
+ 0x1f: 0x8000000,
548
+ 0x80000010: 0x20000,
549
+ 0x80000011: 0x800,
550
+ 0x80000012: 0x8020020,
551
+ 0x80000013: 0x20820,
552
+ 0x80000014: 0x20,
553
+ 0x80000015: 0x8020000,
554
+ 0x80000016: 0x8000000,
555
+ 0x80000017: 0x8000820,
556
+ 0x80000018: 0x8020820,
557
+ 0x80000019: 0x8000020,
558
+ 0x8000001a: 0x8000800,
559
+ 0x8000001b: 0x0,
560
+ 0x8000001c: 0x20800,
561
+ 0x8000001d: 0x820,
562
+ 0x8000001e: 0x20020,
563
+ 0x8000001f: 0x8020800
564
+ }
565
+ ];
566
+
567
+ // Masks that select the SBOX input
568
+ var SBOX_MASK = [
569
+ 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000,
570
+ 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f
571
+ ];
572
+
573
+ /**
574
+ * DES block cipher algorithm.
575
+ */
576
+ var DES = C_algo.DES = BlockCipher.extend({
577
+ _doReset: function () {
578
+ // Shortcuts
579
+ var key = this._key;
580
+ var keyWords = key.words;
581
+
582
+ // Select 56 bits according to PC1
583
+ var keyBits = [];
584
+ for (var i = 0; i < 56; i++) {
585
+ var keyBitPos = PC1[i] - 1;
586
+ keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1;
587
+ }
588
+
589
+ // Assemble 16 subkeys
590
+ var subKeys = this._subKeys = [];
591
+ for (var nSubKey = 0; nSubKey < 16; nSubKey++) {
592
+ // Create subkey
593
+ var subKey = subKeys[nSubKey] = [];
594
+
595
+ // Shortcut
596
+ var bitShift = BIT_SHIFTS[nSubKey];
597
+
598
+ // Select 48 bits according to PC2
599
+ for (var i = 0; i < 24; i++) {
600
+ // Select from the left 28 key bits
601
+ subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6);
602
+
603
+ // Select from the right 28 key bits
604
+ subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6);
605
+ }
606
+
607
+ // Since each subkey is applied to an expanded 32-bit input,
608
+ // the subkey can be broken into 8 values scaled to 32-bits,
609
+ // which allows the key to be used without expansion
610
+ subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31);
611
+ for (var i = 1; i < 7; i++) {
612
+ subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3);
613
+ }
614
+ subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27);
615
+ }
616
+
617
+ // Compute inverse subkeys
618
+ var invSubKeys = this._invSubKeys = [];
619
+ for (var i = 0; i < 16; i++) {
620
+ invSubKeys[i] = subKeys[15 - i];
621
+ }
622
+ },
623
+
624
+ encryptBlock: function (M, offset) {
625
+ this._doCryptBlock(M, offset, this._subKeys);
626
+ },
627
+
628
+ decryptBlock: function (M, offset) {
629
+ this._doCryptBlock(M, offset, this._invSubKeys);
630
+ },
631
+
632
+ _doCryptBlock: function (M, offset, subKeys) {
633
+ // Get input
634
+ this._lBlock = M[offset];
635
+ this._rBlock = M[offset + 1];
636
+
637
+ // Initial permutation
638
+ exchangeLR.call(this, 4, 0x0f0f0f0f);
639
+ exchangeLR.call(this, 16, 0x0000ffff);
640
+ exchangeRL.call(this, 2, 0x33333333);
641
+ exchangeRL.call(this, 8, 0x00ff00ff);
642
+ exchangeLR.call(this, 1, 0x55555555);
643
+
644
+ // Rounds
645
+ for (var round = 0; round < 16; round++) {
646
+ // Shortcuts
647
+ var subKey = subKeys[round];
648
+ var lBlock = this._lBlock;
649
+ var rBlock = this._rBlock;
650
+
651
+ // Feistel function
652
+ var f = 0;
653
+ for (var i = 0; i < 8; i++) {
654
+ f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0];
655
+ }
656
+ this._lBlock = rBlock;
657
+ this._rBlock = lBlock ^ f;
658
+ }
659
+
660
+ // Undo swap from last round
661
+ var t = this._lBlock;
662
+ this._lBlock = this._rBlock;
663
+ this._rBlock = t;
664
+
665
+ // Final permutation
666
+ exchangeLR.call(this, 1, 0x55555555);
667
+ exchangeRL.call(this, 8, 0x00ff00ff);
668
+ exchangeRL.call(this, 2, 0x33333333);
669
+ exchangeLR.call(this, 16, 0x0000ffff);
670
+ exchangeLR.call(this, 4, 0x0f0f0f0f);
671
+
672
+ // Set output
673
+ M[offset] = this._lBlock;
674
+ M[offset + 1] = this._rBlock;
675
+ },
676
+
677
+ keySize: 64/32,
678
+
679
+ ivSize: 64/32,
680
+
681
+ blockSize: 64/32
682
+ });
683
+
684
+ // Swap bits across the left and right words
685
+ function exchangeLR(offset, mask) {
686
+ var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask;
687
+ this._rBlock ^= t;
688
+ this._lBlock ^= t << offset;
689
+ }
690
+
691
+ function exchangeRL(offset, mask) {
692
+ var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask;
693
+ this._lBlock ^= t;
694
+ this._rBlock ^= t << offset;
695
+ }
696
+
697
+ /**
698
+ * Shortcut functions to the cipher's object interface.
699
+ *
700
+ * @example
701
+ *
702
+ * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg);
703
+ * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg);
704
+ */
705
+ C.DES = BlockCipher._createHelper(DES);
706
+
707
+ /**
708
+ * Triple-DES block cipher algorithm.
709
+ */
710
+ var TripleDES = C_algo.TripleDES = BlockCipher.extend({
711
+ _doReset: function () {
712
+ // Shortcuts
713
+ var key = this._key;
714
+ var keyWords = key.words;
715
+ // Make sure the key length is valid (64, 128 or >= 192 bit)
716
+ if (keyWords.length !== 2 && keyWords.length !== 4 && keyWords.length < 6) {
717
+ throw new Error('Invalid key length - 3DES requires the key length to be 64, 128, 192 or >192.');
718
+ }
719
+
720
+ // Extend the key according to the keying options defined in 3DES standard
721
+ var key1 = keyWords.slice(0, 2);
722
+ var key2 = keyWords.length < 4 ? keyWords.slice(0, 2) : keyWords.slice(2, 4);
723
+ var key3 = keyWords.length < 6 ? keyWords.slice(0, 2) : keyWords.slice(4, 6);
724
+
725
+ // Create DES instances
726
+ this._des1 = DES.createEncryptor(WordArray.create(key1));
727
+ this._des2 = DES.createEncryptor(WordArray.create(key2));
728
+ this._des3 = DES.createEncryptor(WordArray.create(key3));
729
+ },
730
+
731
+ encryptBlock: function (M, offset) {
732
+ this._des1.encryptBlock(M, offset);
733
+ this._des2.decryptBlock(M, offset);
734
+ this._des3.encryptBlock(M, offset);
735
+ },
736
+
737
+ decryptBlock: function (M, offset) {
738
+ this._des3.decryptBlock(M, offset);
739
+ this._des2.encryptBlock(M, offset);
740
+ this._des1.decryptBlock(M, offset);
741
+ },
742
+
743
+ keySize: 192/32,
744
+
745
+ ivSize: 64/32,
746
+
747
+ blockSize: 64/32
748
+ });
749
+
750
+ /**
751
+ * Shortcut functions to the cipher's object interface.
752
+ *
753
+ * @example
754
+ *
755
+ * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg);
756
+ * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg);
757
+ */
758
+ C.TripleDES = BlockCipher._createHelper(TripleDES);
759
+ }());