forked from dchest/tweetnacl-js
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnacl.min.js
1 lines (1 loc) · 18.9 KB
/
nacl.min.js
1
!function(f){"use strict";var K=function(r,n){this.hi=0|r,this.lo=0|n},g=function(r){var n,e=new Float64Array(16);if(r)for(n=0;n<r.length;n++)e[n]=r[n];return e},i=function(){throw new Error("no PRNG")},o=new Uint8Array(16),e=new Uint8Array(32);e[0]=9;var c=g(),w=g([1]),b=g([56129,1]),y=g([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),l=g([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),t=g([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),a=g([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),s=g([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function h(r,n){return r<<n|r>>>32-n}function v(r,n){var e=255&r[n+3];return(e=(e=e<<8|255&r[n+2])<<8|255&r[n+1])<<8|255&r[n+0]}function m(r,n){var e=r[n]<<24|r[n+1]<<16|r[n+2]<<8|r[n+3],t=r[n+4]<<24|r[n+5]<<16|r[n+6]<<8|r[n+7];return new K(e,t)}function p(r,n,e){var t;for(t=0;t<4;t++)r[n+t]=255&e,e>>>=8}function B(r,n,e){r[n]=e.hi>>24&255,r[n+1]=e.hi>>16&255,r[n+2]=e.hi>>8&255,r[n+3]=255&e.hi,r[n+4]=e.lo>>24&255,r[n+5]=e.lo>>16&255,r[n+6]=e.lo>>8&255,r[n+7]=255&e.lo}function u(r,n,e,t,o){var a,i=0;for(a=0;a<o;a++)i|=r[n+a]^e[t+a];return(1&i-1>>>8)-1}function _(r,n,e,t){return u(r,n,e,t,16)}function A(r,n,e,t){return u(r,n,e,t,32)}function U(r,n,e,t,o){var a,i,f,u=new Uint32Array(16),c=new Uint32Array(16),w=new Uint32Array(16),y=new Uint32Array(4);for(a=0;a<4;a++)c[5*a]=v(t,4*a),c[1+a]=v(e,4*a),c[6+a]=v(n,4*a),c[11+a]=v(e,16+4*a);for(a=0;a<16;a++)w[a]=c[a];for(a=0;a<20;a++){for(i=0;i<4;i++){for(f=0;f<4;f++)y[f]=c[(5*i+4*f)%16];for(y[1]^=h(y[0]+y[3]|0,7),y[2]^=h(y[1]+y[0]|0,9),y[3]^=h(y[2]+y[1]|0,13),y[0]^=h(y[3]+y[2]|0,18),f=0;f<4;f++)u[4*i+(i+f)%4]=y[f]}for(f=0;f<16;f++)c[f]=u[f]}if(o){for(a=0;a<16;a++)c[a]=c[a]+w[a]|0;for(a=0;a<4;a++)c[5*a]=c[5*a]-v(t,4*a)|0,c[6+a]=c[6+a]-v(n,4*a)|0;for(a=0;a<4;a++)p(r,4*a,c[5*a]),p(r,16+4*a,c[6+a])}else for(a=0;a<16;a++)p(r,4*a,c[a]+w[a]|0)}function E(r,n,e,t){U(r,n,e,t,!1)}function x(r,n,e,t){return U(r,n,e,t,!0),0}var d=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function S(r,n,e,t,o,a,i){var f,u,c=new Uint8Array(16),w=new Uint8Array(64);if(!o)return 0;for(u=0;u<16;u++)c[u]=0;for(u=0;u<8;u++)c[u]=a[u];for(;64<=o;){for(E(w,c,i,d),u=0;u<64;u++)r[n+u]=(e?e[t+u]:0)^w[u];for(f=1,u=8;u<16;u++)f=f+(255&c[u])|0,c[u]=255&f,f>>>=8;o-=64,n+=64,e&&(t+=64)}if(0<o)for(E(w,c,i,d),u=0;u<o;u++)r[n+u]=(e?e[t+u]:0)^w[u];return 0}function L(r,n,e,t,o){return S(r,n,null,0,e,t,o)}function Y(r,n,e,t,o){var a=new Uint8Array(32);return x(a,t,o,d),L(r,n,e,t.subarray(16),a)}function T(r,n,e,t,o,a,i){var f=new Uint8Array(32);return x(f,a,i,d),S(r,n,e,t,o,a.subarray(16),f)}function k(r,n){var e,t=0;for(e=0;e<17;e++)t=t+(r[e]+n[e]|0)|0,r[e]=255&t,t>>>=8}var z=new Uint32Array([5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252]);function R(r,n,e,t,o,a){var i,f,u,c,w=new Uint32Array(17),y=new Uint32Array(17),l=new Uint32Array(17),s=new Uint32Array(17),h=new Uint32Array(17);for(u=0;u<17;u++)y[u]=l[u]=0;for(u=0;u<16;u++)y[u]=a[u];for(y[3]&=15,y[4]&=252,y[7]&=15,y[8]&=252,y[11]&=15,y[12]&=252,y[15]&=15;0<o;){for(u=0;u<17;u++)s[u]=0;for(u=0;u<16&&u<o;++u)s[u]=e[t+u];for(s[u]=1,t+=u,o-=u,k(l,s),f=0;f<17;f++)for(u=w[f]=0;u<17;u++)w[f]=w[f]+l[u]*(u<=f?y[f-u]:320*y[f+17-u]|0)|0;for(f=0;f<17;f++)l[f]=w[f];for(u=c=0;u<16;u++)c=c+l[u]|0,l[u]=255&c,c>>>=8;for(c=c+l[16]|0,l[16]=3&c,c=5*(c>>>2)|0,u=0;u<16;u++)c=c+l[u]|0,l[u]=255&c,c>>>=8;c=c+l[16]|0,l[16]=c}for(u=0;u<17;u++)h[u]=l[u];for(k(l,z),i=0|-(l[16]>>>7),u=0;u<17;u++)l[u]^=i&(h[u]^l[u]);for(u=0;u<16;u++)s[u]=a[u+16];for(s[16]=0,k(l,s),u=0;u<16;u++)r[n+u]=l[u];return 0}function P(r,n,e,t,o,a){var i=new Uint8Array(16);return R(i,0,e,t,o,a),_(r,n,i,0)}function C(r,n,e,t,o){var a;if(e<32)return-1;for(T(r,0,n,0,e,t,o),R(r,16,r,32,e-32,r),a=0;a<16;a++)r[a]=0;return 0}function N(r,n,e,t,o){var a,i=new Uint8Array(32);if(e<32)return-1;if(Y(i,0,32,t,o),0!==P(n,16,n,32,e-32,i))return-1;for(T(r,0,n,0,e,t,o),a=0;a<32;a++)r[a]=0;return 0}function O(r,n){var e;for(e=0;e<16;e++)r[e]=0|n[e]}function M(r){var n,e;for(e=0;e<16;e++)r[e]+=65536,n=Math.floor(r[e]/65536),r[(e+1)*(e<15?1:0)]+=n-1+37*(n-1)*(15===e?1:0),r[e]-=65536*n}function F(r,n,e){for(var t,o=~(e-1),a=0;a<16;a++)t=o&(r[a]^n[a]),r[a]^=t,n[a]^=t}function Z(r,n){var e,t,o,a=g(),i=g();for(e=0;e<16;e++)i[e]=n[e];for(M(i),M(i),M(i),t=0;t<2;t++){for(a[0]=i[0]-65517,e=1;e<15;e++)a[e]=i[e]-65535-(a[e-1]>>16&1),a[e-1]&=65535;a[15]=i[15]-32767-(a[14]>>16&1),o=a[15]>>16&1,a[14]&=65535,F(i,a,1-o)}for(e=0;e<16;e++)r[2*e]=255&i[e],r[2*e+1]=i[e]>>8}function G(r,n){var e=new Uint8Array(32),t=new Uint8Array(32);return Z(e,r),Z(t,n),A(e,0,t,0)}function I(r){var n=new Uint8Array(32);return Z(n,r),1&n[0]}function q(r,n){var e;for(e=0;e<16;e++)r[e]=n[2*e]+(n[2*e+1]<<8);r[15]&=32767}function D(r,n,e){var t;for(t=0;t<16;t++)r[t]=n[t]+e[t]|0}function V(r,n,e){var t;for(t=0;t<16;t++)r[t]=n[t]-e[t]|0}function X(r,n,e){var t,o,a=new Float64Array(31);for(t=0;t<31;t++)a[t]=0;for(t=0;t<16;t++)for(o=0;o<16;o++)a[t+o]+=n[t]*e[o];for(t=0;t<15;t++)a[t]+=38*a[t+16];for(t=0;t<16;t++)r[t]=a[t];M(r),M(r)}function j(r,n){X(r,n,n)}function H(r,n){var e,t=g();for(e=0;e<16;e++)t[e]=n[e];for(e=253;0<=e;e--)j(t,t),2!==e&&4!==e&&X(t,t,n);for(e=0;e<16;e++)r[e]=t[e]}function J(r,n){var e,t=g();for(e=0;e<16;e++)t[e]=n[e];for(e=250;0<=e;e--)j(t,t),1!==e&&X(t,t,n);for(e=0;e<16;e++)r[e]=t[e]}function Q(r,n,e){var t,o,a=new Uint8Array(32),i=new Float64Array(80),f=g(),u=g(),c=g(),w=g(),y=g(),l=g();for(o=0;o<31;o++)a[o]=n[o];for(a[31]=127&n[31]|64,a[0]&=248,q(i,e),o=0;o<16;o++)u[o]=i[o],w[o]=f[o]=c[o]=0;for(f[0]=w[0]=1,o=254;0<=o;--o)F(f,u,t=a[o>>>3]>>>(7&o)&1),F(c,w,t),D(y,f,c),V(f,f,c),D(c,u,w),V(u,u,w),j(w,y),j(l,f),X(f,c,f),X(c,u,y),D(y,f,c),V(f,f,c),j(u,f),V(c,w,l),X(f,c,b),D(f,f,w),X(c,c,f),X(f,w,l),X(w,u,i),j(u,y),F(f,u,t),F(c,w,t);for(o=0;o<16;o++)i[o+16]=f[o],i[o+32]=c[o],i[o+48]=u[o],i[o+64]=w[o];var s=i.subarray(32),h=i.subarray(16);return H(s,s),X(h,h,s),Z(r,h),0}function W(r,n){return Q(r,n,e)}function $(r,n){return i(n,32),W(r,n)}function rr(r,n,e){var t=new Uint8Array(32);return Q(t,e,n),x(r,o,t,d)}var nr=C,er=N;function tr(){var r,n,e,t=0,o=0,a=0,i=0,f=65535;for(e=0;e<arguments.length;e++)t+=(r=arguments[e].lo)&f,o+=r>>>16,a+=(n=arguments[e].hi)&f,i+=n>>>16;return new K((a+=(o+=t>>>16)>>>16)&f|(i+=a>>>16)<<16,t&f|o<<16)}function or(r,n){return new K(r.hi>>>n,r.lo>>>n|r.hi<<32-n)}function ar(){var r,n=0,e=0;for(r=0;r<arguments.length;r++)n^=arguments[r].lo,e^=arguments[r].hi;return new K(e,n)}function ir(r,n){var e,t,o=32-n;return n<32?(e=r.hi>>>n|r.lo<<o,t=r.lo>>>n|r.hi<<o):n<64&&(e=r.lo>>>n|r.hi<<o,t=r.hi>>>n|r.lo<<o),new K(e,t)}var fr=[new K(1116352408,3609767458),new K(1899447441,602891725),new K(3049323471,3964484399),new K(3921009573,2173295548),new K(961987163,4081628472),new K(1508970993,3053834265),new K(2453635748,2937671579),new K(2870763221,3664609560),new K(3624381080,2734883394),new K(310598401,1164996542),new K(607225278,1323610764),new K(1426881987,3590304994),new K(1925078388,4068182383),new K(2162078206,991336113),new K(2614888103,633803317),new K(3248222580,3479774868),new K(3835390401,2666613458),new K(4022224774,944711139),new K(264347078,2341262773),new K(604807628,2007800933),new K(770255983,1495990901),new K(1249150122,1856431235),new K(1555081692,3175218132),new K(1996064986,2198950837),new K(2554220882,3999719339),new K(2821834349,766784016),new K(2952996808,2566594879),new K(3210313671,3203337956),new K(3336571891,1034457026),new K(3584528711,2466948901),new K(113926993,3758326383),new K(338241895,168717936),new K(666307205,1188179964),new K(773529912,1546045734),new K(1294757372,1522805485),new K(1396182291,2643833823),new K(1695183700,2343527390),new K(1986661051,1014477480),new K(2177026350,1206759142),new K(2456956037,344077627),new K(2730485921,1290863460),new K(2820302411,3158454273),new K(3259730800,3505952657),new K(3345764771,106217008),new K(3516065817,3606008344),new K(3600352804,1432725776),new K(4094571909,1467031594),new K(275423344,851169720),new K(430227734,3100823752),new K(506948616,1363258195),new K(659060556,3750685593),new K(883997877,3785050280),new K(958139571,3318307427),new K(1322822218,3812723403),new K(1537002063,2003034995),new K(1747873779,3602036899),new K(1955562222,1575990012),new K(2024104815,1125592928),new K(2227730452,2716904306),new K(2361852424,442776044),new K(2428436474,593698344),new K(2756734187,3733110249),new K(3204031479,2999351573),new K(3329325298,3815920427),new K(3391569614,3928383900),new K(3515267271,566280711),new K(3940187606,3454069534),new K(4118630271,4000239992),new K(116418474,1914138554),new K(174292421,2731055270),new K(289380356,3203993006),new K(460393269,320620315),new K(685471733,587496836),new K(852142971,1086792851),new K(1017036298,365543100),new K(1126000580,2618297676),new K(1288033470,3409855158),new K(1501505948,4234509866),new K(1607167915,987167468),new K(1816402316,1246189591)];function ur(r,n,e){var t,o,a,i=[],f=[],u=[],c=[];for(o=0;o<8;o++)i[o]=u[o]=m(r,8*o);for(var w,y,l,s,h,g,b,v,p,_,A,U,E,x,d=0;128<=e;){for(o=0;o<16;o++)c[o]=m(n,8*o+d);for(o=0;o<80;o++){for(a=0;a<8;a++)f[a]=u[a];for(t=tr(u[7],ar(ir(x=u[4],14),ir(x,18),ir(x,41)),(p=u[4],_=u[5],A=u[6],0,U=p.hi&_.hi^~p.hi&A.hi,E=p.lo&_.lo^~p.lo&A.lo,new K(U,E)),fr[o],c[o%16]),f[7]=tr(t,ar(ir(v=u[0],28),ir(v,34),ir(v,39)),(l=u[0],s=u[1],h=u[2],0,g=l.hi&s.hi^l.hi&h.hi^s.hi&h.hi,b=l.lo&s.lo^l.lo&h.lo^s.lo&h.lo,new K(g,b))),f[3]=tr(f[3],t),a=0;a<8;a++)u[(a+1)%8]=f[a];if(o%16==15)for(a=0;a<16;a++)c[a]=tr(c[a],c[(a+9)%16],ar(ir(y=c[(a+1)%16],1),ir(y,8),or(y,7)),ar(ir(w=c[(a+14)%16],19),ir(w,61),or(w,6)))}for(o=0;o<8;o++)u[o]=tr(u[o],i[o]),i[o]=u[o];d+=128,e-=128}for(o=0;o<8;o++)B(r,8*o,i[o]);return e}var cr=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]);function wr(r,n,e){var t,o=new Uint8Array(64),a=new Uint8Array(256),i=e;for(t=0;t<64;t++)o[t]=cr[t];for(ur(o,n,e),e%=128,t=0;t<256;t++)a[t]=0;for(t=0;t<e;t++)a[t]=n[i-e+t];for(a[e]=128,a[(e=256-128*(e<112?1:0))-9]=0,B(a,e-8,new K(i/536870912|0,i<<3)),ur(o,a,e),t=0;t<64;t++)r[t]=o[t];return 0}function yr(r,n){var e=g(),t=g(),o=g(),a=g(),i=g(),f=g(),u=g(),c=g(),w=g();V(e,r[1],r[0]),V(w,n[1],n[0]),X(e,e,w),D(t,r[0],r[1]),D(w,n[0],n[1]),X(t,t,w),X(o,r[3],n[3]),X(o,o,l),X(a,r[2],n[2]),D(a,a,a),V(i,t,e),V(f,a,o),D(u,a,o),D(c,t,e),X(r[0],i,f),X(r[1],c,u),X(r[2],u,f),X(r[3],i,c)}function lr(r,n,e){var t;for(t=0;t<4;t++)F(r[t],n[t],e)}function sr(r,n){var e=g(),t=g(),o=g();H(o,n[2]),X(e,n[0],o),X(t,n[1],o),Z(r,t),r[31]^=I(e)<<7}function hr(r,n,e){var t,o;for(O(r[0],c),O(r[1],w),O(r[2],w),O(r[3],c),o=255;0<=o;--o)lr(r,n,t=e[o/8|0]>>(7&o)&1),yr(n,r),yr(r,r),lr(r,n,t)}function gr(r,n){var e=[g(),g(),g(),g()];O(e[0],t),O(e[1],a),O(e[2],w),X(e[3],t,a),hr(r,e,n)}function br(r,n,e){var t,o=new Uint8Array(64),a=[g(),g(),g(),g()];for(e||i(n,32),wr(o,n,32),o[0]&=248,o[31]&=127,o[31]|=64,gr(a,o),sr(r,a),t=0;t<32;t++)n[t+32]=r[t];return 0}var vr=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 pr(r,n){var e,t,o,a;for(t=63;32<=t;--t){for(e=0,o=t-32,a=t-12;o<a;++o)n[o]+=e-16*n[t]*vr[o-(t-32)],e=Math.floor((n[o]+128)/256),n[o]-=256*e;n[o]+=e,n[t]=0}for(o=e=0;o<32;o++)n[o]+=e-(n[31]>>4)*vr[o],e=n[o]>>8,n[o]&=255;for(o=0;o<32;o++)n[o]-=e*vr[o];for(t=0;t<32;t++)n[t+1]+=n[t]>>8,r[t]=255&n[t]}function _r(r){var n,e=new Float64Array(64);for(n=0;n<64;n++)e[n]=r[n];for(n=0;n<64;n++)r[n]=0;pr(r,e)}function Ar(r,n,e,t){var o,a,i=new Uint8Array(64),f=new Uint8Array(64),u=new Uint8Array(64),c=new Float64Array(64),w=[g(),g(),g(),g()];wr(i,t,32),i[0]&=248,i[31]&=127,i[31]|=64;var y=e+64;for(o=0;o<e;o++)r[64+o]=n[o];for(o=0;o<32;o++)r[32+o]=i[32+o];for(wr(u,r.subarray(32),e+32),_r(u),gr(w,u),sr(r,w),o=32;o<64;o++)r[o]=t[o];for(wr(f,r,e+64),_r(f),o=0;o<64;o++)c[o]=0;for(o=0;o<32;o++)c[o]=u[o];for(o=0;o<32;o++)for(a=0;a<32;a++)c[o+a]+=f[o]*i[a];return pr(r.subarray(32),c),y}function Ur(r,n,e,t){var o,a=new Uint8Array(32),i=new Uint8Array(64),f=[g(),g(),g(),g()],u=[g(),g(),g(),g()];if(e<64)return-1;if(function(r,n){var e=g(),t=g(),o=g(),a=g(),i=g(),f=g(),u=g();if(O(r[2],w),q(r[1],n),j(o,r[1]),X(a,o,y),V(o,o,r[2]),D(a,r[2],a),j(i,a),j(f,i),X(u,f,i),X(e,u,o),X(e,e,a),J(e,e),X(e,e,o),X(e,e,a),X(e,e,a),X(r[0],e,a),j(t,r[0]),X(t,t,a),G(t,o)&&X(r[0],r[0],s),j(t,r[0]),X(t,t,a),G(t,o))return 1;I(r[0])===n[31]>>7&&V(r[0],c,r[0]),X(r[3],r[0],r[1])}(u,t))return-1;for(o=0;o<e;o++)r[o]=n[o];for(o=0;o<32;o++)r[o+32]=t[o];if(wr(i,r,e),_r(i),hr(f,u,i),gr(u,n.subarray(32)),yr(f,u),sr(a,f),e-=64,A(n,0,a,0)){for(o=0;o<e;o++)r[o]=0;return-1}for(o=0;o<e;o++)r[o]=n[o+64];return e}function Er(r,n){if(32!==r.length)throw new Error("bad key size");if(24!==n.length)throw new Error("bad nonce size")}function xr(){for(var r=0;r<arguments.length;r++)if(!(arguments[r]instanceof Uint8Array))throw new TypeError("unexpected type, use Uint8Array")}function dr(r){for(var n=0;n<r.length;n++)r[n]=0}f.lowlevel={crypto_core_hsalsa20:x,crypto_stream_xor:T,crypto_stream:Y,crypto_stream_salsa20_xor:S,crypto_stream_salsa20:L,crypto_onetimeauth:R,crypto_onetimeauth_verify:P,crypto_verify_16:_,crypto_verify_32:A,crypto_secretbox:C,crypto_secretbox_open:N,crypto_scalarmult:Q,crypto_scalarmult_base:W,crypto_box_beforenm:rr,crypto_box_afternm:nr,crypto_box:function(r,n,e,t,o,a){var i=new Uint8Array(32);return rr(i,o,a),nr(r,n,e,t,i)},crypto_box_open:function(r,n,e,t,o,a){var i=new Uint8Array(32);return rr(i,o,a),er(r,n,e,t,i)},crypto_box_keypair:$,crypto_hash:wr,crypto_sign:Ar,crypto_sign_keypair:br,crypto_sign_open:Ur,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:24,crypto_box_ZEROBYTES:32,crypto_box_BOXZEROBYTES:16,crypto_sealedbox_NONCEBYTES:24,crypto_sealedbox_PUBLICKEYBYTES:32,crypto_sealedbox_SECRETKEYBYTES:32,crypto_sign_BYTES:64,crypto_sign_PUBLICKEYBYTES:32,crypto_sign_SECRETKEYBYTES:64,crypto_sign_SEEDBYTES:32,crypto_hash_BYTES:64,gf:g,D:y,L:vr,pack25519:Z,unpack25519:q,M:X,A:D,S:j,Z:V,pow2523:J,add:yr,set25519:O,modL:pr,scalarmult:hr,scalarbase:gr},f.randomBytes=function(r){var n=new Uint8Array(r);return i(n,r),n},f.secretbox=function(r,n,e){xr(r,n,e),Er(e,n);for(var t=new Uint8Array(32+r.length),o=new Uint8Array(t.length),a=0;a<r.length;a++)t[a+32]=r[a];return C(o,t,t.length,n,e),o.subarray(16)},f.secretbox.open=function(r,n,e){xr(r,n,e),Er(e,n);for(var t=new Uint8Array(16+r.length),o=new Uint8Array(t.length),a=0;a<r.length;a++)t[a+16]=r[a];return t.length<32||0!==N(o,t,t.length,n,e)?null:o.subarray(32)},f.secretbox.keyLength=32,f.secretbox.nonceLength=24,f.secretbox.overheadLength=16,f.scalarMult=function(r,n){if(xr(r,n),32!==r.length)throw new Error("bad n size");if(32!==n.length)throw new Error("bad p size");var e=new Uint8Array(32);return Q(e,r,n),e},f.scalarMult.base=function(r){if(xr(r),32!==r.length)throw new Error("bad n size");var n=new Uint8Array(32);return W(n,r),n},f.scalarMult.scalarLength=32,f.scalarMult.groupElementLength=32,f.box=function(r,n,e,t){var o=f.box.before(e,t);return f.secretbox(r,n,o)},f.box.before=function(r,n){xr(r,n),function(r,n){if(32!==r.length)throw new Error("bad public key size");if(32!==n.length)throw new Error("bad secret key size")}(r,n);var e=new Uint8Array(32);return rr(e,r,n),e},f.box.after=f.secretbox,f.box.open=function(r,n,e,t){var o=f.box.before(e,t);return f.secretbox.open(r,n,o)},f.box.open.after=f.secretbox.open,f.box.keyPair=function(){var r=new Uint8Array(32),n=new Uint8Array(32);return $(r,n),{publicKey:r,secretKey:n}},f.box.keyPair.fromSecretKey=function(r){if(xr(r),32!==r.length)throw new Error("bad secret key size");var n=new Uint8Array(32);return W(n,r),{publicKey:n,secretKey:new Uint8Array(r)}},f.box.publicKeyLength=32,f.box.secretKeyLength=32,f.box.sharedKeyLength=32,f.box.nonceLength=24,f.box.overheadLength=f.secretbox.overheadLength,f.sealedbox=function(r,n,e){xr(r,n,e),Er(e,n);for(var t=f.box.keyPair(),o=f.box(r,n,e,t.secretKey),a=0;a<t.secretKey.length;a++)t.secretKey[a]=0;var i=new Uint8Array(t.publicKey.length+o.length);for(a=0;a<t.publicKey.length;a++)i[a]=t.publicKey[a];for(a=0;a<o.length;a++)i[t.publicKey.length+a]=o[a];return i},f.sealedbox.open=function(r,n,e){xr(r,n,e),function(r,n,e){if(32!==r.length)throw new Error("bad secret key size");if(24!==n.length)throw new Error("bad nonce size");if(e.length<=32)throw new Error("bad message size")}(e,n,r);for(var t=new Uint8Array(32),o=0;o<t.length;o++)t[o]=r[o];var a=new Uint8Array(r.length-32);for(o=0;o<a.length;o++)a[o]=r[32+o];return f.box.open(a,n,t,e)},f.sealedbox.publicKeyLength=32,f.sealedbox.secretKeyLength=32,f.sealedbox.nonceLength=24,f.sealedbox.overheadLength=f.box.overheadLength+32,f.sign=function(r,n){if(xr(r,n),64!==n.length)throw new Error("bad secret key size");var e=new Uint8Array(64+r.length);return Ar(e,r,r.length,n),e},f.sign.open=function(r,n){if(xr(r,n),32!==n.length)throw new Error("bad public key size");var e=new Uint8Array(r.length),t=Ur(e,r,r.length,n);if(t<0)return null;for(var o=new Uint8Array(t),a=0;a<o.length;a++)o[a]=e[a];return o},f.sign.detached=function(r,n){for(var e=f.sign(r,n),t=new Uint8Array(64),o=0;o<t.length;o++)t[o]=e[o];return t},f.sign.detached.verify=function(r,n,e){if(xr(r,n,e),64!==n.length)throw new Error("bad signature size");if(32!==e.length)throw new Error("bad public key size");var t,o=new Uint8Array(64+r.length),a=new Uint8Array(64+r.length);for(t=0;t<64;t++)o[t]=n[t];for(t=0;t<r.length;t++)o[t+64]=r[t];return 0<=Ur(a,o,o.length,e)},f.sign.keyPair=function(){var r=new Uint8Array(32),n=new Uint8Array(64);return br(r,n),{publicKey:r,secretKey:n}},f.sign.keyPair.fromSecretKey=function(r){if(xr(r),64!==r.length)throw new Error("bad secret key size");for(var n=new Uint8Array(32),e=0;e<n.length;e++)n[e]=r[32+e];return{publicKey:n,secretKey:new Uint8Array(r)}},f.sign.keyPair.fromSeed=function(r){if(xr(r),32!==r.length)throw new Error("bad seed size");for(var n=new Uint8Array(32),e=new Uint8Array(64),t=0;t<32;t++)e[t]=r[t];return br(n,e,!0),{publicKey:n,secretKey:e}},f.sign.publicKeyLength=32,f.sign.secretKeyLength=64,f.sign.seedLength=32,f.sign.signatureLength=64,f.hash=function(r){xr(r);var n=new Uint8Array(64);return wr(n,r,r.length),n},f.hash.hashLength=64,f.verify=function(r,n){return xr(r,n),0!==r.length&&0!==n.length&&(r.length===n.length&&0===u(r,0,n,0,r.length))},f.setPRNG=function(r){i=r},function(){var o="undefined"!=typeof self?self.crypto||self.msCrypto:null;if(o&&o.getRandomValues){f.setPRNG(function(r,n){var e,t=new Uint8Array(n);for(e=0;e<n;e+=65536)o.getRandomValues(t.subarray(e,e+Math.min(n-e,65536)));for(e=0;e<n;e++)r[e]=t[e];dr(t)})}else"undefined"!=typeof require&&(o=require("crypto"))&&o.randomBytes&&f.setPRNG(function(r,n){var e,t=o.randomBytes(n);for(e=0;e<n;e++)r[e]=t[e];dr(t)})}()}("undefined"!=typeof module&&module.exports?module.exports:self.nacl=self.nacl||{});