Skip to content

Commit

Permalink
Post-merge; Fixed genSalt not defaulting to default rounds with omitt…
Browse files Browse the repository at this point in the history
…ed callback (promise), see #58
  • Loading branch information
dcodeIO committed Feb 7, 2017
1 parent bfba82c commit 5be2eb6
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 60 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"vsicons.presets.angular": false
}
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bcryptjs",
"description": "Optimized bcrypt in plain JavaScript with zero dependencies.",
"version": "2.4.0",
"version": "2.4.1",
"main": "dist/bcrypt.min.js",
"license": "New-BSD",
"homepage": "http://dcode.io/",
Expand Down
4 changes: 4 additions & 0 deletions debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[0207/082007:ERROR:tcp_listen_socket.cc(76)] Could not bind socket to 127.0.0.1:6004
[0207/082007:ERROR:node_debugger.cc(86)] Cannot start debugger server
[0207/082011:ERROR:tcp_listen_socket.cc(76)] Could not bind socket to 127.0.0.1:6004
[0207/082011:ERROR:node_debugger.cc(86)] Cannot start debugger server
121 changes: 112 additions & 9 deletions dist/bcrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@
seed_length = undefined; // Not supported.
if (typeof rounds === 'function')
callback = rounds,
rounds = undefined;
if (typeof rounds === 'undefined')
rounds = GENSALT_DEFAULT_LOG2_ROUNDS;
else if (typeof rounds !== 'number')
throw Error("illegal arguments: "+(typeof rounds));

function _async(callback) {
nextTick(function() { // Pretty thin, but salting is fast enough
if (typeof rounds !== 'number') {
callback(Error("Illegal arguments: "+(typeof rounds)));
return;
}
try {
callback(null, bcrypt.genSaltSync(rounds));
} catch (err) {
Expand Down Expand Up @@ -962,19 +962,113 @@
r = lr[off + 1];

l ^= P[0];

/*
for (var i=0, k=BLOWFISH_NUM_ROUNDS-2; i<=k;)
// Feistel substitution on left word
n = S[(l >> 24) & 0xff],
n = S[l >>> 24],
n += S[0x100 | ((l >> 16) & 0xff)],
n ^= S[0x200 | ((l >> 8) & 0xff)],
n += S[0x300 | (l & 0xff)],
r ^= n ^ P[++i],
// Feistel substitution on right word
n = S[(r >> 24) & 0xff],
n = S[r >>> 24],
n += S[0x100 | ((r >> 16) & 0xff)],
n ^= S[0x200 | ((r >> 8) & 0xff)],
n += S[0x300 | (r & 0xff)],
l ^= n ^ P[++i];
*/

//The following is an unrolled version of the above loop.
//Iteration 0
n = S[l >>> 24];
n += S[0x100 | ((l >> 16) & 0xff)];
n ^= S[0x200 | ((l >> 8) & 0xff)];
n += S[0x300 | (l & 0xff)];
r ^= n ^ P[1];
n = S[r >>> 24];
n += S[0x100 | ((r >> 16) & 0xff)];
n ^= S[0x200 | ((r >> 8) & 0xff)];
n += S[0x300 | (r & 0xff)];
l ^= n ^ P[2];
//Iteration 1
n = S[l >>> 24];
n += S[0x100 | ((l >> 16) & 0xff)];
n ^= S[0x200 | ((l >> 8) & 0xff)];
n += S[0x300 | (l & 0xff)];
r ^= n ^ P[3];
n = S[r >>> 24];
n += S[0x100 | ((r >> 16) & 0xff)];
n ^= S[0x200 | ((r >> 8) & 0xff)];
n += S[0x300 | (r & 0xff)];
l ^= n ^ P[4];
//Iteration 2
n = S[l >>> 24];
n += S[0x100 | ((l >> 16) & 0xff)];
n ^= S[0x200 | ((l >> 8) & 0xff)];
n += S[0x300 | (l & 0xff)];
r ^= n ^ P[5];
n = S[r >>> 24];
n += S[0x100 | ((r >> 16) & 0xff)];
n ^= S[0x200 | ((r >> 8) & 0xff)];
n += S[0x300 | (r & 0xff)];
l ^= n ^ P[6];
//Iteration 3
n = S[l >>> 24];
n += S[0x100 | ((l >> 16) & 0xff)];
n ^= S[0x200 | ((l >> 8) & 0xff)];
n += S[0x300 | (l & 0xff)];
r ^= n ^ P[7];
n = S[r >>> 24];
n += S[0x100 | ((r >> 16) & 0xff)];
n ^= S[0x200 | ((r >> 8) & 0xff)];
n += S[0x300 | (r & 0xff)];
l ^= n ^ P[8];
//Iteration 4
n = S[l >>> 24];
n += S[0x100 | ((l >> 16) & 0xff)];
n ^= S[0x200 | ((l >> 8) & 0xff)];
n += S[0x300 | (l & 0xff)];
r ^= n ^ P[9];
n = S[r >>> 24];
n += S[0x100 | ((r >> 16) & 0xff)];
n ^= S[0x200 | ((r >> 8) & 0xff)];
n += S[0x300 | (r & 0xff)];
l ^= n ^ P[10];
//Iteration 5
n = S[l >>> 24];
n += S[0x100 | ((l >> 16) & 0xff)];
n ^= S[0x200 | ((l >> 8) & 0xff)];
n += S[0x300 | (l & 0xff)];
r ^= n ^ P[11];
n = S[r >>> 24];
n += S[0x100 | ((r >> 16) & 0xff)];
n ^= S[0x200 | ((r >> 8) & 0xff)];
n += S[0x300 | (r & 0xff)];
l ^= n ^ P[12];
//Iteration 6
n = S[l >>> 24];
n += S[0x100 | ((l >> 16) & 0xff)];
n ^= S[0x200 | ((l >> 8) & 0xff)];
n += S[0x300 | (l & 0xff)];
r ^= n ^ P[13];
n = S[r >>> 24];
n += S[0x100 | ((r >> 16) & 0xff)];
n ^= S[0x200 | ((r >> 8) & 0xff)];
n += S[0x300 | (r & 0xff)];
l ^= n ^ P[14];
//Iteration 7
n = S[l >>> 24];
n += S[0x100 | ((l >> 16) & 0xff)];
n ^= S[0x200 | ((l >> 8) & 0xff)];
n += S[0x300 | (l & 0xff)];
r ^= n ^ P[15];
n = S[r >>> 24];
n += S[0x100 | ((r >> 16) & 0xff)];
n ^= S[0x200 | ((r >> 8) & 0xff)];
n += S[0x300 | (r & 0xff)];
l ^= n ^ P[16];

lr[off] = r ^ P[BLOWFISH_NUM_ROUNDS + 1];
lr[off + 1] = l;
return lr;
Expand Down Expand Up @@ -1094,9 +1188,18 @@
throw err;
}
rounds = (1 << rounds) >>> 0;
var P = P_ORIG.slice(),
S = S_ORIG.slice(),
i = 0, j;

var P, S, i = 0, j;

//Use typed arrays when available - huge speedup!
if (Int32Array) {
P = new Int32Array(P_ORIG);
S = new Int32Array(S_ORIG);
} else {
P = P_ORIG.slice();
S = S_ORIG.slice();
}

_ekskey(salt, b, P, S);

/**
Expand Down
Loading

0 comments on commit 5be2eb6

Please sign in to comment.