vendor: 9,303 bytes, lines 1-308
1;(function (root, factory) { 2 if (typeof exports === "object") { 3 // CommonJS 4 module.exports = exports = factory(); 5 } 6 else if (typeof define === "function" && define.amd) { 7 // AMD 8 define([], factory); 9 } 10 else { 11 // Global (browser) 12 root.CryptoJS = factory(); 13 } 14}(this, function () { 15 16 /** 17 * CryptoJS core components. 18 */ 19 var CryptoJS = CryptoJS || (function (Math, undefined) { 20 /* 21 * Local polyfil of Object.create 22 */ 23 var create = Object.create || (function () { 24 function F() {}; 25 26 return function (obj) { 27 var subtype; 28 29 F.prototype = obj; 30 31 subtype = new F(); 32 33 F.prototype = null; 34 35 return subtype; 36 }; 37 }()) 38 39 /** 40 * CryptoJS namespace. 41 */ 42 var C = {}; 43 44 /** 45 * Library namespace. 46 */ 47 var C_lib = C.lib = {}; 48 49 /** 50 * Base object for prototypal inheritance. 51 */ 52 var Base = C_lib.Base = (function () { 53 54 55 return { 56 /** 57 * Creates a new object that inherits from this object. 58 * 59 * @param {Object} overrides Properties to copy into the new object. 60 * 61 * @return {Object} The new object. 62 * 63 * @static 64 * 65 * @example 66 * 67 * var MyType = CryptoJS.lib.Base.extend({ 68 * field: 'value', 69 * 70 * method: function () { 71 * } 72 * }); 73 */ 74 extend: function (overrides) { 75 // Spawn 76 var subtype = create(this); 77 78 // Augment 79 if (overrides) { 80 subtype.mixIn(overrides); 81 } 82 83 // Create default initializer 84 if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { 85 subtype.init = function () { 86 subtype.$super.init.apply(this, arguments); 87 }; 88 } 89 90 // Initializer's prototype is the subtype object 91 subtype.init.prototype = subtype; 92 93 // Reference supertype 94 subtype.$super = this; 95 96 return subtype; 97 }, 98 99 /** 100 * Extends this object and runs the init method. 101 * Arguments to create() will be passed to init(). 102 * 103 * @return {Object} The new object. 104 * 105 * @static 106 * 107 * @example 108 * 109 * var instance = MyType.create(); 110 */ 111 create: function () { 112 var instance = this.extend(); 113 instance.init.apply(instance, arguments); 114 115 return instance; 116 }, 117 118 /** 119 * Initializes a newly created object. 120 * Override this method to add some logic when your objects are created. 121 * 122 * @example 123 * 124 * var MyType = CryptoJS.lib.Base.extend({ 125 * init: function () { 126 * // ... 127 * } 128 * }); 129 */ 130 init: function () { 131 }, 132 133 /** 134 * Copies properties into this object. 135 * 136 * @param {Object} properties The properties to mix in. 137 * 138 * @example 139 * 140 * MyType.mixIn({ 141 * field: 'value' 142 * }); 143 */ 144 mixIn: function (properties) { 145 for (var propertyName in properties) { 146 if (properties.hasOwnProperty(propertyName)) { 147 this[propertyName] = properties[propertyName]; 148 } 149 } 150 151 // IE won't copy toString using the loop above 152 if (properties.hasOwnProperty('toString')) { 153 this.toString = properties.toString; 154 } 155 }, 156 157 /** 158 * Creates a copy of this object. 159 * 160 * @return {Object} The clone. 161 * 162 * @example 163 * 164 * var clone = instance.clone(); 165 */ 166 clone: function () { 167 return this.init.prototype.extend(this); 168 } 169 }; 170 }()); 171 172 /** 173 * An array of 32-bit words. 174 * 175 * @property {Array} words The array of 32-bit words. 176 * @property {number} sigBytes The number of significant bytes in this word array. 177 */ 178 var WordArray = C_lib.WordArray = Base.extend({ 179 /** 180 * Initializes a newly created word array. 181 * 182 * @param {Array} words (Optional) An array of 32-bit words. 183 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 184 * 185 * @example 186 * 187 * var wordArray = CryptoJS.lib.WordArray.create(); 188 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); 189 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); 190 */ 191 init: function (words, sigBytes) { 192 words = this.words = words || []; 193 194 if (sigBytes != undefined) { 195 this.sigBytes = sigBytes; 196 } else { 197 this.sigBytes = words.length * 4; 198 } 199 }, 200 201 /** 202 * Converts this word array to a string. 203 * 204 * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex 205 * 206 * @return {string} The stringified word array. 207 * 208 * @example 209 * 210 * var string = wordArray + ''; 211 * var string = wordArray.toString(); 212 * var string = wordArray.toString(CryptoJS.enc.Utf8); 213 */ 214 toString: function (encoder) { 215 return (encoder || Hex).stringify(this); 216 }, 217 218 /** 219 * Concatenates a word array to this word array. 220 * 221 * @param {WordArray} wordArray The word array to append. 222 * 223 * @return {WordArray} This word array. 224 * 225 * @example 226 * 227 * wordArray1.concat(wordArray2); 228 */ 229 concat: function (wordArray) { 230 // Shortcuts 231 var thisWords = this.words; 232 var thatWords = wordArray.words; 233 var thisSigBytes = this.sigBytes; 234 var thatSigBytes = wordArray.sigBytes; 235 236 // Clamp excess bits 237 this.clamp(); 238 239 // Concat 240 if (thisSigBytes % 4) { 241 // Copy one byte at a time 242 for (var i = 0; i < thatSigBytes; i++) { 243 var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 244 thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); 245 } 246 } else { 247 // Copy one word at a time 248 for (var i = 0; i < thatSigBytes; i += 4) { 249 thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; 250 } 251 } 252 this.sigBytes += thatSigBytes; 253 254 // Chainable 255 return this; 256 }, 257 258 /** 259 * Removes insignificant bits. 260 * 261 * @example 262 * 263 * wordArray.clamp(); 264 */ 265 clamp: function () { 266 // Shortcuts 267 var words = this.words; 268 var sigBytes = this.sigBytes; 269 270 // Clamp 271 words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); 272 words.length = Math.ceil(sigBytes / 4); 273 }, 274 275 /** 276 * Creates a copy of this word array. 277 * 278 * @return {WordArray} The clone. 279 * 280 * @example 281 * 282 * var clone = wordArray.clone(); 283 */ 284 clone: function () { 285 var clone = Base.clone.call(this); 286 clone.words = this.words.slice(0); 287 288 return clone; 289 }, 290 291 /** 292 * Creates a word array filled with random bytes. 293 * 294 * @param {number} nBytes The number of random bytes to generate. 295 * 296 * @return {WordArray} The random word array. 297 * 298 * @static 299 * 300 * @example 301 * 302 * var wordArray = CryptoJS.lib.WordArray.random(16); 303 */ 304 random: function (nBytes) { 305 var words = []; 306 307 var r = (function (m_w) { 308 var m_w = m_w;
vendor: 11,356 bytes, lines 309-669
309 var m_z = 0x3ade68b1; 310 var mask = 0xffffffff; 311 312 return function () { 313 m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask; 314 m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask; 315 var result = ((m_z << 0x10) + m_w) & mask; 316 result /= 0x100000000; 317 result += 0.5; 318 return result * (Math.random() > .5 ? 1 : -1); 319 } 320 }); 321 322 for (var i = 0, rcache; i < nBytes; i += 4) { 323 var _r = r((rcache || Math.random()) * 0x100000000); 324 325 rcache = _r() * 0x3ade67b7; 326 words.push((_r() * 0x100000000) | 0); 327 } 328 329 return new WordArray.init(words, nBytes); 330 } 331 }); 332 333 /** 334 * Encoder namespace. 335 */ 336 var C_enc = C.enc = {}; 337 338 /** 339 * Hex encoding strategy. 340 */ 341 var Hex = C_enc.Hex = { 342 /** 343 * Converts a word array to a hex string. 344 * 345 * @param {WordArray} wordArray The word array. 346 * 347 * @return {string} The hex string. 348 * 349 * @static 350 * 351 * @example 352 * 353 * var hexString = CryptoJS.enc.Hex.stringify(wordArray); 354 */ 355 stringify: function (wordArray) { 356 // Shortcuts 357 var words = wordArray.words; 358 var sigBytes = wordArray.sigBytes; 359 360 // Convert 361 var hexChars = []; 362 for (var i = 0; i < sigBytes; i++) { 363 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 364 hexChars.push((bite >>> 4).toString(16)); 365 hexChars.push((bite & 0x0f).toString(16)); 366 } 367 368 return hexChars.join(''); 369 }, 370 371 /** 372 * Converts a hex string to a word array. 373 * 374 * @param {string} hexStr The hex string. 375 * 376 * @return {WordArray} The word array. 377 * 378 * @static 379 * 380 * @example 381 * 382 * var wordArray = CryptoJS.enc.Hex.parse(hexString); 383 */ 384 parse: function (hexStr) { 385 // Shortcut 386 var hexStrLength = hexStr.length; 387 388 // Convert 389 var words = []; 390 for (var i = 0; i < hexStrLength; i += 2) { 391 words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); 392 } 393 394 return new WordArray.init(words, hexStrLength / 2); 395 } 396 }; 397 398 /** 399 * Latin1 encoding strategy. 400 */ 401 var Latin1 = C_enc.Latin1 = { 402 /** 403 * Converts a word array to a Latin1 string. 404 * 405 * @param {WordArray} wordArray The word array. 406 * 407 * @return {string} The Latin1 string. 408 * 409 * @static 410 * 411 * @example 412 * 413 * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); 414 */ 415 stringify: function (wordArray) { 416 // Shortcuts 417 var words = wordArray.words; 418 var sigBytes = wordArray.sigBytes; 419 420 // Convert 421 var latin1Chars = []; 422 for (var i = 0; i < sigBytes; i++) { 423 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 424 latin1Chars.push(String.fromCharCode(bite)); 425 } 426 427 return latin1Chars.join(''); 428 }, 429 430 /** 431 * Converts a Latin1 string to a word array. 432 * 433 * @param {string} latin1Str The Latin1 string. 434 * 435 * @return {WordArray} The word array. 436 * 437 * @static 438 * 439 * @example 440 * 441 * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); 442 */ 443 parse: function (latin1Str) { 444 // Shortcut 445 var latin1StrLength = latin1Str.length; 446 447 // Convert 448 var words = []; 449 for (var i = 0; i < latin1StrLength; i++) { 450 words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); 451 } 452 453 return new WordArray.init(words, latin1StrLength); 454 } 455 }; 456 457 /** 458 * UTF-8 encoding strategy. 459 */ 460 var Utf8 = C_enc.Utf8 = { 461 /** 462 * Converts a word array to a UTF-8 string. 463 * 464 * @param {WordArray} wordArray The word array. 465 * 466 * @return {string} The UTF-8 string. 467 * 468 * @static 469 * 470 * @example 471 * 472 * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); 473 */ 474 stringify: function (wordArray) { 475 try { 476 return decodeURIComponent(escape(Latin1.stringify(wordArray))); 477 } catch (e) { 478 throw new Error('Malformed UTF-8 data'); 479 } 480 }, 481 482 /** 483 * Converts a UTF-8 string to a word array. 484 * 485 * @param {string} utf8Str The UTF-8 string. 486 * 487 * @return {WordArray} The word array. 488 * 489 * @static 490 * 491 * @example 492 * 493 * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); 494 */ 495 parse: function (utf8Str) { 496 return Latin1.parse(unescape(encodeURIComponent(utf8Str))); 497 } 498 }; 499 500 /** 501 * Abstract buffered block algorithm template. 502 * 503 * The property blockSize must be implemented in a concrete subtype. 504 * 505 * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 506 */ 507 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ 508 /** 509 * Resets this block algorithm's data buffer to its initial state. 510 * 511 * @example 512 * 513 * bufferedBlockAlgorithm.reset(); 514 */ 515 reset: function () { 516 // Initial values 517 this._data = new WordArray.init(); 518 this._nDataBytes = 0; 519 }, 520 521 /** 522 * Adds new data to this block algorithm's buffer. 523 * 524 * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. 525 * 526 * @example 527 * 528 * bufferedBlockAlgorithm._append('data'); 529 * bufferedBlockAlgorithm._append(wordArray); 530 */ 531 _append: function (data) { 532 // Convert string to WordArray, else assume WordArray already 533 if (typeof data == 'string') { 534 data = Utf8.parse(data); 535 } 536 537 // Append 538 this._data.concat(data); 539 this._nDataBytes += data.sigBytes; 540 }, 541 542 /** 543 * Processes available data blocks. 544 * 545 * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. 546 * 547 * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. 548 * 549 * @return {WordArray} The processed data. 550 * 551 * @example 552 * 553 * var processedData = bufferedBlockAlgorithm._process(); 554 * var processedData = bufferedBlockAlgorithm._process(!!'flush'); 555 */ 556 _process: function (doFlush) { 557 // Shortcuts 558 var data = this._data; 559 var dataWords = data.words; 560 var dataSigBytes = data.sigBytes; 561 var blockSize = this.blockSize; 562 var blockSizeBytes = blockSize * 4; 563 564 // Count blocks ready 565 var nBlocksReady = dataSigBytes / blockSizeBytes; 566 if (doFlush) { 567 // Round up to include partial blocks 568 nBlocksReady = Math.ceil(nBlocksReady); 569 } else { 570 // Round down to include only full blocks, 571 // less the number of blocks that must remain in the buffer 572 nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); 573 } 574 575 // Count words ready 576 var nWordsReady = nBlocksReady * blockSize; 577 578 // Count bytes ready 579 var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); 580 581 // Process blocks 582 if (nWordsReady) { 583 for (var offset = 0; offset < nWordsReady; offset += blockSize) { 584 // Perform concrete-algorithm logic 585 this._doProcessBlock(dataWords, offset); 586 } 587 588 // Remove processed words 589 var processedWords = dataWords.splice(0, nWordsReady); 590 data.sigBytes -= nBytesReady; 591 } 592 593 // Return processed words 594 return new WordArray.init(processedWords, nBytesReady); 595 }, 596 597 /** 598 * Creates a copy of this object. 599 * 600 * @return {Object} The clone. 601 * 602 * @example 603 * 604 * var clone = bufferedBlockAlgorithm.clone(); 605 */ 606 clone: function () { 607 var clone = Base.clone.call(this); 608 clone._data = this._data.clone(); 609 610 return clone; 611 }, 612 613 _minBufferSize: 0 614 }); 615 616 /** 617 * Abstract hasher template. 618 * 619 * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) 620 */ 621 var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ 622 /** 623 * Configuration options. 624 */ 625 cfg: Base.extend(), 626 627 /** 628 * Initializes a newly created hasher. 629 * 630 * @param {Object} cfg (Optional) The configuration options to use for this hash computation. 631 * 632 * @example 633 * 634 * var hasher = CryptoJS.algo.SHA256.create(); 635 */ 636 init: function (cfg) { 637 // Apply config defaults 638 this.cfg = this.cfg.extend(cfg); 639 640 // Set initial values 641 this.reset(); 642 }, 643 644 /** 645 * Resets this hasher to its initial state. 646 * 647 * @example 648 * 649 * hasher.reset(); 650 */ 651 reset: function () { 652 // Reset data buffer 653 BufferedBlockAlgorithm.reset.call(this); 654 655 // Perform concrete-hasher logic 656 this._doReset(); 657 }, 658 659 /** 660 * Updates this hasher with a message. 661 * 662 * @param {WordArray|string} messageUpdate The message to append. 663 * 664 * @return {Hasher} This hasher. 665 * 666 * @example 667 * 668 * hasher.update('message'); 669 * hasher.update(wordArray);
vendor: 5,118 bytes, lines 670-837
670 */ 671 update: function (messageUpdate) { 672 // Append 673 this._append(messageUpdate); 674 675 // Update the hash 676 this._process(); 677 678 // Chainable 679 return this; 680 }, 681 682 /** 683 * Finalizes the hash computation. 684 * Note that the finalize operation is effectively a destructive, read-once operation. 685 * 686 * @param {WordArray|string} messageUpdate (Optional) A final message update. 687 * 688 * @return {WordArray} The hash. 689 * 690 * @example 691 * 692 * var hash = hasher.finalize(); 693 * var hash = hasher.finalize('message'); 694 * var hash = hasher.finalize(wordArray); 695 */ 696 finalize: function (messageUpdate) { 697 // Final message update 698 if (messageUpdate) { 699 this._append(messageUpdate); 700 } 701 702 // Perform concrete-hasher logic 703 var hash = this._doFinalize(); 704 705 return hash; 706 }, 707 708 blockSize: 512/32, 709 710 /** 711 * Creates a shortcut function to a hasher's object interface. 712 * 713 * @param {Hasher} hasher The hasher to create a helper for. 714 * 715 * @return {Function} The shortcut function. 716 * 717 * @static 718 * 719 * @example 720 * 721 * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); 722 */ 723 _createHelper: function (hasher) { 724 return function (message, cfg) { 725 return new hasher.init(cfg).finalize(message); 726 }; 727 }, 728 729 /** 730 * Creates a shortcut function to the HMAC's object interface. 731 * 732 * @param {Hasher} hasher The hasher to use in this HMAC helper. 733 * 734 * @return {Function} The shortcut function. 735 * 736 * @static 737 * 738 * @example 739 * 740 * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); 741 */ 742 _createHmacHelper: function (hasher) { 743 return function (message, key) { 744 return new C_algo.HMAC.init(hasher, key).finalize(message); 745 }; 746 } 747 }); 748 749 /** 750 * Algorithm namespace. 751 */ 752 var C_algo = C.algo = {}; 753 754 return C; 755 }(Math)); 756 757 758 (function () { 759 // Shortcuts 760 var C = CryptoJS; 761 var C_lib = C.lib; 762 var WordArray = C_lib.WordArray; 763 var C_enc = C.enc; 764 765 /** 766 * Base64 encoding strategy. 767 */ 768 var Base64 = C_enc.Base64 = { 769 /** 770 * Converts a word array to a Base64 string. 771 * 772 * @param {WordArray} wordArray The word array. 773 * 774 * @return {string} The Base64 string. 775 * 776 * @static 777 * 778 * @example 779 * 780 * var base64String = CryptoJS.enc.Base64.stringify(wordArray); 781 */ 782 stringify: function (wordArray) { 783 // Shortcuts 784 var words = wordArray.words; 785 var sigBytes = wordArray.sigBytes; 786 var map = this._map; 787 788 // Clamp excess bits 789 wordArray.clamp(); 790 791 // Convert 792 var base64Chars = []; 793 for (var i = 0; i < sigBytes; i += 3) { 794 var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 795 var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; 796 var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; 797 798 var triplet = (byte1 << 16) | (byte2 << 8) | byte3; 799 800 for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) { 801 base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); 802 } 803 } 804 805 // Add padding 806 var paddingChar = map.charAt(64); 807 if (paddingChar) { 808 while (base64Chars.length % 4) { 809 base64Chars.push(paddingChar); 810 } 811 } 812 813 return base64Chars.join(''); 814 }, 815 816 /** 817 * Converts a Base64 string to a word array. 818 * 819 * @param {string} base64Str The Base64 string. 820 * 821 * @return {WordArray} The word array. 822 * 823 * @static 824 * 825 * @example 826 * 827 * var wordArray = CryptoJS.enc.Base64.parse(base64String); 828 */ 829 parse: function (base64Str) { 830 // Shortcuts 831 var base64StrLength = base64Str.length; 832 var map = this._map; 833 var reverseMap = this._reverseMap; 834 835 if (!reverseMap) { 836 reverseMap = this._reverseMap = []; 837 for (var j = 0; j < map.length; j++) {
vendor: 3,513 bytes, lines 838-945
838 reverseMap[map.charCodeAt(j)] = j; 839 } 840 } 841 842 // Ignore padding 843 var paddingChar = map.charAt(64); 844 if (paddingChar) { 845 var paddingIndex = base64Str.indexOf(paddingChar); 846 if (paddingIndex !== -1) { 847 base64StrLength = paddingIndex; 848 } 849 } 850 851 // Convert 852 return parseLoop(base64Str, base64StrLength, reverseMap); 853 854 }, 855 856 _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' 857 }; 858 859 function parseLoop(base64Str, base64StrLength, reverseMap) { 860 var words = []; 861 var nBytes = 0; 862 for (var i = 0; i < base64StrLength; i++) { 863 if (i % 4) { 864 var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); 865 var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); 866 words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8); 867 nBytes++; 868 } 869 } 870 return WordArray.create(words, nBytes); 871 } 872 }()); 873 874 875 (function (Math) { 876 // Shortcuts 877 var C = CryptoJS; 878 var C_lib = C.lib; 879 var WordArray = C_lib.WordArray; 880 var Hasher = C_lib.Hasher; 881 var C_algo = C.algo; 882 883 // Constants table 884 var T = []; 885 886 // Compute constants 887 (function () { 888 for (var i = 0; i < 64; i++) { 889 T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0; 890 } 891 }()); 892 893 /** 894 * MD5 hash algorithm. 895 */ 896 var MD5 = C_algo.MD5 = Hasher.extend({ 897 _doReset: function () { 898 this._hash = new WordArray.init([ 899 0x67452301, 0xefcdab89, 900 0x98badcfe, 0x10325476 901 ]); 902 }, 903 904 _doProcessBlock: function (M, offset) { 905 // Swap endian 906 for (var i = 0; i < 16; i++) { 907 // Shortcuts 908 var offset_i = offset + i; 909 var M_offset_i = M[offset_i]; 910 911 M[offset_i] = ( 912 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 913 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 914 ); 915 } 916 917 // Shortcuts 918 var H = this._hash.words; 919 920 var M_offset_0 = M[offset + 0]; 921 var M_offset_1 = M[offset + 1]; 922 var M_offset_2 = M[offset + 2]; 923 var M_offset_3 = M[offset + 3]; 924 var M_offset_4 = M[offset + 4]; 925 var M_offset_5 = M[offset + 5]; 926 var M_offset_6 = M[offset + 6]; 927 var M_offset_7 = M[offset + 7]; 928 var M_offset_8 = M[offset + 8]; 929 var M_offset_9 = M[offset + 9]; 930 var M_offset_10 = M[offset + 10]; 931 var M_offset_11 = M[offset + 11]; 932 var M_offset_12 = M[offset + 12]; 933 var M_offset_13 = M[offset + 13]; 934 var M_offset_14 = M[offset + 14]; 935 var M_offset_15 = M[offset + 15]; 936 937 // Working varialbes 938 var a = H[0]; 939 var b = H[1]; 940 var c = H[2]; 941 var d = H[3]; 942 943 // Computation 944 a = FF(a, b, c, d, M_offset_0, 7, T[0]); 945 d = FF(d, a, b, c, M_offset_1, 12, T[1]);
946 c = FF(c, d, a, b, M_offset_2, 17, T[2]); 947 b = FF(b, c, d, a, M_offset_3, 22, T[3]); 948 a = FF(a, b, c, d, M_offset_4, 7, T[4]); 949 d = FF(d, a, b, c, M_offset_5, 12, T[5]); 950 c = FF(c, d, a, b, M_offset_6, 17, T[6]); 951 b = FF(b, c, d, a, M_offset_7, 22, T[7]); 952 a = FF(a, b, c, d, M_offset_8, 7, T[8]); 953 d = FF(d, a, b, c, M_offset_9, 12, T[9]); 954 c = FF(c, d, a, b, M_offset_10, 17, T[10]); 955 b = FF(b, c, d, a, M_offset_11, 22, T[11]); 956 a = FF(a, b, c, d, M_offset_12, 7, T[12]); 957 d = FF(d, a, b, c, M_offset_13, 12, T[13]); 958 c = FF(c, d, a, b, M_offset_14, 17, T[14]); 959 b = FF(b, c, d, a, M_offset_15, 22, T[15]); 960 961 a = GG(a, b, c, d, M_offset_1, 5, T[16]); 962 d = GG(d, a, b, c, M_offset_6, 9, T[17]); 963 c = GG(c, d, a, b, M_offset_11, 14, T[18]); 964 b = GG(b, c, d, a, M_offset_0, 20, T[19]); 965 a = GG(a, b, c, d, M_offset_5, 5, T[20]); 966 d = GG(d, a, b, c, M_offset_10, 9, T[21]); 967 c = GG(c, d, a, b, M_offset_15, 14, T[22]); 968 b = GG(b, c, d, a, M_offset_4, 20, T[23]);
vendor: 17,316 bytes, lines 969-1519
969 a = GG(a, b, c, d, M_offset_9, 5, T[24]); 970 d = GG(d, a, b, c, M_offset_14, 9, T[25]); 971 c = GG(c, d, a, b, M_offset_3, 14, T[26]); 972 b = GG(b, c, d, a, M_offset_8, 20, T[27]); 973 a = GG(a, b, c, d, M_offset_13, 5, T[28]); 974 d = GG(d, a, b, c, M_offset_2, 9, T[29]); 975 c = GG(c, d, a, b, M_offset_7, 14, T[30]); 976 b = GG(b, c, d, a, M_offset_12, 20, T[31]); 977 978 a = HH(a, b, c, d, M_offset_5, 4, T[32]); 979 d = HH(d, a, b, c, M_offset_8, 11, T[33]); 980 c = HH(c, d, a, b, M_offset_11, 16, T[34]); 981 b = HH(b, c, d, a, M_offset_14, 23, T[35]); 982 a = HH(a, b, c, d, M_offset_1, 4, T[36]); 983 d = HH(d, a, b, c, M_offset_4, 11, T[37]); 984 c = HH(c, d, a, b, M_offset_7, 16, T[38]); 985 b = HH(b, c, d, a, M_offset_10, 23, T[39]); 986 a = HH(a, b, c, d, M_offset_13, 4, T[40]); 987 d = HH(d, a, b, c, M_offset_0, 11, T[41]); 988 c = HH(c, d, a, b, M_offset_3, 16, T[42]); 989 b = HH(b, c, d, a, M_offset_6, 23, T[43]); 990 a = HH(a, b, c, d, M_offset_9, 4, T[44]); 991 d = HH(d, a, b, c, M_offset_12, 11, T[45]); 992 c = HH(c, d, a, b, M_offset_15, 16, T[46]); 993 b = HH(b, c, d, a, M_offset_2, 23, T[47]); 994 995 a = II(a, b, c, d, M_offset_0, 6, T[48]); 996 d = II(d, a, b, c, M_offset_7, 10, T[49]); 997 c = II(c, d, a, b, M_offset_14, 15, T[50]); 998 b = II(b, c, d, a, M_offset_5, 21, T[51]); 999 a = II(a, b, c, d, M_offset_12, 6, T[52]); 1000 d = II(d, a, b, c, M_offset_3, 10, T[53]); 1001 c = II(c, d, a, b, M_offset_10, 15, T[54]); 1002 b = II(b, c, d, a, M_offset_1, 21, T[55]); 1003 a = II(a, b, c, d, M_offset_8, 6, T[56]); 1004 d = II(d, a, b, c, M_offset_15, 10, T[57]); 1005 c = II(c, d, a, b, M_offset_6, 15, T[58]); 1006 b = II(b, c, d, a, M_offset_13, 21, T[59]); 1007 a = II(a, b, c, d, M_offset_4, 6, T[60]); 1008 d = II(d, a, b, c, M_offset_11, 10, T[61]); 1009 c = II(c, d, a, b, M_offset_2, 15, T[62]); 1010 b = II(b, c, d, a, M_offset_9, 21, T[63]); 1011 1012 // Intermediate hash value 1013 H[0] = (H[0] + a) | 0; 1014 H[1] = (H[1] + b) | 0; 1015 H[2] = (H[2] + c) | 0; 1016 H[3] = (H[3] + d) | 0; 1017 }, 1018 1019 _doFinalize: function () { 1020 // Shortcuts 1021 var data = this._data; 1022 var dataWords = data.words; 1023 1024 var nBitsTotal = this._nDataBytes * 8; 1025 var nBitsLeft = data.sigBytes * 8; 1026 1027 // Add padding 1028 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 1029 1030 var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000); 1031 var nBitsTotalL = nBitsTotal; 1032 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = ( 1033 (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | 1034 (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00) 1035 ); 1036 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 1037 (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | 1038 (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00) 1039 ); 1040 1041 data.sigBytes = (dataWords.length + 1) * 4; 1042 1043 // Hash final blocks 1044 this._process(); 1045 1046 // Shortcuts 1047 var hash = this._hash; 1048 var H = hash.words; 1049 1050 // Swap endian 1051 for (var i = 0; i < 4; i++) { 1052 // Shortcut 1053 var H_i = H[i]; 1054 1055 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 1056 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 1057 } 1058 1059 // Return final computed hash 1060 return hash; 1061 }, 1062 1063 clone: function () { 1064 var clone = Hasher.clone.call(this); 1065 clone._hash = this._hash.clone(); 1066 1067 return clone; 1068 } 1069 }); 1070 1071 function FF(a, b, c, d, x, s, t) { 1072 var n = a + ((b & c) | (~b & d)) + x + t; 1073 return ((n << s) | (n >>> (32 - s))) + b; 1074 } 1075 1076 function GG(a, b, c, d, x, s, t) { 1077 var n = a + ((b & d) | (c & ~d)) + x + t; 1078 return ((n << s) | (n >>> (32 - s))) + b; 1079 } 1080 1081 function HH(a, b, c, d, x, s, t) { 1082 var n = a + (b ^ c ^ d) + x + t; 1083 return ((n << s) | (n >>> (32 - s))) + b; 1084 } 1085 1086 function II(a, b, c, d, x, s, t) { 1087 var n = a + (c ^ (b | ~d)) + x + t; 1088 return ((n << s) | (n >>> (32 - s))) + b; 1089 } 1090 1091 /** 1092 * Shortcut function to the hasher's object interface. 1093 * 1094 * @param {WordArray|string} message The message to hash. 1095 * 1096 * @return {WordArray} The hash. 1097 * 1098 * @static 1099 * 1100 * @example 1101 * 1102 * var hash = CryptoJS.MD5('message'); 1103 * var hash = CryptoJS.MD5(wordArray); 1104 */ 1105 C.MD5 = Hasher._createHelper(MD5); 1106 1107 /** 1108 * Shortcut function to the HMAC's object interface. 1109 * 1110 * @param {WordArray|string} message The message to hash. 1111 * @param {WordArray|string} key The secret key. 1112 * 1113 * @return {WordArray} The HMAC. 1114 * 1115 * @static 1116 * 1117 * @example 1118 * 1119 * var hmac = CryptoJS.HmacMD5(message, key); 1120 */ 1121 C.HmacMD5 = Hasher._createHmacHelper(MD5); 1122 }(Math)); 1123 1124 1125 (function () { 1126 // Shortcuts 1127 var C = CryptoJS; 1128 var C_lib = C.lib; 1129 var WordArray = C_lib.WordArray; 1130 var Hasher = C_lib.Hasher; 1131 var C_algo = C.algo; 1132 1133 // Reusable object 1134 var W = []; 1135 1136 /** 1137 * SHA-1 hash algorithm. 1138 */ 1139 var SHA1 = C_algo.SHA1 = Hasher.extend({ 1140 _doReset: function () { 1141 this._hash = new WordArray.init([ 1142 0x67452301, 0xefcdab89, 1143 0x98badcfe, 0x10325476, 1144 0xc3d2e1f0 1145 ]); 1146 }, 1147 1148 _doProcessBlock: function (M, offset) { 1149 // Shortcut 1150 var H = this._hash.words; 1151 1152 // Working variables 1153 var a = H[0]; 1154 var b = H[1]; 1155 var c = H[2]; 1156 var d = H[3]; 1157 var e = H[4]; 1158 1159 // Computation 1160 for (var i = 0; i < 80; i++) { 1161 if (i < 16) { 1162 W[i] = M[offset + i] | 0; 1163 } else { 1164 var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; 1165 W[i] = (n << 1) | (n >>> 31); 1166 } 1167 1168 var t = ((a << 5) | (a >>> 27)) + e + W[i]; 1169 if (i < 20) { 1170 t += ((b & c) | (~b & d)) + 0x5a827999; 1171 } else if (i < 40) { 1172 t += (b ^ c ^ d) + 0x6ed9eba1; 1173 } else if (i < 60) { 1174 t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; 1175 } else /* if (i < 80) */ { 1176 t += (b ^ c ^ d) - 0x359d3e2a; 1177 } 1178 1179 e = d; 1180 d = c; 1181 c = (b << 30) | (b >>> 2); 1182 b = a; 1183 a = t; 1184 } 1185 1186 // Intermediate hash value 1187 H[0] = (H[0] + a) | 0; 1188 H[1] = (H[1] + b) | 0; 1189 H[2] = (H[2] + c) | 0; 1190 H[3] = (H[3] + d) | 0; 1191 H[4] = (H[4] + e) | 0; 1192 }, 1193 1194 _doFinalize: function () { 1195 // Shortcuts 1196 var data = this._data; 1197 var dataWords = data.words; 1198 1199 var nBitsTotal = this._nDataBytes * 8; 1200 var nBitsLeft = data.sigBytes * 8; 1201 1202 // Add padding 1203 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 1204 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 1205 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 1206 data.sigBytes = dataWords.length * 4; 1207 1208 // Hash final blocks 1209 this._process(); 1210 1211 // Return final computed hash 1212 return this._hash; 1213 }, 1214 1215 clone: function () { 1216 var clone = Hasher.clone.call(this); 1217 clone._hash = this._hash.clone(); 1218 1219 return clone; 1220 } 1221 }); 1222 1223 /** 1224 * Shortcut function to the hasher's object interface. 1225 * 1226 * @param {WordArray|string} message The message to hash. 1227 * 1228 * @return {WordArray} The hash. 1229 * 1230 * @static 1231 * 1232 * @example 1233 * 1234 * var hash = CryptoJS.SHA1('message'); 1235 * var hash = CryptoJS.SHA1(wordArray); 1236 */ 1237 C.SHA1 = Hasher._createHelper(SHA1); 1238 1239 /** 1240 * Shortcut function to the HMAC's object interface. 1241 * 1242 * @param {WordArray|string} message The message to hash. 1243 * @param {WordArray|string} key The secret key. 1244 * 1245 * @return {WordArray} The HMAC. 1246 * 1247 * @static 1248 * 1249 * @example 1250 * 1251 * var hmac = CryptoJS.HmacSHA1(message, key); 1252 */ 1253 C.HmacSHA1 = Hasher._createHmacHelper(SHA1); 1254 }()); 1255 1256 1257 (function (Math) { 1258 // Shortcuts 1259 var C = CryptoJS; 1260 var C_lib = C.lib; 1261 var WordArray = C_lib.WordArray; 1262 var Hasher = C_lib.Hasher; 1263 var C_algo = C.algo; 1264 1265 // Initialization and round constants tables 1266 var H = []; 1267 var K = []; 1268 1269 // Compute constants 1270 (function () { 1271 function isPrime(n) { 1272 var sqrtN = Math.sqrt(n); 1273 for (var factor = 2; factor <= sqrtN; factor++) { 1274 if (!(n % factor)) { 1275 return false; 1276 } 1277 } 1278 1279 return true; 1280 } 1281 1282 function getFractionalBits(n) { 1283 return ((n - (n | 0)) * 0x100000000) | 0; 1284 } 1285 1286 var n = 2; 1287 var nPrime = 0; 1288 while (nPrime < 64) { 1289 if (isPrime(n)) { 1290 if (nPrime < 8) { 1291 H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); 1292 } 1293 K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); 1294 1295 nPrime++; 1296 } 1297 1298 n++; 1299 } 1300 }()); 1301 1302 // Reusable object 1303 var W = []; 1304 1305 /** 1306 * SHA-256 hash algorithm. 1307 */ 1308 var SHA256 = C_algo.SHA256 = Hasher.extend({ 1309 _doReset: function () { 1310 this._hash = new WordArray.init(H.slice(0)); 1311 }, 1312 1313 _doProcessBlock: function (M, offset) { 1314 // Shortcut 1315 var H = this._hash.words; 1316 1317 // Working variables 1318 var a = H[0]; 1319 var b = H[1]; 1320 var c = H[2]; 1321 var d = H[3]; 1322 var e = H[4]; 1323 var f = H[5]; 1324 var g = H[6]; 1325 var h = H[7]; 1326 1327 // Computation 1328 for (var i = 0; i < 64; i++) { 1329 if (i < 16) { 1330 W[i] = M[offset + i] | 0; 1331 } else { 1332 var gamma0x = W[i - 15]; 1333 var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ 1334 ((gamma0x << 14) | (gamma0x >>> 18)) ^ 1335 (gamma0x >>> 3); 1336 1337 var gamma1x = W[i - 2]; 1338 var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ 1339 ((gamma1x << 13) | (gamma1x >>> 19)) ^ 1340 (gamma1x >>> 10); 1341 1342 W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; 1343 } 1344 1345 var ch = (e & f) ^ (~e & g); 1346 var maj = (a & b) ^ (a & c) ^ (b & c); 1347 1348 var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); 1349 var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); 1350 1351 var t1 = h + sigma1 + ch + K[i] + W[i]; 1352 var t2 = sigma0 + maj; 1353 1354 h = g; 1355 g = f; 1356 f = e; 1357 e = (d + t1) | 0; 1358 d = c; 1359 c = b; 1360 b = a; 1361 a = (t1 + t2) | 0; 1362 } 1363 1364 // Intermediate hash value 1365 H[0] = (H[0] + a) | 0; 1366 H[1] = (H[1] + b) | 0; 1367 H[2] = (H[2] + c) | 0; 1368 H[3] = (H[3] + d) | 0; 1369 H[4] = (H[4] + e) | 0; 1370 H[5] = (H[5] + f) | 0; 1371 H[6] = (H[6] + g) | 0; 1372 H[7] = (H[7] + h) | 0; 1373 }, 1374 1375 _doFinalize: function () { 1376 // Shortcuts 1377 var data = this._data; 1378 var dataWords = data.words; 1379 1380 var nBitsTotal = this._nDataBytes * 8; 1381 var nBitsLeft = data.sigBytes * 8; 1382 1383 // Add padding 1384 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 1385 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 1386 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 1387 data.sigBytes = dataWords.length * 4; 1388 1389 // Hash final blocks 1390 this._process(); 1391 1392 // Return final computed hash 1393 return this._hash; 1394 }, 1395 1396 clone: function () { 1397 var clone = Hasher.clone.call(this); 1398 clone._hash = this._hash.clone(); 1399 1400 return clone; 1401 } 1402 }); 1403 1404 /** 1405 * Shortcut function to the hasher's object interface. 1406 * 1407 * @param {WordArray|string} message The message to hash. 1408 * 1409 * @return {WordArray} The hash. 1410 * 1411 * @static 1412 * 1413 * @example 1414 * 1415 * var hash = CryptoJS.SHA256('message'); 1416 * var hash = CryptoJS.SHA256(wordArray); 1417 */ 1418 C.SHA256 = Hasher._createHelper(SHA256); 1419 1420 /** 1421 * Shortcut function to the HMAC's object interface. 1422 * 1423 * @param {WordArray|string} message The message to hash. 1424 * @param {WordArray|string} key The secret key. 1425 * 1426 * @return {WordArray} The HMAC. 1427 * 1428 * @static 1429 * 1430 * @example 1431 * 1432 * var hmac = CryptoJS.HmacSHA256(message, key); 1433 */ 1434 C.HmacSHA256 = Hasher._createHmacHelper(SHA256); 1435 }(Math)); 1436 1437 1438 (function () { 1439 // Shortcuts 1440 var C = CryptoJS; 1441 var C_lib = C.lib; 1442 var WordArray = C_lib.WordArray; 1443 var C_enc = C.enc; 1444 1445 /** 1446 * UTF-16 BE encoding strategy. 1447 */ 1448 var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = { 1449 /** 1450 * Converts a word array to a UTF-16 BE string. 1451 * 1452 * @param {WordArray} wordArray The word array. 1453 * 1454 * @return {string} The UTF-16 BE string. 1455 * 1456 * @static 1457 * 1458 * @example 1459 * 1460 * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray); 1461 */ 1462 stringify: function (wordArray) { 1463 // Shortcuts 1464 var words = wordArray.words; 1465 var sigBytes = wordArray.sigBytes; 1466 1467 // Convert 1468 var utf16Chars = []; 1469 for (var i = 0; i < sigBytes; i += 2) { 1470 var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff; 1471 utf16Chars.push(String.fromCharCode(codePoint)); 1472 } 1473 1474 return utf16Chars.join(''); 1475 }, 1476 1477 /** 1478 * Converts a UTF-16 BE string to a word array. 1479 * 1480 * @param {string} utf16Str The UTF-16 BE string. 1481 * 1482 * @return {WordArray} The word array. 1483 * 1484 * @static 1485 * 1486 * @example 1487 * 1488 * var wordArray = CryptoJS.enc.Utf16.parse(utf16String); 1489 */ 1490 parse: function (utf16Str) { 1491 // Shortcut 1492 var utf16StrLength = utf16Str.length; 1493 1494 // Convert 1495 var words = []; 1496 for (var i = 0; i < utf16StrLength; i++) { 1497 words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16); 1498 } 1499 1500 return WordArray.create(words, utf16StrLength * 2); 1501 } 1502 }; 1503 1504 /** 1505 * UTF-16 LE encoding strategy. 1506 */ 1507 C_enc.Utf16LE = { 1508 /** 1509 * Converts a word array to a UTF-16 LE string. 1510 * 1511 * @param {WordArray} wordArray The word array. 1512 * 1513 * @return {string} The UTF-16 LE string. 1514 * 1515 * @static 1516 * 1517 * @example 1518 * 1519 * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray);
vendor: 4,341 bytes, lines 1520-1635
1520 */ 1521 stringify: function (wordArray) { 1522 // Shortcuts 1523 var words = wordArray.words; 1524 var sigBytes = wordArray.sigBytes; 1525 1526 // Convert 1527 var utf16Chars = []; 1528 for (var i = 0; i < sigBytes; i += 2) { 1529 var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff); 1530 utf16Chars.push(String.fromCharCode(codePoint)); 1531 } 1532 1533 return utf16Chars.join(''); 1534 }, 1535 1536 /** 1537 * Converts a UTF-16 LE string to a word array. 1538 * 1539 * @param {string} utf16Str The UTF-16 LE string. 1540 * 1541 * @return {WordArray} The word array. 1542 * 1543 * @static 1544 * 1545 * @example 1546 * 1547 * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str); 1548 */ 1549 parse: function (utf16Str) { 1550 // Shortcut 1551 var utf16StrLength = utf16Str.length; 1552 1553 // Convert 1554 var words = []; 1555 for (var i = 0; i < utf16StrLength; i++) { 1556 words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16)); 1557 } 1558 1559 return WordArray.create(words, utf16StrLength * 2); 1560 } 1561 }; 1562 1563 function swapEndian(word) { 1564 return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff); 1565 } 1566 }()); 1567 1568 1569 (function () { 1570 // Check if typed arrays are supported 1571 if (typeof ArrayBuffer != 'function') { 1572 return; 1573 } 1574 1575 // Shortcuts 1576 var C = CryptoJS; 1577 var C_lib = C.lib; 1578 var WordArray = C_lib.WordArray; 1579 1580 // Reference original init 1581 var superInit = WordArray.init; 1582 1583 // Augment WordArray.init to handle typed arrays 1584 var subInit = WordArray.init = function (typedArray) { 1585 // Convert buffers to uint8 1586 if (typedArray instanceof ArrayBuffer) { 1587 typedArray = new Uint8Array(typedArray); 1588 } 1589 1590 // Convert other array views to uint8 1591 if ( 1592 typedArray instanceof Int8Array || 1593 (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) || 1594 typedArray instanceof Int16Array || 1595 typedArray instanceof Uint16Array || 1596 typedArray instanceof Int32Array || 1597 typedArray instanceof Uint32Array || 1598 typedArray instanceof Float32Array || 1599 typedArray instanceof Float64Array 1600 ) { 1601 typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); 1602 } 1603 1604 // Handle Uint8Array 1605 if (typedArray instanceof Uint8Array) { 1606 // Shortcut 1607 var typedArrayByteLength = typedArray.byteLength; 1608 1609 // Extract bytes 1610 var words = []; 1611 for (var i = 0; i < typedArrayByteLength; i++) { 1612 words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8); 1613 } 1614 1615 // Initialize this word array 1616 superInit.call(this, words, typedArrayByteLength); 1617 } else { 1618 // Else call normal init 1619 superInit.apply(this, arguments); 1620 } 1621 }; 1622 1623 subInit.prototype = WordArray; 1624 }()); 1625 1626 1627 /** @preserve 1628 (c) 2012 by Cédric Mesnil. All rights reserved. 1629 1630 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1631 1632 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 1633 - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 1634 1635 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (
1635INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1636 */ 1637 1638 (function (Math) { 1639 // Shortcuts 1640 var C = CryptoJS; 1641 var C_lib = C.lib; 1642 var WordArray = C_lib.WordArray; 1643 var Hasher = C_lib.Hasher; 1644 var C_algo = C.algo; 1645 1646 // Constants table 1647 var _zl = WordArray.create([ 1648 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1649 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 1650 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1651 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 1652 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]); 1653 var _zr = WordArray.create([ 1654 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 1655 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 1656 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 1657 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 1658 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]); 1659 var _sl = WordArray.create([ 1660 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 1661 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 1662 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 1663 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 1664 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]); 1665 var _sr = WordArray.create([ 1666 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 1667 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 1668 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 1669 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 1670 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]); 1671 1672 var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]); 1673 var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]); 1674 1675 /** 1676 * RIPEMD160 hash algorithm. 1677 */ 1678 var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({ 1679 _doReset: function () { 1680 this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]); 1681 }, 1682 1683 _doProcessBlock: function (M, offset) { 1684 1685 // Swap endian 1686 for (var i = 0; i < 16; i++) { 1687 // Shortcuts 1688 var offset_i = offset + i; 1689 var M_offset_i = M[offset_i]; 1690 1691 // Swap 1692 M[offset_i] = ( 1693 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 1694 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 1695 ); 1696 } 1697 // Shortcut 1698 var H = this._hash.words; 1699 var hl = _hl.words; 1700 var hr = _hr.words; 1701 var zl = _zl.words; 1702 var zr = _zr.words; 1703 var sl = _sl.words; 1704 var sr = _sr.words; 1705 1706 // Working variables 1707 var al, bl, cl, dl, el; 1708 var ar, br, cr, dr, er; 1709 1710 ar = al = H[0]; 1711 br = bl = H[1]; 1712 cr = cl = H[2]; 1713 dr = dl = H[3]; 1714 er = el = H[4]; 1715 // Computation 1716 var t; 1717 for (var i = 0; i < 80; i += 1) { 1718 t = (al + M[offset+zl[i]])|0; 1719 if (i<16){ 1720 t += f1(bl,cl,dl) + hl[0]; 1721 } else if (i<32) { 1722 t += f2(bl,cl,dl) + hl[1]; 1723 } else if (i<48) { 1724 t += f3(bl,cl,dl) + hl[2]; 1725 } else if (i<64) { 1726 t += f4(bl,cl,dl) + hl[3]; 1727 } else {// if (i<80) { 1728 t += f5(bl,cl,dl) + hl[4]; 1729 } 1730 t = t|0; 1731 t = rotl(t,sl[i]); 1732 t = (t+el)|0; 1733 al = el; 1734 el = dl; 1735 dl = rotl(cl, 10); 1736 cl = bl; 1737 bl = t; 1738 1739 t = (ar + M[offset+zr[i]])|0; 1740 if (i<16){ 1741 t += f5(br,cr,dr) + hr[0];
vendor: 6,344 bytes, lines 1742-1965
1742 } else if (i<32) { 1743 t += f4(br,cr,dr) + hr[1]; 1744 } else if (i<48) { 1745 t += f3(br,cr,dr) + hr[2]; 1746 } else if (i<64) { 1747 t += f2(br,cr,dr) + hr[3]; 1748 } else {// if (i<80) { 1749 t += f1(br,cr,dr) + hr[4]; 1750 } 1751 t = t|0; 1752 t = rotl(t,sr[i]) ; 1753 t = (t+er)|0; 1754 ar = er; 1755 er = dr; 1756 dr = rotl(cr, 10); 1757 cr = br; 1758 br = t; 1759 } 1760 // Intermediate hash value 1761 t = (H[1] + cl + dr)|0; 1762 H[1] = (H[2] + dl + er)|0; 1763 H[2] = (H[3] + el + ar)|0; 1764 H[3] = (H[4] + al + br)|0; 1765 H[4] = (H[0] + bl + cr)|0; 1766 H[0] = t; 1767 }, 1768 1769 _doFinalize: function () { 1770 // Shortcuts 1771 var data = this._data; 1772 var dataWords = data.words; 1773 1774 var nBitsTotal = this._nDataBytes * 8; 1775 var nBitsLeft = data.sigBytes * 8; 1776 1777 // Add padding 1778 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 1779 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 1780 (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) | 1781 (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00) 1782 ); 1783 data.sigBytes = (dataWords.length + 1) * 4; 1784 1785 // Hash final blocks 1786 this._process(); 1787 1788 // Shortcuts 1789 var hash = this._hash; 1790 var H = hash.words; 1791 1792 // Swap endian 1793 for (var i = 0; i < 5; i++) { 1794 // Shortcut 1795 var H_i = H[i]; 1796 1797 // Swap 1798 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 1799 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 1800 } 1801 1802 // Return final computed hash 1803 return hash; 1804 }, 1805 1806 clone: function () { 1807 var clone = Hasher.clone.call(this); 1808 clone._hash = this._hash.clone(); 1809 1810 return clone; 1811 } 1812 }); 1813 1814 1815 function f1(x, y, z) { 1816 return ((x) ^ (y) ^ (z)); 1817 1818 } 1819 1820 function f2(x, y, z) { 1821 return (((x)&(y)) | ((~x)&(z))); 1822 } 1823 1824 function f3(x, y, z) { 1825 return (((x) | (~(y))) ^ (z)); 1826 } 1827 1828 function f4(x, y, z) { 1829 return (((x) & (z)) | ((y)&(~(z)))); 1830 } 1831 1832 function f5(x, y, z) { 1833 return ((x) ^ ((y) |(~(z)))); 1834 1835 } 1836 1837 function rotl(x,n) { 1838 return (x<<n) | (x>>>(32-n)); 1839 } 1840 1841 1842 /** 1843 * Shortcut function to the hasher's object interface. 1844 * 1845 * @param {WordArray|string} message The message to hash. 1846 * 1847 * @return {WordArray} The hash. 1848 * 1849 * @static 1850 * 1851 * @example 1852 * 1853 * var hash = CryptoJS.RIPEMD160('message'); 1854 * var hash = CryptoJS.RIPEMD160(wordArray); 1855 */ 1856 C.RIPEMD160 = Hasher._createHelper(RIPEMD160); 1857 1858 /** 1859 * Shortcut function to the HMAC's object interface. 1860 * 1861 * @param {WordArray|string} message The message to hash. 1862 * @param {WordArray|string} key The secret key. 1863 * 1864 * @return {WordArray} The HMAC. 1865 * 1866 * @static 1867 * 1868 * @example 1869 * 1870 * var hmac = CryptoJS.HmacRIPEMD160(message, key); 1871 */ 1872 C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160); 1873 }(Math)); 1874 1875 1876 (function () { 1877 // Shortcuts 1878 var C = CryptoJS; 1879 var C_lib = C.lib; 1880 var Base = C_lib.Base; 1881 var C_enc = C.enc; 1882 var Utf8 = C_enc.Utf8; 1883 var C_algo = C.algo; 1884 1885 /** 1886 * HMAC algorithm. 1887 */ 1888 var HMAC = C_algo.HMAC = Base.extend({ 1889 /** 1890 * Initializes a newly created HMAC. 1891 * 1892 * @param {Hasher} hasher The hash algorithm to use. 1893 * @param {WordArray|string} key The secret key. 1894 * 1895 * @example 1896 * 1897 * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key); 1898 */ 1899 init: function (hasher, key) { 1900 // Init hasher 1901 hasher = this._hasher = new hasher.init(); 1902 1903 // Convert string to WordArray, else assume WordArray already 1904 if (typeof key == 'string') { 1905 key = Utf8.parse(key); 1906 } 1907 1908 // Shortcuts 1909 var hasherBlockSize = hasher.blockSize; 1910 var hasherBlockSizeBytes = hasherBlockSize * 4; 1911 1912 // Allow arbitrary length keys 1913 if (key.sigBytes > hasherBlockSizeBytes) { 1914 key = hasher.finalize(key); 1915 } 1916 1917 // Clamp excess bits 1918 key.clamp(); 1919 1920 // Clone key for inner and outer pads 1921 var oKey = this._oKey = key.clone(); 1922 var iKey = this._iKey = key.clone(); 1923 1924 // Shortcuts 1925 var oKeyWords = oKey.words; 1926 var iKeyWords = iKey.words; 1927 1928 // XOR keys with pad constants 1929 for (var i = 0; i < hasherBlockSize; i++) { 1930 oKeyWords[i] ^= 0x5c5c5c5c; 1931 iKeyWords[i] ^= 0x36363636; 1932 } 1933 oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes; 1934 1935 // Set initial values 1936 this.reset(); 1937 }, 1938 1939 /** 1940 * Resets this HMAC to its initial state. 1941 * 1942 * @example 1943 * 1944 * hmacHasher.reset(); 1945 */ 1946 reset: function () { 1947 // Shortcut 1948 var hasher = this._hasher; 1949 1950 // Reset 1951 hasher.reset(); 1952 hasher.update(this._iKey); 1953 }, 1954 1955 /** 1956 * Updates this HMAC with a message. 1957 * 1958 * @param {WordArray|string} messageUpdate The message to append. 1959 * 1960 * @return {HMAC} This HMAC instance. 1961 * 1962 * @example 1963 * 1964 * hmacHasher.update('message'); 1965 * hmacHasher.update(wordArray);
vendor: 10,087 bytes, lines 1966-2284
1966 */ 1967 update: function (messageUpdate) { 1968 this._hasher.update(messageUpdate); 1969 1970 // Chainable 1971 return this; 1972 }, 1973 1974 /** 1975 * Finalizes the HMAC computation. 1976 * Note that the finalize operation is effectively a destructive, read-once operation. 1977 * 1978 * @param {WordArray|string} messageUpdate (Optional) A final message update. 1979 * 1980 * @return {WordArray} The HMAC. 1981 * 1982 * @example 1983 * 1984 * var hmac = hmacHasher.finalize(); 1985 * var hmac = hmacHasher.finalize('message'); 1986 * var hmac = hmacHasher.finalize(wordArray); 1987 */ 1988 finalize: function (messageUpdate) { 1989 // Shortcut 1990 var hasher = this._hasher; 1991 1992 // Compute HMAC 1993 var innerHash = hasher.finalize(messageUpdate); 1994 hasher.reset(); 1995 var hmac = hasher.finalize(this._oKey.clone().concat(innerHash)); 1996 1997 return hmac; 1998 } 1999 }); 2000 }()); 2001 2002 2003 (function () { 2004 // Shortcuts 2005 var C = CryptoJS; 2006 var C_lib = C.lib; 2007 var Base = C_lib.Base; 2008 var WordArray = C_lib.WordArray; 2009 var C_algo = C.algo; 2010 var SHA1 = C_algo.SHA1; 2011 var HMAC = C_algo.HMAC; 2012 2013 /** 2014 * Password-Based Key Derivation Function 2 algorithm. 2015 */ 2016 var PBKDF2 = C_algo.PBKDF2 = Base.extend({ 2017 /** 2018 * Configuration options. 2019 * 2020 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 2021 * @property {Hasher} hasher The hasher to use. Default: SHA1 2022 * @property {number} iterations The number of iterations to perform. Default: 1 2023 */ 2024 cfg: Base.extend({ 2025 keySize: 128/32, 2026 hasher: SHA1, 2027 iterations: 1 2028 }), 2029 2030 /** 2031 * Initializes a newly created key derivation function. 2032 * 2033 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 2034 * 2035 * @example 2036 * 2037 * var kdf = CryptoJS.algo.PBKDF2.create(); 2038 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 }); 2039 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 }); 2040 */ 2041 init: function (cfg) { 2042 this.cfg = this.cfg.extend(cfg); 2043 }, 2044 2045 /** 2046 * Computes the Password-Based Key Derivation Function 2. 2047 * 2048 * @param {WordArray|string} password The password. 2049 * @param {WordArray|string} salt A salt. 2050 * 2051 * @return {WordArray} The derived key. 2052 * 2053 * @example 2054 * 2055 * var key = kdf.compute(password, salt); 2056 */ 2057 compute: function (password, salt) { 2058 // Shortcut 2059 var cfg = this.cfg; 2060 2061 // Init HMAC 2062 var hmac = HMAC.create(cfg.hasher, password); 2063 2064 // Initial values 2065 var derivedKey = WordArray.create(); 2066 var blockIndex = WordArray.create([0x00000001]); 2067 2068 // Shortcuts 2069 var derivedKeyWords = derivedKey.words; 2070 var blockIndexWords = blockIndex.words; 2071 var keySize = cfg.keySize; 2072 var iterations = cfg.iterations; 2073 2074 // Generate key 2075 while (derivedKeyWords.length < keySize) { 2076 var block = hmac.update(salt).finalize(blockIndex); 2077 hmac.reset(); 2078 2079 // Shortcuts 2080 var blockWords = block.words; 2081 var blockWordsLength = blockWords.length; 2082 2083 // Iterations 2084 var intermediate = block; 2085 for (var i = 1; i < iterations; i++) { 2086 intermediate = hmac.finalize(intermediate); 2087 hmac.reset(); 2088 2089 // Shortcut 2090 var intermediateWords = intermediate.words; 2091 2092 // XOR intermediate with block 2093 for (var j = 0; j < blockWordsLength; j++) { 2094 blockWords[j] ^= intermediateWords[j]; 2095 } 2096 } 2097 2098 derivedKey.concat(block); 2099 blockIndexWords[0]++; 2100 } 2101 derivedKey.sigBytes = keySize * 4; 2102 2103 return derivedKey; 2104 } 2105 }); 2106 2107 /** 2108 * Computes the Password-Based Key Derivation Function 2. 2109 * 2110 * @param {WordArray|string} password The password. 2111 * @param {WordArray|string} salt A salt. 2112 * @param {Object} cfg (Optional) The configuration options to use for this computation. 2113 * 2114 * @return {WordArray} The derived key. 2115 * 2116 * @static 2117 * 2118 * @example 2119 * 2120 * var key = CryptoJS.PBKDF2(password, salt); 2121 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 }); 2122 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 }); 2123 */ 2124 C.PBKDF2 = function (password, salt, cfg) { 2125 return PBKDF2.create(cfg).compute(password, salt); 2126 }; 2127 }()); 2128 2129 2130 (function () { 2131 // Shortcuts 2132 var C = CryptoJS; 2133 var C_lib = C.lib; 2134 var Base = C_lib.Base; 2135 var WordArray = C_lib.WordArray; 2136 var C_algo = C.algo; 2137 var MD5 = C_algo.MD5; 2138 2139 /** 2140 * This key derivation function is meant to conform with EVP_BytesToKey. 2141 * www.openssl.org/docs/crypto/EVP_BytesToKey.html 2142 */ 2143 var EvpKDF = C_algo.EvpKDF = Base.extend({ 2144 /** 2145 * Configuration options. 2146 * 2147 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 2148 * @property {Hasher} hasher The hash algorithm to use. Default: MD5 2149 * @property {number} iterations The number of iterations to perform. Default: 1 2150 */ 2151 cfg: Base.extend({ 2152 keySize: 128/32, 2153 hasher: MD5, 2154 iterations: 1 2155 }), 2156 2157 /** 2158 * Initializes a newly created key derivation function. 2159 * 2160 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 2161 * 2162 * @example 2163 * 2164 * var kdf = CryptoJS.algo.EvpKDF.create(); 2165 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 }); 2166 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 }); 2167 */ 2168 init: function (cfg) { 2169 this.cfg = this.cfg.extend(cfg); 2170 }, 2171 2172 /** 2173 * Derives a key from a password. 2174 * 2175 * @param {WordArray|string} password The password. 2176 * @param {WordArray|string} salt A salt. 2177 * 2178 * @return {WordArray} The derived key. 2179 * 2180 * @example 2181 * 2182 * var key = kdf.compute(password, salt); 2183 */ 2184 compute: function (password, salt) { 2185 // Shortcut 2186 var cfg = this.cfg; 2187 2188 // Init hasher 2189 var hasher = cfg.hasher.create(); 2190 2191 // Initial values 2192 var derivedKey = WordArray.create(); 2193 2194 // Shortcuts 2195 var derivedKeyWords = derivedKey.words; 2196 var keySize = cfg.keySize; 2197 var iterations = cfg.iterations; 2198 2199 // Generate key 2200 while (derivedKeyWords.length < keySize) { 2201 if (block) { 2202 hasher.update(block); 2203 } 2204 var block = hasher.update(password).finalize(salt); 2205 hasher.reset(); 2206 2207 // Iterations 2208 for (var i = 1; i < iterations; i++) { 2209 block = hasher.finalize(block); 2210 hasher.reset(); 2211 } 2212 2213 derivedKey.concat(block); 2214 } 2215 derivedKey.sigBytes = keySize * 4; 2216 2217 return derivedKey; 2218 } 2219 }); 2220 2221 /** 2222 * Derives a key from a password. 2223 * 2224 * @param {WordArray|string} password The password. 2225 * @param {WordArray|string} salt A salt. 2226 * @param {Object} cfg (Optional) The configuration options to use for this computation. 2227 * 2228 * @return {WordArray} The derived key. 2229 * 2230 * @static 2231 * 2232 * @example 2233 * 2234 * var key = CryptoJS.EvpKDF(password, salt); 2235 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 }); 2236 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 }); 2237 */ 2238 C.EvpKDF = function (password, salt, cfg) { 2239 return EvpKDF.create(cfg).compute(password, salt); 2240 }; 2241 }()); 2242 2243 2244 (function () { 2245 // Shortcuts 2246 var C = CryptoJS; 2247 var C_lib = C.lib; 2248 var WordArray = C_lib.WordArray; 2249 var C_algo = C.algo; 2250 var SHA256 = C_algo.SHA256; 2251 2252 /** 2253 * SHA-224 hash algorithm. 2254 */ 2255 var SHA224 = C_algo.SHA224 = SHA256.extend({ 2256 _doReset: function () { 2257 this._hash = new WordArray.init([ 2258 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 2259 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 2260 ]); 2261 }, 2262 2263 _doFinalize: function () { 2264 var hash = SHA256._doFinalize.call(this); 2265 2266 hash.sigBytes -= 4; 2267 2268 return hash; 2269 } 2270 }); 2271 2272 /** 2273 * Shortcut function to the hasher's object interface. 2274 * 2275 * @param {WordArray|string} message The message to hash. 2276 * 2277 * @return {WordArray} The hash. 2278 * 2279 * @static 2280 * 2281 * @example 2282 * 2283 * var hash = CryptoJS.SHA224('message'); 2284 * var hash = CryptoJS.SHA224(wordArray);
2285 */ 2286 C.SHA224 = SHA256._createHelper(SHA224); 2287 2288 /** 2289 * Shortcut function to the HMAC's object interface. 2290 * 2291 * @param {WordArray|string} message The message to hash. 2292 * @param {WordArray|string} key The secret key. 2293 * 2294 * @return {WordArray} The HMAC. 2295 * 2296 * @static 2297 * 2298 * @example 2299 * 2300 * var hmac = CryptoJS.HmacSHA224(message, key); 2301 */ 2302 C.HmacSHA224 = SHA256._createHmacHelper(SHA224); 2303 }()); 2304 2305 2306 (function (undefined) { 2307 // Shortcuts 2308 var C = CryptoJS; 2309 var C_lib = C.lib; 2310 var Base = C_lib.Base; 2311 var X32WordArray = C_lib.WordArray; 2312 2313 /** 2314 * x64 namespace. 2315 */ 2316 var C_x64 = C.x64 = {}; 2317 2318 /** 2319 * A 64-bit word. 2320 */ 2321 var X64Word = C_x64.Word = Base.extend({ 2322 /** 2323 * Initializes a newly created 64-bit word. 2324 * 2325 * @param {number} high The high 32 bits. 2326 * @param {number} low The low 32 bits. 2327 * 2328 * @example 2329 * 2330 * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607); 2331 */ 2332 init: function (high, low) { 2333 this.high = high; 2334 this.low = low; 2335 } 2336 2337 /** 2338 * Bitwise NOTs this word. 2339 * 2340 * @return {X64Word} A new x64-Word object after negating. 2341 * 2342 * @example 2343 * 2344 * var negated = x64Word.not(); 2345 */ 2346 // not: function () { 2347 // var high = ~this.high; 2348 // var low = ~this.low; 2349 2350 // return X64Word.create(high, low); 2351 // }, 2352 2353 /** 2354 * Bitwise ANDs this word with the passed word. 2355 * 2356 * @param {X64Word} word The x64-Word to AND with this word. 2357 * 2358 * @return {X64Word} A new x64-Word object after ANDing. 2359 * 2360 * @example 2361 * 2362 * var anded = x64Word.and(anotherX64Word); 2363 */ 2364 // and: function (word) { 2365 // var high = this.high & word.high; 2366 // var low = this.low & word.low; 2367 2368 // return X64Word.create(high, low); 2369 // }, 2370 2371 /** 2372 * Bitwise ORs this word with the passed word. 2373 * 2374 * @param {X64Word} word The x64-Word to OR with this word. 2375 * 2376 * @return {X64Word} A new x64-Word object after ORing. 2377 * 2378 * @example 2379 * 2380 * var ored = x64Word.or(anotherX64Word); 2381 */ 2382 // or: function (word) { 2383 // var high = this.high | word.high; 2384 // var low = this.low | word.low; 2385 2386 // return X64Word.create(high, low); 2387 // }, 2388 2389 /** 2390 * Bitwise XORs this word with the passed word. 2391 * 2392 * @param {X64Word} word The x64-Word to XOR with this word. 2393 * 2394 * @return {X64Word} A new x64-Word object after XORing. 2395 * 2396 * @example 2397 * 2398 * var xored = x64Word.xor(anotherX64Word); 2399 */ 2400 // xor: function (word) { 2401 // var high = this.high ^ word.high; 2402 // var low = this.low ^ word.low; 2403 2404 // return X64Word.create(high, low); 2405 // }, 2406 2407 /** 2408 * Shifts this word n bits to the left. 2409 * 2410 * @param {number} n The number of bits to shift. 2411 * 2412 * @return {X64Word} A new x64-Word object after shifting. 2413 * 2414 * @example 2415 * 2416 * var shifted = x64Word.shiftL(25); 2417 */ 2418 // shiftL: function (n) { 2419 // if (n < 32) { 2420 // var high = (this.high << n) | (this.low >>> (32 - n)); 2421 // var low = this.low << n; 2422 // } else { 2423 // var high = this.low << (n - 32); 2424 // var low = 0; 2425 // } 2426 2427 // return X64Word.create(high, low); 2428 // }, 2429 2430 /** 2431 * Shifts this word n bits to the right. 2432 * 2433 * @param {number} n The number of bits to shift. 2434 * 2435 * @return {X64Word} A new x64-Word object after shifting. 2436 * 2437 * @example 2438 * 2439 * var shifted = x64Word.shiftR(7); 2440 */ 2441 // shiftR: function (n) { 2442 // if (n < 32) { 2443 // var low = (this.low >>> n) | (this.high << (32 - n)); 2444 // var high = this.high >>> n; 2445 // } else { 2446 // var low = this.high >>> (n - 32); 2447 // var high = 0; 2448 // } 2449 2450 // return X64Word.create(high, low); 2451 // }, 2452 2453 /** 2454 * Rotates this word n bits to the left. 2455 * 2456 * @param {number} n The number of bits to rotate. 2457 * 2458 * @return {X64Word} A new x64-Word object after rotating. 2459 * 2460 * @example 2461 * 2462 * var rotated = x64Word.rotL(25);
vendor: 5,134 bytes, lines 2463-2626
2463 */ 2464 // rotL: function (n) { 2465 // return this.shiftL(n).or(this.shiftR(64 - n)); 2466 // }, 2467 2468 /** 2469 * Rotates this word n bits to the right. 2470 * 2471 * @param {number} n The number of bits to rotate. 2472 * 2473 * @return {X64Word} A new x64-Word object after rotating. 2474 * 2475 * @example 2476 * 2477 * var rotated = x64Word.rotR(7); 2478 */ 2479 // rotR: function (n) { 2480 // return this.shiftR(n).or(this.shiftL(64 - n)); 2481 // }, 2482 2483 /** 2484 * Adds this word with the passed word. 2485 * 2486 * @param {X64Word} word The x64-Word to add with this word. 2487 * 2488 * @return {X64Word} A new x64-Word object after adding. 2489 * 2490 * @example 2491 * 2492 * var added = x64Word.add(anotherX64Word); 2493 */ 2494 // add: function (word) { 2495 // var low = (this.low + word.low) | 0; 2496 // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0; 2497 // var high = (this.high + word.high + carry) | 0; 2498 2499 // return X64Word.create(high, low); 2500 // } 2501 }); 2502 2503 /** 2504 * An array of 64-bit words. 2505 * 2506 * @property {Array} words The array of CryptoJS.x64.Word objects. 2507 * @property {number} sigBytes The number of significant bytes in this word array. 2508 */ 2509 var X64WordArray = C_x64.WordArray = Base.extend({ 2510 /** 2511 * Initializes a newly created word array. 2512 * 2513 * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects. 2514 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 2515 * 2516 * @example 2517 * 2518 * var wordArray = CryptoJS.x64.WordArray.create(); 2519 * 2520 * var wordArray = CryptoJS.x64.WordArray.create([ 2521 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 2522 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 2523 * ]); 2524 * 2525 * var wordArray = CryptoJS.x64.WordArray.create([ 2526 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 2527 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 2528 * ], 10); 2529 */ 2530 init: function (words, sigBytes) { 2531 words = this.words = words || []; 2532 2533 if (sigBytes != undefined) { 2534 this.sigBytes = sigBytes; 2535 } else { 2536 this.sigBytes = words.length * 8; 2537 } 2538 }, 2539 2540 /** 2541 * Converts this 64-bit word array to a 32-bit word array. 2542 * 2543 * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array. 2544 * 2545 * @example 2546 * 2547 * var x32WordArray = x64WordArray.toX32(); 2548 */ 2549 toX32: function () { 2550 // Shortcuts 2551 var x64Words = this.words; 2552 var x64WordsLength = x64Words.length; 2553 2554 // Convert 2555 var x32Words = []; 2556 for (var i = 0; i < x64WordsLength; i++) { 2557 var x64Word = x64Words[i]; 2558 x32Words.push(x64Word.high); 2559 x32Words.push(x64Word.low); 2560 } 2561 2562 return X32WordArray.create(x32Words, this.sigBytes); 2563 }, 2564 2565 /** 2566 * Creates a copy of this word array. 2567 * 2568 * @return {X64WordArray} The clone. 2569 * 2570 * @example 2571 * 2572 * var clone = x64WordArray.clone(); 2573 */ 2574 clone: function () { 2575 var clone = Base.clone.call(this); 2576 2577 // Clone "words" array 2578 var words = clone.words = this.words.slice(0); 2579 2580 // Clone each X64Word object 2581 var wordsLength = words.length; 2582 for (var i = 0; i < wordsLength; i++) { 2583 words[i] = words[i].clone(); 2584 } 2585 2586 return clone; 2587 } 2588 }); 2589 }()); 2590 2591 2592 (function (Math) { 2593 // Shortcuts 2594 var C = CryptoJS; 2595 var C_lib = C.lib; 2596 var WordArray = C_lib.WordArray; 2597 var Hasher = C_lib.Hasher; 2598 var C_x64 = C.x64; 2599 var X64Word = C_x64.Word; 2600 var C_algo = C.algo; 2601 2602 // Constants tables 2603 var RHO_OFFSETS = []; 2604 var PI_INDEXES = []; 2605 var ROUND_CONSTANTS = []; 2606 2607 // Compute Constants 2608 (function () { 2609 // Compute rho offset constants 2610 var x = 1, y = 0; 2611 for (var t = 0; t < 24; t++) { 2612 RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64; 2613 2614 var newX = y % 5; 2615 var newY = (2 * x + 3 * y) % 5; 2616 x = newX; 2617 y = newY; 2618 } 2619 2620 // Compute pi index constants 2621 for (var x = 0; x < 5; x++) { 2622 for (var y = 0; y < 5; y++) { 2623 PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5; 2624 } 2625 } 2626
vendor: 6,252 bytes, lines 2627-2791
2627 // Compute round constants 2628 var LFSR = 0x01; 2629 for (var i = 0; i < 24; i++) { 2630 var roundConstantMsw = 0; 2631 var roundConstantLsw = 0; 2632 2633 for (var j = 0; j < 7; j++) { 2634 if (LFSR & 0x01) { 2635 var bitPosition = (1 << j) - 1; 2636 if (bitPosition < 32) { 2637 roundConstantLsw ^= 1 << bitPosition; 2638 } else /* if (bitPosition >= 32) */ { 2639 roundConstantMsw ^= 1 << (bitPosition - 32); 2640 } 2641 } 2642 2643 // Compute next LFSR 2644 if (LFSR & 0x80) { 2645 // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1 2646 LFSR = (LFSR << 1) ^ 0x71; 2647 } else { 2648 LFSR <<= 1; 2649 } 2650 } 2651 2652 ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw); 2653 } 2654 }()); 2655 2656 // Reusable objects for temporary values 2657 var T = []; 2658 (function () { 2659 for (var i = 0; i < 25; i++) { 2660 T[i] = X64Word.create(); 2661 } 2662 }()); 2663 2664 /** 2665 * SHA-3 hash algorithm. 2666 */ 2667 var SHA3 = C_algo.SHA3 = Hasher.extend({ 2668 /** 2669 * Configuration options. 2670 * 2671 * @property {number} outputLength 2672 * The desired number of bits in the output hash. 2673 * Only values permitted are: 224, 256, 384, 512. 2674 * Default: 512 2675 */ 2676 cfg: Hasher.cfg.extend({ 2677 outputLength: 512 2678 }), 2679 2680 _doReset: function () { 2681 var state = this._state = [] 2682 for (var i = 0; i < 25; i++) { 2683 state[i] = new X64Word.init(); 2684 } 2685 2686 this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32; 2687 }, 2688 2689 _doProcessBlock: function (M, offset) { 2690 // Shortcuts 2691 var state = this._state; 2692 var nBlockSizeLanes = this.blockSize / 2; 2693 2694 // Absorb 2695 for (var i = 0; i < nBlockSizeLanes; i++) { 2696 // Shortcuts 2697 var M2i = M[offset + 2 * i]; 2698 var M2i1 = M[offset + 2 * i + 1]; 2699 2700 // Swap endian 2701 M2i = ( 2702 (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | 2703 (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00) 2704 ); 2705 M2i1 = ( 2706 (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | 2707 (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00) 2708 ); 2709 2710 // Absorb message into state 2711 var lane = state[i]; 2712 lane.high ^= M2i1; 2713 lane.low ^= M2i; 2714 } 2715 2716 // Rounds 2717 for (var round = 0; round < 24; round++) { 2718 // Theta 2719 for (var x = 0; x < 5; x++) { 2720 // Mix column lanes 2721 var tMsw = 0, tLsw = 0; 2722 for (var y = 0; y < 5; y++) { 2723 var lane = state[x + 5 * y]; 2724 tMsw ^= lane.high; 2725 tLsw ^= lane.low; 2726 } 2727 2728 // Temporary values 2729 var Tx = T[x]; 2730 Tx.high = tMsw; 2731 Tx.low = tLsw; 2732 } 2733 for (var x = 0; x < 5; x++) { 2734 // Shortcuts 2735 var Tx4 = T[(x + 4) % 5]; 2736 var Tx1 = T[(x + 1) % 5]; 2737 var Tx1Msw = Tx1.high; 2738 var Tx1Lsw = Tx1.low; 2739 2740 // Mix surrounding columns 2741 var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); 2742 var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); 2743 for (var y = 0; y < 5; y++) { 2744 var lane = state[x + 5 * y]; 2745 lane.high ^= tMsw; 2746 lane.low ^= tLsw; 2747 } 2748 } 2749 2750 // Rho Pi 2751 for (var laneIndex = 1; laneIndex < 25; laneIndex++) { 2752 // Shortcuts 2753 var lane = state[laneIndex]; 2754 var laneMsw = lane.high; 2755 var laneLsw = lane.low; 2756 var rhoOffset = RHO_OFFSETS[laneIndex]; 2757 2758 // Rotate lanes 2759 if (rhoOffset < 32) { 2760 var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); 2761 var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); 2762 } else /* if (rhoOffset >= 32) */ { 2763 var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); 2764 var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); 2765 } 2766 2767 // Transpose lanes 2768 var TPiLane = T[PI_INDEXES[laneIndex]]; 2769 TPiLane.high = tMsw; 2770 TPiLane.low = tLsw; 2771 } 2772 2773 // Rho pi at x = y = 0 2774 var T0 = T[0]; 2775 var state0 = state[0]; 2776 T0.high = state0.high; 2777 T0.low = state0.low; 2778 2779 // Chi 2780 for (var x = 0; x < 5; x++) { 2781 for (var y = 0; y < 5; y++) { 2782 // Shortcuts 2783 var laneIndex = x + 5 * y; 2784 var lane = state[laneIndex]; 2785 var TLane = T[laneIndex]; 2786 var Tx1Lane = T[((x + 1) % 5) + 5 * y]; 2787 var Tx2Lane = T[((x + 2) % 5) + 5 * y]; 2788 2789 // Mix rows 2790 lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); 2791 lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low);
vendor: 5,372 bytes, lines 2792-2931
2792 } 2793 } 2794 2795 // Iota 2796 var lane = state[0]; 2797 var roundConstant = ROUND_CONSTANTS[round]; 2798 lane.high ^= roundConstant.high; 2799 lane.low ^= roundConstant.low;; 2800 } 2801 }, 2802 2803 _doFinalize: function () { 2804 // Shortcuts 2805 var data = this._data; 2806 var dataWords = data.words; 2807 var nBitsTotal = this._nDataBytes * 8; 2808 var nBitsLeft = data.sigBytes * 8; 2809 var blockSizeBits = this.blockSize * 32; 2810 2811 // Add padding 2812 dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32); 2813 dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; 2814 data.sigBytes = dataWords.length * 4; 2815 2816 // Hash final blocks 2817 this._process(); 2818 2819 // Shortcuts 2820 var state = this._state; 2821 var outputLengthBytes = this.cfg.outputLength / 8; 2822 var outputLengthLanes = outputLengthBytes / 8; 2823 2824 // Squeeze 2825 var hashWords = []; 2826 for (var i = 0; i < outputLengthLanes; i++) { 2827 // Shortcuts 2828 var lane = state[i]; 2829 var laneMsw = lane.high; 2830 var laneLsw = lane.low; 2831 2832 // Swap endian 2833 laneMsw = ( 2834 (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | 2835 (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00) 2836 ); 2837 laneLsw = ( 2838 (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | 2839 (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00) 2840 ); 2841 2842 // Squeeze state to retrieve hash 2843 hashWords.push(laneLsw); 2844 hashWords.push(laneMsw); 2845 } 2846 2847 // Return final computed hash 2848 return new WordArray.init(hashWords, outputLengthBytes); 2849 }, 2850 2851 clone: function () { 2852 var clone = Hasher.clone.call(this); 2853 2854 var state = clone._state = this._state.slice(0); 2855 for (var i = 0; i < 25; i++) { 2856 state[i] = state[i].clone(); 2857 } 2858 2859 return clone; 2860 } 2861 }); 2862 2863 /** 2864 * Shortcut function to the hasher's object interface. 2865 * 2866 * @param {WordArray|string} message The message to hash. 2867 * 2868 * @return {WordArray} The hash. 2869 * 2870 * @static 2871 * 2872 * @example 2873 * 2874 * var hash = CryptoJS.SHA3('message'); 2875 * var hash = CryptoJS.SHA3(wordArray); 2876 */ 2877 C.SHA3 = Hasher._createHelper(SHA3); 2878 2879 /** 2880 * Shortcut function to the HMAC's object interface. 2881 * 2882 * @param {WordArray|string} message The message to hash. 2883 * @param {WordArray|string} key The secret key. 2884 * 2885 * @return {WordArray} The HMAC. 2886 * 2887 * @static 2888 * 2889 * @example 2890 * 2891 * var hmac = CryptoJS.HmacSHA3(message, key); 2892 */ 2893 C.HmacSHA3 = Hasher._createHmacHelper(SHA3); 2894 }(Math)); 2895 2896 2897 (function () { 2898 // Shortcuts 2899 var C = CryptoJS; 2900 var C_lib = C.lib; 2901 var Hasher = C_lib.Hasher; 2902 var C_x64 = C.x64; 2903 var X64Word = C_x64.Word; 2904 var X64WordArray = C_x64.WordArray; 2905 var C_algo = C.algo; 2906 2907 function X64Word_create() { 2908 return X64Word.create.apply(X64Word, arguments); 2909 } 2910 2911 // Constants 2912 var K = [ 2913 X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd), 2914 X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc), 2915 X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019), 2916 X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118), 2917 X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe), 2918 X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2), 2919 X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1), 2920 X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694), 2921 X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3), 2922 X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65), 2923 X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483), 2924 X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5), 2925 X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210), 2926 X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4), 2927 X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725), 2928 X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70), 2929 X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926), 2930 X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df), 2931 X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb,
vendor: 5,547 bytes, lines 2931-3050
29310x3c77b2a8), 2932 X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b), 2933 X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001), 2934 X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30), 2935 X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910), 2936 X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8), 2937 X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53), 2938 X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8), 2939 X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb), 2940 X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3), 2941 X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60), 2942 X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec), 2943 X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9), 2944 X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b), 2945 X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207), 2946 X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178), 2947 X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6), 2948 X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b), 2949 X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493), 2950 X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c), 2951 X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a), 2952 X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817) 2953 ]; 2954 2955 // Reusable objects 2956 var W = []; 2957 (function () { 2958 for (var i = 0; i < 80; i++) { 2959 W[i] = X64Word_create(); 2960 } 2961 }()); 2962 2963 /** 2964 * SHA-512 hash algorithm. 2965 */ 2966 var SHA512 = C_algo.SHA512 = Hasher.extend({ 2967 _doReset: function () { 2968 this._hash = new X64WordArray.init([ 2969 new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b), 2970 new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1), 2971 new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f), 2972 new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179) 2973 ]); 2974 }, 2975 2976 _doProcessBlock: function (M, offset) { 2977 // Shortcuts 2978 var H = this._hash.words; 2979 2980 var H0 = H[0]; 2981 var H1 = H[1]; 2982 var H2 = H[2]; 2983 var H3 = H[3]; 2984 var H4 = H[4]; 2985 var H5 = H[5]; 2986 var H6 = H[6]; 2987 var H7 = H[7]; 2988 2989 var H0h = H0.high; 2990 var H0l = H0.low; 2991 var H1h = H1.high; 2992 var H1l = H1.low; 2993 var H2h = H2.high; 2994 var H2l = H2.low; 2995 var H3h = H3.high; 2996 var H3l = H3.low; 2997 var H4h = H4.high; 2998 var H4l = H4.low; 2999 var H5h = H5.high; 3000 var H5l = H5.low; 3001 var H6h = H6.high; 3002 var H6l = H6.low; 3003 var H7h = H7.high; 3004 var H7l = H7.low; 3005 3006 // Working variables 3007 var ah = H0h; 3008 var al = H0l; 3009 var bh = H1h; 3010 var bl = H1l; 3011 var ch = H2h; 3012 var cl = H2l; 3013 var dh = H3h; 3014 var dl = H3l; 3015 var eh = H4h; 3016 var el = H4l; 3017 var fh = H5h; 3018 var fl = H5l; 3019 var gh = H6h; 3020 var gl = H6l; 3021 var hh = H7h; 3022 var hl = H7l; 3023 3024 // Rounds 3025 for (var i = 0; i < 80; i++) { 3026 // Shortcut 3027 var Wi = W[i]; 3028 3029 // Extend message 3030 if (i < 16) { 3031 var Wih = Wi.high = M[offset + i * 2] | 0; 3032 var Wil = Wi.low = M[offset + i * 2 + 1] | 0; 3033 } else { 3034 // Gamma0 3035 var gamma0x = W[i - 15]; 3036 var gamma0xh = gamma0x.high; 3037 var gamma0xl = gamma0x.low; 3038 var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7); 3039 var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25)); 3040 3041 // Gamma1 3042 var gamma1x = W[i - 2]; 3043 var gamma1xh = gamma1x.high; 3044 var gamma1xl = gamma1x.low; 3045 var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); 3046 var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26)); 3047 3048 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] 3049 var Wi7 = W[i - 7]; 3050 var Wi7h = Wi7.high;
vendor: 11,554 bytes, lines 3051-3383
3051 var Wi7l = Wi7.low; 3052 3053 var Wi16 = W[i - 16]; 3054 var Wi16h = Wi16.high; 3055 var Wi16l = Wi16.low; 3056 3057 var Wil = gamma0l + Wi7l; 3058 var Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); 3059 var Wil = Wil + gamma1l; 3060 var Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); 3061 var Wil = Wil + Wi16l; 3062 var Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); 3063 3064 Wi.high = Wih; 3065 Wi.low = Wil; 3066 } 3067 3068 var chh = (eh & fh) ^ (~eh & gh); 3069 var chl = (el & fl) ^ (~el & gl); 3070 var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); 3071 var majl = (al & bl) ^ (al & cl) ^ (bl & cl); 3072 3073 var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7)); 3074 var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7)); 3075 var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9)); 3076 var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9)); 3077 3078 // t1 = h + sigma1 + ch + K[i] + W[i] 3079 var Ki = K[i]; 3080 var Kih = Ki.high; 3081 var Kil = Ki.low; 3082 3083 var t1l = hl + sigma1l; 3084 var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0); 3085 var t1l = t1l + chl; 3086 var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0); 3087 var t1l = t1l + Kil; 3088 var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0); 3089 var t1l = t1l + Wil; 3090 var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0); 3091 3092 // t2 = sigma0 + maj 3093 var t2l = sigma0l + majl; 3094 var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0); 3095 3096 // Update working variables 3097 hh = gh; 3098 hl = gl; 3099 gh = fh; 3100 gl = fl; 3101 fh = eh; 3102 fl = el; 3103 el = (dl + t1l) | 0; 3104 eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0; 3105 dh = ch; 3106 dl = cl; 3107 ch = bh; 3108 cl = bl; 3109 bh = ah; 3110 bl = al; 3111 al = (t1l + t2l) | 0; 3112 ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0; 3113 } 3114 3115 // Intermediate hash value 3116 H0l = H0.low = (H0l + al); 3117 H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0)); 3118 H1l = H1.low = (H1l + bl); 3119 H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0)); 3120 H2l = H2.low = (H2l + cl); 3121 H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0)); 3122 H3l = H3.low = (H3l + dl); 3123 H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0)); 3124 H4l = H4.low = (H4l + el); 3125 H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0)); 3126 H5l = H5.low = (H5l + fl); 3127 H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0)); 3128 H6l = H6.low = (H6l + gl); 3129 H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0)); 3130 H7l = H7.low = (H7l + hl); 3131 H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0)); 3132 }, 3133 3134 _doFinalize: function () { 3135 // Shortcuts 3136 var data = this._data; 3137 var dataWords = data.words; 3138 3139 var nBitsTotal = this._nDataBytes * 8; 3140 var nBitsLeft = data.sigBytes * 8; 3141 3142 // Add padding 3143 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 3144 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000); 3145 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; 3146 data.sigBytes = dataWords.length * 4; 3147 3148 // Hash final blocks 3149 this._process(); 3150 3151 // Convert hash to 32-bit word array before returning 3152 var hash = this._hash.toX32(); 3153 3154 // Return final computed hash 3155 return hash; 3156 }, 3157 3158 clone: function () { 3159 var clone = Hasher.clone.call(this); 3160 clone._hash = this._hash.clone(); 3161 3162 return clone; 3163 }, 3164 3165 blockSize: 1024/32 3166 }); 3167 3168 /** 3169 * Shortcut function to the hasher's object interface. 3170 * 3171 * @param {WordArray|string} message The message to hash. 3172 * 3173 * @return {WordArray} The hash. 3174 * 3175 * @static 3176 * 3177 * @example 3178 * 3179 * var hash = CryptoJS.SHA512('message'); 3180 * var hash = CryptoJS.SHA512(wordArray); 3181 */ 3182 C.SHA512 = Hasher._createHelper(SHA512); 3183 3184 /** 3185 * Shortcut function to the HMAC's object interface. 3186 * 3187 * @param {WordArray|string} message The message to hash. 3188 * @param {WordArray|string} key The secret key. 3189 * 3190 * @return {WordArray} The HMAC. 3191 * 3192 * @static 3193 * 3194 * @example 3195 * 3196 * var hmac = CryptoJS.HmacSHA512(message, key); 3197 */ 3198 C.HmacSHA512 = Hasher._createHmacHelper(SHA512); 3199 }()); 3200 3201 3202 (function () { 3203 // Shortcuts 3204 var C = CryptoJS; 3205 var C_x64 = C.x64; 3206 var X64Word = C_x64.Word; 3207 var X64WordArray = C_x64.WordArray; 3208 var C_algo = C.algo; 3209 var SHA512 = C_algo.SHA512; 3210 3211 /** 3212 * SHA-384 hash algorithm. 3213 */ 3214 var SHA384 = C_algo.SHA384 = SHA512.extend({ 3215 _doReset: function () { 3216 this._hash = new X64WordArray.init([ 3217 new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507), 3218 new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939), 3219 new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511), 3220 new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4) 3221 ]); 3222 }, 3223 3224 _doFinalize: function () { 3225 var hash = SHA512._doFinalize.call(this); 3226 3227 hash.sigBytes -= 16; 3228 3229 return hash; 3230 } 3231 }); 3232 3233 /** 3234 * Shortcut function to the hasher's object interface. 3235 * 3236 * @param {WordArray|string} message The message to hash. 3237 * 3238 * @return {WordArray} The hash. 3239 * 3240 * @static 3241 * 3242 * @example 3243 * 3244 * var hash = CryptoJS.SHA384('message'); 3245 * var hash = CryptoJS.SHA384(wordArray); 3246 */ 3247 C.SHA384 = SHA512._createHelper(SHA384); 3248 3249 /** 3250 * Shortcut function to the HMAC's object interface. 3251 * 3252 * @param {WordArray|string} message The message to hash. 3253 * @param {WordArray|string} key The secret key. 3254 * 3255 * @return {WordArray} The HMAC. 3256 * 3257 * @static 3258 * 3259 * @example 3260 * 3261 * var hmac = CryptoJS.HmacSHA384(message, key); 3262 */ 3263 C.HmacSHA384 = SHA512._createHmacHelper(SHA384); 3264 }()); 3265 3266 3267 /** 3268 * Cipher core components. 3269 */ 3270 CryptoJS.lib.Cipher || (function (undefined) { 3271 // Shortcuts 3272 var C = CryptoJS; 3273 var C_lib = C.lib; 3274 var Base = C_lib.Base; 3275 var WordArray = C_lib.WordArray; 3276 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm; 3277 var C_enc = C.enc; 3278 var Utf8 = C_enc.Utf8; 3279 var Base64 = C_enc.Base64; 3280 var C_algo = C.algo; 3281 var EvpKDF = C_algo.EvpKDF; 3282 3283 /** 3284 * Abstract base cipher template. 3285 * 3286 * @property {number} keySize This cipher's key size. Default: 4 (128 bits) 3287 * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits) 3288 * @property {number} _ENC_XFORM_MODE A constant representing encryption mode. 3289 * @property {number} _DEC_XFORM_MODE A constant representing decryption mode. 3290 */ 3291 var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({ 3292 /** 3293 * Configuration options. 3294 * 3295 * @property {WordArray} iv The IV to use for this operation. 3296 */ 3297 cfg: Base.extend(), 3298 3299 /** 3300 * Creates this cipher in encryption mode. 3301 * 3302 * @param {WordArray} key The key. 3303 * @param {Object} cfg (Optional) The configuration options to use for this operation. 3304 * 3305 * @return {Cipher} A cipher instance. 3306 * 3307 * @static 3308 * 3309 * @example 3310 * 3311 * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray }); 3312 */ 3313 createEncryptor: function (key, cfg) { 3314 return this.create(this._ENC_XFORM_MODE, key, cfg); 3315 }, 3316 3317 /** 3318 * Creates this cipher in decryption mode. 3319 * 3320 * @param {WordArray} key The key. 3321 * @param {Object} cfg (Optional) The configuration options to use for this operation. 3322 * 3323 * @return {Cipher} A cipher instance. 3324 * 3325 * @static 3326 * 3327 * @example 3328 * 3329 * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray }); 3330 */ 3331 createDecryptor: function (key, cfg) { 3332 return this.create(this._DEC_XFORM_MODE, key, cfg); 3333 }, 3334 3335 /** 3336 * Initializes a newly created cipher. 3337 * 3338 * @param {number} xformMode Either the encryption or decryption transormation mode constant. 3339 * @param {WordArray} key The key. 3340 * @param {Object} cfg (Optional) The configuration options to use for this operation. 3341 * 3342 * @example 3343 * 3344 * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); 3345 */ 3346 init: function (xformMode, key, cfg) { 3347 // Apply config defaults 3348 this.cfg = this.cfg.extend(cfg); 3349 3350 // Store transform mode and key 3351 this._xformMode = xformMode; 3352 this._key = key; 3353 3354 // Set initial values 3355 this.reset(); 3356 }, 3357 3358 /** 3359 * Resets this cipher to its initial state. 3360 * 3361 * @example 3362 * 3363 * cipher.reset(); 3364 */ 3365 reset: function () { 3366 // Reset data buffer 3367 BufferedBlockAlgorithm.reset.call(this); 3368 3369 // Perform concrete-cipher logic 3370 this._doReset(); 3371 }, 3372 3373 /** 3374 * Adds data to be encrypted or decrypted. 3375 * 3376 * @param {WordArray|string} dataUpdate The data to encrypt or decrypt. 3377 * 3378 * @return {WordArray} The data after processing. 3379 * 3380 * @example 3381 * 3382 * var encrypted = cipher.process('data'); 3383 * var encrypted = cipher.process(wordArray);
vendor: 4,485 bytes, lines 3384-3528
3384 */ 3385 process: function (dataUpdate) { 3386 // Append 3387 this._append(dataUpdate); 3388 3389 // Process available blocks 3390 return this._process(); 3391 }, 3392 3393 /** 3394 * Finalizes the encryption or decryption process. 3395 * Note that the finalize operation is effectively a destructive, read-once operation. 3396 * 3397 * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt. 3398 * 3399 * @return {WordArray} The data after final processing. 3400 * 3401 * @example 3402 * 3403 * var encrypted = cipher.finalize(); 3404 * var encrypted = cipher.finalize('data'); 3405 * var encrypted = cipher.finalize(wordArray); 3406 */ 3407 finalize: function (dataUpdate) { 3408 // Final data update 3409 if (dataUpdate) { 3410 this._append(dataUpdate); 3411 } 3412 3413 // Perform concrete-cipher logic 3414 var finalProcessedData = this._doFinalize(); 3415 3416 return finalProcessedData; 3417 }, 3418 3419 keySize: 128/32, 3420 3421 ivSize: 128/32, 3422 3423 _ENC_XFORM_MODE: 1, 3424 3425 _DEC_XFORM_MODE: 2, 3426 3427 /** 3428 * Creates shortcut functions to a cipher's object interface. 3429 * 3430 * @param {Cipher} cipher The cipher to create a helper for. 3431 * 3432 * @return {Object} An object with encrypt and decrypt shortcut functions. 3433 * 3434 * @static 3435 * 3436 * @example 3437 * 3438 * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); 3439 */ 3440 _createHelper: (function () { 3441 function selectCipherStrategy(key) { 3442 if (typeof key == 'string') { 3443 return PasswordBasedCipher; 3444 } else { 3445 return SerializableCipher; 3446 } 3447 } 3448 3449 return function (cipher) { 3450 return { 3451 encrypt: function (message, key, cfg) { 3452 return selectCipherStrategy(key).encrypt(cipher, message, key, cfg); 3453 }, 3454 3455 decrypt: function (ciphertext, key, cfg) { 3456 return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg); 3457 } 3458 }; 3459 }; 3460 }()) 3461 }); 3462 3463 /** 3464 * Abstract base stream cipher template. 3465 * 3466 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits) 3467 */ 3468 var StreamCipher = C_lib.StreamCipher = Cipher.extend({ 3469 _doFinalize: function () { 3470 // Process partial blocks 3471 var finalProcessedBlocks = this._process(!!'flush'); 3472 3473 return finalProcessedBlocks; 3474 }, 3475 3476 blockSize: 1 3477 }); 3478 3479 /** 3480 * Mode namespace. 3481 */ 3482 var C_mode = C.mode = {}; 3483 3484 /** 3485 * Abstract base block cipher mode template. 3486 */ 3487 var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({ 3488 /** 3489 * Creates this mode for encryption. 3490 * 3491 * @param {Cipher} cipher A block cipher instance. 3492 * @param {Array} iv The IV words. 3493 * 3494 * @static 3495 * 3496 * @example 3497 * 3498 * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words); 3499 */ 3500 createEncryptor: function (cipher, iv) { 3501 return this.Encryptor.create(cipher, iv); 3502 }, 3503 3504 /** 3505 * Creates this mode for decryption. 3506 * 3507 * @param {Cipher} cipher A block cipher instance. 3508 * @param {Array} iv The IV words. 3509 * 3510 * @static 3511 * 3512 * @example 3513 * 3514 * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words); 3515 */ 3516 createDecryptor: function (cipher, iv) { 3517 return this.Decryptor.create(cipher, iv); 3518 }, 3519 3520 /** 3521 * Initializes a newly created mode. 3522 * 3523 * @param {Cipher} cipher A block cipher instance. 3524 * @param {Array} iv The IV words. 3525 * 3526 * @example 3527 * 3528 * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
vendor: 12,465 bytes, lines 3529-3898
3529 */ 3530 init: function (cipher, iv) { 3531 this._cipher = cipher; 3532 this._iv = iv; 3533 } 3534 }); 3535 3536 /** 3537 * Cipher Block Chaining mode. 3538 */ 3539 var CBC = C_mode.CBC = (function () { 3540 /** 3541 * Abstract base CBC mode. 3542 */ 3543 var CBC = BlockCipherMode.extend(); 3544 3545 /** 3546 * CBC encryptor. 3547 */ 3548 CBC.Encryptor = CBC.extend({ 3549 /** 3550 * Processes the data block at offset. 3551 * 3552 * @param {Array} words The data words to operate on. 3553 * @param {number} offset The offset where the block starts. 3554 * 3555 * @example 3556 * 3557 * mode.processBlock(data.words, offset); 3558 */ 3559 processBlock: function (words, offset) { 3560 // Shortcuts 3561 var cipher = this._cipher; 3562 var blockSize = cipher.blockSize; 3563 3564 // XOR and encrypt 3565 xorBlock.call(this, words, offset, blockSize); 3566 cipher.encryptBlock(words, offset); 3567 3568 // Remember this block to use with next block 3569 this._prevBlock = words.slice(offset, offset + blockSize); 3570 } 3571 }); 3572 3573 /** 3574 * CBC decryptor. 3575 */ 3576 CBC.Decryptor = CBC.extend({ 3577 /** 3578 * Processes the data block at offset. 3579 * 3580 * @param {Array} words The data words to operate on. 3581 * @param {number} offset The offset where the block starts. 3582 * 3583 * @example 3584 * 3585 * mode.processBlock(data.words, offset); 3586 */ 3587 processBlock: function (words, offset) { 3588 // Shortcuts 3589 var cipher = this._cipher; 3590 var blockSize = cipher.blockSize; 3591 3592 // Remember this block to use with next block 3593 var thisBlock = words.slice(offset, offset + blockSize); 3594 3595 // Decrypt and XOR 3596 cipher.decryptBlock(words, offset); 3597 xorBlock.call(this, words, offset, blockSize); 3598 3599 // This block becomes the previous block 3600 this._prevBlock = thisBlock; 3601 } 3602 }); 3603 3604 function xorBlock(words, offset, blockSize) { 3605 // Shortcut 3606 var iv = this._iv; 3607 3608 // Choose mixing block 3609 if (iv) { 3610 var block = iv; 3611 3612 // Remove IV for subsequent blocks 3613 this._iv = undefined; 3614 } else { 3615 var block = this._prevBlock; 3616 } 3617 3618 // XOR blocks 3619 for (var i = 0; i < blockSize; i++) { 3620 words[offset + i] ^= block[i]; 3621 } 3622 } 3623 3624 return CBC; 3625 }()); 3626 3627 /** 3628 * Padding namespace. 3629 */ 3630 var C_pad = C.pad = {}; 3631 3632 /** 3633 * PKCS #5/7 padding strategy. 3634 */ 3635 var Pkcs7 = C_pad.Pkcs7 = { 3636 /** 3637 * Pads data using the algorithm defined in PKCS #5/7. 3638 * 3639 * @param {WordArray} data The data to pad. 3640 * @param {number} blockSize The multiple that the data should be padded to. 3641 * 3642 * @static 3643 * 3644 * @example 3645 * 3646 * CryptoJS.pad.Pkcs7.pad(wordArray, 4); 3647 */ 3648 pad: function (data, blockSize) { 3649 // Shortcut 3650 var blockSizeBytes = blockSize * 4; 3651 3652 // Count padding bytes 3653 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 3654 3655 // Create padding word 3656 var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes; 3657 3658 // Create padding 3659 var paddingWords = []; 3660 for (var i = 0; i < nPaddingBytes; i += 4) { 3661 paddingWords.push(paddingWord); 3662 } 3663 var padding = WordArray.create(paddingWords, nPaddingBytes); 3664 3665 // Add padding 3666 data.concat(padding); 3667 }, 3668 3669 /** 3670 * Unpads data that had been padded using the algorithm defined in PKCS #5/7. 3671 * 3672 * @param {WordArray} data The data to unpad. 3673 * 3674 * @static 3675 * 3676 * @example 3677 * 3678 * CryptoJS.pad.Pkcs7.unpad(wordArray); 3679 */ 3680 unpad: function (data) { 3681 // Get number of padding bytes from last byte 3682 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 3683 3684 // Remove padding 3685 data.sigBytes -= nPaddingBytes; 3686 } 3687 }; 3688 3689 /** 3690 * Abstract base block cipher template. 3691 * 3692 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits) 3693 */ 3694 var BlockCipher = C_lib.BlockCipher = Cipher.extend({ 3695 /** 3696 * Configuration options. 3697 * 3698 * @property {Mode} mode The block mode to use. Default: CBC 3699 * @property {Padding} padding The padding strategy to use. Default: Pkcs7 3700 */ 3701 cfg: Cipher.cfg.extend({ 3702 mode: CBC, 3703 padding: Pkcs7 3704 }), 3705 3706 reset: function () { 3707 // Reset cipher 3708 Cipher.reset.call(this); 3709 3710 // Shortcuts 3711 var cfg = this.cfg; 3712 var iv = cfg.iv; 3713 var mode = cfg.mode; 3714 3715 // Reset block mode 3716 if (this._xformMode == this._ENC_XFORM_MODE) { 3717 var modeCreator = mode.createEncryptor; 3718 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 3719 var modeCreator = mode.createDecryptor; 3720 // Keep at least one block in the buffer for unpadding 3721 this._minBufferSize = 1; 3722 } 3723 3724 if (this._mode && this._mode.__creator == modeCreator) { 3725 this._mode.init(this, iv && iv.words); 3726 } else { 3727 this._mode = modeCreator.call(mode, this, iv && iv.words); 3728 this._mode.__creator = modeCreator; 3729 } 3730 }, 3731 3732 _doProcessBlock: function (words, offset) { 3733 this._mode.processBlock(words, offset); 3734 }, 3735 3736 _doFinalize: function () { 3737 // Shortcut 3738 var padding = this.cfg.padding; 3739 3740 // Finalize 3741 if (this._xformMode == this._ENC_XFORM_MODE) { 3742 // Pad data 3743 padding.pad(this._data, this.blockSize); 3744 3745 // Process final blocks 3746 var finalProcessedBlocks = this._process(!!'flush'); 3747 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 3748 // Process final blocks 3749 var finalProcessedBlocks = this._process(!!'flush'); 3750 3751 // Unpad data 3752 padding.unpad(finalProcessedBlocks); 3753 } 3754 3755 return finalProcessedBlocks; 3756 }, 3757 3758 blockSize: 128/32 3759 }); 3760 3761 /** 3762 * A collection of cipher parameters. 3763 * 3764 * @property {WordArray} ciphertext The raw ciphertext. 3765 * @property {WordArray} key The key to this ciphertext. 3766 * @property {WordArray} iv The IV used in the ciphering operation. 3767 * @property {WordArray} salt The salt used with a key derivation function. 3768 * @property {Cipher} algorithm The cipher algorithm. 3769 * @property {Mode} mode The block mode used in the ciphering operation. 3770 * @property {Padding} padding The padding scheme used in the ciphering operation. 3771 * @property {number} blockSize The block size of the cipher. 3772 * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string. 3773 */ 3774 var CipherParams = C_lib.CipherParams = Base.extend({ 3775 /** 3776 * Initializes a newly created cipher params object. 3777 * 3778 * @param {Object} cipherParams An object with any of the possible cipher parameters. 3779 * 3780 * @example 3781 * 3782 * var cipherParams = CryptoJS.lib.CipherParams.create({ 3783 * ciphertext: ciphertextWordArray, 3784 * key: keyWordArray, 3785 * iv: ivWordArray, 3786 * salt: saltWordArray, 3787 * algorithm: CryptoJS.algo.AES, 3788 * mode: CryptoJS.mode.CBC, 3789 * padding: CryptoJS.pad.PKCS7, 3790 * blockSize: 4, 3791 * formatter: CryptoJS.format.OpenSSL 3792 * }); 3793 */ 3794 init: function (cipherParams) { 3795 this.mixIn(cipherParams); 3796 }, 3797 3798 /** 3799 * Converts this cipher params object to a string. 3800 * 3801 * @param {Format} formatter (Optional) The formatting strategy to use. 3802 * 3803 * @return {string} The stringified cipher params. 3804 * 3805 * @throws Error If neither the formatter nor the default formatter is set. 3806 * 3807 * @example 3808 * 3809 * var string = cipherParams + ''; 3810 * var string = cipherParams.toString(); 3811 * var string = cipherParams.toString(CryptoJS.format.OpenSSL); 3812 */ 3813 toString: function (formatter) { 3814 return (formatter || this.formatter).stringify(this); 3815 } 3816 }); 3817 3818 /** 3819 * Format namespace. 3820 */ 3821 var C_format = C.format = {}; 3822 3823 /** 3824 * OpenSSL formatting strategy. 3825 */ 3826 var OpenSSLFormatter = C_format.OpenSSL = { 3827 /** 3828 * Converts a cipher params object to an OpenSSL-compatible string. 3829 * 3830 * @param {CipherParams} cipherParams The cipher params object. 3831 * 3832 * @return {string} The OpenSSL-compatible string. 3833 * 3834 * @static 3835 * 3836 * @example 3837 * 3838 * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); 3839 */ 3840 stringify: function (cipherParams) { 3841 // Shortcuts 3842 var ciphertext = cipherParams.ciphertext; 3843 var salt = cipherParams.salt; 3844 3845 // Format 3846 if (salt) { 3847 var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext); 3848 } else { 3849 var wordArray = ciphertext; 3850 } 3851 3852 return wordArray.toString(Base64); 3853 }, 3854 3855 /** 3856 * Converts an OpenSSL-compatible string to a cipher params object. 3857 * 3858 * @param {string} openSSLStr The OpenSSL-compatible string. 3859 * 3860 * @return {CipherParams} The cipher params object. 3861 * 3862 * @static 3863 * 3864 * @example 3865 * 3866 * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); 3867 */ 3868 parse: function (openSSLStr) { 3869 // Parse base64 3870 var ciphertext = Base64.parse(openSSLStr); 3871 3872 // Shortcut 3873 var ciphertextWords = ciphertext.words; 3874 3875 // Test for salt 3876 if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) { 3877 // Extract salt 3878 var salt = WordArray.create(ciphertextWords.slice(2, 4)); 3879 3880 // Remove salt from ciphertext 3881 ciphertextWords.splice(0, 4); 3882 ciphertext.sigBytes -= 16; 3883 } 3884 3885 return CipherParams.create({ ciphertext: ciphertext, salt: salt }); 3886 } 3887 }; 3888 3889 /** 3890 * A cipher wrapper that returns ciphertext as a serializable cipher params object. 3891 */ 3892 var SerializableCipher = C_lib.SerializableCipher = Base.extend({ 3893 /** 3894 * Configuration options. 3895 * 3896 * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL 3897 */ 3898 cfg: Base.extend({
vendor: 5,188 bytes, lines 3899-4030
3899 format: OpenSSLFormatter 3900 }), 3901 3902 /** 3903 * Encrypts a message. 3904 * 3905 * @param {Cipher} cipher The cipher algorithm to use. 3906 * @param {WordArray|string} message The message to encrypt. 3907 * @param {WordArray} key The key. 3908 * @param {Object} cfg (Optional) The configuration options to use for this operation. 3909 * 3910 * @return {CipherParams} A cipher params object. 3911 * 3912 * @static 3913 * 3914 * @example 3915 * 3916 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); 3917 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); 3918 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 3919 */ 3920 encrypt: function (cipher, message, key, cfg) { 3921 // Apply config defaults 3922 cfg = this.cfg.extend(cfg); 3923 3924 // Encrypt 3925 var encryptor = cipher.createEncryptor(key, cfg); 3926 var ciphertext = encryptor.finalize(message); 3927 3928 // Shortcut 3929 var cipherCfg = encryptor.cfg; 3930 3931 // Create and return serializable cipher params 3932 return CipherParams.create({ 3933 ciphertext: ciphertext, 3934 key: key, 3935 iv: cipherCfg.iv, 3936 algorithm: cipher, 3937 mode: cipherCfg.mode, 3938 padding: cipherCfg.padding, 3939 blockSize: cipher.blockSize, 3940 formatter: cfg.format 3941 }); 3942 }, 3943 3944 /** 3945 * Decrypts serialized ciphertext. 3946 * 3947 * @param {Cipher} cipher The cipher algorithm to use. 3948 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 3949 * @param {WordArray} key The key. 3950 * @param {Object} cfg (Optional) The configuration options to use for this operation. 3951 * 3952 * @return {WordArray} The plaintext. 3953 * 3954 * @static 3955 * 3956 * @example 3957 * 3958 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 3959 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 3960 */ 3961 decrypt: function (cipher, ciphertext, key, cfg) { 3962 // Apply config defaults 3963 cfg = this.cfg.extend(cfg); 3964 3965 // Convert string to CipherParams 3966 ciphertext = this._parse(ciphertext, cfg.format); 3967 3968 // Decrypt 3969 var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext); 3970 3971 return plaintext; 3972 }, 3973 3974 /** 3975 * Converts serialized ciphertext to CipherParams, 3976 * else assumed CipherParams already and returns ciphertext unchanged. 3977 * 3978 * @param {CipherParams|string} ciphertext The ciphertext. 3979 * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext. 3980 * 3981 * @return {CipherParams} The unserialized ciphertext. 3982 * 3983 * @static 3984 * 3985 * @example 3986 * 3987 * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); 3988 */ 3989 _parse: function (ciphertext, format) { 3990 if (typeof ciphertext == 'string') { 3991 return format.parse(ciphertext, this); 3992 } else { 3993 return ciphertext; 3994 } 3995 } 3996 }); 3997 3998 /** 3999 * Key derivation function namespace. 4000 */ 4001 var C_kdf = C.kdf = {}; 4002 4003 /** 4004 * OpenSSL key derivation function. 4005 */ 4006 var OpenSSLKdf = C_kdf.OpenSSL = { 4007 /** 4008 * Derives a key and IV from a password. 4009 * 4010 * @param {string} password The password to derive from. 4011 * @param {number} keySize The size in words of the key to generate. 4012 * @param {number} ivSize The size in words of the IV to generate. 4013 * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. 4014 * 4015 * @return {CipherParams} A cipher params object with the key, IV, and salt. 4016 * 4017 * @static 4018 * 4019 * @example 4020 * 4021 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32); 4022 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); 4023 */ 4024 execute: function (password, keySize, ivSize, salt) { 4025 // Generate random salt 4026 if (!salt) { 4027 salt = WordArray.random(64/8); 4028 } 4029 4030 // Derive key and IV
vendor: 6,869 bytes, lines 4031-4234
4031 var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt); 4032 4033 // Separate key and IV 4034 var iv = WordArray.create(key.words.slice(keySize), ivSize * 4); 4035 key.sigBytes = keySize * 4; 4036 4037 // Return params 4038 return CipherParams.create({ key: key, iv: iv, salt: salt }); 4039 } 4040 }; 4041 4042 /** 4043 * A serializable cipher wrapper that derives the key from a password, 4044 * and returns ciphertext as a serializable cipher params object. 4045 */ 4046 var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({ 4047 /** 4048 * Configuration options. 4049 * 4050 * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL 4051 */ 4052 cfg: SerializableCipher.cfg.extend({ 4053 kdf: OpenSSLKdf 4054 }), 4055 4056 /** 4057 * Encrypts a message using a password. 4058 * 4059 * @param {Cipher} cipher The cipher algorithm to use. 4060 * @param {WordArray|string} message The message to encrypt. 4061 * @param {string} password The password. 4062 * @param {Object} cfg (Optional) The configuration options to use for this operation. 4063 * 4064 * @return {CipherParams} A cipher params object. 4065 * 4066 * @static 4067 * 4068 * @example 4069 * 4070 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password'); 4071 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL }); 4072 */ 4073 encrypt: function (cipher, message, password, cfg) { 4074 // Apply config defaults 4075 cfg = this.cfg.extend(cfg); 4076 4077 // Derive key and other params 4078 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize); 4079 4080 // Add IV to config 4081 cfg.iv = derivedParams.iv; 4082 4083 // Encrypt 4084 var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg); 4085 4086 // Mix in derived params 4087 ciphertext.mixIn(derivedParams); 4088 4089 return ciphertext; 4090 }, 4091 4092 /** 4093 * Decrypts serialized ciphertext using a password. 4094 * 4095 * @param {Cipher} cipher The cipher algorithm to use. 4096 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 4097 * @param {string} password The password. 4098 * @param {Object} cfg (Optional) The configuration options to use for this operation. 4099 * 4100 * @return {WordArray} The plaintext. 4101 * 4102 * @static 4103 * 4104 * @example 4105 * 4106 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL }); 4107 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL }); 4108 */ 4109 decrypt: function (cipher, ciphertext, password, cfg) { 4110 // Apply config defaults 4111 cfg = this.cfg.extend(cfg); 4112 4113 // Convert string to CipherParams 4114 ciphertext = this._parse(ciphertext, cfg.format); 4115 4116 // Derive key and other params 4117 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt); 4118 4119 // Add IV to config 4120 cfg.iv = derivedParams.iv; 4121 4122 // Decrypt 4123 var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg); 4124 4125 return plaintext; 4126 } 4127 }); 4128 }()); 4129 4130 4131 /** 4132 * Cipher Feedback block mode. 4133 */ 4134 CryptoJS.mode.CFB = (function () { 4135 var CFB = CryptoJS.lib.BlockCipherMode.extend(); 4136 4137 CFB.Encryptor = CFB.extend({ 4138 processBlock: function (words, offset) { 4139 // Shortcuts 4140 var cipher = this._cipher; 4141 var blockSize = cipher.blockSize; 4142 4143 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 4144 4145 // Remember this block to use with next block 4146 this._prevBlock = words.slice(offset, offset + blockSize); 4147 } 4148 }); 4149 4150 CFB.Decryptor = CFB.extend({ 4151 processBlock: function (words, offset) { 4152 // Shortcuts 4153 var cipher = this._cipher; 4154 var blockSize = cipher.blockSize; 4155 4156 // Remember this block to use with next block 4157 var thisBlock = words.slice(offset, offset + blockSize); 4158 4159 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 4160 4161 // This block becomes the previous block 4162 this._prevBlock = thisBlock; 4163 } 4164 }); 4165 4166 function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { 4167 // Shortcut 4168 var iv = this._iv; 4169 4170 // Generate keystream 4171 if (iv) { 4172 var keystream = iv.slice(0); 4173 4174 // Remove IV for subsequent blocks 4175 this._iv = undefined; 4176 } else { 4177 var keystream = this._prevBlock; 4178 } 4179 cipher.encryptBlock(keystream, 0); 4180 4181 // Encrypt 4182 for (var i = 0; i < blockSize; i++) { 4183 words[offset + i] ^= keystream[i]; 4184 } 4185 } 4186 4187 return CFB; 4188 }()); 4189 4190 4191 /** 4192 * Electronic Codebook block mode. 4193 */ 4194 CryptoJS.mode.ECB = (function () { 4195 var ECB = CryptoJS.lib.BlockCipherMode.extend(); 4196 4197 ECB.Encryptor = ECB.extend({ 4198 processBlock: function (words, offset) { 4199 this._cipher.encryptBlock(words, offset); 4200 } 4201 }); 4202 4203 ECB.Decryptor = ECB.extend({ 4204 processBlock: function (words, offset) { 4205 this._cipher.decryptBlock(words, offset); 4206 } 4207 }); 4208 4209 return ECB; 4210 }()); 4211 4212 4213 /** 4214 * ANSI X.923 padding strategy. 4215 */ 4216 CryptoJS.pad.AnsiX923 = { 4217 pad: function (data, blockSize) { 4218 // Shortcuts 4219 var dataSigBytes = data.sigBytes; 4220 var blockSizeBytes = blockSize * 4; 4221 4222 // Count padding bytes 4223 var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes; 4224 4225 // Compute last byte position 4226 var lastBytePos = dataSigBytes + nPaddingBytes - 1; 4227 4228 // Pad 4229 data.clamp(); 4230 data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8); 4231 data.sigBytes += nPaddingBytes; 4232 }, 4233 4234 unpad: function (data) {
vendor: 6,752 bytes, lines 4235-4473
4235 // Get number of padding bytes from last byte 4236 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 4237 4238 // Remove padding 4239 data.sigBytes -= nPaddingBytes; 4240 } 4241 }; 4242 4243 4244 /** 4245 * ISO 10126 padding strategy. 4246 */ 4247 CryptoJS.pad.Iso10126 = { 4248 pad: function (data, blockSize) { 4249 // Shortcut 4250 var blockSizeBytes = blockSize * 4; 4251 4252 // Count padding bytes 4253 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 4254 4255 // Pad 4256 data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)). 4257 concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1)); 4258 }, 4259 4260 unpad: function (data) { 4261 // Get number of padding bytes from last byte 4262 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 4263 4264 // Remove padding 4265 data.sigBytes -= nPaddingBytes; 4266 } 4267 }; 4268 4269 4270 /** 4271 * ISO/IEC 9797-1 Padding Method 2. 4272 */ 4273 CryptoJS.pad.Iso97971 = { 4274 pad: function (data, blockSize) { 4275 // Add 0x80 byte 4276 data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1)); 4277 4278 // Zero pad the rest 4279 CryptoJS.pad.ZeroPadding.pad(data, blockSize); 4280 }, 4281 4282 unpad: function (data) { 4283 // Remove zero padding 4284 CryptoJS.pad.ZeroPadding.unpad(data); 4285 4286 // Remove one more byte -- the 0x80 byte 4287 data.sigBytes--; 4288 } 4289 }; 4290 4291 4292 /** 4293 * Output Feedback block mode. 4294 */ 4295 CryptoJS.mode.OFB = (function () { 4296 var OFB = CryptoJS.lib.BlockCipherMode.extend(); 4297 4298 var Encryptor = OFB.Encryptor = OFB.extend({ 4299 processBlock: function (words, offset) { 4300 // Shortcuts 4301 var cipher = this._cipher 4302 var blockSize = cipher.blockSize; 4303 var iv = this._iv; 4304 var keystream = this._keystream; 4305 4306 // Generate keystream 4307 if (iv) { 4308 keystream = this._keystream = iv.slice(0); 4309 4310 // Remove IV for subsequent blocks 4311 this._iv = undefined; 4312 } 4313 cipher.encryptBlock(keystream, 0); 4314 4315 // Encrypt 4316 for (var i = 0; i < blockSize; i++) { 4317 words[offset + i] ^= keystream[i]; 4318 } 4319 } 4320 }); 4321 4322 OFB.Decryptor = Encryptor; 4323 4324 return OFB; 4325 }()); 4326 4327 4328 /** 4329 * A noop padding strategy. 4330 */ 4331 CryptoJS.pad.NoPadding = { 4332 pad: function () { 4333 }, 4334 4335 unpad: function () { 4336 } 4337 }; 4338 4339 4340 (function (undefined) { 4341 // Shortcuts 4342 var C = CryptoJS; 4343 var C_lib = C.lib; 4344 var CipherParams = C_lib.CipherParams; 4345 var C_enc = C.enc; 4346 var Hex = C_enc.Hex; 4347 var C_format = C.format; 4348 4349 var HexFormatter = C_format.Hex = { 4350 /** 4351 * Converts the ciphertext of a cipher params object to a hexadecimally encoded string. 4352 * 4353 * @param {CipherParams} cipherParams The cipher params object. 4354 * 4355 * @return {string} The hexadecimally encoded string. 4356 * 4357 * @static 4358 * 4359 * @example 4360 * 4361 * var hexString = CryptoJS.format.Hex.stringify(cipherParams); 4362 */ 4363 stringify: function (cipherParams) { 4364 return cipherParams.ciphertext.toString(Hex); 4365 }, 4366 4367 /** 4368 * Converts a hexadecimally encoded ciphertext string to a cipher params object. 4369 * 4370 * @param {string} input The hexadecimally encoded string. 4371 * 4372 * @return {CipherParams} The cipher params object. 4373 * 4374 * @static 4375 * 4376 * @example 4377 * 4378 * var cipherParams = CryptoJS.format.Hex.parse(hexString); 4379 */ 4380 parse: function (input) { 4381 var ciphertext = Hex.parse(input); 4382 return CipherParams.create({ ciphertext: ciphertext }); 4383 } 4384 }; 4385 }()); 4386 4387 4388 (function () { 4389 // Shortcuts 4390 var C = CryptoJS; 4391 var C_lib = C.lib; 4392 var BlockCipher = C_lib.BlockCipher; 4393 var C_algo = C.algo; 4394 4395 // Lookup tables 4396 var SBOX = []; 4397 var INV_SBOX = []; 4398 var SUB_MIX_0 = []; 4399 var SUB_MIX_1 = []; 4400 var SUB_MIX_2 = []; 4401 var SUB_MIX_3 = []; 4402 var INV_SUB_MIX_0 = []; 4403 var INV_SUB_MIX_1 = []; 4404 var INV_SUB_MIX_2 = []; 4405 var INV_SUB_MIX_3 = []; 4406 4407 // Compute lookup tables 4408 (function () { 4409 // Compute double table 4410 var d = []; 4411 for (var i = 0; i < 256; i++) { 4412 if (i < 128) { 4413 d[i] = i << 1; 4414 } else { 4415 d[i] = (i << 1) ^ 0x11b; 4416 } 4417 } 4418 4419 // Walk GF(2^8) 4420 var x = 0; 4421 var xi = 0; 4422 for (var i = 0; i < 256; i++) { 4423 // Compute sbox 4424 var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4); 4425 sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63; 4426 SBOX[x] = sx; 4427 INV_SBOX[sx] = x; 4428 4429 // Compute multiplication 4430 var x2 = d[x]; 4431 var x4 = d[x2]; 4432 var x8 = d[x4]; 4433 4434 // Compute sub bytes, mix columns tables 4435 var t = (d[sx] * 0x101) ^ (sx * 0x1010100); 4436 SUB_MIX_0[x] = (t << 24) | (t >>> 8); 4437 SUB_MIX_1[x] = (t << 16) | (t >>> 16); 4438 SUB_MIX_2[x] = (t << 8) | (t >>> 24); 4439 SUB_MIX_3[x] = t; 4440 4441 // Compute inv sub bytes, inv mix columns tables 4442 var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100); 4443 INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8); 4444 INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16); 4445 INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24); 4446 INV_SUB_MIX_3[sx] = t; 4447 4448 // Compute next counter 4449 if (!x) { 4450 x = xi = 1; 4451 } else { 4452 x = x2 ^ d[d[d[x8 ^ x2]]]; 4453 xi ^= d[d[xi]]; 4454 } 4455 } 4456 }()); 4457 4458 // Precomputed Rcon lookup 4459 var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]; 4460 4461 /** 4462 * AES block cipher algorithm. 4463 */ 4464 var AES = C_algo.AES = BlockCipher.extend({ 4465 _doReset: function () { 4466 // Skip reset of nRounds has been set before and key did not change 4467 if (this._nRounds && this._keyPriorReset === this._key) { 4468 return; 4469 } 4470 4471 // Shortcuts 4472 var key = this._keyPriorReset = this._key; 4473 var keyWords = key.words;
vendor: 3,067 bytes, lines 4474-4547
4474 var keySize = key.sigBytes / 4; 4475 4476 // Compute number of rounds 4477 var nRounds = this._nRounds = keySize + 6; 4478 4479 // Compute number of key schedule rows 4480 var ksRows = (nRounds + 1) * 4; 4481 4482 // Compute key schedule 4483 var keySchedule = this._keySchedule = []; 4484 for (var ksRow = 0; ksRow < ksRows; ksRow++) { 4485 if (ksRow < keySize) { 4486 keySchedule[ksRow] = keyWords[ksRow]; 4487 } else { 4488 var t = keySchedule[ksRow - 1]; 4489 4490 if (!(ksRow % keySize)) { 4491 // Rot word 4492 t = (t << 8) | (t >>> 24); 4493 4494 // Sub word 4495 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 4496 4497 // Mix Rcon 4498 t ^= RCON[(ksRow / keySize) | 0] << 24; 4499 } else if (keySize > 6 && ksRow % keySize == 4) { 4500 // Sub word 4501 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 4502 } 4503 4504 keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t; 4505 } 4506 } 4507 4508 // Compute inv key schedule 4509 var invKeySchedule = this._invKeySchedule = []; 4510 for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) { 4511 var ksRow = ksRows - invKsRow; 4512 4513 if (invKsRow % 4) { 4514 var t = keySchedule[ksRow]; 4515 } else { 4516 var t = keySchedule[ksRow - 4]; 4517 } 4518 4519 if (invKsRow < 4 || ksRow <= 4) { 4520 invKeySchedule[invKsRow] = t; 4521 } else { 4522 invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ 4523 INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]]; 4524 } 4525 } 4526 }, 4527 4528 encryptBlock: function (M, offset) { 4529 this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX); 4530 }, 4531 4532 decryptBlock: function (M, offset) { 4533 // Swap 2nd and 4th rows 4534 var t = M[offset + 1]; 4535 M[offset + 1] = M[offset + 3]; 4536 M[offset + 3] = t; 4537 4538 this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX); 4539 4540 // Inv swap 2nd and 4th rows 4541 var t = M[offset + 1]; 4542 M[offset + 1] = M[offset + 3]; 4543 M[offset + 3] = t; 4544 }, 4545 4546 _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) { 4547 // Shortcut
vendor: 15,268 bytes, lines 4548-4988
4548 var nRounds = this._nRounds; 4549 4550 // Get input, add round key 4551 var s0 = M[offset] ^ keySchedule[0]; 4552 var s1 = M[offset + 1] ^ keySchedule[1]; 4553 var s2 = M[offset + 2] ^ keySchedule[2]; 4554 var s3 = M[offset + 3] ^ keySchedule[3]; 4555 4556 // Key schedule row counter 4557 var ksRow = 4; 4558 4559 // Rounds 4560 for (var round = 1; round < nRounds; round++) { 4561 // Shift rows, sub bytes, mix columns, add round key 4562 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++]; 4563 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++]; 4564 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++]; 4565 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++]; 4566 4567 // Update state 4568 s0 = t0; 4569 s1 = t1; 4570 s2 = t2; 4571 s3 = t3; 4572 } 4573 4574 // Shift rows, sub bytes, add round key 4575 var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]; 4576 var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]; 4577 var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]; 4578 var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]; 4579 4580 // Set output 4581 M[offset] = t0; 4582 M[offset + 1] = t1; 4583 M[offset + 2] = t2; 4584 M[offset + 3] = t3; 4585 }, 4586 4587 keySize: 256/32 4588 }); 4589 4590 /** 4591 * Shortcut functions to the cipher's object interface. 4592 * 4593 * @example 4594 * 4595 * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg); 4596 * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg); 4597 */ 4598 C.AES = BlockCipher._createHelper(AES); 4599 }()); 4600 4601 4602 (function () { 4603 // Shortcuts 4604 var C = CryptoJS; 4605 var C_lib = C.lib; 4606 var WordArray = C_lib.WordArray; 4607 var BlockCipher = C_lib.BlockCipher; 4608 var C_algo = C.algo; 4609 4610 // Permuted Choice 1 constants 4611 var PC1 = [ 4612 57, 49, 41, 33, 25, 17, 9, 1, 4613 58, 50, 42, 34, 26, 18, 10, 2, 4614 59, 51, 43, 35, 27, 19, 11, 3, 4615 60, 52, 44, 36, 63, 55, 47, 39, 4616 31, 23, 15, 7, 62, 54, 46, 38, 4617 30, 22, 14, 6, 61, 53, 45, 37, 4618 29, 21, 13, 5, 28, 20, 12, 4 4619 ]; 4620 4621 // Permuted Choice 2 constants 4622 var PC2 = [ 4623 14, 17, 11, 24, 1, 5, 4624 3, 28, 15, 6, 21, 10, 4625 23, 19, 12, 4, 26, 8, 4626 16, 7, 27, 20, 13, 2, 4627 41, 52, 31, 37, 47, 55, 4628 30, 40, 51, 45, 33, 48, 4629 44, 49, 39, 56, 34, 53, 4630 46, 42, 50, 36, 29, 32 4631 ]; 4632 4633 // Cumulative bit shift constants 4634 var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; 4635 4636 // SBOXes and round permutation constants 4637 var SBOX_P = [ 4638 { 4639 0x0: 0x808200, 4640 0x10000000: 0x8000, 4641 0x20000000: 0x808002, 4642 0x30000000: 0x2, 4643 0x40000000: 0x200, 4644 0x50000000: 0x808202, 4645 0x60000000: 0x800202, 4646 0x70000000: 0x800000, 4647 0x80000000: 0x202, 4648 0x90000000: 0x800200, 4649 0xa0000000: 0x8200, 4650 0xb0000000: 0x808000, 4651 0xc0000000: 0x8002, 4652 0xd0000000: 0x800002, 4653 0xe0000000: 0x0, 4654 0xf0000000: 0x8202, 4655 0x8000000: 0x0, 4656 0x18000000: 0x808202, 4657 0x28000000: 0x8202, 4658 0x38000000: 0x8000, 4659 0x48000000: 0x808200, 4660 0x58000000: 0x200, 4661 0x68000000: 0x808002, 4662 0x78000000: 0x2, 4663 0x88000000: 0x800200, 4664 0x98000000: 0x8200, 4665 0xa8000000: 0x808000, 4666 0xb8000000: 0x800202, 4667 0xc8000000: 0x800002, 4668 0xd8000000: 0x8002, 4669 0xe8000000: 0x202, 4670 0xf8000000: 0x800000, 4671 0x1: 0x8000, 4672 0x10000001: 0x2, 4673 0x20000001: 0x808200, 4674 0x30000001: 0x800000, 4675 0x40000001: 0x808002, 4676 0x50000001: 0x8200, 4677 0x60000001: 0x200, 4678 0x70000001: 0x800202, 4679 0x80000001: 0x808202, 4680 0x90000001: 0x808000, 4681 0xa0000001: 0x800002, 4682 0xb0000001: 0x8202, 4683 0xc0000001: 0x202, 4684 0xd0000001: 0x800200, 4685 0xe0000001: 0x8002, 4686 0xf0000001: 0x0, 4687 0x8000001: 0x808202, 4688 0x18000001: 0x808000, 4689 0x28000001: 0x800000, 4690 0x38000001: 0x200, 4691 0x48000001: 0x8000, 4692 0x58000001: 0x800002, 4693 0x68000001: 0x2, 4694 0x78000001: 0x8202, 4695 0x88000001: 0x8002, 4696 0x98000001: 0x800202, 4697 0xa8000001: 0x202, 4698 0xb8000001: 0x808200, 4699 0xc8000001: 0x800200, 4700 0xd8000001: 0x0, 4701 0xe8000001: 0x8200, 4702 0xf8000001: 0x808002 4703 }, 4704 { 4705 0x0: 0x40084010, 4706 0x1000000: 0x4000, 4707 0x2000000: 0x80000, 4708 0x3000000: 0x40080010, 4709 0x4000000: 0x40000010, 4710 0x5000000: 0x40084000, 4711 0x6000000: 0x40004000, 4712 0x7000000: 0x10, 4713 0x8000000: 0x84000, 4714 0x9000000: 0x40004010, 4715 0xa000000: 0x40000000, 4716 0xb000000: 0x84010, 4717 0xc000000: 0x80010, 4718 0xd000000: 0x0, 4719 0xe000000: 0x4010, 4720 0xf000000: 0x40080000, 4721 0x800000: 0x40004000, 4722 0x1800000: 0x84010, 4723 0x2800000: 0x10, 4724 0x3800000: 0x40004010, 4725 0x4800000: 0x40084010, 4726 0x5800000: 0x40000000, 4727 0x6800000: 0x80000, 4728 0x7800000: 0x40080010, 4729 0x8800000: 0x80010, 4730 0x9800000: 0x0, 4731 0xa800000: 0x4000, 4732 0xb800000: 0x40080000, 4733 0xc800000: 0x40000010, 4734 0xd800000: 0x84000, 4735 0xe800000: 0x40084000, 4736 0xf800000: 0x4010, 4737 0x10000000: 0x0, 4738 0x11000000: 0x40080010, 4739 0x12000000: 0x40004010, 4740 0x13000000: 0x40084000, 4741 0x14000000: 0x40080000, 4742 0x15000000: 0x10, 4743 0x16000000: 0x84010, 4744 0x17000000: 0x4000, 4745 0x18000000: 0x4010, 4746 0x19000000: 0x80000, 4747 0x1a000000: 0x80010, 4748 0x1b000000: 0x40000010, 4749 0x1c000000: 0x84000, 4750 0x1d000000: 0x40004000, 4751 0x1e000000: 0x40000000, 4752 0x1f000000: 0x40084010, 4753 0x10800000: 0x84010, 4754 0x11800000: 0x80000, 4755 0x12800000: 0x40080000, 4756 0x13800000: 0x4000, 4757 0x14800000: 0x40004000, 4758 0x15800000: 0x40084010, 4759 0x16800000: 0x10, 4760 0x17800000: 0x40000000, 4761 0x18800000: 0x40084000, 4762 0x19800000: 0x40000010, 4763 0x1a800000: 0x40004010, 4764 0x1b800000: 0x80010, 4765 0x1c800000: 0x0, 4766 0x1d800000: 0x4010, 4767 0x1e800000: 0x40080010, 4768 0x1f800000: 0x84000 4769 }, 4770 { 4771 0x0: 0x104, 4772 0x100000: 0x0, 4773 0x200000: 0x4000100, 4774 0x300000: 0x10104, 4775 0x400000: 0x10004, 4776 0x500000: 0x4000004, 4777 0x600000: 0x4010104, 4778 0x700000: 0x4010000, 4779 0x800000: 0x4000000, 4780 0x900000: 0x4010100, 4781 0xa00000: 0x10100, 4782 0xb00000: 0x4010004, 4783 0xc00000: 0x4000104, 4784 0xd00000: 0x10000, 4785 0xe00000: 0x4, 4786 0xf00000: 0x100, 4787 0x80000: 0x4010100, 4788 0x180000: 0x4010004, 4789 0x280000: 0x0, 4790 0x380000: 0x4000100, 4791 0x480000: 0x4000004, 4792 0x580000: 0x10000, 4793 0x680000: 0x10004, 4794 0x780000: 0x104, 4795 0x880000: 0x4, 4796 0x980000: 0x100, 4797 0xa80000: 0x4010000, 4798 0xb80000: 0x10104, 4799 0xc80000: 0x10100, 4800 0xd80000: 0x4000104, 4801 0xe80000: 0x4010104, 4802 0xf80000: 0x4000000, 4803 0x1000000: 0x4010100, 4804 0x1100000: 0x10004, 4805 0x1200000: 0x10000, 4806 0x1300000: 0x4000100, 4807 0x1400000: 0x100, 4808 0x1500000: 0x4010104, 4809 0x1600000: 0x4000004, 4810 0x1700000: 0x0, 4811 0x1800000: 0x4000104, 4812 0x1900000: 0x4000000, 4813 0x1a00000: 0x4, 4814 0x1b00000: 0x10100, 4815 0x1c00000: 0x4010000, 4816 0x1d00000: 0x104, 4817 0x1e00000: 0x10104, 4818 0x1f00000: 0x4010004, 4819 0x1080000: 0x4000000, 4820 0x1180000: 0x104, 4821 0x1280000: 0x4010100, 4822 0x1380000: 0x0, 4823 0x1480000: 0x10004, 4824 0x1580000: 0x4000100, 4825 0x1680000: 0x100, 4826 0x1780000: 0x4010004, 4827 0x1880000: 0x10000, 4828 0x1980000: 0x4010104, 4829 0x1a80000: 0x10104, 4830 0x1b80000: 0x4000004, 4831 0x1c80000: 0x4000104, 4832 0x1d80000: 0x4010000, 4833 0x1e80000: 0x4, 4834 0x1f80000: 0x10100 4835 }, 4836 { 4837 0x0: 0x80401000, 4838 0x10000: 0x80001040, 4839 0x20000: 0x401040, 4840 0x30000: 0x80400000, 4841 0x40000: 0x0, 4842 0x50000: 0x401000, 4843 0x60000: 0x80000040, 4844 0x70000: 0x400040, 4845 0x80000: 0x80000000, 4846 0x90000: 0x400000, 4847 0xa0000: 0x40, 4848 0xb0000: 0x80001000, 4849 0xc0000: 0x80400040, 4850 0xd0000: 0x1040, 4851 0xe0000: 0x1000, 4852 0xf0000: 0x80401040, 4853 0x8000: 0x80001040, 4854 0x18000: 0x40, 4855 0x28000: 0x80400040, 4856 0x38000: 0x80001000, 4857 0x48000: 0x401000, 4858 0x58000: 0x80401040, 4859 0x68000: 0x0, 4860 0x78000: 0x80400000, 4861 0x88000: 0x1000, 4862 0x98000: 0x80401000, 4863 0xa8000: 0x400000, 4864 0xb8000: 0x1040, 4865 0xc8000: 0x80000000, 4866 0xd8000: 0x400040, 4867 0xe8000: 0x401040, 4868 0xf8000: 0x80000040, 4869 0x100000: 0x400040, 4870 0x110000: 0x401000, 4871 0x120000: 0x80000040, 4872 0x130000: 0x0, 4873 0x140000: 0x1040, 4874 0x150000: 0x80400040, 4875 0x160000: 0x80401000, 4876 0x170000: 0x80001040, 4877 0x180000: 0x80401040, 4878 0x190000: 0x80000000, 4879 0x1a0000: 0x80400000, 4880 0x1b0000: 0x401040, 4881 0x1c0000: 0x80001000, 4882 0x1d0000: 0x400000, 4883 0x1e0000: 0x40, 4884 0x1f0000: 0x1000, 4885 0x108000: 0x80400000, 4886 0x118000: 0x80401040, 4887 0x128000: 0x0, 4888 0x138000: 0x401000, 4889 0x148000: 0x400040, 4890 0x158000: 0x80000000, 4891 0x168000: 0x80001040, 4892 0x178000: 0x40, 4893 0x188000: 0x80000040, 4894 0x198000: 0x1000, 4895 0x1a8000: 0x80001000, 4896 0x1b8000: 0x80400040, 4897 0x1c8000: 0x1040, 4898 0x1d8000: 0x80401000, 4899 0x1e8000: 0x400000, 4900 0x1f8000: 0x401040 4901 }, 4902 { 4903 0x0: 0x80, 4904 0x1000: 0x1040000, 4905 0x2000: 0x40000, 4906 0x3000: 0x20000000, 4907 0x4000: 0x20040080, 4908 0x5000: 0x1000080, 4909 0x6000: 0x21000080, 4910 0x7000: 0x40080, 4911 0x8000: 0x1000000, 4912 0x9000: 0x20040000, 4913 0xa000: 0x20000080, 4914 0xb000: 0x21040080, 4915 0xc000: 0x21040000, 4916 0xd000: 0x0, 4917 0xe000: 0x1040080, 4918 0xf000: 0x21000000, 4919 0x800: 0x1040080, 4920 0x1800: 0x21000080, 4921 0x2800: 0x80, 4922 0x3800: 0x1040000, 4923 0x4800: 0x40000, 4924 0x5800: 0x20040080, 4925 0x6800: 0x21040000, 4926 0x7800: 0x20000000, 4927 0x8800: 0x20040000, 4928 0x9800: 0x0, 4929 0xa800: 0x21040080, 4930 0xb800: 0x1000080, 4931 0xc800: 0x20000080, 4932 0xd800: 0x21000000, 4933 0xe800: 0x1000000, 4934 0xf800: 0x40080, 4935 0x10000: 0x40000, 4936 0x11000: 0x80, 4937 0x12000: 0x20000000, 4938 0x13000: 0x21000080, 4939 0x14000: 0x1000080, 4940 0x15000: 0x21040000, 4941 0x16000: 0x20040080, 4942 0x17000: 0x1000000, 4943 0x18000: 0x21040080, 4944 0x19000: 0x21000000, 4945 0x1a000: 0x1040000, 4946 0x1b000: 0x20040000, 4947 0x1c000: 0x40080, 4948 0x1d000: 0x20000080, 4949 0x1e000: 0x0, 4950 0x1f000: 0x1040080, 4951 0x10800: 0x21000080, 4952 0x11800: 0x1000000, 4953 0x12800: 0x1040000, 4954 0x13800: 0x20040080, 4955 0x14800: 0x20000000, 4956 0x15800: 0x1040080, 4957 0x16800: 0x80, 4958 0x17800: 0x21040000, 4959 0x18800: 0x40080, 4960 0x19800: 0x21040080, 4961 0x1a800: 0x0, 4962 0x1b800: 0x21000000, 4963 0x1c800: 0x1000080, 4964 0x1d800: 0x40000, 4965 0x1e800: 0x20040000, 4966 0x1f800: 0x20000080 4967 }, 4968 { 4969 0x0: 0x10000008, 4970 0x100: 0x2000, 4971 0x200: 0x10200000, 4972 0x300: 0x10202008, 4973 0x400: 0x10002000, 4974 0x500: 0x200000, 4975 0x600: 0x200008, 4976 0x700: 0x10000000, 4977 0x800: 0x0, 4978 0x900: 0x10002008, 4979 0xa00: 0x202000, 4980 0xb00: 0x8, 4981 0xc00: 0x10200008, 4982 0xd00: 0x202008, 4983 0xe00: 0x2008, 4984 0xf00: 0x10202000, 4985 0x80: 0x10200000, 4986 0x180: 0x10202008, 4987 0x280: 0x8, 4988 0x380: 0x200000,
4989 0x480: 0x202008, 4990 0x580: 0x10000008, 4991 0x680: 0x10002000, 4992 0x780: 0x2008, 4993 0x880: 0x200008, 4994 0x980: 0x2000, 4995 0xa80: 0x10002008, 4996 0xb80: 0x10200008, 4997 0xc80: 0x0, 4998 0xd80: 0x10202000, 4999 0xe80: 0x202000, 5000 0xf80: 0x10000000, 5001 0x1000: 0x10002000, 5002 0x1100: 0x10200008, 5003 0x1200: 0x10202008, 5004 0x1300: 0x2008, 5005 0x1400: 0x200000, 5006 0x1500: 0x10000000, 5007 0x1600: 0x10000008, 5008 0x1700: 0x202000, 5009 0x1800: 0x202008, 5010 0x1900: 0x0, 5011 0x1a00: 0x8, 5012 0x1b00: 0x10200000, 5013 0x1c00: 0x2000, 5014 0x1d00: 0x10002008, 5015 0x1e00: 0x10202000, 5016 0x1f00: 0x200008, 5017 0x1080: 0x8, 5018 0x1180: 0x202000, 5019 0x1280: 0x200000, 5020 0x1380: 0x10000008, 5021 0x1480: 0x10002000, 5022 0x1580: 0x2008, 5023 0x1680: 0x10202008, 5024 0x1780: 0x10200000, 5025 0x1880: 0x10202000, 5026 0x1980: 0x10200008, 5027 0x1a80: 0x2000, 5028 0x1b80: 0x202008, 5029 0x1c80: 0x200008, 5030 0x1d80: 0x0, 5031 0x1e80: 0x10000000, 5032 0x1f80: 0x10002008 5033 }, 5034 { 5035 0x0: 0x100000, 5036 0x10: 0x2000401, 5037 0x20: 0x400, 5038 0x30: 0x100401, 5039 0x40: 0x2100401, 5040 0x50: 0x0, 5041 0x60: 0x1, 5042 0x70: 0x2100001, 5043 0x80: 0x2000400, 5044 0x90: 0x100001, 5045 0xa0: 0x2000001, 5046 0xb0: 0x2100400, 5047 0xc0: 0x2100000, 5048 0xd0: 0x401, 5049 0xe0: 0x100400, 5050 0xf0: 0x2000000, 5051 0x8: 0x2100001, 5052 0x18: 0x0, 5053 0x28: 0x2000401, 5054 0x38: 0x2100400, 5055 0x48: 0x100000, 5056 0x58: 0x2000001, 5057 0x68: 0x2000000, 5058 0x78: 0x401, 5059 0x88: 0x100401, 5060 0x98: 0x2000400, 5061 0xa8: 0x2100000, 5062 0xb8: 0x100001, 5063 0xc8: 0x400, 5064 0xd8: 0x2100401, 5065 0xe8: 0x1, 5066 0xf8: 0x100400, 5067 0x100: 0x2000000, 5068 0x110: 0x100000, 5069 0x120: 0x2000401, 5070 0x130: 0x2100001, 5071 0x140: 0x100001, 5072 0x150: 0x2000400, 5073 0x160: 0x2100400, 5074 0x170: 0x100401, 5075 0x180: 0x401, 5076 0x190: 0x2100401, 5077 0x1a0: 0x100400, 5078 0x1b0: 0x1, 5079 0x1c0: 0x0, 5080 0x1d0: 0x2100000, 5081 0x1e0: 0x2000001, 5082 0x1f0: 0x400, 5083 0x108: 0x100400, 5084 0x118: 0x2000401, 5085 0x128: 0x2100001, 5086 0x138: 0x1, 5087 0x148: 0x2000000, 5088 0x158: 0x100000, 5089 0x168: 0x401, 5090 0x178: 0x2100400, 5091 0x188: 0x2000001, 5092 0x198: 0x2100000, 5093 0x1a8: 0x0, 5094 0x1b8: 0x2100401, 5095 0x1c8: 0x100401, 5096 0x1d8: 0x400, 5097 0x1e8: 0x2000400, 5098 0x1f8: 0x100001 5099 }, 5100 { 5101 0x0: 0x8000820, 5102 0x1: 0x20000, 5103 0x2: 0x8000000, 5104 0x3: 0x20, 5105 0x4: 0x20020, 5106 0x5: 0x8020820, 5107 0x6: 0x8020800, 5108 0x7: 0x800, 5109 0x8: 0x8020000, 5110 0x9: 0x8000800, 5111 0xa: 0x20800, 5112 0xb: 0x8020020, 5113 0xc: 0x820, 5114 0xd: 0x0, 5115 0xe: 0x8000020, 5116 0xf: 0x20820, 5117 0x80000000: 0x800, 5118 0x80000001: 0x8020820, 5119 0x80000002: 0x8000820, 5120 0x80000003: 0x8000000, 5121 0x80000004: 0x8020000, 5122 0x80000005: 0x20800, 5123 0x80000006: 0x20820, 5124 0x80000007: 0x20, 5125 0x80000008: 0x8000020, 5126 0x80000009: 0x820, 5127 0x8000000a: 0x20020, 5128 0x8000000b: 0x8020800, 5129 0x8000000c: 0x0, 5130 0x8000000d: 0x8020020, 5131 0x8000000e: 0x8000800, 5132 0x8000000f: 0x20000, 5133 0x10: 0x20820, 5134 0x11: 0x8020800, 5135 0x12: 0x20, 5136 0x13: 0x800, 5137 0x14: 0x8000800, 5138 0x15: 0x8000020, 5139 0x16: 0x8020020, 5140 0x17: 0x20000, 5141 0x18: 0x0, 5142 0x19: 0x20020, 5143 0x1a: 0x8020000, 5144 0x1b: 0x8000820, 5145 0x1c: 0x8020820,
vendor: 5,433 bytes, lines 5146-5302
5146 0x1d: 0x20800, 5147 0x1e: 0x820, 5148 0x1f: 0x8000000, 5149 0x80000010: 0x20000, 5150 0x80000011: 0x800, 5151 0x80000012: 0x8020020, 5152 0x80000013: 0x20820, 5153 0x80000014: 0x20, 5154 0x80000015: 0x8020000, 5155 0x80000016: 0x8000000, 5156 0x80000017: 0x8000820, 5157 0x80000018: 0x8020820, 5158 0x80000019: 0x8000020, 5159 0x8000001a: 0x8000800, 5160 0x8000001b: 0x0, 5161 0x8000001c: 0x20800, 5162 0x8000001d: 0x820, 5163 0x8000001e: 0x20020, 5164 0x8000001f: 0x8020800 5165 } 5166 ]; 5167 5168 // Masks that select the SBOX input 5169 var SBOX_MASK = [ 5170 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000, 5171 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f 5172 ]; 5173 5174 /** 5175 * DES block cipher algorithm. 5176 */ 5177 var DES = C_algo.DES = BlockCipher.extend({ 5178 _doReset: function () { 5179 // Shortcuts 5180 var key = this._key; 5181 var keyWords = key.words; 5182 5183 // Select 56 bits according to PC1 5184 var keyBits = []; 5185 for (var i = 0; i < 56; i++) { 5186 var keyBitPos = PC1[i] - 1; 5187 keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1; 5188 } 5189 5190 // Assemble 16 subkeys 5191 var subKeys = this._subKeys = []; 5192 for (var nSubKey = 0; nSubKey < 16; nSubKey++) { 5193 // Create subkey 5194 var subKey = subKeys[nSubKey] = []; 5195 5196 // Shortcut 5197 var bitShift = BIT_SHIFTS[nSubKey]; 5198 5199 // Select 48 bits according to PC2 5200 for (var i = 0; i < 24; i++) { 5201 // Select from the left 28 key bits 5202 subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6); 5203 5204 // Select from the right 28 key bits 5205 subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6); 5206 } 5207 5208 // Since each subkey is applied to an expanded 32-bit input, 5209 // the subkey can be broken into 8 values scaled to 32-bits, 5210 // which allows the key to be used without expansion 5211 subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31); 5212 for (var i = 1; i < 7; i++) { 5213 subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3); 5214 } 5215 subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27); 5216 } 5217 5218 // Compute inverse subkeys 5219 var invSubKeys = this._invSubKeys = []; 5220 for (var i = 0; i < 16; i++) { 5221 invSubKeys[i] = subKeys[15 - i]; 5222 } 5223 }, 5224 5225 encryptBlock: function (M, offset) { 5226 this._doCryptBlock(M, offset, this._subKeys); 5227 }, 5228 5229 decryptBlock: function (M, offset) { 5230 this._doCryptBlock(M, offset, this._invSubKeys); 5231 }, 5232 5233 _doCryptBlock: function (M, offset, subKeys) { 5234 // Get input 5235 this._lBlock = M[offset]; 5236 this._rBlock = M[offset + 1]; 5237 5238 // Initial permutation 5239 exchangeLR.call(this, 4, 0x0f0f0f0f); 5240 exchangeLR.call(this, 16, 0x0000ffff); 5241 exchangeRL.call(this, 2, 0x33333333); 5242 exchangeRL.call(this, 8, 0x00ff00ff); 5243 exchangeLR.call(this, 1, 0x55555555); 5244 5245 // Rounds 5246 for (var round = 0; round < 16; round++) { 5247 // Shortcuts 5248 var subKey = subKeys[round]; 5249 var lBlock = this._lBlock; 5250 var rBlock = this._rBlock; 5251 5252 // Feistel function 5253 var f = 0; 5254 for (var i = 0; i < 8; i++) { 5255 f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0]; 5256 } 5257 this._lBlock = rBlock; 5258 this._rBlock = lBlock ^ f; 5259 } 5260 5261 // Undo swap from last round 5262 var t = this._lBlock; 5263 this._lBlock = this._rBlock; 5264 this._rBlock = t; 5265 5266 // Final permutation 5267 exchangeLR.call(this, 1, 0x55555555); 5268 exchangeRL.call(this, 8, 0x00ff00ff); 5269 exchangeRL.call(this, 2, 0x33333333); 5270 exchangeLR.call(this, 16, 0x0000ffff); 5271 exchangeLR.call(this, 4, 0x0f0f0f0f); 5272 5273 // Set output 5274 M[offset] = this._lBlock; 5275 M[offset + 1] = this._rBlock; 5276 }, 5277 5278 keySize: 64/32, 5279 5280 ivSize: 64/32, 5281 5282 blockSize: 64/32 5283 }); 5284 5285 // Swap bits across the left and right words 5286 function exchangeLR(offset, mask) { 5287 var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask; 5288 this._rBlock ^= t; 5289 this._lBlock ^= t << offset; 5290 } 5291 5292 function exchangeRL(offset, mask) { 5293 var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask; 5294 this._lBlock ^= t; 5295 this._rBlock ^= t << offset; 5296 } 5297 5298 /** 5299 * Shortcut functions to the cipher's object interface. 5300 * 5301 * @example 5302 *
vendor: 4,602 bytes, lines 5303-5467
5303 * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg); 5304 * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg); 5305 */ 5306 C.DES = BlockCipher._createHelper(DES); 5307 5308 /** 5309 * Triple-DES block cipher algorithm. 5310 */ 5311 var TripleDES = C_algo.TripleDES = BlockCipher.extend({ 5312 _doReset: function () { 5313 // Shortcuts 5314 var key = this._key; 5315 var keyWords = key.words; 5316 5317 // Create DES instances 5318 this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2))); 5319 this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4))); 5320 this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6))); 5321 }, 5322 5323 encryptBlock: function (M, offset) { 5324 this._des1.encryptBlock(M, offset); 5325 this._des2.decryptBlock(M, offset); 5326 this._des3.encryptBlock(M, offset); 5327 }, 5328 5329 decryptBlock: function (M, offset) { 5330 this._des3.decryptBlock(M, offset); 5331 this._des2.encryptBlock(M, offset); 5332 this._des1.decryptBlock(M, offset); 5333 }, 5334 5335 keySize: 192/32, 5336 5337 ivSize: 64/32, 5338 5339 blockSize: 64/32 5340 }); 5341 5342 /** 5343 * Shortcut functions to the cipher's object interface. 5344 * 5345 * @example 5346 * 5347 * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg); 5348 * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg); 5349 */ 5350 C.TripleDES = BlockCipher._createHelper(TripleDES); 5351 }()); 5352 5353 5354 (function () { 5355 // Shortcuts 5356 var C = CryptoJS; 5357 var C_lib = C.lib; 5358 var StreamCipher = C_lib.StreamCipher; 5359 var C_algo = C.algo; 5360 5361 /** 5362 * RC4 stream cipher algorithm. 5363 */ 5364 var RC4 = C_algo.RC4 = StreamCipher.extend({ 5365 _doReset: function () { 5366 // Shortcuts 5367 var key = this._key; 5368 var keyWords = key.words; 5369 var keySigBytes = key.sigBytes; 5370 5371 // Init sbox 5372 var S = this._S = []; 5373 for (var i = 0; i < 256; i++) { 5374 S[i] = i; 5375 } 5376 5377 // Key setup 5378 for (var i = 0, j = 0; i < 256; i++) { 5379 var keyByteIndex = i % keySigBytes; 5380 var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff; 5381 5382 j = (j + S[i] + keyByte) % 256; 5383 5384 // Swap 5385 var t = S[i]; 5386 S[i] = S[j]; 5387 S[j] = t; 5388 } 5389 5390 // Counters 5391 this._i = this._j = 0; 5392 }, 5393 5394 _doProcessBlock: function (M, offset) { 5395 M[offset] ^= generateKeystreamWord.call(this); 5396 }, 5397 5398 keySize: 256/32, 5399 5400 ivSize: 0 5401 }); 5402 5403 function generateKeystreamWord() { 5404 // Shortcuts 5405 var S = this._S; 5406 var i = this._i; 5407 var j = this._j; 5408 5409 // Generate keystream word 5410 var keystreamWord = 0; 5411 for (var n = 0; n < 4; n++) { 5412 i = (i + 1) % 256; 5413 j = (j + S[i]) % 256; 5414 5415 // Swap 5416 var t = S[i]; 5417 S[i] = S[j]; 5418 S[j] = t; 5419 5420 keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8); 5421 } 5422 5423 // Update counters 5424 this._i = i; 5425 this._j = j; 5426 5427 return keystreamWord; 5428 } 5429 5430 /** 5431 * Shortcut functions to the cipher's object interface. 5432 * 5433 * @example 5434 * 5435 * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg); 5436 * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg); 5437 */ 5438 C.RC4 = StreamCipher._createHelper(RC4); 5439 5440 /** 5441 * Modified RC4 stream cipher algorithm. 5442 */ 5443 var RC4Drop = C_algo.RC4Drop = RC4.extend({ 5444 /** 5445 * Configuration options. 5446 * 5447 * @property {number} drop The number of keystream words to drop. Default 192 5448 */ 5449 cfg: RC4.cfg.extend({ 5450 drop: 192 5451 }), 5452 5453 _doReset: function () { 5454 RC4._doReset.call(this); 5455 5456 // Drop 5457 for (var i = this.cfg.drop; i > 0; i--) { 5458 generateKeystreamWord.call(this); 5459 } 5460 } 5461 }); 5462 5463 /** 5464 * Shortcut functions to the cipher's object interface. 5465 * 5466 * @example 5467 *
vendor: 13,316 bytes, lines 5468-5887
5468 * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg); 5469 * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg); 5470 */ 5471 C.RC4Drop = StreamCipher._createHelper(RC4Drop); 5472 }()); 5473 5474 5475 /** @preserve 5476 * Counter block mode compatible with Dr Brian Gladman fileenc.c 5477 * derived from CryptoJS.mode.CTR 5478 * Jan Hruby [email protected] 5479 */ 5480 CryptoJS.mode.CTRGladman = (function () { 5481 var CTRGladman = CryptoJS.lib.BlockCipherMode.extend(); 5482 5483 function incWord(word) 5484 { 5485 if (((word >> 24) & 0xff) === 0xff) { //overflow 5486 var b1 = (word >> 16)&0xff; 5487 var b2 = (word >> 8)&0xff; 5488 var b3 = word & 0xff; 5489 5490 if (b1 === 0xff) // overflow b1 5491 { 5492 b1 = 0; 5493 if (b2 === 0xff) 5494 { 5495 b2 = 0; 5496 if (b3 === 0xff) 5497 { 5498 b3 = 0; 5499 } 5500 else 5501 { 5502 ++b3; 5503 } 5504 } 5505 else 5506 { 5507 ++b2; 5508 } 5509 } 5510 else 5511 { 5512 ++b1; 5513 } 5514 5515 word = 0; 5516 word += (b1 << 16); 5517 word += (b2 << 8); 5518 word += b3; 5519 } 5520 else 5521 { 5522 word += (0x01 << 24); 5523 } 5524 return word; 5525 } 5526 5527 function incCounter(counter) 5528 { 5529 if ((counter[0] = incWord(counter[0])) === 0) 5530 { 5531 // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8 5532 counter[1] = incWord(counter[1]); 5533 } 5534 return counter; 5535 } 5536 5537 var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({ 5538 processBlock: function (words, offset) { 5539 // Shortcuts 5540 var cipher = this._cipher 5541 var blockSize = cipher.blockSize; 5542 var iv = this._iv; 5543 var counter = this._counter; 5544 5545 // Generate keystream 5546 if (iv) { 5547 counter = this._counter = iv.slice(0); 5548 5549 // Remove IV for subsequent blocks 5550 this._iv = undefined; 5551 } 5552 5553 incCounter(counter); 5554 5555 var keystream = counter.slice(0); 5556 cipher.encryptBlock(keystream, 0); 5557 5558 // Encrypt 5559 for (var i = 0; i < blockSize; i++) { 5560 words[offset + i] ^= keystream[i]; 5561 } 5562 } 5563 }); 5564 5565 CTRGladman.Decryptor = Encryptor; 5566 5567 return CTRGladman; 5568 }()); 5569 5570 5571 5572 5573 (function () { 5574 // Shortcuts 5575 var C = CryptoJS; 5576 var C_lib = C.lib; 5577 var StreamCipher = C_lib.StreamCipher; 5578 var C_algo = C.algo; 5579 5580 // Reusable objects 5581 var S = []; 5582 var C_ = []; 5583 var G = []; 5584 5585 /** 5586 * Rabbit stream cipher algorithm 5587 */ 5588 var Rabbit = C_algo.Rabbit = StreamCipher.extend({ 5589 _doReset: function () { 5590 // Shortcuts 5591 var K = this._key.words; 5592 var iv = this.cfg.iv; 5593 5594 // Swap endian 5595 for (var i = 0; i < 4; i++) { 5596 K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) | 5597 (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00); 5598 } 5599 5600 // Generate initial state values 5601 var X = this._X = [ 5602 K[0], (K[3] << 16) | (K[2] >>> 16), 5603 K[1], (K[0] << 16) | (K[3] >>> 16), 5604 K[2], (K[1] << 16) | (K[0] >>> 16), 5605 K[3], (K[2] << 16) | (K[1] >>> 16) 5606 ]; 5607 5608 // Generate initial counter values 5609 var C = this._C = [ 5610 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 5611 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 5612 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 5613 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 5614 ]; 5615 5616 // Carry bit 5617 this._b = 0; 5618 5619 // Iterate the system four times 5620 for (var i = 0; i < 4; i++) { 5621 nextState.call(this); 5622 } 5623 5624 // Modify the counters 5625 for (var i = 0; i < 8; i++) { 5626 C[i] ^= X[(i + 4) & 7]; 5627 } 5628 5629 // IV setup 5630 if (iv) { 5631 // Shortcuts 5632 var IV = iv.words; 5633 var IV_0 = IV[0]; 5634 var IV_1 = IV[1]; 5635 5636 // Generate four subvectors 5637 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 5638 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 5639 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 5640 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 5641 5642 // Modify counter values 5643 C[0] ^= i0; 5644 C[1] ^= i1; 5645 C[2] ^= i2; 5646 C[3] ^= i3; 5647 C[4] ^= i0; 5648 C[5] ^= i1; 5649 C[6] ^= i2; 5650 C[7] ^= i3; 5651 5652 // Iterate the system four times 5653 for (var i = 0; i < 4; i++) { 5654 nextState.call(this); 5655 } 5656 } 5657 }, 5658 5659 _doProcessBlock: function (M, offset) { 5660 // Shortcut 5661 var X = this._X; 5662 5663 // Iterate the system 5664 nextState.call(this); 5665 5666 // Generate four keystream words 5667 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 5668 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 5669 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 5670 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 5671 5672 for (var i = 0; i < 4; i++) { 5673 // Swap endian 5674 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 5675 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 5676 5677 // Encrypt 5678 M[offset + i] ^= S[i]; 5679 } 5680 }, 5681 5682 blockSize: 128/32, 5683 5684 ivSize: 64/32 5685 }); 5686 5687 function nextState() { 5688 // Shortcuts 5689 var X = this._X; 5690 var C = this._C; 5691 5692 // Save old counter values 5693 for (var i = 0; i < 8; i++) { 5694 C_[i] = C[i]; 5695 } 5696 5697 // Calculate new counter values 5698 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 5699 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 5700 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 5701 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 5702 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 5703 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 5704 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 5705 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 5706 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 5707 5708 // Calculate the g-values 5709 for (var i = 0; i < 8; i++) { 5710 var gx = X[i] + C[i]; 5711 5712 // Construct high and low argument for squaring 5713 var ga = gx & 0xffff; 5714 var gb = gx >>> 16; 5715 5716 // Calculate high and low result of squaring 5717 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 5718 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 5719 5720 // High XOR low 5721 G[i] = gh ^ gl; 5722 } 5723 5724 // Calculate new state values 5725 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 5726 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 5727 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 5728 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 5729 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 5730 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 5731 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 5732 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 5733 } 5734 5735 /** 5736 * Shortcut functions to the cipher's object interface. 5737 * 5738 * @example 5739 * 5740 * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg); 5741 * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg); 5742 */ 5743 C.Rabbit = StreamCipher._createHelper(Rabbit); 5744 }()); 5745 5746 5747 /** 5748 * Counter block mode. 5749 */ 5750 CryptoJS.mode.CTR = (function () { 5751 var CTR = CryptoJS.lib.BlockCipherMode.extend(); 5752 5753 var Encryptor = CTR.Encryptor = CTR.extend({ 5754 processBlock: function (words, offset) { 5755 // Shortcuts 5756 var cipher = this._cipher 5757 var blockSize = cipher.blockSize; 5758 var iv = this._iv; 5759 var counter = this._counter; 5760 5761 // Generate keystream 5762 if (iv) { 5763 counter = this._counter = iv.slice(0); 5764 5765 // Remove IV for subsequent blocks 5766 this._iv = undefined; 5767 } 5768 var keystream = counter.slice(0); 5769 cipher.encryptBlock(keystream, 0); 5770 5771 // Increment counter 5772 counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0 5773 5774 // Encrypt 5775 for (var i = 0; i < blockSize; i++) { 5776 words[offset + i] ^= keystream[i]; 5777 } 5778 } 5779 }); 5780 5781 CTR.Decryptor = Encryptor; 5782 5783 return CTR; 5784 }()); 5785 5786 5787 (function () { 5788 // Shortcuts 5789 var C = CryptoJS; 5790 var C_lib = C.lib; 5791 var StreamCipher = C_lib.StreamCipher; 5792 var C_algo = C.algo; 5793 5794 // Reusable objects 5795 var S = []; 5796 var C_ = []; 5797 var G = []; 5798 5799 /** 5800 * Rabbit stream cipher algorithm. 5801 * 5802 * This is a legacy version that neglected to convert the key to little-endian. 5803 * This error doesn't affect the cipher's security, 5804 * but it does affect its compatibility with other implementations. 5805 */ 5806 var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({ 5807 _doReset: function () { 5808 // Shortcuts 5809 var K = this._key.words; 5810 var iv = this.cfg.iv; 5811 5812 // Generate initial state values 5813 var X = this._X = [ 5814 K[0], (K[3] << 16) | (K[2] >>> 16), 5815 K[1], (K[0] << 16) | (K[3] >>> 16), 5816 K[2], (K[1] << 16) | (K[0] >>> 16), 5817 K[3], (K[2] << 16) | (K[1] >>> 16) 5818 ]; 5819 5820 // Generate initial counter values 5821 var C = this._C = [ 5822 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 5823 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 5824 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 5825 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 5826 ]; 5827 5828 // Carry bit 5829 this._b = 0; 5830 5831 // Iterate the system four times 5832 for (var i = 0; i < 4; i++) { 5833 nextState.call(this); 5834 } 5835 5836 // Modify the counters 5837 for (var i = 0; i < 8; i++) { 5838 C[i] ^= X[(i + 4) & 7]; 5839 } 5840 5841 // IV setup 5842 if (iv) { 5843 // Shortcuts 5844 var IV = iv.words; 5845 var IV_0 = IV[0]; 5846 var IV_1 = IV[1]; 5847 5848 // Generate four subvectors 5849 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 5850 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 5851 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 5852 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 5853 5854 // Modify counter values 5855 C[0] ^= i0; 5856 C[1] ^= i1; 5857 C[2] ^= i2; 5858 C[3] ^= i3; 5859 C[4] ^= i0; 5860 C[5] ^= i1; 5861 C[6] ^= i2; 5862 C[7] ^= i3; 5863 5864 // Iterate the system four times 5865 for (var i = 0; i < 4; i++) { 5866 nextState.call(this); 5867 } 5868 } 5869 }, 5870 5871 _doProcessBlock: function (M, offset) { 5872 // Shortcut 5873 var X = this._X; 5874 5875 // Iterate the system 5876 nextState.call(this); 5877 5878 // Generate four keystream words 5879 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 5880 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 5881 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 5882 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 5883 5884 for (var i = 0; i < 4; i++) { 5885 // Swap endian 5886 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 5887 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
vendor: 3,401 bytes, lines 5888-5988
5888 5889 // Encrypt 5890 M[offset + i] ^= S[i]; 5891 } 5892 }, 5893 5894 blockSize: 128/32, 5895 5896 ivSize: 64/32 5897 }); 5898 5899 function nextState() { 5900 // Shortcuts 5901 var X = this._X; 5902 var C = this._C; 5903 5904 // Save old counter values 5905 for (var i = 0; i < 8; i++) { 5906 C_[i] = C[i]; 5907 } 5908 5909 // Calculate new counter values 5910 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 5911 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 5912 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 5913 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 5914 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 5915 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 5916 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 5917 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 5918 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 5919 5920 // Calculate the g-values 5921 for (var i = 0; i < 8; i++) { 5922 var gx = X[i] + C[i]; 5923 5924 // Construct high and low argument for squaring 5925 var ga = gx & 0xffff; 5926 var gb = gx >>> 16; 5927 5928 // Calculate high and low result of squaring 5929 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 5930 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 5931 5932 // High XOR low 5933 G[i] = gh ^ gl; 5934 } 5935 5936 // Calculate new state values 5937 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 5938 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 5939 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 5940 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 5941 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 5942 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 5943 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 5944 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 5945 } 5946 5947 /** 5948 * Shortcut functions to the cipher's object interface. 5949 * 5950 * @example 5951 * 5952 * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg); 5953 * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg); 5954 */ 5955 C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy); 5956 }()); 5957 5958 5959 /** 5960 * Zero padding strategy. 5961 */ 5962 CryptoJS.pad.ZeroPadding = { 5963 pad: function (data, blockSize) { 5964 // Shortcut 5965 var blockSizeBytes = blockSize * 4; 5966 5967 // Pad 5968 data.clamp(); 5969 data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes); 5970 }, 5971 5972 unpad: function (data) { 5973 // Shortcut 5974 var dataWords = data.words; 5975 5976 // Unpad 5977 var i = data.sigBytes - 1; 5978 while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { 5979 i--; 5980 } 5981 data.sigBytes = i + 1; 5982 } 5983 }; 5984 5985 5986 return CryptoJS; 5987 5988}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.