-
Notifications
You must be signed in to change notification settings - Fork 41
/
blake2s.min.js
1 lines (1 loc) · 2.06 KB
/
blake2s.min.js
1
"use strict";function blake2s_core(r,e,a){function n(r,e,a,n,i,l){var o;k[r]=k[r]+k[e]+i,o=k[n]^k[r],k[n]=o>>>16|o<<16,k[a]=k[a]+k[n],o=k[e]^k[a],k[e]=o>>>12|o<<20,k[r]=k[r]+k[e]+l,o=k[n]^k[r],k[n]=o>>>8|o<<24,k[a]=k[a]+k[n],o=k[e]^k[a],k[e]=o>>>7|o<<25}var i,l,o=0,v=e.length,f=new Array(16),k=new Array(16),b=new Array(64),t=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0];for(i=0;i<8;i++)k[i]=r[i];if(v||!r[8])do{for(l=64,v<=64&&(l=v,a||(r[10]=-1)),r[8]+=l,i=0;i<l;i++)b[i]="string"==typeof e?e.charCodeAt(o+i):+e[o+i];for(;i<64;)b[i++]=0;for(i=0;i<64;i+=4)f[i>>2]=b[i]|b[i+1]<<8|b[i+2]<<16|b[i+3]<<24;for(k[8]=blake_iv[0],k[12]=r[8]^blake_iv[4],k[9]=blake_iv[1],k[13]=r[9]^blake_iv[5],k[10]=blake_iv[2],k[14]=r[10]^blake_iv[6],k[11]=blake_iv[3],k[15]=r[11]^blake_iv[7],i=0;i<160;i+=16)n(0,4,8,12,f[t[i+0]],f[t[i+1]]),n(1,5,9,13,f[t[i+2]],f[t[i+3]]),n(2,6,10,14,f[t[i+4]],f[t[i+5]]),n(3,7,11,15,f[t[i+6]],f[t[i+7]]),n(0,5,10,15,f[t[i+8]],f[t[i+9]]),n(1,6,11,12,f[t[i+10]],f[t[i+11]]),n(2,7,8,13,f[t[i+12]],f[t[i+13]]),n(3,4,9,14,f[t[i+14]],f[t[i+15]]);for(i=0;i<8;i++)r[i]^=k[i]^k[i+8],k[i]=r[i];o+=64,v-=64}while(v>0)}function Blake2s(r,e,a){var n=blake_iv.slice(0);n[0]^=16842784,a&&blake2s_core(n,a,64,r.length>0),blake2s_core(n,r,!1);for(var i=new Array(32),l=0;l<8;l++)i[4*l]=255&n[l],i[4*l+1]=n[l]>>8&255,i[4*l+2]=n[l]>>16&255,i[4*l+3]=n[l]>>>24;return"bin"==e?i:function(r,e){for(var a="",n="HEX"==e?"0123456789ABCDEF":"0123456789abcdef",i=0;i<32;i++)a+=n[r[i]>>4&15]+n[15&r[i]];return a}(i,e)}function Blake2s_HMAC(r,e,a){for(var n=new Array(64),i=new Array(64),l=0;l<64;l++){var o=l<32?255&e[l]:0;n[l]=54^o,i[l]=92^o}return Blake2s(Blake2s(r,"bin",n),a,i)}var blake_iv=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225,0,0,0,0];