Skip to content

Commit 887dcaa

Browse files
committed
Rollback.
1 parent 79209bc commit 887dcaa

14 files changed

+120
-256
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ console.log(decryptedData); // [{id: 1}, {id: 2}]
212212

213213
## Release notes
214214

215+
### 3.3.0
216+
217+
Rollback, `3.3.0` is the same as `3.1.9-1`.
218+
219+
The move of using native secure crypto module will be shifted to a new `4.x.x` version. As it is a breaking change the impact is too big for a minor release.
220+
215221
### 3.2.1
216222

217223
The usage of the native crypto module has been fixed. The import and access of the native crypto module has been improved.

aes.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@
9191
*/
9292
var AES = C_algo.AES = BlockCipher.extend({
9393
_doReset: function () {
94-
var t;
95-
9694
// Skip reset of nRounds has been set before and key did not change
9795
if (this._nRounds && this._keyPriorReset === this._key) {
9896
return;
@@ -115,7 +113,7 @@
115113
if (ksRow < keySize) {
116114
keySchedule[ksRow] = keyWords[ksRow];
117115
} else {
118-
t = keySchedule[ksRow - 1];
116+
var t = keySchedule[ksRow - 1];
119117

120118
if (!(ksRow % keySize)) {
121119
// Rot word

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "crypto-js",
3-
"version": "3.2.1",
3+
"version": "3.3.0",
44
"description": "JavaScript library of crypto standards.",
55
"license": "MIT",
66
"homepage": "http://github.com/brix/crypto-js",

cipher-core.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -351,19 +351,17 @@
351351
});
352352

353353
function xorBlock(words, offset, blockSize) {
354-
var block;
355-
356354
// Shortcut
357355
var iv = this._iv;
358356

359357
// Choose mixing block
360358
if (iv) {
361-
block = iv;
359+
var block = iv;
362360

363361
// Remove IV for subsequent blocks
364362
this._iv = undefined;
365363
} else {
366-
block = this._prevBlock;
364+
var block = this._prevBlock;
367365
}
368366

369367
// XOR blocks
@@ -455,8 +453,6 @@
455453
}),
456454

457455
reset: function () {
458-
var modeCreator;
459-
460456
// Reset cipher
461457
Cipher.reset.call(this);
462458

@@ -467,9 +463,9 @@
467463

468464
// Reset block mode
469465
if (this._xformMode == this._ENC_XFORM_MODE) {
470-
modeCreator = mode.createEncryptor;
466+
var modeCreator = mode.createEncryptor;
471467
} else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
472-
modeCreator = mode.createDecryptor;
468+
var modeCreator = mode.createDecryptor;
473469
// Keep at least one block in the buffer for unpadding
474470
this._minBufferSize = 1;
475471
}
@@ -487,8 +483,6 @@
487483
},
488484

489485
_doFinalize: function () {
490-
var finalProcessedBlocks;
491-
492486
// Shortcut
493487
var padding = this.cfg.padding;
494488

@@ -498,10 +492,10 @@
498492
padding.pad(this._data, this.blockSize);
499493

500494
// Process final blocks
501-
finalProcessedBlocks = this._process(!!'flush');
495+
var finalProcessedBlocks = this._process(!!'flush');
502496
} else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
503497
// Process final blocks
504-
finalProcessedBlocks = this._process(!!'flush');
498+
var finalProcessedBlocks = this._process(!!'flush');
505499

506500
// Unpad data
507501
padding.unpad(finalProcessedBlocks);
@@ -593,17 +587,15 @@
593587
* var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
594588
*/
595589
stringify: function (cipherParams) {
596-
var wordArray;
597-
598590
// Shortcuts
599591
var ciphertext = cipherParams.ciphertext;
600592
var salt = cipherParams.salt;
601593

602594
// Format
603595
if (salt) {
604-
wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
596+
var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
605597
} else {
606-
wordArray = ciphertext;
598+
var wordArray = ciphertext;
607599
}
608600

609601
return wordArray.toString(Base64);
@@ -623,8 +615,6 @@
623615
* var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
624616
*/
625617
parse: function (openSSLStr) {
626-
var salt;
627-
628618
// Parse base64
629619
var ciphertext = Base64.parse(openSSLStr);
630620

@@ -634,7 +624,7 @@
634624
// Test for salt
635625
if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) {
636626
// Extract salt
637-
salt = WordArray.create(ciphertextWords.slice(2, 4));
627+
var salt = WordArray.create(ciphertextWords.slice(2, 4));
638628

639629
// Remove salt from ciphertext
640630
ciphertextWords.splice(0, 4);

core.js

Lines changed: 23 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -13,68 +13,15 @@
1313
}
1414
}(this, function () {
1515

16-
/*globals window, global, require*/
17-
1816
/**
1917
* CryptoJS core components.
2018
*/
2119
var CryptoJS = CryptoJS || (function (Math, undefined) {
22-
23-
var crypto;
24-
25-
// Native crypto from window (Browser)
26-
if (typeof window !== 'undefined' && window.crypto) {
27-
crypto = window.crypto;
28-
}
29-
30-
// Native (experimental IE 11) crypto from window (Browser)
31-
if (!crypto && typeof window !== 'undefined' && window.msCrypto) {
32-
crypto = window.msCrypto;
33-
}
34-
35-
// Native crypto from global (NodeJS)
36-
if (!crypto && typeof global !== 'undefined' && global.crypto) {
37-
crypto = global.crypto;
38-
}
39-
40-
// Native crypto import via require (NodeJS)
41-
if (!crypto && typeof require === 'function') {
42-
try {
43-
crypto = require('crypto');
44-
} catch (err) {}
45-
}
46-
47-
/*
48-
* Cryptographically secure pseudorandom number generator
49-
*
50-
* As Math.random() is cryptographically not safe to use
51-
*/
52-
var cryptoSecureRandomInt = function () {
53-
if (crypto) {
54-
// Use getRandomValues method (Browser)
55-
if (typeof crypto.getRandomValues === 'function') {
56-
try {
57-
return crypto.getRandomValues(new Uint32Array(1))[0];
58-
} catch (err) {}
59-
}
60-
61-
// Use randomBytes method (NodeJS)
62-
if (typeof crypto.randomBytes === 'function') {
63-
try {
64-
return crypto.randomBytes(4).readInt32LE();
65-
} catch (err) {}
66-
}
67-
}
68-
69-
throw new Error('Native crypto module could not be used to get secure random number.');
70-
};
71-
7220
/*
73-
* Local polyfill of Object.create
74-
21+
* Local polyfil of Object.create
7522
*/
7623
var create = Object.create || (function () {
77-
function F() {}
24+
function F() {};
7825

7926
return function (obj) {
8027
var subtype;
@@ -357,8 +304,26 @@
357304
random: function (nBytes) {
358305
var words = [];
359306

360-
for (var i = 0; i < nBytes; i += 4) {
361-
words.push(cryptoSecureRandomInt());
307+
var r = (function (m_w) {
308+
var m_w = m_w;
309+
var m_z = 0x3ade68b1;
310+
var mask = 0xffffffff;
311+
312+
return function () {
313+
m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
314+
m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
315+
var result = ((m_z << 0x10) + m_w) & mask;
316+
result /= 0x100000000;
317+
result += 0.5;
318+
return result * (Math.random() > .5 ? 1 : -1);
319+
}
320+
});
321+
322+
for (var i = 0, rcache; i < nBytes; i += 4) {
323+
var _r = r((rcache || Math.random()) * 0x100000000);
324+
325+
rcache = _r() * 0x3ade67b7;
326+
words.push((_r() * 0x100000000) | 0);
362327
}
363328

364329
return new WordArray.init(words, nBytes);
@@ -589,8 +554,6 @@
589554
* var processedData = bufferedBlockAlgorithm._process(!!'flush');
590555
*/
591556
_process: function (doFlush) {
592-
var processedWords;
593-
594557
// Shortcuts
595558
var data = this._data;
596559
var dataWords = data.words;
@@ -623,7 +586,7 @@
623586
}
624587

625588
// Remove processed words
626-
processedWords = dataWords.splice(0, nWordsReady);
589+
var processedWords = dataWords.splice(0, nWordsReady);
627590
data.sigBytes -= nBytesReady;
628591
}
629592

0 commit comments

Comments
 (0)