forked from crdrost/sha3-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keccak.min.js
1 lines (1 loc) · 2.05 KB
/
keccak.min.js
1
keccak=(function(){var c,S,L,p,Z,R,r,K;L=function(a,b){this.l=a?a:0;this.h=b?b:0};L.c=function(a){return new L(a.l,a.h)};L.prototype={X:function(a){this.l^=a.l;this.h^=a.h;return this},N:function(){return new L(~this.l,~this.h)},A:function(a){this.l&=a.l;this.h&=a.h;return this},C:function(n){var a,m;if(n>=32){a=this.l;this.l=this.h;this.h=a;n-=32}if(n===0){return this}m=32-n;a=(this.h<<n)+(this.l>>>m);this.l=(this.l<<n)+(this.h>>>m);this.h=a;return this},toString:(function(){var a,o;a=function(n){return("00"+n.toString(16)).slice(-2)};o=function(n){return a(n&255)+a(n>>>8)+a(n>>>16)+a(n>>>24)};return function(){return o(this.l)+o(this.h)}}())};Z=function(k){var i,z=[];for(i=0;i<k;i+=1){z[i]=new L()}return z};S=function(s){var a=function(x,y){return a.a[(x%5)+5*(y%5)]};a.a=s?s:Z(25);a.c=function(){return new S(a.a.map(L.c))};return a};p=[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="0,1;0,8082;z,808A;z,yy;0,808B;0,y0001;z,y8081;z,8009;0,8A;0,88;0,y8009;0,y000A;0,y808B;z,8B;z,8089;z,8003;z,8002;z,80;0,800A;z,y000A;z,y8081;z,8080;0,y0001;z,y8008".replace(/z/g,"80000000").replace(/y/g,"8000").split(";").map(function(a){var k=a.split(",");return new L(parseInt(k[1],16),parseInt(k[0],16))});r=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14];K=function(){var x,y,i,b,C,D,round,last;for(round=0;round<24;round+=1){C=Z(5);for(x=0;x<5;x+=1){for(y=0;y<5;y+=1){C[x].X(c(x,y))}}D=C.map(L.c);D=D.concat(D.splice(0,1));for(x=0;x<5;x+=1){D[x].C(1).X(C[(x+4)%5])}for(x=0;x<5;x+=1){for(y=0;y<5;y+=1){c(x,y).X(D[x])}}for(x=0;x<5;x+=1){for(y=0;y<5;y+=1){c(x,y).C(r[5*y+x])}}last=c.a.slice(0);for(i=0;i<25;i+=1){c.a[p[i]]=last[i]}b=c.c();for(x=0;x<5;x+=1){for(y=0;y<5;y+=1){c(x,y).X(b(x+1,y).N().A(b(x+2,y)))}}c(0,0).X(R[round])}};return function(m){c=new S();if(m.length%68===67){m+="\u8001"}else{m+="\x01";while(m.length%68!==67){m+="\0"}m+="\u8000"}var b,k;for(b=0;b<m.length;b+=68){for(k=0;k<68;k+=4){c.a[k/4].X(new L(m.charCodeAt(b+k)+m.charCodeAt(b+k+1)*65536,m.charCodeAt(b+k+2)+m.charCodeAt(b+k+3)*65536))}K()}return c.a.slice(0,4).join("")}}());