-
Notifications
You must be signed in to change notification settings - Fork 14
/
sjcl.js
51 lines (51 loc) · 21.9 KB
/
sjcl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"use strict";function r(a){throw a;}var s=void 0,v=!1;function H(){return function(){}}
var sjcl={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(a){this.toString=function(){return"CORRUPT: "+this.message};this.message=a},invalid:function(a){this.toString=function(){return"INVALID: "+this.message};this.message=a},bug:function(a){this.toString=function(){return"BUG: "+this.message};this.message=a},notReady:function(a){this.toString=function(){return"NOT READY: "+this.message};this.message=a}}};
"undefined"!==typeof module&&module.exports&&(module.exports=sjcl);"function"===typeof define&&define([],function(){return sjcl});
sjcl.cipher.aes=function(a){this.l[0][0][0]||this.q();var b,c,d,e,g=this.l[0][4],f=this.l[1];b=a.length;var h=1;4!==b&&(6!==b&&8!==b)&&r(new sjcl.exception.invalid("invalid aes key size"));this.b=[d=a.slice(0),e=[]];for(a=b;a<4*b+28;a++){c=d[a-1];if(0===a%b||8===b&&4===a%b)c=g[c>>>24]<<24^g[c>>16&255]<<16^g[c>>8&255]<<8^g[c&255],0===a%b&&(c=c<<8^c>>>24^h<<24,h=h<<1^283*(h>>7));d[a]=d[a-b]^c}for(b=0;a;b++,a--)c=d[b&3?a:a-4],e[b]=4>=a||4>b?c:f[0][g[c>>>24]]^f[1][g[c>>16&255]]^f[2][g[c>>8&255]]^f[3][g[c&
255]]};
sjcl.cipher.aes.prototype={encrypt:function(a){return aa(this,a,0)},decrypt:function(a){return aa(this,a,1)},l:[[[],[],[],[],[]],[[],[],[],[],[]]],q:function(){var a=this.l[0],b=this.l[1],c=a[4],d=b[4],e,g,f,h=[],k=[],n,l,m,p;for(e=0;0x100>e;e++)k[(h[e]=e<<1^283*(e>>7))^e]=e;for(g=f=0;!c[g];g^=n||1,f=k[f]||1){m=f^f<<1^f<<2^f<<3^f<<4;m=m>>8^m&255^99;c[g]=m;d[m]=g;l=h[e=h[n=h[g]]];p=0x1010101*l^0x10001*e^0x101*n^0x1010100*g;l=0x101*h[m]^0x1010100*m;for(e=0;4>e;e++)a[e][g]=l=l<<24^l>>>8,b[e][m]=p=p<<24^p>>>8}for(e=
0;5>e;e++)a[e]=a[e].slice(0),b[e]=b[e].slice(0)}};
function aa(a,b,c){4!==b.length&&r(new sjcl.exception.invalid("invalid aes block size"));var d=a.b[c],e=b[0]^d[0],g=b[c?3:1]^d[1],f=b[2]^d[2];b=b[c?1:3]^d[3];var h,k,n,l=d.length/4-2,m,p=4,w=[0,0,0,0];h=a.l[c];a=h[0];var D=h[1],B=h[2],E=h[3],C=h[4];for(m=0;m<l;m++)h=a[e>>>24]^D[g>>16&255]^B[f>>8&255]^E[b&255]^d[p],k=a[g>>>24]^D[f>>16&255]^B[b>>8&255]^E[e&255]^d[p+1],n=a[f>>>24]^D[b>>16&255]^B[e>>8&255]^E[g&255]^d[p+2],b=a[b>>>24]^D[e>>16&255]^B[g>>8&255]^E[f&255]^d[p+3],p+=4,e=h,g=k,f=n;for(m=0;4>
m;m++)w[c?3&-m:m]=C[e>>>24]<<24^C[g>>16&255]<<16^C[f>>8&255]<<8^C[b&255]^d[p++],h=e,e=g,g=f,f=b,b=h;return w}
sjcl.bitArray={bitSlice:function(a,b,c){a=sjcl.bitArray.M(a.slice(b/32),32-(b&31)).slice(1);return c===s?a:sjcl.bitArray.clamp(a,c-b)},extract:function(a,b,c){var d=Math.floor(-b-c&31);return((b+c-1^b)&-32?a[b/32|0]<<32-d^a[b/32+1|0]>>>d:a[b/32|0]>>>d)&(1<<c)-1},concat:function(a,b){if(0===a.length||0===b.length)return a.concat(b);var c=a[a.length-1],d=sjcl.bitArray.getPartial(c);return 32===d?a.concat(b):sjcl.bitArray.M(b,d,c|0,a.slice(0,a.length-1))},bitLength:function(a){var b=a.length;return 0===
b?0:32*(b-1)+sjcl.bitArray.getPartial(a[b-1])},clamp:function(a,b){if(32*a.length<b)return a;a=a.slice(0,Math.ceil(b/32));var c=a.length;b&=31;0<c&&b&&(a[c-1]=sjcl.bitArray.partial(b,a[c-1]&2147483648>>b-1,1));return a},partial:function(a,b,c){return 32===a?b:(c?b|0:b<<32-a)+0x10000000000*a},getPartial:function(a){return Math.round(a/0x10000000000)||32},equal:function(a,b){if(sjcl.bitArray.bitLength(a)!==sjcl.bitArray.bitLength(b))return v;var c=0,d;for(d=0;d<a.length;d++)c|=a[d]^b[d];return 0===
c},M:function(a,b,c,d){var e;e=0;for(d===s&&(d=[]);32<=b;b-=32)d.push(c),c=0;if(0===b)return d.concat(a);for(e=0;e<a.length;e++)d.push(c|a[e]>>>b),c=a[e]<<32-b;e=a.length?a[a.length-1]:0;a=sjcl.bitArray.getPartial(e);d.push(sjcl.bitArray.partial(b+a&31,32<b+a?c:d.pop(),1));return d},u:function(a,b){return[a[0]^b[0],a[1]^b[1],a[2]^b[2],a[3]^b[3]]},byteswapM:function(a){var b,c;for(b=0;b<a.length;++b)c=a[b],a[b]=c>>>24|c>>>8&0xff00|(c&0xff00)<<8|c<<24;return a}};
sjcl.codec.utf8String={fromBits:function(a){var b="",c=sjcl.bitArray.bitLength(a),d,e;for(d=0;d<c/8;d++)0===(d&3)&&(e=a[d/4]),b+=String.fromCharCode(e>>>24),e<<=8;return decodeURIComponent(escape(b))},toBits:function(a){a=unescape(encodeURIComponent(a));var b=[],c,d=0;for(c=0;c<a.length;c++)d=d<<8|a.charCodeAt(c),3===(c&3)&&(b.push(d),d=0);c&3&&b.push(sjcl.bitArray.partial(8*(c&3),d));return b}};
sjcl.codec.base64={I:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fromBits:function(a,b,c){var d="",e=0,g=sjcl.codec.base64.I,f=0,h=sjcl.bitArray.bitLength(a);c&&(g=g.substr(0,62)+"-_");for(c=0;6*d.length<h;)d+=g.charAt((f^a[c]>>>e)>>>26),6>e?(f=a[c]<<6-e,e+=26,c++):(f<<=6,e-=6);for(;d.length&3&&!b;)d+="=";return d},toBits:function(a,b){a=a.replace(/\s|=/g,"");var c=[],d,e=0,g=sjcl.codec.base64.I,f=0,h;b&&(g=g.substr(0,62)+"-_");for(d=0;d<a.length;d++)h=g.indexOf(a.charAt(d)),
0>h&&r(new sjcl.exception.invalid("this isn't base64!")),26<e?(e-=26,c.push(f^h>>>e),f=h<<32-e):(e+=6,f^=h<<32-e);e&56&&c.push(sjcl.bitArray.partial(e&56,f,1));return c}};sjcl.codec.base64url={fromBits:function(a){return sjcl.codec.base64.fromBits(a,1,1)},toBits:function(a){return sjcl.codec.base64.toBits(a,1)}};
sjcl.codec.bytes={fromBits:function(a){var b=[],c=sjcl.bitArray.bitLength(a),d,e;for(d=0;d<c/8;d++)0===(d&3)&&(e=a[d/4]),b.push(e>>>24),e<<=8;return b},toBits:function(a){var b=[],c,d=0;for(c=0;c<a.length;c++)d=d<<8|a[c],3===(c&3)&&(b.push(d),d=0);c&3&&b.push(sjcl.bitArray.partial(8*(c&3),d));return b}};sjcl.hash.sha256=function(a){this.b[0]||this.q();a?(this.e=a.e.slice(0),this.d=a.d.slice(0),this.c=a.c):this.reset()};sjcl.hash.sha256.hash=function(a){return(new sjcl.hash.sha256).update(a).finalize()};
sjcl.hash.sha256.prototype={blockSize:512,reset:function(){this.e=this.i.slice(0);this.d=[];this.c=0;return this},update:function(a){"string"===typeof a&&(a=sjcl.codec.utf8String.toBits(a));var b,c=this.d=sjcl.bitArray.concat(this.d,a);b=this.c;a=this.c=b+sjcl.bitArray.bitLength(a);for(b=512+b&-512;b<=a;b+=512)this.n(c.splice(0,16));return this},finalize:function(){var a,b=this.d,c=this.e,b=sjcl.bitArray.concat(b,[sjcl.bitArray.partial(1,1)]);for(a=b.length+2;a&15;a++)b.push(0);b.push(Math.floor(this.c/
4294967296));for(b.push(this.c|0);b.length;)this.n(b.splice(0,16));this.reset();return c},i:[],b:[],q:function(){function a(a){return 0x100000000*(a-Math.floor(a))|0}var b=0,c=2,d;a:for(;64>b;c++){for(d=2;d*d<=c;d++)if(0===c%d)continue a;8>b&&(this.i[b]=a(Math.pow(c,0.5)));this.b[b]=a(Math.pow(c,1/3));b++}},n:function(a){var b,c,d=a.slice(0),e=this.e,g=this.b,f=e[0],h=e[1],k=e[2],n=e[3],l=e[4],m=e[5],p=e[6],w=e[7];for(a=0;64>a;a++)16>a?b=d[a]:(b=d[a+1&15],c=d[a+14&15],b=d[a&15]=(b>>>7^b>>>18^b>>>3^
b<<25^b<<14)+(c>>>17^c>>>19^c>>>10^c<<15^c<<13)+d[a&15]+d[a+9&15]|0),b=b+w+(l>>>6^l>>>11^l>>>25^l<<26^l<<21^l<<7)+(p^l&(m^p))+g[a],w=p,p=m,m=l,l=n+b|0,n=k,k=h,h=f,f=b+(h&k^n&(h^k))+(h>>>2^h>>>13^h>>>22^h<<30^h<<19^h<<10)|0;e[0]=e[0]+f|0;e[1]=e[1]+h|0;e[2]=e[2]+k|0;e[3]=e[3]+n|0;e[4]=e[4]+l|0;e[5]=e[5]+m|0;e[6]=e[6]+p|0;e[7]=e[7]+w|0}};sjcl.hash.sha512=function(a){this.b[0]||this.q();a?(this.e=a.e.slice(0),this.d=a.d.slice(0),this.c=a.c):this.reset()};sjcl.hash.sha512.hash=function(a){return(new sjcl.hash.sha512).update(a).finalize()};
sjcl.hash.sha512.prototype={blockSize:1024,reset:function(){this.e=this.i.slice(0);this.d=[];this.c=0;return this},update:function(a){"string"===typeof a&&(a=sjcl.codec.utf8String.toBits(a));var b,c=this.d=sjcl.bitArray.concat(this.d,a);b=this.c;a=this.c=b+sjcl.bitArray.bitLength(a);for(b=1024+b&-1024;b<=a;b+=1024)this.n(c.splice(0,32));return this},finalize:function(){var a,b=this.d,c=this.e,b=sjcl.bitArray.concat(b,[sjcl.bitArray.partial(1,1)]);for(a=b.length+4;a&31;a++)b.push(0);b.push(0);b.push(0);
b.push(Math.floor(this.c/0x100000000));for(b.push(this.c|0);b.length;)this.n(b.splice(0,32));this.reset();return c},i:[],T:[12372232,13281083,9762859,1914609,15106769,4090911,4308331,8266105],b:[],V:[2666018,15689165,5061423,9034684,4764984,380953,1658779,7176472,197186,7368638,14987916,16757986,8096111,1480369,13046325,6891156,15813330,5187043,9229749,11312229,2818677,10937475,4324308,1135541,6741931,11809296,16458047,15666916,11046850,698149,229999,945776,13774844,2541862,12856045,9810911,11494366,
7844520,15576806,8533307,15795044,4337665,16291729,5553712,15684120,6662416,7413802,12308920,13816008,4303699,9366425,10176680,13195875,4295371,6546291,11712675,15708924,1519456,15772530,6568428,6495784,8568297,13007125,7492395,2515356,12632583,14740254,7262584,1535930,13146278,16321966,1853211,294276,13051027,13221564,1051980,4080310,6651434,14088940,4675607],q:function(){function a(a){return 0x100000000*(a-Math.floor(a))|0}function b(a){return 0x10000000000*(a-Math.floor(a))&255}var c=0,d=2,e;a:for(;80>
c;d++){for(e=2;e*e<=d;e++)if(0===d%e)continue a;8>c&&(this.i[2*c]=a(Math.pow(d,0.5)),this.i[2*c+1]=b(Math.pow(d,0.5))<<24|this.T[c]);this.b[2*c]=a(Math.pow(d,1/3));this.b[2*c+1]=b(Math.pow(d,1/3))<<24|this.V[c];c++}},n:function(a){var b,c,d=a.slice(0),e=this.e,g=this.b,f=e[0],h=e[1],k=e[2],n=e[3],l=e[4],m=e[5],p=e[6],w=e[7],D=e[8],B=e[9],E=e[10],C=e[11],ga=e[12],R=e[13],ha=e[14],S=e[15],x=f,t=h,I=k,F=n,J=l,G=m,X=p,K=w,y=D,u=B,T=E,L=C,U=ga,M=R,Y=ha,N=S;for(a=0;80>a;a++){if(16>a)b=d[2*a],c=d[2*a+1];
else{c=d[2*(a-15)];var q=d[2*(a-15)+1];b=(q<<31|c>>>1)^(q<<24|c>>>8)^c>>>7;var z=(c<<31|q>>>1)^(c<<24|q>>>8)^(c<<25|q>>>7);c=d[2*(a-2)];var A=d[2*(a-2)+1],q=(A<<13|c>>>19)^(c<<3|A>>>29)^c>>>6,A=(c<<13|A>>>19)^(A<<3|c>>>29)^(c<<26|A>>>6),Z=d[2*(a-7)],$=d[2*(a-16)],O=d[2*(a-16)+1];c=z+d[2*(a-7)+1];b=b+Z+(c>>>0<z>>>0?1:0);c+=A;b+=q+(c>>>0<A>>>0?1:0);c+=O;b+=$+(c>>>0<O>>>0?1:0)}d[2*a]=b|=0;d[2*a+1]=c|=0;var Z=y&T^~y&U,ia=u&L^~u&M,A=x&I^x&J^I&J,ma=t&F^t&G^F&G,$=(t<<4|x>>>28)^(x<<30|t>>>2)^(x<<25|t>>>7),
O=(x<<4|t>>>28)^(t<<30|x>>>2)^(t<<25|x>>>7),na=g[2*a],ja=g[2*a+1],q=N+((y<<18|u>>>14)^(y<<14|u>>>18)^(u<<23|y>>>9)),z=Y+((u<<18|y>>>14)^(u<<14|y>>>18)^(y<<23|u>>>9))+(q>>>0<N>>>0?1:0),q=q+ia,z=z+(Z+(q>>>0<ia>>>0?1:0)),q=q+ja,z=z+(na+(q>>>0<ja>>>0?1:0)),q=q+c|0,z=z+(b+(q>>>0<c>>>0?1:0));c=O+ma;b=$+A+(c>>>0<O>>>0?1:0);Y=U;N=M;U=T;M=L;T=y;L=u;u=K+q|0;y=X+z+(u>>>0<K>>>0?1:0)|0;X=J;K=G;J=I;G=F;I=x;F=t;t=q+c|0;x=z+b+(t>>>0<q>>>0?1:0)|0}h=e[1]=h+t|0;e[0]=f+x+(h>>>0<t>>>0?1:0)|0;n=e[3]=n+F|0;e[2]=k+I+(n>>>
0<F>>>0?1:0)|0;m=e[5]=m+G|0;e[4]=l+J+(m>>>0<G>>>0?1:0)|0;w=e[7]=w+K|0;e[6]=p+X+(w>>>0<K>>>0?1:0)|0;B=e[9]=B+u|0;e[8]=D+y+(B>>>0<u>>>0?1:0)|0;C=e[11]=C+L|0;e[10]=E+T+(C>>>0<L>>>0?1:0)|0;R=e[13]=R+M|0;e[12]=ga+U+(R>>>0<M>>>0?1:0)|0;S=e[15]=S+N|0;e[14]=ha+Y+(S>>>0<N>>>0?1:0)|0}};
sjcl.mode.ccm={name:"ccm",s:[],listenProgress:function(a){sjcl.mode.ccm.s.push(a)},unListenProgress:function(a){a=sjcl.mode.ccm.s.indexOf(a);-1<a&&sjcl.mode.ccm.s.splice(a,1)},H:function(a){var b=sjcl.mode.ccm.s.slice(),c;for(c=0;c<b.length;c+=1)b[c](a)},encrypt:function(a,b,c,d,e){var g,f=b.slice(0),h=sjcl.bitArray,k=h.bitLength(c)/8,n=h.bitLength(f)/8;e=e||64;d=d||[];7>k&&r(new sjcl.exception.invalid("ccm: iv must be at least 7 bytes"));for(g=2;4>g&&n>>>8*g;g++);g<15-k&&(g=15-k);c=h.clamp(c,8*(15-
g));b=sjcl.mode.ccm.o(a,b,c,d,e,g);f=sjcl.mode.ccm.p(a,f,c,b,e,g);return h.concat(f.data,f.tag)},decrypt:function(a,b,c,d,e){e=e||64;d=d||[];var g=sjcl.bitArray,f=g.bitLength(c)/8,h=g.bitLength(b),k=g.clamp(b,h-e),n=g.bitSlice(b,h-e),h=(h-e)/8;7>f&&r(new sjcl.exception.invalid("ccm: iv must be at least 7 bytes"));for(b=2;4>b&&h>>>8*b;b++);b<15-f&&(b=15-f);c=g.clamp(c,8*(15-b));k=sjcl.mode.ccm.p(a,k,c,n,e,b);a=sjcl.mode.ccm.o(a,k.data,c,d,e,b);g.equal(k.tag,a)||r(new sjcl.exception.corrupt("ccm: tag doesn't match"));
return k.data},K:function(a,b,c,d,e,g){var f=[],h=sjcl.bitArray,k=h.u;d=[h.partial(8,(b.length?64:0)|d-2<<2|g-1)];d=h.concat(d,c);d[3]|=e;d=a.encrypt(d);if(b.length){c=h.bitLength(b)/8;65279>=c?f=[h.partial(16,c)]:0xffffffff>=c&&(f=h.concat([h.partial(16,65534)],[c]));f=h.concat(f,b);for(b=0;b<f.length;b+=4)d=a.encrypt(k(d,f.slice(b,b+4).concat([0,0,0])))}return d},o:function(a,b,c,d,e,g){var f=sjcl.bitArray,h=f.u;e/=8;(e%2||4>e||16<e)&&r(new sjcl.exception.invalid("ccm: invalid tag length"));(0xffffffff<
d.length||0xffffffff<b.length)&&r(new sjcl.exception.bug("ccm: can't deal with 4GiB or more data"));c=sjcl.mode.ccm.K(a,d,c,e,f.bitLength(b)/8,g);for(d=0;d<b.length;d+=4)c=a.encrypt(h(c,b.slice(d,d+4).concat([0,0,0])));return f.clamp(c,8*e)},p:function(a,b,c,d,e,g){var f,h=sjcl.bitArray;f=h.u;var k=b.length,n=h.bitLength(b),l=k/50,m=l;c=h.concat([h.partial(8,g-1)],c).concat([0,0,0]).slice(0,4);d=h.bitSlice(f(d,a.encrypt(c)),0,e);if(!k)return{tag:d,data:[]};for(f=0;f<k;f+=4)f>l&&(sjcl.mode.ccm.H(f/
k),l+=m),c[3]++,e=a.encrypt(c),b[f]^=e[0],b[f+1]^=e[1],b[f+2]^=e[2],b[f+3]^=e[3];return{tag:d,data:h.clamp(b,n)}}};sjcl.prng=function(a){this.f=[new sjcl.hash.sha256];this.j=[0];this.F=0;this.t={};this.D=0;this.J={};this.L=this.g=this.k=this.S=0;this.b=[0,0,0,0,0,0,0,0];this.h=[0,0,0,0];this.B=s;this.C=a;this.r=v;this.A={progress:{},seeded:{}};this.m=this.R=0;this.v=1;this.w=2;this.O=0x10000;this.G=[0,48,64,96,128,192,0x100,384,512,768,1024];this.P=3E4;this.N=80};
sjcl.prng.prototype={randomWords:function(a,b){var c=[],d;d=this.isReady(b);var e;d===this.m&&r(new sjcl.exception.notReady("generator isn't seeded"));if(d&this.w){d=!(d&this.v);e=[];var g=0,f;this.L=e[0]=(new Date).valueOf()+this.P;for(f=0;16>f;f++)e.push(0x100000000*Math.random()|0);for(f=0;f<this.f.length&&!(e=e.concat(this.f[f].finalize()),g+=this.j[f],this.j[f]=0,!d&&this.F&1<<f);f++);this.F>=1<<this.f.length&&(this.f.push(new sjcl.hash.sha256),this.j.push(0));this.g-=g;g>this.k&&(this.k=g);this.F++;
this.b=sjcl.hash.sha256.hash(this.b.concat(e));this.B=new sjcl.cipher.aes(this.b);for(d=0;4>d&&!(this.h[d]=this.h[d]+1|0,this.h[d]);d++);}for(d=0;d<a;d+=4)0===(d+1)%this.O&&ba(this),e=ca(this),c.push(e[0],e[1],e[2],e[3]);ba(this);return c.slice(0,a)},setDefaultParanoia:function(a,b){0===a&&"Setting paranoia=0 will ruin your security; use it only for testing"!==b&&r("Setting paranoia=0 will ruin your security; use it only for testing");this.C=a},addEntropy:function(a,b,c){c=c||"user";var d,e,g=(new Date).valueOf(),
f=this.t[c],h=this.isReady(),k=0;d=this.J[c];d===s&&(d=this.J[c]=this.S++);f===s&&(f=this.t[c]=0);this.t[c]=(this.t[c]+1)%this.f.length;switch(typeof a){case "number":b===s&&(b=1);this.f[f].update([d,this.D++,1,b,g,1,a|0]);break;case "object":c=Object.prototype.toString.call(a);if("[object Uint32Array]"===c){e=[];for(c=0;c<a.length;c++)e.push(a[c]);a=e}else{"[object Array]"!==c&&(k=1);for(c=0;c<a.length&&!k;c++)"number"!==typeof a[c]&&(k=1)}if(!k){if(b===s)for(c=b=0;c<a.length;c++)for(e=a[c];0<e;)b++,
e>>>=1;this.f[f].update([d,this.D++,2,b,g,a.length].concat(a))}break;case "string":b===s&&(b=a.length);this.f[f].update([d,this.D++,3,b,g,a.length]);this.f[f].update(a);break;default:k=1}k&&r(new sjcl.exception.bug("random: addEntropy only supports number, array of numbers or string"));this.j[f]+=b;this.g+=b;h===this.m&&(this.isReady()!==this.m&&da("seeded",Math.max(this.k,this.g)),da("progress",this.getProgress()))},isReady:function(a){a=this.G[a!==s?a:this.C];return this.k&&this.k>=a?this.j[0]>
this.N&&(new Date).valueOf()>this.L?this.w|this.v:this.v:this.g>=a?this.w|this.m:this.m},getProgress:function(a){a=this.G[a?a:this.C];return this.k>=a?1:this.g>a?1:this.g/a},startCollectors:function(){this.r||(this.a={loadTimeCollector:P(this,this.W),mouseCollector:P(this,this.X),keyboardCollector:P(this,this.U),accelerometerCollector:P(this,this.Q),touchCollector:P(this,this.Y)},window.addEventListener?(window.addEventListener("load",this.a.loadTimeCollector,v),window.addEventListener("mousemove",
this.a.mouseCollector,v),window.addEventListener("keypress",this.a.keyboardCollector,v),window.addEventListener("devicemotion",this.a.accelerometerCollector,v),window.addEventListener("touchmove",this.a.touchCollector,v)):document.attachEvent?(document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector)):r(new sjcl.exception.bug("can't attach event")),this.r=!0)},stopCollectors:function(){this.r&&
(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,v),window.removeEventListener("mousemove",this.a.mouseCollector,v),window.removeEventListener("keypress",this.a.keyboardCollector,v),window.removeEventListener("devicemotion",this.a.accelerometerCollector,v),window.removeEventListener("touchmove",this.a.touchCollector,v)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",
this.a.keyboardCollector)),this.r=v)},addEventListener:function(a,b){this.A[a][this.R++]=b},removeEventListener:function(a,b){var c,d,e=this.A[a],g=[];for(d in e)e.hasOwnProperty(d)&&e[d]===b&&g.push(d);for(c=0;c<g.length;c++)d=g[c],delete e[d]},U:function(){Q(1)},X:function(a){var b,c;try{b=a.x||a.clientX||a.offsetX||0,c=a.y||a.clientY||a.offsetY||0}catch(d){c=b=0}0!=b&&0!=c&&sjcl.random.addEntropy([b,c],2,"mouse");Q(0)},Y:function(a){a=a.touches[0]||a.changedTouches[0];sjcl.random.addEntropy([a.pageX||
a.clientX,a.pageY||a.clientY],1,"touch");Q(0)},W:function(){Q(2)},Q:function(a){a=a.accelerationIncludingGravity.x||a.accelerationIncludingGravity.y||a.accelerationIncludingGravity.z;if(window.orientation){var b=window.orientation;"number"===typeof b&&sjcl.random.addEntropy(b,1,"accelerometer")}a&&sjcl.random.addEntropy(a,2,"accelerometer");Q(0)}};function da(a,b){var c,d=sjcl.random.A[a],e=[];for(c in d)d.hasOwnProperty(c)&&e.push(d[c]);for(c=0;c<e.length;c++)e[c](b)}
function Q(a){"undefined"!==typeof window&&window.performance&&"function"===typeof window.performance.now?sjcl.random.addEntropy(window.performance.now(),a,"loadtime"):sjcl.random.addEntropy((new Date).valueOf(),a,"loadtime")}function ba(a){a.b=ca(a).concat(ca(a));a.B=new sjcl.cipher.aes(a.b)}function ca(a){for(var b=0;4>b&&!(a.h[b]=a.h[b]+1|0,a.h[b]);b++);return a.B.encrypt(a.h)}function P(a,b){return function(){b.apply(a,arguments)}}sjcl.random=new sjcl.prng(6);
a:try{var V,ea,W,fa;if(fa="undefined"!==typeof module){var ka;if(ka=module.exports){var la;try{la=require("crypto")}catch(oa){la=null}ka=(ea=la)&&ea.randomBytes}fa=ka}if(fa)V=ea.randomBytes(128),V=new Uint32Array((new Uint8Array(V)).buffer),sjcl.random.addEntropy(V,1024,"crypto['randomBytes']");else if("undefined"!==typeof window&&"undefined"!==typeof Uint32Array){W=new Uint32Array(32);if(window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(W);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(W);
else break a;sjcl.random.addEntropy(W,1024,"crypto['getRandomValues']")}}catch(pa){"undefined"!==typeof window&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(pa))}sjcl.arrayBuffer=sjcl.arrayBuffer||{};"undefined"===typeof ArrayBuffer&&function(a){a.ArrayBuffer=H();a.DataView=H()}(this);
sjcl.arrayBuffer.ccm={mode:"ccm",defaults:{tlen:128},compat_encrypt:function(a,b,c,d,e){var g=sjcl.codec.arrayBuffer.fromBits(b,!0,16);b=sjcl.bitArray.bitLength(b)/8;d=d||[];a=sjcl.arrayBuffer.ccm.encrypt(a,g,c,d,e||64,b);c=sjcl.codec.arrayBuffer.toBits(a.ciphertext_buffer);c=sjcl.bitArray.clamp(c,8*b);return sjcl.bitArray.concat(c,a.tag)},compat_decrypt:function(a,b,c,d,e){e=e||64;d=d||[];var g=sjcl.bitArray,f=g.bitLength(b),h=g.clamp(b,f-e);b=g.bitSlice(b,f-e);h=sjcl.codec.arrayBuffer.fromBits(h,
!0,16);a=sjcl.arrayBuffer.ccm.decrypt(a,h,c,b,d,e,(f-e)/8);return sjcl.bitArray.clamp(sjcl.codec.arrayBuffer.toBits(a),f-e)},encrypt:function(a,b,c,d,e,g){var f,h=sjcl.bitArray,k=h.bitLength(c)/8;d=d||[];e=e||sjcl.arrayBuffer.ccm.defaults.tlen;g=g||b.byteLength;e=Math.ceil(e/8);for(f=2;4>f&&g>>>8*f;f++);f<15-k&&(f=15-k);c=h.clamp(c,8*(15-f));d=sjcl.arrayBuffer.ccm.o(a,b,c,d,e,g,f);d=sjcl.arrayBuffer.ccm.p(a,b,c,d,e,f);return{ciphertext_buffer:b,tag:d}},decrypt:function(a,b,c,d,e,g,f){var h,k=sjcl.bitArray,
n=k.bitLength(c)/8;e=e||[];g=g||sjcl.arrayBuffer.ccm.defaults.tlen;f=f||b.byteLength;g=Math.ceil(g/8);for(h=2;4>h&&f>>>8*h;h++);h<15-n&&(h=15-n);c=k.clamp(c,8*(15-h));d=sjcl.arrayBuffer.ccm.p(a,b,c,d,g,h);a=sjcl.arrayBuffer.ccm.o(a,b,c,e,g,f,h);sjcl.bitArray.equal(d,a)||r(new sjcl.exception.corrupt("ccm: tag doesn't match"));return b},o:function(a,b,c,d,e,g,f){c=sjcl.mode.ccm.K(a,d,c,e,g,f);if(0!==b.byteLength){for(d=new DataView(b);g<b.byteLength;g++)d.setUint8(g,0);for(g=0;g<d.byteLength;g+=16)c[0]^=
d.getUint32(g),c[1]^=d.getUint32(g+4),c[2]^=d.getUint32(g+8),c[3]^=d.getUint32(g+12),c=a.encrypt(c)}return sjcl.bitArray.clamp(c,8*e)},p:function(a,b,c,d,e,g){var f,h,k,n,l;f=sjcl.bitArray;h=f.u;var m=b.byteLength/50,p=m;new DataView(new ArrayBuffer(16));c=f.concat([f.partial(8,g-1)],c).concat([0,0,0]).slice(0,4);d=f.bitSlice(h(d,a.encrypt(c)),0,8*e);c[3]++;0===c[3]&&c[2]++;if(0!==b.byteLength){e=new DataView(b);for(l=0;l<e.byteLength;l+=16)l>m&&(sjcl.mode.ccm.H(l/b.byteLength),m+=p),n=a.encrypt(c),
f=e.getUint32(l),h=e.getUint32(l+4),g=e.getUint32(l+8),k=e.getUint32(l+12),e.setUint32(l,f^n[0]),e.setUint32(l+4,h^n[1]),e.setUint32(l+8,g^n[2]),e.setUint32(l+12,k^n[3]),c[3]++,0===c[3]&&c[2]++}return d}};"undefined"===typeof ArrayBuffer&&function(a){a.ArrayBuffer=H();a.DataView=H()}(this);
sjcl.codec.arrayBuffer={fromBits:function(a,b,c){var d;b=b==s?!0:b;c=c||8;if(0===a.length)return new ArrayBuffer(0);d=sjcl.bitArray.bitLength(a)/8;0!==sjcl.bitArray.bitLength(a)%8&&r(new sjcl.exception.invalid("Invalid bit size, must be divisble by 8 to fit in an arraybuffer correctly"));b&&0!==d%c&&(d+=c-d%c);c=new DataView(new ArrayBuffer(4*a.length));for(b=0;b<a.length;b++)c.setUint32(4*b,a[b]<<32);a=new DataView(new ArrayBuffer(d));if(a.byteLength===c.byteLength)return c.buffer;d=c.byteLength<
a.byteLength?c.byteLength:a.byteLength;for(b=0;b<d;b++)a.setUint8(b,c.getUint8(b));return a.buffer},toBits:function(a){var b=[],c,d,e;if(0===a.byteLength)return[];d=new DataView(a);c=d.byteLength-d.byteLength%4;for(a=0;a<c;a+=4)b.push(d.getUint32(a));if(0!=d.byteLength%4){e=new DataView(new ArrayBuffer(4));a=0;for(var g=d.byteLength%4;a<g;a++)e.setUint8(a+4-g,d.getUint8(c+a));b.push(sjcl.bitArray.partial(8*(d.byteLength%4),e.getUint32(0)))}return b},Z:function(a){function b(a){a+="";return 4<=a.length?
a:Array(4-a.length+1).join("0")+a}a=new DataView(a);for(var c="",d=0;d<a.byteLength;d+=2)0==d%16&&(c+="\n"+d.toString(16)+"\t"),c+=b(a.getUint16(d).toString(16))+" ";typeof console===s&&(console=console||{log:H()});console.log(c.toUpperCase())}};