Skip to content

Commit

Permalink
Merge branch 'release/3.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
evanvosberg committed Feb 12, 2020
2 parents 79209bc + 887dcaa commit 4db30e7
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 256 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ console.log(decryptedData); // [{id: 1}, {id: 2}]

## Release notes

### 3.3.0

Rollback, `3.3.0` is the same as `3.1.9-1`.

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.

### 3.2.1

The usage of the native crypto module has been fixed. The import and access of the native crypto module has been improved.
Expand Down
4 changes: 1 addition & 3 deletions aes.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@
*/
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 @@ -115,7 +113,7 @@
if (ksRow < keySize) {
keySchedule[ksRow] = keyWords[ksRow];
} else {
t = keySchedule[ksRow - 1];
var t = keySchedule[ksRow - 1];

if (!(ksRow % keySize)) {
// Rot word
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crypto-js",
"version": "3.2.1",
"version": "3.3.0",
"description": "JavaScript library of crypto standards.",
"license": "MIT",
"homepage": "http://github.com/brix/crypto-js",
Expand Down
28 changes: 9 additions & 19 deletions cipher-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,19 +351,17 @@
});

function xorBlock(words, offset, blockSize) {
var block;

// Shortcut
var iv = this._iv;

// Choose mixing block
if (iv) {
block = iv;
var block = iv;

// Remove IV for subsequent blocks
this._iv = undefined;
} else {
block = this._prevBlock;
var block = this._prevBlock;
}

// XOR blocks
Expand Down Expand Up @@ -455,8 +453,6 @@
}),

reset: function () {
var modeCreator;

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

Expand All @@ -467,9 +463,9 @@

// Reset block mode
if (this._xformMode == this._ENC_XFORM_MODE) {
modeCreator = mode.createEncryptor;
var modeCreator = mode.createEncryptor;
} else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
modeCreator = mode.createDecryptor;
var modeCreator = mode.createDecryptor;
// Keep at least one block in the buffer for unpadding
this._minBufferSize = 1;
}
Expand All @@ -487,8 +483,6 @@
},

_doFinalize: function () {
var finalProcessedBlocks;

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

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

// Process final blocks
finalProcessedBlocks = this._process(!!'flush');
var finalProcessedBlocks = this._process(!!'flush');
} else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
// Process final blocks
finalProcessedBlocks = this._process(!!'flush');
var finalProcessedBlocks = this._process(!!'flush');

// Unpad data
padding.unpad(finalProcessedBlocks);
Expand Down Expand Up @@ -593,17 +587,15 @@
* var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
*/
stringify: function (cipherParams) {
var wordArray;

// Shortcuts
var ciphertext = cipherParams.ciphertext;
var salt = cipherParams.salt;

// Format
if (salt) {
wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
} else {
wordArray = ciphertext;
var wordArray = ciphertext;
}

return wordArray.toString(Base64);
Expand All @@ -623,8 +615,6 @@
* var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
*/
parse: function (openSSLStr) {
var salt;

// Parse base64
var ciphertext = Base64.parse(openSSLStr);

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

// Remove salt from ciphertext
ciphertextWords.splice(0, 4);
Expand Down
83 changes: 23 additions & 60 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,68 +13,15 @@
}
}(this, function () {

/*globals window, global, require*/

/**
* 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) {}
}

/*
* 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
* Local polyfil of Object.create
*/
var create = Object.create || (function () {
function F() {}
function F() {};

return function (obj) {
var subtype;
Expand Down Expand Up @@ -357,8 +304,26 @@
random: function (nBytes) {
var words = [];

for (var i = 0; i < nBytes; i += 4) {
words.push(cryptoSecureRandomInt());
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);
}

return new WordArray.init(words, nBytes);
Expand Down Expand Up @@ -589,8 +554,6 @@
* var processedData = bufferedBlockAlgorithm._process(!!'flush');
*/
_process: function (doFlush) {
var processedWords;

// Shortcuts
var data = this._data;
var dataWords = data.words;
Expand Down Expand Up @@ -623,7 +586,7 @@
}

// Remove processed words
processedWords = dataWords.splice(0, nWordsReady);
var processedWords = dataWords.splice(0, nWordsReady);
data.sigBytes -= nBytesReady;
}

Expand Down
Loading

0 comments on commit 4db30e7

Please sign in to comment.