Skip to content

Commit

Permalink
Pass jshint test.
Browse files Browse the repository at this point in the history
  • Loading branch information
evanvosberg committed Sep 13, 2018
1 parent 70f725b commit 89ce246
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 33 deletions.
19 changes: 18 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 2 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ module.exports = function (grunt) {
}
}
});



// Will load the custom tasks
grunt.loadTasks('./grunt/tasks');
Expand Down
2 changes: 1 addition & 1 deletion grunt/config/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module.exports = {
dev: {
options: {
jshintrc: true,
jshintrc: process.cwd() + '/.jshintrc',
reporterOutput: ''
},
files: {
Expand Down
4 changes: 3 additions & 1 deletion src/aes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
28 changes: 19 additions & 9 deletions src/cipher-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -438,6 +440,8 @@ CryptoJS.lib.Cipher || (function (undefined) {
}),

reset: function () {
var modeCreator;

// Reset cipher
Cipher.reset.call(this);

Expand All @@ -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;
}
Expand All @@ -468,6 +472,8 @@ CryptoJS.lib.Cipher || (function (undefined) {
},

_doFinalize: function () {
var finalProcessedBlocks;

// Shortcut
var padding = this.cfg.padding;

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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);
Expand Down
12 changes: 7 additions & 5 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion src/evpkdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
* var key = kdf.compute(password, salt);
*/
compute: function (password, salt) {
var block;

// Shortcut
var cfg = this.cfg;

Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/mode-cfb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 8 additions & 5 deletions src/sha3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
},

Expand Down
19 changes: 11 additions & 8 deletions src/sha512.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand Down

0 comments on commit 89ce246

Please sign in to comment.