Authored by 李奇

加解密模块引入

Too many changes to show.

To preserve performance only 32 of 32+ files are displayed.

1 // 线上环境 1 // 线上环境
2 -export const API_HOST = 'https://api.yoho.cn';  
3 -export const SERVICE_HOST = 'https://api.yoho.cn';  
4 -export const ACTIVITY_HOST = 'https://action.yoho.cn';  
5 -export const APP_REPORT_HOST = 'https://app.yoho.cn/collect/v3';  
6 -export const LOG_EVENT_HOST = 'https://analysis.yohobuy.com/yas_mobile'; 2 +// export const API_HOST = 'https://api.yoho.cn';
  3 +// export const SERVICE_HOST = 'https://api.yoho.cn';
  4 +// export const ACTIVITY_HOST = 'https://action.yoho.cn';
  5 +// export const APP_REPORT_HOST = 'https://app.yoho.cn/collect/v3';
  6 +// export const LOG_EVENT_HOST = 'https://analysis.yohobuy.com/yas_mobile';
7 7
8 // 测试环境 8 // 测试环境
9 -// export const API_HOST = 'http://api-test3.dev.yohocorp.com';  
10 -// export const SERVICE_HOST = 'http://api-test3.dev.yohocorp.com';  
11 -// export const ACTIVITY_HOST = 'http://yoho-activity-platform.test3.ingress.dev.yohocorp.com';  
12 -// export const ACTIVITY_HOST = 'http://limit-yoho-activity-platform.test3.ingress.dev.yohocorp.com';  
13 -// export const APP_REPORT_HOST = 'http://app.yoho.cn/collect/v3';  
14 -// export const LOG_EVENT_HOST = 'https://analysis.yohobuy.com/yas_mobile'; 9 +export const API_HOST = 'http://api-test3.dev.yohocorp.com';
  10 +export const SERVICE_HOST = 'http://api-test3.dev.yohocorp.com';
  11 +export const ACTIVITY_HOST = 'http://yoho-activity-platform.test3.ingress.dev.yohocorp.com';
  12 +export const APP_REPORT_HOST = 'http://app.yoho.cn/collect/v3';
  13 +export const LOG_EVENT_HOST = 'https://analysis.yohobuy.com/yas_mobile';
15 14
16 export const MINI_APP_TYPE = 29; 15 export const MINI_APP_TYPE = 29;
17 export const MINI_QR_TYPE = 16; 16 export const MINI_QR_TYPE = 16;
  1 +const clearEncoding = 'utf8';
  2 +const cipherEncoding = 'base64';
  3 +const ENCRYPT_MODE = 'aes-128-cbc'
  4 +const AES_IV = 'YOHO9646yoho9646';
  5 +const AES_KEY = 'yoho9646YOHO9646';
  6 +//
  7 +// const ivBytes = stringToBytes(AES_IV);
  8 +// const keyBytes = stringToBytes(AES_SECRET_KET);
  9 +//
  10 +// const iv = new Buffer(keyBytes);
  11 +// const key = new Buffer(keyBytes);
  12 +
  13 +const CryptoJS = require('../vendors/crypto-js/cipher-core');
  14 +
  15 +const key = CryptoJS.enc.Utf8.parse(AES_KEY); //十六位十六进制数作为密钥
  16 +const iv = CryptoJS.enc.Utf8.parse(AES_IV); //十六位十六进制数作为密钥偏移量
  17 +
  18 +//解密方法
  19 +function encrypt(word) {
  20 + let encryptedHexStr = CryptoJS.enc.Hex.parse(word);
  21 + let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
  22 + let decrypt = CryptoJS.AES.decrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
  23 + let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
  24 + return decryptedStr.toString();
  25 +}
  26 +
  27 +//加密方法
  28 +function decrypt(word) {
  29 + let srcs = CryptoJS.enc.Utf8.parse(word);
  30 + let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
  31 + return encrypted.ciphertext.toString().toUpperCase();
  32 +}
  33 +
  34 +export {
  35 + encrypt,
  36 + decrypt
  37 +};
  1 +(function () {
  2 + // Shortcuts
  3 + var C = CryptoJS;
  4 + var C_lib = C.lib;
  5 + var BlockCipher = C_lib.BlockCipher;
  6 + var C_algo = C.algo;
  7 +
  8 + // Lookup tables
  9 + var SBOX = [];
  10 + var INV_SBOX = [];
  11 + var SUB_MIX_0 = [];
  12 + var SUB_MIX_1 = [];
  13 + var SUB_MIX_2 = [];
  14 + var SUB_MIX_3 = [];
  15 + var INV_SUB_MIX_0 = [];
  16 + var INV_SUB_MIX_1 = [];
  17 + var INV_SUB_MIX_2 = [];
  18 + var INV_SUB_MIX_3 = [];
  19 +
  20 + // Compute lookup tables
  21 + (function () {
  22 + // Compute double table
  23 + var d = [];
  24 + for (var i = 0; i < 256; i++) {
  25 + if (i < 128) {
  26 + d[i] = i << 1;
  27 + } else {
  28 + d[i] = (i << 1) ^ 0x11b;
  29 + }
  30 + }
  31 +
  32 + // Walk GF(2^8)
  33 + var x = 0;
  34 + var xi = 0;
  35 + for (var i = 0; i < 256; i++) {
  36 + // Compute sbox
  37 + var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
  38 + sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
  39 + SBOX[x] = sx;
  40 + INV_SBOX[sx] = x;
  41 +
  42 + // Compute multiplication
  43 + var x2 = d[x];
  44 + var x4 = d[x2];
  45 + var x8 = d[x4];
  46 +
  47 + // Compute sub bytes, mix columns tables
  48 + var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
  49 + SUB_MIX_0[x] = (t << 24) | (t >>> 8);
  50 + SUB_MIX_1[x] = (t << 16) | (t >>> 16);
  51 + SUB_MIX_2[x] = (t << 8) | (t >>> 24);
  52 + SUB_MIX_3[x] = t;
  53 +
  54 + // Compute inv sub bytes, inv mix columns tables
  55 + var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
  56 + INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
  57 + INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
  58 + INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
  59 + INV_SUB_MIX_3[sx] = t;
  60 +
  61 + // Compute next counter
  62 + if (!x) {
  63 + x = xi = 1;
  64 + } else {
  65 + x = x2 ^ d[d[d[x8 ^ x2]]];
  66 + xi ^= d[d[xi]];
  67 + }
  68 + }
  69 + }());
  70 +
  71 + // Precomputed Rcon lookup
  72 + var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
  73 +
  74 + /**
  75 + * AES block cipher algorithm.
  76 + */
  77 + var AES = C_algo.AES = BlockCipher.extend({
  78 + _doReset: function () {
  79 + var t;
  80 +
  81 + // Skip reset of nRounds has been set before and key did not change
  82 + if (this._nRounds && this._keyPriorReset === this._key) {
  83 + return;
  84 + }
  85 +
  86 + // Shortcuts
  87 + var key = this._keyPriorReset = this._key;
  88 + var keyWords = key.words;
  89 + var keySize = key.sigBytes / 4;
  90 +
  91 + // Compute number of rounds
  92 + var nRounds = this._nRounds = keySize + 6;
  93 +
  94 + // Compute number of key schedule rows
  95 + var ksRows = (nRounds + 1) * 4;
  96 +
  97 + // Compute key schedule
  98 + var keySchedule = this._keySchedule = [];
  99 + for (var ksRow = 0; ksRow < ksRows; ksRow++) {
  100 + if (ksRow < keySize) {
  101 + keySchedule[ksRow] = keyWords[ksRow];
  102 + } else {
  103 + t = keySchedule[ksRow - 1];
  104 +
  105 + if (!(ksRow % keySize)) {
  106 + // Rot word
  107 + t = (t << 8) | (t >>> 24);
  108 +
  109 + // Sub word
  110 + t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  111 +
  112 + // Mix Rcon
  113 + t ^= RCON[(ksRow / keySize) | 0] << 24;
  114 + } else if (keySize > 6 && ksRow % keySize == 4) {
  115 + // Sub word
  116 + t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  117 + }
  118 +
  119 + keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
  120 + }
  121 + }
  122 +
  123 + // Compute inv key schedule
  124 + var invKeySchedule = this._invKeySchedule = [];
  125 + for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
  126 + var ksRow = ksRows - invKsRow;
  127 +
  128 + if (invKsRow % 4) {
  129 + var t = keySchedule[ksRow];
  130 + } else {
  131 + var t = keySchedule[ksRow - 4];
  132 + }
  133 +
  134 + if (invKsRow < 4 || ksRow <= 4) {
  135 + invKeySchedule[invKsRow] = t;
  136 + } else {
  137 + invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
  138 + INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
  139 + }
  140 + }
  141 + },
  142 +
  143 + encryptBlock: function (M, offset) {
  144 + this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
  145 + },
  146 +
  147 + decryptBlock: function (M, offset) {
  148 + // Swap 2nd and 4th rows
  149 + var t = M[offset + 1];
  150 + M[offset + 1] = M[offset + 3];
  151 + M[offset + 3] = t;
  152 +
  153 + this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
  154 +
  155 + // Inv swap 2nd and 4th rows
  156 + var t = M[offset + 1];
  157 + M[offset + 1] = M[offset + 3];
  158 + M[offset + 3] = t;
  159 + },
  160 +
  161 + _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
  162 + // Shortcut
  163 + var nRounds = this._nRounds;
  164 +
  165 + // Get input, add round key
  166 + var s0 = M[offset] ^ keySchedule[0];
  167 + var s1 = M[offset + 1] ^ keySchedule[1];
  168 + var s2 = M[offset + 2] ^ keySchedule[2];
  169 + var s3 = M[offset + 3] ^ keySchedule[3];
  170 +
  171 + // Key schedule row counter
  172 + var ksRow = 4;
  173 +
  174 + // Rounds
  175 + for (var round = 1; round < nRounds; round++) {
  176 + // Shift rows, sub bytes, mix columns, add round key
  177 + var t0 = SUB_MIX_0[s0 >>> 24] ^ SUB_MIX_1[(s1 >>> 16) & 0xff] ^ SUB_MIX_2[(s2 >>> 8) & 0xff] ^ SUB_MIX_3[s3 & 0xff] ^ keySchedule[ksRow++];
  178 + var t1 = SUB_MIX_0[s1 >>> 24] ^ SUB_MIX_1[(s2 >>> 16) & 0xff] ^ SUB_MIX_2[(s3 >>> 8) & 0xff] ^ SUB_MIX_3[s0 & 0xff] ^ keySchedule[ksRow++];
  179 + var t2 = SUB_MIX_0[s2 >>> 24] ^ SUB_MIX_1[(s3 >>> 16) & 0xff] ^ SUB_MIX_2[(s0 >>> 8) & 0xff] ^ SUB_MIX_3[s1 & 0xff] ^ keySchedule[ksRow++];
  180 + var t3 = SUB_MIX_0[s3 >>> 24] ^ SUB_MIX_1[(s0 >>> 16) & 0xff] ^ SUB_MIX_2[(s1 >>> 8) & 0xff] ^ SUB_MIX_3[s2 & 0xff] ^ keySchedule[ksRow++];
  181 +
  182 + // Update state
  183 + s0 = t0;
  184 + s1 = t1;
  185 + s2 = t2;
  186 + s3 = t3;
  187 + }
  188 +
  189 + // Shift rows, sub bytes, add round key
  190 + var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
  191 + var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
  192 + var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
  193 + var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
  194 +
  195 + // Set output
  196 + M[offset] = t0;
  197 + M[offset + 1] = t1;
  198 + M[offset + 2] = t2;
  199 + M[offset + 3] = t3;
  200 + },
  201 +
  202 + keySize: 256/32
  203 + });
  204 +
  205 + /**
  206 + * Shortcut functions to the cipher's object interface.
  207 + *
  208 + * @example
  209 + *
  210 + * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
  211 + * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
  212 + */
  213 + C.AES = BlockCipher._createHelper(AES);
  214 +}());
  1 +/**
  2 + * Cipher core components.
  3 + */
  4 +CryptoJS.lib.Cipher || (function (undefined) {
  5 + // Shortcuts
  6 + var C = CryptoJS;
  7 + var C_lib = C.lib;
  8 + var Base = C_lib.Base;
  9 + var WordArray = C_lib.WordArray;
  10 + var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
  11 + var C_enc = C.enc;
  12 + var Utf8 = C_enc.Utf8;
  13 + var Base64 = C_enc.Base64;
  14 + var C_algo = C.algo;
  15 + var EvpKDF = C_algo.EvpKDF;
  16 +
  17 + /**
  18 + * Abstract base cipher template.
  19 + *
  20 + * @property {number} keySize This cipher's key size. Default: 4 (128 bits)
  21 + * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits)
  22 + * @property {number} _ENC_XFORM_MODE A constant representing encryption mode.
  23 + * @property {number} _DEC_XFORM_MODE A constant representing decryption mode.
  24 + */
  25 + var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({
  26 + /**
  27 + * Configuration options.
  28 + *
  29 + * @property {WordArray} iv The IV to use for this operation.
  30 + */
  31 + cfg: Base.extend(),
  32 +
  33 + /**
  34 + * Creates this cipher in encryption mode.
  35 + *
  36 + * @param {WordArray} key The key.
  37 + * @param {Object} cfg (Optional) The configuration options to use for this operation.
  38 + *
  39 + * @return {Cipher} A cipher instance.
  40 + *
  41 + * @static
  42 + *
  43 + * @example
  44 + *
  45 + * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
  46 + */
  47 + createEncryptor: function (key, cfg) {
  48 + return this.create(this._ENC_XFORM_MODE, key, cfg);
  49 + },
  50 +
  51 + /**
  52 + * Creates this cipher in decryption mode.
  53 + *
  54 + * @param {WordArray} key The key.
  55 + * @param {Object} cfg (Optional) The configuration options to use for this operation.
  56 + *
  57 + * @return {Cipher} A cipher instance.
  58 + *
  59 + * @static
  60 + *
  61 + * @example
  62 + *
  63 + * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
  64 + */
  65 + createDecryptor: function (key, cfg) {
  66 + return this.create(this._DEC_XFORM_MODE, key, cfg);
  67 + },
  68 +
  69 + /**
  70 + * Initializes a newly created cipher.
  71 + *
  72 + * @param {number} xformMode Either the encryption or decryption transormation mode constant.
  73 + * @param {WordArray} key The key.
  74 + * @param {Object} cfg (Optional) The configuration options to use for this operation.
  75 + *
  76 + * @example
  77 + *
  78 + * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
  79 + */
  80 + init: function (xformMode, key, cfg) {
  81 + // Apply config defaults
  82 + this.cfg = this.cfg.extend(cfg);
  83 +
  84 + // Store transform mode and key
  85 + this._xformMode = xformMode;
  86 + this._key = key;
  87 +
  88 + // Set initial values
  89 + this.reset();
  90 + },
  91 +
  92 + /**
  93 + * Resets this cipher to its initial state.
  94 + *
  95 + * @example
  96 + *
  97 + * cipher.reset();
  98 + */
  99 + reset: function () {
  100 + // Reset data buffer
  101 + BufferedBlockAlgorithm.reset.call(this);
  102 +
  103 + // Perform concrete-cipher logic
  104 + this._doReset();
  105 + },
  106 +
  107 + /**
  108 + * Adds data to be encrypted or decrypted.
  109 + *
  110 + * @param {WordArray|string} dataUpdate The data to encrypt or decrypt.
  111 + *
  112 + * @return {WordArray} The data after processing.
  113 + *
  114 + * @example
  115 + *
  116 + * var encrypted = cipher.process('data');
  117 + * var encrypted = cipher.process(wordArray);
  118 + */
  119 + process: function (dataUpdate) {
  120 + // Append
  121 + this._append(dataUpdate);
  122 +
  123 + // Process available blocks
  124 + return this._process();
  125 + },
  126 +
  127 + /**
  128 + * Finalizes the encryption or decryption process.
  129 + * Note that the finalize operation is effectively a destructive, read-once operation.
  130 + *
  131 + * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt.
  132 + *
  133 + * @return {WordArray} The data after final processing.
  134 + *
  135 + * @example
  136 + *
  137 + * var encrypted = cipher.finalize();
  138 + * var encrypted = cipher.finalize('data');
  139 + * var encrypted = cipher.finalize(wordArray);
  140 + */
  141 + finalize: function (dataUpdate) {
  142 + // Final data update
  143 + if (dataUpdate) {
  144 + this._append(dataUpdate);
  145 + }
  146 +
  147 + // Perform concrete-cipher logic
  148 + var finalProcessedData = this._doFinalize();
  149 +
  150 + return finalProcessedData;
  151 + },
  152 +
  153 + keySize: 128/32,
  154 +
  155 + ivSize: 128/32,
  156 +
  157 + _ENC_XFORM_MODE: 1,
  158 +
  159 + _DEC_XFORM_MODE: 2,
  160 +
  161 + /**
  162 + * Creates shortcut functions to a cipher's object interface.
  163 + *
  164 + * @param {Cipher} cipher The cipher to create a helper for.
  165 + *
  166 + * @return {Object} An object with encrypt and decrypt shortcut functions.
  167 + *
  168 + * @static
  169 + *
  170 + * @example
  171 + *
  172 + * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
  173 + */
  174 + _createHelper: (function () {
  175 + function selectCipherStrategy(key) {
  176 + if (typeof key == 'string') {
  177 + return PasswordBasedCipher;
  178 + } else {
  179 + return SerializableCipher;
  180 + }
  181 + }
  182 +
  183 + return function (cipher) {
  184 + return {
  185 + encrypt: function (message, key, cfg) {
  186 + return selectCipherStrategy(key).encrypt(cipher, message, key, cfg);
  187 + },
  188 +
  189 + decrypt: function (ciphertext, key, cfg) {
  190 + return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg);
  191 + }
  192 + };
  193 + };
  194 + }())
  195 + });
  196 +
  197 + /**
  198 + * Abstract base stream cipher template.
  199 + *
  200 + * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
  201 + */
  202 + var StreamCipher = C_lib.StreamCipher = Cipher.extend({
  203 + _doFinalize: function () {
  204 + // Process partial blocks
  205 + var finalProcessedBlocks = this._process(!!'flush');
  206 +
  207 + return finalProcessedBlocks;
  208 + },
  209 +
  210 + blockSize: 1
  211 + });
  212 +
  213 + /**
  214 + * Mode namespace.
  215 + */
  216 + var C_mode = C.mode = {};
  217 +
  218 + /**
  219 + * Abstract base block cipher mode template.
  220 + */
  221 + var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({
  222 + /**
  223 + * Creates this mode for encryption.
  224 + *
  225 + * @param {Cipher} cipher A block cipher instance.
  226 + * @param {Array} iv The IV words.
  227 + *
  228 + * @static
  229 + *
  230 + * @example
  231 + *
  232 + * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
  233 + */
  234 + createEncryptor: function (cipher, iv) {
  235 + return this.Encryptor.create(cipher, iv);
  236 + },
  237 +
  238 + /**
  239 + * Creates this mode for decryption.
  240 + *
  241 + * @param {Cipher} cipher A block cipher instance.
  242 + * @param {Array} iv The IV words.
  243 + *
  244 + * @static
  245 + *
  246 + * @example
  247 + *
  248 + * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
  249 + */
  250 + createDecryptor: function (cipher, iv) {
  251 + return this.Decryptor.create(cipher, iv);
  252 + },
  253 +
  254 + /**
  255 + * Initializes a newly created mode.
  256 + *
  257 + * @param {Cipher} cipher A block cipher instance.
  258 + * @param {Array} iv The IV words.
  259 + *
  260 + * @example
  261 + *
  262 + * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
  263 + */
  264 + init: function (cipher, iv) {
  265 + this._cipher = cipher;
  266 + this._iv = iv;
  267 + }
  268 + });
  269 +
  270 + /**
  271 + * Cipher Block Chaining mode.
  272 + */
  273 + var CBC = C_mode.CBC = (function () {
  274 + /**
  275 + * Abstract base CBC mode.
  276 + */
  277 + var CBC = BlockCipherMode.extend();
  278 +
  279 + /**
  280 + * CBC encryptor.
  281 + */
  282 + CBC.Encryptor = CBC.extend({
  283 + /**
  284 + * Processes the data block at offset.
  285 + *
  286 + * @param {Array} words The data words to operate on.
  287 + * @param {number} offset The offset where the block starts.
  288 + *
  289 + * @example
  290 + *
  291 + * mode.processBlock(data.words, offset);
  292 + */
  293 + processBlock: function (words, offset) {
  294 + // Shortcuts
  295 + var cipher = this._cipher;
  296 + var blockSize = cipher.blockSize;
  297 +
  298 + // XOR and encrypt
  299 + xorBlock.call(this, words, offset, blockSize);
  300 + cipher.encryptBlock(words, offset);
  301 +
  302 + // Remember this block to use with next block
  303 + this._prevBlock = words.slice(offset, offset + blockSize);
  304 + }
  305 + });
  306 +
  307 + /**
  308 + * CBC decryptor.
  309 + */
  310 + CBC.Decryptor = CBC.extend({
  311 + /**
  312 + * Processes the data block at offset.
  313 + *
  314 + * @param {Array} words The data words to operate on.
  315 + * @param {number} offset The offset where the block starts.
  316 + *
  317 + * @example
  318 + *
  319 + * mode.processBlock(data.words, offset);
  320 + */
  321 + processBlock: function (words, offset) {
  322 + // Shortcuts
  323 + var cipher = this._cipher;
  324 + var blockSize = cipher.blockSize;
  325 +
  326 + // Remember this block to use with next block
  327 + var thisBlock = words.slice(offset, offset + blockSize);
  328 +
  329 + // Decrypt and XOR
  330 + cipher.decryptBlock(words, offset);
  331 + xorBlock.call(this, words, offset, blockSize);
  332 +
  333 + // This block becomes the previous block
  334 + this._prevBlock = thisBlock;
  335 + }
  336 + });
  337 +
  338 + function xorBlock(words, offset, blockSize) {
  339 + var block;
  340 +
  341 + // Shortcut
  342 + var iv = this._iv;
  343 +
  344 + // Choose mixing block
  345 + if (iv) {
  346 + block = iv;
  347 +
  348 + // Remove IV for subsequent blocks
  349 + this._iv = undefined;
  350 + } else {
  351 + block = this._prevBlock;
  352 + }
  353 +
  354 + // XOR blocks
  355 + for (var i = 0; i < blockSize; i++) {
  356 + words[offset + i] ^= block[i];
  357 + }
  358 + }
  359 +
  360 + return CBC;
  361 + }());
  362 +
  363 + /**
  364 + * Padding namespace.
  365 + */
  366 + var C_pad = C.pad = {};
  367 +
  368 + /**
  369 + * PKCS #5/7 padding strategy.
  370 + */
  371 + var Pkcs7 = C_pad.Pkcs7 = {
  372 + /**
  373 + * Pads data using the algorithm defined in PKCS #5/7.
  374 + *
  375 + * @param {WordArray} data The data to pad.
  376 + * @param {number} blockSize The multiple that the data should be padded to.
  377 + *
  378 + * @static
  379 + *
  380 + * @example
  381 + *
  382 + * CryptoJS.pad.Pkcs7.pad(wordArray, 4);
  383 + */
  384 + pad: function (data, blockSize) {
  385 + // Shortcut
  386 + var blockSizeBytes = blockSize * 4;
  387 +
  388 + // Count padding bytes
  389 + var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
  390 +
  391 + // Create padding word
  392 + var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes;
  393 +
  394 + // Create padding
  395 + var paddingWords = [];
  396 + for (var i = 0; i < nPaddingBytes; i += 4) {
  397 + paddingWords.push(paddingWord);
  398 + }
  399 + var padding = WordArray.create(paddingWords, nPaddingBytes);
  400 +
  401 + // Add padding
  402 + data.concat(padding);
  403 + },
  404 +
  405 + /**
  406 + * Unpads data that had been padded using the algorithm defined in PKCS #5/7.
  407 + *
  408 + * @param {WordArray} data The data to unpad.
  409 + *
  410 + * @static
  411 + *
  412 + * @example
  413 + *
  414 + * CryptoJS.pad.Pkcs7.unpad(wordArray);
  415 + */
  416 + unpad: function (data) {
  417 + // Get number of padding bytes from last byte
  418 + var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  419 +
  420 + // Remove padding
  421 + data.sigBytes -= nPaddingBytes;
  422 + }
  423 + };
  424 +
  425 + /**
  426 + * Abstract base block cipher template.
  427 + *
  428 + * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits)
  429 + */
  430 + var BlockCipher = C_lib.BlockCipher = Cipher.extend({
  431 + /**
  432 + * Configuration options.
  433 + *
  434 + * @property {Mode} mode The block mode to use. Default: CBC
  435 + * @property {Padding} padding The padding strategy to use. Default: Pkcs7
  436 + */
  437 + cfg: Cipher.cfg.extend({
  438 + mode: CBC,
  439 + padding: Pkcs7
  440 + }),
  441 +
  442 + reset: function () {
  443 + var modeCreator;
  444 +
  445 + // Reset cipher
  446 + Cipher.reset.call(this);
  447 +
  448 + // Shortcuts
  449 + var cfg = this.cfg;
  450 + var iv = cfg.iv;
  451 + var mode = cfg.mode;
  452 +
  453 + // Reset block mode
  454 + if (this._xformMode == this._ENC_XFORM_MODE) {
  455 + modeCreator = mode.createEncryptor;
  456 + } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
  457 + modeCreator = mode.createDecryptor;
  458 + // Keep at least one block in the buffer for unpadding
  459 + this._minBufferSize = 1;
  460 + }
  461 +
  462 + if (this._mode && this._mode.__creator == modeCreator) {
  463 + this._mode.init(this, iv && iv.words);
  464 + } else {
  465 + this._mode = modeCreator.call(mode, this, iv && iv.words);
  466 + this._mode.__creator = modeCreator;
  467 + }
  468 + },
  469 +
  470 + _doProcessBlock: function (words, offset) {
  471 + this._mode.processBlock(words, offset);
  472 + },
  473 +
  474 + _doFinalize: function () {
  475 + var finalProcessedBlocks;
  476 +
  477 + // Shortcut
  478 + var padding = this.cfg.padding;
  479 +
  480 + // Finalize
  481 + if (this._xformMode == this._ENC_XFORM_MODE) {
  482 + // Pad data
  483 + padding.pad(this._data, this.blockSize);
  484 +
  485 + // Process final blocks
  486 + finalProcessedBlocks = this._process(!!'flush');
  487 + } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
  488 + // Process final blocks
  489 + finalProcessedBlocks = this._process(!!'flush');
  490 +
  491 + // Unpad data
  492 + padding.unpad(finalProcessedBlocks);
  493 + }
  494 +
  495 + return finalProcessedBlocks;
  496 + },
  497 +
  498 + blockSize: 128/32
  499 + });
  500 +
  501 + /**
  502 + * A collection of cipher parameters.
  503 + *
  504 + * @property {WordArray} ciphertext The raw ciphertext.
  505 + * @property {WordArray} key The key to this ciphertext.
  506 + * @property {WordArray} iv The IV used in the ciphering operation.
  507 + * @property {WordArray} salt The salt used with a key derivation function.
  508 + * @property {Cipher} algorithm The cipher algorithm.
  509 + * @property {Mode} mode The block mode used in the ciphering operation.
  510 + * @property {Padding} padding The padding scheme used in the ciphering operation.
  511 + * @property {number} blockSize The block size of the cipher.
  512 + * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string.
  513 + */
  514 + var CipherParams = C_lib.CipherParams = Base.extend({
  515 + /**
  516 + * Initializes a newly created cipher params object.
  517 + *
  518 + * @param {Object} cipherParams An object with any of the possible cipher parameters.
  519 + *
  520 + * @example
  521 + *
  522 + * var cipherParams = CryptoJS.lib.CipherParams.create({
  523 + * ciphertext: ciphertextWordArray,
  524 + * key: keyWordArray,
  525 + * iv: ivWordArray,
  526 + * salt: saltWordArray,
  527 + * algorithm: CryptoJS.algo.AES,
  528 + * mode: CryptoJS.mode.CBC,
  529 + * padding: CryptoJS.pad.PKCS7,
  530 + * blockSize: 4,
  531 + * formatter: CryptoJS.format.OpenSSL
  532 + * });
  533 + */
  534 + init: function (cipherParams) {
  535 + this.mixIn(cipherParams);
  536 + },
  537 +
  538 + /**
  539 + * Converts this cipher params object to a string.
  540 + *
  541 + * @param {Format} formatter (Optional) The formatting strategy to use.
  542 + *
  543 + * @return {string} The stringified cipher params.
  544 + *
  545 + * @throws Error If neither the formatter nor the default formatter is set.
  546 + *
  547 + * @example
  548 + *
  549 + * var string = cipherParams + '';
  550 + * var string = cipherParams.toString();
  551 + * var string = cipherParams.toString(CryptoJS.format.OpenSSL);
  552 + */
  553 + toString: function (formatter) {
  554 + return (formatter || this.formatter).stringify(this);
  555 + }
  556 + });
  557 +
  558 + /**
  559 + * Format namespace.
  560 + */
  561 + var C_format = C.format = {};
  562 +
  563 + /**
  564 + * OpenSSL formatting strategy.
  565 + */
  566 + var OpenSSLFormatter = C_format.OpenSSL = {
  567 + /**
  568 + * Converts a cipher params object to an OpenSSL-compatible string.
  569 + *
  570 + * @param {CipherParams} cipherParams The cipher params object.
  571 + *
  572 + * @return {string} The OpenSSL-compatible string.
  573 + *
  574 + * @static
  575 + *
  576 + * @example
  577 + *
  578 + * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
  579 + */
  580 + stringify: function (cipherParams) {
  581 + var wordArray;
  582 +
  583 + // Shortcuts
  584 + var ciphertext = cipherParams.ciphertext;
  585 + var salt = cipherParams.salt;
  586 +
  587 + // Format
  588 + if (salt) {
  589 + wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
  590 + } else {
  591 + wordArray = ciphertext;
  592 + }
  593 +
  594 + return wordArray.toString(Base64);
  595 + },
  596 +
  597 + /**
  598 + * Converts an OpenSSL-compatible string to a cipher params object.
  599 + *
  600 + * @param {string} openSSLStr The OpenSSL-compatible string.
  601 + *
  602 + * @return {CipherParams} The cipher params object.
  603 + *
  604 + * @static
  605 + *
  606 + * @example
  607 + *
  608 + * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
  609 + */
  610 + parse: function (openSSLStr) {
  611 + var salt;
  612 +
  613 + // Parse base64
  614 + var ciphertext = Base64.parse(openSSLStr);
  615 +
  616 + // Shortcut
  617 + var ciphertextWords = ciphertext.words;
  618 +
  619 + // Test for salt
  620 + if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) {
  621 + // Extract salt
  622 + salt = WordArray.create(ciphertextWords.slice(2, 4));
  623 +
  624 + // Remove salt from ciphertext
  625 + ciphertextWords.splice(0, 4);
  626 + ciphertext.sigBytes -= 16;
  627 + }
  628 +
  629 + return CipherParams.create({ ciphertext: ciphertext, salt: salt });
  630 + }
  631 + };
  632 +
  633 + /**
  634 + * A cipher wrapper that returns ciphertext as a serializable cipher params object.
  635 + */
  636 + var SerializableCipher = C_lib.SerializableCipher = Base.extend({
  637 + /**
  638 + * Configuration options.
  639 + *
  640 + * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL
  641 + */
  642 + cfg: Base.extend({
  643 + format: OpenSSLFormatter
  644 + }),
  645 +
  646 + /**
  647 + * Encrypts a message.
  648 + *
  649 + * @param {Cipher} cipher The cipher algorithm to use.
  650 + * @param {WordArray|string} message The message to encrypt.
  651 + * @param {WordArray} key The key.
  652 + * @param {Object} cfg (Optional) The configuration options to use for this operation.
  653 + *
  654 + * @return {CipherParams} A cipher params object.
  655 + *
  656 + * @static
  657 + *
  658 + * @example
  659 + *
  660 + * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
  661 + * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
  662 + * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  663 + */
  664 + encrypt: function (cipher, message, key, cfg) {
  665 + // Apply config defaults
  666 + cfg = this.cfg.extend(cfg);
  667 +
  668 + // Encrypt
  669 + var encryptor = cipher.createEncryptor(key, cfg);
  670 + var ciphertext = encryptor.finalize(message);
  671 +
  672 + // Shortcut
  673 + var cipherCfg = encryptor.cfg;
  674 +
  675 + // Create and return serializable cipher params
  676 + return CipherParams.create({
  677 + ciphertext: ciphertext,
  678 + key: key,
  679 + iv: cipherCfg.iv,
  680 + algorithm: cipher,
  681 + mode: cipherCfg.mode,
  682 + padding: cipherCfg.padding,
  683 + blockSize: cipher.blockSize,
  684 + formatter: cfg.format
  685 + });
  686 + },
  687 +
  688 + /**
  689 + * Decrypts serialized ciphertext.
  690 + *
  691 + * @param {Cipher} cipher The cipher algorithm to use.
  692 + * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  693 + * @param {WordArray} key The key.
  694 + * @param {Object} cfg (Optional) The configuration options to use for this operation.
  695 + *
  696 + * @return {WordArray} The plaintext.
  697 + *
  698 + * @static
  699 + *
  700 + * @example
  701 + *
  702 + * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  703 + * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  704 + */
  705 + decrypt: function (cipher, ciphertext, key, cfg) {
  706 + // Apply config defaults
  707 + cfg = this.cfg.extend(cfg);
  708 +
  709 + // Convert string to CipherParams
  710 + ciphertext = this._parse(ciphertext, cfg.format);
  711 +
  712 + // Decrypt
  713 + var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext);
  714 +
  715 + return plaintext;
  716 + },
  717 +
  718 + /**
  719 + * Converts serialized ciphertext to CipherParams,
  720 + * else assumed CipherParams already and returns ciphertext unchanged.
  721 + *
  722 + * @param {CipherParams|string} ciphertext The ciphertext.
  723 + * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
  724 + *
  725 + * @return {CipherParams} The unserialized ciphertext.
  726 + *
  727 + * @static
  728 + *
  729 + * @example
  730 + *
  731 + * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
  732 + */
  733 + _parse: function (ciphertext, format) {
  734 + if (typeof ciphertext == 'string') {
  735 + return format.parse(ciphertext, this);
  736 + } else {
  737 + return ciphertext;
  738 + }
  739 + }
  740 + });
  741 +
  742 + /**
  743 + * Key derivation function namespace.
  744 + */
  745 + var C_kdf = C.kdf = {};
  746 +
  747 + /**
  748 + * OpenSSL key derivation function.
  749 + */
  750 + var OpenSSLKdf = C_kdf.OpenSSL = {
  751 + /**
  752 + * Derives a key and IV from a password.
  753 + *
  754 + * @param {string} password The password to derive from.
  755 + * @param {number} keySize The size in words of the key to generate.
  756 + * @param {number} ivSize The size in words of the IV to generate.
  757 + * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
  758 + *
  759 + * @return {CipherParams} A cipher params object with the key, IV, and salt.
  760 + *
  761 + * @static
  762 + *
  763 + * @example
  764 + *
  765 + * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
  766 + * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
  767 + */
  768 + execute: function (password, keySize, ivSize, salt) {
  769 + // Generate random salt
  770 + if (!salt) {
  771 + salt = WordArray.random(64/8);
  772 + }
  773 +
  774 + // Derive key and IV
  775 + var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
  776 +
  777 + // Separate key and IV
  778 + var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
  779 + key.sigBytes = keySize * 4;
  780 +
  781 + // Return params
  782 + return CipherParams.create({ key: key, iv: iv, salt: salt });
  783 + }
  784 + };
  785 +
  786 + /**
  787 + * A serializable cipher wrapper that derives the key from a password,
  788 + * and returns ciphertext as a serializable cipher params object.
  789 + */
  790 + var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({
  791 + /**
  792 + * Configuration options.
  793 + *
  794 + * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL
  795 + */
  796 + cfg: SerializableCipher.cfg.extend({
  797 + kdf: OpenSSLKdf
  798 + }),
  799 +
  800 + /**
  801 + * Encrypts a message using a password.
  802 + *
  803 + * @param {Cipher} cipher The cipher algorithm to use.
  804 + * @param {WordArray|string} message The message to encrypt.
  805 + * @param {string} password The password.
  806 + * @param {Object} cfg (Optional) The configuration options to use for this operation.
  807 + *
  808 + * @return {CipherParams} A cipher params object.
  809 + *
  810 + * @static
  811 + *
  812 + * @example
  813 + *
  814 + * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
  815 + * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
  816 + */
  817 + encrypt: function (cipher, message, password, cfg) {
  818 + // Apply config defaults
  819 + cfg = this.cfg.extend(cfg);
  820 +
  821 + // Derive key and other params
  822 + var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize);
  823 +
  824 + // Add IV to config
  825 + cfg.iv = derivedParams.iv;
  826 +
  827 + // Encrypt
  828 + var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg);
  829 +
  830 + // Mix in derived params
  831 + ciphertext.mixIn(derivedParams);
  832 +
  833 + return ciphertext;
  834 + },
  835 +
  836 + /**
  837 + * Decrypts serialized ciphertext using a password.
  838 + *
  839 + * @param {Cipher} cipher The cipher algorithm to use.
  840 + * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  841 + * @param {string} password The password.
  842 + * @param {Object} cfg (Optional) The configuration options to use for this operation.
  843 + *
  844 + * @return {WordArray} The plaintext.
  845 + *
  846 + * @static
  847 + *
  848 + * @example
  849 + *
  850 + * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
  851 + * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
  852 + */
  853 + decrypt: function (cipher, ciphertext, password, cfg) {
  854 + // Apply config defaults
  855 + cfg = this.cfg.extend(cfg);
  856 +
  857 + // Convert string to CipherParams
  858 + ciphertext = this._parse(ciphertext, cfg.format);
  859 +
  860 + // Derive key and other params
  861 + var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt);
  862 +
  863 + // Add IV to config
  864 + cfg.iv = derivedParams.iv;
  865 +
  866 + // Decrypt
  867 + var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg);
  868 +
  869 + return plaintext;
  870 + }
  871 + });
  872 +}());
  1 +/**
  2 + * CryptoJS core components.
  3 + */
  4 +var CryptoJS = CryptoJS || (function (Math, undefined) {
  5 + /*
  6 + * Local polyfil of Object.create
  7 + */
  8 + var create = Object.create || (function () {
  9 + function F() {}
  10 +
  11 + return function (obj) {
  12 + var subtype;
  13 +
  14 + F.prototype = obj;
  15 +
  16 + subtype = new F();
  17 +
  18 + F.prototype = null;
  19 +
  20 + return subtype;
  21 + };
  22 + }())
  23 +
  24 + /**
  25 + * CryptoJS namespace.
  26 + */
  27 + var C = {};
  28 +
  29 + /**
  30 + * Library namespace.
  31 + */
  32 + var C_lib = C.lib = {};
  33 +
  34 + /**
  35 + * Base object for prototypal inheritance.
  36 + */
  37 + var Base = C_lib.Base = (function () {
  38 +
  39 +
  40 + return {
  41 + /**
  42 + * Creates a new object that inherits from this object.
  43 + *
  44 + * @param {Object} overrides Properties to copy into the new object.
  45 + *
  46 + * @return {Object} The new object.
  47 + *
  48 + * @static
  49 + *
  50 + * @example
  51 + *
  52 + * var MyType = CryptoJS.lib.Base.extend({
  53 + * field: 'value',
  54 + *
  55 + * method: function () {
  56 + * }
  57 + * });
  58 + */
  59 + extend: function (overrides) {
  60 + // Spawn
  61 + var subtype = create(this);
  62 +
  63 + // Augment
  64 + if (overrides) {
  65 + subtype.mixIn(overrides);
  66 + }
  67 +
  68 + // Create default initializer
  69 + if (!subtype.hasOwnProperty('init') || this.init === subtype.init) {
  70 + subtype.init = function () {
  71 + subtype.$super.init.apply(this, arguments);
  72 + };
  73 + }
  74 +
  75 + // Initializer's prototype is the subtype object
  76 + subtype.init.prototype = subtype;
  77 +
  78 + // Reference supertype
  79 + subtype.$super = this;
  80 +
  81 + return subtype;
  82 + },
  83 +
  84 + /**
  85 + * Extends this object and runs the init method.
  86 + * Arguments to create() will be passed to init().
  87 + *
  88 + * @return {Object} The new object.
  89 + *
  90 + * @static
  91 + *
  92 + * @example
  93 + *
  94 + * var instance = MyType.create();
  95 + */
  96 + create: function () {
  97 + var instance = this.extend();
  98 + instance.init.apply(instance, arguments);
  99 +
  100 + return instance;
  101 + },
  102 +
  103 + /**
  104 + * Initializes a newly created object.
  105 + * Override this method to add some logic when your objects are created.
  106 + *
  107 + * @example
  108 + *
  109 + * var MyType = CryptoJS.lib.Base.extend({
  110 + * init: function () {
  111 + * // ...
  112 + * }
  113 + * });
  114 + */
  115 + init: function () {
  116 + },
  117 +
  118 + /**
  119 + * Copies properties into this object.
  120 + *
  121 + * @param {Object} properties The properties to mix in.
  122 + *
  123 + * @example
  124 + *
  125 + * MyType.mixIn({
  126 + * field: 'value'
  127 + * });
  128 + */
  129 + mixIn: function (properties) {
  130 + for (var propertyName in properties) {
  131 + if (properties.hasOwnProperty(propertyName)) {
  132 + this[propertyName] = properties[propertyName];
  133 + }
  134 + }
  135 +
  136 + // IE won't copy toString using the loop above
  137 + if (properties.hasOwnProperty('toString')) {
  138 + this.toString = properties.toString;
  139 + }
  140 + },
  141 +
  142 + /**
  143 + * Creates a copy of this object.
  144 + *
  145 + * @return {Object} The clone.
  146 + *
  147 + * @example
  148 + *
  149 + * var clone = instance.clone();
  150 + */
  151 + clone: function () {
  152 + return this.init.prototype.extend(this);
  153 + }
  154 + };
  155 + }());
  156 +
  157 + /**
  158 + * An array of 32-bit words.
  159 + *
  160 + * @property {Array} words The array of 32-bit words.
  161 + * @property {number} sigBytes The number of significant bytes in this word array.
  162 + */
  163 + var WordArray = C_lib.WordArray = Base.extend({
  164 + /**
  165 + * Initializes a newly created word array.
  166 + *
  167 + * @param {Array} words (Optional) An array of 32-bit words.
  168 + * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  169 + *
  170 + * @example
  171 + *
  172 + * var wordArray = CryptoJS.lib.WordArray.create();
  173 + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
  174 + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
  175 + */
  176 + init: function (words, sigBytes) {
  177 + words = this.words = words || [];
  178 +
  179 + if (sigBytes != undefined) {
  180 + this.sigBytes = sigBytes;
  181 + } else {
  182 + this.sigBytes = words.length * 4;
  183 + }
  184 + },
  185 +
  186 + /**
  187 + * Converts this word array to a string.
  188 + *
  189 + * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
  190 + *
  191 + * @return {string} The stringified word array.
  192 + *
  193 + * @example
  194 + *
  195 + * var string = wordArray + '';
  196 + * var string = wordArray.toString();
  197 + * var string = wordArray.toString(CryptoJS.enc.Utf8);
  198 + */
  199 + toString: function (encoder) {
  200 + return (encoder || Hex).stringify(this);
  201 + },
  202 +
  203 + /**
  204 + * Concatenates a word array to this word array.
  205 + *
  206 + * @param {WordArray} wordArray The word array to append.
  207 + *
  208 + * @return {WordArray} This word array.
  209 + *
  210 + * @example
  211 + *
  212 + * wordArray1.concat(wordArray2);
  213 + */
  214 + concat: function (wordArray) {
  215 + // Shortcuts
  216 + var thisWords = this.words;
  217 + var thatWords = wordArray.words;
  218 + var thisSigBytes = this.sigBytes;
  219 + var thatSigBytes = wordArray.sigBytes;
  220 +
  221 + // Clamp excess bits
  222 + this.clamp();
  223 +
  224 + // Concat
  225 + if (thisSigBytes % 4) {
  226 + // Copy one byte at a time
  227 + for (var i = 0; i < thatSigBytes; i++) {
  228 + var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  229 + thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
  230 + }
  231 + } else {
  232 + // Copy one word at a time
  233 + for (var i = 0; i < thatSigBytes; i += 4) {
  234 + thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2];
  235 + }
  236 + }
  237 + this.sigBytes += thatSigBytes;
  238 +
  239 + // Chainable
  240 + return this;
  241 + },
  242 +
  243 + /**
  244 + * Removes insignificant bits.
  245 + *
  246 + * @example
  247 + *
  248 + * wordArray.clamp();
  249 + */
  250 + clamp: function () {
  251 + // Shortcuts
  252 + var words = this.words;
  253 + var sigBytes = this.sigBytes;
  254 +
  255 + // Clamp
  256 + words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
  257 + words.length = Math.ceil(sigBytes / 4);
  258 + },
  259 +
  260 + /**
  261 + * Creates a copy of this word array.
  262 + *
  263 + * @return {WordArray} The clone.
  264 + *
  265 + * @example
  266 + *
  267 + * var clone = wordArray.clone();
  268 + */
  269 + clone: function () {
  270 + var clone = Base.clone.call(this);
  271 + clone.words = this.words.slice(0);
  272 +
  273 + return clone;
  274 + },
  275 +
  276 + /**
  277 + * Creates a word array filled with random bytes.
  278 + *
  279 + * @param {number} nBytes The number of random bytes to generate.
  280 + *
  281 + * @return {WordArray} The random word array.
  282 + *
  283 + * @static
  284 + *
  285 + * @example
  286 + *
  287 + * var wordArray = CryptoJS.lib.WordArray.random(16);
  288 + */
  289 + random: function (nBytes) {
  290 + var words = [];
  291 +
  292 + var r = function (m_w) {
  293 + var m_w = m_w;
  294 + var m_z = 0x3ade68b1;
  295 + var mask = 0xffffffff;
  296 +
  297 + return function () {
  298 + m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
  299 + m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
  300 + var result = ((m_z << 0x10) + m_w) & mask;
  301 + result /= 0x100000000;
  302 + result += 0.5;
  303 + return result * (Math.random() > 0.5 ? 1 : -1);
  304 + }
  305 + };
  306 +
  307 + for (var i = 0, rcache; i < nBytes; i += 4) {
  308 + var _r = r((rcache || Math.random()) * 0x100000000);
  309 +
  310 + rcache = _r() * 0x3ade67b7;
  311 + words.push((_r() * 0x100000000) | 0);
  312 + }
  313 +
  314 + return new WordArray.init(words, nBytes);
  315 + }
  316 + });
  317 +
  318 + /**
  319 + * Encoder namespace.
  320 + */
  321 + var C_enc = C.enc = {};
  322 +
  323 + /**
  324 + * Hex encoding strategy.
  325 + */
  326 + var Hex = C_enc.Hex = {
  327 + /**
  328 + * Converts a word array to a hex string.
  329 + *
  330 + * @param {WordArray} wordArray The word array.
  331 + *
  332 + * @return {string} The hex string.
  333 + *
  334 + * @static
  335 + *
  336 + * @example
  337 + *
  338 + * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
  339 + */
  340 + stringify: function (wordArray) {
  341 + // Shortcuts
  342 + var words = wordArray.words;
  343 + var sigBytes = wordArray.sigBytes;
  344 +
  345 + // Convert
  346 + var hexChars = [];
  347 + for (var i = 0; i < sigBytes; i++) {
  348 + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  349 + hexChars.push((bite >>> 4).toString(16));
  350 + hexChars.push((bite & 0x0f).toString(16));
  351 + }
  352 +
  353 + return hexChars.join('');
  354 + },
  355 +
  356 + /**
  357 + * Converts a hex string to a word array.
  358 + *
  359 + * @param {string} hexStr The hex string.
  360 + *
  361 + * @return {WordArray} The word array.
  362 + *
  363 + * @static
  364 + *
  365 + * @example
  366 + *
  367 + * var wordArray = CryptoJS.enc.Hex.parse(hexString);
  368 + */
  369 + parse: function (hexStr) {
  370 + // Shortcut
  371 + var hexStrLength = hexStr.length;
  372 +
  373 + // Convert
  374 + var words = [];
  375 + for (var i = 0; i < hexStrLength; i += 2) {
  376 + words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
  377 + }
  378 +
  379 + return new WordArray.init(words, hexStrLength / 2);
  380 + }
  381 + };
  382 +
  383 + /**
  384 + * Latin1 encoding strategy.
  385 + */
  386 + var Latin1 = C_enc.Latin1 = {
  387 + /**
  388 + * Converts a word array to a Latin1 string.
  389 + *
  390 + * @param {WordArray} wordArray The word array.
  391 + *
  392 + * @return {string} The Latin1 string.
  393 + *
  394 + * @static
  395 + *
  396 + * @example
  397 + *
  398 + * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
  399 + */
  400 + stringify: function (wordArray) {
  401 + // Shortcuts
  402 + var words = wordArray.words;
  403 + var sigBytes = wordArray.sigBytes;
  404 +
  405 + // Convert
  406 + var latin1Chars = [];
  407 + for (var i = 0; i < sigBytes; i++) {
  408 + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  409 + latin1Chars.push(String.fromCharCode(bite));
  410 + }
  411 +
  412 + return latin1Chars.join('');
  413 + },
  414 +
  415 + /**
  416 + * Converts a Latin1 string to a word array.
  417 + *
  418 + * @param {string} latin1Str The Latin1 string.
  419 + *
  420 + * @return {WordArray} The word array.
  421 + *
  422 + * @static
  423 + *
  424 + * @example
  425 + *
  426 + * var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
  427 + */
  428 + parse: function (latin1Str) {
  429 + // Shortcut
  430 + var latin1StrLength = latin1Str.length;
  431 +
  432 + // Convert
  433 + var words = [];
  434 + for (var i = 0; i < latin1StrLength; i++) {
  435 + words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
  436 + }
  437 +
  438 + return new WordArray.init(words, latin1StrLength);
  439 + }
  440 + };
  441 +
  442 + /**
  443 + * UTF-8 encoding strategy.
  444 + */
  445 + var Utf8 = C_enc.Utf8 = {
  446 + /**
  447 + * Converts a word array to a UTF-8 string.
  448 + *
  449 + * @param {WordArray} wordArray The word array.
  450 + *
  451 + * @return {string} The UTF-8 string.
  452 + *
  453 + * @static
  454 + *
  455 + * @example
  456 + *
  457 + * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
  458 + */
  459 + stringify: function (wordArray) {
  460 + try {
  461 + return decodeURIComponent(escape(Latin1.stringify(wordArray)));
  462 + } catch (e) {
  463 + throw new Error('Malformed UTF-8 data');
  464 + }
  465 + },
  466 +
  467 + /**
  468 + * Converts a UTF-8 string to a word array.
  469 + *
  470 + * @param {string} utf8Str The UTF-8 string.
  471 + *
  472 + * @return {WordArray} The word array.
  473 + *
  474 + * @static
  475 + *
  476 + * @example
  477 + *
  478 + * var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
  479 + */
  480 + parse: function (utf8Str) {
  481 + return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
  482 + }
  483 + };
  484 +
  485 + /**
  486 + * Abstract buffered block algorithm template.
  487 + *
  488 + * The property blockSize must be implemented in a concrete subtype.
  489 + *
  490 + * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
  491 + */
  492 + var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
  493 + /**
  494 + * Resets this block algorithm's data buffer to its initial state.
  495 + *
  496 + * @example
  497 + *
  498 + * bufferedBlockAlgorithm.reset();
  499 + */
  500 + reset: function () {
  501 + // Initial values
  502 + this._data = new WordArray.init();
  503 + this._nDataBytes = 0;
  504 + },
  505 +
  506 + /**
  507 + * Adds new data to this block algorithm's buffer.
  508 + *
  509 + * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
  510 + *
  511 + * @example
  512 + *
  513 + * bufferedBlockAlgorithm._append('data');
  514 + * bufferedBlockAlgorithm._append(wordArray);
  515 + */
  516 + _append: function (data) {
  517 + // Convert string to WordArray, else assume WordArray already
  518 + if (typeof data == 'string') {
  519 + data = Utf8.parse(data);
  520 + }
  521 +
  522 + // Append
  523 + this._data.concat(data);
  524 + this._nDataBytes += data.sigBytes;
  525 + },
  526 +
  527 + /**
  528 + * Processes available data blocks.
  529 + *
  530 + * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
  531 + *
  532 + * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
  533 + *
  534 + * @return {WordArray} The processed data.
  535 + *
  536 + * @example
  537 + *
  538 + * var processedData = bufferedBlockAlgorithm._process();
  539 + * var processedData = bufferedBlockAlgorithm._process(!!'flush');
  540 + */
  541 + _process: function (doFlush) {
  542 + var processedWords;
  543 +
  544 + // Shortcuts
  545 + var data = this._data;
  546 + var dataWords = data.words;
  547 + var dataSigBytes = data.sigBytes;
  548 + var blockSize = this.blockSize;
  549 + var blockSizeBytes = blockSize * 4;
  550 +
  551 + // Count blocks ready
  552 + var nBlocksReady = dataSigBytes / blockSizeBytes;
  553 + if (doFlush) {
  554 + // Round up to include partial blocks
  555 + nBlocksReady = Math.ceil(nBlocksReady);
  556 + } else {
  557 + // Round down to include only full blocks,
  558 + // less the number of blocks that must remain in the buffer
  559 + nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
  560 + }
  561 +
  562 + // Count words ready
  563 + var nWordsReady = nBlocksReady * blockSize;
  564 +
  565 + // Count bytes ready
  566 + var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
  567 +
  568 + // Process blocks
  569 + if (nWordsReady) {
  570 + for (var offset = 0; offset < nWordsReady; offset += blockSize) {
  571 + // Perform concrete-algorithm logic
  572 + this._doProcessBlock(dataWords, offset);
  573 + }
  574 +
  575 + // Remove processed words
  576 + processedWords = dataWords.splice(0, nWordsReady);
  577 + data.sigBytes -= nBytesReady;
  578 + }
  579 +
  580 + // Return processed words
  581 + return new WordArray.init(processedWords, nBytesReady);
  582 + },
  583 +
  584 + /**
  585 + * Creates a copy of this object.
  586 + *
  587 + * @return {Object} The clone.
  588 + *
  589 + * @example
  590 + *
  591 + * var clone = bufferedBlockAlgorithm.clone();
  592 + */
  593 + clone: function () {
  594 + var clone = Base.clone.call(this);
  595 + clone._data = this._data.clone();
  596 +
  597 + return clone;
  598 + },
  599 +
  600 + _minBufferSize: 0
  601 + });
  602 +
  603 + /**
  604 + * Abstract hasher template.
  605 + *
  606 + * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
  607 + */
  608 + var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
  609 + /**
  610 + * Configuration options.
  611 + */
  612 + cfg: Base.extend(),
  613 +
  614 + /**
  615 + * Initializes a newly created hasher.
  616 + *
  617 + * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
  618 + *
  619 + * @example
  620 + *
  621 + * var hasher = CryptoJS.algo.SHA256.create();
  622 + */
  623 + init: function (cfg) {
  624 + // Apply config defaults
  625 + this.cfg = this.cfg.extend(cfg);
  626 +
  627 + // Set initial values
  628 + this.reset();
  629 + },
  630 +
  631 + /**
  632 + * Resets this hasher to its initial state.
  633 + *
  634 + * @example
  635 + *
  636 + * hasher.reset();
  637 + */
  638 + reset: function () {
  639 + // Reset data buffer
  640 + BufferedBlockAlgorithm.reset.call(this);
  641 +
  642 + // Perform concrete-hasher logic
  643 + this._doReset();
  644 + },
  645 +
  646 + /**
  647 + * Updates this hasher with a message.
  648 + *
  649 + * @param {WordArray|string} messageUpdate The message to append.
  650 + *
  651 + * @return {Hasher} This hasher.
  652 + *
  653 + * @example
  654 + *
  655 + * hasher.update('message');
  656 + * hasher.update(wordArray);
  657 + */
  658 + update: function (messageUpdate) {
  659 + // Append
  660 + this._append(messageUpdate);
  661 +
  662 + // Update the hash
  663 + this._process();
  664 +
  665 + // Chainable
  666 + return this;
  667 + },
  668 +
  669 + /**
  670 + * Finalizes the hash computation.
  671 + * Note that the finalize operation is effectively a destructive, read-once operation.
  672 + *
  673 + * @param {WordArray|string} messageUpdate (Optional) A final message update.
  674 + *
  675 + * @return {WordArray} The hash.
  676 + *
  677 + * @example
  678 + *
  679 + * var hash = hasher.finalize();
  680 + * var hash = hasher.finalize('message');
  681 + * var hash = hasher.finalize(wordArray);
  682 + */
  683 + finalize: function (messageUpdate) {
  684 + // Final message update
  685 + if (messageUpdate) {
  686 + this._append(messageUpdate);
  687 + }
  688 +
  689 + // Perform concrete-hasher logic
  690 + var hash = this._doFinalize();
  691 +
  692 + return hash;
  693 + },
  694 +
  695 + blockSize: 512/32,
  696 +
  697 + /**
  698 + * Creates a shortcut function to a hasher's object interface.
  699 + *
  700 + * @param {Hasher} hasher The hasher to create a helper for.
  701 + *
  702 + * @return {Function} The shortcut function.
  703 + *
  704 + * @static
  705 + *
  706 + * @example
  707 + *
  708 + * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
  709 + */
  710 + _createHelper: function (hasher) {
  711 + return function (message, cfg) {
  712 + return new hasher.init(cfg).finalize(message);
  713 + };
  714 + },
  715 +
  716 + /**
  717 + * Creates a shortcut function to the HMAC's object interface.
  718 + *
  719 + * @param {Hasher} hasher The hasher to use in this HMAC helper.
  720 + *
  721 + * @return {Function} The shortcut function.
  722 + *
  723 + * @static
  724 + *
  725 + * @example
  726 + *
  727 + * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
  728 + */
  729 + _createHmacHelper: function (hasher) {
  730 + return function (message, key) {
  731 + return new C_algo.HMAC.init(hasher, key).finalize(message);
  732 + };
  733 + }
  734 + });
  735 +
  736 + /**
  737 + * Algorithm namespace.
  738 + */
  739 + var C_algo = C.algo = {};
  740 +
  741 + return C;
  742 +}(Math));
  1 +(function () {
  2 + // Shortcuts
  3 + var C = CryptoJS;
  4 + var C_lib = C.lib;
  5 + var WordArray = C_lib.WordArray;
  6 + var C_enc = C.enc;
  7 +
  8 + /**
  9 + * Base64 encoding strategy.
  10 + */
  11 + var Base64 = C_enc.Base64 = {
  12 + /**
  13 + * Converts a word array to a Base64 string.
  14 + *
  15 + * @param {WordArray} wordArray The word array.
  16 + *
  17 + * @return {string} The Base64 string.
  18 + *
  19 + * @static
  20 + *
  21 + * @example
  22 + *
  23 + * var base64String = CryptoJS.enc.Base64.stringify(wordArray);
  24 + */
  25 + stringify: function (wordArray) {
  26 + // Shortcuts
  27 + var words = wordArray.words;
  28 + var sigBytes = wordArray.sigBytes;
  29 + var map = this._map;
  30 +
  31 + // Clamp excess bits
  32 + wordArray.clamp();
  33 +
  34 + // Convert
  35 + var base64Chars = [];
  36 + for (var i = 0; i < sigBytes; i += 3) {
  37 + var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  38 + var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
  39 + var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
  40 +
  41 + var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
  42 +
  43 + for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) {
  44 + base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
  45 + }
  46 + }
  47 +
  48 + // Add padding
  49 + var paddingChar = map.charAt(64);
  50 + if (paddingChar) {
  51 + while (base64Chars.length % 4) {
  52 + base64Chars.push(paddingChar);
  53 + }
  54 + }
  55 +
  56 + return base64Chars.join('');
  57 + },
  58 +
  59 + /**
  60 + * Converts a Base64 string to a word array.
  61 + *
  62 + * @param {string} base64Str The Base64 string.
  63 + *
  64 + * @return {WordArray} The word array.
  65 + *
  66 + * @static
  67 + *
  68 + * @example
  69 + *
  70 + * var wordArray = CryptoJS.enc.Base64.parse(base64String);
  71 + */
  72 + parse: function (base64Str) {
  73 + // Shortcuts
  74 + var base64StrLength = base64Str.length;
  75 + var map = this._map;
  76 + var reverseMap = this._reverseMap;
  77 +
  78 + if (!reverseMap) {
  79 + reverseMap = this._reverseMap = [];
  80 + for (var j = 0; j < map.length; j++) {
  81 + reverseMap[map.charCodeAt(j)] = j;
  82 + }
  83 + }
  84 +
  85 + // Ignore padding
  86 + var paddingChar = map.charAt(64);
  87 + if (paddingChar) {
  88 + var paddingIndex = base64Str.indexOf(paddingChar);
  89 + if (paddingIndex !== -1) {
  90 + base64StrLength = paddingIndex;
  91 + }
  92 + }
  93 +
  94 + // Convert
  95 + return parseLoop(base64Str, base64StrLength, reverseMap);
  96 +
  97 + },
  98 +
  99 + _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
  100 + };
  101 +
  102 + function parseLoop(base64Str, base64StrLength, reverseMap) {
  103 + var words = [];
  104 + var nBytes = 0;
  105 + for (var i = 0; i < base64StrLength; i++) {
  106 + if (i % 4) {
  107 + var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
  108 + var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
  109 + var bitsCombined = bits1 | bits2;
  110 + words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8);
  111 + nBytes++;
  112 + }
  113 + }
  114 + return WordArray.create(words, nBytes);
  115 + }
  116 +}());
  1 +(function () {
  2 + // Shortcuts
  3 + var C = CryptoJS;
  4 + var C_lib = C.lib;
  5 + var WordArray = C_lib.WordArray;
  6 + var C_enc = C.enc;
  7 +
  8 + /**
  9 + * UTF-16 BE encoding strategy.
  10 + */
  11 + var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = {
  12 + /**
  13 + * Converts a word array to a UTF-16 BE string.
  14 + *
  15 + * @param {WordArray} wordArray The word array.
  16 + *
  17 + * @return {string} The UTF-16 BE string.
  18 + *
  19 + * @static
  20 + *
  21 + * @example
  22 + *
  23 + * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray);
  24 + */
  25 + stringify: function (wordArray) {
  26 + // Shortcuts
  27 + var words = wordArray.words;
  28 + var sigBytes = wordArray.sigBytes;
  29 +
  30 + // Convert
  31 + var utf16Chars = [];
  32 + for (var i = 0; i < sigBytes; i += 2) {
  33 + var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff;
  34 + utf16Chars.push(String.fromCharCode(codePoint));
  35 + }
  36 +
  37 + return utf16Chars.join('');
  38 + },
  39 +
  40 + /**
  41 + * Converts a UTF-16 BE string to a word array.
  42 + *
  43 + * @param {string} utf16Str The UTF-16 BE string.
  44 + *
  45 + * @return {WordArray} The word array.
  46 + *
  47 + * @static
  48 + *
  49 + * @example
  50 + *
  51 + * var wordArray = CryptoJS.enc.Utf16.parse(utf16String);
  52 + */
  53 + parse: function (utf16Str) {
  54 + // Shortcut
  55 + var utf16StrLength = utf16Str.length;
  56 +
  57 + // Convert
  58 + var words = [];
  59 + for (var i = 0; i < utf16StrLength; i++) {
  60 + words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16);
  61 + }
  62 +
  63 + return WordArray.create(words, utf16StrLength * 2);
  64 + }
  65 + };
  66 +
  67 + /**
  68 + * UTF-16 LE encoding strategy.
  69 + */
  70 + C_enc.Utf16LE = {
  71 + /**
  72 + * Converts a word array to a UTF-16 LE string.
  73 + *
  74 + * @param {WordArray} wordArray The word array.
  75 + *
  76 + * @return {string} The UTF-16 LE string.
  77 + *
  78 + * @static
  79 + *
  80 + * @example
  81 + *
  82 + * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray);
  83 + */
  84 + stringify: function (wordArray) {
  85 + // Shortcuts
  86 + var words = wordArray.words;
  87 + var sigBytes = wordArray.sigBytes;
  88 +
  89 + // Convert
  90 + var utf16Chars = [];
  91 + for (var i = 0; i < sigBytes; i += 2) {
  92 + var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff);
  93 + utf16Chars.push(String.fromCharCode(codePoint));
  94 + }
  95 +
  96 + return utf16Chars.join('');
  97 + },
  98 +
  99 + /**
  100 + * Converts a UTF-16 LE string to a word array.
  101 + *
  102 + * @param {string} utf16Str The UTF-16 LE string.
  103 + *
  104 + * @return {WordArray} The word array.
  105 + *
  106 + * @static
  107 + *
  108 + * @example
  109 + *
  110 + * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str);
  111 + */
  112 + parse: function (utf16Str) {
  113 + // Shortcut
  114 + var utf16StrLength = utf16Str.length;
  115 +
  116 + // Convert
  117 + var words = [];
  118 + for (var i = 0; i < utf16StrLength; i++) {
  119 + words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16));
  120 + }
  121 +
  122 + return WordArray.create(words, utf16StrLength * 2);
  123 + }
  124 + };
  125 +
  126 + function swapEndian(word) {
  127 + return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff);
  128 + }
  129 +}());
  1 +(function () {
  2 + // Shortcuts
  3 + var C = CryptoJS;
  4 + var C_lib = C.lib;
  5 + var Base = C_lib.Base;
  6 + var WordArray = C_lib.WordArray;
  7 + var C_algo = C.algo;
  8 + var MD5 = C_algo.MD5;
  9 +
  10 + /**
  11 + * This key derivation function is meant to conform with EVP_BytesToKey.
  12 + * www.openssl.org/docs/crypto/EVP_BytesToKey.html
  13 + */
  14 + var EvpKDF = C_algo.EvpKDF = Base.extend({
  15 + /**
  16 + * Configuration options.
  17 + *
  18 + * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
  19 + * @property {Hasher} hasher The hash algorithm to use. Default: MD5
  20 + * @property {number} iterations The number of iterations to perform. Default: 1
  21 + */
  22 + cfg: Base.extend({
  23 + keySize: 128/32,
  24 + hasher: MD5,
  25 + iterations: 1
  26 + }),
  27 +
  28 + /**
  29 + * Initializes a newly created key derivation function.
  30 + *
  31 + * @param {Object} cfg (Optional) The configuration options to use for the derivation.
  32 + *
  33 + * @example
  34 + *
  35 + * var kdf = CryptoJS.algo.EvpKDF.create();
  36 + * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
  37 + * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
  38 + */
  39 + init: function (cfg) {
  40 + this.cfg = this.cfg.extend(cfg);
  41 + },
  42 +
  43 + /**
  44 + * Derives a key from a password.
  45 + *
  46 + * @param {WordArray|string} password The password.
  47 + * @param {WordArray|string} salt A salt.
  48 + *
  49 + * @return {WordArray} The derived key.
  50 + *
  51 + * @example
  52 + *
  53 + * var key = kdf.compute(password, salt);
  54 + */
  55 + compute: function (password, salt) {
  56 + var block;
  57 +
  58 + // Shortcut
  59 + var cfg = this.cfg;
  60 +
  61 + // Init hasher
  62 + var hasher = cfg.hasher.create();
  63 +
  64 + // Initial values
  65 + var derivedKey = WordArray.create();
  66 +
  67 + // Shortcuts
  68 + var derivedKeyWords = derivedKey.words;
  69 + var keySize = cfg.keySize;
  70 + var iterations = cfg.iterations;
  71 +
  72 + // Generate key
  73 + while (derivedKeyWords.length < keySize) {
  74 + if (block) {
  75 + hasher.update(block);
  76 + }
  77 + block = hasher.update(password).finalize(salt);
  78 + hasher.reset();
  79 +
  80 + // Iterations
  81 + for (var i = 1; i < iterations; i++) {
  82 + block = hasher.finalize(block);
  83 + hasher.reset();
  84 + }
  85 +
  86 + derivedKey.concat(block);
  87 + }
  88 + derivedKey.sigBytes = keySize * 4;
  89 +
  90 + return derivedKey;
  91 + }
  92 + });
  93 +
  94 + /**
  95 + * Derives a key from a password.
  96 + *
  97 + * @param {WordArray|string} password The password.
  98 + * @param {WordArray|string} salt A salt.
  99 + * @param {Object} cfg (Optional) The configuration options to use for this computation.
  100 + *
  101 + * @return {WordArray} The derived key.
  102 + *
  103 + * @static
  104 + *
  105 + * @example
  106 + *
  107 + * var key = CryptoJS.EvpKDF(password, salt);
  108 + * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
  109 + * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
  110 + */
  111 + C.EvpKDF = function (password, salt, cfg) {
  112 + return EvpKDF.create(cfg).compute(password, salt);
  113 + };
  114 +}());
  1 +(function (undefined) {
  2 + // Shortcuts
  3 + var C = CryptoJS;
  4 + var C_lib = C.lib;
  5 + var CipherParams = C_lib.CipherParams;
  6 + var C_enc = C.enc;
  7 + var Hex = C_enc.Hex;
  8 + var C_format = C.format;
  9 +
  10 + var HexFormatter = C_format.Hex = {
  11 + /**
  12 + * Converts the ciphertext of a cipher params object to a hexadecimally encoded string.
  13 + *
  14 + * @param {CipherParams} cipherParams The cipher params object.
  15 + *
  16 + * @return {string} The hexadecimally encoded string.
  17 + *
  18 + * @static
  19 + *
  20 + * @example
  21 + *
  22 + * var hexString = CryptoJS.format.Hex.stringify(cipherParams);
  23 + */
  24 + stringify: function (cipherParams) {
  25 + return cipherParams.ciphertext.toString(Hex);
  26 + },
  27 +
  28 + /**
  29 + * Converts a hexadecimally encoded ciphertext string to a cipher params object.
  30 + *
  31 + * @param {string} input The hexadecimally encoded string.
  32 + *
  33 + * @return {CipherParams} The cipher params object.
  34 + *
  35 + * @static
  36 + *
  37 + * @example
  38 + *
  39 + * var cipherParams = CryptoJS.format.Hex.parse(hexString);
  40 + */
  41 + parse: function (input) {
  42 + var ciphertext = Hex.parse(input);
  43 + return CipherParams.create({ ciphertext: ciphertext });
  44 + }
  45 + };
  46 +}());
  1 +(function () {
  2 + // Shortcuts
  3 + var C = CryptoJS;
  4 + var C_lib = C.lib;
  5 + var Base = C_lib.Base;
  6 + var C_enc = C.enc;
  7 + var Utf8 = C_enc.Utf8;
  8 + var C_algo = C.algo;
  9 +
  10 + /**
  11 + * HMAC algorithm.
  12 + */
  13 + var HMAC = C_algo.HMAC = Base.extend({
  14 + /**
  15 + * Initializes a newly created HMAC.
  16 + *
  17 + * @param {Hasher} hasher The hash algorithm to use.
  18 + * @param {WordArray|string} key The secret key.
  19 + *
  20 + * @example
  21 + *
  22 + * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
  23 + */
  24 + init: function (hasher, key) {
  25 + // Init hasher
  26 + hasher = this._hasher = new hasher.init();
  27 +
  28 + // Convert string to WordArray, else assume WordArray already
  29 + if (typeof key == 'string') {
  30 + key = Utf8.parse(key);
  31 + }
  32 +
  33 + // Shortcuts
  34 + var hasherBlockSize = hasher.blockSize;
  35 + var hasherBlockSizeBytes = hasherBlockSize * 4;
  36 +
  37 + // Allow arbitrary length keys
  38 + if (key.sigBytes > hasherBlockSizeBytes) {
  39 + key = hasher.finalize(key);
  40 + }
  41 +
  42 + // Clamp excess bits
  43 + key.clamp();
  44 +
  45 + // Clone key for inner and outer pads
  46 + var oKey = this._oKey = key.clone();
  47 + var iKey = this._iKey = key.clone();
  48 +
  49 + // Shortcuts
  50 + var oKeyWords = oKey.words;
  51 + var iKeyWords = iKey.words;
  52 +
  53 + // XOR keys with pad constants
  54 + for (var i = 0; i < hasherBlockSize; i++) {
  55 + oKeyWords[i] ^= 0x5c5c5c5c;
  56 + iKeyWords[i] ^= 0x36363636;
  57 + }
  58 + oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes;
  59 +
  60 + // Set initial values
  61 + this.reset();
  62 + },
  63 +
  64 + /**
  65 + * Resets this HMAC to its initial state.
  66 + *
  67 + * @example
  68 + *
  69 + * hmacHasher.reset();
  70 + */
  71 + reset: function () {
  72 + // Shortcut
  73 + var hasher = this._hasher;
  74 +
  75 + // Reset
  76 + hasher.reset();
  77 + hasher.update(this._iKey);
  78 + },
  79 +
  80 + /**
  81 + * Updates this HMAC with a message.
  82 + *
  83 + * @param {WordArray|string} messageUpdate The message to append.
  84 + *
  85 + * @return {HMAC} This HMAC instance.
  86 + *
  87 + * @example
  88 + *
  89 + * hmacHasher.update('message');
  90 + * hmacHasher.update(wordArray);
  91 + */
  92 + update: function (messageUpdate) {
  93 + this._hasher.update(messageUpdate);
  94 +
  95 + // Chainable
  96 + return this;
  97 + },
  98 +
  99 + /**
  100 + * Finalizes the HMAC computation.
  101 + * Note that the finalize operation is effectively a destructive, read-once operation.
  102 + *
  103 + * @param {WordArray|string} messageUpdate (Optional) A final message update.
  104 + *
  105 + * @return {WordArray} The HMAC.
  106 + *
  107 + * @example
  108 + *
  109 + * var hmac = hmacHasher.finalize();
  110 + * var hmac = hmacHasher.finalize('message');
  111 + * var hmac = hmacHasher.finalize(wordArray);
  112 + */
  113 + finalize: function (messageUpdate) {
  114 + // Shortcut
  115 + var hasher = this._hasher;
  116 +
  117 + // Compute HMAC
  118 + var innerHash = hasher.finalize(messageUpdate);
  119 + hasher.reset();
  120 + var hmac = hasher.finalize(this._oKey.clone().concat(innerHash));
  121 +
  122 + return hmac;
  123 + }
  124 + });
  125 +}());
  1 +(function () {
  2 + // Check if typed arrays are supported
  3 + if (typeof ArrayBuffer != 'function') {
  4 + return;
  5 + }
  6 +
  7 + // Shortcuts
  8 + var C = CryptoJS;
  9 + var C_lib = C.lib;
  10 + var WordArray = C_lib.WordArray;
  11 +
  12 + // Reference original init
  13 + var superInit = WordArray.init;
  14 +
  15 + // Augment WordArray.init to handle typed arrays
  16 + var subInit = WordArray.init = function (typedArray) {
  17 + // Convert buffers to uint8
  18 + if (typedArray instanceof ArrayBuffer) {
  19 + typedArray = new Uint8Array(typedArray);
  20 + }
  21 +
  22 + // Convert other array views to uint8
  23 + if (
  24 + typedArray instanceof Int8Array ||
  25 + (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) ||
  26 + typedArray instanceof Int16Array ||
  27 + typedArray instanceof Uint16Array ||
  28 + typedArray instanceof Int32Array ||
  29 + typedArray instanceof Uint32Array ||
  30 + typedArray instanceof Float32Array ||
  31 + typedArray instanceof Float64Array
  32 + ) {
  33 + typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength);
  34 + }
  35 +
  36 + // Handle Uint8Array
  37 + if (typedArray instanceof Uint8Array) {
  38 + // Shortcut
  39 + var typedArrayByteLength = typedArray.byteLength;
  40 +
  41 + // Extract bytes
  42 + var words = [];
  43 + for (var i = 0; i < typedArrayByteLength; i++) {
  44 + words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8);
  45 + }
  46 +
  47 + // Initialize this word array
  48 + superInit.call(this, words, typedArrayByteLength);
  49 + } else {
  50 + // Else call normal init
  51 + superInit.apply(this, arguments);
  52 + }
  53 + };
  54 +
  55 + subInit.prototype = WordArray;
  56 +}());
  1 +(function (Math) {
  2 + // Shortcuts
  3 + var C = CryptoJS;
  4 + var C_lib = C.lib;
  5 + var WordArray = C_lib.WordArray;
  6 + var Hasher = C_lib.Hasher;
  7 + var C_algo = C.algo;
  8 +
  9 + // Constants table
  10 + var T = [];
  11 +
  12 + // Compute constants
  13 + (function () {
  14 + for (var i = 0; i < 64; i++) {
  15 + T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0;
  16 + }
  17 + }());
  18 +
  19 + /**
  20 + * MD5 hash algorithm.
  21 + */
  22 + var MD5 = C_algo.MD5 = Hasher.extend({
  23 + _doReset: function () {
  24 + this._hash = new WordArray.init([
  25 + 0x67452301, 0xefcdab89,
  26 + 0x98badcfe, 0x10325476
  27 + ]);
  28 + },
  29 +
  30 + _doProcessBlock: function (M, offset) {
  31 + // Swap endian
  32 + for (var i = 0; i < 16; i++) {
  33 + // Shortcuts
  34 + var offset_i = offset + i;
  35 + var M_offset_i = M[offset_i];
  36 +
  37 + M[offset_i] = (
  38 + (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  39 + (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  40 + );
  41 + }
  42 +
  43 + // Shortcuts
  44 + var H = this._hash.words;
  45 +
  46 + var M_offset_0 = M[offset + 0];
  47 + var M_offset_1 = M[offset + 1];
  48 + var M_offset_2 = M[offset + 2];
  49 + var M_offset_3 = M[offset + 3];
  50 + var M_offset_4 = M[offset + 4];
  51 + var M_offset_5 = M[offset + 5];
  52 + var M_offset_6 = M[offset + 6];
  53 + var M_offset_7 = M[offset + 7];
  54 + var M_offset_8 = M[offset + 8];
  55 + var M_offset_9 = M[offset + 9];
  56 + var M_offset_10 = M[offset + 10];
  57 + var M_offset_11 = M[offset + 11];
  58 + var M_offset_12 = M[offset + 12];
  59 + var M_offset_13 = M[offset + 13];
  60 + var M_offset_14 = M[offset + 14];
  61 + var M_offset_15 = M[offset + 15];
  62 +
  63 + // Working varialbes
  64 + var a = H[0];
  65 + var b = H[1];
  66 + var c = H[2];
  67 + var d = H[3];
  68 +
  69 + // Computation
  70 + a = FF(a, b, c, d, M_offset_0, 7, T[0]);
  71 + d = FF(d, a, b, c, M_offset_1, 12, T[1]);
  72 + c = FF(c, d, a, b, M_offset_2, 17, T[2]);
  73 + b = FF(b, c, d, a, M_offset_3, 22, T[3]);
  74 + a = FF(a, b, c, d, M_offset_4, 7, T[4]);
  75 + d = FF(d, a, b, c, M_offset_5, 12, T[5]);
  76 + c = FF(c, d, a, b, M_offset_6, 17, T[6]);
  77 + b = FF(b, c, d, a, M_offset_7, 22, T[7]);
  78 + a = FF(a, b, c, d, M_offset_8, 7, T[8]);
  79 + d = FF(d, a, b, c, M_offset_9, 12, T[9]);
  80 + c = FF(c, d, a, b, M_offset_10, 17, T[10]);
  81 + b = FF(b, c, d, a, M_offset_11, 22, T[11]);
  82 + a = FF(a, b, c, d, M_offset_12, 7, T[12]);
  83 + d = FF(d, a, b, c, M_offset_13, 12, T[13]);
  84 + c = FF(c, d, a, b, M_offset_14, 17, T[14]);
  85 + b = FF(b, c, d, a, M_offset_15, 22, T[15]);
  86 +
  87 + a = GG(a, b, c, d, M_offset_1, 5, T[16]);
  88 + d = GG(d, a, b, c, M_offset_6, 9, T[17]);
  89 + c = GG(c, d, a, b, M_offset_11, 14, T[18]);
  90 + b = GG(b, c, d, a, M_offset_0, 20, T[19]);
  91 + a = GG(a, b, c, d, M_offset_5, 5, T[20]);
  92 + d = GG(d, a, b, c, M_offset_10, 9, T[21]);
  93 + c = GG(c, d, a, b, M_offset_15, 14, T[22]);
  94 + b = GG(b, c, d, a, M_offset_4, 20, T[23]);
  95 + a = GG(a, b, c, d, M_offset_9, 5, T[24]);
  96 + d = GG(d, a, b, c, M_offset_14, 9, T[25]);
  97 + c = GG(c, d, a, b, M_offset_3, 14, T[26]);
  98 + b = GG(b, c, d, a, M_offset_8, 20, T[27]);
  99 + a = GG(a, b, c, d, M_offset_13, 5, T[28]);
  100 + d = GG(d, a, b, c, M_offset_2, 9, T[29]);
  101 + c = GG(c, d, a, b, M_offset_7, 14, T[30]);
  102 + b = GG(b, c, d, a, M_offset_12, 20, T[31]);
  103 +
  104 + a = HH(a, b, c, d, M_offset_5, 4, T[32]);
  105 + d = HH(d, a, b, c, M_offset_8, 11, T[33]);
  106 + c = HH(c, d, a, b, M_offset_11, 16, T[34]);
  107 + b = HH(b, c, d, a, M_offset_14, 23, T[35]);
  108 + a = HH(a, b, c, d, M_offset_1, 4, T[36]);
  109 + d = HH(d, a, b, c, M_offset_4, 11, T[37]);
  110 + c = HH(c, d, a, b, M_offset_7, 16, T[38]);
  111 + b = HH(b, c, d, a, M_offset_10, 23, T[39]);
  112 + a = HH(a, b, c, d, M_offset_13, 4, T[40]);
  113 + d = HH(d, a, b, c, M_offset_0, 11, T[41]);
  114 + c = HH(c, d, a, b, M_offset_3, 16, T[42]);
  115 + b = HH(b, c, d, a, M_offset_6, 23, T[43]);
  116 + a = HH(a, b, c, d, M_offset_9, 4, T[44]);
  117 + d = HH(d, a, b, c, M_offset_12, 11, T[45]);
  118 + c = HH(c, d, a, b, M_offset_15, 16, T[46]);
  119 + b = HH(b, c, d, a, M_offset_2, 23, T[47]);
  120 +
  121 + a = II(a, b, c, d, M_offset_0, 6, T[48]);
  122 + d = II(d, a, b, c, M_offset_7, 10, T[49]);
  123 + c = II(c, d, a, b, M_offset_14, 15, T[50]);
  124 + b = II(b, c, d, a, M_offset_5, 21, T[51]);
  125 + a = II(a, b, c, d, M_offset_12, 6, T[52]);
  126 + d = II(d, a, b, c, M_offset_3, 10, T[53]);
  127 + c = II(c, d, a, b, M_offset_10, 15, T[54]);
  128 + b = II(b, c, d, a, M_offset_1, 21, T[55]);
  129 + a = II(a, b, c, d, M_offset_8, 6, T[56]);
  130 + d = II(d, a, b, c, M_offset_15, 10, T[57]);
  131 + c = II(c, d, a, b, M_offset_6, 15, T[58]);
  132 + b = II(b, c, d, a, M_offset_13, 21, T[59]);
  133 + a = II(a, b, c, d, M_offset_4, 6, T[60]);
  134 + d = II(d, a, b, c, M_offset_11, 10, T[61]);
  135 + c = II(c, d, a, b, M_offset_2, 15, T[62]);
  136 + b = II(b, c, d, a, M_offset_9, 21, T[63]);
  137 +
  138 + // Intermediate hash value
  139 + H[0] = (H[0] + a) | 0;
  140 + H[1] = (H[1] + b) | 0;
  141 + H[2] = (H[2] + c) | 0;
  142 + H[3] = (H[3] + d) | 0;
  143 + },
  144 +
  145 + _doFinalize: function () {
  146 + // Shortcuts
  147 + var data = this._data;
  148 + var dataWords = data.words;
  149 +
  150 + var nBitsTotal = this._nDataBytes * 8;
  151 + var nBitsLeft = data.sigBytes * 8;
  152 +
  153 + // Add padding
  154 + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  155 +
  156 + var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000);
  157 + var nBitsTotalL = nBitsTotal;
  158 + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = (
  159 + (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) |
  160 + (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00)
  161 + );
  162 + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  163 + (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) |
  164 + (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00)
  165 + );
  166 +
  167 + data.sigBytes = (dataWords.length + 1) * 4;
  168 +
  169 + // Hash final blocks
  170 + this._process();
  171 +
  172 + // Shortcuts
  173 + var hash = this._hash;
  174 + var H = hash.words;
  175 +
  176 + // Swap endian
  177 + for (var i = 0; i < 4; i++) {
  178 + // Shortcut
  179 + var H_i = H[i];
  180 +
  181 + H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  182 + (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
  183 + }
  184 +
  185 + // Return final computed hash
  186 + return hash;
  187 + },
  188 +
  189 + clone: function () {
  190 + var clone = Hasher.clone.call(this);
  191 + clone._hash = this._hash.clone();
  192 +
  193 + return clone;
  194 + }
  195 + });
  196 +
  197 + function FF(a, b, c, d, x, s, t) {
  198 + var n = a + ((b & c) | (~b & d)) + x + t;
  199 + return ((n << s) | (n >>> (32 - s))) + b;
  200 + }
  201 +
  202 + function GG(a, b, c, d, x, s, t) {
  203 + var n = a + ((b & d) | (c & ~d)) + x + t;
  204 + return ((n << s) | (n >>> (32 - s))) + b;
  205 + }
  206 +
  207 + function HH(a, b, c, d, x, s, t) {
  208 + var n = a + (b ^ c ^ d) + x + t;
  209 + return ((n << s) | (n >>> (32 - s))) + b;
  210 + }
  211 +
  212 + function II(a, b, c, d, x, s, t) {
  213 + var n = a + (c ^ (b | ~d)) + x + t;
  214 + return ((n << s) | (n >>> (32 - s))) + b;
  215 + }
  216 +
  217 + /**
  218 + * Shortcut function to the hasher's object interface.
  219 + *
  220 + * @param {WordArray|string} message The message to hash.
  221 + *
  222 + * @return {WordArray} The hash.
  223 + *
  224 + * @static
  225 + *
  226 + * @example
  227 + *
  228 + * var hash = CryptoJS.MD5('message');
  229 + * var hash = CryptoJS.MD5(wordArray);
  230 + */
  231 + C.MD5 = Hasher._createHelper(MD5);
  232 +
  233 + /**
  234 + * Shortcut function to the HMAC's object interface.
  235 + *
  236 + * @param {WordArray|string} message The message to hash.
  237 + * @param {WordArray|string} key The secret key.
  238 + *
  239 + * @return {WordArray} The HMAC.
  240 + *
  241 + * @static
  242 + *
  243 + * @example
  244 + *
  245 + * var hmac = CryptoJS.HmacMD5(message, key);
  246 + */
  247 + C.HmacMD5 = Hasher._createHmacHelper(MD5);
  248 +}(Math));
  1 +/**
  2 + * Cipher Feedback block mode.
  3 + */
  4 +CryptoJS.mode.CFB = (function () {
  5 + var CFB = CryptoJS.lib.BlockCipherMode.extend();
  6 +
  7 + CFB.Encryptor = CFB.extend({
  8 + processBlock: function (words, offset) {
  9 + // Shortcuts
  10 + var cipher = this._cipher;
  11 + var blockSize = cipher.blockSize;
  12 +
  13 + generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
  14 +
  15 + // Remember this block to use with next block
  16 + this._prevBlock = words.slice(offset, offset + blockSize);
  17 + }
  18 + });
  19 +
  20 + CFB.Decryptor = CFB.extend({
  21 + processBlock: function (words, offset) {
  22 + // Shortcuts
  23 + var cipher = this._cipher;
  24 + var blockSize = cipher.blockSize;
  25 +
  26 + // Remember this block to use with next block
  27 + var thisBlock = words.slice(offset, offset + blockSize);
  28 +
  29 + generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
  30 +
  31 + // This block becomes the previous block
  32 + this._prevBlock = thisBlock;
  33 + }
  34 + });
  35 +
  36 + function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) {
  37 + var keystream;
  38 +
  39 + // Shortcut
  40 + var iv = this._iv;
  41 +
  42 + // Generate keystream
  43 + if (iv) {
  44 + keystream = iv.slice(0);
  45 +
  46 + // Remove IV for subsequent blocks
  47 + this._iv = undefined;
  48 + } else {
  49 + keystream = this._prevBlock;
  50 + }
  51 + cipher.encryptBlock(keystream, 0);
  52 +
  53 + // Encrypt
  54 + for (var i = 0; i < blockSize; i++) {
  55 + words[offset + i] ^= keystream[i];
  56 + }
  57 + }
  58 +
  59 + return CFB;
  60 +}());
  1 +/** @preserve
  2 + * Counter block mode compatible with Dr Brian Gladman fileenc.c
  3 + * derived from CryptoJS.mode.CTR
  4 + * Jan Hruby jhruby.web@gmail.com
  5 + */
  6 +CryptoJS.mode.CTRGladman = (function () {
  7 + var CTRGladman = CryptoJS.lib.BlockCipherMode.extend();
  8 +
  9 + function incWord(word)
  10 + {
  11 + if (((word >> 24) & 0xff) === 0xff) { //overflow
  12 + var b1 = (word >> 16)&0xff;
  13 + var b2 = (word >> 8)&0xff;
  14 + var b3 = word & 0xff;
  15 +
  16 + if (b1 === 0xff) // overflow b1
  17 + {
  18 + b1 = 0;
  19 + if (b2 === 0xff)
  20 + {
  21 + b2 = 0;
  22 + if (b3 === 0xff)
  23 + {
  24 + b3 = 0;
  25 + }
  26 + else
  27 + {
  28 + ++b3;
  29 + }
  30 + }
  31 + else
  32 + {
  33 + ++b2;
  34 + }
  35 + }
  36 + else
  37 + {
  38 + ++b1;
  39 + }
  40 +
  41 + word = 0;
  42 + word += (b1 << 16);
  43 + word += (b2 << 8);
  44 + word += b3;
  45 + }
  46 + else
  47 + {
  48 + word += (0x01 << 24);
  49 + }
  50 + return word;
  51 + }
  52 +
  53 + function incCounter(counter)
  54 + {
  55 + if ((counter[0] = incWord(counter[0])) === 0)
  56 + {
  57 + // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
  58 + counter[1] = incWord(counter[1]);
  59 + }
  60 + return counter;
  61 + }
  62 +
  63 + var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({
  64 + processBlock: function (words, offset) {
  65 + // Shortcuts
  66 + var cipher = this._cipher
  67 + var blockSize = cipher.blockSize;
  68 + var iv = this._iv;
  69 + var counter = this._counter;
  70 +
  71 + // Generate keystream
  72 + if (iv) {
  73 + counter = this._counter = iv.slice(0);
  74 +
  75 + // Remove IV for subsequent blocks
  76 + this._iv = undefined;
  77 + }
  78 +
  79 + incCounter(counter);
  80 +
  81 + var keystream = counter.slice(0);
  82 + cipher.encryptBlock(keystream, 0);
  83 +
  84 + // Encrypt
  85 + for (var i = 0; i < blockSize; i++) {
  86 + words[offset + i] ^= keystream[i];
  87 + }
  88 + }
  89 + });
  90 +
  91 + CTRGladman.Decryptor = Encryptor;
  92 +
  93 + return CTRGladman;
  94 +}());
  95 +
  96 +
  1 +/**
  2 + * Counter block mode.
  3 + */
  4 +CryptoJS.mode.CTR = (function () {
  5 + var CTR = CryptoJS.lib.BlockCipherMode.extend();
  6 +
  7 + var Encryptor = CTR.Encryptor = CTR.extend({
  8 + processBlock: function (words, offset) {
  9 + // Shortcuts
  10 + var cipher = this._cipher
  11 + var blockSize = cipher.blockSize;
  12 + var iv = this._iv;
  13 + var counter = this._counter;
  14 +
  15 + // Generate keystream
  16 + if (iv) {
  17 + counter = this._counter = iv.slice(0);
  18 +
  19 + // Remove IV for subsequent blocks
  20 + this._iv = undefined;
  21 + }
  22 + var keystream = counter.slice(0);
  23 + cipher.encryptBlock(keystream, 0);
  24 +
  25 + // Increment counter
  26 + counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0
  27 +
  28 + // Encrypt
  29 + for (var i = 0; i < blockSize; i++) {
  30 + words[offset + i] ^= keystream[i];
  31 + }
  32 + }
  33 + });
  34 +
  35 + CTR.Decryptor = Encryptor;
  36 +
  37 + return CTR;
  38 +}());
  1 +/**
  2 + * Electronic Codebook block mode.
  3 + */
  4 +CryptoJS.mode.ECB = (function () {
  5 + var ECB = CryptoJS.lib.BlockCipherMode.extend();
  6 +
  7 + ECB.Encryptor = ECB.extend({
  8 + processBlock: function (words, offset) {
  9 + this._cipher.encryptBlock(words, offset);
  10 + }
  11 + });
  12 +
  13 + ECB.Decryptor = ECB.extend({
  14 + processBlock: function (words, offset) {
  15 + this._cipher.decryptBlock(words, offset);
  16 + }
  17 + });
  18 +
  19 + return ECB;
  20 +}());
  1 +/**
  2 + * Output Feedback block mode.
  3 + */
  4 +CryptoJS.mode.OFB = (function () {
  5 + var OFB = CryptoJS.lib.BlockCipherMode.extend();
  6 +
  7 + var Encryptor = OFB.Encryptor = OFB.extend({
  8 + processBlock: function (words, offset) {
  9 + // Shortcuts
  10 + var cipher = this._cipher
  11 + var blockSize = cipher.blockSize;
  12 + var iv = this._iv;
  13 + var keystream = this._keystream;
  14 +
  15 + // Generate keystream
  16 + if (iv) {
  17 + keystream = this._keystream = iv.slice(0);
  18 +
  19 + // Remove IV for subsequent blocks
  20 + this._iv = undefined;
  21 + }
  22 + cipher.encryptBlock(keystream, 0);
  23 +
  24 + // Encrypt
  25 + for (var i = 0; i < blockSize; i++) {
  26 + words[offset + i] ^= keystream[i];
  27 + }
  28 + }
  29 + });
  30 +
  31 + OFB.Decryptor = Encryptor;
  32 +
  33 + return OFB;
  34 +}());
  1 +/**
  2 + * ANSI X.923 padding strategy.
  3 + */
  4 +CryptoJS.pad.AnsiX923 = {
  5 + pad: function (data, blockSize) {
  6 + // Shortcuts
  7 + var dataSigBytes = data.sigBytes;
  8 + var blockSizeBytes = blockSize * 4;
  9 +
  10 + // Count padding bytes
  11 + var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes;
  12 +
  13 + // Compute last byte position
  14 + var lastBytePos = dataSigBytes + nPaddingBytes - 1;
  15 +
  16 + // Pad
  17 + data.clamp();
  18 + data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8);
  19 + data.sigBytes += nPaddingBytes;
  20 + },
  21 +
  22 + unpad: function (data) {
  23 + // Get number of padding bytes from last byte
  24 + var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  25 +
  26 + // Remove padding
  27 + data.sigBytes -= nPaddingBytes;
  28 + }
  29 +};
  1 +/**
  2 + * ISO 10126 padding strategy.
  3 + */
  4 +CryptoJS.pad.Iso10126 = {
  5 + pad: function (data, blockSize) {
  6 + // Shortcut
  7 + var blockSizeBytes = blockSize * 4;
  8 +
  9 + // Count padding bytes
  10 + var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
  11 +
  12 + // Pad
  13 + data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)).
  14 + concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1));
  15 + },
  16 +
  17 + unpad: function (data) {
  18 + // Get number of padding bytes from last byte
  19 + var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  20 +
  21 + // Remove padding
  22 + data.sigBytes -= nPaddingBytes;
  23 + }
  24 +};
  1 +/**
  2 + * ISO/IEC 9797-1 Padding Method 2.
  3 + */
  4 +CryptoJS.pad.Iso97971 = {
  5 + pad: function (data, blockSize) {
  6 + // Add 0x80 byte
  7 + data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1));
  8 +
  9 + // Zero pad the rest
  10 + CryptoJS.pad.ZeroPadding.pad(data, blockSize);
  11 + },
  12 +
  13 + unpad: function (data) {
  14 + // Remove zero padding
  15 + CryptoJS.pad.ZeroPadding.unpad(data);
  16 +
  17 + // Remove one more byte -- the 0x80 byte
  18 + data.sigBytes--;
  19 + }
  20 +};
  1 +/**
  2 + * A noop padding strategy.
  3 + */
  4 +CryptoJS.pad.NoPadding = {
  5 + pad: function () {
  6 + },
  7 +
  8 + unpad: function () {
  9 + }
  10 +};
  1 +/**
  2 + * Zero padding strategy.
  3 + */
  4 +CryptoJS.pad.ZeroPadding = {
  5 + pad: function (data, blockSize) {
  6 + // Shortcut
  7 + var blockSizeBytes = blockSize * 4;
  8 +
  9 + // Pad
  10 + data.clamp();
  11 + data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes);
  12 + },
  13 +
  14 + unpad: function (data) {
  15 + // Shortcut
  16 + var dataWords = data.words;
  17 +
  18 + // Unpad
  19 + var i = data.sigBytes - 1;
  20 + for (var i = data.sigBytes - 1; i >= 0; i--) {
  21 + if (((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) {
  22 + data.sigBytes = i + 1;
  23 + break;
  24 + }
  25 + }
  26 + }
  27 +};
  1 +(function () {
  2 + // Shortcuts
  3 + var C = CryptoJS;
  4 + var C_lib = C.lib;
  5 + var Base = C_lib.Base;
  6 + var WordArray = C_lib.WordArray;
  7 + var C_algo = C.algo;
  8 + var SHA1 = C_algo.SHA1;
  9 + var HMAC = C_algo.HMAC;
  10 +
  11 + /**
  12 + * Password-Based Key Derivation Function 2 algorithm.
  13 + */
  14 + var PBKDF2 = C_algo.PBKDF2 = Base.extend({
  15 + /**
  16 + * Configuration options.
  17 + *
  18 + * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
  19 + * @property {Hasher} hasher The hasher to use. Default: SHA1
  20 + * @property {number} iterations The number of iterations to perform. Default: 1
  21 + */
  22 + cfg: Base.extend({
  23 + keySize: 128/32,
  24 + hasher: SHA1,
  25 + iterations: 1
  26 + }),
  27 +
  28 + /**
  29 + * Initializes a newly created key derivation function.
  30 + *
  31 + * @param {Object} cfg (Optional) The configuration options to use for the derivation.
  32 + *
  33 + * @example
  34 + *
  35 + * var kdf = CryptoJS.algo.PBKDF2.create();
  36 + * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 });
  37 + * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 });
  38 + */
  39 + init: function (cfg) {
  40 + this.cfg = this.cfg.extend(cfg);
  41 + },
  42 +
  43 + /**
  44 + * Computes the Password-Based Key Derivation Function 2.
  45 + *
  46 + * @param {WordArray|string} password The password.
  47 + * @param {WordArray|string} salt A salt.
  48 + *
  49 + * @return {WordArray} The derived key.
  50 + *
  51 + * @example
  52 + *
  53 + * var key = kdf.compute(password, salt);
  54 + */
  55 + compute: function (password, salt) {
  56 + // Shortcut
  57 + var cfg = this.cfg;
  58 +
  59 + // Init HMAC
  60 + var hmac = HMAC.create(cfg.hasher, password);
  61 +
  62 + // Initial values
  63 + var derivedKey = WordArray.create();
  64 + var blockIndex = WordArray.create([0x00000001]);
  65 +
  66 + // Shortcuts
  67 + var derivedKeyWords = derivedKey.words;
  68 + var blockIndexWords = blockIndex.words;
  69 + var keySize = cfg.keySize;
  70 + var iterations = cfg.iterations;
  71 +
  72 + // Generate key
  73 + while (derivedKeyWords.length < keySize) {
  74 + var block = hmac.update(salt).finalize(blockIndex);
  75 + hmac.reset();
  76 +
  77 + // Shortcuts
  78 + var blockWords = block.words;
  79 + var blockWordsLength = blockWords.length;
  80 +
  81 + // Iterations
  82 + var intermediate = block;
  83 + for (var i = 1; i < iterations; i++) {
  84 + intermediate = hmac.finalize(intermediate);
  85 + hmac.reset();
  86 +
  87 + // Shortcut
  88 + var intermediateWords = intermediate.words;
  89 +
  90 + // XOR intermediate with block
  91 + for (var j = 0; j < blockWordsLength; j++) {
  92 + blockWords[j] ^= intermediateWords[j];
  93 + }
  94 + }
  95 +
  96 + derivedKey.concat(block);
  97 + blockIndexWords[0]++;
  98 + }
  99 + derivedKey.sigBytes = keySize * 4;
  100 +
  101 + return derivedKey;
  102 + }
  103 + });
  104 +
  105 + /**
  106 + * Computes the Password-Based Key Derivation Function 2.
  107 + *
  108 + * @param {WordArray|string} password The password.
  109 + * @param {WordArray|string} salt A salt.
  110 + * @param {Object} cfg (Optional) The configuration options to use for this computation.
  111 + *
  112 + * @return {WordArray} The derived key.
  113 + *
  114 + * @static
  115 + *
  116 + * @example
  117 + *
  118 + * var key = CryptoJS.PBKDF2(password, salt);
  119 + * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 });
  120 + * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 });
  121 + */
  122 + C.PBKDF2 = function (password, salt, cfg) {
  123 + return PBKDF2.create(cfg).compute(password, salt);
  124 + };
  125 +}());
  1 +(function () {
  2 + // Shortcuts
  3 + var C = CryptoJS;
  4 + var C_lib = C.lib;
  5 + var StreamCipher = C_lib.StreamCipher;
  6 + var C_algo = C.algo;
  7 +
  8 + // Reusable objects
  9 + var S = [];
  10 + var C_ = [];
  11 + var G = [];
  12 +
  13 + /**
  14 + * Rabbit stream cipher algorithm.
  15 + *
  16 + * This is a legacy version that neglected to convert the key to little-endian.
  17 + * This error doesn't affect the cipher's security,
  18 + * but it does affect its compatibility with other implementations.
  19 + */
  20 + var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({
  21 + _doReset: function () {
  22 + // Shortcuts
  23 + var K = this._key.words;
  24 + var iv = this.cfg.iv;
  25 +
  26 + // Generate initial state values
  27 + var X = this._X = [
  28 + K[0], (K[3] << 16) | (K[2] >>> 16),
  29 + K[1], (K[0] << 16) | (K[3] >>> 16),
  30 + K[2], (K[1] << 16) | (K[0] >>> 16),
  31 + K[3], (K[2] << 16) | (K[1] >>> 16)
  32 + ];
  33 +
  34 + // Generate initial counter values
  35 + var C = this._C = [
  36 + (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
  37 + (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
  38 + (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
  39 + (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)
  40 + ];
  41 +
  42 + // Carry bit
  43 + this._b = 0;
  44 +
  45 + // Iterate the system four times
  46 + for (var i = 0; i < 4; i++) {
  47 + nextState.call(this);
  48 + }
  49 +
  50 + // Modify the counters
  51 + for (var i = 0; i < 8; i++) {
  52 + C[i] ^= X[(i + 4) & 7];
  53 + }
  54 +
  55 + // IV setup
  56 + if (iv) {
  57 + // Shortcuts
  58 + var IV = iv.words;
  59 + var IV_0 = IV[0];
  60 + var IV_1 = IV[1];
  61 +
  62 + // Generate four subvectors
  63 + var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
  64 + var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
  65 + var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
  66 + var i3 = (i2 << 16) | (i0 & 0x0000ffff);
  67 +
  68 + // Modify counter values
  69 + C[0] ^= i0;
  70 + C[1] ^= i1;
  71 + C[2] ^= i2;
  72 + C[3] ^= i3;
  73 + C[4] ^= i0;
  74 + C[5] ^= i1;
  75 + C[6] ^= i2;
  76 + C[7] ^= i3;
  77 +
  78 + // Iterate the system four times
  79 + for (var i = 0; i < 4; i++) {
  80 + nextState.call(this);
  81 + }
  82 + }
  83 + },
  84 +
  85 + _doProcessBlock: function (M, offset) {
  86 + // Shortcut
  87 + var X = this._X;
  88 +
  89 + // Iterate the system
  90 + nextState.call(this);
  91 +
  92 + // Generate four keystream words
  93 + S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
  94 + S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
  95 + S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
  96 + S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
  97 +
  98 + for (var i = 0; i < 4; i++) {
  99 + // Swap endian
  100 + S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
  101 + (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
  102 +
  103 + // Encrypt
  104 + M[offset + i] ^= S[i];
  105 + }
  106 + },
  107 +
  108 + blockSize: 128/32,
  109 +
  110 + ivSize: 64/32
  111 + });
  112 +
  113 + function nextState() {
  114 + // Shortcuts
  115 + var X = this._X;
  116 + var C = this._C;
  117 +
  118 + // Save old counter values
  119 + for (var i = 0; i < 8; i++) {
  120 + C_[i] = C[i];
  121 + }
  122 +
  123 + // Calculate new counter values
  124 + C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
  125 + C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
  126 + C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
  127 + C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
  128 + C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
  129 + C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
  130 + C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
  131 + C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
  132 + this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
  133 +
  134 + // Calculate the g-values
  135 + for (var i = 0; i < 8; i++) {
  136 + var gx = X[i] + C[i];
  137 +
  138 + // Construct high and low argument for squaring
  139 + var ga = gx & 0xffff;
  140 + var gb = gx >>> 16;
  141 +
  142 + // Calculate high and low result of squaring
  143 + var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
  144 + var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
  145 +
  146 + // High XOR low
  147 + G[i] = gh ^ gl;
  148 + }
  149 +
  150 + // Calculate new state values
  151 + X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
  152 + X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
  153 + X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
  154 + X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
  155 + X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
  156 + X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
  157 + X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
  158 + X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
  159 + }
  160 +
  161 + /**
  162 + * Shortcut functions to the cipher's object interface.
  163 + *
  164 + * @example
  165 + *
  166 + * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg);
  167 + * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg);
  168 + */
  169 + C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy);
  170 +}());
  1 +(function () {
  2 + // Shortcuts
  3 + var C = CryptoJS;
  4 + var C_lib = C.lib;
  5 + var StreamCipher = C_lib.StreamCipher;
  6 + var C_algo = C.algo;
  7 +
  8 + // Reusable objects
  9 + var S = [];
  10 + var C_ = [];
  11 + var G = [];
  12 +
  13 + /**
  14 + * Rabbit stream cipher algorithm
  15 + */
  16 + var Rabbit = C_algo.Rabbit = StreamCipher.extend({
  17 + _doReset: function () {
  18 + // Shortcuts
  19 + var K = this._key.words;
  20 + var iv = this.cfg.iv;
  21 +
  22 + // Swap endian
  23 + for (var i = 0; i < 4; i++) {
  24 + K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) |
  25 + (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00);
  26 + }
  27 +
  28 + // Generate initial state values
  29 + var X = this._X = [
  30 + K[0], (K[3] << 16) | (K[2] >>> 16),
  31 + K[1], (K[0] << 16) | (K[3] >>> 16),
  32 + K[2], (K[1] << 16) | (K[0] >>> 16),
  33 + K[3], (K[2] << 16) | (K[1] >>> 16)
  34 + ];
  35 +
  36 + // Generate initial counter values
  37 + var C = this._C = [
  38 + (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
  39 + (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
  40 + (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
  41 + (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)
  42 + ];
  43 +
  44 + // Carry bit
  45 + this._b = 0;
  46 +
  47 + // Iterate the system four times
  48 + for (var i = 0; i < 4; i++) {
  49 + nextState.call(this);
  50 + }
  51 +
  52 + // Modify the counters
  53 + for (var i = 0; i < 8; i++) {
  54 + C[i] ^= X[(i + 4) & 7];
  55 + }
  56 +
  57 + // IV setup
  58 + if (iv) {
  59 + // Shortcuts
  60 + var IV = iv.words;
  61 + var IV_0 = IV[0];
  62 + var IV_1 = IV[1];
  63 +
  64 + // Generate four subvectors
  65 + var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
  66 + var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
  67 + var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
  68 + var i3 = (i2 << 16) | (i0 & 0x0000ffff);
  69 +
  70 + // Modify counter values
  71 + C[0] ^= i0;
  72 + C[1] ^= i1;
  73 + C[2] ^= i2;
  74 + C[3] ^= i3;
  75 + C[4] ^= i0;
  76 + C[5] ^= i1;
  77 + C[6] ^= i2;
  78 + C[7] ^= i3;
  79 +
  80 + // Iterate the system four times
  81 + for (var i = 0; i < 4; i++) {
  82 + nextState.call(this);
  83 + }
  84 + }
  85 + },
  86 +
  87 + _doProcessBlock: function (M, offset) {
  88 + // Shortcut
  89 + var X = this._X;
  90 +
  91 + // Iterate the system
  92 + nextState.call(this);
  93 +
  94 + // Generate four keystream words
  95 + S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
  96 + S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
  97 + S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
  98 + S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
  99 +
  100 + for (var i = 0; i < 4; i++) {
  101 + // Swap endian
  102 + S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
  103 + (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
  104 +
  105 + // Encrypt
  106 + M[offset + i] ^= S[i];
  107 + }
  108 + },
  109 +
  110 + blockSize: 128/32,
  111 +
  112 + ivSize: 64/32
  113 + });
  114 +
  115 + function nextState() {
  116 + // Shortcuts
  117 + var X = this._X;
  118 + var C = this._C;
  119 +
  120 + // Save old counter values
  121 + for (var i = 0; i < 8; i++) {
  122 + C_[i] = C[i];
  123 + }
  124 +
  125 + // Calculate new counter values
  126 + C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
  127 + C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
  128 + C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
  129 + C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
  130 + C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
  131 + C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
  132 + C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
  133 + C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
  134 + this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
  135 +
  136 + // Calculate the g-values
  137 + for (var i = 0; i < 8; i++) {
  138 + var gx = X[i] + C[i];
  139 +
  140 + // Construct high and low argument for squaring
  141 + var ga = gx & 0xffff;
  142 + var gb = gx >>> 16;
  143 +
  144 + // Calculate high and low result of squaring
  145 + var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
  146 + var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
  147 +
  148 + // High XOR low
  149 + G[i] = gh ^ gl;
  150 + }
  151 +
  152 + // Calculate new state values
  153 + X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
  154 + X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
  155 + X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
  156 + X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
  157 + X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
  158 + X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
  159 + X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
  160 + X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
  161 + }
  162 +
  163 + /**
  164 + * Shortcut functions to the cipher's object interface.
  165 + *
  166 + * @example
  167 + *
  168 + * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg);
  169 + * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg);
  170 + */
  171 + C.Rabbit = StreamCipher._createHelper(Rabbit);
  172 +}());
  1 +(function () {
  2 + // Shortcuts
  3 + var C = CryptoJS;
  4 + var C_lib = C.lib;
  5 + var StreamCipher = C_lib.StreamCipher;
  6 + var C_algo = C.algo;
  7 +
  8 + /**
  9 + * RC4 stream cipher algorithm.
  10 + */
  11 + var RC4 = C_algo.RC4 = StreamCipher.extend({
  12 + _doReset: function () {
  13 + // Shortcuts
  14 + var key = this._key;
  15 + var keyWords = key.words;
  16 + var keySigBytes = key.sigBytes;
  17 +
  18 + // Init sbox
  19 + var S = this._S = [];
  20 + for (var i = 0; i < 256; i++) {
  21 + S[i] = i;
  22 + }
  23 +
  24 + // Key setup
  25 + for (var i = 0, j = 0; i < 256; i++) {
  26 + var keyByteIndex = i % keySigBytes;
  27 + var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff;
  28 +
  29 + j = (j + S[i] + keyByte) % 256;
  30 +
  31 + // Swap
  32 + var t = S[i];
  33 + S[i] = S[j];
  34 + S[j] = t;
  35 + }
  36 +
  37 + // Counters
  38 + this._i = this._j = 0;
  39 + },
  40 +
  41 + _doProcessBlock: function (M, offset) {
  42 + M[offset] ^= generateKeystreamWord.call(this);
  43 + },
  44 +
  45 + keySize: 256/32,
  46 +
  47 + ivSize: 0
  48 + });
  49 +
  50 + function generateKeystreamWord() {
  51 + // Shortcuts
  52 + var S = this._S;
  53 + var i = this._i;
  54 + var j = this._j;
  55 +
  56 + // Generate keystream word
  57 + var keystreamWord = 0;
  58 + for (var n = 0; n < 4; n++) {
  59 + i = (i + 1) % 256;
  60 + j = (j + S[i]) % 256;
  61 +
  62 + // Swap
  63 + var t = S[i];
  64 + S[i] = S[j];
  65 + S[j] = t;
  66 +
  67 + keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8);
  68 + }
  69 +
  70 + // Update counters
  71 + this._i = i;
  72 + this._j = j;
  73 +
  74 + return keystreamWord;
  75 + }
  76 +
  77 + /**
  78 + * Shortcut functions to the cipher's object interface.
  79 + *
  80 + * @example
  81 + *
  82 + * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg);
  83 + * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg);
  84 + */
  85 + C.RC4 = StreamCipher._createHelper(RC4);
  86 +
  87 + /**
  88 + * Modified RC4 stream cipher algorithm.
  89 + */
  90 + var RC4Drop = C_algo.RC4Drop = RC4.extend({
  91 + /**
  92 + * Configuration options.
  93 + *
  94 + * @property {number} drop The number of keystream words to drop. Default 192
  95 + */
  96 + cfg: RC4.cfg.extend({
  97 + drop: 192
  98 + }),
  99 +
  100 + _doReset: function () {
  101 + RC4._doReset.call(this);
  102 +
  103 + // Drop
  104 + for (var i = this.cfg.drop; i > 0; i--) {
  105 + generateKeystreamWord.call(this);
  106 + }
  107 + }
  108 + });
  109 +
  110 + /**
  111 + * Shortcut functions to the cipher's object interface.
  112 + *
  113 + * @example
  114 + *
  115 + * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg);
  116 + * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg);
  117 + */
  118 + C.RC4Drop = StreamCipher._createHelper(RC4Drop);
  119 +}());
  1 +/** @preserve
  2 +(c) 2012 by Cédric Mesnil. All rights reserved.
  3 +
  4 +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  5 +
  6 + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  7 + - 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.
  8 +
  9 +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.
  10 +*/
  11 +
  12 +(function (Math) {
  13 + // Shortcuts
  14 + var C = CryptoJS;
  15 + var C_lib = C.lib;
  16 + var WordArray = C_lib.WordArray;
  17 + var Hasher = C_lib.Hasher;
  18 + var C_algo = C.algo;
  19 +
  20 + // Constants table
  21 + var _zl = WordArray.create([
  22 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  23 + 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
  24 + 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
  25 + 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
  26 + 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]);
  27 + var _zr = WordArray.create([
  28 + 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
  29 + 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
  30 + 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
  31 + 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
  32 + 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]);
  33 + var _sl = WordArray.create([
  34 + 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
  35 + 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
  36 + 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
  37 + 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
  38 + 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]);
  39 + var _sr = WordArray.create([
  40 + 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
  41 + 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
  42 + 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
  43 + 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
  44 + 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]);
  45 +
  46 + var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]);
  47 + var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]);
  48 +
  49 + /**
  50 + * RIPEMD160 hash algorithm.
  51 + */
  52 + var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({
  53 + _doReset: function () {
  54 + this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]);
  55 + },
  56 +
  57 + _doProcessBlock: function (M, offset) {
  58 +
  59 + // Swap endian
  60 + for (var i = 0; i < 16; i++) {
  61 + // Shortcuts
  62 + var offset_i = offset + i;
  63 + var M_offset_i = M[offset_i];
  64 +
  65 + // Swap
  66 + M[offset_i] = (
  67 + (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  68 + (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  69 + );
  70 + }
  71 + // Shortcut
  72 + var H = this._hash.words;
  73 + var hl = _hl.words;
  74 + var hr = _hr.words;
  75 + var zl = _zl.words;
  76 + var zr = _zr.words;
  77 + var sl = _sl.words;
  78 + var sr = _sr.words;
  79 +
  80 + // Working variables
  81 + var al, bl, cl, dl, el;
  82 + var ar, br, cr, dr, er;
  83 +
  84 + ar = al = H[0];
  85 + br = bl = H[1];
  86 + cr = cl = H[2];
  87 + dr = dl = H[3];
  88 + er = el = H[4];
  89 + // Computation
  90 + var t;
  91 + for (var i = 0; i < 80; i += 1) {
  92 + t = (al + M[offset+zl[i]])|0;
  93 + if (i<16){
  94 + t += f1(bl,cl,dl) + hl[0];
  95 + } else if (i<32) {
  96 + t += f2(bl,cl,dl) + hl[1];
  97 + } else if (i<48) {
  98 + t += f3(bl,cl,dl) + hl[2];
  99 + } else if (i<64) {
  100 + t += f4(bl,cl,dl) + hl[3];
  101 + } else {// if (i<80) {
  102 + t += f5(bl,cl,dl) + hl[4];
  103 + }
  104 + t = t|0;
  105 + t = rotl(t,sl[i]);
  106 + t = (t+el)|0;
  107 + al = el;
  108 + el = dl;
  109 + dl = rotl(cl, 10);
  110 + cl = bl;
  111 + bl = t;
  112 +
  113 + t = (ar + M[offset+zr[i]])|0;
  114 + if (i<16){
  115 + t += f5(br,cr,dr) + hr[0];
  116 + } else if (i<32) {
  117 + t += f4(br,cr,dr) + hr[1];
  118 + } else if (i<48) {
  119 + t += f3(br,cr,dr) + hr[2];
  120 + } else if (i<64) {
  121 + t += f2(br,cr,dr) + hr[3];
  122 + } else {// if (i<80) {
  123 + t += f1(br,cr,dr) + hr[4];
  124 + }
  125 + t = t|0;
  126 + t = rotl(t,sr[i]) ;
  127 + t = (t+er)|0;
  128 + ar = er;
  129 + er = dr;
  130 + dr = rotl(cr, 10);
  131 + cr = br;
  132 + br = t;
  133 + }
  134 + // Intermediate hash value
  135 + t = (H[1] + cl + dr)|0;
  136 + H[1] = (H[2] + dl + er)|0;
  137 + H[2] = (H[3] + el + ar)|0;
  138 + H[3] = (H[4] + al + br)|0;
  139 + H[4] = (H[0] + bl + cr)|0;
  140 + H[0] = t;
  141 + },
  142 +
  143 + _doFinalize: function () {
  144 + // Shortcuts
  145 + var data = this._data;
  146 + var dataWords = data.words;
  147 +
  148 + var nBitsTotal = this._nDataBytes * 8;
  149 + var nBitsLeft = data.sigBytes * 8;
  150 +
  151 + // Add padding
  152 + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  153 + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  154 + (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) |
  155 + (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00)
  156 + );
  157 + data.sigBytes = (dataWords.length + 1) * 4;
  158 +
  159 + // Hash final blocks
  160 + this._process();
  161 +
  162 + // Shortcuts
  163 + var hash = this._hash;
  164 + var H = hash.words;
  165 +
  166 + // Swap endian
  167 + for (var i = 0; i < 5; i++) {
  168 + // Shortcut
  169 + var H_i = H[i];
  170 +
  171 + // Swap
  172 + H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  173 + (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
  174 + }
  175 +
  176 + // Return final computed hash
  177 + return hash;
  178 + },
  179 +
  180 + clone: function () {
  181 + var clone = Hasher.clone.call(this);
  182 + clone._hash = this._hash.clone();
  183 +
  184 + return clone;
  185 + }
  186 + });
  187 +
  188 +
  189 + function f1(x, y, z) {
  190 + return ((x) ^ (y) ^ (z));
  191 +
  192 + }
  193 +
  194 + function f2(x, y, z) {
  195 + return (((x)&(y)) | ((~x)&(z)));
  196 + }
  197 +
  198 + function f3(x, y, z) {
  199 + return (((x) | (~(y))) ^ (z));
  200 + }
  201 +
  202 + function f4(x, y, z) {
  203 + return (((x) & (z)) | ((y)&(~(z))));
  204 + }
  205 +
  206 + function f5(x, y, z) {
  207 + return ((x) ^ ((y) |(~(z))));
  208 +
  209 + }
  210 +
  211 + function rotl(x,n) {
  212 + return (x<<n) | (x>>>(32-n));
  213 + }
  214 +
  215 +
  216 + /**
  217 + * Shortcut function to the hasher's object interface.
  218 + *
  219 + * @param {WordArray|string} message The message to hash.
  220 + *
  221 + * @return {WordArray} The hash.
  222 + *
  223 + * @static
  224 + *
  225 + * @example
  226 + *
  227 + * var hash = CryptoJS.RIPEMD160('message');
  228 + * var hash = CryptoJS.RIPEMD160(wordArray);
  229 + */
  230 + C.RIPEMD160 = Hasher._createHelper(RIPEMD160);
  231 +
  232 + /**
  233 + * Shortcut function to the HMAC's object interface.
  234 + *
  235 + * @param {WordArray|string} message The message to hash.
  236 + * @param {WordArray|string} key The secret key.
  237 + *
  238 + * @return {WordArray} The HMAC.
  239 + *
  240 + * @static
  241 + *
  242 + * @example
  243 + *
  244 + * var hmac = CryptoJS.HmacRIPEMD160(message, key);
  245 + */
  246 + C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160);
  247 +}(Math));
  1 +(function () {
  2 + // Shortcuts
  3 + var C = CryptoJS;
  4 + var C_lib = C.lib;
  5 + var WordArray = C_lib.WordArray;
  6 + var Hasher = C_lib.Hasher;
  7 + var C_algo = C.algo;
  8 +
  9 + // Reusable object
  10 + var W = [];
  11 +
  12 + /**
  13 + * SHA-1 hash algorithm.
  14 + */
  15 + var SHA1 = C_algo.SHA1 = Hasher.extend({
  16 + _doReset: function () {
  17 + this._hash = new WordArray.init([
  18 + 0x67452301, 0xefcdab89,
  19 + 0x98badcfe, 0x10325476,
  20 + 0xc3d2e1f0
  21 + ]);
  22 + },
  23 +
  24 + _doProcessBlock: function (M, offset) {
  25 + // Shortcut
  26 + var H = this._hash.words;
  27 +
  28 + // Working variables
  29 + var a = H[0];
  30 + var b = H[1];
  31 + var c = H[2];
  32 + var d = H[3];
  33 + var e = H[4];
  34 +
  35 + // Computation
  36 + for (var i = 0; i < 80; i++) {
  37 + if (i < 16) {
  38 + W[i] = M[offset + i] | 0;
  39 + } else {
  40 + var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
  41 + W[i] = (n << 1) | (n >>> 31);
  42 + }
  43 +
  44 + var t = ((a << 5) | (a >>> 27)) + e + W[i];
  45 + if (i < 20) {
  46 + t += ((b & c) | (~b & d)) + 0x5a827999;
  47 + } else if (i < 40) {
  48 + t += (b ^ c ^ d) + 0x6ed9eba1;
  49 + } else if (i < 60) {
  50 + t += ((b & c) | (b & d) | (c & d)) - 0x70e44324;
  51 + } else /* if (i < 80) */ {
  52 + t += (b ^ c ^ d) - 0x359d3e2a;
  53 + }
  54 +
  55 + e = d;
  56 + d = c;
  57 + c = (b << 30) | (b >>> 2);
  58 + b = a;
  59 + a = t;
  60 + }
  61 +
  62 + // Intermediate hash value
  63 + H[0] = (H[0] + a) | 0;
  64 + H[1] = (H[1] + b) | 0;
  65 + H[2] = (H[2] + c) | 0;
  66 + H[3] = (H[3] + d) | 0;
  67 + H[4] = (H[4] + e) | 0;
  68 + },
  69 +
  70 + _doFinalize: function () {
  71 + // Shortcuts
  72 + var data = this._data;
  73 + var dataWords = data.words;
  74 +
  75 + var nBitsTotal = this._nDataBytes * 8;
  76 + var nBitsLeft = data.sigBytes * 8;
  77 +
  78 + // Add padding
  79 + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  80 + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
  81 + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  82 + data.sigBytes = dataWords.length * 4;
  83 +
  84 + // Hash final blocks
  85 + this._process();
  86 +
  87 + // Return final computed hash
  88 + return this._hash;
  89 + },
  90 +
  91 + clone: function () {
  92 + var clone = Hasher.clone.call(this);
  93 + clone._hash = this._hash.clone();
  94 +
  95 + return clone;
  96 + }
  97 + });
  98 +
  99 + /**
  100 + * Shortcut function to the hasher's object interface.
  101 + *
  102 + * @param {WordArray|string} message The message to hash.
  103 + *
  104 + * @return {WordArray} The hash.
  105 + *
  106 + * @static
  107 + *
  108 + * @example
  109 + *
  110 + * var hash = CryptoJS.SHA1('message');
  111 + * var hash = CryptoJS.SHA1(wordArray);
  112 + */
  113 + C.SHA1 = Hasher._createHelper(SHA1);
  114 +
  115 + /**
  116 + * Shortcut function to the HMAC's object interface.
  117 + *
  118 + * @param {WordArray|string} message The message to hash.
  119 + * @param {WordArray|string} key The secret key.
  120 + *
  121 + * @return {WordArray} The HMAC.
  122 + *
  123 + * @static
  124 + *
  125 + * @example
  126 + *
  127 + * var hmac = CryptoJS.HmacSHA1(message, key);
  128 + */
  129 + C.HmacSHA1 = Hasher._createHmacHelper(SHA1);
  130 +}());
  1 +(function () {
  2 + // Shortcuts
  3 + var C = CryptoJS;
  4 + var C_lib = C.lib;
  5 + var WordArray = C_lib.WordArray;
  6 + var C_algo = C.algo;
  7 + var SHA256 = C_algo.SHA256;
  8 +
  9 + /**
  10 + * SHA-224 hash algorithm.
  11 + */
  12 + var SHA224 = C_algo.SHA224 = SHA256.extend({
  13 + _doReset: function () {
  14 + this._hash = new WordArray.init([
  15 + 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
  16 + 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
  17 + ]);
  18 + },
  19 +
  20 + _doFinalize: function () {
  21 + var hash = SHA256._doFinalize.call(this);
  22 +
  23 + hash.sigBytes -= 4;
  24 +
  25 + return hash;
  26 + }
  27 + });
  28 +
  29 + /**
  30 + * Shortcut function to the hasher's object interface.
  31 + *
  32 + * @param {WordArray|string} message The message to hash.
  33 + *
  34 + * @return {WordArray} The hash.
  35 + *
  36 + * @static
  37 + *
  38 + * @example
  39 + *
  40 + * var hash = CryptoJS.SHA224('message');
  41 + * var hash = CryptoJS.SHA224(wordArray);
  42 + */
  43 + C.SHA224 = SHA256._createHelper(SHA224);
  44 +
  45 + /**
  46 + * Shortcut function to the HMAC's object interface.
  47 + *
  48 + * @param {WordArray|string} message The message to hash.
  49 + * @param {WordArray|string} key The secret key.
  50 + *
  51 + * @return {WordArray} The HMAC.
  52 + *
  53 + * @static
  54 + *
  55 + * @example
  56 + *
  57 + * var hmac = CryptoJS.HmacSHA224(message, key);
  58 + */
  59 + C.HmacSHA224 = SHA256._createHmacHelper(SHA224);
  60 +}());
  1 +(function (Math) {
  2 + // Shortcuts
  3 + var C = CryptoJS;
  4 + var C_lib = C.lib;
  5 + var WordArray = C_lib.WordArray;
  6 + var Hasher = C_lib.Hasher;
  7 + var C_algo = C.algo;
  8 +
  9 + // Initialization and round constants tables
  10 + var H = [];
  11 + var K = [];
  12 +
  13 + // Compute constants
  14 + (function () {
  15 + function isPrime(n) {
  16 + var sqrtN = Math.sqrt(n);
  17 + for (var factor = 2; factor <= sqrtN; factor++) {
  18 + if (!(n % factor)) {
  19 + return false;
  20 + }
  21 + }
  22 +
  23 + return true;
  24 + }
  25 +
  26 + function getFractionalBits(n) {
  27 + return ((n - (n | 0)) * 0x100000000) | 0;
  28 + }
  29 +
  30 + var n = 2;
  31 + var nPrime = 0;
  32 + while (nPrime < 64) {
  33 + if (isPrime(n)) {
  34 + if (nPrime < 8) {
  35 + H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2));
  36 + }
  37 + K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3));
  38 +
  39 + nPrime++;
  40 + }
  41 +
  42 + n++;
  43 + }
  44 + }());
  45 +
  46 + // Reusable object
  47 + var W = [];
  48 +
  49 + /**
  50 + * SHA-256 hash algorithm.
  51 + */
  52 + var SHA256 = C_algo.SHA256 = Hasher.extend({
  53 + _doReset: function () {
  54 + this._hash = new WordArray.init(H.slice(0));
  55 + },
  56 +
  57 + _doProcessBlock: function (M, offset) {
  58 + // Shortcut
  59 + var H = this._hash.words;
  60 +
  61 + // Working variables
  62 + var a = H[0];
  63 + var b = H[1];
  64 + var c = H[2];
  65 + var d = H[3];
  66 + var e = H[4];
  67 + var f = H[5];
  68 + var g = H[6];
  69 + var h = H[7];
  70 +
  71 + // Computation
  72 + for (var i = 0; i < 64; i++) {
  73 + if (i < 16) {
  74 + W[i] = M[offset + i] | 0;
  75 + } else {
  76 + var gamma0x = W[i - 15];
  77 + var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^
  78 + ((gamma0x << 14) | (gamma0x >>> 18)) ^
  79 + (gamma0x >>> 3);
  80 +
  81 + var gamma1x = W[i - 2];
  82 + var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^
  83 + ((gamma1x << 13) | (gamma1x >>> 19)) ^
  84 + (gamma1x >>> 10);
  85 +
  86 + W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
  87 + }
  88 +
  89 + var ch = (e & f) ^ (~e & g);
  90 + var maj = (a & b) ^ (a & c) ^ (b & c);
  91 +
  92 + var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22));
  93 + var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25));
  94 +
  95 + var t1 = h + sigma1 + ch + K[i] + W[i];
  96 + var t2 = sigma0 + maj;
  97 +
  98 + h = g;
  99 + g = f;
  100 + f = e;
  101 + e = (d + t1) | 0;
  102 + d = c;
  103 + c = b;
  104 + b = a;
  105 + a = (t1 + t2) | 0;
  106 + }
  107 +
  108 + // Intermediate hash value
  109 + H[0] = (H[0] + a) | 0;
  110 + H[1] = (H[1] + b) | 0;
  111 + H[2] = (H[2] + c) | 0;
  112 + H[3] = (H[3] + d) | 0;
  113 + H[4] = (H[4] + e) | 0;
  114 + H[5] = (H[5] + f) | 0;
  115 + H[6] = (H[6] + g) | 0;
  116 + H[7] = (H[7] + h) | 0;
  117 + },
  118 +
  119 + _doFinalize: function () {
  120 + // Shortcuts
  121 + var data = this._data;
  122 + var dataWords = data.words;
  123 +
  124 + var nBitsTotal = this._nDataBytes * 8;
  125 + var nBitsLeft = data.sigBytes * 8;
  126 +
  127 + // Add padding
  128 + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  129 + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
  130 + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  131 + data.sigBytes = dataWords.length * 4;
  132 +
  133 + // Hash final blocks
  134 + this._process();
  135 +
  136 + // Return final computed hash
  137 + return this._hash;
  138 + },
  139 +
  140 + clone: function () {
  141 + var clone = Hasher.clone.call(this);
  142 + clone._hash = this._hash.clone();
  143 +
  144 + return clone;
  145 + }
  146 + });
  147 +
  148 + /**
  149 + * Shortcut function to the hasher's object interface.
  150 + *
  151 + * @param {WordArray|string} message The message to hash.
  152 + *
  153 + * @return {WordArray} The hash.
  154 + *
  155 + * @static
  156 + *
  157 + * @example
  158 + *
  159 + * var hash = CryptoJS.SHA256('message');
  160 + * var hash = CryptoJS.SHA256(wordArray);
  161 + */
  162 + C.SHA256 = Hasher._createHelper(SHA256);
  163 +
  164 + /**
  165 + * Shortcut function to the HMAC's object interface.
  166 + *
  167 + * @param {WordArray|string} message The message to hash.
  168 + * @param {WordArray|string} key The secret key.
  169 + *
  170 + * @return {WordArray} The HMAC.
  171 + *
  172 + * @static
  173 + *
  174 + * @example
  175 + *
  176 + * var hmac = CryptoJS.HmacSHA256(message, key);
  177 + */
  178 + C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
  179 +}(Math));
  1 +(function (Math) {
  2 + // Shortcuts
  3 + var C = CryptoJS;
  4 + var C_lib = C.lib;
  5 + var WordArray = C_lib.WordArray;
  6 + var Hasher = C_lib.Hasher;
  7 + var C_x64 = C.x64;
  8 + var X64Word = C_x64.Word;
  9 + var C_algo = C.algo;
  10 +
  11 + // Constants tables
  12 + var RHO_OFFSETS = [];
  13 + var PI_INDEXES = [];
  14 + var ROUND_CONSTANTS = [];
  15 +
  16 + // Compute Constants
  17 + (function () {
  18 + // Compute rho offset constants
  19 + var x = 1, y = 0;
  20 + for (var t = 0; t < 24; t++) {
  21 + RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64;
  22 +
  23 + var newX = y % 5;
  24 + var newY = (2 * x + 3 * y) % 5;
  25 + x = newX;
  26 + y = newY;
  27 + }
  28 +
  29 + // Compute pi index constants
  30 + for (var x = 0; x < 5; x++) {
  31 + for (var y = 0; y < 5; y++) {
  32 + PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5;
  33 + }
  34 + }
  35 +
  36 + // Compute round constants
  37 + var LFSR = 0x01;
  38 + for (var i = 0; i < 24; i++) {
  39 + var roundConstantMsw = 0;
  40 + var roundConstantLsw = 0;
  41 +
  42 + for (var j = 0; j < 7; j++) {
  43 + if (LFSR & 0x01) {
  44 + var bitPosition = (1 << j) - 1;
  45 + if (bitPosition < 32) {
  46 + roundConstantLsw ^= 1 << bitPosition;
  47 + } else /* if (bitPosition >= 32) */ {
  48 + roundConstantMsw ^= 1 << (bitPosition - 32);
  49 + }
  50 + }
  51 +
  52 + // Compute next LFSR
  53 + if (LFSR & 0x80) {
  54 + // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1
  55 + LFSR = (LFSR << 1) ^ 0x71;
  56 + } else {
  57 + LFSR <<= 1;
  58 + }
  59 + }
  60 +
  61 + ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw);
  62 + }
  63 + }());
  64 +
  65 + // Reusable objects for temporary values
  66 + var T = [];
  67 + (function () {
  68 + for (var i = 0; i < 25; i++) {
  69 + T[i] = X64Word.create();
  70 + }
  71 + }());
  72 +
  73 + /**
  74 + * SHA-3 hash algorithm.
  75 + */
  76 + var SHA3 = C_algo.SHA3 = Hasher.extend({
  77 + /**
  78 + * Configuration options.
  79 + *
  80 + * @property {number} outputLength
  81 + * The desired number of bits in the output hash.
  82 + * Only values permitted are: 224, 256, 384, 512.
  83 + * Default: 512
  84 + */
  85 + cfg: Hasher.cfg.extend({
  86 + outputLength: 512
  87 + }),
  88 +
  89 + _doReset: function () {
  90 + var state = this._state = []
  91 + for (var i = 0; i < 25; i++) {
  92 + state[i] = new X64Word.init();
  93 + }
  94 +
  95 + this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32;
  96 + },
  97 +
  98 + _doProcessBlock: function (M, offset) {
  99 + // Shortcuts
  100 + var state = this._state;
  101 + var nBlockSizeLanes = this.blockSize / 2;
  102 +
  103 + // Absorb
  104 + for (var i = 0; i < nBlockSizeLanes; i++) {
  105 + // Shortcuts
  106 + var M2i = M[offset + 2 * i];
  107 + var M2i1 = M[offset + 2 * i + 1];
  108 +
  109 + // Swap endian
  110 + M2i = (
  111 + (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) |
  112 + (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00)
  113 + );
  114 + M2i1 = (
  115 + (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) |
  116 + (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00)
  117 + );
  118 +
  119 + // Absorb message into state
  120 + var lane = state[i];
  121 + lane.high ^= M2i1;
  122 + lane.low ^= M2i;
  123 + }
  124 +
  125 + // Rounds
  126 + for (var round = 0; round < 24; round++) {
  127 + // Theta
  128 + for (var x = 0; x < 5; x++) {
  129 + // Mix column lanes
  130 + var tMsw = 0, tLsw = 0;
  131 + for (var y = 0; y < 5; y++) {
  132 + var lane = state[x + 5 * y];
  133 + tMsw ^= lane.high;
  134 + tLsw ^= lane.low;
  135 + }
  136 +
  137 + // Temporary values
  138 + var Tx = T[x];
  139 + Tx.high = tMsw;
  140 + Tx.low = tLsw;
  141 + }
  142 + for (var x = 0; x < 5; x++) {
  143 + // Shortcuts
  144 + var Tx4 = T[(x + 4) % 5];
  145 + var Tx1 = T[(x + 1) % 5];
  146 + var Tx1Msw = Tx1.high;
  147 + var Tx1Lsw = Tx1.low;
  148 +
  149 + // Mix surrounding columns
  150 + var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31));
  151 + var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31));
  152 + for (var y = 0; y < 5; y++) {
  153 + var lane = state[x + 5 * y];
  154 + lane.high ^= tMsw;
  155 + lane.low ^= tLsw;
  156 + }
  157 + }
  158 +
  159 + // Rho Pi
  160 + for (var laneIndex = 1; laneIndex < 25; laneIndex++) {
  161 + var tMsw;
  162 + var tLsw;
  163 +
  164 + // Shortcuts
  165 + var lane = state[laneIndex];
  166 + var laneMsw = lane.high;
  167 + var laneLsw = lane.low;
  168 + var rhoOffset = RHO_OFFSETS[laneIndex];
  169 +
  170 + // Rotate lanes
  171 + if (rhoOffset < 32) {
  172 + tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset));
  173 + tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset));
  174 + } else /* if (rhoOffset >= 32) */ {
  175 + tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset));
  176 + tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset));
  177 + }
  178 +
  179 + // Transpose lanes
  180 + var TPiLane = T[PI_INDEXES[laneIndex]];
  181 + TPiLane.high = tMsw;
  182 + TPiLane.low = tLsw;
  183 + }
  184 +
  185 + // Rho pi at x = y = 0
  186 + var T0 = T[0];
  187 + var state0 = state[0];
  188 + T0.high = state0.high;
  189 + T0.low = state0.low;
  190 +
  191 + // Chi
  192 + for (var x = 0; x < 5; x++) {
  193 + for (var y = 0; y < 5; y++) {
  194 + // Shortcuts
  195 + var laneIndex = x + 5 * y;
  196 + var lane = state[laneIndex];
  197 + var TLane = T[laneIndex];
  198 + var Tx1Lane = T[((x + 1) % 5) + 5 * y];
  199 + var Tx2Lane = T[((x + 2) % 5) + 5 * y];
  200 +
  201 + // Mix rows
  202 + lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high);
  203 + lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low);
  204 + }
  205 + }
  206 +
  207 + // Iota
  208 + var lane = state[0];
  209 + var roundConstant = ROUND_CONSTANTS[round];
  210 + lane.high ^= roundConstant.high;
  211 + lane.low ^= roundConstant.low;
  212 + }
  213 + },
  214 +
  215 + _doFinalize: function () {
  216 + // Shortcuts
  217 + var data = this._data;
  218 + var dataWords = data.words;
  219 + var nBitsTotal = this._nDataBytes * 8;
  220 + var nBitsLeft = data.sigBytes * 8;
  221 + var blockSizeBits = this.blockSize * 32;
  222 +
  223 + // Add padding
  224 + dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32);
  225 + dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80;
  226 + data.sigBytes = dataWords.length * 4;
  227 +
  228 + // Hash final blocks
  229 + this._process();
  230 +
  231 + // Shortcuts
  232 + var state = this._state;
  233 + var outputLengthBytes = this.cfg.outputLength / 8;
  234 + var outputLengthLanes = outputLengthBytes / 8;
  235 +
  236 + // Squeeze
  237 + var hashWords = [];
  238 + for (var i = 0; i < outputLengthLanes; i++) {
  239 + // Shortcuts
  240 + var lane = state[i];
  241 + var laneMsw = lane.high;
  242 + var laneLsw = lane.low;
  243 +
  244 + // Swap endian
  245 + laneMsw = (
  246 + (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) |
  247 + (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00)
  248 + );
  249 + laneLsw = (
  250 + (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) |
  251 + (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00)
  252 + );
  253 +
  254 + // Squeeze state to retrieve hash
  255 + hashWords.push(laneLsw);
  256 + hashWords.push(laneMsw);
  257 + }
  258 +
  259 + // Return final computed hash
  260 + return new WordArray.init(hashWords, outputLengthBytes);
  261 + },
  262 +
  263 + clone: function () {
  264 + var clone = Hasher.clone.call(this);
  265 +
  266 + var state = clone._state = this._state.slice(0);
  267 + for (var i = 0; i < 25; i++) {
  268 + state[i] = state[i].clone();
  269 + }
  270 +
  271 + return clone;
  272 + }
  273 + });
  274 +
  275 + /**
  276 + * Shortcut function to the hasher's object interface.
  277 + *
  278 + * @param {WordArray|string} message The message to hash.
  279 + *
  280 + * @return {WordArray} The hash.
  281 + *
  282 + * @static
  283 + *
  284 + * @example
  285 + *
  286 + * var hash = CryptoJS.SHA3('message');
  287 + * var hash = CryptoJS.SHA3(wordArray);
  288 + */
  289 + C.SHA3 = Hasher._createHelper(SHA3);
  290 +
  291 + /**
  292 + * Shortcut function to the HMAC's object interface.
  293 + *
  294 + * @param {WordArray|string} message The message to hash.
  295 + * @param {WordArray|string} key The secret key.
  296 + *
  297 + * @return {WordArray} The HMAC.
  298 + *
  299 + * @static
  300 + *
  301 + * @example
  302 + *
  303 + * var hmac = CryptoJS.HmacSHA3(message, key);
  304 + */
  305 + C.HmacSHA3 = Hasher._createHmacHelper(SHA3);
  306 +}(Math));
  1 +(function () {
  2 + // Shortcuts
  3 + var C = CryptoJS;
  4 + var C_x64 = C.x64;
  5 + var X64Word = C_x64.Word;
  6 + var X64WordArray = C_x64.WordArray;
  7 + var C_algo = C.algo;
  8 + var SHA512 = C_algo.SHA512;
  9 +
  10 + /**
  11 + * SHA-384 hash algorithm.
  12 + */
  13 + var SHA384 = C_algo.SHA384 = SHA512.extend({
  14 + _doReset: function () {
  15 + this._hash = new X64WordArray.init([
  16 + new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507),
  17 + new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939),
  18 + new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511),
  19 + new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4)
  20 + ]);
  21 + },
  22 +
  23 + _doFinalize: function () {
  24 + var hash = SHA512._doFinalize.call(this);
  25 +
  26 + hash.sigBytes -= 16;
  27 +
  28 + return hash;
  29 + }
  30 + });
  31 +
  32 + /**
  33 + * Shortcut function to the hasher's object interface.
  34 + *
  35 + * @param {WordArray|string} message The message to hash.
  36 + *
  37 + * @return {WordArray} The hash.
  38 + *
  39 + * @static
  40 + *
  41 + * @example
  42 + *
  43 + * var hash = CryptoJS.SHA384('message');
  44 + * var hash = CryptoJS.SHA384(wordArray);
  45 + */
  46 + C.SHA384 = SHA512._createHelper(SHA384);
  47 +
  48 + /**
  49 + * Shortcut function to the HMAC's object interface.
  50 + *
  51 + * @param {WordArray|string} message The message to hash.
  52 + * @param {WordArray|string} key The secret key.
  53 + *
  54 + * @return {WordArray} The HMAC.
  55 + *
  56 + * @static
  57 + *
  58 + * @example
  59 + *
  60 + * var hmac = CryptoJS.HmacSHA384(message, key);
  61 + */
  62 + C.HmacSHA384 = SHA512._createHmacHelper(SHA384);
  63 +}());