react / wstein / node_modules / browserify / node_modules / crypto-browserify / node_modules / create-hash / node_modules / sha.js / sha1.js
80556 views/*1* A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined2* in FIPS PUB 180-13* Version 2.1a Copyright Paul Johnston 2000 - 2002.4* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet5* Distributed under the BSD License6* See http://pajhome.org.uk/crypt/md5 for details.7*/89var inherits = require('inherits')10var Hash = require('./hash')1112var W = new Array(80)1314function Sha1() {15this.init()16this._w = W1718Hash.call(this, 64, 56)19}2021inherits(Sha1, Hash)2223Sha1.prototype.init = function () {24this._a = 0x6745230125this._b = 0xefcdab8926this._c = 0x98badcfe27this._d = 0x1032547628this._e = 0xc3d2e1f02930return this31}3233/*34* Bitwise rotate a 32-bit number to the left.35*/36function rol(num, cnt) {37return (num << cnt) | (num >>> (32 - cnt));38}3940Sha1.prototype._update = function (M) {41var W = this._w4243var a = this._a44var b = this._b45var c = this._c46var d = this._d47var e = this._e4849var j = 0, k5051function calcW() { return rol(W[j - 3] ^ W[j - 8] ^ W[j - 14] ^ W[j - 16], 1) }52function loop(w, f) {53W[j] = w5455var t = rol(a, 5) + f + e + w + k5657e = d58d = c59c = rol(b, 30)60b = a61a = t62j++63}6465k = 151850024966while (j < 16) loop(M.readInt32BE(j * 4), (b & c) | ((~b) & d))67while (j < 20) loop(calcW(), (b & c) | ((~b) & d))68k = 185977539369while (j < 40) loop(calcW(), b ^ c ^ d)70k = -189400758871while (j < 60) loop(calcW(), (b & c) | (b & d) | (c & d))72k = -89949751473while (j < 80) loop(calcW(), b ^ c ^ d)7475this._a = (a + this._a) | 076this._b = (b + this._b) | 077this._c = (c + this._c) | 078this._d = (d + this._d) | 079this._e = (e + this._e) | 080}8182Sha1.prototype._hash = function () {83var H = new Buffer(20)8485H.writeInt32BE(this._a|0, 0)86H.writeInt32BE(this._b|0, 4)87H.writeInt32BE(this._c|0, 8)88H.writeInt32BE(this._d|0, 12)89H.writeInt32BE(this._e|0, 16)9091return H92}9394module.exports = Sha195969798