Skip to content

Commit 17a693f

Browse files
committed
Polyfill Date.now for IE8 comp, fixes dcodeIO#12
1 parent b5e352c commit 17a693f

12 files changed

+73
-68
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/
22
npm-debug.log
33
.idea/
44
doco/
5+
tests/bench.js

.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
node_modules/
22
npm-debug.log
33
.idea/
4+
doco/
5+
tests/bench.js
46
*.png

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bcryptjs",
33
"description": "Optimized bcrypt in plain JavaScript with zero dependencies.",
4-
"version": "2.0.1",
4+
"version": "2.0.2",
55
"main": "dist/bcrypt-isaac.js",
66
"license": "New-BSD",
77
"homepage": "http://dcode.io/",

dist/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ option to specify a random fallback for browser environments that do not support
1515
has been compiled with Closure Compiler using advanced optimizations.
1616

1717
The standard version, which is slightly smaller, is recommended if you are already using a Web Crypto API polyfill or
18-
intend to not support anything else.
18+
intend to not support anything else / intend to use a custom random fallback.
1919

2020
### Including ISAAC PRNG as default random fallback
2121

dist/bcrypt-isaac.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@
593593
return utfx;
594594
}();
595595

596+
Date.now = Date.now || function() { return +new Date; };
596597

597598
/**
598599
* @type {number}
@@ -871,7 +872,7 @@
871872
r = lr[off + 1];
872873

873874
l ^= P[0];
874-
for (var i=0; i<=BLOWFISH_NUM_ROUNDS-2;)
875+
for (var i=0, k=BLOWFISH_NUM_ROUNDS-2; i<=k;)
875876
// Feistel substitution on left word
876877
n = S[(l >> 24) & 0xff],
877878
n += S[0x100 | ((l >> 16) & 0xff)],
@@ -896,10 +897,9 @@
896897
* @inner
897898
*/
898899
function _streamtoword(data, offp) {
899-
for (var i = 0, word = 0; i < 4; i++) {
900-
word = (word << 8) | (data[offp] & 0xff);
900+
for (var i = 0, word = 0; i < 4; ++i)
901+
word = (word << 8) | (data[offp] & 0xff),
901902
offp = (offp + 1) % data.length;
902-
}
903903
return { key: word, offp: offp };
904904
}
905905

dist/bcrypt-isaac.min.js

+28-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/bcrypt.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@
589589
return utfx;
590590
}();
591591

592+
Date.now = Date.now || function() { return +new Date; };
592593

593594
/**
594595
* @type {number}
@@ -867,7 +868,7 @@
867868
r = lr[off + 1];
868869

869870
l ^= P[0];
870-
for (var i=0; i<=BLOWFISH_NUM_ROUNDS-2;)
871+
for (var i=0, k=BLOWFISH_NUM_ROUNDS-2; i<=k;)
871872
// Feistel substitution on left word
872873
n = S[(l >> 24) & 0xff],
873874
n += S[0x100 | ((l >> 16) & 0xff)],
@@ -892,10 +893,9 @@
892893
* @inner
893894
*/
894895
function _streamtoword(data, offp) {
895-
for (var i = 0, word = 0; i < 4; i++) {
896-
word = (word << 8) | (data[offp] & 0xff);
896+
for (var i = 0, word = 0; i < 4; ++i)
897+
word = (word << 8) | (data[offp] & 0xff),
897898
offp = (offp + 1) % data.length;
898-
}
899899
return { key: word, offp: offp };
900900
}
901901

dist/bcrypt.min.js

+25-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bcryptjs",
33
"description": "Optimized bcrypt in plain JavaScript with zero dependencies. Compatible to 'bcrypt'.",
4-
"version": "2.0.1",
4+
"version": "2.0.2",
55
"author": "Daniel Wirtz <[email protected]>",
66
"contributors": [
77
"Shane Girish <[email protected]> (https://github.com/shaneGirish)",

src/bcrypt.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@
7171
* @type {?function(number):!Array.<number>}
7272
* @inner
7373
*/
74-
var randomFallback =/*? if (ISAAC) { */ function(len) {
74+
var randomFallback = /*? if (ISAAC) { */function(len) {
7575
for (var a=[], i=0; i<len; ++i)
7676
a[i] = ((0.5 + isaac() * 2.3283064365386963e-10) * 256) | 0;
7777
return a;
78-
};/*? } else { */ null;/*? }*/
78+
};/*? } else { */null;/*? }*/
7979

8080

8181
/**

src/bcrypt/impl.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ function _encipher(lr, off, P, S) { // This is our bottleneck: 1714/1905 ticks /
275275
r = lr[off + 1];
276276

277277
l ^= P[0];
278-
for (var i=0; i<=BLOWFISH_NUM_ROUNDS-2;)
278+
for (var i=0, k=BLOWFISH_NUM_ROUNDS-2; i<=k;)
279279
// Feistel substitution on left word
280280
n = S[(l >> 24) & 0xff],
281281
n += S[0x100 | ((l >> 16) & 0xff)],
@@ -300,10 +300,9 @@ function _encipher(lr, off, P, S) { // This is our bottleneck: 1714/1905 ticks /
300300
* @inner
301301
*/
302302
function _streamtoword(data, offp) {
303-
for (var i = 0, word = 0; i < 4; i++) {
304-
word = (word << 8) | (data[offp] & 0xff);
303+
for (var i = 0, word = 0; i < 4; ++i)
304+
word = (word << 8) | (data[offp] & 0xff),
305305
offp = (offp + 1) % data.length;
306-
}
307306
return { key: word, offp: offp };
308307
}
309308

src/bcrypt/util.js

+1
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ function stringToBytes(str) {
3030

3131
//? include("../../node_modules/utfx/dist/utfx-embeddable.js");
3232

33+
Date.now = Date.now || function() { return +new Date; };

0 commit comments

Comments
 (0)