UNPKG

browserify-sjcl

Version:

Browser-side for sjcl which is a Stanford Javascript Crypto Library

1 lines 25.8 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.sjcl=e():t.sjcl=e()}(window,function(){return n={},r.m=i=[function(t,e,i){"use strict";var n=i(1);Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var r=n(i(2)).default;e.default=r},function(t,e){t.exports=function(t){return t&&t.__esModule?t:{default:t}}},function(t,e,i){"use strict";var n,r,o,a,c,s,b={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(t){this.toString=function(){return"CORRUPT: "+this.message},this.message=t},invalid:function(t){this.toString=function(){return"INVALID: "+this.message},this.message=t},bug:function(t){this.toString=function(){return"BUG: "+this.message},this.message=t},notReady:function(t){this.toString=function(){return"NOT READY: "+this.message},this.message=t}}};function h(t,e,i){if(4!==e.length)throw new b.exception.invalid("invalid aes block size");var n=t.b[i],r=e[0]^n[0],o=e[i?3:1]^n[1],a=e[2]^n[2];e=e[i?1:3]^n[3];var c,s,h=n.length/4-2,l=4,u=[0,0,0,0],f=t.s[i];t=f[0];for(var d=f[1],p=f[2],m=f[3],y=f[4],g=0;g<h;g++)f=t[r>>>24]^d[o>>16&255]^p[a>>8&255]^m[255&e]^n[l],c=t[o>>>24]^d[a>>16&255]^p[e>>8&255]^m[255&r]^n[l+1],s=t[a>>>24]^d[e>>16&255]^p[r>>8&255]^m[255&o]^n[l+2],e=t[e>>>24]^d[r>>16&255]^p[o>>8&255]^m[255&a]^n[l+3],l+=4,r=f,o=c,a=s;for(g=0;g<4;g++)u[i?3&-g:g]=y[r>>>24]<<24^y[o>>16&255]<<16^y[a>>8&255]<<8^y[255&e]^n[l++],f=r,r=o,o=a,a=e,e=f;return u}function l(t,e){for(var i,n,r=t.F,o=t.b,a=r[0],c=r[1],s=r[2],h=r[3],l=r[4],u=r[5],f=r[6],d=r[7],p=0;p<64;p++)i=(i=p<16?e[p]:(i=e[p+1&15],n=e[p+14&15],e[15&p]=(i>>>7^i>>>18^i>>>3^i<<25^i<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+e[15&p]+e[p+9&15]|0))+d+(l>>>6^l>>>11^l>>>25^l<<26^l<<21^l<<7)+(f^l&(u^f))+o[p],d=f,f=u,u=l,l=h+i|0,h=s,s=c,a=i+((c=a)&s^h&(c^s))+(c>>>2^c>>>13^c>>>22^c<<30^c<<19^c<<10)|0;r[0]=r[0]+a|0,r[1]=r[1]+c|0,r[2]=r[2]+s|0,r[3]=r[3]+h|0,r[4]=r[4]+l|0,r[5]=r[5]+u|0,r[6]=r[6]+f|0,r[7]=r[7]+d|0}function u(t,e){var i,n=b.random.K[t],r=[];for(i in n)n.hasOwnProperty(i)&&r.push(n[i]);for(i=0;i<r.length;i++)r[i](e)}function f(t,e){"undefined"!=typeof window&&window.performance&&"function"==typeof window.performance.now?t.addEntropy(window.performance.now(),e,"loadtime"):t.addEntropy((new Date).valueOf(),e,"loadtime")}function d(t){t.b=p(t).concat(p(t)),t.L=new b.cipher.aes(t.b)}function p(t){for(var e=0;e<4&&(t.h[e]=t.h[e]+1|0,!t.h[e]);e++);return t.L.encrypt(t.h)}function m(t,e){return function(){e.apply(t,arguments)}}b.cipher.aes=function(t){this.s[0][0][0]||this.O();var e,i,n,r=this.s[0][4],o=this.s[1],a=t.length,c=1;if(4!==a&&6!==a&&8!==a)throw new b.exception.invalid("invalid aes key size");for(this.b=[i=t.slice(0),n=[]],t=a;t<4*a+28;t++)e=i[t-1],(0==t%a||8===a&&4==t%a)&&(e=r[e>>>24]<<24^r[e>>16&255]<<16^r[e>>8&255]<<8^r[255&e],0==t%a&&(e=e<<8^e>>>24^c<<24,c=c<<1^283*(c>>7))),i[t]=i[t-a]^e;for(a=0;t;a++,t--)e=i[3&a?t:t-4],n[a]=t<=4||a<4?e:o[0][r[e>>>24]]^o[1][r[e>>16&255]]^o[2][r[e>>8&255]]^o[3][r[255&e]]},b.cipher.aes.prototype={encrypt:function(t){return h(this,t,0)},decrypt:function(t){return h(this,t,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){for(var t,e,i,n,r,o,a=this.s[0],c=this.s[1],s=a[4],h=c[4],l=[],u=[],f=0;f<256;f++)u[(l[f]=f<<1^283*(f>>7))^f]=f;for(t=e=0;!s[t];t^=i||1,e=u[e]||1)for(r=(r=e^e<<1^e<<2^e<<3^e<<4)>>8^255&r^99,o=16843009*(n=l[f=l[i=l[h[s[t]=r]=t]]])^65537*f^257*i^16843008*t,n=257*l[r]^16843008*r,f=0;f<4;f++)a[f][t]=n=n<<24^n>>>8,c[f][r]=o=o<<24^o>>>8;for(f=0;f<5;f++)a[f]=a[f].slice(0),c[f]=c[f].slice(0)}},b.bitArray={bitSlice:function(t,e,i){return t=b.bitArray.$(t.slice(e/32),32-(31&e)).slice(1),void 0===i?t:b.bitArray.clamp(t,i-e)},extract:function(t,e,i){var n=Math.floor(-e-i&31);return(-32&(e+i-1^e)?t[e/32|0]<<32-n^t[e/32+1|0]>>>n:t[e/32|0]>>>n)&(1<<i)-1},concat:function(t,e){if(0===t.length||0===e.length)return t.concat(e);var i=t[t.length-1],n=b.bitArray.getPartial(i);return 32===n?t.concat(e):b.bitArray.$(e,n,0|i,t.slice(0,t.length-1))},bitLength:function(t){var e=t.length;return 0===e?0:32*(e-1)+b.bitArray.getPartial(t[e-1])},clamp:function(t,e){if(32*t.length<e)return t;var i=(t=t.slice(0,Math.ceil(e/32))).length;return e&=31,0<i&&e&&(t[i-1]=b.bitArray.partial(e,t[i-1]&2147483648>>e-1,1)),t},partial:function(t,e,i){return 32===t?e:(i?0|e:e<<32-t)+1099511627776*t},getPartial:function(t){return Math.round(t/1099511627776)||32},equal:function(t,e){if(b.bitArray.bitLength(t)!==b.bitArray.bitLength(e))return!1;for(var i=0,n=0;n<t.length;n++)i|=t[n]^e[n];return 0===i},$:function(t,e,i,n){var r=0;for(void 0===n&&(n=[]);32<=e;e-=32)n.push(i),i=0;if(0===e)return n.concat(t);for(r=0;r<t.length;r++)n.push(i|t[r]>>>e),i=t[r]<<32-e;return r=t.length?t[t.length-1]:0,t=b.bitArray.getPartial(r),n.push(b.bitArray.partial(e+t&31,32<e+t?i:n.pop(),1)),n},i:function(t,e){return[t[0]^e[0],t[1]^e[1],t[2]^e[2],t[3]^e[3]]},byteswapM:function(t){for(var e,i=0;i<t.length;++i)e=t[i],t[i]=e>>>24|e>>>8&65280|(65280&e)<<8|e<<24;return t}},b.codec.utf8String={fromBits:function(t){for(var e,i="",n=b.bitArray.bitLength(t),r=0;r<n/8;r++)0==(3&r)&&(e=t[r/4]),i+=String.fromCharCode(e>>>8>>>8>>>8),e<<=8;return decodeURIComponent(escape(i))},toBits:function(t){t=unescape(encodeURIComponent(t));for(var e=[],i=0,n=0;n<t.length;n++)i=i<<8|t.charCodeAt(n),3==(3&n)&&(e.push(i),i=0);return 3&n&&e.push(b.bitArray.partial(8*(3&n),i)),e}},b.codec.hex={fromBits:function(t){for(var e="",i=0;i<t.length;i++)e+=(0xf00000000000+(0|t[i])).toString(16).substr(4);return e.substr(0,b.bitArray.bitLength(t)/4)},toBits:function(t){var e,i=[],n=(t=t.replace(/\s|0x/g,"")).length;for(t+="00000000",e=0;e<t.length;e+=8)i.push(0^parseInt(t.substr(e,8),16));return b.bitArray.clamp(i,4*n)}},b.codec.base32={B:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",X:"0123456789ABCDEFGHIJKLMNOPQRSTUV",BITS:32,BASE:5,REMAINING:27,fromBits:function(t,e,i){var n=b.codec.base32.BASE,r=b.codec.base32.REMAINING,o="",a=0,c=b.codec.base32.B,s=0,h=b.bitArray.bitLength(t);for(i&&(c=b.codec.base32.X),i=0;o.length*n<h;)o+=c.charAt((s^t[i]>>>a)>>>r),a<n?(s=t[i]<<n-a,a+=r,i++):(s<<=n,a-=n);for(;7&o.length&&!e;)o+="=";return o},toBits:function(t,e){t=t.replace(/\s|=/g,"").toUpperCase();var i,n,r=b.codec.base32.BITS,o=b.codec.base32.BASE,a=b.codec.base32.REMAINING,c=[],s=0,h=b.codec.base32.B,l=0,u="base32";for(e&&(h=b.codec.base32.X,u="base32hex"),i=0;i<t.length;i++){if((n=h.indexOf(t.charAt(i)))<0){if(!e)try{return b.codec.base32hex.toBits(t)}catch(t){}throw new b.exception.invalid("this isn't "+u+"!")}a<s?(s-=a,c.push(l^n>>>s),l=n<<r-s):l^=n<<r-(s+=o)}return 56&s&&c.push(b.bitArray.partial(56&s,l,1)),c}},b.codec.base32hex={fromBits:function(t,e){return b.codec.base32.fromBits(t,e,1)},toBits:function(t){return b.codec.base32.toBits(t,1)}},b.codec.base64={B:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fromBits:function(t,e,i){var n="",r=0,o=b.codec.base64.B,a=0,c=b.bitArray.bitLength(t);for(i&&(o=o.substr(0,62)+"-_"),i=0;6*n.length<c;)n+=o.charAt((a^t[i]>>>r)>>>26),r<6?(a=t[i]<<6-r,r+=26,i++):(a<<=6,r-=6);for(;3&n.length&&!e;)n+="=";return n},toBits:function(t,e){t=t.replace(/\s|=/g,"");var i,n,r=[],o=0,a=b.codec.base64.B,c=0;for(e&&(a=a.substr(0,62)+"-_"),i=0;i<t.length;i++){if((n=a.indexOf(t.charAt(i)))<0)throw new b.exception.invalid("this isn't base64!");26<o?(o-=26,r.push(c^n>>>o),c=n<<32-o):c^=n<<32-(o+=6)}return 56&o&&r.push(b.bitArray.partial(56&o,c,1)),r}},b.codec.base64url={fromBits:function(t){return b.codec.base64.fromBits(t,1,1)},toBits:function(t){return b.codec.base64.toBits(t,1)}},b.hash.sha256=function(t){this.b[0]||this.O(),t?(this.F=t.F.slice(0),this.A=t.A.slice(0),this.l=t.l):this.reset()},b.hash.sha256.hash=function(t){return(new b.hash.sha256).update(t).finalize()},b.hash.sha256.prototype={blockSize:512,reset:function(){return this.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(t){"string"==typeof t&&(t=b.codec.utf8String.toBits(t));var e=this.A=b.bitArray.concat(this.A,t);if(r=this.l,9007199254740991<(t=this.l=r+b.bitArray.bitLength(t)))throw new b.exception.invalid("Cannot hash more than 2^53 - 1 bits");if("undefined"!=typeof Uint32Array){for(var i=new Uint32Array(e),n=0,r=512+r-(512+r&511);r<=t;r+=512)l(this,i.subarray(16*n,16*(n+1))),n+=1;e.splice(0,16*n)}else for(r=512+r-(512+r&511);r<=t;r+=512)l(this,e.splice(0,16));return this},finalize:function(){for(var t=this.A,e=this.F,i=(t=b.bitArray.concat(t,[b.bitArray.partial(1,1)])).length+2;15&i;i++)t.push(0);for(t.push(Math.floor(this.l/4294967296)),t.push(0|this.l);t.length;)l(this,t.splice(0,16));return this.reset(),e},Y:[],b:[],O:function(){function t(t){return 4294967296*(t-Math.floor(t))|0}for(var e,i,n=0,r=2;n<64;r++){for(i=!0,e=2;e*e<=r;e++)if(0==r%e){i=!1;break}i&&(n<8&&(this.Y[n]=t(Math.pow(r,.5))),this.b[n]=t(Math.pow(r,1/3)),n++)}}},b.mode.ccm={name:"ccm",G:[],listenProgress:function(t){b.mode.ccm.G.push(t)},unListenProgress:function(t){-1<(t=b.mode.ccm.G.indexOf(t))&&b.mode.ccm.G.splice(t,1)},fa:function(t){for(var e=b.mode.ccm.G.slice(),i=0;i<e.length;i+=1)e[i](t)},encrypt:function(t,e,i,n,r){var o,a=e.slice(0),c=b.bitArray,s=c.bitLength(i)/8,h=c.bitLength(a)/8;if(r=r||64,n=n||[],s<7)throw new b.exception.invalid("ccm: iv must be at least 7 bytes");for(o=2;o<4&&h>>>8*o;o++);return o<15-s&&(o=15-s),i=c.clamp(i,8*(15-o)),e=b.mode.ccm.V(t,e,i,n,r,o),a=b.mode.ccm.C(t,a,i,e,r,o),c.concat(a.data,a.tag)},decrypt:function(t,e,i,n,r){r=r||64,n=n||[];var o=b.bitArray,a=o.bitLength(i)/8,c=o.bitLength(e),s=o.clamp(e,c-r),h=o.bitSlice(e,c-r),c=(c-r)/8;if(a<7)throw new b.exception.invalid("ccm: iv must be at least 7 bytes");for(e=2;e<4&&c>>>8*e;e++);if(e<15-a&&(e=15-a),i=o.clamp(i,8*(15-e)),s=b.mode.ccm.C(t,s,i,h,r,e),t=b.mode.ccm.V(t,s.data,i,n,r,e),!o.equal(s.tag,t))throw new b.exception.corrupt("ccm: tag doesn't match");return s.data},na:function(t,e,i,n,r,o){var a=[],c=b.bitArray,s=c.i;if(n=[c.partial(8,(e.length?64:0)|n-2<<2|o-1)],(n=c.concat(n,i))[3]|=r,n=t.encrypt(n),e.length)for((i=c.bitLength(e)/8)<=65279?a=[c.partial(16,i)]:i<=4294967295&&(a=c.concat([c.partial(16,65534)],[i])),a=c.concat(a,e),e=0;e<a.length;e+=4)n=t.encrypt(s(n,a.slice(e,e+4).concat([0,0,0])));return n},V:function(t,e,i,n,r,o){var a=b.bitArray,c=a.i;if((r/=8)%2||r<4||16<r)throw new b.exception.invalid("ccm: invalid tag length");if(4294967295<n.length||4294967295<e.length)throw new b.exception.bug("ccm: can't deal with 4GiB or more data");for(i=b.mode.ccm.na(t,n,i,r,a.bitLength(e)/8,o),n=0;n<e.length;n+=4)i=t.encrypt(c(i,e.slice(n,n+4).concat([0,0,0])));return a.clamp(i,8*r)},C:function(t,e,i,n,r,o){var a=b.bitArray,c=a.i,s=e.length,h=a.bitLength(e),l=s/50,u=l;if(i=a.concat([a.partial(8,o-1)],i).concat([0,0,0]).slice(0,4),n=a.bitSlice(c(n,t.encrypt(i)),0,r),!s)return{tag:n,data:[]};for(c=0;c<s;c+=4)l<c&&(b.mode.ccm.fa(c/s),l+=u),i[3]++,r=t.encrypt(i),e[c]^=r[0],e[c+1]^=r[1],e[c+2]^=r[2],e[c+3]^=r[3];return{tag:n,data:a.clamp(e,h)}}},b.mode.ocb2={name:"ocb2",encrypt:function(t,e,i,n,r,o){if(128!==b.bitArray.bitLength(i))throw new b.exception.invalid("ocb iv must be 128 bits");var a,c=b.mode.ocb2.S,s=b.bitArray,h=s.i,l=[0,0,0,0];i=c(t.encrypt(i));var u,f=[];for(n=n||[],r=r||64,a=0;a+4<e.length;a+=4)l=h(l,u=e.slice(a,a+4)),f=f.concat(h(i,t.encrypt(h(i,u)))),i=c(i);return u=e.slice(a),e=s.bitLength(u),a=t.encrypt(h(i,[0,0,0,e])),u=s.clamp(h(u.concat([0,0,0]),a),e),l=h(l,h(u.concat([0,0,0]),a)),l=t.encrypt(h(l,h(i,c(i)))),n.length&&(l=h(l,o?n:b.mode.ocb2.pmac(t,n))),f.concat(s.concat(u,s.clamp(l,r)))},decrypt:function(t,e,i,n,r,o){if(128!==b.bitArray.bitLength(i))throw new b.exception.invalid("ocb iv must be 128 bits");r=r||64;var a,c,s=b.mode.ocb2.S,h=b.bitArray,l=h.i,u=[0,0,0,0],f=s(t.encrypt(i)),d=b.bitArray.bitLength(e)-r,p=[];for(n=n||[],i=0;i+4<d/32;i+=4)a=l(f,t.decrypt(l(f,e.slice(i,i+4)))),u=l(u,a),p=p.concat(a),f=s(f);if(c=d-32*i,a=t.encrypt(l(f,[0,0,0,c])),a=l(a,h.clamp(e.slice(i),c).concat([0,0,0])),u=l(u,a),u=t.encrypt(l(u,l(f,s(f)))),n.length&&(u=l(u,o?n:b.mode.ocb2.pmac(t,n))),!h.equal(h.clamp(u,r),h.bitSlice(e,d)))throw new b.exception.corrupt("ocb: tag doesn't match");return p.concat(h.clamp(a,c))},pmac:function(t,e){for(var i=b.mode.ocb2.S,n=b.bitArray,r=n.i,o=[0,0,0,0],a=r(a=t.encrypt([0,0,0,0]),i(i(a))),c=0;c+4<e.length;c+=4)a=i(a),o=r(o,t.encrypt(r(a,e.slice(c,c+4))));return c=e.slice(c),n.bitLength(c)<128&&(a=r(a,i(a)),c=n.concat(c,[-2147483648,0,0,0])),o=r(o,c),t.encrypt(r(i(r(a,i(a))),o))},S:function(t){return[t[0]<<1^t[1]>>>31,t[1]<<1^t[2]>>>31,t[2]<<1^t[3]>>>31,t[3]<<1^135*(t[0]>>>31)]}},b.mode.gcm={name:"gcm",encrypt:function(t,e,i,n,r){var o=e.slice(0);return e=b.bitArray,n=n||[],t=b.mode.gcm.C(!0,t,o,n,i,r||128),e.concat(t.data,t.tag)},decrypt:function(t,e,i,n,r){var o=e.slice(0),a=b.bitArray,c=a.bitLength(o);if(n=n||[],o=(r=r||128)<=c?(e=a.bitSlice(o,c-r),a.bitSlice(o,0,c-r)):(e=o,[]),t=b.mode.gcm.C(!1,t,o,n,i,r),!a.equal(t.tag,e))throw new b.exception.corrupt("gcm: tag doesn't match");return t.data},ka:function(t,e){for(var i,n,r=b.bitArray.i,o=[0,0,0,0],a=e.slice(0),c=0;c<128;c++){for((i=0!=(t[Math.floor(c/32)]&1<<31-c%32))&&(o=r(o,a)),n=0!=(1&a[3]),i=3;0<i;i--)a[i]=a[i]>>>1|(1&a[i-1])<<31;a[0]>>>=1,n&&(a[0]^=-520093696)}return o},j:function(t,e,i){var n,r=i.length;for(e=e.slice(0),n=0;n<r;n+=4)e[0]^=4294967295&i[n],e[1]^=4294967295&i[n+1],e[2]^=4294967295&i[n+2],e[3]^=4294967295&i[n+3],e=b.mode.gcm.ka(e,t);return e},C:function(t,e,i,n,r,o){var a,c,s,h=b.bitArray,l=i.length,u=h.bitLength(i),f=h.bitLength(n),d=h.bitLength(r),p=e.encrypt([0,0,0,0]);for(r=96===d?(r=r.slice(0),h.concat(r,[1])):(r=b.mode.gcm.j(p,[0,0,0,0],r),b.mode.gcm.j(p,r,[0,0,Math.floor(d/4294967296),4294967295&d])),d=b.mode.gcm.j(p,[0,0,0,0],n),s=r.slice(0),n=d.slice(0),t||(n=b.mode.gcm.j(p,d,i)),c=0;c<l;c+=4)s[3]++,a=e.encrypt(s),i[c]^=a[0],i[c+1]^=a[1],i[c+2]^=a[2],i[c+3]^=a[3];return i=h.clamp(i,u),t&&(n=b.mode.gcm.j(p,d,i)),t=[Math.floor(f/4294967296),4294967295&f,Math.floor(u/4294967296),4294967295&u],n=b.mode.gcm.j(p,n,t),a=e.encrypt(r),n[0]^=a[0],n[1]^=a[1],n[2]^=a[2],n[3]^=a[3],{tag:h.bitSlice(n,0,o),data:i}}},b.misc.hmac=function(t,e){this.W=e=e||b.hash.sha256;var i,n=[[],[]],r=e.prototype.blockSize/32;for(this.w=[new e,new e],t.length>r&&(t=e.hash(t)),i=0;i<r;i++)n[0][i]=909522486^t[i],n[1][i]=1549556828^t[i];this.w[0].update(n[0]),this.w[1].update(n[1]),this.R=new e(this.w[0])},b.misc.hmac.prototype.encrypt=b.misc.hmac.prototype.mac=function(t){if(this.aa)throw new b.exception.invalid("encrypt on already updated hmac called!");return this.update(t),this.digest(t)},b.misc.hmac.prototype.reset=function(){this.R=new this.W(this.w[0]),this.aa=!1},b.misc.hmac.prototype.update=function(t){this.aa=!0,this.R.update(t)},b.misc.hmac.prototype.digest=function(){var t=this.R.finalize(),t=new this.W(this.w[1]).update(t).finalize();return this.reset(),t},b.misc.pbkdf2=function(t,e,i,n,r){if(i=i||1e4,n<0||i<0)throw new b.exception.invalid("invalid params to pbkdf2");"string"==typeof t&&(t=b.codec.utf8String.toBits(t)),"string"==typeof e&&(e=b.codec.utf8String.toBits(e)),t=new(r=r||b.misc.hmac)(t);for(var o,a,c,s=[],h=b.bitArray,l=1;32*s.length<(n||1);l++){for(r=o=t.encrypt(h.concat(e,[l])),a=1;a<i;a++)for(o=t.encrypt(o),c=0;c<o.length;c++)r[c]^=o[c];s=s.concat(r)}return n&&(s=h.clamp(s,n)),s},b.prng=function(t){this.c=[new b.hash.sha256],this.m=[0],this.P=0,this.H={},this.N=0,this.U={},this.Z=this.f=this.o=this.ha=0,this.b=[0,0,0,0,0,0,0,0],this.h=[0,0,0,0],this.L=void 0,this.M=t,this.D=!1,this.K={progress:{},seeded:{}},this.u=this.ga=0,this.I=1,this.J=2,this.ca=65536,this.T=[0,48,64,96,128,192,256,384,512,768,1024],this.da=3e4,this.ba=80},b.prng.prototype={randomWords:function(t,e){var i,n=[],r=this.isReady(e);if(r===this.u)throw new b.exception.notReady("generator isn't seeded");if(r&this.J){r=!(r&this.I),i=[];var o,a=0;for(this.Z=i[0]=(new Date).valueOf()+this.da,o=0;o<16;o++)i.push(4294967296*Math.random()|0);for(o=0;o<this.c.length&&(i=i.concat(this.c[o].finalize()),a+=this.m[o],this.m[o]=0,r||!(this.P&1<<o));o++);for(this.P>=1<<this.c.length&&(this.c.push(new b.hash.sha256),this.m.push(0)),this.f-=a,a>this.o&&(this.o=a),this.P++,this.b=b.hash.sha256.hash(this.b.concat(i)),this.L=new b.cipher.aes(this.b),r=0;r<4&&(this.h[r]=this.h[r]+1|0,!this.h[r]);r++);}for(r=0;r<t;r+=4)0==(r+1)%this.ca&&d(this),i=p(this),n.push(i[0],i[1],i[2],i[3]);return d(this),n.slice(0,t)},setDefaultParanoia:function(t,e){if(0===t&&"Setting paranoia=0 will ruin your security; use it only for testing"!==e)throw new b.exception.invalid("Setting paranoia=0 will ruin your security; use it only for testing");this.M=t},addEntropy:function(t,e,i){i=i||"user";var n,r=(new Date).valueOf(),o=this.H[i],a=this.isReady(),c=0,s=this.U[i];switch(void 0===s&&(s=this.U[i]=this.ha++),void 0===o&&(o=this.H[i]=0),this.H[i]=(this.H[i]+1)%this.c.length,typeof t){case"number":void 0===e&&(e=1),this.c[o].update([s,this.N++,1,e,r,1,0|t]);break;case"object":if("[object Uint32Array]"===(i=Object.prototype.toString.call(t))){for(n=[],i=0;i<t.length;i++)n.push(t[i]);t=n}else for("[object Array]"!==i&&(c=1),i=0;i<t.length&&!c;i++)"number"!=typeof t[i]&&(c=1);if(!c){if(void 0===e)for(i=e=0;i<t.length;i++)for(n=t[i];0<n;)e++,n>>>=1;this.c[o].update([s,this.N++,2,e,r,t.length].concat(t))}break;case"string":void 0===e&&(e=t.length),this.c[o].update([s,this.N++,3,e,r,t.length]),this.c[o].update(t);break;default:c=1}if(c)throw new b.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[o]+=e,this.f+=e,a===this.u&&(this.isReady()!==this.u&&u("seeded",Math.max(this.o,this.f)),u("progress",this.getProgress()))},isReady:function(t){return t=this.T[void 0!==t?t:this.M],this.o&&this.o>=t?this.m[0]>this.ba&&(new Date).valueOf()>this.Z?this.J|this.I:this.I:this.f>=t?this.J|this.u:this.u},getProgress:function(t){return t=this.T[t||this.M],this.o>=t||this.f>t?1:this.f/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:m(this,this.ma),mouseCollector:m(this,this.oa),keyboardCollector:m(this,this.la),accelerometerCollector:m(this,this.ea),touchCollector:m(this,this.qa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else{if(!document.attachEvent)throw new b.exception.bug("can't attach event");document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector)}this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(t,e){this.K[t][this.ga++]=e},removeEventListener:function(t,e){var i,n,r=this.K[t],o=[];for(n in r)r.hasOwnProperty(n)&&r[n]===e&&o.push(n);for(i=0;i<o.length;i++)delete r[n=o[i]]},la:function(){f(this,1)},oa:function(t){var e,i;try{e=t.x||t.clientX||t.offsetX||0,i=t.y||t.clientY||t.offsetY||0}catch(t){i=e=0}0!=e&&0!=i&&this.addEntropy([e,i],2,"mouse"),f(this,0)},qa:function(t){t=t.touches[0]||t.changedTouches[0],this.addEntropy([t.pageX||t.clientX,t.pageY||t.clientY],1,"touch"),f(this,0)},ma:function(){f(this,2)},ea:function(t){var e;t=t.accelerationIncludingGravity.x||t.accelerationIncludingGravity.y||t.accelerationIncludingGravity.z,!window.orientation||"number"==typeof(e=window.orientation)&&this.addEntropy(e,1,"accelerometer"),t&&this.addEntropy(t,2,"accelerometer"),f(this,0)}},b.random=new b.prng(6);t:try{if(c=t.exports){try{s=null}catch(t){s=null}c=o=s}if(c&&o.randomBytes)r=o.randomBytes(128),r=new Uint32Array(new Uint8Array(r).buffer),b.random.addEntropy(r,1024,"crypto['randomBytes']");else if("undefined"!=typeof window&&"undefined"!=typeof Uint32Array){if(a=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(a);else{if(!window.msCrypto||!window.msCrypto.getRandomValues)break t;window.msCrypto.getRandomValues(a)}b.random.addEntropy(a,1024,"crypto['getRandomValues']")}}catch(t){"undefined"!=typeof window&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(t))}b.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(t,e,i,n){i=i||{},n=n||{};var r,o=b.json,a=o.g({iv:b.random.randomWords(4,0)},o.defaults);if(o.g(a,i),i=a.adata,"string"==typeof a.salt&&(a.salt=b.codec.base64.toBits(a.salt)),"string"==typeof a.iv&&(a.iv=b.codec.base64.toBits(a.iv)),!b.mode[a.mode]||!b.cipher[a.cipher]||"string"==typeof t&&a.iter<=100||64!==a.ts&&96!==a.ts&&128!==a.ts||128!==a.ks&&192!==a.ks&&256!==a.ks||a.iv.length<2||4<a.iv.length)throw new b.exception.invalid("json encrypt: invalid parameters");return"string"==typeof t?(t=(r=b.misc.cachedPbkdf2(t,a)).key.slice(0,a.ks/32),a.salt=r.salt):b.ecc&&t instanceof b.ecc.elGamal.publicKey&&(r=t.kem(),a.kemtag=r.tag,t=r.key.slice(0,a.ks/32)),"string"==typeof e&&(e=b.codec.utf8String.toBits(e)),"string"==typeof i&&(a.adata=i=b.codec.utf8String.toBits(i)),r=new b.cipher[a.cipher](t),o.g(n,a),n.key=t,a.ct="ccm"===a.mode&&b.arrayBuffer&&b.arrayBuffer.ccm&&e instanceof ArrayBuffer?b.arrayBuffer.ccm.encrypt(r,e,a.iv,i,a.ts):b.mode[a.mode].encrypt(r,e,a.iv,i,a.ts),a},encrypt:function(t,e,i,n){var r=b.json,o=r.ja.apply(r,arguments);return r.encode(o)},ia:function(t,e,i,n){i=i||{},n=n||{};var r,o=b.json,a=(e=o.g(o.g(o.g({},o.defaults),e),i,!0)).adata;if("string"==typeof e.salt&&(e.salt=b.codec.base64.toBits(e.salt)),"string"==typeof e.iv&&(e.iv=b.codec.base64.toBits(e.iv)),!b.mode[e.mode]||!b.cipher[e.cipher]||"string"==typeof t&&e.iter<=100||64!==e.ts&&96!==e.ts&&128!==e.ts||128!==e.ks&&192!==e.ks&&256!==e.ks||!e.iv||e.iv.length<2||4<e.iv.length)throw new b.exception.invalid("json decrypt: invalid parameters");return"string"==typeof t?(t=(r=b.misc.cachedPbkdf2(t,e)).key.slice(0,e.ks/32),e.salt=r.salt):b.ecc&&t instanceof b.ecc.elGamal.secretKey&&(t=t.unkem(b.codec.base64.toBits(e.kemtag)).slice(0,e.ks/32)),"string"==typeof a&&(a=b.codec.utf8String.toBits(a)),r=new b.cipher[e.cipher](t),a="ccm"===e.mode&&b.arrayBuffer&&b.arrayBuffer.ccm&&e.ct instanceof ArrayBuffer?b.arrayBuffer.ccm.decrypt(r,e.ct,e.iv,e.tag,a,e.ts):b.mode[e.mode].decrypt(r,e.ct,e.iv,a,e.ts),o.g(n,e),n.key=t,1===i.raw?a:b.codec.utf8String.fromBits(a)},decrypt:function(t,e,i,n){var r=b.json;return r.ia(t,r.decode(e),i,n)},encode:function(t){var e,i="{",n="";for(e in t)if(t.hasOwnProperty(e)){if(!e.match(/^[a-z0-9]+$/i))throw new b.exception.invalid("json encode: invalid property name");switch(i+=n+'"'+e+'":',n=",",typeof t[e]){case"number":case"boolean":i+=t[e];break;case"string":i+='"'+escape(t[e])+'"';break;case"object":i+='"'+b.codec.base64.fromBits(t[e],0)+'"';break;default:throw new b.exception.bug("json encode: unsupported type")}}return i+"}"},decode:function(t){if(!(t=t.replace(/\s/g,"")).match(/^\{.*\}$/))throw new b.exception.invalid("json decode: this isn't json!");t=t.replace(/^\{|\}$/g,"").split(/,/);for(var e,i={},n=0;n<t.length;n++){if(!(e=t[n].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i)))throw new b.exception.invalid("json decode: this isn't json!");null!=e[3]?i[e[2]]=parseInt(e[3],10):null!=e[4]?i[e[2]]=e[2].match(/^(ct|adata|salt|iv)$/)?b.codec.base64.toBits(e[4]):unescape(e[4]):null!=e[5]&&(i[e[2]]="true"===e[5])}return i},g:function(t,e,i){if(void 0===t&&(t={}),void 0===e)return t;for(var n in e)if(e.hasOwnProperty(n)){if(i&&void 0!==t[n]&&t[n]!==e[n])throw new b.exception.invalid("required parameter overridden");t[n]=e[n]}return t},sa:function(t,e){var i,n={};for(i in t)t.hasOwnProperty(i)&&t[i]!==e[i]&&(n[i]=t[i]);return n},ra:function(t,e){for(var i={},n=0;n<e.length;n++)void 0!==t[e[n]]&&(i[e[n]]=t[e[n]]);return i}},b.encrypt=b.json.encrypt,b.decrypt=b.json.decrypt,b.misc.pa={},b.misc.cachedPbkdf2=function(t,e){var i=b.misc.pa,n=(e=e||{}).iter||1e3;return(n=(i=i[t]=i[t]||{})[n]=i[n]||{firstSalt:e.salt&&e.salt.length?e.salt.slice(0):b.random.randomWords(2,0)})[i=void 0===e.salt?n.firstSalt:e.salt]=n[i]||b.misc.pbkdf2(t,i,e.iter),{key:n[i].slice(0),salt:i.slice(0)}},t.exports&&(t.exports=b),void 0===(n=function(){return b}.apply(e,[]))||(t.exports=n)}],r.c=n,r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(i,n,function(t){return e[t]}.bind(null,n));return i},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0);function r(t){if(n[t])return n[t].exports;var e=n[t]={i:t,l:!1,exports:{}};return i[t].call(e.exports,e,e.exports,r),e.l=!0,e.exports}var i,n});