react / wstein / node_modules / browserify / node_modules / crypto-browserify / node_modules / browserify-sign / node_modules / elliptic / node_modules / hash.js / lib / hash / ripemd.js
80644 viewsvar hash = require('../hash');1var utils = hash.utils;23var rotl32 = utils.rotl32;4var sum32 = utils.sum32;5var sum32_3 = utils.sum32_3;6var sum32_4 = utils.sum32_4;7var BlockHash = hash.common.BlockHash;89function RIPEMD160() {10if (!(this instanceof RIPEMD160))11return new RIPEMD160();1213BlockHash.call(this);1415this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ];16this.endian = 'little';17}18utils.inherits(RIPEMD160, BlockHash);19exports.ripemd160 = RIPEMD160;2021RIPEMD160.blockSize = 512;22RIPEMD160.outSize = 160;23RIPEMD160.hmacStrength = 192;24RIPEMD160.padLength = 64;2526RIPEMD160.prototype._update = function update(msg, start) {27var A = this.h[0];28var B = this.h[1];29var C = this.h[2];30var D = this.h[3];31var E = this.h[4];32var Ah = A;33var Bh = B;34var Ch = C;35var Dh = D;36var Eh = E;37for (var j = 0; j < 80; j++) {38var T = sum32(39rotl32(40sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)),41s[j]),42E);43A = E;44E = D;45D = rotl32(C, 10);46C = B;47B = T;48T = sum32(49rotl32(50sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)),51sh[j]),52Eh);53Ah = Eh;54Eh = Dh;55Dh = rotl32(Ch, 10);56Ch = Bh;57Bh = T;58}59T = sum32_3(this.h[1], C, Dh);60this.h[1] = sum32_3(this.h[2], D, Eh);61this.h[2] = sum32_3(this.h[3], E, Ah);62this.h[3] = sum32_3(this.h[4], A, Bh);63this.h[4] = sum32_3(this.h[0], B, Ch);64this.h[0] = T;65};6667RIPEMD160.prototype._digest = function digest(enc) {68if (enc === 'hex')69return utils.toHex32(this.h, 'little');70else71return utils.split32(this.h, 'little');72};7374function f(j, x, y, z) {75if (j <= 15)76return x ^ y ^ z;77else if (j <= 31)78return (x & y) | ((~x) & z);79else if (j <= 47)80return (x | (~y)) ^ z;81else if (j <= 63)82return (x & z) | (y & (~z));83else84return x ^ (y | (~z));85}8687function K(j) {88if (j <= 15)89return 0x00000000;90else if (j <= 31)91return 0x5a827999;92else if (j <= 47)93return 0x6ed9eba1;94else if (j <= 63)95return 0x8f1bbcdc;96else97return 0xa953fd4e;98}99100function Kh(j) {101if (j <= 15)102return 0x50a28be6;103else if (j <= 31)104return 0x5c4dd124;105else if (j <= 47)106return 0x6d703ef3;107else if (j <= 63)108return 0x7a6d76e9;109else110return 0x00000000;111}112113var r = [1140, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,1157, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,1163, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,1171, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,1184, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13119];120121var rh = [1225, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,1236, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,12415, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,1258, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,12612, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11127];128129var s = [13011, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,1317, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,13211, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,13311, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,1349, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6135];136137var sh = [1388, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,1399, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,1409, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,14115, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,1428, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11143];144145146