1 line
13 KiB
JavaScript
1 line
13 KiB
JavaScript
|
!function(){"use strict";const{Array:t,Object:e,Math:n,Error:s,Uint8Array:a,Uint16Array:r,Uint32Array:i,Int32Array:c,DataView:o,TextEncoder:l,crypto:h,postMessage:p}=globalThis,d=[];for(let t=0;256>t;t++){let e=t;for(let t=0;8>t;t++)1&e?e=e>>>1^3988292384:e>>>=1;d[t]=e}class u{constructor(t){this.crc=t||-1}append(t){let e=0|this.crc;for(let n=0,s=0|t.length;s>n;n++)e=e>>>8^d[255&(e^t[n])];this.crc=e}get(){return~this.crc}}const f={concat(t,e){if(0===t.length||0===e.length)return t.concat(e);const n=t[t.length-1],s=f.getPartial(n);return 32===s?t.concat(e):f._shiftRight(e,s,0|n,t.slice(0,t.length-1))},bitLength(t){const e=t.length;if(0===e)return 0;const n=t[e-1];return 32*(e-1)+f.getPartial(n)},clamp(t,e){if(32*t.length<e)return t;const s=(t=t.slice(0,n.ceil(e/32))).length;return e&=31,s>0&&e&&(t[s-1]=f.partial(e,t[s-1]&2147483648>>e-1,1)),t},partial:(t,e,n)=>32===t?e:(n?0|e:e<<32-t)+1099511627776*t,getPartial:t=>n.round(t/1099511627776)||32,_shiftRight(t,e,n,s){for(void 0===s&&(s=[]);e>=32;e-=32)s.push(n),n=0;if(0===e)return s.concat(t);for(let a=0;a<t.length;a++)s.push(n|t[a]>>>e),n=t[a]<<32-e;const a=t.length?t[t.length-1]:0,r=f.getPartial(a);return s.push(f.partial(e+r&31,e+r>32?n:s.pop(),1)),s}},g={bytes:{fromBits(t){const e=f.bitLength(t)/8,n=new a(e);let s;for(let a=0;e>a;a++)0==(3&a)&&(s=t[a/4]),n[a]=s>>>24,s<<=8;return n},toBits(t){const e=[];let n,s=0;for(n=0;n<t.length;n++)s=s<<8|t[n],3==(3&n)&&(e.push(s),s=0);return 3&n&&e.push(f.partial(8*(3&n),s)),e}}},w={sha1:function(t){t?(this._h=t._h.slice(0),this._buffer=t._buffer.slice(0),this._length=t._length):this.reset()}};w.sha1.prototype={blockSize:512,reset:function(){const t=this;return t._h=this._init.slice(0),t._buffer=[],t._length=0,t},update:function(t){const e=this;"string"==typeof t&&(t=g.utf8String.toBits(t));const n=e._buffer=f.concat(e._buffer,t),a=e._length,r=e._length=a+f.bitLength(t);if(r>9007199254740991)throw new s("Cannot hash more than 2^53 - 1 bits");const c=new i(n);let o=0;for(let t=e.blockSize+a-(e.blockSize+a&e.blockSize-1);r>=t;t+=e.blockSize)e._block(c.subarray(16*o,16*(o+1))),o+=1;return n.splice(0,16*o),e},finalize:function(){const t=this;let e=t._buffer;const s=t._h;e=f.concat(e,[f.partial(1,1)]);for(let t=e.length+2;15&t;t++)e.push(0);for(e.push(n.floor(t._length/4294967296)),e.push(0|t._length);e.length;)t._block(e.splice(0,16));return t.reset(),s},_init:[1732584193,4023233417,2562383102,271733878,3285377520],_key:[1518500249,1859775393,2400959708,3395469782],_f:(t,e,n,s)=>t>19?t>39?t>59?t>79?void 0:e^n^s:e&n|e&s|n&s:e^n^s:e&n|~e&s,_S:(t,e)=>e<<t|e>>>32-t,_block:function(e){const s=this,a=s._h,r=t(80);for(let t=0;16>t;t++)r[t]=e[t];let i=a[0],c=a[1],o=a[2],l=a[3],h=a[4];for(let t=0;79>=t;t++){16>t||(r[t]=s._S(1,r[t-3]^r[t-8]^r[t-14]^r[t-16]));const e=s._S(5,i)+s._f(t,c,o,l)+h+r[t]+s._key[n.floor(t/20)]|0;h=l,l=o,o=s._S(30,c),c=i,i=e}a[0]=a[0]+i|0,a[1]=a[1]+c|0,a[2]=a[2]+o|0,a[3]=a[3]+l|0,a[4]=a[4]+h|0}};const y="Invalid pasword",_=16,m={name:"PBKDF2"},b=e.assign({hash:{name:"HMAC"}},m),k=e.assign({iterations:1e3,hash:{name:"SHA-1"}},m),z=["deriveBits"],C=[8,12,16],v=[16,24,32],I=10,S=[0,0,0,0],D=g.bytes,B=class{constructor(t){const e=this;e._tables=[[[],[],[],[],[]],[[],[],[],[],[]]],e._tables[0][0][0]||e._precompute();const n=e._tables[0][4],a=e._tables[1],r=t.length;let i,c,o,l=1;if(4!==r&&6!==r&&8!==r)throw new s("invalid aes key size");for(e._key=[c=t.slice(0),o=[]],i=r;4*r+28>i;i++){let t=c[i-1];(i%r==0||8===r&&i%r==4)&&(t=n[t>>>24]<<24^n[t>>16&255]<<16^n[t>>8&255]<<8^n[255&t],i%r==0&&(t=t<<8^t>>>24^l<<24,l=l<<1^283*(l>>7))),c[i]=c[i-r]^t}for(let t=0;i;t++,i--){const e=c[3&t?i:i-4];o[t]=4>=i||4>t?e:a[0][n[e>>>24]]^a[1][n[e>>16&255]]^a[2][n[e>>8&255]]^a[3][n[255&e]]}}encrypt(t){return this._crypt(t,0)}decrypt(t){return this._crypt(t,1)}_precompute(){const t=this._tables[0],e=this._tables[1],n=t[4],s=e[4],a=[],r=[];let i,c,o,l;for(let t=0;256>t;t++)r[(a[t]=t<<1^283*(t>>7))^t]=t;for(let h=i=0;!n[h];h^=c||1,i=r[i]||1){let r=i^i<<1^i<<2^i<<3^i<<4;r=r>>8^255&r^99,n[h]=r,s[r]=h,l=a[o=a[c=a[h]]];let p=16843009*l^65537*o^257*c^16843008
|