react / wstein / node_modules / browserify / node_modules / crypto-browserify / node_modules / create-hash / node_modules / sha.js / sha.js
80556 views/*1* A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined2* in FIPS PUB 180-13* This source code is derived from sha1.js of the same repository.4* The difference between SHA-0 and SHA-1 is just a bitwise rotate left5* operation was added.6*/78var inherits = require('inherits')9var Hash = require('./hash')1011var W = new Array(80)1213function Sha() {14this.init()15this._w = W1617Hash.call(this, 64, 56)18}1920inherits(Sha, Hash)2122Sha.prototype.init = function () {23this._a = 0x6745230124this._b = 0xefcdab8925this._c = 0x98badcfe26this._d = 0x1032547627this._e = 0xc3d2e1f02829return this30}3132/*33* Bitwise rotate a 32-bit number to the left.34*/35function rol(num, cnt) {36return (num << cnt) | (num >>> (32 - cnt));37}3839Sha.prototype._update = function (M) {40var W = this._w4142var a = this._a43var b = this._b44var c = this._c45var d = this._d46var e = this._e4748var j = 0, k4950/*51* SHA-1 has a bitwise rotate left operation. But, SHA is not52* function calcW() { return rol(W[j - 3] ^ W[j - 8] ^ W[j - 14] ^ W[j - 16], 1) }53*/54function calcW() { return W[j - 3] ^ W[j - 8] ^ W[j - 14] ^ W[j - 16] }55function loop(w, f) {56W[j] = w5758var t = rol(a, 5) + f + e + w + k5960e = d61d = c62c = rol(b, 30)63b = a64a = t65j++66}6768k = 151850024969while (j < 16) loop(M.readInt32BE(j * 4), (b & c) | ((~b) & d))70while (j < 20) loop(calcW(), (b & c) | ((~b) & d))71k = 185977539372while (j < 40) loop(calcW(), b ^ c ^ d)73k = -189400758874while (j < 60) loop(calcW(), (b & c) | (b & d) | (c & d))75k = -89949751476while (j < 80) loop(calcW(), b ^ c ^ d)7778this._a = (a + this._a) | 079this._b = (b + this._b) | 080this._c = (c + this._c) | 081this._d = (d + this._d) | 082this._e = (e + this._e) | 083}8485Sha.prototype._hash = function () {86var H = new Buffer(20)8788H.writeInt32BE(this._a|0, 0)89H.writeInt32BE(this._b|0, 4)90H.writeInt32BE(this._c|0, 8)91H.writeInt32BE(this._d|0, 12)92H.writeInt32BE(this._e|0, 16)9394return H95}9697module.exports = Sha9899100101