这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 34 additions & 31 deletions nacl-fast.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,17 +828,15 @@ var Kl = [
0xcb3e42b6, 0xfc657e2a, 0x3ad6faec, 0x4a475817
];

function crypto_hashblocks(x, m, n) {
var zh = new Int32Array(8), zl = new Int32Array(8),
bh = new Int32Array(8), bl = new Int32Array(8),
function crypto_hashblocks_hl(hh, hl, m, n) {
var bh = new Int32Array(8), bl = new Int32Array(8),
ah = new Int32Array(8), al = new Int32Array(8),
wh = new Int32Array(16), wl = new Int32Array(16),
th, tl, i, j, h, l, xh, xl, a, b, c, d, m16 = 0xffff;

for (i = 0; i < 8; i++) {
j = 8 * i;
zh[i] = ah[i] = (x[j+0] << 24) | (x[j+1] << 16) | (x[j+2] << 8) | x[j+3];
zl[i] = al[i] = (x[j+4] << 24) | (x[j+5] << 16) | (x[j+6] << 8) | x[j+7];
ah[i] = hh[i];
al[i] = hl[i];
}

var pos = 0;
Expand Down Expand Up @@ -1019,8 +1017,8 @@ function crypto_hashblocks(x, m, n) {
a = l & m16; b = l >>> 16;
c = h & m16; d = h >>> 16;

h = zh[i];
l = zl[i];
h = hh[i];
l = hl[i];

a += l & m16; b += l >>> 16;
c += h & m16; d += h >>> 16;
Expand All @@ -1029,48 +1027,53 @@ function crypto_hashblocks(x, m, n) {
c += b >>> 16;
d += c >>> 16;

zh[i] = ah[i] = (c & m16) | (d << 16);
zl[i] = al[i] = (a & m16) | (b << 16);
hh[i] = ah[i] = (c & m16) | (d << 16);
hl[i] = al[i] = (a & m16) | (b << 16);
}

pos += 128;
n -= 128;
}

for (i = 0; i < 8; i++) ts64(x, 8*i, zh[i], zl[i]);
return n;
}

var iv = new Uint8Array([
0x6a,0x09,0xe6,0x67,0xf3,0xbc,0xc9,0x08,
0xbb,0x67,0xae,0x85,0x84,0xca,0xa7,0x3b,
0x3c,0x6e,0xf3,0x72,0xfe,0x94,0xf8,0x2b,
0xa5,0x4f,0xf5,0x3a,0x5f,0x1d,0x36,0xf1,
0x51,0x0e,0x52,0x7f,0xad,0xe6,0x82,0xd1,
0x9b,0x05,0x68,0x8c,0x2b,0x3e,0x6c,0x1f,
0x1f,0x83,0xd9,0xab,0xfb,0x41,0xbd,0x6b,
0x5b,0xe0,0xcd,0x19,0x13,0x7e,0x21,0x79
]);

function crypto_hash(out, m, n) {
var h = new Uint8Array(64), x = new Uint8Array(256);
var i, b = n;

for (i = 0; i < 64; i++) h[i] = iv[i];

crypto_hashblocks(h, m, n);
var hh = new Int32Array(8),
hl = new Int32Array(8),
x = new Uint8Array(256),
i, b = n;

hh[0] = 0x6a09e667;
hh[1] = 0xbb67ae85;
hh[2] = 0x3c6ef372;
hh[3] = 0xa54ff53a;
hh[4] = 0x510e527f;
hh[5] = 0x9b05688c;
hh[6] = 0x1f83d9ab;
hh[7] = 0x5be0cd19;

hl[0] = 0xf3bcc908;
hl[1] = 0x84caa73b;
hl[2] = 0xfe94f82b;
hl[3] = 0x5f1d36f1;
hl[4] = 0xade682d1;
hl[5] = 0x2b3e6c1f;
hl[6] = 0xfb41bd6b;
hl[7] = 0x137e2179;

crypto_hashblocks_hl(hh, hl, m, n);
n %= 128;

for (i = 0; i < 256; i++) x[i] = 0;
for (i = 0; i < n; i++) x[i] = m[b-n+i];
x[n] = 128;

n = 256-128*(n<112?1:0);
x[n-9] = 0;
ts64(x, n-8, (b / 0x20000000) | 0, b << 3);
crypto_hashblocks(h, x, n);
crypto_hashblocks_hl(hh, hl, x, n);

for (i = 0; i < 64; i++) out[i] = h[i];
for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]);

return 0;
}
Expand Down
Loading