aes-bridge 2.0.0

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.
package/md5.js ADDED
@@ -0,0 +1,849 @@
1
+ /**
2
+ * [js-md5]{@link https://github.com/emn178/js-md5}
3
+ *
4
+ * @version 0.8.3
5
+ * @license MIT
6
+ *
7
+ * Copyright 2014-2023 Chen, Yi-Cyuan
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining
10
+ * a copy of this software and associated documentation files (the
11
+ * "Software"), to deal in the Software without restriction, including
12
+ * without limitation the rights to use, copy, modify, merge, publish,
13
+ * distribute, sublicense, and/or sell copies of the Software, and to
14
+ * permit persons to whom the Software is furnished to do so, subject to
15
+ * the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be
18
+ * included in all copies or substantial portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ */
28
+
29
+ var INPUT_ERROR = 'input is invalid type';
30
+ var FINALIZE_ERROR = 'finalize already called';
31
+ var NODE_JS = typeof process === 'object' && process.versions && process.versions.node;
32
+ var ARRAY_BUFFER = typeof ArrayBuffer !== 'undefined';
33
+ var HEX_CHARS = '0123456789abcdef'.split('');
34
+ var EXTRA = [128, 32768, 8388608, -2147483648];
35
+ var SHIFT = [0, 8, 16, 24];
36
+ var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer', 'arrayBuffer', 'base64'];
37
+ var BASE64_ENCODE_CHAR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
38
+
39
+ var blocks = [], buffer8;
40
+ if (ARRAY_BUFFER) {
41
+ var buffer = new ArrayBuffer(68);
42
+ buffer8 = new Uint8Array(buffer);
43
+ blocks = new Uint32Array(buffer);
44
+ }
45
+
46
+ var isArray = Array.isArray;
47
+ if (!isArray) {
48
+ isArray = function (obj) {
49
+ return Object.prototype.toString.call(obj) === '[object Array]';
50
+ };
51
+ }
52
+
53
+ var isView = ArrayBuffer.isView;
54
+ if (ARRAY_BUFFER && !isView) {
55
+ isView = function (obj) {
56
+ return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
57
+ };
58
+ }
59
+
60
+ // [message: string, isString: bool]
61
+ var formatMessage = function (message) {
62
+ var type = typeof message;
63
+ if (type === 'string') {
64
+ return [message, true];
65
+ }
66
+ if (type !== 'object' || message === null) {
67
+ throw new Error(INPUT_ERROR);
68
+ }
69
+ if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
70
+ return [new Uint8Array(message), false];
71
+ }
72
+ if (!isArray(message) && !isView(message)) {
73
+ throw new Error(INPUT_ERROR);
74
+ }
75
+ return [message, false];
76
+ }
77
+
78
+ /**
79
+ * @method hex
80
+ * @memberof md5
81
+ * @description Output hash as hex string
82
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
83
+ * @returns {String} Hex string
84
+ * @example
85
+ * md5.hex('The quick brown fox jumps over the lazy dog');
86
+ * // equal to
87
+ * md5('The quick brown fox jumps over the lazy dog');
88
+ */
89
+ /**
90
+ * @method digest
91
+ * @memberof md5
92
+ * @description Output hash as bytes array
93
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
94
+ * @returns {Array} Bytes array
95
+ * @example
96
+ * md5.digest('The quick brown fox jumps over the lazy dog');
97
+ */
98
+ /**
99
+ * @method array
100
+ * @memberof md5
101
+ * @description Output hash as bytes array
102
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
103
+ * @returns {Array} Bytes array
104
+ * @example
105
+ * md5.array('The quick brown fox jumps over the lazy dog');
106
+ */
107
+ /**
108
+ * @method arrayBuffer
109
+ * @memberof md5
110
+ * @description Output hash as ArrayBuffer
111
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
112
+ * @returns {ArrayBuffer} ArrayBuffer
113
+ * @example
114
+ * md5.arrayBuffer('The quick brown fox jumps over the lazy dog');
115
+ */
116
+ /**
117
+ * @method buffer
118
+ * @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
119
+ * @memberof md5
120
+ * @description Output hash as ArrayBuffer
121
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
122
+ * @returns {ArrayBuffer} ArrayBuffer
123
+ * @example
124
+ * md5.buffer('The quick brown fox jumps over the lazy dog');
125
+ */
126
+ /**
127
+ * @method base64
128
+ * @memberof md5
129
+ * @description Output hash as base64 string
130
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
131
+ * @returns {String} base64 string
132
+ * @example
133
+ * md5.base64('The quick brown fox jumps over the lazy dog');
134
+ */
135
+ var createOutputMethod = function (outputType) {
136
+ return function (message) {
137
+ return new Md5(true).update(message)[outputType]();
138
+ };
139
+ };
140
+
141
+ /**
142
+ * @method create
143
+ * @memberof md5
144
+ * @description Create Md5 object
145
+ * @returns {Md5} Md5 object.
146
+ * @example
147
+ * var hash = md5.create();
148
+ */
149
+ /**
150
+ * @method update
151
+ * @memberof md5
152
+ * @description Create and update Md5 object
153
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
154
+ * @returns {Md5} Md5 object.
155
+ * @example
156
+ * var hash = md5.update('The quick brown fox jumps over the lazy dog');
157
+ * // equal to
158
+ * var hash = md5.create();
159
+ * hash.update('The quick brown fox jumps over the lazy dog');
160
+ */
161
+ var createMethod = function () {
162
+ var method = createOutputMethod('hex');
163
+ if (NODE_JS) {
164
+ method = nodeWrap(method);
165
+ }
166
+ method.create = function () {
167
+ return new Md5();
168
+ };
169
+ method.update = function (message) {
170
+ return method.create().update(message);
171
+ };
172
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
173
+ var type = OUTPUT_TYPES[i];
174
+ method[type] = createOutputMethod(type);
175
+ }
176
+ return method;
177
+ };
178
+
179
+ var nodeWrap = function (method) {
180
+ var crypto = require('crypto')
181
+ var Buffer = require('buffer').Buffer;
182
+ var bufferFrom;
183
+ if (Buffer.from) {
184
+ bufferFrom = Buffer.from;
185
+ } else {
186
+ bufferFrom = function (message) {
187
+ return new Buffer(message);
188
+ };
189
+ }
190
+ var nodeMethod = function (message) {
191
+ if (typeof message === 'string') {
192
+ return crypto.createHash('md5').update(message, 'utf8').digest('hex');
193
+ } else {
194
+ if (message === null || message === undefined) {
195
+ throw new Error(INPUT_ERROR);
196
+ } else if (message.constructor === ArrayBuffer) {
197
+ message = new Uint8Array(message);
198
+ }
199
+ }
200
+ if (isArray(message) || isView(message) ||
201
+ message.constructor === Buffer) {
202
+ return crypto.createHash('md5').update(bufferFrom(message)).digest('hex');
203
+ } else {
204
+ return method(message);
205
+ }
206
+ };
207
+ return nodeMethod;
208
+ };
209
+
210
+ /**
211
+ * @namespace md5.hmac
212
+ */
213
+ /**
214
+ * @method hex
215
+ * @memberof md5.hmac
216
+ * @description Output hash as hex string
217
+ * @param {String|Array|Uint8Array|ArrayBuffer} key key
218
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
219
+ * @returns {String} Hex string
220
+ * @example
221
+ * md5.hmac.hex('key', 'The quick brown fox jumps over the lazy dog');
222
+ * // equal to
223
+ * md5.hmac('key', 'The quick brown fox jumps over the lazy dog');
224
+ */
225
+
226
+ /**
227
+ * @method digest
228
+ * @memberof md5.hmac
229
+ * @description Output hash as bytes array
230
+ * @param {String|Array|Uint8Array|ArrayBuffer} key key
231
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
232
+ * @returns {Array} Bytes array
233
+ * @example
234
+ * md5.hmac.digest('key', 'The quick brown fox jumps over the lazy dog');
235
+ */
236
+ /**
237
+ * @method array
238
+ * @memberof md5.hmac
239
+ * @description Output hash as bytes array
240
+ * @param {String|Array|Uint8Array|ArrayBuffer} key key
241
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
242
+ * @returns {Array} Bytes array
243
+ * @example
244
+ * md5.hmac.array('key', 'The quick brown fox jumps over the lazy dog');
245
+ */
246
+ /**
247
+ * @method arrayBuffer
248
+ * @memberof md5.hmac
249
+ * @description Output hash as ArrayBuffer
250
+ * @param {String|Array|Uint8Array|ArrayBuffer} key key
251
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
252
+ * @returns {ArrayBuffer} ArrayBuffer
253
+ * @example
254
+ * md5.hmac.arrayBuffer('key', 'The quick brown fox jumps over the lazy dog');
255
+ */
256
+ /**
257
+ * @method buffer
258
+ * @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
259
+ * @memberof md5.hmac
260
+ * @description Output hash as ArrayBuffer
261
+ * @param {String|Array|Uint8Array|ArrayBuffer} key key
262
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
263
+ * @returns {ArrayBuffer} ArrayBuffer
264
+ * @example
265
+ * md5.hmac.buffer('key', 'The quick brown fox jumps over the lazy dog');
266
+ */
267
+ /**
268
+ * @method base64
269
+ * @memberof md5.hmac
270
+ * @description Output hash as base64 string
271
+ * @param {String|Array|Uint8Array|ArrayBuffer} key key
272
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
273
+ * @returns {String} base64 string
274
+ * @example
275
+ * md5.hmac.base64('key', 'The quick brown fox jumps over the lazy dog');
276
+ */
277
+ var createHmacOutputMethod = function (outputType) {
278
+ return function (key, message) {
279
+ return new HmacMd5(key, true).update(message)[outputType]();
280
+ };
281
+ };
282
+
283
+ /**
284
+ * @method create
285
+ * @memberof md5.hmac
286
+ * @description Create HmacMd5 object
287
+ * @param {String|Array|Uint8Array|ArrayBuffer} key key
288
+ * @returns {HmacMd5} HmacMd5 object.
289
+ * @example
290
+ * var hash = md5.hmac.create('key');
291
+ */
292
+ /**
293
+ * @method update
294
+ * @memberof md5.hmac
295
+ * @description Create and update HmacMd5 object
296
+ * @param {String|Array|Uint8Array|ArrayBuffer} key key
297
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
298
+ * @returns {HmacMd5} HmacMd5 object.
299
+ * @example
300
+ * var hash = md5.hmac.update('key', 'The quick brown fox jumps over the lazy dog');
301
+ * // equal to
302
+ * var hash = md5.hmac.create('key');
303
+ * hash.update('The quick brown fox jumps over the lazy dog');
304
+ */
305
+ var createHmacMethod = function () {
306
+ var method = createHmacOutputMethod('hex');
307
+ method.create = function (key) {
308
+ return new HmacMd5(key);
309
+ };
310
+ method.update = function (key, message) {
311
+ return method.create(key).update(message);
312
+ };
313
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
314
+ var type = OUTPUT_TYPES[i];
315
+ method[type] = createHmacOutputMethod(type);
316
+ }
317
+ return method;
318
+ };
319
+
320
+ /**
321
+ * Md5 class
322
+ * @class Md5
323
+ * @description This is internal class.
324
+ * @see {@link md5.create}
325
+ */
326
+ function Md5(sharedMemory) {
327
+ if (sharedMemory) {
328
+ blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] =
329
+ blocks[4] = blocks[5] = blocks[6] = blocks[7] =
330
+ blocks[8] = blocks[9] = blocks[10] = blocks[11] =
331
+ blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
332
+ this.blocks = blocks;
333
+ this.buffer8 = buffer8;
334
+ } else {
335
+ if (ARRAY_BUFFER) {
336
+ var buffer = new ArrayBuffer(68);
337
+ this.buffer8 = new Uint8Array(buffer);
338
+ this.blocks = new Uint32Array(buffer);
339
+ } else {
340
+ this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
341
+ }
342
+ }
343
+ this.h0 = this.h1 = this.h2 = this.h3 = this.start = this.bytes = this.hBytes = 0;
344
+ this.finalized = this.hashed = false;
345
+ this.first = true;
346
+ }
347
+
348
+ /**
349
+ * @method update
350
+ * @memberof Md5
351
+ * @instance
352
+ * @description Update hash
353
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
354
+ * @returns {Md5} Md5 object.
355
+ * @see {@link md5.update}
356
+ */
357
+ Md5.prototype.update = function (message) {
358
+ if (this.finalized) {
359
+ throw new Error(FINALIZE_ERROR);
360
+ }
361
+
362
+ var result = formatMessage(message);
363
+ message = result[0];
364
+ var isString = result[1];
365
+ var code, index = 0, i, length = message.length, blocks = this.blocks;
366
+ var buffer8 = this.buffer8;
367
+
368
+ while (index < length) {
369
+ if (this.hashed) {
370
+ this.hashed = false;
371
+ blocks[0] = blocks[16];
372
+ blocks[16] = blocks[1] = blocks[2] = blocks[3] =
373
+ blocks[4] = blocks[5] = blocks[6] = blocks[7] =
374
+ blocks[8] = blocks[9] = blocks[10] = blocks[11] =
375
+ blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
376
+ }
377
+
378
+ if (isString) {
379
+ if (ARRAY_BUFFER) {
380
+ for (i = this.start; index < length && i < 64; ++index) {
381
+ code = message.charCodeAt(index);
382
+ if (code < 0x80) {
383
+ buffer8[i++] = code;
384
+ } else if (code < 0x800) {
385
+ buffer8[i++] = 0xc0 | (code >>> 6);
386
+ buffer8[i++] = 0x80 | (code & 0x3f);
387
+ } else if (code < 0xd800 || code >= 0xe000) {
388
+ buffer8[i++] = 0xe0 | (code >>> 12);
389
+ buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
390
+ buffer8[i++] = 0x80 | (code & 0x3f);
391
+ } else {
392
+ code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
393
+ buffer8[i++] = 0xf0 | (code >>> 18);
394
+ buffer8[i++] = 0x80 | ((code >>> 12) & 0x3f);
395
+ buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
396
+ buffer8[i++] = 0x80 | (code & 0x3f);
397
+ }
398
+ }
399
+ } else {
400
+ for (i = this.start; index < length && i < 64; ++index) {
401
+ code = message.charCodeAt(index);
402
+ if (code < 0x80) {
403
+ blocks[i >>> 2] |= code << SHIFT[i++ & 3];
404
+ } else if (code < 0x800) {
405
+ blocks[i >>> 2] |= (0xc0 | (code >>> 6)) << SHIFT[i++ & 3];
406
+ blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
407
+ } else if (code < 0xd800 || code >= 0xe000) {
408
+ blocks[i >>> 2] |= (0xe0 | (code >>> 12)) << SHIFT[i++ & 3];
409
+ blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
410
+ blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
411
+ } else {
412
+ code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
413
+ blocks[i >>> 2] |= (0xf0 | (code >>> 18)) << SHIFT[i++ & 3];
414
+ blocks[i >>> 2] |= (0x80 | ((code >>> 12) & 0x3f)) << SHIFT[i++ & 3];
415
+ blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
416
+ blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
417
+ }
418
+ }
419
+ }
420
+ } else {
421
+ if (ARRAY_BUFFER) {
422
+ for (i = this.start; index < length && i < 64; ++index) {
423
+ buffer8[i++] = message[index];
424
+ }
425
+ } else {
426
+ for (i = this.start; index < length && i < 64; ++index) {
427
+ blocks[i >>> 2] |= message[index] << SHIFT[i++ & 3];
428
+ }
429
+ }
430
+ }
431
+ this.lastByteIndex = i;
432
+ this.bytes += i - this.start;
433
+ if (i >= 64) {
434
+ this.start = i - 64;
435
+ this.hash();
436
+ this.hashed = true;
437
+ } else {
438
+ this.start = i;
439
+ }
440
+ }
441
+ if (this.bytes > 4294967295) {
442
+ this.hBytes += this.bytes / 4294967296 << 0;
443
+ this.bytes = this.bytes % 4294967296;
444
+ }
445
+ return this;
446
+ };
447
+
448
+ Md5.prototype.finalize = function () {
449
+ if (this.finalized) {
450
+ return;
451
+ }
452
+ this.finalized = true;
453
+ var blocks = this.blocks, i = this.lastByteIndex;
454
+ blocks[i >>> 2] |= EXTRA[i & 3];
455
+ if (i >= 56) {
456
+ if (!this.hashed) {
457
+ this.hash();
458
+ }
459
+ blocks[0] = blocks[16];
460
+ blocks[16] = blocks[1] = blocks[2] = blocks[3] =
461
+ blocks[4] = blocks[5] = blocks[6] = blocks[7] =
462
+ blocks[8] = blocks[9] = blocks[10] = blocks[11] =
463
+ blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
464
+ }
465
+ blocks[14] = this.bytes << 3;
466
+ blocks[15] = this.hBytes << 3 | this.bytes >>> 29;
467
+ this.hash();
468
+ };
469
+
470
+ Md5.prototype.hash = function () {
471
+ var a, b, c, d, bc, da, blocks = this.blocks;
472
+
473
+ if (this.first) {
474
+ a = blocks[0] - 680876937;
475
+ a = (a << 7 | a >>> 25) - 271733879 << 0;
476
+ d = (-1732584194 ^ a & 2004318071) + blocks[1] - 117830708;
477
+ d = (d << 12 | d >>> 20) + a << 0;
478
+ c = (-271733879 ^ (d & (a ^ -271733879))) + blocks[2] - 1126478375;
479
+ c = (c << 17 | c >>> 15) + d << 0;
480
+ b = (a ^ (c & (d ^ a))) + blocks[3] - 1316259209;
481
+ b = (b << 22 | b >>> 10) + c << 0;
482
+ } else {
483
+ a = this.h0;
484
+ b = this.h1;
485
+ c = this.h2;
486
+ d = this.h3;
487
+ a += (d ^ (b & (c ^ d))) + blocks[0] - 680876936;
488
+ a = (a << 7 | a >>> 25) + b << 0;
489
+ d += (c ^ (a & (b ^ c))) + blocks[1] - 389564586;
490
+ d = (d << 12 | d >>> 20) + a << 0;
491
+ c += (b ^ (d & (a ^ b))) + blocks[2] + 606105819;
492
+ c = (c << 17 | c >>> 15) + d << 0;
493
+ b += (a ^ (c & (d ^ a))) + blocks[3] - 1044525330;
494
+ b = (b << 22 | b >>> 10) + c << 0;
495
+ }
496
+
497
+ a += (d ^ (b & (c ^ d))) + blocks[4] - 176418897;
498
+ a = (a << 7 | a >>> 25) + b << 0;
499
+ d += (c ^ (a & (b ^ c))) + blocks[5] + 1200080426;
500
+ d = (d << 12 | d >>> 20) + a << 0;
501
+ c += (b ^ (d & (a ^ b))) + blocks[6] - 1473231341;
502
+ c = (c << 17 | c >>> 15) + d << 0;
503
+ b += (a ^ (c & (d ^ a))) + blocks[7] - 45705983;
504
+ b = (b << 22 | b >>> 10) + c << 0;
505
+ a += (d ^ (b & (c ^ d))) + blocks[8] + 1770035416;
506
+ a = (a << 7 | a >>> 25) + b << 0;
507
+ d += (c ^ (a & (b ^ c))) + blocks[9] - 1958414417;
508
+ d = (d << 12 | d >>> 20) + a << 0;
509
+ c += (b ^ (d & (a ^ b))) + blocks[10] - 42063;
510
+ c = (c << 17 | c >>> 15) + d << 0;
511
+ b += (a ^ (c & (d ^ a))) + blocks[11] - 1990404162;
512
+ b = (b << 22 | b >>> 10) + c << 0;
513
+ a += (d ^ (b & (c ^ d))) + blocks[12] + 1804603682;
514
+ a = (a << 7 | a >>> 25) + b << 0;
515
+ d += (c ^ (a & (b ^ c))) + blocks[13] - 40341101;
516
+ d = (d << 12 | d >>> 20) + a << 0;
517
+ c += (b ^ (d & (a ^ b))) + blocks[14] - 1502002290;
518
+ c = (c << 17 | c >>> 15) + d << 0;
519
+ b += (a ^ (c & (d ^ a))) + blocks[15] + 1236535329;
520
+ b = (b << 22 | b >>> 10) + c << 0;
521
+ a += (c ^ (d & (b ^ c))) + blocks[1] - 165796510;
522
+ a = (a << 5 | a >>> 27) + b << 0;
523
+ d += (b ^ (c & (a ^ b))) + blocks[6] - 1069501632;
524
+ d = (d << 9 | d >>> 23) + a << 0;
525
+ c += (a ^ (b & (d ^ a))) + blocks[11] + 643717713;
526
+ c = (c << 14 | c >>> 18) + d << 0;
527
+ b += (d ^ (a & (c ^ d))) + blocks[0] - 373897302;
528
+ b = (b << 20 | b >>> 12) + c << 0;
529
+ a += (c ^ (d & (b ^ c))) + blocks[5] - 701558691;
530
+ a = (a << 5 | a >>> 27) + b << 0;
531
+ d += (b ^ (c & (a ^ b))) + blocks[10] + 38016083;
532
+ d = (d << 9 | d >>> 23) + a << 0;
533
+ c += (a ^ (b & (d ^ a))) + blocks[15] - 660478335;
534
+ c = (c << 14 | c >>> 18) + d << 0;
535
+ b += (d ^ (a & (c ^ d))) + blocks[4] - 405537848;
536
+ b = (b << 20 | b >>> 12) + c << 0;
537
+ a += (c ^ (d & (b ^ c))) + blocks[9] + 568446438;
538
+ a = (a << 5 | a >>> 27) + b << 0;
539
+ d += (b ^ (c & (a ^ b))) + blocks[14] - 1019803690;
540
+ d = (d << 9 | d >>> 23) + a << 0;
541
+ c += (a ^ (b & (d ^ a))) + blocks[3] - 187363961;
542
+ c = (c << 14 | c >>> 18) + d << 0;
543
+ b += (d ^ (a & (c ^ d))) + blocks[8] + 1163531501;
544
+ b = (b << 20 | b >>> 12) + c << 0;
545
+ a += (c ^ (d & (b ^ c))) + blocks[13] - 1444681467;
546
+ a = (a << 5 | a >>> 27) + b << 0;
547
+ d += (b ^ (c & (a ^ b))) + blocks[2] - 51403784;
548
+ d = (d << 9 | d >>> 23) + a << 0;
549
+ c += (a ^ (b & (d ^ a))) + blocks[7] + 1735328473;
550
+ c = (c << 14 | c >>> 18) + d << 0;
551
+ b += (d ^ (a & (c ^ d))) + blocks[12] - 1926607734;
552
+ b = (b << 20 | b >>> 12) + c << 0;
553
+ bc = b ^ c;
554
+ a += (bc ^ d) + blocks[5] - 378558;
555
+ a = (a << 4 | a >>> 28) + b << 0;
556
+ d += (bc ^ a) + blocks[8] - 2022574463;
557
+ d = (d << 11 | d >>> 21) + a << 0;
558
+ da = d ^ a;
559
+ c += (da ^ b) + blocks[11] + 1839030562;
560
+ c = (c << 16 | c >>> 16) + d << 0;
561
+ b += (da ^ c) + blocks[14] - 35309556;
562
+ b = (b << 23 | b >>> 9) + c << 0;
563
+ bc = b ^ c;
564
+ a += (bc ^ d) + blocks[1] - 1530992060;
565
+ a = (a << 4 | a >>> 28) + b << 0;
566
+ d += (bc ^ a) + blocks[4] + 1272893353;
567
+ d = (d << 11 | d >>> 21) + a << 0;
568
+ da = d ^ a;
569
+ c += (da ^ b) + blocks[7] - 155497632;
570
+ c = (c << 16 | c >>> 16) + d << 0;
571
+ b += (da ^ c) + blocks[10] - 1094730640;
572
+ b = (b << 23 | b >>> 9) + c << 0;
573
+ bc = b ^ c;
574
+ a += (bc ^ d) + blocks[13] + 681279174;
575
+ a = (a << 4 | a >>> 28) + b << 0;
576
+ d += (bc ^ a) + blocks[0] - 358537222;
577
+ d = (d << 11 | d >>> 21) + a << 0;
578
+ da = d ^ a;
579
+ c += (da ^ b) + blocks[3] - 722521979;
580
+ c = (c << 16 | c >>> 16) + d << 0;
581
+ b += (da ^ c) + blocks[6] + 76029189;
582
+ b = (b << 23 | b >>> 9) + c << 0;
583
+ bc = b ^ c;
584
+ a += (bc ^ d) + blocks[9] - 640364487;
585
+ a = (a << 4 | a >>> 28) + b << 0;
586
+ d += (bc ^ a) + blocks[12] - 421815835;
587
+ d = (d << 11 | d >>> 21) + a << 0;
588
+ da = d ^ a;
589
+ c += (da ^ b) + blocks[15] + 530742520;
590
+ c = (c << 16 | c >>> 16) + d << 0;
591
+ b += (da ^ c) + blocks[2] - 995338651;
592
+ b = (b << 23 | b >>> 9) + c << 0;
593
+ a += (c ^ (b | ~d)) + blocks[0] - 198630844;
594
+ a = (a << 6 | a >>> 26) + b << 0;
595
+ d += (b ^ (a | ~c)) + blocks[7] + 1126891415;
596
+ d = (d << 10 | d >>> 22) + a << 0;
597
+ c += (a ^ (d | ~b)) + blocks[14] - 1416354905;
598
+ c = (c << 15 | c >>> 17) + d << 0;
599
+ b += (d ^ (c | ~a)) + blocks[5] - 57434055;
600
+ b = (b << 21 | b >>> 11) + c << 0;
601
+ a += (c ^ (b | ~d)) + blocks[12] + 1700485571;
602
+ a = (a << 6 | a >>> 26) + b << 0;
603
+ d += (b ^ (a | ~c)) + blocks[3] - 1894986606;
604
+ d = (d << 10 | d >>> 22) + a << 0;
605
+ c += (a ^ (d | ~b)) + blocks[10] - 1051523;
606
+ c = (c << 15 | c >>> 17) + d << 0;
607
+ b += (d ^ (c | ~a)) + blocks[1] - 2054922799;
608
+ b = (b << 21 | b >>> 11) + c << 0;
609
+ a += (c ^ (b | ~d)) + blocks[8] + 1873313359;
610
+ a = (a << 6 | a >>> 26) + b << 0;
611
+ d += (b ^ (a | ~c)) + blocks[15] - 30611744;
612
+ d = (d << 10 | d >>> 22) + a << 0;
613
+ c += (a ^ (d | ~b)) + blocks[6] - 1560198380;
614
+ c = (c << 15 | c >>> 17) + d << 0;
615
+ b += (d ^ (c | ~a)) + blocks[13] + 1309151649;
616
+ b = (b << 21 | b >>> 11) + c << 0;
617
+ a += (c ^ (b | ~d)) + blocks[4] - 145523070;
618
+ a = (a << 6 | a >>> 26) + b << 0;
619
+ d += (b ^ (a | ~c)) + blocks[11] - 1120210379;
620
+ d = (d << 10 | d >>> 22) + a << 0;
621
+ c += (a ^ (d | ~b)) + blocks[2] + 718787259;
622
+ c = (c << 15 | c >>> 17) + d << 0;
623
+ b += (d ^ (c | ~a)) + blocks[9] - 343485551;
624
+ b = (b << 21 | b >>> 11) + c << 0;
625
+
626
+ if (this.first) {
627
+ this.h0 = a + 1732584193 << 0;
628
+ this.h1 = b - 271733879 << 0;
629
+ this.h2 = c - 1732584194 << 0;
630
+ this.h3 = d + 271733878 << 0;
631
+ this.first = false;
632
+ } else {
633
+ this.h0 = this.h0 + a << 0;
634
+ this.h1 = this.h1 + b << 0;
635
+ this.h2 = this.h2 + c << 0;
636
+ this.h3 = this.h3 + d << 0;
637
+ }
638
+ };
639
+
640
+ /**
641
+ * @method hex
642
+ * @memberof Md5
643
+ * @instance
644
+ * @description Output hash as hex string
645
+ * @returns {String} Hex string
646
+ * @see {@link md5.hex}
647
+ * @example
648
+ * hash.hex();
649
+ */
650
+ Md5.prototype.hex = function () {
651
+ this.finalize();
652
+
653
+ var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
654
+
655
+ return HEX_CHARS[(h0 >>> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
656
+ HEX_CHARS[(h0 >>> 12) & 0x0F] + HEX_CHARS[(h0 >>> 8) & 0x0F] +
657
+ HEX_CHARS[(h0 >>> 20) & 0x0F] + HEX_CHARS[(h0 >>> 16) & 0x0F] +
658
+ HEX_CHARS[(h0 >>> 28) & 0x0F] + HEX_CHARS[(h0 >>> 24) & 0x0F] +
659
+ HEX_CHARS[(h1 >>> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
660
+ HEX_CHARS[(h1 >>> 12) & 0x0F] + HEX_CHARS[(h1 >>> 8) & 0x0F] +
661
+ HEX_CHARS[(h1 >>> 20) & 0x0F] + HEX_CHARS[(h1 >>> 16) & 0x0F] +
662
+ HEX_CHARS[(h1 >>> 28) & 0x0F] + HEX_CHARS[(h1 >>> 24) & 0x0F] +
663
+ HEX_CHARS[(h2 >>> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
664
+ HEX_CHARS[(h2 >>> 12) & 0x0F] + HEX_CHARS[(h2 >>> 8) & 0x0F] +
665
+ HEX_CHARS[(h2 >>> 20) & 0x0F] + HEX_CHARS[(h2 >>> 16) & 0x0F] +
666
+ HEX_CHARS[(h2 >>> 28) & 0x0F] + HEX_CHARS[(h2 >>> 24) & 0x0F] +
667
+ HEX_CHARS[(h3 >>> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
668
+ HEX_CHARS[(h3 >>> 12) & 0x0F] + HEX_CHARS[(h3 >>> 8) & 0x0F] +
669
+ HEX_CHARS[(h3 >>> 20) & 0x0F] + HEX_CHARS[(h3 >>> 16) & 0x0F] +
670
+ HEX_CHARS[(h3 >>> 28) & 0x0F] + HEX_CHARS[(h3 >>> 24) & 0x0F];
671
+ };
672
+
673
+ /**
674
+ * @method toString
675
+ * @memberof Md5
676
+ * @instance
677
+ * @description Output hash as hex string
678
+ * @returns {String} Hex string
679
+ * @see {@link md5.hex}
680
+ * @example
681
+ * hash.toString();
682
+ */
683
+ Md5.prototype.toString = Md5.prototype.hex;
684
+
685
+ /**
686
+ * @method digest
687
+ * @memberof Md5
688
+ * @instance
689
+ * @description Output hash as bytes array
690
+ * @returns {Array} Bytes array
691
+ * @see {@link md5.digest}
692
+ * @example
693
+ * hash.digest();
694
+ */
695
+ Md5.prototype.digest = function () {
696
+ this.finalize();
697
+
698
+ var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
699
+ return [
700
+ h0 & 0xFF, (h0 >>> 8) & 0xFF, (h0 >>> 16) & 0xFF, (h0 >>> 24) & 0xFF,
701
+ h1 & 0xFF, (h1 >>> 8) & 0xFF, (h1 >>> 16) & 0xFF, (h1 >>> 24) & 0xFF,
702
+ h2 & 0xFF, (h2 >>> 8) & 0xFF, (h2 >>> 16) & 0xFF, (h2 >>> 24) & 0xFF,
703
+ h3 & 0xFF, (h3 >>> 8) & 0xFF, (h3 >>> 16) & 0xFF, (h3 >>> 24) & 0xFF
704
+ ];
705
+ };
706
+
707
+ /**
708
+ * @method array
709
+ * @memberof Md5
710
+ * @instance
711
+ * @description Output hash as bytes array
712
+ * @returns {Array} Bytes array
713
+ * @see {@link md5.array}
714
+ * @example
715
+ * hash.array();
716
+ */
717
+ Md5.prototype.array = Md5.prototype.digest;
718
+
719
+ /**
720
+ * @method arrayBuffer
721
+ * @memberof Md5
722
+ * @instance
723
+ * @description Output hash as ArrayBuffer
724
+ * @returns {ArrayBuffer} ArrayBuffer
725
+ * @see {@link md5.arrayBuffer}
726
+ * @example
727
+ * hash.arrayBuffer();
728
+ */
729
+ Md5.prototype.arrayBuffer = function () {
730
+ this.finalize();
731
+
732
+ var buffer = new ArrayBuffer(16);
733
+ var blocks = new Uint32Array(buffer);
734
+ blocks[0] = this.h0;
735
+ blocks[1] = this.h1;
736
+ blocks[2] = this.h2;
737
+ blocks[3] = this.h3;
738
+ return buffer;
739
+ };
740
+
741
+ /**
742
+ * @method buffer
743
+ * @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
744
+ * @memberof Md5
745
+ * @instance
746
+ * @description Output hash as ArrayBuffer
747
+ * @returns {ArrayBuffer} ArrayBuffer
748
+ * @see {@link md5.buffer}
749
+ * @example
750
+ * hash.buffer();
751
+ */
752
+ Md5.prototype.buffer = Md5.prototype.arrayBuffer;
753
+
754
+ /**
755
+ * @method base64
756
+ * @memberof Md5
757
+ * @instance
758
+ * @description Output hash as base64 string
759
+ * @returns {String} base64 string
760
+ * @see {@link md5.base64}
761
+ * @example
762
+ * hash.base64();
763
+ */
764
+ Md5.prototype.base64 = function () {
765
+ var v1, v2, v3, base64Str = '', bytes = this.array();
766
+ for (var i = 0; i < 15;) {
767
+ v1 = bytes[i++];
768
+ v2 = bytes[i++];
769
+ v3 = bytes[i++];
770
+ base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
771
+ BASE64_ENCODE_CHAR[(v1 << 4 | v2 >>> 4) & 63] +
772
+ BASE64_ENCODE_CHAR[(v2 << 2 | v3 >>> 6) & 63] +
773
+ BASE64_ENCODE_CHAR[v3 & 63];
774
+ }
775
+ v1 = bytes[i];
776
+ base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
777
+ BASE64_ENCODE_CHAR[(v1 << 4) & 63] +
778
+ '==';
779
+ return base64Str;
780
+ };
781
+
782
+ /**
783
+ * HmacMd5 class
784
+ * @class HmacMd5
785
+ * @extends Md5
786
+ * @description This is internal class.
787
+ * @see {@link md5.hmac.create}
788
+ */
789
+ function HmacMd5(key, sharedMemory) {
790
+ var i, result = formatMessage(key);
791
+ key = result[0];
792
+ if (result[1]) {
793
+ var bytes = [], length = key.length, index = 0, code;
794
+ for (i = 0; i < length; ++i) {
795
+ code = key.charCodeAt(i);
796
+ if (code < 0x80) {
797
+ bytes[index++] = code;
798
+ } else if (code < 0x800) {
799
+ bytes[index++] = (0xc0 | (code >>> 6));
800
+ bytes[index++] = (0x80 | (code & 0x3f));
801
+ } else if (code < 0xd800 || code >= 0xe000) {
802
+ bytes[index++] = (0xe0 | (code >>> 12));
803
+ bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
804
+ bytes[index++] = (0x80 | (code & 0x3f));
805
+ } else {
806
+ code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff));
807
+ bytes[index++] = (0xf0 | (code >>> 18));
808
+ bytes[index++] = (0x80 | ((code >>> 12) & 0x3f));
809
+ bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
810
+ bytes[index++] = (0x80 | (code & 0x3f));
811
+ }
812
+ }
813
+ key = bytes;
814
+ }
815
+
816
+ if (key.length > 64) {
817
+ key = (new Md5(true)).update(key).array();
818
+ }
819
+
820
+ var oKeyPad = [], iKeyPad = [];
821
+ for (i = 0; i < 64; ++i) {
822
+ var b = key[i] || 0;
823
+ oKeyPad[i] = 0x5c ^ b;
824
+ iKeyPad[i] = 0x36 ^ b;
825
+ }
826
+
827
+ Md5.call(this, sharedMemory);
828
+
829
+ this.update(iKeyPad);
830
+ this.oKeyPad = oKeyPad;
831
+ this.inner = true;
832
+ this.sharedMemory = sharedMemory;
833
+ }
834
+ HmacMd5.prototype = new Md5();
835
+
836
+ HmacMd5.prototype.finalize = function () {
837
+ Md5.prototype.finalize.call(this);
838
+ if (this.inner) {
839
+ this.inner = false;
840
+ var innerHash = this.array();
841
+ Md5.call(this, this.sharedMemory);
842
+ this.update(this.oKeyPad);
843
+ this.update(innerHash);
844
+ Md5.prototype.finalize.call(this);
845
+ }
846
+ };
847
+
848
+ const md5 = createMethod();
849
+ export default md5;