2 lines
13 KiB
JavaScript
Raw Normal View History

2023-10-10 09:36:22 +08:00
(function(){"use strict";const{Array:T,Object:w,Math:v,Error:z,Uint8Array:p,Uint16Array:_e,Uint32Array:ie,Int32Array:me,DataView:ce,TextEncoder:P,crypto:A,postMessage:K}=globalThis,R=[];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;R[n]=e}class W{constructor(e){this.crc=e||-1}append(e){let t=0|this.crc;for(let s=0,r=0|e.length;r>s;s++)t=t>>>8^R[255&(t^e[s])];this.crc=t}get(){return~this.crc}}const d={concat(n,e){if(n.length===0||e.length===0)return n.concat(e);const t=n[n.length-1],s=d.getPartial(t);return s===32?n.concat(e):d._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)+d.getPartial(t)},clamp(n,e){if(32*n.length<e)return n;const t=(n=n.slice(0,v.ceil(e/32))).length;return e&=31,t>0&&e&&(n[t-1]=d.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=>v.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 r=n.length?n[n.length-1]:0,a=d.getPartial(r);return s.push(d.partial(e+a&31,e+a>32?t:s.pop(),1)),s}},E={bytes:{fromBits(n){const e=d.bitLength(n)/8,t=new p(e);let s;for(let r=0;e>r;r++)!(3&r)&&(s=n[r/4]),t[r]=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(d.partial(8*(3&t),s)),e}}},M={sha1:function(n){n?(this._h=n._h.slice(0),this._buffer=n._buffer.slice(0),this._length=n._length):this.reset()}};M.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=E.utf8String.toBits(n));const t=e._buffer=d.concat(e._buffer,n),s=e._length,r=e._length=s+d.bitLength(n);if(r>9007199254740991)throw new z("Cannot hash more than 2^53 - 1 bits");const a=new ie(t);let i=0;for(let o=e.blockSize+s-(e.blockSize+s&e.blockSize-1);r>=o;o+=e.blockSize)e._block(a.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=d.concat(e,[d.partial(1,1)]);for(let s=e.length+2;15&s;s++)e.push(0);for(e.push(v.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=T(80);for(let c=0;16>c;c++)s[c]=n[c];let r=t[0],a=t[1],i=t[2],o=t[3],l=t[4];for(let c=0;79>=c;c++){16>c||(s[c]=e._S(1,s[c-3]^s[c-8]^s[c-14]^s[c-16]));const h=e._S(5,r)+e._f(c,a,i,o)+l+s[c]+e._key[v.floor(c/20)]|0;l=o,o=i,i=e._S(30,a),a=r,r=h}t[0]=t[0]+r|0,t[1]=t[1]+a|0,t[2]=t[2]+i|0,t[3]=t[3]+o|0,t[4]=t[4]+l|0}};const j="Invalid pasword",I=16,x={name:"PBKDF2"},oe=w.assign({hash:{name:"HMAC"}},x),le=w.assign({iterations:1e3,hash:{name:"SHA-1"}},x),he=["deriveBits"],H=[8,12,16],V=[16,24,32],_=10,F=[0,0,0,0],y=E.bytes,O=class{constructor(n){const e=this;e._tables=[[[],[],[],[],[]],[[],[],[],[],[]]],e._tables[0][0][0]||e._precompute();const t=e._tables[0][4],s=e._tables[1],r=n.length;let a,i,o,l=1;if(r!==4&&r!==6&&r!==8)throw new z("invalid aes key size");for(e._key=[i=n.slice(0),o=[]],a=r;4*r+28>a;a++){let c=i[a-1];(a%r==0||r===8&&a%r==4)&&(c=t[c>>>24]<<24^t[c>>16&255]<<16^t[c>>8&255]<<8^t[255&c],a%r==0&&(c=c<<8^c>>>24^l<<24,l=l<<1^283*(l>>7))),i[a]=i[a-r]^c}for(let c=0;a;c++,a--){const h=i[3&c?a:a-4];o[c]=4>=a||4>c?h:s[0][t[h>>>24]]^s[1][t[h>>16&255]]^s[2][t[h>>8&255]]^s[3][t[255&h]]}}encrypt(n){return this._crypt(n,0)}decrypt(n){return this._crypt(n,1)}_precompute(){const n=this._tables[0],e=this._tables[1],t=n[4],s=e[4],r=[],a=[];let i,o,l,c;for(let h=0;256>h;h++)a[(r[h]=h<<1^283*(h>>7))^h]=h;for(let h=i=0;!t[h];h^=o||1,i=a[i]||1){let f=i^i<<1^i<<2^i<<3^i<<4;f=f>>8^255&f^99,t[h]=f,s[f]=h,c=r[l=r[o=r[h]]];let S=16843009*c^65537*l^257*o^16