react / wstein / node_modules / browserify / node_modules / crypto-browserify / node_modules / create-hash / node_modules / sha.js / sha512.js
80556 viewsvar inherits = require('inherits')1var Hash = require('./hash')23var K = [40x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,50xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,60x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,70x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,80xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,90x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,100x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,110x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,120xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,130x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,140x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,150x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,160x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,170xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,180xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,190x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,200x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,210x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,220x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,230x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,240xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,250xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,260xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,270xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,280x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,290x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,300x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,310x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,320x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,330x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,340x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,350xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,360xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,370xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,380x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,390x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,400x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,410x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,420x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,430x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a47581744]4546var W = new Array(160)4748function Sha512() {49this.init()50this._w = W5152Hash.call(this, 128, 112)53}5455inherits(Sha512, Hash)5657Sha512.prototype.init = function () {58this._a = 0x6a09e667|059this._b = 0xbb67ae85|060this._c = 0x3c6ef372|061this._d = 0xa54ff53a|062this._e = 0x510e527f|063this._f = 0x9b05688c|064this._g = 0x1f83d9ab|065this._h = 0x5be0cd19|06667this._al = 0xf3bcc908|068this._bl = 0x84caa73b|069this._cl = 0xfe94f82b|070this._dl = 0x5f1d36f1|071this._el = 0xade682d1|072this._fl = 0x2b3e6c1f|073this._gl = 0xfb41bd6b|074this._hl = 0x137e2179|07576return this77}7879function S (X, Xl, n) {80return (X >>> n) | (Xl << (32 - n))81}8283function Ch (x, y, z) {84return ((x & y) ^ ((~x) & z));85}8687function Maj (x, y, z) {88return ((x & y) ^ (x & z) ^ (y & z));89}9091Sha512.prototype._update = function(M) {92var W = this._w9394var a = this._a | 095var b = this._b | 096var c = this._c | 097var d = this._d | 098var e = this._e | 099var f = this._f | 0100var g = this._g | 0101var h = this._h | 0102103var al = this._al | 0104var bl = this._bl | 0105var cl = this._cl | 0106var dl = this._dl | 0107var el = this._el | 0108var fl = this._fl | 0109var gl = this._gl | 0110var hl = this._hl | 0111112var i = 0, j = 0113var Wi, Wil114function calcW() {115var x = W[j - 15*2]116var xl = W[j - 15*2 + 1]117var gamma0 = S(x, xl, 1) ^ S(x, xl, 8) ^ (x >>> 7)118var gamma0l = S(xl, x, 1) ^ S(xl, x, 8) ^ S(xl, x, 7)119120x = W[j - 2*2]121xl = W[j - 2*2 + 1]122var gamma1 = S(x, xl, 19) ^ S(xl, x, 29) ^ (x >>> 6)123var gamma1l = S(xl, x, 19) ^ S(x, xl, 29) ^ S(xl, x, 6)124125// W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]126var Wi7 = W[j - 7*2]127var Wi7l = W[j - 7*2 + 1]128129var Wi16 = W[j - 16*2]130var Wi16l = W[j - 16*2 + 1]131132Wil = gamma0l + Wi7l133Wi = gamma0 + Wi7 + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0)134Wil = Wil + gamma1l135Wi = Wi + gamma1 + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0)136Wil = Wil + Wi16l137Wi = Wi + Wi16 + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0)138}139140function loop() {141W[j] = Wi142W[j + 1] = Wil143144var maj = Maj(a, b, c)145var majl = Maj(al, bl, cl)146147var sigma0h = S(a, al, 28) ^ S(al, a, 2) ^ S(al, a, 7)148var sigma0l = S(al, a, 28) ^ S(a, al, 2) ^ S(a, al, 7)149var sigma1h = S(e, el, 14) ^ S(e, el, 18) ^ S(el, e, 9)150var sigma1l = S(el, e, 14) ^ S(el, e, 18) ^ S(e, el, 9)151152// t1 = h + sigma1 + ch + K[i] + W[i]153var Ki = K[j]154var Kil = K[j + 1]155156var ch = Ch(e, f, g)157var chl = Ch(el, fl, gl)158159var t1l = hl + sigma1l160var t1 = h + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0)161t1l = t1l + chl162t1 = t1 + ch + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0)163t1l = t1l + Kil164t1 = t1 + Ki + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0)165t1l = t1l + Wil166t1 = t1 + Wi + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0)167168// t2 = sigma0 + maj169var t2l = sigma0l + majl170var t2 = sigma0h + maj + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0)171172h = g173hl = gl174g = f175gl = fl176f = e177fl = el178el = (dl + t1l) | 0179e = (d + t1 + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0180d = c181dl = cl182c = b183cl = bl184b = a185bl = al186al = (t1l + t2l) | 0187a = (t1 + t2 + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0188189i++190j += 2191}192193while (i < 16) {194Wi = M.readInt32BE(j * 4)195Wil = M.readInt32BE(j * 4 + 4)196197loop()198}199200while (i < 80) {201calcW()202loop()203}204205this._al = (this._al + al) | 0206this._bl = (this._bl + bl) | 0207this._cl = (this._cl + cl) | 0208this._dl = (this._dl + dl) | 0209this._el = (this._el + el) | 0210this._fl = (this._fl + fl) | 0211this._gl = (this._gl + gl) | 0212this._hl = (this._hl + hl) | 0213214this._a = (this._a + a + ((this._al >>> 0) < (al >>> 0) ? 1 : 0)) | 0215this._b = (this._b + b + ((this._bl >>> 0) < (bl >>> 0) ? 1 : 0)) | 0216this._c = (this._c + c + ((this._cl >>> 0) < (cl >>> 0) ? 1 : 0)) | 0217this._d = (this._d + d + ((this._dl >>> 0) < (dl >>> 0) ? 1 : 0)) | 0218this._e = (this._e + e + ((this._el >>> 0) < (el >>> 0) ? 1 : 0)) | 0219this._f = (this._f + f + ((this._fl >>> 0) < (fl >>> 0) ? 1 : 0)) | 0220this._g = (this._g + g + ((this._gl >>> 0) < (gl >>> 0) ? 1 : 0)) | 0221this._h = (this._h + h + ((this._hl >>> 0) < (hl >>> 0) ? 1 : 0)) | 0222}223224Sha512.prototype._hash = function () {225var H = new Buffer(64)226227function writeInt64BE(h, l, offset) {228H.writeInt32BE(h, offset)229H.writeInt32BE(l, offset + 4)230}231232writeInt64BE(this._a, this._al, 0)233writeInt64BE(this._b, this._bl, 8)234writeInt64BE(this._c, this._cl, 16)235writeInt64BE(this._d, this._dl, 24)236writeInt64BE(this._e, this._el, 32)237writeInt64BE(this._f, this._fl, 40)238writeInt64BE(this._g, this._gl, 48)239writeInt64BE(this._h, this._hl, 56)240241return H242}243244module.exports = Sha512245246247