forked from crdrost/sha3-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keccak32.min.js
1 lines (1 loc) · 1.05 KB
/
keccak32.min.js
1
keccak32=(function(){var a=[0,10,20,5,15,16,1,11,21,6,7,17,2,12,22,23,8,18,3,13,14,24,9,19,4],R="1,8082,808a,80008000,808b,80000001,80008081,8009,8a,88,80008009,8000000a,8000808b,8b,8089,8003,8002,80,800a,8000000a,80008081,8080".split(",").map(function(i){return parseInt(i,16)}),r=[0,1,30,28,27,4,12,6,23,20,3,10,11,25,7,9,13,15,21,8,18,2,29,24,14],c=function(s,n){return(s<<n)|(s>>>(32-n))},h=function(n){return("00"+n.toString(16)).slice(-2)},o=function(n){return h(n&255)+h(n>>>8)+h(n>>>16)+h(n>>>24)};return function(m){var i,b,k,x,y,C=[],D=[],p,n=[],s;s=[];for(i=0;i<25;i++)s[i]=0;if(m.length%16==15)m+="\u8001";else{m+="\x01";while(m.length%16!=15)m+="\0";m+="\u8000"}for(b=0;b<m.length;b+=16){for(k=0;k<16;k+=2)s[k/2]^=m.charCodeAt(b+k)+m.charCodeAt(b+k+1)*65536;for(p=0;p<22;p++){for(x=0;x<5;x++)C[x]=s[x]^s[x+5]^s[x+10]^s[x+15]^s[x+20];for(x=0;x<5;x++)D[x]=C[(x+4)%5]^c(C[(x+1)%5],1);for(i=0;i<25;i++)n[a[i]]=c(s[i]^D[i%5],r[i]);for(x=0;x<5;x++)for(y=0;y<25;y+=5)s[y+x]=n[y+x]^((~n[y+(x+1)%5])&(n[y+(x+2)%5]));s[0]^=R[p]}}return s.slice(0,8).map(o).join("")}}());