Comparing version 3.3.0 to 4.0.0
@@ -94,2 +94,4 @@ ;(function (root, factory, undef) { | ||
_doReset: function () { | ||
var t; | ||
// Skip reset of nRounds has been set before and key did not change | ||
@@ -117,3 +119,3 @@ if (this._nRounds && this._keyPriorReset === this._key) { | ||
} else { | ||
var t = keySchedule[ksRow - 1]; | ||
t = keySchedule[ksRow - 1]; | ||
@@ -120,0 +122,0 @@ if (!(ksRow % keySize)) { |
{ | ||
"name": "crypto-js", | ||
"version": "3.3.0", | ||
"version": "4.0.0", | ||
"description": "JavaScript library of crypto standards.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -354,2 +354,4 @@ ;(function (root, factory, undef) { | ||
function xorBlock(words, offset, blockSize) { | ||
var block; | ||
// Shortcut | ||
@@ -360,3 +362,3 @@ var iv = this._iv; | ||
if (iv) { | ||
var block = iv; | ||
block = iv; | ||
@@ -366,3 +368,3 @@ // Remove IV for subsequent blocks | ||
} else { | ||
var block = this._prevBlock; | ||
block = this._prevBlock; | ||
} | ||
@@ -459,2 +461,4 @@ | ||
reset: function () { | ||
var modeCreator; | ||
// Reset cipher | ||
@@ -470,5 +474,5 @@ Cipher.reset.call(this); | ||
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 | ||
@@ -491,2 +495,4 @@ this._minBufferSize = 1; | ||
_doFinalize: function () { | ||
var finalProcessedBlocks; | ||
// Shortcut | ||
@@ -501,6 +507,6 @@ var padding = this.cfg.padding; | ||
// 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'); | ||
@@ -597,2 +603,4 @@ // Unpad data | ||
stringify: function (cipherParams) { | ||
var wordArray; | ||
// Shortcuts | ||
@@ -604,5 +612,5 @@ var ciphertext = cipherParams.ciphertext; | ||
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; | ||
} | ||
@@ -627,2 +635,4 @@ | ||
parse: function (openSSLStr) { | ||
var salt; | ||
// Parse base64 | ||
@@ -637,3 +647,3 @@ var ciphertext = Base64.parse(openSSLStr); | ||
// Extract salt | ||
var salt = WordArray.create(ciphertextWords.slice(2, 4)); | ||
salt = WordArray.create(ciphertextWords.slice(2, 4)); | ||
@@ -640,0 +650,0 @@ // Remove salt from ciphertext |
83
core.js
@@ -16,2 +16,4 @@ ;(function (root, factory) { | ||
/*globals window, global, require*/ | ||
/** | ||
@@ -21,7 +23,58 @@ * CryptoJS core components. | ||
var CryptoJS = CryptoJS || (function (Math, undefined) { | ||
var crypto; | ||
// Native crypto from window (Browser) | ||
if (typeof window !== 'undefined' && window.crypto) { | ||
crypto = window.crypto; | ||
} | ||
// Native (experimental IE 11) crypto from window (Browser) | ||
if (!crypto && typeof window !== 'undefined' && window.msCrypto) { | ||
crypto = window.msCrypto; | ||
} | ||
// Native crypto from global (NodeJS) | ||
if (!crypto && typeof global !== 'undefined' && global.crypto) { | ||
crypto = global.crypto; | ||
} | ||
// Native crypto import via require (NodeJS) | ||
if (!crypto && typeof require === 'function') { | ||
try { | ||
crypto = require('crypto'); | ||
} catch (err) {} | ||
} | ||
/* | ||
* Local polyfil of Object.create | ||
* Cryptographically secure pseudorandom number generator | ||
* | ||
* As Math.random() is cryptographically not safe to use | ||
*/ | ||
var cryptoSecureRandomInt = function () { | ||
if (crypto) { | ||
// Use getRandomValues method (Browser) | ||
if (typeof crypto.getRandomValues === 'function') { | ||
try { | ||
return crypto.getRandomValues(new Uint32Array(1))[0]; | ||
} catch (err) {} | ||
} | ||
// Use randomBytes method (NodeJS) | ||
if (typeof crypto.randomBytes === 'function') { | ||
try { | ||
return crypto.randomBytes(4).readInt32LE(); | ||
} catch (err) {} | ||
} | ||
} | ||
throw new Error('Native crypto module could not be used to get secure random number.'); | ||
}; | ||
/* | ||
* Local polyfill of Object.create | ||
*/ | ||
var create = Object.create || (function () { | ||
function F() {}; | ||
function F() {} | ||
@@ -309,22 +362,4 @@ return function (obj) { | ||
var r = (function (m_w) { | ||
var m_w = m_w; | ||
var m_z = 0x3ade68b1; | ||
var mask = 0xffffffff; | ||
return function () { | ||
m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask; | ||
m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask; | ||
var result = ((m_z << 0x10) + m_w) & mask; | ||
result /= 0x100000000; | ||
result += 0.5; | ||
return result * (Math.random() > .5 ? 1 : -1); | ||
} | ||
}); | ||
for (var i = 0, rcache; i < nBytes; i += 4) { | ||
var _r = r((rcache || Math.random()) * 0x100000000); | ||
rcache = _r() * 0x3ade67b7; | ||
words.push((_r() * 0x100000000) | 0); | ||
for (var i = 0; i < nBytes; i += 4) { | ||
words.push(cryptoSecureRandomInt()); | ||
} | ||
@@ -560,2 +595,4 @@ | ||
_process: function (doFlush) { | ||
var processedWords; | ||
// Shortcuts | ||
@@ -593,3 +630,3 @@ var data = this._data; | ||
// Remove processed words | ||
var processedWords = dataWords.splice(0, nWordsReady); | ||
processedWords = dataWords.splice(0, nWordsReady); | ||
data.sigBytes -= nBytesReady; | ||
@@ -596,0 +633,0 @@ } |
@@ -124,3 +124,4 @@ ;(function (root, factory) { | ||
var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); | ||
words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8); | ||
var bitsCombined = bits1 | bits2; | ||
words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8); | ||
nBytes++; | ||
@@ -127,0 +128,0 @@ } |
@@ -71,2 +71,4 @@ ;(function (root, factory, undef) { | ||
compute: function (password, salt) { | ||
var block; | ||
// Shortcut | ||
@@ -91,3 +93,3 @@ var cfg = this.cfg; | ||
} | ||
var block = hasher.update(password).finalize(salt); | ||
block = hasher.update(password).finalize(salt); | ||
hasher.reset(); | ||
@@ -94,0 +96,0 @@ |
@@ -52,2 +52,4 @@ ;(function (root, factory, undef) { | ||
function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { | ||
var keystream; | ||
// Shortcut | ||
@@ -58,3 +60,3 @@ var iv = this._iv; | ||
if (iv) { | ||
var keystream = iv.slice(0); | ||
keystream = iv.slice(0); | ||
@@ -64,3 +66,3 @@ // Remove IV for subsequent blocks | ||
} else { | ||
var keystream = this._prevBlock; | ||
keystream = this._prevBlock; | ||
} | ||
@@ -67,0 +69,0 @@ cipher.encryptBlock(keystream, 0); |
{ | ||
"name": "crypto-js", | ||
"version": "3.3.0", | ||
"version": "4.0.0", | ||
"description": "JavaScript library of crypto standards.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -35,6 +35,8 @@ ;(function (root, factory, undef) { | ||
var i = data.sigBytes - 1; | ||
while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { | ||
i--; | ||
for (var i = data.sigBytes - 1; i >= 0; i--) { | ||
if (((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { | ||
data.sigBytes = i + 1; | ||
break; | ||
} | ||
} | ||
data.sigBytes = i + 1; | ||
} | ||
@@ -41,0 +43,0 @@ }; |
@@ -215,2 +215,10 @@ # crypto-js [![Build Status](https://travis-ci.org/brix/crypto-js.svg?branch=develop)](https://travis-ci.org/brix/crypto-js) | ||
### 4.0.0 | ||
This is an update including breaking changes for some environments. | ||
In this version `Math.random()` has been replaced by the random methods of the native crypto module. | ||
For this reason CryptoJS might does not run in some JavaScript environments without native crypto module. Such as IE 10 or before or React Native. | ||
### 3.3.0 | ||
@@ -217,0 +225,0 @@ |
13
sha3.js
@@ -176,2 +176,5 @@ ;(function (root, factory, undef) { | ||
for (var laneIndex = 1; laneIndex < 25; laneIndex++) { | ||
var tMsw; | ||
var tLsw; | ||
// Shortcuts | ||
@@ -185,7 +188,7 @@ var lane = state[laneIndex]; | ||
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)); | ||
} | ||
@@ -225,3 +228,3 @@ | ||
lane.high ^= roundConstant.high; | ||
lane.low ^= roundConstant.low;; | ||
lane.low ^= roundConstant.low; | ||
} | ||
@@ -228,0 +231,0 @@ }, |
@@ -145,2 +145,5 @@ ;(function (root, factory, undef) { | ||
for (var i = 0; i < 80; i++) { | ||
var Wil; | ||
var Wih; | ||
// Shortcut | ||
@@ -151,4 +154,4 @@ var Wi = W[i]; | ||
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 { | ||
@@ -178,8 +181,8 @@ // Gamma0 | ||
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); | ||
@@ -186,0 +189,0 @@ Wi.high = Wih; |
@@ -730,7 +730,16 @@ ;(function (root, factory, undef) { | ||
var keyWords = key.words; | ||
// Make sure the key length is valid (64, 128 or >= 192 bit) | ||
if (keyWords.length !== 2 && keyWords.length !== 4 && keyWords.length < 6) { | ||
throw new Error('Invalid key length - 3DES requires the key length to be 64, 128, 192 or >192.'); | ||
} | ||
// Extend the key according to the keying options defined in 3DES standard | ||
var key1 = keyWords.slice(0, 2); | ||
var key2 = keyWords.length < 4 ? keyWords.slice(0, 2) : keyWords.slice(2, 4); | ||
var key3 = keyWords.length < 6 ? keyWords.slice(0, 2) : keyWords.slice(4, 6); | ||
// Create DES instances | ||
this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2))); | ||
this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4))); | ||
this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6))); | ||
this._des1 = DES.createEncryptor(WordArray.create(key1)); | ||
this._des2 = DES.createEncryptor(WordArray.create(key2)); | ||
this._des3 = DES.createEncryptor(WordArray.create(key3)); | ||
}, | ||
@@ -737,0 +746,0 @@ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
434322
11304
250