@basmilius/apple-encryption 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,2 +1,3254 @@
1
- import{i as e,n as t,r as n,t as r}from"./chunk-tuRmWmEN.mjs";import{hkdfSync as i}from"node:crypto";Number.isInteger,Number.isSafeInteger;function a(e,t=new Uint8Array(4),n=0){return t[n+0]=e>>>0,t[n+1]=e>>>8,t[n+2]=e>>>16,t[n+3]=e>>>24,t}function o(e,t=new Uint8Array(8),n=0){return a(e>>>0,t,n),a(e/4294967296>>>0,t,n+4),t}function s(e){for(let t=0;t<e.length;t++)e[t]=0;return e}function c(e,t,n){let r=1634760805,i=857760878,o=2036477234,s=1797285236,c=n[3]<<24|n[2]<<16|n[1]<<8|n[0],l=n[7]<<24|n[6]<<16|n[5]<<8|n[4],u=n[11]<<24|n[10]<<16|n[9]<<8|n[8],d=n[15]<<24|n[14]<<16|n[13]<<8|n[12],f=n[19]<<24|n[18]<<16|n[17]<<8|n[16],p=n[23]<<24|n[22]<<16|n[21]<<8|n[20],m=n[27]<<24|n[26]<<16|n[25]<<8|n[24],h=n[31]<<24|n[30]<<16|n[29]<<8|n[28],g=t[3]<<24|t[2]<<16|t[1]<<8|t[0],_=t[7]<<24|t[6]<<16|t[5]<<8|t[4],v=t[11]<<24|t[10]<<16|t[9]<<8|t[8],y=t[15]<<24|t[14]<<16|t[13]<<8|t[12],b=r,x=i,S=o,C=s,w=c,T=l,E=u,D=d,O=f,k=p,A=m,j=h,M=g,N=_,P=v,F=y;for(let e=0;e<20;e+=2)b=b+w|0,M^=b,M=M>>>16|M<<16,O=O+M|0,w^=O,w=w>>>20|w<<12,x=x+T|0,N^=x,N=N>>>16|N<<16,k=k+N|0,T^=k,T=T>>>20|T<<12,S=S+E|0,P^=S,P=P>>>16|P<<16,A=A+P|0,E^=A,E=E>>>20|E<<12,C=C+D|0,F^=C,F=F>>>16|F<<16,j=j+F|0,D^=j,D=D>>>20|D<<12,S=S+E|0,P^=S,P=P>>>24|P<<8,A=A+P|0,E^=A,E=E>>>25|E<<7,C=C+D|0,F^=C,F=F>>>24|F<<8,j=j+F|0,D^=j,D=D>>>25|D<<7,x=x+T|0,N^=x,N=N>>>24|N<<8,k=k+N|0,T^=k,T=T>>>25|T<<7,b=b+w|0,M^=b,M=M>>>24|M<<8,O=O+M|0,w^=O,w=w>>>25|w<<7,b=b+T|0,F^=b,F=F>>>16|F<<16,A=A+F|0,T^=A,T=T>>>20|T<<12,x=x+E|0,M^=x,M=M>>>16|M<<16,j=j+M|0,E^=j,E=E>>>20|E<<12,S=S+D|0,N^=S,N=N>>>16|N<<16,O=O+N|0,D^=O,D=D>>>20|D<<12,C=C+w|0,P^=C,P=P>>>16|P<<16,k=k+P|0,w^=k,w=w>>>20|w<<12,S=S+D|0,N^=S,N=N>>>24|N<<8,O=O+N|0,D^=O,D=D>>>25|D<<7,C=C+w|0,P^=C,P=P>>>24|P<<8,k=k+P|0,w^=k,w=w>>>25|w<<7,x=x+E|0,M^=x,M=M>>>24|M<<8,j=j+M|0,E^=j,E=E>>>25|E<<7,b=b+T|0,F^=b,F=F>>>24|F<<8,A=A+F|0,T^=A,T=T>>>25|T<<7;a(b+r|0,e,0),a(x+i|0,e,4),a(S+o|0,e,8),a(C+s|0,e,12),a(w+c|0,e,16),a(T+l|0,e,20),a(E+u|0,e,24),a(D+d|0,e,28),a(O+f|0,e,32),a(k+p|0,e,36),a(A+m|0,e,40),a(j+h|0,e,44),a(M+g|0,e,48),a(N+_|0,e,52),a(P+v|0,e,56),a(F+y|0,e,60)}function l(e,t,n,r,i=0){if(e.length!==32)throw Error(`ChaCha: key size must be 32 bytes`);if(r.length<n.length)throw Error(`ChaCha: destination is shorter than source`);let a,o;if(i===0){if(t.length!==8&&t.length!==12)throw Error(`ChaCha nonce must be 8 or 12 bytes`);a=new Uint8Array(16),o=a.length-t.length,a.set(t,o)}else{if(t.length!==16)throw Error(`ChaCha nonce with counter must be 16 bytes`);a=t,o=i}let l=new Uint8Array(64);for(let t=0;t<n.length;t+=64){c(l,a,e);for(let e=t;e<t+64&&e<n.length;e++)r[e]=n[e]^l[e-t];d(a,0,o)}return s(l),i===0&&s(a),r}function u(e,t,n,r=0){return s(n),l(e,t,n,n,r)}function d(e,t,n){let r=1;for(;n--;)r=r+(e[t]&255)|0,e[t]=r&255,r>>>=8,t++;if(r>0)throw Error(`ChaCha: counter overflow`)}function f(e,t){if(e.length!==t.length)return 0;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return 1&n-1>>>8}function p(e,t){return e.length===0||t.length===0?!1:f(e,t)!==0}var m=class{digestLength=16;_buffer=new Uint8Array(16);_r=new Uint16Array(10);_h=new Uint16Array(10);_pad=new Uint16Array(8);_leftover=0;_fin=0;_finished=!1;constructor(e){let t=e[0]|e[1]<<8;this._r[0]=t&8191;let n=e[2]|e[3]<<8;this._r[1]=(t>>>13|n<<3)&8191;let r=e[4]|e[5]<<8;this._r[2]=(n>>>10|r<<6)&7939;let i=e[6]|e[7]<<8;this._r[3]=(r>>>7|i<<9)&8191;let a=e[8]|e[9]<<8;this._r[4]=(i>>>4|a<<12)&255,this._r[5]=a>>>1&8190;let o=e[10]|e[11]<<8;this._r[6]=(a>>>14|o<<2)&8191;let s=e[12]|e[13]<<8;this._r[7]=(o>>>11|s<<5)&8065;let c=e[14]|e[15]<<8;this._r[8]=(s>>>8|c<<8)&8191,this._r[9]=c>>>5&127,this._pad[0]=e[16]|e[17]<<8,this._pad[1]=e[18]|e[19]<<8,this._pad[2]=e[20]|e[21]<<8,this._pad[3]=e[22]|e[23]<<8,this._pad[4]=e[24]|e[25]<<8,this._pad[5]=e[26]|e[27]<<8,this._pad[6]=e[28]|e[29]<<8,this._pad[7]=e[30]|e[31]<<8}_blocks(e,t,n){let r=this._fin?0:2048,i=this._h[0],a=this._h[1],o=this._h[2],s=this._h[3],c=this._h[4],l=this._h[5],u=this._h[6],d=this._h[7],f=this._h[8],p=this._h[9],m=this._r[0],h=this._r[1],g=this._r[2],_=this._r[3],v=this._r[4],y=this._r[5],b=this._r[6],x=this._r[7],S=this._r[8],C=this._r[9];for(;n>=16;){let w=e[t+0]|e[t+1]<<8;i+=w&8191;let T=e[t+2]|e[t+3]<<8;a+=(w>>>13|T<<3)&8191;let E=e[t+4]|e[t+5]<<8;o+=(T>>>10|E<<6)&8191;let D=e[t+6]|e[t+7]<<8;s+=(E>>>7|D<<9)&8191;let O=e[t+8]|e[t+9]<<8;c+=(D>>>4|O<<12)&8191,l+=O>>>1&8191;let k=e[t+10]|e[t+11]<<8;u+=(O>>>14|k<<2)&8191;let A=e[t+12]|e[t+13]<<8;d+=(k>>>11|A<<5)&8191;let j=e[t+14]|e[t+15]<<8;f+=(A>>>8|j<<8)&8191,p+=j>>>5|r;let M=0,N=M;N+=i*m,N+=5*C*a,N+=5*S*o,N+=5*x*s,N+=5*b*c,M=N>>>13,N&=8191,N+=5*y*l,N+=5*v*u,N+=5*_*d,N+=5*g*f,N+=5*h*p,M+=N>>>13,N&=8191;let P=M;P+=i*h,P+=a*m,P+=5*C*o,P+=5*S*s,P+=5*x*c,M=P>>>13,P&=8191,P+=5*b*l,P+=5*y*u,P+=5*v*d,P+=5*_*f,P+=5*g*p,M+=P>>>13,P&=8191;let F=M;F+=i*g,F+=a*h,F+=o*m,F+=5*C*s,F+=5*S*c,M=F>>>13,F&=8191,F+=5*x*l,F+=5*b*u,F+=5*y*d,F+=5*v*f,F+=5*_*p,M+=F>>>13,F&=8191;let I=M;I+=i*_,I+=a*g,I+=o*h,I+=s*m,I+=5*C*c,M=I>>>13,I&=8191,I+=5*S*l,I+=5*x*u,I+=5*b*d,I+=5*y*f,I+=5*v*p,M+=I>>>13,I&=8191;let L=M;L+=i*v,L+=a*_,L+=o*g,L+=s*h,L+=c*m,M=L>>>13,L&=8191,L+=5*C*l,L+=5*S*u,L+=5*x*d,L+=5*b*f,L+=5*y*p,M+=L>>>13,L&=8191;let R=M;R+=i*y,R+=a*v,R+=o*_,R+=s*g,R+=c*h,M=R>>>13,R&=8191,R+=l*m,R+=5*C*u,R+=5*S*d,R+=5*x*f,R+=5*b*p,M+=R>>>13,R&=8191;let z=M;z+=i*b,z+=a*y,z+=o*v,z+=s*_,z+=c*g,M=z>>>13,z&=8191,z+=l*h,z+=u*m,z+=5*C*d,z+=5*S*f,z+=5*x*p,M+=z>>>13,z&=8191;let B=M;B+=i*x,B+=a*b,B+=o*y,B+=s*v,B+=c*_,M=B>>>13,B&=8191,B+=l*g,B+=u*h,B+=d*m,B+=5*C*f,B+=5*S*p,M+=B>>>13,B&=8191;let V=M;V+=i*S,V+=a*x,V+=o*b,V+=s*y,V+=c*v,M=V>>>13,V&=8191,V+=l*_,V+=u*g,V+=d*h,V+=f*m,V+=5*C*p,M+=V>>>13,V&=8191;let H=M;H+=i*C,H+=a*S,H+=o*x,H+=s*b,H+=c*y,M=H>>>13,H&=8191,H+=l*v,H+=u*_,H+=d*g,H+=f*h,H+=p*m,M+=H>>>13,H&=8191,M=(M<<2)+M|0,M=M+N|0,N=M&8191,M>>>=13,P+=M,i=N,a=P,o=F,s=I,c=L,l=R,u=z,d=B,f=V,p=H,t+=16,n-=16}this._h[0]=i,this._h[1]=a,this._h[2]=o,this._h[3]=s,this._h[4]=c,this._h[5]=l,this._h[6]=u,this._h[7]=d,this._h[8]=f,this._h[9]=p}finish(e,t=0){let n=new Uint16Array(10),r,i,a,o;if(this._leftover){for(o=this._leftover,this._buffer[o++]=1;o<16;o++)this._buffer[o]=0;this._fin=1,this._blocks(this._buffer,0,16)}for(r=this._h[1]>>>13,this._h[1]&=8191,o=2;o<10;o++)this._h[o]+=r,r=this._h[o]>>>13,this._h[o]&=8191;for(this._h[0]+=r*5,r=this._h[0]>>>13,this._h[0]&=8191,this._h[1]+=r,r=this._h[1]>>>13,this._h[1]&=8191,this._h[2]+=r,n[0]=this._h[0]+5,r=n[0]>>>13,n[0]&=8191,o=1;o<10;o++)n[o]=this._h[o]+r,r=n[o]>>>13,n[o]&=8191;for(n[9]-=8192,i=(r^1)-1,o=0;o<10;o++)n[o]&=i;for(i=~i,o=0;o<10;o++)this._h[o]=this._h[o]&i|n[o];for(this._h[0]=(this._h[0]|this._h[1]<<13)&65535,this._h[1]=(this._h[1]>>>3|this._h[2]<<10)&65535,this._h[2]=(this._h[2]>>>6|this._h[3]<<7)&65535,this._h[3]=(this._h[3]>>>9|this._h[4]<<4)&65535,this._h[4]=(this._h[4]>>>12|this._h[5]<<1|this._h[6]<<14)&65535,this._h[5]=(this._h[6]>>>2|this._h[7]<<11)&65535,this._h[6]=(this._h[7]>>>5|this._h[8]<<8)&65535,this._h[7]=(this._h[8]>>>8|this._h[9]<<5)&65535,a=this._h[0]+this._pad[0],this._h[0]=a&65535,o=1;o<8;o++)a=(this._h[o]+this._pad[o]|0)+(a>>>16)|0,this._h[o]=a&65535;return e[t+0]=this._h[0]>>>0,e[t+1]=this._h[0]>>>8,e[t+2]=this._h[1]>>>0,e[t+3]=this._h[1]>>>8,e[t+4]=this._h[2]>>>0,e[t+5]=this._h[2]>>>8,e[t+6]=this._h[3]>>>0,e[t+7]=this._h[3]>>>8,e[t+8]=this._h[4]>>>0,e[t+9]=this._h[4]>>>8,e[t+10]=this._h[5]>>>0,e[t+11]=this._h[5]>>>8,e[t+12]=this._h[6]>>>0,e[t+13]=this._h[6]>>>8,e[t+14]=this._h[7]>>>0,e[t+15]=this._h[7]>>>8,this._finished=!0,this}update(e){let t=0,n=e.length,r;if(this._leftover){r=16-this._leftover,r>n&&(r=n);for(let n=0;n<r;n++)this._buffer[this._leftover+n]=e[t+n];if(n-=r,t+=r,this._leftover+=r,this._leftover<16)return this;this._blocks(this._buffer,0,16),this._leftover=0}if(n>=16&&(r=n-n%16,this._blocks(e,t,r),t+=r,n-=r),n){for(let r=0;r<n;r++)this._buffer[this._leftover+r]=e[t+r];this._leftover+=n}return this}digest(){if(this._finished)throw Error(`Poly1305 was finished`);let e=new Uint8Array(16);return this.finish(e),e}clean(){return s(this._buffer),s(this._r),s(this._h),s(this._pad),this._leftover=0,this._fin=0,this._finished=!0,this}};const h=new Uint8Array(16);var g=class{nonceLength=12;tagLength=16;_key;constructor(e){if(e.length!==32)throw Error(`ChaCha20Poly1305 needs 32-byte key`);this._key=new Uint8Array(e)}seal(e,t,n,r){if(e.length>16)throw Error(`ChaCha20Poly1305: incorrect nonce length`);let i=new Uint8Array(16);i.set(e,i.length-e.length);let a=new Uint8Array(32);u(this._key,i,a,4);let o=t.length+this.tagLength,c;if(r){if(r.length!==o)throw Error(`ChaCha20Poly1305: incorrect destination length`);c=r}else c=new Uint8Array(o);return l(this._key,i,t,c,4),this._authenticate(c.subarray(c.length-this.tagLength,c.length),a,c.subarray(0,c.length-this.tagLength),n),s(i),c}open(e,t,n,r){if(e.length>16)throw Error(`ChaCha20Poly1305: incorrect nonce length`);if(t.length<this.tagLength)return null;let i=new Uint8Array(16);i.set(e,i.length-e.length);let a=new Uint8Array(32);u(this._key,i,a,4);let o=new Uint8Array(this.tagLength);if(this._authenticate(o,a,t.subarray(0,t.length-this.tagLength),n),!p(o,t.subarray(t.length-this.tagLength,t.length)))return null;let c=t.length-this.tagLength,d;if(r){if(r.length!==c)throw Error(`ChaCha20Poly1305: incorrect destination length`);d=r}else d=new Uint8Array(c);return l(this._key,i,t.subarray(0,t.length-this.tagLength),d,4),s(i),d}clean(){return s(this._key),this}_authenticate(e,t,n,r){let i=new m(t);r&&(i.update(r),r.length%16>0&&i.update(h.subarray(r.length%16))),i.update(n),n.length%16>0&&i.update(h.subarray(n.length%16));let a=new Uint8Array(8);r&&o(r.length,a),i.update(a),o(n.length,a),i.update(a);let c=i.digest();for(let t=0;t<c.length;t++)e[t]=c[t];i.clean(),s(c),s(a)}},_=t({CHACHA20_AUTH_TAG_LENGTH:()=>v,CHACHA20_NONCE_LENGTH:()=>y,decrypt:()=>b,encrypt:()=>x,padNonce:()=>S});const v=16,y=12;function b(e,t,n,r,i){t=S(t);let a=new g(e),o=Buffer.concat([r,i]),s=a.open(t,o,n??void 0);if(!s)throw Error(`Decryption failed: authentication tag mismatch`);return Buffer.from(s)}function x(e,t,n,r){t=S(t);let i=new g(e).seal(t,r,n??void 0);return{ciphertext:Buffer.from(i.subarray(0,i.length-16)),authTag:Buffer.from(i.subarray(i.length-16))}}function S(e){return e.length>=12?e:Buffer.concat([Buffer.alloc(12-e.length,0),e])}var C=r(((e,t)=>{(function(e){var t=function(e){var t,n=new Float64Array(16);if(e)for(t=0;t<e.length;t++)n[t]=e[t];return n},r=function(){throw Error(`no PRNG`)},i=new Uint8Array(16),a=new Uint8Array(32);a[0]=9;var o=t(),s=t([1]),c=t([56129,1]),l=t([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),u=t([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),d=t([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),f=t([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),p=t([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function m(e,t,n,r){e[t]=n>>24&255,e[t+1]=n>>16&255,e[t+2]=n>>8&255,e[t+3]=n&255,e[t+4]=r>>24&255,e[t+5]=r>>16&255,e[t+6]=r>>8&255,e[t+7]=r&255}function h(e,t,n,r,i){var a,o=0;for(a=0;a<i;a++)o|=e[t+a]^n[r+a];return(1&o-1>>>8)-1}function g(e,t,n,r){return h(e,t,n,r,16)}function _(e,t,n,r){return h(e,t,n,r,32)}function v(e,t,n,r){for(var i=r[0]&255|(r[1]&255)<<8|(r[2]&255)<<16|(r[3]&255)<<24,a=n[0]&255|(n[1]&255)<<8|(n[2]&255)<<16|(n[3]&255)<<24,o=n[4]&255|(n[5]&255)<<8|(n[6]&255)<<16|(n[7]&255)<<24,s=n[8]&255|(n[9]&255)<<8|(n[10]&255)<<16|(n[11]&255)<<24,c=n[12]&255|(n[13]&255)<<8|(n[14]&255)<<16|(n[15]&255)<<24,l=r[4]&255|(r[5]&255)<<8|(r[6]&255)<<16|(r[7]&255)<<24,u=t[0]&255|(t[1]&255)<<8|(t[2]&255)<<16|(t[3]&255)<<24,d=t[4]&255|(t[5]&255)<<8|(t[6]&255)<<16|(t[7]&255)<<24,f=t[8]&255|(t[9]&255)<<8|(t[10]&255)<<16|(t[11]&255)<<24,p=t[12]&255|(t[13]&255)<<8|(t[14]&255)<<16|(t[15]&255)<<24,m=r[8]&255|(r[9]&255)<<8|(r[10]&255)<<16|(r[11]&255)<<24,h=n[16]&255|(n[17]&255)<<8|(n[18]&255)<<16|(n[19]&255)<<24,g=n[20]&255|(n[21]&255)<<8|(n[22]&255)<<16|(n[23]&255)<<24,_=n[24]&255|(n[25]&255)<<8|(n[26]&255)<<16|(n[27]&255)<<24,v=n[28]&255|(n[29]&255)<<8|(n[30]&255)<<16|(n[31]&255)<<24,y=r[12]&255|(r[13]&255)<<8|(r[14]&255)<<16|(r[15]&255)<<24,b=i,x=a,S=o,C=s,w=c,T=l,E=u,D=d,O=f,k=p,A=m,j=h,M=g,N=_,P=v,F=y,I,L=0;L<20;L+=2)I=b+M|0,w^=I<<7|I>>>25,I=w+b|0,O^=I<<9|I>>>23,I=O+w|0,M^=I<<13|I>>>19,I=M+O|0,b^=I<<18|I>>>14,I=T+x|0,k^=I<<7|I>>>25,I=k+T|0,N^=I<<9|I>>>23,I=N+k|0,x^=I<<13|I>>>19,I=x+N|0,T^=I<<18|I>>>14,I=A+E|0,P^=I<<7|I>>>25,I=P+A|0,S^=I<<9|I>>>23,I=S+P|0,E^=I<<13|I>>>19,I=E+S|0,A^=I<<18|I>>>14,I=F+j|0,C^=I<<7|I>>>25,I=C+F|0,D^=I<<9|I>>>23,I=D+C|0,j^=I<<13|I>>>19,I=j+D|0,F^=I<<18|I>>>14,I=b+C|0,x^=I<<7|I>>>25,I=x+b|0,S^=I<<9|I>>>23,I=S+x|0,C^=I<<13|I>>>19,I=C+S|0,b^=I<<18|I>>>14,I=T+w|0,E^=I<<7|I>>>25,I=E+T|0,D^=I<<9|I>>>23,I=D+E|0,w^=I<<13|I>>>19,I=w+D|0,T^=I<<18|I>>>14,I=A+k|0,j^=I<<7|I>>>25,I=j+A|0,O^=I<<9|I>>>23,I=O+j|0,k^=I<<13|I>>>19,I=k+O|0,A^=I<<18|I>>>14,I=F+P|0,M^=I<<7|I>>>25,I=M+F|0,N^=I<<9|I>>>23,I=N+M|0,P^=I<<13|I>>>19,I=P+N|0,F^=I<<18|I>>>14;b=b+i|0,x=x+a|0,S=S+o|0,C=C+s|0,w=w+c|0,T=T+l|0,E=E+u|0,D=D+d|0,O=O+f|0,k=k+p|0,A=A+m|0,j=j+h|0,M=M+g|0,N=N+_|0,P=P+v|0,F=F+y|0,e[0]=b>>>0&255,e[1]=b>>>8&255,e[2]=b>>>16&255,e[3]=b>>>24&255,e[4]=x>>>0&255,e[5]=x>>>8&255,e[6]=x>>>16&255,e[7]=x>>>24&255,e[8]=S>>>0&255,e[9]=S>>>8&255,e[10]=S>>>16&255,e[11]=S>>>24&255,e[12]=C>>>0&255,e[13]=C>>>8&255,e[14]=C>>>16&255,e[15]=C>>>24&255,e[16]=w>>>0&255,e[17]=w>>>8&255,e[18]=w>>>16&255,e[19]=w>>>24&255,e[20]=T>>>0&255,e[21]=T>>>8&255,e[22]=T>>>16&255,e[23]=T>>>24&255,e[24]=E>>>0&255,e[25]=E>>>8&255,e[26]=E>>>16&255,e[27]=E>>>24&255,e[28]=D>>>0&255,e[29]=D>>>8&255,e[30]=D>>>16&255,e[31]=D>>>24&255,e[32]=O>>>0&255,e[33]=O>>>8&255,e[34]=O>>>16&255,e[35]=O>>>24&255,e[36]=k>>>0&255,e[37]=k>>>8&255,e[38]=k>>>16&255,e[39]=k>>>24&255,e[40]=A>>>0&255,e[41]=A>>>8&255,e[42]=A>>>16&255,e[43]=A>>>24&255,e[44]=j>>>0&255,e[45]=j>>>8&255,e[46]=j>>>16&255,e[47]=j>>>24&255,e[48]=M>>>0&255,e[49]=M>>>8&255,e[50]=M>>>16&255,e[51]=M>>>24&255,e[52]=N>>>0&255,e[53]=N>>>8&255,e[54]=N>>>16&255,e[55]=N>>>24&255,e[56]=P>>>0&255,e[57]=P>>>8&255,e[58]=P>>>16&255,e[59]=P>>>24&255,e[60]=F>>>0&255,e[61]=F>>>8&255,e[62]=F>>>16&255,e[63]=F>>>24&255}function y(e,t,n,r){for(var i=r[0]&255|(r[1]&255)<<8|(r[2]&255)<<16|(r[3]&255)<<24,a=n[0]&255|(n[1]&255)<<8|(n[2]&255)<<16|(n[3]&255)<<24,o=n[4]&255|(n[5]&255)<<8|(n[6]&255)<<16|(n[7]&255)<<24,s=n[8]&255|(n[9]&255)<<8|(n[10]&255)<<16|(n[11]&255)<<24,c=n[12]&255|(n[13]&255)<<8|(n[14]&255)<<16|(n[15]&255)<<24,l=r[4]&255|(r[5]&255)<<8|(r[6]&255)<<16|(r[7]&255)<<24,u=t[0]&255|(t[1]&255)<<8|(t[2]&255)<<16|(t[3]&255)<<24,d=t[4]&255|(t[5]&255)<<8|(t[6]&255)<<16|(t[7]&255)<<24,f=t[8]&255|(t[9]&255)<<8|(t[10]&255)<<16|(t[11]&255)<<24,p=t[12]&255|(t[13]&255)<<8|(t[14]&255)<<16|(t[15]&255)<<24,m=r[8]&255|(r[9]&255)<<8|(r[10]&255)<<16|(r[11]&255)<<24,h=n[16]&255|(n[17]&255)<<8|(n[18]&255)<<16|(n[19]&255)<<24,g=n[20]&255|(n[21]&255)<<8|(n[22]&255)<<16|(n[23]&255)<<24,_=n[24]&255|(n[25]&255)<<8|(n[26]&255)<<16|(n[27]&255)<<24,v=n[28]&255|(n[29]&255)<<8|(n[30]&255)<<16|(n[31]&255)<<24,y=r[12]&255|(r[13]&255)<<8|(r[14]&255)<<16|(r[15]&255)<<24,b=i,x=a,S=o,C=s,w=c,T=l,E=u,D=d,O=f,k=p,A=m,j=h,M=g,N=_,P=v,F=y,I,L=0;L<20;L+=2)I=b+M|0,w^=I<<7|I>>>25,I=w+b|0,O^=I<<9|I>>>23,I=O+w|0,M^=I<<13|I>>>19,I=M+O|0,b^=I<<18|I>>>14,I=T+x|0,k^=I<<7|I>>>25,I=k+T|0,N^=I<<9|I>>>23,I=N+k|0,x^=I<<13|I>>>19,I=x+N|0,T^=I<<18|I>>>14,I=A+E|0,P^=I<<7|I>>>25,I=P+A|0,S^=I<<9|I>>>23,I=S+P|0,E^=I<<13|I>>>19,I=E+S|0,A^=I<<18|I>>>14,I=F+j|0,C^=I<<7|I>>>25,I=C+F|0,D^=I<<9|I>>>23,I=D+C|0,j^=I<<13|I>>>19,I=j+D|0,F^=I<<18|I>>>14,I=b+C|0,x^=I<<7|I>>>25,I=x+b|0,S^=I<<9|I>>>23,I=S+x|0,C^=I<<13|I>>>19,I=C+S|0,b^=I<<18|I>>>14,I=T+w|0,E^=I<<7|I>>>25,I=E+T|0,D^=I<<9|I>>>23,I=D+E|0,w^=I<<13|I>>>19,I=w+D|0,T^=I<<18|I>>>14,I=A+k|0,j^=I<<7|I>>>25,I=j+A|0,O^=I<<9|I>>>23,I=O+j|0,k^=I<<13|I>>>19,I=k+O|0,A^=I<<18|I>>>14,I=F+P|0,M^=I<<7|I>>>25,I=M+F|0,N^=I<<9|I>>>23,I=N+M|0,P^=I<<13|I>>>19,I=P+N|0,F^=I<<18|I>>>14;e[0]=b>>>0&255,e[1]=b>>>8&255,e[2]=b>>>16&255,e[3]=b>>>24&255,e[4]=T>>>0&255,e[5]=T>>>8&255,e[6]=T>>>16&255,e[7]=T>>>24&255,e[8]=A>>>0&255,e[9]=A>>>8&255,e[10]=A>>>16&255,e[11]=A>>>24&255,e[12]=F>>>0&255,e[13]=F>>>8&255,e[14]=F>>>16&255,e[15]=F>>>24&255,e[16]=E>>>0&255,e[17]=E>>>8&255,e[18]=E>>>16&255,e[19]=E>>>24&255,e[20]=D>>>0&255,e[21]=D>>>8&255,e[22]=D>>>16&255,e[23]=D>>>24&255,e[24]=O>>>0&255,e[25]=O>>>8&255,e[26]=O>>>16&255,e[27]=O>>>24&255,e[28]=k>>>0&255,e[29]=k>>>8&255,e[30]=k>>>16&255,e[31]=k>>>24&255}function b(e,t,n,r){v(e,t,n,r)}function x(e,t,n,r){y(e,t,n,r)}var S=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function C(e,t,n,r,i,a,o){var s=new Uint8Array(16),c=new Uint8Array(64),l,u;for(u=0;u<16;u++)s[u]=0;for(u=0;u<8;u++)s[u]=a[u];for(;i>=64;){for(b(c,s,o,S),u=0;u<64;u++)e[t+u]=n[r+u]^c[u];for(l=1,u=8;u<16;u++)l=l+(s[u]&255)|0,s[u]=l&255,l>>>=8;i-=64,t+=64,r+=64}if(i>0)for(b(c,s,o,S),u=0;u<i;u++)e[t+u]=n[r+u]^c[u];return 0}function w(e,t,n,r,i){var a=new Uint8Array(16),o=new Uint8Array(64),s,c;for(c=0;c<16;c++)a[c]=0;for(c=0;c<8;c++)a[c]=r[c];for(;n>=64;){for(b(o,a,i,S),c=0;c<64;c++)e[t+c]=o[c];for(s=1,c=8;c<16;c++)s=s+(a[c]&255)|0,a[c]=s&255,s>>>=8;n-=64,t+=64}if(n>0)for(b(o,a,i,S),c=0;c<n;c++)e[t+c]=o[c];return 0}function T(e,t,n,r,i){var a=new Uint8Array(32);x(a,r,i,S);for(var o=new Uint8Array(8),s=0;s<8;s++)o[s]=r[s+16];return w(e,t,n,o,a)}function E(e,t,n,r,i,a,o){var s=new Uint8Array(32);x(s,a,o,S);for(var c=new Uint8Array(8),l=0;l<8;l++)c[l]=a[l+16];return C(e,t,n,r,i,c,s)}var D=function(e){this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.leftover=0,this.fin=0;var t=e[0]&255|(e[1]&255)<<8,n,r,i,a,o,s,c;this.r[0]=t&8191,n=e[2]&255|(e[3]&255)<<8,this.r[1]=(t>>>13|n<<3)&8191,r=e[4]&255|(e[5]&255)<<8,this.r[2]=(n>>>10|r<<6)&7939,i=e[6]&255|(e[7]&255)<<8,this.r[3]=(r>>>7|i<<9)&8191,a=e[8]&255|(e[9]&255)<<8,this.r[4]=(i>>>4|a<<12)&255,this.r[5]=a>>>1&8190,o=e[10]&255|(e[11]&255)<<8,this.r[6]=(a>>>14|o<<2)&8191,s=e[12]&255|(e[13]&255)<<8,this.r[7]=(o>>>11|s<<5)&8065,c=e[14]&255|(e[15]&255)<<8,this.r[8]=(s>>>8|c<<8)&8191,this.r[9]=c>>>5&127,this.pad[0]=e[16]&255|(e[17]&255)<<8,this.pad[1]=e[18]&255|(e[19]&255)<<8,this.pad[2]=e[20]&255|(e[21]&255)<<8,this.pad[3]=e[22]&255|(e[23]&255)<<8,this.pad[4]=e[24]&255|(e[25]&255)<<8,this.pad[5]=e[26]&255|(e[27]&255)<<8,this.pad[6]=e[28]&255|(e[29]&255)<<8,this.pad[7]=e[30]&255|(e[31]&255)<<8};D.prototype.blocks=function(e,t,n){for(var r=this.fin?0:2048,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C=this.h[0],w=this.h[1],T=this.h[2],E=this.h[3],D=this.h[4],O=this.h[5],k=this.h[6],A=this.h[7],j=this.h[8],M=this.h[9],N=this.r[0],P=this.r[1],F=this.r[2],I=this.r[3],L=this.r[4],R=this.r[5],z=this.r[6],B=this.r[7],V=this.r[8],H=this.r[9];n>=16;)i=e[t+0]&255|(e[t+1]&255)<<8,C+=i&8191,a=e[t+2]&255|(e[t+3]&255)<<8,w+=(i>>>13|a<<3)&8191,o=e[t+4]&255|(e[t+5]&255)<<8,T+=(a>>>10|o<<6)&8191,s=e[t+6]&255|(e[t+7]&255)<<8,E+=(o>>>7|s<<9)&8191,c=e[t+8]&255|(e[t+9]&255)<<8,D+=(s>>>4|c<<12)&8191,O+=c>>>1&8191,l=e[t+10]&255|(e[t+11]&255)<<8,k+=(c>>>14|l<<2)&8191,u=e[t+12]&255|(e[t+13]&255)<<8,A+=(l>>>11|u<<5)&8191,d=e[t+14]&255|(e[t+15]&255)<<8,j+=(u>>>8|d<<8)&8191,M+=d>>>5|r,f=0,p=f,p+=C*N,p+=5*H*w,p+=5*V*T,p+=5*B*E,p+=5*z*D,f=p>>>13,p&=8191,p+=5*R*O,p+=5*L*k,p+=5*I*A,p+=5*F*j,p+=5*P*M,f+=p>>>13,p&=8191,m=f,m+=C*P,m+=w*N,m+=5*H*T,m+=5*V*E,m+=5*B*D,f=m>>>13,m&=8191,m+=5*z*O,m+=5*R*k,m+=5*L*A,m+=5*I*j,m+=5*F*M,f+=m>>>13,m&=8191,h=f,h+=C*F,h+=w*P,h+=T*N,h+=5*H*E,h+=5*V*D,f=h>>>13,h&=8191,h+=5*B*O,h+=5*z*k,h+=5*R*A,h+=5*L*j,h+=5*I*M,f+=h>>>13,h&=8191,g=f,g+=C*I,g+=w*F,g+=T*P,g+=E*N,g+=5*H*D,f=g>>>13,g&=8191,g+=5*V*O,g+=5*B*k,g+=5*z*A,g+=5*R*j,g+=5*L*M,f+=g>>>13,g&=8191,_=f,_+=C*L,_+=w*I,_+=T*F,_+=E*P,_+=D*N,f=_>>>13,_&=8191,_+=5*H*O,_+=5*V*k,_+=5*B*A,_+=5*z*j,_+=5*R*M,f+=_>>>13,_&=8191,v=f,v+=C*R,v+=w*L,v+=T*I,v+=E*F,v+=D*P,f=v>>>13,v&=8191,v+=O*N,v+=5*H*k,v+=5*V*A,v+=5*B*j,v+=5*z*M,f+=v>>>13,v&=8191,y=f,y+=C*z,y+=w*R,y+=T*L,y+=E*I,y+=D*F,f=y>>>13,y&=8191,y+=O*P,y+=k*N,y+=5*H*A,y+=5*V*j,y+=5*B*M,f+=y>>>13,y&=8191,b=f,b+=C*B,b+=w*z,b+=T*R,b+=E*L,b+=D*I,f=b>>>13,b&=8191,b+=O*F,b+=k*P,b+=A*N,b+=5*H*j,b+=5*V*M,f+=b>>>13,b&=8191,x=f,x+=C*V,x+=w*B,x+=T*z,x+=E*R,x+=D*L,f=x>>>13,x&=8191,x+=O*I,x+=k*F,x+=A*P,x+=j*N,x+=5*H*M,f+=x>>>13,x&=8191,S=f,S+=C*H,S+=w*V,S+=T*B,S+=E*z,S+=D*R,f=S>>>13,S&=8191,S+=O*L,S+=k*I,S+=A*F,S+=j*P,S+=M*N,f+=S>>>13,S&=8191,f=(f<<2)+f|0,f=f+p|0,p=f&8191,f>>>=13,m+=f,C=p,w=m,T=h,E=g,D=_,O=v,k=y,A=b,j=x,M=S,t+=16,n-=16;this.h[0]=C,this.h[1]=w,this.h[2]=T,this.h[3]=E,this.h[4]=D,this.h[5]=O,this.h[6]=k,this.h[7]=A,this.h[8]=j,this.h[9]=M},D.prototype.finish=function(e,t){var n=new Uint16Array(10),r,i,a,o;if(this.leftover){for(o=this.leftover,this.buffer[o++]=1;o<16;o++)this.buffer[o]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(r=this.h[1]>>>13,this.h[1]&=8191,o=2;o<10;o++)this.h[o]+=r,r=this.h[o]>>>13,this.h[o]&=8191;for(this.h[0]+=r*5,r=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=r,r=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=r,n[0]=this.h[0]+5,r=n[0]>>>13,n[0]&=8191,o=1;o<10;o++)n[o]=this.h[o]+r,r=n[o]>>>13,n[o]&=8191;for(n[9]-=8192,i=(r^1)-1,o=0;o<10;o++)n[o]&=i;for(i=~i,o=0;o<10;o++)this.h[o]=this.h[o]&i|n[o];for(this.h[0]=(this.h[0]|this.h[1]<<13)&65535,this.h[1]=(this.h[1]>>>3|this.h[2]<<10)&65535,this.h[2]=(this.h[2]>>>6|this.h[3]<<7)&65535,this.h[3]=(this.h[3]>>>9|this.h[4]<<4)&65535,this.h[4]=(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14)&65535,this.h[5]=(this.h[6]>>>2|this.h[7]<<11)&65535,this.h[6]=(this.h[7]>>>5|this.h[8]<<8)&65535,this.h[7]=(this.h[8]>>>8|this.h[9]<<5)&65535,a=this.h[0]+this.pad[0],this.h[0]=a&65535,o=1;o<8;o++)a=(this.h[o]+this.pad[o]|0)+(a>>>16)|0,this.h[o]=a&65535;e[t+0]=this.h[0]>>>0&255,e[t+1]=this.h[0]>>>8&255,e[t+2]=this.h[1]>>>0&255,e[t+3]=this.h[1]>>>8&255,e[t+4]=this.h[2]>>>0&255,e[t+5]=this.h[2]>>>8&255,e[t+6]=this.h[3]>>>0&255,e[t+7]=this.h[3]>>>8&255,e[t+8]=this.h[4]>>>0&255,e[t+9]=this.h[4]>>>8&255,e[t+10]=this.h[5]>>>0&255,e[t+11]=this.h[5]>>>8&255,e[t+12]=this.h[6]>>>0&255,e[t+13]=this.h[6]>>>8&255,e[t+14]=this.h[7]>>>0&255,e[t+15]=this.h[7]>>>8&255},D.prototype.update=function(e,t,n){var r,i;if(this.leftover){for(i=16-this.leftover,i>n&&(i=n),r=0;r<i;r++)this.buffer[this.leftover+r]=e[t+r];if(n-=i,t+=i,this.leftover+=i,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(n>=16&&(i=n-n%16,this.blocks(e,t,i),t+=i,n-=i),n){for(r=0;r<n;r++)this.buffer[this.leftover+r]=e[t+r];this.leftover+=n}};function O(e,t,n,r,i,a){var o=new D(a);return o.update(n,r,i),o.finish(e,t),0}function k(e,t,n,r,i,a){var o=new Uint8Array(16);return O(o,0,n,r,i,a),g(e,t,o,0)}function A(e,t,n,r,i){var a;if(n<32)return-1;for(E(e,0,t,0,n,r,i),O(e,16,e,32,n-32,e),a=0;a<16;a++)e[a]=0;return 0}function j(e,t,n,r,i){var a,o=new Uint8Array(32);if(n<32||(T(o,0,32,r,i),k(t,16,t,32,n-32,o)!==0))return-1;for(E(e,0,t,0,n,r,i),a=0;a<32;a++)e[a]=0;return 0}function M(e,t){var n;for(n=0;n<16;n++)e[n]=t[n]|0}function N(e){var t,n,r=1;for(t=0;t<16;t++)n=e[t]+r+65535,r=Math.floor(n/65536),e[t]=n-r*65536;e[0]+=r-1+37*(r-1)}function P(e,t,n){for(var r,i=~(n-1),a=0;a<16;a++)r=i&(e[a]^t[a]),e[a]^=r,t[a]^=r}function F(e,n){var r,i,a,o=t(),s=t();for(r=0;r<16;r++)s[r]=n[r];for(N(s),N(s),N(s),i=0;i<2;i++){for(o[0]=s[0]-65517,r=1;r<15;r++)o[r]=s[r]-65535-(o[r-1]>>16&1),o[r-1]&=65535;o[15]=s[15]-32767-(o[14]>>16&1),a=o[15]>>16&1,o[14]&=65535,P(s,o,1-a)}for(r=0;r<16;r++)e[2*r]=s[r]&255,e[2*r+1]=s[r]>>8}function I(e,t){var n=new Uint8Array(32),r=new Uint8Array(32);return F(n,e),F(r,t),_(n,0,r,0)}function L(e){var t=new Uint8Array(32);return F(t,e),t[0]&1}function R(e,t){var n;for(n=0;n<16;n++)e[n]=t[2*n]+(t[2*n+1]<<8);e[15]&=32767}function z(e,t,n){for(var r=0;r<16;r++)e[r]=t[r]+n[r]}function B(e,t,n){for(var r=0;r<16;r++)e[r]=t[r]-n[r]}function V(e,t,n){var r,i,a=0,o=0,s=0,c=0,l=0,u=0,d=0,f=0,p=0,m=0,h=0,g=0,_=0,v=0,y=0,b=0,x=0,S=0,C=0,w=0,T=0,E=0,D=0,O=0,k=0,A=0,j=0,M=0,N=0,P=0,F=0,I=n[0],L=n[1],R=n[2],z=n[3],B=n[4],V=n[5],H=n[6],U=n[7],W=n[8],G=n[9],K=n[10],q=n[11],J=n[12],Y=n[13],X=n[14],Z=n[15];r=t[0],a+=r*I,o+=r*L,s+=r*R,c+=r*z,l+=r*B,u+=r*V,d+=r*H,f+=r*U,p+=r*W,m+=r*G,h+=r*K,g+=r*q,_+=r*J,v+=r*Y,y+=r*X,b+=r*Z,r=t[1],o+=r*I,s+=r*L,c+=r*R,l+=r*z,u+=r*B,d+=r*V,f+=r*H,p+=r*U,m+=r*W,h+=r*G,g+=r*K,_+=r*q,v+=r*J,y+=r*Y,b+=r*X,x+=r*Z,r=t[2],s+=r*I,c+=r*L,l+=r*R,u+=r*z,d+=r*B,f+=r*V,p+=r*H,m+=r*U,h+=r*W,g+=r*G,_+=r*K,v+=r*q,y+=r*J,b+=r*Y,x+=r*X,S+=r*Z,r=t[3],c+=r*I,l+=r*L,u+=r*R,d+=r*z,f+=r*B,p+=r*V,m+=r*H,h+=r*U,g+=r*W,_+=r*G,v+=r*K,y+=r*q,b+=r*J,x+=r*Y,S+=r*X,C+=r*Z,r=t[4],l+=r*I,u+=r*L,d+=r*R,f+=r*z,p+=r*B,m+=r*V,h+=r*H,g+=r*U,_+=r*W,v+=r*G,y+=r*K,b+=r*q,x+=r*J,S+=r*Y,C+=r*X,w+=r*Z,r=t[5],u+=r*I,d+=r*L,f+=r*R,p+=r*z,m+=r*B,h+=r*V,g+=r*H,_+=r*U,v+=r*W,y+=r*G,b+=r*K,x+=r*q,S+=r*J,C+=r*Y,w+=r*X,T+=r*Z,r=t[6],d+=r*I,f+=r*L,p+=r*R,m+=r*z,h+=r*B,g+=r*V,_+=r*H,v+=r*U,y+=r*W,b+=r*G,x+=r*K,S+=r*q,C+=r*J,w+=r*Y,T+=r*X,E+=r*Z,r=t[7],f+=r*I,p+=r*L,m+=r*R,h+=r*z,g+=r*B,_+=r*V,v+=r*H,y+=r*U,b+=r*W,x+=r*G,S+=r*K,C+=r*q,w+=r*J,T+=r*Y,E+=r*X,D+=r*Z,r=t[8],p+=r*I,m+=r*L,h+=r*R,g+=r*z,_+=r*B,v+=r*V,y+=r*H,b+=r*U,x+=r*W,S+=r*G,C+=r*K,w+=r*q,T+=r*J,E+=r*Y,D+=r*X,O+=r*Z,r=t[9],m+=r*I,h+=r*L,g+=r*R,_+=r*z,v+=r*B,y+=r*V,b+=r*H,x+=r*U,S+=r*W,C+=r*G,w+=r*K,T+=r*q,E+=r*J,D+=r*Y,O+=r*X,k+=r*Z,r=t[10],h+=r*I,g+=r*L,_+=r*R,v+=r*z,y+=r*B,b+=r*V,x+=r*H,S+=r*U,C+=r*W,w+=r*G,T+=r*K,E+=r*q,D+=r*J,O+=r*Y,k+=r*X,A+=r*Z,r=t[11],g+=r*I,_+=r*L,v+=r*R,y+=r*z,b+=r*B,x+=r*V,S+=r*H,C+=r*U,w+=r*W,T+=r*G,E+=r*K,D+=r*q,O+=r*J,k+=r*Y,A+=r*X,j+=r*Z,r=t[12],_+=r*I,v+=r*L,y+=r*R,b+=r*z,x+=r*B,S+=r*V,C+=r*H,w+=r*U,T+=r*W,E+=r*G,D+=r*K,O+=r*q,k+=r*J,A+=r*Y,j+=r*X,M+=r*Z,r=t[13],v+=r*I,y+=r*L,b+=r*R,x+=r*z,S+=r*B,C+=r*V,w+=r*H,T+=r*U,E+=r*W,D+=r*G,O+=r*K,k+=r*q,A+=r*J,j+=r*Y,M+=r*X,N+=r*Z,r=t[14],y+=r*I,b+=r*L,x+=r*R,S+=r*z,C+=r*B,w+=r*V,T+=r*H,E+=r*U,D+=r*W,O+=r*G,k+=r*K,A+=r*q,j+=r*J,M+=r*Y,N+=r*X,P+=r*Z,r=t[15],b+=r*I,x+=r*L,S+=r*R,C+=r*z,w+=r*B,T+=r*V,E+=r*H,D+=r*U,O+=r*W,k+=r*G,A+=r*K,j+=r*q,M+=r*J,N+=r*Y,P+=r*X,F+=r*Z,a+=38*x,o+=38*S,s+=38*C,c+=38*w,l+=38*T,u+=38*E,d+=38*D,f+=38*O,p+=38*k,m+=38*A,h+=38*j,g+=38*M,_+=38*N,v+=38*P,y+=38*F,i=1,r=a+i+65535,i=Math.floor(r/65536),a=r-i*65536,r=o+i+65535,i=Math.floor(r/65536),o=r-i*65536,r=s+i+65535,i=Math.floor(r/65536),s=r-i*65536,r=c+i+65535,i=Math.floor(r/65536),c=r-i*65536,r=l+i+65535,i=Math.floor(r/65536),l=r-i*65536,r=u+i+65535,i=Math.floor(r/65536),u=r-i*65536,r=d+i+65535,i=Math.floor(r/65536),d=r-i*65536,r=f+i+65535,i=Math.floor(r/65536),f=r-i*65536,r=p+i+65535,i=Math.floor(r/65536),p=r-i*65536,r=m+i+65535,i=Math.floor(r/65536),m=r-i*65536,r=h+i+65535,i=Math.floor(r/65536),h=r-i*65536,r=g+i+65535,i=Math.floor(r/65536),g=r-i*65536,r=_+i+65535,i=Math.floor(r/65536),_=r-i*65536,r=v+i+65535,i=Math.floor(r/65536),v=r-i*65536,r=y+i+65535,i=Math.floor(r/65536),y=r-i*65536,r=b+i+65535,i=Math.floor(r/65536),b=r-i*65536,a+=i-1+37*(i-1),i=1,r=a+i+65535,i=Math.floor(r/65536),a=r-i*65536,r=o+i+65535,i=Math.floor(r/65536),o=r-i*65536,r=s+i+65535,i=Math.floor(r/65536),s=r-i*65536,r=c+i+65535,i=Math.floor(r/65536),c=r-i*65536,r=l+i+65535,i=Math.floor(r/65536),l=r-i*65536,r=u+i+65535,i=Math.floor(r/65536),u=r-i*65536,r=d+i+65535,i=Math.floor(r/65536),d=r-i*65536,r=f+i+65535,i=Math.floor(r/65536),f=r-i*65536,r=p+i+65535,i=Math.floor(r/65536),p=r-i*65536,r=m+i+65535,i=Math.floor(r/65536),m=r-i*65536,r=h+i+65535,i=Math.floor(r/65536),h=r-i*65536,r=g+i+65535,i=Math.floor(r/65536),g=r-i*65536,r=_+i+65535,i=Math.floor(r/65536),_=r-i*65536,r=v+i+65535,i=Math.floor(r/65536),v=r-i*65536,r=y+i+65535,i=Math.floor(r/65536),y=r-i*65536,r=b+i+65535,i=Math.floor(r/65536),b=r-i*65536,a+=i-1+37*(i-1),e[0]=a,e[1]=o,e[2]=s,e[3]=c,e[4]=l,e[5]=u,e[6]=d,e[7]=f,e[8]=p,e[9]=m,e[10]=h,e[11]=g,e[12]=_,e[13]=v,e[14]=y,e[15]=b}function H(e,t){V(e,t,t)}function U(e,n){var r=t(),i;for(i=0;i<16;i++)r[i]=n[i];for(i=253;i>=0;i--)H(r,r),i!==2&&i!==4&&V(r,r,n);for(i=0;i<16;i++)e[i]=r[i]}function W(e,n){var r=t(),i;for(i=0;i<16;i++)r[i]=n[i];for(i=250;i>=0;i--)H(r,r),i!==1&&V(r,r,n);for(i=0;i<16;i++)e[i]=r[i]}function G(e,n,r){var i=new Uint8Array(32),a=new Float64Array(80),o,s,l=t(),u=t(),d=t(),f=t(),p=t(),m=t();for(s=0;s<31;s++)i[s]=n[s];for(i[31]=n[31]&127|64,i[0]&=248,R(a,r),s=0;s<16;s++)u[s]=a[s],f[s]=l[s]=d[s]=0;for(l[0]=f[0]=1,s=254;s>=0;--s)o=i[s>>>3]>>>(s&7)&1,P(l,u,o),P(d,f,o),z(p,l,d),B(l,l,d),z(d,u,f),B(u,u,f),H(f,p),H(m,l),V(l,d,l),V(d,u,p),z(p,l,d),B(l,l,d),H(u,l),B(d,f,m),V(l,d,c),z(l,l,f),V(d,d,l),V(l,f,m),V(f,u,a),H(u,p),P(l,u,o),P(d,f,o);for(s=0;s<16;s++)a[s+16]=l[s],a[s+32]=d[s],a[s+48]=u[s],a[s+64]=f[s];var h=a.subarray(32),g=a.subarray(16);return U(h,h),V(g,g,h),F(e,g),0}function K(e,t){return G(e,t,a)}function q(e,t){return r(t,32),K(e,t)}function J(e,t,n){var r=new Uint8Array(32);return G(r,n,t),x(e,i,r,S)}var Y=A,X=j;function Z(e,t,n,r,i,a){var o=new Uint8Array(32);return J(o,i,a),Y(e,t,n,r,o)}function ee(e,t,n,r,i,a){var o=new Uint8Array(32);return J(o,i,a),X(e,t,n,r,o)}var te=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function ne(e,t,n,r){for(var i=new Int32Array(16),a=new Int32Array(16),o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M=e[0],N=e[1],P=e[2],F=e[3],I=e[4],L=e[5],R=e[6],z=e[7],B=t[0],V=t[1],H=t[2],U=t[3],W=t[4],G=t[5],K=t[6],q=t[7],J=0;r>=128;){for(w=0;w<16;w++)T=8*w+J,i[w]=n[T+0]<<24|n[T+1]<<16|n[T+2]<<8|n[T+3],a[w]=n[T+4]<<24|n[T+5]<<16|n[T+6]<<8|n[T+7];for(w=0;w<80;w++)if(o=M,s=N,c=P,l=F,u=I,d=L,f=R,p=z,m=B,h=V,g=H,_=U,v=W,y=G,b=K,x=q,E=z,D=q,O=D&65535,k=D>>>16,A=E&65535,j=E>>>16,E=(I>>>14|W<<18)^(I>>>18|W<<14)^(W>>>9|I<<23),D=(W>>>14|I<<18)^(W>>>18|I<<14)^(I>>>9|W<<23),O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,E=I&L^~I&R,D=W&G^~W&K,O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,E=te[w*2],D=te[w*2+1],O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,E=i[w%16],D=a[w%16],O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,k+=O>>>16,A+=k>>>16,j+=A>>>16,S=A&65535|j<<16,C=O&65535|k<<16,E=S,D=C,O=D&65535,k=D>>>16,A=E&65535,j=E>>>16,E=(M>>>28|B<<4)^(B>>>2|M<<30)^(B>>>7|M<<25),D=(B>>>28|M<<4)^(M>>>2|B<<30)^(M>>>7|B<<25),O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,E=M&N^M&P^N&P,D=B&V^B&H^V&H,O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,k+=O>>>16,A+=k>>>16,j+=A>>>16,p=A&65535|j<<16,x=O&65535|k<<16,E=l,D=_,O=D&65535,k=D>>>16,A=E&65535,j=E>>>16,E=S,D=C,O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,k+=O>>>16,A+=k>>>16,j+=A>>>16,l=A&65535|j<<16,_=O&65535|k<<16,N=o,P=s,F=c,I=l,L=u,R=d,z=f,M=p,V=m,H=h,U=g,W=_,G=v,K=y,q=b,B=x,w%16==15)for(T=0;T<16;T++)E=i[T],D=a[T],O=D&65535,k=D>>>16,A=E&65535,j=E>>>16,E=i[(T+9)%16],D=a[(T+9)%16],O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,S=i[(T+1)%16],C=a[(T+1)%16],E=(S>>>1|C<<31)^(S>>>8|C<<24)^S>>>7,D=(C>>>1|S<<31)^(C>>>8|S<<24)^(C>>>7|S<<25),O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,S=i[(T+14)%16],C=a[(T+14)%16],E=(S>>>19|C<<13)^(C>>>29|S<<3)^S>>>6,D=(C>>>19|S<<13)^(S>>>29|C<<3)^(C>>>6|S<<26),O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,k+=O>>>16,A+=k>>>16,j+=A>>>16,i[T]=A&65535|j<<16,a[T]=O&65535|k<<16;E=M,D=B,O=D&65535,k=D>>>16,A=E&65535,j=E>>>16,E=e[0],D=t[0],O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,k+=O>>>16,A+=k>>>16,j+=A>>>16,e[0]=M=A&65535|j<<16,t[0]=B=O&65535|k<<16,E=N,D=V,O=D&65535,k=D>>>16,A=E&65535,j=E>>>16,E=e[1],D=t[1],O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,k+=O>>>16,A+=k>>>16,j+=A>>>16,e[1]=N=A&65535|j<<16,t[1]=V=O&65535|k<<16,E=P,D=H,O=D&65535,k=D>>>16,A=E&65535,j=E>>>16,E=e[2],D=t[2],O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,k+=O>>>16,A+=k>>>16,j+=A>>>16,e[2]=P=A&65535|j<<16,t[2]=H=O&65535|k<<16,E=F,D=U,O=D&65535,k=D>>>16,A=E&65535,j=E>>>16,E=e[3],D=t[3],O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,k+=O>>>16,A+=k>>>16,j+=A>>>16,e[3]=F=A&65535|j<<16,t[3]=U=O&65535|k<<16,E=I,D=W,O=D&65535,k=D>>>16,A=E&65535,j=E>>>16,E=e[4],D=t[4],O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,k+=O>>>16,A+=k>>>16,j+=A>>>16,e[4]=I=A&65535|j<<16,t[4]=W=O&65535|k<<16,E=L,D=G,O=D&65535,k=D>>>16,A=E&65535,j=E>>>16,E=e[5],D=t[5],O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,k+=O>>>16,A+=k>>>16,j+=A>>>16,e[5]=L=A&65535|j<<16,t[5]=G=O&65535|k<<16,E=R,D=K,O=D&65535,k=D>>>16,A=E&65535,j=E>>>16,E=e[6],D=t[6],O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,k+=O>>>16,A+=k>>>16,j+=A>>>16,e[6]=R=A&65535|j<<16,t[6]=K=O&65535|k<<16,E=z,D=q,O=D&65535,k=D>>>16,A=E&65535,j=E>>>16,E=e[7],D=t[7],O+=D&65535,k+=D>>>16,A+=E&65535,j+=E>>>16,k+=O>>>16,A+=k>>>16,j+=A>>>16,e[7]=z=A&65535|j<<16,t[7]=q=O&65535|k<<16,J+=128,r-=128}return r}function re(e,t,n){var r=new Int32Array(8),i=new Int32Array(8),a=new Uint8Array(256),o,s=n;for(r[0]=1779033703,r[1]=3144134277,r[2]=1013904242,r[3]=2773480762,r[4]=1359893119,r[5]=2600822924,r[6]=528734635,r[7]=1541459225,i[0]=4089235720,i[1]=2227873595,i[2]=4271175723,i[3]=1595750129,i[4]=2917565137,i[5]=725511199,i[6]=4215389547,i[7]=327033209,ne(r,i,t,n),n%=128,o=0;o<n;o++)a[o]=t[s-n+o];for(a[n]=128,n=256-128*(n<112?1:0),a[n-9]=0,m(a,n-8,s/536870912|0,s<<3),ne(r,i,a,n),o=0;o<8;o++)m(e,8*o,r[o],i[o]);return 0}function ie(e,n){var r=t(),i=t(),a=t(),o=t(),s=t(),c=t(),l=t(),d=t(),f=t();B(r,e[1],e[0]),B(f,n[1],n[0]),V(r,r,f),z(i,e[0],e[1]),z(f,n[0],n[1]),V(i,i,f),V(a,e[3],n[3]),V(a,a,u),V(o,e[2],n[2]),z(o,o,o),B(s,i,r),B(c,o,a),z(l,o,a),z(d,i,r),V(e[0],s,c),V(e[1],d,l),V(e[2],l,c),V(e[3],s,d)}function ae(e,t,n){var r;for(r=0;r<4;r++)P(e[r],t[r],n)}function oe(e,n){var r=t(),i=t(),a=t();U(a,n[2]),V(r,n[0],a),V(i,n[1],a),F(e,i),e[31]^=L(r)<<7}function se(e,t,n){var r,i;for(M(e[0],o),M(e[1],s),M(e[2],s),M(e[3],o),i=255;i>=0;--i)r=n[i/8|0]>>(i&7)&1,ae(e,t,r),ie(t,e),ie(e,e),ae(e,t,r)}function ce(e,n){var r=[t(),t(),t(),t()];M(r[0],d),M(r[1],f),M(r[2],s),V(r[3],d,f),se(e,r,n)}function le(e,n,i){var a=new Uint8Array(64),o=[t(),t(),t(),t()],s;for(i||r(n,32),re(a,n,32),a[0]&=248,a[31]&=127,a[31]|=64,ce(o,a),oe(e,o),s=0;s<32;s++)n[s+32]=e[s];return 0}var ue=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function de(e,t){var n,r,i,a;for(r=63;r>=32;--r){for(n=0,i=r-32,a=r-12;i<a;++i)t[i]+=n-16*t[r]*ue[i-(r-32)],n=Math.floor((t[i]+128)/256),t[i]-=n*256;t[i]+=n,t[r]=0}for(n=0,i=0;i<32;i++)t[i]+=n-(t[31]>>4)*ue[i],n=t[i]>>8,t[i]&=255;for(i=0;i<32;i++)t[i]-=n*ue[i];for(r=0;r<32;r++)t[r+1]+=t[r]>>8,e[r]=t[r]&255}function fe(e){var t=new Float64Array(64),n;for(n=0;n<64;n++)t[n]=e[n];for(n=0;n<64;n++)e[n]=0;de(e,t)}function pe(e,n,r,i){var a=new Uint8Array(64),o=new Uint8Array(64),s=new Uint8Array(64),c,l,u=new Float64Array(64),d=[t(),t(),t(),t()];re(a,i,32),a[0]&=248,a[31]&=127,a[31]|=64;var f=r+64;for(c=0;c<r;c++)e[64+c]=n[c];for(c=0;c<32;c++)e[32+c]=a[32+c];for(re(s,e.subarray(32),r+32),fe(s),ce(d,s),oe(e,d),c=32;c<64;c++)e[c]=i[c];for(re(o,e,r+64),fe(o),c=0;c<64;c++)u[c]=0;for(c=0;c<32;c++)u[c]=s[c];for(c=0;c<32;c++)for(l=0;l<32;l++)u[c+l]+=o[c]*a[l];return de(e.subarray(32),u),f}function me(e,n){var r=t(),i=t(),a=t(),c=t(),u=t(),d=t(),f=t();return M(e[2],s),R(e[1],n),H(a,e[1]),V(c,a,l),B(a,a,e[2]),z(c,e[2],c),H(u,c),H(d,u),V(f,d,u),V(r,f,a),V(r,r,c),W(r,r),V(r,r,a),V(r,r,c),V(r,r,c),V(e[0],r,c),H(i,e[0]),V(i,i,c),I(i,a)&&V(e[0],e[0],p),H(i,e[0]),V(i,i,c),I(i,a)?-1:(L(e[0])===n[31]>>7&&B(e[0],o,e[0]),V(e[3],e[0],e[1]),0)}function he(e,n,r,i){var a,o=new Uint8Array(32),s=new Uint8Array(64),c=[t(),t(),t(),t()],l=[t(),t(),t(),t()];if(r<64||me(l,i))return-1;for(a=0;a<r;a++)e[a]=n[a];for(a=0;a<32;a++)e[a+32]=i[a];if(re(s,e,r),fe(s),se(c,l,s),ce(l,n.subarray(32)),ie(c,l),oe(o,c),r-=64,_(n,0,o,0)){for(a=0;a<r;a++)e[a]=0;return-1}for(a=0;a<r;a++)e[a]=n[a+64];return r}var ge=32,_e=24,ve=32,ye=16,be=32,xe=32,Se=32,Ce=32,we=32,Te=_e,Ee=ve,De=ye,Q=64,Oe=32,ke=64,Ae=32,je=64;e.lowlevel={crypto_core_hsalsa20:x,crypto_stream_xor:E,crypto_stream:T,crypto_stream_salsa20_xor:C,crypto_stream_salsa20:w,crypto_onetimeauth:O,crypto_onetimeauth_verify:k,crypto_verify_16:g,crypto_verify_32:_,crypto_secretbox:A,crypto_secretbox_open:j,crypto_scalarmult:G,crypto_scalarmult_base:K,crypto_box_beforenm:J,crypto_box_afternm:Y,crypto_box:Z,crypto_box_open:ee,crypto_box_keypair:q,crypto_hash:re,crypto_sign:pe,crypto_sign_keypair:le,crypto_sign_open:he,crypto_secretbox_KEYBYTES:ge,crypto_secretbox_NONCEBYTES:_e,crypto_secretbox_ZEROBYTES:ve,crypto_secretbox_BOXZEROBYTES:ye,crypto_scalarmult_BYTES:be,crypto_scalarmult_SCALARBYTES:xe,crypto_box_PUBLICKEYBYTES:Se,crypto_box_SECRETKEYBYTES:Ce,crypto_box_BEFORENMBYTES:we,crypto_box_NONCEBYTES:Te,crypto_box_ZEROBYTES:Ee,crypto_box_BOXZEROBYTES:De,crypto_sign_BYTES:Q,crypto_sign_PUBLICKEYBYTES:Oe,crypto_sign_SECRETKEYBYTES:ke,crypto_sign_SEEDBYTES:Ae,crypto_hash_BYTES:je,gf:t,D:l,L:ue,pack25519:F,unpack25519:R,M:V,A:z,S:H,Z:B,pow2523:W,add:ie,set25519:M,modL:de,scalarmult:se,scalarbase:ce};function Me(e,t){if(e.length!==ge)throw Error(`bad key size`);if(t.length!==_e)throw Error(`bad nonce size`)}function Ne(e,t){if(e.length!==Se)throw Error(`bad public key size`);if(t.length!==Ce)throw Error(`bad secret key size`)}function $(){for(var e=0;e<arguments.length;e++)if(!(arguments[e]instanceof Uint8Array))throw TypeError(`unexpected type, use Uint8Array`)}function Pe(e){for(var t=0;t<e.length;t++)e[t]=0}e.randomBytes=function(e){var t=new Uint8Array(e);return r(t,e),t},e.secretbox=function(e,t,n){$(e,t,n),Me(n,t);for(var r=new Uint8Array(ve+e.length),i=new Uint8Array(r.length),a=0;a<e.length;a++)r[a+ve]=e[a];return A(i,r,r.length,t,n),i.subarray(ye)},e.secretbox.open=function(e,t,n){$(e,t,n),Me(n,t);for(var r=new Uint8Array(ye+e.length),i=new Uint8Array(r.length),a=0;a<e.length;a++)r[a+ye]=e[a];return r.length<32||j(i,r,r.length,t,n)!==0?null:i.subarray(ve)},e.secretbox.keyLength=ge,e.secretbox.nonceLength=_e,e.secretbox.overheadLength=ye,e.scalarMult=function(e,t){if($(e,t),e.length!==xe)throw Error(`bad n size`);if(t.length!==be)throw Error(`bad p size`);var n=new Uint8Array(be);return G(n,e,t),n},e.scalarMult.base=function(e){if($(e),e.length!==xe)throw Error(`bad n size`);var t=new Uint8Array(be);return K(t,e),t},e.scalarMult.scalarLength=xe,e.scalarMult.groupElementLength=be,e.box=function(t,n,r,i){var a=e.box.before(r,i);return e.secretbox(t,n,a)},e.box.before=function(e,t){$(e,t),Ne(e,t);var n=new Uint8Array(we);return J(n,e,t),n},e.box.after=e.secretbox,e.box.open=function(t,n,r,i){var a=e.box.before(r,i);return e.secretbox.open(t,n,a)},e.box.open.after=e.secretbox.open,e.box.keyPair=function(){var e=new Uint8Array(Se),t=new Uint8Array(Ce);return q(e,t),{publicKey:e,secretKey:t}},e.box.keyPair.fromSecretKey=function(e){if($(e),e.length!==Ce)throw Error(`bad secret key size`);var t=new Uint8Array(Se);return K(t,e),{publicKey:t,secretKey:new Uint8Array(e)}},e.box.publicKeyLength=Se,e.box.secretKeyLength=Ce,e.box.sharedKeyLength=we,e.box.nonceLength=Te,e.box.overheadLength=e.secretbox.overheadLength,e.sign=function(e,t){if($(e,t),t.length!==ke)throw Error(`bad secret key size`);var n=new Uint8Array(Q+e.length);return pe(n,e,e.length,t),n},e.sign.open=function(e,t){if($(e,t),t.length!==Oe)throw Error(`bad public key size`);var n=new Uint8Array(e.length),r=he(n,e,e.length,t);if(r<0)return null;for(var i=new Uint8Array(r),a=0;a<i.length;a++)i[a]=n[a];return i},e.sign.detached=function(t,n){for(var r=e.sign(t,n),i=new Uint8Array(Q),a=0;a<i.length;a++)i[a]=r[a];return i},e.sign.detached.verify=function(e,t,n){if($(e,t,n),t.length!==Q)throw Error(`bad signature size`);if(n.length!==Oe)throw Error(`bad public key size`);var r=new Uint8Array(Q+e.length),i=new Uint8Array(Q+e.length),a;for(a=0;a<Q;a++)r[a]=t[a];for(a=0;a<e.length;a++)r[a+Q]=e[a];return he(i,r,r.length,n)>=0},e.sign.keyPair=function(){var e=new Uint8Array(Oe),t=new Uint8Array(ke);return le(e,t),{publicKey:e,secretKey:t}},e.sign.keyPair.fromSecretKey=function(e){if($(e),e.length!==ke)throw Error(`bad secret key size`);for(var t=new Uint8Array(Oe),n=0;n<t.length;n++)t[n]=e[32+n];return{publicKey:t,secretKey:new Uint8Array(e)}},e.sign.keyPair.fromSeed=function(e){if($(e),e.length!==Ae)throw Error(`bad seed size`);for(var t=new Uint8Array(Oe),n=new Uint8Array(ke),r=0;r<32;r++)n[r]=e[r];return le(t,n,!0),{publicKey:t,secretKey:n}},e.sign.publicKeyLength=Oe,e.sign.secretKeyLength=ke,e.sign.seedLength=Ae,e.sign.signatureLength=Q,e.hash=function(e){$(e);var t=new Uint8Array(je);return re(t,e,e.length),t},e.hash.hashLength=je,e.verify=function(e,t){return $(e,t),e.length===0||t.length===0||e.length!==t.length?!1:h(e,0,t,0,e.length)===0},e.setPRNG=function(e){r=e},(function(){var t=typeof self<`u`?self.crypto||self.msCrypto:null;if(t&&t.getRandomValues){var r=65536;e.setPRNG(function(e,n){var i,a=new Uint8Array(n);for(i=0;i<n;i+=r)t.getRandomValues(a.subarray(i,i+Math.min(n-i,r)));for(i=0;i<n;i++)e[i]=a[i];Pe(a)})}else n!==void 0&&(t=n(`crypto`),t&&t.randomBytes&&e.setPRNG(function(e,n){var r,i=t.randomBytes(n);for(r=0;r<n;r++)e[r]=i[r];Pe(i)}))})()})(t!==void 0&&t.exports?t.exports:self.nacl=self.nacl||{})})),w=t({generateKeyPair:()=>E,generateSharedSecKey:()=>D}),T=e(C(),1);function E(){let e=T.default.box.keyPair();return{publicKey:e.publicKey,secretKey:e.secretKey}}function D(e,t){return T.default.scalarMult(e,t)}var O=t({generateKeyPair:()=>k,sign:()=>A,verify:()=>j});function k(){let e=T.default.sign.keyPair();return{publicKey:e.publicKey,secretKey:e.secretKey}}function A(e,t){return T.default.sign.detached(e,t)}function j(e,t,n){return T.default.sign.detached.verify(e,t,n)}function M(e){return Buffer.from(i(e.hash,e.key,e.salt,e.info,e.length))}export{_ as Chacha20,w as Curve25519,O as Ed25519,M as hkdf};
1
+ import { i as __toESM, n as __exportAll, r as __require, t as __commonJSMin } from "./chunk-CB5R7In7.mjs";
2
+ import { hkdfSync } from "node:crypto";
3
+
4
+ //#region ../../node_modules/.bun/@stablelib+int@2.0.1/node_modules/@stablelib/int/lib/int.js
5
+ /**
6
+ * Returns true if the argument is an integer number.
7
+ */
8
+ const isInteger = Number.isInteger;
9
+ /**
10
+ * Math.pow(2, 53) - 1
11
+ */
12
+ const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
13
+ /**
14
+ * Returns true if the argument is a safe integer number
15
+ * (-MIN_SAFE_INTEGER < number <= MAX_SAFE_INTEGER)
16
+ */
17
+ const isSafeInteger = Number.isSafeInteger;
18
+
19
+ //#endregion
20
+ //#region ../../node_modules/.bun/@stablelib+binary@2.0.1/node_modules/@stablelib/binary/lib/binary.js
21
+ /**
22
+ * Writes 4-byte little-endian representation of 32-bit unsigned
23
+ * value to array starting at offset.
24
+ *
25
+ * If byte array is not given, creates a new 4-byte one.
26
+ *
27
+ * Returns the output byte array.
28
+ */
29
+ function writeUint32LE(value, out = new Uint8Array(4), offset = 0) {
30
+ out[offset + 0] = value >>> 0;
31
+ out[offset + 1] = value >>> 8;
32
+ out[offset + 2] = value >>> 16;
33
+ out[offset + 3] = value >>> 24;
34
+ return out;
35
+ }
36
+ /**
37
+ * Writes 8-byte little-endian representation of 64-bit unsigned
38
+ * value to byte array starting at offset.
39
+ *
40
+ * Due to JavaScript limitation, supports values up to 2^53-1.
41
+ *
42
+ * If byte array is not given, creates a new 8-byte one.
43
+ *
44
+ * Returns the output byte array.
45
+ */
46
+ function writeUint64LE(value, out = new Uint8Array(8), offset = 0) {
47
+ writeUint32LE(value >>> 0, out, offset);
48
+ writeUint32LE(value / 4294967296 >>> 0, out, offset + 4);
49
+ return out;
50
+ }
51
+
52
+ //#endregion
53
+ //#region ../../node_modules/.bun/@stablelib+wipe@2.0.1/node_modules/@stablelib/wipe/lib/wipe.js
54
+ /**
55
+ * Sets all values in the given array to zero and returns it.
56
+ *
57
+ * The fact that it sets bytes to zero can be relied on.
58
+ *
59
+ * There is no guarantee that this function makes data disappear from memory,
60
+ * as runtime implementation can, for example, have copying garbage collector
61
+ * that will make copies of sensitive data before we wipe it. Or that an
62
+ * operating system will write our data to swap or sleep image. Another thing
63
+ * is that an optimizing compiler can remove calls to this function or make it
64
+ * no-op. There's nothing we can do with it, so we just do our best and hope
65
+ * that everything will be okay and good will triumph over evil.
66
+ */
67
+ function wipe(array) {
68
+ for (let i = 0; i < array.length; i++) array[i] = 0;
69
+ return array;
70
+ }
71
+
72
+ //#endregion
73
+ //#region ../../node_modules/.bun/@stablelib+chacha@2.0.1/node_modules/@stablelib/chacha/lib/chacha.js
74
+ /**
75
+ * Package chacha implements ChaCha stream cipher.
76
+ */
77
+ const ROUNDS = 20;
78
+ function core(out, input, key) {
79
+ let j0 = 1634760805;
80
+ let j1 = 857760878;
81
+ let j2 = 2036477234;
82
+ let j3 = 1797285236;
83
+ let j4 = key[3] << 24 | key[2] << 16 | key[1] << 8 | key[0];
84
+ let j5 = key[7] << 24 | key[6] << 16 | key[5] << 8 | key[4];
85
+ let j6 = key[11] << 24 | key[10] << 16 | key[9] << 8 | key[8];
86
+ let j7 = key[15] << 24 | key[14] << 16 | key[13] << 8 | key[12];
87
+ let j8 = key[19] << 24 | key[18] << 16 | key[17] << 8 | key[16];
88
+ let j9 = key[23] << 24 | key[22] << 16 | key[21] << 8 | key[20];
89
+ let j10 = key[27] << 24 | key[26] << 16 | key[25] << 8 | key[24];
90
+ let j11 = key[31] << 24 | key[30] << 16 | key[29] << 8 | key[28];
91
+ let j12 = input[3] << 24 | input[2] << 16 | input[1] << 8 | input[0];
92
+ let j13 = input[7] << 24 | input[6] << 16 | input[5] << 8 | input[4];
93
+ let j14 = input[11] << 24 | input[10] << 16 | input[9] << 8 | input[8];
94
+ let j15 = input[15] << 24 | input[14] << 16 | input[13] << 8 | input[12];
95
+ let x0 = j0;
96
+ let x1 = j1;
97
+ let x2 = j2;
98
+ let x3 = j3;
99
+ let x4 = j4;
100
+ let x5 = j5;
101
+ let x6 = j6;
102
+ let x7 = j7;
103
+ let x8 = j8;
104
+ let x9 = j9;
105
+ let x10 = j10;
106
+ let x11 = j11;
107
+ let x12 = j12;
108
+ let x13 = j13;
109
+ let x14 = j14;
110
+ let x15 = j15;
111
+ for (let i = 0; i < ROUNDS; i += 2) {
112
+ x0 = x0 + x4 | 0;
113
+ x12 ^= x0;
114
+ x12 = x12 >>> 16 | x12 << 16;
115
+ x8 = x8 + x12 | 0;
116
+ x4 ^= x8;
117
+ x4 = x4 >>> 20 | x4 << 12;
118
+ x1 = x1 + x5 | 0;
119
+ x13 ^= x1;
120
+ x13 = x13 >>> 16 | x13 << 16;
121
+ x9 = x9 + x13 | 0;
122
+ x5 ^= x9;
123
+ x5 = x5 >>> 20 | x5 << 12;
124
+ x2 = x2 + x6 | 0;
125
+ x14 ^= x2;
126
+ x14 = x14 >>> 16 | x14 << 16;
127
+ x10 = x10 + x14 | 0;
128
+ x6 ^= x10;
129
+ x6 = x6 >>> 20 | x6 << 12;
130
+ x3 = x3 + x7 | 0;
131
+ x15 ^= x3;
132
+ x15 = x15 >>> 16 | x15 << 16;
133
+ x11 = x11 + x15 | 0;
134
+ x7 ^= x11;
135
+ x7 = x7 >>> 20 | x7 << 12;
136
+ x2 = x2 + x6 | 0;
137
+ x14 ^= x2;
138
+ x14 = x14 >>> 24 | x14 << 8;
139
+ x10 = x10 + x14 | 0;
140
+ x6 ^= x10;
141
+ x6 = x6 >>> 25 | x6 << 7;
142
+ x3 = x3 + x7 | 0;
143
+ x15 ^= x3;
144
+ x15 = x15 >>> 24 | x15 << 8;
145
+ x11 = x11 + x15 | 0;
146
+ x7 ^= x11;
147
+ x7 = x7 >>> 25 | x7 << 7;
148
+ x1 = x1 + x5 | 0;
149
+ x13 ^= x1;
150
+ x13 = x13 >>> 24 | x13 << 8;
151
+ x9 = x9 + x13 | 0;
152
+ x5 ^= x9;
153
+ x5 = x5 >>> 25 | x5 << 7;
154
+ x0 = x0 + x4 | 0;
155
+ x12 ^= x0;
156
+ x12 = x12 >>> 24 | x12 << 8;
157
+ x8 = x8 + x12 | 0;
158
+ x4 ^= x8;
159
+ x4 = x4 >>> 25 | x4 << 7;
160
+ x0 = x0 + x5 | 0;
161
+ x15 ^= x0;
162
+ x15 = x15 >>> 16 | x15 << 16;
163
+ x10 = x10 + x15 | 0;
164
+ x5 ^= x10;
165
+ x5 = x5 >>> 20 | x5 << 12;
166
+ x1 = x1 + x6 | 0;
167
+ x12 ^= x1;
168
+ x12 = x12 >>> 16 | x12 << 16;
169
+ x11 = x11 + x12 | 0;
170
+ x6 ^= x11;
171
+ x6 = x6 >>> 20 | x6 << 12;
172
+ x2 = x2 + x7 | 0;
173
+ x13 ^= x2;
174
+ x13 = x13 >>> 16 | x13 << 16;
175
+ x8 = x8 + x13 | 0;
176
+ x7 ^= x8;
177
+ x7 = x7 >>> 20 | x7 << 12;
178
+ x3 = x3 + x4 | 0;
179
+ x14 ^= x3;
180
+ x14 = x14 >>> 16 | x14 << 16;
181
+ x9 = x9 + x14 | 0;
182
+ x4 ^= x9;
183
+ x4 = x4 >>> 20 | x4 << 12;
184
+ x2 = x2 + x7 | 0;
185
+ x13 ^= x2;
186
+ x13 = x13 >>> 24 | x13 << 8;
187
+ x8 = x8 + x13 | 0;
188
+ x7 ^= x8;
189
+ x7 = x7 >>> 25 | x7 << 7;
190
+ x3 = x3 + x4 | 0;
191
+ x14 ^= x3;
192
+ x14 = x14 >>> 24 | x14 << 8;
193
+ x9 = x9 + x14 | 0;
194
+ x4 ^= x9;
195
+ x4 = x4 >>> 25 | x4 << 7;
196
+ x1 = x1 + x6 | 0;
197
+ x12 ^= x1;
198
+ x12 = x12 >>> 24 | x12 << 8;
199
+ x11 = x11 + x12 | 0;
200
+ x6 ^= x11;
201
+ x6 = x6 >>> 25 | x6 << 7;
202
+ x0 = x0 + x5 | 0;
203
+ x15 ^= x0;
204
+ x15 = x15 >>> 24 | x15 << 8;
205
+ x10 = x10 + x15 | 0;
206
+ x5 ^= x10;
207
+ x5 = x5 >>> 25 | x5 << 7;
208
+ }
209
+ writeUint32LE(x0 + j0 | 0, out, 0);
210
+ writeUint32LE(x1 + j1 | 0, out, 4);
211
+ writeUint32LE(x2 + j2 | 0, out, 8);
212
+ writeUint32LE(x3 + j3 | 0, out, 12);
213
+ writeUint32LE(x4 + j4 | 0, out, 16);
214
+ writeUint32LE(x5 + j5 | 0, out, 20);
215
+ writeUint32LE(x6 + j6 | 0, out, 24);
216
+ writeUint32LE(x7 + j7 | 0, out, 28);
217
+ writeUint32LE(x8 + j8 | 0, out, 32);
218
+ writeUint32LE(x9 + j9 | 0, out, 36);
219
+ writeUint32LE(x10 + j10 | 0, out, 40);
220
+ writeUint32LE(x11 + j11 | 0, out, 44);
221
+ writeUint32LE(x12 + j12 | 0, out, 48);
222
+ writeUint32LE(x13 + j13 | 0, out, 52);
223
+ writeUint32LE(x14 + j14 | 0, out, 56);
224
+ writeUint32LE(x15 + j15 | 0, out, 60);
225
+ }
226
+ /**
227
+ * Encrypt src with ChaCha20 stream generated for the given 32-byte key and
228
+ * 8-byte (as in original implementation) or 12-byte (as in RFC7539) nonce and
229
+ * write the result into dst and return it.
230
+ *
231
+ * dst and src may be the same, but otherwise must not overlap.
232
+ *
233
+ * If nonce is 12 bytes, users should not encrypt more than 256 GiB with the
234
+ * same key and nonce, otherwise the stream will repeat. The function will
235
+ * throw error if counter overflows to prevent this.
236
+ *
237
+ * If nonce is 8 bytes, the output is practically unlimited (2^70 bytes, which
238
+ * is more than a million petabytes). However, it is not recommended to
239
+ * generate 8-byte nonces randomly, as the chance of collision is high.
240
+ *
241
+ * Never use the same key and nonce to encrypt more than one message.
242
+ *
243
+ * If nonceInplaceCounterLength is not 0, the nonce is assumed to be a 16-byte
244
+ * array with stream counter in first nonceInplaceCounterLength bytes and nonce
245
+ * in the last remaining bytes. The counter will be incremented inplace for
246
+ * each ChaCha block. This is useful if you need to encrypt one stream of data
247
+ * in chunks.
248
+ */
249
+ function streamXOR(key, nonce, src, dst, nonceInplaceCounterLength = 0) {
250
+ if (key.length !== 32) throw new Error("ChaCha: key size must be 32 bytes");
251
+ if (dst.length < src.length) throw new Error("ChaCha: destination is shorter than source");
252
+ let nc;
253
+ let counterLength;
254
+ if (nonceInplaceCounterLength === 0) {
255
+ if (nonce.length !== 8 && nonce.length !== 12) throw new Error("ChaCha nonce must be 8 or 12 bytes");
256
+ nc = new Uint8Array(16);
257
+ counterLength = nc.length - nonce.length;
258
+ nc.set(nonce, counterLength);
259
+ } else {
260
+ if (nonce.length !== 16) throw new Error("ChaCha nonce with counter must be 16 bytes");
261
+ nc = nonce;
262
+ counterLength = nonceInplaceCounterLength;
263
+ }
264
+ const block = new Uint8Array(64);
265
+ for (let i = 0; i < src.length; i += 64) {
266
+ core(block, nc, key);
267
+ for (let j = i; j < i + 64 && j < src.length; j++) dst[j] = src[j] ^ block[j - i];
268
+ incrementCounter(nc, 0, counterLength);
269
+ }
270
+ wipe(block);
271
+ if (nonceInplaceCounterLength === 0) wipe(nc);
272
+ return dst;
273
+ }
274
+ /**
275
+ * Generate ChaCha20 stream for the given 32-byte key and 8-byte or 12-byte
276
+ * nonce and write it into dst and return it.
277
+ *
278
+ * Never use the same key and nonce to generate more than one stream.
279
+ *
280
+ * If nonceInplaceCounterLength is not 0, it behaves the same with respect to
281
+ * the nonce as described in the streamXOR documentation.
282
+ *
283
+ * stream is like streamXOR with all-zero src.
284
+ */
285
+ function stream(key, nonce, dst, nonceInplaceCounterLength = 0) {
286
+ wipe(dst);
287
+ return streamXOR(key, nonce, dst, dst, nonceInplaceCounterLength);
288
+ }
289
+ function incrementCounter(counter, pos, len) {
290
+ let carry = 1;
291
+ while (len--) {
292
+ carry = carry + (counter[pos] & 255) | 0;
293
+ counter[pos] = carry & 255;
294
+ carry >>>= 8;
295
+ pos++;
296
+ }
297
+ if (carry > 0) throw new Error("ChaCha: counter overflow");
298
+ }
299
+
300
+ //#endregion
301
+ //#region ../../node_modules/.bun/@stablelib+constant-time@2.0.1/node_modules/@stablelib/constant-time/lib/constant-time.js
302
+ /**
303
+ * Returns 1 if a and b are of equal length and their contents
304
+ * are equal, or 0 otherwise.
305
+ *
306
+ * Note that unlike in equal(), zero-length inputs are considered
307
+ * the same, so this function will return 1.
308
+ */
309
+ function compare(a, b) {
310
+ if (a.length !== b.length) return 0;
311
+ let result = 0;
312
+ for (let i = 0; i < a.length; i++) result |= a[i] ^ b[i];
313
+ return 1 & result - 1 >>> 8;
314
+ }
315
+ /**
316
+ * Returns true if a and b are of equal non-zero length,
317
+ * and their contents are equal, or false otherwise.
318
+ *
319
+ * Note that unlike in compare() zero-length inputs are considered
320
+ * _not_ equal, so this function will return false.
321
+ */
322
+ function equal(a, b) {
323
+ if (a.length === 0 || b.length === 0) return false;
324
+ return compare(a, b) !== 0;
325
+ }
326
+
327
+ //#endregion
328
+ //#region ../../node_modules/.bun/@stablelib+poly1305@2.0.1/node_modules/@stablelib/poly1305/lib/poly1305.js
329
+ const DIGEST_LENGTH = 16;
330
+ /**
331
+ * Poly1305 computes 16-byte authenticator of message using
332
+ * a one-time 32-byte key.
333
+ *
334
+ * Important: key should be used for only one message,
335
+ * it should never repeat.
336
+ */
337
+ var Poly1305 = class {
338
+ digestLength = DIGEST_LENGTH;
339
+ _buffer = new Uint8Array(16);
340
+ _r = new Uint16Array(10);
341
+ _h = new Uint16Array(10);
342
+ _pad = new Uint16Array(8);
343
+ _leftover = 0;
344
+ _fin = 0;
345
+ _finished = false;
346
+ constructor(key) {
347
+ let t0 = key[0] | key[1] << 8;
348
+ this._r[0] = t0 & 8191;
349
+ let t1 = key[2] | key[3] << 8;
350
+ this._r[1] = (t0 >>> 13 | t1 << 3) & 8191;
351
+ let t2 = key[4] | key[5] << 8;
352
+ this._r[2] = (t1 >>> 10 | t2 << 6) & 7939;
353
+ let t3 = key[6] | key[7] << 8;
354
+ this._r[3] = (t2 >>> 7 | t3 << 9) & 8191;
355
+ let t4 = key[8] | key[9] << 8;
356
+ this._r[4] = (t3 >>> 4 | t4 << 12) & 255;
357
+ this._r[5] = t4 >>> 1 & 8190;
358
+ let t5 = key[10] | key[11] << 8;
359
+ this._r[6] = (t4 >>> 14 | t5 << 2) & 8191;
360
+ let t6 = key[12] | key[13] << 8;
361
+ this._r[7] = (t5 >>> 11 | t6 << 5) & 8065;
362
+ let t7 = key[14] | key[15] << 8;
363
+ this._r[8] = (t6 >>> 8 | t7 << 8) & 8191;
364
+ this._r[9] = t7 >>> 5 & 127;
365
+ this._pad[0] = key[16] | key[17] << 8;
366
+ this._pad[1] = key[18] | key[19] << 8;
367
+ this._pad[2] = key[20] | key[21] << 8;
368
+ this._pad[3] = key[22] | key[23] << 8;
369
+ this._pad[4] = key[24] | key[25] << 8;
370
+ this._pad[5] = key[26] | key[27] << 8;
371
+ this._pad[6] = key[28] | key[29] << 8;
372
+ this._pad[7] = key[30] | key[31] << 8;
373
+ }
374
+ _blocks(m, mpos, bytes) {
375
+ let hibit = this._fin ? 0 : 2048;
376
+ let h0 = this._h[0], h1 = this._h[1], h2 = this._h[2], h3 = this._h[3], h4 = this._h[4], h5 = this._h[5], h6 = this._h[6], h7 = this._h[7], h8 = this._h[8], h9 = this._h[9];
377
+ let r0 = this._r[0], r1 = this._r[1], r2 = this._r[2], r3 = this._r[3], r4 = this._r[4], r5 = this._r[5], r6 = this._r[6], r7 = this._r[7], r8 = this._r[8], r9 = this._r[9];
378
+ while (bytes >= 16) {
379
+ let t0 = m[mpos + 0] | m[mpos + 1] << 8;
380
+ h0 += t0 & 8191;
381
+ let t1 = m[mpos + 2] | m[mpos + 3] << 8;
382
+ h1 += (t0 >>> 13 | t1 << 3) & 8191;
383
+ let t2 = m[mpos + 4] | m[mpos + 5] << 8;
384
+ h2 += (t1 >>> 10 | t2 << 6) & 8191;
385
+ let t3 = m[mpos + 6] | m[mpos + 7] << 8;
386
+ h3 += (t2 >>> 7 | t3 << 9) & 8191;
387
+ let t4 = m[mpos + 8] | m[mpos + 9] << 8;
388
+ h4 += (t3 >>> 4 | t4 << 12) & 8191;
389
+ h5 += t4 >>> 1 & 8191;
390
+ let t5 = m[mpos + 10] | m[mpos + 11] << 8;
391
+ h6 += (t4 >>> 14 | t5 << 2) & 8191;
392
+ let t6 = m[mpos + 12] | m[mpos + 13] << 8;
393
+ h7 += (t5 >>> 11 | t6 << 5) & 8191;
394
+ let t7 = m[mpos + 14] | m[mpos + 15] << 8;
395
+ h8 += (t6 >>> 8 | t7 << 8) & 8191;
396
+ h9 += t7 >>> 5 | hibit;
397
+ let c = 0;
398
+ let d0 = c;
399
+ d0 += h0 * r0;
400
+ d0 += h1 * (5 * r9);
401
+ d0 += h2 * (5 * r8);
402
+ d0 += h3 * (5 * r7);
403
+ d0 += h4 * (5 * r6);
404
+ c = d0 >>> 13;
405
+ d0 &= 8191;
406
+ d0 += h5 * (5 * r5);
407
+ d0 += h6 * (5 * r4);
408
+ d0 += h7 * (5 * r3);
409
+ d0 += h8 * (5 * r2);
410
+ d0 += h9 * (5 * r1);
411
+ c += d0 >>> 13;
412
+ d0 &= 8191;
413
+ let d1 = c;
414
+ d1 += h0 * r1;
415
+ d1 += h1 * r0;
416
+ d1 += h2 * (5 * r9);
417
+ d1 += h3 * (5 * r8);
418
+ d1 += h4 * (5 * r7);
419
+ c = d1 >>> 13;
420
+ d1 &= 8191;
421
+ d1 += h5 * (5 * r6);
422
+ d1 += h6 * (5 * r5);
423
+ d1 += h7 * (5 * r4);
424
+ d1 += h8 * (5 * r3);
425
+ d1 += h9 * (5 * r2);
426
+ c += d1 >>> 13;
427
+ d1 &= 8191;
428
+ let d2 = c;
429
+ d2 += h0 * r2;
430
+ d2 += h1 * r1;
431
+ d2 += h2 * r0;
432
+ d2 += h3 * (5 * r9);
433
+ d2 += h4 * (5 * r8);
434
+ c = d2 >>> 13;
435
+ d2 &= 8191;
436
+ d2 += h5 * (5 * r7);
437
+ d2 += h6 * (5 * r6);
438
+ d2 += h7 * (5 * r5);
439
+ d2 += h8 * (5 * r4);
440
+ d2 += h9 * (5 * r3);
441
+ c += d2 >>> 13;
442
+ d2 &= 8191;
443
+ let d3 = c;
444
+ d3 += h0 * r3;
445
+ d3 += h1 * r2;
446
+ d3 += h2 * r1;
447
+ d3 += h3 * r0;
448
+ d3 += h4 * (5 * r9);
449
+ c = d3 >>> 13;
450
+ d3 &= 8191;
451
+ d3 += h5 * (5 * r8);
452
+ d3 += h6 * (5 * r7);
453
+ d3 += h7 * (5 * r6);
454
+ d3 += h8 * (5 * r5);
455
+ d3 += h9 * (5 * r4);
456
+ c += d3 >>> 13;
457
+ d3 &= 8191;
458
+ let d4 = c;
459
+ d4 += h0 * r4;
460
+ d4 += h1 * r3;
461
+ d4 += h2 * r2;
462
+ d4 += h3 * r1;
463
+ d4 += h4 * r0;
464
+ c = d4 >>> 13;
465
+ d4 &= 8191;
466
+ d4 += h5 * (5 * r9);
467
+ d4 += h6 * (5 * r8);
468
+ d4 += h7 * (5 * r7);
469
+ d4 += h8 * (5 * r6);
470
+ d4 += h9 * (5 * r5);
471
+ c += d4 >>> 13;
472
+ d4 &= 8191;
473
+ let d5 = c;
474
+ d5 += h0 * r5;
475
+ d5 += h1 * r4;
476
+ d5 += h2 * r3;
477
+ d5 += h3 * r2;
478
+ d5 += h4 * r1;
479
+ c = d5 >>> 13;
480
+ d5 &= 8191;
481
+ d5 += h5 * r0;
482
+ d5 += h6 * (5 * r9);
483
+ d5 += h7 * (5 * r8);
484
+ d5 += h8 * (5 * r7);
485
+ d5 += h9 * (5 * r6);
486
+ c += d5 >>> 13;
487
+ d5 &= 8191;
488
+ let d6 = c;
489
+ d6 += h0 * r6;
490
+ d6 += h1 * r5;
491
+ d6 += h2 * r4;
492
+ d6 += h3 * r3;
493
+ d6 += h4 * r2;
494
+ c = d6 >>> 13;
495
+ d6 &= 8191;
496
+ d6 += h5 * r1;
497
+ d6 += h6 * r0;
498
+ d6 += h7 * (5 * r9);
499
+ d6 += h8 * (5 * r8);
500
+ d6 += h9 * (5 * r7);
501
+ c += d6 >>> 13;
502
+ d6 &= 8191;
503
+ let d7 = c;
504
+ d7 += h0 * r7;
505
+ d7 += h1 * r6;
506
+ d7 += h2 * r5;
507
+ d7 += h3 * r4;
508
+ d7 += h4 * r3;
509
+ c = d7 >>> 13;
510
+ d7 &= 8191;
511
+ d7 += h5 * r2;
512
+ d7 += h6 * r1;
513
+ d7 += h7 * r0;
514
+ d7 += h8 * (5 * r9);
515
+ d7 += h9 * (5 * r8);
516
+ c += d7 >>> 13;
517
+ d7 &= 8191;
518
+ let d8 = c;
519
+ d8 += h0 * r8;
520
+ d8 += h1 * r7;
521
+ d8 += h2 * r6;
522
+ d8 += h3 * r5;
523
+ d8 += h4 * r4;
524
+ c = d8 >>> 13;
525
+ d8 &= 8191;
526
+ d8 += h5 * r3;
527
+ d8 += h6 * r2;
528
+ d8 += h7 * r1;
529
+ d8 += h8 * r0;
530
+ d8 += h9 * (5 * r9);
531
+ c += d8 >>> 13;
532
+ d8 &= 8191;
533
+ let d9 = c;
534
+ d9 += h0 * r9;
535
+ d9 += h1 * r8;
536
+ d9 += h2 * r7;
537
+ d9 += h3 * r6;
538
+ d9 += h4 * r5;
539
+ c = d9 >>> 13;
540
+ d9 &= 8191;
541
+ d9 += h5 * r4;
542
+ d9 += h6 * r3;
543
+ d9 += h7 * r2;
544
+ d9 += h8 * r1;
545
+ d9 += h9 * r0;
546
+ c += d9 >>> 13;
547
+ d9 &= 8191;
548
+ c = (c << 2) + c | 0;
549
+ c = c + d0 | 0;
550
+ d0 = c & 8191;
551
+ c = c >>> 13;
552
+ d1 += c;
553
+ h0 = d0;
554
+ h1 = d1;
555
+ h2 = d2;
556
+ h3 = d3;
557
+ h4 = d4;
558
+ h5 = d5;
559
+ h6 = d6;
560
+ h7 = d7;
561
+ h8 = d8;
562
+ h9 = d9;
563
+ mpos += 16;
564
+ bytes -= 16;
565
+ }
566
+ this._h[0] = h0;
567
+ this._h[1] = h1;
568
+ this._h[2] = h2;
569
+ this._h[3] = h3;
570
+ this._h[4] = h4;
571
+ this._h[5] = h5;
572
+ this._h[6] = h6;
573
+ this._h[7] = h7;
574
+ this._h[8] = h8;
575
+ this._h[9] = h9;
576
+ }
577
+ finish(mac, macpos = 0) {
578
+ const g = new Uint16Array(10);
579
+ let c;
580
+ let mask;
581
+ let f;
582
+ let i;
583
+ if (this._leftover) {
584
+ i = this._leftover;
585
+ this._buffer[i++] = 1;
586
+ for (; i < 16; i++) this._buffer[i] = 0;
587
+ this._fin = 1;
588
+ this._blocks(this._buffer, 0, 16);
589
+ }
590
+ c = this._h[1] >>> 13;
591
+ this._h[1] &= 8191;
592
+ for (i = 2; i < 10; i++) {
593
+ this._h[i] += c;
594
+ c = this._h[i] >>> 13;
595
+ this._h[i] &= 8191;
596
+ }
597
+ this._h[0] += c * 5;
598
+ c = this._h[0] >>> 13;
599
+ this._h[0] &= 8191;
600
+ this._h[1] += c;
601
+ c = this._h[1] >>> 13;
602
+ this._h[1] &= 8191;
603
+ this._h[2] += c;
604
+ g[0] = this._h[0] + 5;
605
+ c = g[0] >>> 13;
606
+ g[0] &= 8191;
607
+ for (i = 1; i < 10; i++) {
608
+ g[i] = this._h[i] + c;
609
+ c = g[i] >>> 13;
610
+ g[i] &= 8191;
611
+ }
612
+ g[9] -= 8192;
613
+ mask = (c ^ 1) - 1;
614
+ for (i = 0; i < 10; i++) g[i] &= mask;
615
+ mask = ~mask;
616
+ for (i = 0; i < 10; i++) this._h[i] = this._h[i] & mask | g[i];
617
+ this._h[0] = (this._h[0] | this._h[1] << 13) & 65535;
618
+ this._h[1] = (this._h[1] >>> 3 | this._h[2] << 10) & 65535;
619
+ this._h[2] = (this._h[2] >>> 6 | this._h[3] << 7) & 65535;
620
+ this._h[3] = (this._h[3] >>> 9 | this._h[4] << 4) & 65535;
621
+ this._h[4] = (this._h[4] >>> 12 | this._h[5] << 1 | this._h[6] << 14) & 65535;
622
+ this._h[5] = (this._h[6] >>> 2 | this._h[7] << 11) & 65535;
623
+ this._h[6] = (this._h[7] >>> 5 | this._h[8] << 8) & 65535;
624
+ this._h[7] = (this._h[8] >>> 8 | this._h[9] << 5) & 65535;
625
+ f = this._h[0] + this._pad[0];
626
+ this._h[0] = f & 65535;
627
+ for (i = 1; i < 8; i++) {
628
+ f = (this._h[i] + this._pad[i] | 0) + (f >>> 16) | 0;
629
+ this._h[i] = f & 65535;
630
+ }
631
+ mac[macpos + 0] = this._h[0] >>> 0;
632
+ mac[macpos + 1] = this._h[0] >>> 8;
633
+ mac[macpos + 2] = this._h[1] >>> 0;
634
+ mac[macpos + 3] = this._h[1] >>> 8;
635
+ mac[macpos + 4] = this._h[2] >>> 0;
636
+ mac[macpos + 5] = this._h[2] >>> 8;
637
+ mac[macpos + 6] = this._h[3] >>> 0;
638
+ mac[macpos + 7] = this._h[3] >>> 8;
639
+ mac[macpos + 8] = this._h[4] >>> 0;
640
+ mac[macpos + 9] = this._h[4] >>> 8;
641
+ mac[macpos + 10] = this._h[5] >>> 0;
642
+ mac[macpos + 11] = this._h[5] >>> 8;
643
+ mac[macpos + 12] = this._h[6] >>> 0;
644
+ mac[macpos + 13] = this._h[6] >>> 8;
645
+ mac[macpos + 14] = this._h[7] >>> 0;
646
+ mac[macpos + 15] = this._h[7] >>> 8;
647
+ this._finished = true;
648
+ return this;
649
+ }
650
+ update(m) {
651
+ let mpos = 0;
652
+ let bytes = m.length;
653
+ let want;
654
+ if (this._leftover) {
655
+ want = 16 - this._leftover;
656
+ if (want > bytes) want = bytes;
657
+ for (let i = 0; i < want; i++) this._buffer[this._leftover + i] = m[mpos + i];
658
+ bytes -= want;
659
+ mpos += want;
660
+ this._leftover += want;
661
+ if (this._leftover < 16) return this;
662
+ this._blocks(this._buffer, 0, 16);
663
+ this._leftover = 0;
664
+ }
665
+ if (bytes >= 16) {
666
+ want = bytes - bytes % 16;
667
+ this._blocks(m, mpos, want);
668
+ mpos += want;
669
+ bytes -= want;
670
+ }
671
+ if (bytes) {
672
+ for (let i = 0; i < bytes; i++) this._buffer[this._leftover + i] = m[mpos + i];
673
+ this._leftover += bytes;
674
+ }
675
+ return this;
676
+ }
677
+ digest() {
678
+ if (this._finished) throw new Error("Poly1305 was finished");
679
+ let mac = new Uint8Array(16);
680
+ this.finish(mac);
681
+ return mac;
682
+ }
683
+ clean() {
684
+ wipe(this._buffer);
685
+ wipe(this._r);
686
+ wipe(this._h);
687
+ wipe(this._pad);
688
+ this._leftover = 0;
689
+ this._fin = 0;
690
+ this._finished = true;
691
+ return this;
692
+ }
693
+ };
694
+
695
+ //#endregion
696
+ //#region ../../node_modules/.bun/@stablelib+chacha20poly1305@2.0.1/node_modules/@stablelib/chacha20poly1305/lib/chacha20poly1305.js
697
+ const KEY_LENGTH = 32;
698
+ const NONCE_LENGTH = 12;
699
+ const TAG_LENGTH = 16;
700
+ const ZEROS = new Uint8Array(16);
701
+ /**
702
+ * ChaCha20-Poly1305 Authenticated Encryption with Associated Data.
703
+ *
704
+ * Defined in RFC7539.
705
+ */
706
+ var ChaCha20Poly1305 = class {
707
+ nonceLength = NONCE_LENGTH;
708
+ tagLength = TAG_LENGTH;
709
+ _key;
710
+ /**
711
+ * Creates a new instance with the given 32-byte key.
712
+ */
713
+ constructor(key) {
714
+ if (key.length !== KEY_LENGTH) throw new Error("ChaCha20Poly1305 needs 32-byte key");
715
+ this._key = new Uint8Array(key);
716
+ }
717
+ /**
718
+ * Encrypts and authenticates plaintext, authenticates associated data,
719
+ * and returns sealed ciphertext, which includes authentication tag.
720
+ *
721
+ * RFC7539 specifies 12 bytes for nonce. It may be this 12-byte nonce
722
+ * ("IV"), or full 16-byte counter (called "32-bit fixed-common part")
723
+ * and nonce.
724
+ *
725
+ * If dst is given (it must be the size of plaintext + the size of tag
726
+ * length) the result will be put into it. Dst and plaintext must not
727
+ * overlap.
728
+ */
729
+ seal(nonce, plaintext, associatedData, dst) {
730
+ if (nonce.length > 16) throw new Error("ChaCha20Poly1305: incorrect nonce length");
731
+ const counter = new Uint8Array(16);
732
+ counter.set(nonce, counter.length - nonce.length);
733
+ const authKey = new Uint8Array(32);
734
+ stream(this._key, counter, authKey, 4);
735
+ const resultLength = plaintext.length + this.tagLength;
736
+ let result;
737
+ if (dst) {
738
+ if (dst.length !== resultLength) throw new Error("ChaCha20Poly1305: incorrect destination length");
739
+ result = dst;
740
+ } else result = new Uint8Array(resultLength);
741
+ streamXOR(this._key, counter, plaintext, result, 4);
742
+ this._authenticate(result.subarray(result.length - this.tagLength, result.length), authKey, result.subarray(0, result.length - this.tagLength), associatedData);
743
+ wipe(counter);
744
+ return result;
745
+ }
746
+ /**
747
+ * Authenticates sealed ciphertext (which includes authentication tag) and
748
+ * associated data, decrypts ciphertext and returns decrypted plaintext.
749
+ *
750
+ * RFC7539 specifies 12 bytes for nonce. It may be this 12-byte nonce
751
+ * ("IV"), or full 16-byte counter (called "32-bit fixed-common part")
752
+ * and nonce.
753
+ *
754
+ * If authentication fails, it returns null.
755
+ *
756
+ * If dst is given (it must be of ciphertext length minus tag length),
757
+ * the result will be put into it. Dst and plaintext must not overlap.
758
+ */
759
+ open(nonce, sealed, associatedData, dst) {
760
+ if (nonce.length > 16) throw new Error("ChaCha20Poly1305: incorrect nonce length");
761
+ if (sealed.length < this.tagLength) return null;
762
+ const counter = new Uint8Array(16);
763
+ counter.set(nonce, counter.length - nonce.length);
764
+ const authKey = new Uint8Array(32);
765
+ stream(this._key, counter, authKey, 4);
766
+ const calculatedTag = new Uint8Array(this.tagLength);
767
+ this._authenticate(calculatedTag, authKey, sealed.subarray(0, sealed.length - this.tagLength), associatedData);
768
+ if (!equal(calculatedTag, sealed.subarray(sealed.length - this.tagLength, sealed.length))) return null;
769
+ const resultLength = sealed.length - this.tagLength;
770
+ let result;
771
+ if (dst) {
772
+ if (dst.length !== resultLength) throw new Error("ChaCha20Poly1305: incorrect destination length");
773
+ result = dst;
774
+ } else result = new Uint8Array(resultLength);
775
+ streamXOR(this._key, counter, sealed.subarray(0, sealed.length - this.tagLength), result, 4);
776
+ wipe(counter);
777
+ return result;
778
+ }
779
+ clean() {
780
+ wipe(this._key);
781
+ return this;
782
+ }
783
+ _authenticate(tagOut, authKey, ciphertext, associatedData) {
784
+ const h = new Poly1305(authKey);
785
+ if (associatedData) {
786
+ h.update(associatedData);
787
+ if (associatedData.length % 16 > 0) h.update(ZEROS.subarray(associatedData.length % 16));
788
+ }
789
+ h.update(ciphertext);
790
+ if (ciphertext.length % 16 > 0) h.update(ZEROS.subarray(ciphertext.length % 16));
791
+ const length = new Uint8Array(8);
792
+ if (associatedData) writeUint64LE(associatedData.length, length);
793
+ h.update(length);
794
+ writeUint64LE(ciphertext.length, length);
795
+ h.update(length);
796
+ const tag = h.digest();
797
+ for (let i = 0; i < tag.length; i++) tagOut[i] = tag[i];
798
+ h.clean();
799
+ wipe(tag);
800
+ wipe(length);
801
+ }
802
+ };
803
+
804
+ //#endregion
805
+ //#region src/chacha20.ts
806
+ var chacha20_exports = /* @__PURE__ */ __exportAll({
807
+ CHACHA20_AUTH_TAG_LENGTH: () => CHACHA20_AUTH_TAG_LENGTH,
808
+ CHACHA20_NONCE_LENGTH: () => CHACHA20_NONCE_LENGTH,
809
+ decrypt: () => decrypt,
810
+ encrypt: () => encrypt,
811
+ padNonce: () => padNonce
812
+ });
813
+ const CHACHA20_AUTH_TAG_LENGTH = 16;
814
+ const CHACHA20_NONCE_LENGTH = 12;
815
+ function decrypt(key, nonce, aad, ciphertext, authTag) {
816
+ nonce = padNonce(nonce);
817
+ const chacha = new ChaCha20Poly1305(key);
818
+ const sealed = Buffer.concat([ciphertext, authTag]);
819
+ const plaintext = chacha.open(nonce, sealed, aad ?? void 0);
820
+ if (!plaintext) throw new Error("Decryption failed: authentication tag mismatch");
821
+ return Buffer.from(plaintext);
822
+ }
823
+ function encrypt(key, nonce, aad, plaintext) {
824
+ nonce = padNonce(nonce);
825
+ const sealed = new ChaCha20Poly1305(key).seal(nonce, plaintext, aad ?? void 0);
826
+ return {
827
+ ciphertext: Buffer.from(sealed.subarray(0, sealed.length - CHACHA20_AUTH_TAG_LENGTH)),
828
+ authTag: Buffer.from(sealed.subarray(sealed.length - CHACHA20_AUTH_TAG_LENGTH))
829
+ };
830
+ }
831
+ function padNonce(nonce) {
832
+ if (nonce.length >= CHACHA20_NONCE_LENGTH) return nonce;
833
+ return Buffer.concat([Buffer.alloc(CHACHA20_NONCE_LENGTH - nonce.length, 0), nonce]);
834
+ }
835
+
836
+ //#endregion
837
+ //#region ../../node_modules/.bun/tweetnacl@1.0.3/node_modules/tweetnacl/nacl-fast.js
838
+ var require_nacl_fast = /* @__PURE__ */ __commonJSMin(((exports, module) => {
839
+ (function(nacl) {
840
+ "use strict";
841
+ var gf = function(init) {
842
+ var i, r = new Float64Array(16);
843
+ if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
844
+ return r;
845
+ };
846
+ var randombytes = function() {
847
+ throw new Error("no PRNG");
848
+ };
849
+ var _0 = new Uint8Array(16);
850
+ var _9 = new Uint8Array(32);
851
+ _9[0] = 9;
852
+ var gf0 = gf(), gf1 = gf([1]), _121665 = gf([56129, 1]), D = gf([
853
+ 30883,
854
+ 4953,
855
+ 19914,
856
+ 30187,
857
+ 55467,
858
+ 16705,
859
+ 2637,
860
+ 112,
861
+ 59544,
862
+ 30585,
863
+ 16505,
864
+ 36039,
865
+ 65139,
866
+ 11119,
867
+ 27886,
868
+ 20995
869
+ ]), D2 = gf([
870
+ 61785,
871
+ 9906,
872
+ 39828,
873
+ 60374,
874
+ 45398,
875
+ 33411,
876
+ 5274,
877
+ 224,
878
+ 53552,
879
+ 61171,
880
+ 33010,
881
+ 6542,
882
+ 64743,
883
+ 22239,
884
+ 55772,
885
+ 9222
886
+ ]), X = gf([
887
+ 54554,
888
+ 36645,
889
+ 11616,
890
+ 51542,
891
+ 42930,
892
+ 38181,
893
+ 51040,
894
+ 26924,
895
+ 56412,
896
+ 64982,
897
+ 57905,
898
+ 49316,
899
+ 21502,
900
+ 52590,
901
+ 14035,
902
+ 8553
903
+ ]), Y = gf([
904
+ 26200,
905
+ 26214,
906
+ 26214,
907
+ 26214,
908
+ 26214,
909
+ 26214,
910
+ 26214,
911
+ 26214,
912
+ 26214,
913
+ 26214,
914
+ 26214,
915
+ 26214,
916
+ 26214,
917
+ 26214,
918
+ 26214,
919
+ 26214
920
+ ]), I = gf([
921
+ 41136,
922
+ 18958,
923
+ 6951,
924
+ 50414,
925
+ 58488,
926
+ 44335,
927
+ 6150,
928
+ 12099,
929
+ 55207,
930
+ 15867,
931
+ 153,
932
+ 11085,
933
+ 57099,
934
+ 20417,
935
+ 9344,
936
+ 11139
937
+ ]);
938
+ function ts64(x, i, h, l) {
939
+ x[i] = h >> 24 & 255;
940
+ x[i + 1] = h >> 16 & 255;
941
+ x[i + 2] = h >> 8 & 255;
942
+ x[i + 3] = h & 255;
943
+ x[i + 4] = l >> 24 & 255;
944
+ x[i + 5] = l >> 16 & 255;
945
+ x[i + 6] = l >> 8 & 255;
946
+ x[i + 7] = l & 255;
947
+ }
948
+ function vn(x, xi, y, yi, n) {
949
+ var i, d = 0;
950
+ for (i = 0; i < n; i++) d |= x[xi + i] ^ y[yi + i];
951
+ return (1 & d - 1 >>> 8) - 1;
952
+ }
953
+ function crypto_verify_16(x, xi, y, yi) {
954
+ return vn(x, xi, y, yi, 16);
955
+ }
956
+ function crypto_verify_32(x, xi, y, yi) {
957
+ return vn(x, xi, y, yi, 32);
958
+ }
959
+ function core_salsa20(o, p, k, c) {
960
+ var j0 = c[0] & 255 | (c[1] & 255) << 8 | (c[2] & 255) << 16 | (c[3] & 255) << 24, j1 = k[0] & 255 | (k[1] & 255) << 8 | (k[2] & 255) << 16 | (k[3] & 255) << 24, j2 = k[4] & 255 | (k[5] & 255) << 8 | (k[6] & 255) << 16 | (k[7] & 255) << 24, j3 = k[8] & 255 | (k[9] & 255) << 8 | (k[10] & 255) << 16 | (k[11] & 255) << 24, j4 = k[12] & 255 | (k[13] & 255) << 8 | (k[14] & 255) << 16 | (k[15] & 255) << 24, j5 = c[4] & 255 | (c[5] & 255) << 8 | (c[6] & 255) << 16 | (c[7] & 255) << 24, j6 = p[0] & 255 | (p[1] & 255) << 8 | (p[2] & 255) << 16 | (p[3] & 255) << 24, j7 = p[4] & 255 | (p[5] & 255) << 8 | (p[6] & 255) << 16 | (p[7] & 255) << 24, j8 = p[8] & 255 | (p[9] & 255) << 8 | (p[10] & 255) << 16 | (p[11] & 255) << 24, j9 = p[12] & 255 | (p[13] & 255) << 8 | (p[14] & 255) << 16 | (p[15] & 255) << 24, j10 = c[8] & 255 | (c[9] & 255) << 8 | (c[10] & 255) << 16 | (c[11] & 255) << 24, j11 = k[16] & 255 | (k[17] & 255) << 8 | (k[18] & 255) << 16 | (k[19] & 255) << 24, j12 = k[20] & 255 | (k[21] & 255) << 8 | (k[22] & 255) << 16 | (k[23] & 255) << 24, j13 = k[24] & 255 | (k[25] & 255) << 8 | (k[26] & 255) << 16 | (k[27] & 255) << 24, j14 = k[28] & 255 | (k[29] & 255) << 8 | (k[30] & 255) << 16 | (k[31] & 255) << 24, j15 = c[12] & 255 | (c[13] & 255) << 8 | (c[14] & 255) << 16 | (c[15] & 255) << 24;
961
+ var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, x15 = j15, u;
962
+ for (var i = 0; i < 20; i += 2) {
963
+ u = x0 + x12 | 0;
964
+ x4 ^= u << 7 | u >>> 25;
965
+ u = x4 + x0 | 0;
966
+ x8 ^= u << 9 | u >>> 23;
967
+ u = x8 + x4 | 0;
968
+ x12 ^= u << 13 | u >>> 19;
969
+ u = x12 + x8 | 0;
970
+ x0 ^= u << 18 | u >>> 14;
971
+ u = x5 + x1 | 0;
972
+ x9 ^= u << 7 | u >>> 25;
973
+ u = x9 + x5 | 0;
974
+ x13 ^= u << 9 | u >>> 23;
975
+ u = x13 + x9 | 0;
976
+ x1 ^= u << 13 | u >>> 19;
977
+ u = x1 + x13 | 0;
978
+ x5 ^= u << 18 | u >>> 14;
979
+ u = x10 + x6 | 0;
980
+ x14 ^= u << 7 | u >>> 25;
981
+ u = x14 + x10 | 0;
982
+ x2 ^= u << 9 | u >>> 23;
983
+ u = x2 + x14 | 0;
984
+ x6 ^= u << 13 | u >>> 19;
985
+ u = x6 + x2 | 0;
986
+ x10 ^= u << 18 | u >>> 14;
987
+ u = x15 + x11 | 0;
988
+ x3 ^= u << 7 | u >>> 25;
989
+ u = x3 + x15 | 0;
990
+ x7 ^= u << 9 | u >>> 23;
991
+ u = x7 + x3 | 0;
992
+ x11 ^= u << 13 | u >>> 19;
993
+ u = x11 + x7 | 0;
994
+ x15 ^= u << 18 | u >>> 14;
995
+ u = x0 + x3 | 0;
996
+ x1 ^= u << 7 | u >>> 25;
997
+ u = x1 + x0 | 0;
998
+ x2 ^= u << 9 | u >>> 23;
999
+ u = x2 + x1 | 0;
1000
+ x3 ^= u << 13 | u >>> 19;
1001
+ u = x3 + x2 | 0;
1002
+ x0 ^= u << 18 | u >>> 14;
1003
+ u = x5 + x4 | 0;
1004
+ x6 ^= u << 7 | u >>> 25;
1005
+ u = x6 + x5 | 0;
1006
+ x7 ^= u << 9 | u >>> 23;
1007
+ u = x7 + x6 | 0;
1008
+ x4 ^= u << 13 | u >>> 19;
1009
+ u = x4 + x7 | 0;
1010
+ x5 ^= u << 18 | u >>> 14;
1011
+ u = x10 + x9 | 0;
1012
+ x11 ^= u << 7 | u >>> 25;
1013
+ u = x11 + x10 | 0;
1014
+ x8 ^= u << 9 | u >>> 23;
1015
+ u = x8 + x11 | 0;
1016
+ x9 ^= u << 13 | u >>> 19;
1017
+ u = x9 + x8 | 0;
1018
+ x10 ^= u << 18 | u >>> 14;
1019
+ u = x15 + x14 | 0;
1020
+ x12 ^= u << 7 | u >>> 25;
1021
+ u = x12 + x15 | 0;
1022
+ x13 ^= u << 9 | u >>> 23;
1023
+ u = x13 + x12 | 0;
1024
+ x14 ^= u << 13 | u >>> 19;
1025
+ u = x14 + x13 | 0;
1026
+ x15 ^= u << 18 | u >>> 14;
1027
+ }
1028
+ x0 = x0 + j0 | 0;
1029
+ x1 = x1 + j1 | 0;
1030
+ x2 = x2 + j2 | 0;
1031
+ x3 = x3 + j3 | 0;
1032
+ x4 = x4 + j4 | 0;
1033
+ x5 = x5 + j5 | 0;
1034
+ x6 = x6 + j6 | 0;
1035
+ x7 = x7 + j7 | 0;
1036
+ x8 = x8 + j8 | 0;
1037
+ x9 = x9 + j9 | 0;
1038
+ x10 = x10 + j10 | 0;
1039
+ x11 = x11 + j11 | 0;
1040
+ x12 = x12 + j12 | 0;
1041
+ x13 = x13 + j13 | 0;
1042
+ x14 = x14 + j14 | 0;
1043
+ x15 = x15 + j15 | 0;
1044
+ o[0] = x0 >>> 0 & 255;
1045
+ o[1] = x0 >>> 8 & 255;
1046
+ o[2] = x0 >>> 16 & 255;
1047
+ o[3] = x0 >>> 24 & 255;
1048
+ o[4] = x1 >>> 0 & 255;
1049
+ o[5] = x1 >>> 8 & 255;
1050
+ o[6] = x1 >>> 16 & 255;
1051
+ o[7] = x1 >>> 24 & 255;
1052
+ o[8] = x2 >>> 0 & 255;
1053
+ o[9] = x2 >>> 8 & 255;
1054
+ o[10] = x2 >>> 16 & 255;
1055
+ o[11] = x2 >>> 24 & 255;
1056
+ o[12] = x3 >>> 0 & 255;
1057
+ o[13] = x3 >>> 8 & 255;
1058
+ o[14] = x3 >>> 16 & 255;
1059
+ o[15] = x3 >>> 24 & 255;
1060
+ o[16] = x4 >>> 0 & 255;
1061
+ o[17] = x4 >>> 8 & 255;
1062
+ o[18] = x4 >>> 16 & 255;
1063
+ o[19] = x4 >>> 24 & 255;
1064
+ o[20] = x5 >>> 0 & 255;
1065
+ o[21] = x5 >>> 8 & 255;
1066
+ o[22] = x5 >>> 16 & 255;
1067
+ o[23] = x5 >>> 24 & 255;
1068
+ o[24] = x6 >>> 0 & 255;
1069
+ o[25] = x6 >>> 8 & 255;
1070
+ o[26] = x6 >>> 16 & 255;
1071
+ o[27] = x6 >>> 24 & 255;
1072
+ o[28] = x7 >>> 0 & 255;
1073
+ o[29] = x7 >>> 8 & 255;
1074
+ o[30] = x7 >>> 16 & 255;
1075
+ o[31] = x7 >>> 24 & 255;
1076
+ o[32] = x8 >>> 0 & 255;
1077
+ o[33] = x8 >>> 8 & 255;
1078
+ o[34] = x8 >>> 16 & 255;
1079
+ o[35] = x8 >>> 24 & 255;
1080
+ o[36] = x9 >>> 0 & 255;
1081
+ o[37] = x9 >>> 8 & 255;
1082
+ o[38] = x9 >>> 16 & 255;
1083
+ o[39] = x9 >>> 24 & 255;
1084
+ o[40] = x10 >>> 0 & 255;
1085
+ o[41] = x10 >>> 8 & 255;
1086
+ o[42] = x10 >>> 16 & 255;
1087
+ o[43] = x10 >>> 24 & 255;
1088
+ o[44] = x11 >>> 0 & 255;
1089
+ o[45] = x11 >>> 8 & 255;
1090
+ o[46] = x11 >>> 16 & 255;
1091
+ o[47] = x11 >>> 24 & 255;
1092
+ o[48] = x12 >>> 0 & 255;
1093
+ o[49] = x12 >>> 8 & 255;
1094
+ o[50] = x12 >>> 16 & 255;
1095
+ o[51] = x12 >>> 24 & 255;
1096
+ o[52] = x13 >>> 0 & 255;
1097
+ o[53] = x13 >>> 8 & 255;
1098
+ o[54] = x13 >>> 16 & 255;
1099
+ o[55] = x13 >>> 24 & 255;
1100
+ o[56] = x14 >>> 0 & 255;
1101
+ o[57] = x14 >>> 8 & 255;
1102
+ o[58] = x14 >>> 16 & 255;
1103
+ o[59] = x14 >>> 24 & 255;
1104
+ o[60] = x15 >>> 0 & 255;
1105
+ o[61] = x15 >>> 8 & 255;
1106
+ o[62] = x15 >>> 16 & 255;
1107
+ o[63] = x15 >>> 24 & 255;
1108
+ }
1109
+ function core_hsalsa20(o, p, k, c) {
1110
+ var j0 = c[0] & 255 | (c[1] & 255) << 8 | (c[2] & 255) << 16 | (c[3] & 255) << 24, j1 = k[0] & 255 | (k[1] & 255) << 8 | (k[2] & 255) << 16 | (k[3] & 255) << 24, j2 = k[4] & 255 | (k[5] & 255) << 8 | (k[6] & 255) << 16 | (k[7] & 255) << 24, j3 = k[8] & 255 | (k[9] & 255) << 8 | (k[10] & 255) << 16 | (k[11] & 255) << 24, j4 = k[12] & 255 | (k[13] & 255) << 8 | (k[14] & 255) << 16 | (k[15] & 255) << 24, j5 = c[4] & 255 | (c[5] & 255) << 8 | (c[6] & 255) << 16 | (c[7] & 255) << 24, j6 = p[0] & 255 | (p[1] & 255) << 8 | (p[2] & 255) << 16 | (p[3] & 255) << 24, j7 = p[4] & 255 | (p[5] & 255) << 8 | (p[6] & 255) << 16 | (p[7] & 255) << 24, j8 = p[8] & 255 | (p[9] & 255) << 8 | (p[10] & 255) << 16 | (p[11] & 255) << 24, j9 = p[12] & 255 | (p[13] & 255) << 8 | (p[14] & 255) << 16 | (p[15] & 255) << 24, j10 = c[8] & 255 | (c[9] & 255) << 8 | (c[10] & 255) << 16 | (c[11] & 255) << 24, j11 = k[16] & 255 | (k[17] & 255) << 8 | (k[18] & 255) << 16 | (k[19] & 255) << 24, j12 = k[20] & 255 | (k[21] & 255) << 8 | (k[22] & 255) << 16 | (k[23] & 255) << 24, j13 = k[24] & 255 | (k[25] & 255) << 8 | (k[26] & 255) << 16 | (k[27] & 255) << 24, j14 = k[28] & 255 | (k[29] & 255) << 8 | (k[30] & 255) << 16 | (k[31] & 255) << 24, j15 = c[12] & 255 | (c[13] & 255) << 8 | (c[14] & 255) << 16 | (c[15] & 255) << 24;
1111
+ var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, x15 = j15, u;
1112
+ for (var i = 0; i < 20; i += 2) {
1113
+ u = x0 + x12 | 0;
1114
+ x4 ^= u << 7 | u >>> 25;
1115
+ u = x4 + x0 | 0;
1116
+ x8 ^= u << 9 | u >>> 23;
1117
+ u = x8 + x4 | 0;
1118
+ x12 ^= u << 13 | u >>> 19;
1119
+ u = x12 + x8 | 0;
1120
+ x0 ^= u << 18 | u >>> 14;
1121
+ u = x5 + x1 | 0;
1122
+ x9 ^= u << 7 | u >>> 25;
1123
+ u = x9 + x5 | 0;
1124
+ x13 ^= u << 9 | u >>> 23;
1125
+ u = x13 + x9 | 0;
1126
+ x1 ^= u << 13 | u >>> 19;
1127
+ u = x1 + x13 | 0;
1128
+ x5 ^= u << 18 | u >>> 14;
1129
+ u = x10 + x6 | 0;
1130
+ x14 ^= u << 7 | u >>> 25;
1131
+ u = x14 + x10 | 0;
1132
+ x2 ^= u << 9 | u >>> 23;
1133
+ u = x2 + x14 | 0;
1134
+ x6 ^= u << 13 | u >>> 19;
1135
+ u = x6 + x2 | 0;
1136
+ x10 ^= u << 18 | u >>> 14;
1137
+ u = x15 + x11 | 0;
1138
+ x3 ^= u << 7 | u >>> 25;
1139
+ u = x3 + x15 | 0;
1140
+ x7 ^= u << 9 | u >>> 23;
1141
+ u = x7 + x3 | 0;
1142
+ x11 ^= u << 13 | u >>> 19;
1143
+ u = x11 + x7 | 0;
1144
+ x15 ^= u << 18 | u >>> 14;
1145
+ u = x0 + x3 | 0;
1146
+ x1 ^= u << 7 | u >>> 25;
1147
+ u = x1 + x0 | 0;
1148
+ x2 ^= u << 9 | u >>> 23;
1149
+ u = x2 + x1 | 0;
1150
+ x3 ^= u << 13 | u >>> 19;
1151
+ u = x3 + x2 | 0;
1152
+ x0 ^= u << 18 | u >>> 14;
1153
+ u = x5 + x4 | 0;
1154
+ x6 ^= u << 7 | u >>> 25;
1155
+ u = x6 + x5 | 0;
1156
+ x7 ^= u << 9 | u >>> 23;
1157
+ u = x7 + x6 | 0;
1158
+ x4 ^= u << 13 | u >>> 19;
1159
+ u = x4 + x7 | 0;
1160
+ x5 ^= u << 18 | u >>> 14;
1161
+ u = x10 + x9 | 0;
1162
+ x11 ^= u << 7 | u >>> 25;
1163
+ u = x11 + x10 | 0;
1164
+ x8 ^= u << 9 | u >>> 23;
1165
+ u = x8 + x11 | 0;
1166
+ x9 ^= u << 13 | u >>> 19;
1167
+ u = x9 + x8 | 0;
1168
+ x10 ^= u << 18 | u >>> 14;
1169
+ u = x15 + x14 | 0;
1170
+ x12 ^= u << 7 | u >>> 25;
1171
+ u = x12 + x15 | 0;
1172
+ x13 ^= u << 9 | u >>> 23;
1173
+ u = x13 + x12 | 0;
1174
+ x14 ^= u << 13 | u >>> 19;
1175
+ u = x14 + x13 | 0;
1176
+ x15 ^= u << 18 | u >>> 14;
1177
+ }
1178
+ o[0] = x0 >>> 0 & 255;
1179
+ o[1] = x0 >>> 8 & 255;
1180
+ o[2] = x0 >>> 16 & 255;
1181
+ o[3] = x0 >>> 24 & 255;
1182
+ o[4] = x5 >>> 0 & 255;
1183
+ o[5] = x5 >>> 8 & 255;
1184
+ o[6] = x5 >>> 16 & 255;
1185
+ o[7] = x5 >>> 24 & 255;
1186
+ o[8] = x10 >>> 0 & 255;
1187
+ o[9] = x10 >>> 8 & 255;
1188
+ o[10] = x10 >>> 16 & 255;
1189
+ o[11] = x10 >>> 24 & 255;
1190
+ o[12] = x15 >>> 0 & 255;
1191
+ o[13] = x15 >>> 8 & 255;
1192
+ o[14] = x15 >>> 16 & 255;
1193
+ o[15] = x15 >>> 24 & 255;
1194
+ o[16] = x6 >>> 0 & 255;
1195
+ o[17] = x6 >>> 8 & 255;
1196
+ o[18] = x6 >>> 16 & 255;
1197
+ o[19] = x6 >>> 24 & 255;
1198
+ o[20] = x7 >>> 0 & 255;
1199
+ o[21] = x7 >>> 8 & 255;
1200
+ o[22] = x7 >>> 16 & 255;
1201
+ o[23] = x7 >>> 24 & 255;
1202
+ o[24] = x8 >>> 0 & 255;
1203
+ o[25] = x8 >>> 8 & 255;
1204
+ o[26] = x8 >>> 16 & 255;
1205
+ o[27] = x8 >>> 24 & 255;
1206
+ o[28] = x9 >>> 0 & 255;
1207
+ o[29] = x9 >>> 8 & 255;
1208
+ o[30] = x9 >>> 16 & 255;
1209
+ o[31] = x9 >>> 24 & 255;
1210
+ }
1211
+ function crypto_core_salsa20(out, inp, k, c) {
1212
+ core_salsa20(out, inp, k, c);
1213
+ }
1214
+ function crypto_core_hsalsa20(out, inp, k, c) {
1215
+ core_hsalsa20(out, inp, k, c);
1216
+ }
1217
+ var sigma = new Uint8Array([
1218
+ 101,
1219
+ 120,
1220
+ 112,
1221
+ 97,
1222
+ 110,
1223
+ 100,
1224
+ 32,
1225
+ 51,
1226
+ 50,
1227
+ 45,
1228
+ 98,
1229
+ 121,
1230
+ 116,
1231
+ 101,
1232
+ 32,
1233
+ 107
1234
+ ]);
1235
+ function crypto_stream_salsa20_xor(c, cpos, m, mpos, b, n, k) {
1236
+ var z = new Uint8Array(16), x = new Uint8Array(64);
1237
+ var u, i;
1238
+ for (i = 0; i < 16; i++) z[i] = 0;
1239
+ for (i = 0; i < 8; i++) z[i] = n[i];
1240
+ while (b >= 64) {
1241
+ crypto_core_salsa20(x, z, k, sigma);
1242
+ for (i = 0; i < 64; i++) c[cpos + i] = m[mpos + i] ^ x[i];
1243
+ u = 1;
1244
+ for (i = 8; i < 16; i++) {
1245
+ u = u + (z[i] & 255) | 0;
1246
+ z[i] = u & 255;
1247
+ u >>>= 8;
1248
+ }
1249
+ b -= 64;
1250
+ cpos += 64;
1251
+ mpos += 64;
1252
+ }
1253
+ if (b > 0) {
1254
+ crypto_core_salsa20(x, z, k, sigma);
1255
+ for (i = 0; i < b; i++) c[cpos + i] = m[mpos + i] ^ x[i];
1256
+ }
1257
+ return 0;
1258
+ }
1259
+ function crypto_stream_salsa20(c, cpos, b, n, k) {
1260
+ var z = new Uint8Array(16), x = new Uint8Array(64);
1261
+ var u, i;
1262
+ for (i = 0; i < 16; i++) z[i] = 0;
1263
+ for (i = 0; i < 8; i++) z[i] = n[i];
1264
+ while (b >= 64) {
1265
+ crypto_core_salsa20(x, z, k, sigma);
1266
+ for (i = 0; i < 64; i++) c[cpos + i] = x[i];
1267
+ u = 1;
1268
+ for (i = 8; i < 16; i++) {
1269
+ u = u + (z[i] & 255) | 0;
1270
+ z[i] = u & 255;
1271
+ u >>>= 8;
1272
+ }
1273
+ b -= 64;
1274
+ cpos += 64;
1275
+ }
1276
+ if (b > 0) {
1277
+ crypto_core_salsa20(x, z, k, sigma);
1278
+ for (i = 0; i < b; i++) c[cpos + i] = x[i];
1279
+ }
1280
+ return 0;
1281
+ }
1282
+ function crypto_stream(c, cpos, d, n, k) {
1283
+ var s = new Uint8Array(32);
1284
+ crypto_core_hsalsa20(s, n, k, sigma);
1285
+ var sn = new Uint8Array(8);
1286
+ for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
1287
+ return crypto_stream_salsa20(c, cpos, d, sn, s);
1288
+ }
1289
+ function crypto_stream_xor(c, cpos, m, mpos, d, n, k) {
1290
+ var s = new Uint8Array(32);
1291
+ crypto_core_hsalsa20(s, n, k, sigma);
1292
+ var sn = new Uint8Array(8);
1293
+ for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
1294
+ return crypto_stream_salsa20_xor(c, cpos, m, mpos, d, sn, s);
1295
+ }
1296
+ var poly1305 = function(key) {
1297
+ this.buffer = new Uint8Array(16);
1298
+ this.r = new Uint16Array(10);
1299
+ this.h = new Uint16Array(10);
1300
+ this.pad = new Uint16Array(8);
1301
+ this.leftover = 0;
1302
+ this.fin = 0;
1303
+ var t0 = key[0] & 255 | (key[1] & 255) << 8, t1, t2, t3, t4, t5, t6, t7;
1304
+ this.r[0] = t0 & 8191;
1305
+ t1 = key[2] & 255 | (key[3] & 255) << 8;
1306
+ this.r[1] = (t0 >>> 13 | t1 << 3) & 8191;
1307
+ t2 = key[4] & 255 | (key[5] & 255) << 8;
1308
+ this.r[2] = (t1 >>> 10 | t2 << 6) & 7939;
1309
+ t3 = key[6] & 255 | (key[7] & 255) << 8;
1310
+ this.r[3] = (t2 >>> 7 | t3 << 9) & 8191;
1311
+ t4 = key[8] & 255 | (key[9] & 255) << 8;
1312
+ this.r[4] = (t3 >>> 4 | t4 << 12) & 255;
1313
+ this.r[5] = t4 >>> 1 & 8190;
1314
+ t5 = key[10] & 255 | (key[11] & 255) << 8;
1315
+ this.r[6] = (t4 >>> 14 | t5 << 2) & 8191;
1316
+ t6 = key[12] & 255 | (key[13] & 255) << 8;
1317
+ this.r[7] = (t5 >>> 11 | t6 << 5) & 8065;
1318
+ t7 = key[14] & 255 | (key[15] & 255) << 8;
1319
+ this.r[8] = (t6 >>> 8 | t7 << 8) & 8191;
1320
+ this.r[9] = t7 >>> 5 & 127;
1321
+ this.pad[0] = key[16] & 255 | (key[17] & 255) << 8;
1322
+ this.pad[1] = key[18] & 255 | (key[19] & 255) << 8;
1323
+ this.pad[2] = key[20] & 255 | (key[21] & 255) << 8;
1324
+ this.pad[3] = key[22] & 255 | (key[23] & 255) << 8;
1325
+ this.pad[4] = key[24] & 255 | (key[25] & 255) << 8;
1326
+ this.pad[5] = key[26] & 255 | (key[27] & 255) << 8;
1327
+ this.pad[6] = key[28] & 255 | (key[29] & 255) << 8;
1328
+ this.pad[7] = key[30] & 255 | (key[31] & 255) << 8;
1329
+ };
1330
+ poly1305.prototype.blocks = function(m, mpos, bytes) {
1331
+ var hibit = this.fin ? 0 : 2048;
1332
+ var t0, t1, t2, t3, t4, t5, t6, t7, c;
1333
+ var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
1334
+ var h0 = this.h[0], h1 = this.h[1], h2 = this.h[2], h3 = this.h[3], h4 = this.h[4], h5 = this.h[5], h6 = this.h[6], h7 = this.h[7], h8 = this.h[8], h9 = this.h[9];
1335
+ var r0 = this.r[0], r1 = this.r[1], r2 = this.r[2], r3 = this.r[3], r4 = this.r[4], r5 = this.r[5], r6 = this.r[6], r7 = this.r[7], r8 = this.r[8], r9 = this.r[9];
1336
+ while (bytes >= 16) {
1337
+ t0 = m[mpos + 0] & 255 | (m[mpos + 1] & 255) << 8;
1338
+ h0 += t0 & 8191;
1339
+ t1 = m[mpos + 2] & 255 | (m[mpos + 3] & 255) << 8;
1340
+ h1 += (t0 >>> 13 | t1 << 3) & 8191;
1341
+ t2 = m[mpos + 4] & 255 | (m[mpos + 5] & 255) << 8;
1342
+ h2 += (t1 >>> 10 | t2 << 6) & 8191;
1343
+ t3 = m[mpos + 6] & 255 | (m[mpos + 7] & 255) << 8;
1344
+ h3 += (t2 >>> 7 | t3 << 9) & 8191;
1345
+ t4 = m[mpos + 8] & 255 | (m[mpos + 9] & 255) << 8;
1346
+ h4 += (t3 >>> 4 | t4 << 12) & 8191;
1347
+ h5 += t4 >>> 1 & 8191;
1348
+ t5 = m[mpos + 10] & 255 | (m[mpos + 11] & 255) << 8;
1349
+ h6 += (t4 >>> 14 | t5 << 2) & 8191;
1350
+ t6 = m[mpos + 12] & 255 | (m[mpos + 13] & 255) << 8;
1351
+ h7 += (t5 >>> 11 | t6 << 5) & 8191;
1352
+ t7 = m[mpos + 14] & 255 | (m[mpos + 15] & 255) << 8;
1353
+ h8 += (t6 >>> 8 | t7 << 8) & 8191;
1354
+ h9 += t7 >>> 5 | hibit;
1355
+ c = 0;
1356
+ d0 = c;
1357
+ d0 += h0 * r0;
1358
+ d0 += h1 * (5 * r9);
1359
+ d0 += h2 * (5 * r8);
1360
+ d0 += h3 * (5 * r7);
1361
+ d0 += h4 * (5 * r6);
1362
+ c = d0 >>> 13;
1363
+ d0 &= 8191;
1364
+ d0 += h5 * (5 * r5);
1365
+ d0 += h6 * (5 * r4);
1366
+ d0 += h7 * (5 * r3);
1367
+ d0 += h8 * (5 * r2);
1368
+ d0 += h9 * (5 * r1);
1369
+ c += d0 >>> 13;
1370
+ d0 &= 8191;
1371
+ d1 = c;
1372
+ d1 += h0 * r1;
1373
+ d1 += h1 * r0;
1374
+ d1 += h2 * (5 * r9);
1375
+ d1 += h3 * (5 * r8);
1376
+ d1 += h4 * (5 * r7);
1377
+ c = d1 >>> 13;
1378
+ d1 &= 8191;
1379
+ d1 += h5 * (5 * r6);
1380
+ d1 += h6 * (5 * r5);
1381
+ d1 += h7 * (5 * r4);
1382
+ d1 += h8 * (5 * r3);
1383
+ d1 += h9 * (5 * r2);
1384
+ c += d1 >>> 13;
1385
+ d1 &= 8191;
1386
+ d2 = c;
1387
+ d2 += h0 * r2;
1388
+ d2 += h1 * r1;
1389
+ d2 += h2 * r0;
1390
+ d2 += h3 * (5 * r9);
1391
+ d2 += h4 * (5 * r8);
1392
+ c = d2 >>> 13;
1393
+ d2 &= 8191;
1394
+ d2 += h5 * (5 * r7);
1395
+ d2 += h6 * (5 * r6);
1396
+ d2 += h7 * (5 * r5);
1397
+ d2 += h8 * (5 * r4);
1398
+ d2 += h9 * (5 * r3);
1399
+ c += d2 >>> 13;
1400
+ d2 &= 8191;
1401
+ d3 = c;
1402
+ d3 += h0 * r3;
1403
+ d3 += h1 * r2;
1404
+ d3 += h2 * r1;
1405
+ d3 += h3 * r0;
1406
+ d3 += h4 * (5 * r9);
1407
+ c = d3 >>> 13;
1408
+ d3 &= 8191;
1409
+ d3 += h5 * (5 * r8);
1410
+ d3 += h6 * (5 * r7);
1411
+ d3 += h7 * (5 * r6);
1412
+ d3 += h8 * (5 * r5);
1413
+ d3 += h9 * (5 * r4);
1414
+ c += d3 >>> 13;
1415
+ d3 &= 8191;
1416
+ d4 = c;
1417
+ d4 += h0 * r4;
1418
+ d4 += h1 * r3;
1419
+ d4 += h2 * r2;
1420
+ d4 += h3 * r1;
1421
+ d4 += h4 * r0;
1422
+ c = d4 >>> 13;
1423
+ d4 &= 8191;
1424
+ d4 += h5 * (5 * r9);
1425
+ d4 += h6 * (5 * r8);
1426
+ d4 += h7 * (5 * r7);
1427
+ d4 += h8 * (5 * r6);
1428
+ d4 += h9 * (5 * r5);
1429
+ c += d4 >>> 13;
1430
+ d4 &= 8191;
1431
+ d5 = c;
1432
+ d5 += h0 * r5;
1433
+ d5 += h1 * r4;
1434
+ d5 += h2 * r3;
1435
+ d5 += h3 * r2;
1436
+ d5 += h4 * r1;
1437
+ c = d5 >>> 13;
1438
+ d5 &= 8191;
1439
+ d5 += h5 * r0;
1440
+ d5 += h6 * (5 * r9);
1441
+ d5 += h7 * (5 * r8);
1442
+ d5 += h8 * (5 * r7);
1443
+ d5 += h9 * (5 * r6);
1444
+ c += d5 >>> 13;
1445
+ d5 &= 8191;
1446
+ d6 = c;
1447
+ d6 += h0 * r6;
1448
+ d6 += h1 * r5;
1449
+ d6 += h2 * r4;
1450
+ d6 += h3 * r3;
1451
+ d6 += h4 * r2;
1452
+ c = d6 >>> 13;
1453
+ d6 &= 8191;
1454
+ d6 += h5 * r1;
1455
+ d6 += h6 * r0;
1456
+ d6 += h7 * (5 * r9);
1457
+ d6 += h8 * (5 * r8);
1458
+ d6 += h9 * (5 * r7);
1459
+ c += d6 >>> 13;
1460
+ d6 &= 8191;
1461
+ d7 = c;
1462
+ d7 += h0 * r7;
1463
+ d7 += h1 * r6;
1464
+ d7 += h2 * r5;
1465
+ d7 += h3 * r4;
1466
+ d7 += h4 * r3;
1467
+ c = d7 >>> 13;
1468
+ d7 &= 8191;
1469
+ d7 += h5 * r2;
1470
+ d7 += h6 * r1;
1471
+ d7 += h7 * r0;
1472
+ d7 += h8 * (5 * r9);
1473
+ d7 += h9 * (5 * r8);
1474
+ c += d7 >>> 13;
1475
+ d7 &= 8191;
1476
+ d8 = c;
1477
+ d8 += h0 * r8;
1478
+ d8 += h1 * r7;
1479
+ d8 += h2 * r6;
1480
+ d8 += h3 * r5;
1481
+ d8 += h4 * r4;
1482
+ c = d8 >>> 13;
1483
+ d8 &= 8191;
1484
+ d8 += h5 * r3;
1485
+ d8 += h6 * r2;
1486
+ d8 += h7 * r1;
1487
+ d8 += h8 * r0;
1488
+ d8 += h9 * (5 * r9);
1489
+ c += d8 >>> 13;
1490
+ d8 &= 8191;
1491
+ d9 = c;
1492
+ d9 += h0 * r9;
1493
+ d9 += h1 * r8;
1494
+ d9 += h2 * r7;
1495
+ d9 += h3 * r6;
1496
+ d9 += h4 * r5;
1497
+ c = d9 >>> 13;
1498
+ d9 &= 8191;
1499
+ d9 += h5 * r4;
1500
+ d9 += h6 * r3;
1501
+ d9 += h7 * r2;
1502
+ d9 += h8 * r1;
1503
+ d9 += h9 * r0;
1504
+ c += d9 >>> 13;
1505
+ d9 &= 8191;
1506
+ c = (c << 2) + c | 0;
1507
+ c = c + d0 | 0;
1508
+ d0 = c & 8191;
1509
+ c = c >>> 13;
1510
+ d1 += c;
1511
+ h0 = d0;
1512
+ h1 = d1;
1513
+ h2 = d2;
1514
+ h3 = d3;
1515
+ h4 = d4;
1516
+ h5 = d5;
1517
+ h6 = d6;
1518
+ h7 = d7;
1519
+ h8 = d8;
1520
+ h9 = d9;
1521
+ mpos += 16;
1522
+ bytes -= 16;
1523
+ }
1524
+ this.h[0] = h0;
1525
+ this.h[1] = h1;
1526
+ this.h[2] = h2;
1527
+ this.h[3] = h3;
1528
+ this.h[4] = h4;
1529
+ this.h[5] = h5;
1530
+ this.h[6] = h6;
1531
+ this.h[7] = h7;
1532
+ this.h[8] = h8;
1533
+ this.h[9] = h9;
1534
+ };
1535
+ poly1305.prototype.finish = function(mac, macpos) {
1536
+ var g = new Uint16Array(10);
1537
+ var c, mask, f, i;
1538
+ if (this.leftover) {
1539
+ i = this.leftover;
1540
+ this.buffer[i++] = 1;
1541
+ for (; i < 16; i++) this.buffer[i] = 0;
1542
+ this.fin = 1;
1543
+ this.blocks(this.buffer, 0, 16);
1544
+ }
1545
+ c = this.h[1] >>> 13;
1546
+ this.h[1] &= 8191;
1547
+ for (i = 2; i < 10; i++) {
1548
+ this.h[i] += c;
1549
+ c = this.h[i] >>> 13;
1550
+ this.h[i] &= 8191;
1551
+ }
1552
+ this.h[0] += c * 5;
1553
+ c = this.h[0] >>> 13;
1554
+ this.h[0] &= 8191;
1555
+ this.h[1] += c;
1556
+ c = this.h[1] >>> 13;
1557
+ this.h[1] &= 8191;
1558
+ this.h[2] += c;
1559
+ g[0] = this.h[0] + 5;
1560
+ c = g[0] >>> 13;
1561
+ g[0] &= 8191;
1562
+ for (i = 1; i < 10; i++) {
1563
+ g[i] = this.h[i] + c;
1564
+ c = g[i] >>> 13;
1565
+ g[i] &= 8191;
1566
+ }
1567
+ g[9] -= 8192;
1568
+ mask = (c ^ 1) - 1;
1569
+ for (i = 0; i < 10; i++) g[i] &= mask;
1570
+ mask = ~mask;
1571
+ for (i = 0; i < 10; i++) this.h[i] = this.h[i] & mask | g[i];
1572
+ this.h[0] = (this.h[0] | this.h[1] << 13) & 65535;
1573
+ this.h[1] = (this.h[1] >>> 3 | this.h[2] << 10) & 65535;
1574
+ this.h[2] = (this.h[2] >>> 6 | this.h[3] << 7) & 65535;
1575
+ this.h[3] = (this.h[3] >>> 9 | this.h[4] << 4) & 65535;
1576
+ this.h[4] = (this.h[4] >>> 12 | this.h[5] << 1 | this.h[6] << 14) & 65535;
1577
+ this.h[5] = (this.h[6] >>> 2 | this.h[7] << 11) & 65535;
1578
+ this.h[6] = (this.h[7] >>> 5 | this.h[8] << 8) & 65535;
1579
+ this.h[7] = (this.h[8] >>> 8 | this.h[9] << 5) & 65535;
1580
+ f = this.h[0] + this.pad[0];
1581
+ this.h[0] = f & 65535;
1582
+ for (i = 1; i < 8; i++) {
1583
+ f = (this.h[i] + this.pad[i] | 0) + (f >>> 16) | 0;
1584
+ this.h[i] = f & 65535;
1585
+ }
1586
+ mac[macpos + 0] = this.h[0] >>> 0 & 255;
1587
+ mac[macpos + 1] = this.h[0] >>> 8 & 255;
1588
+ mac[macpos + 2] = this.h[1] >>> 0 & 255;
1589
+ mac[macpos + 3] = this.h[1] >>> 8 & 255;
1590
+ mac[macpos + 4] = this.h[2] >>> 0 & 255;
1591
+ mac[macpos + 5] = this.h[2] >>> 8 & 255;
1592
+ mac[macpos + 6] = this.h[3] >>> 0 & 255;
1593
+ mac[macpos + 7] = this.h[3] >>> 8 & 255;
1594
+ mac[macpos + 8] = this.h[4] >>> 0 & 255;
1595
+ mac[macpos + 9] = this.h[4] >>> 8 & 255;
1596
+ mac[macpos + 10] = this.h[5] >>> 0 & 255;
1597
+ mac[macpos + 11] = this.h[5] >>> 8 & 255;
1598
+ mac[macpos + 12] = this.h[6] >>> 0 & 255;
1599
+ mac[macpos + 13] = this.h[6] >>> 8 & 255;
1600
+ mac[macpos + 14] = this.h[7] >>> 0 & 255;
1601
+ mac[macpos + 15] = this.h[7] >>> 8 & 255;
1602
+ };
1603
+ poly1305.prototype.update = function(m, mpos, bytes) {
1604
+ var i, want;
1605
+ if (this.leftover) {
1606
+ want = 16 - this.leftover;
1607
+ if (want > bytes) want = bytes;
1608
+ for (i = 0; i < want; i++) this.buffer[this.leftover + i] = m[mpos + i];
1609
+ bytes -= want;
1610
+ mpos += want;
1611
+ this.leftover += want;
1612
+ if (this.leftover < 16) return;
1613
+ this.blocks(this.buffer, 0, 16);
1614
+ this.leftover = 0;
1615
+ }
1616
+ if (bytes >= 16) {
1617
+ want = bytes - bytes % 16;
1618
+ this.blocks(m, mpos, want);
1619
+ mpos += want;
1620
+ bytes -= want;
1621
+ }
1622
+ if (bytes) {
1623
+ for (i = 0; i < bytes; i++) this.buffer[this.leftover + i] = m[mpos + i];
1624
+ this.leftover += bytes;
1625
+ }
1626
+ };
1627
+ function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
1628
+ var s = new poly1305(k);
1629
+ s.update(m, mpos, n);
1630
+ s.finish(out, outpos);
1631
+ return 0;
1632
+ }
1633
+ function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
1634
+ var x = new Uint8Array(16);
1635
+ crypto_onetimeauth(x, 0, m, mpos, n, k);
1636
+ return crypto_verify_16(h, hpos, x, 0);
1637
+ }
1638
+ function crypto_secretbox(c, m, d, n, k) {
1639
+ var i;
1640
+ if (d < 32) return -1;
1641
+ crypto_stream_xor(c, 0, m, 0, d, n, k);
1642
+ crypto_onetimeauth(c, 16, c, 32, d - 32, c);
1643
+ for (i = 0; i < 16; i++) c[i] = 0;
1644
+ return 0;
1645
+ }
1646
+ function crypto_secretbox_open(m, c, d, n, k) {
1647
+ var i;
1648
+ var x = new Uint8Array(32);
1649
+ if (d < 32) return -1;
1650
+ crypto_stream(x, 0, 32, n, k);
1651
+ if (crypto_onetimeauth_verify(c, 16, c, 32, d - 32, x) !== 0) return -1;
1652
+ crypto_stream_xor(m, 0, c, 0, d, n, k);
1653
+ for (i = 0; i < 32; i++) m[i] = 0;
1654
+ return 0;
1655
+ }
1656
+ function set25519(r, a) {
1657
+ var i;
1658
+ for (i = 0; i < 16; i++) r[i] = a[i] | 0;
1659
+ }
1660
+ function car25519(o) {
1661
+ var i, v, c = 1;
1662
+ for (i = 0; i < 16; i++) {
1663
+ v = o[i] + c + 65535;
1664
+ c = Math.floor(v / 65536);
1665
+ o[i] = v - c * 65536;
1666
+ }
1667
+ o[0] += c - 1 + 37 * (c - 1);
1668
+ }
1669
+ function sel25519(p, q, b) {
1670
+ var t, c = ~(b - 1);
1671
+ for (var i = 0; i < 16; i++) {
1672
+ t = c & (p[i] ^ q[i]);
1673
+ p[i] ^= t;
1674
+ q[i] ^= t;
1675
+ }
1676
+ }
1677
+ function pack25519(o, n) {
1678
+ var i, j, b;
1679
+ var m = gf(), t = gf();
1680
+ for (i = 0; i < 16; i++) t[i] = n[i];
1681
+ car25519(t);
1682
+ car25519(t);
1683
+ car25519(t);
1684
+ for (j = 0; j < 2; j++) {
1685
+ m[0] = t[0] - 65517;
1686
+ for (i = 1; i < 15; i++) {
1687
+ m[i] = t[i] - 65535 - (m[i - 1] >> 16 & 1);
1688
+ m[i - 1] &= 65535;
1689
+ }
1690
+ m[15] = t[15] - 32767 - (m[14] >> 16 & 1);
1691
+ b = m[15] >> 16 & 1;
1692
+ m[14] &= 65535;
1693
+ sel25519(t, m, 1 - b);
1694
+ }
1695
+ for (i = 0; i < 16; i++) {
1696
+ o[2 * i] = t[i] & 255;
1697
+ o[2 * i + 1] = t[i] >> 8;
1698
+ }
1699
+ }
1700
+ function neq25519(a, b) {
1701
+ var c = new Uint8Array(32), d = new Uint8Array(32);
1702
+ pack25519(c, a);
1703
+ pack25519(d, b);
1704
+ return crypto_verify_32(c, 0, d, 0);
1705
+ }
1706
+ function par25519(a) {
1707
+ var d = new Uint8Array(32);
1708
+ pack25519(d, a);
1709
+ return d[0] & 1;
1710
+ }
1711
+ function unpack25519(o, n) {
1712
+ var i;
1713
+ for (i = 0; i < 16; i++) o[i] = n[2 * i] + (n[2 * i + 1] << 8);
1714
+ o[15] &= 32767;
1715
+ }
1716
+ function A(o, a, b) {
1717
+ for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
1718
+ }
1719
+ function Z(o, a, b) {
1720
+ for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
1721
+ }
1722
+ function M(o, a, b) {
1723
+ var v, c, t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5], b6 = b[6], b7 = b[7], b8 = b[8], b9 = b[9], b10 = b[10], b11 = b[11], b12 = b[12], b13 = b[13], b14 = b[14], b15 = b[15];
1724
+ v = a[0];
1725
+ t0 += v * b0;
1726
+ t1 += v * b1;
1727
+ t2 += v * b2;
1728
+ t3 += v * b3;
1729
+ t4 += v * b4;
1730
+ t5 += v * b5;
1731
+ t6 += v * b6;
1732
+ t7 += v * b7;
1733
+ t8 += v * b8;
1734
+ t9 += v * b9;
1735
+ t10 += v * b10;
1736
+ t11 += v * b11;
1737
+ t12 += v * b12;
1738
+ t13 += v * b13;
1739
+ t14 += v * b14;
1740
+ t15 += v * b15;
1741
+ v = a[1];
1742
+ t1 += v * b0;
1743
+ t2 += v * b1;
1744
+ t3 += v * b2;
1745
+ t4 += v * b3;
1746
+ t5 += v * b4;
1747
+ t6 += v * b5;
1748
+ t7 += v * b6;
1749
+ t8 += v * b7;
1750
+ t9 += v * b8;
1751
+ t10 += v * b9;
1752
+ t11 += v * b10;
1753
+ t12 += v * b11;
1754
+ t13 += v * b12;
1755
+ t14 += v * b13;
1756
+ t15 += v * b14;
1757
+ t16 += v * b15;
1758
+ v = a[2];
1759
+ t2 += v * b0;
1760
+ t3 += v * b1;
1761
+ t4 += v * b2;
1762
+ t5 += v * b3;
1763
+ t6 += v * b4;
1764
+ t7 += v * b5;
1765
+ t8 += v * b6;
1766
+ t9 += v * b7;
1767
+ t10 += v * b8;
1768
+ t11 += v * b9;
1769
+ t12 += v * b10;
1770
+ t13 += v * b11;
1771
+ t14 += v * b12;
1772
+ t15 += v * b13;
1773
+ t16 += v * b14;
1774
+ t17 += v * b15;
1775
+ v = a[3];
1776
+ t3 += v * b0;
1777
+ t4 += v * b1;
1778
+ t5 += v * b2;
1779
+ t6 += v * b3;
1780
+ t7 += v * b4;
1781
+ t8 += v * b5;
1782
+ t9 += v * b6;
1783
+ t10 += v * b7;
1784
+ t11 += v * b8;
1785
+ t12 += v * b9;
1786
+ t13 += v * b10;
1787
+ t14 += v * b11;
1788
+ t15 += v * b12;
1789
+ t16 += v * b13;
1790
+ t17 += v * b14;
1791
+ t18 += v * b15;
1792
+ v = a[4];
1793
+ t4 += v * b0;
1794
+ t5 += v * b1;
1795
+ t6 += v * b2;
1796
+ t7 += v * b3;
1797
+ t8 += v * b4;
1798
+ t9 += v * b5;
1799
+ t10 += v * b6;
1800
+ t11 += v * b7;
1801
+ t12 += v * b8;
1802
+ t13 += v * b9;
1803
+ t14 += v * b10;
1804
+ t15 += v * b11;
1805
+ t16 += v * b12;
1806
+ t17 += v * b13;
1807
+ t18 += v * b14;
1808
+ t19 += v * b15;
1809
+ v = a[5];
1810
+ t5 += v * b0;
1811
+ t6 += v * b1;
1812
+ t7 += v * b2;
1813
+ t8 += v * b3;
1814
+ t9 += v * b4;
1815
+ t10 += v * b5;
1816
+ t11 += v * b6;
1817
+ t12 += v * b7;
1818
+ t13 += v * b8;
1819
+ t14 += v * b9;
1820
+ t15 += v * b10;
1821
+ t16 += v * b11;
1822
+ t17 += v * b12;
1823
+ t18 += v * b13;
1824
+ t19 += v * b14;
1825
+ t20 += v * b15;
1826
+ v = a[6];
1827
+ t6 += v * b0;
1828
+ t7 += v * b1;
1829
+ t8 += v * b2;
1830
+ t9 += v * b3;
1831
+ t10 += v * b4;
1832
+ t11 += v * b5;
1833
+ t12 += v * b6;
1834
+ t13 += v * b7;
1835
+ t14 += v * b8;
1836
+ t15 += v * b9;
1837
+ t16 += v * b10;
1838
+ t17 += v * b11;
1839
+ t18 += v * b12;
1840
+ t19 += v * b13;
1841
+ t20 += v * b14;
1842
+ t21 += v * b15;
1843
+ v = a[7];
1844
+ t7 += v * b0;
1845
+ t8 += v * b1;
1846
+ t9 += v * b2;
1847
+ t10 += v * b3;
1848
+ t11 += v * b4;
1849
+ t12 += v * b5;
1850
+ t13 += v * b6;
1851
+ t14 += v * b7;
1852
+ t15 += v * b8;
1853
+ t16 += v * b9;
1854
+ t17 += v * b10;
1855
+ t18 += v * b11;
1856
+ t19 += v * b12;
1857
+ t20 += v * b13;
1858
+ t21 += v * b14;
1859
+ t22 += v * b15;
1860
+ v = a[8];
1861
+ t8 += v * b0;
1862
+ t9 += v * b1;
1863
+ t10 += v * b2;
1864
+ t11 += v * b3;
1865
+ t12 += v * b4;
1866
+ t13 += v * b5;
1867
+ t14 += v * b6;
1868
+ t15 += v * b7;
1869
+ t16 += v * b8;
1870
+ t17 += v * b9;
1871
+ t18 += v * b10;
1872
+ t19 += v * b11;
1873
+ t20 += v * b12;
1874
+ t21 += v * b13;
1875
+ t22 += v * b14;
1876
+ t23 += v * b15;
1877
+ v = a[9];
1878
+ t9 += v * b0;
1879
+ t10 += v * b1;
1880
+ t11 += v * b2;
1881
+ t12 += v * b3;
1882
+ t13 += v * b4;
1883
+ t14 += v * b5;
1884
+ t15 += v * b6;
1885
+ t16 += v * b7;
1886
+ t17 += v * b8;
1887
+ t18 += v * b9;
1888
+ t19 += v * b10;
1889
+ t20 += v * b11;
1890
+ t21 += v * b12;
1891
+ t22 += v * b13;
1892
+ t23 += v * b14;
1893
+ t24 += v * b15;
1894
+ v = a[10];
1895
+ t10 += v * b0;
1896
+ t11 += v * b1;
1897
+ t12 += v * b2;
1898
+ t13 += v * b3;
1899
+ t14 += v * b4;
1900
+ t15 += v * b5;
1901
+ t16 += v * b6;
1902
+ t17 += v * b7;
1903
+ t18 += v * b8;
1904
+ t19 += v * b9;
1905
+ t20 += v * b10;
1906
+ t21 += v * b11;
1907
+ t22 += v * b12;
1908
+ t23 += v * b13;
1909
+ t24 += v * b14;
1910
+ t25 += v * b15;
1911
+ v = a[11];
1912
+ t11 += v * b0;
1913
+ t12 += v * b1;
1914
+ t13 += v * b2;
1915
+ t14 += v * b3;
1916
+ t15 += v * b4;
1917
+ t16 += v * b5;
1918
+ t17 += v * b6;
1919
+ t18 += v * b7;
1920
+ t19 += v * b8;
1921
+ t20 += v * b9;
1922
+ t21 += v * b10;
1923
+ t22 += v * b11;
1924
+ t23 += v * b12;
1925
+ t24 += v * b13;
1926
+ t25 += v * b14;
1927
+ t26 += v * b15;
1928
+ v = a[12];
1929
+ t12 += v * b0;
1930
+ t13 += v * b1;
1931
+ t14 += v * b2;
1932
+ t15 += v * b3;
1933
+ t16 += v * b4;
1934
+ t17 += v * b5;
1935
+ t18 += v * b6;
1936
+ t19 += v * b7;
1937
+ t20 += v * b8;
1938
+ t21 += v * b9;
1939
+ t22 += v * b10;
1940
+ t23 += v * b11;
1941
+ t24 += v * b12;
1942
+ t25 += v * b13;
1943
+ t26 += v * b14;
1944
+ t27 += v * b15;
1945
+ v = a[13];
1946
+ t13 += v * b0;
1947
+ t14 += v * b1;
1948
+ t15 += v * b2;
1949
+ t16 += v * b3;
1950
+ t17 += v * b4;
1951
+ t18 += v * b5;
1952
+ t19 += v * b6;
1953
+ t20 += v * b7;
1954
+ t21 += v * b8;
1955
+ t22 += v * b9;
1956
+ t23 += v * b10;
1957
+ t24 += v * b11;
1958
+ t25 += v * b12;
1959
+ t26 += v * b13;
1960
+ t27 += v * b14;
1961
+ t28 += v * b15;
1962
+ v = a[14];
1963
+ t14 += v * b0;
1964
+ t15 += v * b1;
1965
+ t16 += v * b2;
1966
+ t17 += v * b3;
1967
+ t18 += v * b4;
1968
+ t19 += v * b5;
1969
+ t20 += v * b6;
1970
+ t21 += v * b7;
1971
+ t22 += v * b8;
1972
+ t23 += v * b9;
1973
+ t24 += v * b10;
1974
+ t25 += v * b11;
1975
+ t26 += v * b12;
1976
+ t27 += v * b13;
1977
+ t28 += v * b14;
1978
+ t29 += v * b15;
1979
+ v = a[15];
1980
+ t15 += v * b0;
1981
+ t16 += v * b1;
1982
+ t17 += v * b2;
1983
+ t18 += v * b3;
1984
+ t19 += v * b4;
1985
+ t20 += v * b5;
1986
+ t21 += v * b6;
1987
+ t22 += v * b7;
1988
+ t23 += v * b8;
1989
+ t24 += v * b9;
1990
+ t25 += v * b10;
1991
+ t26 += v * b11;
1992
+ t27 += v * b12;
1993
+ t28 += v * b13;
1994
+ t29 += v * b14;
1995
+ t30 += v * b15;
1996
+ t0 += 38 * t16;
1997
+ t1 += 38 * t17;
1998
+ t2 += 38 * t18;
1999
+ t3 += 38 * t19;
2000
+ t4 += 38 * t20;
2001
+ t5 += 38 * t21;
2002
+ t6 += 38 * t22;
2003
+ t7 += 38 * t23;
2004
+ t8 += 38 * t24;
2005
+ t9 += 38 * t25;
2006
+ t10 += 38 * t26;
2007
+ t11 += 38 * t27;
2008
+ t12 += 38 * t28;
2009
+ t13 += 38 * t29;
2010
+ t14 += 38 * t30;
2011
+ c = 1;
2012
+ v = t0 + c + 65535;
2013
+ c = Math.floor(v / 65536);
2014
+ t0 = v - c * 65536;
2015
+ v = t1 + c + 65535;
2016
+ c = Math.floor(v / 65536);
2017
+ t1 = v - c * 65536;
2018
+ v = t2 + c + 65535;
2019
+ c = Math.floor(v / 65536);
2020
+ t2 = v - c * 65536;
2021
+ v = t3 + c + 65535;
2022
+ c = Math.floor(v / 65536);
2023
+ t3 = v - c * 65536;
2024
+ v = t4 + c + 65535;
2025
+ c = Math.floor(v / 65536);
2026
+ t4 = v - c * 65536;
2027
+ v = t5 + c + 65535;
2028
+ c = Math.floor(v / 65536);
2029
+ t5 = v - c * 65536;
2030
+ v = t6 + c + 65535;
2031
+ c = Math.floor(v / 65536);
2032
+ t6 = v - c * 65536;
2033
+ v = t7 + c + 65535;
2034
+ c = Math.floor(v / 65536);
2035
+ t7 = v - c * 65536;
2036
+ v = t8 + c + 65535;
2037
+ c = Math.floor(v / 65536);
2038
+ t8 = v - c * 65536;
2039
+ v = t9 + c + 65535;
2040
+ c = Math.floor(v / 65536);
2041
+ t9 = v - c * 65536;
2042
+ v = t10 + c + 65535;
2043
+ c = Math.floor(v / 65536);
2044
+ t10 = v - c * 65536;
2045
+ v = t11 + c + 65535;
2046
+ c = Math.floor(v / 65536);
2047
+ t11 = v - c * 65536;
2048
+ v = t12 + c + 65535;
2049
+ c = Math.floor(v / 65536);
2050
+ t12 = v - c * 65536;
2051
+ v = t13 + c + 65535;
2052
+ c = Math.floor(v / 65536);
2053
+ t13 = v - c * 65536;
2054
+ v = t14 + c + 65535;
2055
+ c = Math.floor(v / 65536);
2056
+ t14 = v - c * 65536;
2057
+ v = t15 + c + 65535;
2058
+ c = Math.floor(v / 65536);
2059
+ t15 = v - c * 65536;
2060
+ t0 += c - 1 + 37 * (c - 1);
2061
+ c = 1;
2062
+ v = t0 + c + 65535;
2063
+ c = Math.floor(v / 65536);
2064
+ t0 = v - c * 65536;
2065
+ v = t1 + c + 65535;
2066
+ c = Math.floor(v / 65536);
2067
+ t1 = v - c * 65536;
2068
+ v = t2 + c + 65535;
2069
+ c = Math.floor(v / 65536);
2070
+ t2 = v - c * 65536;
2071
+ v = t3 + c + 65535;
2072
+ c = Math.floor(v / 65536);
2073
+ t3 = v - c * 65536;
2074
+ v = t4 + c + 65535;
2075
+ c = Math.floor(v / 65536);
2076
+ t4 = v - c * 65536;
2077
+ v = t5 + c + 65535;
2078
+ c = Math.floor(v / 65536);
2079
+ t5 = v - c * 65536;
2080
+ v = t6 + c + 65535;
2081
+ c = Math.floor(v / 65536);
2082
+ t6 = v - c * 65536;
2083
+ v = t7 + c + 65535;
2084
+ c = Math.floor(v / 65536);
2085
+ t7 = v - c * 65536;
2086
+ v = t8 + c + 65535;
2087
+ c = Math.floor(v / 65536);
2088
+ t8 = v - c * 65536;
2089
+ v = t9 + c + 65535;
2090
+ c = Math.floor(v / 65536);
2091
+ t9 = v - c * 65536;
2092
+ v = t10 + c + 65535;
2093
+ c = Math.floor(v / 65536);
2094
+ t10 = v - c * 65536;
2095
+ v = t11 + c + 65535;
2096
+ c = Math.floor(v / 65536);
2097
+ t11 = v - c * 65536;
2098
+ v = t12 + c + 65535;
2099
+ c = Math.floor(v / 65536);
2100
+ t12 = v - c * 65536;
2101
+ v = t13 + c + 65535;
2102
+ c = Math.floor(v / 65536);
2103
+ t13 = v - c * 65536;
2104
+ v = t14 + c + 65535;
2105
+ c = Math.floor(v / 65536);
2106
+ t14 = v - c * 65536;
2107
+ v = t15 + c + 65535;
2108
+ c = Math.floor(v / 65536);
2109
+ t15 = v - c * 65536;
2110
+ t0 += c - 1 + 37 * (c - 1);
2111
+ o[0] = t0;
2112
+ o[1] = t1;
2113
+ o[2] = t2;
2114
+ o[3] = t3;
2115
+ o[4] = t4;
2116
+ o[5] = t5;
2117
+ o[6] = t6;
2118
+ o[7] = t7;
2119
+ o[8] = t8;
2120
+ o[9] = t9;
2121
+ o[10] = t10;
2122
+ o[11] = t11;
2123
+ o[12] = t12;
2124
+ o[13] = t13;
2125
+ o[14] = t14;
2126
+ o[15] = t15;
2127
+ }
2128
+ function S(o, a) {
2129
+ M(o, a, a);
2130
+ }
2131
+ function inv25519(o, i) {
2132
+ var c = gf();
2133
+ var a;
2134
+ for (a = 0; a < 16; a++) c[a] = i[a];
2135
+ for (a = 253; a >= 0; a--) {
2136
+ S(c, c);
2137
+ if (a !== 2 && a !== 4) M(c, c, i);
2138
+ }
2139
+ for (a = 0; a < 16; a++) o[a] = c[a];
2140
+ }
2141
+ function pow2523(o, i) {
2142
+ var c = gf();
2143
+ var a;
2144
+ for (a = 0; a < 16; a++) c[a] = i[a];
2145
+ for (a = 250; a >= 0; a--) {
2146
+ S(c, c);
2147
+ if (a !== 1) M(c, c, i);
2148
+ }
2149
+ for (a = 0; a < 16; a++) o[a] = c[a];
2150
+ }
2151
+ function crypto_scalarmult(q, n, p) {
2152
+ var z = new Uint8Array(32);
2153
+ var x = new Float64Array(80), r, i;
2154
+ var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf();
2155
+ for (i = 0; i < 31; i++) z[i] = n[i];
2156
+ z[31] = n[31] & 127 | 64;
2157
+ z[0] &= 248;
2158
+ unpack25519(x, p);
2159
+ for (i = 0; i < 16; i++) {
2160
+ b[i] = x[i];
2161
+ d[i] = a[i] = c[i] = 0;
2162
+ }
2163
+ a[0] = d[0] = 1;
2164
+ for (i = 254; i >= 0; --i) {
2165
+ r = z[i >>> 3] >>> (i & 7) & 1;
2166
+ sel25519(a, b, r);
2167
+ sel25519(c, d, r);
2168
+ A(e, a, c);
2169
+ Z(a, a, c);
2170
+ A(c, b, d);
2171
+ Z(b, b, d);
2172
+ S(d, e);
2173
+ S(f, a);
2174
+ M(a, c, a);
2175
+ M(c, b, e);
2176
+ A(e, a, c);
2177
+ Z(a, a, c);
2178
+ S(b, a);
2179
+ Z(c, d, f);
2180
+ M(a, c, _121665);
2181
+ A(a, a, d);
2182
+ M(c, c, a);
2183
+ M(a, d, f);
2184
+ M(d, b, x);
2185
+ S(b, e);
2186
+ sel25519(a, b, r);
2187
+ sel25519(c, d, r);
2188
+ }
2189
+ for (i = 0; i < 16; i++) {
2190
+ x[i + 16] = a[i];
2191
+ x[i + 32] = c[i];
2192
+ x[i + 48] = b[i];
2193
+ x[i + 64] = d[i];
2194
+ }
2195
+ var x32 = x.subarray(32);
2196
+ var x16 = x.subarray(16);
2197
+ inv25519(x32, x32);
2198
+ M(x16, x16, x32);
2199
+ pack25519(q, x16);
2200
+ return 0;
2201
+ }
2202
+ function crypto_scalarmult_base(q, n) {
2203
+ return crypto_scalarmult(q, n, _9);
2204
+ }
2205
+ function crypto_box_keypair(y, x) {
2206
+ randombytes(x, 32);
2207
+ return crypto_scalarmult_base(y, x);
2208
+ }
2209
+ function crypto_box_beforenm(k, y, x) {
2210
+ var s = new Uint8Array(32);
2211
+ crypto_scalarmult(s, x, y);
2212
+ return crypto_core_hsalsa20(k, _0, s, sigma);
2213
+ }
2214
+ var crypto_box_afternm = crypto_secretbox;
2215
+ var crypto_box_open_afternm = crypto_secretbox_open;
2216
+ function crypto_box(c, m, d, n, y, x) {
2217
+ var k = new Uint8Array(32);
2218
+ crypto_box_beforenm(k, y, x);
2219
+ return crypto_box_afternm(c, m, d, n, k);
2220
+ }
2221
+ function crypto_box_open(m, c, d, n, y, x) {
2222
+ var k = new Uint8Array(32);
2223
+ crypto_box_beforenm(k, y, x);
2224
+ return crypto_box_open_afternm(m, c, d, n, k);
2225
+ }
2226
+ var K = [
2227
+ 1116352408,
2228
+ 3609767458,
2229
+ 1899447441,
2230
+ 602891725,
2231
+ 3049323471,
2232
+ 3964484399,
2233
+ 3921009573,
2234
+ 2173295548,
2235
+ 961987163,
2236
+ 4081628472,
2237
+ 1508970993,
2238
+ 3053834265,
2239
+ 2453635748,
2240
+ 2937671579,
2241
+ 2870763221,
2242
+ 3664609560,
2243
+ 3624381080,
2244
+ 2734883394,
2245
+ 310598401,
2246
+ 1164996542,
2247
+ 607225278,
2248
+ 1323610764,
2249
+ 1426881987,
2250
+ 3590304994,
2251
+ 1925078388,
2252
+ 4068182383,
2253
+ 2162078206,
2254
+ 991336113,
2255
+ 2614888103,
2256
+ 633803317,
2257
+ 3248222580,
2258
+ 3479774868,
2259
+ 3835390401,
2260
+ 2666613458,
2261
+ 4022224774,
2262
+ 944711139,
2263
+ 264347078,
2264
+ 2341262773,
2265
+ 604807628,
2266
+ 2007800933,
2267
+ 770255983,
2268
+ 1495990901,
2269
+ 1249150122,
2270
+ 1856431235,
2271
+ 1555081692,
2272
+ 3175218132,
2273
+ 1996064986,
2274
+ 2198950837,
2275
+ 2554220882,
2276
+ 3999719339,
2277
+ 2821834349,
2278
+ 766784016,
2279
+ 2952996808,
2280
+ 2566594879,
2281
+ 3210313671,
2282
+ 3203337956,
2283
+ 3336571891,
2284
+ 1034457026,
2285
+ 3584528711,
2286
+ 2466948901,
2287
+ 113926993,
2288
+ 3758326383,
2289
+ 338241895,
2290
+ 168717936,
2291
+ 666307205,
2292
+ 1188179964,
2293
+ 773529912,
2294
+ 1546045734,
2295
+ 1294757372,
2296
+ 1522805485,
2297
+ 1396182291,
2298
+ 2643833823,
2299
+ 1695183700,
2300
+ 2343527390,
2301
+ 1986661051,
2302
+ 1014477480,
2303
+ 2177026350,
2304
+ 1206759142,
2305
+ 2456956037,
2306
+ 344077627,
2307
+ 2730485921,
2308
+ 1290863460,
2309
+ 2820302411,
2310
+ 3158454273,
2311
+ 3259730800,
2312
+ 3505952657,
2313
+ 3345764771,
2314
+ 106217008,
2315
+ 3516065817,
2316
+ 3606008344,
2317
+ 3600352804,
2318
+ 1432725776,
2319
+ 4094571909,
2320
+ 1467031594,
2321
+ 275423344,
2322
+ 851169720,
2323
+ 430227734,
2324
+ 3100823752,
2325
+ 506948616,
2326
+ 1363258195,
2327
+ 659060556,
2328
+ 3750685593,
2329
+ 883997877,
2330
+ 3785050280,
2331
+ 958139571,
2332
+ 3318307427,
2333
+ 1322822218,
2334
+ 3812723403,
2335
+ 1537002063,
2336
+ 2003034995,
2337
+ 1747873779,
2338
+ 3602036899,
2339
+ 1955562222,
2340
+ 1575990012,
2341
+ 2024104815,
2342
+ 1125592928,
2343
+ 2227730452,
2344
+ 2716904306,
2345
+ 2361852424,
2346
+ 442776044,
2347
+ 2428436474,
2348
+ 593698344,
2349
+ 2756734187,
2350
+ 3733110249,
2351
+ 3204031479,
2352
+ 2999351573,
2353
+ 3329325298,
2354
+ 3815920427,
2355
+ 3391569614,
2356
+ 3928383900,
2357
+ 3515267271,
2358
+ 566280711,
2359
+ 3940187606,
2360
+ 3454069534,
2361
+ 4118630271,
2362
+ 4000239992,
2363
+ 116418474,
2364
+ 1914138554,
2365
+ 174292421,
2366
+ 2731055270,
2367
+ 289380356,
2368
+ 3203993006,
2369
+ 460393269,
2370
+ 320620315,
2371
+ 685471733,
2372
+ 587496836,
2373
+ 852142971,
2374
+ 1086792851,
2375
+ 1017036298,
2376
+ 365543100,
2377
+ 1126000580,
2378
+ 2618297676,
2379
+ 1288033470,
2380
+ 3409855158,
2381
+ 1501505948,
2382
+ 4234509866,
2383
+ 1607167915,
2384
+ 987167468,
2385
+ 1816402316,
2386
+ 1246189591
2387
+ ];
2388
+ function crypto_hashblocks_hl(hh, hl, m, n) {
2389
+ var wh = new Int32Array(16), wl = new Int32Array(16), bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, th, tl, i, j, h, l, a, b, c, d;
2390
+ var ah0 = hh[0], ah1 = hh[1], ah2 = hh[2], ah3 = hh[3], ah4 = hh[4], ah5 = hh[5], ah6 = hh[6], ah7 = hh[7], al0 = hl[0], al1 = hl[1], al2 = hl[2], al3 = hl[3], al4 = hl[4], al5 = hl[5], al6 = hl[6], al7 = hl[7];
2391
+ var pos = 0;
2392
+ while (n >= 128) {
2393
+ for (i = 0; i < 16; i++) {
2394
+ j = 8 * i + pos;
2395
+ wh[i] = m[j + 0] << 24 | m[j + 1] << 16 | m[j + 2] << 8 | m[j + 3];
2396
+ wl[i] = m[j + 4] << 24 | m[j + 5] << 16 | m[j + 6] << 8 | m[j + 7];
2397
+ }
2398
+ for (i = 0; i < 80; i++) {
2399
+ bh0 = ah0;
2400
+ bh1 = ah1;
2401
+ bh2 = ah2;
2402
+ bh3 = ah3;
2403
+ bh4 = ah4;
2404
+ bh5 = ah5;
2405
+ bh6 = ah6;
2406
+ bh7 = ah7;
2407
+ bl0 = al0;
2408
+ bl1 = al1;
2409
+ bl2 = al2;
2410
+ bl3 = al3;
2411
+ bl4 = al4;
2412
+ bl5 = al5;
2413
+ bl6 = al6;
2414
+ bl7 = al7;
2415
+ h = ah7;
2416
+ l = al7;
2417
+ a = l & 65535;
2418
+ b = l >>> 16;
2419
+ c = h & 65535;
2420
+ d = h >>> 16;
2421
+ h = (ah4 >>> 14 | al4 << 18) ^ (ah4 >>> 18 | al4 << 14) ^ (al4 >>> 9 | ah4 << 23);
2422
+ l = (al4 >>> 14 | ah4 << 18) ^ (al4 >>> 18 | ah4 << 14) ^ (ah4 >>> 9 | al4 << 23);
2423
+ a += l & 65535;
2424
+ b += l >>> 16;
2425
+ c += h & 65535;
2426
+ d += h >>> 16;
2427
+ h = ah4 & ah5 ^ ~ah4 & ah6;
2428
+ l = al4 & al5 ^ ~al4 & al6;
2429
+ a += l & 65535;
2430
+ b += l >>> 16;
2431
+ c += h & 65535;
2432
+ d += h >>> 16;
2433
+ h = K[i * 2];
2434
+ l = K[i * 2 + 1];
2435
+ a += l & 65535;
2436
+ b += l >>> 16;
2437
+ c += h & 65535;
2438
+ d += h >>> 16;
2439
+ h = wh[i % 16];
2440
+ l = wl[i % 16];
2441
+ a += l & 65535;
2442
+ b += l >>> 16;
2443
+ c += h & 65535;
2444
+ d += h >>> 16;
2445
+ b += a >>> 16;
2446
+ c += b >>> 16;
2447
+ d += c >>> 16;
2448
+ th = c & 65535 | d << 16;
2449
+ tl = a & 65535 | b << 16;
2450
+ h = th;
2451
+ l = tl;
2452
+ a = l & 65535;
2453
+ b = l >>> 16;
2454
+ c = h & 65535;
2455
+ d = h >>> 16;
2456
+ h = (ah0 >>> 28 | al0 << 4) ^ (al0 >>> 2 | ah0 << 30) ^ (al0 >>> 7 | ah0 << 25);
2457
+ l = (al0 >>> 28 | ah0 << 4) ^ (ah0 >>> 2 | al0 << 30) ^ (ah0 >>> 7 | al0 << 25);
2458
+ a += l & 65535;
2459
+ b += l >>> 16;
2460
+ c += h & 65535;
2461
+ d += h >>> 16;
2462
+ h = ah0 & ah1 ^ ah0 & ah2 ^ ah1 & ah2;
2463
+ l = al0 & al1 ^ al0 & al2 ^ al1 & al2;
2464
+ a += l & 65535;
2465
+ b += l >>> 16;
2466
+ c += h & 65535;
2467
+ d += h >>> 16;
2468
+ b += a >>> 16;
2469
+ c += b >>> 16;
2470
+ d += c >>> 16;
2471
+ bh7 = c & 65535 | d << 16;
2472
+ bl7 = a & 65535 | b << 16;
2473
+ h = bh3;
2474
+ l = bl3;
2475
+ a = l & 65535;
2476
+ b = l >>> 16;
2477
+ c = h & 65535;
2478
+ d = h >>> 16;
2479
+ h = th;
2480
+ l = tl;
2481
+ a += l & 65535;
2482
+ b += l >>> 16;
2483
+ c += h & 65535;
2484
+ d += h >>> 16;
2485
+ b += a >>> 16;
2486
+ c += b >>> 16;
2487
+ d += c >>> 16;
2488
+ bh3 = c & 65535 | d << 16;
2489
+ bl3 = a & 65535 | b << 16;
2490
+ ah1 = bh0;
2491
+ ah2 = bh1;
2492
+ ah3 = bh2;
2493
+ ah4 = bh3;
2494
+ ah5 = bh4;
2495
+ ah6 = bh5;
2496
+ ah7 = bh6;
2497
+ ah0 = bh7;
2498
+ al1 = bl0;
2499
+ al2 = bl1;
2500
+ al3 = bl2;
2501
+ al4 = bl3;
2502
+ al5 = bl4;
2503
+ al6 = bl5;
2504
+ al7 = bl6;
2505
+ al0 = bl7;
2506
+ if (i % 16 === 15) for (j = 0; j < 16; j++) {
2507
+ h = wh[j];
2508
+ l = wl[j];
2509
+ a = l & 65535;
2510
+ b = l >>> 16;
2511
+ c = h & 65535;
2512
+ d = h >>> 16;
2513
+ h = wh[(j + 9) % 16];
2514
+ l = wl[(j + 9) % 16];
2515
+ a += l & 65535;
2516
+ b += l >>> 16;
2517
+ c += h & 65535;
2518
+ d += h >>> 16;
2519
+ th = wh[(j + 1) % 16];
2520
+ tl = wl[(j + 1) % 16];
2521
+ h = (th >>> 1 | tl << 31) ^ (th >>> 8 | tl << 24) ^ th >>> 7;
2522
+ l = (tl >>> 1 | th << 31) ^ (tl >>> 8 | th << 24) ^ (tl >>> 7 | th << 25);
2523
+ a += l & 65535;
2524
+ b += l >>> 16;
2525
+ c += h & 65535;
2526
+ d += h >>> 16;
2527
+ th = wh[(j + 14) % 16];
2528
+ tl = wl[(j + 14) % 16];
2529
+ h = (th >>> 19 | tl << 13) ^ (tl >>> 29 | th << 3) ^ th >>> 6;
2530
+ l = (tl >>> 19 | th << 13) ^ (th >>> 29 | tl << 3) ^ (tl >>> 6 | th << 26);
2531
+ a += l & 65535;
2532
+ b += l >>> 16;
2533
+ c += h & 65535;
2534
+ d += h >>> 16;
2535
+ b += a >>> 16;
2536
+ c += b >>> 16;
2537
+ d += c >>> 16;
2538
+ wh[j] = c & 65535 | d << 16;
2539
+ wl[j] = a & 65535 | b << 16;
2540
+ }
2541
+ }
2542
+ h = ah0;
2543
+ l = al0;
2544
+ a = l & 65535;
2545
+ b = l >>> 16;
2546
+ c = h & 65535;
2547
+ d = h >>> 16;
2548
+ h = hh[0];
2549
+ l = hl[0];
2550
+ a += l & 65535;
2551
+ b += l >>> 16;
2552
+ c += h & 65535;
2553
+ d += h >>> 16;
2554
+ b += a >>> 16;
2555
+ c += b >>> 16;
2556
+ d += c >>> 16;
2557
+ hh[0] = ah0 = c & 65535 | d << 16;
2558
+ hl[0] = al0 = a & 65535 | b << 16;
2559
+ h = ah1;
2560
+ l = al1;
2561
+ a = l & 65535;
2562
+ b = l >>> 16;
2563
+ c = h & 65535;
2564
+ d = h >>> 16;
2565
+ h = hh[1];
2566
+ l = hl[1];
2567
+ a += l & 65535;
2568
+ b += l >>> 16;
2569
+ c += h & 65535;
2570
+ d += h >>> 16;
2571
+ b += a >>> 16;
2572
+ c += b >>> 16;
2573
+ d += c >>> 16;
2574
+ hh[1] = ah1 = c & 65535 | d << 16;
2575
+ hl[1] = al1 = a & 65535 | b << 16;
2576
+ h = ah2;
2577
+ l = al2;
2578
+ a = l & 65535;
2579
+ b = l >>> 16;
2580
+ c = h & 65535;
2581
+ d = h >>> 16;
2582
+ h = hh[2];
2583
+ l = hl[2];
2584
+ a += l & 65535;
2585
+ b += l >>> 16;
2586
+ c += h & 65535;
2587
+ d += h >>> 16;
2588
+ b += a >>> 16;
2589
+ c += b >>> 16;
2590
+ d += c >>> 16;
2591
+ hh[2] = ah2 = c & 65535 | d << 16;
2592
+ hl[2] = al2 = a & 65535 | b << 16;
2593
+ h = ah3;
2594
+ l = al3;
2595
+ a = l & 65535;
2596
+ b = l >>> 16;
2597
+ c = h & 65535;
2598
+ d = h >>> 16;
2599
+ h = hh[3];
2600
+ l = hl[3];
2601
+ a += l & 65535;
2602
+ b += l >>> 16;
2603
+ c += h & 65535;
2604
+ d += h >>> 16;
2605
+ b += a >>> 16;
2606
+ c += b >>> 16;
2607
+ d += c >>> 16;
2608
+ hh[3] = ah3 = c & 65535 | d << 16;
2609
+ hl[3] = al3 = a & 65535 | b << 16;
2610
+ h = ah4;
2611
+ l = al4;
2612
+ a = l & 65535;
2613
+ b = l >>> 16;
2614
+ c = h & 65535;
2615
+ d = h >>> 16;
2616
+ h = hh[4];
2617
+ l = hl[4];
2618
+ a += l & 65535;
2619
+ b += l >>> 16;
2620
+ c += h & 65535;
2621
+ d += h >>> 16;
2622
+ b += a >>> 16;
2623
+ c += b >>> 16;
2624
+ d += c >>> 16;
2625
+ hh[4] = ah4 = c & 65535 | d << 16;
2626
+ hl[4] = al4 = a & 65535 | b << 16;
2627
+ h = ah5;
2628
+ l = al5;
2629
+ a = l & 65535;
2630
+ b = l >>> 16;
2631
+ c = h & 65535;
2632
+ d = h >>> 16;
2633
+ h = hh[5];
2634
+ l = hl[5];
2635
+ a += l & 65535;
2636
+ b += l >>> 16;
2637
+ c += h & 65535;
2638
+ d += h >>> 16;
2639
+ b += a >>> 16;
2640
+ c += b >>> 16;
2641
+ d += c >>> 16;
2642
+ hh[5] = ah5 = c & 65535 | d << 16;
2643
+ hl[5] = al5 = a & 65535 | b << 16;
2644
+ h = ah6;
2645
+ l = al6;
2646
+ a = l & 65535;
2647
+ b = l >>> 16;
2648
+ c = h & 65535;
2649
+ d = h >>> 16;
2650
+ h = hh[6];
2651
+ l = hl[6];
2652
+ a += l & 65535;
2653
+ b += l >>> 16;
2654
+ c += h & 65535;
2655
+ d += h >>> 16;
2656
+ b += a >>> 16;
2657
+ c += b >>> 16;
2658
+ d += c >>> 16;
2659
+ hh[6] = ah6 = c & 65535 | d << 16;
2660
+ hl[6] = al6 = a & 65535 | b << 16;
2661
+ h = ah7;
2662
+ l = al7;
2663
+ a = l & 65535;
2664
+ b = l >>> 16;
2665
+ c = h & 65535;
2666
+ d = h >>> 16;
2667
+ h = hh[7];
2668
+ l = hl[7];
2669
+ a += l & 65535;
2670
+ b += l >>> 16;
2671
+ c += h & 65535;
2672
+ d += h >>> 16;
2673
+ b += a >>> 16;
2674
+ c += b >>> 16;
2675
+ d += c >>> 16;
2676
+ hh[7] = ah7 = c & 65535 | d << 16;
2677
+ hl[7] = al7 = a & 65535 | b << 16;
2678
+ pos += 128;
2679
+ n -= 128;
2680
+ }
2681
+ return n;
2682
+ }
2683
+ function crypto_hash(out, m, n) {
2684
+ var hh = new Int32Array(8), hl = new Int32Array(8), x = new Uint8Array(256), i, b = n;
2685
+ hh[0] = 1779033703;
2686
+ hh[1] = 3144134277;
2687
+ hh[2] = 1013904242;
2688
+ hh[3] = 2773480762;
2689
+ hh[4] = 1359893119;
2690
+ hh[5] = 2600822924;
2691
+ hh[6] = 528734635;
2692
+ hh[7] = 1541459225;
2693
+ hl[0] = 4089235720;
2694
+ hl[1] = 2227873595;
2695
+ hl[2] = 4271175723;
2696
+ hl[3] = 1595750129;
2697
+ hl[4] = 2917565137;
2698
+ hl[5] = 725511199;
2699
+ hl[6] = 4215389547;
2700
+ hl[7] = 327033209;
2701
+ crypto_hashblocks_hl(hh, hl, m, n);
2702
+ n %= 128;
2703
+ for (i = 0; i < n; i++) x[i] = m[b - n + i];
2704
+ x[n] = 128;
2705
+ n = 256 - 128 * (n < 112 ? 1 : 0);
2706
+ x[n - 9] = 0;
2707
+ ts64(x, n - 8, b / 536870912 | 0, b << 3);
2708
+ crypto_hashblocks_hl(hh, hl, x, n);
2709
+ for (i = 0; i < 8; i++) ts64(out, 8 * i, hh[i], hl[i]);
2710
+ return 0;
2711
+ }
2712
+ function add(p, q) {
2713
+ var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf(), g = gf(), h = gf(), t = gf();
2714
+ Z(a, p[1], p[0]);
2715
+ Z(t, q[1], q[0]);
2716
+ M(a, a, t);
2717
+ A(b, p[0], p[1]);
2718
+ A(t, q[0], q[1]);
2719
+ M(b, b, t);
2720
+ M(c, p[3], q[3]);
2721
+ M(c, c, D2);
2722
+ M(d, p[2], q[2]);
2723
+ A(d, d, d);
2724
+ Z(e, b, a);
2725
+ Z(f, d, c);
2726
+ A(g, d, c);
2727
+ A(h, b, a);
2728
+ M(p[0], e, f);
2729
+ M(p[1], h, g);
2730
+ M(p[2], g, f);
2731
+ M(p[3], e, h);
2732
+ }
2733
+ function cswap(p, q, b) {
2734
+ var i;
2735
+ for (i = 0; i < 4; i++) sel25519(p[i], q[i], b);
2736
+ }
2737
+ function pack(r, p) {
2738
+ var tx = gf(), ty = gf(), zi = gf();
2739
+ inv25519(zi, p[2]);
2740
+ M(tx, p[0], zi);
2741
+ M(ty, p[1], zi);
2742
+ pack25519(r, ty);
2743
+ r[31] ^= par25519(tx) << 7;
2744
+ }
2745
+ function scalarmult(p, q, s) {
2746
+ var b, i;
2747
+ set25519(p[0], gf0);
2748
+ set25519(p[1], gf1);
2749
+ set25519(p[2], gf1);
2750
+ set25519(p[3], gf0);
2751
+ for (i = 255; i >= 0; --i) {
2752
+ b = s[i / 8 | 0] >> (i & 7) & 1;
2753
+ cswap(p, q, b);
2754
+ add(q, p);
2755
+ add(p, p);
2756
+ cswap(p, q, b);
2757
+ }
2758
+ }
2759
+ function scalarbase(p, s) {
2760
+ var q = [
2761
+ gf(),
2762
+ gf(),
2763
+ gf(),
2764
+ gf()
2765
+ ];
2766
+ set25519(q[0], X);
2767
+ set25519(q[1], Y);
2768
+ set25519(q[2], gf1);
2769
+ M(q[3], X, Y);
2770
+ scalarmult(p, q, s);
2771
+ }
2772
+ function crypto_sign_keypair(pk, sk, seeded) {
2773
+ var d = new Uint8Array(64);
2774
+ var p = [
2775
+ gf(),
2776
+ gf(),
2777
+ gf(),
2778
+ gf()
2779
+ ];
2780
+ var i;
2781
+ if (!seeded) randombytes(sk, 32);
2782
+ crypto_hash(d, sk, 32);
2783
+ d[0] &= 248;
2784
+ d[31] &= 127;
2785
+ d[31] |= 64;
2786
+ scalarbase(p, d);
2787
+ pack(pk, p);
2788
+ for (i = 0; i < 32; i++) sk[i + 32] = pk[i];
2789
+ return 0;
2790
+ }
2791
+ var L = new Float64Array([
2792
+ 237,
2793
+ 211,
2794
+ 245,
2795
+ 92,
2796
+ 26,
2797
+ 99,
2798
+ 18,
2799
+ 88,
2800
+ 214,
2801
+ 156,
2802
+ 247,
2803
+ 162,
2804
+ 222,
2805
+ 249,
2806
+ 222,
2807
+ 20,
2808
+ 0,
2809
+ 0,
2810
+ 0,
2811
+ 0,
2812
+ 0,
2813
+ 0,
2814
+ 0,
2815
+ 0,
2816
+ 0,
2817
+ 0,
2818
+ 0,
2819
+ 0,
2820
+ 0,
2821
+ 0,
2822
+ 0,
2823
+ 16
2824
+ ]);
2825
+ function modL(r, x) {
2826
+ var carry, i, j, k;
2827
+ for (i = 63; i >= 32; --i) {
2828
+ carry = 0;
2829
+ for (j = i - 32, k = i - 12; j < k; ++j) {
2830
+ x[j] += carry - 16 * x[i] * L[j - (i - 32)];
2831
+ carry = Math.floor((x[j] + 128) / 256);
2832
+ x[j] -= carry * 256;
2833
+ }
2834
+ x[j] += carry;
2835
+ x[i] = 0;
2836
+ }
2837
+ carry = 0;
2838
+ for (j = 0; j < 32; j++) {
2839
+ x[j] += carry - (x[31] >> 4) * L[j];
2840
+ carry = x[j] >> 8;
2841
+ x[j] &= 255;
2842
+ }
2843
+ for (j = 0; j < 32; j++) x[j] -= carry * L[j];
2844
+ for (i = 0; i < 32; i++) {
2845
+ x[i + 1] += x[i] >> 8;
2846
+ r[i] = x[i] & 255;
2847
+ }
2848
+ }
2849
+ function reduce(r) {
2850
+ var x = new Float64Array(64), i;
2851
+ for (i = 0; i < 64; i++) x[i] = r[i];
2852
+ for (i = 0; i < 64; i++) r[i] = 0;
2853
+ modL(r, x);
2854
+ }
2855
+ function crypto_sign(sm, m, n, sk) {
2856
+ var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
2857
+ var i, j, x = new Float64Array(64);
2858
+ var p = [
2859
+ gf(),
2860
+ gf(),
2861
+ gf(),
2862
+ gf()
2863
+ ];
2864
+ crypto_hash(d, sk, 32);
2865
+ d[0] &= 248;
2866
+ d[31] &= 127;
2867
+ d[31] |= 64;
2868
+ var smlen = n + 64;
2869
+ for (i = 0; i < n; i++) sm[64 + i] = m[i];
2870
+ for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
2871
+ crypto_hash(r, sm.subarray(32), n + 32);
2872
+ reduce(r);
2873
+ scalarbase(p, r);
2874
+ pack(sm, p);
2875
+ for (i = 32; i < 64; i++) sm[i] = sk[i];
2876
+ crypto_hash(h, sm, n + 64);
2877
+ reduce(h);
2878
+ for (i = 0; i < 64; i++) x[i] = 0;
2879
+ for (i = 0; i < 32; i++) x[i] = r[i];
2880
+ for (i = 0; i < 32; i++) for (j = 0; j < 32; j++) x[i + j] += h[i] * d[j];
2881
+ modL(sm.subarray(32), x);
2882
+ return smlen;
2883
+ }
2884
+ function unpackneg(r, p) {
2885
+ var t = gf(), chk = gf(), num = gf(), den = gf(), den2 = gf(), den4 = gf(), den6 = gf();
2886
+ set25519(r[2], gf1);
2887
+ unpack25519(r[1], p);
2888
+ S(num, r[1]);
2889
+ M(den, num, D);
2890
+ Z(num, num, r[2]);
2891
+ A(den, r[2], den);
2892
+ S(den2, den);
2893
+ S(den4, den2);
2894
+ M(den6, den4, den2);
2895
+ M(t, den6, num);
2896
+ M(t, t, den);
2897
+ pow2523(t, t);
2898
+ M(t, t, num);
2899
+ M(t, t, den);
2900
+ M(t, t, den);
2901
+ M(r[0], t, den);
2902
+ S(chk, r[0]);
2903
+ M(chk, chk, den);
2904
+ if (neq25519(chk, num)) M(r[0], r[0], I);
2905
+ S(chk, r[0]);
2906
+ M(chk, chk, den);
2907
+ if (neq25519(chk, num)) return -1;
2908
+ if (par25519(r[0]) === p[31] >> 7) Z(r[0], gf0, r[0]);
2909
+ M(r[3], r[0], r[1]);
2910
+ return 0;
2911
+ }
2912
+ function crypto_sign_open(m, sm, n, pk) {
2913
+ var i;
2914
+ var t = new Uint8Array(32), h = new Uint8Array(64);
2915
+ var p = [
2916
+ gf(),
2917
+ gf(),
2918
+ gf(),
2919
+ gf()
2920
+ ], q = [
2921
+ gf(),
2922
+ gf(),
2923
+ gf(),
2924
+ gf()
2925
+ ];
2926
+ if (n < 64) return -1;
2927
+ if (unpackneg(q, pk)) return -1;
2928
+ for (i = 0; i < n; i++) m[i] = sm[i];
2929
+ for (i = 0; i < 32; i++) m[i + 32] = pk[i];
2930
+ crypto_hash(h, m, n);
2931
+ reduce(h);
2932
+ scalarmult(p, q, h);
2933
+ scalarbase(q, sm.subarray(32));
2934
+ add(p, q);
2935
+ pack(t, p);
2936
+ n -= 64;
2937
+ if (crypto_verify_32(sm, 0, t, 0)) {
2938
+ for (i = 0; i < n; i++) m[i] = 0;
2939
+ return -1;
2940
+ }
2941
+ for (i = 0; i < n; i++) m[i] = sm[i + 64];
2942
+ return n;
2943
+ }
2944
+ var crypto_secretbox_KEYBYTES = 32, crypto_secretbox_NONCEBYTES = 24, crypto_secretbox_ZEROBYTES = 32, crypto_secretbox_BOXZEROBYTES = 16, crypto_scalarmult_BYTES = 32, crypto_scalarmult_SCALARBYTES = 32, crypto_box_PUBLICKEYBYTES = 32, crypto_box_SECRETKEYBYTES = 32, crypto_box_BEFORENMBYTES = 32, crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, crypto_sign_BYTES = 64, crypto_sign_PUBLICKEYBYTES = 32, crypto_sign_SECRETKEYBYTES = 64, crypto_sign_SEEDBYTES = 32, crypto_hash_BYTES = 64;
2945
+ nacl.lowlevel = {
2946
+ crypto_core_hsalsa20,
2947
+ crypto_stream_xor,
2948
+ crypto_stream,
2949
+ crypto_stream_salsa20_xor,
2950
+ crypto_stream_salsa20,
2951
+ crypto_onetimeauth,
2952
+ crypto_onetimeauth_verify,
2953
+ crypto_verify_16,
2954
+ crypto_verify_32,
2955
+ crypto_secretbox,
2956
+ crypto_secretbox_open,
2957
+ crypto_scalarmult,
2958
+ crypto_scalarmult_base,
2959
+ crypto_box_beforenm,
2960
+ crypto_box_afternm,
2961
+ crypto_box,
2962
+ crypto_box_open,
2963
+ crypto_box_keypair,
2964
+ crypto_hash,
2965
+ crypto_sign,
2966
+ crypto_sign_keypair,
2967
+ crypto_sign_open,
2968
+ crypto_secretbox_KEYBYTES,
2969
+ crypto_secretbox_NONCEBYTES,
2970
+ crypto_secretbox_ZEROBYTES,
2971
+ crypto_secretbox_BOXZEROBYTES,
2972
+ crypto_scalarmult_BYTES,
2973
+ crypto_scalarmult_SCALARBYTES,
2974
+ crypto_box_PUBLICKEYBYTES,
2975
+ crypto_box_SECRETKEYBYTES,
2976
+ crypto_box_BEFORENMBYTES,
2977
+ crypto_box_NONCEBYTES,
2978
+ crypto_box_ZEROBYTES,
2979
+ crypto_box_BOXZEROBYTES,
2980
+ crypto_sign_BYTES,
2981
+ crypto_sign_PUBLICKEYBYTES,
2982
+ crypto_sign_SECRETKEYBYTES,
2983
+ crypto_sign_SEEDBYTES,
2984
+ crypto_hash_BYTES,
2985
+ gf,
2986
+ D,
2987
+ L,
2988
+ pack25519,
2989
+ unpack25519,
2990
+ M,
2991
+ A,
2992
+ S,
2993
+ Z,
2994
+ pow2523,
2995
+ add,
2996
+ set25519,
2997
+ modL,
2998
+ scalarmult,
2999
+ scalarbase
3000
+ };
3001
+ function checkLengths(k, n) {
3002
+ if (k.length !== crypto_secretbox_KEYBYTES) throw new Error("bad key size");
3003
+ if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error("bad nonce size");
3004
+ }
3005
+ function checkBoxLengths(pk, sk) {
3006
+ if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error("bad public key size");
3007
+ if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error("bad secret key size");
3008
+ }
3009
+ function checkArrayTypes() {
3010
+ for (var i = 0; i < arguments.length; i++) if (!(arguments[i] instanceof Uint8Array)) throw new TypeError("unexpected type, use Uint8Array");
3011
+ }
3012
+ function cleanup(arr) {
3013
+ for (var i = 0; i < arr.length; i++) arr[i] = 0;
3014
+ }
3015
+ nacl.randomBytes = function(n) {
3016
+ var b = new Uint8Array(n);
3017
+ randombytes(b, n);
3018
+ return b;
3019
+ };
3020
+ nacl.secretbox = function(msg, nonce, key) {
3021
+ checkArrayTypes(msg, nonce, key);
3022
+ checkLengths(key, nonce);
3023
+ var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
3024
+ var c = new Uint8Array(m.length);
3025
+ for (var i = 0; i < msg.length; i++) m[i + crypto_secretbox_ZEROBYTES] = msg[i];
3026
+ crypto_secretbox(c, m, m.length, nonce, key);
3027
+ return c.subarray(crypto_secretbox_BOXZEROBYTES);
3028
+ };
3029
+ nacl.secretbox.open = function(box, nonce, key) {
3030
+ checkArrayTypes(box, nonce, key);
3031
+ checkLengths(key, nonce);
3032
+ var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
3033
+ var m = new Uint8Array(c.length);
3034
+ for (var i = 0; i < box.length; i++) c[i + crypto_secretbox_BOXZEROBYTES] = box[i];
3035
+ if (c.length < 32) return null;
3036
+ if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
3037
+ return m.subarray(crypto_secretbox_ZEROBYTES);
3038
+ };
3039
+ nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;
3040
+ nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
3041
+ nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
3042
+ nacl.scalarMult = function(n, p) {
3043
+ checkArrayTypes(n, p);
3044
+ if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
3045
+ if (p.length !== crypto_scalarmult_BYTES) throw new Error("bad p size");
3046
+ var q = new Uint8Array(crypto_scalarmult_BYTES);
3047
+ crypto_scalarmult(q, n, p);
3048
+ return q;
3049
+ };
3050
+ nacl.scalarMult.base = function(n) {
3051
+ checkArrayTypes(n);
3052
+ if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
3053
+ var q = new Uint8Array(crypto_scalarmult_BYTES);
3054
+ crypto_scalarmult_base(q, n);
3055
+ return q;
3056
+ };
3057
+ nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
3058
+ nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
3059
+ nacl.box = function(msg, nonce, publicKey, secretKey) {
3060
+ var k = nacl.box.before(publicKey, secretKey);
3061
+ return nacl.secretbox(msg, nonce, k);
3062
+ };
3063
+ nacl.box.before = function(publicKey, secretKey) {
3064
+ checkArrayTypes(publicKey, secretKey);
3065
+ checkBoxLengths(publicKey, secretKey);
3066
+ var k = new Uint8Array(crypto_box_BEFORENMBYTES);
3067
+ crypto_box_beforenm(k, publicKey, secretKey);
3068
+ return k;
3069
+ };
3070
+ nacl.box.after = nacl.secretbox;
3071
+ nacl.box.open = function(msg, nonce, publicKey, secretKey) {
3072
+ var k = nacl.box.before(publicKey, secretKey);
3073
+ return nacl.secretbox.open(msg, nonce, k);
3074
+ };
3075
+ nacl.box.open.after = nacl.secretbox.open;
3076
+ nacl.box.keyPair = function() {
3077
+ var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
3078
+ var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
3079
+ crypto_box_keypair(pk, sk);
3080
+ return {
3081
+ publicKey: pk,
3082
+ secretKey: sk
3083
+ };
3084
+ };
3085
+ nacl.box.keyPair.fromSecretKey = function(secretKey) {
3086
+ checkArrayTypes(secretKey);
3087
+ if (secretKey.length !== crypto_box_SECRETKEYBYTES) throw new Error("bad secret key size");
3088
+ var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
3089
+ crypto_scalarmult_base(pk, secretKey);
3090
+ return {
3091
+ publicKey: pk,
3092
+ secretKey: new Uint8Array(secretKey)
3093
+ };
3094
+ };
3095
+ nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
3096
+ nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
3097
+ nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
3098
+ nacl.box.nonceLength = crypto_box_NONCEBYTES;
3099
+ nacl.box.overheadLength = nacl.secretbox.overheadLength;
3100
+ nacl.sign = function(msg, secretKey) {
3101
+ checkArrayTypes(msg, secretKey);
3102
+ if (secretKey.length !== crypto_sign_SECRETKEYBYTES) throw new Error("bad secret key size");
3103
+ var signedMsg = new Uint8Array(crypto_sign_BYTES + msg.length);
3104
+ crypto_sign(signedMsg, msg, msg.length, secretKey);
3105
+ return signedMsg;
3106
+ };
3107
+ nacl.sign.open = function(signedMsg, publicKey) {
3108
+ checkArrayTypes(signedMsg, publicKey);
3109
+ if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) throw new Error("bad public key size");
3110
+ var tmp = new Uint8Array(signedMsg.length);
3111
+ var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
3112
+ if (mlen < 0) return null;
3113
+ var m = new Uint8Array(mlen);
3114
+ for (var i = 0; i < m.length; i++) m[i] = tmp[i];
3115
+ return m;
3116
+ };
3117
+ nacl.sign.detached = function(msg, secretKey) {
3118
+ var signedMsg = nacl.sign(msg, secretKey);
3119
+ var sig = new Uint8Array(crypto_sign_BYTES);
3120
+ for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
3121
+ return sig;
3122
+ };
3123
+ nacl.sign.detached.verify = function(msg, sig, publicKey) {
3124
+ checkArrayTypes(msg, sig, publicKey);
3125
+ if (sig.length !== crypto_sign_BYTES) throw new Error("bad signature size");
3126
+ if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) throw new Error("bad public key size");
3127
+ var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
3128
+ var m = new Uint8Array(crypto_sign_BYTES + msg.length);
3129
+ var i;
3130
+ for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
3131
+ for (i = 0; i < msg.length; i++) sm[i + crypto_sign_BYTES] = msg[i];
3132
+ return crypto_sign_open(m, sm, sm.length, publicKey) >= 0;
3133
+ };
3134
+ nacl.sign.keyPair = function() {
3135
+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
3136
+ var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
3137
+ crypto_sign_keypair(pk, sk);
3138
+ return {
3139
+ publicKey: pk,
3140
+ secretKey: sk
3141
+ };
3142
+ };
3143
+ nacl.sign.keyPair.fromSecretKey = function(secretKey) {
3144
+ checkArrayTypes(secretKey);
3145
+ if (secretKey.length !== crypto_sign_SECRETKEYBYTES) throw new Error("bad secret key size");
3146
+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
3147
+ for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32 + i];
3148
+ return {
3149
+ publicKey: pk,
3150
+ secretKey: new Uint8Array(secretKey)
3151
+ };
3152
+ };
3153
+ nacl.sign.keyPair.fromSeed = function(seed) {
3154
+ checkArrayTypes(seed);
3155
+ if (seed.length !== crypto_sign_SEEDBYTES) throw new Error("bad seed size");
3156
+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
3157
+ var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
3158
+ for (var i = 0; i < 32; i++) sk[i] = seed[i];
3159
+ crypto_sign_keypair(pk, sk, true);
3160
+ return {
3161
+ publicKey: pk,
3162
+ secretKey: sk
3163
+ };
3164
+ };
3165
+ nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
3166
+ nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
3167
+ nacl.sign.seedLength = crypto_sign_SEEDBYTES;
3168
+ nacl.sign.signatureLength = crypto_sign_BYTES;
3169
+ nacl.hash = function(msg) {
3170
+ checkArrayTypes(msg);
3171
+ var h = new Uint8Array(crypto_hash_BYTES);
3172
+ crypto_hash(h, msg, msg.length);
3173
+ return h;
3174
+ };
3175
+ nacl.hash.hashLength = crypto_hash_BYTES;
3176
+ nacl.verify = function(x, y) {
3177
+ checkArrayTypes(x, y);
3178
+ if (x.length === 0 || y.length === 0) return false;
3179
+ if (x.length !== y.length) return false;
3180
+ return vn(x, 0, y, 0, x.length) === 0 ? true : false;
3181
+ };
3182
+ nacl.setPRNG = function(fn) {
3183
+ randombytes = fn;
3184
+ };
3185
+ (function() {
3186
+ var crypto = typeof self !== "undefined" ? self.crypto || self.msCrypto : null;
3187
+ if (crypto && crypto.getRandomValues) {
3188
+ var QUOTA = 65536;
3189
+ nacl.setPRNG(function(x, n) {
3190
+ var i, v = new Uint8Array(n);
3191
+ for (i = 0; i < n; i += QUOTA) crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
3192
+ for (i = 0; i < n; i++) x[i] = v[i];
3193
+ cleanup(v);
3194
+ });
3195
+ } else if (typeof __require !== "undefined") {
3196
+ crypto = __require("crypto");
3197
+ if (crypto && crypto.randomBytes) nacl.setPRNG(function(x, n) {
3198
+ var i, v = crypto.randomBytes(n);
3199
+ for (i = 0; i < n; i++) x[i] = v[i];
3200
+ cleanup(v);
3201
+ });
3202
+ }
3203
+ })();
3204
+ })(typeof module !== "undefined" && module.exports ? module.exports : self.nacl = self.nacl || {});
3205
+ }));
3206
+
3207
+ //#endregion
3208
+ //#region src/curve25519.ts
3209
+ var curve25519_exports = /* @__PURE__ */ __exportAll({
3210
+ generateKeyPair: () => generateKeyPair$1,
3211
+ generateSharedSecKey: () => generateSharedSecKey
3212
+ });
3213
+ var import_nacl_fast = /* @__PURE__ */ __toESM(require_nacl_fast(), 1);
3214
+ function generateKeyPair$1() {
3215
+ const keyPair = import_nacl_fast.default.box.keyPair();
3216
+ return {
3217
+ publicKey: keyPair.publicKey,
3218
+ secretKey: keyPair.secretKey
3219
+ };
3220
+ }
3221
+ function generateSharedSecKey(priKey, pubKey) {
3222
+ return import_nacl_fast.default.scalarMult(priKey, pubKey);
3223
+ }
3224
+
3225
+ //#endregion
3226
+ //#region src/ed25519.ts
3227
+ var ed25519_exports = /* @__PURE__ */ __exportAll({
3228
+ generateKeyPair: () => generateKeyPair,
3229
+ sign: () => sign,
3230
+ verify: () => verify
3231
+ });
3232
+ function generateKeyPair() {
3233
+ const keyPair = import_nacl_fast.default.sign.keyPair();
3234
+ return {
3235
+ publicKey: keyPair.publicKey,
3236
+ secretKey: keyPair.secretKey
3237
+ };
3238
+ }
3239
+ function sign(message, secretKey) {
3240
+ return import_nacl_fast.default.sign.detached(message, secretKey);
3241
+ }
3242
+ function verify(message, signature, publicKey) {
3243
+ return import_nacl_fast.default.sign.detached.verify(message, signature, publicKey);
3244
+ }
3245
+
3246
+ //#endregion
3247
+ //#region src/hkdf.ts
3248
+ function hkdf_default(options) {
3249
+ return Buffer.from(hkdfSync(options.hash, options.key, options.salt, options.info, options.length));
3250
+ }
3251
+
3252
+ //#endregion
3253
+ export { chacha20_exports as Chacha20, curve25519_exports as Curve25519, ed25519_exports as Ed25519, hkdf_default as hkdf };
2
3254
  //# sourceMappingURL=index.mjs.map