From 726869a401613592653f90a179f75ed3aa06e4f6 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Sat, 11 Nov 2017 01:26:42 +0100 Subject: [PATCH 1/2] Switch from Float64Array to Array This makes signing/verifying ~3 times faster. On 2.6 GHz Intel Core i5 (MBPr Mid 2014), Node.js v8.8.1: Before: sign 92 ops 5.46 ms/op 183.17 ops/sec sign.open 48 ops 10.50 ms/op 95.26 ops/sec After: sign 269 ops 1.86 ms/op 536.52 ops/sec sign.open 136 ops 3.70 ms/op 270.55 ops/sec --- nacl-fast.js | 52 +++++++++++++++++++++++++++++------------------- nacl-fast.min.js | 4 ++-- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/nacl-fast.js b/nacl-fast.js index 34b82e76..7101af28 100644 --- a/nacl-fast.js +++ b/nacl-fast.js @@ -7,11 +7,16 @@ // Implementation derived from TweetNaCl version 20140427. // See for details: http://tweetnacl.cr.yp.to/ -var gf = function(init) { - var i, r = new Float64Array(16); - if (init) for (i = 0; i < init.length; i++) r[i] = init[i]; +function gf() { + return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; +} + +function gfi(init) { + var r = [], i = 0; + for ( ; i < init.length; i++) r[i] = init[i]; + for ( ; i < 16; i++) r[i] = 0; return r; -}; +} // Pluggable, initialized in high-level API below. var randombytes = function(/* x, n */) { throw new Error('no PRNG'); }; @@ -20,13 +25,13 @@ var _0 = new Uint8Array(16); var _9 = new Uint8Array(32); _9[0] = 9; var gf0 = gf(), - gf1 = gf([1]), - _121665 = gf([0xdb41, 1]), - D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]), - D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]), - X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]), - Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]), - I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]); + gf1 = gfi([1]), + _121665 = gfi([0xdb41, 1]), + D = gfi([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]), + D2 = gfi([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]), + X = gfi([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]), + Y = gfi([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]), + I = gfi([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]); function ts64(x, i, h, l) { x[i] = (h >> 24) & 0xff; @@ -1323,7 +1328,7 @@ function pow2523(o, i) { function crypto_scalarmult(q, n, p) { var z = new Uint8Array(32); - var x = new Float64Array(80), r, i; + var x = [] /* 80 */, r, i; var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf(); for (i = 0; i < 31; i++) z[i] = n[i]; @@ -1360,14 +1365,19 @@ function crypto_scalarmult(q, n, p) { sel25519(a,b,r); sel25519(c,d,r); } + var x32 = []; /* 48 */ + for (i = 0; i < 16; i++) { + x32[i] = c[i]; + x32[i+16] = b[i]; + x32[i+32] = d[i]; + } + var x16 = []; /* 64 */ for (i = 0; i < 16; i++) { - x[i+16]=a[i]; - x[i+32]=c[i]; - x[i+48]=b[i]; - x[i+64]=d[i]; + x16[i] = a[i]; + x16[i+16] = c[i]; + x16[i+32] = b[i]; + x16[i+48] = d[i]; } - var x32 = x.subarray(32); - var x16 = x.subarray(16); inv25519(x32,x32); M(x16,x16,x32); pack25519(q,x16); @@ -1932,7 +1942,7 @@ function crypto_sign_keypair(pk, sk, seeded) { return 0; } -var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]); +var L = [0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]; function modL(r, x) { var carry, i, j, k; @@ -1960,7 +1970,7 @@ function modL(r, x) { } function reduce(r) { - var x = new Float64Array(64), i; + var x = [] /* 64 */, i; for (i = 0; i < 64; i++) x[i] = r[i]; for (i = 0; i < 64; i++) r[i] = 0; modL(r, x); @@ -1969,7 +1979,7 @@ function reduce(r) { // Note: difference from C - smlen returned, not passed as argument. function crypto_sign(sm, m, n, sk) { var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64); - var i, j, x = new Float64Array(64); + var i, j, x = [] /* 64 */; var p = [gf(), gf(), gf(), gf()]; crypto_hash(d, sk, 32); diff --git a/nacl-fast.min.js b/nacl-fast.min.js index fcab70b1..83cacfa0 100644 --- a/nacl-fast.min.js +++ b/nacl-fast.min.js @@ -1,2 +1,2 @@ -!function(r){"use strict";function t(r,t,n,e){r[t]=n>>24&255,r[t+1]=n>>16&255,r[t+2]=n>>8&255,r[t+3]=255&n,r[t+4]=e>>24&255,r[t+5]=e>>16&255,r[t+6]=e>>8&255,r[t+7]=255&e}function n(r,t,n,e,o){var i,h=0;for(i=0;i>>8)-1}function e(r,t,e,o){return n(r,t,e,o,16)}function o(r,t,e,o){return n(r,t,e,o,32)}function i(r,t,n,e){for(var o,i=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,h=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,a=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,f=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,s=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,u=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,c=255&t[0]|(255&t[1])<<8|(255&t[2])<<16|(255&t[3])<<24,y=255&t[4]|(255&t[5])<<8|(255&t[6])<<16|(255&t[7])<<24,l=255&t[8]|(255&t[9])<<8|(255&t[10])<<16|(255&t[11])<<24,w=255&t[12]|(255&t[13])<<8|(255&t[14])<<16|(255&t[15])<<24,v=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,p=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,b=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,g=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,_=255&n[28]|(255&n[29])<<8|(255&n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>>24&255,r[4]=d>>>0&255,r[5]=d>>>8&255,r[6]=d>>>16&255,r[7]=d>>>24&255,r[8]=E>>>0&255,r[9]=E>>>8&255,r[10]=E>>>16&255,r[11]=E>>>24&255,r[12]=x>>>0&255,r[13]=x>>>8&255,r[14]=x>>>16&255,r[15]=x>>>24&255,r[16]=M>>>0&255,r[17]=M>>>8&255,r[18]=M>>>16&255,r[19]=M>>>24&255,r[20]=m>>>0&255,r[21]=m>>>8&255,r[22]=m>>>16&255,r[23]=m>>>24&255,r[24]=B>>>0&255,r[25]=B>>>8&255,r[26]=B>>>16&255,r[27]=B>>>24&255,r[28]=S>>>0&255,r[29]=S>>>8&255,r[30]=S>>>16&255,r[31]=S>>>24&255,r[32]=K>>>0&255,r[33]=K>>>8&255,r[34]=K>>>16&255,r[35]=K>>>24&255,r[36]=Y>>>0&255,r[37]=Y>>>8&255,r[38]=Y>>>16&255,r[39]=Y>>>24&255,r[40]=k>>>0&255,r[41]=k>>>8&255,r[42]=k>>>16&255,r[43]=k>>>24&255,r[44]=T>>>0&255,r[45]=T>>>8&255,r[46]=T>>>16&255,r[47]=T>>>24&255,r[48]=L>>>0&255,r[49]=L>>>8&255,r[50]=L>>>16&255,r[51]=L>>>24&255,r[52]=z>>>0&255,r[53]=z>>>8&255,r[54]=z>>>16&255,r[55]=z>>>24&255,r[56]=R>>>0&255,r[57]=R>>>8&255,r[58]=R>>>16&255,r[59]=R>>>24&255,r[60]=P>>>0&255,r[61]=P>>>8&255,r[62]=P>>>16&255,r[63]=P>>>24&255}function h(r,t,n,e){for(var o,i=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,h=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,a=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,f=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,s=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,u=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,c=255&t[0]|(255&t[1])<<8|(255&t[2])<<16|(255&t[3])<<24,y=255&t[4]|(255&t[5])<<8|(255&t[6])<<16|(255&t[7])<<24,l=255&t[8]|(255&t[9])<<8|(255&t[10])<<16|(255&t[11])<<24,w=255&t[12]|(255&t[13])<<8|(255&t[14])<<16|(255&t[15])<<24,v=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,p=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,b=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,g=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,_=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,A=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,U=i,d=h,E=a,x=f,M=s,m=u,B=c,S=y,K=l,Y=w,k=v,T=p,L=b,z=g,R=_,P=A,N=0;N<20;N+=2)o=U+L|0,M^=o<<7|o>>>25,o=M+U|0,K^=o<<9|o>>>23,o=K+M|0,L^=o<<13|o>>>19,o=L+K|0,U^=o<<18|o>>>14,o=m+d|0,Y^=o<<7|o>>>25,o=Y+m|0,z^=o<<9|o>>>23,o=z+Y|0,d^=o<<13|o>>>19,o=d+z|0,m^=o<<18|o>>>14,o=k+B|0,R^=o<<7|o>>>25,o=R+k|0,E^=o<<9|o>>>23,o=E+R|0,B^=o<<13|o>>>19,o=B+E|0,k^=o<<18|o>>>14,o=P+T|0,x^=o<<7|o>>>25,o=x+P|0,S^=o<<9|o>>>23,o=S+x|0,T^=o<<13|o>>>19,o=T+S|0,P^=o<<18|o>>>14,o=U+x|0,d^=o<<7|o>>>25,o=d+U|0,E^=o<<9|o>>>23,o=E+d|0,x^=o<<13|o>>>19,o=x+E|0,U^=o<<18|o>>>14,o=m+M|0,B^=o<<7|o>>>25,o=B+m|0,S^=o<<9|o>>>23,o=S+B|0,M^=o<<13|o>>>19,o=M+S|0,m^=o<<18|o>>>14,o=k+Y|0,T^=o<<7|o>>>25,o=T+k|0,K^=o<<9|o>>>23,o=K+T|0,Y^=o<<13|o>>>19,o=Y+K|0,k^=o<<18|o>>>14,o=P+R|0,L^=o<<7|o>>>25,o=L+P|0,z^=o<<9|o>>>23,o=z+L|0,R^=o<<13|o>>>19,o=R+z|0,P^=o<<18|o>>>14;r[0]=U>>>0&255,r[1]=U>>>8&255,r[2]=U>>>16&255,r[3]=U>>>24&255,r[4]=m>>>0&255,r[5]=m>>>8&255,r[6]=m>>>16&255,r[7]=m>>>24&255,r[8]=k>>>0&255,r[9]=k>>>8&255,r[10]=k>>>16&255,r[11]=k>>>24&255,r[12]=P>>>0&255,r[13]=P>>>8&255,r[14]=P>>>16&255,r[15]=P>>>24&255,r[16]=B>>>0&255,r[17]=B>>>8&255,r[18]=B>>>16&255,r[19]=B>>>24&255,r[20]=S>>>0&255,r[21]=S>>>8&255,r[22]=S>>>16&255,r[23]=S>>>24&255,r[24]=K>>>0&255,r[25]=K>>>8&255,r[26]=K>>>16&255,r[27]=K>>>24&255,r[28]=Y>>>0&255,r[29]=Y>>>8&255,r[30]=Y>>>16&255,r[31]=Y>>>24&255}function a(r,t,n,e){i(r,t,n,e)}function f(r,t,n,e){h(r,t,n,e)}function s(r,t,n,e,o,i,h){var f,s,u=new Uint8Array(16),c=new Uint8Array(64);for(s=0;s<16;s++)u[s]=0;for(s=0;s<8;s++)u[s]=i[s];for(;o>=64;){for(a(c,u,h,cr),s=0;s<64;s++)r[t+s]=n[e+s]^c[s];for(f=1,s=8;s<16;s++)f=f+(255&u[s])|0,u[s]=255&f,f>>>=8;o-=64,t+=64,e+=64}if(o>0)for(a(c,u,h,cr),s=0;s=64;){for(a(s,f,o,cr),h=0;h<64;h++)r[t+h]=s[h];for(i=1,h=8;h<16;h++)i=i+(255&f[h])|0,f[h]=255&i,i>>>=8;n-=64,t+=64}if(n>0)for(a(s,f,o,cr),h=0;h>16&1),i[n-1]&=65535;i[15]=h[15]-32767-(i[14]>>16&1),o=i[15]>>16&1,i[14]&=65535,_(h,i,1-o)}for(n=0;n<16;n++)r[2*n]=255&h[n],r[2*n+1]=h[n]>>8}function U(r,t){var n=new Uint8Array(32),e=new Uint8Array(32);return A(n,r),A(e,t),o(n,0,e,0)}function d(r){var t=new Uint8Array(32);return A(t,r),1&t[0]}function E(r,t){var n;for(n=0;n<16;n++)r[n]=t[2*n]+(t[2*n+1]<<8);r[15]&=32767}function x(r,t,n){for(var e=0;e<16;e++)r[e]=t[e]+n[e]}function M(r,t,n){for(var e=0;e<16;e++)r[e]=t[e]-n[e]}function m(r,t,n){var e,o,i=0,h=0,a=0,f=0,s=0,u=0,c=0,y=0,l=0,w=0,v=0,p=0,b=0,g=0,_=0,A=0,U=0,d=0,E=0,x=0,M=0,m=0,B=0,S=0,K=0,Y=0,k=0,T=0,L=0,z=0,R=0,P=n[0],N=n[1],O=n[2],C=n[3],F=n[4],I=n[5],G=n[6],Z=n[7],q=n[8],V=n[9],X=n[10],D=n[11],j=n[12],H=n[13],J=n[14],Q=n[15];e=t[0],i+=e*P,h+=e*N,a+=e*O,f+=e*C,s+=e*F,u+=e*I,c+=e*G,y+=e*Z,l+=e*q,w+=e*V,v+=e*X,p+=e*D,b+=e*j,g+=e*H,_+=e*J,A+=e*Q,e=t[1],h+=e*P,a+=e*N,f+=e*O,s+=e*C,u+=e*F,c+=e*I,y+=e*G,l+=e*Z,w+=e*q,v+=e*V,p+=e*X,b+=e*D,g+=e*j,_+=e*H,A+=e*J,U+=e*Q,e=t[2],a+=e*P,f+=e*N,s+=e*O,u+=e*C,c+=e*F,y+=e*I,l+=e*G,w+=e*Z,v+=e*q,p+=e*V,b+=e*X,g+=e*D,_+=e*j,A+=e*H,U+=e*J,d+=e*Q,e=t[3],f+=e*P,s+=e*N,u+=e*O,c+=e*C,y+=e*F,l+=e*I,w+=e*G,v+=e*Z,p+=e*q,b+=e*V,g+=e*X,_+=e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e*C,U+=e*F,d+=e*I,E+=e*G,x+=e*Z,M+=e*q,m+=e*V,B+=e*X,S+=e*D,K+=e*j,Y+=e*H,k+=e*J,T+=e*Q,e=t[13],g+=e*P,_+=e*N,A+=e*O,U+=e*C,d+=e*F,E+=e*I,x+=e*G,M+=e*Z,m+=e*q,B+=e*V,S+=e*X,K+=e*D,Y+=e*j,k+=e*H,T+=e*J,L+=e*Q,e=t[14],_+=e*P,A+=e*N,U+=e*O,d+=e*C,E+=e*F,x+=e*I,M+=e*G,m+=e*Z,B+=e*q,S+=e*V,K+=e*X,Y+=e*D,k+=e*j,T+=e*H,L+=e*J,z+=e*Q,e=t[15],A+=e*P,U+=e*N,d+=e*O,E+=e*C,x+=e*F,M+=e*I,m+=e*G,B+=e*Z,S+=e*q,K+=e*V,Y+=e*X,k+=e*D,T+=e*j,L+=e*H,z+=e*J,R+=e*Q,i+=38*U,h+=38*d,a+=38*E,f+=38*x,s+=38*M,u+=38*m,c+=38*B,y+=38*S,l+=38*K,w+=38*Y,v+=38*k,p+=38*T,b+=38*L,g+=38*z,_+=38*R,o=1,e=i+o+65535,o=Math.floor(e/65536),i=e-65536*o,e=h+o+65535,o=Math.floor(e/65536),h=e-65536*o,e=a+o+65535,o=Math.floor(e/65536),a=e-65536*o,e=f+o+65535,o=Math.floor(e/65536),f=e-65536*o,e=s+o+65535,o=Math.floor(e/65536),s=e-65536*o,e=u+o+65535,o=Math.floor(e/65536),u=e-65536*o,e=c+o+65535,o=Math.floor(e/65536),c=e-65536*o,e=y+o+65535,o=Math.floor(e/65536),y=e-65536*o,e=l+o+65535,o=Math.floor(e/65536),l=e-65536*o,e=w+o+65535,o=Math.floor(e/65536),w=e-65536*o,e=v+o+65535,o=Math.floor(e/65536),v=e-65536*o,e=p+o+65535,o=Math.floor(e/65536),p=e-65536*o,e=b+o+65535,o=Math.floor(e/65536),b=e-65536*o,e=g+o+65535,o=Math.floor(e/65536),g=e-65536*o,e=_+o+65535,o=Math.floor(e/65536),_=e-65536*o,e=A+o+65535,o=Math.floor(e/65536),A=e-65536*o,i+=o-1+37*(o-1),o=1,e=i+o+65535,o=Math.floor(e/65536),i=e-65536*o,e=h+o+65535,o=Math.floor(e/65536),h=e-65536*o,e=a+o+65535,o=Math.floor(e/65536),a=e-65536*o,e=f+o+65535,o=Math.floor(e/65536),f=e-65536*o,e=s+o+65535,o=Math.floor(e/65536),s=e-65536*o,e=u+o+65535,o=Math.floor(e/65536),u=e-65536*o,e=c+o+65535,o=Math.floor(e/65536),c=e-65536*o,e=y+o+65535,o=Math.floor(e/65536),y=e-65536*o,e=l+o+65535,o=Math.floor(e/65536),l=e-65536*o,e=w+o+65535,o=Math.floor(e/65536),w=e-65536*o,e=v+o+65535,o=Math.floor(e/65536),v=e-65536*o,e=p+o+65535,o=Math.floor(e/65536),p=e-65536*o,e=b+o+65535,o=Math.floor(e/65536),b=e-65536*o,e=g+o+65535,o=Math.floor(e/65536),g=e-65536*o,e=_+o+65535,o=Math.floor(e/65536),_=e-65536*o,e=A+o+65535,o=Math.floor(e/65536),A=e-65536*o,i+=o-1+37*(o-1),r[0]=i,r[1]=h,r[2]=a,r[3]=f,r[4]=s,r[5]=u,r[6]=c,r[7]=y,r[8]=l,r[9]=w,r[10]=v,r[11]=p,r[12]=b,r[13]=g;r[14]=_;r[15]=A}function B(r,t){m(r,t,t)}function S(r,t){var n,e=$();for(n=0;n<16;n++)e[n]=t[n];for(n=253;n>=0;n--)B(e,e),2!==n&&4!==n&&m(e,e,t);for(n=0;n<16;n++)r[n]=e[n]}function K(r,t){var n,e=$();for(n=0;n<16;n++)e[n]=t[n];for(n=250;n>=0;n--)B(e,e),1!==n&&m(e,e,t);for(n=0;n<16;n++)r[n]=e[n]}function Y(r,t,n){var e,o,i=new Uint8Array(32),h=new Float64Array(80),a=$(),f=$(),s=$(),u=$(),c=$(),y=$();for(o=0;o<31;o++)i[o]=t[o];for(i[31]=127&t[31]|64,i[0]&=248,E(h,n),o=0;o<16;o++)f[o]=h[o],u[o]=a[o]=s[o]=0;for(a[0]=u[0]=1,o=254;o>=0;--o)e=i[o>>>3]>>>(7&o)&1,_(a,f,e),_(s,u,e),x(c,a,s),M(a,a,s),x(s,f,u),M(f,f,u),B(u,c),B(y,a),m(a,s,a),m(s,f,c),x(c,a,s),M(a,a,s),B(f,a),M(s,u,y),m(a,s,ir),x(a,a,u),m(s,s,a),m(a,u,y),m(u,f,h),B(f,c),_(a,f,e),_(s,u,e);for(o=0;o<16;o++)h[o+16]=a[o],h[o+32]=s[o],h[o+48]=f[o],h[o+64]=u[o];var l=h.subarray(32),w=h.subarray(16);return S(l,l),m(w,w,l),A(r,w),0}function k(r,t){return Y(r,t,nr)}function T(r,t){return rr(t,32),k(r,t)}function L(r,t,n){var e=new Uint8Array(32);return Y(e,n,t),f(r,tr,e,cr)}function z(r,t,n,e,o,i){var h=new Uint8Array(32);return L(h,o,i),lr(r,t,n,e,h)}function R(r,t,n,e,o,i){var h=new Uint8Array(32);return L(h,o,i),wr(r,t,n,e,h)}function P(r,t,n,e){for(var o,i,h,a,f,s,u,c,y,l,w,v,p,b,g,_,A,U,d,E,x,M,m,B,S,K,Y=new Int32Array(16),k=new Int32Array(16),T=r[0],L=r[1],z=r[2],R=r[3],P=r[4],N=r[5],O=r[6],C=r[7],F=t[0],I=t[1],G=t[2],Z=t[3],q=t[4],V=t[5],X=t[6],D=t[7],j=0;e>=128;){for(d=0;d<16;d++)E=8*d+j,Y[d]=n[E+0]<<24|n[E+1]<<16|n[E+2]<<8|n[E+3],k[d]=n[E+4]<<24|n[E+5]<<16|n[E+6]<<8|n[E+7];for(d=0;d<80;d++)if(o=T,i=L,h=z,a=R,f=P,s=N,u=O,c=C,y=F,l=I,w=G,v=Z,p=q,b=V,g=X,_=D,x=C,M=D,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=(P>>>14|q<<18)^(P>>>18|q<<14)^(q>>>9|P<<23),M=(q>>>14|P<<18)^(q>>>18|P<<14)^(P>>>9|q<<23),m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,x=P&N^~P&O,M=q&V^~q&X,m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,x=vr[2*d],M=vr[2*d+1],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,x=Y[d%16],M=k[d%16],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,A=65535&S|K<<16,U=65535&m|B<<16,x=A,M=U,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=(T>>>28|F<<4)^(F>>>2|T<<30)^(F>>>7|T<<25),M=(F>>>28|T<<4)^(T>>>2|F<<30)^(T>>>7|F<<25),m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,x=T&L^T&z^L&z,M=F&I^F&G^I&G,m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,c=65535&S|K<<16,_=65535&m|B<<16,x=a,M=v,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=A,M=U,m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,a=65535&S|K<<16,v=65535&m|B<<16,L=o,z=i,R=h,P=a,N=f,O=s,C=u,T=c,I=y,G=l,Z=w,q=v,V=p,X=b,D=g,F=_,d%16===15)for(E=0;E<16;E++)x=Y[E],M=k[E],m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=Y[(E+9)%16],M=k[(E+9)%16],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,A=Y[(E+1)%16],U=k[(E+1)%16],x=(A>>>1|U<<31)^(A>>>8|U<<24)^A>>>7,M=(U>>>1|A<<31)^(U>>>8|A<<24)^(U>>>7|A<<25),m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,A=Y[(E+14)%16],U=k[(E+14)%16],x=(A>>>19|U<<13)^(U>>>29|A<<3)^A>>>6,M=(U>>>19|A<<13)^(A>>>29|U<<3)^(U>>>6|A<<26),m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,Y[E]=65535&S|K<<16,k[E]=65535&m|B<<16;x=T,M=F,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=r[0],M=t[0],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,r[0]=T=65535&S|K<<16,t[0]=F=65535&m|B<<16,x=L,M=I,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=r[1],M=t[1],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,r[1]=L=65535&S|K<<16,t[1]=I=65535&m|B<<16,x=z,M=G,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=r[2],M=t[2],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,r[2]=z=65535&S|K<<16,t[2]=G=65535&m|B<<16,x=R,M=Z,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=r[3],M=t[3],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,r[3]=R=65535&S|K<<16,t[3]=Z=65535&m|B<<16,x=P,M=q,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=r[4],M=t[4],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,r[4]=P=65535&S|K<<16,t[4]=q=65535&m|B<<16,x=N,M=V,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=r[5],M=t[5],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,r[5]=N=65535&S|K<<16,t[5]=V=65535&m|B<<16,x=O,M=X,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=r[6],M=t[6],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,r[6]=O=65535&S|K<<16,t[6]=X=65535&m|B<<16,x=C,M=D,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=r[7],M=t[7],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,r[7]=C=65535&S|K<<16,t[7]=D=65535&m|B<<16,j+=128,e-=128}return e}function N(r,n,e){var o,i=new Int32Array(8),h=new Int32Array(8),a=new Uint8Array(256),f=e;for(i[0]=1779033703,i[1]=3144134277,i[2]=1013904242,i[3]=2773480762,i[4]=1359893119,i[5]=2600822924,i[6]=528734635,i[7]=1541459225,h[0]=4089235720,h[1]=2227873595,h[2]=4271175723,h[3]=1595750129,h[4]=2917565137,h[5]=725511199,h[6]=4215389547,h[7]=327033209,P(i,h,n,e),e%=128,o=0;o=0;--o)e=n[o/8|0]>>(7&o)&1,C(r,t,e),O(t,r),O(r,r),C(r,t,e)}function G(r,t){var n=[$(),$(),$(),$()];b(n[0],fr),b(n[1],sr),b(n[2],or),m(n[3],fr,sr),I(r,n,t)}function Z(r,t,n){var e,o=new Uint8Array(64),i=[$(),$(),$(),$()];for(n||rr(t,32),N(o,t,32),o[0]&=248,o[31]&=127,o[31]|=64,G(i,o),F(r,i),e=0;e<32;e++)t[e+32]=r[e];return 0}function q(r,t){var n,e,o,i;for(e=63;e>=32;--e){for(n=0,o=e-32,i=e-12;o>8,t[o]-=256*n;t[o]+=n,t[e]=0}for(n=0,o=0;o<32;o++)t[o]+=n-(t[31]>>4)*pr[o],n=t[o]>>8,t[o]&=255;for(o=0;o<32;o++)t[o]-=n*pr[o];for(e=0;e<32;e++)t[e+1]+=t[e]>>8,r[e]=255&t[e]}function V(r){var t,n=new Float64Array(64);for(t=0;t<64;t++)n[t]=r[t];for(t=0;t<64;t++)r[t]=0;q(r,n)}function X(r,t,n,e){var o,i,h=new Uint8Array(64),a=new Uint8Array(64),f=new Uint8Array(64),s=new Float64Array(64),u=[$(),$(),$(),$()];N(h,e,32),h[0]&=248,h[31]&=127,h[31]|=64;var c=n+64;for(o=0;o>7&&M(r[0],er,r[0]),m(r[3],r[0],r[1]),0)}function j(r,t,n,e){var i,h,a=new Uint8Array(32),f=new Uint8Array(64),s=[$(),$(),$(),$()],u=[$(),$(),$(),$()];if(h=-1,n<64)return-1;if(D(u,e))return-1;for(i=0;i>>13|n<<3),e=255&r[4]|(255&r[5])<<8,this.r[2]=7939&(n>>>10|e<<6),o=255&r[6]|(255&r[7])<<8,this.r[3]=8191&(e>>>7|o<<9),i=255&r[8]|(255&r[9])<<8,this.r[4]=255&(o>>>4|i<<12),this.r[5]=i>>>1&8190,h=255&r[10]|(255&r[11])<<8,this.r[6]=8191&(i>>>14|h<<2),a=255&r[12]|(255&r[13])<<8,this.r[7]=8065&(h>>>11|a<<5),f=255&r[14]|(255&r[15])<<8,this.r[8]=8191&(a>>>8|f<<8),this.r[9]=f>>>5&127,this.pad[0]=255&r[16]|(255&r[17])<<8,this.pad[1]=255&r[18]|(255&r[19])<<8,this.pad[2]=255&r[20]|(255&r[21])<<8,this.pad[3]=255&r[22]|(255&r[23])<<8,this.pad[4]=255&r[24]|(255&r[25])<<8,this.pad[5]=255&r[26]|(255&r[27])<<8,this.pad[6]=255&r[28]|(255&r[29])<<8,this.pad[7]=255&r[30]|(255&r[31])<<8};yr.prototype.blocks=function(r,t,n){for(var e,o,i,h,a,f,s,u,c,y,l,w,v,p,b,g,_,A,U,d=this.fin?0:2048,E=this.h[0],x=this.h[1],M=this.h[2],m=this.h[3],B=this.h[4],S=this.h[5],K=this.h[6],Y=this.h[7],k=this.h[8],T=this.h[9],L=this.r[0],z=this.r[1],R=this.r[2],P=this.r[3],N=this.r[4],O=this.r[5],C=this.r[6],F=this.r[7],I=this.r[8],G=this.r[9];n>=16;)e=255&r[t+0]|(255&r[t+1])<<8,E+=8191&e,o=255&r[t+2]|(255&r[t+3])<<8,x+=8191&(e>>>13|o<<3),i=255&r[t+4]|(255&r[t+5])<<8,M+=8191&(o>>>10|i<<6),h=255&r[t+6]|(255&r[t+7])<<8,m+=8191&(i>>>7|h<<9),a=255&r[t+8]|(255&r[t+9])<<8,B+=8191&(h>>>4|a<<12),S+=a>>>1&8191,f=255&r[t+10]|(255&r[t+11])<<8,K+=8191&(a>>>14|f<<2),s=255&r[t+12]|(255&r[t+13])<<8,Y+=8191&(f>>>11|s<<5),u=255&r[t+14]|(255&r[t+15])<<8,k+=8191&(s>>>8|u<<8),T+=u>>>5|d,c=0,y=c,y+=E*L,y+=x*(5*G),y+=M*(5*I),y+=m*(5*F),y+=B*(5*C),c=y>>>13,y&=8191,y+=S*(5*O),y+=K*(5*N),y+=Y*(5*P),y+=k*(5*R),y+=T*(5*z),c+=y>>>13,y&=8191,l=c,l+=E*z,l+=x*L,l+=M*(5*G),l+=m*(5*I),l+=B*(5*F),c=l>>>13,l&=8191,l+=S*(5*C),l+=K*(5*O),l+=Y*(5*N),l+=k*(5*P),l+=T*(5*R),c+=l>>>13,l&=8191,w=c,w+=E*R,w+=x*z,w+=M*L,w+=m*(5*G),w+=B*(5*I),c=w>>>13,w&=8191,w+=S*(5*F),w+=K*(5*C),w+=Y*(5*O),w+=k*(5*N),w+=T*(5*P),c+=w>>>13,w&=8191,v=c,v+=E*P,v+=x*R,v+=M*z,v+=m*L,v+=B*(5*G),c=v>>>13,v&=8191,v+=S*(5*I),v+=K*(5*F),v+=Y*(5*C),v+=k*(5*O),v+=T*(5*N),c+=v>>>13,v&=8191,p=c,p+=E*N,p+=x*P,p+=M*R,p+=m*z,p+=B*L,c=p>>>13,p&=8191,p+=S*(5*G),p+=K*(5*I),p+=Y*(5*F),p+=k*(5*C),p+=T*(5*O),c+=p>>>13,p&=8191,b=c,b+=E*O,b+=x*N,b+=M*P,b+=m*R,b+=B*z,c=b>>>13,b&=8191,b+=S*L,b+=K*(5*G),b+=Y*(5*I),b+=k*(5*F),b+=T*(5*C),c+=b>>>13,b&=8191,g=c,g+=E*C,g+=x*O,g+=M*N,g+=m*P,g+=B*R,c=g>>>13,g&=8191,g+=S*z,g+=K*L,g+=Y*(5*G),g+=k*(5*I),g+=T*(5*F),c+=g>>>13,g&=8191,_=c,_+=E*F,_+=x*C,_+=M*O,_+=m*N,_+=B*P,c=_>>>13,_&=8191,_+=S*R,_+=K*z,_+=Y*L,_+=k*(5*G),_+=T*(5*I),c+=_>>>13,_&=8191,A=c,A+=E*I,A+=x*F,A+=M*C,A+=m*O,A+=B*N,c=A>>>13,A&=8191,A+=S*P,A+=K*R,A+=Y*z,A+=k*L,A+=T*(5*G),c+=A>>>13,A&=8191,U=c,U+=E*G,U+=x*I,U+=M*F,U+=m*C,U+=B*O,c=U>>>13,U&=8191,U+=S*N,U+=K*P,U+=Y*R,U+=k*z,U+=T*L,c+=U>>>13,U&=8191,c=(c<<2)+c|0,c=c+y|0,y=8191&c,c>>>=13,l+=c,E=y,x=l,M=w,m=v,B=p,S=b,K=g,Y=_,k=A,T=U,t+=16,n-=16;this.h[0]=E,this.h[1]=x,this.h[2]=M,this.h[3]=m,this.h[4]=B,this.h[5]=S,this.h[6]=K,this.h[7]=Y,this.h[8]=k,this.h[9]=T},yr.prototype.finish=function(r,t){var n,e,o,i,h=new Uint16Array(10);if(this.leftover){for(i=this.leftover,this.buffer[i++]=1;i<16;i++)this.buffer[i]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(n=this.h[1]>>>13,this.h[1]&=8191,i=2;i<10;i++)this.h[i]+=n,n=this.h[i]>>>13,this.h[i]&=8191;for(this.h[0]+=5*n,n=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=n,n=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=n,h[0]=this.h[0]+5,n=h[0]>>>13,h[0]&=8191,i=1;i<10;i++)h[i]=this.h[i]+n,n=h[i]>>>13,h[i]&=8191;for(h[9]-=8192,e=(1^n)-1,i=0;i<10;i++)h[i]&=e;for(e=~e,i=0;i<10;i++)this.h[i]=this.h[i]&e|h[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;i<8;i++)o=(this.h[i]+this.pad[i]|0)+(o>>>16)|0,this.h[i]=65535&o;r[t+0]=this.h[0]>>>0&255,r[t+1]=this.h[0]>>>8&255,r[t+2]=this.h[1]>>>0&255,r[t+3]=this.h[1]>>>8&255,r[t+4]=this.h[2]>>>0&255,r[t+5]=this.h[2]>>>8&255,r[t+6]=this.h[3]>>>0&255,r[t+7]=this.h[3]>>>8&255,r[t+8]=this.h[4]>>>0&255,r[t+9]=this.h[4]>>>8&255,r[t+10]=this.h[5]>>>0&255,r[t+11]=this.h[5]>>>8&255,r[t+12]=this.h[6]>>>0&255,r[t+13]=this.h[6]>>>8&255,r[t+14]=this.h[7]>>>0&255,r[t+15]=this.h[7]>>>8&255},yr.prototype.update=function(r,t,n){var e,o;if(this.leftover){for(o=16-this.leftover,o>n&&(o=n),e=0;e=16&&(o=n-n%16,this.blocks(r,t,o),t+=o,n-=o),n){for(e=0;e=0},r.sign.keyPair=function(){var r=new Uint8Array(Yr),t=new Uint8Array(kr);return Z(r,t),{publicKey:r,secretKey:t}},r.sign.keyPair.fromSecretKey=function(r){if(Q(r),r.length!==kr)throw new Error("bad secret key size");for(var t=new Uint8Array(Yr),n=0;n>24&255,r[t+1]=n>>16&255,r[t+2]=n>>8&255,r[t+3]=255&n,r[t+4]=e>>24&255,r[t+5]=e>>16&255,r[t+6]=e>>8&255,r[t+7]=255&e}function o(r,t,n,e,o){var i,h=0;for(i=0;i>>8)-1}function i(r,t,n,e){return o(r,t,n,e,16)}function h(r,t,n,e){return o(r,t,n,e,32)}function f(r,t,n,e){for(var o,i=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,h=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,f=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,a=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,s=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,u=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,c=255&t[0]|(255&t[1])<<8|(255&t[2])<<16|(255&t[3])<<24,y=255&t[4]|(255&t[5])<<8|(255&t[6])<<16|(255&t[7])<<24,l=255&t[8]|(255&t[9])<<8|(255&t[10])<<16|(255&t[11])<<24,v=255&t[12]|(255&t[13])<<8|(255&t[14])<<16|(255&t[15])<<24,w=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,p=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,b=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,g=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,_=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,A=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,U=i,d=h,E=f,x=a,M=s,m=u,B=c,S=y,K=l,Y=v,k=w,T=p,L=b,z=g,R=_,P=A,N=0;N<20;N+=2)o=U+L|0,M^=o<<7|o>>>25,o=M+U|0,K^=o<<9|o>>>23,o=K+M|0,L^=o<<13|o>>>19,o=L+K|0,U^=o<<18|o>>>14,o=m+d|0,Y^=o<<7|o>>>25,o=Y+m|0,z^=o<<9|o>>>23,o=z+Y|0,d^=o<<13|o>>>19,o=d+z|0,m^=o<<18|o>>>14,o=k+B|0,R^=o<<7|o>>>25,o=R+k|0,E^=o<<9|o>>>23,o=E+R|0,B^=o<<13|o>>>19,o=B+E|0,k^=o<<18|o>>>14,o=P+T|0,x^=o<<7|o>>>25,o=x+P|0,S^=o<<9|o>>>23,o=S+x|0,T^=o<<13|o>>>19,o=T+S|0,P^=o<<18|o>>>14,o=U+x|0,d^=o<<7|o>>>25,o=d+U|0,E^=o<<9|o>>>23,o=E+d|0,x^=o<<13|o>>>19,o=x+E|0,U^=o<<18|o>>>14,o=m+M|0,B^=o<<7|o>>>25,o=B+m|0,S^=o<<9|o>>>23,o=S+B|0,M^=o<<13|o>>>19,o=M+S|0,m^=o<<18|o>>>14,o=k+Y|0,T^=o<<7|o>>>25,o=T+k|0,K^=o<<9|o>>>23,o=K+T|0,Y^=o<<13|o>>>19,o=Y+K|0,k^=o<<18|o>>>14,o=P+R|0,L^=o<<7|o>>>25,o=L+P|0,z^=o<<9|o>>>23,o=z+L|0,R^=o<<13|o>>>19,o=R+z|0,P^=o<<18|o>>>14;U=U+i|0,d=d+h|0,E=E+f|0,x=x+a|0,M=M+s|0,m=m+u|0,B=B+c|0,S=S+y|0,K=K+l|0,Y=Y+v|0,k=k+w|0,T=T+p|0,L=L+b|0,z=z+g|0,R=R+_|0,P=P+A|0,r[0]=U>>>0&255,r[1]=U>>>8&255,r[2]=U>>>16&255,r[3]=U>>>24&255,r[4]=d>>>0&255,r[5]=d>>>8&255,r[6]=d>>>16&255,r[7]=d>>>24&255,r[8]=E>>>0&255,r[9]=E>>>8&255,r[10]=E>>>16&255,r[11]=E>>>24&255,r[12]=x>>>0&255,r[13]=x>>>8&255,r[14]=x>>>16&255,r[15]=x>>>24&255,r[16]=M>>>0&255,r[17]=M>>>8&255,r[18]=M>>>16&255,r[19]=M>>>24&255,r[20]=m>>>0&255,r[21]=m>>>8&255,r[22]=m>>>16&255,r[23]=m>>>24&255,r[24]=B>>>0&255,r[25]=B>>>8&255,r[26]=B>>>16&255,r[27]=B>>>24&255,r[28]=S>>>0&255,r[29]=S>>>8&255,r[30]=S>>>16&255,r[31]=S>>>24&255,r[32]=K>>>0&255,r[33]=K>>>8&255,r[34]=K>>>16&255,r[35]=K>>>24&255,r[36]=Y>>>0&255,r[37]=Y>>>8&255,r[38]=Y>>>16&255,r[39]=Y>>>24&255,r[40]=k>>>0&255,r[41]=k>>>8&255,r[42]=k>>>16&255,r[43]=k>>>24&255,r[44]=T>>>0&255,r[45]=T>>>8&255,r[46]=T>>>16&255,r[47]=T>>>24&255,r[48]=L>>>0&255,r[49]=L>>>8&255,r[50]=L>>>16&255,r[51]=L>>>24&255,r[52]=z>>>0&255,r[53]=z>>>8&255,r[54]=z>>>16&255,r[55]=z>>>24&255,r[56]=R>>>0&255,r[57]=R>>>8&255,r[58]=R>>>16&255,r[59]=R>>>24&255,r[60]=P>>>0&255,r[61]=P>>>8&255,r[62]=P>>>16&255,r[63]=P>>>24&255}function a(r,t,n,e){for(var o,i=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,h=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,f=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,a=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,s=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,u=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,c=255&t[0]|(255&t[1])<<8|(255&t[2])<<16|(255&t[3])<<24,y=255&t[4]|(255&t[5])<<8|(255&t[6])<<16|(255&t[7])<<24,l=255&t[8]|(255&t[9])<<8|(255&t[10])<<16|(255&t[11])<<24,v=255&t[12]|(255&t[13])<<8|(255&t[14])<<16|(255&t[15])<<24,w=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,p=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,b=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,g=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,_=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,A=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,U=i,d=h,E=f,x=a,M=s,m=u,B=c,S=y,K=l,Y=v,k=w,T=p,L=b,z=g,R=_,P=A,N=0;N<20;N+=2)o=U+L|0,M^=o<<7|o>>>25,o=M+U|0,K^=o<<9|o>>>23,o=K+M|0,L^=o<<13|o>>>19,o=L+K|0,U^=o<<18|o>>>14,o=m+d|0,Y^=o<<7|o>>>25,o=Y+m|0,z^=o<<9|o>>>23,o=z+Y|0,d^=o<<13|o>>>19,o=d+z|0,m^=o<<18|o>>>14,o=k+B|0,R^=o<<7|o>>>25,o=R+k|0,E^=o<<9|o>>>23,o=E+R|0,B^=o<<13|o>>>19,o=B+E|0,k^=o<<18|o>>>14,o=P+T|0,x^=o<<7|o>>>25,o=x+P|0,S^=o<<9|o>>>23,o=S+x|0,T^=o<<13|o>>>19,o=T+S|0,P^=o<<18|o>>>14,o=U+x|0,d^=o<<7|o>>>25,o=d+U|0,E^=o<<9|o>>>23,o=E+d|0,x^=o<<13|o>>>19,o=x+E|0,U^=o<<18|o>>>14,o=m+M|0,B^=o<<7|o>>>25,o=B+m|0,S^=o<<9|o>>>23,o=S+B|0,M^=o<<13|o>>>19,o=M+S|0,m^=o<<18|o>>>14,o=k+Y|0,T^=o<<7|o>>>25,o=T+k|0,K^=o<<9|o>>>23,o=K+T|0,Y^=o<<13|o>>>19,o=Y+K|0,k^=o<<18|o>>>14,o=P+R|0,L^=o<<7|o>>>25,o=L+P|0,z^=o<<9|o>>>23,o=z+L|0,R^=o<<13|o>>>19,o=R+z|0,P^=o<<18|o>>>14;r[0]=U>>>0&255,r[1]=U>>>8&255,r[2]=U>>>16&255,r[3]=U>>>24&255,r[4]=m>>>0&255,r[5]=m>>>8&255,r[6]=m>>>16&255,r[7]=m>>>24&255,r[8]=k>>>0&255,r[9]=k>>>8&255,r[10]=k>>>16&255,r[11]=k>>>24&255,r[12]=P>>>0&255,r[13]=P>>>8&255,r[14]=P>>>16&255,r[15]=P>>>24&255,r[16]=B>>>0&255,r[17]=B>>>8&255,r[18]=B>>>16&255,r[19]=B>>>24&255,r[20]=S>>>0&255,r[21]=S>>>8&255,r[22]=S>>>16&255,r[23]=S>>>24&255,r[24]=K>>>0&255,r[25]=K>>>8&255,r[26]=K>>>16&255,r[27]=K>>>24&255,r[28]=Y>>>0&255,r[29]=Y>>>8&255,r[30]=Y>>>16&255,r[31]=Y>>>24&255}function s(r,t,n,e){f(r,t,n,e)}function u(r,t,n,e){a(r,t,n,e)}function c(r,t,n,e,o,i,h){var f,a,u=new Uint8Array(16),c=new Uint8Array(64);for(a=0;a<16;a++)u[a]=0;for(a=0;a<8;a++)u[a]=i[a];for(;o>=64;){for(s(c,u,h,yr),a=0;a<64;a++)r[t+a]=n[e+a]^c[a];for(f=1,a=8;a<16;a++)f=f+(255&u[a])|0,u[a]=255&f,f>>>=8;o-=64,t+=64,e+=64}if(o>0)for(s(c,u,h,yr),a=0;a=64;){for(s(a,f,o,yr),h=0;h<64;h++)r[t+h]=a[h];for(i=1,h=8;h<16;h++)i=i+(255&f[h])|0,f[h]=255&i,i>>>=8;n-=64,t+=64}if(n>0)for(s(a,f,o,yr),h=0;h>16&1),h[e-1]&=65535;h[15]=f[15]-32767-(h[14]>>16&1),i=h[15]>>16&1,h[14]&=65535,U(f,h,1-i)}for(e=0;e<16;e++)r[2*e]=255&f[e],r[2*e+1]=f[e]>>8}function E(r,t){var n=new Uint8Array(32),e=new Uint8Array(32);return d(n,r),d(e,t),h(n,0,e,0)}function x(r){var t=new Uint8Array(32);return d(t,r),1&t[0]}function M(r,t){var n;for(n=0;n<16;n++)r[n]=t[2*n]+(t[2*n+1]<<8);r[15]&=32767}function m(r,t,n){for(var e=0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e*V,S+=e*X,K+=e*D,Y+=e*F,k+=e*j,T+=e*H,L+=e*J,z+=e*Q,e=t[15],A+=e*P,U+=e*N,d+=e*O,E+=e*C,x+=e*I,M+=e*G,m+=e*Z,B+=e*q,S+=e*V,K+=e*X,Y+=e*D,k+=e*F,T+=e*j,L+=e*H,z+=e*J,R+=e*Q,i+=38*U,h+=38*d,f+=38*E,a+=38*x,s+=38*M,u+=38*m,c+=38*B,y+=38*S,l+=38*K,v+=38*Y,w+=38*k,p+=38*T,b+=38*L,g+=38*z,_+=38*R,o=1,e=i+o+65535,o=Math.floor(e/65536),i=e-65536*o,e=h+o+65535,o=Math.floor(e/65536),h=e-65536*o,e=f+o+65535,o=Math.floor(e/65536),f=e-65536*o,e=a+o+65535,o=Math.floor(e/65536),a=e-65536*o,e=s+o+65535,o=Math.floor(e/65536),s=e-65536*o,e=u+o+65535,o=Math.floor(e/65536),u=e-65536*o,e=c+o+65535,o=Math.floor(e/65536),c=e-65536*o,e=y+o+65535,o=Math.floor(e/65536),y=e-65536*o,e=l+o+65535,o=Math.floor(e/65536),l=e-65536*o,e=v+o+65535,o=Math.floor(e/65536),v=e-65536*o,e=w+o+65535,o=Math.floor(e/65536),w=e-65536*o,e=p+o+65535,o=Math.floor(e/65536),p=e-65536*o,e=b+o+65535,o=Math.floor(e/65536),b=e-65536*o,e=g+o+65535,o=Math.floor(e/65536),g=e-65536*o,e=_+o+65535,o=Math.floor(e/65536),_=e-65536*o,e=A+o+65535,o=Math.floor(e/65536),A=e-65536*o,i+=o-1+37*(o-1),o=1,e=i+o+65535,o=Math.floor(e/65536),i=e-65536*o,e=h+o+65535,o=Math.floor(e/65536),h=e-65536*o,e=f+o+65535,o=Math.floor(e/65536),f=e-65536*o,e=a+o+65535,o=Math.floor(e/65536),a=e-65536*o,e=s+o+65535,o=Math.floor(e/65536),s=e-65536*o,e=u+o+65535,o=Math.floor(e/65536),u=e-65536*o,e=c+o+65535,o=Math.floor(e/65536),c=e-65536*o,e=y+o+65535,o=Math.floor(e/65536),y=e-65536*o,e=l+o+65535,o=Math.floor(e/65536),l=e-65536*o,e=v+o+65535,o=Math.floor(e/65536),v=e-65536*o,e=w+o+65535,o=Math.floor(e/65536),w=e-65536*o,e=p+o+65535,o=Math.floor(e/65536),p=e-65536*o,e=b+o+65535,o=Math.floor(e/65536),b=e-65536*o,e=g+o+65535,o=Math.floor(e/65536),g=e-65536*o,e=_+o+65535,o=Math.floor(e/65536),_=e-65536*o,e=A+o+65535,o=Math.floor(e/65536),A=e-65536*o,i+=o-1+37*(o-1),r[0]=i,r[1]=h,r[2]=f,r[3]=a,r[4]=s,r[5]=u,r[6]=c,r[7]=y,r[8]=l,r[9]=v,r[10]=w,r[11]=p,r[12]=b,r[13]=g;r[14]=_;r[15]=A}function K(r,t){S(r,t,t)}function Y(r,n){var e,o=t();for(e=0;e<16;e++)o[e]=n[e];for(e=253;e>=0;e--)K(o,o),2!==e&&4!==e&&S(o,o,n);for(e=0;e<16;e++)r[e]=o[e]}function k(r,n){var e,o=t();for(e=0;e<16;e++)o[e]=n[e];for(e=250;e>=0;e--)K(o,o),1!==e&&S(o,o,n);for(e=0;e<16;e++)r[e]=o[e]}function T(r,n,e){var o,i,h=new Uint8Array(32),f=[],a=t(),s=t(),u=t(),c=t(),y=t(),l=t();for(i=0;i<31;i++)h[i]=n[i];for(h[31]=127&n[31]|64,h[0]&=248,M(f,e),i=0;i<16;i++)s[i]=f[i],c[i]=a[i]=u[i]=0;for(a[0]=c[0]=1,i=254;i>=0;--i)o=h[i>>>3]>>>(7&i)&1,U(a,s,o),U(u,c,o),m(y,a,u),B(a,a,u),m(u,s,c),B(s,s,c),K(c,y),K(l,a),S(a,u,a),S(u,s,y),m(y,a,u),B(a,a,u),K(s,a),B(u,c,l),S(a,u,hr),m(a,a,c),S(u,u,a),S(a,c,l),S(c,s,f),K(s,y),U(a,s,o),U(u,c,o);var v=[];for(i=0;i<16;i++)v[i]=u[i],v[i+16]=s[i],v[i+32]=c[i];var w=[];for(i=0;i<16;i++)w[i]=a[i],w[i+16]=u[i],w[i+32]=s[i],w[i+48]=c[i];return Y(v,v),S(w,w,v),d(r,w),0}function L(r,t){return T(r,t,er)}function z(r,t){return tr(t,32),L(r,t)}function R(r,t,n){var e=new Uint8Array(32);return T(e,n,t),u(r,nr,e,yr)}function P(r,t,n,e,o,i){var h=new Uint8Array(32);return R(h,o,i),vr(r,t,n,e,h)}function N(r,t,n,e,o,i){var h=new Uint8Array(32);return R(h,o,i),wr(r,t,n,e,h)}function O(r,t,n,e){for(var o,i,h,f,a,s,u,c,y,l,v,w,p,b,g,_,A,U,d,E,x,M,m,B,S,K,Y=new Int32Array(16),k=new Int32Array(16),T=r[0],L=r[1],z=r[2],R=r[3],P=r[4],N=r[5],O=r[6],C=r[7],I=t[0],G=t[1],Z=t[2],q=t[3],V=t[4],X=t[5],D=t[6],F=t[7],j=0;e>=128;){for(d=0;d<16;d++)E=8*d+j,Y[d]=n[E+0]<<24|n[E+1]<<16|n[E+2]<<8|n[E+3],k[d]=n[E+4]<<24|n[E+5]<<16|n[E+6]<<8|n[E+7];for(d=0;d<80;d++)if(o=T,i=L,h=z,f=R,a=P,s=N,u=O,c=C,y=I,l=G,v=Z,w=q,p=V,b=X,g=D,_=F,x=C,M=F,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=(P>>>14|V<<18)^(P>>>18|V<<14)^(V>>>9|P<<23),M=(V>>>14|P<<18)^(V>>>18|P<<14)^(P>>>9|V<<23),m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,x=P&N^~P&O,M=V&X^~V&D,m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,x=pr[2*d],M=pr[2*d+1],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,x=Y[d%16],M=k[d%16],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,A=65535&S|K<<16,U=65535&m|B<<16,x=A,M=U,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=(T>>>28|I<<4)^(I>>>2|T<<30)^(I>>>7|T<<25),M=(I>>>28|T<<4)^(T>>>2|I<<30)^(T>>>7|I<<25),m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,x=T&L^T&z^L&z,M=I&G^I&Z^G&Z,m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,c=65535&S|K<<16,_=65535&m|B<<16,x=f,M=w,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=A,M=U,m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,f=65535&S|K<<16,w=65535&m|B<<16,L=o,z=i,R=h,P=f,N=a,O=s,C=u,T=c,G=y,Z=l,q=v,V=w,X=p,D=b,F=g,I=_,d%16===15)for(E=0;E<16;E++)x=Y[E],M=k[E],m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=Y[(E+9)%16],M=k[(E+9)%16],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,A=Y[(E+1)%16],U=k[(E+1)%16],x=(A>>>1|U<<31)^(A>>>8|U<<24)^A>>>7,M=(U>>>1|A<<31)^(U>>>8|A<<24)^(U>>>7|A<<25),m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,A=Y[(E+14)%16],U=k[(E+14)%16],x=(A>>>19|U<<13)^(U>>>29|A<<3)^A>>>6,M=(U>>>19|A<<13)^(A>>>29|U<<3)^(U>>>6|A<<26),m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,Y[E]=65535&S|K<<16,k[E]=65535&m|B<<16;x=T,M=I,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=r[0],M=t[0],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,r[0]=T=65535&S|K<<16,t[0]=I=65535&m|B<<16,x=L,M=G,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=r[1],M=t[1],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,r[1]=L=65535&S|K<<16,t[1]=G=65535&m|B<<16,x=z,M=Z,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=r[2],M=t[2],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,r[2]=z=65535&S|K<<16,t[2]=Z=65535&m|B<<16,x=R,M=q,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=r[3],M=t[3],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,r[3]=R=65535&S|K<<16,t[3]=q=65535&m|B<<16,x=P,M=V,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=r[4],M=t[4],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,r[4]=P=65535&S|K<<16,t[4]=V=65535&m|B<<16,x=N,M=X,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=r[5],M=t[5],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,r[5]=N=65535&S|K<<16,t[5]=X=65535&m|B<<16,x=O,M=D,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=r[6],M=t[6],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,r[6]=O=65535&S|K<<16,t[6]=D=65535&m|B<<16,x=C,M=F,m=65535&M,B=M>>>16,S=65535&x,K=x>>>16,x=r[7],M=t[7],m+=65535&M,B+=M>>>16,S+=65535&x,K+=x>>>16,B+=m>>>16,S+=B>>>16,K+=S>>>16,r[7]=C=65535&S|K<<16,t[7]=F=65535&m|B<<16,j+=128,e-=128}return e}function C(r,t,n){var o,i=new Int32Array(8),h=new Int32Array(8),f=new Uint8Array(256),a=n;for(i[0]=1779033703,i[1]=3144134277,i[2]=1013904242,i[3]=2773480762,i[4]=1359893119,i[5]=2600822924,i[6]=528734635,i[7]=1541459225,h[0]=4089235720,h[1]=2227873595,h[2]=4271175723,h[3]=1595750129,h[4]=2917565137,h[5]=725511199,h[6]=4215389547,h[7]=327033209,O(i,h,t,n),n%=128,o=0;o=0;--o)e=n[o/8|0]>>(7&o)&1,G(r,t,e),I(t,r),I(r,r),G(r,t,e)}function V(r,n){var e=[t(),t(),t(),t()];_(e[0],sr),_(e[1],ur),_(e[2],ir),S(e[3],sr,ur),q(r,e,n)}function X(r,n,e){var o,i=new Uint8Array(64),h=[t(),t(),t(),t()];for(e||tr(n,32),C(i,n,32),i[0]&=248,i[31]&=127,i[31]|=64,V(h,i),Z(r,h),o=0;o<32;o++)n[o+32]=r[o];return 0}function D(r,t){var n,e,o,i;for(e=63;e>=32;--e){for(n=0,o=e-32,i=e-12;o>8,t[o]-=256*n;t[o]+=n,t[e]=0}for(n=0,o=0;o<32;o++)t[o]+=n-(t[31]>>4)*br[o],n=t[o]>>8,t[o]&=255;for(o=0;o<32;o++)t[o]-=n*br[o];for(e=0;e<32;e++)t[e+1]+=t[e]>>8,r[e]=255&t[e]}function F(r){var t,n=[];for(t=0;t<64;t++)n[t]=r[t];for(t=0;t<64;t++)r[t]=0;D(r,n)}function j(r,n,e,o){var i,h,f=new Uint8Array(64),a=new Uint8Array(64),s=new Uint8Array(64),u=[],c=[t(),t(),t(),t()];C(f,o,32),f[0]&=248,f[31]&=127,f[31]|=64;var y=e+64;for(i=0;i>7&&B(r[0],or,r[0]),S(r[3],r[0],r[1]),0)}function J(r,n,e,o){var i,f,a=new Uint8Array(32),s=new Uint8Array(64),u=[t(),t(),t(),t()],c=[t(),t(),t(),t()];if(f=-1,e<64)return-1;if(H(c,o))return-1;for(i=0;i>>13|n<<3),e=255&r[4]|(255&r[5])<<8,this.r[2]=7939&(n>>>10|e<<6),o=255&r[6]|(255&r[7])<<8,this.r[3]=8191&(e>>>7|o<<9),i=255&r[8]|(255&r[9])<<8,this.r[4]=255&(o>>>4|i<<12),this.r[5]=i>>>1&8190,h=255&r[10]|(255&r[11])<<8,this.r[6]=8191&(i>>>14|h<<2),f=255&r[12]|(255&r[13])<<8,this.r[7]=8065&(h>>>11|f<<5),a=255&r[14]|(255&r[15])<<8,this.r[8]=8191&(f>>>8|a<<8),this.r[9]=a>>>5&127,this.pad[0]=255&r[16]|(255&r[17])<<8,this.pad[1]=255&r[18]|(255&r[19])<<8,this.pad[2]=255&r[20]|(255&r[21])<<8,this.pad[3]=255&r[22]|(255&r[23])<<8,this.pad[4]=255&r[24]|(255&r[25])<<8,this.pad[5]=255&r[26]|(255&r[27])<<8,this.pad[6]=255&r[28]|(255&r[29])<<8,this.pad[7]=255&r[30]|(255&r[31])<<8};lr.prototype.blocks=function(r,t,n){for(var e,o,i,h,f,a,s,u,c,y,l,v,w,p,b,g,_,A,U,d=this.fin?0:2048,E=this.h[0],x=this.h[1],M=this.h[2],m=this.h[3],B=this.h[4],S=this.h[5],K=this.h[6],Y=this.h[7],k=this.h[8],T=this.h[9],L=this.r[0],z=this.r[1],R=this.r[2],P=this.r[3],N=this.r[4],O=this.r[5],C=this.r[6],I=this.r[7],G=this.r[8],Z=this.r[9];n>=16;)e=255&r[t+0]|(255&r[t+1])<<8,E+=8191&e,o=255&r[t+2]|(255&r[t+3])<<8,x+=8191&(e>>>13|o<<3),i=255&r[t+4]|(255&r[t+5])<<8,M+=8191&(o>>>10|i<<6),h=255&r[t+6]|(255&r[t+7])<<8,m+=8191&(i>>>7|h<<9),f=255&r[t+8]|(255&r[t+9])<<8,B+=8191&(h>>>4|f<<12),S+=f>>>1&8191,a=255&r[t+10]|(255&r[t+11])<<8,K+=8191&(f>>>14|a<<2),s=255&r[t+12]|(255&r[t+13])<<8,Y+=8191&(a>>>11|s<<5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_&=8191,A=c,A+=E*G,A+=x*I,A+=M*C,A+=m*O,A+=B*N,c=A>>>13,A&=8191,A+=S*P,A+=K*R,A+=Y*z,A+=k*L,A+=T*(5*Z),c+=A>>>13,A&=8191,U=c,U+=E*Z,U+=x*G,U+=M*I,U+=m*C,U+=B*O,c=U>>>13,U&=8191,U+=S*N,U+=K*P,U+=Y*R,U+=k*z,U+=T*L,c+=U>>>13,U&=8191,c=(c<<2)+c|0,c=c+y|0,y=8191&c,c>>>=13,l+=c,E=y,x=l,M=v,m=w,B=p,S=b,K=g,Y=_,k=A,T=U,t+=16,n-=16;this.h[0]=E,this.h[1]=x,this.h[2]=M,this.h[3]=m,this.h[4]=B,this.h[5]=S,this.h[6]=K,this.h[7]=Y,this.h[8]=k,this.h[9]=T},lr.prototype.finish=function(r,t){var n,e,o,i,h=new Uint16Array(10);if(this.leftover){for(i=this.leftover,this.buffer[i++]=1;i<16;i++)this.buffer[i]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(n=this.h[1]>>>13,this.h[1]&=8191,i=2;i<10;i++)this.h[i]+=n,n=this.h[i]>>>13,this.h[i]&=8191;for(this.h[0]+=5*n,n=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=n,n=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=n,h[0]=this.h[0]+5,n=h[0]>>>13,h[0]&=8191,i=1;i<10;i++)h[i]=this.h[i]+n,n=h[i]>>>13,h[i]&=8191;for(h[9]-=8192,e=(1^n)-1,i=0;i<10;i++)h[i]&=e;for(e=~e,i=0;i<10;i++)this.h[i]=this.h[i]&e|h[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;i<8;i++)o=(this.h[i]+this.pad[i]|0)+(o>>>16)|0,this.h[i]=65535&o;r[t+0]=this.h[0]>>>0&255,r[t+1]=this.h[0]>>>8&255,r[t+2]=this.h[1]>>>0&255,r[t+3]=this.h[1]>>>8&255,r[t+4]=this.h[2]>>>0&255,r[t+5]=this.h[2]>>>8&255,r[t+6]=this.h[3]>>>0&255,r[t+7]=this.h[3]>>>8&255,r[t+8]=this.h[4]>>>0&255,r[t+9]=this.h[4]>>>8&255,r[t+10]=this.h[5]>>>0&255,r[t+11]=this.h[5]>>>8&255,r[t+12]=this.h[6]>>>0&255,r[t+13]=this.h[6]>>>8&255,r[t+14]=this.h[7]>>>0&255,r[t+15]=this.h[7]>>>8&255},lr.prototype.update=function(r,t,n){var e,o;if(this.leftover){for(o=16-this.leftover,o>n&&(o=n),e=0;e=16&&(o=n-n%16,this.blocks(r,t,o),t+=o,n-=o),n){for(e=0;e=0},r.sign.keyPair=function(){var r=new Uint8Array(kr),t=new Uint8Array(Tr);return X(r,t),{publicKey:r,secretKey:t}},r.sign.keyPair.fromSecretKey=function(r){if($(r),r.length!==Tr)throw new Error("bad secret key size");for(var t=new Uint8Array(kr),n=0;n Date: Sat, 11 Nov 2017 01:52:54 +0100 Subject: [PATCH 2/2] README: update benchmarks --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0f4373ba..31eabe59 100644 --- a/README.md +++ b/README.md @@ -430,28 +430,28 @@ Benchmarks ---------- For reference, here are benchmarks from MacBook Pro (Retina, 13-inch, Mid 2014) -laptop with 2.6 GHz Intel Core i5 CPU (Intel) in Chrome 53/OS X and Xiaomi Redmi +laptop with 2.6 GHz Intel Core i5 CPU (Intel) in Chrome 62/OS X and Xiaomi Redmi Note 3 smartphone with 1.8 GHz Qualcomm Snapdragon 650 64-bit CPU (ARM) in -Chrome 52/Android: +Chrome 62/Android: | | nacl.js Intel | nacl-fast.js Intel | nacl.js ARM | nacl-fast.js ARM | | ------------- |:-------------:|:-------------------:|:-------------:|:-----------------:| -| salsa20 | 1.3 MB/s | 128 MB/s | 0.4 MB/s | 43 MB/s | -| poly1305 | 13 MB/s | 171 MB/s | 4 MB/s | 52 MB/s | +| salsa20 | 13 MB/s | 128 MB/s | 4.4 MB/s | 43 MB/s | +| poly1305 | 10 MB/s | 195 MB/s | 2 MB/s | 76 MB/s | | hash | 4 MB/s | 34 MB/s | 0.9 MB/s | 12 MB/s | -| secretbox 1K | 1113 op/s | 57583 op/s | 334 op/s | 14227 op/s | -| box 1K | 145 op/s | 718 op/s | 37 op/s | 368 op/s | -| scalarMult | 171 op/s | 733 op/s | 56 op/s | 380 op/s | -| sign | 77 op/s | 200 op/s | 20 op/s | 61 op/s | -| sign.open | 39 op/s | 102 op/s | 11 op/s | 31 op/s | +| secretbox 1K | 5704 op/s | 79980 op/s | 334 op/s | 32949 op/s | +| box 1K | 148 op/s | 1039 op/s | 37 op/s | 576 op/s | +| scalarMult | 171 op/s | 1011 op/s | 56 op/s | 450 op/s | +| sign | 77 op/s | 498 op/s | 22 op/s | 218 op/s | +| sign.open | 39 op/s | 257 op/s | 12 op/s | 130 op/s | (You can run benchmarks on your devices by clicking on the links at the bottom of the [home page](https://tweetnacl.js.org)). In short, with *nacl-fast.js* and 1024-byte messages you can expect to encrypt and -authenticate more than 57000 messages per second on a typical laptop or more than -14000 messages per second on a $170 smartphone, sign about 200 and verify 100 -messages per second on a laptop or 60 and 30 messages per second on a smartphone, +authenticate more than 75000 messages per second on a typical laptop or more than +32000 messages per second on a $170 smartphone, sign about 500 and verify 250 +messages per second on a laptop or 220 and 130 messages per second on a smartphone, per CPU core (with Web Workers you can do these operations in parallel), which is good enough for most applications.