Home

js-spectre @64337f178d031116037b497b1c69ac477df5cfe0 - refs - log -
-
https://git.jolheiser.com/js-spectre.git
JS implementation for spectre/masterpassword
js-spectre / lib / spectre.min.js
- raw
1
2
3
4
5
6
"use strict";var spectre=(()=>{var et=Object.defineProperty;var At=Object.getOwnPropertyDescriptor;var kt=Object.getOwnPropertyNames;var Lt=Object.prototype.hasOwnProperty;var It=(e,t)=>{for(var n in t)et(e,n,{get:t[n],enumerable:!0})},Et=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of kt(t))!Lt.call(e,r)&&r!==n&&et(e,r,{get:()=>t[r],enumerable:!(o=At(t,r))||o.enumerable});return e};var Ut=e=>Et(et({},"__esModule",{value:!0}),e);var Vt={};It(Vt,{Scope:()=>st,SimpleScoper:()=>J,Spectre:()=>dt,Template:()=>nt,characters:()=>rt,defaultScoper:()=>it,defaultTemplate:()=>ct,templates:()=>ot});var nt=(a=>(a.MAXIMUM="Maximum",a.LONG="Long",a.MEDIUM="Medium",a.SHORT="Short",a.PIN="PIN",a.NAME="Name",a.PHRASE="Phrase",a.BASIC="Basic",a))(nt||{}),ot={Maximum:["anoxxxxxxxxxxxxxxxxx","axxxxxxxxxxxxxxxxxno"],Long:["CvcvnoCvcvCvcv","CvcvCvcvnoCvcv","CvcvCvcvCvcvno","CvccnoCvcvCvcv","CvccCvcvnoCvcv","CvccCvcvCvcvno","CvcvnoCvccCvcv","CvcvCvccnoCvcv","CvcvCvccCvcvno","CvcvnoCvcvCvcc","CvcvCvcvnoCvcc","CvcvCvcvCvccno","CvccnoCvccCvcv","CvccCvccnoCvcv","CvccCvccCvcvno","CvcvnoCvccCvcc","CvcvCvccnoCvcc","CvcvCvccCvccno","CvccnoCvcvCvcc","CvccCvcvnoCvcc","CvccCvcvCvccno"],Medium:["CvcnoCvc","CvcCvcno"],Short:["Cvcn"],PIN:["nnnn"],Name:["cvccvcvcv"],Phrase:["cvcc cvc cvccvcv cvc","cvc cvccvcvcv cvcv","cv cvccv cvc cvcvccv"],Basic:["aaanaaan","aannaaan","aaannaaa"]},rt={V:"AEIOU",C:"BCDFGHJKLMNPQRSTVWXYZ",v:"aeiou",c:"bcdfghjklmnpqrstvwxyz",A:"AEIOUBCDFGHJKLMNPQRSTVWXYZ",a:"AEIOUaeiouBCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz",n:"0123456789",o:"@&%?,=[]_:-+*$#!'^~;()/.",x:"AEIOUaeiouBCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz0123456789!@#$%^&*()"," ":" "};var st=(o=>(o.AUTHENTICATION="Authentication",o.IDENTIFICATION="Identification",o.RECOVERY="Recovery",o))(st||{});function ct(e){switch(e){case"Authentication":return"Long";case"Identification":return"Name";case"Recovery":return"Maximum"}}var J=class{key;constructor(t){this.key=t}scope(t){switch(t){case"Authentication":return this.key;case"Identification":return`${this.key}.login`;case"Recovery":return`${this.key}.answer`}}},it=new J("com.lyndir.masterpassword");function v(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Bt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function z(e,...t){if(!Bt(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Q(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");v(e.outputLen),v(e.blockLen)}function K(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function bt(e,t){z(e);let n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Z(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function G(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function g(e,t){return e<<32-t|e>>>t}function u(e,t){return e<<t|e>>>32-t>>>0}var at=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function St(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function ft(e){for(let t=0;t<e.length;t++)e[t]=St(e[t])}function Ht(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function w(e){return typeof e=="string"&&(e=Ht(e)),z(e),e}var j=class{clone(){return this._cloneInto()}};function $(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(e,t)}function vt(e){let t=o=>e().update(w(o)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}var W=class extends j{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Q(t);let o=w(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let r=this.blockLen,s=new Uint8Array(r);s.set(o.length>r?t.create().update(o).digest():o);for(let c=0;c<s.length;c++)s[c]^=54;this.iHash.update(s),this.oHash=t.create();for(let c=0;c<s.length;c++)s[c]^=106;this.oHash.update(s),s.fill(0)}update(t){return K(this),this.iHash.update(t),this}digestInto(t){K(this),z(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:n,iHash:o,finished:r,destroyed:s,blockLen:c,outputLen:i}=this;return t=t,t.finished=r,t.destroyed=s,t.blockLen=c,t.outputLen=i,t.oHash=n._cloneInto(t.oHash),t.iHash=o._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ht=(e,t,n)=>new W(e,t).update(n).digest();ht.create=(e,t)=>new W(e,t);function Nt(e,t,n,o){Q(e);let r=$({dkLen:32,asyncTick:10},o),{c:s,dkLen:c,asyncTick:i}=r;if(v(s),v(c),v(i),s<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let a=w(t),h=w(n),x=new Uint8Array(c),f=ht.create(e,a),l=f._cloneInto().update(h);return{c:s,dkLen:c,asyncTick:i,DK:x,PRF:f,PRFSalt:l}}function Ot(e,t,n,o,r){return e.destroy(),t.destroy(),o&&o.destroy(),r.fill(0),n}function ut(e,t,n,o){let{c:r,dkLen:s,DK:c,PRF:i,PRFSalt:a}=Nt(e,t,n,o),h,x=new Uint8Array(4),f=G(x),l=new Uint8Array(i.outputLen);for(let y=1,d=0;d<s;y++,d+=i.outputLen){let p=c.subarray(d,d+i.outputLen);f.setInt32(0,y,!1),(h=a._cloneInto(h)).update(x).digestInto(l),p.set(l.subarray(0,p.length));for(let m=1;m<r;m++){i._cloneInto(h).update(l).digestInto(l);for(let b=0;b<p.length;b++)p[b]^=l[b]}}return Ot(i,a,c,h,l)}function Mt(e,t,n,o){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,o);let r=BigInt(32),s=BigInt(4294967295),c=Number(n>>r&s),i=Number(n&s),a=o?4:0,h=o?0:4;e.setUint32(t+a,c,o),e.setUint32(t+h,i,o)}function mt(e,t,n){return e&t^~e&n}function gt(e,t,n){return e&t^e&n^t&n}var tt=class extends j{constructor(t,n,o,r){super(),this.blockLen=t,this.outputLen=n,this.padOffset=o,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=G(this.buffer)}update(t){K(this);let{view:n,buffer:o,blockLen:r}=this;t=w(t);let s=t.length;for(let c=0;c<s;){let i=Math.min(r-this.pos,s-c);if(i===r){let a=G(t);for(;r<=s-c;c+=r)this.process(a,c);continue}o.set(t.subarray(c,c+i),this.pos),this.pos+=i,c+=i,this.pos===r&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){K(this),bt(t,this),this.finished=!0;let{buffer:n,view:o,blockLen:r,isLE:s}=this,{pos:c}=this;n[c++]=128,this.buffer.subarray(c).fill(0),this.padOffset>r-c&&(this.process(o,0),c=0);for(let f=c;f<r;f++)n[f]=0;Mt(o,r-8,BigInt(this.length*8),s),this.process(o,0);let i=G(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let h=a/4,x=this.get();if(h>x.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<h;f++)i.setUint32(4*f,x[f],s)}digest(){let{buffer:t,outputLen:n}=this;this.digestInto(t);let o=t.slice(0,n);return this.destroy(),o}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:n,buffer:o,length:r,finished:s,destroyed:c,pos:i}=this;return t.length=r,t.pos=i,t.finished=s,t.destroyed=c,r%n&&t.buffer.set(o),t}};var _t=new Uint32Array([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]),C=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),A=new Uint32Array(64),xt=class extends tt{constructor(){super(64,32,8,!1),this.A=C[0]|0,this.B=C[1]|0,this.C=C[2]|0,this.D=C[3]|0,this.E=C[4]|0,this.F=C[5]|0,this.G=C[6]|0,this.H=C[7]|0}get(){let{A:t,B:n,C:o,D:r,E:s,F:c,G:i,H:a}=this;return[t,n,o,r,s,c,i,a]}set(t,n,o,r,s,c,i,a){this.A=t|0,this.B=n|0,this.C=o|0,this.D=r|0,this.E=s|0,this.F=c|0,this.G=i|0,this.H=a|0}process(t,n){for(let f=0;f<16;f++,n+=4)A[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){let l=A[f-15],y=A[f-2],d=g(l,7)^g(l,18)^l>>>3,p=g(y,17)^g(y,19)^y>>>10;A[f]=p+A[f-7]+d+A[f-16]|0}let{A:o,B:r,C:s,D:c,E:i,F:a,G:h,H:x}=this;for(let f=0;f<64;f++){let l=g(i,6)^g(i,11)^g(i,25),y=x+l+mt(i,a,h)+_t[f]+A[f]|0,p=(g(o,2)^g(o,13)^g(o,22))+gt(o,r,s)|0;x=h,h=a,a=i,i=c+y|0,c=s,s=r,r=o,o=y+p|0}o=o+this.A|0,r=r+this.B|0,s=s+this.C|0,c=c+this.D|0,i=i+this.E|0,a=a+this.F|0,h=h+this.G|0,x=x+this.H|0,this.set(o,r,s,c,i,a,h,x)}roundClean(){A.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Y=vt(()=>new xt);function wt(e,t,n,o,r,s){let c=e[t++]^n[o++],i=e[t++]^n[o++],a=e[t++]^n[o++],h=e[t++]^n[o++],x=e[t++]^n[o++],f=e[t++]^n[o++],l=e[t++]^n[o++],y=e[t++]^n[o++],d=e[t++]^n[o++],p=e[t++]^n[o++],m=e[t++]^n[o++],b=e[t++]^n[o++],X=e[t++]^n[o++],P=e[t++]^n[o++],q=e[t++]^n[o++],k=e[t++]^n[o++],L=c,I=i,E=a,U=h,B=x,S=f,H=l,T=y,N=d,O=p,M=m,_=b,R=X,F=P,V=q,D=k;for(let yt=0;yt<8;yt+=2)B^=u(L+R|0,7),N^=u(B+L|0,9),R^=u(N+B|0,13),L^=u(R+N|0,18),O^=u(S+I|0,7),F^=u(O+S|0,9),I^=u(F+O|0,13),S^=u(I+F|0,18),V^=u(M+H|0,7),E^=u(V+M|0,9),H^=u(E+V|0,13),M^=u(H+E|0,18),U^=u(D+_|0,7),T^=u(U+D|0,9),_^=u(T+U|0,13),D^=u(_+T|0,18),I^=u(L+U|0,7),E^=u(I+L|0,9),U^=u(E+I|0,13),L^=u(U+E|0,18),H^=u(S+B|0,7),T^=u(H+S|0,9),B^=u(T+H|0,13),S^=u(B+T|0,18),_^=u(M+O|0,7),N^=u(_+M|0,9),O^=u(N+_|0,13),M^=u(O+N|0,18),R^=u(D+V|0,7),F^=u(R+D|0,9),V^=u(F+R|0,13),D^=u(V+F|0,18);r[s++]=c+L|0,r[s++]=i+I|0,r[s++]=a+E|0,r[s++]=h+U|0,r[s++]=x+B|0,r[s++]=f+S|0,r[s++]=l+H|0,r[s++]=y+T|0,r[s++]=d+N|0,r[s++]=p+O|0,r[s++]=m+M|0,r[s++]=b+_|0,r[s++]=X+R|0,r[s++]=P+F|0,r[s++]=q+V|0,r[s++]=k+D|0}function lt(e,t,n,o,r){let s=o+0,c=o+16*r;for(let i=0;i<16;i++)n[c+i]=e[t+(2*r-1)*16+i];for(let i=0;i<r;i++,s+=16,t+=16)wt(n,c,e,t,n,s),i>0&&(c+=16),wt(n,s,e,t+=16,n,c)}function Rt(e,t,n){let o=$({dkLen:32,asyncTick:10,maxmem:1073742848},n),{N:r,r:s,p:c,dkLen:i,asyncTick:a,maxmem:h,onProgress:x}=o;if(v(r),v(s),v(c),v(i),v(a),v(h),x!==void 0&&typeof x!="function")throw new Error("progressCb should be function");let f=128*s,l=f/4;if(r<=1||r&r-1||r>2**32)throw new Error("Scrypt: N must be larger than 1, a power of 2, and less than 2^32");if(c<0||c>(2**32-1)*32/f)throw new Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");if(i<0||i>(2**32-1)*32)throw new Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");if(f*(r+c)>h)throw new Error("Scrypt: memused is bigger than maxMem. Expected 128 * r * (N + p) > maxmem of "+h);let d=ut(Y,e,t,{c:1,dkLen:f*c}),p=Z(d),m=Z(new Uint8Array(f*r)),b=Z(new Uint8Array(f)),X=()=>{};if(x){let P=2*r*c,q=Math.max(Math.floor(P/1e4),1),k=0;X=()=>{k++,x&&(!(k%q)||k===P)&&x(k/P)}}return{N:r,r:s,p:c,dkLen:i,blockSize32:l,V:m,B32:p,B:d,tmp:b,blockMixCb:X,asyncTick:a}}function Ft(e,t,n,o,r){let s=ut(Y,e,n,{c:1,dkLen:t});return n.fill(0),o.fill(0),r.fill(0),s}function Ct(e,t,n){let{N:o,r,p:s,dkLen:c,blockSize32:i,V:a,B32:h,B:x,tmp:f,blockMixCb:l}=Rt(e,t,n);at||ft(h);for(let y=0;y<s;y++){let d=i*y;for(let p=0;p<i;p++)a[p]=h[d+p];for(let p=0,m=0;p<o-1;p++)lt(a,m,a,m+=i,r),l();lt(a,(o-1)*i,h,d,r),l();for(let p=0;p<o;p++){let m=h[d+i-16]%o;for(let b=0;b<i;b++)f[b]=h[d+b]^a[m*i+b];lt(f,0,h,d,r),l()}}return at||ft(h),Ft(e,c,x,a,f)}var dt=class{name;secret;scoper;key;constructor(t,n,o=it){this.name=t,this.secret=n,this.scoper=o,this.key=this.userKey()}userKey(){let t=new TextEncoder,n=t.encode(this.name),o=t.encode(this.secret),r=t.encode(this.scoper.scope("Authentication")),s=n.length,c=new Uint8Array([...r,...pt(s),...n]),i=32768,a=8,h=2,x=128*a*(i+h+2);return Ct(o,c,{N:i,r:a,p:h,maxmem:x,dkLen:64})}siteKey(t,n,o){let r=new TextEncoder,s=r.encode(t),c=r.encode(this.scoper.scope(o)),i=s.length,a=new Uint8Array([...c,...pt(i),...s,...pt(n)]),h=new W(Y,this.key);return h.update(a),h.digest()}site(t,n,o=1,r="Authentication"){n===void 0&&(n=ct(r));let s=this.siteKey(t,o,r),c=ot[n],i=c[s[0]%c.length],a="";for(let h=0;h<i.length;h++){let x=i[h],f=rt[x],l=f[s[h+1]%f.length];a+=l}return a}};function pt(e){let t=new ArrayBuffer(4);return new DataView(t).setInt32(0,e,!1),new Uint8Array(t)}return Ut(Vt);})();
/*! Bundled license information:

@noble/hashes/esm/utils.js:
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
*/