diff --git a/Argon2id.js b/Argon2id.js index 0069c57..7f389a2 100644 --- a/Argon2id.js +++ b/Argon2id.js @@ -1,7 +1,7 @@ /* -Argon2id-JS v1.1.0 +Argon2id-JS v1.1.1 https://github.com/Rabbit-Company/Argon2id-JS -License: GPL-3.0 +License: MIT */ class Argon2id{ diff --git a/Argon2id.min.js b/Argon2id.min.js index c5fc048..c5f6321 100644 --- a/Argon2id.min.js +++ b/Argon2id.min.js @@ -1,12 +1,12 @@ /* -Blake2b-JS v1.0.0 +Blake2b-JS v1.0.1 https://github.com/Rabbit-Company/Blake2b-JS -License: GPL-3.0 +License: MIT */ class Blake2b{v=new Uint32Array(32);m=new Uint32Array(32);BLAKE2B_IV32=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]);SIGMA8=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3];parameterBlock=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);SIGMA82=new Uint8Array(this.SIGMA8.map(function(t){return 2*t}));ADD64AA(t,_,$){let e=t[_]+t[$],i=t[_+1]+t[$+1];e>=4294967296&&i++,t[_]=e,t[_+1]=i}ADD64AC(t,_,$,e){let i=t[_]+$;$<0&&(i+=4294967296);let h=t[_+1]+e;i>=4294967296&&h++,t[_]=i,t[_+1]=h}B2B_GET32(t,_){return t[_]^t[_+1]<<8^t[_+2]<<16^t[_+3]<<24}B2B_G(t,_,$,e,i,h){let s=this.m[i],l=this.m[i+1],r=this.m[h],a=this.m[h+1];this.ADD64AA(this.v,t,_),this.ADD64AC(this.v,t,s,l);let n=this.v[e]^this.v[t],A=this.v[e+1]^this.v[t+1];this.v[e]=A,this.v[e+1]=n,this.ADD64AA(this.v,$,e),n=this.v[_]^this.v[$],A=this.v[_+1]^this.v[$+1],this.v[_]=n>>>24^A<<8,this.v[_+1]=A>>>24^n<<8,this.ADD64AA(this.v,t,_),this.ADD64AC(this.v,t,r,a),n=this.v[e]^this.v[t],A=this.v[e+1]^this.v[t+1],this.v[e]=n>>>16^A<<16,this.v[e+1]=A>>>16^n<<16,this.ADD64AA(this.v,$,e),n=this.v[_]^this.v[$],A=this.v[_+1]^this.v[$+1],this.v[_]=A>>>31^n<<1,this.v[_+1]=n>>>31^A<<1}blake2bCompress(t,_){let $=0;for($=0;$<16;$++)this.v[$]=t.h[$],this.v[$+16]=this.BLAKE2B_IV32[$];for(this.v[24]=this.v[24]^t.t,this.v[25]=this.v[25]^t.t/4294967296,_&&(this.v[28]=~this.v[28],this.v[29]=~this.v[29]),$=0;$<32;$++)this.m[$]=this.B2B_GET32(t.b,4*$);for($=0;$<12;$++)this.B2B_G(0,8,16,24,this.SIGMA82[16*$+0],this.SIGMA82[16*$+1]),this.B2B_G(2,10,18,26,this.SIGMA82[16*$+2],this.SIGMA82[16*$+3]),this.B2B_G(4,12,20,28,this.SIGMA82[16*$+4],this.SIGMA82[16*$+5]),this.B2B_G(6,14,22,30,this.SIGMA82[16*$+6],this.SIGMA82[16*$+7]),this.B2B_G(0,10,20,30,this.SIGMA82[16*$+8],this.SIGMA82[16*$+9]),this.B2B_G(2,12,22,24,this.SIGMA82[16*$+10],this.SIGMA82[16*$+11]),this.B2B_G(4,14,16,26,this.SIGMA82[16*$+12],this.SIGMA82[16*$+13]),this.B2B_G(6,8,18,28,this.SIGMA82[16*$+14],this.SIGMA82[16*$+15]);for($=0;$<16;$++)t.h[$]=t.h[$]^this.v[$]^this.v[$+16]}blake2bInit(t,_,$,e){if(0===t||t>64)throw Error("Illegal output length, expected 0 < length <= 64");if(_&&_.length>64)throw Error("Illegal key, expected Uint8Array with 0 < length <= 64");if($&&16!==$.length)throw Error("Illegal salt, expected Uint8Array with length is 16");if(e&&16!==e.length)throw Error("Illegal personal, expected Uint8Array with length is 16");let i={b:new Uint8Array(128),h:new Uint32Array(16),t:0,c:0,outlen:t};this.parameterBlock.fill(0),this.parameterBlock[0]=t,_&&(this.parameterBlock[1]=_.length),this.parameterBlock[2]=1,this.parameterBlock[3]=1,$&&this.parameterBlock.set($,32),e&&this.parameterBlock.set(e,48);for(let h=0;h<16;h++)i.h[h]=this.BLAKE2B_IV32[h]^this.B2B_GET32(this.parameterBlock,4*h);return _&&(this.blake2bUpdate(i,_),i.c=128),i}blake2bUpdate(t,_){for(let $=0;$<_.length;$++)128===t.c&&(t.t+=t.c,this.blake2bCompress(t,!1),t.c=0),t.b[t.c++]=_[$]}blake2bFinal(t){for(t.t+=t.c;t.c<128;)t.b[t.c++]=0;this.blake2bCompress(t,!0);let _=new Uint8Array(t.outlen);for(let $=0;$>2]>>8*(3&$);return _}blake2bStart(t,_,$,e,i){$=$||64,t=this.normalizeInput(t),e&&(e=this.normalizeInput(e)),i&&(i=this.normalizeInput(i));let h=this.blake2bInit($,_,e,i);return this.blake2bUpdate(h,t),this.blake2bFinal(h)}blake2bHex(t,_,$,e,i){let h=blake2bStart(t,_,$,e,i);return toHex(h)}normalizeInput(t){let _;if(t instanceof Uint8Array)_=t;else if("string"==typeof t){let $=new TextEncoder;_=$.encode(t)}else throw Error("Input must be an string, Buffer or Uint8Array");return _}toHex(t){return Array.prototype.map.call(t,function(t){return(t<16?"0":"")+t.toString(16)}).join("")}static hash(t,_,$=64,e,i){let h=new Blake2b,s=h.blake2bStart(t,_,$,e,i);return h.toHex(s)}} /* -Argon2id-JS v1.1.0 +Argon2id-JS v1.1.1 https://github.com/Rabbit-Company/Argon2id-JS -License: GPL-3.0 +License: MIT */ class Argon2id{static memo={};construtor(){this.mm=NaN,this.H_0=NaN,this.p=NaN,this.q=NaN}LE32(t){let e=new Uint8Array(4);return e[0]=t,e[1]=t>>8&255,e[2]=t>>16&255,e[3]=t>>24&255,Array.from(e)}LE64(t){let e=new Uint8Array(8);return e[0]=t,e[1]=t>>8&255,e[2]=t>>16&255,e[3]=t>>24&255,Array.from(e)}toHex(t){return Array.prototype.map.call(t,function(t){return(t<16?"0":"")+t.toString(16)}).join("")}ascii(t){for(var e=[],i=0,n=t.length;i>=8n;return new Uint8Array(e).reverse()}Uint8ArrayToBigInt(t){let e=0n;for(let i=t.length-1;i>=0;i--)e=BigInt(t[i])|e<<8n;return e}ZERO(t){return new Uint8Array(t)}Concatenate(...t){let e=0;t.forEach(t=>{e+=t.length});let i=new Uint8Array(e),n=0;return t.forEach(t=>{i.set(t,n),n+=t.length}),i}XOR(t,e){let i=new Uint8Array(1024);for(let n=0;n>BigInt(32)|(a&s)<>BigInt(24)|(a&BigInt(16777215))<>BigInt(16)|(a&BigInt(65535))<>BigInt(63)|a<{let n=this.XOR(t,e),r=[],s,a;for(let h=0;h<8;h++)a=128*h,(s=this.P(n.slice(a,a+16),n.slice(a+16,a+32),n.slice(a+32,a+48),n.slice(a+48,a+64),n.slice(a+64,a+80),n.slice(a+80,a+96),n.slice(a+96,a+112),n.slice(a+112,a+128))).forEach(t=>r.push(...t));let l=[];for(let o=0;o<8;o++){a=16*o,(s=this.P(r.slice(a,a+16),r.slice(a+128,a+128+16),r.slice(a+256,a+256+16),r.slice(a+384,a+384+16),r.slice(a+512,a+512+16),r.slice(a+640,a+640+16),r.slice(a+768,a+768+16),r.slice(a+896,a+896+16))).forEach(t=>r.push(...t));for(let c=0;c[]);if(window.Worker&&window.runWorker){let u=[];await new Promise(e=>{let i=0,a=0,h=0,l=()=>{u.forEach((e,h)=>{e.postMessage({type:"fill-segment",payload:{B:_,t:i,segment:a,i:Number(h),y:s,segment_Length:$,H_0:c,q:g,p:Number(t),mm:this.mm,time_cost:n,v:r}})})},o=()=>{u.forEach(t=>t.terminate())};for(let f=0;f=t){if(h=0,++a>=4&&(a=0,++i>=n))return o(),e();l()}};l()})}else for(let f=0;fthis._fill_segment(_,f,A,i,s,$,c,g,t,this.mm,n,r)));for(let b=0;b>BigInt(32);p=BigInt(d)-BigInt(1)-(BigInt(d)*p>>BigInt(32));var T=0;0!=e&&3!=i&&(T=(i+1)*s);var w=await this.G(t[n][this.MOD(b-1,h)],t[U][this.MOD(BigInt(T)+p,BigInt(h))]);0!=e&&19==g&&(w=this.XOR(t[n][b],w)),t[n][b]=w}return t[n].slice(i*s,(i+1)*s)}hexToBase64(t){return btoa(t.match(/\w{2}/g).map(function(t){return String.fromCharCode(parseInt(t,16))}).join(""))}base64ToHex(t){let e=atob(t),i="";for(let n=0;n{let o=new Argon2id;o.Argon2Operation(r,s,n,i,19,2,t,e,a,h).then(t=>{l("$argon2id$v=19$m="+n+",t="+i+",p="+r+"$"+btoa(e).replaceAll("=","")+"$"+o.hexToBase64(o.toHex(t)).replaceAll("=",""))})})}static verify(t,e,i="",n=""){let r=t.split("$");if(6!=r.length||"argon2id"!=r[1]||"v=19"!=r[2])return!1;let s=r[3].split(",");if(3!=s.length)return!1;let a=s[0].split("=")[1],h=s[1].split("=")[1],l=s[2].split("=")[1],o=atob(r[4]),c=Argon2id.hashDecode(t);return new Promise(t=>{Argon2id.hash(e,o,h,a,l,c.length/2,i,n).then(e=>{t(c==e)})})}} \ No newline at end of file diff --git a/Argon2idWorker.js b/Argon2idWorker.js index e8ddb18..483b6dc 100644 --- a/Argon2idWorker.js +++ b/Argon2idWorker.js @@ -1,7 +1,7 @@ /* -Argon2id-JS v1.1.0 +Argon2id-JS v1.1.1 https://github.com/Rabbit-Company/Argon2id-JS -License: GPL-3.0 +License: MIT */ function runWorker() { diff --git a/Argon2idWorker.min.js b/Argon2idWorker.min.js index 273dac1..0530b47 100644 --- a/Argon2idWorker.min.js +++ b/Argon2idWorker.min.js @@ -1,6 +1,6 @@ /* -Argon2id-JS v1.1.0 +Argon2id-JS v1.1.1 https://github.com/Rabbit-Company/Argon2id-JS -License: GPL-3.0 +License: MIT */ function runWorker(){class t{v=new Uint32Array(32);m=new Uint32Array(32);BLAKE2B_IV32=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]);SIGMA8=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3];parameterBlock=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);SIGMA82=new Uint8Array(this.SIGMA8.map(function(t){return 2*t}));ADD64AA(t,e,_){let i=t[e]+t[_],l=t[e+1]+t[_+1];i>=4294967296&&l++,t[e]=i,t[e+1]=l}ADD64AC(t,e,_,i){let l=t[e]+_;_<0&&(l+=4294967296);let n=t[e+1]+i;l>=4294967296&&n++,t[e]=l,t[e+1]=n}B2B_GET32(t,e){return t[e]^t[e+1]<<8^t[e+2]<<16^t[e+3]<<24}B2B_G(t,e,_,i,l,n){let $=this.m[l],s=this.m[l+1],h=this.m[n],r=this.m[n+1];this.ADD64AA(this.v,t,e),this.ADD64AC(this.v,t,$,s);let a=this.v[i]^this.v[t],c=this.v[i+1]^this.v[t+1];this.v[i]=c,this.v[i+1]=a,this.ADD64AA(this.v,_,i),a=this.v[e]^this.v[_],c=this.v[e+1]^this.v[_+1],this.v[e]=a>>>24^c<<8,this.v[e+1]=c>>>24^a<<8,this.ADD64AA(this.v,t,e),this.ADD64AC(this.v,t,h,r),a=this.v[i]^this.v[t],c=this.v[i+1]^this.v[t+1],this.v[i]=a>>>16^c<<16,this.v[i+1]=c>>>16^a<<16,this.ADD64AA(this.v,_,i),a=this.v[e]^this.v[_],c=this.v[e+1]^this.v[_+1],this.v[e]=c>>>31^a<<1,this.v[e+1]=a>>>31^c<<1}blake2bCompress(t,e){let _=0;for(_=0;_<16;_++)this.v[_]=t.h[_],this.v[_+16]=this.BLAKE2B_IV32[_];for(this.v[24]=this.v[24]^t.t,this.v[25]=this.v[25]^t.t/4294967296,e&&(this.v[28]=~this.v[28],this.v[29]=~this.v[29]),_=0;_<32;_++)this.m[_]=this.B2B_GET32(t.b,4*_);for(_=0;_<12;_++)this.B2B_G(0,8,16,24,this.SIGMA82[16*_+0],this.SIGMA82[16*_+1]),this.B2B_G(2,10,18,26,this.SIGMA82[16*_+2],this.SIGMA82[16*_+3]),this.B2B_G(4,12,20,28,this.SIGMA82[16*_+4],this.SIGMA82[16*_+5]),this.B2B_G(6,14,22,30,this.SIGMA82[16*_+6],this.SIGMA82[16*_+7]),this.B2B_G(0,10,20,30,this.SIGMA82[16*_+8],this.SIGMA82[16*_+9]),this.B2B_G(2,12,22,24,this.SIGMA82[16*_+10],this.SIGMA82[16*_+11]),this.B2B_G(4,14,16,26,this.SIGMA82[16*_+12],this.SIGMA82[16*_+13]),this.B2B_G(6,8,18,28,this.SIGMA82[16*_+14],this.SIGMA82[16*_+15]);for(_=0;_<16;_++)t.h[_]=t.h[_]^this.v[_]^this.v[_+16]}blake2bInit(t,e,_,i){if(0===t||t>64)throw Error("Illegal output length, expected 0 < length <= 64");if(e&&e.length>64)throw Error("Illegal key, expected Uint8Array with 0 < length <= 64");if(_&&16!==_.length)throw Error("Illegal salt, expected Uint8Array with length is 16");if(i&&16!==i.length)throw Error("Illegal personal, expected Uint8Array with length is 16");let l={b:new Uint8Array(128),h:new Uint32Array(16),t:0,c:0,outlen:t};this.parameterBlock.fill(0),this.parameterBlock[0]=t,e&&(this.parameterBlock[1]=e.length),this.parameterBlock[2]=1,this.parameterBlock[3]=1,_&&this.parameterBlock.set(_,32),i&&this.parameterBlock.set(i,48);for(let n=0;n<16;n++)l.h[n]=this.BLAKE2B_IV32[n]^this.B2B_GET32(this.parameterBlock,4*n);return e&&(this.blake2bUpdate(l,e),l.c=128),l}blake2bUpdate(t,e){for(let _=0;_>2]>>8*(3&_);return e}blake2bStart(t,e,_,i,l){_=_||64,t=this.normalizeInput(t),i&&(i=this.normalizeInput(i)),l&&(l=this.normalizeInput(l));let n=this.blake2bInit(_,e,i,l);return this.blake2bUpdate(n,t),this.blake2bFinal(n)}blake2bHex(t,e,_,i,l){var n;return n=blake2bStart(t,e,_,i,l),Array.prototype.map.call(n,function(t){return(t<16?"0":"")+t.toString(16)}).join("")}normalizeInput(t){let e;if(t instanceof Uint8Array)e=t;else if("string"==typeof t)e=(new TextEncoder).encode(t);else throw Error("Input must be an string, Buffer or Uint8Array");return e}toHex(t){return Array.prototype.map.call(t,function(t){return(t<16?"0":"")+t.toString(16)}).join("")}static hash(e,_,i=64,l,n){let $=new t,s=$.blake2bStart(e,_,i,l,n);return $.toHex(s)}}let e={},_=null;function i(t){let e=new Uint8Array(4);return e[0]=t,e[1]=t>>8&255,e[2]=t>>16&255,e[3]=t>>24&255,Array.from(e)}function l(t){let e=new Uint8Array(8);return e[0]=t,e[1]=t>>8&255,e[2]=t>>16&255,e[3]=t>>24&255,Array.from(e)}function n(t,e){return 0==e?s(t.slice(0,4)):1==e?s(t.slice(4,8)):void 0}function $(t){var e=[];let _=Math.ceil(Math.floor(Math.log2(new Number(t))+1)/8);for(let i=0;i<_;i++)e.unshift(new Number(255n&t)),t>>=8n;return new Uint8Array(e).reverse()}function s(t){let e=0n;for(let _=t.length-1;_>=0;_--)e=BigInt(t[_])|e<<8n;return e}function h(t){return new Uint8Array(t)}function r(...t){let e=0;t.forEach(t=>{e+=t.length});let _=new Uint8Array(e),i=0;return t.forEach(t=>{_.set(t,i),i+=t.length}),_}function a(t,e){let _=new Uint8Array(1024);for(let i=0;i>BigInt(32)|($&n)<>BigInt(24)|($&BigInt(16777215))<>BigInt(16)|($&BigInt(65535))<>BigInt(63)|$<{let i=a(t,e),l=[],n,$;for(let s=0;s<8;s++)$=128*s,(n=f(i.slice($,$+16),i.slice($+16,$+32),i.slice($+32,$+48),i.slice($+48,$+64),i.slice($+64,$+80),i.slice($+80,$+96),i.slice($+96,$+112),i.slice($+112,$+128))).forEach(t=>l.push(...t));let h=[];for(let c=0;c<8;c++){$=16*c,(n=f(l.slice($,$+16),l.slice($+128,$+128+16),l.slice($+256,$+256+16),l.slice($+384,$+384+16),l.slice($+512,$+512+16),l.slice($+640,$+640+16),l.slice($+768,$+768+16),l.slice($+896,$+896+16))).forEach(t=>l.push(...t));for(let o=0;o>BigInt(32);D=BigInt(x)-BigInt(1)-(BigInt(x)*D>>BigInt(32));var U=0;0!=e&&3!=_&&(U=(_+1)*$);var d=await u(t[i][c(m-1,r)],t[F][c(BigInt(U)+D,BigInt(r))]);0!=e&&19==A&&(d=a(t[i][m],d)),t[i][m]=d}return t[i].slice(_*$,(_+1)*$)}onmessage=function(t){let{type:e,payload:_}=t.data;if("fill-segment"===e){let{B:i,t:l,segment:n,i:$,y:s,segment_Length:h,H_0:r,q:a,p:c,mm:o,time_cost:f,v:u}=_;A(i,l,n,$,s,h,r,a,c,o,f,u).then(t=>{postMessage({type:e,payload:_,result:t})})}}}window!=self&&runWorker(); \ No newline at end of file