scrypt-async.min.js
/*!
* Fast "async" scrypt implementation in JavaScript.
* Copyright (c) 2013-2015 Dmitry Chestnykh | BSD License
* https://github.com/dchest/scrypt-async-js
*/
function scrypt(a,b,c,d,e,f,g,h){"use strict";function i(a){function b(a){for(var b=0,m=a.length;m>=64;){var n,o,p,q,r,s=d,t=e,u=f,v=g,w=h,x=i,y=j,z=k;for(o=0;16>o;o++)p=b+4*o,l[o]=(255&a[p])<<24|(255&a[p+1])<<16|(255&a[p+2])<<8|255&a[p+3];for(o=16;64>o;o++)n=l[o-2],q=(n>>>17|n<<15)^(n>>>19|n<<13)^n>>>10,n=l[o-15],r=(n>>>7|n<<25)^(n>>>18|n<<14)^n>>>3,l[o]=(q+l[o-7]|0)+(r+l[o-16]|0)|0;for(o=0;64>o;o++)q=(((w>>>6|w<<26)^(w>>>11|w<<21)^(w>>>25|w<<7))+(w&x^~w&y)|0)+(z+(c[o]+l[o]|0)|0)|0,r=((s>>>2|s<<30)^(s>>>13|s<<19)^(s>>>22|s<<10))+(s&t^s&u^t&u)|0,z=y,y=x,x=w,w=v+q|0,v=u,u=t,t=s,s=q+r|0;d=d+s|0,e=e+t|0,f=f+u|0,g=g+v|0,h=h+w|0,i=i+x|0,j=j+y|0,k=k+z|0,b+=64,m-=64}}var c=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],d=1779033703,e=3144134277,f=1013904242,g=2773480762,h=1359893119,i=2600822924,j=528734635,k=1541459225,l=new Array(64);b(a);var m,n=a.length%64,o=a.length/536870912|0,p=a.length<<3,q=56>n?56:120,r=a.slice(a.length-n,a.length);for(r.push(128),m=n+1;q>m;m++)r.push(0);return r.push(o>>>24&255),r.push(o>>>16&255),r.push(o>>>8&255),r.push(o>>>0&255),r.push(p>>>24&255),r.push(p>>>16&255),r.push(p>>>8&255),r.push(p>>>0&255),b(r),[d>>>24&255,d>>>16&255,d>>>8&255,d>>>0&255,e>>>24&255,e>>>16&255,e>>>8&255,e>>>0&255,f>>>24&255,f>>>16&255,f>>>8&255,f>>>0&255,g>>>24&255,g>>>16&255,g>>>8&255,g>>>0&255,h>>>24&255,h>>>16&255,h>>>8&255,h>>>0&255,i>>>24&255,i>>>16&255,i>>>8&255,i>>>0&255,j>>>24&255,j>>>16&255,j>>>8&255,j>>>0&255,k>>>24&255,k>>>16&255,k>>>8&255,k>>>0&255]}function j(a,b,c){function d(){for(var a=f-1;a>=f-4;a--){if(g[a]++,g[a]<=255)return;g[a]=0}}a=a.length<=64?a:i(a);var e,f=64+b.length+4,g=new Array(f),h=new Array(64),j=[];for(e=0;64>e;e++)g[e]=54;for(e=0;e<a.length;e++)g[e]^=a[e];for(e=0;e<b.length;e++)g[64+e]=b[e];for(e=f-4;f>e;e++)g[e]=0;for(e=0;64>e;e++)h[e]=92;for(e=0;e<a.length;e++)h[e]^=a[e];for(;c>=32;)d(),j=j.concat(i(h.concat(i(g)))),c-=32;return c>0&&(d(),j=j.concat(i(h.concat(i(g))).slice(0,c))),j}function k(a,b,c,d){var e,f,g=a[0]^b[c++],h=a[1]^b[c++],i=a[2]^b[c++],j=a[3]^b[c++],k=a[4]^b[c++],l=a[5]^b[c++],m=a[6]^b[c++],n=a[7]^b[c++],o=a[8]^b[c++],p=a[9]^b[c++],q=a[10]^b[c++],r=a[11]^b[c++],s=a[12]^b[c++],t=a[13]^b[c++],u=a[14]^b[c++],v=a[15]^b[c++],w=g,x=h,y=i,z=j,A=k,B=l,C=m,D=n,E=o,F=p,G=q,H=r,I=s,J=t,K=u,L=v;for(f=0;8>f;f+=2)e=w+I,A^=e<<7|e>>>25,e=A+w,E^=e<<9|e>>>23,e=E+A,I^=e<<13|e>>>19,e=I+E,w^=e<<18|e>>>14,e=B+x,F^=e<<7|e>>>25,e=F+B,J^=e<<9|e>>>23,e=J+F,x^=e<<13|e>>>19,e=x+J,B^=e<<18|e>>>14,e=G+C,K^=e<<7|e>>>25,e=K+G,y^=e<<9|e>>>23,e=y+K,C^=e<<13|e>>>19,e=C+y,G^=e<<18|e>>>14,e=L+H,z^=e<<7|e>>>25,e=z+L,D^=e<<9|e>>>23,e=D+z,H^=e<<13|e>>>19,e=H+D,L^=e<<18|e>>>14,e=w+z,x^=e<<7|e>>>25,e=x+w,y^=e<<9|e>>>23,e=y+x,z^=e<<13|e>>>19,e=z+y,w^=e<<18|e>>>14,e=B+A,C^=e<<7|e>>>25,e=C+B,D^=e<<9|e>>>23,e=D+C,A^=e<<13|e>>>19,e=A+D,B^=e<<18|e>>>14,e=G+F,H^=e<<7|e>>>25,e=H+G,E^=e<<9|e>>>23,e=E+H,F^=e<<13|e>>>19,e=F+E,G^=e<<18|e>>>14,e=L+K,I^=e<<7|e>>>25,e=I+L,J^=e<<9|e>>>23,e=J+I,K^=e<<13|e>>>19,e=K+J,L^=e<<18|e>>>14;b[d++]=a[0]=w+g|0,b[d++]=a[1]=x+h|0,b[d++]=a[2]=y+i|0,b[d++]=a[3]=z+j|0,b[d++]=a[4]=A+k|0,b[d++]=a[5]=B+l|0,b[d++]=a[6]=C+m|0,b[d++]=a[7]=D+n|0,b[d++]=a[8]=E+o|0,b[d++]=a[9]=F+p|0,b[d++]=a[10]=G+q|0,b[d++]=a[11]=H+r|0,b[d++]=a[12]=I+s|0,b[d++]=a[13]=J+t|0,b[d++]=a[14]=K+u|0,b[d++]=a[15]=L+v|0}function l(a,b,c,d,e){for(;e--;)a[b++]=c[d++]}function m(a,b,c,d,e){for(;e--;)a[b++]^=c[d++]}function n(a,b,c,d,e){l(a,0,b,c+16*(2*e-1),16);for(var f=0;2*e>f;f+=2)k(a,b,c+16*f,d+8*f),k(a,b,c+16*f+16,d+8*f+16*e)}function o(a,b,c){return a[b+16*(2*c-1)]}function p(a){for(var b=[],c=0;c<a.length;c++){var d=a.charCodeAt(c);128>d?b.push(d):d>127&&2048>d?(b.push(d>>6|192),b.push(63&d|128)):(b.push(d>>12|224),b.push(d>>6&63|128),b.push(63&d|128))}return b}function q(a){for(var b="0123456789abcdef".split(""),c=a.length,d=[],e=0;c>e;e++)d.push(b[a[e]>>>4&15]),d.push(b[a[e]>>>0&15]);return d.join("")}function r(a){for(var b,c,d,e,f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),g=a.length,h=[],i=0;g>i;)b=g>i?a[i++]:0,c=g>i?a[i++]:0,d=g>i?a[i++]:0,e=(b<<16)+(c<<8)+d,h.push(f[e>>>18&63]),h.push(f[e>>>12&63]),h.push(f[e>>>6&63]),h.push(f[e>>>0&63]);return g%3>0&&(h[h.length-1]="=",g%3===1&&(h[h.length-2]="=")),h.join("")}function s(){for(var a=0;32*d>a;a++){var b=4*a;z[F+a]=(255&B[b+3])<<24|(255&B[b+2])<<16|(255&B[b+1])<<8|(255&B[b+0])<<0}}function t(a,b){for(var c=a;b>c;c+=2)l(A,32*c*d,z,F,32*d),n(C,z,F,G,d),l(A,32*(c+1)*d,z,G,32*d),n(C,z,G,F,d)}function u(a,b){for(var c=a;b>c;c+=2){var e=o(z,F,d)&E-1;m(z,F,A,32*e*d,32*d),n(C,z,F,G,d),e=o(z,G,d)&E-1,m(z,G,A,32*e*d,32*d),n(C,z,G,F,d)}}function v(){for(var a=0;32*d>a;a++){var b=z[F+a];B[4*a+0]=b>>>0&255,B[4*a+1]=b>>>8&255,B[4*a+2]=b>>>16&255,B[4*a+3]=b>>>24&255}}function w(a,b,c,d,e){!function f(){H(function(){d(a,b>a+c?a+c:b),a+=c,b>a?f():e()})}()}function x(b){var c=j(a,B,e);return"base64"===b?r(c):"hex"===b?q(c):c}var y=1;if(1>c||c>31)throw new Error("scrypt: logN not be between 1 and 31");var z,A,B,C,D=1<<31>>>0,E=1<<c>>>0;if(d*y>=1<<30||d>D/128/y||d>D/256||E>D/128/d)throw new Error("scrypt: parameters are too large");"string"==typeof a&&(a=p(a)),"string"==typeof b&&(b=p(b)),"undefined"!=typeof Int32Array?(z=new Int32Array(64*d),A=new Int32Array(32*E*d),C=new Int32Array(16)):(z=[],A=[],C=new Array(16)),B=j(a,b,128*y*d);var F=0,G=32*d,H="undefined"!=typeof setImmediate?setImmediate:setTimeout;"function"==typeof f&&(h=g,g=f,f=1e3),0>=f?(s(),t(0,E),u(0,E),v(),g(x(h))):(s(),w(0,E,2*f,t,function(){w(0,E,2*f,u,function(){v(),g(x(h))})}))}"undefined"!=typeof module&&(module.exports=scrypt);