2 lines
14 KiB
JavaScript
2 lines
14 KiB
JavaScript
|
(function(){"use strict";const{Array:G,Object:y,Math:k,Error:m,Uint8Array:p,Uint16Array:ve,Uint32Array:M,Int32Array:ze,DataView:j,TextEncoder:x,crypto:b,postMessage:A}=globalThis,F=[];for(let n=0;256>n;n++){let e=n;for(let t=0;8>t;t++)1&e?e=e>>>1^3988292384:e>>>=1;F[n]=e}class R{constructor(e){this.crc=e||-1}append(e){let t=0|this.crc;for(let s=0,a=0|e.length;a>s;s++)t=t>>>8^F[255&(t^e[s])];this.crc=t}get(){return~this.crc}}const u={concat(n,e){if(n.length===0||e.length===0)return n.concat(e);const t=n[n.length-1],s=u.getPartial(t);return s===32?n.concat(e):u._shiftRight(e,s,0|t,n.slice(0,n.length-1))},bitLength(n){const e=n.length;if(e===0)return 0;const t=n[e-1];return 32*(e-1)+u.getPartial(t)},clamp(n,e){if(32*n.length<e)return n;const t=(n=n.slice(0,k.ceil(e/32))).length;return e&=31,t>0&&e&&(n[t-1]=u.partial(e,n[t-1]&2147483648>>e-1,1)),n},partial:(n,e,t)=>n===32?e:(t?0|e:e<<32-n)+1099511627776*n,getPartial:n=>k.round(n/1099511627776)||32,_shiftRight(n,e,t,s){for(s===void 0&&(s=[]);e>=32;e-=32)s.push(t),t=0;if(e===0)return s.concat(n);for(let i=0;i<n.length;i++)s.push(t|n[i]>>>e),t=n[i]<<32-e;const a=n.length?n[n.length-1]:0,r=u.getPartial(a);return s.push(u.partial(e+r&31,e+r>32?t:s.pop(),1)),s}},W={bytes:{fromBits(n){const e=u.bitLength(n)/8,t=new p(e);let s;for(let a=0;e>a;a++)!(3&a)&&(s=n[a/4]),t[a]=s>>>24,s<<=8;return t},toBits(n){const e=[];let t,s=0;for(t=0;t<n.length;t++)s=s<<8|n[t],(3&t)==3&&(e.push(s),s=0);return 3&t&&e.push(u.partial(8*(3&t),s)),e}}},O={sha1:function(n){n?(this._h=n._h.slice(0),this._buffer=n._buffer.slice(0),this._length=n._length):this.reset()}};O.sha1.prototype={blockSize:512,reset:function(){const n=this;return n._h=this._init.slice(0),n._buffer=[],n._length=0,n},update:function(n){const e=this;typeof n=="string"&&(n=W.utf8String.toBits(n));const t=e._buffer=u.concat(e._buffer,n),s=e._length,a=e._length=s+u.bitLength(n);if(a>9007199254740991)throw new m("Cannot hash more than 2^53 - 1 bits");const r=new M(t);let i=0;for(let c=e.blockSize+s-(e.blockSize+s&e.blockSize-1);a>=c;c+=e.blockSize)e._block(r.subarray(16*i,16*(i+1))),i+=1;return t.splice(0,16*i),e},finalize:function(){const n=this;let e=n._buffer;const t=n._h;e=u.concat(e,[u.partial(1,1)]);for(let s=e.length+2;15&s;s++)e.push(0);for(e.push(k.floor(n._length/4294967296)),e.push(0|n._length);e.length;)n._block(e.splice(0,16));return n.reset(),t},_init:[1732584193,4023233417,2562383102,271733878,3285377520],_key:[1518500249,1859775393,2400959708,3395469782],_f:(n,e,t,s)=>n>19?n>39?n>59?n>79?void 0:e^t^s:e&t|e&s|t&s:e^t^s:e&t|~e&s,_S:(n,e)=>e<<n|e>>>32-n,_block:function(n){const e=this,t=e._h,s=G(80);for(let o=0;16>o;o++)s[o]=n[o];let a=t[0],r=t[1],i=t[2],c=t[3],l=t[4];for(let o=0;79>=o;o++){16>o||(s[o]=e._S(1,s[o-3]^s[o-8]^s[o-14]^s[o-16]));const h=e._S(5,a)+e._f(o,r,i,c)+l+s[o]+e._key[k.floor(o/20)]|0;l=c,c=i,i=e._S(30,r),r=a,a=h}t[0]=t[0]+a|0,t[1]=t[1]+r|0,t[2]=t[2]+i|0,t[3]=t[3]+c|0,t[4]=t[4]+l|0}};const de={getRandomValues(n){const e=new M(n.buffer),t=s=>{let a=987654321;const r=4294967295;return()=>(a=36969*(65535&a)+(a>>16)&r,(((a<<16)+(s=18e3*(65535&s)+(s>>16)&r)&r)/4294967296+.5)*(k.random()>.5?1:-1))};for(let s,a=0;a<n.length;a+=4){const r=t(4294967296*(s||k.random()));s=987654071*r(),e[a/4]=4294967296*r()|0}return n}},T={importKey:n=>new T.hmacSha1(W.bytes.toBits(n)),pbkdf2(n,e,t,s){if(t=t||1e4,0>s||0>t)throw new m("invalid params to pbkdf2");const a=1+(s>>5)<<2;let r,i,c,l,o;const h=new ArrayBuffer(a),d=new j(h);let w=0;const z=u;for(e=W.bytes.toBits(e),o=1;(a||1)>w;o++){for(r=i=n.encrypt(z.concat(e,[o])),c=1;t>c;c++)for(i=n.encrypt(i),l=0;l<i.length;l++)r[l]^=i[l];for(c=0;(a||1)>w&&c<r.length;c++)d.setInt32(w,r[c]),w+=4}return h.slice(0,s/8)},hmacSha1:class{constructor(n){const e=this,t=e._hash=O.sha1,s=[[],[]],a=t.prototype.blockSize/32;e._baseHash=[new t,new t],n.length>a&&(n=t.hash(n));for(let r=0;a>r;r++)s[0][r]=909522486^n[r],s[1][r]=1549556828^n[r];e._baseHash[0].update(s[0]),e._baseHash[1].update(s[1]),e._resultHash=new t(e._baseHash[0])}reset(){const n=this;n._resultHash=new n._hash(n._baseHash[0]),n._updated=
|