diff --git a/package.json b/package.json index 8725e76..9478779 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scrypt-async", - "version": "1.3.1", + "version": "2.0.0", "description": "Fast \"async\" scrypt implementation in JavaScript.", "main": "scrypt-async.js", "scripts": { diff --git a/scrypt-async.min.js b/scrypt-async.min.js index dda82a1..d063d98 100644 --- a/scrypt-async.min.js +++ b/scrypt-async.min.js @@ -3,4 +3,4 @@ * Copyright (c) 2013-2016 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;o<16;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;o<64;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;o<64;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=n<56?56:120,r=a.slice(a.length-n,a.length);for(r.push(128),m=n+1;m>>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;e<64;e++)g[e]=54;for(e=0;e=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[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=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;f<2*e;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;c127&&d<2048?(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;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;i>>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(a){for(var b=0;b<32*d;b++){var c=a+4*b;D[I+b]=(255&F[c+3])<<24|(255&F[c+2])<<16|(255&F[c+1])<<8|(255&F[c+0])<<0}}function t(a,b){for(var c=a;c>>0&255,F[a+4*b+1]=c>>>8&255,F[a+4*b+2]=c>>>16&255,F[a+4*b+3]=c>>>24&255}}function w(a,b,c,d,e){!function f(){K(function(){d(a,a+c>>0,B=1;if("object"==typeof c){if(arguments.length>4)throw new Error("scrypt: incorrect number of arguments");var C=c;if(g=d,c=C.logN,"undefined"==typeof c){if("undefined"==typeof C.N)throw new Error("scrypt: missing N parameter");if(C.N<2||C.N>A)throw new Error("scrypt: N is out of range");if(0!==(C.N&C.N-1))throw new Error("scrypt: N is not a power of 2");c=Math.log(C.N)/Math.LN2}B=C.p||1,d=C.r,e=C.dkLen||32,f=C.interruptStep||0,h=C.encoding}if(B<1)throw new Error("scrypt: invalid p");if(d<=0)throw new Error("scrypt: invalid r");if(c<1||c>31)throw new Error("scrypt: logN must be between 1 and 31");var D,E,F,G,H=1<>>0;if(d*B>=1<<30||d>A/128/B||d>A/256||H>A/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?(D=new Int32Array(64*d),E=new Int32Array(32*H*d),G=new Int32Array(16)):(D=[],E=[],G=new Array(16)),F=j(a,b,128*B*d);var I=0,J=32*d,K="undefined"!=typeof setImmediate?setImmediate:setTimeout;"function"==typeof f&&(h=g,g=f,f=1e3),f<=0?y():z(0)}"undefined"!=typeof module&&(module.exports=scrypt); \ No newline at end of file +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;o<16;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;o<64;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;o<64;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=n<56?56:120,r=a.slice(a.length-n,a.length);for(r.push(128),m=n+1;m>>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;e<64;e++)g[e]=54;for(e=0;e=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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(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;f<2*e;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>6),b.push(128|63&d);else if(d<55296)b.push(224|d>>12),b.push(128|d>>6&63),b.push(128|63&d);else{if(c>=a.length-1)throw new Error("invalid string");c++,d=(1023&d)<<10,d|=1023&a.charCodeAt(c),d+=65536,b.push(240|d>>18),b.push(128|d>>12&63),b.push(128|d>>6&63),b.push(128|63&d)}}return b}function q(a){for(var b="0123456789abcdef".split(""),c=a.length,d=[],e=0;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;i>>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(a){for(var b=0;b<32*d;b++){var c=a+4*b;D[I+b]=(255&F[c+3])<<24|(255&F[c+2])<<16|(255&F[c+1])<<8|(255&F[c+0])<<0}}function t(a,b){for(var c=a;c>>0&255,F[a+4*b+1]=c>>>8&255,F[a+4*b+2]=c>>>16&255,F[a+4*b+3]=c>>>24&255}}function w(a,b,c,d,e){!function f(){K(function(){d(a,a+c>>0,B=1;if("object"==typeof c){if(arguments.length>4)throw new Error("scrypt: incorrect number of arguments");var C=c;if(g=d,c=C.logN,"undefined"==typeof c){if("undefined"==typeof C.N)throw new Error("scrypt: missing N parameter");if(C.N<2||C.N>A)throw new Error("scrypt: N is out of range");if(0!==(C.N&C.N-1))throw new Error("scrypt: N is not a power of 2");c=Math.log(C.N)/Math.LN2}B=C.p||1,d=C.r,e=C.dkLen||32,f=C.interruptStep||0,h=C.encoding}if(B<1)throw new Error("scrypt: invalid p");if(d<=0)throw new Error("scrypt: invalid r");if(c<1||c>31)throw new Error("scrypt: logN must be between 1 and 31");var D,E,F,G,H=1<>>0;if(d*B>=1<<30||d>A/128/B||d>A/256||H>A/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?(D=new Int32Array(64*d),E=new Int32Array(32*H*d),G=new Int32Array(16)):(D=[],E=[],G=new Array(16)),F=j(a,b,128*B*d);var I=0,J=32*d,K="undefined"!=typeof setImmediate?setImmediate:setTimeout;"function"==typeof f&&(h=g,g=f,f=1e3),f<=0?y():z(0)}"undefined"!=typeof module&&(module.exports=scrypt); \ No newline at end of file