Skip to content

Commit be8d44d

Browse files
author
evanvosberg
committed
Merge branch 'release/3.1.8'
2 parents 67d2e99 + 91819e8 commit be8d44d

File tree

6 files changed

+106
-38
lines changed

6 files changed

+106
-38
lines changed

aes.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,18 @@
9191
*/
9292
var AES = C_algo.AES = BlockCipher.extend({
9393
_doReset: function () {
94+
// Skip reset of nRounds has been set before and key did not change
95+
if (this._nRounds && this._keyPriorReset === this._key) {
96+
return;
97+
}
98+
9499
// Shortcuts
95-
var key = this._key;
100+
var key = this._keyPriorReset = this._key;
96101
var keyWords = key.words;
97102
var keySize = key.sigBytes / 4;
98103

99104
// Compute number of rounds
100-
var nRounds = this._nRounds = keySize + 6
105+
var nRounds = this._nRounds = keySize + 6;
101106

102107
// Compute number of key schedule rows
103108
var ksRows = (nRounds + 1) * 4;

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.1.7",
3+
"version": "3.1.8",
44
"description": "JavaScript library of crypto standards.",
55
"license": "MIT",
66
"homepage": "http://github.com/brix/crypto-js",

core.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@
1717
* CryptoJS core components.
1818
*/
1919
var CryptoJS = CryptoJS || (function (Math, undefined) {
20+
/*
21+
* Local polyfil of Object.create
22+
*/
23+
var create = Object.create || (function () {
24+
function F() {};
25+
26+
return function (obj) {
27+
var subtype;
28+
29+
F.prototype = obj;
30+
31+
subtype = new F();
32+
33+
F.prototype = null;
34+
35+
return subtype;
36+
};
37+
}())
38+
2039
/**
2140
* CryptoJS namespace.
2241
*/
@@ -31,7 +50,7 @@
3150
* Base object for prototypal inheritance.
3251
*/
3352
var Base = C_lib.Base = (function () {
34-
function F() {}
53+
3554

3655
return {
3756
/**
@@ -54,8 +73,7 @@
5473
*/
5574
extend: function (overrides) {
5675
// Spawn
57-
F.prototype = this;
58-
var subtype = new F();
76+
var subtype = create(this);
5977

6078
// Augment
6179
if (overrides) {

crypto-js.js

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@
1717
* CryptoJS core components.
1818
*/
1919
var CryptoJS = CryptoJS || (function (Math, undefined) {
20+
/*
21+
* Local polyfil of Object.create
22+
*/
23+
var create = Object.create || (function () {
24+
function F() {};
25+
26+
return function (obj) {
27+
var subtype;
28+
29+
F.prototype = obj;
30+
31+
subtype = new F();
32+
33+
F.prototype = null;
34+
35+
return subtype;
36+
};
37+
}())
38+
2039
/**
2140
* CryptoJS namespace.
2241
*/
@@ -31,7 +50,7 @@
3150
* Base object for prototypal inheritance.
3251
*/
3352
var Base = C_lib.Base = (function () {
34-
function F() {}
53+
3554

3655
return {
3756
/**
@@ -54,8 +73,7 @@
5473
*/
5574
extend: function (overrides) {
5675
// Spawn
57-
F.prototype = this;
58-
var subtype = new F();
76+
var subtype = create(this);
5977

6078
// Augment
6179
if (overrides) {
@@ -812,34 +830,45 @@
812830
// Shortcuts
813831
var base64StrLength = base64Str.length;
814832
var map = this._map;
833+
var reverseMap = this._reverseMap;
834+
835+
if (!reverseMap) {
836+
reverseMap = this._reverseMap = [];
837+
for (var j = 0; j < map.length; j++) {
838+
reverseMap[map.charCodeAt(j)] = j;
839+
}
840+
}
815841

816842
// Ignore padding
817843
var paddingChar = map.charAt(64);
818844
if (paddingChar) {
819845
var paddingIndex = base64Str.indexOf(paddingChar);
820-
if (paddingIndex != -1) {
846+
if (paddingIndex !== -1) {
821847
base64StrLength = paddingIndex;
822848
}
823849
}
824850

825851
// Convert
826-
var words = [];
827-
var nBytes = 0;
828-
for (var i = 0; i < base64StrLength; i++) {
829-
if (i % 4) {
830-
var bits1 = map.indexOf(base64Str.charAt(i - 1)) << ((i % 4) * 2);
831-
var bits2 = map.indexOf(base64Str.charAt(i)) >>> (6 - (i % 4) * 2);
832-
var bitsCombined = bits1 | bits2;
833-
words[nBytes >>> 2] |= (bitsCombined) << (24 - (nBytes % 4) * 8);
834-
nBytes++;
835-
}
836-
}
852+
return parseLoop(base64Str, base64StrLength, reverseMap);
837853

838-
return WordArray.create(words, nBytes);
839854
},
840855

841856
_map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
842857
};
858+
859+
function parseLoop(base64Str, base64StrLength, reverseMap) {
860+
var words = [];
861+
var nBytes = 0;
862+
for (var i = 0; i < base64StrLength; i++) {
863+
if (i % 4) {
864+
var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
865+
var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
866+
words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8);
867+
nBytes++;
868+
}
869+
}
870+
return WordArray.create(words, nBytes);
871+
}
843872
}());
844873

845874

@@ -4429,13 +4458,18 @@
44294458
*/
44304459
var AES = C_algo.AES = BlockCipher.extend({
44314460
_doReset: function () {
4461+
// Skip reset of nRounds has been set before and key did not change
4462+
if (this._nRounds && this._keyPriorReset === this._key) {
4463+
return;
4464+
}
4465+
44324466
// Shortcuts
4433-
var key = this._key;
4467+
var key = this._keyPriorReset = this._key;
44344468
var keyWords = key.words;
44354469
var keySize = key.sigBytes / 4;
44364470

44374471
// Compute number of rounds
4438-
var nRounds = this._nRounds = keySize + 6
4472+
var nRounds = this._nRounds = keySize + 6;
44394473

44404474
// Compute number of key schedule rows
44414475
var ksRows = (nRounds + 1) * 4;

enc-base64.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,34 +88,45 @@
8888
// Shortcuts
8989
var base64StrLength = base64Str.length;
9090
var map = this._map;
91+
var reverseMap = this._reverseMap;
92+
93+
if (!reverseMap) {
94+
reverseMap = this._reverseMap = [];
95+
for (var j = 0; j < map.length; j++) {
96+
reverseMap[map.charCodeAt(j)] = j;
97+
}
98+
}
9199

92100
// Ignore padding
93101
var paddingChar = map.charAt(64);
94102
if (paddingChar) {
95103
var paddingIndex = base64Str.indexOf(paddingChar);
96-
if (paddingIndex != -1) {
104+
if (paddingIndex !== -1) {
97105
base64StrLength = paddingIndex;
98106
}
99107
}
100108

101109
// Convert
102-
var words = [];
103-
var nBytes = 0;
104-
for (var i = 0; i < base64StrLength; i++) {
105-
if (i % 4) {
106-
var bits1 = map.indexOf(base64Str.charAt(i - 1)) << ((i % 4) * 2);
107-
var bits2 = map.indexOf(base64Str.charAt(i)) >>> (6 - (i % 4) * 2);
108-
var bitsCombined = bits1 | bits2;
109-
words[nBytes >>> 2] |= (bitsCombined) << (24 - (nBytes % 4) * 8);
110-
nBytes++;
111-
}
112-
}
110+
return parseLoop(base64Str, base64StrLength, reverseMap);
113111

114-
return WordArray.create(words, nBytes);
115112
},
116113

117114
_map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
118115
};
116+
117+
function parseLoop(base64Str, base64StrLength, reverseMap) {
118+
var words = [];
119+
var nBytes = 0;
120+
for (var i = 0; i < base64StrLength; i++) {
121+
if (i % 4) {
122+
var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
123+
var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
124+
words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8);
125+
nBytes++;
126+
}
127+
}
128+
return WordArray.create(words, nBytes);
129+
}
119130
}());
120131

121132

package.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.1.7",
3+
"version": "3.1.8",
44
"description": "JavaScript library of crypto standards.",
55
"license": "MIT",
66
"author": {

0 commit comments

Comments
 (0)