\r
var gf0 = gf(),\r
gf1 = gf([1]),\r
- _121665 = gf([0xdb41, 1]),\r
D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),\r
D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]),\r
X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]),\r
Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]),\r
I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);\r
\r
- function ts64(x, i, h, l) {\r
- x[i] = (h >> 24) & 0xff;\r
- x[i+1] = (h >> 16) & 0xff;\r
- x[i+2] = (h >> 8) & 0xff;\r
- x[i+3] = h & 0xff;\r
- x[i+4] = (l >> 24) & 0xff;\r
- x[i+5] = (l >> 16) & 0xff;\r
- x[i+6] = (l >> 8) & 0xff;\r
- x[i+7] = l & 0xff;\r
- }\r
-\r
function vn(x, xi, y, yi, n) {\r
var i,d = 0;\r
for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i];\r
for (a = 0; a < 16; a++) o[a] = c[a];\r
}\r
\r
- var K = [\r
- 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,\r
- 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,\r
- 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,\r
- 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,\r
- 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,\r
- 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,\r
- 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,\r
- 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,\r
- 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,\r
- 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,\r
- 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,\r
- 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,\r
- 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,\r
- 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,\r
- 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,\r
- 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,\r
- 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,\r
- 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,\r
- 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,\r
- 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,\r
- 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,\r
- 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,\r
- 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,\r
- 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,\r
- 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,\r
- 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,\r
- 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,\r
- 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,\r
- 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,\r
- 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,\r
- 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,\r
- 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,\r
- 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,\r
- 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,\r
- 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,\r
- 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,\r
- 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,\r
- 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,\r
- 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,\r
- 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817\r
- ];\r
-\r
- function crypto_hashblocks_hl(hh, hl, m, n) {\r
- var wh = new Int32Array(16), wl = new Int32Array(16),\r
- bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7,\r
- bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7,\r
- th, tl, i, j, h, l, a, b, c, d;\r
-\r
- var ah0 = hh[0],\r
- ah1 = hh[1],\r
- ah2 = hh[2],\r
- ah3 = hh[3],\r
- ah4 = hh[4],\r
- ah5 = hh[5],\r
- ah6 = hh[6],\r
- ah7 = hh[7],\r
-\r
- al0 = hl[0],\r
- al1 = hl[1],\r
- al2 = hl[2],\r
- al3 = hl[3],\r
- al4 = hl[4],\r
- al5 = hl[5],\r
- al6 = hl[6],\r
- al7 = hl[7];\r
-\r
- var pos = 0;\r
- while (n >= 128) {\r
- for (i = 0; i < 16; i++) {\r
- j = 8 * i + pos;\r
- wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3];\r
- wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7];\r
- }\r
- for (i = 0; i < 80; i++) {\r
- bh0 = ah0;\r
- bh1 = ah1;\r
- bh2 = ah2;\r
- bh3 = ah3;\r
- bh4 = ah4;\r
- bh5 = ah5;\r
- bh6 = ah6;\r
- bh7 = ah7;\r
-\r
- bl0 = al0;\r
- bl1 = al1;\r
- bl2 = al2;\r
- bl3 = al3;\r
- bl4 = al4;\r
- bl5 = al5;\r
- bl6 = al6;\r
- bl7 = al7;\r
-\r
- // add\r
- h = ah7;\r
- l = al7;\r
-\r
- a = l & 0xffff; b = l >>> 16;\r
- c = h & 0xffff; d = h >>> 16;\r
-\r
- // Sigma1\r
- h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32))));\r
- l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32))));\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- // Ch\r
- h = (ah4 & ah5) ^ (~ah4 & ah6);\r
- l = (al4 & al5) ^ (~al4 & al6);\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- // K\r
- h = K[i*2];\r
- l = K[i*2+1];\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- // w\r
- h = wh[i%16];\r
- l = wl[i%16];\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- b += a >>> 16;\r
- c += b >>> 16;\r
- d += c >>> 16;\r
-\r
- th = c & 0xffff | d << 16;\r
- tl = a & 0xffff | b << 16;\r
-\r
- // add\r
- h = th;\r
- l = tl;\r
-\r
- a = l & 0xffff; b = l >>> 16;\r
- c = h & 0xffff; d = h >>> 16;\r
-\r
- // Sigma0\r
- h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32))));\r
- l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32))));\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- // Maj\r
- h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2);\r
- l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2);\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- b += a >>> 16;\r
- c += b >>> 16;\r
- d += c >>> 16;\r
-\r
- bh7 = (c & 0xffff) | (d << 16);\r
- bl7 = (a & 0xffff) | (b << 16);\r
-\r
- // add\r
- h = bh3;\r
- l = bl3;\r
-\r
- a = l & 0xffff; b = l >>> 16;\r
- c = h & 0xffff; d = h >>> 16;\r
-\r
- h = th;\r
- l = tl;\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- b += a >>> 16;\r
- c += b >>> 16;\r
- d += c >>> 16;\r
-\r
- bh3 = (c & 0xffff) | (d << 16);\r
- bl3 = (a & 0xffff) | (b << 16);\r
-\r
- ah1 = bh0;\r
- ah2 = bh1;\r
- ah3 = bh2;\r
- ah4 = bh3;\r
- ah5 = bh4;\r
- ah6 = bh5;\r
- ah7 = bh6;\r
- ah0 = bh7;\r
-\r
- al1 = bl0;\r
- al2 = bl1;\r
- al3 = bl2;\r
- al4 = bl3;\r
- al5 = bl4;\r
- al6 = bl5;\r
- al7 = bl6;\r
- al0 = bl7;\r
-\r
- if (i%16 === 15) {\r
- for (j = 0; j < 16; j++) {\r
- // add\r
- h = wh[j];\r
- l = wl[j];\r
-\r
- a = l & 0xffff; b = l >>> 16;\r
- c = h & 0xffff; d = h >>> 16;\r
-\r
- h = wh[(j+9)%16];\r
- l = wl[(j+9)%16];\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- // sigma0\r
- th = wh[(j+1)%16];\r
- tl = wl[(j+1)%16];\r
- h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7);\r
- l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7)));\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- // sigma1\r
- th = wh[(j+14)%16];\r
- tl = wl[(j+14)%16];\r
- h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6);\r
- l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6)));\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- b += a >>> 16;\r
- c += b >>> 16;\r
- d += c >>> 16;\r
-\r
- wh[j] = (c & 0xffff) | (d << 16);\r
- wl[j] = (a & 0xffff) | (b << 16);\r
- }\r
- }\r
- }\r
-\r
- // add\r
- h = ah0;\r
- l = al0;\r
-\r
- a = l & 0xffff; b = l >>> 16;\r
- c = h & 0xffff; d = h >>> 16;\r
-\r
- h = hh[0];\r
- l = hl[0];\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- b += a >>> 16;\r
- c += b >>> 16;\r
- d += c >>> 16;\r
-\r
- hh[0] = ah0 = (c & 0xffff) | (d << 16);\r
- hl[0] = al0 = (a & 0xffff) | (b << 16);\r
-\r
- h = ah1;\r
- l = al1;\r
-\r
- a = l & 0xffff; b = l >>> 16;\r
- c = h & 0xffff; d = h >>> 16;\r
-\r
- h = hh[1];\r
- l = hl[1];\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- b += a >>> 16;\r
- c += b >>> 16;\r
- d += c >>> 16;\r
-\r
- hh[1] = ah1 = (c & 0xffff) | (d << 16);\r
- hl[1] = al1 = (a & 0xffff) | (b << 16);\r
-\r
- h = ah2;\r
- l = al2;\r
-\r
- a = l & 0xffff; b = l >>> 16;\r
- c = h & 0xffff; d = h >>> 16;\r
-\r
- h = hh[2];\r
- l = hl[2];\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- b += a >>> 16;\r
- c += b >>> 16;\r
- d += c >>> 16;\r
-\r
- hh[2] = ah2 = (c & 0xffff) | (d << 16);\r
- hl[2] = al2 = (a & 0xffff) | (b << 16);\r
-\r
- h = ah3;\r
- l = al3;\r
-\r
- a = l & 0xffff; b = l >>> 16;\r
- c = h & 0xffff; d = h >>> 16;\r
-\r
- h = hh[3];\r
- l = hl[3];\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- b += a >>> 16;\r
- c += b >>> 16;\r
- d += c >>> 16;\r
-\r
- hh[3] = ah3 = (c & 0xffff) | (d << 16);\r
- hl[3] = al3 = (a & 0xffff) | (b << 16);\r
-\r
- h = ah4;\r
- l = al4;\r
-\r
- a = l & 0xffff; b = l >>> 16;\r
- c = h & 0xffff; d = h >>> 16;\r
-\r
- h = hh[4];\r
- l = hl[4];\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- b += a >>> 16;\r
- c += b >>> 16;\r
- d += c >>> 16;\r
-\r
- hh[4] = ah4 = (c & 0xffff) | (d << 16);\r
- hl[4] = al4 = (a & 0xffff) | (b << 16);\r
-\r
- h = ah5;\r
- l = al5;\r
-\r
- a = l & 0xffff; b = l >>> 16;\r
- c = h & 0xffff; d = h >>> 16;\r
-\r
- h = hh[5];\r
- l = hl[5];\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- b += a >>> 16;\r
- c += b >>> 16;\r
- d += c >>> 16;\r
-\r
- hh[5] = ah5 = (c & 0xffff) | (d << 16);\r
- hl[5] = al5 = (a & 0xffff) | (b << 16);\r
-\r
- h = ah6;\r
- l = al6;\r
-\r
- a = l & 0xffff; b = l >>> 16;\r
- c = h & 0xffff; d = h >>> 16;\r
-\r
- h = hh[6];\r
- l = hl[6];\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- b += a >>> 16;\r
- c += b >>> 16;\r
- d += c >>> 16;\r
-\r
- hh[6] = ah6 = (c & 0xffff) | (d << 16);\r
- hl[6] = al6 = (a & 0xffff) | (b << 16);\r
-\r
- h = ah7;\r
- l = al7;\r
-\r
- a = l & 0xffff; b = l >>> 16;\r
- c = h & 0xffff; d = h >>> 16;\r
-\r
- h = hh[7];\r
- l = hl[7];\r
-\r
- a += l & 0xffff; b += l >>> 16;\r
- c += h & 0xffff; d += h >>> 16;\r
-\r
- b += a >>> 16;\r
- c += b >>> 16;\r
- d += c >>> 16;\r
-\r
- hh[7] = ah7 = (c & 0xffff) | (d << 16);\r
- hl[7] = al7 = (a & 0xffff) | (b << 16);\r
-\r
- pos += 128;\r
- n -= 128;\r
- }\r
-\r
- return n;\r
- }\r
-\r
- function crypto_hash_sha512(out, m, n) {\r
- var hh = new Int32Array(8),\r
- hl = new Int32Array(8),\r
- x = new Uint8Array(256),\r
- i, b = n;\r
-\r
- hh[0] = 0x6a09e667;\r
- hh[1] = 0xbb67ae85;\r
- hh[2] = 0x3c6ef372;\r
- hh[3] = 0xa54ff53a;\r
- hh[4] = 0x510e527f;\r
- hh[5] = 0x9b05688c;\r
- hh[6] = 0x1f83d9ab;\r
- hh[7] = 0x5be0cd19;\r
-\r
- hl[0] = 0xf3bcc908;\r
- hl[1] = 0x84caa73b;\r
- hl[2] = 0xfe94f82b;\r
- hl[3] = 0x5f1d36f1;\r
- hl[4] = 0xade682d1;\r
- hl[5] = 0x2b3e6c1f;\r
- hl[6] = 0xfb41bd6b;\r
- hl[7] = 0x137e2179;\r
-\r
- crypto_hashblocks_hl(hh, hl, m, n);\r
- n %= 128;\r
-\r
- for (i = 0; i < n; i++) x[i] = m[b-n+i];\r
- x[n] = 128;\r
-\r
- n = 256-128*(n<112?1:0);\r
- x[n-9] = 0;\r
- ts64(x, n-8, (b / 0x20000000) | 0, b << 3);\r
- crypto_hashblocks_hl(hh, hl, x, n);\r
-\r
- for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]);\r
-\r
- return 0;\r
- }\r
-\r
function crypto_hash(out, m, n) {\r
const input = new Uint8Array(n)\r
for (let i = 0; i < n; ++i) {\r