UNPKG

335 kBJavaScriptView Raw
1/******/ (function(modules) { // webpackBootstrap
2/******/ // The module cache
3/******/ var installedModules = {};
4/******/
5/******/ // The require function
6/******/ function __webpack_require__(moduleId) {
7/******/
8/******/ // Check if module is in cache
9/******/ if(installedModules[moduleId])
10/******/ return installedModules[moduleId].exports;
11/******/
12/******/ // Create a new module (and put it into the cache)
13/******/ var module = installedModules[moduleId] = {
14/******/ i: moduleId,
15/******/ l: false,
16/******/ exports: {}
17/******/ };
18/******/
19/******/ // Execute the module function
20/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21/******/
22/******/ // Flag the module as loaded
23/******/ module.l = true;
24/******/
25/******/ // Return the exports of the module
26/******/ return module.exports;
27/******/ }
28/******/
29/******/
30/******/ // expose the modules object (__webpack_modules__)
31/******/ __webpack_require__.m = modules;
32/******/
33/******/ // expose the module cache
34/******/ __webpack_require__.c = installedModules;
35/******/
36/******/ // identity function for calling harmony imports with the correct context
37/******/ __webpack_require__.i = function(value) { return value; };
38/******/
39/******/ // define getter function for harmony exports
40/******/ __webpack_require__.d = function(exports, name, getter) {
41/******/ if(!__webpack_require__.o(exports, name)) {
42/******/ Object.defineProperty(exports, name, {
43/******/ configurable: false,
44/******/ enumerable: true,
45/******/ get: getter
46/******/ });
47/******/ }
48/******/ };
49/******/
50/******/ // getDefaultExport function for compatibility with non-harmony modules
51/******/ __webpack_require__.n = function(module) {
52/******/ var getter = module && module.__esModule ?
53/******/ function getDefault() { return module['default']; } :
54/******/ function getModuleExports() { return module; };
55/******/ __webpack_require__.d(getter, 'a', getter);
56/******/ return getter;
57/******/ };
58/******/
59/******/ // Object.prototype.hasOwnProperty.call
60/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
61/******/
62/******/ // __webpack_public_path__
63/******/ __webpack_require__.p = "";
64/******/
65/******/ // Load entry module and return exports
66/******/ return __webpack_require__(__webpack_require__.s = 26);
67/******/ })
68/************************************************************************/
69/******/ ([
70/* 0 */
71/***/ (function(module, exports) {
72
73/*
74CryptoJS v3.1.2
75code.google.com/p/crypto-js
76(c) 2009-2013 by Jeff Mott. All rights reserved.
77code.google.com/p/crypto-js/wiki/License
78*/
79/**
80 * CryptoJS core components.
81 */
82var CryptoJS = CryptoJS || (function (Math, undefined) {
83 /**
84 * CryptoJS namespace.
85 */
86 var C = {};
87
88 /**
89 * Library namespace.
90 */
91 var C_lib = C.lib = {};
92
93 /**
94 * Base object for prototypal inheritance.
95 */
96 var Base = C_lib.Base = (function () {
97 function F() {}
98
99 return {
100 /**
101 * Creates a new object that inherits from this object.
102 *
103 * @param {Object} overrides Properties to copy into the new object.
104 *
105 * @return {Object} The new object.
106 *
107 * @static
108 *
109 * @example
110 *
111 * var MyType = CryptoJS.lib.Base.extend({
112 * field: 'value',
113 *
114 * method: function () {
115 * }
116 * });
117 */
118 extend: function (overrides) {
119 // Spawn
120 F.prototype = this;
121 var subtype = new F();
122
123 // Augment
124 if (overrides) {
125 subtype.mixIn(overrides);
126 }
127
128 // Create default initializer
129 if (!subtype.hasOwnProperty('init')) {
130 subtype.init = function () {
131 subtype.$super.init.apply(this, arguments);
132 };
133 }
134
135 // Initializer's prototype is the subtype object
136 subtype.init.prototype = subtype;
137
138 // Reference supertype
139 subtype.$super = this;
140
141 return subtype;
142 },
143
144 /**
145 * Extends this object and runs the init method.
146 * Arguments to create() will be passed to init().
147 *
148 * @return {Object} The new object.
149 *
150 * @static
151 *
152 * @example
153 *
154 * var instance = MyType.create();
155 */
156 create: function () {
157 var instance = this.extend();
158 instance.init.apply(instance, arguments);
159
160 return instance;
161 },
162
163 /**
164 * Initializes a newly created object.
165 * Override this method to add some logic when your objects are created.
166 *
167 * @example
168 *
169 * var MyType = CryptoJS.lib.Base.extend({
170 * init: function () {
171 * // ...
172 * }
173 * });
174 */
175 init: function () {
176 },
177
178 /**
179 * Copies properties into this object.
180 *
181 * @param {Object} properties The properties to mix in.
182 *
183 * @example
184 *
185 * MyType.mixIn({
186 * field: 'value'
187 * });
188 */
189 mixIn: function (properties) {
190 for (var propertyName in properties) {
191 if (properties.hasOwnProperty(propertyName)) {
192 this[propertyName] = properties[propertyName];
193 }
194 }
195
196 // IE won't copy toString using the loop above
197 if (properties.hasOwnProperty('toString')) {
198 this.toString = properties.toString;
199 }
200 },
201
202 /**
203 * Creates a copy of this object.
204 *
205 * @return {Object} The clone.
206 *
207 * @example
208 *
209 * var clone = instance.clone();
210 */
211 clone: function () {
212 return this.init.prototype.extend(this);
213 }
214 };
215 }());
216
217 /**
218 * An array of 32-bit words.
219 *
220 * @property {Array} words The array of 32-bit words.
221 * @property {number} sigBytes The number of significant bytes in this word array.
222 */
223 var WordArray = C_lib.WordArray = Base.extend({
224 /**
225 * Initializes a newly created word array.
226 *
227 * @param {Array} words (Optional) An array of 32-bit words.
228 * @param {number} sigBytes (Optional) The number of significant bytes in the words.
229 *
230 * @example
231 *
232 * var wordArray = CryptoJS.lib.WordArray.create();
233 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
234 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
235 */
236 init: function (words, sigBytes) {
237 words = this.words = words || [];
238
239 if (sigBytes != undefined) {
240 this.sigBytes = sigBytes;
241 } else {
242 this.sigBytes = words.length * 4;
243 }
244 },
245
246 /**
247 * Converts this word array to a string.
248 *
249 * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
250 *
251 * @return {string} The stringified word array.
252 *
253 * @example
254 *
255 * var string = wordArray + '';
256 * var string = wordArray.toString();
257 * var string = wordArray.toString(CryptoJS.enc.Utf8);
258 */
259 toString: function (encoder) {
260 return (encoder || Hex).stringify(this);
261 },
262
263 /**
264 * Concatenates a word array to this word array.
265 *
266 * @param {WordArray} wordArray The word array to append.
267 *
268 * @return {WordArray} This word array.
269 *
270 * @example
271 *
272 * wordArray1.concat(wordArray2);
273 */
274 concat: function (wordArray) {
275 // Shortcuts
276 var thisWords = this.words;
277 var thatWords = wordArray.words;
278 var thisSigBytes = this.sigBytes;
279 var thatSigBytes = wordArray.sigBytes;
280
281 // Clamp excess bits
282 this.clamp();
283
284 // Concat
285 if (thisSigBytes % 4) {
286 // Copy one byte at a time
287 for (var i = 0; i < thatSigBytes; i++) {
288 var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
289 thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
290 }
291 } else if (thatWords.length > 0xffff) {
292 // Copy one word at a time
293 for (var i = 0; i < thatSigBytes; i += 4) {
294 thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2];
295 }
296 } else {
297 // Copy all words at once
298 thisWords.push.apply(thisWords, thatWords);
299 }
300 this.sigBytes += thatSigBytes;
301
302 // Chainable
303 return this;
304 },
305
306 /**
307 * Removes insignificant bits.
308 *
309 * @example
310 *
311 * wordArray.clamp();
312 */
313 clamp: function () {
314 // Shortcuts
315 var words = this.words;
316 var sigBytes = this.sigBytes;
317
318 // Clamp
319 words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
320 words.length = Math.ceil(sigBytes / 4);
321 },
322
323 /**
324 * Creates a copy of this word array.
325 *
326 * @return {WordArray} The clone.
327 *
328 * @example
329 *
330 * var clone = wordArray.clone();
331 */
332 clone: function () {
333 var clone = Base.clone.call(this);
334 clone.words = this.words.slice(0);
335
336 return clone;
337 },
338
339 /**
340 * Creates a word array filled with random bytes.
341 *
342 * @param {number} nBytes The number of random bytes to generate.
343 *
344 * @return {WordArray} The random word array.
345 *
346 * @static
347 *
348 * @example
349 *
350 * var wordArray = CryptoJS.lib.WordArray.random(16);
351 */
352 random: function (nBytes) {
353 var words = [];
354 for (var i = 0; i < nBytes; i += 4) {
355 words.push((Math.random() * 0x100000000) | 0);
356 }
357
358 return new WordArray.init(words, nBytes);
359 }
360 });
361
362 /**
363 * Encoder namespace.
364 */
365 var C_enc = C.enc = {};
366
367 /**
368 * Hex encoding strategy.
369 */
370 var Hex = C_enc.Hex = {
371 /**
372 * Converts a word array to a hex string.
373 *
374 * @param {WordArray} wordArray The word array.
375 *
376 * @return {string} The hex string.
377 *
378 * @static
379 *
380 * @example
381 *
382 * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
383 */
384 stringify: function (wordArray) {
385 // Shortcuts
386 var words = wordArray.words;
387 var sigBytes = wordArray.sigBytes;
388
389 // Convert
390 var hexChars = [];
391 for (var i = 0; i < sigBytes; i++) {
392 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
393 hexChars.push((bite >>> 4).toString(16));
394 hexChars.push((bite & 0x0f).toString(16));
395 }
396
397 return hexChars.join('');
398 },
399
400 /**
401 * Converts a hex string to a word array.
402 *
403 * @param {string} hexStr The hex string.
404 *
405 * @return {WordArray} The word array.
406 *
407 * @static
408 *
409 * @example
410 *
411 * var wordArray = CryptoJS.enc.Hex.parse(hexString);
412 */
413 parse: function (hexStr) {
414 // Shortcut
415 var hexStrLength = hexStr.length;
416
417 // Convert
418 var words = [];
419 for (var i = 0; i < hexStrLength; i += 2) {
420 words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
421 }
422
423 return new WordArray.init(words, hexStrLength / 2);
424 }
425 };
426
427 /**
428 * Latin1 encoding strategy.
429 */
430 var Latin1 = C_enc.Latin1 = {
431 /**
432 * Converts a word array to a Latin1 string.
433 *
434 * @param {WordArray} wordArray The word array.
435 *
436 * @return {string} The Latin1 string.
437 *
438 * @static
439 *
440 * @example
441 *
442 * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
443 */
444 stringify: function (wordArray) {
445 // Shortcuts
446 var words = wordArray.words;
447 var sigBytes = wordArray.sigBytes;
448
449 // Convert
450 var latin1Chars = [];
451 for (var i = 0; i < sigBytes; i++) {
452 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
453 latin1Chars.push(String.fromCharCode(bite));
454 }
455
456 return latin1Chars.join('');
457 },
458
459 /**
460 * Converts a Latin1 string to a word array.
461 *
462 * @param {string} latin1Str The Latin1 string.
463 *
464 * @return {WordArray} The word array.
465 *
466 * @static
467 *
468 * @example
469 *
470 * var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
471 */
472 parse: function (latin1Str) {
473 // Shortcut
474 var latin1StrLength = latin1Str.length;
475
476 // Convert
477 var words = [];
478 for (var i = 0; i < latin1StrLength; i++) {
479 words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
480 }
481
482 return new WordArray.init(words, latin1StrLength);
483 }
484 };
485
486 /**
487 * UTF-8 encoding strategy.
488 */
489 var Utf8 = C_enc.Utf8 = {
490 /**
491 * Converts a word array to a UTF-8 string.
492 *
493 * @param {WordArray} wordArray The word array.
494 *
495 * @return {string} The UTF-8 string.
496 *
497 * @static
498 *
499 * @example
500 *
501 * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
502 */
503 stringify: function (wordArray) {
504 try {
505 return decodeURIComponent(escape(Latin1.stringify(wordArray)));
506 } catch (e) {
507 throw new Error('Malformed UTF-8 data');
508 }
509 },
510
511 /**
512 * Converts a UTF-8 string to a word array.
513 *
514 * @param {string} utf8Str The UTF-8 string.
515 *
516 * @return {WordArray} The word array.
517 *
518 * @static
519 *
520 * @example
521 *
522 * var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
523 */
524 parse: function (utf8Str) {
525 return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
526 }
527 };
528
529 /**
530 * Abstract buffered block algorithm template.
531 *
532 * The property blockSize must be implemented in a concrete subtype.
533 *
534 * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
535 */
536 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
537 /**
538 * Resets this block algorithm's data buffer to its initial state.
539 *
540 * @example
541 *
542 * bufferedBlockAlgorithm.reset();
543 */
544 reset: function () {
545 // Initial values
546 this._data = new WordArray.init();
547 this._nDataBytes = 0;
548 },
549
550 /**
551 * Adds new data to this block algorithm's buffer.
552 *
553 * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
554 *
555 * @example
556 *
557 * bufferedBlockAlgorithm._append('data');
558 * bufferedBlockAlgorithm._append(wordArray);
559 */
560 _append: function (data) {
561 // Convert string to WordArray, else assume WordArray already
562 if (typeof data == 'string') {
563 data = Utf8.parse(data);
564 }
565
566 // Append
567 this._data.concat(data);
568 this._nDataBytes += data.sigBytes;
569 },
570
571 /**
572 * Processes available data blocks.
573 *
574 * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
575 *
576 * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
577 *
578 * @return {WordArray} The processed data.
579 *
580 * @example
581 *
582 * var processedData = bufferedBlockAlgorithm._process();
583 * var processedData = bufferedBlockAlgorithm._process(!!'flush');
584 */
585 _process: function (doFlush) {
586 // Shortcuts
587 var data = this._data;
588 var dataWords = data.words;
589 var dataSigBytes = data.sigBytes;
590 var blockSize = this.blockSize;
591 var blockSizeBytes = blockSize * 4;
592
593 // Count blocks ready
594 var nBlocksReady = dataSigBytes / blockSizeBytes;
595 if (doFlush) {
596 // Round up to include partial blocks
597 nBlocksReady = Math.ceil(nBlocksReady);
598 } else {
599 // Round down to include only full blocks,
600 // less the number of blocks that must remain in the buffer
601 nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
602 }
603
604 // Count words ready
605 var nWordsReady = nBlocksReady * blockSize;
606
607 // Count bytes ready
608 var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
609
610 // Process blocks
611 if (nWordsReady) {
612 for (var offset = 0; offset < nWordsReady; offset += blockSize) {
613 // Perform concrete-algorithm logic
614 this._doProcessBlock(dataWords, offset);
615 }
616
617 // Remove processed words
618 var processedWords = dataWords.splice(0, nWordsReady);
619 data.sigBytes -= nBytesReady;
620 }
621
622 // Return processed words
623 return new WordArray.init(processedWords, nBytesReady);
624 },
625
626 /**
627 * Creates a copy of this object.
628 *
629 * @return {Object} The clone.
630 *
631 * @example
632 *
633 * var clone = bufferedBlockAlgorithm.clone();
634 */
635 clone: function () {
636 var clone = Base.clone.call(this);
637 clone._data = this._data.clone();
638
639 return clone;
640 },
641
642 _minBufferSize: 0
643 });
644
645 /**
646 * Abstract hasher template.
647 *
648 * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
649 */
650 var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
651 /**
652 * Configuration options.
653 */
654 cfg: Base.extend(),
655
656 /**
657 * Initializes a newly created hasher.
658 *
659 * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
660 *
661 * @example
662 *
663 * var hasher = CryptoJS.algo.SHA256.create();
664 */
665 init: function (cfg) {
666 // Apply config defaults
667 this.cfg = this.cfg.extend(cfg);
668
669 // Set initial values
670 this.reset();
671 },
672
673 /**
674 * Resets this hasher to its initial state.
675 *
676 * @example
677 *
678 * hasher.reset();
679 */
680 reset: function () {
681 // Reset data buffer
682 BufferedBlockAlgorithm.reset.call(this);
683
684 // Perform concrete-hasher logic
685 this._doReset();
686 },
687
688 /**
689 * Updates this hasher with a message.
690 *
691 * @param {WordArray|string} messageUpdate The message to append.
692 *
693 * @return {Hasher} This hasher.
694 *
695 * @example
696 *
697 * hasher.update('message');
698 * hasher.update(wordArray);
699 */
700 update: function (messageUpdate) {
701 // Append
702 this._append(messageUpdate);
703
704 // Update the hash
705 this._process();
706
707 // Chainable
708 return this;
709 },
710
711 /**
712 * Finalizes the hash computation.
713 * Note that the finalize operation is effectively a destructive, read-once operation.
714 *
715 * @param {WordArray|string} messageUpdate (Optional) A final message update.
716 *
717 * @return {WordArray} The hash.
718 *
719 * @example
720 *
721 * var hash = hasher.finalize();
722 * var hash = hasher.finalize('message');
723 * var hash = hasher.finalize(wordArray);
724 */
725 finalize: function (messageUpdate) {
726 // Final message update
727 if (messageUpdate) {
728 this._append(messageUpdate);
729 }
730
731 // Perform concrete-hasher logic
732 var hash = this._doFinalize();
733
734 return hash;
735 },
736
737 blockSize: 512/32,
738
739 /**
740 * Creates a shortcut function to a hasher's object interface.
741 *
742 * @param {Hasher} hasher The hasher to create a helper for.
743 *
744 * @return {Function} The shortcut function.
745 *
746 * @static
747 *
748 * @example
749 *
750 * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
751 */
752 _createHelper: function (hasher) {
753 return function (message, cfg) {
754 return new hasher.init(cfg).finalize(message);
755 };
756 },
757
758 /**
759 * Creates a shortcut function to the HMAC's object interface.
760 *
761 * @param {Hasher} hasher The hasher to use in this HMAC helper.
762 *
763 * @return {Function} The shortcut function.
764 *
765 * @static
766 *
767 * @example
768 *
769 * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
770 */
771 _createHmacHelper: function (hasher) {
772 return function (message, key) {
773 return new C_algo.HMAC.init(hasher, key).finalize(message);
774 };
775 }
776 });
777
778 /**
779 * Algorithm namespace.
780 */
781 var C_algo = C.algo = {};
782
783 return C;
784}(Math));
785
786exports.CryptoJS = CryptoJS;
787
788
789/***/ }),
790/* 1 */
791/***/ (function(module, exports, __webpack_require__) {
792
793"use strict";
794
795
796
797var TYPED_OK = (typeof Uint8Array !== 'undefined') &&
798 (typeof Uint16Array !== 'undefined') &&
799 (typeof Int32Array !== 'undefined');
800
801
802exports.assign = function (obj /*from1, from2, from3, ...*/) {
803 var sources = Array.prototype.slice.call(arguments, 1);
804 while (sources.length) {
805 var source = sources.shift();
806 if (!source) { continue; }
807
808 if (typeof source !== 'object') {
809 throw new TypeError(source + 'must be non-object');
810 }
811
812 for (var p in source) {
813 if (source.hasOwnProperty(p)) {
814 obj[p] = source[p];
815 }
816 }
817 }
818
819 return obj;
820};
821
822
823// reduce buffer size, avoiding mem copy
824exports.shrinkBuf = function (buf, size) {
825 if (buf.length === size) { return buf; }
826 if (buf.subarray) { return buf.subarray(0, size); }
827 buf.length = size;
828 return buf;
829};
830
831
832var fnTyped = {
833 arraySet: function (dest, src, src_offs, len, dest_offs) {
834 if (src.subarray && dest.subarray) {
835 dest.set(src.subarray(src_offs, src_offs + len), dest_offs);
836 return;
837 }
838 // Fallback to ordinary array
839 for (var i = 0; i < len; i++) {
840 dest[dest_offs + i] = src[src_offs + i];
841 }
842 },
843 // Join array of chunks to single array.
844 flattenChunks: function (chunks) {
845 var i, l, len, pos, chunk, result;
846
847 // calculate data length
848 len = 0;
849 for (i = 0, l = chunks.length; i < l; i++) {
850 len += chunks[i].length;
851 }
852
853 // join chunks
854 result = new Uint8Array(len);
855 pos = 0;
856 for (i = 0, l = chunks.length; i < l; i++) {
857 chunk = chunks[i];
858 result.set(chunk, pos);
859 pos += chunk.length;
860 }
861
862 return result;
863 }
864};
865
866var fnUntyped = {
867 arraySet: function (dest, src, src_offs, len, dest_offs) {
868 for (var i = 0; i < len; i++) {
869 dest[dest_offs + i] = src[src_offs + i];
870 }
871 },
872 // Join array of chunks to single array.
873 flattenChunks: function (chunks) {
874 return [].concat.apply([], chunks);
875 }
876};
877
878
879// Enable/Disable typed arrays use, for testing
880//
881exports.setTyped = function (on) {
882 if (on) {
883 exports.Buf8 = Uint8Array;
884 exports.Buf16 = Uint16Array;
885 exports.Buf32 = Int32Array;
886 exports.assign(exports, fnTyped);
887 } else {
888 exports.Buf8 = Array;
889 exports.Buf16 = Array;
890 exports.Buf32 = Array;
891 exports.assign(exports, fnUntyped);
892 }
893};
894
895exports.setTyped(TYPED_OK);
896
897
898/***/ }),
899/* 2 */
900/***/ (function(module, __webpack_exports__, __webpack_require__) {
901
902"use strict";
903/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_jsbn__ = __webpack_require__(12);
904/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_jsbn___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_jsbn__);
905/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_rusha__ = __webpack_require__(24);
906/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_rusha___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_rusha__);
907/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__goodmind_node_cryptojs_aes__ = __webpack_require__(3);
908/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__goodmind_node_cryptojs_aes___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2__goodmind_node_cryptojs_aes__);
909/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_pako_lib_inflate__ = __webpack_require__(13);
910/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_pako_lib_inflate___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_3_pako_lib_inflate__);
911/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__leemon__ = __webpack_require__(11);
912/* unused harmony export bigint */
913/* unused harmony export bigStringInt */
914/* unused harmony export dHexDump */
915/* unused harmony export bytesToHex */
916/* unused harmony export bytesFromHex */
917/* unused harmony export bytesToBase64 */
918/* unused harmony export uint6ToBase64 */
919/* unused harmony export bytesCmp */
920/* unused harmony export bytesXor */
921/* unused harmony export bytesToWords */
922/* unused harmony export bytesFromWords */
923/* unused harmony export bytesFromBigInt */
924/* unused harmony export bytesFromLeemonBigInt */
925/* unused harmony export bytesToArrayBuffer */
926/* unused harmony export convertToArrayBuffer */
927/* unused harmony export convertToUint8Array */
928/* unused harmony export convertToByteArray */
929/* unused harmony export bytesFromArrayBuffer */
930/* unused harmony export bufferConcat */
931/* unused harmony export longToInts */
932/* unused harmony export longToBytes */
933/* unused harmony export longFromInts */
934/* unused harmony export intToUint */
935/* unused harmony export uintToInt */
936/* harmony export (immutable) */ __webpack_exports__["c"] = sha1HashSync;
937/* unused harmony export sha1BytesSync */
938/* unused harmony export sha256HashSync */
939/* unused harmony export rsaEncrypt */
940/* unused harmony export addPadding */
941/* harmony export (immutable) */ __webpack_exports__["d"] = aesEncryptSync;
942/* harmony export (immutable) */ __webpack_exports__["e"] = aesDecryptSync;
943/* unused harmony export gzipUncompress */
944/* unused harmony export nextRandomInt */
945/* harmony export (immutable) */ __webpack_exports__["a"] = pqPrimeFactorization;
946/* unused harmony export pqPrimeJsbn */
947/* unused harmony export pqPrimeLeemon */
948/* harmony export (immutable) */ __webpack_exports__["b"] = bytesModPow;
949
950
951
952const { CryptoJS } = __WEBPACK_IMPORTED_MODULE_2__goodmind_node_cryptojs_aes__;
953
954
955
956// import Int from 'big-integer'
957
958// import BN from 'bn.js'
959
960
961
962// import { bigInt2str } from 'BigInt'
963
964// const { BigInteger } = jsbn
965
966const rushaInstance = new __WEBPACK_IMPORTED_MODULE_1_rusha___default.a(1024 * 1024);
967
968function bigint(num) {
969 return new __WEBPACK_IMPORTED_MODULE_0_jsbn__["BigInteger"](num.toString(16), 16);
970}
971
972function bigStringInt(strNum) {
973 return new __WEBPACK_IMPORTED_MODULE_0_jsbn__["BigInteger"](strNum, 10);
974}
975
976function dHexDump(bytes) {
977 const arr = [];
978 for (let i = 0; i < bytes.length; i++) {
979 if (i && !(i % 2)) {
980 if (!(i % 16)) {
981 arr.push('\n');
982 } else if (!(i % 4)) {
983 arr.push(' ');
984 } else {
985 arr.push(' ');
986 }
987 }
988 arr.push((bytes[i] < 16 ? '0' : '') + bytes[i].toString(16));
989 }
990
991 console.log(arr.join(''));
992}
993
994function bytesToHex(bytes = []) {
995 const arr = [];
996 for (let i = 0; i < bytes.length; i++) {
997 arr.push((bytes[i] < 16 ? '0' : '') + (bytes[i] || 0).toString(16));
998 }
999 return arr.join('');
1000}
1001
1002function bytesFromHex(hexString) {
1003 const len = hexString.length;
1004 let start = 0;
1005 const bytes = [];
1006
1007 if (hexString.length % 2) {
1008 bytes.push(parseInt(hexString.charAt(0), 16));
1009 start++;
1010 }
1011
1012 for (let i = start; i < len; i += 2) {
1013 bytes.push(parseInt(hexString.substr(i, 2), 16));
1014 }
1015
1016 return bytes;
1017}
1018
1019function bytesToBase64(bytes) {
1020 let mod3;
1021 let result = '';
1022
1023 for (let nLen = bytes.length, nUint24 = 0, nIdx = 0; nIdx < nLen; nIdx++) {
1024 mod3 = nIdx % 3;
1025 nUint24 |= bytes[nIdx] << (16 >>> mod3 & 24);
1026 if (mod3 === 2 || nLen - nIdx === 1) {
1027 result += String.fromCharCode(uint6ToBase64(nUint24 >>> 18 & 63), uint6ToBase64(nUint24 >>> 12 & 63), uint6ToBase64(nUint24 >>> 6 & 63), uint6ToBase64(nUint24 & 63));
1028 nUint24 = 0;
1029 }
1030 }
1031
1032 return result.replace(/A(?=A$|$)/g, '=');
1033}
1034
1035function uint6ToBase64(nUint6) {
1036 return nUint6 < 26 ? nUint6 + 65 : nUint6 < 52 ? nUint6 + 71 : nUint6 < 62 ? nUint6 - 4 : nUint6 === 62 ? 43 : nUint6 === 63 ? 47 : 65;
1037}
1038
1039// export function base64ToBlob(base64str, mimeType) {
1040// const sliceSize = 1024
1041// const byteCharacters = atob(base64str)
1042// const bytesLength = byteCharacters.length
1043// const slicesCount = Math.ceil(bytesLength / sliceSize)
1044// const byteArrays = new Array(slicesCount)
1045
1046// for (let sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
1047// const begin = sliceIndex * sliceSize
1048// const end = Math.min(begin + sliceSize, bytesLength)
1049
1050// const bytes = new Array(end - begin)
1051// for (let offset = begin, i = 0; offset < end; ++i, ++offset) {
1052// bytes[i] = byteCharacters[offset].charCodeAt(0)
1053// }
1054// byteArrays[sliceIndex] = new Uint8Array(bytes)
1055// }
1056
1057// return blobConstruct(byteArrays, mimeType)
1058// }
1059
1060// export function dataUrlToBlob(url) {
1061// // var name = 'b64blob ' + url.length
1062// // console.time(name)
1063// const urlParts = url.split(',')
1064// const base64str = urlParts[1]
1065// const mimeType = urlParts[0].split(':')[1].split(';')[0]
1066// const blob = base64ToBlob(base64str, mimeType)
1067// // console.timeEnd(name)
1068// return blob
1069// }
1070
1071// export function blobConstruct(blobParts, mimeType) {
1072// let blob
1073// try {
1074// blob = new Blob(blobParts, { type: mimeType })
1075// } catch (e) {
1076// const bb = new BlobBuilder
1077// angular.forEach(blobParts, function(blobPart) {
1078// bb.append(blobPart)
1079// })
1080// blob = bb.getBlob(mimeType)
1081// }
1082// return blob
1083// }
1084
1085function bytesCmp(bytes1, bytes2) {
1086 const len = bytes1.length;
1087 if (len !== bytes2.length) {
1088 return false;
1089 }
1090
1091 for (let i = 0; i < len; i++) {
1092 if (bytes1[i] !== bytes2[i]) return false;
1093 }
1094 return true;
1095}
1096
1097function bytesXor(bytes1, bytes2) {
1098 const len = bytes1.length;
1099 const bytes = [];
1100
1101 for (let i = 0; i < len; ++i) {
1102 bytes[i] = bytes1[i] ^ bytes2[i];
1103 }
1104
1105 return bytes;
1106}
1107
1108function bytesToWords(bytes) {
1109 if (bytes instanceof ArrayBuffer) {
1110 bytes = new Uint8Array(bytes);
1111 }
1112 const len = bytes.length;
1113 const words = [];
1114 let i;
1115 for (i = 0; i < len; i++) {
1116 words[i >>> 2] |= bytes[i] << 24 - i % 4 * 8;
1117 }
1118
1119 return new CryptoJS.lib.WordArray.init(words, len);
1120}
1121
1122function bytesFromWords(wordArray) {
1123 const words = wordArray.words;
1124 const sigBytes = wordArray.sigBytes;
1125 const bytes = [];
1126
1127 for (let i = 0; i < sigBytes; i++) {
1128 bytes.push(words[i >>> 2] >>> 24 - i % 4 * 8 & 0xff);
1129 }
1130
1131 return bytes;
1132}
1133
1134function bytesFromBigInt(bigInt, len) {
1135 let bytes = bigInt.toByteArray();
1136
1137 if (len && bytes.length < len) {
1138 const padding = [];
1139 for (let i = 0, needPadding = len - bytes.length; i < needPadding; i++) {
1140 padding[i] = 0;
1141 }
1142 if (bytes instanceof ArrayBuffer) {
1143 bytes = bufferConcat(padding, bytes);
1144 } else {
1145 bytes = padding.concat(bytes);
1146 }
1147 } else {
1148 while (!bytes[0] && (!len || bytes.length > len)) {
1149 bytes = bytes.slice(1);
1150 }
1151 }
1152
1153 return bytes;
1154}
1155
1156function bytesFromLeemonBigInt(bigInt, len) {
1157 const str = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["a" /* bigInt2str */])(bigInt, 16);
1158 return bytesFromHex(str);
1159}
1160
1161function bytesToArrayBuffer(b) {
1162 return new Uint8Array(b).buffer;
1163}
1164
1165function convertToArrayBuffer(bytes) {
1166 // Be careful with converting subarrays!!
1167 if (bytes instanceof ArrayBuffer) {
1168 return bytes;
1169 }
1170 if (bytes.buffer !== undefined && bytes.buffer.byteLength == bytes.length * bytes.BYTES_PER_ELEMENT) {
1171 return bytes.buffer;
1172 }
1173 return bytesToArrayBuffer(bytes);
1174}
1175
1176function convertToUint8Array(bytes) {
1177 if (bytes.buffer !== undefined) {
1178 return bytes;
1179 }
1180 return new Uint8Array(bytes);
1181}
1182
1183function convertToByteArray(bytes) {
1184 if (Array.isArray(bytes)) {
1185 return bytes;
1186 }
1187 bytes = convertToUint8Array(bytes);
1188 const newBytes = [];
1189 for (let i = 0, len = bytes.length; i < len; i++) {
1190 newBytes.push(bytes[i]);
1191 }
1192 return newBytes;
1193}
1194
1195function bytesFromArrayBuffer(buffer) {
1196 const byteView = new Uint8Array(buffer);
1197 const bytes = Array.from(byteView);
1198 return bytes;
1199}
1200
1201function bufferConcat(buffer1, buffer2) {
1202 const l1 = buffer1.byteLength || buffer1.length;
1203 const l2 = buffer2.byteLength || buffer2.length;
1204 const tmp = new Uint8Array(l1 + l2);
1205 tmp.set(buffer1 instanceof ArrayBuffer ? new Uint8Array(buffer1) : buffer1, 0);
1206 tmp.set(buffer2 instanceof ArrayBuffer ? new Uint8Array(buffer2) : buffer2, l1);
1207
1208 return tmp.buffer;
1209}
1210
1211function longToInts(sLong) {
1212 const divRem = bigStringInt(sLong).divideAndRemainder(bigint(0x100000000));
1213
1214 return [divRem[0].intValue(), divRem[1].intValue()];
1215}
1216
1217function longToBytes(sLong) {
1218 return bytesFromWords({ words: longToInts(sLong), sigBytes: 8 }).reverse();
1219}
1220
1221function longFromInts(high, low) {
1222 return bigint(high).shiftLeft(32).add(bigint(low)).toString(10);
1223}
1224
1225function intToUint(val) {
1226 val = parseInt(val);
1227 if (val < 0) {
1228 val = val + 4294967296;
1229 }
1230 return val;
1231}
1232
1233function uintToInt(val) {
1234 if (val > 2147483647) {
1235 val = val - 4294967296;
1236 }
1237 return val;
1238}
1239
1240function sha1HashSync(bytes) {
1241 // console.log(dT(), 'SHA-1 hash start', bytes.byteLength || bytes.length)
1242 const hashBytes = rushaInstance.rawDigest(bytes).buffer;
1243 // console.log(dT(), 'SHA-1 hash finish')
1244
1245 return hashBytes;
1246}
1247
1248function sha1BytesSync(bytes) {
1249 return bytesFromArrayBuffer(sha1HashSync(bytes));
1250}
1251
1252function sha256HashSync(bytes) {
1253 // console.log(dT(), 'SHA-2 hash start', bytes.byteLength || bytes.length)
1254 const hashWords = CryptoJS.SHA256(bytesToWords(bytes));
1255 // console.log(dT(), 'SHA-2 hash finish')
1256
1257 const hashBytes = bytesFromWords(hashWords);
1258
1259 return hashBytes;
1260}
1261
1262function rsaEncrypt(publicKey, bytes) {
1263 bytes = addPadding(bytes, 255);
1264
1265 // console.log('RSA encrypt start')
1266 const N = new __WEBPACK_IMPORTED_MODULE_0_jsbn__["BigInteger"](publicKey.modulus, 16);
1267 const E = new __WEBPACK_IMPORTED_MODULE_0_jsbn__["BigInteger"](publicKey.exponent, 16);
1268 const X = new __WEBPACK_IMPORTED_MODULE_0_jsbn__["BigInteger"](bytes);
1269 const encryptedBigInt = X.modPowInt(E, N),
1270 encryptedBytes = bytesFromBigInt(encryptedBigInt, 256);
1271 // console.log('RSA encrypt finish')
1272
1273 return encryptedBytes;
1274}
1275
1276function addPadding(bytes, blockSize, zeroes) {
1277 blockSize = blockSize || 16;
1278 const len = bytes.byteLength || bytes.length;
1279 const needPadding = blockSize - len % blockSize;
1280 if (needPadding > 0 && needPadding < blockSize) {
1281 const padding = new Array(needPadding);
1282 if (zeroes) {
1283 for (let i = 0; i < needPadding; i++) {
1284 padding[i] = 0;
1285 }
1286 } else {
1287 new __WEBPACK_IMPORTED_MODULE_0_jsbn__["SecureRandom"]().nextBytes(padding);
1288 }
1289
1290 if (bytes instanceof ArrayBuffer) {
1291 bytes = bufferConcat(bytes, padding);
1292 } else {
1293 bytes = bytes.concat(padding);
1294 }
1295 }
1296
1297 return bytes;
1298}
1299
1300function aesEncryptSync(bytes, keyBytes, ivBytes) {
1301 const len = bytes.byteLength || bytes.length;
1302
1303 // console.log(dT(), 'AES encrypt start', len/*, bytesToHex(keyBytes), bytesToHex(ivBytes)*/)
1304 bytes = addPadding(bytes);
1305
1306 const encryptedWords = CryptoJS.AES.encrypt(bytesToWords(bytes), bytesToWords(keyBytes), {
1307 iv: bytesToWords(ivBytes),
1308 padding: CryptoJS.pad.NoPadding,
1309 mode: CryptoJS.mode.IGE
1310 }).ciphertext;
1311
1312 const encryptedBytes = bytesFromWords(encryptedWords);
1313 // console.log(dT(), 'AES encrypt finish')
1314
1315 return encryptedBytes;
1316}
1317
1318function aesDecryptSync(encryptedBytes, keyBytes, ivBytes) {
1319
1320 // console.log(dT(), 'AES decrypt start', encryptedBytes.length)
1321 const decryptedWords = CryptoJS.AES.decrypt({ ciphertext: bytesToWords(encryptedBytes) }, bytesToWords(keyBytes), {
1322 iv: bytesToWords(ivBytes),
1323 padding: CryptoJS.pad.NoPadding,
1324 mode: CryptoJS.mode.IGE
1325 });
1326
1327 const bytes = bytesFromWords(decryptedWords);
1328 // console.log(dT(), 'AES decrypt finish')
1329
1330 return bytes;
1331}
1332
1333function gzipUncompress(bytes) {
1334 // console.log('Gzip uncompress start')
1335 const result = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_pako_lib_inflate__["inflate"])(bytes);
1336 // console.log('Gzip uncompress finish')
1337 return result;
1338}
1339
1340function nextRandomInt(maxValue) {
1341 return Math.floor(Math.random() * maxValue);
1342}
1343
1344// const bytesToInt = bytes => Int(bytesToHex(bytes), 16)
1345// const bytesFromInt = int => bytesFromHex(int.toString(16))
1346
1347function pqPrimeFactorization(pqBytes) {
1348 const what = new __WEBPACK_IMPORTED_MODULE_0_jsbn__["BigInteger"](pqBytes);
1349 // const whatInt = bytesToInt(pqBytes)
1350 // const whatBn = new BN(bytesToHex(pqBytes), 16)
1351 let result = false;
1352 // let intRes = []
1353 // const bnRes = []
1354 // console.log(dT(), 'PQ start', pqBytes, what.toString(16), what.bitLength())
1355
1356 // try {
1357 // console.time('pq leemon')
1358 // const toHex = bytesToHex(pqBytes)
1359 result = pqPrimeLeemon(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["b" /* str2bigInt */])(what.toString(16), 16, Math.ceil(64 / __WEBPACK_IMPORTED_MODULE_4__leemon__["c" /* bpe */]) + 1));
1360 // console.timeEnd('pq leemon')
1361 // } catch (e) {
1362 // console.error('Pq leemon Exception', e)
1363 // }
1364
1365 /*if (result === false && what.bitLength() <= 64) {
1366 // console.time('PQ long')
1367 try {
1368 result = pqPrimeLong(goog.math.Long.fromString(what.toString(16), 16))
1369 } catch (e) {
1370 console.error('Pq long Exception', e)
1371 }
1372 // console.timeEnd('PQ long')
1373 }*/
1374 // console.log(result)
1375
1376 // if (result === false) {
1377 // console.time('pq BigInt')
1378 // intRes = pqPrimeJsbn(what)
1379 // console.timeEnd('pq BigInt')
1380
1381 // console.time('pq bn')
1382 // bnRes = pqPrimeBN(whatBn)
1383 // console.timeEnd('pq bn')
1384 // }
1385 // console.log(...result, ...bnRes)
1386 // console.log(dT(), 'PQ finish')
1387
1388 return result;
1389 //intRes//result//bnRes
1390}
1391
1392/*export function pqPrimeBN(what) {
1393 let it = 0,
1394 g
1395 const nOne = new BN(1)
1396 for (let i = 0; i < 3; i++) {
1397 const q = (nextRandomInt(128) & 15) + 17
1398 let x = new BN(nextRandomInt(1000000000) + 1)
1399 let y = x.clone()
1400 const lim = 1 << (i + 18)
1401
1402 for (let j = 1; j < lim; j++) {
1403 ++it
1404 let a = x.clone()
1405 let b = x.clone()
1406 let c = new BN(q)
1407
1408 while (!b.isZero()) {
1409 if (!b.and(nOne).isZero()) {
1410 c = c.add(a)
1411 if (c.gt(what)) {
1412 c = c.sub(what)
1413 }
1414 }
1415 a = a.add(a)
1416 if (a.gt(what)) {
1417 a = a.sub(what)
1418 }
1419 b = b.shrn(1)
1420 }
1421
1422 x = c.clone()
1423 const z = x.lt(y)
1424 ? y.sub(x)
1425 : x.sub(y)
1426 g = z.gcd(what)
1427 if (!g.eq(nOne)) {
1428 break
1429 }
1430 if ((j & (j - 1)) == 0) {
1431 y = x.clone()
1432 }
1433 }
1434 if (g.gt(nOne)) {
1435 break
1436 }
1437 }
1438
1439 let f = what.div(g), P, Q
1440
1441 if (g.gt(f)) {
1442 P = f
1443 Q = g
1444 } else {
1445 P = g
1446 Q = f
1447 }
1448
1449 return [P.toArray(), Q.toArray(), it]
1450}*/
1451
1452function pqPrimeJsbn(what) {
1453 let it = 0,
1454 g;
1455 for (let i = 0; i < 3; i++) {
1456 const q = (nextRandomInt(128) & 15) + 17;
1457 let x = bigint(nextRandomInt(1000000000) + 1);
1458 let y = x.clone();
1459 const lim = 1 << i + 18;
1460
1461 for (let j = 1; j < lim; j++) {
1462 ++it;
1463 let a = x.clone();
1464 let b = x.clone();
1465 let c = bigint(q);
1466
1467 while (!b.equals(__WEBPACK_IMPORTED_MODULE_0_jsbn__["BigInteger"].ZERO)) {
1468 if (!b.and(__WEBPACK_IMPORTED_MODULE_0_jsbn__["BigInteger"].ONE).equals(__WEBPACK_IMPORTED_MODULE_0_jsbn__["BigInteger"].ZERO)) {
1469 c = c.add(a);
1470 if (c.compareTo(what) > 0) {
1471 c = c.subtract(what);
1472 }
1473 }
1474 a = a.add(a);
1475 if (a.compareTo(what) > 0) {
1476 a = a.subtract(what);
1477 }
1478 b = b.shiftRight(1);
1479 }
1480
1481 x = c.clone();
1482 const z = x.compareTo(y) < 0 ? y.subtract(x) : x.subtract(y);
1483 g = z.gcd(what);
1484 if (!g.equals(__WEBPACK_IMPORTED_MODULE_0_jsbn__["BigInteger"].ONE)) {
1485 break;
1486 }
1487 if ((j & j - 1) == 0) {
1488 y = x.clone();
1489 }
1490 }
1491 if (g.compareTo(__WEBPACK_IMPORTED_MODULE_0_jsbn__["BigInteger"].ONE) > 0) {
1492 break;
1493 }
1494 }
1495
1496 let f = what.divide(g),
1497 P,
1498 Q;
1499
1500 if (g.compareTo(f) > 0) {
1501 P = f;
1502 Q = g;
1503 } else {
1504 P = g;
1505 Q = f;
1506 }
1507
1508 return [bytesFromBigInt(P), bytesFromBigInt(Q), it];
1509}
1510
1511/*export function pqPrimeBigInteger(what) {
1512 let it = 0,
1513 g
1514 for (let i = 0; i < 3; i++) {
1515 const q = (nextRandomInt(128) & 15) + 17
1516 let x = Int(nextRandomInt(1000000000) + 1)
1517 let y = Int(x)
1518 const lim = 1 << (i + 18)
1519
1520 for (let j = 1; j < lim; j++) {
1521 ++it
1522 let a = Int(x)
1523 let b = Int(x)
1524 let c = Int(q)
1525
1526 while (!b.isZero()) {
1527 if (!b.and(Int.one).isZero()) {
1528 c = c.add(a)
1529 if (c.greater(what))
1530 c = c.subtract(what)
1531 }
1532 a = a.add(a)
1533 if (a.greater(what))
1534 a = a.subtract(what)
1535 b = b.shiftRight(1)
1536 }
1537
1538 x = Int(c)
1539 const z = x.lesser(y)
1540 ? y.subtract(x)
1541 : x.subtract(y)
1542 g = Int.gcd(z, what)
1543 if (g.notEquals(Int.one))
1544 break
1545 if ((j & (j - 1)) == 0)
1546 y = Int(x)
1547 }
1548 if (g.greater(Int.one))
1549 break
1550 }
1551
1552 const f = what.divide(g)
1553 let P, Q
1554
1555 if (g.greater(f)) {
1556 P = f
1557 Q = g
1558 } else {
1559 P = g
1560 Q = f
1561 }
1562
1563 return [bytesFromInt(P), bytesFromInt(Q), it]
1564}*/
1565
1566/*export function gcdLong(a, b) {
1567 while (a.notEquals(goog.math.Long.ZERO) && b.notEquals(goog.math.Long.ZERO)) {
1568 while (b.and(goog.math.Long.ONE).equals(goog.math.Long.ZERO)) {
1569 b = b.shiftRight(1)
1570 }
1571 while (a.and(goog.math.Long.ONE).equals(goog.math.Long.ZERO)) {
1572 a = a.shiftRight(1)
1573 }
1574 if (a.compare(b) > 0) {
1575 a = a.subtract(b)
1576 } else {
1577 b = b.subtract(a)
1578 }
1579 }
1580 return b.equals(goog.math.Long.ZERO) ? a : b
1581}
1582
1583export function pqPrimeLong(what) {
1584 let it = 0,
1585 g
1586 for (let i = 0; i < 3; i++) {
1587 const q = goog.math.Long.fromInt((nextRandomInt(128) & 15) + 17)
1588 let x = goog.math.Long.fromInt(nextRandomInt(1000000000) + 1)
1589 let y = x
1590 const lim = 1 << (i + 18)
1591
1592 for (let j = 1; j < lim; j++) {
1593 ++it
1594 let a = x
1595 let b = x
1596 let c = q
1597
1598 while (b.notEquals(goog.math.Long.ZERO)) {
1599 if (b.and(goog.math.Long.ONE).notEquals(goog.math.Long.ZERO)) {
1600 c = c.add(a)
1601 if (c.compare(what) > 0) {
1602 c = c.subtract(what)
1603 }
1604 }
1605 a = a.add(a)
1606 if (a.compare(what) > 0) {
1607 a = a.subtract(what)
1608 }
1609 b = b.shiftRight(1)
1610 }
1611
1612 x = c
1613 const z = x.compare(y) < 0 ? y.subtract(x) : x.subtract(y)
1614 g = gcdLong(z, what)
1615 if (g.notEquals(goog.math.Long.ONE)) {
1616 break
1617 }
1618 if ((j & (j - 1)) == 0) {
1619 y = x
1620 }
1621 }
1622 if (g.compare(goog.math.Long.ONE) > 0) {
1623 break
1624 }
1625 }
1626
1627 let f = what.div(g), P, Q
1628
1629 if (g.compare(f) > 0) {
1630 P = f
1631 Q = g
1632 } else {
1633 P = g
1634 Q = f
1635 }
1636
1637 return [bytesFromHex(P.toString(16)), bytesFromHex(Q.toString(16)), it]
1638}*/
1639
1640/*//is bigint x equal to integer y?
1641//y must have less than bpe bits
1642function equalsInt(x,y) {
1643 var i;
1644 if (x[0]!=y)
1645 return 0;
1646 for (i=1;i<x.length;i++)
1647 if (x[i])
1648 return 0;
1649 return 1;
1650}*/
1651
1652function pqPrimeLeemon(what) {
1653 const minBits = 64;
1654 const minLen = Math.ceil(minBits / __WEBPACK_IMPORTED_MODULE_4__leemon__["c" /* bpe */]) + 1;
1655 let it = 0;
1656 let q, lim;
1657 const a = new Array(minLen);
1658 const b = new Array(minLen);
1659 const c = new Array(minLen);
1660 const g = new Array(minLen);
1661 const z = new Array(minLen);
1662 const x = new Array(minLen);
1663 const y = new Array(minLen);
1664
1665 for (let i = 0; i < 3; i++) {
1666 q = (nextRandomInt(128) & 15) + 17;
1667 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["d" /* copyInt_ */])(x, nextRandomInt(1000000000) + 1);
1668 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["e" /* copy_ */])(y, x);
1669 lim = 1 << i + 18;
1670
1671 for (let j = 1; j < lim; j++) {
1672 ++it;
1673 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["e" /* copy_ */])(a, x);
1674 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["e" /* copy_ */])(b, x);
1675 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["d" /* copyInt_ */])(c, q);
1676
1677 while (!__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["f" /* isZero */])(b)) {
1678 if (b[0] & 1) {
1679 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["g" /* add_ */])(c, a);
1680 if (__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["h" /* greater */])(c, what)) {
1681 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["i" /* sub_ */])(c, what);
1682 }
1683 }
1684 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["g" /* add_ */])(a, a);
1685 if (__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["h" /* greater */])(a, what)) {
1686 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["i" /* sub_ */])(a, what);
1687 }
1688 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["j" /* rightShift_ */])(b, 1);
1689 }
1690
1691 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["e" /* copy_ */])(x, c);
1692 if (__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["h" /* greater */])(x, y)) {
1693 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["e" /* copy_ */])(z, x);
1694 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["i" /* sub_ */])(z, y);
1695 } else {
1696 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["e" /* copy_ */])(z, y);
1697 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["i" /* sub_ */])(z, x);
1698 }
1699 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["k" /* eGCD_ */])(z, what, g, a, b);
1700 if (!__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["l" /* equalsInt */])(g, 1)) {
1701 break;
1702 }
1703 if ((j & j - 1) === 0) {
1704 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["e" /* copy_ */])(y, x);
1705 }
1706 }
1707 if (__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["h" /* greater */])(g, __WEBPACK_IMPORTED_MODULE_4__leemon__["m" /* one */])) {
1708 break;
1709 }
1710 }
1711
1712 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["n" /* divide_ */])(what, g, x, y);
1713
1714 const [P, Q] = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["h" /* greater */])(g, x) ? [x, g] : [g, x];
1715
1716 // console.log(dT(), 'done', bigInt2str(what, 10), bigInt2str(P, 10), bigInt2str(Q, 10))
1717
1718 return [bytesFromLeemonBigInt(P), bytesFromLeemonBigInt(Q), it];
1719}
1720
1721function bytesModPow(x, y, m) {
1722 try {
1723 const xBigInt = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["b" /* str2bigInt */])(bytesToHex(x), 16);
1724 const yBigInt = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["b" /* str2bigInt */])(bytesToHex(y), 16);
1725 const mBigInt = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["b" /* str2bigInt */])(bytesToHex(m), 16);
1726 const resBigInt = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["o" /* powMod */])(xBigInt, yBigInt, mBigInt);
1727
1728 return bytesFromHex(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_4__leemon__["a" /* bigInt2str */])(resBigInt, 16));
1729 } catch (e) {
1730 console.error('mod pow error', e);
1731 }
1732
1733 return bytesFromBigInt(new __WEBPACK_IMPORTED_MODULE_0_jsbn__["BigInteger"](x).modPow(new __WEBPACK_IMPORTED_MODULE_0_jsbn__["BigInteger"](y), new __WEBPACK_IMPORTED_MODULE_0_jsbn__["BigInteger"](m)), 256);
1734}
1735
1736/***/ }),
1737/* 3 */
1738/***/ (function(module, exports, __webpack_require__) {
1739
1740var CryptoJS = __webpack_require__(0).CryptoJS;
1741__webpack_require__(6);
1742__webpack_require__(9);
1743__webpack_require__(7);
1744__webpack_require__(5);
1745__webpack_require__(4);
1746__webpack_require__(10);
1747var JsonFormatter = __webpack_require__(8).JsonFormatter;
1748
1749exports.CryptoJS = CryptoJS;
1750exports.JsonFormatter = JsonFormatter;
1751
1752/***/ }),
1753/* 4 */
1754/***/ (function(module, exports, __webpack_require__) {
1755
1756var CryptoJS = __webpack_require__(0).CryptoJS;
1757
1758/*
1759CryptoJS v3.1.2
1760code.google.com/p/crypto-js
1761(c) 2009-2013 by Jeff Mott. All rights reserved.
1762code.google.com/p/crypto-js/wiki/License
1763*/
1764(function () {
1765 // Shortcuts
1766 var C = CryptoJS;
1767 var C_lib = C.lib;
1768 var BlockCipher = C_lib.BlockCipher;
1769 var C_algo = C.algo;
1770
1771 // Lookup tables
1772 var SBOX = [];
1773 var INV_SBOX = [];
1774 var SUB_MIX_0 = [];
1775 var SUB_MIX_1 = [];
1776 var SUB_MIX_2 = [];
1777 var SUB_MIX_3 = [];
1778 var INV_SUB_MIX_0 = [];
1779 var INV_SUB_MIX_1 = [];
1780 var INV_SUB_MIX_2 = [];
1781 var INV_SUB_MIX_3 = [];
1782
1783 // Compute lookup tables
1784 (function () {
1785 // Compute double table
1786 var d = [];
1787 for (var i = 0; i < 256; i++) {
1788 if (i < 128) {
1789 d[i] = i << 1;
1790 } else {
1791 d[i] = (i << 1) ^ 0x11b;
1792 }
1793 }
1794
1795 // Walk GF(2^8)
1796 var x = 0;
1797 var xi = 0;
1798 for (var i = 0; i < 256; i++) {
1799 // Compute sbox
1800 var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
1801 sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
1802 SBOX[x] = sx;
1803 INV_SBOX[sx] = x;
1804
1805 // Compute multiplication
1806 var x2 = d[x];
1807 var x4 = d[x2];
1808 var x8 = d[x4];
1809
1810 // Compute sub bytes, mix columns tables
1811 var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
1812 SUB_MIX_0[x] = (t << 24) | (t >>> 8);
1813 SUB_MIX_1[x] = (t << 16) | (t >>> 16);
1814 SUB_MIX_2[x] = (t << 8) | (t >>> 24);
1815 SUB_MIX_3[x] = t;
1816
1817 // Compute inv sub bytes, inv mix columns tables
1818 var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
1819 INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
1820 INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
1821 INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
1822 INV_SUB_MIX_3[sx] = t;
1823
1824 // Compute next counter
1825 if (!x) {
1826 x = xi = 1;
1827 } else {
1828 x = x2 ^ d[d[d[x8 ^ x2]]];
1829 xi ^= d[d[xi]];
1830 }
1831 }
1832 }());
1833
1834 // Precomputed Rcon lookup
1835 var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
1836
1837 /**
1838 * AES block cipher algorithm.
1839 */
1840 var AES = C_algo.AES = BlockCipher.extend({
1841 _doReset: function () {
1842 // Shortcuts
1843 var key = this._key;
1844 var keyWords = key.words;
1845 var keySize = key.sigBytes / 4;
1846
1847 // Compute number of rounds
1848 var nRounds = this._nRounds = keySize + 6
1849
1850 // Compute number of key schedule rows
1851 var ksRows = (nRounds + 1) * 4;
1852
1853 // Compute key schedule
1854 var keySchedule = this._keySchedule = [];
1855 for (var ksRow = 0; ksRow < ksRows; ksRow++) {
1856 if (ksRow < keySize) {
1857 keySchedule[ksRow] = keyWords[ksRow];
1858 } else {
1859 var t = keySchedule[ksRow - 1];
1860
1861 if (!(ksRow % keySize)) {
1862 // Rot word
1863 t = (t << 8) | (t >>> 24);
1864
1865 // Sub word
1866 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
1867
1868 // Mix Rcon
1869 t ^= RCON[(ksRow / keySize) | 0] << 24;
1870 } else if (keySize > 6 && ksRow % keySize == 4) {
1871 // Sub word
1872 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
1873 }
1874
1875 keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
1876 }
1877 }
1878
1879 // Compute inv key schedule
1880 var invKeySchedule = this._invKeySchedule = [];
1881 for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
1882 var ksRow = ksRows - invKsRow;
1883
1884 if (invKsRow % 4) {
1885 var t = keySchedule[ksRow];
1886 } else {
1887 var t = keySchedule[ksRow - 4];
1888 }
1889
1890 if (invKsRow < 4 || ksRow <= 4) {
1891 invKeySchedule[invKsRow] = t;
1892 } else {
1893 invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
1894 INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
1895 }
1896 }
1897 },
1898
1899 encryptBlock: function (M, offset) {
1900 this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
1901 },
1902
1903 decryptBlock: function (M, offset) {
1904 // Swap 2nd and 4th rows
1905 var t = M[offset + 1];
1906 M[offset + 1] = M[offset + 3];
1907 M[offset + 3] = t;
1908
1909 this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
1910
1911 // Inv swap 2nd and 4th rows
1912 var t = M[offset + 1];
1913 M[offset + 1] = M[offset + 3];
1914 M[offset + 3] = t;
1915 },
1916
1917 _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
1918 // Shortcut
1919 var nRounds = this._nRounds;
1920
1921 // Get input, add round key
1922 var s0 = M[offset] ^ keySchedule[0];
1923 var s1 = M[offset + 1] ^ keySchedule[1];
1924 var s2 = M[offset + 2] ^ keySchedule[2];
1925 var s3 = M[offset + 3] ^ keySchedule[3];
1926
1927 // Key schedule row counter
1928 var ksRow = 4;
1929
1930 // Rounds
1931 for (var round = 1; round < nRounds; round++) {
1932 // Shift rows, sub bytes, mix columns, add round key
1933 var t0 = SUB_MIX_0[s0 >>> 24] ^ SUB_MIX_1[(s1 >>> 16) & 0xff] ^ SUB_MIX_2[(s2 >>> 8) & 0xff] ^ SUB_MIX_3[s3 & 0xff] ^ keySchedule[ksRow++];
1934 var t1 = SUB_MIX_0[s1 >>> 24] ^ SUB_MIX_1[(s2 >>> 16) & 0xff] ^ SUB_MIX_2[(s3 >>> 8) & 0xff] ^ SUB_MIX_3[s0 & 0xff] ^ keySchedule[ksRow++];
1935 var t2 = SUB_MIX_0[s2 >>> 24] ^ SUB_MIX_1[(s3 >>> 16) & 0xff] ^ SUB_MIX_2[(s0 >>> 8) & 0xff] ^ SUB_MIX_3[s1 & 0xff] ^ keySchedule[ksRow++];
1936 var t3 = SUB_MIX_0[s3 >>> 24] ^ SUB_MIX_1[(s0 >>> 16) & 0xff] ^ SUB_MIX_2[(s1 >>> 8) & 0xff] ^ SUB_MIX_3[s2 & 0xff] ^ keySchedule[ksRow++];
1937
1938 // Update state
1939 s0 = t0;
1940 s1 = t1;
1941 s2 = t2;
1942 s3 = t3;
1943 }
1944
1945 // Shift rows, sub bytes, add round key
1946 var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
1947 var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
1948 var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
1949 var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
1950
1951 // Set output
1952 M[offset] = t0;
1953 M[offset + 1] = t1;
1954 M[offset + 2] = t2;
1955 M[offset + 3] = t3;
1956 },
1957
1958 keySize: 256/32
1959 });
1960
1961 /**
1962 * Shortcut functions to the cipher's object interface.
1963 *
1964 * @example
1965 *
1966 * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
1967 * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
1968 */
1969 C.AES = BlockCipher._createHelper(AES);
1970}());
1971
1972
1973/***/ }),
1974/* 5 */
1975/***/ (function(module, exports, __webpack_require__) {
1976
1977var CryptoJS = __webpack_require__(0).CryptoJS;
1978
1979/*
1980CryptoJS v3.1.2
1981code.google.com/p/crypto-js
1982(c) 2009-2013 by Jeff Mott. All rights reserved.
1983code.google.com/p/crypto-js/wiki/License
1984*/
1985/**
1986 * Cipher core components.
1987 */
1988CryptoJS.lib.Cipher || (function (undefined) {
1989 // Shortcuts
1990 var C = CryptoJS;
1991 var C_lib = C.lib;
1992 var Base = C_lib.Base;
1993 var WordArray = C_lib.WordArray;
1994 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
1995 var C_enc = C.enc;
1996 var Utf8 = C_enc.Utf8;
1997 var Base64 = C_enc.Base64;
1998 var C_algo = C.algo;
1999 var EvpKDF = C_algo.EvpKDF;
2000
2001 /**
2002 * Abstract base cipher template.
2003 *
2004 * @property {number} keySize This cipher's key size. Default: 4 (128 bits)
2005 * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits)
2006 * @property {number} _ENC_XFORM_MODE A constant representing encryption mode.
2007 * @property {number} _DEC_XFORM_MODE A constant representing decryption mode.
2008 */
2009 var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({
2010 /**
2011 * Configuration options.
2012 *
2013 * @property {WordArray} iv The IV to use for this operation.
2014 */
2015 cfg: Base.extend(),
2016
2017 /**
2018 * Creates this cipher in encryption mode.
2019 *
2020 * @param {WordArray} key The key.
2021 * @param {Object} cfg (Optional) The configuration options to use for this operation.
2022 *
2023 * @return {Cipher} A cipher instance.
2024 *
2025 * @static
2026 *
2027 * @example
2028 *
2029 * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
2030 */
2031 createEncryptor: function (key, cfg) {
2032 return this.create(this._ENC_XFORM_MODE, key, cfg);
2033 },
2034
2035 /**
2036 * Creates this cipher in decryption mode.
2037 *
2038 * @param {WordArray} key The key.
2039 * @param {Object} cfg (Optional) The configuration options to use for this operation.
2040 *
2041 * @return {Cipher} A cipher instance.
2042 *
2043 * @static
2044 *
2045 * @example
2046 *
2047 * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
2048 */
2049 createDecryptor: function (key, cfg) {
2050 return this.create(this._DEC_XFORM_MODE, key, cfg);
2051 },
2052
2053 /**
2054 * Initializes a newly created cipher.
2055 *
2056 * @param {number} xformMode Either the encryption or decryption transormation mode constant.
2057 * @param {WordArray} key The key.
2058 * @param {Object} cfg (Optional) The configuration options to use for this operation.
2059 *
2060 * @example
2061 *
2062 * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
2063 */
2064 init: function (xformMode, key, cfg) {
2065 // Apply config defaults
2066 this.cfg = this.cfg.extend(cfg);
2067
2068 // Store transform mode and key
2069 this._xformMode = xformMode;
2070 this._key = key;
2071
2072 // Set initial values
2073 this.reset();
2074 },
2075
2076 /**
2077 * Resets this cipher to its initial state.
2078 *
2079 * @example
2080 *
2081 * cipher.reset();
2082 */
2083 reset: function () {
2084 // Reset data buffer
2085 BufferedBlockAlgorithm.reset.call(this);
2086
2087 // Perform concrete-cipher logic
2088 this._doReset();
2089 },
2090
2091 /**
2092 * Adds data to be encrypted or decrypted.
2093 *
2094 * @param {WordArray|string} dataUpdate The data to encrypt or decrypt.
2095 *
2096 * @return {WordArray} The data after processing.
2097 *
2098 * @example
2099 *
2100 * var encrypted = cipher.process('data');
2101 * var encrypted = cipher.process(wordArray);
2102 */
2103 process: function (dataUpdate) {
2104 // Append
2105 this._append(dataUpdate);
2106
2107 // Process available blocks
2108 return this._process();
2109 },
2110
2111 /**
2112 * Finalizes the encryption or decryption process.
2113 * Note that the finalize operation is effectively a destructive, read-once operation.
2114 *
2115 * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt.
2116 *
2117 * @return {WordArray} The data after final processing.
2118 *
2119 * @example
2120 *
2121 * var encrypted = cipher.finalize();
2122 * var encrypted = cipher.finalize('data');
2123 * var encrypted = cipher.finalize(wordArray);
2124 */
2125 finalize: function (dataUpdate) {
2126 // Final data update
2127 if (dataUpdate) {
2128 this._append(dataUpdate);
2129 }
2130
2131 // Perform concrete-cipher logic
2132 var finalProcessedData = this._doFinalize();
2133
2134 return finalProcessedData;
2135 },
2136
2137 keySize: 128/32,
2138
2139 ivSize: 128/32,
2140
2141 _ENC_XFORM_MODE: 1,
2142
2143 _DEC_XFORM_MODE: 2,
2144
2145 /**
2146 * Creates shortcut functions to a cipher's object interface.
2147 *
2148 * @param {Cipher} cipher The cipher to create a helper for.
2149 *
2150 * @return {Object} An object with encrypt and decrypt shortcut functions.
2151 *
2152 * @static
2153 *
2154 * @example
2155 *
2156 * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
2157 */
2158 _createHelper: (function () {
2159 function selectCipherStrategy(key) {
2160 if (typeof key == 'string') {
2161 return PasswordBasedCipher;
2162 } else {
2163 return SerializableCipher;
2164 }
2165 }
2166
2167 return function (cipher) {
2168 return {
2169 encrypt: function (message, key, cfg) {
2170 return selectCipherStrategy(key).encrypt(cipher, message, key, cfg);
2171 },
2172
2173 decrypt: function (ciphertext, key, cfg) {
2174 return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg);
2175 }
2176 };
2177 };
2178 }())
2179 });
2180
2181 /**
2182 * Abstract base stream cipher template.
2183 *
2184 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
2185 */
2186 var StreamCipher = C_lib.StreamCipher = Cipher.extend({
2187 _doFinalize: function () {
2188 // Process partial blocks
2189 var finalProcessedBlocks = this._process(!!'flush');
2190
2191 return finalProcessedBlocks;
2192 },
2193
2194 blockSize: 1
2195 });
2196
2197 /**
2198 * Mode namespace.
2199 */
2200 var C_mode = C.mode = {};
2201
2202 /**
2203 * Abstract base block cipher mode template.
2204 */
2205 var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({
2206 /**
2207 * Creates this mode for encryption.
2208 *
2209 * @param {Cipher} cipher A block cipher instance.
2210 * @param {Array} iv The IV words.
2211 *
2212 * @static
2213 *
2214 * @example
2215 *
2216 * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
2217 */
2218 createEncryptor: function (cipher, iv) {
2219 return this.Encryptor.create(cipher, iv);
2220 },
2221
2222 /**
2223 * Creates this mode for decryption.
2224 *
2225 * @param {Cipher} cipher A block cipher instance.
2226 * @param {Array} iv The IV words.
2227 *
2228 * @static
2229 *
2230 * @example
2231 *
2232 * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
2233 */
2234 createDecryptor: function (cipher, iv) {
2235 return this.Decryptor.create(cipher, iv);
2236 },
2237
2238 /**
2239 * Initializes a newly created mode.
2240 *
2241 * @param {Cipher} cipher A block cipher instance.
2242 * @param {Array} iv The IV words.
2243 *
2244 * @example
2245 *
2246 * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
2247 */
2248 init: function (cipher, iv) {
2249 this._cipher = cipher;
2250 this._iv = iv;
2251 }
2252 });
2253
2254 /**
2255 * Cipher Block Chaining mode.
2256 */
2257 var CBC = C_mode.CBC = (function () {
2258 /**
2259 * Abstract base CBC mode.
2260 */
2261 var CBC = BlockCipherMode.extend();
2262
2263 /**
2264 * CBC encryptor.
2265 */
2266 CBC.Encryptor = CBC.extend({
2267 /**
2268 * Processes the data block at offset.
2269 *
2270 * @param {Array} words The data words to operate on.
2271 * @param {number} offset The offset where the block starts.
2272 *
2273 * @example
2274 *
2275 * mode.processBlock(data.words, offset);
2276 */
2277 processBlock: function (words, offset) {
2278 // Shortcuts
2279 var cipher = this._cipher;
2280 var blockSize = cipher.blockSize;
2281
2282 // XOR and encrypt
2283 xorBlock.call(this, words, offset, blockSize);
2284 cipher.encryptBlock(words, offset);
2285
2286 // Remember this block to use with next block
2287 this._prevBlock = words.slice(offset, offset + blockSize);
2288 }
2289 });
2290
2291 /**
2292 * CBC decryptor.
2293 */
2294 CBC.Decryptor = CBC.extend({
2295 /**
2296 * Processes the data block at offset.
2297 *
2298 * @param {Array} words The data words to operate on.
2299 * @param {number} offset The offset where the block starts.
2300 *
2301 * @example
2302 *
2303 * mode.processBlock(data.words, offset);
2304 */
2305 processBlock: function (words, offset) {
2306 // Shortcuts
2307 var cipher = this._cipher;
2308 var blockSize = cipher.blockSize;
2309
2310 // Remember this block to use with next block
2311 var thisBlock = words.slice(offset, offset + blockSize);
2312
2313 // Decrypt and XOR
2314 cipher.decryptBlock(words, offset);
2315 xorBlock.call(this, words, offset, blockSize);
2316
2317 // This block becomes the previous block
2318 this._prevBlock = thisBlock;
2319 }
2320 });
2321
2322 function xorBlock(words, offset, blockSize) {
2323 // Shortcut
2324 var iv = this._iv;
2325
2326 // Choose mixing block
2327 if (iv) {
2328 var block = iv;
2329
2330 // Remove IV for subsequent blocks
2331 this._iv = undefined;
2332 } else {
2333 var block = this._prevBlock;
2334 }
2335
2336 // XOR blocks
2337 for (var i = 0; i < blockSize; i++) {
2338 words[offset + i] ^= block[i];
2339 }
2340 }
2341
2342 return CBC;
2343 }());
2344
2345 /**
2346 * Infinite Garble Extension mode.
2347 */
2348 var IGE = C_mode.IGE = (function () {
2349 /**
2350 * Abstract base IGE mode.
2351 */
2352 var IGE = BlockCipherMode.extend();
2353
2354 /**
2355 * IGE encryptor.
2356 */
2357 IGE.Encryptor = IGE.extend({
2358 /**
2359 * Processes the data block at offset.
2360 *
2361 * @param {Array} words The data words to operate on.
2362 * @param {number} offset The offset where the block starts.
2363 *
2364 * @example
2365 *
2366 * mode.processBlock(data.words, offset);
2367 */
2368 processBlock: function (words, offset) {
2369 // Shortcuts
2370 var cipher = this._cipher;
2371 var blockSize = cipher.blockSize;
2372
2373 if (this._ivp === undefined) {
2374 this._ivp = this._iv.slice(0, blockSize);
2375 this._iv2p = this._iv.slice(blockSize, blockSize + blockSize);
2376 }
2377
2378
2379 // Remember this block to use with next block
2380 var nextIv2p = words.slice(offset, offset + blockSize);
2381
2382 // XOR with previous ciphertext
2383 xorBlock(words, this._ivp, offset, blockSize);
2384
2385 // Block cipher
2386 cipher.encryptBlock(words, offset);
2387
2388 // XOR with previous plaintext
2389 xorBlock(words, this._iv2p, offset, blockSize);
2390
2391 this._ivp = words.slice(offset, offset + blockSize);
2392 this._iv2p = nextIv2p;
2393 }
2394 });
2395
2396 /**
2397 * IGE decryptor.
2398 */
2399 IGE.Decryptor = IGE.extend({
2400 /**
2401 * Processes the data block at offset.
2402 *
2403 * @param {Array} words The data words to operate on.
2404 * @param {number} offset The offset where the block starts.
2405 *
2406 * @example
2407 *
2408 * mode.processBlock(data.words, offset);
2409 */
2410 processBlock: function (words, offset) {
2411 // Shortcuts
2412 var cipher = this._cipher;
2413 var blockSize = cipher.blockSize;
2414
2415 if (this._ivp === undefined) {
2416 this._ivp = this._iv.slice(0, blockSize);
2417 this._iv2p = this._iv.slice(blockSize, 2 * blockSize);
2418 }
2419
2420 // Remember this block to use with next block
2421 var nextIvp = words.slice(offset, offset + blockSize);
2422
2423 // XOR with previous ciphertext
2424 xorBlock(words, this._iv2p, offset, blockSize);
2425
2426 // Block cipher
2427 cipher.decryptBlock(words, offset);
2428
2429 // XOR with previous plaintext
2430 xorBlock(words, this._ivp, offset, blockSize);
2431
2432 this._ivp = nextIvp;
2433 this._iv2p = words.slice(offset, offset + blockSize);
2434 }
2435 });
2436
2437 function xorBlock(words, block, offset, blockSize) {
2438 for (var i = 0; i < blockSize; i++) {
2439 words[offset + i] ^= block[i];
2440 }
2441 }
2442
2443 return IGE;
2444 }());
2445
2446 /**
2447 * Padding namespace.
2448 */
2449 var C_pad = C.pad = {};
2450
2451 /**
2452 * PKCS #5/7 padding strategy.
2453 */
2454 var Pkcs7 = C_pad.Pkcs7 = {
2455 /**
2456 * Pads data using the algorithm defined in PKCS #5/7.
2457 *
2458 * @param {WordArray} data The data to pad.
2459 * @param {number} blockSize The multiple that the data should be padded to.
2460 *
2461 * @static
2462 *
2463 * @example
2464 *
2465 * CryptoJS.pad.Pkcs7.pad(wordArray, 4);
2466 */
2467 pad: function (data, blockSize) {
2468 // Shortcut
2469 var blockSizeBytes = blockSize * 4;
2470
2471 // Count padding bytes
2472 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
2473
2474 // Create padding word
2475 var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes;
2476
2477 // Create padding
2478 var paddingWords = [];
2479 for (var i = 0; i < nPaddingBytes; i += 4) {
2480 paddingWords.push(paddingWord);
2481 }
2482 var padding = WordArray.create(paddingWords, nPaddingBytes);
2483
2484 // Add padding
2485 data.concat(padding);
2486 },
2487
2488 /**
2489 * Unpads data that had been padded using the algorithm defined in PKCS #5/7.
2490 *
2491 * @param {WordArray} data The data to unpad.
2492 *
2493 * @static
2494 *
2495 * @example
2496 *
2497 * CryptoJS.pad.Pkcs7.unpad(wordArray);
2498 */
2499 unpad: function (data) {
2500 // Get number of padding bytes from last byte
2501 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
2502
2503 // Remove padding
2504 data.sigBytes -= nPaddingBytes;
2505 }
2506 };
2507
2508 var NoPadding = C_pad.NoPadding = {
2509 pad: function () {
2510 },
2511
2512 unpad: function () {
2513 }
2514 };
2515
2516
2517 /**
2518 * Abstract base block cipher template.
2519 *
2520 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits)
2521 */
2522 var BlockCipher = C_lib.BlockCipher = Cipher.extend({
2523 /**
2524 * Configuration options.
2525 *
2526 * @property {Mode} mode The block mode to use. Default: CBC
2527 * @property {Padding} padding The padding strategy to use. Default: Pkcs7
2528 */
2529 cfg: Cipher.cfg.extend({
2530 mode: CBC,
2531 padding: Pkcs7
2532 }),
2533
2534 reset: function () {
2535 // Reset cipher
2536 Cipher.reset.call(this);
2537
2538 // Shortcuts
2539 var cfg = this.cfg;
2540 var iv = cfg.iv;
2541 var mode = cfg.mode;
2542
2543 // Reset block mode
2544 if (this._xformMode == this._ENC_XFORM_MODE) {
2545 var modeCreator = mode.createEncryptor;
2546 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
2547 var modeCreator = mode.createDecryptor;
2548
2549 // Keep at least one block in the buffer for unpadding
2550 this._minBufferSize = 1;
2551 }
2552 this._mode = modeCreator.call(mode, this, iv && iv.words);
2553 },
2554
2555 _doProcessBlock: function (words, offset) {
2556 this._mode.processBlock(words, offset);
2557 },
2558
2559 _doFinalize: function () {
2560 // Shortcut
2561 var padding = this.cfg.padding;
2562
2563 // Finalize
2564 if (this._xformMode == this._ENC_XFORM_MODE) {
2565 // Pad data
2566 padding.pad(this._data, this.blockSize);
2567
2568 // Process final blocks
2569 var finalProcessedBlocks = this._process(!!'flush');
2570 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
2571 // Process final blocks
2572 var finalProcessedBlocks = this._process(!!'flush');
2573
2574 // Unpad data
2575 padding.unpad(finalProcessedBlocks);
2576 }
2577
2578 return finalProcessedBlocks;
2579 },
2580
2581 blockSize: 128/32
2582 });
2583
2584 /**
2585 * A collection of cipher parameters.
2586 *
2587 * @property {WordArray} ciphertext The raw ciphertext.
2588 * @property {WordArray} key The key to this ciphertext.
2589 * @property {WordArray} iv The IV used in the ciphering operation.
2590 * @property {WordArray} salt The salt used with a key derivation function.
2591 * @property {Cipher} algorithm The cipher algorithm.
2592 * @property {Mode} mode The block mode used in the ciphering operation.
2593 * @property {Padding} padding The padding scheme used in the ciphering operation.
2594 * @property {number} blockSize The block size of the cipher.
2595 * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string.
2596 */
2597 var CipherParams = C_lib.CipherParams = Base.extend({
2598 /**
2599 * Initializes a newly created cipher params object.
2600 *
2601 * @param {Object} cipherParams An object with any of the possible cipher parameters.
2602 *
2603 * @example
2604 *
2605 * var cipherParams = CryptoJS.lib.CipherParams.create({
2606 * ciphertext: ciphertextWordArray,
2607 * key: keyWordArray,
2608 * iv: ivWordArray,
2609 * salt: saltWordArray,
2610 * algorithm: CryptoJS.algo.AES,
2611 * mode: CryptoJS.mode.CBC,
2612 * padding: CryptoJS.pad.PKCS7,
2613 * blockSize: 4,
2614 * formatter: CryptoJS.format.OpenSSL
2615 * });
2616 */
2617 init: function (cipherParams) {
2618 this.mixIn(cipherParams);
2619 },
2620
2621 /**
2622 * Converts this cipher params object to a string.
2623 *
2624 * @param {Format} formatter (Optional) The formatting strategy to use.
2625 *
2626 * @return {string} The stringified cipher params.
2627 *
2628 * @throws Error If neither the formatter nor the default formatter is set.
2629 *
2630 * @example
2631 *
2632 * var string = cipherParams + '';
2633 * var string = cipherParams.toString();
2634 * var string = cipherParams.toString(CryptoJS.format.OpenSSL);
2635 */
2636 toString: function (formatter) {
2637 return (formatter || this.formatter).stringify(this);
2638 }
2639 });
2640
2641 /**
2642 * Format namespace.
2643 */
2644 var C_format = C.format = {};
2645
2646 /**
2647 * OpenSSL formatting strategy.
2648 */
2649 var OpenSSLFormatter = C_format.OpenSSL = {
2650 /**
2651 * Converts a cipher params object to an OpenSSL-compatible string.
2652 *
2653 * @param {CipherParams} cipherParams The cipher params object.
2654 *
2655 * @return {string} The OpenSSL-compatible string.
2656 *
2657 * @static
2658 *
2659 * @example
2660 *
2661 * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
2662 */
2663 stringify: function (cipherParams) {
2664 // Shortcuts
2665 var ciphertext = cipherParams.ciphertext;
2666 var salt = cipherParams.salt;
2667
2668 // Format
2669 if (salt) {
2670 var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
2671 } else {
2672 var wordArray = ciphertext;
2673 }
2674
2675 return wordArray.toString(Base64);
2676 },
2677
2678 /**
2679 * Converts an OpenSSL-compatible string to a cipher params object.
2680 *
2681 * @param {string} openSSLStr The OpenSSL-compatible string.
2682 *
2683 * @return {CipherParams} The cipher params object.
2684 *
2685 * @static
2686 *
2687 * @example
2688 *
2689 * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
2690 */
2691 parse: function (openSSLStr) {
2692 // Parse base64
2693 var ciphertext = Base64.parse(openSSLStr);
2694
2695 // Shortcut
2696 var ciphertextWords = ciphertext.words;
2697
2698 // Test for salt
2699 if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) {
2700 // Extract salt
2701 var salt = WordArray.create(ciphertextWords.slice(2, 4));
2702
2703 // Remove salt from ciphertext
2704 ciphertextWords.splice(0, 4);
2705 ciphertext.sigBytes -= 16;
2706 }
2707
2708 return CipherParams.create({ ciphertext: ciphertext, salt: salt });
2709 }
2710 };
2711
2712 /**
2713 * A cipher wrapper that returns ciphertext as a serializable cipher params object.
2714 */
2715 var SerializableCipher = C_lib.SerializableCipher = Base.extend({
2716 /**
2717 * Configuration options.
2718 *
2719 * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL
2720 */
2721 cfg: Base.extend({
2722 format: OpenSSLFormatter
2723 }),
2724
2725 /**
2726 * Encrypts a message.
2727 *
2728 * @param {Cipher} cipher The cipher algorithm to use.
2729 * @param {WordArray|string} message The message to encrypt.
2730 * @param {WordArray} key The key.
2731 * @param {Object} cfg (Optional) The configuration options to use for this operation.
2732 *
2733 * @return {CipherParams} A cipher params object.
2734 *
2735 * @static
2736 *
2737 * @example
2738 *
2739 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
2740 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
2741 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
2742 */
2743 encrypt: function (cipher, message, key, cfg) {
2744 // Apply config defaults
2745 cfg = this.cfg.extend(cfg);
2746
2747 // Encrypt
2748 var encryptor = cipher.createEncryptor(key, cfg);
2749 var ciphertext = encryptor.finalize(message);
2750
2751 // Shortcut
2752 var cipherCfg = encryptor.cfg;
2753
2754 // Create and return serializable cipher params
2755 return CipherParams.create({
2756 ciphertext: ciphertext,
2757 key: key,
2758 iv: cipherCfg.iv,
2759 algorithm: cipher,
2760 mode: cipherCfg.mode,
2761 padding: cipherCfg.padding,
2762 blockSize: cipher.blockSize,
2763 formatter: cfg.format
2764 });
2765 },
2766
2767 /**
2768 * Decrypts serialized ciphertext.
2769 *
2770 * @param {Cipher} cipher The cipher algorithm to use.
2771 * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
2772 * @param {WordArray} key The key.
2773 * @param {Object} cfg (Optional) The configuration options to use for this operation.
2774 *
2775 * @return {WordArray} The plaintext.
2776 *
2777 * @static
2778 *
2779 * @example
2780 *
2781 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
2782 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
2783 */
2784 decrypt: function (cipher, ciphertext, key, cfg) {
2785 // Apply config defaults
2786 cfg = this.cfg.extend(cfg);
2787
2788 // Convert string to CipherParams
2789 ciphertext = this._parse(ciphertext, cfg.format);
2790
2791 // Decrypt
2792 var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext);
2793
2794 return plaintext;
2795 },
2796
2797 /**
2798 * Converts serialized ciphertext to CipherParams,
2799 * else assumed CipherParams already and returns ciphertext unchanged.
2800 *
2801 * @param {CipherParams|string} ciphertext The ciphertext.
2802 * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
2803 *
2804 * @return {CipherParams} The unserialized ciphertext.
2805 *
2806 * @static
2807 *
2808 * @example
2809 *
2810 * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
2811 */
2812 _parse: function (ciphertext, format) {
2813 if (typeof ciphertext == 'string') {
2814 return format.parse(ciphertext, this);
2815 } else {
2816 return ciphertext;
2817 }
2818 }
2819 });
2820
2821 /**
2822 * Key derivation function namespace.
2823 */
2824 var C_kdf = C.kdf = {};
2825
2826 /**
2827 * OpenSSL key derivation function.
2828 */
2829 var OpenSSLKdf = C_kdf.OpenSSL = {
2830 /**
2831 * Derives a key and IV from a password.
2832 *
2833 * @param {string} password The password to derive from.
2834 * @param {number} keySize The size in words of the key to generate.
2835 * @param {number} ivSize The size in words of the IV to generate.
2836 * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
2837 *
2838 * @return {CipherParams} A cipher params object with the key, IV, and salt.
2839 *
2840 * @static
2841 *
2842 * @example
2843 *
2844 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
2845 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
2846 */
2847 execute: function (password, keySize, ivSize, salt) {
2848 // Generate random salt
2849 if (!salt) {
2850 salt = WordArray.random(64/8);
2851 }
2852
2853 // Derive key and IV
2854 var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
2855
2856 // Separate key and IV
2857 var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
2858 key.sigBytes = keySize * 4;
2859
2860 // Return params
2861 return CipherParams.create({ key: key, iv: iv, salt: salt });
2862 }
2863 };
2864
2865 /**
2866 * A serializable cipher wrapper that derives the key from a password,
2867 * and returns ciphertext as a serializable cipher params object.
2868 */
2869 var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({
2870 /**
2871 * Configuration options.
2872 *
2873 * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL
2874 */
2875 cfg: SerializableCipher.cfg.extend({
2876 kdf: OpenSSLKdf
2877 }),
2878
2879 /**
2880 * Encrypts a message using a password.
2881 *
2882 * @param {Cipher} cipher The cipher algorithm to use.
2883 * @param {WordArray|string} message The message to encrypt.
2884 * @param {string} password The password.
2885 * @param {Object} cfg (Optional) The configuration options to use for this operation.
2886 *
2887 * @return {CipherParams} A cipher params object.
2888 *
2889 * @static
2890 *
2891 * @example
2892 *
2893 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
2894 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
2895 */
2896 encrypt: function (cipher, message, password, cfg) {
2897 // Apply config defaults
2898 cfg = this.cfg.extend(cfg);
2899
2900 // Derive key and other params
2901 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize);
2902
2903 // Add IV to config
2904 cfg.iv = derivedParams.iv;
2905
2906 // Encrypt
2907 var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg);
2908
2909 // Mix in derived params
2910 ciphertext.mixIn(derivedParams);
2911
2912 return ciphertext;
2913 },
2914
2915 /**
2916 * Decrypts serialized ciphertext using a password.
2917 *
2918 * @param {Cipher} cipher The cipher algorithm to use.
2919 * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
2920 * @param {string} password The password.
2921 * @param {Object} cfg (Optional) The configuration options to use for this operation.
2922 *
2923 * @return {WordArray} The plaintext.
2924 *
2925 * @static
2926 *
2927 * @example
2928 *
2929 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
2930 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
2931 */
2932 decrypt: function (cipher, ciphertext, password, cfg) {
2933 // Apply config defaults
2934 cfg = this.cfg.extend(cfg);
2935
2936 // Convert string to CipherParams
2937 ciphertext = this._parse(ciphertext, cfg.format);
2938
2939 // Derive key and other params
2940 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt);
2941
2942 // Add IV to config
2943 cfg.iv = derivedParams.iv;
2944
2945 // Decrypt
2946 var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg);
2947
2948 return plaintext;
2949 }
2950 });
2951}());
2952
2953
2954/***/ }),
2955/* 6 */
2956/***/ (function(module, exports, __webpack_require__) {
2957
2958var CryptoJS = __webpack_require__(0).CryptoJS;
2959
2960/*
2961CryptoJS v3.1.2
2962code.google.com/p/crypto-js
2963(c) 2009-2013 by Jeff Mott. All rights reserved.
2964code.google.com/p/crypto-js/wiki/License
2965*/
2966(function () {
2967 // Shortcuts
2968 var C = CryptoJS;
2969 var C_lib = C.lib;
2970 var WordArray = C_lib.WordArray;
2971 var C_enc = C.enc;
2972
2973 /**
2974 * Base64 encoding strategy.
2975 */
2976 var Base64 = C_enc.Base64 = {
2977 /**
2978 * Converts a word array to a Base64 string.
2979 *
2980 * @param {WordArray} wordArray The word array.
2981 *
2982 * @return {string} The Base64 string.
2983 *
2984 * @static
2985 *
2986 * @example
2987 *
2988 * var base64String = CryptoJS.enc.Base64.stringify(wordArray);
2989 */
2990 stringify: function (wordArray) {
2991 // Shortcuts
2992 var words = wordArray.words;
2993 var sigBytes = wordArray.sigBytes;
2994 var map = this._map;
2995
2996 // Clamp excess bits
2997 wordArray.clamp();
2998
2999 // Convert
3000 var base64Chars = [];
3001 for (var i = 0; i < sigBytes; i += 3) {
3002 var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
3003 var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
3004 var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
3005
3006 var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
3007
3008 for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) {
3009 base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
3010 }
3011 }
3012
3013 // Add padding
3014 var paddingChar = map.charAt(64);
3015 if (paddingChar) {
3016 while (base64Chars.length % 4) {
3017 base64Chars.push(paddingChar);
3018 }
3019 }
3020
3021 return base64Chars.join('');
3022 },
3023
3024 /**
3025 * Converts a Base64 string to a word array.
3026 *
3027 * @param {string} base64Str The Base64 string.
3028 *
3029 * @return {WordArray} The word array.
3030 *
3031 * @static
3032 *
3033 * @example
3034 *
3035 * var wordArray = CryptoJS.enc.Base64.parse(base64String);
3036 */
3037 parse: function (base64Str) {
3038 // Shortcuts
3039 var base64StrLength = base64Str.length;
3040 var map = this._map;
3041
3042 // Ignore padding
3043 var paddingChar = map.charAt(64);
3044 if (paddingChar) {
3045 var paddingIndex = base64Str.indexOf(paddingChar);
3046 if (paddingIndex != -1) {
3047 base64StrLength = paddingIndex;
3048 }
3049 }
3050
3051 // Convert
3052 var words = [];
3053 var nBytes = 0;
3054 for (var i = 0; i < base64StrLength; i++) {
3055 if (i % 4) {
3056 var bits1 = map.indexOf(base64Str.charAt(i - 1)) << ((i % 4) * 2);
3057 var bits2 = map.indexOf(base64Str.charAt(i)) >>> (6 - (i % 4) * 2);
3058 words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8);
3059 nBytes++;
3060 }
3061 }
3062
3063 return WordArray.create(words, nBytes);
3064 },
3065
3066 _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
3067 };
3068}());
3069
3070
3071/***/ }),
3072/* 7 */
3073/***/ (function(module, exports, __webpack_require__) {
3074
3075var CryptoJS = __webpack_require__(0).CryptoJS;
3076
3077/*
3078CryptoJS v3.1.2
3079code.google.com/p/crypto-js
3080(c) 2009-2013 by Jeff Mott. All rights reserved.
3081code.google.com/p/crypto-js/wiki/License
3082*/
3083(function () {
3084 // Shortcuts
3085 var C = CryptoJS;
3086 var C_lib = C.lib;
3087 var Base = C_lib.Base;
3088 var WordArray = C_lib.WordArray;
3089 var C_algo = C.algo;
3090 var MD5 = C_algo.MD5;
3091
3092 /**
3093 * This key derivation function is meant to conform with EVP_BytesToKey.
3094 * www.openssl.org/docs/crypto/EVP_BytesToKey.html
3095 */
3096 var EvpKDF = C_algo.EvpKDF = Base.extend({
3097 /**
3098 * Configuration options.
3099 *
3100 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
3101 * @property {Hasher} hasher The hash algorithm to use. Default: MD5
3102 * @property {number} iterations The number of iterations to perform. Default: 1
3103 */
3104 cfg: Base.extend({
3105 keySize: 128/32,
3106 hasher: MD5,
3107 iterations: 1
3108 }),
3109
3110 /**
3111 * Initializes a newly created key derivation function.
3112 *
3113 * @param {Object} cfg (Optional) The configuration options to use for the derivation.
3114 *
3115 * @example
3116 *
3117 * var kdf = CryptoJS.algo.EvpKDF.create();
3118 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
3119 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
3120 */
3121 init: function (cfg) {
3122 this.cfg = this.cfg.extend(cfg);
3123 },
3124
3125 /**
3126 * Derives a key from a password.
3127 *
3128 * @param {WordArray|string} password The password.
3129 * @param {WordArray|string} salt A salt.
3130 *
3131 * @return {WordArray} The derived key.
3132 *
3133 * @example
3134 *
3135 * var key = kdf.compute(password, salt);
3136 */
3137 compute: function (password, salt) {
3138 // Shortcut
3139 var cfg = this.cfg;
3140
3141 // Init hasher
3142 var hasher = cfg.hasher.create();
3143
3144 // Initial values
3145 var derivedKey = WordArray.create();
3146
3147 // Shortcuts
3148 var derivedKeyWords = derivedKey.words;
3149 var keySize = cfg.keySize;
3150 var iterations = cfg.iterations;
3151
3152 // Generate key
3153 while (derivedKeyWords.length < keySize) {
3154 if (block) {
3155 hasher.update(block);
3156 }
3157 var block = hasher.update(password).finalize(salt);
3158 hasher.reset();
3159
3160 // Iterations
3161 for (var i = 1; i < iterations; i++) {
3162 block = hasher.finalize(block);
3163 hasher.reset();
3164 }
3165
3166 derivedKey.concat(block);
3167 }
3168 derivedKey.sigBytes = keySize * 4;
3169
3170 return derivedKey;
3171 }
3172 });
3173
3174 /**
3175 * Derives a key from a password.
3176 *
3177 * @param {WordArray|string} password The password.
3178 * @param {WordArray|string} salt A salt.
3179 * @param {Object} cfg (Optional) The configuration options to use for this computation.
3180 *
3181 * @return {WordArray} The derived key.
3182 *
3183 * @static
3184 *
3185 * @example
3186 *
3187 * var key = CryptoJS.EvpKDF(password, salt);
3188 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
3189 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
3190 */
3191 C.EvpKDF = function (password, salt, cfg) {
3192 return EvpKDF.create(cfg).compute(password, salt);
3193 };
3194}());
3195
3196
3197/***/ }),
3198/* 8 */
3199/***/ (function(module, exports, __webpack_require__) {
3200
3201var CryptoJS = __webpack_require__(0).CryptoJS;
3202
3203// create custom json serialization format
3204var JsonFormatter = {
3205 stringify: function (cipherParams) {
3206 // create json object with ciphertext
3207 var jsonObj = {
3208 ct: cipherParams.ciphertext.toString(CryptoJS.enc.Base64)
3209 };
3210
3211 // optionally add iv and salt
3212 if (cipherParams.iv) {
3213 jsonObj.iv = cipherParams.iv.toString();
3214 }
3215
3216 if (cipherParams.salt) {
3217 jsonObj.s = cipherParams.salt.toString();
3218 }
3219
3220 // stringify json object
3221 return JSON.stringify(jsonObj)
3222 },
3223
3224 parse: function (jsonStr) {
3225 // parse json string
3226 var jsonObj = JSON.parse(jsonStr);
3227
3228 // extract ciphertext from json object, and create cipher params object
3229 var cipherParams = CryptoJS.lib.CipherParams.create({
3230 ciphertext: CryptoJS.enc.Base64.parse(jsonObj.ct)
3231 });
3232
3233 // optionally extract iv and salt
3234 if (jsonObj.iv) {
3235 cipherParams.iv = CryptoJS.enc.Hex.parse(jsonObj.iv);
3236 }
3237
3238 if (jsonObj.s) {
3239 cipherParams.salt = CryptoJS.enc.Hex.parse(jsonObj.s);
3240 }
3241
3242 return cipherParams;
3243 }
3244};
3245
3246exports.JsonFormatter = JsonFormatter;
3247
3248/***/ }),
3249/* 9 */
3250/***/ (function(module, exports, __webpack_require__) {
3251
3252var CryptoJS = __webpack_require__(0).CryptoJS;
3253
3254/*
3255CryptoJS v3.1.2
3256code.google.com/p/crypto-js
3257(c) 2009-2013 by Jeff Mott. All rights reserved.
3258code.google.com/p/crypto-js/wiki/License
3259*/
3260(function (Math) {
3261 // Shortcuts
3262 var C = CryptoJS;
3263 var C_lib = C.lib;
3264 var WordArray = C_lib.WordArray;
3265 var Hasher = C_lib.Hasher;
3266 var C_algo = C.algo;
3267
3268 // Constants table
3269 var T = [];
3270
3271 // Compute constants
3272 (function () {
3273 for (var i = 0; i < 64; i++) {
3274 T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0;
3275 }
3276 }());
3277
3278 /**
3279 * MD5 hash algorithm.
3280 */
3281 var MD5 = C_algo.MD5 = Hasher.extend({
3282 _doReset: function () {
3283 this._hash = new WordArray.init([
3284 0x67452301, 0xefcdab89,
3285 0x98badcfe, 0x10325476
3286 ]);
3287 },
3288
3289 _doProcessBlock: function (M, offset) {
3290 // Swap endian
3291 for (var i = 0; i < 16; i++) {
3292 // Shortcuts
3293 var offset_i = offset + i;
3294 var M_offset_i = M[offset_i];
3295
3296 M[offset_i] = (
3297 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
3298 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
3299 );
3300 }
3301
3302 // Shortcuts
3303 var H = this._hash.words;
3304
3305 var M_offset_0 = M[offset + 0];
3306 var M_offset_1 = M[offset + 1];
3307 var M_offset_2 = M[offset + 2];
3308 var M_offset_3 = M[offset + 3];
3309 var M_offset_4 = M[offset + 4];
3310 var M_offset_5 = M[offset + 5];
3311 var M_offset_6 = M[offset + 6];
3312 var M_offset_7 = M[offset + 7];
3313 var M_offset_8 = M[offset + 8];
3314 var M_offset_9 = M[offset + 9];
3315 var M_offset_10 = M[offset + 10];
3316 var M_offset_11 = M[offset + 11];
3317 var M_offset_12 = M[offset + 12];
3318 var M_offset_13 = M[offset + 13];
3319 var M_offset_14 = M[offset + 14];
3320 var M_offset_15 = M[offset + 15];
3321
3322 // Working varialbes
3323 var a = H[0];
3324 var b = H[1];
3325 var c = H[2];
3326 var d = H[3];
3327
3328 // Computation
3329 a = FF(a, b, c, d, M_offset_0, 7, T[0]);
3330 d = FF(d, a, b, c, M_offset_1, 12, T[1]);
3331 c = FF(c, d, a, b, M_offset_2, 17, T[2]);
3332 b = FF(b, c, d, a, M_offset_3, 22, T[3]);
3333 a = FF(a, b, c, d, M_offset_4, 7, T[4]);
3334 d = FF(d, a, b, c, M_offset_5, 12, T[5]);
3335 c = FF(c, d, a, b, M_offset_6, 17, T[6]);
3336 b = FF(b, c, d, a, M_offset_7, 22, T[7]);
3337 a = FF(a, b, c, d, M_offset_8, 7, T[8]);
3338 d = FF(d, a, b, c, M_offset_9, 12, T[9]);
3339 c = FF(c, d, a, b, M_offset_10, 17, T[10]);
3340 b = FF(b, c, d, a, M_offset_11, 22, T[11]);
3341 a = FF(a, b, c, d, M_offset_12, 7, T[12]);
3342 d = FF(d, a, b, c, M_offset_13, 12, T[13]);
3343 c = FF(c, d, a, b, M_offset_14, 17, T[14]);
3344 b = FF(b, c, d, a, M_offset_15, 22, T[15]);
3345
3346 a = GG(a, b, c, d, M_offset_1, 5, T[16]);
3347 d = GG(d, a, b, c, M_offset_6, 9, T[17]);
3348 c = GG(c, d, a, b, M_offset_11, 14, T[18]);
3349 b = GG(b, c, d, a, M_offset_0, 20, T[19]);
3350 a = GG(a, b, c, d, M_offset_5, 5, T[20]);
3351 d = GG(d, a, b, c, M_offset_10, 9, T[21]);
3352 c = GG(c, d, a, b, M_offset_15, 14, T[22]);
3353 b = GG(b, c, d, a, M_offset_4, 20, T[23]);
3354 a = GG(a, b, c, d, M_offset_9, 5, T[24]);
3355 d = GG(d, a, b, c, M_offset_14, 9, T[25]);
3356 c = GG(c, d, a, b, M_offset_3, 14, T[26]);
3357 b = GG(b, c, d, a, M_offset_8, 20, T[27]);
3358 a = GG(a, b, c, d, M_offset_13, 5, T[28]);
3359 d = GG(d, a, b, c, M_offset_2, 9, T[29]);
3360 c = GG(c, d, a, b, M_offset_7, 14, T[30]);
3361 b = GG(b, c, d, a, M_offset_12, 20, T[31]);
3362
3363 a = HH(a, b, c, d, M_offset_5, 4, T[32]);
3364 d = HH(d, a, b, c, M_offset_8, 11, T[33]);
3365 c = HH(c, d, a, b, M_offset_11, 16, T[34]);
3366 b = HH(b, c, d, a, M_offset_14, 23, T[35]);
3367 a = HH(a, b, c, d, M_offset_1, 4, T[36]);
3368 d = HH(d, a, b, c, M_offset_4, 11, T[37]);
3369 c = HH(c, d, a, b, M_offset_7, 16, T[38]);
3370 b = HH(b, c, d, a, M_offset_10, 23, T[39]);
3371 a = HH(a, b, c, d, M_offset_13, 4, T[40]);
3372 d = HH(d, a, b, c, M_offset_0, 11, T[41]);
3373 c = HH(c, d, a, b, M_offset_3, 16, T[42]);
3374 b = HH(b, c, d, a, M_offset_6, 23, T[43]);
3375 a = HH(a, b, c, d, M_offset_9, 4, T[44]);
3376 d = HH(d, a, b, c, M_offset_12, 11, T[45]);
3377 c = HH(c, d, a, b, M_offset_15, 16, T[46]);
3378 b = HH(b, c, d, a, M_offset_2, 23, T[47]);
3379
3380 a = II(a, b, c, d, M_offset_0, 6, T[48]);
3381 d = II(d, a, b, c, M_offset_7, 10, T[49]);
3382 c = II(c, d, a, b, M_offset_14, 15, T[50]);
3383 b = II(b, c, d, a, M_offset_5, 21, T[51]);
3384 a = II(a, b, c, d, M_offset_12, 6, T[52]);
3385 d = II(d, a, b, c, M_offset_3, 10, T[53]);
3386 c = II(c, d, a, b, M_offset_10, 15, T[54]);
3387 b = II(b, c, d, a, M_offset_1, 21, T[55]);
3388 a = II(a, b, c, d, M_offset_8, 6, T[56]);
3389 d = II(d, a, b, c, M_offset_15, 10, T[57]);
3390 c = II(c, d, a, b, M_offset_6, 15, T[58]);
3391 b = II(b, c, d, a, M_offset_13, 21, T[59]);
3392 a = II(a, b, c, d, M_offset_4, 6, T[60]);
3393 d = II(d, a, b, c, M_offset_11, 10, T[61]);
3394 c = II(c, d, a, b, M_offset_2, 15, T[62]);
3395 b = II(b, c, d, a, M_offset_9, 21, T[63]);
3396
3397 // Intermediate hash value
3398 H[0] = (H[0] + a) | 0;
3399 H[1] = (H[1] + b) | 0;
3400 H[2] = (H[2] + c) | 0;
3401 H[3] = (H[3] + d) | 0;
3402 },
3403
3404 _doFinalize: function () {
3405 // Shortcuts
3406 var data = this._data;
3407 var dataWords = data.words;
3408
3409 var nBitsTotal = this._nDataBytes * 8;
3410 var nBitsLeft = data.sigBytes * 8;
3411
3412 // Add padding
3413 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
3414
3415 var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000);
3416 var nBitsTotalL = nBitsTotal;
3417 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = (
3418 (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) |
3419 (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00)
3420 );
3421 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
3422 (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) |
3423 (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00)
3424 );
3425
3426 data.sigBytes = (dataWords.length + 1) * 4;
3427
3428 // Hash final blocks
3429 this._process();
3430
3431 // Shortcuts
3432 var hash = this._hash;
3433 var H = hash.words;
3434
3435 // Swap endian
3436 for (var i = 0; i < 4; i++) {
3437 // Shortcut
3438 var H_i = H[i];
3439
3440 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
3441 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
3442 }
3443
3444 // Return final computed hash
3445 return hash;
3446 },
3447
3448 clone: function () {
3449 var clone = Hasher.clone.call(this);
3450 clone._hash = this._hash.clone();
3451
3452 return clone;
3453 }
3454 });
3455
3456 function FF(a, b, c, d, x, s, t) {
3457 var n = a + ((b & c) | (~b & d)) + x + t;
3458 return ((n << s) | (n >>> (32 - s))) + b;
3459 }
3460
3461 function GG(a, b, c, d, x, s, t) {
3462 var n = a + ((b & d) | (c & ~d)) + x + t;
3463 return ((n << s) | (n >>> (32 - s))) + b;
3464 }
3465
3466 function HH(a, b, c, d, x, s, t) {
3467 var n = a + (b ^ c ^ d) + x + t;
3468 return ((n << s) | (n >>> (32 - s))) + b;
3469 }
3470
3471 function II(a, b, c, d, x, s, t) {
3472 var n = a + (c ^ (b | ~d)) + x + t;
3473 return ((n << s) | (n >>> (32 - s))) + b;
3474 }
3475
3476 /**
3477 * Shortcut function to the hasher's object interface.
3478 *
3479 * @param {WordArray|string} message The message to hash.
3480 *
3481 * @return {WordArray} The hash.
3482 *
3483 * @static
3484 *
3485 * @example
3486 *
3487 * var hash = CryptoJS.MD5('message');
3488 * var hash = CryptoJS.MD5(wordArray);
3489 */
3490 C.MD5 = Hasher._createHelper(MD5);
3491
3492 /**
3493 * Shortcut function to the HMAC's object interface.
3494 *
3495 * @param {WordArray|string} message The message to hash.
3496 * @param {WordArray|string} key The secret key.
3497 *
3498 * @return {WordArray} The HMAC.
3499 *
3500 * @static
3501 *
3502 * @example
3503 *
3504 * var hmac = CryptoJS.HmacMD5(message, key);
3505 */
3506 C.HmacMD5 = Hasher._createHmacHelper(MD5);
3507}(Math));
3508
3509
3510/***/ }),
3511/* 10 */
3512/***/ (function(module, exports, __webpack_require__) {
3513
3514var CryptoJS = __webpack_require__(0).CryptoJS;
3515
3516(function (Math) {
3517 // Shortcuts
3518 var C = CryptoJS;
3519 var C_lib = C.lib;
3520 var WordArray = C_lib.WordArray;
3521 var Hasher = C_lib.Hasher;
3522 var C_algo = C.algo;
3523
3524 // Initialization and round constants tables
3525 var H = [];
3526 var K = [];
3527
3528 // Compute constants
3529 (function () {
3530 function isPrime(n) {
3531 var sqrtN = Math.sqrt(n);
3532 for (var factor = 2; factor <= sqrtN; factor++) {
3533 if (!(n % factor)) {
3534 return false;
3535 }
3536 }
3537
3538 return true;
3539 }
3540
3541 function getFractionalBits(n) {
3542 return ((n - (n | 0)) * 0x100000000) | 0;
3543 }
3544
3545 var n = 2;
3546 var nPrime = 0;
3547 while (nPrime < 64) {
3548 if (isPrime(n)) {
3549 if (nPrime < 8) {
3550 H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2));
3551 }
3552 K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3));
3553
3554 nPrime++;
3555 }
3556
3557 n++;
3558 }
3559 }());
3560
3561 // Reusable object
3562 var W = [];
3563
3564 /**
3565 * SHA-256 hash algorithm.
3566 */
3567 var SHA256 = C_algo.SHA256 = Hasher.extend({
3568 _doReset: function () {
3569 this._hash = new WordArray.init(H.slice(0));
3570 },
3571
3572 _doProcessBlock: function (M, offset) {
3573 // Shortcut
3574 var H = this._hash.words;
3575
3576 // Working variables
3577 var a = H[0];
3578 var b = H[1];
3579 var c = H[2];
3580 var d = H[3];
3581 var e = H[4];
3582 var f = H[5];
3583 var g = H[6];
3584 var h = H[7];
3585
3586 // Computation
3587 for (var i = 0; i < 64; i++) {
3588 if (i < 16) {
3589 W[i] = M[offset + i] | 0;
3590 } else {
3591 var gamma0x = W[i - 15];
3592 var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^
3593 ((gamma0x << 14) | (gamma0x >>> 18)) ^
3594 (gamma0x >>> 3);
3595
3596 var gamma1x = W[i - 2];
3597 var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^
3598 ((gamma1x << 13) | (gamma1x >>> 19)) ^
3599 (gamma1x >>> 10);
3600
3601 W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
3602 }
3603
3604 var ch = (e & f) ^ (~e & g);
3605 var maj = (a & b) ^ (a & c) ^ (b & c);
3606
3607 var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22));
3608 var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25));
3609
3610 var t1 = h + sigma1 + ch + K[i] + W[i];
3611 var t2 = sigma0 + maj;
3612
3613 h = g;
3614 g = f;
3615 f = e;
3616 e = (d + t1) | 0;
3617 d = c;
3618 c = b;
3619 b = a;
3620 a = (t1 + t2) | 0;
3621 }
3622
3623 // Intermediate hash value
3624 H[0] = (H[0] + a) | 0;
3625 H[1] = (H[1] + b) | 0;
3626 H[2] = (H[2] + c) | 0;
3627 H[3] = (H[3] + d) | 0;
3628 H[4] = (H[4] + e) | 0;
3629 H[5] = (H[5] + f) | 0;
3630 H[6] = (H[6] + g) | 0;
3631 H[7] = (H[7] + h) | 0;
3632 },
3633
3634 _doFinalize: function () {
3635 // Shortcuts
3636 var data = this._data;
3637 var dataWords = data.words;
3638
3639 var nBitsTotal = this._nDataBytes * 8;
3640 var nBitsLeft = data.sigBytes * 8;
3641
3642 // Add padding
3643 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
3644 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
3645 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
3646 data.sigBytes = dataWords.length * 4;
3647
3648 // Hash final blocks
3649 this._process();
3650
3651 // Return final computed hash
3652 return this._hash;
3653 },
3654
3655 clone: function () {
3656 var clone = Hasher.clone.call(this);
3657 clone._hash = this._hash.clone();
3658
3659 return clone;
3660 }
3661 });
3662
3663 /**
3664 * Shortcut function to the hasher's object interface.
3665 *
3666 * @param {WordArray|string} message The message to hash.
3667 *
3668 * @return {WordArray} The hash.
3669 *
3670 * @static
3671 *
3672 * @example
3673 *
3674 * var hash = CryptoJS.SHA256('message');
3675 * var hash = CryptoJS.SHA256(wordArray);
3676 */
3677 C.SHA256 = Hasher._createHelper(SHA256);
3678
3679 /**
3680 * Shortcut function to the HMAC's object interface.
3681 *
3682 * @param {WordArray|string} message The message to hash.
3683 * @param {WordArray|string} key The secret key.
3684 *
3685 * @return {WordArray} The HMAC.
3686 *
3687 * @static
3688 *
3689 * @example
3690 *
3691 * var hmac = CryptoJS.HmacSHA256(message, key);
3692 */
3693 C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
3694}(Math));
3695
3696/***/ }),
3697/* 11 */
3698/***/ (function(module, __webpack_exports__, __webpack_require__) {
3699
3700"use strict";
3701/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return bpe; });
3702/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "m", function() { return one; });
3703/* harmony export (immutable) */ __webpack_exports__["o"] = powMod;
3704/* harmony export (immutable) */ __webpack_exports__["k"] = eGCD_;
3705/* harmony export (immutable) */ __webpack_exports__["h"] = greater;
3706/* harmony export (immutable) */ __webpack_exports__["n"] = divide_;
3707/* harmony export (immutable) */ __webpack_exports__["b"] = str2bigInt;
3708/* harmony export (immutable) */ __webpack_exports__["l"] = equalsInt;
3709/* harmony export (immutable) */ __webpack_exports__["f"] = isZero;
3710/* harmony export (immutable) */ __webpack_exports__["a"] = bigInt2str;
3711/* harmony export (immutable) */ __webpack_exports__["e"] = copy_;
3712/* harmony export (immutable) */ __webpack_exports__["d"] = copyInt_;
3713/* harmony export (immutable) */ __webpack_exports__["j"] = rightShift_;
3714/* harmony export (immutable) */ __webpack_exports__["i"] = sub_;
3715/* harmony export (immutable) */ __webpack_exports__["g"] = add_;
3716////////////////////////////////////////////////////////////////////////////////////////
3717// Big Integer Library v. 5.5
3718// Created 2000, last modified 2013
3719// Leemon Baird
3720// www.leemon.com
3721//
3722// Version history:
3723// v 5.5 17 Mar 2013
3724// - two lines of a form like "if (x<0) x+=n" had the "if" changed to "while" to
3725// handle the case when x<-n. (Thanks to James Ansell for finding that bug)
3726// v 5.4 3 Oct 2009
3727// - added "var i" to greaterShift() so i is not global. (Thanks to PŽter Szab— for finding that bug)
3728//
3729// v 5.3 21 Sep 2009
3730// - added randProbPrime(k) for probable primes
3731// - unrolled loop in mont_ (slightly faster)
3732// - millerRabin now takes a bigInt parameter rather than an int
3733//
3734// v 5.2 15 Sep 2009
3735// - fixed capitalization in call to int2bigInt in randBigInt
3736// (thanks to Emili Evripidou, Reinhold Behringer, and Samuel Macaleese for finding that bug)
3737//
3738// v 5.1 8 Oct 2007
3739// - renamed inverseModInt_ to inverseModInt since it doesn't change its parameters
3740// - added functions GCD and randBigInt, which call GCD_ and randBigInt_
3741// - fixed a bug found by Rob Visser (see comment with his name below)
3742// - improved comments
3743//
3744// This file is public domain. You can use it for any purpose without restriction.
3745// I do not guarantee that it is correct, so use it at your own risk. If you use
3746// it for something interesting, I'd appreciate hearing about it. If you find
3747// any bugs or make any improvements, I'd appreciate hearing about those too.
3748// It would also be nice if my name and URL were left in the comments. But none
3749// of that is required.
3750//
3751// This code defines a bigInt library for arbitrary-precision integers.
3752// A bigInt is an array of integers storing the value in chunks of bpe bits,
3753// little endian (buff[0] is the least significant word).
3754// Negative bigInts are stored two's complement. Almost all the functions treat
3755// bigInts as nonnegative. The few that view them as two's complement say so
3756// in their comments. Some functions assume their parameters have at least one
3757// leading zero element. Functions with an underscore at the end of the name put
3758// their answer into one of the arrays passed in, and have unpredictable behavior
3759// in case of overflow, so the caller must make sure the arrays are big enough to
3760// hold the answer. But the average user should never have to call any of the
3761// underscored functions. Each important underscored function has a wrapper function
3762// of the same name without the underscore that takes care of the details for you.
3763// For each underscored function where a parameter is modified, that same variable
3764// must not be used as another argument too. So, you cannot square x by doing
3765// multMod_(x,x,n). You must use squareMod_(x,n) instead, or do y=dup(x); multMod_(x,y,n).
3766// Or simply use the multMod(x,x,n) function without the underscore, where
3767// such issues never arise, because non-underscored functions never change
3768// their parameters; they always allocate new memory for the answer that is returned.
3769//
3770// These functions are designed to avoid frequent dynamic memory allocation in the inner loop.
3771// For most functions, if it needs a BigInt as a local variable it will actually use
3772// a global, and will only allocate to it only when it's not the right size. This ensures
3773// that when a function is called repeatedly with same-sized parameters, it only allocates
3774// memory on the first call.
3775//
3776// Note that for cryptographic purposes, the calls to Math.random() must
3777// be replaced with calls to a better pseudorandom number generator.
3778//
3779// In the following, "bigInt" means a bigInt with at least one leading zero element,
3780// and "integer" means a nonnegative integer less than radix. In some cases, integer
3781// can be negative. Negative bigInts are 2s complement.
3782//
3783// The following functions do not modify their inputs.
3784// Those returning a bigInt, string, or Array will dynamically allocate memory for that value.
3785// Those returning a boolean will return the integer 0 (false) or 1 (true).
3786// Those returning boolean or int will not allocate memory except possibly on the first
3787// time they're called with a given parameter size.
3788//
3789// bigInt add(x,y) //return (x+y) for bigInts x and y.
3790// bigInt addInt(x,n) //return (x+n) where x is a bigInt and n is an integer.
3791// string bigInt2str(x,base) //return a string form of bigInt x in a given base, with 2 <= base <= 95
3792// int bitSize(x) //return how many bits long the bigInt x is, not counting leading zeros
3793// bigInt dup(x) //return a copy of bigInt x
3794// boolean equals(x,y) //is the bigInt x equal to the bigint y?
3795// boolean equalsInt(x,y) //is bigint x equal to integer y?
3796// bigInt expand(x,n) //return a copy of x with at least n elements, adding leading zeros if needed
3797// Array findPrimes(n) //return array of all primes less than integer n
3798// bigInt GCD(x,y) //return greatest common divisor of bigInts x and y (each with same number of elements).
3799// boolean greater(x,y) //is x>y? (x and y are nonnegative bigInts)
3800// boolean greaterShift(x,y,shift)//is (x <<(shift*bpe)) > y?
3801// bigInt int2bigInt(t,n,m) //return a bigInt equal to integer t, with at least n bits and m array elements
3802// bigInt inverseMod(x,n) //return (x**(-1) mod n) for bigInts x and n. If no inverse exists, it returns null
3803// int inverseModInt(x,n) //return x**(-1) mod n, for integers x and n. Return 0 if there is no inverse
3804// boolean isZero(x) //is the bigInt x equal to zero?
3805// boolean millerRabin(x,b) //does one round of Miller-Rabin base integer b say that bigInt x is possibly prime? (b is bigInt, 1<b<x)
3806// boolean millerRabinInt(x,b) //does one round of Miller-Rabin base integer b say that bigInt x is possibly prime? (b is int, 1<b<x)
3807// bigInt mod(x,n) //return a new bigInt equal to (x mod n) for bigInts x and n.
3808// int modInt(x,n) //return x mod n for bigInt x and integer n.
3809// bigInt mult(x,y) //return x*y for bigInts x and y. This is faster when y<x.
3810// bigInt multMod(x,y,n) //return (x*y mod n) for bigInts x,y,n. For greater speed, let y<x.
3811// boolean negative(x) //is bigInt x negative?
3812// bigInt powMod(x,y,n) //return (x**y mod n) where x,y,n are bigInts and ** is exponentiation. 0**0=1. Faster for odd n.
3813// bigInt randBigInt(n,s) //return an n-bit random BigInt (n>=1). If s=1, then the most significant of those n bits is set to 1.
3814// bigInt randTruePrime(k) //return a new, random, k-bit, true prime bigInt using Maurer's algorithm.
3815// bigInt randProbPrime(k) //return a new, random, k-bit, probable prime bigInt (probability it's composite less than 2^-80).
3816// bigInt str2bigInt(s,b,n,m) //return a bigInt for number represented in string s in base b with at least n bits and m array elements
3817// bigInt sub(x,y) //return (x-y) for bigInts x and y. Negative answers will be 2s complement
3818// bigInt trim(x,k) //return a copy of x with exactly k leading zero elements
3819//
3820//
3821// The following functions each have a non-underscored version, which most users should call instead.
3822// These functions each write to a single parameter, and the caller is responsible for ensuring the array
3823// passed in is large enough to hold the result.
3824//
3825// void addInt_(x,n) //do x=x+n where x is a bigInt and n is an integer
3826// void add_(x,y) //do x=x+y for bigInts x and y
3827// void copy_(x,y) //do x=y on bigInts x and y
3828// void copyInt_(x,n) //do x=n on bigInt x and integer n
3829// void GCD_(x,y) //set x to the greatest common divisor of bigInts x and y, (y is destroyed). (This never overflows its array).
3830// boolean inverseMod_(x,n) //do x=x**(-1) mod n, for bigInts x and n. Returns 1 (0) if inverse does (doesn't) exist
3831// void mod_(x,n) //do x=x mod n for bigInts x and n. (This never overflows its array).
3832// void mult_(x,y) //do x=x*y for bigInts x and y.
3833// void multMod_(x,y,n) //do x=x*y mod n for bigInts x,y,n.
3834// void powMod_(x,y,n) //do x=x**y mod n, where x,y,n are bigInts (n is odd) and ** is exponentiation. 0**0=1.
3835// void randBigInt_(b,n,s) //do b = an n-bit random BigInt. if s=1, then nth bit (most significant bit) is set to 1. n>=1.
3836// void randTruePrime_(ans,k) //do ans = a random k-bit true random prime (not just probable prime) with 1 in the msb.
3837// void sub_(x,y) //do x=x-y for bigInts x and y. Negative answers will be 2s complement.
3838//
3839// The following functions do NOT have a non-underscored version.
3840// They each write a bigInt result to one or more parameters. The caller is responsible for
3841// ensuring the arrays passed in are large enough to hold the results.
3842//
3843// void addShift_(x,y,ys) //do x=x+(y<<(ys*bpe))
3844// void carry_(x) //do carries and borrows so each element of the bigInt x fits in bpe bits.
3845// void divide_(x,y,q,r) //divide x by y giving quotient q and remainder r
3846// int divInt_(x,n) //do x=floor(x/n) for bigInt x and integer n, and return the remainder. (This never overflows its array).
3847// int eGCD_(x,y,d,a,b) //sets a,b,d to positive bigInts such that d = GCD_(x,y) = a*x-b*y
3848// void halve_(x) //do x=floor(|x|/2)*sgn(x) for bigInt x in 2's complement. (This never overflows its array).
3849// void leftShift_(x,n) //left shift bigInt x by n bits. n<bpe.
3850// void linComb_(x,y,a,b) //do x=a*x+b*y for bigInts x and y and integers a and b
3851// void linCombShift_(x,y,b,ys) //do x=x+b*(y<<(ys*bpe)) for bigInts x and y, and integers b and ys
3852// void mont_(x,y,n,np) //Montgomery multiplication (see comments where the function is defined)
3853// void multInt_(x,n) //do x=x*n where x is a bigInt and n is an integer.
3854// void rightShift_(x,n) //right shift bigInt x by n bits. 0 <= n < bpe. (This never overflows its array).
3855// void squareMod_(x,n) //do x=x*x mod n for bigInts x,n
3856// void subShift_(x,y,ys) //do x=x-(y<<(ys*bpe)). Negative answers will be 2s complement.
3857//
3858// The following functions are based on algorithms from the _Handbook of Applied Cryptography_
3859// powMod_() = algorithm 14.94, Montgomery exponentiation
3860// eGCD_,inverseMod_() = algorithm 14.61, Binary extended GCD_
3861// GCD_() = algorothm 14.57, Lehmer's algorithm
3862// mont_() = algorithm 14.36, Montgomery multiplication
3863// divide_() = algorithm 14.20 Multiple-precision division
3864// squareMod_() = algorithm 14.16 Multiple-precision squaring
3865// randTruePrime_() = algorithm 4.62, Maurer's algorithm
3866// millerRabin() = algorithm 4.24, Miller-Rabin algorithm
3867//
3868// Profiling shows:
3869// randTruePrime_() spends:
3870// 10% of its time in calls to powMod_()
3871// 85% of its time in calls to millerRabin()
3872// millerRabin() spends:
3873// 99% of its time in calls to powMod_() (always with a base of 2)
3874// powMod_() spends:
3875// 94% of its time in calls to mont_() (almost always with x==y)
3876//
3877// This suggests there are several ways to speed up this library slightly:
3878// - convert powMod_ to use a Montgomery form of k-ary window (or maybe a Montgomery form of sliding window)
3879// -- this should especially focus on being fast when raising 2 to a power mod n
3880// - convert randTruePrime_() to use a minimum r of 1/3 instead of 1/2 with the appropriate change to the test
3881// - tune the parameters in randTruePrime_(), including c, m, and recLimit
3882// - speed up the single loop in mont_() that takes 95% of the runtime, perhaps by reducing checking
3883// within the loop when all the parameters are the same length.
3884//
3885// There are several ideas that look like they wouldn't help much at all:
3886// - replacing trial division in randTruePrime_() with a sieve (that speeds up something taking almost no time anyway)
3887// - increase bpe from 15 to 30 (that would help if we had a 32*32->64 multiplier, but not with JavaScript's 32*32->32)
3888// - speeding up mont_(x,y,n,np) when x==y by doing a non-modular, non-Montgomery square
3889// followed by a Montgomery reduction. The intermediate answer will be twice as long as x, so that
3890// method would be slower. This is unfortunate because the code currently spends almost all of its time
3891// doing mont_(x,x,...), both for randTruePrime_() and powMod_(). A faster method for Montgomery squaring
3892// would have a large impact on the speed of randTruePrime_() and powMod_(). HAC has a couple of poorly-worded
3893// sentences that seem to imply it's faster to do a non-modular square followed by a single
3894// Montgomery reduction, but that's obviously wrong.
3895////////////////////////////////////////////////////////////////////////////////////////
3896
3897//globals
3898var bpe = 0; //bits stored per array element
3899var mask = 0; //AND this with an array element to chop it down to bpe bits
3900var radix = mask + 1; //equals 2^bpe. A single 1 bit to the left of the last bit of mask.
3901
3902//the digits for converting to different bases
3903var digitsStr = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_=!@#$%^&*()[]{}|;:,.<>/?`~ \\\'\"+-';
3904
3905//initialize the global variables
3906for (bpe = 0; 1 << bpe + 1 > 1 << bpe; bpe++); //bpe=number of bits in the mantissa on this platform
3907bpe >>= 1; //bpe=number of bits in one element of the array representing the bigInt
3908mask = (1 << bpe) - 1; //AND the mask with an integer to get its bpe least significant bits
3909radix = mask + 1; //2^bpe. a single 1 bit to the left of the first bit of mask
3910var one = int2bigInt(1, 1, 1); //constant used in powMod_()
3911
3912//the following global variables are scratchpad memory to
3913//reduce dynamic memory allocation in the inner loop
3914var t = new Array(0);
3915var ss = t; //used in mult_()
3916var s0 = t; //used in multMod_(), squareMod_()
3917var s1 = t; //used in powMod_(), multMod_(), squareMod_()
3918var s2 = t; //used in powMod_(), multMod_()
3919var s3 = t; //used in powMod_()
3920var s4 = t,
3921 s5 = t; //used in mod_()
3922var s6 = t; //used in bigInt2str()
3923var s7 = t; //used in powMod_()
3924var T = t; //used in GCD_()
3925var sa = t; //used in mont_()
3926var mr_x1 = t,
3927 mr_r = t,
3928 mr_a = t,
3929 //used in millerRabin()
3930eg_v = t,
3931 eg_u = t,
3932 eg_A = t,
3933 eg_B = t,
3934 eg_C = t,
3935 eg_D = t,
3936 //used in eGCD_(), inverseMod_()
3937md_q1 = t,
3938 md_q2 = t,
3939 md_q3 = t,
3940 md_r = t,
3941 md_r1 = t,
3942 md_r2 = t,
3943 md_tt = t,
3944 //used in mod_()
3945
3946primes = t,
3947 pows = t,
3948 s_i = t,
3949 s_i2 = t,
3950 s_R = t,
3951 s_rm = t,
3952 s_q = t,
3953 s_n1 = t,
3954 s_a = t,
3955 s_r2 = t,
3956 s_n = t,
3957 s_b = t,
3958 s_d = t,
3959 s_x1 = t,
3960 s_x2 = t,
3961 s_aa = t,
3962 //used in randTruePrime_()
3963
3964rpprb = t; //used in randProbPrimeRounds() (which also uses "primes")
3965
3966////////////////////////////////////////////////////////////////////////////////////////
3967
3968var k, buff;
3969
3970//return array of all primes less than integer n
3971function findPrimes(n) {
3972 var i, s, p, ans;
3973 s = new Array(n);
3974 for (i = 0; i < n; i++) s[i] = 0;
3975 s[0] = 2;
3976 p = 0; //first p elements of s are primes, the rest are a sieve
3977 for (; s[p] < n;) {
3978 //s[p] is the pth prime
3979 for (i = s[p] * s[p]; i < n; i += s[p]) //mark multiples of s[p]
3980 s[i] = 1;
3981 p++;
3982 s[p] = s[p - 1] + 1;
3983 for (; s[p] < n && s[s[p]]; s[p]++); //find next prime (where s[p]==0)
3984 }
3985 ans = new Array(p);
3986 for (i = 0; i < p; i++) ans[i] = s[i];
3987 return ans;
3988}
3989
3990//does a single round of Miller-Rabin base b consider x to be a possible prime?
3991//x is a bigInt, and b is an integer, with b<x
3992function millerRabinInt(x, b) {
3993 if (mr_x1.length != x.length) {
3994 mr_x1 = dup(x);
3995 mr_r = dup(x);
3996 mr_a = dup(x);
3997 }
3998
3999 copyInt_(mr_a, b);
4000 return millerRabin(x, mr_a);
4001}
4002
4003//does a single round of Miller-Rabin base b consider x to be a possible prime?
4004//x and b are bigInts with b<x
4005function millerRabin(x, b) {
4006 var i, j, k, s;
4007
4008 if (mr_x1.length != x.length) {
4009 mr_x1 = dup(x);
4010 mr_r = dup(x);
4011 mr_a = dup(x);
4012 }
4013
4014 copy_(mr_a, b);
4015 copy_(mr_r, x);
4016 copy_(mr_x1, x);
4017
4018 addInt_(mr_r, -1);
4019 addInt_(mr_x1, -1);
4020
4021 //s=the highest power of two that divides mr_r
4022 k = 0;
4023 for (i = 0; i < mr_r.length; i++) for (j = 1; j < mask; j <<= 1) if (x[i] & j) {
4024 s = k < mr_r.length + bpe ? k : 0;
4025 i = mr_r.length;
4026 j = mask;
4027 } else k++;
4028
4029 if (s) rightShift_(mr_r, s);
4030
4031 powMod_(mr_a, mr_r, x);
4032
4033 if (!equalsInt(mr_a, 1) && !equals(mr_a, mr_x1)) {
4034 j = 1;
4035 while (j <= s - 1 && !equals(mr_a, mr_x1)) {
4036 squareMod_(mr_a, x);
4037 if (equalsInt(mr_a, 1)) {
4038 return 0;
4039 }
4040 j++;
4041 }
4042 if (!equals(mr_a, mr_x1)) {
4043 return 0;
4044 }
4045 }
4046 return 1;
4047}
4048
4049//returns how many bits long the bigInt is, not counting leading zeros.
4050function bitSize(x) {
4051 var j, z, w;
4052 for (j = x.length - 1; x[j] == 0 && j > 0; j--);
4053 for (z = 0, w = x[j]; w; w >>= 1, z++);
4054 z += bpe * j;
4055 return z;
4056}
4057
4058//return a copy of x with at least n elements, adding leading zeros if needed
4059function expand(x, n) {
4060 var ans = int2bigInt(0, (x.length > n ? x.length : n) * bpe, 0);
4061 copy_(ans, x);
4062 return ans;
4063}
4064
4065//return a k-bit true random prime using Maurer's algorithm.
4066function randTruePrime(k) {
4067 var ans = int2bigInt(0, k, 0);
4068 randTruePrime_(ans, k);
4069 return trim(ans, 1);
4070}
4071
4072//return a k-bit random probable prime with probability of error < 2^-80
4073function randProbPrime(k) {
4074 if (k >= 600) return randProbPrimeRounds(k, 2); //numbers from HAC table 4.3
4075 if (k >= 550) return randProbPrimeRounds(k, 4);
4076 if (k >= 500) return randProbPrimeRounds(k, 5);
4077 if (k >= 400) return randProbPrimeRounds(k, 6);
4078 if (k >= 350) return randProbPrimeRounds(k, 7);
4079 if (k >= 300) return randProbPrimeRounds(k, 9);
4080 if (k >= 250) return randProbPrimeRounds(k, 12); //numbers from HAC table 4.4
4081 if (k >= 200) return randProbPrimeRounds(k, 15);
4082 if (k >= 150) return randProbPrimeRounds(k, 18);
4083 if (k >= 100) return randProbPrimeRounds(k, 27);
4084 return randProbPrimeRounds(k, 40); //number from HAC remark 4.26 (only an estimate)
4085}
4086
4087//return a k-bit probable random prime using n rounds of Miller Rabin (after trial division with small primes)
4088function randProbPrimeRounds(k, n) {
4089 var ans, i, divisible, B;
4090 B = 30000; //B is largest prime to use in trial division
4091 ans = int2bigInt(0, k, 0);
4092
4093 //optimization: try larger and smaller B to find the best limit.
4094
4095 if (primes.length == 0) primes = findPrimes(30000); //check for divisibility by primes <=30000
4096
4097 if (rpprb.length != ans.length) rpprb = dup(ans);
4098
4099 for (;;) {
4100 //keep trying random values for ans until one appears to be prime
4101 //optimization: pick a random number times L=2*3*5*...*p, plus a
4102 // random element of the list of all numbers in [0,L) not divisible by any prime up to p.
4103 // This can reduce the amount of random number generation.
4104
4105 randBigInt_(ans, k, 0); //ans = a random odd number to check
4106 ans[0] |= 1;
4107 divisible = 0;
4108
4109 //check ans for divisibility by small primes up to B
4110 for (i = 0; i < primes.length && primes[i] <= B; i++) if (modInt(ans, primes[i]) == 0 && !equalsInt(ans, primes[i])) {
4111 divisible = 1;
4112 break;
4113 }
4114
4115 //optimization: change millerRabin so the base can be bigger than the number being checked, then eliminate the while here.
4116
4117 //do n rounds of Miller Rabin, with random bases less than ans
4118 for (i = 0; i < n && !divisible; i++) {
4119 randBigInt_(rpprb, k, 0);
4120 while (!greater(ans, rpprb)) //pick a random rpprb that's < ans
4121 randBigInt_(rpprb, k, 0);
4122 if (!millerRabin(ans, rpprb)) divisible = 1;
4123 }
4124
4125 if (!divisible) return ans;
4126 }
4127}
4128
4129//return a new bigInt equal to (x mod n) for bigInts x and n.
4130function mod(x, n) {
4131 var ans = dup(x);
4132 mod_(ans, n);
4133 return trim(ans, 1);
4134}
4135
4136//return (x+n) where x is a bigInt and n is an integer.
4137function addInt(x, n) {
4138 var ans = expand(x, x.length + 1);
4139 addInt_(ans, n);
4140 return trim(ans, 1);
4141}
4142
4143//return x*y for bigInts x and y. This is faster when y<x.
4144function mult(x, y) {
4145 var ans = expand(x, x.length + y.length);
4146 mult_(ans, y);
4147 return trim(ans, 1);
4148}
4149
4150//return (x**y mod n) where x,y,n are bigInts and ** is exponentiation. 0**0=1. Faster for odd n.
4151function powMod(x, y, n) {
4152 var ans = expand(x, n.length);
4153 powMod_(ans, trim(y, 2), trim(n, 2), 0); //this should work without the trim, but doesn't
4154 return trim(ans, 1);
4155}
4156
4157//return (x-y) for bigInts x and y. Negative answers will be 2s complement
4158function sub(x, y) {
4159 var ans = expand(x, x.length > y.length ? x.length + 1 : y.length + 1);
4160 sub_(ans, y);
4161 return trim(ans, 1);
4162}
4163
4164//return (x+y) for bigInts x and y.
4165function add(x, y) {
4166 var ans = expand(x, x.length > y.length ? x.length + 1 : y.length + 1);
4167 add_(ans, y);
4168 return trim(ans, 1);
4169}
4170
4171//return (x**(-1) mod n) for bigInts x and n. If no inverse exists, it returns null
4172function inverseMod(x, n) {
4173 var ans = expand(x, n.length);
4174 var s;
4175 s = inverseMod_(ans, n);
4176 return s ? trim(ans, 1) : null;
4177}
4178
4179//return (x*y mod n) for bigInts x,y,n. For greater speed, let y<x.
4180function multMod(x, y, n) {
4181 var ans = expand(x, n.length);
4182 multMod_(ans, y, n);
4183 return trim(ans, 1);
4184}
4185
4186//generate a k-bit true random prime using Maurer's algorithm,
4187//and put it into ans. The bigInt ans must be large enough to hold it.
4188function randTruePrime_(ans, k) {
4189 var c, m, pm, dd, j, r, B, divisible, z, zz, recSize;
4190
4191 if (primes.length == 0) primes = findPrimes(30000); //check for divisibility by primes <=30000
4192
4193 if (pows.length == 0) {
4194 pows = new Array(512);
4195 for (j = 0; j < 512; j++) {
4196 pows[j] = Math.pow(2, j / 511. - 1.);
4197 }
4198 }
4199
4200 //c and m should be tuned for a particular machine and value of k, to maximize speed
4201 c = 0.1; //c=0.1 in HAC
4202 m = 20; //generate this k-bit number by first recursively generating a number that has between k/2 and k-m bits
4203 recLimit = 20; //stop recursion when k <=recLimit. Must have recLimit >= 2
4204
4205 if (s_i2.length != ans.length) {
4206 s_i2 = dup(ans);
4207 s_R = dup(ans);
4208 s_n1 = dup(ans);
4209 s_r2 = dup(ans);
4210 s_d = dup(ans);
4211 s_x1 = dup(ans);
4212 s_x2 = dup(ans);
4213 s_b = dup(ans);
4214 s_n = dup(ans);
4215 s_i = dup(ans);
4216 s_rm = dup(ans);
4217 s_q = dup(ans);
4218 s_a = dup(ans);
4219 s_aa = dup(ans);
4220 }
4221
4222 if (k <= recLimit) {
4223 //generate small random primes by trial division up to its square root
4224 pm = (1 << (k + 2 >> 1)) - 1; //pm is binary number with all ones, just over sqrt(2^k)
4225 copyInt_(ans, 0);
4226 for (dd = 1; dd;) {
4227 dd = 0;
4228 ans[0] = 1 | 1 << k - 1 | Math.floor(Math.random() * (1 << k)); //random, k-bit, odd integer, with msb 1
4229 for (j = 1; j < primes.length && (primes[j] & pm) == primes[j]; j++) {
4230 //trial division by all primes 3...sqrt(2^k)
4231 if (0 == ans[0] % primes[j]) {
4232 dd = 1;
4233 break;
4234 }
4235 }
4236 }
4237 carry_(ans);
4238 return;
4239 }
4240
4241 B = c * k * k; //try small primes up to B (or all the primes[] array if the largest is less than B).
4242 if (k > 2 * m) //generate this k-bit number by first recursively generating a number that has between k/2 and k-m bits
4243 for (r = 1; k - k * r <= m;) r = pows[Math.floor(Math.random() * 512)]; //r=Math.pow(2,Math.random()-1);
4244 else r = .5;
4245
4246 //simulation suggests the more complex algorithm using r=.333 is only slightly faster.
4247
4248 recSize = Math.floor(r * k) + 1;
4249
4250 randTruePrime_(s_q, recSize);
4251 copyInt_(s_i2, 0);
4252 s_i2[Math.floor((k - 2) / bpe)] |= 1 << (k - 2) % bpe; //s_i2=2^(k-2)
4253 divide_(s_i2, s_q, s_i, s_rm); //s_i=floor((2^(k-1))/(2q))
4254
4255 z = bitSize(s_i);
4256
4257 for (;;) {
4258 for (;;) {
4259 //generate z-bit numbers until one falls in the range [0,s_i-1]
4260 randBigInt_(s_R, z, 0);
4261 if (greater(s_i, s_R)) break;
4262 } //now s_R is in the range [0,s_i-1]
4263 addInt_(s_R, 1); //now s_R is in the range [1,s_i]
4264 add_(s_R, s_i); //now s_R is in the range [s_i+1,2*s_i]
4265
4266 copy_(s_n, s_q);
4267 mult_(s_n, s_R);
4268 multInt_(s_n, 2);
4269 addInt_(s_n, 1); //s_n=2*s_R*s_q+1
4270
4271 copy_(s_r2, s_R);
4272 multInt_(s_r2, 2); //s_r2=2*s_R
4273
4274 //check s_n for divisibility by small primes up to B
4275 for (divisible = 0, j = 0; j < primes.length && primes[j] < B; j++) if (modInt(s_n, primes[j]) == 0 && !equalsInt(s_n, primes[j])) {
4276 divisible = 1;
4277 break;
4278 }
4279
4280 if (!divisible) //if it passes small primes check, then try a single Miller-Rabin base 2
4281 if (!millerRabinInt(s_n, 2)) //this line represents 75% of the total runtime for randTruePrime_
4282 divisible = 1;
4283
4284 if (!divisible) {
4285 //if it passes that test, continue checking s_n
4286 addInt_(s_n, -3);
4287 for (j = s_n.length - 1; s_n[j] == 0 && j > 0; j--); //strip leading zeros
4288 for (zz = 0, w = s_n[j]; w; w >>= 1, zz++);
4289 zz += bpe * j; //zz=number of bits in s_n, ignoring leading zeros
4290 for (;;) {
4291 //generate z-bit numbers until one falls in the range [0,s_n-1]
4292 randBigInt_(s_a, zz, 0);
4293 if (greater(s_n, s_a)) break;
4294 } //now s_a is in the range [0,s_n-1]
4295 addInt_(s_n, 3); //now s_a is in the range [0,s_n-4]
4296 addInt_(s_a, 2); //now s_a is in the range [2,s_n-2]
4297 copy_(s_b, s_a);
4298 copy_(s_n1, s_n);
4299 addInt_(s_n1, -1);
4300 powMod_(s_b, s_n1, s_n); //s_b=s_a^(s_n-1) modulo s_n
4301 addInt_(s_b, -1);
4302 if (isZero(s_b)) {
4303 copy_(s_b, s_a);
4304 powMod_(s_b, s_r2, s_n);
4305 addInt_(s_b, -1);
4306 copy_(s_aa, s_n);
4307 copy_(s_d, s_b);
4308 GCD_(s_d, s_n); //if s_b and s_n are relatively prime, then s_n is a prime
4309 if (equalsInt(s_d, 1)) {
4310 copy_(ans, s_aa);
4311 return; //if we've made it this far, then s_n is absolutely guaranteed to be prime
4312 }
4313 }
4314 }
4315 }
4316}
4317
4318//Return an n-bit random BigInt (n>=1). If s=1, then the most significant of those n bits is set to 1.
4319function randBigInt(n, s) {
4320 var a, b;
4321 a = Math.floor((n - 1) / bpe) + 2; //# array elements to hold the BigInt with a leading 0 element
4322 b = int2bigInt(0, 0, a);
4323 randBigInt_(b, n, s);
4324 return b;
4325}
4326
4327//Set b to an n-bit random BigInt. If s=1, then the most significant of those n bits is set to 1.
4328//Array b must be big enough to hold the result. Must have n>=1
4329function randBigInt_(b, n, s) {
4330 var i, a;
4331 for (i = 0; i < b.length; i++) b[i] = 0;
4332 a = Math.floor((n - 1) / bpe) + 1; //# array elements to hold the BigInt
4333 for (i = 0; i < a; i++) {
4334 b[i] = Math.floor(Math.random() * (1 << bpe - 1));
4335 }
4336 b[a - 1] &= (2 << (n - 1) % bpe) - 1;
4337 if (s == 1) b[a - 1] |= 1 << (n - 1) % bpe;
4338}
4339
4340//Return the greatest common divisor of bigInts x and y (each with same number of elements).
4341function GCD(x, y) {
4342 var xc, yc;
4343 xc = dup(x);
4344 yc = dup(y);
4345 GCD_(xc, yc);
4346 return xc;
4347}
4348
4349//set x to the greatest common divisor of bigInts x and y (each with same number of elements).
4350//y is destroyed.
4351function GCD_(x, y) {
4352 var i, xp, yp, A, B, C, D, q, sing;
4353 if (T.length != x.length) T = dup(x);
4354
4355 sing = 1;
4356 while (sing) {
4357 //while y has nonzero elements other than y[0]
4358 sing = 0;
4359 for (i = 1; i < y.length; i++) //check if y has nonzero elements other than 0
4360 if (y[i]) {
4361 sing = 1;
4362 break;
4363 }
4364 if (!sing) break; //quit when y all zero elements except possibly y[0]
4365
4366 for (i = x.length; !x[i] && i >= 0; i--); //find most significant element of x
4367 xp = x[i];
4368 yp = y[i];
4369 A = 1;B = 0;C = 0;D = 1;
4370 while (yp + C && yp + D) {
4371 q = Math.floor((xp + A) / (yp + C));
4372 qp = Math.floor((xp + B) / (yp + D));
4373 if (q != qp) break;
4374 t = A - q * C;A = C;C = t; // do (A,B,xp, C,D,yp) = (C,D,yp, A,B,xp) - q*(0,0,0, C,D,yp)
4375 t = B - q * D;B = D;D = t;
4376 t = xp - q * yp;xp = yp;yp = t;
4377 }
4378 if (B) {
4379 copy_(T, x);
4380 linComb_(x, y, A, B); //x=A*x+B*y
4381 linComb_(y, T, D, C); //y=D*y+C*T
4382 } else {
4383 mod_(x, y);
4384 copy_(T, x);
4385 copy_(x, y);
4386 copy_(y, T);
4387 }
4388 }
4389 if (y[0] == 0) return;
4390 t = modInt(x, y[0]);
4391 copyInt_(x, y[0]);
4392 y[0] = t;
4393 while (y[0]) {
4394 x[0] %= y[0];
4395 t = x[0];x[0] = y[0];y[0] = t;
4396 }
4397}
4398
4399//do x=x**(-1) mod n, for bigInts x and n.
4400//If no inverse exists, it sets x to zero and returns 0, else it returns 1.
4401//The x array must be at least as large as the n array.
4402function inverseMod_(x, n) {
4403 var k = 1 + 2 * Math.max(x.length, n.length);
4404
4405 if (!(x[0] & 1) && !(n[0] & 1)) {
4406 //if both inputs are even, then inverse doesn't exist
4407 copyInt_(x, 0);
4408 return 0;
4409 }
4410
4411 if (eg_u.length != k) {
4412 eg_u = new Array(k);
4413 eg_v = new Array(k);
4414 eg_A = new Array(k);
4415 eg_B = new Array(k);
4416 eg_C = new Array(k);
4417 eg_D = new Array(k);
4418 }
4419
4420 copy_(eg_u, x);
4421 copy_(eg_v, n);
4422 copyInt_(eg_A, 1);
4423 copyInt_(eg_B, 0);
4424 copyInt_(eg_C, 0);
4425 copyInt_(eg_D, 1);
4426 for (;;) {
4427 while (!(eg_u[0] & 1)) {
4428 //while eg_u is even
4429 halve_(eg_u);
4430 if (!(eg_A[0] & 1) && !(eg_B[0] & 1)) {
4431 //if eg_A==eg_B==0 mod 2
4432 halve_(eg_A);
4433 halve_(eg_B);
4434 } else {
4435 add_(eg_A, n);halve_(eg_A);
4436 sub_(eg_B, x);halve_(eg_B);
4437 }
4438 }
4439
4440 while (!(eg_v[0] & 1)) {
4441 //while eg_v is even
4442 halve_(eg_v);
4443 if (!(eg_C[0] & 1) && !(eg_D[0] & 1)) {
4444 //if eg_C==eg_D==0 mod 2
4445 halve_(eg_C);
4446 halve_(eg_D);
4447 } else {
4448 add_(eg_C, n);halve_(eg_C);
4449 sub_(eg_D, x);halve_(eg_D);
4450 }
4451 }
4452
4453 if (!greater(eg_v, eg_u)) {
4454 //eg_v <= eg_u
4455 sub_(eg_u, eg_v);
4456 sub_(eg_A, eg_C);
4457 sub_(eg_B, eg_D);
4458 } else {
4459 //eg_v > eg_u
4460 sub_(eg_v, eg_u);
4461 sub_(eg_C, eg_A);
4462 sub_(eg_D, eg_B);
4463 }
4464
4465 if (equalsInt(eg_u, 0)) {
4466 while (negative(eg_C)) //make sure answer is nonnegative
4467 add_(eg_C, n);
4468 copy_(x, eg_C);
4469
4470 if (!equalsInt(eg_v, 1)) {
4471 //if GCD_(x,n)!=1, then there is no inverse
4472 copyInt_(x, 0);
4473 return 0;
4474 }
4475 return 1;
4476 }
4477 }
4478}
4479
4480//return x**(-1) mod n, for integers x and n. Return 0 if there is no inverse
4481function inverseModInt(x, n) {
4482 var a = 1,
4483 b = 0,
4484 t;
4485 for (;;) {
4486 if (x == 1) return a;
4487 if (x == 0) return 0;
4488 b -= a * Math.floor(n / x);
4489 n %= x;
4490
4491 if (n == 1) return b; //to avoid negatives, change this b to n-b, and each -= to +=
4492 if (n == 0) return 0;
4493 a -= b * Math.floor(x / n);
4494 x %= n;
4495 }
4496}
4497
4498//this deprecated function is for backward compatibility only.
4499function inverseModInt_(x, n) {
4500 return inverseModInt(x, n);
4501}
4502
4503//Given positive bigInts x and y, change the bigints v, a, and b to positive bigInts such that:
4504// v = GCD_(x,y) = a*x-b*y
4505//The bigInts v, a, b, must have exactly as many elements as the larger of x and y.
4506function eGCD_(x, y, v, a, b) {
4507 var g = 0;
4508 var k = Math.max(x.length, y.length);
4509 if (eg_u.length != k) {
4510 eg_u = new Array(k);
4511 eg_A = new Array(k);
4512 eg_B = new Array(k);
4513 eg_C = new Array(k);
4514 eg_D = new Array(k);
4515 }
4516 while (!(x[0] & 1) && !(y[0] & 1)) {
4517 //while x and y both even
4518 halve_(x);
4519 halve_(y);
4520 g++;
4521 }
4522 copy_(eg_u, x);
4523 copy_(v, y);
4524 copyInt_(eg_A, 1);
4525 copyInt_(eg_B, 0);
4526 copyInt_(eg_C, 0);
4527 copyInt_(eg_D, 1);
4528 for (;;) {
4529 while (!(eg_u[0] & 1)) {
4530 //while u is even
4531 halve_(eg_u);
4532 if (!(eg_A[0] & 1) && !(eg_B[0] & 1)) {
4533 //if A==B==0 mod 2
4534 halve_(eg_A);
4535 halve_(eg_B);
4536 } else {
4537 add_(eg_A, y);halve_(eg_A);
4538 sub_(eg_B, x);halve_(eg_B);
4539 }
4540 }
4541
4542 while (!(v[0] & 1)) {
4543 //while v is even
4544 halve_(v);
4545 if (!(eg_C[0] & 1) && !(eg_D[0] & 1)) {
4546 //if C==D==0 mod 2
4547 halve_(eg_C);
4548 halve_(eg_D);
4549 } else {
4550 add_(eg_C, y);halve_(eg_C);
4551 sub_(eg_D, x);halve_(eg_D);
4552 }
4553 }
4554
4555 if (!greater(v, eg_u)) {
4556 //v<=u
4557 sub_(eg_u, v);
4558 sub_(eg_A, eg_C);
4559 sub_(eg_B, eg_D);
4560 } else {
4561 //v>u
4562 sub_(v, eg_u);
4563 sub_(eg_C, eg_A);
4564 sub_(eg_D, eg_B);
4565 }
4566 if (equalsInt(eg_u, 0)) {
4567 while (negative(eg_C)) {
4568 //make sure a (C) is nonnegative
4569 add_(eg_C, y);
4570 sub_(eg_D, x);
4571 }
4572 multInt_(eg_D, -1); ///make sure b (D) is nonnegative
4573 copy_(a, eg_C);
4574 copy_(b, eg_D);
4575 leftShift_(v, g);
4576 return;
4577 }
4578 }
4579}
4580
4581//is bigInt x negative?
4582function negative(x) {
4583 return x[x.length - 1] >> bpe - 1 & 1;
4584}
4585
4586//is (x << (shift*bpe)) > y?
4587//x and y are nonnegative bigInts
4588//shift is a nonnegative integer
4589function greaterShift(x, y, shift) {
4590 var i,
4591 kx = x.length,
4592 ky = y.length;
4593 k = kx + shift < ky ? kx + shift : ky;
4594 for (i = ky - 1 - shift; i < kx && i >= 0; i++) if (x[i] > 0) return 1; //if there are nonzeros in x to the left of the first column of y, then x is bigger
4595 for (i = kx - 1 + shift; i < ky; i++) if (y[i] > 0) return 0; //if there are nonzeros in y to the left of the first column of x, then x is not bigger
4596 for (i = k - 1; i >= shift; i--) if (x[i - shift] > y[i]) return 1;else if (x[i - shift] < y[i]) return 0;
4597 return 0;
4598}
4599
4600//is x > y? (x and y both nonnegative)
4601function greater(x, y) {
4602 var i;
4603 var k = x.length < y.length ? x.length : y.length;
4604
4605 for (i = x.length; i < y.length; i++) if (y[i]) return 0; //y has more digits
4606
4607 for (i = y.length; i < x.length; i++) if (x[i]) return 1; //x has more digits
4608
4609 for (i = k - 1; i >= 0; i--) if (x[i] > y[i]) return 1;else if (x[i] < y[i]) return 0;
4610 return 0;
4611}
4612
4613//divide x by y giving quotient q and remainder r. (q=floor(x/y), r=x mod y). All 4 are bigints.
4614//x must have at least one leading zero element.
4615//y must be nonzero.
4616//q and r must be arrays that are exactly the same length as x. (Or q can have more).
4617//Must have x.length >= y.length >= 2.
4618function divide_(x, y, q, r) {
4619 var kx, ky;
4620 var i, j, y1, y2, c, a, b;
4621 copy_(r, x);
4622 for (ky = y.length; y[ky - 1] == 0; ky--); //ky is number of elements in y, not including leading zeros
4623
4624 //normalize: ensure the most significant element of y has its highest bit set
4625 b = y[ky - 1];
4626 for (a = 0; b; a++) b >>= 1;
4627 a = bpe - a; //a is how many bits to shift so that the high order bit of y is leftmost in its array element
4628 leftShift_(y, a); //multiply both by 1<<a now, then divide both by that at the end
4629 leftShift_(r, a);
4630
4631 //Rob Visser discovered a bug: the following line was originally just before the normalization.
4632 for (kx = r.length; r[kx - 1] == 0 && kx > ky; kx--); //kx is number of elements in normalized x, not including leading zeros
4633
4634 copyInt_(q, 0); // q=0
4635 while (!greaterShift(y, r, kx - ky)) {
4636 // while (leftShift_(y,kx-ky) <= r) {
4637 subShift_(r, y, kx - ky); // r=r-leftShift_(y,kx-ky)
4638 q[kx - ky]++; // q[kx-ky]++;
4639 } // }
4640
4641 for (i = kx - 1; i >= ky; i--) {
4642 if (r[i] == y[ky - 1]) q[i - ky] = mask;else q[i - ky] = Math.floor((r[i] * radix + r[i - 1]) / y[ky - 1]);
4643
4644 //The following for(;;) loop is equivalent to the commented while loop,
4645 //except that the uncommented version avoids overflow.
4646 //The commented loop comes from HAC, which assumes r[-1]==y[-1]==0
4647 // while (q[i-ky]*(y[ky-1]*radix+y[ky-2]) > r[i]*radix*radix+r[i-1]*radix+r[i-2])
4648 // q[i-ky]--;
4649 for (;;) {
4650 y2 = (ky > 1 ? y[ky - 2] : 0) * q[i - ky];
4651 c = y2 >> bpe;
4652 y2 = y2 & mask;
4653 y1 = c + q[i - ky] * y[ky - 1];
4654 c = y1 >> bpe;
4655 y1 = y1 & mask;
4656
4657 if (c == r[i] ? y1 == r[i - 1] ? y2 > (i > 1 ? r[i - 2] : 0) : y1 > r[i - 1] : c > r[i]) q[i - ky]--;else break;
4658 }
4659
4660 linCombShift_(r, y, -q[i - ky], i - ky); //r=r-q[i-ky]*leftShift_(y,i-ky)
4661 if (negative(r)) {
4662 addShift_(r, y, i - ky); //r=r+leftShift_(y,i-ky)
4663 q[i - ky]--;
4664 }
4665 }
4666
4667 rightShift_(y, a); //undo the normalization step
4668 rightShift_(r, a); //undo the normalization step
4669}
4670
4671//do carries and borrows so each element of the bigInt x fits in bpe bits.
4672function carry_(x) {
4673 var i, k, c, b;
4674 k = x.length;
4675 c = 0;
4676 for (i = 0; i < k; i++) {
4677 c += x[i];
4678 b = 0;
4679 if (c < 0) {
4680 b = -(c >> bpe);
4681 c += b * radix;
4682 }
4683 x[i] = c & mask;
4684 c = (c >> bpe) - b;
4685 }
4686}
4687
4688//return x mod n for bigInt x and integer n.
4689function modInt(x, n) {
4690 var i,
4691 c = 0;
4692 for (i = x.length - 1; i >= 0; i--) c = (c * radix + x[i]) % n;
4693 return c;
4694}
4695
4696//convert the integer t into a bigInt with at least the given number of bits.
4697//the returned array stores the bigInt in bpe-bit chunks, little endian (buff[0] is least significant word)
4698//Pad the array with leading zeros so that it has at least minSize elements.
4699//There will always be at least one leading 0 element.
4700function int2bigInt(t, bits, minSize) {
4701 var i, k;
4702 k = Math.ceil(bits / bpe) + 1;
4703 k = minSize > k ? minSize : k;
4704 var buff = new Array(k);
4705 copyInt_(buff, t);
4706 return buff;
4707}
4708
4709//return the bigInt given a string representation in a given base.
4710//Pad the array with leading zeros so that it has at least minSize elements.
4711//If base=-1, then it reads in a space-separated list of array elements in decimal.
4712//The array will always have at least one leading zero, unless base=-1.
4713function str2bigInt(s, base, minSize) {
4714 var d, i, j, x, y, kk;
4715 var k = s.length;
4716 if (base == -1) {
4717 //comma-separated list of array elements in decimal
4718 x = new Array(0);
4719 for (;;) {
4720 y = new Array(x.length + 1);
4721 for (i = 0; i < x.length; i++) y[i + 1] = x[i];
4722 y[0] = parseInt(s, 10);
4723 x = y;
4724 d = s.indexOf(',', 0);
4725 if (d < 1) break;
4726 s = s.substring(d + 1);
4727 if (s.length == 0) break;
4728 }
4729 if (x.length < minSize) {
4730 y = new Array(minSize);
4731 copy_(y, x);
4732 return y;
4733 }
4734 return x;
4735 }
4736
4737 x = int2bigInt(0, base * k, 0);
4738 for (i = 0; i < k; i++) {
4739 d = digitsStr.indexOf(s.substring(i, i + 1), 0);
4740 if (base <= 36 && d >= 36) //convert lowercase to uppercase if base<=36
4741 d -= 26;
4742 if (d >= base || d < 0) {
4743 //stop at first illegal character
4744 break;
4745 }
4746 multInt_(x, base);
4747 addInt_(x, d);
4748 }
4749
4750 for (k = x.length; k > 0 && !x[k - 1]; k--); //strip off leading zeros
4751 k = minSize > k + 1 ? minSize : k + 1;
4752 y = new Array(k);
4753 kk = k < x.length ? k : x.length;
4754 for (i = 0; i < kk; i++) y[i] = x[i];
4755 for (; i < k; i++) y[i] = 0;
4756 return y;
4757}
4758
4759//is bigint x equal to integer y?
4760//y must have less than bpe bits
4761function equalsInt(x, y) {
4762 var i;
4763 if (x[0] != y) return 0;
4764 for (i = 1; i < x.length; i++) if (x[i]) return 0;
4765 return 1;
4766}
4767
4768//are bigints x and y equal?
4769//this works even if x and y are different lengths and have arbitrarily many leading zeros
4770function equals(x, y) {
4771 var i;
4772 var k = x.length < y.length ? x.length : y.length;
4773 for (i = 0; i < k; i++) if (x[i] != y[i]) return 0;
4774 if (x.length > y.length) {
4775 for (; i < x.length; i++) if (x[i]) return 0;
4776 } else {
4777 for (; i < y.length; i++) if (y[i]) return 0;
4778 }
4779 return 1;
4780}
4781
4782//is the bigInt x equal to zero?
4783function isZero(x) {
4784 var i;
4785 for (i = 0; i < x.length; i++) if (x[i]) return 0;
4786 return 1;
4787}
4788
4789//convert a bigInt into a string in a given base, from base 2 up to base 95.
4790//Base -1 prints the contents of the array representing the number.
4791function bigInt2str(x, base) {
4792 var i,
4793 t,
4794 s = "";
4795
4796 if (s6.length != x.length) s6 = dup(x);else copy_(s6, x);
4797
4798 if (base == -1) {
4799 //return the list of array contents
4800 for (i = x.length - 1; i > 0; i--) s += x[i] + ',';
4801 s += x[0];
4802 } else {
4803 //return it in the given base
4804 while (!isZero(s6)) {
4805 t = divInt_(s6, base); //t=s6 % base; s6=floor(s6/base);
4806 s = digitsStr.substring(t, t + 1) + s;
4807 }
4808 }
4809 if (s.length == 0) s = "0";
4810 return s;
4811}
4812
4813//returns a duplicate of bigInt x
4814function dup(x) {
4815 var i;
4816 buff = new Array(x.length);
4817 copy_(buff, x);
4818 return buff;
4819}
4820
4821//do x=y on bigInts x and y. x must be an array at least as big as y (not counting the leading zeros in y).
4822function copy_(x, y) {
4823 var i;
4824 var k = x.length < y.length ? x.length : y.length;
4825 for (i = 0; i < k; i++) x[i] = y[i];
4826 for (i = k; i < x.length; i++) x[i] = 0;
4827}
4828
4829//do x=y on bigInt x and integer y.
4830function copyInt_(x, n) {
4831 var i, c;
4832 for (c = n, i = 0; i < x.length; i++) {
4833 x[i] = c & mask;
4834 c >>= bpe;
4835 }
4836}
4837
4838//do x=x+n where x is a bigInt and n is an integer.
4839//x must be large enough to hold the result.
4840function addInt_(x, n) {
4841 var i, k, c, b;
4842 x[0] += n;
4843 k = x.length;
4844 c = 0;
4845 for (i = 0; i < k; i++) {
4846 c += x[i];
4847 b = 0;
4848 if (c < 0) {
4849 b = -(c >> bpe);
4850 c += b * radix;
4851 }
4852 x[i] = c & mask;
4853 c = (c >> bpe) - b;
4854 if (!c) return; //stop carrying as soon as the carry is zero
4855 }
4856}
4857
4858//right shift bigInt x by n bits. 0 <= n < bpe.
4859function rightShift_(x, n) {
4860 var i;
4861 var k = Math.floor(n / bpe);
4862 if (k) {
4863 for (i = 0; i < x.length - k; i++) //right shift x by k elements
4864 x[i] = x[i + k];
4865 for (; i < x.length; i++) x[i] = 0;
4866 n %= bpe;
4867 }
4868 for (i = 0; i < x.length - 1; i++) {
4869 x[i] = mask & (x[i + 1] << bpe - n | x[i] >> n);
4870 }
4871 x[i] >>= n;
4872}
4873
4874//do x=floor(|x|/2)*sgn(x) for bigInt x in 2's complement
4875function halve_(x) {
4876 var i;
4877 for (i = 0; i < x.length - 1; i++) {
4878 x[i] = mask & (x[i + 1] << bpe - 1 | x[i] >> 1);
4879 }
4880 x[i] = x[i] >> 1 | x[i] & radix >> 1; //most significant bit stays the same
4881}
4882
4883//left shift bigInt x by n bits.
4884function leftShift_(x, n) {
4885 var i;
4886 var k = Math.floor(n / bpe);
4887 if (k) {
4888 for (i = x.length; i >= k; i--) //left shift x by k elements
4889 x[i] = x[i - k];
4890 for (; i >= 0; i--) x[i] = 0;
4891 n %= bpe;
4892 }
4893 if (!n) return;
4894 for (i = x.length - 1; i > 0; i--) {
4895 x[i] = mask & (x[i] << n | x[i - 1] >> bpe - n);
4896 }
4897 x[i] = mask & x[i] << n;
4898}
4899
4900//do x=x*n where x is a bigInt and n is an integer.
4901//x must be large enough to hold the result.
4902function multInt_(x, n) {
4903 var i, k, c, b;
4904 if (!n) return;
4905 k = x.length;
4906 c = 0;
4907 for (i = 0; i < k; i++) {
4908 c += x[i] * n;
4909 b = 0;
4910 if (c < 0) {
4911 b = -(c >> bpe);
4912 c += b * radix;
4913 }
4914 x[i] = c & mask;
4915 c = (c >> bpe) - b;
4916 }
4917}
4918
4919//do x=floor(x/n) for bigInt x and integer n, and return the remainder
4920function divInt_(x, n) {
4921 var i,
4922 r = 0,
4923 s;
4924 for (i = x.length - 1; i >= 0; i--) {
4925 s = r * radix + x[i];
4926 x[i] = Math.floor(s / n);
4927 r = s % n;
4928 }
4929 return r;
4930}
4931
4932//do the linear combination x=a*x+b*y for bigInts x and y, and integers a and b.
4933//x must be large enough to hold the answer.
4934function linComb_(x, y, a, b) {
4935 var i, c, k, kk;
4936 k = x.length < y.length ? x.length : y.length;
4937 kk = x.length;
4938 for (c = 0, i = 0; i < k; i++) {
4939 c += a * x[i] + b * y[i];
4940 x[i] = c & mask;
4941 c >>= bpe;
4942 }
4943 for (i = k; i < kk; i++) {
4944 c += a * x[i];
4945 x[i] = c & mask;
4946 c >>= bpe;
4947 }
4948}
4949
4950//do the linear combination x=a*x+b*(y<<(ys*bpe)) for bigInts x and y, and integers a, b and ys.
4951//x must be large enough to hold the answer.
4952function linCombShift_(x, y, b, ys) {
4953 var i, c, k, kk;
4954 k = x.length < ys + y.length ? x.length : ys + y.length;
4955 kk = x.length;
4956 for (c = 0, i = ys; i < k; i++) {
4957 c += x[i] + b * y[i - ys];
4958 x[i] = c & mask;
4959 c >>= bpe;
4960 }
4961 for (i = k; c && i < kk; i++) {
4962 c += x[i];
4963 x[i] = c & mask;
4964 c >>= bpe;
4965 }
4966}
4967
4968//do x=x+(y<<(ys*bpe)) for bigInts x and y, and integers a,b and ys.
4969//x must be large enough to hold the answer.
4970function addShift_(x, y, ys) {
4971 var i, c, k, kk;
4972 k = x.length < ys + y.length ? x.length : ys + y.length;
4973 kk = x.length;
4974 for (c = 0, i = ys; i < k; i++) {
4975 c += x[i] + y[i - ys];
4976 x[i] = c & mask;
4977 c >>= bpe;
4978 }
4979 for (i = k; c && i < kk; i++) {
4980 c += x[i];
4981 x[i] = c & mask;
4982 c >>= bpe;
4983 }
4984}
4985
4986//do x=x-(y<<(ys*bpe)) for bigInts x and y, and integers a,b and ys.
4987//x must be large enough to hold the answer.
4988function subShift_(x, y, ys) {
4989 var i, c, k, kk;
4990 k = x.length < ys + y.length ? x.length : ys + y.length;
4991 kk = x.length;
4992 for (c = 0, i = ys; i < k; i++) {
4993 c += x[i] - y[i - ys];
4994 x[i] = c & mask;
4995 c >>= bpe;
4996 }
4997 for (i = k; c && i < kk; i++) {
4998 c += x[i];
4999 x[i] = c & mask;
5000 c >>= bpe;
5001 }
5002}
5003
5004//do x=x-y for bigInts x and y.
5005//x must be large enough to hold the answer.
5006//negative answers will be 2s complement
5007function sub_(x, y) {
5008 var i, c, k, kk;
5009 k = x.length < y.length ? x.length : y.length;
5010 for (c = 0, i = 0; i < k; i++) {
5011 c += x[i] - y[i];
5012 x[i] = c & mask;
5013 c >>= bpe;
5014 }
5015 for (i = k; c && i < x.length; i++) {
5016 c += x[i];
5017 x[i] = c & mask;
5018 c >>= bpe;
5019 }
5020}
5021
5022//do x=x+y for bigInts x and y.
5023//x must be large enough to hold the answer.
5024function add_(x, y) {
5025 var i, c, k, kk;
5026 k = x.length < y.length ? x.length : y.length;
5027 for (c = 0, i = 0; i < k; i++) {
5028 c += x[i] + y[i];
5029 x[i] = c & mask;
5030 c >>= bpe;
5031 }
5032 for (i = k; c && i < x.length; i++) {
5033 c += x[i];
5034 x[i] = c & mask;
5035 c >>= bpe;
5036 }
5037}
5038
5039//do x=x*y for bigInts x and y. This is faster when y<x.
5040function mult_(x, y) {
5041 var i;
5042 if (ss.length != 2 * x.length) ss = new Array(2 * x.length);
5043 copyInt_(ss, 0);
5044 for (i = 0; i < y.length; i++) if (y[i]) linCombShift_(ss, x, y[i], i); //ss=1*ss+y[i]*(x<<(i*bpe))
5045 copy_(x, ss);
5046}
5047
5048//do x=x mod n for bigInts x and n.
5049function mod_(x, n) {
5050 if (s4.length != x.length) s4 = dup(x);else copy_(s4, x);
5051 if (s5.length != x.length) s5 = dup(x);
5052 divide_(s4, n, s5, x); //x = remainder of s4 / n
5053}
5054
5055//do x=x*y mod n for bigInts x,y,n.
5056//for greater speed, let y<x.
5057function multMod_(x, y, n) {
5058 var i;
5059 if (s0.length != 2 * x.length) s0 = new Array(2 * x.length);
5060 copyInt_(s0, 0);
5061 for (i = 0; i < y.length; i++) if (y[i]) linCombShift_(s0, x, y[i], i); //s0=1*s0+y[i]*(x<<(i*bpe))
5062 mod_(s0, n);
5063 copy_(x, s0);
5064}
5065
5066//do x=x*x mod n for bigInts x,n.
5067function squareMod_(x, n) {
5068 var i, j, d, c, kx, kn, k;
5069 for (kx = x.length; kx > 0 && !x[kx - 1]; kx--); //ignore leading zeros in x
5070 k = kx > n.length ? 2 * kx : 2 * n.length; //k=# elements in the product, which is twice the elements in the larger of x and n
5071 if (s0.length != k) s0 = new Array(k);
5072 copyInt_(s0, 0);
5073 for (i = 0; i < kx; i++) {
5074 c = s0[2 * i] + x[i] * x[i];
5075 s0[2 * i] = c & mask;
5076 c >>= bpe;
5077 for (j = i + 1; j < kx; j++) {
5078 c = s0[i + j] + 2 * x[i] * x[j] + c;
5079 s0[i + j] = c & mask;
5080 c >>= bpe;
5081 }
5082 s0[i + kx] = c;
5083 }
5084 mod_(s0, n);
5085 copy_(x, s0);
5086}
5087
5088//return x with exactly k leading zero elements
5089function trim(x, k) {
5090 var i, y;
5091 for (i = x.length; i > 0 && !x[i - 1]; i--);
5092 y = new Array(i + k);
5093 copy_(y, x);
5094 return y;
5095}
5096
5097//do x=x**y mod n, where x,y,n are bigInts and ** is exponentiation. 0**0=1.
5098//this is faster when n is odd. x usually needs to have as many elements as n.
5099function powMod_(x, y, n) {
5100 var k1, k2, kn, np;
5101 if (s7.length != n.length) s7 = dup(n);
5102
5103 //for even modulus, use a simple square-and-multiply algorithm,
5104 //rather than using the more complex Montgomery algorithm.
5105 if ((n[0] & 1) == 0) {
5106 copy_(s7, x);
5107 copyInt_(x, 1);
5108 while (!equalsInt(y, 0)) {
5109 if (y[0] & 1) multMod_(x, s7, n);
5110 divInt_(y, 2);
5111 squareMod_(s7, n);
5112 }
5113 return;
5114 }
5115
5116 //calculate np from n for the Montgomery multiplications
5117 copyInt_(s7, 0);
5118 for (kn = n.length; kn > 0 && !n[kn - 1]; kn--);
5119 np = radix - inverseModInt(modInt(n, radix), radix);
5120 s7[kn] = 1;
5121 multMod_(x, s7, n); // x = x * 2**(kn*bp) mod n
5122
5123 if (s3.length != x.length) s3 = dup(x);else copy_(s3, x);
5124
5125 for (k1 = y.length - 1; k1 > 0 & !y[k1]; k1--); //k1=first nonzero element of y
5126 if (y[k1] == 0) {
5127 //anything to the 0th power is 1
5128 copyInt_(x, 1);
5129 return;
5130 }
5131 for (k2 = 1 << bpe - 1; k2 && !(y[k1] & k2); k2 >>= 1); //k2=position of first 1 bit in y[k1]
5132 for (;;) {
5133 if (!(k2 >>= 1)) {
5134 //look at next bit of y
5135 k1--;
5136 if (k1 < 0) {
5137 mont_(x, one, n, np);
5138 return;
5139 }
5140 k2 = 1 << bpe - 1;
5141 }
5142 mont_(x, x, n, np);
5143
5144 if (k2 & y[k1]) //if next bit is a 1
5145 mont_(x, s3, n, np);
5146 }
5147}
5148
5149//do x=x*y*Ri mod n for bigInts x,y,n,
5150// where Ri = 2**(-kn*bpe) mod n, and kn is the
5151// number of elements in the n array, not
5152// counting leading zeros.
5153//x array must have at least as many elemnts as the n array
5154//It's OK if x and y are the same variable.
5155//must have:
5156// x,y < n
5157// n is odd
5158// np = -(n^(-1)) mod radix
5159function mont_(x, y, n, np) {
5160 var i, j, c, ui, t, ks;
5161 var kn = n.length;
5162 var ky = y.length;
5163
5164 if (sa.length != kn) sa = new Array(kn);
5165
5166 copyInt_(sa, 0);
5167
5168 for (; kn > 0 && n[kn - 1] == 0; kn--); //ignore leading zeros of n
5169 for (; ky > 0 && y[ky - 1] == 0; ky--); //ignore leading zeros of y
5170 ks = sa.length - 1; //sa will never have more than this many nonzero elements.
5171
5172 //the following loop consumes 95% of the runtime for randTruePrime_() and powMod_() for large numbers
5173 for (i = 0; i < kn; i++) {
5174 t = sa[0] + x[i] * y[0];
5175 ui = (t & mask) * np & mask; //the inner "& mask" was needed on Safari (but not MSIE) at one time
5176 c = t + ui * n[0] >> bpe;
5177 t = x[i];
5178
5179 //do sa=(sa+x[i]*y+ui*n)/b where b=2**bpe. Loop is unrolled 5-fold for speed
5180 j = 1;
5181 for (; j < ky - 4;) {
5182 c += sa[j] + ui * n[j] + t * y[j];sa[j - 1] = c & mask;c >>= bpe;j++;
5183 c += sa[j] + ui * n[j] + t * y[j];sa[j - 1] = c & mask;c >>= bpe;j++;
5184 c += sa[j] + ui * n[j] + t * y[j];sa[j - 1] = c & mask;c >>= bpe;j++;
5185 c += sa[j] + ui * n[j] + t * y[j];sa[j - 1] = c & mask;c >>= bpe;j++;
5186 c += sa[j] + ui * n[j] + t * y[j];sa[j - 1] = c & mask;c >>= bpe;j++;
5187 }
5188 for (; j < ky;) {
5189 c += sa[j] + ui * n[j] + t * y[j];sa[j - 1] = c & mask;c >>= bpe;j++;
5190 }
5191 for (; j < kn - 4;) {
5192 c += sa[j] + ui * n[j];sa[j - 1] = c & mask;c >>= bpe;j++;
5193 c += sa[j] + ui * n[j];sa[j - 1] = c & mask;c >>= bpe;j++;
5194 c += sa[j] + ui * n[j];sa[j - 1] = c & mask;c >>= bpe;j++;
5195 c += sa[j] + ui * n[j];sa[j - 1] = c & mask;c >>= bpe;j++;
5196 c += sa[j] + ui * n[j];sa[j - 1] = c & mask;c >>= bpe;j++;
5197 }
5198 for (; j < kn;) {
5199 c += sa[j] + ui * n[j];sa[j - 1] = c & mask;c >>= bpe;j++;
5200 }
5201 for (; j < ks;) {
5202 c += sa[j];sa[j - 1] = c & mask;c >>= bpe;j++;
5203 }
5204 sa[j - 1] = c & mask;
5205 }
5206
5207 if (!greater(n, sa)) sub_(sa, n);
5208 copy_(x, sa);
5209}
5210
5211/***/ }),
5212/* 12 */
5213/***/ (function(module, exports, __webpack_require__) {
5214
5215(function(){
5216
5217 // Copyright (c) 2005 Tom Wu
5218 // All Rights Reserved.
5219 // See "LICENSE" for details.
5220
5221 // Basic JavaScript BN library - subset useful for RSA encryption.
5222
5223 // Bits per digit
5224 var dbits;
5225
5226 // JavaScript engine analysis
5227 var canary = 0xdeadbeefcafe;
5228 var j_lm = ((canary&0xffffff)==0xefcafe);
5229
5230 // (public) Constructor
5231 function BigInteger(a,b,c) {
5232 if(a != null)
5233 if("number" == typeof a) this.fromNumber(a,b,c);
5234 else if(b == null && "string" != typeof a) this.fromString(a,256);
5235 else this.fromString(a,b);
5236 }
5237
5238 // return new, unset BigInteger
5239 function nbi() { return new BigInteger(null); }
5240
5241 // am: Compute w_j += (x*this_i), propagate carries,
5242 // c is initial carry, returns final carry.
5243 // c < 3*dvalue, x < 2*dvalue, this_i < dvalue
5244 // We need to select the fastest one that works in this environment.
5245
5246 // am1: use a single mult and divide to get the high bits,
5247 // max digit bits should be 26 because
5248 // max internal value = 2*dvalue^2-2*dvalue (< 2^53)
5249 function am1(i,x,w,j,c,n) {
5250 while(--n >= 0) {
5251 var v = x*this[i++]+w[j]+c;
5252 c = Math.floor(v/0x4000000);
5253 w[j++] = v&0x3ffffff;
5254 }
5255 return c;
5256 }
5257 // am2 avoids a big mult-and-extract completely.
5258 // Max digit bits should be <= 30 because we do bitwise ops
5259 // on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
5260 function am2(i,x,w,j,c,n) {
5261 var xl = x&0x7fff, xh = x>>15;
5262 while(--n >= 0) {
5263 var l = this[i]&0x7fff;
5264 var h = this[i++]>>15;
5265 var m = xh*l+h*xl;
5266 l = xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff);
5267 c = (l>>>30)+(m>>>15)+xh*h+(c>>>30);
5268 w[j++] = l&0x3fffffff;
5269 }
5270 return c;
5271 }
5272 // Alternately, set max digit bits to 28 since some
5273 // browsers slow down when dealing with 32-bit numbers.
5274 function am3(i,x,w,j,c,n) {
5275 var xl = x&0x3fff, xh = x>>14;
5276 while(--n >= 0) {
5277 var l = this[i]&0x3fff;
5278 var h = this[i++]>>14;
5279 var m = xh*l+h*xl;
5280 l = xl*l+((m&0x3fff)<<14)+w[j]+c;
5281 c = (l>>28)+(m>>14)+xh*h;
5282 w[j++] = l&0xfffffff;
5283 }
5284 return c;
5285 }
5286 var inBrowser = typeof navigator !== "undefined";
5287 if(inBrowser && j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
5288 BigInteger.prototype.am = am2;
5289 dbits = 30;
5290 }
5291 else if(inBrowser && j_lm && (navigator.appName != "Netscape")) {
5292 BigInteger.prototype.am = am1;
5293 dbits = 26;
5294 }
5295 else { // Mozilla/Netscape seems to prefer am3
5296 BigInteger.prototype.am = am3;
5297 dbits = 28;
5298 }
5299
5300 BigInteger.prototype.DB = dbits;
5301 BigInteger.prototype.DM = ((1<<dbits)-1);
5302 BigInteger.prototype.DV = (1<<dbits);
5303
5304 var BI_FP = 52;
5305 BigInteger.prototype.FV = Math.pow(2,BI_FP);
5306 BigInteger.prototype.F1 = BI_FP-dbits;
5307 BigInteger.prototype.F2 = 2*dbits-BI_FP;
5308
5309 // Digit conversions
5310 var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
5311 var BI_RC = new Array();
5312 var rr,vv;
5313 rr = "0".charCodeAt(0);
5314 for(vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
5315 rr = "a".charCodeAt(0);
5316 for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
5317 rr = "A".charCodeAt(0);
5318 for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
5319
5320 function int2char(n) { return BI_RM.charAt(n); }
5321 function intAt(s,i) {
5322 var c = BI_RC[s.charCodeAt(i)];
5323 return (c==null)?-1:c;
5324 }
5325
5326 // (protected) copy this to r
5327 function bnpCopyTo(r) {
5328 for(var i = this.t-1; i >= 0; --i) r[i] = this[i];
5329 r.t = this.t;
5330 r.s = this.s;
5331 }
5332
5333 // (protected) set from integer value x, -DV <= x < DV
5334 function bnpFromInt(x) {
5335 this.t = 1;
5336 this.s = (x<0)?-1:0;
5337 if(x > 0) this[0] = x;
5338 else if(x < -1) this[0] = x+this.DV;
5339 else this.t = 0;
5340 }
5341
5342 // return bigint initialized to value
5343 function nbv(i) { var r = nbi(); r.fromInt(i); return r; }
5344
5345 // (protected) set from string and radix
5346 function bnpFromString(s,b) {
5347 var k;
5348 if(b == 16) k = 4;
5349 else if(b == 8) k = 3;
5350 else if(b == 256) k = 8; // byte array
5351 else if(b == 2) k = 1;
5352 else if(b == 32) k = 5;
5353 else if(b == 4) k = 2;
5354 else { this.fromRadix(s,b); return; }
5355 this.t = 0;
5356 this.s = 0;
5357 var i = s.length, mi = false, sh = 0;
5358 while(--i >= 0) {
5359 var x = (k==8)?s[i]&0xff:intAt(s,i);
5360 if(x < 0) {
5361 if(s.charAt(i) == "-") mi = true;
5362 continue;
5363 }
5364 mi = false;
5365 if(sh == 0)
5366 this[this.t++] = x;
5367 else if(sh+k > this.DB) {
5368 this[this.t-1] |= (x&((1<<(this.DB-sh))-1))<<sh;
5369 this[this.t++] = (x>>(this.DB-sh));
5370 }
5371 else
5372 this[this.t-1] |= x<<sh;
5373 sh += k;
5374 if(sh >= this.DB) sh -= this.DB;
5375 }
5376 if(k == 8 && (s[0]&0x80) != 0) {
5377 this.s = -1;
5378 if(sh > 0) this[this.t-1] |= ((1<<(this.DB-sh))-1)<<sh;
5379 }
5380 this.clamp();
5381 if(mi) BigInteger.ZERO.subTo(this,this);
5382 }
5383
5384 // (protected) clamp off excess high words
5385 function bnpClamp() {
5386 var c = this.s&this.DM;
5387 while(this.t > 0 && this[this.t-1] == c) --this.t;
5388 }
5389
5390 // (public) return string representation in given radix
5391 function bnToString(b) {
5392 if(this.s < 0) return "-"+this.negate().toString(b);
5393 var k;
5394 if(b == 16) k = 4;
5395 else if(b == 8) k = 3;
5396 else if(b == 2) k = 1;
5397 else if(b == 32) k = 5;
5398 else if(b == 4) k = 2;
5399 else return this.toRadix(b);
5400 var km = (1<<k)-1, d, m = false, r = "", i = this.t;
5401 var p = this.DB-(i*this.DB)%k;
5402 if(i-- > 0) {
5403 if(p < this.DB && (d = this[i]>>p) > 0) { m = true; r = int2char(d); }
5404 while(i >= 0) {
5405 if(p < k) {
5406 d = (this[i]&((1<<p)-1))<<(k-p);
5407 d |= this[--i]>>(p+=this.DB-k);
5408 }
5409 else {
5410 d = (this[i]>>(p-=k))&km;
5411 if(p <= 0) { p += this.DB; --i; }
5412 }
5413 if(d > 0) m = true;
5414 if(m) r += int2char(d);
5415 }
5416 }
5417 return m?r:"0";
5418 }
5419
5420 // (public) -this
5421 function bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this,r); return r; }
5422
5423 // (public) |this|
5424 function bnAbs() { return (this.s<0)?this.negate():this; }
5425
5426 // (public) return + if this > a, - if this < a, 0 if equal
5427 function bnCompareTo(a) {
5428 var r = this.s-a.s;
5429 if(r != 0) return r;
5430 var i = this.t;
5431 r = i-a.t;
5432 if(r != 0) return (this.s<0)?-r:r;
5433 while(--i >= 0) if((r=this[i]-a[i]) != 0) return r;
5434 return 0;
5435 }
5436
5437 // returns bit length of the integer x
5438 function nbits(x) {
5439 var r = 1, t;
5440 if((t=x>>>16) != 0) { x = t; r += 16; }
5441 if((t=x>>8) != 0) { x = t; r += 8; }
5442 if((t=x>>4) != 0) { x = t; r += 4; }
5443 if((t=x>>2) != 0) { x = t; r += 2; }
5444 if((t=x>>1) != 0) { x = t; r += 1; }
5445 return r;
5446 }
5447
5448 // (public) return the number of bits in "this"
5449 function bnBitLength() {
5450 if(this.t <= 0) return 0;
5451 return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM));
5452 }
5453
5454 // (protected) r = this << n*DB
5455 function bnpDLShiftTo(n,r) {
5456 var i;
5457 for(i = this.t-1; i >= 0; --i) r[i+n] = this[i];
5458 for(i = n-1; i >= 0; --i) r[i] = 0;
5459 r.t = this.t+n;
5460 r.s = this.s;
5461 }
5462
5463 // (protected) r = this >> n*DB
5464 function bnpDRShiftTo(n,r) {
5465 for(var i = n; i < this.t; ++i) r[i-n] = this[i];
5466 r.t = Math.max(this.t-n,0);
5467 r.s = this.s;
5468 }
5469
5470 // (protected) r = this << n
5471 function bnpLShiftTo(n,r) {
5472 var bs = n%this.DB;
5473 var cbs = this.DB-bs;
5474 var bm = (1<<cbs)-1;
5475 var ds = Math.floor(n/this.DB), c = (this.s<<bs)&this.DM, i;
5476 for(i = this.t-1; i >= 0; --i) {
5477 r[i+ds+1] = (this[i]>>cbs)|c;
5478 c = (this[i]&bm)<<bs;
5479 }
5480 for(i = ds-1; i >= 0; --i) r[i] = 0;
5481 r[ds] = c;
5482 r.t = this.t+ds+1;
5483 r.s = this.s;
5484 r.clamp();
5485 }
5486
5487 // (protected) r = this >> n
5488 function bnpRShiftTo(n,r) {
5489 r.s = this.s;
5490 var ds = Math.floor(n/this.DB);
5491 if(ds >= this.t) { r.t = 0; return; }
5492 var bs = n%this.DB;
5493 var cbs = this.DB-bs;
5494 var bm = (1<<bs)-1;
5495 r[0] = this[ds]>>bs;
5496 for(var i = ds+1; i < this.t; ++i) {
5497 r[i-ds-1] |= (this[i]&bm)<<cbs;
5498 r[i-ds] = this[i]>>bs;
5499 }
5500 if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<<cbs;
5501 r.t = this.t-ds;
5502 r.clamp();
5503 }
5504
5505 // (protected) r = this - a
5506 function bnpSubTo(a,r) {
5507 var i = 0, c = 0, m = Math.min(a.t,this.t);
5508 while(i < m) {
5509 c += this[i]-a[i];
5510 r[i++] = c&this.DM;
5511 c >>= this.DB;
5512 }
5513 if(a.t < this.t) {
5514 c -= a.s;
5515 while(i < this.t) {
5516 c += this[i];
5517 r[i++] = c&this.DM;
5518 c >>= this.DB;
5519 }
5520 c += this.s;
5521 }
5522 else {
5523 c += this.s;
5524 while(i < a.t) {
5525 c -= a[i];
5526 r[i++] = c&this.DM;
5527 c >>= this.DB;
5528 }
5529 c -= a.s;
5530 }
5531 r.s = (c<0)?-1:0;
5532 if(c < -1) r[i++] = this.DV+c;
5533 else if(c > 0) r[i++] = c;
5534 r.t = i;
5535 r.clamp();
5536 }
5537
5538 // (protected) r = this * a, r != this,a (HAC 14.12)
5539 // "this" should be the larger one if appropriate.
5540 function bnpMultiplyTo(a,r) {
5541 var x = this.abs(), y = a.abs();
5542 var i = x.t;
5543 r.t = i+y.t;
5544 while(--i >= 0) r[i] = 0;
5545 for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t);
5546 r.s = 0;
5547 r.clamp();
5548 if(this.s != a.s) BigInteger.ZERO.subTo(r,r);
5549 }
5550
5551 // (protected) r = this^2, r != this (HAC 14.16)
5552 function bnpSquareTo(r) {
5553 var x = this.abs();
5554 var i = r.t = 2*x.t;
5555 while(--i >= 0) r[i] = 0;
5556 for(i = 0; i < x.t-1; ++i) {
5557 var c = x.am(i,x[i],r,2*i,0,1);
5558 if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x.DV) {
5559 r[i+x.t] -= x.DV;
5560 r[i+x.t+1] = 1;
5561 }
5562 }
5563 if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1);
5564 r.s = 0;
5565 r.clamp();
5566 }
5567
5568 // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
5569 // r != q, this != m. q or r may be null.
5570 function bnpDivRemTo(m,q,r) {
5571 var pm = m.abs();
5572 if(pm.t <= 0) return;
5573 var pt = this.abs();
5574 if(pt.t < pm.t) {
5575 if(q != null) q.fromInt(0);
5576 if(r != null) this.copyTo(r);
5577 return;
5578 }
5579 if(r == null) r = nbi();
5580 var y = nbi(), ts = this.s, ms = m.s;
5581 var nsh = this.DB-nbits(pm[pm.t-1]); // normalize modulus
5582 if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); }
5583 else { pm.copyTo(y); pt.copyTo(r); }
5584 var ys = y.t;
5585 var y0 = y[ys-1];
5586 if(y0 == 0) return;
5587 var yt = y0*(1<<this.F1)+((ys>1)?y[ys-2]>>this.F2:0);
5588 var d1 = this.FV/yt, d2 = (1<<this.F1)/yt, e = 1<<this.F2;
5589 var i = r.t, j = i-ys, t = (q==null)?nbi():q;
5590 y.dlShiftTo(j,t);
5591 if(r.compareTo(t) >= 0) {
5592 r[r.t++] = 1;
5593 r.subTo(t,r);
5594 }
5595 BigInteger.ONE.dlShiftTo(ys,t);
5596 t.subTo(y,y); // "negative" y so we can replace sub with am later
5597 while(y.t < ys) y[y.t++] = 0;
5598 while(--j >= 0) {
5599 // Estimate quotient digit
5600 var qd = (r[--i]==y0)?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);
5601 if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) { // Try it out
5602 y.dlShiftTo(j,t);
5603 r.subTo(t,r);
5604 while(r[i] < --qd) r.subTo(t,r);
5605 }
5606 }
5607 if(q != null) {
5608 r.drShiftTo(ys,q);
5609 if(ts != ms) BigInteger.ZERO.subTo(q,q);
5610 }
5611 r.t = ys;
5612 r.clamp();
5613 if(nsh > 0) r.rShiftTo(nsh,r); // Denormalize remainder
5614 if(ts < 0) BigInteger.ZERO.subTo(r,r);
5615 }
5616
5617 // (public) this mod a
5618 function bnMod(a) {
5619 var r = nbi();
5620 this.abs().divRemTo(a,null,r);
5621 if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r,r);
5622 return r;
5623 }
5624
5625 // Modular reduction using "classic" algorithm
5626 function Classic(m) { this.m = m; }
5627 function cConvert(x) {
5628 if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m);
5629 else return x;
5630 }
5631 function cRevert(x) { return x; }
5632 function cReduce(x) { x.divRemTo(this.m,null,x); }
5633 function cMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
5634 function cSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
5635
5636 Classic.prototype.convert = cConvert;
5637 Classic.prototype.revert = cRevert;
5638 Classic.prototype.reduce = cReduce;
5639 Classic.prototype.mulTo = cMulTo;
5640 Classic.prototype.sqrTo = cSqrTo;
5641
5642 // (protected) return "-1/this % 2^DB"; useful for Mont. reduction
5643 // justification:
5644 // xy == 1 (mod m)
5645 // xy = 1+km
5646 // xy(2-xy) = (1+km)(1-km)
5647 // x[y(2-xy)] = 1-k^2m^2
5648 // x[y(2-xy)] == 1 (mod m^2)
5649 // if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
5650 // should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
5651 // JS multiply "overflows" differently from C/C++, so care is needed here.
5652 function bnpInvDigit() {
5653 if(this.t < 1) return 0;
5654 var x = this[0];
5655 if((x&1) == 0) return 0;
5656 var y = x&3; // y == 1/x mod 2^2
5657 y = (y*(2-(x&0xf)*y))&0xf; // y == 1/x mod 2^4
5658 y = (y*(2-(x&0xff)*y))&0xff; // y == 1/x mod 2^8
5659 y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; // y == 1/x mod 2^16
5660 // last step - calculate inverse mod DV directly;
5661 // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
5662 y = (y*(2-x*y%this.DV))%this.DV; // y == 1/x mod 2^dbits
5663 // we really want the negative inverse, and -DV < y < DV
5664 return (y>0)?this.DV-y:-y;
5665 }
5666
5667 // Montgomery reduction
5668 function Montgomery(m) {
5669 this.m = m;
5670 this.mp = m.invDigit();
5671 this.mpl = this.mp&0x7fff;
5672 this.mph = this.mp>>15;
5673 this.um = (1<<(m.DB-15))-1;
5674 this.mt2 = 2*m.t;
5675 }
5676
5677 // xR mod m
5678 function montConvert(x) {
5679 var r = nbi();
5680 x.abs().dlShiftTo(this.m.t,r);
5681 r.divRemTo(this.m,null,r);
5682 if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r);
5683 return r;
5684 }
5685
5686 // x/R mod m
5687 function montRevert(x) {
5688 var r = nbi();
5689 x.copyTo(r);
5690 this.reduce(r);
5691 return r;
5692 }
5693
5694 // x = x/R mod m (HAC 14.32)
5695 function montReduce(x) {
5696 while(x.t <= this.mt2) // pad x so am has enough room later
5697 x[x.t++] = 0;
5698 for(var i = 0; i < this.m.t; ++i) {
5699 // faster way of calculating u0 = x[i]*mp mod DV
5700 var j = x[i]&0x7fff;
5701 var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.DM;
5702 // use am to combine the multiply-shift-add into one call
5703 j = i+this.m.t;
5704 x[j] += this.m.am(0,u0,x,i,0,this.m.t);
5705 // propagate carry
5706 while(x[j] >= x.DV) { x[j] -= x.DV; x[++j]++; }
5707 }
5708 x.clamp();
5709 x.drShiftTo(this.m.t,x);
5710 if(x.compareTo(this.m) >= 0) x.subTo(this.m,x);
5711 }
5712
5713 // r = "x^2/R mod m"; x != r
5714 function montSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
5715
5716 // r = "xy/R mod m"; x,y != r
5717 function montMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
5718
5719 Montgomery.prototype.convert = montConvert;
5720 Montgomery.prototype.revert = montRevert;
5721 Montgomery.prototype.reduce = montReduce;
5722 Montgomery.prototype.mulTo = montMulTo;
5723 Montgomery.prototype.sqrTo = montSqrTo;
5724
5725 // (protected) true iff this is even
5726 function bnpIsEven() { return ((this.t>0)?(this[0]&1):this.s) == 0; }
5727
5728 // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
5729 function bnpExp(e,z) {
5730 if(e > 0xffffffff || e < 1) return BigInteger.ONE;
5731 var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1;
5732 g.copyTo(r);
5733 while(--i >= 0) {
5734 z.sqrTo(r,r2);
5735 if((e&(1<<i)) > 0) z.mulTo(r2,g,r);
5736 else { var t = r; r = r2; r2 = t; }
5737 }
5738 return z.revert(r);
5739 }
5740
5741 // (public) this^e % m, 0 <= e < 2^32
5742 function bnModPowInt(e,m) {
5743 var z;
5744 if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m);
5745 return this.exp(e,z);
5746 }
5747
5748 // protected
5749 BigInteger.prototype.copyTo = bnpCopyTo;
5750 BigInteger.prototype.fromInt = bnpFromInt;
5751 BigInteger.prototype.fromString = bnpFromString;
5752 BigInteger.prototype.clamp = bnpClamp;
5753 BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
5754 BigInteger.prototype.drShiftTo = bnpDRShiftTo;
5755 BigInteger.prototype.lShiftTo = bnpLShiftTo;
5756 BigInteger.prototype.rShiftTo = bnpRShiftTo;
5757 BigInteger.prototype.subTo = bnpSubTo;
5758 BigInteger.prototype.multiplyTo = bnpMultiplyTo;
5759 BigInteger.prototype.squareTo = bnpSquareTo;
5760 BigInteger.prototype.divRemTo = bnpDivRemTo;
5761 BigInteger.prototype.invDigit = bnpInvDigit;
5762 BigInteger.prototype.isEven = bnpIsEven;
5763 BigInteger.prototype.exp = bnpExp;
5764
5765 // public
5766 BigInteger.prototype.toString = bnToString;
5767 BigInteger.prototype.negate = bnNegate;
5768 BigInteger.prototype.abs = bnAbs;
5769 BigInteger.prototype.compareTo = bnCompareTo;
5770 BigInteger.prototype.bitLength = bnBitLength;
5771 BigInteger.prototype.mod = bnMod;
5772 BigInteger.prototype.modPowInt = bnModPowInt;
5773
5774 // "constants"
5775 BigInteger.ZERO = nbv(0);
5776 BigInteger.ONE = nbv(1);
5777
5778 // Copyright (c) 2005-2009 Tom Wu
5779 // All Rights Reserved.
5780 // See "LICENSE" for details.
5781
5782 // Extended JavaScript BN functions, required for RSA private ops.
5783
5784 // Version 1.1: new BigInteger("0", 10) returns "proper" zero
5785 // Version 1.2: square() API, isProbablePrime fix
5786
5787 // (public)
5788 function bnClone() { var r = nbi(); this.copyTo(r); return r; }
5789
5790 // (public) return value as integer
5791 function bnIntValue() {
5792 if(this.s < 0) {
5793 if(this.t == 1) return this[0]-this.DV;
5794 else if(this.t == 0) return -1;
5795 }
5796 else if(this.t == 1) return this[0];
5797 else if(this.t == 0) return 0;
5798 // assumes 16 < DB < 32
5799 return ((this[1]&((1<<(32-this.DB))-1))<<this.DB)|this[0];
5800 }
5801
5802 // (public) return value as byte
5803 function bnByteValue() { return (this.t==0)?this.s:(this[0]<<24)>>24; }
5804
5805 // (public) return value as short (assumes DB>=16)
5806 function bnShortValue() { return (this.t==0)?this.s:(this[0]<<16)>>16; }
5807
5808 // (protected) return x s.t. r^x < DV
5809 function bnpChunkSize(r) { return Math.floor(Math.LN2*this.DB/Math.log(r)); }
5810
5811 // (public) 0 if this == 0, 1 if this > 0
5812 function bnSigNum() {
5813 if(this.s < 0) return -1;
5814 else if(this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0;
5815 else return 1;
5816 }
5817
5818 // (protected) convert to radix string
5819 function bnpToRadix(b) {
5820 if(b == null) b = 10;
5821 if(this.signum() == 0 || b < 2 || b > 36) return "0";
5822 var cs = this.chunkSize(b);
5823 var a = Math.pow(b,cs);
5824 var d = nbv(a), y = nbi(), z = nbi(), r = "";
5825 this.divRemTo(d,y,z);
5826 while(y.signum() > 0) {
5827 r = (a+z.intValue()).toString(b).substr(1) + r;
5828 y.divRemTo(d,y,z);
5829 }
5830 return z.intValue().toString(b) + r;
5831 }
5832
5833 // (protected) convert from radix string
5834 function bnpFromRadix(s,b) {
5835 this.fromInt(0);
5836 if(b == null) b = 10;
5837 var cs = this.chunkSize(b);
5838 var d = Math.pow(b,cs), mi = false, j = 0, w = 0;
5839 for(var i = 0; i < s.length; ++i) {
5840 var x = intAt(s,i);
5841 if(x < 0) {
5842 if(s.charAt(i) == "-" && this.signum() == 0) mi = true;
5843 continue;
5844 }
5845 w = b*w+x;
5846 if(++j >= cs) {
5847 this.dMultiply(d);
5848 this.dAddOffset(w,0);
5849 j = 0;
5850 w = 0;
5851 }
5852 }
5853 if(j > 0) {
5854 this.dMultiply(Math.pow(b,j));
5855 this.dAddOffset(w,0);
5856 }
5857 if(mi) BigInteger.ZERO.subTo(this,this);
5858 }
5859
5860 // (protected) alternate constructor
5861 function bnpFromNumber(a,b,c) {
5862 if("number" == typeof b) {
5863 // new BigInteger(int,int,RNG)
5864 if(a < 2) this.fromInt(1);
5865 else {
5866 this.fromNumber(a,c);
5867 if(!this.testBit(a-1)) // force MSB set
5868 this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this);
5869 if(this.isEven()) this.dAddOffset(1,0); // force odd
5870 while(!this.isProbablePrime(b)) {
5871 this.dAddOffset(2,0);
5872 if(this.bitLength() > a) this.subTo(BigInteger.ONE.shiftLeft(a-1),this);
5873 }
5874 }
5875 }
5876 else {
5877 // new BigInteger(int,RNG)
5878 var x = new Array(), t = a&7;
5879 x.length = (a>>3)+1;
5880 b.nextBytes(x);
5881 if(t > 0) x[0] &= ((1<<t)-1); else x[0] = 0;
5882 this.fromString(x,256);
5883 }
5884 }
5885
5886 // (public) convert to bigendian byte array
5887 function bnToByteArray() {
5888 var i = this.t, r = new Array();
5889 r[0] = this.s;
5890 var p = this.DB-(i*this.DB)%8, d, k = 0;
5891 if(i-- > 0) {
5892 if(p < this.DB && (d = this[i]>>p) != (this.s&this.DM)>>p)
5893 r[k++] = d|(this.s<<(this.DB-p));
5894 while(i >= 0) {
5895 if(p < 8) {
5896 d = (this[i]&((1<<p)-1))<<(8-p);
5897 d |= this[--i]>>(p+=this.DB-8);
5898 }
5899 else {
5900 d = (this[i]>>(p-=8))&0xff;
5901 if(p <= 0) { p += this.DB; --i; }
5902 }
5903 if((d&0x80) != 0) d |= -256;
5904 if(k == 0 && (this.s&0x80) != (d&0x80)) ++k;
5905 if(k > 0 || d != this.s) r[k++] = d;
5906 }
5907 }
5908 return r;
5909 }
5910
5911 function bnEquals(a) { return(this.compareTo(a)==0); }
5912 function bnMin(a) { return(this.compareTo(a)<0)?this:a; }
5913 function bnMax(a) { return(this.compareTo(a)>0)?this:a; }
5914
5915 // (protected) r = this op a (bitwise)
5916 function bnpBitwiseTo(a,op,r) {
5917 var i, f, m = Math.min(a.t,this.t);
5918 for(i = 0; i < m; ++i) r[i] = op(this[i],a[i]);
5919 if(a.t < this.t) {
5920 f = a.s&this.DM;
5921 for(i = m; i < this.t; ++i) r[i] = op(this[i],f);
5922 r.t = this.t;
5923 }
5924 else {
5925 f = this.s&this.DM;
5926 for(i = m; i < a.t; ++i) r[i] = op(f,a[i]);
5927 r.t = a.t;
5928 }
5929 r.s = op(this.s,a.s);
5930 r.clamp();
5931 }
5932
5933 // (public) this & a
5934 function op_and(x,y) { return x&y; }
5935 function bnAnd(a) { var r = nbi(); this.bitwiseTo(a,op_and,r); return r; }
5936
5937 // (public) this | a
5938 function op_or(x,y) { return x|y; }
5939 function bnOr(a) { var r = nbi(); this.bitwiseTo(a,op_or,r); return r; }
5940
5941 // (public) this ^ a
5942 function op_xor(x,y) { return x^y; }
5943 function bnXor(a) { var r = nbi(); this.bitwiseTo(a,op_xor,r); return r; }
5944
5945 // (public) this & ~a
5946 function op_andnot(x,y) { return x&~y; }
5947 function bnAndNot(a) { var r = nbi(); this.bitwiseTo(a,op_andnot,r); return r; }
5948
5949 // (public) ~this
5950 function bnNot() {
5951 var r = nbi();
5952 for(var i = 0; i < this.t; ++i) r[i] = this.DM&~this[i];
5953 r.t = this.t;
5954 r.s = ~this.s;
5955 return r;
5956 }
5957
5958 // (public) this << n
5959 function bnShiftLeft(n) {
5960 var r = nbi();
5961 if(n < 0) this.rShiftTo(-n,r); else this.lShiftTo(n,r);
5962 return r;
5963 }
5964
5965 // (public) this >> n
5966 function bnShiftRight(n) {
5967 var r = nbi();
5968 if(n < 0) this.lShiftTo(-n,r); else this.rShiftTo(n,r);
5969 return r;
5970 }
5971
5972 // return index of lowest 1-bit in x, x < 2^31
5973 function lbit(x) {
5974 if(x == 0) return -1;
5975 var r = 0;
5976 if((x&0xffff) == 0) { x >>= 16; r += 16; }
5977 if((x&0xff) == 0) { x >>= 8; r += 8; }
5978 if((x&0xf) == 0) { x >>= 4; r += 4; }
5979 if((x&3) == 0) { x >>= 2; r += 2; }
5980 if((x&1) == 0) ++r;
5981 return r;
5982 }
5983
5984 // (public) returns index of lowest 1-bit (or -1 if none)
5985 function bnGetLowestSetBit() {
5986 for(var i = 0; i < this.t; ++i)
5987 if(this[i] != 0) return i*this.DB+lbit(this[i]);
5988 if(this.s < 0) return this.t*this.DB;
5989 return -1;
5990 }
5991
5992 // return number of 1 bits in x
5993 function cbit(x) {
5994 var r = 0;
5995 while(x != 0) { x &= x-1; ++r; }
5996 return r;
5997 }
5998
5999 // (public) return number of set bits
6000 function bnBitCount() {
6001 var r = 0, x = this.s&this.DM;
6002 for(var i = 0; i < this.t; ++i) r += cbit(this[i]^x);
6003 return r;
6004 }
6005
6006 // (public) true iff nth bit is set
6007 function bnTestBit(n) {
6008 var j = Math.floor(n/this.DB);
6009 if(j >= this.t) return(this.s!=0);
6010 return((this[j]&(1<<(n%this.DB)))!=0);
6011 }
6012
6013 // (protected) this op (1<<n)
6014 function bnpChangeBit(n,op) {
6015 var r = BigInteger.ONE.shiftLeft(n);
6016 this.bitwiseTo(r,op,r);
6017 return r;
6018 }
6019
6020 // (public) this | (1<<n)
6021 function bnSetBit(n) { return this.changeBit(n,op_or); }
6022
6023 // (public) this & ~(1<<n)
6024 function bnClearBit(n) { return this.changeBit(n,op_andnot); }
6025
6026 // (public) this ^ (1<<n)
6027 function bnFlipBit(n) { return this.changeBit(n,op_xor); }
6028
6029 // (protected) r = this + a
6030 function bnpAddTo(a,r) {
6031 var i = 0, c = 0, m = Math.min(a.t,this.t);
6032 while(i < m) {
6033 c += this[i]+a[i];
6034 r[i++] = c&this.DM;
6035 c >>= this.DB;
6036 }
6037 if(a.t < this.t) {
6038 c += a.s;
6039 while(i < this.t) {
6040 c += this[i];
6041 r[i++] = c&this.DM;
6042 c >>= this.DB;
6043 }
6044 c += this.s;
6045 }
6046 else {
6047 c += this.s;
6048 while(i < a.t) {
6049 c += a[i];
6050 r[i++] = c&this.DM;
6051 c >>= this.DB;
6052 }
6053 c += a.s;
6054 }
6055 r.s = (c<0)?-1:0;
6056 if(c > 0) r[i++] = c;
6057 else if(c < -1) r[i++] = this.DV+c;
6058 r.t = i;
6059 r.clamp();
6060 }
6061
6062 // (public) this + a
6063 function bnAdd(a) { var r = nbi(); this.addTo(a,r); return r; }
6064
6065 // (public) this - a
6066 function bnSubtract(a) { var r = nbi(); this.subTo(a,r); return r; }
6067
6068 // (public) this * a
6069 function bnMultiply(a) { var r = nbi(); this.multiplyTo(a,r); return r; }
6070
6071 // (public) this^2
6072 function bnSquare() { var r = nbi(); this.squareTo(r); return r; }
6073
6074 // (public) this / a
6075 function bnDivide(a) { var r = nbi(); this.divRemTo(a,r,null); return r; }
6076
6077 // (public) this % a
6078 function bnRemainder(a) { var r = nbi(); this.divRemTo(a,null,r); return r; }
6079
6080 // (public) [this/a,this%a]
6081 function bnDivideAndRemainder(a) {
6082 var q = nbi(), r = nbi();
6083 this.divRemTo(a,q,r);
6084 return new Array(q,r);
6085 }
6086
6087 // (protected) this *= n, this >= 0, 1 < n < DV
6088 function bnpDMultiply(n) {
6089 this[this.t] = this.am(0,n-1,this,0,0,this.t);
6090 ++this.t;
6091 this.clamp();
6092 }
6093
6094 // (protected) this += n << w words, this >= 0
6095 function bnpDAddOffset(n,w) {
6096 if(n == 0) return;
6097 while(this.t <= w) this[this.t++] = 0;
6098 this[w] += n;
6099 while(this[w] >= this.DV) {
6100 this[w] -= this.DV;
6101 if(++w >= this.t) this[this.t++] = 0;
6102 ++this[w];
6103 }
6104 }
6105
6106 // A "null" reducer
6107 function NullExp() {}
6108 function nNop(x) { return x; }
6109 function nMulTo(x,y,r) { x.multiplyTo(y,r); }
6110 function nSqrTo(x,r) { x.squareTo(r); }
6111
6112 NullExp.prototype.convert = nNop;
6113 NullExp.prototype.revert = nNop;
6114 NullExp.prototype.mulTo = nMulTo;
6115 NullExp.prototype.sqrTo = nSqrTo;
6116
6117 // (public) this^e
6118 function bnPow(e) { return this.exp(e,new NullExp()); }
6119
6120 // (protected) r = lower n words of "this * a", a.t <= n
6121 // "this" should be the larger one if appropriate.
6122 function bnpMultiplyLowerTo(a,n,r) {
6123 var i = Math.min(this.t+a.t,n);
6124 r.s = 0; // assumes a,this >= 0
6125 r.t = i;
6126 while(i > 0) r[--i] = 0;
6127 var j;
6128 for(j = r.t-this.t; i < j; ++i) r[i+this.t] = this.am(0,a[i],r,i,0,this.t);
6129 for(j = Math.min(a.t,n); i < j; ++i) this.am(0,a[i],r,i,0,n-i);
6130 r.clamp();
6131 }
6132
6133 // (protected) r = "this * a" without lower n words, n > 0
6134 // "this" should be the larger one if appropriate.
6135 function bnpMultiplyUpperTo(a,n,r) {
6136 --n;
6137 var i = r.t = this.t+a.t-n;
6138 r.s = 0; // assumes a,this >= 0
6139 while(--i >= 0) r[i] = 0;
6140 for(i = Math.max(n-this.t,0); i < a.t; ++i)
6141 r[this.t+i-n] = this.am(n-i,a[i],r,0,0,this.t+i-n);
6142 r.clamp();
6143 r.drShiftTo(1,r);
6144 }
6145
6146 // Barrett modular reduction
6147 function Barrett(m) {
6148 // setup Barrett
6149 this.r2 = nbi();
6150 this.q3 = nbi();
6151 BigInteger.ONE.dlShiftTo(2*m.t,this.r2);
6152 this.mu = this.r2.divide(m);
6153 this.m = m;
6154 }
6155
6156 function barrettConvert(x) {
6157 if(x.s < 0 || x.t > 2*this.m.t) return x.mod(this.m);
6158 else if(x.compareTo(this.m) < 0) return x;
6159 else { var r = nbi(); x.copyTo(r); this.reduce(r); return r; }
6160 }
6161
6162 function barrettRevert(x) { return x; }
6163
6164 // x = x mod m (HAC 14.42)
6165 function barrettReduce(x) {
6166 x.drShiftTo(this.m.t-1,this.r2);
6167 if(x.t > this.m.t+1) { x.t = this.m.t+1; x.clamp(); }
6168 this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3);
6169 this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);
6170 while(x.compareTo(this.r2) < 0) x.dAddOffset(1,this.m.t+1);
6171 x.subTo(this.r2,x);
6172 while(x.compareTo(this.m) >= 0) x.subTo(this.m,x);
6173 }
6174
6175 // r = x^2 mod m; x != r
6176 function barrettSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
6177
6178 // r = x*y mod m; x,y != r
6179 function barrettMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
6180
6181 Barrett.prototype.convert = barrettConvert;
6182 Barrett.prototype.revert = barrettRevert;
6183 Barrett.prototype.reduce = barrettReduce;
6184 Barrett.prototype.mulTo = barrettMulTo;
6185 Barrett.prototype.sqrTo = barrettSqrTo;
6186
6187 // (public) this^e % m (HAC 14.85)
6188 function bnModPow(e,m) {
6189 var i = e.bitLength(), k, r = nbv(1), z;
6190 if(i <= 0) return r;
6191 else if(i < 18) k = 1;
6192 else if(i < 48) k = 3;
6193 else if(i < 144) k = 4;
6194 else if(i < 768) k = 5;
6195 else k = 6;
6196 if(i < 8)
6197 z = new Classic(m);
6198 else if(m.isEven())
6199 z = new Barrett(m);
6200 else
6201 z = new Montgomery(m);
6202
6203 // precomputation
6204 var g = new Array(), n = 3, k1 = k-1, km = (1<<k)-1;
6205 g[1] = z.convert(this);
6206 if(k > 1) {
6207 var g2 = nbi();
6208 z.sqrTo(g[1],g2);
6209 while(n <= km) {
6210 g[n] = nbi();
6211 z.mulTo(g2,g[n-2],g[n]);
6212 n += 2;
6213 }
6214 }
6215
6216 var j = e.t-1, w, is1 = true, r2 = nbi(), t;
6217 i = nbits(e[j])-1;
6218 while(j >= 0) {
6219 if(i >= k1) w = (e[j]>>(i-k1))&km;
6220 else {
6221 w = (e[j]&((1<<(i+1))-1))<<(k1-i);
6222 if(j > 0) w |= e[j-1]>>(this.DB+i-k1);
6223 }
6224
6225 n = k;
6226 while((w&1) == 0) { w >>= 1; --n; }
6227 if((i -= n) < 0) { i += this.DB; --j; }
6228 if(is1) { // ret == 1, don't bother squaring or multiplying it
6229 g[w].copyTo(r);
6230 is1 = false;
6231 }
6232 else {
6233 while(n > 1) { z.sqrTo(r,r2); z.sqrTo(r2,r); n -= 2; }
6234 if(n > 0) z.sqrTo(r,r2); else { t = r; r = r2; r2 = t; }
6235 z.mulTo(r2,g[w],r);
6236 }
6237
6238 while(j >= 0 && (e[j]&(1<<i)) == 0) {
6239 z.sqrTo(r,r2); t = r; r = r2; r2 = t;
6240 if(--i < 0) { i = this.DB-1; --j; }
6241 }
6242 }
6243 return z.revert(r);
6244 }
6245
6246 // (public) gcd(this,a) (HAC 14.54)
6247 function bnGCD(a) {
6248 var x = (this.s<0)?this.negate():this.clone();
6249 var y = (a.s<0)?a.negate():a.clone();
6250 if(x.compareTo(y) < 0) { var t = x; x = y; y = t; }
6251 var i = x.getLowestSetBit(), g = y.getLowestSetBit();
6252 if(g < 0) return x;
6253 if(i < g) g = i;
6254 if(g > 0) {
6255 x.rShiftTo(g,x);
6256 y.rShiftTo(g,y);
6257 }
6258 while(x.signum() > 0) {
6259 if((i = x.getLowestSetBit()) > 0) x.rShiftTo(i,x);
6260 if((i = y.getLowestSetBit()) > 0) y.rShiftTo(i,y);
6261 if(x.compareTo(y) >= 0) {
6262 x.subTo(y,x);
6263 x.rShiftTo(1,x);
6264 }
6265 else {
6266 y.subTo(x,y);
6267 y.rShiftTo(1,y);
6268 }
6269 }
6270 if(g > 0) y.lShiftTo(g,y);
6271 return y;
6272 }
6273
6274 // (protected) this % n, n < 2^26
6275 function bnpModInt(n) {
6276 if(n <= 0) return 0;
6277 var d = this.DV%n, r = (this.s<0)?n-1:0;
6278 if(this.t > 0)
6279 if(d == 0) r = this[0]%n;
6280 else for(var i = this.t-1; i >= 0; --i) r = (d*r+this[i])%n;
6281 return r;
6282 }
6283
6284 // (public) 1/this % m (HAC 14.61)
6285 function bnModInverse(m) {
6286 var ac = m.isEven();
6287 if((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO;
6288 var u = m.clone(), v = this.clone();
6289 var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1);
6290 while(u.signum() != 0) {
6291 while(u.isEven()) {
6292 u.rShiftTo(1,u);
6293 if(ac) {
6294 if(!a.isEven() || !b.isEven()) { a.addTo(this,a); b.subTo(m,b); }
6295 a.rShiftTo(1,a);
6296 }
6297 else if(!b.isEven()) b.subTo(m,b);
6298 b.rShiftTo(1,b);
6299 }
6300 while(v.isEven()) {
6301 v.rShiftTo(1,v);
6302 if(ac) {
6303 if(!c.isEven() || !d.isEven()) { c.addTo(this,c); d.subTo(m,d); }
6304 c.rShiftTo(1,c);
6305 }
6306 else if(!d.isEven()) d.subTo(m,d);
6307 d.rShiftTo(1,d);
6308 }
6309 if(u.compareTo(v) >= 0) {
6310 u.subTo(v,u);
6311 if(ac) a.subTo(c,a);
6312 b.subTo(d,b);
6313 }
6314 else {
6315 v.subTo(u,v);
6316 if(ac) c.subTo(a,c);
6317 d.subTo(b,d);
6318 }
6319 }
6320 if(v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO;
6321 if(d.compareTo(m) >= 0) return d.subtract(m);
6322 if(d.signum() < 0) d.addTo(m,d); else return d;
6323 if(d.signum() < 0) return d.add(m); else return d;
6324 }
6325
6326 var lowprimes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997];
6327 var lplim = (1<<26)/lowprimes[lowprimes.length-1];
6328
6329 // (public) test primality with certainty >= 1-.5^t
6330 function bnIsProbablePrime(t) {
6331 var i, x = this.abs();
6332 if(x.t == 1 && x[0] <= lowprimes[lowprimes.length-1]) {
6333 for(i = 0; i < lowprimes.length; ++i)
6334 if(x[0] == lowprimes[i]) return true;
6335 return false;
6336 }
6337 if(x.isEven()) return false;
6338 i = 1;
6339 while(i < lowprimes.length) {
6340 var m = lowprimes[i], j = i+1;
6341 while(j < lowprimes.length && m < lplim) m *= lowprimes[j++];
6342 m = x.modInt(m);
6343 while(i < j) if(m%lowprimes[i++] == 0) return false;
6344 }
6345 return x.millerRabin(t);
6346 }
6347
6348 // (protected) true if probably prime (HAC 4.24, Miller-Rabin)
6349 function bnpMillerRabin(t) {
6350 var n1 = this.subtract(BigInteger.ONE);
6351 var k = n1.getLowestSetBit();
6352 if(k <= 0) return false;
6353 var r = n1.shiftRight(k);
6354 t = (t+1)>>1;
6355 if(t > lowprimes.length) t = lowprimes.length;
6356 var a = nbi();
6357 for(var i = 0; i < t; ++i) {
6358 //Pick bases at random, instead of starting at 2
6359 a.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);
6360 var y = a.modPow(r,this);
6361 if(y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
6362 var j = 1;
6363 while(j++ < k && y.compareTo(n1) != 0) {
6364 y = y.modPowInt(2,this);
6365 if(y.compareTo(BigInteger.ONE) == 0) return false;
6366 }
6367 if(y.compareTo(n1) != 0) return false;
6368 }
6369 }
6370 return true;
6371 }
6372
6373 // protected
6374 BigInteger.prototype.chunkSize = bnpChunkSize;
6375 BigInteger.prototype.toRadix = bnpToRadix;
6376 BigInteger.prototype.fromRadix = bnpFromRadix;
6377 BigInteger.prototype.fromNumber = bnpFromNumber;
6378 BigInteger.prototype.bitwiseTo = bnpBitwiseTo;
6379 BigInteger.prototype.changeBit = bnpChangeBit;
6380 BigInteger.prototype.addTo = bnpAddTo;
6381 BigInteger.prototype.dMultiply = bnpDMultiply;
6382 BigInteger.prototype.dAddOffset = bnpDAddOffset;
6383 BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo;
6384 BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo;
6385 BigInteger.prototype.modInt = bnpModInt;
6386 BigInteger.prototype.millerRabin = bnpMillerRabin;
6387
6388 // public
6389 BigInteger.prototype.clone = bnClone;
6390 BigInteger.prototype.intValue = bnIntValue;
6391 BigInteger.prototype.byteValue = bnByteValue;
6392 BigInteger.prototype.shortValue = bnShortValue;
6393 BigInteger.prototype.signum = bnSigNum;
6394 BigInteger.prototype.toByteArray = bnToByteArray;
6395 BigInteger.prototype.equals = bnEquals;
6396 BigInteger.prototype.min = bnMin;
6397 BigInteger.prototype.max = bnMax;
6398 BigInteger.prototype.and = bnAnd;
6399 BigInteger.prototype.or = bnOr;
6400 BigInteger.prototype.xor = bnXor;
6401 BigInteger.prototype.andNot = bnAndNot;
6402 BigInteger.prototype.not = bnNot;
6403 BigInteger.prototype.shiftLeft = bnShiftLeft;
6404 BigInteger.prototype.shiftRight = bnShiftRight;
6405 BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit;
6406 BigInteger.prototype.bitCount = bnBitCount;
6407 BigInteger.prototype.testBit = bnTestBit;
6408 BigInteger.prototype.setBit = bnSetBit;
6409 BigInteger.prototype.clearBit = bnClearBit;
6410 BigInteger.prototype.flipBit = bnFlipBit;
6411 BigInteger.prototype.add = bnAdd;
6412 BigInteger.prototype.subtract = bnSubtract;
6413 BigInteger.prototype.multiply = bnMultiply;
6414 BigInteger.prototype.divide = bnDivide;
6415 BigInteger.prototype.remainder = bnRemainder;
6416 BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder;
6417 BigInteger.prototype.modPow = bnModPow;
6418 BigInteger.prototype.modInverse = bnModInverse;
6419 BigInteger.prototype.pow = bnPow;
6420 BigInteger.prototype.gcd = bnGCD;
6421 BigInteger.prototype.isProbablePrime = bnIsProbablePrime;
6422
6423 // JSBN-specific extension
6424 BigInteger.prototype.square = bnSquare;
6425
6426 // Expose the Barrett function
6427 BigInteger.prototype.Barrett = Barrett
6428
6429 // BigInteger interfaces not implemented in jsbn:
6430
6431 // BigInteger(int signum, byte[] magnitude)
6432 // double doubleValue()
6433 // float floatValue()
6434 // int hashCode()
6435 // long longValue()
6436 // static BigInteger valueOf(long val)
6437
6438 // Random number generator - requires a PRNG backend, e.g. prng4.js
6439
6440 // For best results, put code like
6441 // <body onClick='rng_seed_time();' onKeyPress='rng_seed_time();'>
6442 // in your main HTML document.
6443
6444 var rng_state;
6445 var rng_pool;
6446 var rng_pptr;
6447
6448 // Mix in a 32-bit integer into the pool
6449 function rng_seed_int(x) {
6450 rng_pool[rng_pptr++] ^= x & 255;
6451 rng_pool[rng_pptr++] ^= (x >> 8) & 255;
6452 rng_pool[rng_pptr++] ^= (x >> 16) & 255;
6453 rng_pool[rng_pptr++] ^= (x >> 24) & 255;
6454 if(rng_pptr >= rng_psize) rng_pptr -= rng_psize;
6455 }
6456
6457 // Mix in the current time (w/milliseconds) into the pool
6458 function rng_seed_time() {
6459 rng_seed_int(new Date().getTime());
6460 }
6461
6462 // Initialize the pool with junk if needed.
6463 if(rng_pool == null) {
6464 rng_pool = new Array();
6465 rng_pptr = 0;
6466 var t;
6467 if(typeof window !== "undefined" && window.crypto) {
6468 if (window.crypto.getRandomValues) {
6469 // Use webcrypto if available
6470 var ua = new Uint8Array(32);
6471 window.crypto.getRandomValues(ua);
6472 for(t = 0; t < 32; ++t)
6473 rng_pool[rng_pptr++] = ua[t];
6474 }
6475 else if(navigator.appName == "Netscape" && navigator.appVersion < "5") {
6476 // Extract entropy (256 bits) from NS4 RNG if available
6477 var z = window.crypto.random(32);
6478 for(t = 0; t < z.length; ++t)
6479 rng_pool[rng_pptr++] = z.charCodeAt(t) & 255;
6480 }
6481 }
6482 while(rng_pptr < rng_psize) { // extract some randomness from Math.random()
6483 t = Math.floor(65536 * Math.random());
6484 rng_pool[rng_pptr++] = t >>> 8;
6485 rng_pool[rng_pptr++] = t & 255;
6486 }
6487 rng_pptr = 0;
6488 rng_seed_time();
6489 //rng_seed_int(window.screenX);
6490 //rng_seed_int(window.screenY);
6491 }
6492
6493 function rng_get_byte() {
6494 if(rng_state == null) {
6495 rng_seed_time();
6496 rng_state = prng_newstate();
6497 rng_state.init(rng_pool);
6498 for(rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr)
6499 rng_pool[rng_pptr] = 0;
6500 rng_pptr = 0;
6501 //rng_pool = null;
6502 }
6503 // TODO: allow reseeding after first request
6504 return rng_state.next();
6505 }
6506
6507 function rng_get_bytes(ba) {
6508 var i;
6509 for(i = 0; i < ba.length; ++i) ba[i] = rng_get_byte();
6510 }
6511
6512 function SecureRandom() {}
6513
6514 SecureRandom.prototype.nextBytes = rng_get_bytes;
6515
6516 // prng4.js - uses Arcfour as a PRNG
6517
6518 function Arcfour() {
6519 this.i = 0;
6520 this.j = 0;
6521 this.S = new Array();
6522 }
6523
6524 // Initialize arcfour context from key, an array of ints, each from [0..255]
6525 function ARC4init(key) {
6526 var i, j, t;
6527 for(i = 0; i < 256; ++i)
6528 this.S[i] = i;
6529 j = 0;
6530 for(i = 0; i < 256; ++i) {
6531 j = (j + this.S[i] + key[i % key.length]) & 255;
6532 t = this.S[i];
6533 this.S[i] = this.S[j];
6534 this.S[j] = t;
6535 }
6536 this.i = 0;
6537 this.j = 0;
6538 }
6539
6540 function ARC4next() {
6541 var t;
6542 this.i = (this.i + 1) & 255;
6543 this.j = (this.j + this.S[this.i]) & 255;
6544 t = this.S[this.i];
6545 this.S[this.i] = this.S[this.j];
6546 this.S[this.j] = t;
6547 return this.S[(t + this.S[this.i]) & 255];
6548 }
6549
6550 Arcfour.prototype.init = ARC4init;
6551 Arcfour.prototype.next = ARC4next;
6552
6553 // Plug in your RNG constructor here
6554 function prng_newstate() {
6555 return new Arcfour();
6556 }
6557
6558 // Pool size must be a multiple of 4 and greater than 32.
6559 // An array of bytes the size of the pool will be passed to init()
6560 var rng_psize = 256;
6561
6562 if (true) {
6563 exports = module.exports = {
6564 default: BigInteger,
6565 BigInteger: BigInteger,
6566 SecureRandom: SecureRandom,
6567 };
6568 } else {
6569 this.jsbn = {
6570 BigInteger: BigInteger,
6571 SecureRandom: SecureRandom
6572 };
6573 }
6574
6575}).call(this);
6576
6577
6578/***/ }),
6579/* 13 */
6580/***/ (function(module, exports, __webpack_require__) {
6581
6582"use strict";
6583
6584
6585
6586var zlib_inflate = __webpack_require__(20);
6587var utils = __webpack_require__(1);
6588var strings = __webpack_require__(14);
6589var c = __webpack_require__(16);
6590var msg = __webpack_require__(22);
6591var ZStream = __webpack_require__(23);
6592var GZheader = __webpack_require__(18);
6593
6594var toString = Object.prototype.toString;
6595
6596/**
6597 * class Inflate
6598 *
6599 * Generic JS-style wrapper for zlib calls. If you don't need
6600 * streaming behaviour - use more simple functions: [[inflate]]
6601 * and [[inflateRaw]].
6602 **/
6603
6604/* internal
6605 * inflate.chunks -> Array
6606 *
6607 * Chunks of output data, if [[Inflate#onData]] not overriden.
6608 **/
6609
6610/**
6611 * Inflate.result -> Uint8Array|Array|String
6612 *
6613 * Uncompressed result, generated by default [[Inflate#onData]]
6614 * and [[Inflate#onEnd]] handlers. Filled after you push last chunk
6615 * (call [[Inflate#push]] with `Z_FINISH` / `true` param) or if you
6616 * push a chunk with explicit flush (call [[Inflate#push]] with
6617 * `Z_SYNC_FLUSH` param).
6618 **/
6619
6620/**
6621 * Inflate.err -> Number
6622 *
6623 * Error code after inflate finished. 0 (Z_OK) on success.
6624 * Should be checked if broken data possible.
6625 **/
6626
6627/**
6628 * Inflate.msg -> String
6629 *
6630 * Error message, if [[Inflate.err]] != 0
6631 **/
6632
6633
6634/**
6635 * new Inflate(options)
6636 * - options (Object): zlib inflate options.
6637 *
6638 * Creates new inflator instance with specified params. Throws exception
6639 * on bad params. Supported options:
6640 *
6641 * - `windowBits`
6642 * - `dictionary`
6643 *
6644 * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
6645 * for more information on these.
6646 *
6647 * Additional options, for internal needs:
6648 *
6649 * - `chunkSize` - size of generated data chunks (16K by default)
6650 * - `raw` (Boolean) - do raw inflate
6651 * - `to` (String) - if equal to 'string', then result will be converted
6652 * from utf8 to utf16 (javascript) string. When string output requested,
6653 * chunk length can differ from `chunkSize`, depending on content.
6654 *
6655 * By default, when no options set, autodetect deflate/gzip data format via
6656 * wrapper header.
6657 *
6658 * ##### Example:
6659 *
6660 * ```javascript
6661 * var pako = require('pako')
6662 * , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
6663 * , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
6664 *
6665 * var inflate = new pako.Inflate({ level: 3});
6666 *
6667 * inflate.push(chunk1, false);
6668 * inflate.push(chunk2, true); // true -> last chunk
6669 *
6670 * if (inflate.err) { throw new Error(inflate.err); }
6671 *
6672 * console.log(inflate.result);
6673 * ```
6674 **/
6675function Inflate(options) {
6676 if (!(this instanceof Inflate)) return new Inflate(options);
6677
6678 this.options = utils.assign({
6679 chunkSize: 16384,
6680 windowBits: 0,
6681 to: ''
6682 }, options || {});
6683
6684 var opt = this.options;
6685
6686 // Force window size for `raw` data, if not set directly,
6687 // because we have no header for autodetect.
6688 if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {
6689 opt.windowBits = -opt.windowBits;
6690 if (opt.windowBits === 0) { opt.windowBits = -15; }
6691 }
6692
6693 // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
6694 if ((opt.windowBits >= 0) && (opt.windowBits < 16) &&
6695 !(options && options.windowBits)) {
6696 opt.windowBits += 32;
6697 }
6698
6699 // Gzip header has no info about windows size, we can do autodetect only
6700 // for deflate. So, if window size not set, force it to max when gzip possible
6701 if ((opt.windowBits > 15) && (opt.windowBits < 48)) {
6702 // bit 3 (16) -> gzipped data
6703 // bit 4 (32) -> autodetect gzip/deflate
6704 if ((opt.windowBits & 15) === 0) {
6705 opt.windowBits |= 15;
6706 }
6707 }
6708
6709 this.err = 0; // error code, if happens (0 = Z_OK)
6710 this.msg = ''; // error message
6711 this.ended = false; // used to avoid multiple onEnd() calls
6712 this.chunks = []; // chunks of compressed data
6713
6714 this.strm = new ZStream();
6715 this.strm.avail_out = 0;
6716
6717 var status = zlib_inflate.inflateInit2(
6718 this.strm,
6719 opt.windowBits
6720 );
6721
6722 if (status !== c.Z_OK) {
6723 throw new Error(msg[status]);
6724 }
6725
6726 this.header = new GZheader();
6727
6728 zlib_inflate.inflateGetHeader(this.strm, this.header);
6729}
6730
6731/**
6732 * Inflate#push(data[, mode]) -> Boolean
6733 * - data (Uint8Array|Array|ArrayBuffer|String): input data
6734 * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
6735 * See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.
6736 *
6737 * Sends input data to inflate pipe, generating [[Inflate#onData]] calls with
6738 * new output chunks. Returns `true` on success. The last data block must have
6739 * mode Z_FINISH (or `true`). That will flush internal pending buffers and call
6740 * [[Inflate#onEnd]]. For interim explicit flushes (without ending the stream) you
6741 * can use mode Z_SYNC_FLUSH, keeping the decompression context.
6742 *
6743 * On fail call [[Inflate#onEnd]] with error code and return false.
6744 *
6745 * We strongly recommend to use `Uint8Array` on input for best speed (output
6746 * format is detected automatically). Also, don't skip last param and always
6747 * use the same type in your code (boolean or number). That will improve JS speed.
6748 *
6749 * For regular `Array`-s make sure all elements are [0..255].
6750 *
6751 * ##### Example
6752 *
6753 * ```javascript
6754 * push(chunk, false); // push one of data chunks
6755 * ...
6756 * push(chunk, true); // push last chunk
6757 * ```
6758 **/
6759Inflate.prototype.push = function (data, mode) {
6760 var strm = this.strm;
6761 var chunkSize = this.options.chunkSize;
6762 var dictionary = this.options.dictionary;
6763 var status, _mode;
6764 var next_out_utf8, tail, utf8str;
6765 var dict;
6766
6767 // Flag to properly process Z_BUF_ERROR on testing inflate call
6768 // when we check that all output data was flushed.
6769 var allowBufError = false;
6770
6771 if (this.ended) { return false; }
6772 _mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH);
6773
6774 // Convert data if needed
6775 if (typeof data === 'string') {
6776 // Only binary strings can be decompressed on practice
6777 strm.input = strings.binstring2buf(data);
6778 } else if (toString.call(data) === '[object ArrayBuffer]') {
6779 strm.input = new Uint8Array(data);
6780 } else {
6781 strm.input = data;
6782 }
6783
6784 strm.next_in = 0;
6785 strm.avail_in = strm.input.length;
6786
6787 do {
6788 if (strm.avail_out === 0) {
6789 strm.output = new utils.Buf8(chunkSize);
6790 strm.next_out = 0;
6791 strm.avail_out = chunkSize;
6792 }
6793
6794 status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH); /* no bad return value */
6795
6796 if (status === c.Z_NEED_DICT && dictionary) {
6797 // Convert data if needed
6798 if (typeof dictionary === 'string') {
6799 dict = strings.string2buf(dictionary);
6800 } else if (toString.call(dictionary) === '[object ArrayBuffer]') {
6801 dict = new Uint8Array(dictionary);
6802 } else {
6803 dict = dictionary;
6804 }
6805
6806 status = zlib_inflate.inflateSetDictionary(this.strm, dict);
6807
6808 }
6809
6810 if (status === c.Z_BUF_ERROR && allowBufError === true) {
6811 status = c.Z_OK;
6812 allowBufError = false;
6813 }
6814
6815 if (status !== c.Z_STREAM_END && status !== c.Z_OK) {
6816 this.onEnd(status);
6817 this.ended = true;
6818 return false;
6819 }
6820
6821 if (strm.next_out) {
6822 if (strm.avail_out === 0 || status === c.Z_STREAM_END || (strm.avail_in === 0 && (_mode === c.Z_FINISH || _mode === c.Z_SYNC_FLUSH))) {
6823
6824 if (this.options.to === 'string') {
6825
6826 next_out_utf8 = strings.utf8border(strm.output, strm.next_out);
6827
6828 tail = strm.next_out - next_out_utf8;
6829 utf8str = strings.buf2string(strm.output, next_out_utf8);
6830
6831 // move tail
6832 strm.next_out = tail;
6833 strm.avail_out = chunkSize - tail;
6834 if (tail) { utils.arraySet(strm.output, strm.output, next_out_utf8, tail, 0); }
6835
6836 this.onData(utf8str);
6837
6838 } else {
6839 this.onData(utils.shrinkBuf(strm.output, strm.next_out));
6840 }
6841 }
6842 }
6843
6844 // When no more input data, we should check that internal inflate buffers
6845 // are flushed. The only way to do it when avail_out = 0 - run one more
6846 // inflate pass. But if output data not exists, inflate return Z_BUF_ERROR.
6847 // Here we set flag to process this error properly.
6848 //
6849 // NOTE. Deflate does not return error in this case and does not needs such
6850 // logic.
6851 if (strm.avail_in === 0 && strm.avail_out === 0) {
6852 allowBufError = true;
6853 }
6854
6855 } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== c.Z_STREAM_END);
6856
6857 if (status === c.Z_STREAM_END) {
6858 _mode = c.Z_FINISH;
6859 }
6860
6861 // Finalize on the last chunk.
6862 if (_mode === c.Z_FINISH) {
6863 status = zlib_inflate.inflateEnd(this.strm);
6864 this.onEnd(status);
6865 this.ended = true;
6866 return status === c.Z_OK;
6867 }
6868
6869 // callback interim results if Z_SYNC_FLUSH.
6870 if (_mode === c.Z_SYNC_FLUSH) {
6871 this.onEnd(c.Z_OK);
6872 strm.avail_out = 0;
6873 return true;
6874 }
6875
6876 return true;
6877};
6878
6879
6880/**
6881 * Inflate#onData(chunk) -> Void
6882 * - chunk (Uint8Array|Array|String): ouput data. Type of array depends
6883 * on js engine support. When string output requested, each chunk
6884 * will be string.
6885 *
6886 * By default, stores data blocks in `chunks[]` property and glue
6887 * those in `onEnd`. Override this handler, if you need another behaviour.
6888 **/
6889Inflate.prototype.onData = function (chunk) {
6890 this.chunks.push(chunk);
6891};
6892
6893
6894/**
6895 * Inflate#onEnd(status) -> Void
6896 * - status (Number): inflate status. 0 (Z_OK) on success,
6897 * other if not.
6898 *
6899 * Called either after you tell inflate that the input stream is
6900 * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH)
6901 * or if an error happened. By default - join collected chunks,
6902 * free memory and fill `results` / `err` properties.
6903 **/
6904Inflate.prototype.onEnd = function (status) {
6905 // On success - join
6906 if (status === c.Z_OK) {
6907 if (this.options.to === 'string') {
6908 // Glue & convert here, until we teach pako to send
6909 // utf8 alligned strings to onData
6910 this.result = this.chunks.join('');
6911 } else {
6912 this.result = utils.flattenChunks(this.chunks);
6913 }
6914 }
6915 this.chunks = [];
6916 this.err = status;
6917 this.msg = this.strm.msg;
6918};
6919
6920
6921/**
6922 * inflate(data[, options]) -> Uint8Array|Array|String
6923 * - data (Uint8Array|Array|String): input data to decompress.
6924 * - options (Object): zlib inflate options.
6925 *
6926 * Decompress `data` with inflate/ungzip and `options`. Autodetect
6927 * format via wrapper header by default. That's why we don't provide
6928 * separate `ungzip` method.
6929 *
6930 * Supported options are:
6931 *
6932 * - windowBits
6933 *
6934 * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
6935 * for more information.
6936 *
6937 * Sugar (options):
6938 *
6939 * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
6940 * negative windowBits implicitly.
6941 * - `to` (String) - if equal to 'string', then result will be converted
6942 * from utf8 to utf16 (javascript) string. When string output requested,
6943 * chunk length can differ from `chunkSize`, depending on content.
6944 *
6945 *
6946 * ##### Example:
6947 *
6948 * ```javascript
6949 * var pako = require('pako')
6950 * , input = pako.deflate([1,2,3,4,5,6,7,8,9])
6951 * , output;
6952 *
6953 * try {
6954 * output = pako.inflate(input);
6955 * } catch (err)
6956 * console.log(err);
6957 * }
6958 * ```
6959 **/
6960function inflate(input, options) {
6961 var inflator = new Inflate(options);
6962
6963 inflator.push(input, true);
6964
6965 // That will never happens, if you don't cheat with options :)
6966 if (inflator.err) { throw inflator.msg || msg[inflator.err]; }
6967
6968 return inflator.result;
6969}
6970
6971
6972/**
6973 * inflateRaw(data[, options]) -> Uint8Array|Array|String
6974 * - data (Uint8Array|Array|String): input data to decompress.
6975 * - options (Object): zlib inflate options.
6976 *
6977 * The same as [[inflate]], but creates raw data, without wrapper
6978 * (header and adler32 crc).
6979 **/
6980function inflateRaw(input, options) {
6981 options = options || {};
6982 options.raw = true;
6983 return inflate(input, options);
6984}
6985
6986
6987/**
6988 * ungzip(data[, options]) -> Uint8Array|Array|String
6989 * - data (Uint8Array|Array|String): input data to decompress.
6990 * - options (Object): zlib inflate options.
6991 *
6992 * Just shortcut to [[inflate]], because it autodetects format
6993 * by header.content. Done for convenience.
6994 **/
6995
6996
6997exports.Inflate = Inflate;
6998exports.inflate = inflate;
6999exports.inflateRaw = inflateRaw;
7000exports.ungzip = inflate;
7001
7002
7003/***/ }),
7004/* 14 */
7005/***/ (function(module, exports, __webpack_require__) {
7006
7007"use strict";
7008// String encode/decode helpers
7009
7010
7011
7012var utils = __webpack_require__(1);
7013
7014
7015// Quick check if we can use fast array to bin string conversion
7016//
7017// - apply(Array) can fail on Android 2.2
7018// - apply(Uint8Array) can fail on iOS 5.1 Safary
7019//
7020var STR_APPLY_OK = true;
7021var STR_APPLY_UIA_OK = true;
7022
7023try { String.fromCharCode.apply(null, [ 0 ]); } catch (__) { STR_APPLY_OK = false; }
7024try { String.fromCharCode.apply(null, new Uint8Array(1)); } catch (__) { STR_APPLY_UIA_OK = false; }
7025
7026
7027// Table with utf8 lengths (calculated by first byte of sequence)
7028// Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,
7029// because max possible codepoint is 0x10ffff
7030var _utf8len = new utils.Buf8(256);
7031for (var q = 0; q < 256; q++) {
7032 _utf8len[q] = (q >= 252 ? 6 : q >= 248 ? 5 : q >= 240 ? 4 : q >= 224 ? 3 : q >= 192 ? 2 : 1);
7033}
7034_utf8len[254] = _utf8len[254] = 1; // Invalid sequence start
7035
7036
7037// convert string to array (typed, when possible)
7038exports.string2buf = function (str) {
7039 var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0;
7040
7041 // count binary size
7042 for (m_pos = 0; m_pos < str_len; m_pos++) {
7043 c = str.charCodeAt(m_pos);
7044 if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) {
7045 c2 = str.charCodeAt(m_pos + 1);
7046 if ((c2 & 0xfc00) === 0xdc00) {
7047 c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
7048 m_pos++;
7049 }
7050 }
7051 buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;
7052 }
7053
7054 // allocate buffer
7055 buf = new utils.Buf8(buf_len);
7056
7057 // convert
7058 for (i = 0, m_pos = 0; i < buf_len; m_pos++) {
7059 c = str.charCodeAt(m_pos);
7060 if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) {
7061 c2 = str.charCodeAt(m_pos + 1);
7062 if ((c2 & 0xfc00) === 0xdc00) {
7063 c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
7064 m_pos++;
7065 }
7066 }
7067 if (c < 0x80) {
7068 /* one byte */
7069 buf[i++] = c;
7070 } else if (c < 0x800) {
7071 /* two bytes */
7072 buf[i++] = 0xC0 | (c >>> 6);
7073 buf[i++] = 0x80 | (c & 0x3f);
7074 } else if (c < 0x10000) {
7075 /* three bytes */
7076 buf[i++] = 0xE0 | (c >>> 12);
7077 buf[i++] = 0x80 | (c >>> 6 & 0x3f);
7078 buf[i++] = 0x80 | (c & 0x3f);
7079 } else {
7080 /* four bytes */
7081 buf[i++] = 0xf0 | (c >>> 18);
7082 buf[i++] = 0x80 | (c >>> 12 & 0x3f);
7083 buf[i++] = 0x80 | (c >>> 6 & 0x3f);
7084 buf[i++] = 0x80 | (c & 0x3f);
7085 }
7086 }
7087
7088 return buf;
7089};
7090
7091// Helper (used in 2 places)
7092function buf2binstring(buf, len) {
7093 // use fallback for big arrays to avoid stack overflow
7094 if (len < 65537) {
7095 if ((buf.subarray && STR_APPLY_UIA_OK) || (!buf.subarray && STR_APPLY_OK)) {
7096 return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len));
7097 }
7098 }
7099
7100 var result = '';
7101 for (var i = 0; i < len; i++) {
7102 result += String.fromCharCode(buf[i]);
7103 }
7104 return result;
7105}
7106
7107
7108// Convert byte array to binary string
7109exports.buf2binstring = function (buf) {
7110 return buf2binstring(buf, buf.length);
7111};
7112
7113
7114// Convert binary string (typed, when possible)
7115exports.binstring2buf = function (str) {
7116 var buf = new utils.Buf8(str.length);
7117 for (var i = 0, len = buf.length; i < len; i++) {
7118 buf[i] = str.charCodeAt(i);
7119 }
7120 return buf;
7121};
7122
7123
7124// convert array to string
7125exports.buf2string = function (buf, max) {
7126 var i, out, c, c_len;
7127 var len = max || buf.length;
7128
7129 // Reserve max possible length (2 words per char)
7130 // NB: by unknown reasons, Array is significantly faster for
7131 // String.fromCharCode.apply than Uint16Array.
7132 var utf16buf = new Array(len * 2);
7133
7134 for (out = 0, i = 0; i < len;) {
7135 c = buf[i++];
7136 // quick process ascii
7137 if (c < 0x80) { utf16buf[out++] = c; continue; }
7138
7139 c_len = _utf8len[c];
7140 // skip 5 & 6 byte codes
7141 if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len - 1; continue; }
7142
7143 // apply mask on first byte
7144 c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;
7145 // join the rest
7146 while (c_len > 1 && i < len) {
7147 c = (c << 6) | (buf[i++] & 0x3f);
7148 c_len--;
7149 }
7150
7151 // terminated by end of string?
7152 if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; }
7153
7154 if (c < 0x10000) {
7155 utf16buf[out++] = c;
7156 } else {
7157 c -= 0x10000;
7158 utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff);
7159 utf16buf[out++] = 0xdc00 | (c & 0x3ff);
7160 }
7161 }
7162
7163 return buf2binstring(utf16buf, out);
7164};
7165
7166
7167// Calculate max possible position in utf8 buffer,
7168// that will not break sequence. If that's not possible
7169// - (very small limits) return max size as is.
7170//
7171// buf[] - utf8 bytes array
7172// max - length limit (mandatory);
7173exports.utf8border = function (buf, max) {
7174 var pos;
7175
7176 max = max || buf.length;
7177 if (max > buf.length) { max = buf.length; }
7178
7179 // go back from last position, until start of sequence found
7180 pos = max - 1;
7181 while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }
7182
7183 // Fuckup - very small and broken sequence,
7184 // return max, because we should return something anyway.
7185 if (pos < 0) { return max; }
7186
7187 // If we came to start of buffer - that means vuffer is too small,
7188 // return max too.
7189 if (pos === 0) { return max; }
7190
7191 return (pos + _utf8len[buf[pos]] > max) ? pos : max;
7192};
7193
7194
7195/***/ }),
7196/* 15 */
7197/***/ (function(module, exports, __webpack_require__) {
7198
7199"use strict";
7200
7201
7202// Note: adler32 takes 12% for level 0 and 2% for level 6.
7203// It doesn't worth to make additional optimizationa as in original.
7204// Small size is preferable.
7205
7206function adler32(adler, buf, len, pos) {
7207 var s1 = (adler & 0xffff) |0,
7208 s2 = ((adler >>> 16) & 0xffff) |0,
7209 n = 0;
7210
7211 while (len !== 0) {
7212 // Set limit ~ twice less than 5552, to keep
7213 // s2 in 31-bits, because we force signed ints.
7214 // in other case %= will fail.
7215 n = len > 2000 ? 2000 : len;
7216 len -= n;
7217
7218 do {
7219 s1 = (s1 + buf[pos++]) |0;
7220 s2 = (s2 + s1) |0;
7221 } while (--n);
7222
7223 s1 %= 65521;
7224 s2 %= 65521;
7225 }
7226
7227 return (s1 | (s2 << 16)) |0;
7228}
7229
7230
7231module.exports = adler32;
7232
7233
7234/***/ }),
7235/* 16 */
7236/***/ (function(module, exports, __webpack_require__) {
7237
7238"use strict";
7239
7240
7241
7242module.exports = {
7243
7244 /* Allowed flush values; see deflate() and inflate() below for details */
7245 Z_NO_FLUSH: 0,
7246 Z_PARTIAL_FLUSH: 1,
7247 Z_SYNC_FLUSH: 2,
7248 Z_FULL_FLUSH: 3,
7249 Z_FINISH: 4,
7250 Z_BLOCK: 5,
7251 Z_TREES: 6,
7252
7253 /* Return codes for the compression/decompression functions. Negative values
7254 * are errors, positive values are used for special but normal events.
7255 */
7256 Z_OK: 0,
7257 Z_STREAM_END: 1,
7258 Z_NEED_DICT: 2,
7259 Z_ERRNO: -1,
7260 Z_STREAM_ERROR: -2,
7261 Z_DATA_ERROR: -3,
7262 //Z_MEM_ERROR: -4,
7263 Z_BUF_ERROR: -5,
7264 //Z_VERSION_ERROR: -6,
7265
7266 /* compression levels */
7267 Z_NO_COMPRESSION: 0,
7268 Z_BEST_SPEED: 1,
7269 Z_BEST_COMPRESSION: 9,
7270 Z_DEFAULT_COMPRESSION: -1,
7271
7272
7273 Z_FILTERED: 1,
7274 Z_HUFFMAN_ONLY: 2,
7275 Z_RLE: 3,
7276 Z_FIXED: 4,
7277 Z_DEFAULT_STRATEGY: 0,
7278
7279 /* Possible values of the data_type field (though see inflate()) */
7280 Z_BINARY: 0,
7281 Z_TEXT: 1,
7282 //Z_ASCII: 1, // = Z_TEXT (deprecated)
7283 Z_UNKNOWN: 2,
7284
7285 /* The deflate compression method */
7286 Z_DEFLATED: 8
7287 //Z_NULL: null // Use -1 or null inline, depending on var type
7288};
7289
7290
7291/***/ }),
7292/* 17 */
7293/***/ (function(module, exports, __webpack_require__) {
7294
7295"use strict";
7296
7297
7298// Note: we can't get significant speed boost here.
7299// So write code to minimize size - no pregenerated tables
7300// and array tools dependencies.
7301
7302
7303// Use ordinary array, since untyped makes no boost here
7304function makeTable() {
7305 var c, table = [];
7306
7307 for (var n = 0; n < 256; n++) {
7308 c = n;
7309 for (var k = 0; k < 8; k++) {
7310 c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
7311 }
7312 table[n] = c;
7313 }
7314
7315 return table;
7316}
7317
7318// Create table on load. Just 255 signed longs. Not a problem.
7319var crcTable = makeTable();
7320
7321
7322function crc32(crc, buf, len, pos) {
7323 var t = crcTable,
7324 end = pos + len;
7325
7326 crc ^= -1;
7327
7328 for (var i = pos; i < end; i++) {
7329 crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF];
7330 }
7331
7332 return (crc ^ (-1)); // >>> 0;
7333}
7334
7335
7336module.exports = crc32;
7337
7338
7339/***/ }),
7340/* 18 */
7341/***/ (function(module, exports, __webpack_require__) {
7342
7343"use strict";
7344
7345
7346
7347function GZheader() {
7348 /* true if compressed data believed to be text */
7349 this.text = 0;
7350 /* modification time */
7351 this.time = 0;
7352 /* extra flags (not used when writing a gzip file) */
7353 this.xflags = 0;
7354 /* operating system */
7355 this.os = 0;
7356 /* pointer to extra field or Z_NULL if none */
7357 this.extra = null;
7358 /* extra field length (valid if extra != Z_NULL) */
7359 this.extra_len = 0; // Actually, we don't need it in JS,
7360 // but leave for few code modifications
7361
7362 //
7363 // Setup limits is not necessary because in js we should not preallocate memory
7364 // for inflate use constant limit in 65536 bytes
7365 //
7366
7367 /* space at extra (only when reading header) */
7368 // this.extra_max = 0;
7369 /* pointer to zero-terminated file name or Z_NULL */
7370 this.name = '';
7371 /* space at name (only when reading header) */
7372 // this.name_max = 0;
7373 /* pointer to zero-terminated comment or Z_NULL */
7374 this.comment = '';
7375 /* space at comment (only when reading header) */
7376 // this.comm_max = 0;
7377 /* true if there was or will be a header crc */
7378 this.hcrc = 0;
7379 /* true when done reading gzip header (not used when writing a gzip file) */
7380 this.done = false;
7381}
7382
7383module.exports = GZheader;
7384
7385
7386/***/ }),
7387/* 19 */
7388/***/ (function(module, exports, __webpack_require__) {
7389
7390"use strict";
7391
7392
7393// See state defs from inflate.js
7394var BAD = 30; /* got a data error -- remain here until reset */
7395var TYPE = 12; /* i: waiting for type bits, including last-flag bit */
7396
7397/*
7398 Decode literal, length, and distance codes and write out the resulting
7399 literal and match bytes until either not enough input or output is
7400 available, an end-of-block is encountered, or a data error is encountered.
7401 When large enough input and output buffers are supplied to inflate(), for
7402 example, a 16K input buffer and a 64K output buffer, more than 95% of the
7403 inflate execution time is spent in this routine.
7404
7405 Entry assumptions:
7406
7407 state.mode === LEN
7408 strm.avail_in >= 6
7409 strm.avail_out >= 258
7410 start >= strm.avail_out
7411 state.bits < 8
7412
7413 On return, state.mode is one of:
7414
7415 LEN -- ran out of enough output space or enough available input
7416 TYPE -- reached end of block code, inflate() to interpret next block
7417 BAD -- error in block data
7418
7419 Notes:
7420
7421 - The maximum input bits used by a length/distance pair is 15 bits for the
7422 length code, 5 bits for the length extra, 15 bits for the distance code,
7423 and 13 bits for the distance extra. This totals 48 bits, or six bytes.
7424 Therefore if strm.avail_in >= 6, then there is enough input to avoid
7425 checking for available input while decoding.
7426
7427 - The maximum bytes that a single length/distance pair can output is 258
7428 bytes, which is the maximum length that can be coded. inflate_fast()
7429 requires strm.avail_out >= 258 for each loop to avoid checking for
7430 output space.
7431 */
7432module.exports = function inflate_fast(strm, start) {
7433 var state;
7434 var _in; /* local strm.input */
7435 var last; /* have enough input while in < last */
7436 var _out; /* local strm.output */
7437 var beg; /* inflate()'s initial strm.output */
7438 var end; /* while out < end, enough space available */
7439//#ifdef INFLATE_STRICT
7440 var dmax; /* maximum distance from zlib header */
7441//#endif
7442 var wsize; /* window size or zero if not using window */
7443 var whave; /* valid bytes in the window */
7444 var wnext; /* window write index */
7445 // Use `s_window` instead `window`, avoid conflict with instrumentation tools
7446 var s_window; /* allocated sliding window, if wsize != 0 */
7447 var hold; /* local strm.hold */
7448 var bits; /* local strm.bits */
7449 var lcode; /* local strm.lencode */
7450 var dcode; /* local strm.distcode */
7451 var lmask; /* mask for first level of length codes */
7452 var dmask; /* mask for first level of distance codes */
7453 var here; /* retrieved table entry */
7454 var op; /* code bits, operation, extra bits, or */
7455 /* window position, window bytes to copy */
7456 var len; /* match length, unused bytes */
7457 var dist; /* match distance */
7458 var from; /* where to copy match from */
7459 var from_source;
7460
7461
7462 var input, output; // JS specific, because we have no pointers
7463
7464 /* copy state to local variables */
7465 state = strm.state;
7466 //here = state.here;
7467 _in = strm.next_in;
7468 input = strm.input;
7469 last = _in + (strm.avail_in - 5);
7470 _out = strm.next_out;
7471 output = strm.output;
7472 beg = _out - (start - strm.avail_out);
7473 end = _out + (strm.avail_out - 257);
7474//#ifdef INFLATE_STRICT
7475 dmax = state.dmax;
7476//#endif
7477 wsize = state.wsize;
7478 whave = state.whave;
7479 wnext = state.wnext;
7480 s_window = state.window;
7481 hold = state.hold;
7482 bits = state.bits;
7483 lcode = state.lencode;
7484 dcode = state.distcode;
7485 lmask = (1 << state.lenbits) - 1;
7486 dmask = (1 << state.distbits) - 1;
7487
7488
7489 /* decode literals and length/distances until end-of-block or not enough
7490 input data or output space */
7491
7492 top:
7493 do {
7494 if (bits < 15) {
7495 hold += input[_in++] << bits;
7496 bits += 8;
7497 hold += input[_in++] << bits;
7498 bits += 8;
7499 }
7500
7501 here = lcode[hold & lmask];
7502
7503 dolen:
7504 for (;;) { // Goto emulation
7505 op = here >>> 24/*here.bits*/;
7506 hold >>>= op;
7507 bits -= op;
7508 op = (here >>> 16) & 0xff/*here.op*/;
7509 if (op === 0) { /* literal */
7510 //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
7511 // "inflate: literal '%c'\n" :
7512 // "inflate: literal 0x%02x\n", here.val));
7513 output[_out++] = here & 0xffff/*here.val*/;
7514 }
7515 else if (op & 16) { /* length base */
7516 len = here & 0xffff/*here.val*/;
7517 op &= 15; /* number of extra bits */
7518 if (op) {
7519 if (bits < op) {
7520 hold += input[_in++] << bits;
7521 bits += 8;
7522 }
7523 len += hold & ((1 << op) - 1);
7524 hold >>>= op;
7525 bits -= op;
7526 }
7527 //Tracevv((stderr, "inflate: length %u\n", len));
7528 if (bits < 15) {
7529 hold += input[_in++] << bits;
7530 bits += 8;
7531 hold += input[_in++] << bits;
7532 bits += 8;
7533 }
7534 here = dcode[hold & dmask];
7535
7536 dodist:
7537 for (;;) { // goto emulation
7538 op = here >>> 24/*here.bits*/;
7539 hold >>>= op;
7540 bits -= op;
7541 op = (here >>> 16) & 0xff/*here.op*/;
7542
7543 if (op & 16) { /* distance base */
7544 dist = here & 0xffff/*here.val*/;
7545 op &= 15; /* number of extra bits */
7546 if (bits < op) {
7547 hold += input[_in++] << bits;
7548 bits += 8;
7549 if (bits < op) {
7550 hold += input[_in++] << bits;
7551 bits += 8;
7552 }
7553 }
7554 dist += hold & ((1 << op) - 1);
7555//#ifdef INFLATE_STRICT
7556 if (dist > dmax) {
7557 strm.msg = 'invalid distance too far back';
7558 state.mode = BAD;
7559 break top;
7560 }
7561//#endif
7562 hold >>>= op;
7563 bits -= op;
7564 //Tracevv((stderr, "inflate: distance %u\n", dist));
7565 op = _out - beg; /* max distance in output */
7566 if (dist > op) { /* see if copy from window */
7567 op = dist - op; /* distance back in window */
7568 if (op > whave) {
7569 if (state.sane) {
7570 strm.msg = 'invalid distance too far back';
7571 state.mode = BAD;
7572 break top;
7573 }
7574
7575// (!) This block is disabled in zlib defailts,
7576// don't enable it for binary compatibility
7577//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
7578// if (len <= op - whave) {
7579// do {
7580// output[_out++] = 0;
7581// } while (--len);
7582// continue top;
7583// }
7584// len -= op - whave;
7585// do {
7586// output[_out++] = 0;
7587// } while (--op > whave);
7588// if (op === 0) {
7589// from = _out - dist;
7590// do {
7591// output[_out++] = output[from++];
7592// } while (--len);
7593// continue top;
7594// }
7595//#endif
7596 }
7597 from = 0; // window index
7598 from_source = s_window;
7599 if (wnext === 0) { /* very common case */
7600 from += wsize - op;
7601 if (op < len) { /* some from window */
7602 len -= op;
7603 do {
7604 output[_out++] = s_window[from++];
7605 } while (--op);
7606 from = _out - dist; /* rest from output */
7607 from_source = output;
7608 }
7609 }
7610 else if (wnext < op) { /* wrap around window */
7611 from += wsize + wnext - op;
7612 op -= wnext;
7613 if (op < len) { /* some from end of window */
7614 len -= op;
7615 do {
7616 output[_out++] = s_window[from++];
7617 } while (--op);
7618 from = 0;
7619 if (wnext < len) { /* some from start of window */
7620 op = wnext;
7621 len -= op;
7622 do {
7623 output[_out++] = s_window[from++];
7624 } while (--op);
7625 from = _out - dist; /* rest from output */
7626 from_source = output;
7627 }
7628 }
7629 }
7630 else { /* contiguous in window */
7631 from += wnext - op;
7632 if (op < len) { /* some from window */
7633 len -= op;
7634 do {
7635 output[_out++] = s_window[from++];
7636 } while (--op);
7637 from = _out - dist; /* rest from output */
7638 from_source = output;
7639 }
7640 }
7641 while (len > 2) {
7642 output[_out++] = from_source[from++];
7643 output[_out++] = from_source[from++];
7644 output[_out++] = from_source[from++];
7645 len -= 3;
7646 }
7647 if (len) {
7648 output[_out++] = from_source[from++];
7649 if (len > 1) {
7650 output[_out++] = from_source[from++];
7651 }
7652 }
7653 }
7654 else {
7655 from = _out - dist; /* copy direct from output */
7656 do { /* minimum length is three */
7657 output[_out++] = output[from++];
7658 output[_out++] = output[from++];
7659 output[_out++] = output[from++];
7660 len -= 3;
7661 } while (len > 2);
7662 if (len) {
7663 output[_out++] = output[from++];
7664 if (len > 1) {
7665 output[_out++] = output[from++];
7666 }
7667 }
7668 }
7669 }
7670 else if ((op & 64) === 0) { /* 2nd level distance code */
7671 here = dcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
7672 continue dodist;
7673 }
7674 else {
7675 strm.msg = 'invalid distance code';
7676 state.mode = BAD;
7677 break top;
7678 }
7679
7680 break; // need to emulate goto via "continue"
7681 }
7682 }
7683 else if ((op & 64) === 0) { /* 2nd level length code */
7684 here = lcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
7685 continue dolen;
7686 }
7687 else if (op & 32) { /* end-of-block */
7688 //Tracevv((stderr, "inflate: end of block\n"));
7689 state.mode = TYPE;
7690 break top;
7691 }
7692 else {
7693 strm.msg = 'invalid literal/length code';
7694 state.mode = BAD;
7695 break top;
7696 }
7697
7698 break; // need to emulate goto via "continue"
7699 }
7700 } while (_in < last && _out < end);
7701
7702 /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
7703 len = bits >> 3;
7704 _in -= len;
7705 bits -= len << 3;
7706 hold &= (1 << bits) - 1;
7707
7708 /* update state and return */
7709 strm.next_in = _in;
7710 strm.next_out = _out;
7711 strm.avail_in = (_in < last ? 5 + (last - _in) : 5 - (_in - last));
7712 strm.avail_out = (_out < end ? 257 + (end - _out) : 257 - (_out - end));
7713 state.hold = hold;
7714 state.bits = bits;
7715 return;
7716};
7717
7718
7719/***/ }),
7720/* 20 */
7721/***/ (function(module, exports, __webpack_require__) {
7722
7723"use strict";
7724
7725
7726
7727var utils = __webpack_require__(1);
7728var adler32 = __webpack_require__(15);
7729var crc32 = __webpack_require__(17);
7730var inflate_fast = __webpack_require__(19);
7731var inflate_table = __webpack_require__(21);
7732
7733var CODES = 0;
7734var LENS = 1;
7735var DISTS = 2;
7736
7737/* Public constants ==========================================================*/
7738/* ===========================================================================*/
7739
7740
7741/* Allowed flush values; see deflate() and inflate() below for details */
7742//var Z_NO_FLUSH = 0;
7743//var Z_PARTIAL_FLUSH = 1;
7744//var Z_SYNC_FLUSH = 2;
7745//var Z_FULL_FLUSH = 3;
7746var Z_FINISH = 4;
7747var Z_BLOCK = 5;
7748var Z_TREES = 6;
7749
7750
7751/* Return codes for the compression/decompression functions. Negative values
7752 * are errors, positive values are used for special but normal events.
7753 */
7754var Z_OK = 0;
7755var Z_STREAM_END = 1;
7756var Z_NEED_DICT = 2;
7757//var Z_ERRNO = -1;
7758var Z_STREAM_ERROR = -2;
7759var Z_DATA_ERROR = -3;
7760var Z_MEM_ERROR = -4;
7761var Z_BUF_ERROR = -5;
7762//var Z_VERSION_ERROR = -6;
7763
7764/* The deflate compression method */
7765var Z_DEFLATED = 8;
7766
7767
7768/* STATES ====================================================================*/
7769/* ===========================================================================*/
7770
7771
7772var HEAD = 1; /* i: waiting for magic header */
7773var FLAGS = 2; /* i: waiting for method and flags (gzip) */
7774var TIME = 3; /* i: waiting for modification time (gzip) */
7775var OS = 4; /* i: waiting for extra flags and operating system (gzip) */
7776var EXLEN = 5; /* i: waiting for extra length (gzip) */
7777var EXTRA = 6; /* i: waiting for extra bytes (gzip) */
7778var NAME = 7; /* i: waiting for end of file name (gzip) */
7779var COMMENT = 8; /* i: waiting for end of comment (gzip) */
7780var HCRC = 9; /* i: waiting for header crc (gzip) */
7781var DICTID = 10; /* i: waiting for dictionary check value */
7782var DICT = 11; /* waiting for inflateSetDictionary() call */
7783var TYPE = 12; /* i: waiting for type bits, including last-flag bit */
7784var TYPEDO = 13; /* i: same, but skip check to exit inflate on new block */
7785var STORED = 14; /* i: waiting for stored size (length and complement) */
7786var COPY_ = 15; /* i/o: same as COPY below, but only first time in */
7787var COPY = 16; /* i/o: waiting for input or output to copy stored block */
7788var TABLE = 17; /* i: waiting for dynamic block table lengths */
7789var LENLENS = 18; /* i: waiting for code length code lengths */
7790var CODELENS = 19; /* i: waiting for length/lit and distance code lengths */
7791var LEN_ = 20; /* i: same as LEN below, but only first time in */
7792var LEN = 21; /* i: waiting for length/lit/eob code */
7793var LENEXT = 22; /* i: waiting for length extra bits */
7794var DIST = 23; /* i: waiting for distance code */
7795var DISTEXT = 24; /* i: waiting for distance extra bits */
7796var MATCH = 25; /* o: waiting for output space to copy string */
7797var LIT = 26; /* o: waiting for output space to write literal */
7798var CHECK = 27; /* i: waiting for 32-bit check value */
7799var LENGTH = 28; /* i: waiting for 32-bit length (gzip) */
7800var DONE = 29; /* finished check, done -- remain here until reset */
7801var BAD = 30; /* got a data error -- remain here until reset */
7802var MEM = 31; /* got an inflate() memory error -- remain here until reset */
7803var SYNC = 32; /* looking for synchronization bytes to restart inflate() */
7804
7805/* ===========================================================================*/
7806
7807
7808
7809var ENOUGH_LENS = 852;
7810var ENOUGH_DISTS = 592;
7811//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
7812
7813var MAX_WBITS = 15;
7814/* 32K LZ77 window */
7815var DEF_WBITS = MAX_WBITS;
7816
7817
7818function zswap32(q) {
7819 return (((q >>> 24) & 0xff) +
7820 ((q >>> 8) & 0xff00) +
7821 ((q & 0xff00) << 8) +
7822 ((q & 0xff) << 24));
7823}
7824
7825
7826function InflateState() {
7827 this.mode = 0; /* current inflate mode */
7828 this.last = false; /* true if processing last block */
7829 this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */
7830 this.havedict = false; /* true if dictionary provided */
7831 this.flags = 0; /* gzip header method and flags (0 if zlib) */
7832 this.dmax = 0; /* zlib header max distance (INFLATE_STRICT) */
7833 this.check = 0; /* protected copy of check value */
7834 this.total = 0; /* protected copy of output count */
7835 // TODO: may be {}
7836 this.head = null; /* where to save gzip header information */
7837
7838 /* sliding window */
7839 this.wbits = 0; /* log base 2 of requested window size */
7840 this.wsize = 0; /* window size or zero if not using window */
7841 this.whave = 0; /* valid bytes in the window */
7842 this.wnext = 0; /* window write index */
7843 this.window = null; /* allocated sliding window, if needed */
7844
7845 /* bit accumulator */
7846 this.hold = 0; /* input bit accumulator */
7847 this.bits = 0; /* number of bits in "in" */
7848
7849 /* for string and stored block copying */
7850 this.length = 0; /* literal or length of data to copy */
7851 this.offset = 0; /* distance back to copy string from */
7852
7853 /* for table and code decoding */
7854 this.extra = 0; /* extra bits needed */
7855
7856 /* fixed and dynamic code tables */
7857 this.lencode = null; /* starting table for length/literal codes */
7858 this.distcode = null; /* starting table for distance codes */
7859 this.lenbits = 0; /* index bits for lencode */
7860 this.distbits = 0; /* index bits for distcode */
7861
7862 /* dynamic table building */
7863 this.ncode = 0; /* number of code length code lengths */
7864 this.nlen = 0; /* number of length code lengths */
7865 this.ndist = 0; /* number of distance code lengths */
7866 this.have = 0; /* number of code lengths in lens[] */
7867 this.next = null; /* next available space in codes[] */
7868
7869 this.lens = new utils.Buf16(320); /* temporary storage for code lengths */
7870 this.work = new utils.Buf16(288); /* work area for code table building */
7871
7872 /*
7873 because we don't have pointers in js, we use lencode and distcode directly
7874 as buffers so we don't need codes
7875 */
7876 //this.codes = new utils.Buf32(ENOUGH); /* space for code tables */
7877 this.lendyn = null; /* dynamic table for length/literal codes (JS specific) */
7878 this.distdyn = null; /* dynamic table for distance codes (JS specific) */
7879 this.sane = 0; /* if false, allow invalid distance too far */
7880 this.back = 0; /* bits back of last unprocessed length/lit */
7881 this.was = 0; /* initial length of match */
7882}
7883
7884function inflateResetKeep(strm) {
7885 var state;
7886
7887 if (!strm || !strm.state) { return Z_STREAM_ERROR; }
7888 state = strm.state;
7889 strm.total_in = strm.total_out = state.total = 0;
7890 strm.msg = ''; /*Z_NULL*/
7891 if (state.wrap) { /* to support ill-conceived Java test suite */
7892 strm.adler = state.wrap & 1;
7893 }
7894 state.mode = HEAD;
7895 state.last = 0;
7896 state.havedict = 0;
7897 state.dmax = 32768;
7898 state.head = null/*Z_NULL*/;
7899 state.hold = 0;
7900 state.bits = 0;
7901 //state.lencode = state.distcode = state.next = state.codes;
7902 state.lencode = state.lendyn = new utils.Buf32(ENOUGH_LENS);
7903 state.distcode = state.distdyn = new utils.Buf32(ENOUGH_DISTS);
7904
7905 state.sane = 1;
7906 state.back = -1;
7907 //Tracev((stderr, "inflate: reset\n"));
7908 return Z_OK;
7909}
7910
7911function inflateReset(strm) {
7912 var state;
7913
7914 if (!strm || !strm.state) { return Z_STREAM_ERROR; }
7915 state = strm.state;
7916 state.wsize = 0;
7917 state.whave = 0;
7918 state.wnext = 0;
7919 return inflateResetKeep(strm);
7920
7921}
7922
7923function inflateReset2(strm, windowBits) {
7924 var wrap;
7925 var state;
7926
7927 /* get the state */
7928 if (!strm || !strm.state) { return Z_STREAM_ERROR; }
7929 state = strm.state;
7930
7931 /* extract wrap request from windowBits parameter */
7932 if (windowBits < 0) {
7933 wrap = 0;
7934 windowBits = -windowBits;
7935 }
7936 else {
7937 wrap = (windowBits >> 4) + 1;
7938 if (windowBits < 48) {
7939 windowBits &= 15;
7940 }
7941 }
7942
7943 /* set number of window bits, free window if different */
7944 if (windowBits && (windowBits < 8 || windowBits > 15)) {
7945 return Z_STREAM_ERROR;
7946 }
7947 if (state.window !== null && state.wbits !== windowBits) {
7948 state.window = null;
7949 }
7950
7951 /* update state and reset the rest of it */
7952 state.wrap = wrap;
7953 state.wbits = windowBits;
7954 return inflateReset(strm);
7955}
7956
7957function inflateInit2(strm, windowBits) {
7958 var ret;
7959 var state;
7960
7961 if (!strm) { return Z_STREAM_ERROR; }
7962 //strm.msg = Z_NULL; /* in case we return an error */
7963
7964 state = new InflateState();
7965
7966 //if (state === Z_NULL) return Z_MEM_ERROR;
7967 //Tracev((stderr, "inflate: allocated\n"));
7968 strm.state = state;
7969 state.window = null/*Z_NULL*/;
7970 ret = inflateReset2(strm, windowBits);
7971 if (ret !== Z_OK) {
7972 strm.state = null/*Z_NULL*/;
7973 }
7974 return ret;
7975}
7976
7977function inflateInit(strm) {
7978 return inflateInit2(strm, DEF_WBITS);
7979}
7980
7981
7982/*
7983 Return state with length and distance decoding tables and index sizes set to
7984 fixed code decoding. Normally this returns fixed tables from inffixed.h.
7985 If BUILDFIXED is defined, then instead this routine builds the tables the
7986 first time it's called, and returns those tables the first time and
7987 thereafter. This reduces the size of the code by about 2K bytes, in
7988 exchange for a little execution time. However, BUILDFIXED should not be
7989 used for threaded applications, since the rewriting of the tables and virgin
7990 may not be thread-safe.
7991 */
7992var virgin = true;
7993
7994var lenfix, distfix; // We have no pointers in JS, so keep tables separate
7995
7996function fixedtables(state) {
7997 /* build fixed huffman tables if first call (may not be thread safe) */
7998 if (virgin) {
7999 var sym;
8000
8001 lenfix = new utils.Buf32(512);
8002 distfix = new utils.Buf32(32);
8003
8004 /* literal/length table */
8005 sym = 0;
8006 while (sym < 144) { state.lens[sym++] = 8; }
8007 while (sym < 256) { state.lens[sym++] = 9; }
8008 while (sym < 280) { state.lens[sym++] = 7; }
8009 while (sym < 288) { state.lens[sym++] = 8; }
8010
8011 inflate_table(LENS, state.lens, 0, 288, lenfix, 0, state.work, { bits: 9 });
8012
8013 /* distance table */
8014 sym = 0;
8015 while (sym < 32) { state.lens[sym++] = 5; }
8016
8017 inflate_table(DISTS, state.lens, 0, 32, distfix, 0, state.work, { bits: 5 });
8018
8019 /* do this just once */
8020 virgin = false;
8021 }
8022
8023 state.lencode = lenfix;
8024 state.lenbits = 9;
8025 state.distcode = distfix;
8026 state.distbits = 5;
8027}
8028
8029
8030/*
8031 Update the window with the last wsize (normally 32K) bytes written before
8032 returning. If window does not exist yet, create it. This is only called
8033 when a window is already in use, or when output has been written during this
8034 inflate call, but the end of the deflate stream has not been reached yet.
8035 It is also called to create a window for dictionary data when a dictionary
8036 is loaded.
8037
8038 Providing output buffers larger than 32K to inflate() should provide a speed
8039 advantage, since only the last 32K of output is copied to the sliding window
8040 upon return from inflate(), and since all distances after the first 32K of
8041 output will fall in the output data, making match copies simpler and faster.
8042 The advantage may be dependent on the size of the processor's data caches.
8043 */
8044function updatewindow(strm, src, end, copy) {
8045 var dist;
8046 var state = strm.state;
8047
8048 /* if it hasn't been done already, allocate space for the window */
8049 if (state.window === null) {
8050 state.wsize = 1 << state.wbits;
8051 state.wnext = 0;
8052 state.whave = 0;
8053
8054 state.window = new utils.Buf8(state.wsize);
8055 }
8056
8057 /* copy state->wsize or less output bytes into the circular window */
8058 if (copy >= state.wsize) {
8059 utils.arraySet(state.window, src, end - state.wsize, state.wsize, 0);
8060 state.wnext = 0;
8061 state.whave = state.wsize;
8062 }
8063 else {
8064 dist = state.wsize - state.wnext;
8065 if (dist > copy) {
8066 dist = copy;
8067 }
8068 //zmemcpy(state->window + state->wnext, end - copy, dist);
8069 utils.arraySet(state.window, src, end - copy, dist, state.wnext);
8070 copy -= dist;
8071 if (copy) {
8072 //zmemcpy(state->window, end - copy, copy);
8073 utils.arraySet(state.window, src, end - copy, copy, 0);
8074 state.wnext = copy;
8075 state.whave = state.wsize;
8076 }
8077 else {
8078 state.wnext += dist;
8079 if (state.wnext === state.wsize) { state.wnext = 0; }
8080 if (state.whave < state.wsize) { state.whave += dist; }
8081 }
8082 }
8083 return 0;
8084}
8085
8086function inflate(strm, flush) {
8087 var state;
8088 var input, output; // input/output buffers
8089 var next; /* next input INDEX */
8090 var put; /* next output INDEX */
8091 var have, left; /* available input and output */
8092 var hold; /* bit buffer */
8093 var bits; /* bits in bit buffer */
8094 var _in, _out; /* save starting available input and output */
8095 var copy; /* number of stored or match bytes to copy */
8096 var from; /* where to copy match bytes from */
8097 var from_source;
8098 var here = 0; /* current decoding table entry */
8099 var here_bits, here_op, here_val; // paked "here" denormalized (JS specific)
8100 //var last; /* parent table entry */
8101 var last_bits, last_op, last_val; // paked "last" denormalized (JS specific)
8102 var len; /* length to copy for repeats, bits to drop */
8103 var ret; /* return code */
8104 var hbuf = new utils.Buf8(4); /* buffer for gzip header crc calculation */
8105 var opts;
8106
8107 var n; // temporary var for NEED_BITS
8108
8109 var order = /* permutation of code lengths */
8110 [ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 ];
8111
8112
8113 if (!strm || !strm.state || !strm.output ||
8114 (!strm.input && strm.avail_in !== 0)) {
8115 return Z_STREAM_ERROR;
8116 }
8117
8118 state = strm.state;
8119 if (state.mode === TYPE) { state.mode = TYPEDO; } /* skip check */
8120
8121
8122 //--- LOAD() ---
8123 put = strm.next_out;
8124 output = strm.output;
8125 left = strm.avail_out;
8126 next = strm.next_in;
8127 input = strm.input;
8128 have = strm.avail_in;
8129 hold = state.hold;
8130 bits = state.bits;
8131 //---
8132
8133 _in = have;
8134 _out = left;
8135 ret = Z_OK;
8136
8137 inf_leave: // goto emulation
8138 for (;;) {
8139 switch (state.mode) {
8140 case HEAD:
8141 if (state.wrap === 0) {
8142 state.mode = TYPEDO;
8143 break;
8144 }
8145 //=== NEEDBITS(16);
8146 while (bits < 16) {
8147 if (have === 0) { break inf_leave; }
8148 have--;
8149 hold += input[next++] << bits;
8150 bits += 8;
8151 }
8152 //===//
8153 if ((state.wrap & 2) && hold === 0x8b1f) { /* gzip header */
8154 state.check = 0/*crc32(0L, Z_NULL, 0)*/;
8155 //=== CRC2(state.check, hold);
8156 hbuf[0] = hold & 0xff;
8157 hbuf[1] = (hold >>> 8) & 0xff;
8158 state.check = crc32(state.check, hbuf, 2, 0);
8159 //===//
8160
8161 //=== INITBITS();
8162 hold = 0;
8163 bits = 0;
8164 //===//
8165 state.mode = FLAGS;
8166 break;
8167 }
8168 state.flags = 0; /* expect zlib header */
8169 if (state.head) {
8170 state.head.done = false;
8171 }
8172 if (!(state.wrap & 1) || /* check if zlib header allowed */
8173 (((hold & 0xff)/*BITS(8)*/ << 8) + (hold >> 8)) % 31) {
8174 strm.msg = 'incorrect header check';
8175 state.mode = BAD;
8176 break;
8177 }
8178 if ((hold & 0x0f)/*BITS(4)*/ !== Z_DEFLATED) {
8179 strm.msg = 'unknown compression method';
8180 state.mode = BAD;
8181 break;
8182 }
8183 //--- DROPBITS(4) ---//
8184 hold >>>= 4;
8185 bits -= 4;
8186 //---//
8187 len = (hold & 0x0f)/*BITS(4)*/ + 8;
8188 if (state.wbits === 0) {
8189 state.wbits = len;
8190 }
8191 else if (len > state.wbits) {
8192 strm.msg = 'invalid window size';
8193 state.mode = BAD;
8194 break;
8195 }
8196 state.dmax = 1 << len;
8197 //Tracev((stderr, "inflate: zlib header ok\n"));
8198 strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;
8199 state.mode = hold & 0x200 ? DICTID : TYPE;
8200 //=== INITBITS();
8201 hold = 0;
8202 bits = 0;
8203 //===//
8204 break;
8205 case FLAGS:
8206 //=== NEEDBITS(16); */
8207 while (bits < 16) {
8208 if (have === 0) { break inf_leave; }
8209 have--;
8210 hold += input[next++] << bits;
8211 bits += 8;
8212 }
8213 //===//
8214 state.flags = hold;
8215 if ((state.flags & 0xff) !== Z_DEFLATED) {
8216 strm.msg = 'unknown compression method';
8217 state.mode = BAD;
8218 break;
8219 }
8220 if (state.flags & 0xe000) {
8221 strm.msg = 'unknown header flags set';
8222 state.mode = BAD;
8223 break;
8224 }
8225 if (state.head) {
8226 state.head.text = ((hold >> 8) & 1);
8227 }
8228 if (state.flags & 0x0200) {
8229 //=== CRC2(state.check, hold);
8230 hbuf[0] = hold & 0xff;
8231 hbuf[1] = (hold >>> 8) & 0xff;
8232 state.check = crc32(state.check, hbuf, 2, 0);
8233 //===//
8234 }
8235 //=== INITBITS();
8236 hold = 0;
8237 bits = 0;
8238 //===//
8239 state.mode = TIME;
8240 /* falls through */
8241 case TIME:
8242 //=== NEEDBITS(32); */
8243 while (bits < 32) {
8244 if (have === 0) { break inf_leave; }
8245 have--;
8246 hold += input[next++] << bits;
8247 bits += 8;
8248 }
8249 //===//
8250 if (state.head) {
8251 state.head.time = hold;
8252 }
8253 if (state.flags & 0x0200) {
8254 //=== CRC4(state.check, hold)
8255 hbuf[0] = hold & 0xff;
8256 hbuf[1] = (hold >>> 8) & 0xff;
8257 hbuf[2] = (hold >>> 16) & 0xff;
8258 hbuf[3] = (hold >>> 24) & 0xff;
8259 state.check = crc32(state.check, hbuf, 4, 0);
8260 //===
8261 }
8262 //=== INITBITS();
8263 hold = 0;
8264 bits = 0;
8265 //===//
8266 state.mode = OS;
8267 /* falls through */
8268 case OS:
8269 //=== NEEDBITS(16); */
8270 while (bits < 16) {
8271 if (have === 0) { break inf_leave; }
8272 have--;
8273 hold += input[next++] << bits;
8274 bits += 8;
8275 }
8276 //===//
8277 if (state.head) {
8278 state.head.xflags = (hold & 0xff);
8279 state.head.os = (hold >> 8);
8280 }
8281 if (state.flags & 0x0200) {
8282 //=== CRC2(state.check, hold);
8283 hbuf[0] = hold & 0xff;
8284 hbuf[1] = (hold >>> 8) & 0xff;
8285 state.check = crc32(state.check, hbuf, 2, 0);
8286 //===//
8287 }
8288 //=== INITBITS();
8289 hold = 0;
8290 bits = 0;
8291 //===//
8292 state.mode = EXLEN;
8293 /* falls through */
8294 case EXLEN:
8295 if (state.flags & 0x0400) {
8296 //=== NEEDBITS(16); */
8297 while (bits < 16) {
8298 if (have === 0) { break inf_leave; }
8299 have--;
8300 hold += input[next++] << bits;
8301 bits += 8;
8302 }
8303 //===//
8304 state.length = hold;
8305 if (state.head) {
8306 state.head.extra_len = hold;
8307 }
8308 if (state.flags & 0x0200) {
8309 //=== CRC2(state.check, hold);
8310 hbuf[0] = hold & 0xff;
8311 hbuf[1] = (hold >>> 8) & 0xff;
8312 state.check = crc32(state.check, hbuf, 2, 0);
8313 //===//
8314 }
8315 //=== INITBITS();
8316 hold = 0;
8317 bits = 0;
8318 //===//
8319 }
8320 else if (state.head) {
8321 state.head.extra = null/*Z_NULL*/;
8322 }
8323 state.mode = EXTRA;
8324 /* falls through */
8325 case EXTRA:
8326 if (state.flags & 0x0400) {
8327 copy = state.length;
8328 if (copy > have) { copy = have; }
8329 if (copy) {
8330 if (state.head) {
8331 len = state.head.extra_len - state.length;
8332 if (!state.head.extra) {
8333 // Use untyped array for more conveniend processing later
8334 state.head.extra = new Array(state.head.extra_len);
8335 }
8336 utils.arraySet(
8337 state.head.extra,
8338 input,
8339 next,
8340 // extra field is limited to 65536 bytes
8341 // - no need for additional size check
8342 copy,
8343 /*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/
8344 len
8345 );
8346 //zmemcpy(state.head.extra + len, next,
8347 // len + copy > state.head.extra_max ?
8348 // state.head.extra_max - len : copy);
8349 }
8350 if (state.flags & 0x0200) {
8351 state.check = crc32(state.check, input, copy, next);
8352 }
8353 have -= copy;
8354 next += copy;
8355 state.length -= copy;
8356 }
8357 if (state.length) { break inf_leave; }
8358 }
8359 state.length = 0;
8360 state.mode = NAME;
8361 /* falls through */
8362 case NAME:
8363 if (state.flags & 0x0800) {
8364 if (have === 0) { break inf_leave; }
8365 copy = 0;
8366 do {
8367 // TODO: 2 or 1 bytes?
8368 len = input[next + copy++];
8369 /* use constant limit because in js we should not preallocate memory */
8370 if (state.head && len &&
8371 (state.length < 65536 /*state.head.name_max*/)) {
8372 state.head.name += String.fromCharCode(len);
8373 }
8374 } while (len && copy < have);
8375
8376 if (state.flags & 0x0200) {
8377 state.check = crc32(state.check, input, copy, next);
8378 }
8379 have -= copy;
8380 next += copy;
8381 if (len) { break inf_leave; }
8382 }
8383 else if (state.head) {
8384 state.head.name = null;
8385 }
8386 state.length = 0;
8387 state.mode = COMMENT;
8388 /* falls through */
8389 case COMMENT:
8390 if (state.flags & 0x1000) {
8391 if (have === 0) { break inf_leave; }
8392 copy = 0;
8393 do {
8394 len = input[next + copy++];
8395 /* use constant limit because in js we should not preallocate memory */
8396 if (state.head && len &&
8397 (state.length < 65536 /*state.head.comm_max*/)) {
8398 state.head.comment += String.fromCharCode(len);
8399 }
8400 } while (len && copy < have);
8401 if (state.flags & 0x0200) {
8402 state.check = crc32(state.check, input, copy, next);
8403 }
8404 have -= copy;
8405 next += copy;
8406 if (len) { break inf_leave; }
8407 }
8408 else if (state.head) {
8409 state.head.comment = null;
8410 }
8411 state.mode = HCRC;
8412 /* falls through */
8413 case HCRC:
8414 if (state.flags & 0x0200) {
8415 //=== NEEDBITS(16); */
8416 while (bits < 16) {
8417 if (have === 0) { break inf_leave; }
8418 have--;
8419 hold += input[next++] << bits;
8420 bits += 8;
8421 }
8422 //===//
8423 if (hold !== (state.check & 0xffff)) {
8424 strm.msg = 'header crc mismatch';
8425 state.mode = BAD;
8426 break;
8427 }
8428 //=== INITBITS();
8429 hold = 0;
8430 bits = 0;
8431 //===//
8432 }
8433 if (state.head) {
8434 state.head.hcrc = ((state.flags >> 9) & 1);
8435 state.head.done = true;
8436 }
8437 strm.adler = state.check = 0;
8438 state.mode = TYPE;
8439 break;
8440 case DICTID:
8441 //=== NEEDBITS(32); */
8442 while (bits < 32) {
8443 if (have === 0) { break inf_leave; }
8444 have--;
8445 hold += input[next++] << bits;
8446 bits += 8;
8447 }
8448 //===//
8449 strm.adler = state.check = zswap32(hold);
8450 //=== INITBITS();
8451 hold = 0;
8452 bits = 0;
8453 //===//
8454 state.mode = DICT;
8455 /* falls through */
8456 case DICT:
8457 if (state.havedict === 0) {
8458 //--- RESTORE() ---
8459 strm.next_out = put;
8460 strm.avail_out = left;
8461 strm.next_in = next;
8462 strm.avail_in = have;
8463 state.hold = hold;
8464 state.bits = bits;
8465 //---
8466 return Z_NEED_DICT;
8467 }
8468 strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;
8469 state.mode = TYPE;
8470 /* falls through */
8471 case TYPE:
8472 if (flush === Z_BLOCK || flush === Z_TREES) { break inf_leave; }
8473 /* falls through */
8474 case TYPEDO:
8475 if (state.last) {
8476 //--- BYTEBITS() ---//
8477 hold >>>= bits & 7;
8478 bits -= bits & 7;
8479 //---//
8480 state.mode = CHECK;
8481 break;
8482 }
8483 //=== NEEDBITS(3); */
8484 while (bits < 3) {
8485 if (have === 0) { break inf_leave; }
8486 have--;
8487 hold += input[next++] << bits;
8488 bits += 8;
8489 }
8490 //===//
8491 state.last = (hold & 0x01)/*BITS(1)*/;
8492 //--- DROPBITS(1) ---//
8493 hold >>>= 1;
8494 bits -= 1;
8495 //---//
8496
8497 switch ((hold & 0x03)/*BITS(2)*/) {
8498 case 0: /* stored block */
8499 //Tracev((stderr, "inflate: stored block%s\n",
8500 // state.last ? " (last)" : ""));
8501 state.mode = STORED;
8502 break;
8503 case 1: /* fixed block */
8504 fixedtables(state);
8505 //Tracev((stderr, "inflate: fixed codes block%s\n",
8506 // state.last ? " (last)" : ""));
8507 state.mode = LEN_; /* decode codes */
8508 if (flush === Z_TREES) {
8509 //--- DROPBITS(2) ---//
8510 hold >>>= 2;
8511 bits -= 2;
8512 //---//
8513 break inf_leave;
8514 }
8515 break;
8516 case 2: /* dynamic block */
8517 //Tracev((stderr, "inflate: dynamic codes block%s\n",
8518 // state.last ? " (last)" : ""));
8519 state.mode = TABLE;
8520 break;
8521 case 3:
8522 strm.msg = 'invalid block type';
8523 state.mode = BAD;
8524 }
8525 //--- DROPBITS(2) ---//
8526 hold >>>= 2;
8527 bits -= 2;
8528 //---//
8529 break;
8530 case STORED:
8531 //--- BYTEBITS() ---// /* go to byte boundary */
8532 hold >>>= bits & 7;
8533 bits -= bits & 7;
8534 //---//
8535 //=== NEEDBITS(32); */
8536 while (bits < 32) {
8537 if (have === 0) { break inf_leave; }
8538 have--;
8539 hold += input[next++] << bits;
8540 bits += 8;
8541 }
8542 //===//
8543 if ((hold & 0xffff) !== ((hold >>> 16) ^ 0xffff)) {
8544 strm.msg = 'invalid stored block lengths';
8545 state.mode = BAD;
8546 break;
8547 }
8548 state.length = hold & 0xffff;
8549 //Tracev((stderr, "inflate: stored length %u\n",
8550 // state.length));
8551 //=== INITBITS();
8552 hold = 0;
8553 bits = 0;
8554 //===//
8555 state.mode = COPY_;
8556 if (flush === Z_TREES) { break inf_leave; }
8557 /* falls through */
8558 case COPY_:
8559 state.mode = COPY;
8560 /* falls through */
8561 case COPY:
8562 copy = state.length;
8563 if (copy) {
8564 if (copy > have) { copy = have; }
8565 if (copy > left) { copy = left; }
8566 if (copy === 0) { break inf_leave; }
8567 //--- zmemcpy(put, next, copy); ---
8568 utils.arraySet(output, input, next, copy, put);
8569 //---//
8570 have -= copy;
8571 next += copy;
8572 left -= copy;
8573 put += copy;
8574 state.length -= copy;
8575 break;
8576 }
8577 //Tracev((stderr, "inflate: stored end\n"));
8578 state.mode = TYPE;
8579 break;
8580 case TABLE:
8581 //=== NEEDBITS(14); */
8582 while (bits < 14) {
8583 if (have === 0) { break inf_leave; }
8584 have--;
8585 hold += input[next++] << bits;
8586 bits += 8;
8587 }
8588 //===//
8589 state.nlen = (hold & 0x1f)/*BITS(5)*/ + 257;
8590 //--- DROPBITS(5) ---//
8591 hold >>>= 5;
8592 bits -= 5;
8593 //---//
8594 state.ndist = (hold & 0x1f)/*BITS(5)*/ + 1;
8595 //--- DROPBITS(5) ---//
8596 hold >>>= 5;
8597 bits -= 5;
8598 //---//
8599 state.ncode = (hold & 0x0f)/*BITS(4)*/ + 4;
8600 //--- DROPBITS(4) ---//
8601 hold >>>= 4;
8602 bits -= 4;
8603 //---//
8604//#ifndef PKZIP_BUG_WORKAROUND
8605 if (state.nlen > 286 || state.ndist > 30) {
8606 strm.msg = 'too many length or distance symbols';
8607 state.mode = BAD;
8608 break;
8609 }
8610//#endif
8611 //Tracev((stderr, "inflate: table sizes ok\n"));
8612 state.have = 0;
8613 state.mode = LENLENS;
8614 /* falls through */
8615 case LENLENS:
8616 while (state.have < state.ncode) {
8617 //=== NEEDBITS(3);
8618 while (bits < 3) {
8619 if (have === 0) { break inf_leave; }
8620 have--;
8621 hold += input[next++] << bits;
8622 bits += 8;
8623 }
8624 //===//
8625 state.lens[order[state.have++]] = (hold & 0x07);//BITS(3);
8626 //--- DROPBITS(3) ---//
8627 hold >>>= 3;
8628 bits -= 3;
8629 //---//
8630 }
8631 while (state.have < 19) {
8632 state.lens[order[state.have++]] = 0;
8633 }
8634 // We have separate tables & no pointers. 2 commented lines below not needed.
8635 //state.next = state.codes;
8636 //state.lencode = state.next;
8637 // Switch to use dynamic table
8638 state.lencode = state.lendyn;
8639 state.lenbits = 7;
8640
8641 opts = { bits: state.lenbits };
8642 ret = inflate_table(CODES, state.lens, 0, 19, state.lencode, 0, state.work, opts);
8643 state.lenbits = opts.bits;
8644
8645 if (ret) {
8646 strm.msg = 'invalid code lengths set';
8647 state.mode = BAD;
8648 break;
8649 }
8650 //Tracev((stderr, "inflate: code lengths ok\n"));
8651 state.have = 0;
8652 state.mode = CODELENS;
8653 /* falls through */
8654 case CODELENS:
8655 while (state.have < state.nlen + state.ndist) {
8656 for (;;) {
8657 here = state.lencode[hold & ((1 << state.lenbits) - 1)];/*BITS(state.lenbits)*/
8658 here_bits = here >>> 24;
8659 here_op = (here >>> 16) & 0xff;
8660 here_val = here & 0xffff;
8661
8662 if ((here_bits) <= bits) { break; }
8663 //--- PULLBYTE() ---//
8664 if (have === 0) { break inf_leave; }
8665 have--;
8666 hold += input[next++] << bits;
8667 bits += 8;
8668 //---//
8669 }
8670 if (here_val < 16) {
8671 //--- DROPBITS(here.bits) ---//
8672 hold >>>= here_bits;
8673 bits -= here_bits;
8674 //---//
8675 state.lens[state.have++] = here_val;
8676 }
8677 else {
8678 if (here_val === 16) {
8679 //=== NEEDBITS(here.bits + 2);
8680 n = here_bits + 2;
8681 while (bits < n) {
8682 if (have === 0) { break inf_leave; }
8683 have--;
8684 hold += input[next++] << bits;
8685 bits += 8;
8686 }
8687 //===//
8688 //--- DROPBITS(here.bits) ---//
8689 hold >>>= here_bits;
8690 bits -= here_bits;
8691 //---//
8692 if (state.have === 0) {
8693 strm.msg = 'invalid bit length repeat';
8694 state.mode = BAD;
8695 break;
8696 }
8697 len = state.lens[state.have - 1];
8698 copy = 3 + (hold & 0x03);//BITS(2);
8699 //--- DROPBITS(2) ---//
8700 hold >>>= 2;
8701 bits -= 2;
8702 //---//
8703 }
8704 else if (here_val === 17) {
8705 //=== NEEDBITS(here.bits + 3);
8706 n = here_bits + 3;
8707 while (bits < n) {
8708 if (have === 0) { break inf_leave; }
8709 have--;
8710 hold += input[next++] << bits;
8711 bits += 8;
8712 }
8713 //===//
8714 //--- DROPBITS(here.bits) ---//
8715 hold >>>= here_bits;
8716 bits -= here_bits;
8717 //---//
8718 len = 0;
8719 copy = 3 + (hold & 0x07);//BITS(3);
8720 //--- DROPBITS(3) ---//
8721 hold >>>= 3;
8722 bits -= 3;
8723 //---//
8724 }
8725 else {
8726 //=== NEEDBITS(here.bits + 7);
8727 n = here_bits + 7;
8728 while (bits < n) {
8729 if (have === 0) { break inf_leave; }
8730 have--;
8731 hold += input[next++] << bits;
8732 bits += 8;
8733 }
8734 //===//
8735 //--- DROPBITS(here.bits) ---//
8736 hold >>>= here_bits;
8737 bits -= here_bits;
8738 //---//
8739 len = 0;
8740 copy = 11 + (hold & 0x7f);//BITS(7);
8741 //--- DROPBITS(7) ---//
8742 hold >>>= 7;
8743 bits -= 7;
8744 //---//
8745 }
8746 if (state.have + copy > state.nlen + state.ndist) {
8747 strm.msg = 'invalid bit length repeat';
8748 state.mode = BAD;
8749 break;
8750 }
8751 while (copy--) {
8752 state.lens[state.have++] = len;
8753 }
8754 }
8755 }
8756
8757 /* handle error breaks in while */
8758 if (state.mode === BAD) { break; }
8759
8760 /* check for end-of-block code (better have one) */
8761 if (state.lens[256] === 0) {
8762 strm.msg = 'invalid code -- missing end-of-block';
8763 state.mode = BAD;
8764 break;
8765 }
8766
8767 /* build code tables -- note: do not change the lenbits or distbits
8768 values here (9 and 6) without reading the comments in inftrees.h
8769 concerning the ENOUGH constants, which depend on those values */
8770 state.lenbits = 9;
8771
8772 opts = { bits: state.lenbits };
8773 ret = inflate_table(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts);
8774 // We have separate tables & no pointers. 2 commented lines below not needed.
8775 // state.next_index = opts.table_index;
8776 state.lenbits = opts.bits;
8777 // state.lencode = state.next;
8778
8779 if (ret) {
8780 strm.msg = 'invalid literal/lengths set';
8781 state.mode = BAD;
8782 break;
8783 }
8784
8785 state.distbits = 6;
8786 //state.distcode.copy(state.codes);
8787 // Switch to use dynamic table
8788 state.distcode = state.distdyn;
8789 opts = { bits: state.distbits };
8790 ret = inflate_table(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts);
8791 // We have separate tables & no pointers. 2 commented lines below not needed.
8792 // state.next_index = opts.table_index;
8793 state.distbits = opts.bits;
8794 // state.distcode = state.next;
8795
8796 if (ret) {
8797 strm.msg = 'invalid distances set';
8798 state.mode = BAD;
8799 break;
8800 }
8801 //Tracev((stderr, 'inflate: codes ok\n'));
8802 state.mode = LEN_;
8803 if (flush === Z_TREES) { break inf_leave; }
8804 /* falls through */
8805 case LEN_:
8806 state.mode = LEN;
8807 /* falls through */
8808 case LEN:
8809 if (have >= 6 && left >= 258) {
8810 //--- RESTORE() ---
8811 strm.next_out = put;
8812 strm.avail_out = left;
8813 strm.next_in = next;
8814 strm.avail_in = have;
8815 state.hold = hold;
8816 state.bits = bits;
8817 //---
8818 inflate_fast(strm, _out);
8819 //--- LOAD() ---
8820 put = strm.next_out;
8821 output = strm.output;
8822 left = strm.avail_out;
8823 next = strm.next_in;
8824 input = strm.input;
8825 have = strm.avail_in;
8826 hold = state.hold;
8827 bits = state.bits;
8828 //---
8829
8830 if (state.mode === TYPE) {
8831 state.back = -1;
8832 }
8833 break;
8834 }
8835 state.back = 0;
8836 for (;;) {
8837 here = state.lencode[hold & ((1 << state.lenbits) - 1)]; /*BITS(state.lenbits)*/
8838 here_bits = here >>> 24;
8839 here_op = (here >>> 16) & 0xff;
8840 here_val = here & 0xffff;
8841
8842 if (here_bits <= bits) { break; }
8843 //--- PULLBYTE() ---//
8844 if (have === 0) { break inf_leave; }
8845 have--;
8846 hold += input[next++] << bits;
8847 bits += 8;
8848 //---//
8849 }
8850 if (here_op && (here_op & 0xf0) === 0) {
8851 last_bits = here_bits;
8852 last_op = here_op;
8853 last_val = here_val;
8854 for (;;) {
8855 here = state.lencode[last_val +
8856 ((hold & ((1 << (last_bits + last_op)) - 1))/*BITS(last.bits + last.op)*/ >> last_bits)];
8857 here_bits = here >>> 24;
8858 here_op = (here >>> 16) & 0xff;
8859 here_val = here & 0xffff;
8860
8861 if ((last_bits + here_bits) <= bits) { break; }
8862 //--- PULLBYTE() ---//
8863 if (have === 0) { break inf_leave; }
8864 have--;
8865 hold += input[next++] << bits;
8866 bits += 8;
8867 //---//
8868 }
8869 //--- DROPBITS(last.bits) ---//
8870 hold >>>= last_bits;
8871 bits -= last_bits;
8872 //---//
8873 state.back += last_bits;
8874 }
8875 //--- DROPBITS(here.bits) ---//
8876 hold >>>= here_bits;
8877 bits -= here_bits;
8878 //---//
8879 state.back += here_bits;
8880 state.length = here_val;
8881 if (here_op === 0) {
8882 //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
8883 // "inflate: literal '%c'\n" :
8884 // "inflate: literal 0x%02x\n", here.val));
8885 state.mode = LIT;
8886 break;
8887 }
8888 if (here_op & 32) {
8889 //Tracevv((stderr, "inflate: end of block\n"));
8890 state.back = -1;
8891 state.mode = TYPE;
8892 break;
8893 }
8894 if (here_op & 64) {
8895 strm.msg = 'invalid literal/length code';
8896 state.mode = BAD;
8897 break;
8898 }
8899 state.extra = here_op & 15;
8900 state.mode = LENEXT;
8901 /* falls through */
8902 case LENEXT:
8903 if (state.extra) {
8904 //=== NEEDBITS(state.extra);
8905 n = state.extra;
8906 while (bits < n) {
8907 if (have === 0) { break inf_leave; }
8908 have--;
8909 hold += input[next++] << bits;
8910 bits += 8;
8911 }
8912 //===//
8913 state.length += hold & ((1 << state.extra) - 1)/*BITS(state.extra)*/;
8914 //--- DROPBITS(state.extra) ---//
8915 hold >>>= state.extra;
8916 bits -= state.extra;
8917 //---//
8918 state.back += state.extra;
8919 }
8920 //Tracevv((stderr, "inflate: length %u\n", state.length));
8921 state.was = state.length;
8922 state.mode = DIST;
8923 /* falls through */
8924 case DIST:
8925 for (;;) {
8926 here = state.distcode[hold & ((1 << state.distbits) - 1)];/*BITS(state.distbits)*/
8927 here_bits = here >>> 24;
8928 here_op = (here >>> 16) & 0xff;
8929 here_val = here & 0xffff;
8930
8931 if ((here_bits) <= bits) { break; }
8932 //--- PULLBYTE() ---//
8933 if (have === 0) { break inf_leave; }
8934 have--;
8935 hold += input[next++] << bits;
8936 bits += 8;
8937 //---//
8938 }
8939 if ((here_op & 0xf0) === 0) {
8940 last_bits = here_bits;
8941 last_op = here_op;
8942 last_val = here_val;
8943 for (;;) {
8944 here = state.distcode[last_val +
8945 ((hold & ((1 << (last_bits + last_op)) - 1))/*BITS(last.bits + last.op)*/ >> last_bits)];
8946 here_bits = here >>> 24;
8947 here_op = (here >>> 16) & 0xff;
8948 here_val = here & 0xffff;
8949
8950 if ((last_bits + here_bits) <= bits) { break; }
8951 //--- PULLBYTE() ---//
8952 if (have === 0) { break inf_leave; }
8953 have--;
8954 hold += input[next++] << bits;
8955 bits += 8;
8956 //---//
8957 }
8958 //--- DROPBITS(last.bits) ---//
8959 hold >>>= last_bits;
8960 bits -= last_bits;
8961 //---//
8962 state.back += last_bits;
8963 }
8964 //--- DROPBITS(here.bits) ---//
8965 hold >>>= here_bits;
8966 bits -= here_bits;
8967 //---//
8968 state.back += here_bits;
8969 if (here_op & 64) {
8970 strm.msg = 'invalid distance code';
8971 state.mode = BAD;
8972 break;
8973 }
8974 state.offset = here_val;
8975 state.extra = (here_op) & 15;
8976 state.mode = DISTEXT;
8977 /* falls through */
8978 case DISTEXT:
8979 if (state.extra) {
8980 //=== NEEDBITS(state.extra);
8981 n = state.extra;
8982 while (bits < n) {
8983 if (have === 0) { break inf_leave; }
8984 have--;
8985 hold += input[next++] << bits;
8986 bits += 8;
8987 }
8988 //===//
8989 state.offset += hold & ((1 << state.extra) - 1)/*BITS(state.extra)*/;
8990 //--- DROPBITS(state.extra) ---//
8991 hold >>>= state.extra;
8992 bits -= state.extra;
8993 //---//
8994 state.back += state.extra;
8995 }
8996//#ifdef INFLATE_STRICT
8997 if (state.offset > state.dmax) {
8998 strm.msg = 'invalid distance too far back';
8999 state.mode = BAD;
9000 break;
9001 }
9002//#endif
9003 //Tracevv((stderr, "inflate: distance %u\n", state.offset));
9004 state.mode = MATCH;
9005 /* falls through */
9006 case MATCH:
9007 if (left === 0) { break inf_leave; }
9008 copy = _out - left;
9009 if (state.offset > copy) { /* copy from window */
9010 copy = state.offset - copy;
9011 if (copy > state.whave) {
9012 if (state.sane) {
9013 strm.msg = 'invalid distance too far back';
9014 state.mode = BAD;
9015 break;
9016 }
9017// (!) This block is disabled in zlib defailts,
9018// don't enable it for binary compatibility
9019//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
9020// Trace((stderr, "inflate.c too far\n"));
9021// copy -= state.whave;
9022// if (copy > state.length) { copy = state.length; }
9023// if (copy > left) { copy = left; }
9024// left -= copy;
9025// state.length -= copy;
9026// do {
9027// output[put++] = 0;
9028// } while (--copy);
9029// if (state.length === 0) { state.mode = LEN; }
9030// break;
9031//#endif
9032 }
9033 if (copy > state.wnext) {
9034 copy -= state.wnext;
9035 from = state.wsize - copy;
9036 }
9037 else {
9038 from = state.wnext - copy;
9039 }
9040 if (copy > state.length) { copy = state.length; }
9041 from_source = state.window;
9042 }
9043 else { /* copy from output */
9044 from_source = output;
9045 from = put - state.offset;
9046 copy = state.length;
9047 }
9048 if (copy > left) { copy = left; }
9049 left -= copy;
9050 state.length -= copy;
9051 do {
9052 output[put++] = from_source[from++];
9053 } while (--copy);
9054 if (state.length === 0) { state.mode = LEN; }
9055 break;
9056 case LIT:
9057 if (left === 0) { break inf_leave; }
9058 output[put++] = state.length;
9059 left--;
9060 state.mode = LEN;
9061 break;
9062 case CHECK:
9063 if (state.wrap) {
9064 //=== NEEDBITS(32);
9065 while (bits < 32) {
9066 if (have === 0) { break inf_leave; }
9067 have--;
9068 // Use '|' insdead of '+' to make sure that result is signed
9069 hold |= input[next++] << bits;
9070 bits += 8;
9071 }
9072 //===//
9073 _out -= left;
9074 strm.total_out += _out;
9075 state.total += _out;
9076 if (_out) {
9077 strm.adler = state.check =
9078 /*UPDATE(state.check, put - _out, _out);*/
9079 (state.flags ? crc32(state.check, output, _out, put - _out) : adler32(state.check, output, _out, put - _out));
9080
9081 }
9082 _out = left;
9083 // NB: crc32 stored as signed 32-bit int, zswap32 returns signed too
9084 if ((state.flags ? hold : zswap32(hold)) !== state.check) {
9085 strm.msg = 'incorrect data check';
9086 state.mode = BAD;
9087 break;
9088 }
9089 //=== INITBITS();
9090 hold = 0;
9091 bits = 0;
9092 //===//
9093 //Tracev((stderr, "inflate: check matches trailer\n"));
9094 }
9095 state.mode = LENGTH;
9096 /* falls through */
9097 case LENGTH:
9098 if (state.wrap && state.flags) {
9099 //=== NEEDBITS(32);
9100 while (bits < 32) {
9101 if (have === 0) { break inf_leave; }
9102 have--;
9103 hold += input[next++] << bits;
9104 bits += 8;
9105 }
9106 //===//
9107 if (hold !== (state.total & 0xffffffff)) {
9108 strm.msg = 'incorrect length check';
9109 state.mode = BAD;
9110 break;
9111 }
9112 //=== INITBITS();
9113 hold = 0;
9114 bits = 0;
9115 //===//
9116 //Tracev((stderr, "inflate: length matches trailer\n"));
9117 }
9118 state.mode = DONE;
9119 /* falls through */
9120 case DONE:
9121 ret = Z_STREAM_END;
9122 break inf_leave;
9123 case BAD:
9124 ret = Z_DATA_ERROR;
9125 break inf_leave;
9126 case MEM:
9127 return Z_MEM_ERROR;
9128 case SYNC:
9129 /* falls through */
9130 default:
9131 return Z_STREAM_ERROR;
9132 }
9133 }
9134
9135 // inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave"
9136
9137 /*
9138 Return from inflate(), updating the total counts and the check value.
9139 If there was no progress during the inflate() call, return a buffer
9140 error. Call updatewindow() to create and/or update the window state.
9141 Note: a memory error from inflate() is non-recoverable.
9142 */
9143
9144 //--- RESTORE() ---
9145 strm.next_out = put;
9146 strm.avail_out = left;
9147 strm.next_in = next;
9148 strm.avail_in = have;
9149 state.hold = hold;
9150 state.bits = bits;
9151 //---
9152
9153 if (state.wsize || (_out !== strm.avail_out && state.mode < BAD &&
9154 (state.mode < CHECK || flush !== Z_FINISH))) {
9155 if (updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out)) {
9156 state.mode = MEM;
9157 return Z_MEM_ERROR;
9158 }
9159 }
9160 _in -= strm.avail_in;
9161 _out -= strm.avail_out;
9162 strm.total_in += _in;
9163 strm.total_out += _out;
9164 state.total += _out;
9165 if (state.wrap && _out) {
9166 strm.adler = state.check = /*UPDATE(state.check, strm.next_out - _out, _out);*/
9167 (state.flags ? crc32(state.check, output, _out, strm.next_out - _out) : adler32(state.check, output, _out, strm.next_out - _out));
9168 }
9169 strm.data_type = state.bits + (state.last ? 64 : 0) +
9170 (state.mode === TYPE ? 128 : 0) +
9171 (state.mode === LEN_ || state.mode === COPY_ ? 256 : 0);
9172 if (((_in === 0 && _out === 0) || flush === Z_FINISH) && ret === Z_OK) {
9173 ret = Z_BUF_ERROR;
9174 }
9175 return ret;
9176}
9177
9178function inflateEnd(strm) {
9179
9180 if (!strm || !strm.state /*|| strm->zfree == (free_func)0*/) {
9181 return Z_STREAM_ERROR;
9182 }
9183
9184 var state = strm.state;
9185 if (state.window) {
9186 state.window = null;
9187 }
9188 strm.state = null;
9189 return Z_OK;
9190}
9191
9192function inflateGetHeader(strm, head) {
9193 var state;
9194
9195 /* check state */
9196 if (!strm || !strm.state) { return Z_STREAM_ERROR; }
9197 state = strm.state;
9198 if ((state.wrap & 2) === 0) { return Z_STREAM_ERROR; }
9199
9200 /* save header structure */
9201 state.head = head;
9202 head.done = false;
9203 return Z_OK;
9204}
9205
9206function inflateSetDictionary(strm, dictionary) {
9207 var dictLength = dictionary.length;
9208
9209 var state;
9210 var dictid;
9211 var ret;
9212
9213 /* check state */
9214 if (!strm /* == Z_NULL */ || !strm.state /* == Z_NULL */) { return Z_STREAM_ERROR; }
9215 state = strm.state;
9216
9217 if (state.wrap !== 0 && state.mode !== DICT) {
9218 return Z_STREAM_ERROR;
9219 }
9220
9221 /* check for correct dictionary identifier */
9222 if (state.mode === DICT) {
9223 dictid = 1; /* adler32(0, null, 0)*/
9224 /* dictid = adler32(dictid, dictionary, dictLength); */
9225 dictid = adler32(dictid, dictionary, dictLength, 0);
9226 if (dictid !== state.check) {
9227 return Z_DATA_ERROR;
9228 }
9229 }
9230 /* copy dictionary to window using updatewindow(), which will amend the
9231 existing dictionary if appropriate */
9232 ret = updatewindow(strm, dictionary, dictLength, dictLength);
9233 if (ret) {
9234 state.mode = MEM;
9235 return Z_MEM_ERROR;
9236 }
9237 state.havedict = 1;
9238 // Tracev((stderr, "inflate: dictionary set\n"));
9239 return Z_OK;
9240}
9241
9242exports.inflateReset = inflateReset;
9243exports.inflateReset2 = inflateReset2;
9244exports.inflateResetKeep = inflateResetKeep;
9245exports.inflateInit = inflateInit;
9246exports.inflateInit2 = inflateInit2;
9247exports.inflate = inflate;
9248exports.inflateEnd = inflateEnd;
9249exports.inflateGetHeader = inflateGetHeader;
9250exports.inflateSetDictionary = inflateSetDictionary;
9251exports.inflateInfo = 'pako inflate (from Nodeca project)';
9252
9253/* Not implemented
9254exports.inflateCopy = inflateCopy;
9255exports.inflateGetDictionary = inflateGetDictionary;
9256exports.inflateMark = inflateMark;
9257exports.inflatePrime = inflatePrime;
9258exports.inflateSync = inflateSync;
9259exports.inflateSyncPoint = inflateSyncPoint;
9260exports.inflateUndermine = inflateUndermine;
9261*/
9262
9263
9264/***/ }),
9265/* 21 */
9266/***/ (function(module, exports, __webpack_require__) {
9267
9268"use strict";
9269
9270
9271
9272var utils = __webpack_require__(1);
9273
9274var MAXBITS = 15;
9275var ENOUGH_LENS = 852;
9276var ENOUGH_DISTS = 592;
9277//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
9278
9279var CODES = 0;
9280var LENS = 1;
9281var DISTS = 2;
9282
9283var lbase = [ /* Length codes 257..285 base */
9284 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
9285 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
9286];
9287
9288var lext = [ /* Length codes 257..285 extra */
9289 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
9290 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78
9291];
9292
9293var dbase = [ /* Distance codes 0..29 base */
9294 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
9295 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
9296 8193, 12289, 16385, 24577, 0, 0
9297];
9298
9299var dext = [ /* Distance codes 0..29 extra */
9300 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
9301 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
9302 28, 28, 29, 29, 64, 64
9303];
9304
9305module.exports = function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts)
9306{
9307 var bits = opts.bits;
9308 //here = opts.here; /* table entry for duplication */
9309
9310 var len = 0; /* a code's length in bits */
9311 var sym = 0; /* index of code symbols */
9312 var min = 0, max = 0; /* minimum and maximum code lengths */
9313 var root = 0; /* number of index bits for root table */
9314 var curr = 0; /* number of index bits for current table */
9315 var drop = 0; /* code bits to drop for sub-table */
9316 var left = 0; /* number of prefix codes available */
9317 var used = 0; /* code entries in table used */
9318 var huff = 0; /* Huffman code */
9319 var incr; /* for incrementing code, index */
9320 var fill; /* index for replicating entries */
9321 var low; /* low bits for current root entry */
9322 var mask; /* mask for low root bits */
9323 var next; /* next available space in table */
9324 var base = null; /* base value table to use */
9325 var base_index = 0;
9326// var shoextra; /* extra bits table to use */
9327 var end; /* use base and extra for symbol > end */
9328 var count = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* number of codes of each length */
9329 var offs = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* offsets in table for each length */
9330 var extra = null;
9331 var extra_index = 0;
9332
9333 var here_bits, here_op, here_val;
9334
9335 /*
9336 Process a set of code lengths to create a canonical Huffman code. The
9337 code lengths are lens[0..codes-1]. Each length corresponds to the
9338 symbols 0..codes-1. The Huffman code is generated by first sorting the
9339 symbols by length from short to long, and retaining the symbol order
9340 for codes with equal lengths. Then the code starts with all zero bits
9341 for the first code of the shortest length, and the codes are integer
9342 increments for the same length, and zeros are appended as the length
9343 increases. For the deflate format, these bits are stored backwards
9344 from their more natural integer increment ordering, and so when the
9345 decoding tables are built in the large loop below, the integer codes
9346 are incremented backwards.
9347
9348 This routine assumes, but does not check, that all of the entries in
9349 lens[] are in the range 0..MAXBITS. The caller must assure this.
9350 1..MAXBITS is interpreted as that code length. zero means that that
9351 symbol does not occur in this code.
9352
9353 The codes are sorted by computing a count of codes for each length,
9354 creating from that a table of starting indices for each length in the
9355 sorted table, and then entering the symbols in order in the sorted
9356 table. The sorted table is work[], with that space being provided by
9357 the caller.
9358
9359 The length counts are used for other purposes as well, i.e. finding
9360 the minimum and maximum length codes, determining if there are any
9361 codes at all, checking for a valid set of lengths, and looking ahead
9362 at length counts to determine sub-table sizes when building the
9363 decoding tables.
9364 */
9365
9366 /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
9367 for (len = 0; len <= MAXBITS; len++) {
9368 count[len] = 0;
9369 }
9370 for (sym = 0; sym < codes; sym++) {
9371 count[lens[lens_index + sym]]++;
9372 }
9373
9374 /* bound code lengths, force root to be within code lengths */
9375 root = bits;
9376 for (max = MAXBITS; max >= 1; max--) {
9377 if (count[max] !== 0) { break; }
9378 }
9379 if (root > max) {
9380 root = max;
9381 }
9382 if (max === 0) { /* no symbols to code at all */
9383 //table.op[opts.table_index] = 64; //here.op = (var char)64; /* invalid code marker */
9384 //table.bits[opts.table_index] = 1; //here.bits = (var char)1;
9385 //table.val[opts.table_index++] = 0; //here.val = (var short)0;
9386 table[table_index++] = (1 << 24) | (64 << 16) | 0;
9387
9388
9389 //table.op[opts.table_index] = 64;
9390 //table.bits[opts.table_index] = 1;
9391 //table.val[opts.table_index++] = 0;
9392 table[table_index++] = (1 << 24) | (64 << 16) | 0;
9393
9394 opts.bits = 1;
9395 return 0; /* no symbols, but wait for decoding to report error */
9396 }
9397 for (min = 1; min < max; min++) {
9398 if (count[min] !== 0) { break; }
9399 }
9400 if (root < min) {
9401 root = min;
9402 }
9403
9404 /* check for an over-subscribed or incomplete set of lengths */
9405 left = 1;
9406 for (len = 1; len <= MAXBITS; len++) {
9407 left <<= 1;
9408 left -= count[len];
9409 if (left < 0) {
9410 return -1;
9411 } /* over-subscribed */
9412 }
9413 if (left > 0 && (type === CODES || max !== 1)) {
9414 return -1; /* incomplete set */
9415 }
9416
9417 /* generate offsets into symbol table for each length for sorting */
9418 offs[1] = 0;
9419 for (len = 1; len < MAXBITS; len++) {
9420 offs[len + 1] = offs[len] + count[len];
9421 }
9422
9423 /* sort symbols by length, by symbol order within each length */
9424 for (sym = 0; sym < codes; sym++) {
9425 if (lens[lens_index + sym] !== 0) {
9426 work[offs[lens[lens_index + sym]]++] = sym;
9427 }
9428 }
9429
9430 /*
9431 Create and fill in decoding tables. In this loop, the table being
9432 filled is at next and has curr index bits. The code being used is huff
9433 with length len. That code is converted to an index by dropping drop
9434 bits off of the bottom. For codes where len is less than drop + curr,
9435 those top drop + curr - len bits are incremented through all values to
9436 fill the table with replicated entries.
9437
9438 root is the number of index bits for the root table. When len exceeds
9439 root, sub-tables are created pointed to by the root entry with an index
9440 of the low root bits of huff. This is saved in low to check for when a
9441 new sub-table should be started. drop is zero when the root table is
9442 being filled, and drop is root when sub-tables are being filled.
9443
9444 When a new sub-table is needed, it is necessary to look ahead in the
9445 code lengths to determine what size sub-table is needed. The length
9446 counts are used for this, and so count[] is decremented as codes are
9447 entered in the tables.
9448
9449 used keeps track of how many table entries have been allocated from the
9450 provided *table space. It is checked for LENS and DIST tables against
9451 the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
9452 the initial root table size constants. See the comments in inftrees.h
9453 for more information.
9454
9455 sym increments through all symbols, and the loop terminates when
9456 all codes of length max, i.e. all codes, have been processed. This
9457 routine permits incomplete codes, so another loop after this one fills
9458 in the rest of the decoding tables with invalid code markers.
9459 */
9460
9461 /* set up for code type */
9462 // poor man optimization - use if-else instead of switch,
9463 // to avoid deopts in old v8
9464 if (type === CODES) {
9465 base = extra = work; /* dummy value--not used */
9466 end = 19;
9467
9468 } else if (type === LENS) {
9469 base = lbase;
9470 base_index -= 257;
9471 extra = lext;
9472 extra_index -= 257;
9473 end = 256;
9474
9475 } else { /* DISTS */
9476 base = dbase;
9477 extra = dext;
9478 end = -1;
9479 }
9480
9481 /* initialize opts for loop */
9482 huff = 0; /* starting code */
9483 sym = 0; /* starting code symbol */
9484 len = min; /* starting code length */
9485 next = table_index; /* current table to fill in */
9486 curr = root; /* current table index bits */
9487 drop = 0; /* current bits to drop from code for index */
9488 low = -1; /* trigger new sub-table when len > root */
9489 used = 1 << root; /* use root table entries */
9490 mask = used - 1; /* mask for comparing low */
9491
9492 /* check available table space */
9493 if ((type === LENS && used > ENOUGH_LENS) ||
9494 (type === DISTS && used > ENOUGH_DISTS)) {
9495 return 1;
9496 }
9497
9498 /* process all codes and make table entries */
9499 for (;;) {
9500 /* create table entry */
9501 here_bits = len - drop;
9502 if (work[sym] < end) {
9503 here_op = 0;
9504 here_val = work[sym];
9505 }
9506 else if (work[sym] > end) {
9507 here_op = extra[extra_index + work[sym]];
9508 here_val = base[base_index + work[sym]];
9509 }
9510 else {
9511 here_op = 32 + 64; /* end of block */
9512 here_val = 0;
9513 }
9514
9515 /* replicate for those indices with low len bits equal to huff */
9516 incr = 1 << (len - drop);
9517 fill = 1 << curr;
9518 min = fill; /* save offset to next table */
9519 do {
9520 fill -= incr;
9521 table[next + (huff >> drop) + fill] = (here_bits << 24) | (here_op << 16) | here_val |0;
9522 } while (fill !== 0);
9523
9524 /* backwards increment the len-bit code huff */
9525 incr = 1 << (len - 1);
9526 while (huff & incr) {
9527 incr >>= 1;
9528 }
9529 if (incr !== 0) {
9530 huff &= incr - 1;
9531 huff += incr;
9532 } else {
9533 huff = 0;
9534 }
9535
9536 /* go to next symbol, update count, len */
9537 sym++;
9538 if (--count[len] === 0) {
9539 if (len === max) { break; }
9540 len = lens[lens_index + work[sym]];
9541 }
9542
9543 /* create new sub-table if needed */
9544 if (len > root && (huff & mask) !== low) {
9545 /* if first time, transition to sub-tables */
9546 if (drop === 0) {
9547 drop = root;
9548 }
9549
9550 /* increment past last table */
9551 next += min; /* here min is 1 << curr */
9552
9553 /* determine length of next table */
9554 curr = len - drop;
9555 left = 1 << curr;
9556 while (curr + drop < max) {
9557 left -= count[curr + drop];
9558 if (left <= 0) { break; }
9559 curr++;
9560 left <<= 1;
9561 }
9562
9563 /* check for enough space */
9564 used += 1 << curr;
9565 if ((type === LENS && used > ENOUGH_LENS) ||
9566 (type === DISTS && used > ENOUGH_DISTS)) {
9567 return 1;
9568 }
9569
9570 /* point entry in root table to sub-table */
9571 low = huff & mask;
9572 /*table.op[low] = curr;
9573 table.bits[low] = root;
9574 table.val[low] = next - opts.table_index;*/
9575 table[low] = (root << 24) | (curr << 16) | (next - table_index) |0;
9576 }
9577 }
9578
9579 /* fill in remaining table entry if code is incomplete (guaranteed to have
9580 at most one remaining entry, since if the code is incomplete, the
9581 maximum code length that was allowed to get this far is one bit) */
9582 if (huff !== 0) {
9583 //table.op[next + huff] = 64; /* invalid code marker */
9584 //table.bits[next + huff] = len - drop;
9585 //table.val[next + huff] = 0;
9586 table[next + huff] = ((len - drop) << 24) | (64 << 16) |0;
9587 }
9588
9589 /* set return parameters */
9590 //opts.table_index += used;
9591 opts.bits = root;
9592 return 0;
9593};
9594
9595
9596/***/ }),
9597/* 22 */
9598/***/ (function(module, exports, __webpack_require__) {
9599
9600"use strict";
9601
9602
9603module.exports = {
9604 2: 'need dictionary', /* Z_NEED_DICT 2 */
9605 1: 'stream end', /* Z_STREAM_END 1 */
9606 0: '', /* Z_OK 0 */
9607 '-1': 'file error', /* Z_ERRNO (-1) */
9608 '-2': 'stream error', /* Z_STREAM_ERROR (-2) */
9609 '-3': 'data error', /* Z_DATA_ERROR (-3) */
9610 '-4': 'insufficient memory', /* Z_MEM_ERROR (-4) */
9611 '-5': 'buffer error', /* Z_BUF_ERROR (-5) */
9612 '-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */
9613};
9614
9615
9616/***/ }),
9617/* 23 */
9618/***/ (function(module, exports, __webpack_require__) {
9619
9620"use strict";
9621
9622
9623
9624function ZStream() {
9625 /* next input byte */
9626 this.input = null; // JS specific, because we have no pointers
9627 this.next_in = 0;
9628 /* number of bytes available at input */
9629 this.avail_in = 0;
9630 /* total number of input bytes read so far */
9631 this.total_in = 0;
9632 /* next output byte should be put there */
9633 this.output = null; // JS specific, because we have no pointers
9634 this.next_out = 0;
9635 /* remaining free space at output */
9636 this.avail_out = 0;
9637 /* total number of bytes output so far */
9638 this.total_out = 0;
9639 /* last error message, NULL if no error */
9640 this.msg = ''/*Z_NULL*/;
9641 /* not visible by applications */
9642 this.state = null;
9643 /* best guess about the data type: binary or text */
9644 this.data_type = 2/*Z_UNKNOWN*/;
9645 /* adler32 value of the uncompressed data */
9646 this.adler = 0;
9647}
9648
9649module.exports = ZStream;
9650
9651
9652/***/ }),
9653/* 24 */
9654/***/ (function(module, exports, __webpack_require__) {
9655
9656/* WEBPACK VAR INJECTION */(function(global) {(function () {
9657 var /*
9658 * Rusha, a JavaScript implementation of the Secure Hash Algorithm, SHA-1,
9659 * as defined in FIPS PUB 180-1, tuned for high performance with large inputs.
9660 * (http://github.com/srijs/rusha)
9661 *
9662 * Inspired by Paul Johnstons implementation (http://pajhome.org.uk/crypt/md5).
9663 *
9664 * Copyright (c) 2013 Sam Rijs (http://awesam.de).
9665 * Released under the terms of the MIT license as follows:
9666 *
9667 * Permission is hereby granted, free of charge, to any person obtaining a
9668 * copy of this software and associated documentation files (the "Software"),
9669 * to deal in the Software without restriction, including without limitation
9670 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9671 * and/or sell copies of the Software, and to permit persons to whom the
9672 * Software is furnished to do so, subject to the following conditions:
9673 *
9674 * The above copyright notice and this permission notice shall be included in
9675 * all copies or substantial portions of the Software.
9676 *
9677 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9678 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9679 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
9680 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9681 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
9682 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
9683 * IN THE SOFTWARE.
9684 */
9685 util = {
9686 getDataType: function (data) {
9687 if (typeof data === 'string') {
9688 return 'string';
9689 }
9690 if (data instanceof Array) {
9691 return 'array';
9692 }
9693 if (typeof global !== 'undefined' && global.Buffer && global.Buffer.isBuffer(data)) {
9694 return 'buffer';
9695 }
9696 if (data instanceof ArrayBuffer) {
9697 return 'arraybuffer';
9698 }
9699 if (data.buffer instanceof ArrayBuffer) {
9700 return 'view';
9701 }
9702 if (data instanceof Blob) {
9703 return 'blob';
9704 }
9705 throw new Error('Unsupported data type.');
9706 }
9707 };
9708 function Rusha(chunkSize) {
9709 'use strict';
9710 var // Private object structure.
9711 self$2 = { fill: 0 };
9712 var // Calculate the length of buffer that the sha1 routine uses
9713 // including the padding.
9714 padlen = function (len) {
9715 for (len += 9; len % 64 > 0; len += 1);
9716 return len;
9717 };
9718 var padZeroes = function (bin, len) {
9719 var h8 = new Uint8Array(bin.buffer);
9720 var om = len % 4, align = len - om;
9721 switch (om) {
9722 case 0:
9723 h8[align + 3] = 0;
9724 case 1:
9725 h8[align + 2] = 0;
9726 case 2:
9727 h8[align + 1] = 0;
9728 case 3:
9729 h8[align + 0] = 0;
9730 }
9731 for (var i$2 = (len >> 2) + 1; i$2 < bin.length; i$2++)
9732 bin[i$2] = 0;
9733 };
9734 var padData = function (bin, chunkLen, msgLen) {
9735 bin[chunkLen >> 2] |= 128 << 24 - (chunkLen % 4 << 3);
9736 // To support msgLen >= 2 GiB, use a float division when computing the
9737 // high 32-bits of the big-endian message length in bits.
9738 bin[((chunkLen >> 2) + 2 & ~15) + 14] = msgLen / (1 << 29) | 0;
9739 bin[((chunkLen >> 2) + 2 & ~15) + 15] = msgLen << 3;
9740 };
9741 var // Convert a binary string and write it to the heap.
9742 // A binary string is expected to only contain char codes < 256.
9743 convStr = function (H8, H32, start, len, off) {
9744 var str = this, i$2, om = off % 4, lm = (len + om) % 4, j = len - lm;
9745 switch (om) {
9746 case 0:
9747 H8[off] = str.charCodeAt(start + 3);
9748 case 1:
9749 H8[off + 1 - (om << 1) | 0] = str.charCodeAt(start + 2);
9750 case 2:
9751 H8[off + 2 - (om << 1) | 0] = str.charCodeAt(start + 1);
9752 case 3:
9753 H8[off + 3 - (om << 1) | 0] = str.charCodeAt(start);
9754 }
9755 if (len < lm + om) {
9756 return;
9757 }
9758 for (i$2 = 4 - om; i$2 < j; i$2 = i$2 + 4 | 0) {
9759 H32[off + i$2 >> 2] = str.charCodeAt(start + i$2) << 24 | str.charCodeAt(start + i$2 + 1) << 16 | str.charCodeAt(start + i$2 + 2) << 8 | str.charCodeAt(start + i$2 + 3);
9760 }
9761 switch (lm) {
9762 case 3:
9763 H8[off + j + 1 | 0] = str.charCodeAt(start + j + 2);
9764 case 2:
9765 H8[off + j + 2 | 0] = str.charCodeAt(start + j + 1);
9766 case 1:
9767 H8[off + j + 3 | 0] = str.charCodeAt(start + j);
9768 }
9769 };
9770 var // Convert a buffer or array and write it to the heap.
9771 // The buffer or array is expected to only contain elements < 256.
9772 convBuf = function (H8, H32, start, len, off) {
9773 var buf = this, i$2, om = off % 4, lm = (len + om) % 4, j = len - lm;
9774 switch (om) {
9775 case 0:
9776 H8[off] = buf[start + 3];
9777 case 1:
9778 H8[off + 1 - (om << 1) | 0] = buf[start + 2];
9779 case 2:
9780 H8[off + 2 - (om << 1) | 0] = buf[start + 1];
9781 case 3:
9782 H8[off + 3 - (om << 1) | 0] = buf[start];
9783 }
9784 if (len < lm + om) {
9785 return;
9786 }
9787 for (i$2 = 4 - om; i$2 < j; i$2 = i$2 + 4 | 0) {
9788 H32[off + i$2 >> 2 | 0] = buf[start + i$2] << 24 | buf[start + i$2 + 1] << 16 | buf[start + i$2 + 2] << 8 | buf[start + i$2 + 3];
9789 }
9790 switch (lm) {
9791 case 3:
9792 H8[off + j + 1 | 0] = buf[start + j + 2];
9793 case 2:
9794 H8[off + j + 2 | 0] = buf[start + j + 1];
9795 case 1:
9796 H8[off + j + 3 | 0] = buf[start + j];
9797 }
9798 };
9799 var convBlob = function (H8, H32, start, len, off) {
9800 var blob = this, i$2, om = off % 4, lm = (len + om) % 4, j = len - lm;
9801 var buf = new Uint8Array(reader.readAsArrayBuffer(blob.slice(start, start + len)));
9802 switch (om) {
9803 case 0:
9804 H8[off] = buf[3];
9805 case 1:
9806 H8[off + 1 - (om << 1) | 0] = buf[2];
9807 case 2:
9808 H8[off + 2 - (om << 1) | 0] = buf[1];
9809 case 3:
9810 H8[off + 3 - (om << 1) | 0] = buf[0];
9811 }
9812 if (len < lm + om) {
9813 return;
9814 }
9815 for (i$2 = 4 - om; i$2 < j; i$2 = i$2 + 4 | 0) {
9816 H32[off + i$2 >> 2 | 0] = buf[i$2] << 24 | buf[i$2 + 1] << 16 | buf[i$2 + 2] << 8 | buf[i$2 + 3];
9817 }
9818 switch (lm) {
9819 case 3:
9820 H8[off + j + 1 | 0] = buf[j + 2];
9821 case 2:
9822 H8[off + j + 2 | 0] = buf[j + 1];
9823 case 1:
9824 H8[off + j + 3 | 0] = buf[j];
9825 }
9826 };
9827 var convFn = function (data) {
9828 switch (util.getDataType(data)) {
9829 case 'string':
9830 return convStr.bind(data);
9831 case 'array':
9832 return convBuf.bind(data);
9833 case 'buffer':
9834 return convBuf.bind(data);
9835 case 'arraybuffer':
9836 return convBuf.bind(new Uint8Array(data));
9837 case 'view':
9838 return convBuf.bind(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));
9839 case 'blob':
9840 return convBlob.bind(data);
9841 }
9842 };
9843 var slice = function (data, offset) {
9844 switch (util.getDataType(data)) {
9845 case 'string':
9846 return data.slice(offset);
9847 case 'array':
9848 return data.slice(offset);
9849 case 'buffer':
9850 return data.slice(offset);
9851 case 'arraybuffer':
9852 return data.slice(offset);
9853 case 'view':
9854 return data.buffer.slice(offset);
9855 }
9856 };
9857 var // Precompute 00 - ff strings
9858 precomputedHex = new Array(256);
9859 for (var i = 0; i < 256; i++) {
9860 precomputedHex[i] = (i < 16 ? '0' : '') + i.toString(16);
9861 }
9862 var // Convert an ArrayBuffer into its hexadecimal string representation.
9863 hex = function (arrayBuffer) {
9864 var binarray = new Uint8Array(arrayBuffer);
9865 var res = new Array(arrayBuffer.byteLength);
9866 for (var i$2 = 0; i$2 < res.length; i$2++) {
9867 res[i$2] = precomputedHex[binarray[i$2]];
9868 }
9869 return res.join('');
9870 };
9871 var ceilHeapSize = function (v) {
9872 // The asm.js spec says:
9873 // The heap object's byteLength must be either
9874 // 2^n for n in [12, 24) or 2^24 * n for n ≥ 1.
9875 // Also, byteLengths smaller than 2^16 are deprecated.
9876 var p;
9877 if (// If v is smaller than 2^16, the smallest possible solution
9878 // is 2^16.
9879 v <= 65536)
9880 return 65536;
9881 if (// If v < 2^24, we round up to 2^n,
9882 // otherwise we round up to 2^24 * n.
9883 v < 16777216) {
9884 for (p = 1; p < v; p = p << 1);
9885 } else {
9886 for (p = 16777216; p < v; p += 16777216);
9887 }
9888 return p;
9889 };
9890 var // Initialize the internal data structures to a new capacity.
9891 init = function (size) {
9892 if (size % 64 > 0) {
9893 throw new Error('Chunk size must be a multiple of 128 bit');
9894 }
9895 self$2.offset = 0;
9896 self$2.maxChunkLen = size;
9897 self$2.padMaxChunkLen = padlen(size);
9898 // The size of the heap is the sum of:
9899 // 1. The padded input message size
9900 // 2. The extended space the algorithm needs (320 byte)
9901 // 3. The 160 bit state the algoritm uses
9902 self$2.heap = new ArrayBuffer(ceilHeapSize(self$2.padMaxChunkLen + 320 + 20));
9903 self$2.h32 = new Int32Array(self$2.heap);
9904 self$2.h8 = new Int8Array(self$2.heap);
9905 self$2.core = new Rusha._core({
9906 Int32Array: Int32Array,
9907 DataView: DataView
9908 }, {}, self$2.heap);
9909 self$2.buffer = null;
9910 };
9911 // Iinitializethe datastructures according
9912 // to a chunk siyze.
9913 init(chunkSize || 64 * 1024);
9914 var initState = function (heap, padMsgLen) {
9915 self$2.offset = 0;
9916 var io = new Int32Array(heap, padMsgLen + 320, 5);
9917 io[0] = 1732584193;
9918 io[1] = -271733879;
9919 io[2] = -1732584194;
9920 io[3] = 271733878;
9921 io[4] = -1009589776;
9922 };
9923 var padChunk = function (chunkLen, msgLen) {
9924 var padChunkLen = padlen(chunkLen);
9925 var view = new Int32Array(self$2.heap, 0, padChunkLen >> 2);
9926 padZeroes(view, chunkLen);
9927 padData(view, chunkLen, msgLen);
9928 return padChunkLen;
9929 };
9930 var // Write data to the heap.
9931 write = function (data, chunkOffset, chunkLen, off) {
9932 convFn(data)(self$2.h8, self$2.h32, chunkOffset, chunkLen, off || 0);
9933 };
9934 var // Initialize and call the RushaCore,
9935 // assuming an input buffer of length len * 4.
9936 coreCall = function (data, chunkOffset, chunkLen, msgLen, finalize) {
9937 var padChunkLen = chunkLen;
9938 write(data, chunkOffset, chunkLen);
9939 if (finalize) {
9940 padChunkLen = padChunk(chunkLen, msgLen);
9941 }
9942 self$2.core.hash(padChunkLen, self$2.padMaxChunkLen);
9943 };
9944 var getRawDigest = function (heap, padMaxChunkLen) {
9945 var io = new Int32Array(heap, padMaxChunkLen + 320, 5);
9946 var out = new Int32Array(5);
9947 var arr = new DataView(out.buffer);
9948 arr.setInt32(0, io[0], false);
9949 arr.setInt32(4, io[1], false);
9950 arr.setInt32(8, io[2], false);
9951 arr.setInt32(12, io[3], false);
9952 arr.setInt32(16, io[4], false);
9953 return out;
9954 };
9955 var // Calculate the hash digest as an array of 5 32bit integers.
9956 rawDigest = this.rawDigest = function (str) {
9957 var msgLen = str.byteLength || str.length || str.size || 0;
9958 initState(self$2.heap, self$2.padMaxChunkLen);
9959 var chunkOffset = 0, chunkLen = self$2.maxChunkLen, last;
9960 for (chunkOffset = 0; msgLen > chunkOffset + chunkLen; chunkOffset += chunkLen) {
9961 coreCall(str, chunkOffset, chunkLen, msgLen, false);
9962 }
9963 coreCall(str, chunkOffset, msgLen - chunkOffset, msgLen, true);
9964 return getRawDigest(self$2.heap, self$2.padMaxChunkLen);
9965 };
9966 // The digest and digestFrom* interface returns the hash digest
9967 // as a hex string.
9968 this.digest = this.digestFromString = this.digestFromBuffer = this.digestFromArrayBuffer = function (str) {
9969 return hex(rawDigest(str).buffer);
9970 };
9971 this.resetState = function () {
9972 initState(self$2.heap, self$2.padMaxChunkLen);
9973 return this;
9974 };
9975 this.append = function (chunk) {
9976 var chunkOffset = 0;
9977 var chunkLen = chunk.byteLength || chunk.length || chunk.size || 0;
9978 var turnOffset = self$2.offset % self$2.maxChunkLen;
9979 var inputLen;
9980 self$2.offset += chunkLen;
9981 while (chunkOffset < chunkLen) {
9982 inputLen = Math.min(chunkLen - chunkOffset, self$2.maxChunkLen - turnOffset);
9983 write(chunk, chunkOffset, inputLen, turnOffset);
9984 turnOffset += inputLen;
9985 chunkOffset += inputLen;
9986 if (turnOffset === self$2.maxChunkLen) {
9987 self$2.core.hash(self$2.maxChunkLen, self$2.padMaxChunkLen);
9988 turnOffset = 0;
9989 }
9990 }
9991 return this;
9992 };
9993 this.getState = function () {
9994 var turnOffset = self$2.offset % self$2.maxChunkLen;
9995 var heap;
9996 if (!turnOffset) {
9997 var io = new Int32Array(self$2.heap, self$2.padMaxChunkLen + 320, 5);
9998 heap = io.buffer.slice(io.byteOffset, io.byteOffset + io.byteLength);
9999 } else {
10000 heap = self$2.heap.slice(0);
10001 }
10002 return {
10003 offset: self$2.offset,
10004 heap: heap
10005 };
10006 };
10007 this.setState = function (state) {
10008 self$2.offset = state.offset;
10009 if (state.heap.byteLength === 20) {
10010 var io = new Int32Array(self$2.heap, self$2.padMaxChunkLen + 320, 5);
10011 io.set(new Int32Array(state.heap));
10012 } else {
10013 self$2.h32.set(new Int32Array(state.heap));
10014 }
10015 return this;
10016 };
10017 var rawEnd = this.rawEnd = function () {
10018 var msgLen = self$2.offset;
10019 var chunkLen = msgLen % self$2.maxChunkLen;
10020 var padChunkLen = padChunk(chunkLen, msgLen);
10021 self$2.core.hash(padChunkLen, self$2.padMaxChunkLen);
10022 var result = getRawDigest(self$2.heap, self$2.padMaxChunkLen);
10023 initState(self$2.heap, self$2.padMaxChunkLen);
10024 return result;
10025 };
10026 this.end = function () {
10027 return hex(rawEnd().buffer);
10028 };
10029 }
10030 ;
10031 // The low-level RushCore module provides the heart of Rusha,
10032 // a high-speed sha1 implementation working on an Int32Array heap.
10033 // At first glance, the implementation seems complicated, however
10034 // with the SHA1 spec at hand, it is obvious this almost a textbook
10035 // implementation that has a few functions hand-inlined and a few loops
10036 // hand-unrolled.
10037 Rusha._core = function RushaCore(stdlib, foreign, heap) {
10038 'use asm';
10039 var H = new stdlib.Int32Array(heap);
10040 function hash(k, x) {
10041 // k in bytes
10042 k = k | 0;
10043 x = x | 0;
10044 var i = 0, j = 0, y0 = 0, z0 = 0, y1 = 0, z1 = 0, y2 = 0, z2 = 0, y3 = 0, z3 = 0, y4 = 0, z4 = 0, t0 = 0, t1 = 0;
10045 y0 = H[x + 320 >> 2] | 0;
10046 y1 = H[x + 324 >> 2] | 0;
10047 y2 = H[x + 328 >> 2] | 0;
10048 y3 = H[x + 332 >> 2] | 0;
10049 y4 = H[x + 336 >> 2] | 0;
10050 for (i = 0; (i | 0) < (k | 0); i = i + 64 | 0) {
10051 z0 = y0;
10052 z1 = y1;
10053 z2 = y2;
10054 z3 = y3;
10055 z4 = y4;
10056 for (j = 0; (j | 0) < 64; j = j + 4 | 0) {
10057 t1 = H[i + j >> 2] | 0;
10058 t0 = ((y0 << 5 | y0 >>> 27) + (y1 & y2 | ~y1 & y3) | 0) + ((t1 + y4 | 0) + 1518500249 | 0) | 0;
10059 y4 = y3;
10060 y3 = y2;
10061 y2 = y1 << 30 | y1 >>> 2;
10062 y1 = y0;
10063 y0 = t0;
10064 H[k + j >> 2] = t1;
10065 }
10066 for (j = k + 64 | 0; (j | 0) < (k + 80 | 0); j = j + 4 | 0) {
10067 t1 = (H[j - 12 >> 2] ^ H[j - 32 >> 2] ^ H[j - 56 >> 2] ^ H[j - 64 >> 2]) << 1 | (H[j - 12 >> 2] ^ H[j - 32 >> 2] ^ H[j - 56 >> 2] ^ H[j - 64 >> 2]) >>> 31;
10068 t0 = ((y0 << 5 | y0 >>> 27) + (y1 & y2 | ~y1 & y3) | 0) + ((t1 + y4 | 0) + 1518500249 | 0) | 0;
10069 y4 = y3;
10070 y3 = y2;
10071 y2 = y1 << 30 | y1 >>> 2;
10072 y1 = y0;
10073 y0 = t0;
10074 H[j >> 2] = t1;
10075 }
10076 for (j = k + 80 | 0; (j | 0) < (k + 160 | 0); j = j + 4 | 0) {
10077 t1 = (H[j - 12 >> 2] ^ H[j - 32 >> 2] ^ H[j - 56 >> 2] ^ H[j - 64 >> 2]) << 1 | (H[j - 12 >> 2] ^ H[j - 32 >> 2] ^ H[j - 56 >> 2] ^ H[j - 64 >> 2]) >>> 31;
10078 t0 = ((y0 << 5 | y0 >>> 27) + (y1 ^ y2 ^ y3) | 0) + ((t1 + y4 | 0) + 1859775393 | 0) | 0;
10079 y4 = y3;
10080 y3 = y2;
10081 y2 = y1 << 30 | y1 >>> 2;
10082 y1 = y0;
10083 y0 = t0;
10084 H[j >> 2] = t1;
10085 }
10086 for (j = k + 160 | 0; (j | 0) < (k + 240 | 0); j = j + 4 | 0) {
10087 t1 = (H[j - 12 >> 2] ^ H[j - 32 >> 2] ^ H[j - 56 >> 2] ^ H[j - 64 >> 2]) << 1 | (H[j - 12 >> 2] ^ H[j - 32 >> 2] ^ H[j - 56 >> 2] ^ H[j - 64 >> 2]) >>> 31;
10088 t0 = ((y0 << 5 | y0 >>> 27) + (y1 & y2 | y1 & y3 | y2 & y3) | 0) + ((t1 + y4 | 0) - 1894007588 | 0) | 0;
10089 y4 = y3;
10090 y3 = y2;
10091 y2 = y1 << 30 | y1 >>> 2;
10092 y1 = y0;
10093 y0 = t0;
10094 H[j >> 2] = t1;
10095 }
10096 for (j = k + 240 | 0; (j | 0) < (k + 320 | 0); j = j + 4 | 0) {
10097 t1 = (H[j - 12 >> 2] ^ H[j - 32 >> 2] ^ H[j - 56 >> 2] ^ H[j - 64 >> 2]) << 1 | (H[j - 12 >> 2] ^ H[j - 32 >> 2] ^ H[j - 56 >> 2] ^ H[j - 64 >> 2]) >>> 31;
10098 t0 = ((y0 << 5 | y0 >>> 27) + (y1 ^ y2 ^ y3) | 0) + ((t1 + y4 | 0) - 899497514 | 0) | 0;
10099 y4 = y3;
10100 y3 = y2;
10101 y2 = y1 << 30 | y1 >>> 2;
10102 y1 = y0;
10103 y0 = t0;
10104 H[j >> 2] = t1;
10105 }
10106 y0 = y0 + z0 | 0;
10107 y1 = y1 + z1 | 0;
10108 y2 = y2 + z2 | 0;
10109 y3 = y3 + z3 | 0;
10110 y4 = y4 + z4 | 0;
10111 }
10112 H[x + 320 >> 2] = y0;
10113 H[x + 324 >> 2] = y1;
10114 H[x + 328 >> 2] = y2;
10115 H[x + 332 >> 2] = y3;
10116 H[x + 336 >> 2] = y4;
10117 }
10118 return { hash: hash };
10119 };
10120 if (// If we'e running in Node.JS, export a module.
10121 true) {
10122 module.exports = Rusha;
10123 } else if (// If we're running in a DOM context, export
10124 // the Rusha object to toplevel.
10125 typeof window !== 'undefined') {
10126 window.Rusha = Rusha;
10127 }
10128 if (// If we're running in a webworker, accept
10129 // messages containing a jobid and a buffer
10130 // or blob object, and return the hash result.
10131 typeof FileReaderSync !== 'undefined') {
10132 var reader = new FileReaderSync(), hasher = new Rusha(4 * 1024 * 1024);
10133 self.onmessage = function onMessage(event) {
10134 var hash, data = event.data.data;
10135 try {
10136 hash = hasher.digest(data);
10137 self.postMessage({
10138 id: event.data.id,
10139 hash: hash
10140 });
10141 } catch (e) {
10142 self.postMessage({
10143 id: event.data.id,
10144 error: e.name
10145 });
10146 }
10147 };
10148 }
10149}());
10150/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(25)))
10151
10152/***/ }),
10153/* 25 */
10154/***/ (function(module, exports) {
10155
10156var g;
10157
10158// This works in non-strict mode
10159g = (function() {
10160 return this;
10161})();
10162
10163try {
10164 // This works if eval is allowed (see CSP)
10165 g = g || Function("return this")() || (1,eval)("this");
10166} catch(e) {
10167 // This works if the window reference is available
10168 if(typeof window === "object")
10169 g = window;
10170}
10171
10172// g can still be undefined, but nothing to do about it...
10173// We return undefined, instead of nothing here, so it's
10174// easier to handle this case. if(!global) { ...}
10175
10176module.exports = g;
10177
10178
10179/***/ }),
10180/* 26 */
10181/***/ (function(module, __webpack_exports__, __webpack_require__) {
10182
10183"use strict";
10184Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
10185/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__bin__ = __webpack_require__(2);
10186
10187
10188console.info('Crypto worker registered');
10189
10190const runTask = data => {
10191 switch (data.task) {
10192 case 'factorize':
10193 return __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__bin__["a" /* pqPrimeFactorization */])(data.bytes);
10194 case 'mod-pow':
10195 return __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__bin__["b" /* bytesModPow */])(data.x, data.y, data.m);
10196 case 'sha1-hash':
10197 return __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__bin__["c" /* sha1HashSync */])(data.bytes);
10198 case 'aes-encrypt':
10199 return __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__bin__["d" /* aesEncryptSync */])(data.bytes, data.keyBytes, data.ivBytes);
10200 case 'aes-decrypt':
10201 return __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__bin__["e" /* aesDecryptSync */])(data.encryptedBytes, data.keyBytes, data.ivBytes);
10202 default:
10203 throw new Error(`Unknown task: ${data.task}`);
10204 }
10205};
10206
10207onmessage = function (e) {
10208 if (e.data === '') {
10209 console.info('empty crypto task');
10210 } else if (typeof e.data === 'string') {
10211 console.info('crypto task string message', e.data);
10212 } else {
10213 const taskID = e.data.taskID;
10214 const result = runTask(e.data);
10215 postMessage({ taskID, result });
10216 }
10217};
10218
10219postMessage('ready');
10220
10221/***/ })
10222/******/ ]);
10223//# sourceMappingURL=hash.worker.js.map
\No newline at end of file