UNPKG

tweetnacljs

Version:

Port of TweetNaCl cryptographic library to JavaScript

1 lines 23.1 kB
!function(r){"use strict";function n(r,n){var t=255&r[n+3];return t=t<<8|255&r[n+2],t=t<<8|255&r[n+1],t<<8|255&r[n+0]}function t(r,n){var t=r[n]<<24|r[n+1]<<16|r[n+2]<<8|r[n+3],e=r[n+4]<<24|r[n+5]<<16|r[n+6]<<8|r[n+7];return new vn(t,e)}function e(r,n,t){var e;for(e=0;4>e;e++)r[n+e]=255&t,t>>>=8}function o(r,n,t){r[n]=t.hi>>24&255,r[n+1]=t.hi>>16&255,r[n+2]=t.hi>>8&255,r[n+3]=255&t.hi,r[n+4]=t.lo>>24&255,r[n+5]=t.lo>>16&255,r[n+6]=t.lo>>8&255,r[n+7]=255&t.lo}function i(r,n,t,e,o){var i,f=0;for(i=0;o>i;i++)f|=r[n+i]^t[e+i];return(1&f-1>>>8)-1}function f(r,n,t,e){return i(r,n,t,e,16)}function a(r,n,t,e){return i(r,n,t,e,32)}function h(r,t,o,i){for(var f,a=n(i,0),h=n(o,0),u=n(o,4),s=n(o,8),c=n(o,12),w=n(i,4),y=n(t,0),l=n(t,4),v=n(t,8),p=n(t,12),b=n(i,8),g=n(o,16),A=n(o,20),_=n(o,24),U=n(o,28),d=n(i,12),E=a,x=h,m=u,B=s,S=c,K=w,T=y,Y=l,k=v,C=p,L=b,R=g,z=A,P=_,F=U,N=d,O=0;20>O;O+=2)f=E+z|0,S^=f<<7|f>>>25,f=S+E|0,k^=f<<9|f>>>23,f=k+S|0,z^=f<<13|f>>>19,f=z+k|0,E^=f<<18|f>>>14,f=K+x|0,C^=f<<7|f>>>25,f=C+K|0,P^=f<<9|f>>>23,f=P+C|0,x^=f<<13|f>>>19,f=x+P|0,K^=f<<18|f>>>14,f=L+T|0,F^=f<<7|f>>>25,f=F+L|0,m^=f<<9|f>>>23,f=m+F|0,T^=f<<13|f>>>19,f=T+m|0,L^=f<<18|f>>>14,f=N+R|0,B^=f<<7|f>>>25,f=B+N|0,Y^=f<<9|f>>>23,f=Y+B|0,R^=f<<13|f>>>19,f=R+Y|0,N^=f<<18|f>>>14,f=E+B|0,x^=f<<7|f>>>25,f=x+E|0,m^=f<<9|f>>>23,f=m+x|0,B^=f<<13|f>>>19,f=B+m|0,E^=f<<18|f>>>14,f=K+S|0,T^=f<<7|f>>>25,f=T+K|0,Y^=f<<9|f>>>23,f=Y+T|0,S^=f<<13|f>>>19,f=S+Y|0,K^=f<<18|f>>>14,f=L+C|0,R^=f<<7|f>>>25,f=R+L|0,k^=f<<9|f>>>23,f=k+R|0,C^=f<<13|f>>>19,f=C+k|0,L^=f<<18|f>>>14,f=N+F|0,z^=f<<7|f>>>25,f=z+N|0,P^=f<<9|f>>>23,f=P+z|0,F^=f<<13|f>>>19,f=F+P|0,N^=f<<18|f>>>14;E=E+a|0,x=x+h|0,m=m+u|0,B=B+s|0,S=S+c|0,K=K+w|0,T=T+y|0,Y=Y+l|0,k=k+v|0,C=C+p|0,L=L+b|0,R=R+g|0,z=z+A|0,P=P+_|0,F=F+U|0,N=N+d|0,e(r,0,E),e(r,4,x),e(r,8,m),e(r,12,B),e(r,16,S),e(r,20,K),e(r,24,T),e(r,28,Y),e(r,32,k),e(r,36,C),e(r,40,L),e(r,44,R),e(r,48,z),e(r,52,P),e(r,56,F),e(r,60,N)}function u(r,t,o,i){for(var f,a=n(i,0),h=n(o,0),u=n(o,4),s=n(o,8),c=n(o,12),w=n(i,4),y=n(t,0),l=n(t,4),v=n(t,8),p=n(t,12),b=n(i,8),g=n(o,16),A=n(o,20),_=n(o,24),U=n(o,28),d=n(i,12),E=a,x=h,m=u,B=s,S=c,K=w,T=y,Y=l,k=v,C=p,L=b,R=g,z=A,P=_,F=U,N=d,O=0;20>O;O+=2)f=E+z|0,S^=f<<7|f>>>25,f=S+E|0,k^=f<<9|f>>>23,f=k+S|0,z^=f<<13|f>>>19,f=z+k|0,E^=f<<18|f>>>14,f=K+x|0,C^=f<<7|f>>>25,f=C+K|0,P^=f<<9|f>>>23,f=P+C|0,x^=f<<13|f>>>19,f=x+P|0,K^=f<<18|f>>>14,f=L+T|0,F^=f<<7|f>>>25,f=F+L|0,m^=f<<9|f>>>23,f=m+F|0,T^=f<<13|f>>>19,f=T+m|0,L^=f<<18|f>>>14,f=N+R|0,B^=f<<7|f>>>25,f=B+N|0,Y^=f<<9|f>>>23,f=Y+B|0,R^=f<<13|f>>>19,f=R+Y|0,N^=f<<18|f>>>14,f=E+B|0,x^=f<<7|f>>>25,f=x+E|0,m^=f<<9|f>>>23,f=m+x|0,B^=f<<13|f>>>19,f=B+m|0,E^=f<<18|f>>>14,f=K+S|0,T^=f<<7|f>>>25,f=T+K|0,Y^=f<<9|f>>>23,f=Y+T|0,S^=f<<13|f>>>19,f=S+Y|0,K^=f<<18|f>>>14,f=L+C|0,R^=f<<7|f>>>25,f=R+L|0,k^=f<<9|f>>>23,f=k+R|0,C^=f<<13|f>>>19,f=C+k|0,L^=f<<18|f>>>14,f=N+F|0,z^=f<<7|f>>>25,f=z+N|0,P^=f<<9|f>>>23,f=P+z|0,F^=f<<13|f>>>19,f=F+P|0,N^=f<<18|f>>>14;e(r,0,E),e(r,4,K),e(r,8,L),e(r,12,N),e(r,16,T),e(r,20,Y),e(r,24,k),e(r,28,C)}function s(r,n,t,e){h(r,n,t,e)}function c(r,n,t,e){u(r,n,t,e)}function w(r,n,t,e,o,i,f){var a,h,u=new Uint8Array(16),c=new Uint8Array(64);for(h=0;16>h;h++)u[h]=0;for(h=0;8>h;h++)u[h]=i[h];for(;o>=64;){for(s(c,u,f,Kn),h=0;64>h;h++)r[n+h]=t[e+h]^c[h];for(a=1,h=8;16>h;h++)a=a+(255&u[h])|0,u[h]=255&a,a>>>=8;o-=64,n+=64,e+=64}if(o>0)for(s(c,u,f,Kn),h=0;o>h;h++)r[n+h]=t[e+h]^c[h];return 0}function y(r,n,t,e,o){var i,f,a=new Uint8Array(16),h=new Uint8Array(64);for(f=0;16>f;f++)a[f]=0;for(f=0;8>f;f++)a[f]=e[f];for(;t>=64;){for(s(h,a,o,Kn),f=0;64>f;f++)r[n+f]=h[f];for(i=1,f=8;16>f;f++)i=i+(255&a[f])|0,a[f]=255&i,i>>>=8;t-=64,n+=64}if(t>0)for(s(h,a,o,Kn),f=0;t>f;f++)r[n+f]=h[f];return 0}function l(r,n,t,e,o){var i=new Uint8Array(32);c(i,e,o,Kn);for(var f=new Uint8Array(8),a=0;8>a;a++)f[a]=e[a+16];return y(r,n,t,f,i)}function v(r,n,t,e,o,i,f){var a=new Uint8Array(32);c(a,i,f,Kn);for(var h=new Uint8Array(8),u=0;8>u;u++)h[u]=i[u+16];return w(r,n,t,e,o,h,a)}function p(r,n){return 255&r[n]|(255&r[n+1])<<8}function b(r,n,t){r[n]=t>>>0&255,r[n+1]=t>>>8&255}function g(r,n,t,e,o,i){var f=new Tn(i);return f.update(t,e,o),f.finish(r,n),0}function A(r,n,t,e,o,i){var a=new Uint8Array(16);return g(a,0,t,e,o,i),f(r,n,a,0)}function _(r,n,t,e,o){var i;if(32>t)return-1;for(v(r,0,n,0,t,e,o),g(r,16,r,32,t-32,r),i=0;16>i;i++)r[i]=0;return 0}function U(r,n,t,e,o){var i,f=new Uint8Array(32);if(32>t)return-1;if(l(f,0,32,e,o),0!==A(n,16,n,32,t-32,f))return-1;for(v(r,0,n,0,t,e,o),i=0;32>i;i++)r[i]=0;return 0}function d(r,n){var t;for(t=0;16>t;t++)r[t]=0|n[t]}function E(r){var n,t;for(t=0;16>t;t++)r[t]+=65536,n=Math.floor(r[t]/65536),r[(t+1)*(15>t?1:0)]+=n-1+37*(n-1)*(15===t?1:0),r[t]-=65536*n}function x(r,n,t){for(var e,o=~(t-1),i=0;16>i;i++)e=o&(r[i]^n[i]),r[i]^=e,n[i]^=e}function m(r,n){var t,e,o,i=pn(),f=pn();for(t=0;16>t;t++)f[t]=n[t];for(E(f),E(f),E(f),e=0;2>e;e++){for(i[0]=f[0]-65517,t=1;15>t;t++)i[t]=f[t]-65535-(i[t-1]>>16&1),i[t-1]&=65535;i[15]=f[15]-32767-(i[14]>>16&1),o=i[15]>>16&1,i[14]&=65535,x(f,i,1-o)}for(t=0;16>t;t++)r[2*t]=255&f[t],r[2*t+1]=f[t]>>8}function B(r,n){var t=new Uint8Array(32),e=new Uint8Array(32);return m(t,r),m(e,n),a(t,0,e,0)}function S(r){var n=new Uint8Array(32);return m(n,r),1&n[0]}function K(r,n){var t;for(t=0;16>t;t++)r[t]=n[2*t]+(n[2*t+1]<<8);r[15]&=32767}function T(r,n,t){var e;for(e=0;16>e;e++)r[e]=n[e]+t[e]|0}function Y(r,n,t){var e;for(e=0;16>e;e++)r[e]=n[e]-t[e]|0}function k(r,n,t){var e,o,i=new Float64Array(31);for(e=0;31>e;e++)i[e]=0;for(e=0;16>e;e++)for(o=0;16>o;o++)i[e+o]+=n[e]*t[o];for(e=0;15>e;e++)i[e]+=38*i[e+16];for(e=0;16>e;e++)r[e]=i[e];E(r),E(r)}function C(r,n){k(r,n,n)}function L(r,n){var t,e=pn();for(t=0;16>t;t++)e[t]=n[t];for(t=253;t>=0;t--)C(e,e),2!==t&&4!==t&&k(e,e,n);for(t=0;16>t;t++)r[t]=e[t]}function R(r,n){var t,e=pn();for(t=0;16>t;t++)e[t]=n[t];for(t=250;t>=0;t--)C(e,e),1!==t&&k(e,e,n);for(t=0;16>t;t++)r[t]=e[t]}function z(r,n,t){var e,o,i=new Uint8Array(32),f=new Float64Array(80),a=pn(),h=pn(),u=pn(),s=pn(),c=pn(),w=pn();for(o=0;31>o;o++)i[o]=n[o];for(i[31]=127&n[31]|64,i[0]&=248,K(f,t),o=0;16>o;o++)h[o]=f[o],s[o]=a[o]=u[o]=0;for(a[0]=s[0]=1,o=254;o>=0;--o)e=i[o>>>3]>>>(7&o)&1,x(a,h,e),x(u,s,e),T(c,a,u),Y(a,a,u),T(u,h,s),Y(h,h,s),C(s,c),C(w,a),k(a,u,a),k(u,h,c),T(c,a,u),Y(a,a,u),C(h,a),Y(u,s,w),k(a,u,dn),T(a,a,s),k(u,u,a),k(a,s,w),k(s,h,f),C(h,c),x(a,h,e),x(u,s,e);for(o=0;16>o;o++)f[o+16]=a[o],f[o+32]=u[o],f[o+48]=h[o],f[o+64]=s[o];var y=f.subarray(32),l=f.subarray(16);return L(y,y),k(l,l,y),m(r,l),0}function P(r,n){return z(r,n,An)}function F(r,n){return bn(n,32),P(r,n)}function N(r,n,t){var e=new Uint8Array(32);return z(e,t,n),c(r,gn,e,Kn)}function O(r,n,t,e,o,i){var f=new Uint8Array(32);return N(f,o,i),Yn(r,n,t,e,f)}function M(r,n,t,e,o,i){var f=new Uint8Array(32);return N(f,o,i),kn(r,n,t,e,f)}function G(){var r,n,t,e=0,o=0,i=0,f=0,a=65535;for(t=0;t<arguments.length;t++)r=arguments[t].lo,n=arguments[t].hi,e+=r&a,o+=r>>>16,i+=n&a,f+=n>>>16;return o+=e>>>16,i+=o>>>16,f+=i>>>16,new vn(i&a|f<<16,e&a|o<<16)}function I(r,n){return new vn(r.hi>>>n,r.lo>>>n|r.hi<<32-n)}function Z(){var r,n=0,t=0;for(r=0;r<arguments.length;r++)n^=arguments[r].lo,t^=arguments[r].hi;return new vn(t,n)}function j(r,n){var t,e,o=32-n;return 32>n?(t=r.hi>>>n|r.lo<<o,e=r.lo>>>n|r.hi<<o):64>n&&(t=r.lo>>>n|r.hi<<o,e=r.hi>>>n|r.lo<<o),new vn(t,e)}function V(r,n,t){var e=r.hi&n.hi^~r.hi&t.hi,o=r.lo&n.lo^~r.lo&t.lo;return new vn(e,o)}function q(r,n,t){var e=r.hi&n.hi^r.hi&t.hi^n.hi&t.hi,o=r.lo&n.lo^r.lo&t.lo^n.lo&t.lo;return new vn(e,o)}function X(r){return Z(j(r,28),j(r,34),j(r,39))}function D(r){return Z(j(r,14),j(r,18),j(r,41))}function H(r){return Z(j(r,1),j(r,8),I(r,7))}function J(r){return Z(j(r,19),j(r,61),I(r,6))}function Q(r,n,e){var i,f,a,h=[],u=[],s=[],c=[];for(f=0;8>f;f++)h[f]=s[f]=t(r,8*f);for(var w=0;e>=128;){for(f=0;16>f;f++)c[f]=t(n,8*f+w);for(f=0;80>f;f++){for(a=0;8>a;a++)u[a]=s[a];for(i=G(s[7],D(s[4]),V(s[4],s[5],s[6]),Cn[f],c[f%16]),u[7]=G(i,X(s[0]),q(s[0],s[1],s[2])),u[3]=G(u[3],i),a=0;8>a;a++)s[(a+1)%8]=u[a];if(f%16===15)for(a=0;16>a;a++)c[a]=G(c[a],c[(a+9)%16],H(c[(a+1)%16]),J(c[(a+14)%16]))}for(f=0;8>f;f++)s[f]=G(s[f],h[f]),h[f]=s[f];w+=128,e-=128}for(f=0;8>f;f++)o(r,8*f,h[f]);return e}function W(r,n,t){var e,i=new Uint8Array(64),f=new Uint8Array(256),a=t;for(e=0;64>e;e++)i[e]=Ln[e];for(Q(i,n,t),t%=128,e=0;256>e;e++)f[e]=0;for(e=0;t>e;e++)f[e]=n[a-t+e];for(f[t]=128,t=256-128*(112>t?1:0),f[t-9]=0,o(f,t-8,new vn(a/536870912|0,a<<3)),Q(i,f,t),e=0;64>e;e++)r[e]=i[e];return 0}function $(r,n){var t=pn(),e=pn(),o=pn(),i=pn(),f=pn(),a=pn(),h=pn(),u=pn(),s=pn();Y(t,r[1],r[0]),Y(s,n[1],n[0]),k(t,t,s),T(e,r[0],r[1]),T(s,n[0],n[1]),k(e,e,s),k(o,r[3],n[3]),k(o,o,xn),k(i,r[2],n[2]),T(i,i,i),Y(f,e,t),Y(a,i,o),T(h,i,o),T(u,e,t),k(r[0],f,a),k(r[1],u,h),k(r[2],h,a),k(r[3],f,u)}function rn(r,n,t){var e;for(e=0;4>e;e++)x(r[e],n[e],t)}function nn(r,n){var t=pn(),e=pn(),o=pn();L(o,n[2]),k(t,n[0],o),k(e,n[1],o),m(r,e),r[31]^=S(t)<<7}function tn(r,n,t){var e,o;for(d(r[0],_n),d(r[1],Un),d(r[2],Un),d(r[3],_n),o=255;o>=0;--o)e=t[o/8|0]>>(7&o)&1,rn(r,n,e),$(n,r),$(r,r),rn(r,n,e)}function en(r,n){var t=[pn(),pn(),pn(),pn()];d(t[0],mn),d(t[1],Bn),d(t[2],Un),k(t[3],mn,Bn),tn(r,t,n)}function on(r,n,t){var e,o=new Uint8Array(64),i=[pn(),pn(),pn(),pn()];for(W(o,r,32),o[0]&=248,o[31]&=127,o[31]|=64,en(i,o),nn(n,i),e=0;32>e;e++)t[e]=r[e];for(e=0;32>e;e++)t[e+32]=n[e];return 0}function fn(r,n){var t=new Uint8Array(Dn);return bn(t,Dn),on(t,r,n)}function an(r,n){var t,e,o,i;for(e=63;e>=32;--e){for(t=0,o=e-32,i=e-12;i>o;++o)n[o]+=t-16*n[e]*Rn[o-(e-32)],t=n[o]+128>>8,n[o]-=256*t;n[o]+=t,n[e]=0}for(t=0,o=0;32>o;o++)n[o]+=t-(n[31]>>4)*Rn[o],t=n[o]>>8,n[o]&=255;for(o=0;32>o;o++)n[o]-=t*Rn[o];for(e=0;32>e;e++)n[e+1]+=n[e]>>8,r[e]=255&n[e]}function hn(r){var n,t=new Float64Array(64);for(n=0;64>n;n++)t[n]=r[n];for(n=0;64>n;n++)r[n]=0;an(r,t)}function un(r,n,t,e){var o,i,f=new Uint8Array(64),a=new Uint8Array(64),h=new Uint8Array(64),u=new Float64Array(64),s=[pn(),pn(),pn(),pn()];W(f,e,32),f[0]&=248,f[31]&=127,f[31]|=64;var c=t+64;for(o=0;t>o;o++)r[64+o]=n[o];for(o=0;32>o;o++)r[32+o]=f[32+o];for(W(h,r.subarray(32),t+32),hn(h),en(s,h),nn(r,s),o=32;64>o;o++)r[o]=e[o];for(W(a,r,t+64),hn(a),o=0;64>o;o++)u[o]=0;for(o=0;32>o;o++)u[o]=h[o];for(o=0;32>o;o++)for(i=0;32>i;i++)u[o+i]+=a[o]*f[i];return an(r.subarray(32),u),c}function sn(r,n){var t=pn(),e=pn(),o=pn(),i=pn(),f=pn(),a=pn(),h=pn();return d(r[2],Un),K(r[1],n),C(o,r[1]),k(i,o,En),Y(o,o,r[2]),T(i,r[2],i),C(f,i),C(a,f),k(h,a,f),k(t,h,o),k(t,t,i),R(t,t),k(t,t,o),k(t,t,i),k(t,t,i),k(r[0],t,i),C(e,r[0]),k(e,e,i),B(e,o)&&k(r[0],r[0],Sn),C(e,r[0]),k(e,e,i),B(e,o)?-1:(S(r[0])===n[31]>>7&&Y(r[0],_n,r[0]),k(r[3],r[0],r[1]),0)}function cn(r,n,t,e){var o,i,f=new Uint8Array(32),h=new Uint8Array(64),u=[pn(),pn(),pn(),pn()],s=[pn(),pn(),pn(),pn()];if(i=-1,64>t)return-1;if(sn(s,e))return-1;for(o=0;t>o;o++)r[o]=n[o];for(o=0;32>o;o++)r[o+32]=e[o];if(W(h,r,t),hn(h),tn(u,s,h),en(s,n.subarray(32)),$(u,s),nn(f,u),t-=64,a(n,0,f,0)){for(o=0;t>o;o++)r[o]=0;return-1}for(o=0;t>o;o++)r[o]=n[o+64];return i=t}function wn(r,n){if(r.length!==zn)throw new Error("bad key size");if(n.length!==Pn)throw new Error("bad nonce size")}function yn(r,n){if(r.length!==Gn)throw new Error("bad public key size");if(n.length!==In)throw new Error("bad secret key size")}function ln(){for(var r,n={}.toString,t=0;t<arguments.length;t++)if("[object Uint8Array]"!==(r=n.call(arguments[t])))throw new TypeError("unexpected type "+r+", use Uint8Array")}var vn=function(r,n){this.hi=0|r,this.lo=0|n},pn=function(r){var n,t=new Float64Array(16);if(r)for(n=0;n<r.length;n++)t[n]=r[n];return t},bn=function(){throw new Error("no PRNG")},gn=new Uint8Array(16),An=new Uint8Array(32);An[0]=9;var _n=pn(),Un=pn([1]),dn=pn([56129,1]),En=pn([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),xn=pn([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),mn=pn([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),Bn=pn([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),Sn=pn([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]),Kn=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]),Tn=function(r){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 n,t,e,o,i,f,a,h,u;for(t=p(r,0),this.r[0]=8191&t,e=p(r,2),this.r[1]=8191&(t>>>13|e<<3),o=p(r,4),this.r[2]=7939&(e>>>10|o<<6),i=p(r,6),this.r[3]=8191&(o>>>7|i<<9),f=p(r,8),this.r[4]=255&(i>>>4|f<<12),this.r[5]=f>>>1&8190,a=p(r,10),this.r[6]=8191&(f>>>14|a<<2),h=p(r,12),this.r[7]=8065&(a>>>11|h<<5),u=p(r,14),this.r[8]=8191&(h>>>8|u<<8),this.r[9]=u>>>5&127,n=0;8>n;n++)this.pad[n]=p(r,16+2*n)};Tn.prototype.blocks=function(r,n,t){for(var e,o,i,f,a,h,u,s,c,w,y,l=this.fin?0:2048,v=new Uint32Array(10);t>=16;){for(e=p(r,n+0),this.h[0]+=8191&e,o=p(r,n+2),this.h[1]+=8191&(e>>>13|o<<3),i=p(r,n+4),this.h[2]+=8191&(o>>>10|i<<6),f=p(r,n+6),this.h[3]+=8191&(i>>>7|f<<9),a=p(r,n+8),this.h[4]+=8191&(f>>>4|a<<12),this.h[5]+=a>>>1&8191,h=p(r,n+10),this.h[6]+=8191&(a>>>14|h<<2),u=p(r,n+12),this.h[7]+=8191&(h>>>11|u<<5),s=p(r,n+14),this.h[8]+=8191&(u>>>8|s<<8),this.h[9]+=s>>>5|l,w=0,c=0;10>w;w++){for(v[w]=c,y=0;10>y;y++)v[w]+=this.h[y]*(w>=y?this.r[w-y]:5*this.r[w+10-y]),4===y&&(c=v[w]>>>13,v[w]&=8191);c+=v[w]>>>13,v[w]&=8191}for(c=(c<<2)+c|0,c=c+v[0]|0,v[0]=8191&c,c>>>=13,v[1]+=c,w=0;10>w;w++)this.h[w]=v[w];n+=16,t-=16}},Tn.prototype.finish=function(r,n){var t,e,o,i,f=new Uint16Array(10);if(this.leftover){for(i=this.leftover,this.buffer[i++]=1;16>i;i++)this.buffer[i]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(t=this.h[1]>>>13,this.h[1]&=8191,i=2;10>i;i++)this.h[i]+=t,t=this.h[i]>>>13,this.h[i]&=8191;for(this.h[0]+=5*t,t=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=t,t=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=t,f[0]=this.h[0]+5,t=f[0]>>>13,f[0]&=8191,i=1;10>i;i++)f[i]=this.h[i]+t,t=f[i]>>>13,f[i]&=8191;for(f[9]-=8192,e=(f[9]>>>15)-1,i=0;10>i;i++)f[i]&=e;for(e=~e,i=0;10>i;i++)this.h[i]=this.h[i]&e|f[i];for(this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5),o=this.h[0]+this.pad[0],this.h[0]=65535&o,i=1;8>i;i++)o=(this.h[i]+this.pad[i]|0)+(o>>>16)|0,this.h[i]=65535&o;for(i=0;8>i;i++)b(r,n+2*i,this.h[i])},Tn.prototype.update=function(r,n,t){var e,o;if(this.leftover){for(o=16-this.leftover,o>t&&(o=t),e=0;o>e;e++)this.buffer[this.leftover+e]=r[n+e];if(t-=o,n+=o,this.leftover+=o,this.leftover<16)return;this.blocks(buffer,0,16),this.leftover=0}if(t>=16&&(o=t-t%16,this.blocks(r,n,o),n+=o,t-=o),t){for(e=0;t>e;e++)this.buffer[this.leftover+e]=r[n+e];this.leftover+=t}};var Yn=_,kn=U,Cn=[new vn(1116352408,3609767458),new vn(1899447441,602891725),new vn(3049323471,3964484399),new vn(3921009573,2173295548),new vn(961987163,4081628472),new vn(1508970993,3053834265),new vn(2453635748,2937671579),new vn(2870763221,3664609560),new vn(3624381080,2734883394),new vn(310598401,1164996542),new vn(607225278,1323610764),new vn(1426881987,3590304994),new vn(1925078388,4068182383),new vn(2162078206,991336113),new vn(2614888103,633803317),new vn(3248222580,3479774868),new vn(3835390401,2666613458),new vn(4022224774,944711139),new vn(264347078,2341262773),new vn(604807628,2007800933),new vn(770255983,1495990901),new vn(1249150122,1856431235),new vn(1555081692,3175218132),new vn(1996064986,2198950837),new vn(2554220882,3999719339),new vn(2821834349,766784016),new vn(2952996808,2566594879),new vn(3210313671,3203337956),new vn(3336571891,1034457026),new vn(3584528711,2466948901),new vn(113926993,3758326383),new vn(338241895,168717936),new vn(666307205,1188179964),new vn(773529912,1546045734),new vn(1294757372,1522805485),new vn(1396182291,2643833823),new vn(1695183700,2343527390),new vn(1986661051,1014477480),new vn(2177026350,1206759142),new vn(2456956037,344077627),new vn(2730485921,1290863460),new vn(2820302411,3158454273),new vn(3259730800,3505952657),new vn(3345764771,106217008),new vn(3516065817,3606008344),new vn(3600352804,1432725776),new vn(4094571909,1467031594),new vn(275423344,851169720),new vn(430227734,3100823752),new vn(506948616,1363258195),new vn(659060556,3750685593),new vn(883997877,3785050280),new vn(958139571,3318307427),new vn(1322822218,3812723403),new vn(1537002063,2003034995),new vn(1747873779,3602036899),new vn(1955562222,1575990012),new vn(2024104815,1125592928),new vn(2227730452,2716904306),new vn(2361852424,442776044),new vn(2428436474,593698344),new vn(2756734187,3733110249),new vn(3204031479,2999351573),new vn(3329325298,3815920427),new vn(3391569614,3928383900),new vn(3515267271,566280711),new vn(3940187606,3454069534),new vn(4118630271,4000239992),new vn(116418474,1914138554),new vn(174292421,2731055270),new vn(289380356,3203993006),new vn(460393269,320620315),new vn(685471733,587496836),new vn(852142971,1086792851),new vn(1017036298,365543100),new vn(1126000580,2618297676),new vn(1288033470,3409855158),new vn(1501505948,4234509866),new vn(1607167915,987167468),new vn(1816402316,1246189591)],Ln=new Uint8Array([106,9,230,103,243,188,201,8,187,103,174,133,132,202,167,59,60,110,243,114,254,148,248,43,165,79,245,58,95,29,54,241,81,14,82,127,173,230,130,209,155,5,104,140,43,62,108,31,31,131,217,171,251,65,189,107,91,224,205,25,19,126,33,121]),Rn=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]),zn=32,Pn=24,Fn=32,Nn=16,On=32,Mn=32,Gn=32,In=32,Zn=32,jn=Pn,Vn=Fn,qn=Nn,Xn=64,Dn=32,Hn=32,Jn=64,Qn=64;r.lowlevel={crypto_stream_xor:v,crypto_stream:l,crypto_stream_salsa20_xor:w,crypto_stream_salsa20:y,crypto_onetimeauth:g,crypto_onetimeauth_verify:A,crypto_verify_16:f,crypto_verify_32:a,crypto_secretbox:_,crypto_secretbox_open:U,crypto_scalarmult:z,crypto_scalarmult_base:P,crypto_box_beforenm:N,crypto_box_afternm:Yn,crypto_box:O,crypto_box_open:M,crypto_box_keypair:F,crypto_hash:W,crypto_hashblocks:Q,crypto_sign:un,crypto_sign_keypair:fn,crypto_sign_open:cn,crypto_secretbox_KEYBYTES:zn,crypto_secretbox_NONCEBYTES:Pn,crypto_secretbox_ZEROBYTES:Fn,crypto_secretbox_BOXZEROBYTES:Nn,crypto_scalarmult_BYTES:On,crypto_scalarmult_SCALARBYTES:Mn,crypto_box_PUBLICKEYBYTES:Gn,crypto_box_SECRETKEYBYTES:In,crypto_box_BEFORENMBYTES:Zn,crypto_box_NONCEBYTES:jn,crypto_box_ZEROBYTES:Vn,crypto_box_BOXZEROBYTES:qn,crypto_sign_BYTES:Xn,crypto_sign_SEEDBYTES:Dn,crypto_sign_PUBLICKEYBYTES:Hn,crypto_sign_SECRETKEYBYTES:Jn,crypto_hash_BYTES:Qn},r.util={},r.util.decodeUTF8=function(r){var n,t=unescape(encodeURIComponent(r)),e=new Uint8Array(t.length);for(n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e},r.util.encodeUTF8=function(r){var n,t=[];for(n=0;n<r.length;n++)t.push(String.fromCharCode(r[n]));return decodeURIComponent(escape(t.join("")))},r.util.encodeBase64=function(r){if("undefined"==typeof btoa)return new Buffer(r).toString("base64");var n,t=[],e=r.length;for(n=0;e>n;n++)t.push(String.fromCharCode(r[n]));return btoa(t.join(""))},r.util.decodeBase64=function(r){if("undefined"==typeof atob)return new Uint8Array(Array.prototype.slice.call(new Buffer(r,"base64"),0));var n,t=atob(r),e=new Uint8Array(t.length);for(n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e},r.randomBytes=function(r){var n=new Uint8Array(r);return bn(n,r),n},r.secretbox=function(r,n,t){ln(r,n,t),wn(t,n);for(var e=new Uint8Array(Fn+r.length),o=new Uint8Array(e.length),i=0;i<r.length;i++)e[i+Fn]=r[i];return _(o,e,e.length,n,t),o.subarray(Nn)},r.secretbox.open=function(r,n,t){ln(r,n,t),wn(t,n);for(var e=new Uint8Array(Nn+r.length),o=new Uint8Array(e.length),i=0;i<r.length;i++)e[i+Nn]=r[i];return e.length<32?!1:0!==U(o,e,e.length,n,t)?!1:o.subarray(Fn)},r.secretbox.keyLength=zn,r.secretbox.nonceLength=Pn,r.secretbox.overheadLength=Nn,r.scalarMult=function(r,n){if(ln(r,n),r.length!==Mn)throw new Error("bad n size");if(n.length!==On)throw new Error("bad p size");var t=new Uint8Array(On);return z(t,r,n),t},r.scalarMult.base=function(r){if(ln(r),r.length!==Mn)throw new Error("bad n size");var n=new Uint8Array(On);return P(n,r),n},r.scalarMult.scalarLength=Mn,r.scalarMult.groupElementLength=On,r.box=function(n,t,e,o){var i=r.box.before(e,o);return r.secretbox(n,t,i)},r.box.before=function(r,n){ln(r,n),yn(r,n);var t=new Uint8Array(Zn);return N(t,r,n),t},r.box.after=r.secretbox,r.box.open=function(n,t,e,o){var i=r.box.before(e,o);return r.secretbox.open(n,t,i)},r.box.open.after=r.secretbox.open,r.box.keyPair=function(){var r=new Uint8Array(Gn),n=new Uint8Array(In);return F(r,n),{publicKey:r,secretKey:n}},r.box.keyPair.fromSecretKey=function(r){if(ln(r),r.length!==In)throw new Error("bad secret key size");var n=new Uint8Array(Gn);return P(n,r),{publicKey:n,secretKey:r}},r.box.publicKeyLength=Gn,r.box.secretKeyLength=In,r.box.sharedKeyLength=Zn,r.box.nonceLength=jn,r.box.overheadLength=r.secretbox.overheadLength,r.sign=function(r,n){if(ln(r,n),n.length!==Jn)throw new Error("bad secret key size");var t=new Uint8Array(Xn+r.length);un(t,r,r.length,n);for(var e=new Uint8Array(Xn),o=0;o<e.length;o++)e[o]=t[o];return e},r.sign.open=function(r,n,t){if(ln(r,n,t),n.length!==Xn)throw new Error("bad signature size");if(t.length!==Hn)throw new Error("bad public key size");var e,o=new Uint8Array(Xn+r.length),i=new Uint8Array(Xn+r.length);for(e=0;Xn>e;e++)o[e]=n[e];for(e=0;e<r.length;e++)o[e+Xn]=r[e];var f=cn(i,o,o.length,t);return 0>f?!1:i.subarray(0,f)},r.sign.keyPair=function(){var r=new Uint8Array(Hn),n=new Uint8Array(Jn);return fn(r,n),{publicKey:r,secretKey:n}},r.sign.keyPair.fromSecretKey=function(r){if(ln(r),r.length!==Jn)throw new Error("bad secret key size");var n,t=new Uint8Array(Hn);for(n=0;32>n;n++)t[n]=r[32+n];return{publicKey:t,secretKey:r}},r.sign.keyPair.fromSeed=function(r){if(ln(r),r.length!==Dn)throw new Error("bad seed size");var n=new Uint8Array(Hn),t=new Uint8Array(Jn);return on(r,n,t),{publicKey:n,secretKey:t}},r.sign.publicKeyLength=Hn,r.sign.secretKeyLength=Jn,r.sign.signatureLength=Xn,r.hash=function(r){ln(r);var n=new Uint8Array(Qn);return W(n,r,r.length),n},r.hash.hashLength=Qn,r.verify=function(r,n){return ln(r,n),0===r.length||0===n.length?!1:r.length!==n.length?!1:0===i(r,0,n,0,r.length)?!0:!1},r.setPRNG=function(r){bn=r},function(){var n;"undefined"!=typeof window?(window.crypto&&window.crypto.getRandomValues?n=window.crypto:window.msCrypto&&window.msCrypto.getRandomValues&&(n=window.msCrypto),n&&r.setPRNG(function(r,t){var e,o=new Uint8Array(t);for(n.getRandomValues(o),e=0;t>e;e++)r[e]=o[e]})):"undefined"!=typeof require&&(n=require("crypto"),n&&r.setPRNG(function(r,t){var e,o=n.randomBytes(t);for(e=0;t>e;e++)r[e]=o[e]}))}()}("undefined"!=typeof module&&module.exports?module.exports:window.nacl=window.nacl||{});