Crypto-JS

crypto-js是谷歌开发的一个纯JavaScript的加密算法类库,可以非常方便的在前端进行其所支持的加解密操作。目前crypto-js已支持的算法有:MD5、SHA-1、SHA-256、AES、RSA、Rabbit、MARC4、HMAC、HMAC-MD5、HMAC-SHA1、HMAC-SHA256、PBKDF2等。使用时可以引用总文件,也可以单独引用某一文件。

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/486152/1448081/Crypto-JS.js

  1. // @ts-nocheck
  2. (function (root, factory) {
  3. if (typeof exports === "object" && typeof module !== "undefined") {
  4. /* 适用于NodeJs或typeScript */
  5. module.exports = factory();
  6. } else {
  7. root = typeof globalThis !== "undefined" ? globalThis : root || self;
  8. /* 适用于浏览器中,且this对象是window,如果this是其它,那么会在其它对象下注册(不可用)对象 */
  9. root.CryptoJS = factory();
  10. }
  11. })(this, function () {
  12. /*globals window, global, require*/
  13.  
  14. /**
  15. * CryptoJS core components.
  16. */
  17. var CryptoJS =
  18. CryptoJS ||
  19. (function (Math, undefined) {
  20. var crypto;
  21.  
  22. // Native crypto from window (Browser)
  23. if (typeof window !== "undefined" && window.crypto) {
  24. crypto = window.crypto;
  25. }
  26.  
  27. // Native crypto in web worker (Browser)
  28. if (typeof self !== "undefined" && self.crypto) {
  29. crypto = self.crypto;
  30. }
  31.  
  32. // Native crypto from worker
  33. if (typeof globalThis !== "undefined" && globalThis.crypto) {
  34. crypto = globalThis.crypto;
  35. }
  36.  
  37. // Native (experimental IE 11) crypto from window (Browser)
  38. if (!crypto && typeof window !== "undefined" && window.msCrypto) {
  39. crypto = window.msCrypto;
  40. }
  41.  
  42. // Native crypto from global (NodeJS)
  43. if (!crypto && typeof global !== "undefined" && global.crypto) {
  44. crypto = global.crypto;
  45. }
  46.  
  47. // Native crypto import via require (NodeJS)
  48. if (!crypto && typeof require === "function") {
  49. try {
  50. crypto = require("crypto");
  51. } catch (err) {}
  52. }
  53.  
  54. /*
  55. * Cryptographically secure pseudorandom number generator
  56. *
  57. * As Math.random() is cryptographically not safe to use
  58. */
  59. var cryptoSecureRandomInt = function () {
  60. if (crypto) {
  61. // Use getRandomValues method (Browser)
  62. if (typeof crypto.getRandomValues === "function") {
  63. try {
  64. return crypto.getRandomValues(new Uint32Array(1))[0];
  65. } catch (err) {}
  66. }
  67.  
  68. // Use randomBytes method (NodeJS)
  69. if (typeof crypto.randomBytes === "function") {
  70. try {
  71. return crypto.randomBytes(4).readInt32LE();
  72. } catch (err) {}
  73. }
  74. }
  75.  
  76. throw new Error(
  77. "Native crypto module could not be used to get secure random number."
  78. );
  79. };
  80.  
  81. /*
  82. * Local polyfill of Object.create
  83.  
  84. */
  85. var create =
  86. Object.create ||
  87. (function () {
  88. function F() {}
  89.  
  90. return function (obj) {
  91. var subtype;
  92.  
  93. F.prototype = obj;
  94.  
  95. subtype = new F();
  96.  
  97. F.prototype = null;
  98.  
  99. return subtype;
  100. };
  101. })();
  102.  
  103. /**
  104. * CryptoJS namespace.
  105. */
  106. var C = {};
  107.  
  108. /**
  109. * Library namespace.
  110. */
  111. var C_lib = (C.lib = {});
  112.  
  113. /**
  114. * Base object for prototypal inheritance.
  115. */
  116. var Base = (C_lib.Base = (function () {
  117. return {
  118. /**
  119. * Creates a new object that inherits from this object.
  120. *
  121. * @param {Object} overrides Properties to copy into the new object.
  122. *
  123. * @return {Object} The new object.
  124. *
  125. * @static
  126. *
  127. * @example
  128. *
  129. * var MyType = CryptoJS.lib.Base.extend({
  130. * field: 'value',
  131. *
  132. * method: function () {
  133. * }
  134. * });
  135. */
  136. extend: function (overrides) {
  137. // Spawn
  138. var subtype = create(this);
  139.  
  140. // Augment
  141. if (overrides) {
  142. subtype.mixIn(overrides);
  143. }
  144.  
  145. // Create default initializer
  146. if (!subtype.hasOwnProperty("init") || this.init === subtype.init) {
  147. subtype.init = function () {
  148. subtype.$super.init.apply(this, arguments);
  149. };
  150. }
  151.  
  152. // Initializer's prototype is the subtype object
  153. subtype.init.prototype = subtype;
  154.  
  155. // Reference supertype
  156. subtype.$super = this;
  157.  
  158. return subtype;
  159. },
  160.  
  161. /**
  162. * Extends this object and runs the init method.
  163. * Arguments to create() will be passed to init().
  164. *
  165. * @return {Object} The new object.
  166. *
  167. * @static
  168. *
  169. * @example
  170. *
  171. * var instance = MyType.create();
  172. */
  173. create: function () {
  174. var instance = this.extend();
  175. instance.init.apply(instance, arguments);
  176.  
  177. return instance;
  178. },
  179.  
  180. /**
  181. * Initializes a newly created object.
  182. * Override this method to add some logic when your objects are created.
  183. *
  184. * @example
  185. *
  186. * var MyType = CryptoJS.lib.Base.extend({
  187. * init: function () {
  188. * // ...
  189. * }
  190. * });
  191. */
  192. init: function () {},
  193.  
  194. /**
  195. * Copies properties into this object.
  196. *
  197. * @param {Object} properties The properties to mix in.
  198. *
  199. * @example
  200. *
  201. * MyType.mixIn({
  202. * field: 'value'
  203. * });
  204. */
  205. mixIn: function (properties) {
  206. for (var propertyName in properties) {
  207. if (properties.hasOwnProperty(propertyName)) {
  208. this[propertyName] = properties[propertyName];
  209. }
  210. }
  211.  
  212. // IE won't copy toString using the loop above
  213. if (properties.hasOwnProperty("toString")) {
  214. this.toString = properties.toString;
  215. }
  216. },
  217.  
  218. /**
  219. * Creates a copy of this object.
  220. *
  221. * @return {Object} The clone.
  222. *
  223. * @example
  224. *
  225. * var clone = instance.clone();
  226. */
  227. clone: function () {
  228. return this.init.prototype.extend(this);
  229. },
  230. };
  231. })());
  232.  
  233. /**
  234. * An array of 32-bit words.
  235. *
  236. * @property {Array} words The array of 32-bit words.
  237. * @property {number} sigBytes The number of significant bytes in this word array.
  238. */
  239. var WordArray = (C_lib.WordArray = Base.extend({
  240. /**
  241. * Initializes a newly created word array.
  242. *
  243. * @param {Array} words (Optional) An array of 32-bit words.
  244. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  245. *
  246. * @example
  247. *
  248. * var wordArray = CryptoJS.lib.WordArray.create();
  249. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
  250. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
  251. */
  252. init: function (words, sigBytes) {
  253. words = this.words = words || [];
  254.  
  255. if (sigBytes != undefined) {
  256. this.sigBytes = sigBytes;
  257. } else {
  258. this.sigBytes = words.length * 4;
  259. }
  260. },
  261.  
  262. /**
  263. * Converts this word array to a string.
  264. *
  265. * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
  266. *
  267. * @return {string} The stringified word array.
  268. *
  269. * @example
  270. *
  271. * var string = wordArray + '';
  272. * var string = wordArray.toString();
  273. * var string = wordArray.toString(CryptoJS.enc.Utf8);
  274. */
  275. toString: function (encoder) {
  276. return (encoder || Hex).stringify(this);
  277. },
  278.  
  279. /**
  280. * Concatenates a word array to this word array.
  281. *
  282. * @param {WordArray} wordArray The word array to append.
  283. *
  284. * @return {WordArray} This word array.
  285. *
  286. * @example
  287. *
  288. * wordArray1.concat(wordArray2);
  289. */
  290. concat: function (wordArray) {
  291. // Shortcuts
  292. var thisWords = this.words;
  293. var thatWords = wordArray.words;
  294. var thisSigBytes = this.sigBytes;
  295. var thatSigBytes = wordArray.sigBytes;
  296.  
  297. // Clamp excess bits
  298. this.clamp();
  299.  
  300. // Concat
  301. if (thisSigBytes % 4) {
  302. // Copy one byte at a time
  303. for (var i = 0; i < thatSigBytes; i++) {
  304. var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  305. thisWords[(thisSigBytes + i) >>> 2] |=
  306. thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
  307. }
  308. } else {
  309. // Copy one word at a time
  310. for (var j = 0; j < thatSigBytes; j += 4) {
  311. thisWords[(thisSigBytes + j) >>> 2] = thatWords[j >>> 2];
  312. }
  313. }
  314. this.sigBytes += thatSigBytes;
  315.  
  316. // Chainable
  317. return this;
  318. },
  319.  
  320. /**
  321. * Removes insignificant bits.
  322. *
  323. * @example
  324. *
  325. * wordArray.clamp();
  326. */
  327. clamp: function () {
  328. // Shortcuts
  329. var words = this.words;
  330. var sigBytes = this.sigBytes;
  331.  
  332. // Clamp
  333. words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
  334. words.length = Math.ceil(sigBytes / 4);
  335. },
  336.  
  337. /**
  338. * Creates a copy of this word array.
  339. *
  340. * @return {WordArray} The clone.
  341. *
  342. * @example
  343. *
  344. * var clone = wordArray.clone();
  345. */
  346. clone: function () {
  347. var clone = Base.clone.call(this);
  348. clone.words = this.words.slice(0);
  349.  
  350. return clone;
  351. },
  352.  
  353. /**
  354. * Creates a word array filled with random bytes.
  355. *
  356. * @param {number} nBytes The number of random bytes to generate.
  357. *
  358. * @return {WordArray} The random word array.
  359. *
  360. * @static
  361. *
  362. * @example
  363. *
  364. * var wordArray = CryptoJS.lib.WordArray.random(16);
  365. */
  366. random: function (nBytes) {
  367. var words = [];
  368.  
  369. for (var i = 0; i < nBytes; i += 4) {
  370. words.push(cryptoSecureRandomInt());
  371. }
  372.  
  373. return new WordArray.init(words, nBytes);
  374. },
  375. }));
  376.  
  377. /**
  378. * Encoder namespace.
  379. */
  380. var C_enc = (C.enc = {});
  381.  
  382. /**
  383. * Hex encoding strategy.
  384. */
  385. var Hex = (C_enc.Hex = {
  386. /**
  387. * Converts a word array to a hex string.
  388. *
  389. * @param {WordArray} wordArray The word array.
  390. *
  391. * @return {string} The hex string.
  392. *
  393. * @static
  394. *
  395. * @example
  396. *
  397. * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
  398. */
  399. stringify: function (wordArray) {
  400. // Shortcuts
  401. var words = wordArray.words;
  402. var sigBytes = wordArray.sigBytes;
  403.  
  404. // Convert
  405. var hexChars = [];
  406. for (var i = 0; i < sigBytes; i++) {
  407. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  408. hexChars.push((bite >>> 4).toString(16));
  409. hexChars.push((bite & 0x0f).toString(16));
  410. }
  411.  
  412. return hexChars.join("");
  413. },
  414.  
  415. /**
  416. * Converts a hex string to a word array.
  417. *
  418. * @param {string} hexStr The hex string.
  419. *
  420. * @return {WordArray} The word array.
  421. *
  422. * @static
  423. *
  424. * @example
  425. *
  426. * var wordArray = CryptoJS.enc.Hex.parse(hexString);
  427. */
  428. parse: function (hexStr) {
  429. // Shortcut
  430. var hexStrLength = hexStr.length;
  431.  
  432. // Convert
  433. var words = [];
  434. for (var i = 0; i < hexStrLength; i += 2) {
  435. words[i >>> 3] |=
  436. parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
  437. }
  438.  
  439. return new WordArray.init(words, hexStrLength / 2);
  440. },
  441. });
  442.  
  443. /**
  444. * Latin1 encoding strategy.
  445. */
  446. var Latin1 = (C_enc.Latin1 = {
  447. /**
  448. * Converts a word array to a Latin1 string.
  449. *
  450. * @param {WordArray} wordArray The word array.
  451. *
  452. * @return {string} The Latin1 string.
  453. *
  454. * @static
  455. *
  456. * @example
  457. *
  458. * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
  459. */
  460. stringify: function (wordArray) {
  461. // Shortcuts
  462. var words = wordArray.words;
  463. var sigBytes = wordArray.sigBytes;
  464.  
  465. // Convert
  466. var latin1Chars = [];
  467. for (var i = 0; i < sigBytes; i++) {
  468. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  469. latin1Chars.push(String.fromCharCode(bite));
  470. }
  471.  
  472. return latin1Chars.join("");
  473. },
  474.  
  475. /**
  476. * Converts a Latin1 string to a word array.
  477. *
  478. * @param {string} latin1Str The Latin1 string.
  479. *
  480. * @return {WordArray} The word array.
  481. *
  482. * @static
  483. *
  484. * @example
  485. *
  486. * var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
  487. */
  488. parse: function (latin1Str) {
  489. // Shortcut
  490. var latin1StrLength = latin1Str.length;
  491.  
  492. // Convert
  493. var words = [];
  494. for (var i = 0; i < latin1StrLength; i++) {
  495. words[i >>> 2] |=
  496. (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
  497. }
  498.  
  499. return new WordArray.init(words, latin1StrLength);
  500. },
  501. });
  502.  
  503. /**
  504. * UTF-8 encoding strategy.
  505. */
  506. var Utf8 = (C_enc.Utf8 = {
  507. /**
  508. * Converts a word array to a UTF-8 string.
  509. *
  510. * @param {WordArray} wordArray The word array.
  511. *
  512. * @return {string} The UTF-8 string.
  513. *
  514. * @static
  515. *
  516. * @example
  517. *
  518. * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
  519. */
  520. stringify: function (wordArray) {
  521. try {
  522. return decodeURIComponent(escape(Latin1.stringify(wordArray)));
  523. } catch (e) {
  524. throw new Error("Malformed UTF-8 data");
  525. }
  526. },
  527.  
  528. /**
  529. * Converts a UTF-8 string to a word array.
  530. *
  531. * @param {string} utf8Str The UTF-8 string.
  532. *
  533. * @return {WordArray} The word array.
  534. *
  535. * @static
  536. *
  537. * @example
  538. *
  539. * var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
  540. */
  541. parse: function (utf8Str) {
  542. return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
  543. },
  544. });
  545.  
  546. /**
  547. * Abstract buffered block algorithm template.
  548. *
  549. * The property blockSize must be implemented in a concrete subtype.
  550. *
  551. * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
  552. */
  553. var BufferedBlockAlgorithm = (C_lib.BufferedBlockAlgorithm = Base.extend({
  554. /**
  555. * Resets this block algorithm's data buffer to its initial state.
  556. *
  557. * @example
  558. *
  559. * bufferedBlockAlgorithm.reset();
  560. */
  561. reset: function () {
  562. // Initial values
  563. this._data = new WordArray.init();
  564. this._nDataBytes = 0;
  565. },
  566.  
  567. /**
  568. * Adds new data to this block algorithm's buffer.
  569. *
  570. * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
  571. *
  572. * @example
  573. *
  574. * bufferedBlockAlgorithm._append('data');
  575. * bufferedBlockAlgorithm._append(wordArray);
  576. */
  577. _append: function (data) {
  578. // Convert string to WordArray, else assume WordArray already
  579. if (typeof data == "string") {
  580. data = Utf8.parse(data);
  581. }
  582.  
  583. // Append
  584. this._data.concat(data);
  585. this._nDataBytes += data.sigBytes;
  586. },
  587.  
  588. /**
  589. * Processes available data blocks.
  590. *
  591. * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
  592. *
  593. * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
  594. *
  595. * @return {WordArray} The processed data.
  596. *
  597. * @example
  598. *
  599. * var processedData = bufferedBlockAlgorithm._process();
  600. * var processedData = bufferedBlockAlgorithm._process(!!'flush');
  601. */
  602. _process: function (doFlush) {
  603. var processedWords;
  604.  
  605. // Shortcuts
  606. var data = this._data;
  607. var dataWords = data.words;
  608. var dataSigBytes = data.sigBytes;
  609. var blockSize = this.blockSize;
  610. var blockSizeBytes = blockSize * 4;
  611.  
  612. // Count blocks ready
  613. var nBlocksReady = dataSigBytes / blockSizeBytes;
  614. if (doFlush) {
  615. // Round up to include partial blocks
  616. nBlocksReady = Math.ceil(nBlocksReady);
  617. } else {
  618. // Round down to include only full blocks,
  619. // less the number of blocks that must remain in the buffer
  620. nBlocksReady = Math.max(
  621. (nBlocksReady | 0) - this._minBufferSize,
  622. 0
  623. );
  624. }
  625.  
  626. // Count words ready
  627. var nWordsReady = nBlocksReady * blockSize;
  628.  
  629. // Count bytes ready
  630. var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
  631.  
  632. // Process blocks
  633. if (nWordsReady) {
  634. for (var offset = 0; offset < nWordsReady; offset += blockSize) {
  635. // Perform concrete-algorithm logic
  636. this._doProcessBlock(dataWords, offset);
  637. }
  638.  
  639. // Remove processed words
  640. processedWords = dataWords.splice(0, nWordsReady);
  641. data.sigBytes -= nBytesReady;
  642. }
  643.  
  644. // Return processed words
  645. return new WordArray.init(processedWords, nBytesReady);
  646. },
  647.  
  648. /**
  649. * Creates a copy of this object.
  650. *
  651. * @return {Object} The clone.
  652. *
  653. * @example
  654. *
  655. * var clone = bufferedBlockAlgorithm.clone();
  656. */
  657. clone: function () {
  658. var clone = Base.clone.call(this);
  659. clone._data = this._data.clone();
  660.  
  661. return clone;
  662. },
  663.  
  664. _minBufferSize: 0,
  665. }));
  666.  
  667. /**
  668. * Abstract hasher template.
  669. *
  670. * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
  671. */
  672. var Hasher = (C_lib.Hasher = BufferedBlockAlgorithm.extend({
  673. /**
  674. * Configuration options.
  675. */
  676. cfg: Base.extend(),
  677.  
  678. /**
  679. * Initializes a newly created hasher.
  680. *
  681. * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
  682. *
  683. * @example
  684. *
  685. * var hasher = CryptoJS.algo.SHA256.create();
  686. */
  687. init: function (cfg) {
  688. // Apply config defaults
  689. this.cfg = this.cfg.extend(cfg);
  690.  
  691. // Set initial values
  692. this.reset();
  693. },
  694.  
  695. /**
  696. * Resets this hasher to its initial state.
  697. *
  698. * @example
  699. *
  700. * hasher.reset();
  701. */
  702. reset: function () {
  703. // Reset data buffer
  704. BufferedBlockAlgorithm.reset.call(this);
  705.  
  706. // Perform concrete-hasher logic
  707. this._doReset();
  708. },
  709.  
  710. /**
  711. * Updates this hasher with a message.
  712. *
  713. * @param {WordArray|string} messageUpdate The message to append.
  714. *
  715. * @return {Hasher} This hasher.
  716. *
  717. * @example
  718. *
  719. * hasher.update('message');
  720. * hasher.update(wordArray);
  721. */
  722. update: function (messageUpdate) {
  723. // Append
  724. this._append(messageUpdate);
  725.  
  726. // Update the hash
  727. this._process();
  728.  
  729. // Chainable
  730. return this;
  731. },
  732.  
  733. /**
  734. * Finalizes the hash computation.
  735. * Note that the finalize operation is effectively a destructive, read-once operation.
  736. *
  737. * @param {WordArray|string} messageUpdate (Optional) A final message update.
  738. *
  739. * @return {WordArray} The hash.
  740. *
  741. * @example
  742. *
  743. * var hash = hasher.finalize();
  744. * var hash = hasher.finalize('message');
  745. * var hash = hasher.finalize(wordArray);
  746. */
  747. finalize: function (messageUpdate) {
  748. // Final message update
  749. if (messageUpdate) {
  750. this._append(messageUpdate);
  751. }
  752.  
  753. // Perform concrete-hasher logic
  754. var hash = this._doFinalize();
  755.  
  756. return hash;
  757. },
  758.  
  759. blockSize: 512 / 32,
  760.  
  761. /**
  762. * Creates a shortcut function to a hasher's object interface.
  763. *
  764. * @param {Hasher} hasher The hasher to create a helper for.
  765. *
  766. * @return {Function} The shortcut function.
  767. *
  768. * @static
  769. *
  770. * @example
  771. *
  772. * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
  773. */
  774. _createHelper: function (hasher) {
  775. return function (message, cfg) {
  776. return new hasher.init(cfg).finalize(message);
  777. };
  778. },
  779.  
  780. /**
  781. * Creates a shortcut function to the HMAC's object interface.
  782. *
  783. * @param {Hasher} hasher The hasher to use in this HMAC helper.
  784. *
  785. * @return {Function} The shortcut function.
  786. *
  787. * @static
  788. *
  789. * @example
  790. *
  791. * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
  792. */
  793. _createHmacHelper: function (hasher) {
  794. return function (message, key) {
  795. return new C_algo.HMAC.init(hasher, key).finalize(message);
  796. };
  797. },
  798. }));
  799.  
  800. /**
  801. * Algorithm namespace.
  802. */
  803. var C_algo = (C.algo = {});
  804.  
  805. return C;
  806. })(Math);
  807.  
  808. (function (undefined) {
  809. // Shortcuts
  810. var C = CryptoJS;
  811. var C_lib = C.lib;
  812. var Base = C_lib.Base;
  813. var X32WordArray = C_lib.WordArray;
  814.  
  815. /**
  816. * x64 namespace.
  817. */
  818. var C_x64 = (C.x64 = {});
  819.  
  820. /**
  821. * A 64-bit word.
  822. */
  823. var X64Word = (C_x64.Word = Base.extend({
  824. /**
  825. * Initializes a newly created 64-bit word.
  826. *
  827. * @param {number} high The high 32 bits.
  828. * @param {number} low The low 32 bits.
  829. *
  830. * @example
  831. *
  832. * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
  833. */
  834. init: function (high, low) {
  835. this.high = high;
  836. this.low = low;
  837. },
  838.  
  839. /**
  840. * Bitwise NOTs this word.
  841. *
  842. * @return {X64Word} A new x64-Word object after negating.
  843. *
  844. * @example
  845. *
  846. * var negated = x64Word.not();
  847. */
  848. // not: function () {
  849. // var high = ~this.high;
  850. // var low = ~this.low;
  851.  
  852. // return X64Word.create(high, low);
  853. // },
  854.  
  855. /**
  856. * Bitwise ANDs this word with the passed word.
  857. *
  858. * @param {X64Word} word The x64-Word to AND with this word.
  859. *
  860. * @return {X64Word} A new x64-Word object after ANDing.
  861. *
  862. * @example
  863. *
  864. * var anded = x64Word.and(anotherX64Word);
  865. */
  866. // and: function (word) {
  867. // var high = this.high & word.high;
  868. // var low = this.low & word.low;
  869.  
  870. // return X64Word.create(high, low);
  871. // },
  872.  
  873. /**
  874. * Bitwise ORs this word with the passed word.
  875. *
  876. * @param {X64Word} word The x64-Word to OR with this word.
  877. *
  878. * @return {X64Word} A new x64-Word object after ORing.
  879. *
  880. * @example
  881. *
  882. * var ored = x64Word.or(anotherX64Word);
  883. */
  884. // or: function (word) {
  885. // var high = this.high | word.high;
  886. // var low = this.low | word.low;
  887.  
  888. // return X64Word.create(high, low);
  889. // },
  890.  
  891. /**
  892. * Bitwise XORs this word with the passed word.
  893. *
  894. * @param {X64Word} word The x64-Word to XOR with this word.
  895. *
  896. * @return {X64Word} A new x64-Word object after XORing.
  897. *
  898. * @example
  899. *
  900. * var xored = x64Word.xor(anotherX64Word);
  901. */
  902. // xor: function (word) {
  903. // var high = this.high ^ word.high;
  904. // var low = this.low ^ word.low;
  905.  
  906. // return X64Word.create(high, low);
  907. // },
  908.  
  909. /**
  910. * Shifts this word n bits to the left.
  911. *
  912. * @param {number} n The number of bits to shift.
  913. *
  914. * @return {X64Word} A new x64-Word object after shifting.
  915. *
  916. * @example
  917. *
  918. * var shifted = x64Word.shiftL(25);
  919. */
  920. // shiftL: function (n) {
  921. // if (n < 32) {
  922. // var high = (this.high << n) | (this.low >>> (32 - n));
  923. // var low = this.low << n;
  924. // } else {
  925. // var high = this.low << (n - 32);
  926. // var low = 0;
  927. // }
  928.  
  929. // return X64Word.create(high, low);
  930. // },
  931.  
  932. /**
  933. * Shifts this word n bits to the right.
  934. *
  935. * @param {number} n The number of bits to shift.
  936. *
  937. * @return {X64Word} A new x64-Word object after shifting.
  938. *
  939. * @example
  940. *
  941. * var shifted = x64Word.shiftR(7);
  942. */
  943. // shiftR: function (n) {
  944. // if (n < 32) {
  945. // var low = (this.low >>> n) | (this.high << (32 - n));
  946. // var high = this.high >>> n;
  947. // } else {
  948. // var low = this.high >>> (n - 32);
  949. // var high = 0;
  950. // }
  951.  
  952. // return X64Word.create(high, low);
  953. // },
  954.  
  955. /**
  956. * Rotates this word n bits to the left.
  957. *
  958. * @param {number} n The number of bits to rotate.
  959. *
  960. * @return {X64Word} A new x64-Word object after rotating.
  961. *
  962. * @example
  963. *
  964. * var rotated = x64Word.rotL(25);
  965. */
  966. // rotL: function (n) {
  967. // return this.shiftL(n).or(this.shiftR(64 - n));
  968. // },
  969.  
  970. /**
  971. * Rotates this word n bits to the right.
  972. *
  973. * @param {number} n The number of bits to rotate.
  974. *
  975. * @return {X64Word} A new x64-Word object after rotating.
  976. *
  977. * @example
  978. *
  979. * var rotated = x64Word.rotR(7);
  980. */
  981. // rotR: function (n) {
  982. // return this.shiftR(n).or(this.shiftL(64 - n));
  983. // },
  984.  
  985. /**
  986. * Adds this word with the passed word.
  987. *
  988. * @param {X64Word} word The x64-Word to add with this word.
  989. *
  990. * @return {X64Word} A new x64-Word object after adding.
  991. *
  992. * @example
  993. *
  994. * var added = x64Word.add(anotherX64Word);
  995. */
  996. // add: function (word) {
  997. // var low = (this.low + word.low) | 0;
  998. // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0;
  999. // var high = (this.high + word.high + carry) | 0;
  1000.  
  1001. // return X64Word.create(high, low);
  1002. // }
  1003. }));
  1004.  
  1005. /**
  1006. * An array of 64-bit words.
  1007. *
  1008. * @property {Array} words The array of CryptoJS.x64.Word objects.
  1009. * @property {number} sigBytes The number of significant bytes in this word array.
  1010. */
  1011. var X64WordArray = (C_x64.WordArray = Base.extend({
  1012. /**
  1013. * Initializes a newly created word array.
  1014. *
  1015. * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects.
  1016. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  1017. *
  1018. * @example
  1019. *
  1020. * var wordArray = CryptoJS.x64.WordArray.create();
  1021. *
  1022. * var wordArray = CryptoJS.x64.WordArray.create([
  1023. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  1024. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  1025. * ]);
  1026. *
  1027. * var wordArray = CryptoJS.x64.WordArray.create([
  1028. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  1029. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  1030. * ], 10);
  1031. */
  1032. init: function (words, sigBytes) {
  1033. words = this.words = words || [];
  1034.  
  1035. if (sigBytes != undefined) {
  1036. this.sigBytes = sigBytes;
  1037. } else {
  1038. this.sigBytes = words.length * 8;
  1039. }
  1040. },
  1041.  
  1042. /**
  1043. * Converts this 64-bit word array to a 32-bit word array.
  1044. *
  1045. * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array.
  1046. *
  1047. * @example
  1048. *
  1049. * var x32WordArray = x64WordArray.toX32();
  1050. */
  1051. toX32: function () {
  1052. // Shortcuts
  1053. var x64Words = this.words;
  1054. var x64WordsLength = x64Words.length;
  1055.  
  1056. // Convert
  1057. var x32Words = [];
  1058. for (var i = 0; i < x64WordsLength; i++) {
  1059. var x64Word = x64Words[i];
  1060. x32Words.push(x64Word.high);
  1061. x32Words.push(x64Word.low);
  1062. }
  1063.  
  1064. return X32WordArray.create(x32Words, this.sigBytes);
  1065. },
  1066.  
  1067. /**
  1068. * Creates a copy of this word array.
  1069. *
  1070. * @return {X64WordArray} The clone.
  1071. *
  1072. * @example
  1073. *
  1074. * var clone = x64WordArray.clone();
  1075. */
  1076. clone: function () {
  1077. var clone = Base.clone.call(this);
  1078.  
  1079. // Clone "words" array
  1080. var words = (clone.words = this.words.slice(0));
  1081.  
  1082. // Clone each X64Word object
  1083. var wordsLength = words.length;
  1084. for (var i = 0; i < wordsLength; i++) {
  1085. words[i] = words[i].clone();
  1086. }
  1087.  
  1088. return clone;
  1089. },
  1090. }));
  1091. })();
  1092.  
  1093. (function () {
  1094. // Check if typed arrays are supported
  1095. if (typeof ArrayBuffer != "function") {
  1096. return;
  1097. }
  1098.  
  1099. // Shortcuts
  1100. var C = CryptoJS;
  1101. var C_lib = C.lib;
  1102. var WordArray = C_lib.WordArray;
  1103.  
  1104. // Reference original init
  1105. var superInit = WordArray.init;
  1106.  
  1107. // Augment WordArray.init to handle typed arrays
  1108. var subInit = (WordArray.init = function (typedArray) {
  1109. // Convert buffers to uint8
  1110. if (typedArray instanceof ArrayBuffer) {
  1111. typedArray = new Uint8Array(typedArray);
  1112. }
  1113.  
  1114. // Convert other array views to uint8
  1115. if (
  1116. typedArray instanceof Int8Array ||
  1117. (typeof Uint8ClampedArray !== "undefined" &&
  1118. typedArray instanceof Uint8ClampedArray) ||
  1119. typedArray instanceof Int16Array ||
  1120. typedArray instanceof Uint16Array ||
  1121. typedArray instanceof Int32Array ||
  1122. typedArray instanceof Uint32Array ||
  1123. typedArray instanceof Float32Array ||
  1124. typedArray instanceof Float64Array
  1125. ) {
  1126. typedArray = new Uint8Array(
  1127. typedArray.buffer,
  1128. typedArray.byteOffset,
  1129. typedArray.byteLength
  1130. );
  1131. }
  1132.  
  1133. // Handle Uint8Array
  1134. if (typedArray instanceof Uint8Array) {
  1135. // Shortcut
  1136. var typedArrayByteLength = typedArray.byteLength;
  1137.  
  1138. // Extract bytes
  1139. var words = [];
  1140. for (var i = 0; i < typedArrayByteLength; i++) {
  1141. words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8);
  1142. }
  1143.  
  1144. // Initialize this word array
  1145. superInit.call(this, words, typedArrayByteLength);
  1146. } else {
  1147. // Else call normal init
  1148. superInit.apply(this, arguments);
  1149. }
  1150. });
  1151.  
  1152. subInit.prototype = WordArray;
  1153. })();
  1154.  
  1155. (function () {
  1156. // Shortcuts
  1157. var C = CryptoJS;
  1158. var C_lib = C.lib;
  1159. var WordArray = C_lib.WordArray;
  1160. var C_enc = C.enc;
  1161.  
  1162. /**
  1163. * UTF-16 BE encoding strategy.
  1164. */
  1165. var Utf16BE =
  1166. (C_enc.Utf16 =
  1167. C_enc.Utf16BE =
  1168. {
  1169. /**
  1170. * Converts a word array to a UTF-16 BE string.
  1171. *
  1172. * @param {WordArray} wordArray The word array.
  1173. *
  1174. * @return {string} The UTF-16 BE string.
  1175. *
  1176. * @static
  1177. *
  1178. * @example
  1179. *
  1180. * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray);
  1181. */
  1182. stringify: function (wordArray) {
  1183. // Shortcuts
  1184. var words = wordArray.words;
  1185. var sigBytes = wordArray.sigBytes;
  1186.  
  1187. // Convert
  1188. var utf16Chars = [];
  1189. for (var i = 0; i < sigBytes; i += 2) {
  1190. var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff;
  1191. utf16Chars.push(String.fromCharCode(codePoint));
  1192. }
  1193.  
  1194. return utf16Chars.join("");
  1195. },
  1196.  
  1197. /**
  1198. * Converts a UTF-16 BE string to a word array.
  1199. *
  1200. * @param {string} utf16Str The UTF-16 BE string.
  1201. *
  1202. * @return {WordArray} The word array.
  1203. *
  1204. * @static
  1205. *
  1206. * @example
  1207. *
  1208. * var wordArray = CryptoJS.enc.Utf16.parse(utf16String);
  1209. */
  1210. parse: function (utf16Str) {
  1211. // Shortcut
  1212. var utf16StrLength = utf16Str.length;
  1213.  
  1214. // Convert
  1215. var words = [];
  1216. for (var i = 0; i < utf16StrLength; i++) {
  1217. words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16);
  1218. }
  1219.  
  1220. return WordArray.create(words, utf16StrLength * 2);
  1221. },
  1222. });
  1223.  
  1224. /**
  1225. * UTF-16 LE encoding strategy.
  1226. */
  1227. C_enc.Utf16LE = {
  1228. /**
  1229. * Converts a word array to a UTF-16 LE string.
  1230. *
  1231. * @param {WordArray} wordArray The word array.
  1232. *
  1233. * @return {string} The UTF-16 LE string.
  1234. *
  1235. * @static
  1236. *
  1237. * @example
  1238. *
  1239. * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray);
  1240. */
  1241. stringify: function (wordArray) {
  1242. // Shortcuts
  1243. var words = wordArray.words;
  1244. var sigBytes = wordArray.sigBytes;
  1245.  
  1246. // Convert
  1247. var utf16Chars = [];
  1248. for (var i = 0; i < sigBytes; i += 2) {
  1249. var codePoint = swapEndian(
  1250. (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff
  1251. );
  1252. utf16Chars.push(String.fromCharCode(codePoint));
  1253. }
  1254.  
  1255. return utf16Chars.join("");
  1256. },
  1257.  
  1258. /**
  1259. * Converts a UTF-16 LE string to a word array.
  1260. *
  1261. * @param {string} utf16Str The UTF-16 LE string.
  1262. *
  1263. * @return {WordArray} The word array.
  1264. *
  1265. * @static
  1266. *
  1267. * @example
  1268. *
  1269. * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str);
  1270. */
  1271. parse: function (utf16Str) {
  1272. // Shortcut
  1273. var utf16StrLength = utf16Str.length;
  1274.  
  1275. // Convert
  1276. var words = [];
  1277. for (var i = 0; i < utf16StrLength; i++) {
  1278. words[i >>> 1] |= swapEndian(
  1279. utf16Str.charCodeAt(i) << (16 - (i % 2) * 16)
  1280. );
  1281. }
  1282.  
  1283. return WordArray.create(words, utf16StrLength * 2);
  1284. },
  1285. };
  1286.  
  1287. function swapEndian(word) {
  1288. return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff);
  1289. }
  1290. })();
  1291.  
  1292. (function () {
  1293. // Shortcuts
  1294. var C = CryptoJS;
  1295. var C_lib = C.lib;
  1296. var WordArray = C_lib.WordArray;
  1297. var C_enc = C.enc;
  1298.  
  1299. /**
  1300. * Base64 encoding strategy.
  1301. */
  1302. var Base64 = (C_enc.Base64 = {
  1303. /**
  1304. * Converts a word array to a Base64 string.
  1305. *
  1306. * @param {WordArray} wordArray The word array.
  1307. *
  1308. * @return {string} The Base64 string.
  1309. *
  1310. * @static
  1311. *
  1312. * @example
  1313. *
  1314. * var base64String = CryptoJS.enc.Base64.stringify(wordArray);
  1315. */
  1316. stringify: function (wordArray) {
  1317. // Shortcuts
  1318. var words = wordArray.words;
  1319. var sigBytes = wordArray.sigBytes;
  1320. var map = this._map;
  1321.  
  1322. // Clamp excess bits
  1323. wordArray.clamp();
  1324.  
  1325. // Convert
  1326. var base64Chars = [];
  1327. for (var i = 0; i < sigBytes; i += 3) {
  1328. var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  1329. var byte2 =
  1330. (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
  1331. var byte3 =
  1332. (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
  1333.  
  1334. var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
  1335.  
  1336. for (var j = 0; j < 4 && i + j * 0.75 < sigBytes; j++) {
  1337. base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
  1338. }
  1339. }
  1340.  
  1341. // Add padding
  1342. var paddingChar = map.charAt(64);
  1343. if (paddingChar) {
  1344. while (base64Chars.length % 4) {
  1345. base64Chars.push(paddingChar);
  1346. }
  1347. }
  1348.  
  1349. return base64Chars.join("");
  1350. },
  1351.  
  1352. /**
  1353. * Converts a Base64 string to a word array.
  1354. *
  1355. * @param {string} base64Str The Base64 string.
  1356. *
  1357. * @return {WordArray} The word array.
  1358. *
  1359. * @static
  1360. *
  1361. * @example
  1362. *
  1363. * var wordArray = CryptoJS.enc.Base64.parse(base64String);
  1364. */
  1365. parse: function (base64Str) {
  1366. // Shortcuts
  1367. var base64StrLength = base64Str.length;
  1368. var map = this._map;
  1369. var reverseMap = this._reverseMap;
  1370.  
  1371. if (!reverseMap) {
  1372. reverseMap = this._reverseMap = [];
  1373. for (var j = 0; j < map.length; j++) {
  1374. reverseMap[map.charCodeAt(j)] = j;
  1375. }
  1376. }
  1377.  
  1378. // Ignore padding
  1379. var paddingChar = map.charAt(64);
  1380. if (paddingChar) {
  1381. var paddingIndex = base64Str.indexOf(paddingChar);
  1382. if (paddingIndex !== -1) {
  1383. base64StrLength = paddingIndex;
  1384. }
  1385. }
  1386.  
  1387. // Convert
  1388. return parseLoop(base64Str, base64StrLength, reverseMap);
  1389. },
  1390.  
  1391. _map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
  1392. });
  1393.  
  1394. function parseLoop(base64Str, base64StrLength, reverseMap) {
  1395. var words = [];
  1396. var nBytes = 0;
  1397. for (var i = 0; i < base64StrLength; i++) {
  1398. if (i % 4) {
  1399. var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
  1400. var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
  1401. var bitsCombined = bits1 | bits2;
  1402. words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8);
  1403. nBytes++;
  1404. }
  1405. }
  1406. return WordArray.create(words, nBytes);
  1407. }
  1408. })();
  1409.  
  1410. (function () {
  1411. // Shortcuts
  1412. var C = CryptoJS;
  1413. var C_lib = C.lib;
  1414. var WordArray = C_lib.WordArray;
  1415. var C_enc = C.enc;
  1416.  
  1417. /**
  1418. * Base64url encoding strategy.
  1419. */
  1420. var Base64url = (C_enc.Base64url = {
  1421. /**
  1422. * Converts a word array to a Base64url string.
  1423. *
  1424. * @param {WordArray} wordArray The word array.
  1425. *
  1426. * @param {boolean} urlSafe Whether to use url safe
  1427. *
  1428. * @return {string} The Base64url string.
  1429. *
  1430. * @static
  1431. *
  1432. * @example
  1433. *
  1434. * var base64String = CryptoJS.enc.Base64url.stringify(wordArray);
  1435. */
  1436. stringify: function (wordArray, urlSafe) {
  1437. if (urlSafe === undefined) {
  1438. urlSafe = true;
  1439. }
  1440. // Shortcuts
  1441. var words = wordArray.words;
  1442. var sigBytes = wordArray.sigBytes;
  1443. var map = urlSafe ? this._safe_map : this._map;
  1444.  
  1445. // Clamp excess bits
  1446. wordArray.clamp();
  1447.  
  1448. // Convert
  1449. var base64Chars = [];
  1450. for (var i = 0; i < sigBytes; i += 3) {
  1451. var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  1452. var byte2 =
  1453. (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
  1454. var byte3 =
  1455. (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
  1456.  
  1457. var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
  1458.  
  1459. for (var j = 0; j < 4 && i + j * 0.75 < sigBytes; j++) {
  1460. base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
  1461. }
  1462. }
  1463.  
  1464. // Add padding
  1465. var paddingChar = map.charAt(64);
  1466. if (paddingChar) {
  1467. while (base64Chars.length % 4) {
  1468. base64Chars.push(paddingChar);
  1469. }
  1470. }
  1471.  
  1472. return base64Chars.join("");
  1473. },
  1474.  
  1475. /**
  1476. * Converts a Base64url string to a word array.
  1477. *
  1478. * @param {string} base64Str The Base64url string.
  1479. *
  1480. * @param {boolean} urlSafe Whether to use url safe
  1481. *
  1482. * @return {WordArray} The word array.
  1483. *
  1484. * @static
  1485. *
  1486. * @example
  1487. *
  1488. * var wordArray = CryptoJS.enc.Base64url.parse(base64String);
  1489. */
  1490. parse: function (base64Str, urlSafe) {
  1491. if (urlSafe === undefined) {
  1492. urlSafe = true;
  1493. }
  1494.  
  1495. // Shortcuts
  1496. var base64StrLength = base64Str.length;
  1497. var map = urlSafe ? this._safe_map : this._map;
  1498. var reverseMap = this._reverseMap;
  1499.  
  1500. if (!reverseMap) {
  1501. reverseMap = this._reverseMap = [];
  1502. for (var j = 0; j < map.length; j++) {
  1503. reverseMap[map.charCodeAt(j)] = j;
  1504. }
  1505. }
  1506.  
  1507. // Ignore padding
  1508. var paddingChar = map.charAt(64);
  1509. if (paddingChar) {
  1510. var paddingIndex = base64Str.indexOf(paddingChar);
  1511. if (paddingIndex !== -1) {
  1512. base64StrLength = paddingIndex;
  1513. }
  1514. }
  1515.  
  1516. // Convert
  1517. return parseLoop(base64Str, base64StrLength, reverseMap);
  1518. },
  1519.  
  1520. _map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
  1521. _safe_map:
  1522. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
  1523. });
  1524.  
  1525. function parseLoop(base64Str, base64StrLength, reverseMap) {
  1526. var words = [];
  1527. var nBytes = 0;
  1528. for (var i = 0; i < base64StrLength; i++) {
  1529. if (i % 4) {
  1530. var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
  1531. var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
  1532. var bitsCombined = bits1 | bits2;
  1533. words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8);
  1534. nBytes++;
  1535. }
  1536. }
  1537. return WordArray.create(words, nBytes);
  1538. }
  1539. })();
  1540.  
  1541. (function (Math) {
  1542. // Shortcuts
  1543. var C = CryptoJS;
  1544. var C_lib = C.lib;
  1545. var WordArray = C_lib.WordArray;
  1546. var Hasher = C_lib.Hasher;
  1547. var C_algo = C.algo;
  1548.  
  1549. // Constants table
  1550. var T = [];
  1551.  
  1552. // Compute constants
  1553. (function () {
  1554. for (var i = 0; i < 64; i++) {
  1555. T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0;
  1556. }
  1557. })();
  1558.  
  1559. /**
  1560. * MD5 hash algorithm.
  1561. */
  1562. var MD5 = (C_algo.MD5 = Hasher.extend({
  1563. _doReset: function () {
  1564. this._hash = new WordArray.init([
  1565. 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476,
  1566. ]);
  1567. },
  1568.  
  1569. _doProcessBlock: function (M, offset) {
  1570. // Swap endian
  1571. for (var i = 0; i < 16; i++) {
  1572. // Shortcuts
  1573. var offset_i = offset + i;
  1574. var M_offset_i = M[offset_i];
  1575.  
  1576. M[offset_i] =
  1577. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  1578. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00);
  1579. }
  1580.  
  1581. // Shortcuts
  1582. var H = this._hash.words;
  1583.  
  1584. var M_offset_0 = M[offset + 0];
  1585. var M_offset_1 = M[offset + 1];
  1586. var M_offset_2 = M[offset + 2];
  1587. var M_offset_3 = M[offset + 3];
  1588. var M_offset_4 = M[offset + 4];
  1589. var M_offset_5 = M[offset + 5];
  1590. var M_offset_6 = M[offset + 6];
  1591. var M_offset_7 = M[offset + 7];
  1592. var M_offset_8 = M[offset + 8];
  1593. var M_offset_9 = M[offset + 9];
  1594. var M_offset_10 = M[offset + 10];
  1595. var M_offset_11 = M[offset + 11];
  1596. var M_offset_12 = M[offset + 12];
  1597. var M_offset_13 = M[offset + 13];
  1598. var M_offset_14 = M[offset + 14];
  1599. var M_offset_15 = M[offset + 15];
  1600.  
  1601. // Working variables
  1602. var a = H[0];
  1603. var b = H[1];
  1604. var c = H[2];
  1605. var d = H[3];
  1606.  
  1607. // Computation
  1608. a = FF(a, b, c, d, M_offset_0, 7, T[0]);
  1609. d = FF(d, a, b, c, M_offset_1, 12, T[1]);
  1610. c = FF(c, d, a, b, M_offset_2, 17, T[2]);
  1611. b = FF(b, c, d, a, M_offset_3, 22, T[3]);
  1612. a = FF(a, b, c, d, M_offset_4, 7, T[4]);
  1613. d = FF(d, a, b, c, M_offset_5, 12, T[5]);
  1614. c = FF(c, d, a, b, M_offset_6, 17, T[6]);
  1615. b = FF(b, c, d, a, M_offset_7, 22, T[7]);
  1616. a = FF(a, b, c, d, M_offset_8, 7, T[8]);
  1617. d = FF(d, a, b, c, M_offset_9, 12, T[9]);
  1618. c = FF(c, d, a, b, M_offset_10, 17, T[10]);
  1619. b = FF(b, c, d, a, M_offset_11, 22, T[11]);
  1620. a = FF(a, b, c, d, M_offset_12, 7, T[12]);
  1621. d = FF(d, a, b, c, M_offset_13, 12, T[13]);
  1622. c = FF(c, d, a, b, M_offset_14, 17, T[14]);
  1623. b = FF(b, c, d, a, M_offset_15, 22, T[15]);
  1624.  
  1625. a = GG(a, b, c, d, M_offset_1, 5, T[16]);
  1626. d = GG(d, a, b, c, M_offset_6, 9, T[17]);
  1627. c = GG(c, d, a, b, M_offset_11, 14, T[18]);
  1628. b = GG(b, c, d, a, M_offset_0, 20, T[19]);
  1629. a = GG(a, b, c, d, M_offset_5, 5, T[20]);
  1630. d = GG(d, a, b, c, M_offset_10, 9, T[21]);
  1631. c = GG(c, d, a, b, M_offset_15, 14, T[22]);
  1632. b = GG(b, c, d, a, M_offset_4, 20, T[23]);
  1633. a = GG(a, b, c, d, M_offset_9, 5, T[24]);
  1634. d = GG(d, a, b, c, M_offset_14, 9, T[25]);
  1635. c = GG(c, d, a, b, M_offset_3, 14, T[26]);
  1636. b = GG(b, c, d, a, M_offset_8, 20, T[27]);
  1637. a = GG(a, b, c, d, M_offset_13, 5, T[28]);
  1638. d = GG(d, a, b, c, M_offset_2, 9, T[29]);
  1639. c = GG(c, d, a, b, M_offset_7, 14, T[30]);
  1640. b = GG(b, c, d, a, M_offset_12, 20, T[31]);
  1641.  
  1642. a = HH(a, b, c, d, M_offset_5, 4, T[32]);
  1643. d = HH(d, a, b, c, M_offset_8, 11, T[33]);
  1644. c = HH(c, d, a, b, M_offset_11, 16, T[34]);
  1645. b = HH(b, c, d, a, M_offset_14, 23, T[35]);
  1646. a = HH(a, b, c, d, M_offset_1, 4, T[36]);
  1647. d = HH(d, a, b, c, M_offset_4, 11, T[37]);
  1648. c = HH(c, d, a, b, M_offset_7, 16, T[38]);
  1649. b = HH(b, c, d, a, M_offset_10, 23, T[39]);
  1650. a = HH(a, b, c, d, M_offset_13, 4, T[40]);
  1651. d = HH(d, a, b, c, M_offset_0, 11, T[41]);
  1652. c = HH(c, d, a, b, M_offset_3, 16, T[42]);
  1653. b = HH(b, c, d, a, M_offset_6, 23, T[43]);
  1654. a = HH(a, b, c, d, M_offset_9, 4, T[44]);
  1655. d = HH(d, a, b, c, M_offset_12, 11, T[45]);
  1656. c = HH(c, d, a, b, M_offset_15, 16, T[46]);
  1657. b = HH(b, c, d, a, M_offset_2, 23, T[47]);
  1658.  
  1659. a = II(a, b, c, d, M_offset_0, 6, T[48]);
  1660. d = II(d, a, b, c, M_offset_7, 10, T[49]);
  1661. c = II(c, d, a, b, M_offset_14, 15, T[50]);
  1662. b = II(b, c, d, a, M_offset_5, 21, T[51]);
  1663. a = II(a, b, c, d, M_offset_12, 6, T[52]);
  1664. d = II(d, a, b, c, M_offset_3, 10, T[53]);
  1665. c = II(c, d, a, b, M_offset_10, 15, T[54]);
  1666. b = II(b, c, d, a, M_offset_1, 21, T[55]);
  1667. a = II(a, b, c, d, M_offset_8, 6, T[56]);
  1668. d = II(d, a, b, c, M_offset_15, 10, T[57]);
  1669. c = II(c, d, a, b, M_offset_6, 15, T[58]);
  1670. b = II(b, c, d, a, M_offset_13, 21, T[59]);
  1671. a = II(a, b, c, d, M_offset_4, 6, T[60]);
  1672. d = II(d, a, b, c, M_offset_11, 10, T[61]);
  1673. c = II(c, d, a, b, M_offset_2, 15, T[62]);
  1674. b = II(b, c, d, a, M_offset_9, 21, T[63]);
  1675.  
  1676. // Intermediate hash value
  1677. H[0] = (H[0] + a) | 0;
  1678. H[1] = (H[1] + b) | 0;
  1679. H[2] = (H[2] + c) | 0;
  1680. H[3] = (H[3] + d) | 0;
  1681. },
  1682.  
  1683. _doFinalize: function () {
  1684. // Shortcuts
  1685. var data = this._data;
  1686. var dataWords = data.words;
  1687.  
  1688. var nBitsTotal = this._nDataBytes * 8;
  1689. var nBitsLeft = data.sigBytes * 8;
  1690.  
  1691. // Add padding
  1692. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - (nBitsLeft % 32));
  1693.  
  1694. var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000);
  1695. var nBitsTotalL = nBitsTotal;
  1696. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] =
  1697. (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) |
  1698. (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00);
  1699. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] =
  1700. (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) |
  1701. (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00);
  1702.  
  1703. data.sigBytes = (dataWords.length + 1) * 4;
  1704.  
  1705. // Hash final blocks
  1706. this._process();
  1707.  
  1708. // Shortcuts
  1709. var hash = this._hash;
  1710. var H = hash.words;
  1711.  
  1712. // Swap endian
  1713. for (var i = 0; i < 4; i++) {
  1714. // Shortcut
  1715. var H_i = H[i];
  1716.  
  1717. H[i] =
  1718. (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  1719. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
  1720. }
  1721.  
  1722. // Return final computed hash
  1723. return hash;
  1724. },
  1725.  
  1726. clone: function () {
  1727. var clone = Hasher.clone.call(this);
  1728. clone._hash = this._hash.clone();
  1729.  
  1730. return clone;
  1731. },
  1732. }));
  1733.  
  1734. function FF(a, b, c, d, x, s, t) {
  1735. var n = a + ((b & c) | (~b & d)) + x + t;
  1736. return ((n << s) | (n >>> (32 - s))) + b;
  1737. }
  1738.  
  1739. function GG(a, b, c, d, x, s, t) {
  1740. var n = a + ((b & d) | (c & ~d)) + x + t;
  1741. return ((n << s) | (n >>> (32 - s))) + b;
  1742. }
  1743.  
  1744. function HH(a, b, c, d, x, s, t) {
  1745. var n = a + (b ^ c ^ d) + x + t;
  1746. return ((n << s) | (n >>> (32 - s))) + b;
  1747. }
  1748.  
  1749. function II(a, b, c, d, x, s, t) {
  1750. var n = a + (c ^ (b | ~d)) + x + t;
  1751. return ((n << s) | (n >>> (32 - s))) + b;
  1752. }
  1753.  
  1754. /**
  1755. * Shortcut function to the hasher's object interface.
  1756. *
  1757. * @param {WordArray|string} message The message to hash.
  1758. *
  1759. * @return {WordArray} The hash.
  1760. *
  1761. * @static
  1762. *
  1763. * @example
  1764. *
  1765. * var hash = CryptoJS.MD5('message');
  1766. * var hash = CryptoJS.MD5(wordArray);
  1767. */
  1768. C.MD5 = Hasher._createHelper(MD5);
  1769.  
  1770. /**
  1771. * Shortcut function to the HMAC's object interface.
  1772. *
  1773. * @param {WordArray|string} message The message to hash.
  1774. * @param {WordArray|string} key The secret key.
  1775. *
  1776. * @return {WordArray} The HMAC.
  1777. *
  1778. * @static
  1779. *
  1780. * @example
  1781. *
  1782. * var hmac = CryptoJS.HmacMD5(message, key);
  1783. */
  1784. C.HmacMD5 = Hasher._createHmacHelper(MD5);
  1785. })(Math);
  1786.  
  1787. (function () {
  1788. // Shortcuts
  1789. var C = CryptoJS;
  1790. var C_lib = C.lib;
  1791. var WordArray = C_lib.WordArray;
  1792. var Hasher = C_lib.Hasher;
  1793. var C_algo = C.algo;
  1794.  
  1795. // Reusable object
  1796. var W = [];
  1797.  
  1798. /**
  1799. * SHA-1 hash algorithm.
  1800. */
  1801. var SHA1 = (C_algo.SHA1 = Hasher.extend({
  1802. _doReset: function () {
  1803. this._hash = new WordArray.init([
  1804. 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0,
  1805. ]);
  1806. },
  1807.  
  1808. _doProcessBlock: function (M, offset) {
  1809. // Shortcut
  1810. var H = this._hash.words;
  1811.  
  1812. // Working variables
  1813. var a = H[0];
  1814. var b = H[1];
  1815. var c = H[2];
  1816. var d = H[3];
  1817. var e = H[4];
  1818.  
  1819. // Computation
  1820. for (var i = 0; i < 80; i++) {
  1821. if (i < 16) {
  1822. W[i] = M[offset + i] | 0;
  1823. } else {
  1824. var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
  1825. W[i] = (n << 1) | (n >>> 31);
  1826. }
  1827.  
  1828. var t = ((a << 5) | (a >>> 27)) + e + W[i];
  1829. if (i < 20) {
  1830. t += ((b & c) | (~b & d)) + 0x5a827999;
  1831. } else if (i < 40) {
  1832. t += (b ^ c ^ d) + 0x6ed9eba1;
  1833. } else if (i < 60) {
  1834. t += ((b & c) | (b & d) | (c & d)) - 0x70e44324;
  1835. } /* if (i < 80) */ else {
  1836. t += (b ^ c ^ d) - 0x359d3e2a;
  1837. }
  1838.  
  1839. e = d;
  1840. d = c;
  1841. c = (b << 30) | (b >>> 2);
  1842. b = a;
  1843. a = t;
  1844. }
  1845.  
  1846. // Intermediate hash value
  1847. H[0] = (H[0] + a) | 0;
  1848. H[1] = (H[1] + b) | 0;
  1849. H[2] = (H[2] + c) | 0;
  1850. H[3] = (H[3] + d) | 0;
  1851. H[4] = (H[4] + e) | 0;
  1852. },
  1853.  
  1854. _doFinalize: function () {
  1855. // Shortcuts
  1856. var data = this._data;
  1857. var dataWords = data.words;
  1858.  
  1859. var nBitsTotal = this._nDataBytes * 8;
  1860. var nBitsLeft = data.sigBytes * 8;
  1861.  
  1862. // Add padding
  1863. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - (nBitsLeft % 32));
  1864. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(
  1865. nBitsTotal / 0x100000000
  1866. );
  1867. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  1868. data.sigBytes = dataWords.length * 4;
  1869.  
  1870. // Hash final blocks
  1871. this._process();
  1872.  
  1873. // Return final computed hash
  1874. return this._hash;
  1875. },
  1876.  
  1877. clone: function () {
  1878. var clone = Hasher.clone.call(this);
  1879. clone._hash = this._hash.clone();
  1880.  
  1881. return clone;
  1882. },
  1883. }));
  1884.  
  1885. /**
  1886. * Shortcut function to the hasher's object interface.
  1887. *
  1888. * @param {WordArray|string} message The message to hash.
  1889. *
  1890. * @return {WordArray} The hash.
  1891. *
  1892. * @static
  1893. *
  1894. * @example
  1895. *
  1896. * var hash = CryptoJS.SHA1('message');
  1897. * var hash = CryptoJS.SHA1(wordArray);
  1898. */
  1899. C.SHA1 = Hasher._createHelper(SHA1);
  1900.  
  1901. /**
  1902. * Shortcut function to the HMAC's object interface.
  1903. *
  1904. * @param {WordArray|string} message The message to hash.
  1905. * @param {WordArray|string} key The secret key.
  1906. *
  1907. * @return {WordArray} The HMAC.
  1908. *
  1909. * @static
  1910. *
  1911. * @example
  1912. *
  1913. * var hmac = CryptoJS.HmacSHA1(message, key);
  1914. */
  1915. C.HmacSHA1 = Hasher._createHmacHelper(SHA1);
  1916. })();
  1917.  
  1918. (function (Math) {
  1919. // Shortcuts
  1920. var C = CryptoJS;
  1921. var C_lib = C.lib;
  1922. var WordArray = C_lib.WordArray;
  1923. var Hasher = C_lib.Hasher;
  1924. var C_algo = C.algo;
  1925.  
  1926. // Initialization and round constants tables
  1927. var H = [];
  1928. var K = [];
  1929.  
  1930. // Compute constants
  1931. (function () {
  1932. function isPrime(n) {
  1933. var sqrtN = Math.sqrt(n);
  1934. for (var factor = 2; factor <= sqrtN; factor++) {
  1935. if (!(n % factor)) {
  1936. return false;
  1937. }
  1938. }
  1939.  
  1940. return true;
  1941. }
  1942.  
  1943. function getFractionalBits(n) {
  1944. return ((n - (n | 0)) * 0x100000000) | 0;
  1945. }
  1946.  
  1947. var n = 2;
  1948. var nPrime = 0;
  1949. while (nPrime < 64) {
  1950. if (isPrime(n)) {
  1951. if (nPrime < 8) {
  1952. H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2));
  1953. }
  1954. K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3));
  1955.  
  1956. nPrime++;
  1957. }
  1958.  
  1959. n++;
  1960. }
  1961. })();
  1962.  
  1963. // Reusable object
  1964. var W = [];
  1965.  
  1966. /**
  1967. * SHA-256 hash algorithm.
  1968. */
  1969. var SHA256 = (C_algo.SHA256 = Hasher.extend({
  1970. _doReset: function () {
  1971. this._hash = new WordArray.init(H.slice(0));
  1972. },
  1973.  
  1974. _doProcessBlock: function (M, offset) {
  1975. // Shortcut
  1976. var H = this._hash.words;
  1977.  
  1978. // Working variables
  1979. var a = H[0];
  1980. var b = H[1];
  1981. var c = H[2];
  1982. var d = H[3];
  1983. var e = H[4];
  1984. var f = H[5];
  1985. var g = H[6];
  1986. var h = H[7];
  1987.  
  1988. // Computation
  1989. for (var i = 0; i < 64; i++) {
  1990. if (i < 16) {
  1991. W[i] = M[offset + i] | 0;
  1992. } else {
  1993. var gamma0x = W[i - 15];
  1994. var gamma0 =
  1995. ((gamma0x << 25) | (gamma0x >>> 7)) ^
  1996. ((gamma0x << 14) | (gamma0x >>> 18)) ^
  1997. (gamma0x >>> 3);
  1998.  
  1999. var gamma1x = W[i - 2];
  2000. var gamma1 =
  2001. ((gamma1x << 15) | (gamma1x >>> 17)) ^
  2002. ((gamma1x << 13) | (gamma1x >>> 19)) ^
  2003. (gamma1x >>> 10);
  2004.  
  2005. W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
  2006. }
  2007.  
  2008. var ch = (e & f) ^ (~e & g);
  2009. var maj = (a & b) ^ (a & c) ^ (b & c);
  2010.  
  2011. var sigma0 =
  2012. ((a << 30) | (a >>> 2)) ^
  2013. ((a << 19) | (a >>> 13)) ^
  2014. ((a << 10) | (a >>> 22));
  2015. var sigma1 =
  2016. ((e << 26) | (e >>> 6)) ^
  2017. ((e << 21) | (e >>> 11)) ^
  2018. ((e << 7) | (e >>> 25));
  2019.  
  2020. var t1 = h + sigma1 + ch + K[i] + W[i];
  2021. var t2 = sigma0 + maj;
  2022.  
  2023. h = g;
  2024. g = f;
  2025. f = e;
  2026. e = (d + t1) | 0;
  2027. d = c;
  2028. c = b;
  2029. b = a;
  2030. a = (t1 + t2) | 0;
  2031. }
  2032.  
  2033. // Intermediate hash value
  2034. H[0] = (H[0] + a) | 0;
  2035. H[1] = (H[1] + b) | 0;
  2036. H[2] = (H[2] + c) | 0;
  2037. H[3] = (H[3] + d) | 0;
  2038. H[4] = (H[4] + e) | 0;
  2039. H[5] = (H[5] + f) | 0;
  2040. H[6] = (H[6] + g) | 0;
  2041. H[7] = (H[7] + h) | 0;
  2042. },
  2043.  
  2044. _doFinalize: function () {
  2045. // Shortcuts
  2046. var data = this._data;
  2047. var dataWords = data.words;
  2048.  
  2049. var nBitsTotal = this._nDataBytes * 8;
  2050. var nBitsLeft = data.sigBytes * 8;
  2051.  
  2052. // Add padding
  2053. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - (nBitsLeft % 32));
  2054. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(
  2055. nBitsTotal / 0x100000000
  2056. );
  2057. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  2058. data.sigBytes = dataWords.length * 4;
  2059.  
  2060. // Hash final blocks
  2061. this._process();
  2062.  
  2063. // Return final computed hash
  2064. return this._hash;
  2065. },
  2066.  
  2067. clone: function () {
  2068. var clone = Hasher.clone.call(this);
  2069. clone._hash = this._hash.clone();
  2070.  
  2071. return clone;
  2072. },
  2073. }));
  2074.  
  2075. /**
  2076. * Shortcut function to the hasher's object interface.
  2077. *
  2078. * @param {WordArray|string} message The message to hash.
  2079. *
  2080. * @return {WordArray} The hash.
  2081. *
  2082. * @static
  2083. *
  2084. * @example
  2085. *
  2086. * var hash = CryptoJS.SHA256('message');
  2087. * var hash = CryptoJS.SHA256(wordArray);
  2088. */
  2089. C.SHA256 = Hasher._createHelper(SHA256);
  2090.  
  2091. /**
  2092. * Shortcut function to the HMAC's object interface.
  2093. *
  2094. * @param {WordArray|string} message The message to hash.
  2095. * @param {WordArray|string} key The secret key.
  2096. *
  2097. * @return {WordArray} The HMAC.
  2098. *
  2099. * @static
  2100. *
  2101. * @example
  2102. *
  2103. * var hmac = CryptoJS.HmacSHA256(message, key);
  2104. */
  2105. C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
  2106. })(Math);
  2107.  
  2108. (function () {
  2109. // Shortcuts
  2110. var C = CryptoJS;
  2111. var C_lib = C.lib;
  2112. var WordArray = C_lib.WordArray;
  2113. var C_algo = C.algo;
  2114. var SHA256 = C_algo.SHA256;
  2115.  
  2116. /**
  2117. * SHA-224 hash algorithm.
  2118. */
  2119. var SHA224 = (C_algo.SHA224 = SHA256.extend({
  2120. _doReset: function () {
  2121. this._hash = new WordArray.init([
  2122. 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31,
  2123. 0x68581511, 0x64f98fa7, 0xbefa4fa4,
  2124. ]);
  2125. },
  2126.  
  2127. _doFinalize: function () {
  2128. var hash = SHA256._doFinalize.call(this);
  2129.  
  2130. hash.sigBytes -= 4;
  2131.  
  2132. return hash;
  2133. },
  2134. }));
  2135.  
  2136. /**
  2137. * Shortcut function to the hasher's object interface.
  2138. *
  2139. * @param {WordArray|string} message The message to hash.
  2140. *
  2141. * @return {WordArray} The hash.
  2142. *
  2143. * @static
  2144. *
  2145. * @example
  2146. *
  2147. * var hash = CryptoJS.SHA224('message');
  2148. * var hash = CryptoJS.SHA224(wordArray);
  2149. */
  2150. C.SHA224 = SHA256._createHelper(SHA224);
  2151.  
  2152. /**
  2153. * Shortcut function to the HMAC's object interface.
  2154. *
  2155. * @param {WordArray|string} message The message to hash.
  2156. * @param {WordArray|string} key The secret key.
  2157. *
  2158. * @return {WordArray} The HMAC.
  2159. *
  2160. * @static
  2161. *
  2162. * @example
  2163. *
  2164. * var hmac = CryptoJS.HmacSHA224(message, key);
  2165. */
  2166. C.HmacSHA224 = SHA256._createHmacHelper(SHA224);
  2167. })();
  2168.  
  2169. (function () {
  2170. // Shortcuts
  2171. var C = CryptoJS;
  2172. var C_lib = C.lib;
  2173. var Hasher = C_lib.Hasher;
  2174. var C_x64 = C.x64;
  2175. var X64Word = C_x64.Word;
  2176. var X64WordArray = C_x64.WordArray;
  2177. var C_algo = C.algo;
  2178.  
  2179. function X64Word_create() {
  2180. return X64Word.create.apply(X64Word, arguments);
  2181. }
  2182.  
  2183. // Constants
  2184. var K = [
  2185. X64Word_create(0x428a2f98, 0xd728ae22),
  2186. X64Word_create(0x71374491, 0x23ef65cd),
  2187. X64Word_create(0xb5c0fbcf, 0xec4d3b2f),
  2188. X64Word_create(0xe9b5dba5, 0x8189dbbc),
  2189. X64Word_create(0x3956c25b, 0xf348b538),
  2190. X64Word_create(0x59f111f1, 0xb605d019),
  2191. X64Word_create(0x923f82a4, 0xaf194f9b),
  2192. X64Word_create(0xab1c5ed5, 0xda6d8118),
  2193. X64Word_create(0xd807aa98, 0xa3030242),
  2194. X64Word_create(0x12835b01, 0x45706fbe),
  2195. X64Word_create(0x243185be, 0x4ee4b28c),
  2196. X64Word_create(0x550c7dc3, 0xd5ffb4e2),
  2197. X64Word_create(0x72be5d74, 0xf27b896f),
  2198. X64Word_create(0x80deb1fe, 0x3b1696b1),
  2199. X64Word_create(0x9bdc06a7, 0x25c71235),
  2200. X64Word_create(0xc19bf174, 0xcf692694),
  2201. X64Word_create(0xe49b69c1, 0x9ef14ad2),
  2202. X64Word_create(0xefbe4786, 0x384f25e3),
  2203. X64Word_create(0x0fc19dc6, 0x8b8cd5b5),
  2204. X64Word_create(0x240ca1cc, 0x77ac9c65),
  2205. X64Word_create(0x2de92c6f, 0x592b0275),
  2206. X64Word_create(0x4a7484aa, 0x6ea6e483),
  2207. X64Word_create(0x5cb0a9dc, 0xbd41fbd4),
  2208. X64Word_create(0x76f988da, 0x831153b5),
  2209. X64Word_create(0x983e5152, 0xee66dfab),
  2210. X64Word_create(0xa831c66d, 0x2db43210),
  2211. X64Word_create(0xb00327c8, 0x98fb213f),
  2212. X64Word_create(0xbf597fc7, 0xbeef0ee4),
  2213. X64Word_create(0xc6e00bf3, 0x3da88fc2),
  2214. X64Word_create(0xd5a79147, 0x930aa725),
  2215. X64Word_create(0x06ca6351, 0xe003826f),
  2216. X64Word_create(0x14292967, 0x0a0e6e70),
  2217. X64Word_create(0x27b70a85, 0x46d22ffc),
  2218. X64Word_create(0x2e1b2138, 0x5c26c926),
  2219. X64Word_create(0x4d2c6dfc, 0x5ac42aed),
  2220. X64Word_create(0x53380d13, 0x9d95b3df),
  2221. X64Word_create(0x650a7354, 0x8baf63de),
  2222. X64Word_create(0x766a0abb, 0x3c77b2a8),
  2223. X64Word_create(0x81c2c92e, 0x47edaee6),
  2224. X64Word_create(0x92722c85, 0x1482353b),
  2225. X64Word_create(0xa2bfe8a1, 0x4cf10364),
  2226. X64Word_create(0xa81a664b, 0xbc423001),
  2227. X64Word_create(0xc24b8b70, 0xd0f89791),
  2228. X64Word_create(0xc76c51a3, 0x0654be30),
  2229. X64Word_create(0xd192e819, 0xd6ef5218),
  2230. X64Word_create(0xd6990624, 0x5565a910),
  2231. X64Word_create(0xf40e3585, 0x5771202a),
  2232. X64Word_create(0x106aa070, 0x32bbd1b8),
  2233. X64Word_create(0x19a4c116, 0xb8d2d0c8),
  2234. X64Word_create(0x1e376c08, 0x5141ab53),
  2235. X64Word_create(0x2748774c, 0xdf8eeb99),
  2236. X64Word_create(0x34b0bcb5, 0xe19b48a8),
  2237. X64Word_create(0x391c0cb3, 0xc5c95a63),
  2238. X64Word_create(0x4ed8aa4a, 0xe3418acb),
  2239. X64Word_create(0x5b9cca4f, 0x7763e373),
  2240. X64Word_create(0x682e6ff3, 0xd6b2b8a3),
  2241. X64Word_create(0x748f82ee, 0x5defb2fc),
  2242. X64Word_create(0x78a5636f, 0x43172f60),
  2243. X64Word_create(0x84c87814, 0xa1f0ab72),
  2244. X64Word_create(0x8cc70208, 0x1a6439ec),
  2245. X64Word_create(0x90befffa, 0x23631e28),
  2246. X64Word_create(0xa4506ceb, 0xde82bde9),
  2247. X64Word_create(0xbef9a3f7, 0xb2c67915),
  2248. X64Word_create(0xc67178f2, 0xe372532b),
  2249. X64Word_create(0xca273ece, 0xea26619c),
  2250. X64Word_create(0xd186b8c7, 0x21c0c207),
  2251. X64Word_create(0xeada7dd6, 0xcde0eb1e),
  2252. X64Word_create(0xf57d4f7f, 0xee6ed178),
  2253. X64Word_create(0x06f067aa, 0x72176fba),
  2254. X64Word_create(0x0a637dc5, 0xa2c898a6),
  2255. X64Word_create(0x113f9804, 0xbef90dae),
  2256. X64Word_create(0x1b710b35, 0x131c471b),
  2257. X64Word_create(0x28db77f5, 0x23047d84),
  2258. X64Word_create(0x32caab7b, 0x40c72493),
  2259. X64Word_create(0x3c9ebe0a, 0x15c9bebc),
  2260. X64Word_create(0x431d67c4, 0x9c100d4c),
  2261. X64Word_create(0x4cc5d4be, 0xcb3e42b6),
  2262. X64Word_create(0x597f299c, 0xfc657e2a),
  2263. X64Word_create(0x5fcb6fab, 0x3ad6faec),
  2264. X64Word_create(0x6c44198c, 0x4a475817),
  2265. ];
  2266.  
  2267. // Reusable objects
  2268. var W = [];
  2269. (function () {
  2270. for (var i = 0; i < 80; i++) {
  2271. W[i] = X64Word_create();
  2272. }
  2273. })();
  2274.  
  2275. /**
  2276. * SHA-512 hash algorithm.
  2277. */
  2278. var SHA512 = (C_algo.SHA512 = Hasher.extend({
  2279. _doReset: function () {
  2280. this._hash = new X64WordArray.init([
  2281. new X64Word.init(0x6a09e667, 0xf3bcc908),
  2282. new X64Word.init(0xbb67ae85, 0x84caa73b),
  2283. new X64Word.init(0x3c6ef372, 0xfe94f82b),
  2284. new X64Word.init(0xa54ff53a, 0x5f1d36f1),
  2285. new X64Word.init(0x510e527f, 0xade682d1),
  2286. new X64Word.init(0x9b05688c, 0x2b3e6c1f),
  2287. new X64Word.init(0x1f83d9ab, 0xfb41bd6b),
  2288. new X64Word.init(0x5be0cd19, 0x137e2179),
  2289. ]);
  2290. },
  2291.  
  2292. _doProcessBlock: function (M, offset) {
  2293. // Shortcuts
  2294. var H = this._hash.words;
  2295.  
  2296. var H0 = H[0];
  2297. var H1 = H[1];
  2298. var H2 = H[2];
  2299. var H3 = H[3];
  2300. var H4 = H[4];
  2301. var H5 = H[5];
  2302. var H6 = H[6];
  2303. var H7 = H[7];
  2304.  
  2305. var H0h = H0.high;
  2306. var H0l = H0.low;
  2307. var H1h = H1.high;
  2308. var H1l = H1.low;
  2309. var H2h = H2.high;
  2310. var H2l = H2.low;
  2311. var H3h = H3.high;
  2312. var H3l = H3.low;
  2313. var H4h = H4.high;
  2314. var H4l = H4.low;
  2315. var H5h = H5.high;
  2316. var H5l = H5.low;
  2317. var H6h = H6.high;
  2318. var H6l = H6.low;
  2319. var H7h = H7.high;
  2320. var H7l = H7.low;
  2321.  
  2322. // Working variables
  2323. var ah = H0h;
  2324. var al = H0l;
  2325. var bh = H1h;
  2326. var bl = H1l;
  2327. var ch = H2h;
  2328. var cl = H2l;
  2329. var dh = H3h;
  2330. var dl = H3l;
  2331. var eh = H4h;
  2332. var el = H4l;
  2333. var fh = H5h;
  2334. var fl = H5l;
  2335. var gh = H6h;
  2336. var gl = H6l;
  2337. var hh = H7h;
  2338. var hl = H7l;
  2339.  
  2340. // Rounds
  2341. for (var i = 0; i < 80; i++) {
  2342. var Wil;
  2343. var Wih;
  2344.  
  2345. // Shortcut
  2346. var Wi = W[i];
  2347.  
  2348. // Extend message
  2349. if (i < 16) {
  2350. Wih = Wi.high = M[offset + i * 2] | 0;
  2351. Wil = Wi.low = M[offset + i * 2 + 1] | 0;
  2352. } else {
  2353. // Gamma0
  2354. var gamma0x = W[i - 15];
  2355. var gamma0xh = gamma0x.high;
  2356. var gamma0xl = gamma0x.low;
  2357. var gamma0h =
  2358. ((gamma0xh >>> 1) | (gamma0xl << 31)) ^
  2359. ((gamma0xh >>> 8) | (gamma0xl << 24)) ^
  2360. (gamma0xh >>> 7);
  2361. var gamma0l =
  2362. ((gamma0xl >>> 1) | (gamma0xh << 31)) ^
  2363. ((gamma0xl >>> 8) | (gamma0xh << 24)) ^
  2364. ((gamma0xl >>> 7) | (gamma0xh << 25));
  2365.  
  2366. // Gamma1
  2367. var gamma1x = W[i - 2];
  2368. var gamma1xh = gamma1x.high;
  2369. var gamma1xl = gamma1x.low;
  2370. var gamma1h =
  2371. ((gamma1xh >>> 19) | (gamma1xl << 13)) ^
  2372. ((gamma1xh << 3) | (gamma1xl >>> 29)) ^
  2373. (gamma1xh >>> 6);
  2374. var gamma1l =
  2375. ((gamma1xl >>> 19) | (gamma1xh << 13)) ^
  2376. ((gamma1xl << 3) | (gamma1xh >>> 29)) ^
  2377. ((gamma1xl >>> 6) | (gamma1xh << 26));
  2378.  
  2379. // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
  2380. var Wi7 = W[i - 7];
  2381. var Wi7h = Wi7.high;
  2382. var Wi7l = Wi7.low;
  2383.  
  2384. var Wi16 = W[i - 16];
  2385. var Wi16h = Wi16.high;
  2386. var Wi16l = Wi16.low;
  2387.  
  2388. Wil = gamma0l + Wi7l;
  2389. Wih = gamma0h + Wi7h + (Wil >>> 0 < gamma0l >>> 0 ? 1 : 0);
  2390. Wil = Wil + gamma1l;
  2391. Wih = Wih + gamma1h + (Wil >>> 0 < gamma1l >>> 0 ? 1 : 0);
  2392. Wil = Wil + Wi16l;
  2393. Wih = Wih + Wi16h + (Wil >>> 0 < Wi16l >>> 0 ? 1 : 0);
  2394.  
  2395. Wi.high = Wih;
  2396. Wi.low = Wil;
  2397. }
  2398.  
  2399. var chh = (eh & fh) ^ (~eh & gh);
  2400. var chl = (el & fl) ^ (~el & gl);
  2401. var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch);
  2402. var majl = (al & bl) ^ (al & cl) ^ (bl & cl);
  2403.  
  2404. var sigma0h =
  2405. ((ah >>> 28) | (al << 4)) ^
  2406. ((ah << 30) | (al >>> 2)) ^
  2407. ((ah << 25) | (al >>> 7));
  2408. var sigma0l =
  2409. ((al >>> 28) | (ah << 4)) ^
  2410. ((al << 30) | (ah >>> 2)) ^
  2411. ((al << 25) | (ah >>> 7));
  2412. var sigma1h =
  2413. ((eh >>> 14) | (el << 18)) ^
  2414. ((eh >>> 18) | (el << 14)) ^
  2415. ((eh << 23) | (el >>> 9));
  2416. var sigma1l =
  2417. ((el >>> 14) | (eh << 18)) ^
  2418. ((el >>> 18) | (eh << 14)) ^
  2419. ((el << 23) | (eh >>> 9));
  2420.  
  2421. // t1 = h + sigma1 + ch + K[i] + W[i]
  2422. var Ki = K[i];
  2423. var Kih = Ki.high;
  2424. var Kil = Ki.low;
  2425.  
  2426. var t1l = hl + sigma1l;
  2427. var t1h = hh + sigma1h + (t1l >>> 0 < hl >>> 0 ? 1 : 0);
  2428. var t1l = t1l + chl;
  2429. var t1h = t1h + chh + (t1l >>> 0 < chl >>> 0 ? 1 : 0);
  2430. var t1l = t1l + Kil;
  2431. var t1h = t1h + Kih + (t1l >>> 0 < Kil >>> 0 ? 1 : 0);
  2432. var t1l = t1l + Wil;
  2433. var t1h = t1h + Wih + (t1l >>> 0 < Wil >>> 0 ? 1 : 0);
  2434.  
  2435. // t2 = sigma0 + maj
  2436. var t2l = sigma0l + majl;
  2437. var t2h = sigma0h + majh + (t2l >>> 0 < sigma0l >>> 0 ? 1 : 0);
  2438.  
  2439. // Update working variables
  2440. hh = gh;
  2441. hl = gl;
  2442. gh = fh;
  2443. gl = fl;
  2444. fh = eh;
  2445. fl = el;
  2446. el = (dl + t1l) | 0;
  2447. eh = (dh + t1h + (el >>> 0 < dl >>> 0 ? 1 : 0)) | 0;
  2448. dh = ch;
  2449. dl = cl;
  2450. ch = bh;
  2451. cl = bl;
  2452. bh = ah;
  2453. bl = al;
  2454. al = (t1l + t2l) | 0;
  2455. ah = (t1h + t2h + (al >>> 0 < t1l >>> 0 ? 1 : 0)) | 0;
  2456. }
  2457.  
  2458. // Intermediate hash value
  2459. H0l = H0.low = H0l + al;
  2460. H0.high = H0h + ah + (H0l >>> 0 < al >>> 0 ? 1 : 0);
  2461. H1l = H1.low = H1l + bl;
  2462. H1.high = H1h + bh + (H1l >>> 0 < bl >>> 0 ? 1 : 0);
  2463. H2l = H2.low = H2l + cl;
  2464. H2.high = H2h + ch + (H2l >>> 0 < cl >>> 0 ? 1 : 0);
  2465. H3l = H3.low = H3l + dl;
  2466. H3.high = H3h + dh + (H3l >>> 0 < dl >>> 0 ? 1 : 0);
  2467. H4l = H4.low = H4l + el;
  2468. H4.high = H4h + eh + (H4l >>> 0 < el >>> 0 ? 1 : 0);
  2469. H5l = H5.low = H5l + fl;
  2470. H5.high = H5h + fh + (H5l >>> 0 < fl >>> 0 ? 1 : 0);
  2471. H6l = H6.low = H6l + gl;
  2472. H6.high = H6h + gh + (H6l >>> 0 < gl >>> 0 ? 1 : 0);
  2473. H7l = H7.low = H7l + hl;
  2474. H7.high = H7h + hh + (H7l >>> 0 < hl >>> 0 ? 1 : 0);
  2475. },
  2476.  
  2477. _doFinalize: function () {
  2478. // Shortcuts
  2479. var data = this._data;
  2480. var dataWords = data.words;
  2481.  
  2482. var nBitsTotal = this._nDataBytes * 8;
  2483. var nBitsLeft = data.sigBytes * 8;
  2484.  
  2485. // Add padding
  2486. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - (nBitsLeft % 32));
  2487. dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(
  2488. nBitsTotal / 0x100000000
  2489. );
  2490. dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal;
  2491. data.sigBytes = dataWords.length * 4;
  2492.  
  2493. // Hash final blocks
  2494. this._process();
  2495.  
  2496. // Convert hash to 32-bit word array before returning
  2497. var hash = this._hash.toX32();
  2498.  
  2499. // Return final computed hash
  2500. return hash;
  2501. },
  2502.  
  2503. clone: function () {
  2504. var clone = Hasher.clone.call(this);
  2505. clone._hash = this._hash.clone();
  2506.  
  2507. return clone;
  2508. },
  2509.  
  2510. blockSize: 1024 / 32,
  2511. }));
  2512.  
  2513. /**
  2514. * Shortcut function to the hasher's object interface.
  2515. *
  2516. * @param {WordArray|string} message The message to hash.
  2517. *
  2518. * @return {WordArray} The hash.
  2519. *
  2520. * @static
  2521. *
  2522. * @example
  2523. *
  2524. * var hash = CryptoJS.SHA512('message');
  2525. * var hash = CryptoJS.SHA512(wordArray);
  2526. */
  2527. C.SHA512 = Hasher._createHelper(SHA512);
  2528.  
  2529. /**
  2530. * Shortcut function to the HMAC's object interface.
  2531. *
  2532. * @param {WordArray|string} message The message to hash.
  2533. * @param {WordArray|string} key The secret key.
  2534. *
  2535. * @return {WordArray} The HMAC.
  2536. *
  2537. * @static
  2538. *
  2539. * @example
  2540. *
  2541. * var hmac = CryptoJS.HmacSHA512(message, key);
  2542. */
  2543. C.HmacSHA512 = Hasher._createHmacHelper(SHA512);
  2544. })();
  2545.  
  2546. (function () {
  2547. // Shortcuts
  2548. var C = CryptoJS;
  2549. var C_x64 = C.x64;
  2550. var X64Word = C_x64.Word;
  2551. var X64WordArray = C_x64.WordArray;
  2552. var C_algo = C.algo;
  2553. var SHA512 = C_algo.SHA512;
  2554.  
  2555. /**
  2556. * SHA-384 hash algorithm.
  2557. */
  2558. var SHA384 = (C_algo.SHA384 = SHA512.extend({
  2559. _doReset: function () {
  2560. this._hash = new X64WordArray.init([
  2561. new X64Word.init(0xcbbb9d5d, 0xc1059ed8),
  2562. new X64Word.init(0x629a292a, 0x367cd507),
  2563. new X64Word.init(0x9159015a, 0x3070dd17),
  2564. new X64Word.init(0x152fecd8, 0xf70e5939),
  2565. new X64Word.init(0x67332667, 0xffc00b31),
  2566. new X64Word.init(0x8eb44a87, 0x68581511),
  2567. new X64Word.init(0xdb0c2e0d, 0x64f98fa7),
  2568. new X64Word.init(0x47b5481d, 0xbefa4fa4),
  2569. ]);
  2570. },
  2571.  
  2572. _doFinalize: function () {
  2573. var hash = SHA512._doFinalize.call(this);
  2574.  
  2575. hash.sigBytes -= 16;
  2576.  
  2577. return hash;
  2578. },
  2579. }));
  2580.  
  2581. /**
  2582. * Shortcut function to the hasher's object interface.
  2583. *
  2584. * @param {WordArray|string} message The message to hash.
  2585. *
  2586. * @return {WordArray} The hash.
  2587. *
  2588. * @static
  2589. *
  2590. * @example
  2591. *
  2592. * var hash = CryptoJS.SHA384('message');
  2593. * var hash = CryptoJS.SHA384(wordArray);
  2594. */
  2595. C.SHA384 = SHA512._createHelper(SHA384);
  2596.  
  2597. /**
  2598. * Shortcut function to the HMAC's object interface.
  2599. *
  2600. * @param {WordArray|string} message The message to hash.
  2601. * @param {WordArray|string} key The secret key.
  2602. *
  2603. * @return {WordArray} The HMAC.
  2604. *
  2605. * @static
  2606. *
  2607. * @example
  2608. *
  2609. * var hmac = CryptoJS.HmacSHA384(message, key);
  2610. */
  2611. C.HmacSHA384 = SHA512._createHmacHelper(SHA384);
  2612. })();
  2613.  
  2614. (function (Math) {
  2615. // Shortcuts
  2616. var C = CryptoJS;
  2617. var C_lib = C.lib;
  2618. var WordArray = C_lib.WordArray;
  2619. var Hasher = C_lib.Hasher;
  2620. var C_x64 = C.x64;
  2621. var X64Word = C_x64.Word;
  2622. var C_algo = C.algo;
  2623.  
  2624. // Constants tables
  2625. var RHO_OFFSETS = [];
  2626. var PI_INDEXES = [];
  2627. var ROUND_CONSTANTS = [];
  2628.  
  2629. // Compute Constants
  2630. (function () {
  2631. // Compute rho offset constants
  2632. var x = 1,
  2633. y = 0;
  2634. for (var t = 0; t < 24; t++) {
  2635. RHO_OFFSETS[x + 5 * y] = (((t + 1) * (t + 2)) / 2) % 64;
  2636.  
  2637. var newX = y % 5;
  2638. var newY = (2 * x + 3 * y) % 5;
  2639. x = newX;
  2640. y = newY;
  2641. }
  2642.  
  2643. // Compute pi index constants
  2644. for (var x = 0; x < 5; x++) {
  2645. for (var y = 0; y < 5; y++) {
  2646. PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5;
  2647. }
  2648. }
  2649.  
  2650. // Compute round constants
  2651. var LFSR = 0x01;
  2652. for (var i = 0; i < 24; i++) {
  2653. var roundConstantMsw = 0;
  2654. var roundConstantLsw = 0;
  2655.  
  2656. for (var j = 0; j < 7; j++) {
  2657. if (LFSR & 0x01) {
  2658. var bitPosition = (1 << j) - 1;
  2659. if (bitPosition < 32) {
  2660. roundConstantLsw ^= 1 << bitPosition;
  2661. } /* if (bitPosition >= 32) */ else {
  2662. roundConstantMsw ^= 1 << (bitPosition - 32);
  2663. }
  2664. }
  2665.  
  2666. // Compute next LFSR
  2667. if (LFSR & 0x80) {
  2668. // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1
  2669. LFSR = (LFSR << 1) ^ 0x71;
  2670. } else {
  2671. LFSR <<= 1;
  2672. }
  2673. }
  2674.  
  2675. ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw);
  2676. }
  2677. })();
  2678.  
  2679. // Reusable objects for temporary values
  2680. var T = [];
  2681. (function () {
  2682. for (var i = 0; i < 25; i++) {
  2683. T[i] = X64Word.create();
  2684. }
  2685. })();
  2686.  
  2687. /**
  2688. * SHA-3 hash algorithm.
  2689. */
  2690. var SHA3 = (C_algo.SHA3 = Hasher.extend({
  2691. /**
  2692. * Configuration options.
  2693. *
  2694. * @property {number} outputLength
  2695. * The desired number of bits in the output hash.
  2696. * Only values permitted are: 224, 256, 384, 512.
  2697. * Default: 512
  2698. */
  2699. cfg: Hasher.cfg.extend({
  2700. outputLength: 512,
  2701. }),
  2702.  
  2703. _doReset: function () {
  2704. var state = (this._state = []);
  2705. for (var i = 0; i < 25; i++) {
  2706. state[i] = new X64Word.init();
  2707. }
  2708.  
  2709. this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32;
  2710. },
  2711.  
  2712. _doProcessBlock: function (M, offset) {
  2713. // Shortcuts
  2714. var state = this._state;
  2715. var nBlockSizeLanes = this.blockSize / 2;
  2716.  
  2717. // Absorb
  2718. for (var i = 0; i < nBlockSizeLanes; i++) {
  2719. // Shortcuts
  2720. var M2i = M[offset + 2 * i];
  2721. var M2i1 = M[offset + 2 * i + 1];
  2722.  
  2723. // Swap endian
  2724. M2i =
  2725. (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) |
  2726. (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00);
  2727. M2i1 =
  2728. (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) |
  2729. (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00);
  2730.  
  2731. // Absorb message into state
  2732. var lane = state[i];
  2733. lane.high ^= M2i1;
  2734. lane.low ^= M2i;
  2735. }
  2736.  
  2737. // Rounds
  2738. for (var round = 0; round < 24; round++) {
  2739. // Theta
  2740. for (var x = 0; x < 5; x++) {
  2741. // Mix column lanes
  2742. var tMsw = 0,
  2743. tLsw = 0;
  2744. for (var y = 0; y < 5; y++) {
  2745. var lane = state[x + 5 * y];
  2746. tMsw ^= lane.high;
  2747. tLsw ^= lane.low;
  2748. }
  2749.  
  2750. // Temporary values
  2751. var Tx = T[x];
  2752. Tx.high = tMsw;
  2753. Tx.low = tLsw;
  2754. }
  2755. for (var x = 0; x < 5; x++) {
  2756. // Shortcuts
  2757. var Tx4 = T[(x + 4) % 5];
  2758. var Tx1 = T[(x + 1) % 5];
  2759. var Tx1Msw = Tx1.high;
  2760. var Tx1Lsw = Tx1.low;
  2761.  
  2762. // Mix surrounding columns
  2763. var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31));
  2764. var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31));
  2765. for (var y = 0; y < 5; y++) {
  2766. var lane = state[x + 5 * y];
  2767. lane.high ^= tMsw;
  2768. lane.low ^= tLsw;
  2769. }
  2770. }
  2771.  
  2772. // Rho Pi
  2773. for (var laneIndex = 1; laneIndex < 25; laneIndex++) {
  2774. var tMsw;
  2775. var tLsw;
  2776.  
  2777. // Shortcuts
  2778. var lane = state[laneIndex];
  2779. var laneMsw = lane.high;
  2780. var laneLsw = lane.low;
  2781. var rhoOffset = RHO_OFFSETS[laneIndex];
  2782.  
  2783. // Rotate lanes
  2784. if (rhoOffset < 32) {
  2785. tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset));
  2786. tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset));
  2787. } /* if (rhoOffset >= 32) */ else {
  2788. tMsw =
  2789. (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset));
  2790. tLsw =
  2791. (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset));
  2792. }
  2793.  
  2794. // Transpose lanes
  2795. var TPiLane = T[PI_INDEXES[laneIndex]];
  2796. TPiLane.high = tMsw;
  2797. TPiLane.low = tLsw;
  2798. }
  2799.  
  2800. // Rho pi at x = y = 0
  2801. var T0 = T[0];
  2802. var state0 = state[0];
  2803. T0.high = state0.high;
  2804. T0.low = state0.low;
  2805.  
  2806. // Chi
  2807. for (var x = 0; x < 5; x++) {
  2808. for (var y = 0; y < 5; y++) {
  2809. // Shortcuts
  2810. var laneIndex = x + 5 * y;
  2811. var lane = state[laneIndex];
  2812. var TLane = T[laneIndex];
  2813. var Tx1Lane = T[((x + 1) % 5) + 5 * y];
  2814. var Tx2Lane = T[((x + 2) % 5) + 5 * y];
  2815.  
  2816. // Mix rows
  2817. lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high);
  2818. lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low);
  2819. }
  2820. }
  2821.  
  2822. // Iota
  2823. var lane = state[0];
  2824. var roundConstant = ROUND_CONSTANTS[round];
  2825. lane.high ^= roundConstant.high;
  2826. lane.low ^= roundConstant.low;
  2827. }
  2828. },
  2829.  
  2830. _doFinalize: function () {
  2831. // Shortcuts
  2832. var data = this._data;
  2833. var dataWords = data.words;
  2834. var nBitsTotal = this._nDataBytes * 8;
  2835. var nBitsLeft = data.sigBytes * 8;
  2836. var blockSizeBits = this.blockSize * 32;
  2837.  
  2838. // Add padding
  2839. dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - (nBitsLeft % 32));
  2840. dataWords[
  2841. ((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) -
  2842. 1
  2843. ] |= 0x80;
  2844. data.sigBytes = dataWords.length * 4;
  2845.  
  2846. // Hash final blocks
  2847. this._process();
  2848.  
  2849. // Shortcuts
  2850. var state = this._state;
  2851. var outputLengthBytes = this.cfg.outputLength / 8;
  2852. var outputLengthLanes = outputLengthBytes / 8;
  2853.  
  2854. // Squeeze
  2855. var hashWords = [];
  2856. for (var i = 0; i < outputLengthLanes; i++) {
  2857. // Shortcuts
  2858. var lane = state[i];
  2859. var laneMsw = lane.high;
  2860. var laneLsw = lane.low;
  2861.  
  2862. // Swap endian
  2863. laneMsw =
  2864. (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) |
  2865. (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00);
  2866. laneLsw =
  2867. (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) |
  2868. (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00);
  2869.  
  2870. // Squeeze state to retrieve hash
  2871. hashWords.push(laneLsw);
  2872. hashWords.push(laneMsw);
  2873. }
  2874.  
  2875. // Return final computed hash
  2876. return new WordArray.init(hashWords, outputLengthBytes);
  2877. },
  2878.  
  2879. clone: function () {
  2880. var clone = Hasher.clone.call(this);
  2881.  
  2882. var state = (clone._state = this._state.slice(0));
  2883. for (var i = 0; i < 25; i++) {
  2884. state[i] = state[i].clone();
  2885. }
  2886.  
  2887. return clone;
  2888. },
  2889. }));
  2890.  
  2891. /**
  2892. * Shortcut function to the hasher's object interface.
  2893. *
  2894. * @param {WordArray|string} message The message to hash.
  2895. *
  2896. * @return {WordArray} The hash.
  2897. *
  2898. * @static
  2899. *
  2900. * @example
  2901. *
  2902. * var hash = CryptoJS.SHA3('message');
  2903. * var hash = CryptoJS.SHA3(wordArray);
  2904. */
  2905. C.SHA3 = Hasher._createHelper(SHA3);
  2906.  
  2907. /**
  2908. * Shortcut function to the HMAC's object interface.
  2909. *
  2910. * @param {WordArray|string} message The message to hash.
  2911. * @param {WordArray|string} key The secret key.
  2912. *
  2913. * @return {WordArray} The HMAC.
  2914. *
  2915. * @static
  2916. *
  2917. * @example
  2918. *
  2919. * var hmac = CryptoJS.HmacSHA3(message, key);
  2920. */
  2921. C.HmacSHA3 = Hasher._createHmacHelper(SHA3);
  2922. })(Math);
  2923.  
  2924. /** @preserve
  2925. (c) 2012 by Cédric Mesnil. All rights reserved.
  2926.  
  2927. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  2928.  
  2929. - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2930. - 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.
  2931.  
  2932. 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 (INCLUDING, 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.
  2933. */
  2934.  
  2935. (function (Math) {
  2936. // Shortcuts
  2937. var C = CryptoJS;
  2938. var C_lib = C.lib;
  2939. var WordArray = C_lib.WordArray;
  2940. var Hasher = C_lib.Hasher;
  2941. var C_algo = C.algo;
  2942.  
  2943. // Constants table
  2944. var _zl = WordArray.create([
  2945. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6,
  2946. 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6,
  2947. 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0,
  2948. 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13,
  2949. ]);
  2950. var _zr = WordArray.create([
  2951. 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13,
  2952. 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2,
  2953. 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12,
  2954. 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11,
  2955. ]);
  2956. var _sl = WordArray.create([
  2957. 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11,
  2958. 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8,
  2959. 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5,
  2960. 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6,
  2961. ]);
  2962. var _sr = WordArray.create([
  2963. 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12,
  2964. 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13,
  2965. 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15,
  2966. 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11,
  2967. ]);
  2968.  
  2969. var _hl = WordArray.create([
  2970. 0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e,
  2971. ]);
  2972. var _hr = WordArray.create([
  2973. 0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000,
  2974. ]);
  2975.  
  2976. /**
  2977. * RIPEMD160 hash algorithm.
  2978. */
  2979. var RIPEMD160 = (C_algo.RIPEMD160 = Hasher.extend({
  2980. _doReset: function () {
  2981. this._hash = WordArray.create([
  2982. 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0,
  2983. ]);
  2984. },
  2985.  
  2986. _doProcessBlock: function (M, offset) {
  2987. // Swap endian
  2988. for (var i = 0; i < 16; i++) {
  2989. // Shortcuts
  2990. var offset_i = offset + i;
  2991. var M_offset_i = M[offset_i];
  2992.  
  2993. // Swap
  2994. M[offset_i] =
  2995. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  2996. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00);
  2997. }
  2998. // Shortcut
  2999. var H = this._hash.words;
  3000. var hl = _hl.words;
  3001. var hr = _hr.words;
  3002. var zl = _zl.words;
  3003. var zr = _zr.words;
  3004. var sl = _sl.words;
  3005. var sr = _sr.words;
  3006.  
  3007. // Working variables
  3008. var al, bl, cl, dl, el;
  3009. var ar, br, cr, dr, er;
  3010.  
  3011. ar = al = H[0];
  3012. br = bl = H[1];
  3013. cr = cl = H[2];
  3014. dr = dl = H[3];
  3015. er = el = H[4];
  3016. // Computation
  3017. var t;
  3018. for (var i = 0; i < 80; i += 1) {
  3019. t = (al + M[offset + zl[i]]) | 0;
  3020. if (i < 16) {
  3021. t += f1(bl, cl, dl) + hl[0];
  3022. } else if (i < 32) {
  3023. t += f2(bl, cl, dl) + hl[1];
  3024. } else if (i < 48) {
  3025. t += f3(bl, cl, dl) + hl[2];
  3026. } else if (i < 64) {
  3027. t += f4(bl, cl, dl) + hl[3];
  3028. } else {
  3029. // if (i<80) {
  3030. t += f5(bl, cl, dl) + hl[4];
  3031. }
  3032. t = t | 0;
  3033. t = rotl(t, sl[i]);
  3034. t = (t + el) | 0;
  3035. al = el;
  3036. el = dl;
  3037. dl = rotl(cl, 10);
  3038. cl = bl;
  3039. bl = t;
  3040.  
  3041. t = (ar + M[offset + zr[i]]) | 0;
  3042. if (i < 16) {
  3043. t += f5(br, cr, dr) + hr[0];
  3044. } else if (i < 32) {
  3045. t += f4(br, cr, dr) + hr[1];
  3046. } else if (i < 48) {
  3047. t += f3(br, cr, dr) + hr[2];
  3048. } else if (i < 64) {
  3049. t += f2(br, cr, dr) + hr[3];
  3050. } else {
  3051. // if (i<80) {
  3052. t += f1(br, cr, dr) + hr[4];
  3053. }
  3054. t = t | 0;
  3055. t = rotl(t, sr[i]);
  3056. t = (t + er) | 0;
  3057. ar = er;
  3058. er = dr;
  3059. dr = rotl(cr, 10);
  3060. cr = br;
  3061. br = t;
  3062. }
  3063. // Intermediate hash value
  3064. t = (H[1] + cl + dr) | 0;
  3065. H[1] = (H[2] + dl + er) | 0;
  3066. H[2] = (H[3] + el + ar) | 0;
  3067. H[3] = (H[4] + al + br) | 0;
  3068. H[4] = (H[0] + bl + cr) | 0;
  3069. H[0] = t;
  3070. },
  3071.  
  3072. _doFinalize: function () {
  3073. // Shortcuts
  3074. var data = this._data;
  3075. var dataWords = data.words;
  3076.  
  3077. var nBitsTotal = this._nDataBytes * 8;
  3078. var nBitsLeft = data.sigBytes * 8;
  3079.  
  3080. // Add padding
  3081. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - (nBitsLeft % 32));
  3082. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] =
  3083. (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) |
  3084. (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00);
  3085. data.sigBytes = (dataWords.length + 1) * 4;
  3086.  
  3087. // Hash final blocks
  3088. this._process();
  3089.  
  3090. // Shortcuts
  3091. var hash = this._hash;
  3092. var H = hash.words;
  3093.  
  3094. // Swap endian
  3095. for (var i = 0; i < 5; i++) {
  3096. // Shortcut
  3097. var H_i = H[i];
  3098.  
  3099. // Swap
  3100. H[i] =
  3101. (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  3102. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
  3103. }
  3104.  
  3105. // Return final computed hash
  3106. return hash;
  3107. },
  3108.  
  3109. clone: function () {
  3110. var clone = Hasher.clone.call(this);
  3111. clone._hash = this._hash.clone();
  3112.  
  3113. return clone;
  3114. },
  3115. }));
  3116.  
  3117. function f1(x, y, z) {
  3118. return x ^ y ^ z;
  3119. }
  3120.  
  3121. function f2(x, y, z) {
  3122. return (x & y) | (~x & z);
  3123. }
  3124.  
  3125. function f3(x, y, z) {
  3126. return (x | ~y) ^ z;
  3127. }
  3128.  
  3129. function f4(x, y, z) {
  3130. return (x & z) | (y & ~z);
  3131. }
  3132.  
  3133. function f5(x, y, z) {
  3134. return x ^ (y | ~z);
  3135. }
  3136.  
  3137. function rotl(x, n) {
  3138. return (x << n) | (x >>> (32 - n));
  3139. }
  3140.  
  3141. /**
  3142. * Shortcut function to the hasher's object interface.
  3143. *
  3144. * @param {WordArray|string} message The message to hash.
  3145. *
  3146. * @return {WordArray} The hash.
  3147. *
  3148. * @static
  3149. *
  3150. * @example
  3151. *
  3152. * var hash = CryptoJS.RIPEMD160('message');
  3153. * var hash = CryptoJS.RIPEMD160(wordArray);
  3154. */
  3155. C.RIPEMD160 = Hasher._createHelper(RIPEMD160);
  3156.  
  3157. /**
  3158. * Shortcut function to the HMAC's object interface.
  3159. *
  3160. * @param {WordArray|string} message The message to hash.
  3161. * @param {WordArray|string} key The secret key.
  3162. *
  3163. * @return {WordArray} The HMAC.
  3164. *
  3165. * @static
  3166. *
  3167. * @example
  3168. *
  3169. * var hmac = CryptoJS.HmacRIPEMD160(message, key);
  3170. */
  3171. C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160);
  3172. })(Math);
  3173.  
  3174. (function () {
  3175. // Shortcuts
  3176. var C = CryptoJS;
  3177. var C_lib = C.lib;
  3178. var Base = C_lib.Base;
  3179. var C_enc = C.enc;
  3180. var Utf8 = C_enc.Utf8;
  3181. var C_algo = C.algo;
  3182.  
  3183. /**
  3184. * HMAC algorithm.
  3185. */
  3186. var HMAC = (C_algo.HMAC = Base.extend({
  3187. /**
  3188. * Initializes a newly created HMAC.
  3189. *
  3190. * @param {Hasher} hasher The hash algorithm to use.
  3191. * @param {WordArray|string} key The secret key.
  3192. *
  3193. * @example
  3194. *
  3195. * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
  3196. */
  3197. init: function (hasher, key) {
  3198. // Init hasher
  3199. hasher = this._hasher = new hasher.init();
  3200.  
  3201. // Convert string to WordArray, else assume WordArray already
  3202. if (typeof key == "string") {
  3203. key = Utf8.parse(key);
  3204. }
  3205.  
  3206. // Shortcuts
  3207. var hasherBlockSize = hasher.blockSize;
  3208. var hasherBlockSizeBytes = hasherBlockSize * 4;
  3209.  
  3210. // Allow arbitrary length keys
  3211. if (key.sigBytes > hasherBlockSizeBytes) {
  3212. key = hasher.finalize(key);
  3213. }
  3214.  
  3215. // Clamp excess bits
  3216. key.clamp();
  3217.  
  3218. // Clone key for inner and outer pads
  3219. var oKey = (this._oKey = key.clone());
  3220. var iKey = (this._iKey = key.clone());
  3221.  
  3222. // Shortcuts
  3223. var oKeyWords = oKey.words;
  3224. var iKeyWords = iKey.words;
  3225.  
  3226. // XOR keys with pad constants
  3227. for (var i = 0; i < hasherBlockSize; i++) {
  3228. oKeyWords[i] ^= 0x5c5c5c5c;
  3229. iKeyWords[i] ^= 0x36363636;
  3230. }
  3231. oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes;
  3232.  
  3233. // Set initial values
  3234. this.reset();
  3235. },
  3236.  
  3237. /**
  3238. * Resets this HMAC to its initial state.
  3239. *
  3240. * @example
  3241. *
  3242. * hmacHasher.reset();
  3243. */
  3244. reset: function () {
  3245. // Shortcut
  3246. var hasher = this._hasher;
  3247.  
  3248. // Reset
  3249. hasher.reset();
  3250. hasher.update(this._iKey);
  3251. },
  3252.  
  3253. /**
  3254. * Updates this HMAC with a message.
  3255. *
  3256. * @param {WordArray|string} messageUpdate The message to append.
  3257. *
  3258. * @return {HMAC} This HMAC instance.
  3259. *
  3260. * @example
  3261. *
  3262. * hmacHasher.update('message');
  3263. * hmacHasher.update(wordArray);
  3264. */
  3265. update: function (messageUpdate) {
  3266. this._hasher.update(messageUpdate);
  3267.  
  3268. // Chainable
  3269. return this;
  3270. },
  3271.  
  3272. /**
  3273. * Finalizes the HMAC computation.
  3274. * Note that the finalize operation is effectively a destructive, read-once operation.
  3275. *
  3276. * @param {WordArray|string} messageUpdate (Optional) A final message update.
  3277. *
  3278. * @return {WordArray} The HMAC.
  3279. *
  3280. * @example
  3281. *
  3282. * var hmac = hmacHasher.finalize();
  3283. * var hmac = hmacHasher.finalize('message');
  3284. * var hmac = hmacHasher.finalize(wordArray);
  3285. */
  3286. finalize: function (messageUpdate) {
  3287. // Shortcut
  3288. var hasher = this._hasher;
  3289.  
  3290. // Compute HMAC
  3291. var innerHash = hasher.finalize(messageUpdate);
  3292. hasher.reset();
  3293. var hmac = hasher.finalize(this._oKey.clone().concat(innerHash));
  3294.  
  3295. return hmac;
  3296. },
  3297. }));
  3298. })();
  3299.  
  3300. (function () {
  3301. // Shortcuts
  3302. var C = CryptoJS;
  3303. var C_lib = C.lib;
  3304. var Base = C_lib.Base;
  3305. var WordArray = C_lib.WordArray;
  3306. var C_algo = C.algo;
  3307. var SHA256 = C_algo.SHA256;
  3308. var HMAC = C_algo.HMAC;
  3309.  
  3310. /**
  3311. * Password-Based Key Derivation Function 2 algorithm.
  3312. */
  3313. var PBKDF2 = (C_algo.PBKDF2 = Base.extend({
  3314. /**
  3315. * Configuration options.
  3316. *
  3317. * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
  3318. * @property {Hasher} hasher The hasher to use. Default: SHA256
  3319. * @property {number} iterations The number of iterations to perform. Default: 250000
  3320. */
  3321. cfg: Base.extend({
  3322. keySize: 128 / 32,
  3323. hasher: SHA256,
  3324. iterations: 250000,
  3325. }),
  3326.  
  3327. /**
  3328. * Initializes a newly created key derivation function.
  3329. *
  3330. * @param {Object} cfg (Optional) The configuration options to use for the derivation.
  3331. *
  3332. * @example
  3333. *
  3334. * var kdf = CryptoJS.algo.PBKDF2.create();
  3335. * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 });
  3336. * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 });
  3337. */
  3338. init: function (cfg) {
  3339. this.cfg = this.cfg.extend(cfg);
  3340. },
  3341.  
  3342. /**
  3343. * Computes the Password-Based Key Derivation Function 2.
  3344. *
  3345. * @param {WordArray|string} password The password.
  3346. * @param {WordArray|string} salt A salt.
  3347. *
  3348. * @return {WordArray} The derived key.
  3349. *
  3350. * @example
  3351. *
  3352. * var key = kdf.compute(password, salt);
  3353. */
  3354. compute: function (password, salt) {
  3355. // Shortcut
  3356. var cfg = this.cfg;
  3357.  
  3358. // Init HMAC
  3359. var hmac = HMAC.create(cfg.hasher, password);
  3360.  
  3361. // Initial values
  3362. var derivedKey = WordArray.create();
  3363. var blockIndex = WordArray.create([0x00000001]);
  3364.  
  3365. // Shortcuts
  3366. var derivedKeyWords = derivedKey.words;
  3367. var blockIndexWords = blockIndex.words;
  3368. var keySize = cfg.keySize;
  3369. var iterations = cfg.iterations;
  3370.  
  3371. // Generate key
  3372. while (derivedKeyWords.length < keySize) {
  3373. var block = hmac.update(salt).finalize(blockIndex);
  3374. hmac.reset();
  3375.  
  3376. // Shortcuts
  3377. var blockWords = block.words;
  3378. var blockWordsLength = blockWords.length;
  3379.  
  3380. // Iterations
  3381. var intermediate = block;
  3382. for (var i = 1; i < iterations; i++) {
  3383. intermediate = hmac.finalize(intermediate);
  3384. hmac.reset();
  3385.  
  3386. // Shortcut
  3387. var intermediateWords = intermediate.words;
  3388.  
  3389. // XOR intermediate with block
  3390. for (var j = 0; j < blockWordsLength; j++) {
  3391. blockWords[j] ^= intermediateWords[j];
  3392. }
  3393. }
  3394.  
  3395. derivedKey.concat(block);
  3396. blockIndexWords[0]++;
  3397. }
  3398. derivedKey.sigBytes = keySize * 4;
  3399.  
  3400. return derivedKey;
  3401. },
  3402. }));
  3403.  
  3404. /**
  3405. * Computes the Password-Based Key Derivation Function 2.
  3406. *
  3407. * @param {WordArray|string} password The password.
  3408. * @param {WordArray|string} salt A salt.
  3409. * @param {Object} cfg (Optional) The configuration options to use for this computation.
  3410. *
  3411. * @return {WordArray} The derived key.
  3412. *
  3413. * @static
  3414. *
  3415. * @example
  3416. *
  3417. * var key = CryptoJS.PBKDF2(password, salt);
  3418. * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 });
  3419. * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 });
  3420. */
  3421. C.PBKDF2 = function (password, salt, cfg) {
  3422. return PBKDF2.create(cfg).compute(password, salt);
  3423. };
  3424. })();
  3425.  
  3426. (function () {
  3427. // Shortcuts
  3428. var C = CryptoJS;
  3429. var C_lib = C.lib;
  3430. var Base = C_lib.Base;
  3431. var WordArray = C_lib.WordArray;
  3432. var C_algo = C.algo;
  3433. var MD5 = C_algo.MD5;
  3434.  
  3435. /**
  3436. * This key derivation function is meant to conform with EVP_BytesToKey.
  3437. * www.openssl.org/docs/crypto/EVP_BytesToKey.html
  3438. */
  3439. var EvpKDF = (C_algo.EvpKDF = Base.extend({
  3440. /**
  3441. * Configuration options.
  3442. *
  3443. * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
  3444. * @property {Hasher} hasher The hash algorithm to use. Default: MD5
  3445. * @property {number} iterations The number of iterations to perform. Default: 1
  3446. */
  3447. cfg: Base.extend({
  3448. keySize: 128 / 32,
  3449. hasher: MD5,
  3450. iterations: 1,
  3451. }),
  3452.  
  3453. /**
  3454. * Initializes a newly created key derivation function.
  3455. *
  3456. * @param {Object} cfg (Optional) The configuration options to use for the derivation.
  3457. *
  3458. * @example
  3459. *
  3460. * var kdf = CryptoJS.algo.EvpKDF.create();
  3461. * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
  3462. * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
  3463. */
  3464. init: function (cfg) {
  3465. this.cfg = this.cfg.extend(cfg);
  3466. },
  3467.  
  3468. /**
  3469. * Derives a key from a password.
  3470. *
  3471. * @param {WordArray|string} password The password.
  3472. * @param {WordArray|string} salt A salt.
  3473. *
  3474. * @return {WordArray} The derived key.
  3475. *
  3476. * @example
  3477. *
  3478. * var key = kdf.compute(password, salt);
  3479. */
  3480. compute: function (password, salt) {
  3481. var block;
  3482.  
  3483. // Shortcut
  3484. var cfg = this.cfg;
  3485.  
  3486. // Init hasher
  3487. var hasher = cfg.hasher.create();
  3488.  
  3489. // Initial values
  3490. var derivedKey = WordArray.create();
  3491.  
  3492. // Shortcuts
  3493. var derivedKeyWords = derivedKey.words;
  3494. var keySize = cfg.keySize;
  3495. var iterations = cfg.iterations;
  3496.  
  3497. // Generate key
  3498. while (derivedKeyWords.length < keySize) {
  3499. if (block) {
  3500. hasher.update(block);
  3501. }
  3502. block = hasher.update(password).finalize(salt);
  3503. hasher.reset();
  3504.  
  3505. // Iterations
  3506. for (var i = 1; i < iterations; i++) {
  3507. block = hasher.finalize(block);
  3508. hasher.reset();
  3509. }
  3510.  
  3511. derivedKey.concat(block);
  3512. }
  3513. derivedKey.sigBytes = keySize * 4;
  3514.  
  3515. return derivedKey;
  3516. },
  3517. }));
  3518.  
  3519. /**
  3520. * Derives a key from a password.
  3521. *
  3522. * @param {WordArray|string} password The password.
  3523. * @param {WordArray|string} salt A salt.
  3524. * @param {Object} cfg (Optional) The configuration options to use for this computation.
  3525. *
  3526. * @return {WordArray} The derived key.
  3527. *
  3528. * @static
  3529. *
  3530. * @example
  3531. *
  3532. * var key = CryptoJS.EvpKDF(password, salt);
  3533. * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
  3534. * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
  3535. */
  3536. C.EvpKDF = function (password, salt, cfg) {
  3537. return EvpKDF.create(cfg).compute(password, salt);
  3538. };
  3539. })();
  3540.  
  3541. /**
  3542. * Cipher core components.
  3543. */
  3544. CryptoJS.lib.Cipher ||
  3545. (function (undefined) {
  3546. // Shortcuts
  3547. var C = CryptoJS;
  3548. var C_lib = C.lib;
  3549. var Base = C_lib.Base;
  3550. var WordArray = C_lib.WordArray;
  3551. var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
  3552. var C_enc = C.enc;
  3553. var Utf8 = C_enc.Utf8;
  3554. var Base64 = C_enc.Base64;
  3555. var C_algo = C.algo;
  3556. var EvpKDF = C_algo.EvpKDF;
  3557.  
  3558. /**
  3559. * Abstract base cipher template.
  3560. *
  3561. * @property {number} keySize This cipher's key size. Default: 4 (128 bits)
  3562. * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits)
  3563. * @property {number} _ENC_XFORM_MODE A constant representing encryption mode.
  3564. * @property {number} _DEC_XFORM_MODE A constant representing decryption mode.
  3565. */
  3566. var Cipher = (C_lib.Cipher = BufferedBlockAlgorithm.extend({
  3567. /**
  3568. * Configuration options.
  3569. *
  3570. * @property {WordArray} iv The IV to use for this operation.
  3571. */
  3572. cfg: Base.extend(),
  3573.  
  3574. /**
  3575. * Creates this cipher in encryption mode.
  3576. *
  3577. * @param {WordArray} key The key.
  3578. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3579. *
  3580. * @return {Cipher} A cipher instance.
  3581. *
  3582. * @static
  3583. *
  3584. * @example
  3585. *
  3586. * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
  3587. */
  3588. createEncryptor: function (key, cfg) {
  3589. return this.create(this._ENC_XFORM_MODE, key, cfg);
  3590. },
  3591.  
  3592. /**
  3593. * Creates this cipher in decryption mode.
  3594. *
  3595. * @param {WordArray} key The key.
  3596. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3597. *
  3598. * @return {Cipher} A cipher instance.
  3599. *
  3600. * @static
  3601. *
  3602. * @example
  3603. *
  3604. * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
  3605. */
  3606. createDecryptor: function (key, cfg) {
  3607. return this.create(this._DEC_XFORM_MODE, key, cfg);
  3608. },
  3609.  
  3610. /**
  3611. * Initializes a newly created cipher.
  3612. *
  3613. * @param {number} xformMode Either the encryption or decryption transormation mode constant.
  3614. * @param {WordArray} key The key.
  3615. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3616. *
  3617. * @example
  3618. *
  3619. * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
  3620. */
  3621. init: function (xformMode, key, cfg) {
  3622. // Apply config defaults
  3623. this.cfg = this.cfg.extend(cfg);
  3624.  
  3625. // Store transform mode and key
  3626. this._xformMode = xformMode;
  3627. this._key = key;
  3628.  
  3629. // Set initial values
  3630. this.reset();
  3631. },
  3632.  
  3633. /**
  3634. * Resets this cipher to its initial state.
  3635. *
  3636. * @example
  3637. *
  3638. * cipher.reset();
  3639. */
  3640. reset: function () {
  3641. // Reset data buffer
  3642. BufferedBlockAlgorithm.reset.call(this);
  3643.  
  3644. // Perform concrete-cipher logic
  3645. this._doReset();
  3646. },
  3647.  
  3648. /**
  3649. * Adds data to be encrypted or decrypted.
  3650. *
  3651. * @param {WordArray|string} dataUpdate The data to encrypt or decrypt.
  3652. *
  3653. * @return {WordArray} The data after processing.
  3654. *
  3655. * @example
  3656. *
  3657. * var encrypted = cipher.process('data');
  3658. * var encrypted = cipher.process(wordArray);
  3659. */
  3660. process: function (dataUpdate) {
  3661. // Append
  3662. this._append(dataUpdate);
  3663.  
  3664. // Process available blocks
  3665. return this._process();
  3666. },
  3667.  
  3668. /**
  3669. * Finalizes the encryption or decryption process.
  3670. * Note that the finalize operation is effectively a destructive, read-once operation.
  3671. *
  3672. * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt.
  3673. *
  3674. * @return {WordArray} The data after final processing.
  3675. *
  3676. * @example
  3677. *
  3678. * var encrypted = cipher.finalize();
  3679. * var encrypted = cipher.finalize('data');
  3680. * var encrypted = cipher.finalize(wordArray);
  3681. */
  3682. finalize: function (dataUpdate) {
  3683. // Final data update
  3684. if (dataUpdate) {
  3685. this._append(dataUpdate);
  3686. }
  3687.  
  3688. // Perform concrete-cipher logic
  3689. var finalProcessedData = this._doFinalize();
  3690.  
  3691. return finalProcessedData;
  3692. },
  3693.  
  3694. keySize: 128 / 32,
  3695.  
  3696. ivSize: 128 / 32,
  3697.  
  3698. _ENC_XFORM_MODE: 1,
  3699.  
  3700. _DEC_XFORM_MODE: 2,
  3701.  
  3702. /**
  3703. * Creates shortcut functions to a cipher's object interface.
  3704. *
  3705. * @param {Cipher} cipher The cipher to create a helper for.
  3706. *
  3707. * @return {Object} An object with encrypt and decrypt shortcut functions.
  3708. *
  3709. * @static
  3710. *
  3711. * @example
  3712. *
  3713. * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
  3714. */
  3715. _createHelper: (function () {
  3716. function selectCipherStrategy(key) {
  3717. if (typeof key == "string") {
  3718. return PasswordBasedCipher;
  3719. } else {
  3720. return SerializableCipher;
  3721. }
  3722. }
  3723.  
  3724. return function (cipher) {
  3725. return {
  3726. encrypt: function (message, key, cfg) {
  3727. return selectCipherStrategy(key).encrypt(
  3728. cipher,
  3729. message,
  3730. key,
  3731. cfg
  3732. );
  3733. },
  3734.  
  3735. decrypt: function (ciphertext, key, cfg) {
  3736. return selectCipherStrategy(key).decrypt(
  3737. cipher,
  3738. ciphertext,
  3739. key,
  3740. cfg
  3741. );
  3742. },
  3743. };
  3744. };
  3745. })(),
  3746. }));
  3747.  
  3748. /**
  3749. * Abstract base stream cipher template.
  3750. *
  3751. * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
  3752. */
  3753. var StreamCipher = (C_lib.StreamCipher = Cipher.extend({
  3754. _doFinalize: function () {
  3755. // Process partial blocks
  3756. var finalProcessedBlocks = this._process(!!"flush");
  3757.  
  3758. return finalProcessedBlocks;
  3759. },
  3760.  
  3761. blockSize: 1,
  3762. }));
  3763.  
  3764. /**
  3765. * Mode namespace.
  3766. */
  3767. var C_mode = (C.mode = {});
  3768.  
  3769. /**
  3770. * Abstract base block cipher mode template.
  3771. */
  3772. var BlockCipherMode = (C_lib.BlockCipherMode = Base.extend({
  3773. /**
  3774. * Creates this mode for encryption.
  3775. *
  3776. * @param {Cipher} cipher A block cipher instance.
  3777. * @param {Array} iv The IV words.
  3778. *
  3779. * @static
  3780. *
  3781. * @example
  3782. *
  3783. * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
  3784. */
  3785. createEncryptor: function (cipher, iv) {
  3786. return this.Encryptor.create(cipher, iv);
  3787. },
  3788.  
  3789. /**
  3790. * Creates this mode for decryption.
  3791. *
  3792. * @param {Cipher} cipher A block cipher instance.
  3793. * @param {Array} iv The IV words.
  3794. *
  3795. * @static
  3796. *
  3797. * @example
  3798. *
  3799. * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
  3800. */
  3801. createDecryptor: function (cipher, iv) {
  3802. return this.Decryptor.create(cipher, iv);
  3803. },
  3804.  
  3805. /**
  3806. * Initializes a newly created mode.
  3807. *
  3808. * @param {Cipher} cipher A block cipher instance.
  3809. * @param {Array} iv The IV words.
  3810. *
  3811. * @example
  3812. *
  3813. * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
  3814. */
  3815. init: function (cipher, iv) {
  3816. this._cipher = cipher;
  3817. this._iv = iv;
  3818. },
  3819. }));
  3820.  
  3821. /**
  3822. * Cipher Block Chaining mode.
  3823. */
  3824. var CBC = (C_mode.CBC = (function () {
  3825. /**
  3826. * Abstract base CBC mode.
  3827. */
  3828. var CBC = BlockCipherMode.extend();
  3829.  
  3830. /**
  3831. * CBC encryptor.
  3832. */
  3833. CBC.Encryptor = CBC.extend({
  3834. /**
  3835. * Processes the data block at offset.
  3836. *
  3837. * @param {Array} words The data words to operate on.
  3838. * @param {number} offset The offset where the block starts.
  3839. *
  3840. * @example
  3841. *
  3842. * mode.processBlock(data.words, offset);
  3843. */
  3844. processBlock: function (words, offset) {
  3845. // Shortcuts
  3846. var cipher = this._cipher;
  3847. var blockSize = cipher.blockSize;
  3848.  
  3849. // XOR and encrypt
  3850. xorBlock.call(this, words, offset, blockSize);
  3851. cipher.encryptBlock(words, offset);
  3852.  
  3853. // Remember this block to use with next block
  3854. this._prevBlock = words.slice(offset, offset + blockSize);
  3855. },
  3856. });
  3857.  
  3858. /**
  3859. * CBC decryptor.
  3860. */
  3861. CBC.Decryptor = CBC.extend({
  3862. /**
  3863. * Processes the data block at offset.
  3864. *
  3865. * @param {Array} words The data words to operate on.
  3866. * @param {number} offset The offset where the block starts.
  3867. *
  3868. * @example
  3869. *
  3870. * mode.processBlock(data.words, offset);
  3871. */
  3872. processBlock: function (words, offset) {
  3873. // Shortcuts
  3874. var cipher = this._cipher;
  3875. var blockSize = cipher.blockSize;
  3876.  
  3877. // Remember this block to use with next block
  3878. var thisBlock = words.slice(offset, offset + blockSize);
  3879.  
  3880. // Decrypt and XOR
  3881. cipher.decryptBlock(words, offset);
  3882. xorBlock.call(this, words, offset, blockSize);
  3883.  
  3884. // This block becomes the previous block
  3885. this._prevBlock = thisBlock;
  3886. },
  3887. });
  3888.  
  3889. function xorBlock(words, offset, blockSize) {
  3890. var block;
  3891.  
  3892. // Shortcut
  3893. var iv = this._iv;
  3894.  
  3895. // Choose mixing block
  3896. if (iv) {
  3897. block = iv;
  3898.  
  3899. // Remove IV for subsequent blocks
  3900. this._iv = undefined;
  3901. } else {
  3902. block = this._prevBlock;
  3903. }
  3904.  
  3905. // XOR blocks
  3906. for (var i = 0; i < blockSize; i++) {
  3907. words[offset + i] ^= block[i];
  3908. }
  3909. }
  3910.  
  3911. return CBC;
  3912. })());
  3913.  
  3914. /**
  3915. * Padding namespace.
  3916. */
  3917. var C_pad = (C.pad = {});
  3918.  
  3919. /**
  3920. * PKCS #5/7 padding strategy.
  3921. */
  3922. var Pkcs7 = (C_pad.Pkcs7 = {
  3923. /**
  3924. * Pads data using the algorithm defined in PKCS #5/7.
  3925. *
  3926. * @param {WordArray} data The data to pad.
  3927. * @param {number} blockSize The multiple that the data should be padded to.
  3928. *
  3929. * @static
  3930. *
  3931. * @example
  3932. *
  3933. * CryptoJS.pad.Pkcs7.pad(wordArray, 4);
  3934. */
  3935. pad: function (data, blockSize) {
  3936. // Shortcut
  3937. var blockSizeBytes = blockSize * 4;
  3938.  
  3939. // Count padding bytes
  3940. var nPaddingBytes = blockSizeBytes - (data.sigBytes % blockSizeBytes);
  3941.  
  3942. // Create padding word
  3943. var paddingWord =
  3944. (nPaddingBytes << 24) |
  3945. (nPaddingBytes << 16) |
  3946. (nPaddingBytes << 8) |
  3947. nPaddingBytes;
  3948.  
  3949. // Create padding
  3950. var paddingWords = [];
  3951. for (var i = 0; i < nPaddingBytes; i += 4) {
  3952. paddingWords.push(paddingWord);
  3953. }
  3954. var padding = WordArray.create(paddingWords, nPaddingBytes);
  3955.  
  3956. // Add padding
  3957. data.concat(padding);
  3958. },
  3959.  
  3960. /**
  3961. * Unpads data that had been padded using the algorithm defined in PKCS #5/7.
  3962. *
  3963. * @param {WordArray} data The data to unpad.
  3964. *
  3965. * @static
  3966. *
  3967. * @example
  3968. *
  3969. * CryptoJS.pad.Pkcs7.unpad(wordArray);
  3970. */
  3971. unpad: function (data) {
  3972. // Get number of padding bytes from last byte
  3973. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  3974.  
  3975. // Remove padding
  3976. data.sigBytes -= nPaddingBytes;
  3977. },
  3978. });
  3979.  
  3980. /**
  3981. * Abstract base block cipher template.
  3982. *
  3983. * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits)
  3984. */
  3985. var BlockCipher = (C_lib.BlockCipher = Cipher.extend({
  3986. /**
  3987. * Configuration options.
  3988. *
  3989. * @property {Mode} mode The block mode to use. Default: CBC
  3990. * @property {Padding} padding The padding strategy to use. Default: Pkcs7
  3991. */
  3992. cfg: Cipher.cfg.extend({
  3993. mode: CBC,
  3994. padding: Pkcs7,
  3995. }),
  3996.  
  3997. reset: function () {
  3998. var modeCreator;
  3999.  
  4000. // Reset cipher
  4001. Cipher.reset.call(this);
  4002.  
  4003. // Shortcuts
  4004. var cfg = this.cfg;
  4005. var iv = cfg.iv;
  4006. var mode = cfg.mode;
  4007.  
  4008. // Reset block mode
  4009. if (this._xformMode == this._ENC_XFORM_MODE) {
  4010. modeCreator = mode.createEncryptor;
  4011. } /* if (this._xformMode == this._DEC_XFORM_MODE) */ else {
  4012. modeCreator = mode.createDecryptor;
  4013. // Keep at least one block in the buffer for unpadding
  4014. this._minBufferSize = 1;
  4015. }
  4016.  
  4017. if (this._mode && this._mode.__creator == modeCreator) {
  4018. this._mode.init(this, iv && iv.words);
  4019. } else {
  4020. this._mode = modeCreator.call(mode, this, iv && iv.words);
  4021. this._mode.__creator = modeCreator;
  4022. }
  4023. },
  4024.  
  4025. _doProcessBlock: function (words, offset) {
  4026. this._mode.processBlock(words, offset);
  4027. },
  4028.  
  4029. _doFinalize: function () {
  4030. var finalProcessedBlocks;
  4031.  
  4032. // Shortcut
  4033. var padding = this.cfg.padding;
  4034.  
  4035. // Finalize
  4036. if (this._xformMode == this._ENC_XFORM_MODE) {
  4037. // Pad data
  4038. padding.pad(this._data, this.blockSize);
  4039.  
  4040. // Process final blocks
  4041. finalProcessedBlocks = this._process(!!"flush");
  4042. } /* if (this._xformMode == this._DEC_XFORM_MODE) */ else {
  4043. // Process final blocks
  4044. finalProcessedBlocks = this._process(!!"flush");
  4045.  
  4046. // Unpad data
  4047. padding.unpad(finalProcessedBlocks);
  4048. }
  4049.  
  4050. return finalProcessedBlocks;
  4051. },
  4052.  
  4053. blockSize: 128 / 32,
  4054. }));
  4055.  
  4056. /**
  4057. * A collection of cipher parameters.
  4058. *
  4059. * @property {WordArray} ciphertext The raw ciphertext.
  4060. * @property {WordArray} key The key to this ciphertext.
  4061. * @property {WordArray} iv The IV used in the ciphering operation.
  4062. * @property {WordArray} salt The salt used with a key derivation function.
  4063. * @property {Cipher} algorithm The cipher algorithm.
  4064. * @property {Mode} mode The block mode used in the ciphering operation.
  4065. * @property {Padding} padding The padding scheme used in the ciphering operation.
  4066. * @property {number} blockSize The block size of the cipher.
  4067. * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string.
  4068. */
  4069. var CipherParams = (C_lib.CipherParams = Base.extend({
  4070. /**
  4071. * Initializes a newly created cipher params object.
  4072. *
  4073. * @param {Object} cipherParams An object with any of the possible cipher parameters.
  4074. *
  4075. * @example
  4076. *
  4077. * var cipherParams = CryptoJS.lib.CipherParams.create({
  4078. * ciphertext: ciphertextWordArray,
  4079. * key: keyWordArray,
  4080. * iv: ivWordArray,
  4081. * salt: saltWordArray,
  4082. * algorithm: CryptoJS.algo.AES,
  4083. * mode: CryptoJS.mode.CBC,
  4084. * padding: CryptoJS.pad.PKCS7,
  4085. * blockSize: 4,
  4086. * formatter: CryptoJS.format.OpenSSL
  4087. * });
  4088. */
  4089. init: function (cipherParams) {
  4090. this.mixIn(cipherParams);
  4091. },
  4092.  
  4093. /**
  4094. * Converts this cipher params object to a string.
  4095. *
  4096. * @param {Format} formatter (Optional) The formatting strategy to use.
  4097. *
  4098. * @return {string} The stringified cipher params.
  4099. *
  4100. * @throws Error If neither the formatter nor the default formatter is set.
  4101. *
  4102. * @example
  4103. *
  4104. * var string = cipherParams + '';
  4105. * var string = cipherParams.toString();
  4106. * var string = cipherParams.toString(CryptoJS.format.OpenSSL);
  4107. */
  4108. toString: function (formatter) {
  4109. return (formatter || this.formatter).stringify(this);
  4110. },
  4111. }));
  4112.  
  4113. /**
  4114. * Format namespace.
  4115. */
  4116. var C_format = (C.format = {});
  4117.  
  4118. /**
  4119. * OpenSSL formatting strategy.
  4120. */
  4121. var OpenSSLFormatter = (C_format.OpenSSL = {
  4122. /**
  4123. * Converts a cipher params object to an OpenSSL-compatible string.
  4124. *
  4125. * @param {CipherParams} cipherParams The cipher params object.
  4126. *
  4127. * @return {string} The OpenSSL-compatible string.
  4128. *
  4129. * @static
  4130. *
  4131. * @example
  4132. *
  4133. * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
  4134. */
  4135. stringify: function (cipherParams) {
  4136. var wordArray;
  4137.  
  4138. // Shortcuts
  4139. var ciphertext = cipherParams.ciphertext;
  4140. var salt = cipherParams.salt;
  4141.  
  4142. // Format
  4143. if (salt) {
  4144. wordArray = WordArray.create([0x53616c74, 0x65645f5f])
  4145. .concat(salt)
  4146. .concat(ciphertext);
  4147. } else {
  4148. wordArray = ciphertext;
  4149. }
  4150.  
  4151. return wordArray.toString(Base64);
  4152. },
  4153.  
  4154. /**
  4155. * Converts an OpenSSL-compatible string to a cipher params object.
  4156. *
  4157. * @param {string} openSSLStr The OpenSSL-compatible string.
  4158. *
  4159. * @return {CipherParams} The cipher params object.
  4160. *
  4161. * @static
  4162. *
  4163. * @example
  4164. *
  4165. * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
  4166. */
  4167. parse: function (openSSLStr) {
  4168. var salt;
  4169.  
  4170. // Parse base64
  4171. var ciphertext = Base64.parse(openSSLStr);
  4172.  
  4173. // Shortcut
  4174. var ciphertextWords = ciphertext.words;
  4175.  
  4176. // Test for salt
  4177. if (
  4178. ciphertextWords[0] == 0x53616c74 &&
  4179. ciphertextWords[1] == 0x65645f5f
  4180. ) {
  4181. // Extract salt
  4182. salt = WordArray.create(ciphertextWords.slice(2, 4));
  4183.  
  4184. // Remove salt from ciphertext
  4185. ciphertextWords.splice(0, 4);
  4186. ciphertext.sigBytes -= 16;
  4187. }
  4188.  
  4189. return CipherParams.create({ ciphertext: ciphertext, salt: salt });
  4190. },
  4191. });
  4192.  
  4193. /**
  4194. * A cipher wrapper that returns ciphertext as a serializable cipher params object.
  4195. */
  4196. var SerializableCipher = (C_lib.SerializableCipher = Base.extend({
  4197. /**
  4198. * Configuration options.
  4199. *
  4200. * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL
  4201. */
  4202. cfg: Base.extend({
  4203. format: OpenSSLFormatter,
  4204. }),
  4205.  
  4206. /**
  4207. * Encrypts a message.
  4208. *
  4209. * @param {Cipher} cipher The cipher algorithm to use.
  4210. * @param {WordArray|string} message The message to encrypt.
  4211. * @param {WordArray} key The key.
  4212. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  4213. *
  4214. * @return {CipherParams} A cipher params object.
  4215. *
  4216. * @static
  4217. *
  4218. * @example
  4219. *
  4220. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
  4221. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
  4222. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  4223. */
  4224. encrypt: function (cipher, message, key, cfg) {
  4225. // Apply config defaults
  4226. cfg = this.cfg.extend(cfg);
  4227.  
  4228. // Encrypt
  4229. var encryptor = cipher.createEncryptor(key, cfg);
  4230. var ciphertext = encryptor.finalize(message);
  4231.  
  4232. // Shortcut
  4233. var cipherCfg = encryptor.cfg;
  4234.  
  4235. // Create and return serializable cipher params
  4236. return CipherParams.create({
  4237. ciphertext: ciphertext,
  4238. key: key,
  4239. iv: cipherCfg.iv,
  4240. algorithm: cipher,
  4241. mode: cipherCfg.mode,
  4242. padding: cipherCfg.padding,
  4243. blockSize: cipher.blockSize,
  4244. formatter: cfg.format,
  4245. });
  4246. },
  4247.  
  4248. /**
  4249. * Decrypts serialized ciphertext.
  4250. *
  4251. * @param {Cipher} cipher The cipher algorithm to use.
  4252. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  4253. * @param {WordArray} key The key.
  4254. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  4255. *
  4256. * @return {WordArray} The plaintext.
  4257. *
  4258. * @static
  4259. *
  4260. * @example
  4261. *
  4262. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  4263. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  4264. */
  4265. decrypt: function (cipher, ciphertext, key, cfg) {
  4266. // Apply config defaults
  4267. cfg = this.cfg.extend(cfg);
  4268.  
  4269. // Convert string to CipherParams
  4270. ciphertext = this._parse(ciphertext, cfg.format);
  4271.  
  4272. // Decrypt
  4273. var plaintext = cipher
  4274. .createDecryptor(key, cfg)
  4275. .finalize(ciphertext.ciphertext);
  4276.  
  4277. return plaintext;
  4278. },
  4279.  
  4280. /**
  4281. * Converts serialized ciphertext to CipherParams,
  4282. * else assumed CipherParams already and returns ciphertext unchanged.
  4283. *
  4284. * @param {CipherParams|string} ciphertext The ciphertext.
  4285. * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
  4286. *
  4287. * @return {CipherParams} The unserialized ciphertext.
  4288. *
  4289. * @static
  4290. *
  4291. * @example
  4292. *
  4293. * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
  4294. */
  4295. _parse: function (ciphertext, format) {
  4296. if (typeof ciphertext == "string") {
  4297. return format.parse(ciphertext, this);
  4298. } else {
  4299. return ciphertext;
  4300. }
  4301. },
  4302. }));
  4303.  
  4304. /**
  4305. * Key derivation function namespace.
  4306. */
  4307. var C_kdf = (C.kdf = {});
  4308.  
  4309. /**
  4310. * OpenSSL key derivation function.
  4311. */
  4312. var OpenSSLKdf = (C_kdf.OpenSSL = {
  4313. /**
  4314. * Derives a key and IV from a password.
  4315. *
  4316. * @param {string} password The password to derive from.
  4317. * @param {number} keySize The size in words of the key to generate.
  4318. * @param {number} ivSize The size in words of the IV to generate.
  4319. * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
  4320. *
  4321. * @return {CipherParams} A cipher params object with the key, IV, and salt.
  4322. *
  4323. * @static
  4324. *
  4325. * @example
  4326. *
  4327. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
  4328. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
  4329. */
  4330. execute: function (password, keySize, ivSize, salt, hasher) {
  4331. // Generate random salt
  4332. if (!salt) {
  4333. salt = WordArray.random(64 / 8);
  4334. }
  4335.  
  4336. // Derive key and IV
  4337. if (!hasher) {
  4338. var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(
  4339. password,
  4340. salt
  4341. );
  4342. } else {
  4343. var key = EvpKDF.create({
  4344. keySize: keySize + ivSize,
  4345. hasher: hasher,
  4346. }).compute(password, salt);
  4347. }
  4348.  
  4349. // Separate key and IV
  4350. var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
  4351. key.sigBytes = keySize * 4;
  4352.  
  4353. // Return params
  4354. return CipherParams.create({ key: key, iv: iv, salt: salt });
  4355. },
  4356. });
  4357.  
  4358. /**
  4359. * A serializable cipher wrapper that derives the key from a password,
  4360. * and returns ciphertext as a serializable cipher params object.
  4361. */
  4362. var PasswordBasedCipher = (C_lib.PasswordBasedCipher =
  4363. SerializableCipher.extend({
  4364. /**
  4365. * Configuration options.
  4366. *
  4367. * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL
  4368. */
  4369. cfg: SerializableCipher.cfg.extend({
  4370. kdf: OpenSSLKdf,
  4371. }),
  4372.  
  4373. /**
  4374. * Encrypts a message using a password.
  4375. *
  4376. * @param {Cipher} cipher The cipher algorithm to use.
  4377. * @param {WordArray|string} message The message to encrypt.
  4378. * @param {string} password The password.
  4379. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  4380. *
  4381. * @return {CipherParams} A cipher params object.
  4382. *
  4383. * @static
  4384. *
  4385. * @example
  4386. *
  4387. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
  4388. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
  4389. */
  4390. encrypt: function (cipher, message, password, cfg) {
  4391. // Apply config defaults
  4392. cfg = this.cfg.extend(cfg);
  4393.  
  4394. // Derive key and other params
  4395. var derivedParams = cfg.kdf.execute(
  4396. password,
  4397. cipher.keySize,
  4398. cipher.ivSize,
  4399. cfg.salt,
  4400. cfg.hasher
  4401. );
  4402.  
  4403. // Add IV to config
  4404. cfg.iv = derivedParams.iv;
  4405.  
  4406. // Encrypt
  4407. var ciphertext = SerializableCipher.encrypt.call(
  4408. this,
  4409. cipher,
  4410. message,
  4411. derivedParams.key,
  4412. cfg
  4413. );
  4414.  
  4415. // Mix in derived params
  4416. ciphertext.mixIn(derivedParams);
  4417.  
  4418. return ciphertext;
  4419. },
  4420.  
  4421. /**
  4422. * Decrypts serialized ciphertext using a password.
  4423. *
  4424. * @param {Cipher} cipher The cipher algorithm to use.
  4425. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  4426. * @param {string} password The password.
  4427. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  4428. *
  4429. * @return {WordArray} The plaintext.
  4430. *
  4431. * @static
  4432. *
  4433. * @example
  4434. *
  4435. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
  4436. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
  4437. */
  4438. decrypt: function (cipher, ciphertext, password, cfg) {
  4439. // Apply config defaults
  4440. cfg = this.cfg.extend(cfg);
  4441.  
  4442. // Convert string to CipherParams
  4443. ciphertext = this._parse(ciphertext, cfg.format);
  4444.  
  4445. // Derive key and other params
  4446. var derivedParams = cfg.kdf.execute(
  4447. password,
  4448. cipher.keySize,
  4449. cipher.ivSize,
  4450. ciphertext.salt,
  4451. cfg.hasher
  4452. );
  4453.  
  4454. // Add IV to config
  4455. cfg.iv = derivedParams.iv;
  4456.  
  4457. // Decrypt
  4458. var plaintext = SerializableCipher.decrypt.call(
  4459. this,
  4460. cipher,
  4461. ciphertext,
  4462. derivedParams.key,
  4463. cfg
  4464. );
  4465.  
  4466. return plaintext;
  4467. },
  4468. }));
  4469. })();
  4470.  
  4471. /**
  4472. * Cipher Feedback block mode.
  4473. */
  4474. CryptoJS.mode.CFB = (function () {
  4475. var CFB = CryptoJS.lib.BlockCipherMode.extend();
  4476.  
  4477. CFB.Encryptor = CFB.extend({
  4478. processBlock: function (words, offset) {
  4479. // Shortcuts
  4480. var cipher = this._cipher;
  4481. var blockSize = cipher.blockSize;
  4482.  
  4483. generateKeystreamAndEncrypt.call(
  4484. this,
  4485. words,
  4486. offset,
  4487. blockSize,
  4488. cipher
  4489. );
  4490.  
  4491. // Remember this block to use with next block
  4492. this._prevBlock = words.slice(offset, offset + blockSize);
  4493. },
  4494. });
  4495.  
  4496. CFB.Decryptor = CFB.extend({
  4497. processBlock: function (words, offset) {
  4498. // Shortcuts
  4499. var cipher = this._cipher;
  4500. var blockSize = cipher.blockSize;
  4501.  
  4502. // Remember this block to use with next block
  4503. var thisBlock = words.slice(offset, offset + blockSize);
  4504.  
  4505. generateKeystreamAndEncrypt.call(
  4506. this,
  4507. words,
  4508. offset,
  4509. blockSize,
  4510. cipher
  4511. );
  4512.  
  4513. // This block becomes the previous block
  4514. this._prevBlock = thisBlock;
  4515. },
  4516. });
  4517.  
  4518. function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) {
  4519. var keystream;
  4520.  
  4521. // Shortcut
  4522. var iv = this._iv;
  4523.  
  4524. // Generate keystream
  4525. if (iv) {
  4526. keystream = iv.slice(0);
  4527.  
  4528. // Remove IV for subsequent blocks
  4529. this._iv = undefined;
  4530. } else {
  4531. keystream = this._prevBlock;
  4532. }
  4533. cipher.encryptBlock(keystream, 0);
  4534.  
  4535. // Encrypt
  4536. for (var i = 0; i < blockSize; i++) {
  4537. words[offset + i] ^= keystream[i];
  4538. }
  4539. }
  4540.  
  4541. return CFB;
  4542. })();
  4543.  
  4544. /**
  4545. * Counter block mode.
  4546. */
  4547. CryptoJS.mode.CTR = (function () {
  4548. var CTR = CryptoJS.lib.BlockCipherMode.extend();
  4549.  
  4550. var Encryptor = (CTR.Encryptor = CTR.extend({
  4551. processBlock: function (words, offset) {
  4552. // Shortcuts
  4553. var cipher = this._cipher;
  4554. var blockSize = cipher.blockSize;
  4555. var iv = this._iv;
  4556. var counter = this._counter;
  4557.  
  4558. // Generate keystream
  4559. if (iv) {
  4560. counter = this._counter = iv.slice(0);
  4561.  
  4562. // Remove IV for subsequent blocks
  4563. this._iv = undefined;
  4564. }
  4565. var keystream = counter.slice(0);
  4566. cipher.encryptBlock(keystream, 0);
  4567.  
  4568. // Increment counter
  4569. counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0;
  4570.  
  4571. // Encrypt
  4572. for (var i = 0; i < blockSize; i++) {
  4573. words[offset + i] ^= keystream[i];
  4574. }
  4575. },
  4576. }));
  4577.  
  4578. CTR.Decryptor = Encryptor;
  4579.  
  4580. return CTR;
  4581. })();
  4582.  
  4583. /** @preserve
  4584. * Counter block mode compatible with Dr Brian Gladman fileenc.c
  4585. * derived from CryptoJS.mode.CTR
  4586. * Jan Hruby jhruby.web@gmail.com
  4587. */
  4588. CryptoJS.mode.CTRGladman = (function () {
  4589. var CTRGladman = CryptoJS.lib.BlockCipherMode.extend();
  4590.  
  4591. function incWord(word) {
  4592. if (((word >> 24) & 0xff) === 0xff) {
  4593. //overflow
  4594. var b1 = (word >> 16) & 0xff;
  4595. var b2 = (word >> 8) & 0xff;
  4596. var b3 = word & 0xff;
  4597.  
  4598. if (b1 === 0xff) {
  4599. // overflow b1
  4600. b1 = 0;
  4601. if (b2 === 0xff) {
  4602. b2 = 0;
  4603. if (b3 === 0xff) {
  4604. b3 = 0;
  4605. } else {
  4606. ++b3;
  4607. }
  4608. } else {
  4609. ++b2;
  4610. }
  4611. } else {
  4612. ++b1;
  4613. }
  4614.  
  4615. word = 0;
  4616. word += b1 << 16;
  4617. word += b2 << 8;
  4618. word += b3;
  4619. } else {
  4620. word += 0x01 << 24;
  4621. }
  4622. return word;
  4623. }
  4624.  
  4625. function incCounter(counter) {
  4626. if ((counter[0] = incWord(counter[0])) === 0) {
  4627. // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
  4628. counter[1] = incWord(counter[1]);
  4629. }
  4630. return counter;
  4631. }
  4632.  
  4633. var Encryptor = (CTRGladman.Encryptor = CTRGladman.extend({
  4634. processBlock: function (words, offset) {
  4635. // Shortcuts
  4636. var cipher = this._cipher;
  4637. var blockSize = cipher.blockSize;
  4638. var iv = this._iv;
  4639. var counter = this._counter;
  4640.  
  4641. // Generate keystream
  4642. if (iv) {
  4643. counter = this._counter = iv.slice(0);
  4644.  
  4645. // Remove IV for subsequent blocks
  4646. this._iv = undefined;
  4647. }
  4648.  
  4649. incCounter(counter);
  4650.  
  4651. var keystream = counter.slice(0);
  4652. cipher.encryptBlock(keystream, 0);
  4653.  
  4654. // Encrypt
  4655. for (var i = 0; i < blockSize; i++) {
  4656. words[offset + i] ^= keystream[i];
  4657. }
  4658. },
  4659. }));
  4660.  
  4661. CTRGladman.Decryptor = Encryptor;
  4662.  
  4663. return CTRGladman;
  4664. })();
  4665.  
  4666. /**
  4667. * Output Feedback block mode.
  4668. */
  4669. CryptoJS.mode.OFB = (function () {
  4670. var OFB = CryptoJS.lib.BlockCipherMode.extend();
  4671.  
  4672. var Encryptor = (OFB.Encryptor = OFB.extend({
  4673. processBlock: function (words, offset) {
  4674. // Shortcuts
  4675. var cipher = this._cipher;
  4676. var blockSize = cipher.blockSize;
  4677. var iv = this._iv;
  4678. var keystream = this._keystream;
  4679.  
  4680. // Generate keystream
  4681. if (iv) {
  4682. keystream = this._keystream = iv.slice(0);
  4683.  
  4684. // Remove IV for subsequent blocks
  4685. this._iv = undefined;
  4686. }
  4687. cipher.encryptBlock(keystream, 0);
  4688.  
  4689. // Encrypt
  4690. for (var i = 0; i < blockSize; i++) {
  4691. words[offset + i] ^= keystream[i];
  4692. }
  4693. },
  4694. }));
  4695.  
  4696. OFB.Decryptor = Encryptor;
  4697.  
  4698. return OFB;
  4699. })();
  4700.  
  4701. /**
  4702. * Electronic Codebook block mode.
  4703. */
  4704. CryptoJS.mode.ECB = (function () {
  4705. var ECB = CryptoJS.lib.BlockCipherMode.extend();
  4706.  
  4707. ECB.Encryptor = ECB.extend({
  4708. processBlock: function (words, offset) {
  4709. this._cipher.encryptBlock(words, offset);
  4710. },
  4711. });
  4712.  
  4713. ECB.Decryptor = ECB.extend({
  4714. processBlock: function (words, offset) {
  4715. this._cipher.decryptBlock(words, offset);
  4716. },
  4717. });
  4718.  
  4719. return ECB;
  4720. })();
  4721.  
  4722. /**
  4723. * ANSI X.923 padding strategy.
  4724. */
  4725. CryptoJS.pad.AnsiX923 = {
  4726. pad: function (data, blockSize) {
  4727. // Shortcuts
  4728. var dataSigBytes = data.sigBytes;
  4729. var blockSizeBytes = blockSize * 4;
  4730.  
  4731. // Count padding bytes
  4732. var nPaddingBytes = blockSizeBytes - (dataSigBytes % blockSizeBytes);
  4733.  
  4734. // Compute last byte position
  4735. var lastBytePos = dataSigBytes + nPaddingBytes - 1;
  4736.  
  4737. // Pad
  4738. data.clamp();
  4739. data.words[lastBytePos >>> 2] |=
  4740. nPaddingBytes << (24 - (lastBytePos % 4) * 8);
  4741. data.sigBytes += nPaddingBytes;
  4742. },
  4743.  
  4744. unpad: function (data) {
  4745. // Get number of padding bytes from last byte
  4746. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  4747.  
  4748. // Remove padding
  4749. data.sigBytes -= nPaddingBytes;
  4750. },
  4751. };
  4752.  
  4753. /**
  4754. * ISO 10126 padding strategy.
  4755. */
  4756. CryptoJS.pad.Iso10126 = {
  4757. pad: function (data, blockSize) {
  4758. // Shortcut
  4759. var blockSizeBytes = blockSize * 4;
  4760.  
  4761. // Count padding bytes
  4762. var nPaddingBytes = blockSizeBytes - (data.sigBytes % blockSizeBytes);
  4763.  
  4764. // Pad
  4765. data
  4766. .concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1))
  4767. .concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1));
  4768. },
  4769.  
  4770. unpad: function (data) {
  4771. // Get number of padding bytes from last byte
  4772. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  4773.  
  4774. // Remove padding
  4775. data.sigBytes -= nPaddingBytes;
  4776. },
  4777. };
  4778.  
  4779. /**
  4780. * ISO/IEC 9797-1 Padding Method 2.
  4781. */
  4782. CryptoJS.pad.Iso97971 = {
  4783. pad: function (data, blockSize) {
  4784. // Add 0x80 byte
  4785. data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1));
  4786.  
  4787. // Zero pad the rest
  4788. CryptoJS.pad.ZeroPadding.pad(data, blockSize);
  4789. },
  4790.  
  4791. unpad: function (data) {
  4792. // Remove zero padding
  4793. CryptoJS.pad.ZeroPadding.unpad(data);
  4794.  
  4795. // Remove one more byte -- the 0x80 byte
  4796. data.sigBytes--;
  4797. },
  4798. };
  4799.  
  4800. /**
  4801. * Zero padding strategy.
  4802. */
  4803. CryptoJS.pad.ZeroPadding = {
  4804. pad: function (data, blockSize) {
  4805. // Shortcut
  4806. var blockSizeBytes = blockSize * 4;
  4807.  
  4808. // Pad
  4809. data.clamp();
  4810. data.sigBytes +=
  4811. blockSizeBytes - (data.sigBytes % blockSizeBytes || blockSizeBytes);
  4812. },
  4813.  
  4814. unpad: function (data) {
  4815. // Shortcut
  4816. var dataWords = data.words;
  4817.  
  4818. // Unpad
  4819. var i = data.sigBytes - 1;
  4820. for (var i = data.sigBytes - 1; i >= 0; i--) {
  4821. if ((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff) {
  4822. data.sigBytes = i + 1;
  4823. break;
  4824. }
  4825. }
  4826. },
  4827. };
  4828.  
  4829. /**
  4830. * A noop padding strategy.
  4831. */
  4832. CryptoJS.pad.NoPadding = {
  4833. pad: function () {},
  4834.  
  4835. unpad: function () {},
  4836. };
  4837.  
  4838. (function (undefined) {
  4839. // Shortcuts
  4840. var C = CryptoJS;
  4841. var C_lib = C.lib;
  4842. var CipherParams = C_lib.CipherParams;
  4843. var C_enc = C.enc;
  4844. var Hex = C_enc.Hex;
  4845. var C_format = C.format;
  4846.  
  4847. var HexFormatter = (C_format.Hex = {
  4848. /**
  4849. * Converts the ciphertext of a cipher params object to a hexadecimally encoded string.
  4850. *
  4851. * @param {CipherParams} cipherParams The cipher params object.
  4852. *
  4853. * @return {string} The hexadecimally encoded string.
  4854. *
  4855. * @static
  4856. *
  4857. * @example
  4858. *
  4859. * var hexString = CryptoJS.format.Hex.stringify(cipherParams);
  4860. */
  4861. stringify: function (cipherParams) {
  4862. return cipherParams.ciphertext.toString(Hex);
  4863. },
  4864.  
  4865. /**
  4866. * Converts a hexadecimally encoded ciphertext string to a cipher params object.
  4867. *
  4868. * @param {string} input The hexadecimally encoded string.
  4869. *
  4870. * @return {CipherParams} The cipher params object.
  4871. *
  4872. * @static
  4873. *
  4874. * @example
  4875. *
  4876. * var cipherParams = CryptoJS.format.Hex.parse(hexString);
  4877. */
  4878. parse: function (input) {
  4879. var ciphertext = Hex.parse(input);
  4880. return CipherParams.create({ ciphertext: ciphertext });
  4881. },
  4882. });
  4883. })();
  4884.  
  4885. (function () {
  4886. // Shortcuts
  4887. var C = CryptoJS;
  4888. var C_lib = C.lib;
  4889. var BlockCipher = C_lib.BlockCipher;
  4890. var C_algo = C.algo;
  4891.  
  4892. // Lookup tables
  4893. var SBOX = [];
  4894. var INV_SBOX = [];
  4895. var SUB_MIX_0 = [];
  4896. var SUB_MIX_1 = [];
  4897. var SUB_MIX_2 = [];
  4898. var SUB_MIX_3 = [];
  4899. var INV_SUB_MIX_0 = [];
  4900. var INV_SUB_MIX_1 = [];
  4901. var INV_SUB_MIX_2 = [];
  4902. var INV_SUB_MIX_3 = [];
  4903.  
  4904. // Compute lookup tables
  4905. (function () {
  4906. // Compute double table
  4907. var d = [];
  4908. for (var i = 0; i < 256; i++) {
  4909. if (i < 128) {
  4910. d[i] = i << 1;
  4911. } else {
  4912. d[i] = (i << 1) ^ 0x11b;
  4913. }
  4914. }
  4915.  
  4916. // Walk GF(2^8)
  4917. var x = 0;
  4918. var xi = 0;
  4919. for (var i = 0; i < 256; i++) {
  4920. // Compute sbox
  4921. var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
  4922. sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
  4923. SBOX[x] = sx;
  4924. INV_SBOX[sx] = x;
  4925.  
  4926. // Compute multiplication
  4927. var x2 = d[x];
  4928. var x4 = d[x2];
  4929. var x8 = d[x4];
  4930.  
  4931. // Compute sub bytes, mix columns tables
  4932. var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
  4933. SUB_MIX_0[x] = (t << 24) | (t >>> 8);
  4934. SUB_MIX_1[x] = (t << 16) | (t >>> 16);
  4935. SUB_MIX_2[x] = (t << 8) | (t >>> 24);
  4936. SUB_MIX_3[x] = t;
  4937.  
  4938. // Compute inv sub bytes, inv mix columns tables
  4939. var t =
  4940. (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
  4941. INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
  4942. INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
  4943. INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
  4944. INV_SUB_MIX_3[sx] = t;
  4945.  
  4946. // Compute next counter
  4947. if (!x) {
  4948. x = xi = 1;
  4949. } else {
  4950. x = x2 ^ d[d[d[x8 ^ x2]]];
  4951. xi ^= d[d[xi]];
  4952. }
  4953. }
  4954. })();
  4955.  
  4956. // Precomputed Rcon lookup
  4957. var RCON = [
  4958. 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36,
  4959. ];
  4960.  
  4961. /**
  4962. * AES block cipher algorithm.
  4963. */
  4964. var AES = (C_algo.AES = BlockCipher.extend({
  4965. _doReset: function () {
  4966. var t;
  4967.  
  4968. // Skip reset of nRounds has been set before and key did not change
  4969. if (this._nRounds && this._keyPriorReset === this._key) {
  4970. return;
  4971. }
  4972.  
  4973. // Shortcuts
  4974. var key = (this._keyPriorReset = this._key);
  4975. var keyWords = key.words;
  4976. var keySize = key.sigBytes / 4;
  4977.  
  4978. // Compute number of rounds
  4979. var nRounds = (this._nRounds = keySize + 6);
  4980.  
  4981. // Compute number of key schedule rows
  4982. var ksRows = (nRounds + 1) * 4;
  4983.  
  4984. // Compute key schedule
  4985. var keySchedule = (this._keySchedule = []);
  4986. for (var ksRow = 0; ksRow < ksRows; ksRow++) {
  4987. if (ksRow < keySize) {
  4988. keySchedule[ksRow] = keyWords[ksRow];
  4989. } else {
  4990. t = keySchedule[ksRow - 1];
  4991.  
  4992. if (!(ksRow % keySize)) {
  4993. // Rot word
  4994. t = (t << 8) | (t >>> 24);
  4995.  
  4996. // Sub word
  4997. t =
  4998. (SBOX[t >>> 24] << 24) |
  4999. (SBOX[(t >>> 16) & 0xff] << 16) |
  5000. (SBOX[(t >>> 8) & 0xff] << 8) |
  5001. SBOX[t & 0xff];
  5002.  
  5003. // Mix Rcon
  5004. t ^= RCON[(ksRow / keySize) | 0] << 24;
  5005. } else if (keySize > 6 && ksRow % keySize == 4) {
  5006. // Sub word
  5007. t =
  5008. (SBOX[t >>> 24] << 24) |
  5009. (SBOX[(t >>> 16) & 0xff] << 16) |
  5010. (SBOX[(t >>> 8) & 0xff] << 8) |
  5011. SBOX[t & 0xff];
  5012. }
  5013.  
  5014. keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
  5015. }
  5016. }
  5017.  
  5018. // Compute inv key schedule
  5019. var invKeySchedule = (this._invKeySchedule = []);
  5020. for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
  5021. var ksRow = ksRows - invKsRow;
  5022.  
  5023. if (invKsRow % 4) {
  5024. var t = keySchedule[ksRow];
  5025. } else {
  5026. var t = keySchedule[ksRow - 4];
  5027. }
  5028.  
  5029. if (invKsRow < 4 || ksRow <= 4) {
  5030. invKeySchedule[invKsRow] = t;
  5031. } else {
  5032. invKeySchedule[invKsRow] =
  5033. INV_SUB_MIX_0[SBOX[t >>> 24]] ^
  5034. INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
  5035. INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^
  5036. INV_SUB_MIX_3[SBOX[t & 0xff]];
  5037. }
  5038. }
  5039. },
  5040.  
  5041. encryptBlock: function (M, offset) {
  5042. this._doCryptBlock(
  5043. M,
  5044. offset,
  5045. this._keySchedule,
  5046. SUB_MIX_0,
  5047. SUB_MIX_1,
  5048. SUB_MIX_2,
  5049. SUB_MIX_3,
  5050. SBOX
  5051. );
  5052. },
  5053.  
  5054. decryptBlock: function (M, offset) {
  5055. // Swap 2nd and 4th rows
  5056. var t = M[offset + 1];
  5057. M[offset + 1] = M[offset + 3];
  5058. M[offset + 3] = t;
  5059.  
  5060. this._doCryptBlock(
  5061. M,
  5062. offset,
  5063. this._invKeySchedule,
  5064. INV_SUB_MIX_0,
  5065. INV_SUB_MIX_1,
  5066. INV_SUB_MIX_2,
  5067. INV_SUB_MIX_3,
  5068. INV_SBOX
  5069. );
  5070.  
  5071. // Inv swap 2nd and 4th rows
  5072. var t = M[offset + 1];
  5073. M[offset + 1] = M[offset + 3];
  5074. M[offset + 3] = t;
  5075. },
  5076.  
  5077. _doCryptBlock: function (
  5078. M,
  5079. offset,
  5080. keySchedule,
  5081. SUB_MIX_0,
  5082. SUB_MIX_1,
  5083. SUB_MIX_2,
  5084. SUB_MIX_3,
  5085. SBOX
  5086. ) {
  5087. // Shortcut
  5088. var nRounds = this._nRounds;
  5089.  
  5090. // Get input, add round key
  5091. var s0 = M[offset] ^ keySchedule[0];
  5092. var s1 = M[offset + 1] ^ keySchedule[1];
  5093. var s2 = M[offset + 2] ^ keySchedule[2];
  5094. var s3 = M[offset + 3] ^ keySchedule[3];
  5095.  
  5096. // Key schedule row counter
  5097. var ksRow = 4;
  5098.  
  5099. // Rounds
  5100. for (var round = 1; round < nRounds; round++) {
  5101. // Shift rows, sub bytes, mix columns, add round key
  5102. var t0 =
  5103. SUB_MIX_0[s0 >>> 24] ^
  5104. SUB_MIX_1[(s1 >>> 16) & 0xff] ^
  5105. SUB_MIX_2[(s2 >>> 8) & 0xff] ^
  5106. SUB_MIX_3[s3 & 0xff] ^
  5107. keySchedule[ksRow++];
  5108. var t1 =
  5109. SUB_MIX_0[s1 >>> 24] ^
  5110. SUB_MIX_1[(s2 >>> 16) & 0xff] ^
  5111. SUB_MIX_2[(s3 >>> 8) & 0xff] ^
  5112. SUB_MIX_3[s0 & 0xff] ^
  5113. keySchedule[ksRow++];
  5114. var t2 =
  5115. SUB_MIX_0[s2 >>> 24] ^
  5116. SUB_MIX_1[(s3 >>> 16) & 0xff] ^
  5117. SUB_MIX_2[(s0 >>> 8) & 0xff] ^
  5118. SUB_MIX_3[s1 & 0xff] ^
  5119. keySchedule[ksRow++];
  5120. var t3 =
  5121. SUB_MIX_0[s3 >>> 24] ^
  5122. SUB_MIX_1[(s0 >>> 16) & 0xff] ^
  5123. SUB_MIX_2[(s1 >>> 8) & 0xff] ^
  5124. SUB_MIX_3[s2 & 0xff] ^
  5125. keySchedule[ksRow++];
  5126.  
  5127. // Update state
  5128. s0 = t0;
  5129. s1 = t1;
  5130. s2 = t2;
  5131. s3 = t3;
  5132. }
  5133.  
  5134. // Shift rows, sub bytes, add round key
  5135. var t0 =
  5136. ((SBOX[s0 >>> 24] << 24) |
  5137. (SBOX[(s1 >>> 16) & 0xff] << 16) |
  5138. (SBOX[(s2 >>> 8) & 0xff] << 8) |
  5139. SBOX[s3 & 0xff]) ^
  5140. keySchedule[ksRow++];
  5141. var t1 =
  5142. ((SBOX[s1 >>> 24] << 24) |
  5143. (SBOX[(s2 >>> 16) & 0xff] << 16) |
  5144. (SBOX[(s3 >>> 8) & 0xff] << 8) |
  5145. SBOX[s0 & 0xff]) ^
  5146. keySchedule[ksRow++];
  5147. var t2 =
  5148. ((SBOX[s2 >>> 24] << 24) |
  5149. (SBOX[(s3 >>> 16) & 0xff] << 16) |
  5150. (SBOX[(s0 >>> 8) & 0xff] << 8) |
  5151. SBOX[s1 & 0xff]) ^
  5152. keySchedule[ksRow++];
  5153. var t3 =
  5154. ((SBOX[s3 >>> 24] << 24) |
  5155. (SBOX[(s0 >>> 16) & 0xff] << 16) |
  5156. (SBOX[(s1 >>> 8) & 0xff] << 8) |
  5157. SBOX[s2 & 0xff]) ^
  5158. keySchedule[ksRow++];
  5159.  
  5160. // Set output
  5161. M[offset] = t0;
  5162. M[offset + 1] = t1;
  5163. M[offset + 2] = t2;
  5164. M[offset + 3] = t3;
  5165. },
  5166.  
  5167. keySize: 256 / 32,
  5168. }));
  5169.  
  5170. /**
  5171. * Shortcut functions to the cipher's object interface.
  5172. *
  5173. * @example
  5174. *
  5175. * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
  5176. * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
  5177. */
  5178. C.AES = BlockCipher._createHelper(AES);
  5179. })();
  5180.  
  5181. (function () {
  5182. // Shortcuts
  5183. var C = CryptoJS;
  5184. var C_lib = C.lib;
  5185. var WordArray = C_lib.WordArray;
  5186. var BlockCipher = C_lib.BlockCipher;
  5187. var C_algo = C.algo;
  5188.  
  5189. // Permuted Choice 1 constants
  5190. var PC1 = [
  5191. 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43,
  5192. 35, 27, 19, 11, 3, 60, 52, 44, 36, 63, 55, 47, 39, 31, 23, 15, 7, 62, 54,
  5193. 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4,
  5194. ];
  5195.  
  5196. // Permuted Choice 2 constants
  5197. var PC2 = [
  5198. 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 23, 19, 12, 4, 26, 8, 16, 7,
  5199. 27, 20, 13, 2, 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39,
  5200. 56, 34, 53, 46, 42, 50, 36, 29, 32,
  5201. ];
  5202.  
  5203. // Cumulative bit shift constants
  5204. var BIT_SHIFTS = [
  5205. 1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28,
  5206. ];
  5207.  
  5208. // SBOXes and round permutation constants
  5209. var SBOX_P = [
  5210. {
  5211. 0x0: 0x808200,
  5212. 0x10000000: 0x8000,
  5213. 0x20000000: 0x808002,
  5214. 0x30000000: 0x2,
  5215. 0x40000000: 0x200,
  5216. 0x50000000: 0x808202,
  5217. 0x60000000: 0x800202,
  5218. 0x70000000: 0x800000,
  5219. 0x80000000: 0x202,
  5220. 0x90000000: 0x800200,
  5221. 0xa0000000: 0x8200,
  5222. 0xb0000000: 0x808000,
  5223. 0xc0000000: 0x8002,
  5224. 0xd0000000: 0x800002,
  5225. 0xe0000000: 0x0,
  5226. 0xf0000000: 0x8202,
  5227. 0x8000000: 0x0,
  5228. 0x18000000: 0x808202,
  5229. 0x28000000: 0x8202,
  5230. 0x38000000: 0x8000,
  5231. 0x48000000: 0x808200,
  5232. 0x58000000: 0x200,
  5233. 0x68000000: 0x808002,
  5234. 0x78000000: 0x2,
  5235. 0x88000000: 0x800200,
  5236. 0x98000000: 0x8200,
  5237. 0xa8000000: 0x808000,
  5238. 0xb8000000: 0x800202,
  5239. 0xc8000000: 0x800002,
  5240. 0xd8000000: 0x8002,
  5241. 0xe8000000: 0x202,
  5242. 0xf8000000: 0x800000,
  5243. 0x1: 0x8000,
  5244. 0x10000001: 0x2,
  5245. 0x20000001: 0x808200,
  5246. 0x30000001: 0x800000,
  5247. 0x40000001: 0x808002,
  5248. 0x50000001: 0x8200,
  5249. 0x60000001: 0x200,
  5250. 0x70000001: 0x800202,
  5251. 0x80000001: 0x808202,
  5252. 0x90000001: 0x808000,
  5253. 0xa0000001: 0x800002,
  5254. 0xb0000001: 0x8202,
  5255. 0xc0000001: 0x202,
  5256. 0xd0000001: 0x800200,
  5257. 0xe0000001: 0x8002,
  5258. 0xf0000001: 0x0,
  5259. 0x8000001: 0x808202,
  5260. 0x18000001: 0x808000,
  5261. 0x28000001: 0x800000,
  5262. 0x38000001: 0x200,
  5263. 0x48000001: 0x8000,
  5264. 0x58000001: 0x800002,
  5265. 0x68000001: 0x2,
  5266. 0x78000001: 0x8202,
  5267. 0x88000001: 0x8002,
  5268. 0x98000001: 0x800202,
  5269. 0xa8000001: 0x202,
  5270. 0xb8000001: 0x808200,
  5271. 0xc8000001: 0x800200,
  5272. 0xd8000001: 0x0,
  5273. 0xe8000001: 0x8200,
  5274. 0xf8000001: 0x808002,
  5275. },
  5276. {
  5277. 0x0: 0x40084010,
  5278. 0x1000000: 0x4000,
  5279. 0x2000000: 0x80000,
  5280. 0x3000000: 0x40080010,
  5281. 0x4000000: 0x40000010,
  5282. 0x5000000: 0x40084000,
  5283. 0x6000000: 0x40004000,
  5284. 0x7000000: 0x10,
  5285. 0x8000000: 0x84000,
  5286. 0x9000000: 0x40004010,
  5287. 0xa000000: 0x40000000,
  5288. 0xb000000: 0x84010,
  5289. 0xc000000: 0x80010,
  5290. 0xd000000: 0x0,
  5291. 0xe000000: 0x4010,
  5292. 0xf000000: 0x40080000,
  5293. 0x800000: 0x40004000,
  5294. 0x1800000: 0x84010,
  5295. 0x2800000: 0x10,
  5296. 0x3800000: 0x40004010,
  5297. 0x4800000: 0x40084010,
  5298. 0x5800000: 0x40000000,
  5299. 0x6800000: 0x80000,
  5300. 0x7800000: 0x40080010,
  5301. 0x8800000: 0x80010,
  5302. 0x9800000: 0x0,
  5303. 0xa800000: 0x4000,
  5304. 0xb800000: 0x40080000,
  5305. 0xc800000: 0x40000010,
  5306. 0xd800000: 0x84000,
  5307. 0xe800000: 0x40084000,
  5308. 0xf800000: 0x4010,
  5309. 0x10000000: 0x0,
  5310. 0x11000000: 0x40080010,
  5311. 0x12000000: 0x40004010,
  5312. 0x13000000: 0x40084000,
  5313. 0x14000000: 0x40080000,
  5314. 0x15000000: 0x10,
  5315. 0x16000000: 0x84010,
  5316. 0x17000000: 0x4000,
  5317. 0x18000000: 0x4010,
  5318. 0x19000000: 0x80000,
  5319. 0x1a000000: 0x80010,
  5320. 0x1b000000: 0x40000010,
  5321. 0x1c000000: 0x84000,
  5322. 0x1d000000: 0x40004000,
  5323. 0x1e000000: 0x40000000,
  5324. 0x1f000000: 0x40084010,
  5325. 0x10800000: 0x84010,
  5326. 0x11800000: 0x80000,
  5327. 0x12800000: 0x40080000,
  5328. 0x13800000: 0x4000,
  5329. 0x14800000: 0x40004000,
  5330. 0x15800000: 0x40084010,
  5331. 0x16800000: 0x10,
  5332. 0x17800000: 0x40000000,
  5333. 0x18800000: 0x40084000,
  5334. 0x19800000: 0x40000010,
  5335. 0x1a800000: 0x40004010,
  5336. 0x1b800000: 0x80010,
  5337. 0x1c800000: 0x0,
  5338. 0x1d800000: 0x4010,
  5339. 0x1e800000: 0x40080010,
  5340. 0x1f800000: 0x84000,
  5341. },
  5342. {
  5343. 0x0: 0x104,
  5344. 0x100000: 0x0,
  5345. 0x200000: 0x4000100,
  5346. 0x300000: 0x10104,
  5347. 0x400000: 0x10004,
  5348. 0x500000: 0x4000004,
  5349. 0x600000: 0x4010104,
  5350. 0x700000: 0x4010000,
  5351. 0x800000: 0x4000000,
  5352. 0x900000: 0x4010100,
  5353. 0xa00000: 0x10100,
  5354. 0xb00000: 0x4010004,
  5355. 0xc00000: 0x4000104,
  5356. 0xd00000: 0x10000,
  5357. 0xe00000: 0x4,
  5358. 0xf00000: 0x100,
  5359. 0x80000: 0x4010100,
  5360. 0x180000: 0x4010004,
  5361. 0x280000: 0x0,
  5362. 0x380000: 0x4000100,
  5363. 0x480000: 0x4000004,
  5364. 0x580000: 0x10000,
  5365. 0x680000: 0x10004,
  5366. 0x780000: 0x104,
  5367. 0x880000: 0x4,
  5368. 0x980000: 0x100,
  5369. 0xa80000: 0x4010000,
  5370. 0xb80000: 0x10104,
  5371. 0xc80000: 0x10100,
  5372. 0xd80000: 0x4000104,
  5373. 0xe80000: 0x4010104,
  5374. 0xf80000: 0x4000000,
  5375. 0x1000000: 0x4010100,
  5376. 0x1100000: 0x10004,
  5377. 0x1200000: 0x10000,
  5378. 0x1300000: 0x4000100,
  5379. 0x1400000: 0x100,
  5380. 0x1500000: 0x4010104,
  5381. 0x1600000: 0x4000004,
  5382. 0x1700000: 0x0,
  5383. 0x1800000: 0x4000104,
  5384. 0x1900000: 0x4000000,
  5385. 0x1a00000: 0x4,
  5386. 0x1b00000: 0x10100,
  5387. 0x1c00000: 0x4010000,
  5388. 0x1d00000: 0x104,
  5389. 0x1e00000: 0x10104,
  5390. 0x1f00000: 0x4010004,
  5391. 0x1080000: 0x4000000,
  5392. 0x1180000: 0x104,
  5393. 0x1280000: 0x4010100,
  5394. 0x1380000: 0x0,
  5395. 0x1480000: 0x10004,
  5396. 0x1580000: 0x4000100,
  5397. 0x1680000: 0x100,
  5398. 0x1780000: 0x4010004,
  5399. 0x1880000: 0x10000,
  5400. 0x1980000: 0x4010104,
  5401. 0x1a80000: 0x10104,
  5402. 0x1b80000: 0x4000004,
  5403. 0x1c80000: 0x4000104,
  5404. 0x1d80000: 0x4010000,
  5405. 0x1e80000: 0x4,
  5406. 0x1f80000: 0x10100,
  5407. },
  5408. {
  5409. 0x0: 0x80401000,
  5410. 0x10000: 0x80001040,
  5411. 0x20000: 0x401040,
  5412. 0x30000: 0x80400000,
  5413. 0x40000: 0x0,
  5414. 0x50000: 0x401000,
  5415. 0x60000: 0x80000040,
  5416. 0x70000: 0x400040,
  5417. 0x80000: 0x80000000,
  5418. 0x90000: 0x400000,
  5419. 0xa0000: 0x40,
  5420. 0xb0000: 0x80001000,
  5421. 0xc0000: 0x80400040,
  5422. 0xd0000: 0x1040,
  5423. 0xe0000: 0x1000,
  5424. 0xf0000: 0x80401040,
  5425. 0x8000: 0x80001040,
  5426. 0x18000: 0x40,
  5427. 0x28000: 0x80400040,
  5428. 0x38000: 0x80001000,
  5429. 0x48000: 0x401000,
  5430. 0x58000: 0x80401040,
  5431. 0x68000: 0x0,
  5432. 0x78000: 0x80400000,
  5433. 0x88000: 0x1000,
  5434. 0x98000: 0x80401000,
  5435. 0xa8000: 0x400000,
  5436. 0xb8000: 0x1040,
  5437. 0xc8000: 0x80000000,
  5438. 0xd8000: 0x400040,
  5439. 0xe8000: 0x401040,
  5440. 0xf8000: 0x80000040,
  5441. 0x100000: 0x400040,
  5442. 0x110000: 0x401000,
  5443. 0x120000: 0x80000040,
  5444. 0x130000: 0x0,
  5445. 0x140000: 0x1040,
  5446. 0x150000: 0x80400040,
  5447. 0x160000: 0x80401000,
  5448. 0x170000: 0x80001040,
  5449. 0x180000: 0x80401040,
  5450. 0x190000: 0x80000000,
  5451. 0x1a0000: 0x80400000,
  5452. 0x1b0000: 0x401040,
  5453. 0x1c0000: 0x80001000,
  5454. 0x1d0000: 0x400000,
  5455. 0x1e0000: 0x40,
  5456. 0x1f0000: 0x1000,
  5457. 0x108000: 0x80400000,
  5458. 0x118000: 0x80401040,
  5459. 0x128000: 0x0,
  5460. 0x138000: 0x401000,
  5461. 0x148000: 0x400040,
  5462. 0x158000: 0x80000000,
  5463. 0x168000: 0x80001040,
  5464. 0x178000: 0x40,
  5465. 0x188000: 0x80000040,
  5466. 0x198000: 0x1000,
  5467. 0x1a8000: 0x80001000,
  5468. 0x1b8000: 0x80400040,
  5469. 0x1c8000: 0x1040,
  5470. 0x1d8000: 0x80401000,
  5471. 0x1e8000: 0x400000,
  5472. 0x1f8000: 0x401040,
  5473. },
  5474. {
  5475. 0x0: 0x80,
  5476. 0x1000: 0x1040000,
  5477. 0x2000: 0x40000,
  5478. 0x3000: 0x20000000,
  5479. 0x4000: 0x20040080,
  5480. 0x5000: 0x1000080,
  5481. 0x6000: 0x21000080,
  5482. 0x7000: 0x40080,
  5483. 0x8000: 0x1000000,
  5484. 0x9000: 0x20040000,
  5485. 0xa000: 0x20000080,
  5486. 0xb000: 0x21040080,
  5487. 0xc000: 0x21040000,
  5488. 0xd000: 0x0,
  5489. 0xe000: 0x1040080,
  5490. 0xf000: 0x21000000,
  5491. 0x800: 0x1040080,
  5492. 0x1800: 0x21000080,
  5493. 0x2800: 0x80,
  5494. 0x3800: 0x1040000,
  5495. 0x4800: 0x40000,
  5496. 0x5800: 0x20040080,
  5497. 0x6800: 0x21040000,
  5498. 0x7800: 0x20000000,
  5499. 0x8800: 0x20040000,
  5500. 0x9800: 0x0,
  5501. 0xa800: 0x21040080,
  5502. 0xb800: 0x1000080,
  5503. 0xc800: 0x20000080,
  5504. 0xd800: 0x21000000,
  5505. 0xe800: 0x1000000,
  5506. 0xf800: 0x40080,
  5507. 0x10000: 0x40000,
  5508. 0x11000: 0x80,
  5509. 0x12000: 0x20000000,
  5510. 0x13000: 0x21000080,
  5511. 0x14000: 0x1000080,
  5512. 0x15000: 0x21040000,
  5513. 0x16000: 0x20040080,
  5514. 0x17000: 0x1000000,
  5515. 0x18000: 0x21040080,
  5516. 0x19000: 0x21000000,
  5517. 0x1a000: 0x1040000,
  5518. 0x1b000: 0x20040000,
  5519. 0x1c000: 0x40080,
  5520. 0x1d000: 0x20000080,
  5521. 0x1e000: 0x0,
  5522. 0x1f000: 0x1040080,
  5523. 0x10800: 0x21000080,
  5524. 0x11800: 0x1000000,
  5525. 0x12800: 0x1040000,
  5526. 0x13800: 0x20040080,
  5527. 0x14800: 0x20000000,
  5528. 0x15800: 0x1040080,
  5529. 0x16800: 0x80,
  5530. 0x17800: 0x21040000,
  5531. 0x18800: 0x40080,
  5532. 0x19800: 0x21040080,
  5533. 0x1a800: 0x0,
  5534. 0x1b800: 0x21000000,
  5535. 0x1c800: 0x1000080,
  5536. 0x1d800: 0x40000,
  5537. 0x1e800: 0x20040000,
  5538. 0x1f800: 0x20000080,
  5539. },
  5540. {
  5541. 0x0: 0x10000008,
  5542. 0x100: 0x2000,
  5543. 0x200: 0x10200000,
  5544. 0x300: 0x10202008,
  5545. 0x400: 0x10002000,
  5546. 0x500: 0x200000,
  5547. 0x600: 0x200008,
  5548. 0x700: 0x10000000,
  5549. 0x800: 0x0,
  5550. 0x900: 0x10002008,
  5551. 0xa00: 0x202000,
  5552. 0xb00: 0x8,
  5553. 0xc00: 0x10200008,
  5554. 0xd00: 0x202008,
  5555. 0xe00: 0x2008,
  5556. 0xf00: 0x10202000,
  5557. 0x80: 0x10200000,
  5558. 0x180: 0x10202008,
  5559. 0x280: 0x8,
  5560. 0x380: 0x200000,
  5561. 0x480: 0x202008,
  5562. 0x580: 0x10000008,
  5563. 0x680: 0x10002000,
  5564. 0x780: 0x2008,
  5565. 0x880: 0x200008,
  5566. 0x980: 0x2000,
  5567. 0xa80: 0x10002008,
  5568. 0xb80: 0x10200008,
  5569. 0xc80: 0x0,
  5570. 0xd80: 0x10202000,
  5571. 0xe80: 0x202000,
  5572. 0xf80: 0x10000000,
  5573. 0x1000: 0x10002000,
  5574. 0x1100: 0x10200008,
  5575. 0x1200: 0x10202008,
  5576. 0x1300: 0x2008,
  5577. 0x1400: 0x200000,
  5578. 0x1500: 0x10000000,
  5579. 0x1600: 0x10000008,
  5580. 0x1700: 0x202000,
  5581. 0x1800: 0x202008,
  5582. 0x1900: 0x0,
  5583. 0x1a00: 0x8,
  5584. 0x1b00: 0x10200000,
  5585. 0x1c00: 0x2000,
  5586. 0x1d00: 0x10002008,
  5587. 0x1e00: 0x10202000,
  5588. 0x1f00: 0x200008,
  5589. 0x1080: 0x8,
  5590. 0x1180: 0x202000,
  5591. 0x1280: 0x200000,
  5592. 0x1380: 0x10000008,
  5593. 0x1480: 0x10002000,
  5594. 0x1580: 0x2008,
  5595. 0x1680: 0x10202008,
  5596. 0x1780: 0x10200000,
  5597. 0x1880: 0x10202000,
  5598. 0x1980: 0x10200008,
  5599. 0x1a80: 0x2000,
  5600. 0x1b80: 0x202008,
  5601. 0x1c80: 0x200008,
  5602. 0x1d80: 0x0,
  5603. 0x1e80: 0x10000000,
  5604. 0x1f80: 0x10002008,
  5605. },
  5606. {
  5607. 0x0: 0x100000,
  5608. 0x10: 0x2000401,
  5609. 0x20: 0x400,
  5610. 0x30: 0x100401,
  5611. 0x40: 0x2100401,
  5612. 0x50: 0x0,
  5613. 0x60: 0x1,
  5614. 0x70: 0x2100001,
  5615. 0x80: 0x2000400,
  5616. 0x90: 0x100001,
  5617. 0xa0: 0x2000001,
  5618. 0xb0: 0x2100400,
  5619. 0xc0: 0x2100000,
  5620. 0xd0: 0x401,
  5621. 0xe0: 0x100400,
  5622. 0xf0: 0x2000000,
  5623. 0x8: 0x2100001,
  5624. 0x18: 0x0,
  5625. 0x28: 0x2000401,
  5626. 0x38: 0x2100400,
  5627. 0x48: 0x100000,
  5628. 0x58: 0x2000001,
  5629. 0x68: 0x2000000,
  5630. 0x78: 0x401,
  5631. 0x88: 0x100401,
  5632. 0x98: 0x2000400,
  5633. 0xa8: 0x2100000,
  5634. 0xb8: 0x100001,
  5635. 0xc8: 0x400,
  5636. 0xd8: 0x2100401,
  5637. 0xe8: 0x1,
  5638. 0xf8: 0x100400,
  5639. 0x100: 0x2000000,
  5640. 0x110: 0x100000,
  5641. 0x120: 0x2000401,
  5642. 0x130: 0x2100001,
  5643. 0x140: 0x100001,
  5644. 0x150: 0x2000400,
  5645. 0x160: 0x2100400,
  5646. 0x170: 0x100401,
  5647. 0x180: 0x401,
  5648. 0x190: 0x2100401,
  5649. 0x1a0: 0x100400,
  5650. 0x1b0: 0x1,
  5651. 0x1c0: 0x0,
  5652. 0x1d0: 0x2100000,
  5653. 0x1e0: 0x2000001,
  5654. 0x1f0: 0x400,
  5655. 0x108: 0x100400,
  5656. 0x118: 0x2000401,
  5657. 0x128: 0x2100001,
  5658. 0x138: 0x1,
  5659. 0x148: 0x2000000,
  5660. 0x158: 0x100000,
  5661. 0x168: 0x401,
  5662. 0x178: 0x2100400,
  5663. 0x188: 0x2000001,
  5664. 0x198: 0x2100000,
  5665. 0x1a8: 0x0,
  5666. 0x1b8: 0x2100401,
  5667. 0x1c8: 0x100401,
  5668. 0x1d8: 0x400,
  5669. 0x1e8: 0x2000400,
  5670. 0x1f8: 0x100001,
  5671. },
  5672. {
  5673. 0x0: 0x8000820,
  5674. 0x1: 0x20000,
  5675. 0x2: 0x8000000,
  5676. 0x3: 0x20,
  5677. 0x4: 0x20020,
  5678. 0x5: 0x8020820,
  5679. 0x6: 0x8020800,
  5680. 0x7: 0x800,
  5681. 0x8: 0x8020000,
  5682. 0x9: 0x8000800,
  5683. 0xa: 0x20800,
  5684. 0xb: 0x8020020,
  5685. 0xc: 0x820,
  5686. 0xd: 0x0,
  5687. 0xe: 0x8000020,
  5688. 0xf: 0x20820,
  5689. 0x80000000: 0x800,
  5690. 0x80000001: 0x8020820,
  5691. 0x80000002: 0x8000820,
  5692. 0x80000003: 0x8000000,
  5693. 0x80000004: 0x8020000,
  5694. 0x80000005: 0x20800,
  5695. 0x80000006: 0x20820,
  5696. 0x80000007: 0x20,
  5697. 0x80000008: 0x8000020,
  5698. 0x80000009: 0x820,
  5699. 0x8000000a: 0x20020,
  5700. 0x8000000b: 0x8020800,
  5701. 0x8000000c: 0x0,
  5702. 0x8000000d: 0x8020020,
  5703. 0x8000000e: 0x8000800,
  5704. 0x8000000f: 0x20000,
  5705. 0x10: 0x20820,
  5706. 0x11: 0x8020800,
  5707. 0x12: 0x20,
  5708. 0x13: 0x800,
  5709. 0x14: 0x8000800,
  5710. 0x15: 0x8000020,
  5711. 0x16: 0x8020020,
  5712. 0x17: 0x20000,
  5713. 0x18: 0x0,
  5714. 0x19: 0x20020,
  5715. 0x1a: 0x8020000,
  5716. 0x1b: 0x8000820,
  5717. 0x1c: 0x8020820,
  5718. 0x1d: 0x20800,
  5719. 0x1e: 0x820,
  5720. 0x1f: 0x8000000,
  5721. 0x80000010: 0x20000,
  5722. 0x80000011: 0x800,
  5723. 0x80000012: 0x8020020,
  5724. 0x80000013: 0x20820,
  5725. 0x80000014: 0x20,
  5726. 0x80000015: 0x8020000,
  5727. 0x80000016: 0x8000000,
  5728. 0x80000017: 0x8000820,
  5729. 0x80000018: 0x8020820,
  5730. 0x80000019: 0x8000020,
  5731. 0x8000001a: 0x8000800,
  5732. 0x8000001b: 0x0,
  5733. 0x8000001c: 0x20800,
  5734. 0x8000001d: 0x820,
  5735. 0x8000001e: 0x20020,
  5736. 0x8000001f: 0x8020800,
  5737. },
  5738. ];
  5739.  
  5740. // Masks that select the SBOX input
  5741. var SBOX_MASK = [
  5742. 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000, 0x0001f800, 0x00001f80,
  5743. 0x000001f8, 0x8000001f,
  5744. ];
  5745.  
  5746. /**
  5747. * DES block cipher algorithm.
  5748. */
  5749. var DES = (C_algo.DES = BlockCipher.extend({
  5750. _doReset: function () {
  5751. // Shortcuts
  5752. var key = this._key;
  5753. var keyWords = key.words;
  5754.  
  5755. // Select 56 bits according to PC1
  5756. var keyBits = [];
  5757. for (var i = 0; i < 56; i++) {
  5758. var keyBitPos = PC1[i] - 1;
  5759. keyBits[i] =
  5760. (keyWords[keyBitPos >>> 5] >>> (31 - (keyBitPos % 32))) & 1;
  5761. }
  5762.  
  5763. // Assemble 16 subkeys
  5764. var subKeys = (this._subKeys = []);
  5765. for (var nSubKey = 0; nSubKey < 16; nSubKey++) {
  5766. // Create subkey
  5767. var subKey = (subKeys[nSubKey] = []);
  5768.  
  5769. // Shortcut
  5770. var bitShift = BIT_SHIFTS[nSubKey];
  5771.  
  5772. // Select 48 bits according to PC2
  5773. for (var i = 0; i < 24; i++) {
  5774. // Select from the left 28 key bits
  5775. subKey[(i / 6) | 0] |=
  5776. keyBits[(PC2[i] - 1 + bitShift) % 28] << (31 - (i % 6));
  5777.  
  5778. // Select from the right 28 key bits
  5779. subKey[4 + ((i / 6) | 0)] |=
  5780. keyBits[28 + ((PC2[i + 24] - 1 + bitShift) % 28)] <<
  5781. (31 - (i % 6));
  5782. }
  5783.  
  5784. // Since each subkey is applied to an expanded 32-bit input,
  5785. // the subkey can be broken into 8 values scaled to 32-bits,
  5786. // which allows the key to be used without expansion
  5787. subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31);
  5788. for (var i = 1; i < 7; i++) {
  5789. subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3);
  5790. }
  5791. subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27);
  5792. }
  5793.  
  5794. // Compute inverse subkeys
  5795. var invSubKeys = (this._invSubKeys = []);
  5796. for (var i = 0; i < 16; i++) {
  5797. invSubKeys[i] = subKeys[15 - i];
  5798. }
  5799. },
  5800.  
  5801. encryptBlock: function (M, offset) {
  5802. this._doCryptBlock(M, offset, this._subKeys);
  5803. },
  5804.  
  5805. decryptBlock: function (M, offset) {
  5806. this._doCryptBlock(M, offset, this._invSubKeys);
  5807. },
  5808.  
  5809. _doCryptBlock: function (M, offset, subKeys) {
  5810. // Get input
  5811. this._lBlock = M[offset];
  5812. this._rBlock = M[offset + 1];
  5813.  
  5814. // Initial permutation
  5815. exchangeLR.call(this, 4, 0x0f0f0f0f);
  5816. exchangeLR.call(this, 16, 0x0000ffff);
  5817. exchangeRL.call(this, 2, 0x33333333);
  5818. exchangeRL.call(this, 8, 0x00ff00ff);
  5819. exchangeLR.call(this, 1, 0x55555555);
  5820.  
  5821. // Rounds
  5822. for (var round = 0; round < 16; round++) {
  5823. // Shortcuts
  5824. var subKey = subKeys[round];
  5825. var lBlock = this._lBlock;
  5826. var rBlock = this._rBlock;
  5827.  
  5828. // Feistel function
  5829. var f = 0;
  5830. for (var i = 0; i < 8; i++) {
  5831. f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0];
  5832. }
  5833. this._lBlock = rBlock;
  5834. this._rBlock = lBlock ^ f;
  5835. }
  5836.  
  5837. // Undo swap from last round
  5838. var t = this._lBlock;
  5839. this._lBlock = this._rBlock;
  5840. this._rBlock = t;
  5841.  
  5842. // Final permutation
  5843. exchangeLR.call(this, 1, 0x55555555);
  5844. exchangeRL.call(this, 8, 0x00ff00ff);
  5845. exchangeRL.call(this, 2, 0x33333333);
  5846. exchangeLR.call(this, 16, 0x0000ffff);
  5847. exchangeLR.call(this, 4, 0x0f0f0f0f);
  5848.  
  5849. // Set output
  5850. M[offset] = this._lBlock;
  5851. M[offset + 1] = this._rBlock;
  5852. },
  5853.  
  5854. keySize: 64 / 32,
  5855.  
  5856. ivSize: 64 / 32,
  5857.  
  5858. blockSize: 64 / 32,
  5859. }));
  5860.  
  5861. // Swap bits across the left and right words
  5862. function exchangeLR(offset, mask) {
  5863. var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask;
  5864. this._rBlock ^= t;
  5865. this._lBlock ^= t << offset;
  5866. }
  5867.  
  5868. function exchangeRL(offset, mask) {
  5869. var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask;
  5870. this._lBlock ^= t;
  5871. this._rBlock ^= t << offset;
  5872. }
  5873.  
  5874. /**
  5875. * Shortcut functions to the cipher's object interface.
  5876. *
  5877. * @example
  5878. *
  5879. * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg);
  5880. * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg);
  5881. */
  5882. C.DES = BlockCipher._createHelper(DES);
  5883.  
  5884. /**
  5885. * Triple-DES block cipher algorithm.
  5886. */
  5887. var TripleDES = (C_algo.TripleDES = BlockCipher.extend({
  5888. _doReset: function () {
  5889. // Shortcuts
  5890. var key = this._key;
  5891. var keyWords = key.words;
  5892. // Make sure the key length is valid (64, 128 or >= 192 bit)
  5893. if (
  5894. keyWords.length !== 2 &&
  5895. keyWords.length !== 4 &&
  5896. keyWords.length < 6
  5897. ) {
  5898. throw new Error(
  5899. "Invalid key length - 3DES requires the key length to be 64, 128, 192 or >192."
  5900. );
  5901. }
  5902.  
  5903. // Extend the key according to the keying options defined in 3DES standard
  5904. var key1 = keyWords.slice(0, 2);
  5905. var key2 =
  5906. keyWords.length < 4 ? keyWords.slice(0, 2) : keyWords.slice(2, 4);
  5907. var key3 =
  5908. keyWords.length < 6 ? keyWords.slice(0, 2) : keyWords.slice(4, 6);
  5909.  
  5910. // Create DES instances
  5911. this._des1 = DES.createEncryptor(WordArray.create(key1));
  5912. this._des2 = DES.createEncryptor(WordArray.create(key2));
  5913. this._des3 = DES.createEncryptor(WordArray.create(key3));
  5914. },
  5915.  
  5916. encryptBlock: function (M, offset) {
  5917. this._des1.encryptBlock(M, offset);
  5918. this._des2.decryptBlock(M, offset);
  5919. this._des3.encryptBlock(M, offset);
  5920. },
  5921.  
  5922. decryptBlock: function (M, offset) {
  5923. this._des3.decryptBlock(M, offset);
  5924. this._des2.encryptBlock(M, offset);
  5925. this._des1.decryptBlock(M, offset);
  5926. },
  5927.  
  5928. keySize: 192 / 32,
  5929.  
  5930. ivSize: 64 / 32,
  5931.  
  5932. blockSize: 64 / 32,
  5933. }));
  5934.  
  5935. /**
  5936. * Shortcut functions to the cipher's object interface.
  5937. *
  5938. * @example
  5939. *
  5940. * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg);
  5941. * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg);
  5942. */
  5943. C.TripleDES = BlockCipher._createHelper(TripleDES);
  5944. })();
  5945.  
  5946. (function () {
  5947. // Shortcuts
  5948. var C = CryptoJS;
  5949. var C_lib = C.lib;
  5950. var StreamCipher = C_lib.StreamCipher;
  5951. var C_algo = C.algo;
  5952.  
  5953. /**
  5954. * RC4 stream cipher algorithm.
  5955. */
  5956. var RC4 = (C_algo.RC4 = StreamCipher.extend({
  5957. _doReset: function () {
  5958. // Shortcuts
  5959. var key = this._key;
  5960. var keyWords = key.words;
  5961. var keySigBytes = key.sigBytes;
  5962.  
  5963. // Init sbox
  5964. var S = (this._S = []);
  5965. for (var i = 0; i < 256; i++) {
  5966. S[i] = i;
  5967. }
  5968.  
  5969. // Key setup
  5970. for (var i = 0, j = 0; i < 256; i++) {
  5971. var keyByteIndex = i % keySigBytes;
  5972. var keyByte =
  5973. (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) &
  5974. 0xff;
  5975.  
  5976. j = (j + S[i] + keyByte) % 256;
  5977.  
  5978. // Swap
  5979. var t = S[i];
  5980. S[i] = S[j];
  5981. S[j] = t;
  5982. }
  5983.  
  5984. // Counters
  5985. this._i = this._j = 0;
  5986. },
  5987.  
  5988. _doProcessBlock: function (M, offset) {
  5989. M[offset] ^= generateKeystreamWord.call(this);
  5990. },
  5991.  
  5992. keySize: 256 / 32,
  5993.  
  5994. ivSize: 0,
  5995. }));
  5996.  
  5997. function generateKeystreamWord() {
  5998. // Shortcuts
  5999. var S = this._S;
  6000. var i = this._i;
  6001. var j = this._j;
  6002.  
  6003. // Generate keystream word
  6004. var keystreamWord = 0;
  6005. for (var n = 0; n < 4; n++) {
  6006. i = (i + 1) % 256;
  6007. j = (j + S[i]) % 256;
  6008.  
  6009. // Swap
  6010. var t = S[i];
  6011. S[i] = S[j];
  6012. S[j] = t;
  6013.  
  6014. keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8);
  6015. }
  6016.  
  6017. // Update counters
  6018. this._i = i;
  6019. this._j = j;
  6020.  
  6021. return keystreamWord;
  6022. }
  6023.  
  6024. /**
  6025. * Shortcut functions to the cipher's object interface.
  6026. *
  6027. * @example
  6028. *
  6029. * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg);
  6030. * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg);
  6031. */
  6032. C.RC4 = StreamCipher._createHelper(RC4);
  6033.  
  6034. /**
  6035. * Modified RC4 stream cipher algorithm.
  6036. */
  6037. var RC4Drop = (C_algo.RC4Drop = RC4.extend({
  6038. /**
  6039. * Configuration options.
  6040. *
  6041. * @property {number} drop The number of keystream words to drop. Default 192
  6042. */
  6043. cfg: RC4.cfg.extend({
  6044. drop: 192,
  6045. }),
  6046.  
  6047. _doReset: function () {
  6048. RC4._doReset.call(this);
  6049.  
  6050. // Drop
  6051. for (var i = this.cfg.drop; i > 0; i--) {
  6052. generateKeystreamWord.call(this);
  6053. }
  6054. },
  6055. }));
  6056.  
  6057. /**
  6058. * Shortcut functions to the cipher's object interface.
  6059. *
  6060. * @example
  6061. *
  6062. * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg);
  6063. * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg);
  6064. */
  6065. C.RC4Drop = StreamCipher._createHelper(RC4Drop);
  6066. })();
  6067.  
  6068. (function () {
  6069. // Shortcuts
  6070. var C = CryptoJS;
  6071. var C_lib = C.lib;
  6072. var StreamCipher = C_lib.StreamCipher;
  6073. var C_algo = C.algo;
  6074.  
  6075. // Reusable objects
  6076. var S = [];
  6077. var C_ = [];
  6078. var G = [];
  6079.  
  6080. /**
  6081. * Rabbit stream cipher algorithm
  6082. */
  6083. var Rabbit = (C_algo.Rabbit = StreamCipher.extend({
  6084. _doReset: function () {
  6085. // Shortcuts
  6086. var K = this._key.words;
  6087. var iv = this.cfg.iv;
  6088.  
  6089. // Swap endian
  6090. for (var i = 0; i < 4; i++) {
  6091. K[i] =
  6092. (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) |
  6093. (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00);
  6094. }
  6095.  
  6096. // Generate initial state values
  6097. var X = (this._X = [
  6098. K[0],
  6099. (K[3] << 16) | (K[2] >>> 16),
  6100. K[1],
  6101. (K[0] << 16) | (K[3] >>> 16),
  6102. K[2],
  6103. (K[1] << 16) | (K[0] >>> 16),
  6104. K[3],
  6105. (K[2] << 16) | (K[1] >>> 16),
  6106. ]);
  6107.  
  6108. // Generate initial counter values
  6109. var C = (this._C = [
  6110. (K[2] << 16) | (K[2] >>> 16),
  6111. (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
  6112. (K[3] << 16) | (K[3] >>> 16),
  6113. (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
  6114. (K[0] << 16) | (K[0] >>> 16),
  6115. (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
  6116. (K[1] << 16) | (K[1] >>> 16),
  6117. (K[3] & 0xffff0000) | (K[0] & 0x0000ffff),
  6118. ]);
  6119.  
  6120. // Carry bit
  6121. this._b = 0;
  6122.  
  6123. // Iterate the system four times
  6124. for (var i = 0; i < 4; i++) {
  6125. nextState.call(this);
  6126. }
  6127.  
  6128. // Modify the counters
  6129. for (var i = 0; i < 8; i++) {
  6130. C[i] ^= X[(i + 4) & 7];
  6131. }
  6132.  
  6133. // IV setup
  6134. if (iv) {
  6135. // Shortcuts
  6136. var IV = iv.words;
  6137. var IV_0 = IV[0];
  6138. var IV_1 = IV[1];
  6139.  
  6140. // Generate four subvectors
  6141. var i0 =
  6142. (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) |
  6143. (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
  6144. var i2 =
  6145. (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) |
  6146. (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
  6147. var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
  6148. var i3 = (i2 << 16) | (i0 & 0x0000ffff);
  6149.  
  6150. // Modify counter values
  6151. C[0] ^= i0;
  6152. C[1] ^= i1;
  6153. C[2] ^= i2;
  6154. C[3] ^= i3;
  6155. C[4] ^= i0;
  6156. C[5] ^= i1;
  6157. C[6] ^= i2;
  6158. C[7] ^= i3;
  6159.  
  6160. // Iterate the system four times
  6161. for (var i = 0; i < 4; i++) {
  6162. nextState.call(this);
  6163. }
  6164. }
  6165. },
  6166.  
  6167. _doProcessBlock: function (M, offset) {
  6168. // Shortcut
  6169. var X = this._X;
  6170.  
  6171. // Iterate the system
  6172. nextState.call(this);
  6173.  
  6174. // Generate four keystream words
  6175. S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
  6176. S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
  6177. S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
  6178. S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
  6179.  
  6180. for (var i = 0; i < 4; i++) {
  6181. // Swap endian
  6182. S[i] =
  6183. (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
  6184. (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
  6185.  
  6186. // Encrypt
  6187. M[offset + i] ^= S[i];
  6188. }
  6189. },
  6190.  
  6191. blockSize: 128 / 32,
  6192.  
  6193. ivSize: 64 / 32,
  6194. }));
  6195.  
  6196. function nextState() {
  6197. // Shortcuts
  6198. var X = this._X;
  6199. var C = this._C;
  6200.  
  6201. // Save old counter values
  6202. for (var i = 0; i < 8; i++) {
  6203. C_[i] = C[i];
  6204. }
  6205.  
  6206. // Calculate new counter values
  6207. C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
  6208. C[1] = (C[1] + 0xd34d34d3 + (C[0] >>> 0 < C_[0] >>> 0 ? 1 : 0)) | 0;
  6209. C[2] = (C[2] + 0x34d34d34 + (C[1] >>> 0 < C_[1] >>> 0 ? 1 : 0)) | 0;
  6210. C[3] = (C[3] + 0x4d34d34d + (C[2] >>> 0 < C_[2] >>> 0 ? 1 : 0)) | 0;
  6211. C[4] = (C[4] + 0xd34d34d3 + (C[3] >>> 0 < C_[3] >>> 0 ? 1 : 0)) | 0;
  6212. C[5] = (C[5] + 0x34d34d34 + (C[4] >>> 0 < C_[4] >>> 0 ? 1 : 0)) | 0;
  6213. C[6] = (C[6] + 0x4d34d34d + (C[5] >>> 0 < C_[5] >>> 0 ? 1 : 0)) | 0;
  6214. C[7] = (C[7] + 0xd34d34d3 + (C[6] >>> 0 < C_[6] >>> 0 ? 1 : 0)) | 0;
  6215. this._b = C[7] >>> 0 < C_[7] >>> 0 ? 1 : 0;
  6216.  
  6217. // Calculate the g-values
  6218. for (var i = 0; i < 8; i++) {
  6219. var gx = X[i] + C[i];
  6220.  
  6221. // Construct high and low argument for squaring
  6222. var ga = gx & 0xffff;
  6223. var gb = gx >>> 16;
  6224.  
  6225. // Calculate high and low result of squaring
  6226. var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
  6227. var gl =
  6228. (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
  6229.  
  6230. // High XOR low
  6231. G[i] = gh ^ gl;
  6232. }
  6233.  
  6234. // Calculate new state values
  6235. X[0] =
  6236. (G[0] +
  6237. ((G[7] << 16) | (G[7] >>> 16)) +
  6238. ((G[6] << 16) | (G[6] >>> 16))) |
  6239. 0;
  6240. X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
  6241. X[2] =
  6242. (G[2] +
  6243. ((G[1] << 16) | (G[1] >>> 16)) +
  6244. ((G[0] << 16) | (G[0] >>> 16))) |
  6245. 0;
  6246. X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
  6247. X[4] =
  6248. (G[4] +
  6249. ((G[3] << 16) | (G[3] >>> 16)) +
  6250. ((G[2] << 16) | (G[2] >>> 16))) |
  6251. 0;
  6252. X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
  6253. X[6] =
  6254. (G[6] +
  6255. ((G[5] << 16) | (G[5] >>> 16)) +
  6256. ((G[4] << 16) | (G[4] >>> 16))) |
  6257. 0;
  6258. X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
  6259. }
  6260.  
  6261. /**
  6262. * Shortcut functions to the cipher's object interface.
  6263. *
  6264. * @example
  6265. *
  6266. * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg);
  6267. * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg);
  6268. */
  6269. C.Rabbit = StreamCipher._createHelper(Rabbit);
  6270. })();
  6271.  
  6272. (function () {
  6273. // Shortcuts
  6274. var C = CryptoJS;
  6275. var C_lib = C.lib;
  6276. var StreamCipher = C_lib.StreamCipher;
  6277. var C_algo = C.algo;
  6278.  
  6279. // Reusable objects
  6280. var S = [];
  6281. var C_ = [];
  6282. var G = [];
  6283.  
  6284. /**
  6285. * Rabbit stream cipher algorithm.
  6286. *
  6287. * This is a legacy version that neglected to convert the key to little-endian.
  6288. * This error doesn't affect the cipher's security,
  6289. * but it does affect its compatibility with other implementations.
  6290. */
  6291. var RabbitLegacy = (C_algo.RabbitLegacy = StreamCipher.extend({
  6292. _doReset: function () {
  6293. // Shortcuts
  6294. var K = this._key.words;
  6295. var iv = this.cfg.iv;
  6296.  
  6297. // Generate initial state values
  6298. var X = (this._X = [
  6299. K[0],
  6300. (K[3] << 16) | (K[2] >>> 16),
  6301. K[1],
  6302. (K[0] << 16) | (K[3] >>> 16),
  6303. K[2],
  6304. (K[1] << 16) | (K[0] >>> 16),
  6305. K[3],
  6306. (K[2] << 16) | (K[1] >>> 16),
  6307. ]);
  6308.  
  6309. // Generate initial counter values
  6310. var C = (this._C = [
  6311. (K[2] << 16) | (K[2] >>> 16),
  6312. (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
  6313. (K[3] << 16) | (K[3] >>> 16),
  6314. (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
  6315. (K[0] << 16) | (K[0] >>> 16),
  6316. (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
  6317. (K[1] << 16) | (K[1] >>> 16),
  6318. (K[3] & 0xffff0000) | (K[0] & 0x0000ffff),
  6319. ]);
  6320.  
  6321. // Carry bit
  6322. this._b = 0;
  6323.  
  6324. // Iterate the system four times
  6325. for (var i = 0; i < 4; i++) {
  6326. nextState.call(this);
  6327. }
  6328.  
  6329. // Modify the counters
  6330. for (var i = 0; i < 8; i++) {
  6331. C[i] ^= X[(i + 4) & 7];
  6332. }
  6333.  
  6334. // IV setup
  6335. if (iv) {
  6336. // Shortcuts
  6337. var IV = iv.words;
  6338. var IV_0 = IV[0];
  6339. var IV_1 = IV[1];
  6340.  
  6341. // Generate four subvectors
  6342. var i0 =
  6343. (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) |
  6344. (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
  6345. var i2 =
  6346. (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) |
  6347. (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
  6348. var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
  6349. var i3 = (i2 << 16) | (i0 & 0x0000ffff);
  6350.  
  6351. // Modify counter values
  6352. C[0] ^= i0;
  6353. C[1] ^= i1;
  6354. C[2] ^= i2;
  6355. C[3] ^= i3;
  6356. C[4] ^= i0;
  6357. C[5] ^= i1;
  6358. C[6] ^= i2;
  6359. C[7] ^= i3;
  6360.  
  6361. // Iterate the system four times
  6362. for (var i = 0; i < 4; i++) {
  6363. nextState.call(this);
  6364. }
  6365. }
  6366. },
  6367.  
  6368. _doProcessBlock: function (M, offset) {
  6369. // Shortcut
  6370. var X = this._X;
  6371.  
  6372. // Iterate the system
  6373. nextState.call(this);
  6374.  
  6375. // Generate four keystream words
  6376. S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
  6377. S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
  6378. S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
  6379. S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
  6380.  
  6381. for (var i = 0; i < 4; i++) {
  6382. // Swap endian
  6383. S[i] =
  6384. (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
  6385. (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
  6386.  
  6387. // Encrypt
  6388. M[offset + i] ^= S[i];
  6389. }
  6390. },
  6391.  
  6392. blockSize: 128 / 32,
  6393.  
  6394. ivSize: 64 / 32,
  6395. }));
  6396.  
  6397. function nextState() {
  6398. // Shortcuts
  6399. var X = this._X;
  6400. var C = this._C;
  6401.  
  6402. // Save old counter values
  6403. for (var i = 0; i < 8; i++) {
  6404. C_[i] = C[i];
  6405. }
  6406.  
  6407. // Calculate new counter values
  6408. C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
  6409. C[1] = (C[1] + 0xd34d34d3 + (C[0] >>> 0 < C_[0] >>> 0 ? 1 : 0)) | 0;
  6410. C[2] = (C[2] + 0x34d34d34 + (C[1] >>> 0 < C_[1] >>> 0 ? 1 : 0)) | 0;
  6411. C[3] = (C[3] + 0x4d34d34d + (C[2] >>> 0 < C_[2] >>> 0 ? 1 : 0)) | 0;
  6412. C[4] = (C[4] + 0xd34d34d3 + (C[3] >>> 0 < C_[3] >>> 0 ? 1 : 0)) | 0;
  6413. C[5] = (C[5] + 0x34d34d34 + (C[4] >>> 0 < C_[4] >>> 0 ? 1 : 0)) | 0;
  6414. C[6] = (C[6] + 0x4d34d34d + (C[5] >>> 0 < C_[5] >>> 0 ? 1 : 0)) | 0;
  6415. C[7] = (C[7] + 0xd34d34d3 + (C[6] >>> 0 < C_[6] >>> 0 ? 1 : 0)) | 0;
  6416. this._b = C[7] >>> 0 < C_[7] >>> 0 ? 1 : 0;
  6417.  
  6418. // Calculate the g-values
  6419. for (var i = 0; i < 8; i++) {
  6420. var gx = X[i] + C[i];
  6421.  
  6422. // Construct high and low argument for squaring
  6423. var ga = gx & 0xffff;
  6424. var gb = gx >>> 16;
  6425.  
  6426. // Calculate high and low result of squaring
  6427. var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
  6428. var gl =
  6429. (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
  6430.  
  6431. // High XOR low
  6432. G[i] = gh ^ gl;
  6433. }
  6434.  
  6435. // Calculate new state values
  6436. X[0] =
  6437. (G[0] +
  6438. ((G[7] << 16) | (G[7] >>> 16)) +
  6439. ((G[6] << 16) | (G[6] >>> 16))) |
  6440. 0;
  6441. X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
  6442. X[2] =
  6443. (G[2] +
  6444. ((G[1] << 16) | (G[1] >>> 16)) +
  6445. ((G[0] << 16) | (G[0] >>> 16))) |
  6446. 0;
  6447. X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
  6448. X[4] =
  6449. (G[4] +
  6450. ((G[3] << 16) | (G[3] >>> 16)) +
  6451. ((G[2] << 16) | (G[2] >>> 16))) |
  6452. 0;
  6453. X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
  6454. X[6] =
  6455. (G[6] +
  6456. ((G[5] << 16) | (G[5] >>> 16)) +
  6457. ((G[4] << 16) | (G[4] >>> 16))) |
  6458. 0;
  6459. X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
  6460. }
  6461.  
  6462. /**
  6463. * Shortcut functions to the cipher's object interface.
  6464. *
  6465. * @example
  6466. *
  6467. * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg);
  6468. * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg);
  6469. */
  6470. C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy);
  6471. })();
  6472.  
  6473. (function () {
  6474. // Shortcuts
  6475. var C = CryptoJS;
  6476. var C_lib = C.lib;
  6477. var BlockCipher = C_lib.BlockCipher;
  6478. var C_algo = C.algo;
  6479.  
  6480. const N = 16;
  6481.  
  6482. //Origin pbox and sbox, derived from PI
  6483. const ORIG_P = [
  6484. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0,
  6485. 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
  6486. 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b,
  6487. ];
  6488.  
  6489. const ORIG_S = [
  6490. [
  6491. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96,
  6492. 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
  6493. 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658,
  6494. 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  6495. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e,
  6496. 0x6c9e0e8b, 0xb01e8a3e, 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
  6497. 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, 0x55ca396a, 0x2aab10b6,
  6498. 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  6499. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c,
  6500. 0x7a325381, 0x28958677, 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
  6501. 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, 0xef845d5d, 0xe98575b1,
  6502. 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  6503. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a,
  6504. 0x670c9c61, 0xabd388f0, 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
  6505. 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, 0xa1f1651d, 0x39af0176,
  6506. 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  6507. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706,
  6508. 0x1bfedf72, 0x429b023d, 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
  6509. 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, 0xe3fe501a, 0xb6794c3b,
  6510. 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  6511. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c,
  6512. 0xcc814544, 0xaf5ebd09, 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
  6513. 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, 0x5579c0bd, 0x1a60320a,
  6514. 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  6515. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760,
  6516. 0x53317b48, 0x3e00df82, 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
  6517. 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, 0x695b27b0, 0xbbca58c8,
  6518. 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  6519. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33,
  6520. 0x62fb1341, 0xcee4c6e8, 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
  6521. 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, 0xd08ed1d0, 0xafc725e0,
  6522. 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  6523. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777,
  6524. 0xea752dfe, 0x8b021fa1, 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
  6525. 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, 0x165fa266, 0x80957705,
  6526. 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  6527. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e,
  6528. 0x226800bb, 0x57b8e0af, 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
  6529. 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, 0x83260376, 0x6295cfa9,
  6530. 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  6531. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f,
  6532. 0xf296ec6b, 0x2a0dd915, 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
  6533. 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  6534. ],
  6535. [
  6536. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d,
  6537. 0x9cee60b8, 0x8fedb266, 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
  6538. 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, 0x3f54989a, 0x5b429d65,
  6539. 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  6540. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9,
  6541. 0x3c971814, 0x6b6a70a1, 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
  6542. 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, 0xb03ada37, 0xf0500c0d,
  6543. 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  6544. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc,
  6545. 0xc8b57634, 0x9af3dda7, 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
  6546. 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, 0x4e548b38, 0x4f6db908,
  6547. 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  6548. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124,
  6549. 0x501adde6, 0x9f84cd87, 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
  6550. 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, 0xef1c1847, 0x3215d908,
  6551. 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  6552. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b,
  6553. 0x3c11183b, 0x5924a509, 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
  6554. 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, 0x771fe71c, 0x4e3d06fa,
  6555. 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  6556. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d,
  6557. 0x1939260f, 0x19c27960, 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
  6558. 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, 0xc332ddef, 0xbe6c5aa5,
  6559. 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  6560. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96,
  6561. 0x0334fe1e, 0xaa0363cf, 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
  6562. 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, 0x648b1eaf, 0x19bdf0ca,
  6563. 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  6564. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77,
  6565. 0x11ed935f, 0x16681281, 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
  6566. 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, 0xcdb30aeb, 0x532e3054,
  6567. 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  6568. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea,
  6569. 0xdb6c4f15, 0xfacb4fd0, 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
  6570. 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, 0xcf62a1f2, 0x5b8d2646,
  6571. 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  6572. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea,
  6573. 0x1dadf43e, 0x233f7061, 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
  6574. 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, 0xa6078084, 0x19f8509e,
  6575. 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  6576. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd,
  6577. 0x675fda79, 0xe3674340, 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
  6578. 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  6579. ],
  6580. [
  6581. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7,
  6582. 0xbcf46b2e, 0xd4a20068, 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
  6583. 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, 0x4d95fc1d, 0x96b591af,
  6584. 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  6585. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4,
  6586. 0x0a2c86da, 0xe9b66dfb, 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
  6587. 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, 0xaace1e7c, 0xd3375fec,
  6588. 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  6589. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332,
  6590. 0x6841e7f7, 0xca7820fb, 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
  6591. 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, 0x55a867bc, 0xa1159a58,
  6592. 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  6593. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22,
  6594. 0x48c1133f, 0xc70f86dc, 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
  6595. 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, 0x257b7834, 0x602a9c60,
  6596. 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  6597. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99,
  6598. 0xde720c8c, 0x2da2f728, 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
  6599. 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, 0x0a476341, 0x992eff74,
  6600. 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  6601. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3,
  6602. 0xb5390f92, 0x690fed0b, 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
  6603. 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, 0x37392eb3, 0xcc115979,
  6604. 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  6605. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa,
  6606. 0x3d25bdd8, 0xe2e1c3c9, 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
  6607. 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, 0x9dbc8057, 0xf0f7c086,
  6608. 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  6609. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24,
  6610. 0x55464299, 0xbf582e61, 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
  6611. 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, 0x7aeb2661, 0x8b1ddf84,
  6612. 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  6613. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09,
  6614. 0x662d09a1, 0xc4324633, 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
  6615. 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, 0xdcb7da83, 0x573906fe,
  6616. 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  6617. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0,
  6618. 0x006058aa, 0x30dc7d62, 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
  6619. 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, 0x6f05e409, 0x4b7c0188,
  6620. 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  6621. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8,
  6622. 0xa28514d9, 0x6c51133c, 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
  6623. 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  6624. ],
  6625. [
  6626. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742,
  6627. 0xd3822740, 0x99bc9bbe, 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
  6628. 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, 0x5748ab2f, 0xbc946e79,
  6629. 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  6630. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a,
  6631. 0x63ef8ce2, 0x9a86ee22, 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
  6632. 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, 0x2826a2f9, 0xa73a3ae1,
  6633. 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  6634. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797,
  6635. 0x2cf0b7d9, 0x022b8b51, 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
  6636. 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, 0xe029ac71, 0xe019a5e6,
  6637. 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  6638. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba,
  6639. 0x03a16125, 0x0564f0bd, 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
  6640. 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, 0x7533d928, 0xb155fdf5,
  6641. 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  6642. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce,
  6643. 0x5121ce64, 0x774fbe32, 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
  6644. 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, 0xb39a460a, 0x6445c0dd,
  6645. 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  6646. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb,
  6647. 0x8d6612ae, 0xbf3c6f47, 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
  6648. 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, 0x4040cb08, 0x4eb4e2cc,
  6649. 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  6650. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc,
  6651. 0xbb3a792b, 0x344525bd, 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
  6652. 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, 0x1a908749, 0xd44fbd9a,
  6653. 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  6654. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a,
  6655. 0x0f91fc71, 0x9b941525, 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
  6656. 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, 0xe0ec6e0e, 0x1698db3b,
  6657. 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  6658. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e,
  6659. 0xe60b6f47, 0x0fe3f11d, 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
  6660. 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, 0xf523f357, 0xa6327623,
  6661. 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  6662. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a,
  6663. 0x45e1d006, 0xc3f27b9a, 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
  6664. 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, 0x53113ec0, 0x1640e3d3,
  6665. 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  6666. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c,
  6667. 0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
  6668. 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6,
  6669. ],
  6670. ];
  6671.  
  6672. var BLOWFISH_CTX = {
  6673. pbox: [],
  6674. sbox: [],
  6675. };
  6676.  
  6677. function F(ctx, x) {
  6678. let a = (x >> 24) & 0xff;
  6679. let b = (x >> 16) & 0xff;
  6680. let c = (x >> 8) & 0xff;
  6681. let d = x & 0xff;
  6682.  
  6683. let y = ctx.sbox[0][a] + ctx.sbox[1][b];
  6684. y = y ^ ctx.sbox[2][c];
  6685. y = y + ctx.sbox[3][d];
  6686.  
  6687. return y;
  6688. }
  6689.  
  6690. function BlowFish_Encrypt(ctx, left, right) {
  6691. let Xl = left;
  6692. let Xr = right;
  6693. let temp;
  6694.  
  6695. for (let i = 0; i < N; ++i) {
  6696. Xl = Xl ^ ctx.pbox[i];
  6697. Xr = F(ctx, Xl) ^ Xr;
  6698.  
  6699. temp = Xl;
  6700. Xl = Xr;
  6701. Xr = temp;
  6702. }
  6703.  
  6704. temp = Xl;
  6705. Xl = Xr;
  6706. Xr = temp;
  6707.  
  6708. Xr = Xr ^ ctx.pbox[N];
  6709. Xl = Xl ^ ctx.pbox[N + 1];
  6710.  
  6711. return { left: Xl, right: Xr };
  6712. }
  6713.  
  6714. function BlowFish_Decrypt(ctx, left, right) {
  6715. let Xl = left;
  6716. let Xr = right;
  6717. let temp;
  6718.  
  6719. for (let i = N + 1; i > 1; --i) {
  6720. Xl = Xl ^ ctx.pbox[i];
  6721. Xr = F(ctx, Xl) ^ Xr;
  6722.  
  6723. temp = Xl;
  6724. Xl = Xr;
  6725. Xr = temp;
  6726. }
  6727.  
  6728. temp = Xl;
  6729. Xl = Xr;
  6730. Xr = temp;
  6731.  
  6732. Xr = Xr ^ ctx.pbox[1];
  6733. Xl = Xl ^ ctx.pbox[0];
  6734.  
  6735. return { left: Xl, right: Xr };
  6736. }
  6737.  
  6738. /**
  6739. * Initialization ctx's pbox and sbox.
  6740. *
  6741. * @param {Object} ctx The object has pbox and sbox.
  6742. * @param {Array} key An array of 32-bit words.
  6743. * @param {int} keysize The length of the key.
  6744. *
  6745. * @example
  6746. *
  6747. * BlowFishInit(BLOWFISH_CTX, key, 128/32);
  6748. */
  6749. function BlowFishInit(ctx, key, keysize) {
  6750. for (let Row = 0; Row < 4; Row++) {
  6751. ctx.sbox[Row] = [];
  6752. for (let Col = 0; Col < 256; Col++) {
  6753. ctx.sbox[Row][Col] = ORIG_S[Row][Col];
  6754. }
  6755. }
  6756.  
  6757. let keyIndex = 0;
  6758. for (let index = 0; index < N + 2; index++) {
  6759. ctx.pbox[index] = ORIG_P[index] ^ key[keyIndex];
  6760. keyIndex++;
  6761. if (keyIndex >= keysize) {
  6762. keyIndex = 0;
  6763. }
  6764. }
  6765.  
  6766. let Data1 = 0;
  6767. let Data2 = 0;
  6768. let res = 0;
  6769. for (let i = 0; i < N + 2; i += 2) {
  6770. res = BlowFish_Encrypt(ctx, Data1, Data2);
  6771. Data1 = res.left;
  6772. Data2 = res.right;
  6773. ctx.pbox[i] = Data1;
  6774. ctx.pbox[i + 1] = Data2;
  6775. }
  6776.  
  6777. for (let i = 0; i < 4; i++) {
  6778. for (let j = 0; j < 256; j += 2) {
  6779. res = BlowFish_Encrypt(ctx, Data1, Data2);
  6780. Data1 = res.left;
  6781. Data2 = res.right;
  6782. ctx.sbox[i][j] = Data1;
  6783. ctx.sbox[i][j + 1] = Data2;
  6784. }
  6785. }
  6786.  
  6787. return true;
  6788. }
  6789.  
  6790. /**
  6791. * Blowfish block cipher algorithm.
  6792. */
  6793. var Blowfish = (C_algo.Blowfish = BlockCipher.extend({
  6794. _doReset: function () {
  6795. // Skip reset of nRounds has been set before and key did not change
  6796. if (this._keyPriorReset === this._key) {
  6797. return;
  6798. }
  6799.  
  6800. // Shortcuts
  6801. var key = (this._keyPriorReset = this._key);
  6802. var keyWords = key.words;
  6803. var keySize = key.sigBytes / 4;
  6804.  
  6805. //Initialization pbox and sbox
  6806. BlowFishInit(BLOWFISH_CTX, keyWords, keySize);
  6807. },
  6808.  
  6809. encryptBlock: function (M, offset) {
  6810. var res = BlowFish_Encrypt(BLOWFISH_CTX, M[offset], M[offset + 1]);
  6811. M[offset] = res.left;
  6812. M[offset + 1] = res.right;
  6813. },
  6814.  
  6815. decryptBlock: function (M, offset) {
  6816. var res = BlowFish_Decrypt(BLOWFISH_CTX, M[offset], M[offset + 1]);
  6817. M[offset] = res.left;
  6818. M[offset + 1] = res.right;
  6819. },
  6820.  
  6821. blockSize: 64 / 32,
  6822.  
  6823. keySize: 128 / 32,
  6824.  
  6825. ivSize: 64 / 32,
  6826. }));
  6827.  
  6828. /**
  6829. * Shortcut functions to the cipher's object interface.
  6830. *
  6831. * @example
  6832. *
  6833. * var ciphertext = CryptoJS.Blowfish.encrypt(message, key, cfg);
  6834. * var plaintext = CryptoJS.Blowfish.decrypt(ciphertext, key, cfg);
  6835. */
  6836. C.Blowfish = BlockCipher._createHelper(Blowfish);
  6837. })();
  6838.  
  6839. return CryptoJS;
  6840. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址