diff --git a/.jshintrc b/.jshintrc index ae02577..7672d3a 100644 --- a/.jshintrc +++ b/.jshintrc @@ -10,7 +10,24 @@ "strict" : false, // Requires all functions to run in ECMAScript 5's strict mode "undef" : true, // Require non-global variables to be declared (prevents global leaks) "asi" : true, // Suppresses warnings about missing semicolons + "funcscope" : false, + "shadow" : true, + "expr" : true, + "-W041" : true, + "-W018" : true, "globals": { - "CryptoJS": true + "CryptoJS" : true, + "escape" : true, + "unescape" : true, + "Int8Array" : true, + "Int16Array" : true, + "Int32Array" : true, + "Uint8Array" : true, + "Uint16Array" : true, + "Uint32Array" : true, + "Uint8ClampedArray" : true, + "ArrayBuffer" : true, + "Float32Array" : true, + "Float64Array" : true } } diff --git a/Gruntfile.js b/Gruntfile.js index 9f67b00..e083f92 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -29,6 +29,8 @@ module.exports = function (grunt) { } } }); + + // Will load the custom tasks grunt.loadTasks('./grunt/tasks'); diff --git a/grunt/config/jshint.js b/grunt/config/jshint.js index 7c83ee1..1c3cb23 100644 --- a/grunt/config/jshint.js +++ b/grunt/config/jshint.js @@ -5,7 +5,7 @@ module.exports = { dev: { options: { - jshintrc: true, + jshintrc: process.cwd() + '/.jshintrc', reporterOutput: '' }, files: { diff --git a/src/aes.js b/src/aes.js index aaf6e92..2d033c0 100644 --- a/src/aes.js +++ b/src/aes.js @@ -76,6 +76,8 @@ */ var AES = C_algo.AES = BlockCipher.extend({ _doReset: function () { + var t; + // Skip reset of nRounds has been set before and key did not change if (this._nRounds && this._keyPriorReset === this._key) { return; @@ -98,7 +100,7 @@ if (ksRow < keySize) { keySchedule[ksRow] = keyWords[ksRow]; } else { - var t = keySchedule[ksRow - 1]; + t = keySchedule[ksRow - 1]; if (!(ksRow % keySize)) { // Rot word diff --git a/src/cipher-core.js b/src/cipher-core.js index 85ba200..0fe6136 100644 --- a/src/cipher-core.js +++ b/src/cipher-core.js @@ -336,17 +336,19 @@ CryptoJS.lib.Cipher || (function (undefined) { }); function xorBlock(words, offset, blockSize) { + var block; + // Shortcut var iv = this._iv; // Choose mixing block if (iv) { - var block = iv; + block = iv; // Remove IV for subsequent blocks this._iv = undefined; } else { - var block = this._prevBlock; + block = this._prevBlock; } // XOR blocks @@ -438,6 +440,8 @@ CryptoJS.lib.Cipher || (function (undefined) { }), reset: function () { + var modeCreator; + // Reset cipher Cipher.reset.call(this); @@ -448,9 +452,9 @@ CryptoJS.lib.Cipher || (function (undefined) { // Reset block mode if (this._xformMode == this._ENC_XFORM_MODE) { - var modeCreator = mode.createEncryptor; + modeCreator = mode.createEncryptor; } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { - var modeCreator = mode.createDecryptor; + modeCreator = mode.createDecryptor; // Keep at least one block in the buffer for unpadding this._minBufferSize = 1; } @@ -468,6 +472,8 @@ CryptoJS.lib.Cipher || (function (undefined) { }, _doFinalize: function () { + var finalProcessedBlocks; + // Shortcut var padding = this.cfg.padding; @@ -477,10 +483,10 @@ CryptoJS.lib.Cipher || (function (undefined) { padding.pad(this._data, this.blockSize); // Process final blocks - var finalProcessedBlocks = this._process(!!'flush'); + finalProcessedBlocks = this._process(!!'flush'); } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { // Process final blocks - var finalProcessedBlocks = this._process(!!'flush'); + finalProcessedBlocks = this._process(!!'flush'); // Unpad data padding.unpad(finalProcessedBlocks); @@ -572,15 +578,17 @@ CryptoJS.lib.Cipher || (function (undefined) { * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); */ stringify: function (cipherParams) { + var wordArray; + // Shortcuts var ciphertext = cipherParams.ciphertext; var salt = cipherParams.salt; // Format if (salt) { - var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext); + wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext); } else { - var wordArray = ciphertext; + wordArray = ciphertext; } return wordArray.toString(Base64); @@ -600,6 +608,8 @@ CryptoJS.lib.Cipher || (function (undefined) { * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); */ parse: function (openSSLStr) { + var salt; + // Parse base64 var ciphertext = Base64.parse(openSSLStr); @@ -609,7 +619,7 @@ CryptoJS.lib.Cipher || (function (undefined) { // Test for salt if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) { // Extract salt - var salt = WordArray.create(ciphertextWords.slice(2, 4)); + salt = WordArray.create(ciphertextWords.slice(2, 4)); // Remove salt from ciphertext ciphertextWords.splice(0, 4); diff --git a/src/core.js b/src/core.js index 8903bf8..fd95ea5 100644 --- a/src/core.js +++ b/src/core.js @@ -6,7 +6,7 @@ var CryptoJS = CryptoJS || (function (Math, undefined) { * Local polyfil of Object.create */ var create = Object.create || (function () { - function F() {}; + function F() {} return function (obj) { var subtype; @@ -289,7 +289,7 @@ var CryptoJS = CryptoJS || (function (Math, undefined) { random: function (nBytes) { var words = []; - var r = (function (m_w) { + var r = function (m_w) { var m_w = m_w; var m_z = 0x3ade68b1; var mask = 0xffffffff; @@ -300,9 +300,9 @@ var CryptoJS = CryptoJS || (function (Math, undefined) { var result = ((m_z << 0x10) + m_w) & mask; result /= 0x100000000; result += 0.5; - return result * (Math.random() > .5 ? 1 : -1); + return result * (Math.random() > 0.5 ? 1 : -1); } - }); + }; for (var i = 0, rcache; i < nBytes; i += 4) { var _r = r((rcache || Math.random()) * 0x100000000); @@ -539,6 +539,8 @@ var CryptoJS = CryptoJS || (function (Math, undefined) { * var processedData = bufferedBlockAlgorithm._process(!!'flush'); */ _process: function (doFlush) { + var processedWords; + // Shortcuts var data = this._data; var dataWords = data.words; @@ -571,7 +573,7 @@ var CryptoJS = CryptoJS || (function (Math, undefined) { } // Remove processed words - var processedWords = dataWords.splice(0, nWordsReady); + processedWords = dataWords.splice(0, nWordsReady); data.sigBytes -= nBytesReady; } diff --git a/src/evpkdf.js b/src/evpkdf.js index e0fe703..2bc993e 100644 --- a/src/evpkdf.js +++ b/src/evpkdf.js @@ -53,6 +53,8 @@ * var key = kdf.compute(password, salt); */ compute: function (password, salt) { + var block; + // Shortcut var cfg = this.cfg; @@ -72,7 +74,7 @@ if (block) { hasher.update(block); } - var block = hasher.update(password).finalize(salt); + block = hasher.update(password).finalize(salt); hasher.reset(); // Iterations diff --git a/src/mode-cfb.js b/src/mode-cfb.js index 8d8d449..e750620 100644 --- a/src/mode-cfb.js +++ b/src/mode-cfb.js @@ -34,17 +34,19 @@ CryptoJS.mode.CFB = (function () { }); function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { + var keystream; + // Shortcut var iv = this._iv; // Generate keystream if (iv) { - var keystream = iv.slice(0); + keystream = iv.slice(0); // Remove IV for subsequent blocks this._iv = undefined; } else { - var keystream = this._prevBlock; + keystream = this._prevBlock; } cipher.encryptBlock(keystream, 0); diff --git a/src/sha3.js b/src/sha3.js index 72ca230..9545fcd 100644 --- a/src/sha3.js +++ b/src/sha3.js @@ -158,6 +158,9 @@ // Rho Pi for (var laneIndex = 1; laneIndex < 25; laneIndex++) { + var tMsw; + var tLsw; + // Shortcuts var lane = state[laneIndex]; var laneMsw = lane.high; @@ -166,11 +169,11 @@ // Rotate lanes if (rhoOffset < 32) { - var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); - var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); + tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); + tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); } else /* if (rhoOffset >= 32) */ { - var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); - var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); + tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); + tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); } // Transpose lanes @@ -205,7 +208,7 @@ var lane = state[0]; var roundConstant = ROUND_CONSTANTS[round]; lane.high ^= roundConstant.high; - lane.low ^= roundConstant.low;; + lane.low ^= roundConstant.low; } }, diff --git a/src/sha512.js b/src/sha512.js index 8646322..2ca9991 100644 --- a/src/sha512.js +++ b/src/sha512.js @@ -127,13 +127,16 @@ // Rounds for (var i = 0; i < 80; i++) { + var Wil; + var Wih; + // Shortcut var Wi = W[i]; // Extend message if (i < 16) { - var Wih = Wi.high = M[offset + i * 2] | 0; - var Wil = Wi.low = M[offset + i * 2 + 1] | 0; + Wih = Wi.high = M[offset + i * 2] | 0; + Wil = Wi.low = M[offset + i * 2 + 1] | 0; } else { // Gamma0 var gamma0x = W[i - 15]; @@ -158,12 +161,12 @@ var Wi16h = Wi16.high; var Wi16l = Wi16.low; - var Wil = gamma0l + Wi7l; - var Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); - var Wil = Wil + gamma1l; - var Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); - var Wil = Wil + Wi16l; - var Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); + Wil = gamma0l + Wi7l; + Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); + Wil = Wil + gamma1l; + Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); + Wil = Wil + Wi16l; + Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); Wi.high = Wih; Wi.low = Wil;