middleman-gibberish 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +155 -0
- data/Rakefile +397 -0
- data/assets/gibberish.js +1017 -0
- data/assets/jquery.cookie.js +113 -0
- data/assets/jquery.js +5 -0
- data/lib/middleman-gibberish.rb +257 -0
- data/middleman-gibberish.gemspec +41 -0
- metadata +78 -0
data/assets/gibberish.js
ADDED
@@ -0,0 +1,1017 @@
|
|
1
|
+
/**
|
2
|
+
* @license Gibberish-AES
|
3
|
+
* A lightweight Javascript Libray for OpenSSL compatible AES CBC encryption.
|
4
|
+
*
|
5
|
+
* Author: Mark Percival
|
6
|
+
* Email: mark@mpercival.com
|
7
|
+
* Copyright: Mark Percival - http://mpercival.com 2008
|
8
|
+
*
|
9
|
+
* With thanks to:
|
10
|
+
* Josh Davis - http://www.josh-davis.org/ecmaScrypt
|
11
|
+
* Chris Veness - http://www.movable-type.co.uk/scripts/aes.html
|
12
|
+
* Michel I. Gallant - http://www.jensign.com/
|
13
|
+
* Jean-Luc Cooke <jlcooke@certainkey.com> 2012-07-12: added strhex + invertArr to compress G2X/G3X/G9X/GBX/GEX/SBox/SBoxInv/Rcon saving over 7KB, and added encString, decString, also made the MD5 routine more easlier compressible using yuicompressor.
|
14
|
+
*
|
15
|
+
* License: MIT
|
16
|
+
*
|
17
|
+
* Usage: GibberishAES.enc("secret", "password")
|
18
|
+
* Outputs: AES Encrypted text encoded in Base64
|
19
|
+
*/
|
20
|
+
|
21
|
+
|
22
|
+
(function (root, factory) {
|
23
|
+
if (typeof exports === 'object') {
|
24
|
+
// Node.
|
25
|
+
module.exports = factory();
|
26
|
+
} else if (typeof define === 'function' && define.amd) {
|
27
|
+
// AMD. Register as an anonymous module.
|
28
|
+
define(factory);
|
29
|
+
} else {
|
30
|
+
// Browser globals (root is window)
|
31
|
+
root.GibberishAES = factory();
|
32
|
+
}
|
33
|
+
}(this, function () {
|
34
|
+
'use strict';
|
35
|
+
|
36
|
+
var Nr = 14,
|
37
|
+
/* Default to 256 Bit Encryption */
|
38
|
+
Nk = 8,
|
39
|
+
Decrypt = false,
|
40
|
+
|
41
|
+
enc_utf8 = function(s)
|
42
|
+
{
|
43
|
+
try {
|
44
|
+
return unescape(encodeURIComponent(s));
|
45
|
+
}
|
46
|
+
catch(e) {
|
47
|
+
throw 'Error on UTF-8 encode';
|
48
|
+
}
|
49
|
+
},
|
50
|
+
|
51
|
+
dec_utf8 = function(s)
|
52
|
+
{
|
53
|
+
try {
|
54
|
+
return decodeURIComponent(escape(s));
|
55
|
+
}
|
56
|
+
catch(e) {
|
57
|
+
throw ('Bad Key');
|
58
|
+
}
|
59
|
+
},
|
60
|
+
|
61
|
+
padBlock = function(byteArr)
|
62
|
+
{
|
63
|
+
var array = [], cpad, i;
|
64
|
+
if (byteArr.length < 16) {
|
65
|
+
cpad = 16 - byteArr.length;
|
66
|
+
array = [cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad];
|
67
|
+
}
|
68
|
+
for (i = 0; i < byteArr.length; i++)
|
69
|
+
{
|
70
|
+
array[i] = byteArr[i];
|
71
|
+
}
|
72
|
+
return array;
|
73
|
+
},
|
74
|
+
|
75
|
+
block2s = function(block, lastBlock)
|
76
|
+
{
|
77
|
+
var string = '', padding, i;
|
78
|
+
if (lastBlock) {
|
79
|
+
padding = block[15];
|
80
|
+
if (padding > 16) {
|
81
|
+
throw ('Decryption error: Maybe bad key');
|
82
|
+
}
|
83
|
+
if (padding === 16) {
|
84
|
+
return '';
|
85
|
+
}
|
86
|
+
for (i = 0; i < 16 - padding; i++) {
|
87
|
+
string += String.fromCharCode(block[i]);
|
88
|
+
}
|
89
|
+
} else {
|
90
|
+
for (i = 0; i < 16; i++) {
|
91
|
+
string += String.fromCharCode(block[i]);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
return string;
|
95
|
+
},
|
96
|
+
|
97
|
+
a2h = function(numArr)
|
98
|
+
{
|
99
|
+
var string = '', i;
|
100
|
+
for (i = 0; i < numArr.length; i++) {
|
101
|
+
string += (numArr[i] < 16 ? '0': '') + numArr[i].toString(16);
|
102
|
+
}
|
103
|
+
return string;
|
104
|
+
},
|
105
|
+
|
106
|
+
h2a = function(s)
|
107
|
+
{
|
108
|
+
var ret = [];
|
109
|
+
s.replace(/(..)/g,
|
110
|
+
function(s) {
|
111
|
+
ret.push(parseInt(s, 16));
|
112
|
+
});
|
113
|
+
return ret;
|
114
|
+
},
|
115
|
+
|
116
|
+
s2a = function(string, binary) {
|
117
|
+
var array = [], i;
|
118
|
+
|
119
|
+
if (! binary) {
|
120
|
+
string = enc_utf8(string);
|
121
|
+
}
|
122
|
+
|
123
|
+
for (i = 0; i < string.length; i++)
|
124
|
+
{
|
125
|
+
array[i] = string.charCodeAt(i);
|
126
|
+
}
|
127
|
+
|
128
|
+
return array;
|
129
|
+
},
|
130
|
+
|
131
|
+
size = function(newsize)
|
132
|
+
{
|
133
|
+
switch (newsize)
|
134
|
+
{
|
135
|
+
case 128:
|
136
|
+
Nr = 10;
|
137
|
+
Nk = 4;
|
138
|
+
break;
|
139
|
+
case 192:
|
140
|
+
Nr = 12;
|
141
|
+
Nk = 6;
|
142
|
+
break;
|
143
|
+
case 256:
|
144
|
+
Nr = 14;
|
145
|
+
Nk = 8;
|
146
|
+
break;
|
147
|
+
default:
|
148
|
+
throw ('Invalid Key Size Specified:' + newsize);
|
149
|
+
}
|
150
|
+
},
|
151
|
+
|
152
|
+
randArr = function(num) {
|
153
|
+
var result = [], i;
|
154
|
+
for (i = 0; i < num; i++) {
|
155
|
+
result = result.concat(Math.floor(Math.random() * 256));
|
156
|
+
}
|
157
|
+
return result;
|
158
|
+
},
|
159
|
+
|
160
|
+
openSSLKey = function(passwordArr, saltArr) {
|
161
|
+
// Number of rounds depends on the size of the AES in use
|
162
|
+
// 3 rounds for 256
|
163
|
+
// 2 rounds for the key, 1 for the IV
|
164
|
+
// 2 rounds for 128
|
165
|
+
// 1 round for the key, 1 round for the IV
|
166
|
+
// 3 rounds for 192 since it's not evenly divided by 128 bits
|
167
|
+
var rounds = Nr >= 12 ? 3: 2,
|
168
|
+
key = [],
|
169
|
+
iv = [],
|
170
|
+
md5_hash = [],
|
171
|
+
result = [],
|
172
|
+
data00 = passwordArr.concat(saltArr),
|
173
|
+
i;
|
174
|
+
md5_hash[0] = MD5(data00);
|
175
|
+
result = md5_hash[0];
|
176
|
+
for (i = 1; i < rounds; i++) {
|
177
|
+
md5_hash[i] = MD5(md5_hash[i - 1].concat(data00));
|
178
|
+
result = result.concat(md5_hash[i]);
|
179
|
+
}
|
180
|
+
key = result.slice(0, 4 * Nk);
|
181
|
+
iv = result.slice(4 * Nk, 4 * Nk + 16);
|
182
|
+
return {
|
183
|
+
key: key,
|
184
|
+
iv: iv
|
185
|
+
};
|
186
|
+
},
|
187
|
+
|
188
|
+
rawEncrypt = function(plaintext, key, iv) {
|
189
|
+
// plaintext, key and iv as byte arrays
|
190
|
+
key = expandKey(key);
|
191
|
+
var numBlocks = Math.ceil(plaintext.length / 16),
|
192
|
+
blocks = [],
|
193
|
+
i,
|
194
|
+
cipherBlocks = [];
|
195
|
+
for (i = 0; i < numBlocks; i++) {
|
196
|
+
blocks[i] = padBlock(plaintext.slice(i * 16, i * 16 + 16));
|
197
|
+
}
|
198
|
+
if (plaintext.length % 16 === 0) {
|
199
|
+
blocks.push([16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16]);
|
200
|
+
// CBC OpenSSL padding scheme
|
201
|
+
numBlocks++;
|
202
|
+
}
|
203
|
+
for (i = 0; i < blocks.length; i++) {
|
204
|
+
blocks[i] = (i === 0) ? xorBlocks(blocks[i], iv) : xorBlocks(blocks[i], cipherBlocks[i - 1]);
|
205
|
+
cipherBlocks[i] = encryptBlock(blocks[i], key);
|
206
|
+
}
|
207
|
+
return cipherBlocks;
|
208
|
+
},
|
209
|
+
|
210
|
+
rawDecrypt = function(cryptArr, key, iv, binary) {
|
211
|
+
// cryptArr, key and iv as byte arrays
|
212
|
+
key = expandKey(key);
|
213
|
+
var numBlocks = cryptArr.length / 16,
|
214
|
+
cipherBlocks = [],
|
215
|
+
i,
|
216
|
+
plainBlocks = [],
|
217
|
+
string = '';
|
218
|
+
for (i = 0; i < numBlocks; i++) {
|
219
|
+
cipherBlocks.push(cryptArr.slice(i * 16, (i + 1) * 16));
|
220
|
+
}
|
221
|
+
for (i = cipherBlocks.length - 1; i >= 0; i--) {
|
222
|
+
plainBlocks[i] = decryptBlock(cipherBlocks[i], key);
|
223
|
+
plainBlocks[i] = (i === 0) ? xorBlocks(plainBlocks[i], iv) : xorBlocks(plainBlocks[i], cipherBlocks[i - 1]);
|
224
|
+
}
|
225
|
+
for (i = 0; i < numBlocks - 1; i++) {
|
226
|
+
string += block2s(plainBlocks[i]);
|
227
|
+
}
|
228
|
+
string += block2s(plainBlocks[i], true);
|
229
|
+
return binary ? string : dec_utf8(string);
|
230
|
+
},
|
231
|
+
|
232
|
+
encryptBlock = function(block, words) {
|
233
|
+
Decrypt = false;
|
234
|
+
var state = addRoundKey(block, words, 0),
|
235
|
+
round;
|
236
|
+
for (round = 1; round < (Nr + 1); round++) {
|
237
|
+
state = subBytes(state);
|
238
|
+
state = shiftRows(state);
|
239
|
+
if (round < Nr) {
|
240
|
+
state = mixColumns(state);
|
241
|
+
}
|
242
|
+
//last round? don't mixColumns
|
243
|
+
state = addRoundKey(state, words, round);
|
244
|
+
}
|
245
|
+
|
246
|
+
return state;
|
247
|
+
},
|
248
|
+
|
249
|
+
decryptBlock = function(block, words) {
|
250
|
+
Decrypt = true;
|
251
|
+
var state = addRoundKey(block, words, Nr),
|
252
|
+
round;
|
253
|
+
for (round = Nr - 1; round > -1; round--) {
|
254
|
+
state = shiftRows(state);
|
255
|
+
state = subBytes(state);
|
256
|
+
state = addRoundKey(state, words, round);
|
257
|
+
if (round > 0) {
|
258
|
+
state = mixColumns(state);
|
259
|
+
}
|
260
|
+
//last round? don't mixColumns
|
261
|
+
}
|
262
|
+
|
263
|
+
return state;
|
264
|
+
},
|
265
|
+
|
266
|
+
subBytes = function(state) {
|
267
|
+
var S = Decrypt ? SBoxInv: SBox,
|
268
|
+
temp = [],
|
269
|
+
i;
|
270
|
+
for (i = 0; i < 16; i++) {
|
271
|
+
temp[i] = S[state[i]];
|
272
|
+
}
|
273
|
+
return temp;
|
274
|
+
},
|
275
|
+
|
276
|
+
shiftRows = function(state) {
|
277
|
+
var temp = [],
|
278
|
+
shiftBy = Decrypt ? [0, 13, 10, 7, 4, 1, 14, 11, 8, 5, 2, 15, 12, 9, 6, 3] : [0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11],
|
279
|
+
i;
|
280
|
+
for (i = 0; i < 16; i++) {
|
281
|
+
temp[i] = state[shiftBy[i]];
|
282
|
+
}
|
283
|
+
return temp;
|
284
|
+
},
|
285
|
+
|
286
|
+
mixColumns = function(state) {
|
287
|
+
var t = [],
|
288
|
+
c;
|
289
|
+
if (!Decrypt) {
|
290
|
+
for (c = 0; c < 4; c++) {
|
291
|
+
t[c * 4] = G2X[state[c * 4]] ^ G3X[state[1 + c * 4]] ^ state[2 + c * 4] ^ state[3 + c * 4];
|
292
|
+
t[1 + c * 4] = state[c * 4] ^ G2X[state[1 + c * 4]] ^ G3X[state[2 + c * 4]] ^ state[3 + c * 4];
|
293
|
+
t[2 + c * 4] = state[c * 4] ^ state[1 + c * 4] ^ G2X[state[2 + c * 4]] ^ G3X[state[3 + c * 4]];
|
294
|
+
t[3 + c * 4] = G3X[state[c * 4]] ^ state[1 + c * 4] ^ state[2 + c * 4] ^ G2X[state[3 + c * 4]];
|
295
|
+
}
|
296
|
+
}else {
|
297
|
+
for (c = 0; c < 4; c++) {
|
298
|
+
t[c*4] = GEX[state[c*4]] ^ GBX[state[1+c*4]] ^ GDX[state[2+c*4]] ^ G9X[state[3+c*4]];
|
299
|
+
t[1+c*4] = G9X[state[c*4]] ^ GEX[state[1+c*4]] ^ GBX[state[2+c*4]] ^ GDX[state[3+c*4]];
|
300
|
+
t[2+c*4] = GDX[state[c*4]] ^ G9X[state[1+c*4]] ^ GEX[state[2+c*4]] ^ GBX[state[3+c*4]];
|
301
|
+
t[3+c*4] = GBX[state[c*4]] ^ GDX[state[1+c*4]] ^ G9X[state[2+c*4]] ^ GEX[state[3+c*4]];
|
302
|
+
}
|
303
|
+
}
|
304
|
+
|
305
|
+
return t;
|
306
|
+
},
|
307
|
+
|
308
|
+
addRoundKey = function(state, words, round) {
|
309
|
+
var temp = [],
|
310
|
+
i;
|
311
|
+
for (i = 0; i < 16; i++) {
|
312
|
+
temp[i] = state[i] ^ words[round][i];
|
313
|
+
}
|
314
|
+
return temp;
|
315
|
+
},
|
316
|
+
|
317
|
+
xorBlocks = function(block1, block2) {
|
318
|
+
var temp = [],
|
319
|
+
i;
|
320
|
+
for (i = 0; i < 16; i++) {
|
321
|
+
temp[i] = block1[i] ^ block2[i];
|
322
|
+
}
|
323
|
+
return temp;
|
324
|
+
},
|
325
|
+
|
326
|
+
expandKey = function(key) {
|
327
|
+
// Expects a 1d number array
|
328
|
+
var w = [],
|
329
|
+
temp = [],
|
330
|
+
i,
|
331
|
+
r,
|
332
|
+
t,
|
333
|
+
flat = [],
|
334
|
+
j;
|
335
|
+
|
336
|
+
for (i = 0; i < Nk; i++) {
|
337
|
+
r = [key[4 * i], key[4 * i + 1], key[4 * i + 2], key[4 * i + 3]];
|
338
|
+
w[i] = r;
|
339
|
+
}
|
340
|
+
|
341
|
+
for (i = Nk; i < (4 * (Nr + 1)); i++) {
|
342
|
+
w[i] = [];
|
343
|
+
for (t = 0; t < 4; t++) {
|
344
|
+
temp[t] = w[i - 1][t];
|
345
|
+
}
|
346
|
+
if (i % Nk === 0) {
|
347
|
+
temp = subWord(rotWord(temp));
|
348
|
+
temp[0] ^= Rcon[i / Nk - 1];
|
349
|
+
} else if (Nk > 6 && i % Nk === 4) {
|
350
|
+
temp = subWord(temp);
|
351
|
+
}
|
352
|
+
for (t = 0; t < 4; t++) {
|
353
|
+
w[i][t] = w[i - Nk][t] ^ temp[t];
|
354
|
+
}
|
355
|
+
}
|
356
|
+
for (i = 0; i < (Nr + 1); i++) {
|
357
|
+
flat[i] = [];
|
358
|
+
for (j = 0; j < 4; j++) {
|
359
|
+
flat[i].push(w[i * 4 + j][0], w[i * 4 + j][1], w[i * 4 + j][2], w[i * 4 + j][3]);
|
360
|
+
}
|
361
|
+
}
|
362
|
+
return flat;
|
363
|
+
},
|
364
|
+
|
365
|
+
subWord = function(w) {
|
366
|
+
// apply SBox to 4-byte word w
|
367
|
+
for (var i = 0; i < 4; i++) {
|
368
|
+
w[i] = SBox[w[i]];
|
369
|
+
}
|
370
|
+
return w;
|
371
|
+
},
|
372
|
+
|
373
|
+
rotWord = function(w) {
|
374
|
+
// rotate 4-byte word w left by one byte
|
375
|
+
var tmp = w[0],
|
376
|
+
i;
|
377
|
+
for (i = 0; i < 4; i++) {
|
378
|
+
w[i] = w[i + 1];
|
379
|
+
}
|
380
|
+
w[3] = tmp;
|
381
|
+
return w;
|
382
|
+
},
|
383
|
+
|
384
|
+
// jlcooke: 2012-07-12: added strhex + invertArr to compress G2X/G3X/G9X/GBX/GEX/SBox/SBoxInv/Rcon saving over 7KB, and added encString, decString
|
385
|
+
strhex = function(str,size) {
|
386
|
+
var i, ret = [];
|
387
|
+
for (i=0; i<str.length; i+=size){
|
388
|
+
ret[i/size] = parseInt(str.substr(i,size), 16);
|
389
|
+
}
|
390
|
+
return ret;
|
391
|
+
},
|
392
|
+
invertArr = function(arr) {
|
393
|
+
var i, ret = [];
|
394
|
+
for (i=0; i<arr.length; i++){
|
395
|
+
ret[arr[i]] = i;
|
396
|
+
}
|
397
|
+
return ret;
|
398
|
+
},
|
399
|
+
Gxx = function(a, b) {
|
400
|
+
var i, ret;
|
401
|
+
|
402
|
+
ret = 0;
|
403
|
+
for (i=0; i<8; i++) {
|
404
|
+
ret = ((b&1)===1) ? ret^a : ret;
|
405
|
+
/* xmult */
|
406
|
+
a = (a>0x7f) ? 0x11b^(a<<1) : (a<<1);
|
407
|
+
b >>>= 1;
|
408
|
+
}
|
409
|
+
|
410
|
+
return ret;
|
411
|
+
},
|
412
|
+
Gx = function(x) {
|
413
|
+
var i, r = [];
|
414
|
+
for (i=0; i<256; i++){
|
415
|
+
r[i] = Gxx(x, i);
|
416
|
+
}
|
417
|
+
return r;
|
418
|
+
},
|
419
|
+
|
420
|
+
// S-box
|
421
|
+
/*
|
422
|
+
SBox = [
|
423
|
+
99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171,
|
424
|
+
118, 202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164,
|
425
|
+
114, 192, 183, 253, 147, 38, 54, 63, 247, 204, 52, 165, 229, 241, 113,
|
426
|
+
216, 49, 21, 4, 199, 35, 195, 24, 150, 5, 154, 7, 18, 128, 226,
|
427
|
+
235, 39, 178, 117, 9, 131, 44, 26, 27, 110, 90, 160, 82, 59, 214,
|
428
|
+
179, 41, 227, 47, 132, 83, 209, 0, 237, 32, 252, 177, 91, 106, 203,
|
429
|
+
190, 57, 74, 76, 88, 207, 208, 239, 170, 251, 67, 77, 51, 133, 69,
|
430
|
+
249, 2, 127, 80, 60, 159, 168, 81, 163, 64, 143, 146, 157, 56, 245,
|
431
|
+
188, 182, 218, 33, 16, 255, 243, 210, 205, 12, 19, 236, 95, 151, 68,
|
432
|
+
23, 196, 167, 126, 61, 100, 93, 25, 115, 96, 129, 79, 220, 34, 42,
|
433
|
+
144, 136, 70, 238, 184, 20, 222, 94, 11, 219, 224, 50, 58, 10, 73,
|
434
|
+
6, 36, 92, 194, 211, 172, 98, 145, 149, 228, 121, 231, 200, 55, 109,
|
435
|
+
141, 213, 78, 169, 108, 86, 244, 234, 101, 122, 174, 8, 186, 120, 37,
|
436
|
+
46, 28, 166, 180, 198, 232, 221, 116, 31, 75, 189, 139, 138, 112, 62,
|
437
|
+
181, 102, 72, 3, 246, 14, 97, 53, 87, 185, 134, 193, 29, 158, 225,
|
438
|
+
248, 152, 17, 105, 217, 142, 148, 155, 30, 135, 233, 206, 85, 40, 223,
|
439
|
+
140, 161, 137, 13, 191, 230, 66, 104, 65, 153, 45, 15, 176, 84, 187,
|
440
|
+
22], //*/ SBox = strhex('637c777bf26b6fc53001672bfed7ab76ca82c97dfa5947f0add4a2af9ca472c0b7fd9326363ff7cc34a5e5f171d8311504c723c31896059a071280e2eb27b27509832c1a1b6e5aa0523bd6b329e32f8453d100ed20fcb15b6acbbe394a4c58cfd0efaafb434d338545f9027f503c9fa851a3408f929d38f5bcb6da2110fff3d2cd0c13ec5f974417c4a77e3d645d197360814fdc222a908846eeb814de5e0bdbe0323a0a4906245cc2d3ac629195e479e7c8376d8dd54ea96c56f4ea657aae08ba78252e1ca6b4c6e8dd741f4bbd8b8a703eb5664803f60e613557b986c11d9ee1f8981169d98e949b1e87e9ce5528df8ca1890dbfe6426841992d0fb054bb16',2),
|
441
|
+
|
442
|
+
// Precomputed lookup table for the inverse SBox
|
443
|
+
/* SBoxInv = [
|
444
|
+
82, 9, 106, 213, 48, 54, 165, 56, 191, 64, 163, 158, 129, 243, 215,
|
445
|
+
251, 124, 227, 57, 130, 155, 47, 255, 135, 52, 142, 67, 68, 196, 222,
|
446
|
+
233, 203, 84, 123, 148, 50, 166, 194, 35, 61, 238, 76, 149, 11, 66,
|
447
|
+
250, 195, 78, 8, 46, 161, 102, 40, 217, 36, 178, 118, 91, 162, 73,
|
448
|
+
109, 139, 209, 37, 114, 248, 246, 100, 134, 104, 152, 22, 212, 164, 92,
|
449
|
+
204, 93, 101, 182, 146, 108, 112, 72, 80, 253, 237, 185, 218, 94, 21,
|
450
|
+
70, 87, 167, 141, 157, 132, 144, 216, 171, 0, 140, 188, 211, 10, 247,
|
451
|
+
228, 88, 5, 184, 179, 69, 6, 208, 44, 30, 143, 202, 63, 15, 2,
|
452
|
+
193, 175, 189, 3, 1, 19, 138, 107, 58, 145, 17, 65, 79, 103, 220,
|
453
|
+
234, 151, 242, 207, 206, 240, 180, 230, 115, 150, 172, 116, 34, 231, 173,
|
454
|
+
53, 133, 226, 249, 55, 232, 28, 117, 223, 110, 71, 241, 26, 113, 29,
|
455
|
+
41, 197, 137, 111, 183, 98, 14, 170, 24, 190, 27, 252, 86, 62, 75,
|
456
|
+
198, 210, 121, 32, 154, 219, 192, 254, 120, 205, 90, 244, 31, 221, 168,
|
457
|
+
51, 136, 7, 199, 49, 177, 18, 16, 89, 39, 128, 236, 95, 96, 81,
|
458
|
+
127, 169, 25, 181, 74, 13, 45, 229, 122, 159, 147, 201, 156, 239, 160,
|
459
|
+
224, 59, 77, 174, 42, 245, 176, 200, 235, 187, 60, 131, 83, 153, 97,
|
460
|
+
23, 43, 4, 126, 186, 119, 214, 38, 225, 105, 20, 99, 85, 33, 12,
|
461
|
+
125], //*/ SBoxInv = invertArr(SBox),
|
462
|
+
|
463
|
+
// Rijndael Rcon
|
464
|
+
/*
|
465
|
+
Rcon = [1, 2, 4, 8, 16, 32, 64, 128, 27, 54, 108, 216, 171, 77, 154, 47, 94,
|
466
|
+
188, 99, 198, 151, 53, 106, 212, 179, 125, 250, 239, 197, 145],
|
467
|
+
//*/ Rcon = strhex('01020408102040801b366cd8ab4d9a2f5ebc63c697356ad4b37dfaefc591',2),
|
468
|
+
|
469
|
+
/*
|
470
|
+
G2X = [
|
471
|
+
0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x16,
|
472
|
+
0x18, 0x1a, 0x1c, 0x1e, 0x20, 0x22, 0x24, 0x26, 0x28, 0x2a, 0x2c, 0x2e,
|
473
|
+
0x30, 0x32, 0x34, 0x36, 0x38, 0x3a, 0x3c, 0x3e, 0x40, 0x42, 0x44, 0x46,
|
474
|
+
0x48, 0x4a, 0x4c, 0x4e, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5a, 0x5c, 0x5e,
|
475
|
+
0x60, 0x62, 0x64, 0x66, 0x68, 0x6a, 0x6c, 0x6e, 0x70, 0x72, 0x74, 0x76,
|
476
|
+
0x78, 0x7a, 0x7c, 0x7e, 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e,
|
477
|
+
0x90, 0x92, 0x94, 0x96, 0x98, 0x9a, 0x9c, 0x9e, 0xa0, 0xa2, 0xa4, 0xa6,
|
478
|
+
0xa8, 0xaa, 0xac, 0xae, 0xb0, 0xb2, 0xb4, 0xb6, 0xb8, 0xba, 0xbc, 0xbe,
|
479
|
+
0xc0, 0xc2, 0xc4, 0xc6, 0xc8, 0xca, 0xcc, 0xce, 0xd0, 0xd2, 0xd4, 0xd6,
|
480
|
+
0xd8, 0xda, 0xdc, 0xde, 0xe0, 0xe2, 0xe4, 0xe6, 0xe8, 0xea, 0xec, 0xee,
|
481
|
+
0xf0, 0xf2, 0xf4, 0xf6, 0xf8, 0xfa, 0xfc, 0xfe, 0x1b, 0x19, 0x1f, 0x1d,
|
482
|
+
0x13, 0x11, 0x17, 0x15, 0x0b, 0x09, 0x0f, 0x0d, 0x03, 0x01, 0x07, 0x05,
|
483
|
+
0x3b, 0x39, 0x3f, 0x3d, 0x33, 0x31, 0x37, 0x35, 0x2b, 0x29, 0x2f, 0x2d,
|
484
|
+
0x23, 0x21, 0x27, 0x25, 0x5b, 0x59, 0x5f, 0x5d, 0x53, 0x51, 0x57, 0x55,
|
485
|
+
0x4b, 0x49, 0x4f, 0x4d, 0x43, 0x41, 0x47, 0x45, 0x7b, 0x79, 0x7f, 0x7d,
|
486
|
+
0x73, 0x71, 0x77, 0x75, 0x6b, 0x69, 0x6f, 0x6d, 0x63, 0x61, 0x67, 0x65,
|
487
|
+
0x9b, 0x99, 0x9f, 0x9d, 0x93, 0x91, 0x97, 0x95, 0x8b, 0x89, 0x8f, 0x8d,
|
488
|
+
0x83, 0x81, 0x87, 0x85, 0xbb, 0xb9, 0xbf, 0xbd, 0xb3, 0xb1, 0xb7, 0xb5,
|
489
|
+
0xab, 0xa9, 0xaf, 0xad, 0xa3, 0xa1, 0xa7, 0xa5, 0xdb, 0xd9, 0xdf, 0xdd,
|
490
|
+
0xd3, 0xd1, 0xd7, 0xd5, 0xcb, 0xc9, 0xcf, 0xcd, 0xc3, 0xc1, 0xc7, 0xc5,
|
491
|
+
0xfb, 0xf9, 0xff, 0xfd, 0xf3, 0xf1, 0xf7, 0xf5, 0xeb, 0xe9, 0xef, 0xed,
|
492
|
+
0xe3, 0xe1, 0xe7, 0xe5
|
493
|
+
], //*/ G2X = Gx(2),
|
494
|
+
|
495
|
+
/* G3X = [
|
496
|
+
0x00, 0x03, 0x06, 0x05, 0x0c, 0x0f, 0x0a, 0x09, 0x18, 0x1b, 0x1e, 0x1d,
|
497
|
+
0x14, 0x17, 0x12, 0x11, 0x30, 0x33, 0x36, 0x35, 0x3c, 0x3f, 0x3a, 0x39,
|
498
|
+
0x28, 0x2b, 0x2e, 0x2d, 0x24, 0x27, 0x22, 0x21, 0x60, 0x63, 0x66, 0x65,
|
499
|
+
0x6c, 0x6f, 0x6a, 0x69, 0x78, 0x7b, 0x7e, 0x7d, 0x74, 0x77, 0x72, 0x71,
|
500
|
+
0x50, 0x53, 0x56, 0x55, 0x5c, 0x5f, 0x5a, 0x59, 0x48, 0x4b, 0x4e, 0x4d,
|
501
|
+
0x44, 0x47, 0x42, 0x41, 0xc0, 0xc3, 0xc6, 0xc5, 0xcc, 0xcf, 0xca, 0xc9,
|
502
|
+
0xd8, 0xdb, 0xde, 0xdd, 0xd4, 0xd7, 0xd2, 0xd1, 0xf0, 0xf3, 0xf6, 0xf5,
|
503
|
+
0xfc, 0xff, 0xfa, 0xf9, 0xe8, 0xeb, 0xee, 0xed, 0xe4, 0xe7, 0xe2, 0xe1,
|
504
|
+
0xa0, 0xa3, 0xa6, 0xa5, 0xac, 0xaf, 0xaa, 0xa9, 0xb8, 0xbb, 0xbe, 0xbd,
|
505
|
+
0xb4, 0xb7, 0xb2, 0xb1, 0x90, 0x93, 0x96, 0x95, 0x9c, 0x9f, 0x9a, 0x99,
|
506
|
+
0x88, 0x8b, 0x8e, 0x8d, 0x84, 0x87, 0x82, 0x81, 0x9b, 0x98, 0x9d, 0x9e,
|
507
|
+
0x97, 0x94, 0x91, 0x92, 0x83, 0x80, 0x85, 0x86, 0x8f, 0x8c, 0x89, 0x8a,
|
508
|
+
0xab, 0xa8, 0xad, 0xae, 0xa7, 0xa4, 0xa1, 0xa2, 0xb3, 0xb0, 0xb5, 0xb6,
|
509
|
+
0xbf, 0xbc, 0xb9, 0xba, 0xfb, 0xf8, 0xfd, 0xfe, 0xf7, 0xf4, 0xf1, 0xf2,
|
510
|
+
0xe3, 0xe0, 0xe5, 0xe6, 0xef, 0xec, 0xe9, 0xea, 0xcb, 0xc8, 0xcd, 0xce,
|
511
|
+
0xc7, 0xc4, 0xc1, 0xc2, 0xd3, 0xd0, 0xd5, 0xd6, 0xdf, 0xdc, 0xd9, 0xda,
|
512
|
+
0x5b, 0x58, 0x5d, 0x5e, 0x57, 0x54, 0x51, 0x52, 0x43, 0x40, 0x45, 0x46,
|
513
|
+
0x4f, 0x4c, 0x49, 0x4a, 0x6b, 0x68, 0x6d, 0x6e, 0x67, 0x64, 0x61, 0x62,
|
514
|
+
0x73, 0x70, 0x75, 0x76, 0x7f, 0x7c, 0x79, 0x7a, 0x3b, 0x38, 0x3d, 0x3e,
|
515
|
+
0x37, 0x34, 0x31, 0x32, 0x23, 0x20, 0x25, 0x26, 0x2f, 0x2c, 0x29, 0x2a,
|
516
|
+
0x0b, 0x08, 0x0d, 0x0e, 0x07, 0x04, 0x01, 0x02, 0x13, 0x10, 0x15, 0x16,
|
517
|
+
0x1f, 0x1c, 0x19, 0x1a
|
518
|
+
], //*/ G3X = Gx(3),
|
519
|
+
|
520
|
+
/*
|
521
|
+
G9X = [
|
522
|
+
0x00, 0x09, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f, 0x48, 0x41, 0x5a, 0x53,
|
523
|
+
0x6c, 0x65, 0x7e, 0x77, 0x90, 0x99, 0x82, 0x8b, 0xb4, 0xbd, 0xa6, 0xaf,
|
524
|
+
0xd8, 0xd1, 0xca, 0xc3, 0xfc, 0xf5, 0xee, 0xe7, 0x3b, 0x32, 0x29, 0x20,
|
525
|
+
0x1f, 0x16, 0x0d, 0x04, 0x73, 0x7a, 0x61, 0x68, 0x57, 0x5e, 0x45, 0x4c,
|
526
|
+
0xab, 0xa2, 0xb9, 0xb0, 0x8f, 0x86, 0x9d, 0x94, 0xe3, 0xea, 0xf1, 0xf8,
|
527
|
+
0xc7, 0xce, 0xd5, 0xdc, 0x76, 0x7f, 0x64, 0x6d, 0x52, 0x5b, 0x40, 0x49,
|
528
|
+
0x3e, 0x37, 0x2c, 0x25, 0x1a, 0x13, 0x08, 0x01, 0xe6, 0xef, 0xf4, 0xfd,
|
529
|
+
0xc2, 0xcb, 0xd0, 0xd9, 0xae, 0xa7, 0xbc, 0xb5, 0x8a, 0x83, 0x98, 0x91,
|
530
|
+
0x4d, 0x44, 0x5f, 0x56, 0x69, 0x60, 0x7b, 0x72, 0x05, 0x0c, 0x17, 0x1e,
|
531
|
+
0x21, 0x28, 0x33, 0x3a, 0xdd, 0xd4, 0xcf, 0xc6, 0xf9, 0xf0, 0xeb, 0xe2,
|
532
|
+
0x95, 0x9c, 0x87, 0x8e, 0xb1, 0xb8, 0xa3, 0xaa, 0xec, 0xe5, 0xfe, 0xf7,
|
533
|
+
0xc8, 0xc1, 0xda, 0xd3, 0xa4, 0xad, 0xb6, 0xbf, 0x80, 0x89, 0x92, 0x9b,
|
534
|
+
0x7c, 0x75, 0x6e, 0x67, 0x58, 0x51, 0x4a, 0x43, 0x34, 0x3d, 0x26, 0x2f,
|
535
|
+
0x10, 0x19, 0x02, 0x0b, 0xd7, 0xde, 0xc5, 0xcc, 0xf3, 0xfa, 0xe1, 0xe8,
|
536
|
+
0x9f, 0x96, 0x8d, 0x84, 0xbb, 0xb2, 0xa9, 0xa0, 0x47, 0x4e, 0x55, 0x5c,
|
537
|
+
0x63, 0x6a, 0x71, 0x78, 0x0f, 0x06, 0x1d, 0x14, 0x2b, 0x22, 0x39, 0x30,
|
538
|
+
0x9a, 0x93, 0x88, 0x81, 0xbe, 0xb7, 0xac, 0xa5, 0xd2, 0xdb, 0xc0, 0xc9,
|
539
|
+
0xf6, 0xff, 0xe4, 0xed, 0x0a, 0x03, 0x18, 0x11, 0x2e, 0x27, 0x3c, 0x35,
|
540
|
+
0x42, 0x4b, 0x50, 0x59, 0x66, 0x6f, 0x74, 0x7d, 0xa1, 0xa8, 0xb3, 0xba,
|
541
|
+
0x85, 0x8c, 0x97, 0x9e, 0xe9, 0xe0, 0xfb, 0xf2, 0xcd, 0xc4, 0xdf, 0xd6,
|
542
|
+
0x31, 0x38, 0x23, 0x2a, 0x15, 0x1c, 0x07, 0x0e, 0x79, 0x70, 0x6b, 0x62,
|
543
|
+
0x5d, 0x54, 0x4f, 0x46
|
544
|
+
], //*/ G9X = Gx(9),
|
545
|
+
|
546
|
+
/* GBX = [
|
547
|
+
0x00, 0x0b, 0x16, 0x1d, 0x2c, 0x27, 0x3a, 0x31, 0x58, 0x53, 0x4e, 0x45,
|
548
|
+
0x74, 0x7f, 0x62, 0x69, 0xb0, 0xbb, 0xa6, 0xad, 0x9c, 0x97, 0x8a, 0x81,
|
549
|
+
0xe8, 0xe3, 0xfe, 0xf5, 0xc4, 0xcf, 0xd2, 0xd9, 0x7b, 0x70, 0x6d, 0x66,
|
550
|
+
0x57, 0x5c, 0x41, 0x4a, 0x23, 0x28, 0x35, 0x3e, 0x0f, 0x04, 0x19, 0x12,
|
551
|
+
0xcb, 0xc0, 0xdd, 0xd6, 0xe7, 0xec, 0xf1, 0xfa, 0x93, 0x98, 0x85, 0x8e,
|
552
|
+
0xbf, 0xb4, 0xa9, 0xa2, 0xf6, 0xfd, 0xe0, 0xeb, 0xda, 0xd1, 0xcc, 0xc7,
|
553
|
+
0xae, 0xa5, 0xb8, 0xb3, 0x82, 0x89, 0x94, 0x9f, 0x46, 0x4d, 0x50, 0x5b,
|
554
|
+
0x6a, 0x61, 0x7c, 0x77, 0x1e, 0x15, 0x08, 0x03, 0x32, 0x39, 0x24, 0x2f,
|
555
|
+
0x8d, 0x86, 0x9b, 0x90, 0xa1, 0xaa, 0xb7, 0xbc, 0xd5, 0xde, 0xc3, 0xc8,
|
556
|
+
0xf9, 0xf2, 0xef, 0xe4, 0x3d, 0x36, 0x2b, 0x20, 0x11, 0x1a, 0x07, 0x0c,
|
557
|
+
0x65, 0x6e, 0x73, 0x78, 0x49, 0x42, 0x5f, 0x54, 0xf7, 0xfc, 0xe1, 0xea,
|
558
|
+
0xdb, 0xd0, 0xcd, 0xc6, 0xaf, 0xa4, 0xb9, 0xb2, 0x83, 0x88, 0x95, 0x9e,
|
559
|
+
0x47, 0x4c, 0x51, 0x5a, 0x6b, 0x60, 0x7d, 0x76, 0x1f, 0x14, 0x09, 0x02,
|
560
|
+
0x33, 0x38, 0x25, 0x2e, 0x8c, 0x87, 0x9a, 0x91, 0xa0, 0xab, 0xb6, 0xbd,
|
561
|
+
0xd4, 0xdf, 0xc2, 0xc9, 0xf8, 0xf3, 0xee, 0xe5, 0x3c, 0x37, 0x2a, 0x21,
|
562
|
+
0x10, 0x1b, 0x06, 0x0d, 0x64, 0x6f, 0x72, 0x79, 0x48, 0x43, 0x5e, 0x55,
|
563
|
+
0x01, 0x0a, 0x17, 0x1c, 0x2d, 0x26, 0x3b, 0x30, 0x59, 0x52, 0x4f, 0x44,
|
564
|
+
0x75, 0x7e, 0x63, 0x68, 0xb1, 0xba, 0xa7, 0xac, 0x9d, 0x96, 0x8b, 0x80,
|
565
|
+
0xe9, 0xe2, 0xff, 0xf4, 0xc5, 0xce, 0xd3, 0xd8, 0x7a, 0x71, 0x6c, 0x67,
|
566
|
+
0x56, 0x5d, 0x40, 0x4b, 0x22, 0x29, 0x34, 0x3f, 0x0e, 0x05, 0x18, 0x13,
|
567
|
+
0xca, 0xc1, 0xdc, 0xd7, 0xe6, 0xed, 0xf0, 0xfb, 0x92, 0x99, 0x84, 0x8f,
|
568
|
+
0xbe, 0xb5, 0xa8, 0xa3
|
569
|
+
], //*/ GBX = Gx(0xb),
|
570
|
+
|
571
|
+
/*
|
572
|
+
GDX = [
|
573
|
+
0x00, 0x0d, 0x1a, 0x17, 0x34, 0x39, 0x2e, 0x23, 0x68, 0x65, 0x72, 0x7f,
|
574
|
+
0x5c, 0x51, 0x46, 0x4b, 0xd0, 0xdd, 0xca, 0xc7, 0xe4, 0xe9, 0xfe, 0xf3,
|
575
|
+
0xb8, 0xb5, 0xa2, 0xaf, 0x8c, 0x81, 0x96, 0x9b, 0xbb, 0xb6, 0xa1, 0xac,
|
576
|
+
0x8f, 0x82, 0x95, 0x98, 0xd3, 0xde, 0xc9, 0xc4, 0xe7, 0xea, 0xfd, 0xf0,
|
577
|
+
0x6b, 0x66, 0x71, 0x7c, 0x5f, 0x52, 0x45, 0x48, 0x03, 0x0e, 0x19, 0x14,
|
578
|
+
0x37, 0x3a, 0x2d, 0x20, 0x6d, 0x60, 0x77, 0x7a, 0x59, 0x54, 0x43, 0x4e,
|
579
|
+
0x05, 0x08, 0x1f, 0x12, 0x31, 0x3c, 0x2b, 0x26, 0xbd, 0xb0, 0xa7, 0xaa,
|
580
|
+
0x89, 0x84, 0x93, 0x9e, 0xd5, 0xd8, 0xcf, 0xc2, 0xe1, 0xec, 0xfb, 0xf6,
|
581
|
+
0xd6, 0xdb, 0xcc, 0xc1, 0xe2, 0xef, 0xf8, 0xf5, 0xbe, 0xb3, 0xa4, 0xa9,
|
582
|
+
0x8a, 0x87, 0x90, 0x9d, 0x06, 0x0b, 0x1c, 0x11, 0x32, 0x3f, 0x28, 0x25,
|
583
|
+
0x6e, 0x63, 0x74, 0x79, 0x5a, 0x57, 0x40, 0x4d, 0xda, 0xd7, 0xc0, 0xcd,
|
584
|
+
0xee, 0xe3, 0xf4, 0xf9, 0xb2, 0xbf, 0xa8, 0xa5, 0x86, 0x8b, 0x9c, 0x91,
|
585
|
+
0x0a, 0x07, 0x10, 0x1d, 0x3e, 0x33, 0x24, 0x29, 0x62, 0x6f, 0x78, 0x75,
|
586
|
+
0x56, 0x5b, 0x4c, 0x41, 0x61, 0x6c, 0x7b, 0x76, 0x55, 0x58, 0x4f, 0x42,
|
587
|
+
0x09, 0x04, 0x13, 0x1e, 0x3d, 0x30, 0x27, 0x2a, 0xb1, 0xbc, 0xab, 0xa6,
|
588
|
+
0x85, 0x88, 0x9f, 0x92, 0xd9, 0xd4, 0xc3, 0xce, 0xed, 0xe0, 0xf7, 0xfa,
|
589
|
+
0xb7, 0xba, 0xad, 0xa0, 0x83, 0x8e, 0x99, 0x94, 0xdf, 0xd2, 0xc5, 0xc8,
|
590
|
+
0xeb, 0xe6, 0xf1, 0xfc, 0x67, 0x6a, 0x7d, 0x70, 0x53, 0x5e, 0x49, 0x44,
|
591
|
+
0x0f, 0x02, 0x15, 0x18, 0x3b, 0x36, 0x21, 0x2c, 0x0c, 0x01, 0x16, 0x1b,
|
592
|
+
0x38, 0x35, 0x22, 0x2f, 0x64, 0x69, 0x7e, 0x73, 0x50, 0x5d, 0x4a, 0x47,
|
593
|
+
0xdc, 0xd1, 0xc6, 0xcb, 0xe8, 0xe5, 0xf2, 0xff, 0xb4, 0xb9, 0xae, 0xa3,
|
594
|
+
0x80, 0x8d, 0x9a, 0x97
|
595
|
+
], //*/ GDX = Gx(0xd),
|
596
|
+
|
597
|
+
/*
|
598
|
+
GEX = [
|
599
|
+
0x00, 0x0e, 0x1c, 0x12, 0x38, 0x36, 0x24, 0x2a, 0x70, 0x7e, 0x6c, 0x62,
|
600
|
+
0x48, 0x46, 0x54, 0x5a, 0xe0, 0xee, 0xfc, 0xf2, 0xd8, 0xd6, 0xc4, 0xca,
|
601
|
+
0x90, 0x9e, 0x8c, 0x82, 0xa8, 0xa6, 0xb4, 0xba, 0xdb, 0xd5, 0xc7, 0xc9,
|
602
|
+
0xe3, 0xed, 0xff, 0xf1, 0xab, 0xa5, 0xb7, 0xb9, 0x93, 0x9d, 0x8f, 0x81,
|
603
|
+
0x3b, 0x35, 0x27, 0x29, 0x03, 0x0d, 0x1f, 0x11, 0x4b, 0x45, 0x57, 0x59,
|
604
|
+
0x73, 0x7d, 0x6f, 0x61, 0xad, 0xa3, 0xb1, 0xbf, 0x95, 0x9b, 0x89, 0x87,
|
605
|
+
0xdd, 0xd3, 0xc1, 0xcf, 0xe5, 0xeb, 0xf9, 0xf7, 0x4d, 0x43, 0x51, 0x5f,
|
606
|
+
0x75, 0x7b, 0x69, 0x67, 0x3d, 0x33, 0x21, 0x2f, 0x05, 0x0b, 0x19, 0x17,
|
607
|
+
0x76, 0x78, 0x6a, 0x64, 0x4e, 0x40, 0x52, 0x5c, 0x06, 0x08, 0x1a, 0x14,
|
608
|
+
0x3e, 0x30, 0x22, 0x2c, 0x96, 0x98, 0x8a, 0x84, 0xae, 0xa0, 0xb2, 0xbc,
|
609
|
+
0xe6, 0xe8, 0xfa, 0xf4, 0xde, 0xd0, 0xc2, 0xcc, 0x41, 0x4f, 0x5d, 0x53,
|
610
|
+
0x79, 0x77, 0x65, 0x6b, 0x31, 0x3f, 0x2d, 0x23, 0x09, 0x07, 0x15, 0x1b,
|
611
|
+
0xa1, 0xaf, 0xbd, 0xb3, 0x99, 0x97, 0x85, 0x8b, 0xd1, 0xdf, 0xcd, 0xc3,
|
612
|
+
0xe9, 0xe7, 0xf5, 0xfb, 0x9a, 0x94, 0x86, 0x88, 0xa2, 0xac, 0xbe, 0xb0,
|
613
|
+
0xea, 0xe4, 0xf6, 0xf8, 0xd2, 0xdc, 0xce, 0xc0, 0x7a, 0x74, 0x66, 0x68,
|
614
|
+
0x42, 0x4c, 0x5e, 0x50, 0x0a, 0x04, 0x16, 0x18, 0x32, 0x3c, 0x2e, 0x20,
|
615
|
+
0xec, 0xe2, 0xf0, 0xfe, 0xd4, 0xda, 0xc8, 0xc6, 0x9c, 0x92, 0x80, 0x8e,
|
616
|
+
0xa4, 0xaa, 0xb8, 0xb6, 0x0c, 0x02, 0x10, 0x1e, 0x34, 0x3a, 0x28, 0x26,
|
617
|
+
0x7c, 0x72, 0x60, 0x6e, 0x44, 0x4a, 0x58, 0x56, 0x37, 0x39, 0x2b, 0x25,
|
618
|
+
0x0f, 0x01, 0x13, 0x1d, 0x47, 0x49, 0x5b, 0x55, 0x7f, 0x71, 0x63, 0x6d,
|
619
|
+
0xd7, 0xd9, 0xcb, 0xc5, 0xef, 0xe1, 0xf3, 0xfd, 0xa7, 0xa9, 0xbb, 0xb5,
|
620
|
+
0x9f, 0x91, 0x83, 0x8d
|
621
|
+
], //*/ GEX = Gx(0xe),
|
622
|
+
|
623
|
+
enc = function(string, pass, binary) {
|
624
|
+
// string, password in plaintext
|
625
|
+
var salt = randArr(8),
|
626
|
+
pbe = openSSLKey(s2a(pass, binary), salt),
|
627
|
+
key = pbe.key,
|
628
|
+
iv = pbe.iv,
|
629
|
+
cipherBlocks,
|
630
|
+
saltBlock = [[83, 97, 108, 116, 101, 100, 95, 95].concat(salt)];
|
631
|
+
string = s2a(string, binary);
|
632
|
+
cipherBlocks = rawEncrypt(string, key, iv);
|
633
|
+
// Spells out 'Salted__'
|
634
|
+
cipherBlocks = saltBlock.concat(cipherBlocks);
|
635
|
+
return Base64.encode(cipherBlocks);
|
636
|
+
},
|
637
|
+
|
638
|
+
dec = function(string, pass, binary) {
|
639
|
+
// string, password in plaintext
|
640
|
+
var cryptArr = Base64.decode(string),
|
641
|
+
salt = cryptArr.slice(8, 16),
|
642
|
+
pbe = openSSLKey(s2a(pass, binary), salt),
|
643
|
+
key = pbe.key,
|
644
|
+
iv = pbe.iv;
|
645
|
+
cryptArr = cryptArr.slice(16, cryptArr.length);
|
646
|
+
// Take off the Salted__ffeeddcc
|
647
|
+
string = rawDecrypt(cryptArr, key, iv, binary);
|
648
|
+
return string;
|
649
|
+
},
|
650
|
+
|
651
|
+
MD5 = function(numArr) {
|
652
|
+
|
653
|
+
function rotateLeft(lValue, iShiftBits) {
|
654
|
+
return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
|
655
|
+
}
|
656
|
+
|
657
|
+
function addUnsigned(lX, lY) {
|
658
|
+
var lX4,
|
659
|
+
lY4,
|
660
|
+
lX8,
|
661
|
+
lY8,
|
662
|
+
lResult;
|
663
|
+
lX8 = (lX & 0x80000000);
|
664
|
+
lY8 = (lY & 0x80000000);
|
665
|
+
lX4 = (lX & 0x40000000);
|
666
|
+
lY4 = (lY & 0x40000000);
|
667
|
+
lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
|
668
|
+
if (lX4 & lY4) {
|
669
|
+
return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
|
670
|
+
}
|
671
|
+
if (lX4 | lY4) {
|
672
|
+
if (lResult & 0x40000000) {
|
673
|
+
return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
|
674
|
+
} else {
|
675
|
+
return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
|
676
|
+
}
|
677
|
+
} else {
|
678
|
+
return (lResult ^ lX8 ^ lY8);
|
679
|
+
}
|
680
|
+
}
|
681
|
+
|
682
|
+
function f(x, y, z) {
|
683
|
+
return (x & y) | ((~x) & z);
|
684
|
+
}
|
685
|
+
function g(x, y, z) {
|
686
|
+
return (x & z) | (y & (~z));
|
687
|
+
}
|
688
|
+
function h(x, y, z) {
|
689
|
+
return (x ^ y ^ z);
|
690
|
+
}
|
691
|
+
function funcI(x, y, z) {
|
692
|
+
return (y ^ (x | (~z)));
|
693
|
+
}
|
694
|
+
|
695
|
+
function ff(a, b, c, d, x, s, ac) {
|
696
|
+
a = addUnsigned(a, addUnsigned(addUnsigned(f(b, c, d), x), ac));
|
697
|
+
return addUnsigned(rotateLeft(a, s), b);
|
698
|
+
}
|
699
|
+
|
700
|
+
function gg(a, b, c, d, x, s, ac) {
|
701
|
+
a = addUnsigned(a, addUnsigned(addUnsigned(g(b, c, d), x), ac));
|
702
|
+
return addUnsigned(rotateLeft(a, s), b);
|
703
|
+
}
|
704
|
+
|
705
|
+
function hh(a, b, c, d, x, s, ac) {
|
706
|
+
a = addUnsigned(a, addUnsigned(addUnsigned(h(b, c, d), x), ac));
|
707
|
+
return addUnsigned(rotateLeft(a, s), b);
|
708
|
+
}
|
709
|
+
|
710
|
+
function ii(a, b, c, d, x, s, ac) {
|
711
|
+
a = addUnsigned(a, addUnsigned(addUnsigned(funcI(b, c, d), x), ac));
|
712
|
+
return addUnsigned(rotateLeft(a, s), b);
|
713
|
+
}
|
714
|
+
|
715
|
+
function convertToWordArray(numArr) {
|
716
|
+
var lWordCount,
|
717
|
+
lMessageLength = numArr.length,
|
718
|
+
lNumberOfWords_temp1 = lMessageLength + 8,
|
719
|
+
lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64,
|
720
|
+
lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16,
|
721
|
+
lWordArray = [],
|
722
|
+
lBytePosition = 0,
|
723
|
+
lByteCount = 0;
|
724
|
+
while (lByteCount < lMessageLength) {
|
725
|
+
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
|
726
|
+
lBytePosition = (lByteCount % 4) * 8;
|
727
|
+
lWordArray[lWordCount] = (lWordArray[lWordCount] | (numArr[lByteCount] << lBytePosition));
|
728
|
+
lByteCount++;
|
729
|
+
}
|
730
|
+
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
|
731
|
+
lBytePosition = (lByteCount % 4) * 8;
|
732
|
+
lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
|
733
|
+
lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
|
734
|
+
lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
|
735
|
+
return lWordArray;
|
736
|
+
}
|
737
|
+
|
738
|
+
function wordToHex(lValue) {
|
739
|
+
var lByte,
|
740
|
+
lCount,
|
741
|
+
wordToHexArr = [];
|
742
|
+
for (lCount = 0; lCount <= 3; lCount++) {
|
743
|
+
lByte = (lValue >>> (lCount * 8)) & 255;
|
744
|
+
wordToHexArr = wordToHexArr.concat(lByte);
|
745
|
+
}
|
746
|
+
return wordToHexArr;
|
747
|
+
}
|
748
|
+
|
749
|
+
/*function utf8Encode(string) {
|
750
|
+
string = string.replace(/\r\n/g, "\n");
|
751
|
+
var utftext = "",
|
752
|
+
n,
|
753
|
+
c;
|
754
|
+
|
755
|
+
for (n = 0; n < string.length; n++) {
|
756
|
+
|
757
|
+
c = string.charCodeAt(n);
|
758
|
+
|
759
|
+
if (c < 128) {
|
760
|
+
utftext += String.fromCharCode(c);
|
761
|
+
}
|
762
|
+
else if ((c > 127) && (c < 2048)) {
|
763
|
+
utftext += String.fromCharCode((c >> 6) | 192);
|
764
|
+
utftext += String.fromCharCode((c & 63) | 128);
|
765
|
+
}
|
766
|
+
else {
|
767
|
+
utftext += String.fromCharCode((c >> 12) | 224);
|
768
|
+
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
769
|
+
utftext += String.fromCharCode((c & 63) | 128);
|
770
|
+
}
|
771
|
+
|
772
|
+
}
|
773
|
+
|
774
|
+
return utftext;
|
775
|
+
}*/
|
776
|
+
|
777
|
+
var x = [],
|
778
|
+
k,
|
779
|
+
AA,
|
780
|
+
BB,
|
781
|
+
CC,
|
782
|
+
DD,
|
783
|
+
a,
|
784
|
+
b,
|
785
|
+
c,
|
786
|
+
d,
|
787
|
+
rnd = strhex('67452301efcdab8998badcfe10325476d76aa478e8c7b756242070dbc1bdceeef57c0faf4787c62aa8304613fd469501698098d88b44f7afffff5bb1895cd7be6b901122fd987193a679438e49b40821f61e2562c040b340265e5a51e9b6c7aad62f105d02441453d8a1e681e7d3fbc821e1cde6c33707d6f4d50d87455a14eda9e3e905fcefa3f8676f02d98d2a4c8afffa39428771f6816d9d6122fde5380ca4beea444bdecfa9f6bb4b60bebfbc70289b7ec6eaa127fad4ef308504881d05d9d4d039e6db99e51fa27cf8c4ac5665f4292244432aff97ab9423a7fc93a039655b59c38f0ccc92ffeff47d85845dd16fa87e4ffe2ce6e0a30143144e0811a1f7537e82bd3af2352ad7d2bbeb86d391',8);
|
788
|
+
|
789
|
+
x = convertToWordArray(numArr);
|
790
|
+
|
791
|
+
a = rnd[0];
|
792
|
+
b = rnd[1];
|
793
|
+
c = rnd[2];
|
794
|
+
d = rnd[3];
|
795
|
+
|
796
|
+
for (k = 0; k < x.length; k += 16) {
|
797
|
+
AA = a;
|
798
|
+
BB = b;
|
799
|
+
CC = c;
|
800
|
+
DD = d;
|
801
|
+
a = ff(a, b, c, d, x[k + 0], 7, rnd[4]);
|
802
|
+
d = ff(d, a, b, c, x[k + 1], 12, rnd[5]);
|
803
|
+
c = ff(c, d, a, b, x[k + 2], 17, rnd[6]);
|
804
|
+
b = ff(b, c, d, a, x[k + 3], 22, rnd[7]);
|
805
|
+
a = ff(a, b, c, d, x[k + 4], 7, rnd[8]);
|
806
|
+
d = ff(d, a, b, c, x[k + 5], 12, rnd[9]);
|
807
|
+
c = ff(c, d, a, b, x[k + 6], 17, rnd[10]);
|
808
|
+
b = ff(b, c, d, a, x[k + 7], 22, rnd[11]);
|
809
|
+
a = ff(a, b, c, d, x[k + 8], 7, rnd[12]);
|
810
|
+
d = ff(d, a, b, c, x[k + 9], 12, rnd[13]);
|
811
|
+
c = ff(c, d, a, b, x[k + 10], 17, rnd[14]);
|
812
|
+
b = ff(b, c, d, a, x[k + 11], 22, rnd[15]);
|
813
|
+
a = ff(a, b, c, d, x[k + 12], 7, rnd[16]);
|
814
|
+
d = ff(d, a, b, c, x[k + 13], 12, rnd[17]);
|
815
|
+
c = ff(c, d, a, b, x[k + 14], 17, rnd[18]);
|
816
|
+
b = ff(b, c, d, a, x[k + 15], 22, rnd[19]);
|
817
|
+
a = gg(a, b, c, d, x[k + 1], 5, rnd[20]);
|
818
|
+
d = gg(d, a, b, c, x[k + 6], 9, rnd[21]);
|
819
|
+
c = gg(c, d, a, b, x[k + 11], 14, rnd[22]);
|
820
|
+
b = gg(b, c, d, a, x[k + 0], 20, rnd[23]);
|
821
|
+
a = gg(a, b, c, d, x[k + 5], 5, rnd[24]);
|
822
|
+
d = gg(d, a, b, c, x[k + 10], 9, rnd[25]);
|
823
|
+
c = gg(c, d, a, b, x[k + 15], 14, rnd[26]);
|
824
|
+
b = gg(b, c, d, a, x[k + 4], 20, rnd[27]);
|
825
|
+
a = gg(a, b, c, d, x[k + 9], 5, rnd[28]);
|
826
|
+
d = gg(d, a, b, c, x[k + 14], 9, rnd[29]);
|
827
|
+
c = gg(c, d, a, b, x[k + 3], 14, rnd[30]);
|
828
|
+
b = gg(b, c, d, a, x[k + 8], 20, rnd[31]);
|
829
|
+
a = gg(a, b, c, d, x[k + 13], 5, rnd[32]);
|
830
|
+
d = gg(d, a, b, c, x[k + 2], 9, rnd[33]);
|
831
|
+
c = gg(c, d, a, b, x[k + 7], 14, rnd[34]);
|
832
|
+
b = gg(b, c, d, a, x[k + 12], 20, rnd[35]);
|
833
|
+
a = hh(a, b, c, d, x[k + 5], 4, rnd[36]);
|
834
|
+
d = hh(d, a, b, c, x[k + 8], 11, rnd[37]);
|
835
|
+
c = hh(c, d, a, b, x[k + 11], 16, rnd[38]);
|
836
|
+
b = hh(b, c, d, a, x[k + 14], 23, rnd[39]);
|
837
|
+
a = hh(a, b, c, d, x[k + 1], 4, rnd[40]);
|
838
|
+
d = hh(d, a, b, c, x[k + 4], 11, rnd[41]);
|
839
|
+
c = hh(c, d, a, b, x[k + 7], 16, rnd[42]);
|
840
|
+
b = hh(b, c, d, a, x[k + 10], 23, rnd[43]);
|
841
|
+
a = hh(a, b, c, d, x[k + 13], 4, rnd[44]);
|
842
|
+
d = hh(d, a, b, c, x[k + 0], 11, rnd[45]);
|
843
|
+
c = hh(c, d, a, b, x[k + 3], 16, rnd[46]);
|
844
|
+
b = hh(b, c, d, a, x[k + 6], 23, rnd[47]);
|
845
|
+
a = hh(a, b, c, d, x[k + 9], 4, rnd[48]);
|
846
|
+
d = hh(d, a, b, c, x[k + 12], 11, rnd[49]);
|
847
|
+
c = hh(c, d, a, b, x[k + 15], 16, rnd[50]);
|
848
|
+
b = hh(b, c, d, a, x[k + 2], 23, rnd[51]);
|
849
|
+
a = ii(a, b, c, d, x[k + 0], 6, rnd[52]);
|
850
|
+
d = ii(d, a, b, c, x[k + 7], 10, rnd[53]);
|
851
|
+
c = ii(c, d, a, b, x[k + 14], 15, rnd[54]);
|
852
|
+
b = ii(b, c, d, a, x[k + 5], 21, rnd[55]);
|
853
|
+
a = ii(a, b, c, d, x[k + 12], 6, rnd[56]);
|
854
|
+
d = ii(d, a, b, c, x[k + 3], 10, rnd[57]);
|
855
|
+
c = ii(c, d, a, b, x[k + 10], 15, rnd[58]);
|
856
|
+
b = ii(b, c, d, a, x[k + 1], 21, rnd[59]);
|
857
|
+
a = ii(a, b, c, d, x[k + 8], 6, rnd[60]);
|
858
|
+
d = ii(d, a, b, c, x[k + 15], 10, rnd[61]);
|
859
|
+
c = ii(c, d, a, b, x[k + 6], 15, rnd[62]);
|
860
|
+
b = ii(b, c, d, a, x[k + 13], 21, rnd[63]);
|
861
|
+
a = ii(a, b, c, d, x[k + 4], 6, rnd[64]);
|
862
|
+
d = ii(d, a, b, c, x[k + 11], 10, rnd[65]);
|
863
|
+
c = ii(c, d, a, b, x[k + 2], 15, rnd[66]);
|
864
|
+
b = ii(b, c, d, a, x[k + 9], 21, rnd[67]);
|
865
|
+
a = addUnsigned(a, AA);
|
866
|
+
b = addUnsigned(b, BB);
|
867
|
+
c = addUnsigned(c, CC);
|
868
|
+
d = addUnsigned(d, DD);
|
869
|
+
}
|
870
|
+
|
871
|
+
return wordToHex(a).concat(wordToHex(b), wordToHex(c), wordToHex(d));
|
872
|
+
},
|
873
|
+
|
874
|
+
encString = function(plaintext, key, iv) {
|
875
|
+
var i;
|
876
|
+
plaintext = s2a(plaintext);
|
877
|
+
|
878
|
+
key = s2a(key);
|
879
|
+
for (i=key.length; i<32; i++){
|
880
|
+
key[i] = 0;
|
881
|
+
}
|
882
|
+
|
883
|
+
if (iv === undefined) {
|
884
|
+
// TODO: This is not defined anywhere... commented out...
|
885
|
+
// iv = genIV();
|
886
|
+
} else {
|
887
|
+
iv = s2a(iv);
|
888
|
+
for (i=iv.length; i<16; i++){
|
889
|
+
iv[i] = 0;
|
890
|
+
}
|
891
|
+
}
|
892
|
+
|
893
|
+
var ct = rawEncrypt(plaintext, key, iv);
|
894
|
+
var ret = [iv];
|
895
|
+
for (i=0; i<ct.length; i++){
|
896
|
+
ret[ret.length] = ct[i];
|
897
|
+
}
|
898
|
+
return Base64.encode(ret);
|
899
|
+
},
|
900
|
+
|
901
|
+
decString = function(ciphertext, key) {
|
902
|
+
var tmp = Base64.decode(ciphertext);
|
903
|
+
var iv = tmp.slice(0, 16);
|
904
|
+
var ct = tmp.slice(16, tmp.length);
|
905
|
+
var i;
|
906
|
+
|
907
|
+
key = s2a(key);
|
908
|
+
for (i=key.length; i<32; i++){
|
909
|
+
key[i] = 0;
|
910
|
+
}
|
911
|
+
|
912
|
+
var pt = rawDecrypt(ct, key, iv, false);
|
913
|
+
return pt;
|
914
|
+
},
|
915
|
+
|
916
|
+
Base64 = (function(){
|
917
|
+
// Takes a Nx16x1 byte array and converts it to Base64
|
918
|
+
var _chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
|
919
|
+
chars = _chars.split(''),
|
920
|
+
|
921
|
+
encode = function(b, withBreaks) {
|
922
|
+
var flatArr = [],
|
923
|
+
b64 = '',
|
924
|
+
i,
|
925
|
+
broken_b64,
|
926
|
+
totalChunks = Math.floor(b.length * 16 / 3);
|
927
|
+
for (i = 0; i < b.length * 16; i++) {
|
928
|
+
flatArr.push(b[Math.floor(i / 16)][i % 16]);
|
929
|
+
}
|
930
|
+
for (i = 0; i < flatArr.length; i = i + 3) {
|
931
|
+
b64 += chars[flatArr[i] >> 2];
|
932
|
+
b64 += chars[((flatArr[i] & 3) << 4) | (flatArr[i + 1] >> 4)];
|
933
|
+
if ( flatArr[i + 1] !== undefined ) {
|
934
|
+
b64 += chars[((flatArr[i + 1] & 15) << 2) | (flatArr[i + 2] >> 6)];
|
935
|
+
} else {
|
936
|
+
b64 += '=';
|
937
|
+
}
|
938
|
+
if ( flatArr[i + 2] !== undefined ) {
|
939
|
+
b64 += chars[flatArr[i + 2] & 63];
|
940
|
+
} else {
|
941
|
+
b64 += '=';
|
942
|
+
}
|
943
|
+
}
|
944
|
+
// OpenSSL is super particular about line breaks
|
945
|
+
broken_b64 = b64.slice(0, 64) + '\n';
|
946
|
+
for (i = 1; i < (Math.ceil(b64.length / 64)); i++) {
|
947
|
+
broken_b64 += b64.slice(i * 64, i * 64 + 64) + (Math.ceil(b64.length / 64) === i + 1 ? '': '\n');
|
948
|
+
}
|
949
|
+
return broken_b64;
|
950
|
+
},
|
951
|
+
|
952
|
+
decode = function(string) {
|
953
|
+
string = string.replace(/\n/g, '');
|
954
|
+
var flatArr = [],
|
955
|
+
c = [],
|
956
|
+
b = [],
|
957
|
+
i;
|
958
|
+
for (i = 0; i < string.length; i = i + 4) {
|
959
|
+
c[0] = _chars.indexOf(string.charAt(i));
|
960
|
+
c[1] = _chars.indexOf(string.charAt(i + 1));
|
961
|
+
c[2] = _chars.indexOf(string.charAt(i + 2));
|
962
|
+
c[3] = _chars.indexOf(string.charAt(i + 3));
|
963
|
+
|
964
|
+
b[0] = (c[0] << 2) | (c[1] >> 4);
|
965
|
+
b[1] = ((c[1] & 15) << 4) | (c[2] >> 2);
|
966
|
+
b[2] = ((c[2] & 3) << 6) | c[3];
|
967
|
+
flatArr.push(b[0], b[1], b[2]);
|
968
|
+
}
|
969
|
+
flatArr = flatArr.slice(0, flatArr.length - (flatArr.length % 16));
|
970
|
+
return flatArr;
|
971
|
+
};
|
972
|
+
|
973
|
+
//internet explorer
|
974
|
+
if(typeof Array.indexOf === "function") {
|
975
|
+
_chars = chars;
|
976
|
+
}
|
977
|
+
|
978
|
+
/*
|
979
|
+
//other way to solve internet explorer problem
|
980
|
+
if(!Array.indexOf){
|
981
|
+
Array.prototype.indexOf = function(obj){
|
982
|
+
for(var i=0; i<this.length; i++){
|
983
|
+
if(this[i]===obj){
|
984
|
+
return i;
|
985
|
+
}
|
986
|
+
}
|
987
|
+
return -1;
|
988
|
+
}
|
989
|
+
}
|
990
|
+
*/
|
991
|
+
|
992
|
+
|
993
|
+
return {
|
994
|
+
"encode": encode,
|
995
|
+
"decode": decode
|
996
|
+
};
|
997
|
+
})();
|
998
|
+
|
999
|
+
return {
|
1000
|
+
"size": size,
|
1001
|
+
"h2a":h2a,
|
1002
|
+
"expandKey":expandKey,
|
1003
|
+
"encryptBlock":encryptBlock,
|
1004
|
+
"decryptBlock":decryptBlock,
|
1005
|
+
"Decrypt":Decrypt,
|
1006
|
+
"s2a":s2a,
|
1007
|
+
"rawEncrypt":rawEncrypt,
|
1008
|
+
"rawDecrypt":rawDecrypt,
|
1009
|
+
"dec":dec,
|
1010
|
+
"openSSLKey":openSSLKey,
|
1011
|
+
"a2h":a2h,
|
1012
|
+
"enc":enc,
|
1013
|
+
"Hash":{"MD5":MD5},
|
1014
|
+
"Base64":Base64
|
1015
|
+
};
|
1016
|
+
|
1017
|
+
}));
|