|
|
|
@ -2,31 +2,9 @@ function DSA(){this.select_hash_algorithm=function(b){var a=openpgp.config.confi
|
|
|
|
|
e.subtract(BigInteger.ONE));c=c.modPow(a,d).mod(e);e=a.modInverse(e).multiply(b.add(f.multiply(c))).mod(e);f=[];f[0]=c.toMPI();f[1]=e.toMPI();return f};this.verify=function(b,a,c,d,e,f,g,h){b=util.getLeftNBits(openpgp_crypto_hashData(b,d),f.bitLength());b=new BigInteger(util.hexstrdump(b),16);if(0<BigInteger.ZERO.compareTo(a)||0<a.compareTo(f)||0<BigInteger.ZERO.compareTo(c)||0<c.compareTo(f))return util.print_error("invalid DSA Signature"),null;c=c.modInverse(f);b=b.multiply(c).mod(f);a=a.multiply(c).mod(f);
|
|
|
|
|
return g.modPow(b,e).multiply(h.modPow(a,e)).mod(e).mod(f)}}
|
|
|
|
|
function Elgamal(){this.encrypt=function(b,a,c,d){var e=BigInteger.ONE.add(BigInteger.ONE),f=c.subtract(e),e=openpgp_crypto_getRandomBigIntegerInRange(e,f),e=e.mod(f).add(BigInteger.ONE),f=[];f[0]=a.modPow(e,c);f[1]=d.modPow(e,c).multiply(b).mod(c).toMPI();f[0]=f[0].toMPI();return f};this.decrypt=function(b,a,c,d){util.print_debug("Elgamal Decrypt:\nc1:"+util.hexstrdump(b.toMPI())+"\nc2:"+util.hexstrdump(a.toMPI())+"\np:"+util.hexstrdump(c.toMPI())+"\nx:"+util.hexstrdump(d.toMPI()));return b.modPow(d,
|
|
|
|
|
c).modInverse(c).multiply(a).mod(c)}}var dbits,canary=244837814094590,j_lm=15715070==(canary&16777215);function BigInteger(b,a,c){null!=b&&("number"==typeof b?this.fromNumber(b,a,c):null==a&&"string"!=typeof b?this.fromString(b,256):this.fromString(b,a))}function nbi(){return new BigInteger(null)}function am1(b,a,c,d,e,f){for(;0<=--f;){var g=a*this[b++]+c[d]+e,e=Math.floor(g/67108864);c[d++]=g&67108863}return e}
|
|
|
|
|
function am2(b,a,c,d,e,f){for(var g=a&32767,a=a>>15;0<=--f;){var h=this[b]&32767,k=this[b++]>>15,j=a*h+k*g,h=g*h+((j&32767)<<15)+c[d]+(e&1073741823),e=(h>>>30)+(j>>>15)+a*k+(e>>>30);c[d++]=h&1073741823}return e}function am3(b,a,c,d,e,f){for(var g=a&16383,a=a>>14;0<=--f;){var h=this[b]&16383,k=this[b++]>>14,j=a*h+k*g,h=g*h+((j&16383)<<14)+c[d]+e,e=(h>>28)+(j>>14)+a*k;c[d++]=h&268435455}return e}
|
|
|
|
|
j_lm&&"Microsoft Internet Explorer"==navigator.appName?(BigInteger.prototype.am=am2,dbits=30):j_lm&&"Netscape"!=navigator.appName?(BigInteger.prototype.am=am1,dbits=26):(BigInteger.prototype.am=am3,dbits=28);BigInteger.prototype.DB=dbits;BigInteger.prototype.DM=(1<<dbits)-1;BigInteger.prototype.DV=1<<dbits;var BI_FP=52;BigInteger.prototype.FV=Math.pow(2,BI_FP);BigInteger.prototype.F1=BI_FP-dbits;BigInteger.prototype.F2=2*dbits-BI_FP;var BI_RM="0123456789abcdefghijklmnopqrstuvwxyz",BI_RC=[],rr,vv;
|
|
|
|
|
rr=48;for(vv=0;9>=vv;++vv)BI_RC[rr++]=vv;rr=97;for(vv=10;36>vv;++vv)BI_RC[rr++]=vv;rr=65;for(vv=10;36>vv;++vv)BI_RC[rr++]=vv;function int2char(b){return BI_RM.charAt(b)}function intAt(b,a){var c=BI_RC[b.charCodeAt(a)];return null==c?-1:c}function bnpCopyTo(b){for(var a=this.t-1;0<=a;--a)b[a]=this[a];b.t=this.t;b.s=this.s}function bnpFromInt(b){this.t=1;this.s=0>b?-1:0;0<b?this[0]=b:-1>b?this[0]=b+DV:this.t=0}function nbv(b){var a=nbi();a.fromInt(b);return a}
|
|
|
|
|
function bnpFromString(b,a){var c;if(16==a)c=4;else if(8==a)c=3;else if(256==a)c=8;else if(2==a)c=1;else if(32==a)c=5;else if(4==a)c=2;else{this.fromRadix(b,a);return}this.s=this.t=0;for(var d=b.length,e=!1,f=0;0<=--d;){var g=8==c?b[d]&255:intAt(b,d);0>g?"-"==b.charAt(d)&&(e=!0):(e=!1,0==f?this[this.t++]=g:f+c>this.DB?(this[this.t-1]|=(g&(1<<this.DB-f)-1)<<f,this[this.t++]=g>>this.DB-f):this[this.t-1]|=g<<f,f+=c,f>=this.DB&&(f-=this.DB))}if(8==c&&0!=(b[0]&128))this.s=-1,0<f&&(this[this.t-1]|=(1<<
|
|
|
|
|
this.DB-f)-1<<f);this.clamp();e&&BigInteger.ZERO.subTo(this,this)}function bnpClamp(){for(var b=this.s&this.DM;0<this.t&&this[this.t-1]==b;)--this.t}
|
|
|
|
|
function bnToString(b){if(0>this.s)return"-"+this.negate().toString(b);if(16==b)b=4;else if(8==b)b=3;else if(2==b)b=1;else if(32==b)b=5;else if(4==b)b=2;else return this.toRadix(b);var a=(1<<b)-1,c,d=!1,e="",f=this.t,g=this.DB-f*this.DB%b;if(0<f--){if(g<this.DB&&0<(c=this[f]>>g))d=!0,e=int2char(c);for(;0<=f;)g<b?(c=(this[f]&(1<<g)-1)<<b-g,c|=this[--f]>>(g+=this.DB-b)):(c=this[f]>>(g-=b)&a,0>=g&&(g+=this.DB,--f)),0<c&&(d=!0),d&&(e+=int2char(c))}return d?e:"0"}
|
|
|
|
|
function bnNegate(){var b=nbi();BigInteger.ZERO.subTo(this,b);return b}function bnAbs(){return 0>this.s?this.negate():this}function bnCompareTo(b){var a=this.s-b.s;if(0!=a)return a;var c=this.t,a=c-b.t;if(0!=a)return a;for(;0<=--c;)if(0!=(a=this[c]-b[c]))return a;return 0}function nbits(b){var a=1,c;if(0!=(c=b>>>16))b=c,a+=16;if(0!=(c=b>>8))b=c,a+=8;if(0!=(c=b>>4))b=c,a+=4;if(0!=(c=b>>2))b=c,a+=2;0!=b>>1&&(a+=1);return a}
|
|
|
|
|
function bnBitLength(){return 0>=this.t?0:this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}function bnpDLShiftTo(b,a){var c;for(c=this.t-1;0<=c;--c)a[c+b]=this[c];for(c=b-1;0<=c;--c)a[c]=0;a.t=this.t+b;a.s=this.s}function bnpDRShiftTo(b,a){for(var c=b;c<this.t;++c)a[c-b]=this[c];a.t=Math.max(this.t-b,0);a.s=this.s}
|
|
|
|
|
function bnpLShiftTo(b,a){var c=b%this.DB,d=this.DB-c,e=(1<<d)-1,f=Math.floor(b/this.DB),g=this.s<<c&this.DM,h;for(h=this.t-1;0<=h;--h)a[h+f+1]=this[h]>>d|g,g=(this[h]&e)<<c;for(h=f-1;0<=h;--h)a[h]=0;a[f]=g;a.t=this.t+f+1;a.s=this.s;a.clamp()}
|
|
|
|
|
function bnpRShiftTo(b,a){a.s=this.s;var c=Math.floor(b/this.DB);if(c>=this.t)a.t=0;else{var d=b%this.DB,e=this.DB-d,f=(1<<d)-1;a[0]=this[c]>>d;for(var g=c+1;g<this.t;++g)a[g-c-1]|=(this[g]&f)<<e,a[g-c]=this[g]>>d;0<d&&(a[this.t-c-1]|=(this.s&f)<<e);a.t=this.t-c;a.clamp()}}
|
|
|
|
|
function bnpSubTo(b,a){for(var c=0,d=0,e=Math.min(b.t,this.t);c<e;)d+=this[c]-b[c],a[c++]=d&this.DM,d>>=this.DB;if(b.t<this.t){for(d-=b.s;c<this.t;)d+=this[c],a[c++]=d&this.DM,d>>=this.DB;d+=this.s}else{for(d+=this.s;c<b.t;)d-=b[c],a[c++]=d&this.DM,d>>=this.DB;d-=b.s}a.s=0>d?-1:0;-1>d?a[c++]=this.DV+d:0<d&&(a[c++]=d);a.t=c;a.clamp()}
|
|
|
|
|
function bnpMultiplyTo(b,a){var c=this.abs(),d=b.abs(),e=c.t;for(a.t=e+d.t;0<=--e;)a[e]=0;for(e=0;e<d.t;++e)a[e+c.t]=c.am(0,d[e],a,e,0,c.t);a.s=0;a.clamp();this.s!=b.s&&BigInteger.ZERO.subTo(a,a)}function bnpSquareTo(b){for(var a=this.abs(),c=b.t=2*a.t;0<=--c;)b[c]=0;for(c=0;c<a.t-1;++c){var d=a.am(c,a[c],b,2*c,0,1);if((b[c+a.t]+=a.am(c+1,2*a[c],b,2*c+1,d,a.t-c-1))>=a.DV)b[c+a.t]-=a.DV,b[c+a.t+1]=1}0<b.t&&(b[b.t-1]+=a.am(c,a[c],b,2*c,0,1));b.s=0;b.clamp()}
|
|
|
|
|
function bnpDivRemTo(b,a,c){var d=b.abs();if(!(0>=d.t)){var e=this.abs();if(e.t<d.t)null!=a&&a.fromInt(0),null!=c&&this.copyTo(c);else{null==c&&(c=nbi());var f=nbi(),g=this.s,b=b.s,h=this.DB-nbits(d[d.t-1]);0<h?(d.lShiftTo(h,f),e.lShiftTo(h,c)):(d.copyTo(f),e.copyTo(c));d=f.t;e=f[d-1];if(0!=e){var k=e*(1<<this.F1)+(1<d?f[d-2]>>this.F2:0),j=this.FV/k,k=(1<<this.F1)/k,l=1<<this.F2,o=c.t,r=o-d,p=null==a?nbi():a;f.dlShiftTo(r,p);0<=c.compareTo(p)&&(c[c.t++]=1,c.subTo(p,c));BigInteger.ONE.dlShiftTo(d,
|
|
|
|
|
p);for(p.subTo(f,f);f.t<d;)f[f.t++]=0;for(;0<=--r;){var m=c[--o]==e?this.DM:Math.floor(c[o]*j+(c[o-1]+l)*k);if((c[o]+=f.am(0,m,c,r,0,d))<m){f.dlShiftTo(r,p);for(c.subTo(p,c);c[o]<--m;)c.subTo(p,c)}}null!=a&&(c.drShiftTo(d,a),g!=b&&BigInteger.ZERO.subTo(a,a));c.t=d;c.clamp();0<h&&c.rShiftTo(h,c);0>g&&BigInteger.ZERO.subTo(c,c)}}}}function bnMod(b){var a=nbi();this.abs().divRemTo(b,null,a);0>this.s&&0<a.compareTo(BigInteger.ZERO)&&b.subTo(a,a);return a}function Classic(b){this.m=b}
|
|
|
|
|
function cConvert(b){return 0>b.s||0<=b.compareTo(this.m)?b.mod(this.m):b}function cRevert(b){return b}function cReduce(b){b.divRemTo(this.m,null,b)}function cMulTo(b,a,c){b.multiplyTo(a,c);this.reduce(c)}function cSqrTo(b,a){b.squareTo(a);this.reduce(a)}Classic.prototype.convert=cConvert;Classic.prototype.revert=cRevert;Classic.prototype.reduce=cReduce;Classic.prototype.mulTo=cMulTo;Classic.prototype.sqrTo=cSqrTo;
|
|
|
|
|
function bnpInvDigit(){if(1>this.t)return 0;var b=this[0];if(0==(b&1))return 0;var a=b&3,a=a*(2-(b&15)*a)&15,a=a*(2-(b&255)*a)&255,a=a*(2-((b&65535)*a&65535))&65535,a=a*(2-b*a%this.DV)%this.DV;return 0<a?this.DV-a:-a}function Montgomery(b){this.m=b;this.mp=b.invDigit();this.mpl=this.mp&32767;this.mph=this.mp>>15;this.um=(1<<b.DB-15)-1;this.mt2=2*b.t}
|
|
|
|
|
function montConvert(b){var a=nbi();b.abs().dlShiftTo(this.m.t,a);a.divRemTo(this.m,null,a);0>b.s&&0<a.compareTo(BigInteger.ZERO)&&this.m.subTo(a,a);return a}function montRevert(b){var a=nbi();b.copyTo(a);this.reduce(a);return a}
|
|
|
|
|
function montReduce(b){for(;b.t<=this.mt2;)b[b.t++]=0;for(var a=0;a<this.m.t;++a){var c=b[a]&32767,d=c*this.mpl+((c*this.mph+(b[a]>>15)*this.mpl&this.um)<<15)&b.DM,c=a+this.m.t;for(b[c]+=this.m.am(0,d,b,a,0,this.m.t);b[c]>=b.DV;)b[c]-=b.DV,b[++c]++}b.clamp();b.drShiftTo(this.m.t,b);0<=b.compareTo(this.m)&&b.subTo(this.m,b)}function montSqrTo(b,a){b.squareTo(a);this.reduce(a)}function montMulTo(b,a,c){b.multiplyTo(a,c);this.reduce(c)}Montgomery.prototype.convert=montConvert;
|
|
|
|
|
Montgomery.prototype.revert=montRevert;Montgomery.prototype.reduce=montReduce;Montgomery.prototype.mulTo=montMulTo;Montgomery.prototype.sqrTo=montSqrTo;function bnpIsEven(){return 0==(0<this.t?this[0]&1:this.s)}function bnpExp(b,a){if(4294967295<b||1>b)return BigInteger.ONE;var c=nbi(),d=nbi(),e=a.convert(this),f=nbits(b)-1;for(e.copyTo(c);0<=--f;)if(a.sqrTo(c,d),0<(b&1<<f))a.mulTo(d,e,c);else var g=c,c=d,d=g;return a.revert(c)}
|
|
|
|
|
function bnModPowInt(b,a){var c;c=256>b||a.isEven()?new Classic(a):new Montgomery(a);return this.exp(b,c)}BigInteger.prototype.copyTo=bnpCopyTo;BigInteger.prototype.fromInt=bnpFromInt;BigInteger.prototype.fromString=bnpFromString;BigInteger.prototype.clamp=bnpClamp;BigInteger.prototype.dlShiftTo=bnpDLShiftTo;BigInteger.prototype.drShiftTo=bnpDRShiftTo;BigInteger.prototype.lShiftTo=bnpLShiftTo;BigInteger.prototype.rShiftTo=bnpRShiftTo;BigInteger.prototype.subTo=bnpSubTo;
|
|
|
|
|
BigInteger.prototype.multiplyTo=bnpMultiplyTo;BigInteger.prototype.squareTo=bnpSquareTo;BigInteger.prototype.divRemTo=bnpDivRemTo;BigInteger.prototype.invDigit=bnpInvDigit;BigInteger.prototype.isEven=bnpIsEven;BigInteger.prototype.exp=bnpExp;BigInteger.prototype.toString=bnToString;BigInteger.prototype.negate=bnNegate;BigInteger.prototype.abs=bnAbs;BigInteger.prototype.compareTo=bnCompareTo;BigInteger.prototype.bitLength=bnBitLength;BigInteger.prototype.mod=bnMod;BigInteger.prototype.modPowInt=bnModPowInt;
|
|
|
|
|
BigInteger.ZERO=nbv(0);BigInteger.ONE=nbv(1);function bnClone(){var b=nbi();this.copyTo(b);return b}function bnIntValue(){if(0>this.s){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function bnByteValue(){return 0==this.t?this.s:this[0]<<24>>24}function bnShortValue(){return 0==this.t?this.s:this[0]<<16>>16}function bnpChunkSize(b){return Math.floor(Math.LN2*this.DB/Math.log(b))}
|
|
|
|
|
c).modInverse(c).multiply(a).mod(c)}}function bnClone(){var b=nbi();this.copyTo(b);return b}function bnIntValue(){if(0>this.s){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function bnByteValue(){return 0==this.t?this.s:this[0]<<24>>24}function bnShortValue(){return 0==this.t?this.s:this[0]<<16>>16}function bnpChunkSize(b){return Math.floor(Math.LN2*this.DB/Math.log(b))}
|
|
|
|
|
function bnSigNum(){return 0>this.s?-1:0>=this.t||1==this.t&&0>=this[0]?0:1}function bnpToRadix(b){null==b&&(b=10);if(0==this.signum()||2>b||36<b)return"0";var a=this.chunkSize(b),a=Math.pow(b,a),c=nbv(a),d=nbi(),e=nbi(),f="";for(this.divRemTo(c,d,e);0<d.signum();)f=(a+e.intValue()).toString(b).substr(1)+f,d.divRemTo(c,d,e);return e.intValue().toString(b)+f}
|
|
|
|
|
function bnpFromRadix(b,a){this.fromInt(0);null==a&&(a=10);for(var c=this.chunkSize(a),d=Math.pow(a,c),e=!1,f=0,g=0,h=0;h<b.length;++h){var k=intAt(b,h);0>k?"-"==b.charAt(h)&&0==this.signum()&&(e=!0):(g=a*g+k,++f>=c&&(this.dMultiply(d),this.dAddOffset(g,0),g=f=0))}0<f&&(this.dMultiply(Math.pow(a,f)),this.dAddOffset(g,0));e&&BigInteger.ZERO.subTo(this,this)}
|
|
|
|
|
function bnpFromRadix(b,a){this.fromInt(0);null==a&&(a=10);for(var c=this.chunkSize(a),d=Math.pow(a,c),e=!1,f=0,g=0,h=0;h<b.length;++h){var j=intAt(b,h);0>j?"-"==b.charAt(h)&&0==this.signum()&&(e=!0):(g=a*g+j,++f>=c&&(this.dMultiply(d),this.dAddOffset(g,0),g=f=0))}0<f&&(this.dMultiply(Math.pow(a,f)),this.dAddOffset(g,0));e&&BigInteger.ZERO.subTo(this,this)}
|
|
|
|
|
function bnpFromNumber(b,a,c){if("number"==typeof a)if(2>b)this.fromInt(1);else{this.fromNumber(b,c);this.testBit(b-1)||this.bitwiseTo(BigInteger.ONE.shiftLeft(b-1),op_or,this);for(this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(a);)this.dAddOffset(2,0),this.bitLength()>b&&this.subTo(BigInteger.ONE.shiftLeft(b-1),this)}else{var c=[],d=b&7;c.length=(b>>3)+1;a.nextBytes(c);c[0]=0<d?c[0]&(1<<d)-1:0;this.fromString(c,256)}}
|
|
|
|
|
function bnToByteArray(){var b=this.t,a=[];a[0]=this.s;var c=this.DB-b*this.DB%8,d,e=0;if(0<b--){if(c<this.DB&&(d=this[b]>>c)!=(this.s&this.DM)>>c)a[e++]=d|this.s<<this.DB-c;for(;0<=b;)if(8>c?(d=(this[b]&(1<<c)-1)<<8-c,d|=this[--b]>>(c+=this.DB-8)):(d=this[b]>>(c-=8)&255,0>=c&&(c+=this.DB,--b)),0<e||d!=this.s)a[e++]=d}return a}function bnEquals(b){return 0==this.compareTo(b)}function bnMin(b){return 0>this.compareTo(b)?this:b}function bnMax(b){return 0<this.compareTo(b)?this:b}
|
|
|
|
|
function bnpBitwiseTo(b,a,c){var d,e,f=Math.min(b.t,this.t);for(d=0;d<f;++d)c[d]=a(this[d],b[d]);if(b.t<this.t){e=b.s&this.DM;for(d=f;d<this.t;++d)c[d]=a(this[d],e);c.t=this.t}else{e=this.s&this.DM;for(d=f;d<b.t;++d)c[d]=a(e,b[d]);c.t=b.t}c.s=a(this.s,b.s);c.clamp()}function op_and(b,a){return b&a}function bnAnd(b){var a=nbi();this.bitwiseTo(b,op_and,a);return a}function op_or(b,a){return b|a}function bnOr(b){var a=nbi();this.bitwiseTo(b,op_or,a);return a}function op_xor(b,a){return b^a}
|
|
|
|
@ -40,8 +18,8 @@ function bnpMultiplyLowerTo(b,a,c){var d=Math.min(this.t+b.t,a);c.s=0;for(c.t=d;
|
|
|
|
|
function Barrett(b){this.r2=nbi();this.q3=nbi();BigInteger.ONE.dlShiftTo(2*b.t,this.r2);this.mu=this.r2.divide(b);this.m=b}function barrettConvert(b){if(0>b.s||b.t>2*this.m.t)return b.mod(this.m);if(0>b.compareTo(this.m))return b;var a=nbi();b.copyTo(a);this.reduce(a);return a}function barrettRevert(b){return b}
|
|
|
|
|
function barrettReduce(b){b.drShiftTo(this.m.t-1,this.r2);if(b.t>this.m.t+1)b.t=this.m.t+1,b.clamp();this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3);for(this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);0>b.compareTo(this.r2);)b.dAddOffset(1,this.m.t+1);for(b.subTo(this.r2,b);0<=b.compareTo(this.m);)b.subTo(this.m,b)}function barrettSqrTo(b,a){b.squareTo(a);this.reduce(a)}function barrettMulTo(b,a,c){b.multiplyTo(a,c);this.reduce(c)}Barrett.prototype.convert=barrettConvert;
|
|
|
|
|
Barrett.prototype.revert=barrettRevert;Barrett.prototype.reduce=barrettReduce;Barrett.prototype.mulTo=barrettMulTo;Barrett.prototype.sqrTo=barrettSqrTo;
|
|
|
|
|
function bnModPow(b,a){var c=b.bitLength(),d,e=nbv(1),f;if(0>=c)return e;d=18>c?1:48>c?3:144>c?4:768>c?5:6;f=8>c?new Classic(a):a.isEven()?new Barrett(a):new Montgomery(a);var g=[],h=3,k=d-1,j=(1<<d)-1;g[1]=f.convert(this);if(1<d){c=nbi();for(f.sqrTo(g[1],c);h<=j;)g[h]=nbi(),f.mulTo(c,g[h-2],g[h]),h+=2}for(var l=b.t-1,o,r=!0,p=nbi(),c=nbits(b[l])-1;0<=l;){c>=k?o=b[l]>>c-k&j:(o=(b[l]&(1<<c+1)-1)<<k-c,0<l&&(o|=b[l-1]>>this.DB+c-k));for(h=d;0==(o&1);)o>>=1,--h;if(0>(c-=h))c+=this.DB,--l;if(r)g[o].copyTo(e),
|
|
|
|
|
r=!1;else{for(;1<h;)f.sqrTo(e,p),f.sqrTo(p,e),h-=2;0<h?f.sqrTo(e,p):(h=e,e=p,p=h);f.mulTo(p,g[o],e)}for(;0<=l&&0==(b[l]&1<<c);)f.sqrTo(e,p),h=e,e=p,p=h,0>--c&&(c=this.DB-1,--l)}return f.revert(e)}
|
|
|
|
|
function bnModPow(b,a){var c=b.bitLength(),d,e=nbv(1),f;if(0>=c)return e;d=18>c?1:48>c?3:144>c?4:768>c?5:6;f=8>c?new Classic(a):a.isEven()?new Barrett(a):new Montgomery(a);var g=[],h=3,j=d-1,k=(1<<d)-1;g[1]=f.convert(this);if(1<d){c=nbi();for(f.sqrTo(g[1],c);h<=k;)g[h]=nbi(),f.mulTo(c,g[h-2],g[h]),h+=2}for(var l=b.t-1,m,r=!0,p=nbi(),c=nbits(b[l])-1;0<=l;){c>=j?m=b[l]>>c-j&k:(m=(b[l]&(1<<c+1)-1)<<j-c,0<l&&(m|=b[l-1]>>this.DB+c-j));for(h=d;0==(m&1);)m>>=1,--h;if(0>(c-=h))c+=this.DB,--l;if(r)g[m].copyTo(e),
|
|
|
|
|
r=!1;else{for(;1<h;)f.sqrTo(e,p),f.sqrTo(p,e),h-=2;0<h?f.sqrTo(e,p):(h=e,e=p,p=h);f.mulTo(p,g[m],e)}for(;0<=l&&0==(b[l]&1<<c);)f.sqrTo(e,p),h=e,e=p,p=h,0>--c&&(c=this.DB-1,--l)}return f.revert(e)}
|
|
|
|
|
function bnGCD(b){var a=0>this.s?this.negate():this.clone(),b=0>b.s?b.negate():b.clone();if(0>a.compareTo(b))var c=a,a=b,b=c;var c=a.getLowestSetBit(),d=b.getLowestSetBit();if(0>d)return a;c<d&&(d=c);0<d&&(a.rShiftTo(d,a),b.rShiftTo(d,b));for(;0<a.signum();)0<(c=a.getLowestSetBit())&&a.rShiftTo(c,a),0<(c=b.getLowestSetBit())&&b.rShiftTo(c,b),0<=a.compareTo(b)?(a.subTo(b,a),a.rShiftTo(1,a)):(b.subTo(a,b),b.rShiftTo(1,b));0<d&&b.lShiftTo(d,b);return b}
|
|
|
|
|
function bnpModInt(b){if(0>=b)return 0;var a=this.DV%b,c=0>this.s?b-1:0;if(0<this.t)if(0==a)c=this[0]%b;else for(var d=this.t-1;0<=d;--d)c=(a*c+this[d])%b;return c}
|
|
|
|
|
function bnModInverse(b){var a=b.isEven();if(this.isEven()&&a||0==b.signum())return BigInteger.ZERO;for(var c=b.clone(),d=this.clone(),e=nbv(1),f=nbv(0),g=nbv(0),h=nbv(1);0!=c.signum();){for(;c.isEven();){c.rShiftTo(1,c);if(a){if(!e.isEven()||!f.isEven())e.addTo(this,e),f.subTo(b,f);e.rShiftTo(1,e)}else f.isEven()||f.subTo(b,f);f.rShiftTo(1,f)}for(;d.isEven();){d.rShiftTo(1,d);if(a){if(!g.isEven()||!h.isEven())g.addTo(this,g),h.subTo(b,h);g.rShiftTo(1,g)}else h.isEven()||h.subTo(b,h);h.rShiftTo(1,
|
|
|
|
@ -55,10 +33,32 @@ BigInteger.prototype.chunkSize=bnpChunkSize;BigInteger.prototype.toRadix=bnpToRa
|
|
|
|
|
BigInteger.prototype.modInt=bnpModInt;BigInteger.prototype.millerRabin=bnpMillerRabin;BigInteger.prototype.clone=bnClone;BigInteger.prototype.intValue=bnIntValue;BigInteger.prototype.byteValue=bnByteValue;BigInteger.prototype.shortValue=bnShortValue;BigInteger.prototype.signum=bnSigNum;BigInteger.prototype.toByteArray=bnToByteArray;BigInteger.prototype.equals=bnEquals;BigInteger.prototype.min=bnMin;BigInteger.prototype.max=bnMax;BigInteger.prototype.and=bnAnd;BigInteger.prototype.or=bnOr;
|
|
|
|
|
BigInteger.prototype.xor=bnXor;BigInteger.prototype.andNot=bnAndNot;BigInteger.prototype.not=bnNot;BigInteger.prototype.shiftLeft=bnShiftLeft;BigInteger.prototype.shiftRight=bnShiftRight;BigInteger.prototype.getLowestSetBit=bnGetLowestSetBit;BigInteger.prototype.bitCount=bnBitCount;BigInteger.prototype.testBit=bnTestBit;BigInteger.prototype.setBit=bnSetBit;BigInteger.prototype.clearBit=bnClearBit;BigInteger.prototype.flipBit=bnFlipBit;BigInteger.prototype.add=bnAdd;BigInteger.prototype.subtract=bnSubtract;
|
|
|
|
|
BigInteger.prototype.multiply=bnMultiply;BigInteger.prototype.divide=bnDivide;BigInteger.prototype.remainder=bnRemainder;BigInteger.prototype.divideAndRemainder=bnDivideAndRemainder;BigInteger.prototype.modPow=bnModPow;BigInteger.prototype.modInverse=bnModInverse;BigInteger.prototype.pow=bnPow;BigInteger.prototype.gcd=bnGCD;BigInteger.prototype.isProbablePrime=bnIsProbablePrime;BigInteger.prototype.toMPI=bnToMPI;BigInteger.prototype.square=bnSquare;
|
|
|
|
|
function SecureRandom(){this.nextBytes=function(b){for(var a=0;a<b.length;a++)b[a]=openpgp_crypto_getSecureRandomOctet()}}
|
|
|
|
|
var dbits,canary=244837814094590,j_lm=15715070==(canary&16777215);function BigInteger(b,a,c){null!=b&&("number"==typeof b?this.fromNumber(b,a,c):null==a&&"string"!=typeof b?this.fromString(b,256):this.fromString(b,a))}function nbi(){return new BigInteger(null)}function am1(b,a,c,d,e,f){for(;0<=--f;){var g=a*this[b++]+c[d]+e,e=Math.floor(g/67108864);c[d++]=g&67108863}return e}
|
|
|
|
|
function am2(b,a,c,d,e,f){for(var g=a&32767,a=a>>15;0<=--f;){var h=this[b]&32767,j=this[b++]>>15,k=a*h+j*g,h=g*h+((k&32767)<<15)+c[d]+(e&1073741823),e=(h>>>30)+(k>>>15)+a*j+(e>>>30);c[d++]=h&1073741823}return e}function am3(b,a,c,d,e,f){for(var g=a&16383,a=a>>14;0<=--f;){var h=this[b]&16383,j=this[b++]>>14,k=a*h+j*g,h=g*h+((k&16383)<<14)+c[d]+e,e=(h>>28)+(k>>14)+a*j;c[d++]=h&268435455}return e}
|
|
|
|
|
j_lm&&"Microsoft Internet Explorer"==navigator.appName?(BigInteger.prototype.am=am2,dbits=30):j_lm&&"Netscape"!=navigator.appName?(BigInteger.prototype.am=am1,dbits=26):(BigInteger.prototype.am=am3,dbits=28);BigInteger.prototype.DB=dbits;BigInteger.prototype.DM=(1<<dbits)-1;BigInteger.prototype.DV=1<<dbits;var BI_FP=52;BigInteger.prototype.FV=Math.pow(2,BI_FP);BigInteger.prototype.F1=BI_FP-dbits;BigInteger.prototype.F2=2*dbits-BI_FP;var BI_RM="0123456789abcdefghijklmnopqrstuvwxyz",BI_RC=[],rr,vv;
|
|
|
|
|
rr=48;for(vv=0;9>=vv;++vv)BI_RC[rr++]=vv;rr=97;for(vv=10;36>vv;++vv)BI_RC[rr++]=vv;rr=65;for(vv=10;36>vv;++vv)BI_RC[rr++]=vv;function int2char(b){return BI_RM.charAt(b)}function intAt(b,a){var c=BI_RC[b.charCodeAt(a)];return null==c?-1:c}function bnpCopyTo(b){for(var a=this.t-1;0<=a;--a)b[a]=this[a];b.t=this.t;b.s=this.s}function bnpFromInt(b){this.t=1;this.s=0>b?-1:0;0<b?this[0]=b:-1>b?this[0]=b+DV:this.t=0}function nbv(b){var a=nbi();a.fromInt(b);return a}
|
|
|
|
|
function bnpFromString(b,a){var c;if(16==a)c=4;else if(8==a)c=3;else if(256==a)c=8;else if(2==a)c=1;else if(32==a)c=5;else if(4==a)c=2;else{this.fromRadix(b,a);return}this.s=this.t=0;for(var d=b.length,e=!1,f=0;0<=--d;){var g=8==c?b[d]&255:intAt(b,d);0>g?"-"==b.charAt(d)&&(e=!0):(e=!1,0==f?this[this.t++]=g:f+c>this.DB?(this[this.t-1]|=(g&(1<<this.DB-f)-1)<<f,this[this.t++]=g>>this.DB-f):this[this.t-1]|=g<<f,f+=c,f>=this.DB&&(f-=this.DB))}if(8==c&&0!=(b[0]&128))this.s=-1,0<f&&(this[this.t-1]|=(1<<
|
|
|
|
|
this.DB-f)-1<<f);this.clamp();e&&BigInteger.ZERO.subTo(this,this)}function bnpClamp(){for(var b=this.s&this.DM;0<this.t&&this[this.t-1]==b;)--this.t}
|
|
|
|
|
function bnToString(b){if(0>this.s)return"-"+this.negate().toString(b);if(16==b)b=4;else if(8==b)b=3;else if(2==b)b=1;else if(32==b)b=5;else if(4==b)b=2;else return this.toRadix(b);var a=(1<<b)-1,c,d=!1,e="",f=this.t,g=this.DB-f*this.DB%b;if(0<f--){if(g<this.DB&&0<(c=this[f]>>g))d=!0,e=int2char(c);for(;0<=f;)g<b?(c=(this[f]&(1<<g)-1)<<b-g,c|=this[--f]>>(g+=this.DB-b)):(c=this[f]>>(g-=b)&a,0>=g&&(g+=this.DB,--f)),0<c&&(d=!0),d&&(e+=int2char(c))}return d?e:"0"}
|
|
|
|
|
function bnNegate(){var b=nbi();BigInteger.ZERO.subTo(this,b);return b}function bnAbs(){return 0>this.s?this.negate():this}function bnCompareTo(b){var a=this.s-b.s;if(0!=a)return a;var c=this.t,a=c-b.t;if(0!=a)return a;for(;0<=--c;)if(0!=(a=this[c]-b[c]))return a;return 0}function nbits(b){var a=1,c;if(0!=(c=b>>>16))b=c,a+=16;if(0!=(c=b>>8))b=c,a+=8;if(0!=(c=b>>4))b=c,a+=4;if(0!=(c=b>>2))b=c,a+=2;0!=b>>1&&(a+=1);return a}
|
|
|
|
|
function bnBitLength(){return 0>=this.t?0:this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}function bnpDLShiftTo(b,a){var c;for(c=this.t-1;0<=c;--c)a[c+b]=this[c];for(c=b-1;0<=c;--c)a[c]=0;a.t=this.t+b;a.s=this.s}function bnpDRShiftTo(b,a){for(var c=b;c<this.t;++c)a[c-b]=this[c];a.t=Math.max(this.t-b,0);a.s=this.s}
|
|
|
|
|
function bnpLShiftTo(b,a){var c=b%this.DB,d=this.DB-c,e=(1<<d)-1,f=Math.floor(b/this.DB),g=this.s<<c&this.DM,h;for(h=this.t-1;0<=h;--h)a[h+f+1]=this[h]>>d|g,g=(this[h]&e)<<c;for(h=f-1;0<=h;--h)a[h]=0;a[f]=g;a.t=this.t+f+1;a.s=this.s;a.clamp()}
|
|
|
|
|
function bnpRShiftTo(b,a){a.s=this.s;var c=Math.floor(b/this.DB);if(c>=this.t)a.t=0;else{var d=b%this.DB,e=this.DB-d,f=(1<<d)-1;a[0]=this[c]>>d;for(var g=c+1;g<this.t;++g)a[g-c-1]|=(this[g]&f)<<e,a[g-c]=this[g]>>d;0<d&&(a[this.t-c-1]|=(this.s&f)<<e);a.t=this.t-c;a.clamp()}}
|
|
|
|
|
function bnpSubTo(b,a){for(var c=0,d=0,e=Math.min(b.t,this.t);c<e;)d+=this[c]-b[c],a[c++]=d&this.DM,d>>=this.DB;if(b.t<this.t){for(d-=b.s;c<this.t;)d+=this[c],a[c++]=d&this.DM,d>>=this.DB;d+=this.s}else{for(d+=this.s;c<b.t;)d-=b[c],a[c++]=d&this.DM,d>>=this.DB;d-=b.s}a.s=0>d?-1:0;-1>d?a[c++]=this.DV+d:0<d&&(a[c++]=d);a.t=c;a.clamp()}
|
|
|
|
|
function bnpMultiplyTo(b,a){var c=this.abs(),d=b.abs(),e=c.t;for(a.t=e+d.t;0<=--e;)a[e]=0;for(e=0;e<d.t;++e)a[e+c.t]=c.am(0,d[e],a,e,0,c.t);a.s=0;a.clamp();this.s!=b.s&&BigInteger.ZERO.subTo(a,a)}function bnpSquareTo(b){for(var a=this.abs(),c=b.t=2*a.t;0<=--c;)b[c]=0;for(c=0;c<a.t-1;++c){var d=a.am(c,a[c],b,2*c,0,1);if((b[c+a.t]+=a.am(c+1,2*a[c],b,2*c+1,d,a.t-c-1))>=a.DV)b[c+a.t]-=a.DV,b[c+a.t+1]=1}0<b.t&&(b[b.t-1]+=a.am(c,a[c],b,2*c,0,1));b.s=0;b.clamp()}
|
|
|
|
|
function bnpDivRemTo(b,a,c){var d=b.abs();if(!(0>=d.t)){var e=this.abs();if(e.t<d.t)null!=a&&a.fromInt(0),null!=c&&this.copyTo(c);else{null==c&&(c=nbi());var f=nbi(),g=this.s,b=b.s,h=this.DB-nbits(d[d.t-1]);0<h?(d.lShiftTo(h,f),e.lShiftTo(h,c)):(d.copyTo(f),e.copyTo(c));d=f.t;e=f[d-1];if(0!=e){var j=e*(1<<this.F1)+(1<d?f[d-2]>>this.F2:0),k=this.FV/j,j=(1<<this.F1)/j,l=1<<this.F2,m=c.t,r=m-d,p=null==a?nbi():a;f.dlShiftTo(r,p);0<=c.compareTo(p)&&(c[c.t++]=1,c.subTo(p,c));BigInteger.ONE.dlShiftTo(d,
|
|
|
|
|
p);for(p.subTo(f,f);f.t<d;)f[f.t++]=0;for(;0<=--r;){var o=c[--m]==e?this.DM:Math.floor(c[m]*k+(c[m-1]+l)*j);if((c[m]+=f.am(0,o,c,r,0,d))<o){f.dlShiftTo(r,p);for(c.subTo(p,c);c[m]<--o;)c.subTo(p,c)}}null!=a&&(c.drShiftTo(d,a),g!=b&&BigInteger.ZERO.subTo(a,a));c.t=d;c.clamp();0<h&&c.rShiftTo(h,c);0>g&&BigInteger.ZERO.subTo(c,c)}}}}function bnMod(b){var a=nbi();this.abs().divRemTo(b,null,a);0>this.s&&0<a.compareTo(BigInteger.ZERO)&&b.subTo(a,a);return a}function Classic(b){this.m=b}
|
|
|
|
|
function cConvert(b){return 0>b.s||0<=b.compareTo(this.m)?b.mod(this.m):b}function cRevert(b){return b}function cReduce(b){b.divRemTo(this.m,null,b)}function cMulTo(b,a,c){b.multiplyTo(a,c);this.reduce(c)}function cSqrTo(b,a){b.squareTo(a);this.reduce(a)}Classic.prototype.convert=cConvert;Classic.prototype.revert=cRevert;Classic.prototype.reduce=cReduce;Classic.prototype.mulTo=cMulTo;Classic.prototype.sqrTo=cSqrTo;
|
|
|
|
|
function bnpInvDigit(){if(1>this.t)return 0;var b=this[0];if(0==(b&1))return 0;var a=b&3,a=a*(2-(b&15)*a)&15,a=a*(2-(b&255)*a)&255,a=a*(2-((b&65535)*a&65535))&65535,a=a*(2-b*a%this.DV)%this.DV;return 0<a?this.DV-a:-a}function Montgomery(b){this.m=b;this.mp=b.invDigit();this.mpl=this.mp&32767;this.mph=this.mp>>15;this.um=(1<<b.DB-15)-1;this.mt2=2*b.t}
|
|
|
|
|
function montConvert(b){var a=nbi();b.abs().dlShiftTo(this.m.t,a);a.divRemTo(this.m,null,a);0>b.s&&0<a.compareTo(BigInteger.ZERO)&&this.m.subTo(a,a);return a}function montRevert(b){var a=nbi();b.copyTo(a);this.reduce(a);return a}
|
|
|
|
|
function montReduce(b){for(;b.t<=this.mt2;)b[b.t++]=0;for(var a=0;a<this.m.t;++a){var c=b[a]&32767,d=c*this.mpl+((c*this.mph+(b[a]>>15)*this.mpl&this.um)<<15)&b.DM,c=a+this.m.t;for(b[c]+=this.m.am(0,d,b,a,0,this.m.t);b[c]>=b.DV;)b[c]-=b.DV,b[++c]++}b.clamp();b.drShiftTo(this.m.t,b);0<=b.compareTo(this.m)&&b.subTo(this.m,b)}function montSqrTo(b,a){b.squareTo(a);this.reduce(a)}function montMulTo(b,a,c){b.multiplyTo(a,c);this.reduce(c)}Montgomery.prototype.convert=montConvert;
|
|
|
|
|
Montgomery.prototype.revert=montRevert;Montgomery.prototype.reduce=montReduce;Montgomery.prototype.mulTo=montMulTo;Montgomery.prototype.sqrTo=montSqrTo;function bnpIsEven(){return 0==(0<this.t?this[0]&1:this.s)}function bnpExp(b,a){if(4294967295<b||1>b)return BigInteger.ONE;var c=nbi(),d=nbi(),e=a.convert(this),f=nbits(b)-1;for(e.copyTo(c);0<=--f;)if(a.sqrTo(c,d),0<(b&1<<f))a.mulTo(d,e,c);else var g=c,c=d,d=g;return a.revert(c)}
|
|
|
|
|
function bnModPowInt(b,a){var c;c=256>b||a.isEven()?new Classic(a):new Montgomery(a);return this.exp(b,c)}BigInteger.prototype.copyTo=bnpCopyTo;BigInteger.prototype.fromInt=bnpFromInt;BigInteger.prototype.fromString=bnpFromString;BigInteger.prototype.clamp=bnpClamp;BigInteger.prototype.dlShiftTo=bnpDLShiftTo;BigInteger.prototype.drShiftTo=bnpDRShiftTo;BigInteger.prototype.lShiftTo=bnpLShiftTo;BigInteger.prototype.rShiftTo=bnpRShiftTo;BigInteger.prototype.subTo=bnpSubTo;
|
|
|
|
|
BigInteger.prototype.multiplyTo=bnpMultiplyTo;BigInteger.prototype.squareTo=bnpSquareTo;BigInteger.prototype.divRemTo=bnpDivRemTo;BigInteger.prototype.invDigit=bnpInvDigit;BigInteger.prototype.isEven=bnpIsEven;BigInteger.prototype.exp=bnpExp;BigInteger.prototype.toString=bnToString;BigInteger.prototype.negate=bnNegate;BigInteger.prototype.abs=bnAbs;BigInteger.prototype.compareTo=bnCompareTo;BigInteger.prototype.bitLength=bnBitLength;BigInteger.prototype.mod=bnMod;BigInteger.prototype.modPowInt=bnModPowInt;
|
|
|
|
|
BigInteger.ZERO=nbv(0);BigInteger.ONE=nbv(1);function SecureRandom(){this.nextBytes=function(b){for(var a=0;a<b.length;a++)b[a]=openpgp_crypto_getSecureRandomOctet()}}
|
|
|
|
|
function RSA(){function b(){this.n=null;this.e=0;this.u=this.dmq1=this.dmp1=this.q=this.p=this.d=this.ee=null}this.encrypt=function(a,b,d){return a.modPowInt(b,d)};this.decrypt=function(a,b,d,e,f){var g=a.mod(d).modPow(b.mod(d.subtract(BigInteger.ONE)),d),a=a.mod(e).modPow(b.mod(e.subtract(BigInteger.ONE)),e);util.print_debug("rsa.js decrypt\nxpn:"+util.hexstrdump(g.toMPI())+"\nxqn:"+util.hexstrdump(a.toMPI()));b=a.subtract(g);0==b[0]?(b=g.subtract(a),b=b.multiply(f).mod(e),b=e.subtract(b)):b=b.multiply(f).mod(e);
|
|
|
|
|
return b.multiply(d).add(g)};this.verify=function(a,b,d){return a.modPowInt(b,d)};this.sign=function(a,b,d){return a.modPow(b,d)};this.generate=function(a,c){var d=new b,e=new SecureRandom,f=a>>1;d.e=parseInt(c,16);for(d.ee=new BigInteger(c,16);;){for(;!(d.p=new BigInteger(a-f,1,e),0==d.p.subtract(BigInteger.ONE).gcd(d.ee).compareTo(BigInteger.ONE)&&d.p.isProbablePrime(10)););for(;!(d.q=new BigInteger(f,1,e),0==d.q.subtract(BigInteger.ONE).gcd(d.ee).compareTo(BigInteger.ONE)&&d.q.isProbablePrime(10)););
|
|
|
|
|
if(0>=d.p.compareTo(d.q)){var g=d.p;d.p=d.q;d.q=g}var g=d.p.subtract(BigInteger.ONE),h=d.q.subtract(BigInteger.ONE),k=g.multiply(h);if(0==k.gcd(d.ee).compareTo(BigInteger.ONE)){d.n=d.p.multiply(d.q);d.d=d.ee.modInverse(k);d.dmp1=d.d.mod(g);d.dmq1=d.d.mod(h);d.u=d.p.modInverse(d.q);break}}return d};this.keyObject=b}function MD5(b){b=md5(b);return util.hex2bin(b)}
|
|
|
|
|
if(0>=d.p.compareTo(d.q)){var g=d.p;d.p=d.q;d.q=g}var g=d.p.subtract(BigInteger.ONE),h=d.q.subtract(BigInteger.ONE),j=g.multiply(h);if(0==j.gcd(d.ee).compareTo(BigInteger.ONE)){d.n=d.p.multiply(d.q);d.d=d.ee.modInverse(j);d.dmp1=d.d.mod(g);d.dmq1=d.d.mod(h);d.u=d.p.modInverse(d.q);break}}return d};this.keyObject=b}function MD5(b){b=md5(b);return util.hex2bin(b)}
|
|
|
|
|
function md5cycle(b,a){var c=b[0],d=b[1],e=b[2],f=b[3],c=ff(c,d,e,f,a[0],7,-680876936),f=ff(f,c,d,e,a[1],12,-389564586),e=ff(e,f,c,d,a[2],17,606105819),d=ff(d,e,f,c,a[3],22,-1044525330),c=ff(c,d,e,f,a[4],7,-176418897),f=ff(f,c,d,e,a[5],12,1200080426),e=ff(e,f,c,d,a[6],17,-1473231341),d=ff(d,e,f,c,a[7],22,-45705983),c=ff(c,d,e,f,a[8],7,1770035416),f=ff(f,c,d,e,a[9],12,-1958414417),e=ff(e,f,c,d,a[10],17,-42063),d=ff(d,e,f,c,a[11],22,-1990404162),c=ff(c,d,e,f,a[12],7,1804603682),f=ff(f,c,d,e,a[13],12,
|
|
|
|
|
-40341101),e=ff(e,f,c,d,a[14],17,-1502002290),d=ff(d,e,f,c,a[15],22,1236535329),c=gg(c,d,e,f,a[1],5,-165796510),f=gg(f,c,d,e,a[6],9,-1069501632),e=gg(e,f,c,d,a[11],14,643717713),d=gg(d,e,f,c,a[0],20,-373897302),c=gg(c,d,e,f,a[5],5,-701558691),f=gg(f,c,d,e,a[10],9,38016083),e=gg(e,f,c,d,a[15],14,-660478335),d=gg(d,e,f,c,a[4],20,-405537848),c=gg(c,d,e,f,a[9],5,568446438),f=gg(f,c,d,e,a[14],9,-1019803690),e=gg(e,f,c,d,a[3],14,-187363961),d=gg(d,e,f,c,a[8],20,1163531501),c=gg(c,d,e,f,a[13],5,-1444681467),
|
|
|
|
|
f=gg(f,c,d,e,a[2],9,-51403784),e=gg(e,f,c,d,a[7],14,1735328473),d=gg(d,e,f,c,a[12],20,-1926607734),c=hh(c,d,e,f,a[5],4,-378558),f=hh(f,c,d,e,a[8],11,-2022574463),e=hh(e,f,c,d,a[11],16,1839030562),d=hh(d,e,f,c,a[14],23,-35309556),c=hh(c,d,e,f,a[1],4,-1530992060),f=hh(f,c,d,e,a[4],11,1272893353),e=hh(e,f,c,d,a[7],16,-155497632),d=hh(d,e,f,c,a[10],23,-1094730640),c=hh(c,d,e,f,a[13],4,681279174),f=hh(f,c,d,e,a[0],11,-358537222),e=hh(e,f,c,d,a[3],16,-722521979),d=hh(d,e,f,c,a[6],23,76029189),c=hh(c,d,
|
|
|
|
@ -76,44 +76,44 @@ function compress(b,a){blockA=[];blockB=[];for(var c,d=0;5>d;d++)blockA[d]=new N
|
|
|
|
|
function MDfinish(b,a,c,d){var e=Array(16);zeroX(e);for(var f=0,g=0;g<(c&63);g++)e[g>>>2]^=(a.charCodeAt(f++)&255)<<8*(g&3);e[c>>>2&15]^=1<<8*(c&3)+7;55<(c&63)&&(compress(b,e),e=Array(16),zeroX(e));e[14]=c<<3;e[15]=c>>>29|d<<3;compress(b,e)}function BYTES_TO_DWORD(b){var a=(b.charCodeAt(3)&255)<<24,a=a|(b.charCodeAt(2)&255)<<16,a=a|(b.charCodeAt(1)&255)<<8;return a|=b.charCodeAt(0)&255}
|
|
|
|
|
function RMD(b){var a=Array(RMDsize/32),c=Array(RMDsize/8),d,e;MDinit(a);d=b.length;var f=Array(16);zeroX(f);var g=0;for(e=d;63<e;e-=64){for(var h=0;16>h;h++)f[h]=BYTES_TO_DWORD(b.substr(g,4)),g+=4;compress(a,f)}MDfinish(a,b.substr(g),d,0);for(h=0;h<RMDsize/8;h+=4)c[h]=a[h>>>2]&255,c[h+1]=a[h>>>2]>>>8&255,c[h+2]=a[h>>>2]>>>16&255,c[h+3]=a[h>>>2]>>>24&255;return c}function RMDstring(b){for(var b=RMD(b),a="",c=0;c<RMDsize/8;c++)a+=String.fromCharCode(b[c]);return a}
|
|
|
|
|
var jsSHA=function(){var b=function(a,b){this.highOrder=a;this.lowOrder=b},a=function(a){var b=[],c=8*a.length,d;for(d=0;d<c;d+=8)b[d>>5]|=(a.charCodeAt(d/8)&255)<<24-d%32;return b},c=function(a){var b=[],c=a.length,d,e;for(d=0;d<c;d+=2){e=parseInt(a.substr(d,2),16);if(isNaN(e))return"INVALID HEX STRING";b[d>>3]|=e<<24-4*(d%8)}return b},d=function(a){var b="",c=4*a.length,d,e;for(d=0;d<c;d+=1)e=a[d>>2]>>8*(3-d%4),b+="0123456789abcdef".charAt(e>>4&15)+"0123456789abcdef".charAt(e&15);return b},e=function(a){var b=
|
|
|
|
|
"",c=4*a.length,d,e,f;for(d=0;d<c;d+=3){f=(a[d>>2]>>8*(3-d%4)&255)<<16|(a[d+1>>2]>>8*(3-(d+1)%4)&255)<<8|a[d+2>>2]>>8*(3-(d+2)%4)&255;for(e=0;4>e;e+=1)b=8*d+6*e<=32*a.length?b+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(f>>6*(3-e)&63):b+""}return b},f=function(a){for(var b="",c=0;c<32*a.length;c+=8)b+=String.fromCharCode(a[c>>5]>>>24-c%32&255);return b},g=function(a,b){return a<<b|a>>>32-b},h=function(a,b){return a>>>b|a<<32-b},k=function(a,c){return 32>=c?new b(a.highOrder>>>
|
|
|
|
|
c|a.lowOrder<<32-c,a.lowOrder>>>c|a.highOrder<<32-c):new b(a.lowOrder>>>c|a.highOrder<<32-c,a.highOrder>>>c|a.lowOrder<<32-c)},j=function(a,c){return 32>=c?new b(a.highOrder>>>c,a.lowOrder>>>c|a.highOrder<<32-c):new b(0,a.highOrder<<32-c)},l=function(a,b,c){return a&b^~a&c},o=function(a,c,d){return new b(a.highOrder&c.highOrder^~a.highOrder&d.highOrder,a.lowOrder&c.lowOrder^~a.lowOrder&d.lowOrder)},r=function(a,b,c){return a&b^a&c^b&c},p=function(a,c,d){return new b(a.highOrder&c.highOrder^a.highOrder&
|
|
|
|
|
d.highOrder^c.highOrder&d.highOrder,a.lowOrder&c.lowOrder^a.lowOrder&d.lowOrder^c.lowOrder&d.lowOrder)},m=function(a){return h(a,2)^h(a,13)^h(a,22)},y=function(a){var c=k(a,28),d=k(a,34),a=k(a,39);return new b(c.highOrder^d.highOrder^a.highOrder,c.lowOrder^d.lowOrder^a.lowOrder)},x=function(a){return h(a,6)^h(a,11)^h(a,25)},v=function(a){var c=k(a,14),d=k(a,18),a=k(a,41);return new b(c.highOrder^d.highOrder^a.highOrder,c.lowOrder^d.lowOrder^a.lowOrder)},u=function(a){return h(a,7)^h(a,18)^a>>>3},
|
|
|
|
|
t=function(a){var c=k(a,1),d=k(a,8),a=j(a,7);return new b(c.highOrder^d.highOrder^a.highOrder,c.lowOrder^d.lowOrder^a.lowOrder)},E=function(a){return h(a,17)^h(a,19)^a>>>10},Q=function(a){var c=k(a,19),d=k(a,61),a=j(a,6);return new b(c.highOrder^d.highOrder^a.highOrder,c.lowOrder^d.lowOrder^a.lowOrder)},D=function(a,b){var c=(a&65535)+(b&65535);return((a>>>16)+(b>>>16)+(c>>>16)&65535)<<16|c&65535},M=function(a,b,c,d){var e=(a&65535)+(b&65535)+(c&65535)+(d&65535);return((a>>>16)+(b>>>16)+(c>>>16)+
|
|
|
|
|
"",c=4*a.length,d,e,f;for(d=0;d<c;d+=3){f=(a[d>>2]>>8*(3-d%4)&255)<<16|(a[d+1>>2]>>8*(3-(d+1)%4)&255)<<8|a[d+2>>2]>>8*(3-(d+2)%4)&255;for(e=0;4>e;e+=1)b=8*d+6*e<=32*a.length?b+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(f>>6*(3-e)&63):b+""}return b},f=function(a){for(var b="",c=0;c<32*a.length;c+=8)b+=String.fromCharCode(a[c>>5]>>>24-c%32&255);return b},g=function(a,b){return a<<b|a>>>32-b},h=function(a,b){return a>>>b|a<<32-b},j=function(a,c){return 32>=c?new b(a.highOrder>>>
|
|
|
|
|
c|a.lowOrder<<32-c,a.lowOrder>>>c|a.highOrder<<32-c):new b(a.lowOrder>>>c|a.highOrder<<32-c,a.highOrder>>>c|a.lowOrder<<32-c)},k=function(a,c){return 32>=c?new b(a.highOrder>>>c,a.lowOrder>>>c|a.highOrder<<32-c):new b(0,a.highOrder<<32-c)},l=function(a,b,c){return a&b^~a&c},m=function(a,c,d){return new b(a.highOrder&c.highOrder^~a.highOrder&d.highOrder,a.lowOrder&c.lowOrder^~a.lowOrder&d.lowOrder)},r=function(a,b,c){return a&b^a&c^b&c},p=function(a,c,d){return new b(a.highOrder&c.highOrder^a.highOrder&
|
|
|
|
|
d.highOrder^c.highOrder&d.highOrder,a.lowOrder&c.lowOrder^a.lowOrder&d.lowOrder^c.lowOrder&d.lowOrder)},o=function(a){return h(a,2)^h(a,13)^h(a,22)},y=function(a){var c=j(a,28),d=j(a,34),a=j(a,39);return new b(c.highOrder^d.highOrder^a.highOrder,c.lowOrder^d.lowOrder^a.lowOrder)},x=function(a){return h(a,6)^h(a,11)^h(a,25)},v=function(a){var c=j(a,14),d=j(a,18),a=j(a,41);return new b(c.highOrder^d.highOrder^a.highOrder,c.lowOrder^d.lowOrder^a.lowOrder)},u=function(a){return h(a,7)^h(a,18)^a>>>3},
|
|
|
|
|
t=function(a){var c=j(a,1),d=j(a,8),a=k(a,7);return new b(c.highOrder^d.highOrder^a.highOrder,c.lowOrder^d.lowOrder^a.lowOrder)},E=function(a){return h(a,17)^h(a,19)^a>>>10},Q=function(a){var c=j(a,19),d=j(a,61),a=k(a,6);return new b(c.highOrder^d.highOrder^a.highOrder,c.lowOrder^d.lowOrder^a.lowOrder)},D=function(a,b){var c=(a&65535)+(b&65535);return((a>>>16)+(b>>>16)+(c>>>16)&65535)<<16|c&65535},M=function(a,b,c,d){var e=(a&65535)+(b&65535)+(c&65535)+(d&65535);return((a>>>16)+(b>>>16)+(c>>>16)+
|
|
|
|
|
(d>>>16)+(e>>>16)&65535)<<16|e&65535},K=function(a,b,c,d,e){var f=(a&65535)+(b&65535)+(c&65535)+(d&65535)+(e&65535);return((a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16)+(f>>>16)&65535)<<16|f&65535},w=function(a,c){var d,e,f;d=(a.lowOrder&65535)+(c.lowOrder&65535);e=(a.lowOrder>>>16)+(c.lowOrder>>>16)+(d>>>16);f=(e&65535)<<16|d&65535;d=(a.highOrder&65535)+(c.highOrder&65535)+(e>>>16);e=(a.highOrder>>>16)+(c.highOrder>>>16)+(d>>>16);return new b((e&65535)<<16|d&65535,f)},z=function(a,c,d,e){var f,g,
|
|
|
|
|
h;f=(a.lowOrder&65535)+(c.lowOrder&65535)+(d.lowOrder&65535)+(e.lowOrder&65535);g=(a.lowOrder>>>16)+(c.lowOrder>>>16)+(d.lowOrder>>>16)+(e.lowOrder>>>16)+(f>>>16);h=(g&65535)<<16|f&65535;f=(a.highOrder&65535)+(c.highOrder&65535)+(d.highOrder&65535)+(e.highOrder&65535)+(g>>>16);g=(a.highOrder>>>16)+(c.highOrder>>>16)+(d.highOrder>>>16)+(e.highOrder>>>16)+(f>>>16);return new b((g&65535)<<16|f&65535,h)},T=function(a,c,d,e,f){var g,h,k;g=(a.lowOrder&65535)+(c.lowOrder&65535)+(d.lowOrder&65535)+(e.lowOrder&
|
|
|
|
|
65535)+(f.lowOrder&65535);h=(a.lowOrder>>>16)+(c.lowOrder>>>16)+(d.lowOrder>>>16)+(e.lowOrder>>>16)+(f.lowOrder>>>16)+(g>>>16);k=(h&65535)<<16|g&65535;g=(a.highOrder&65535)+(c.highOrder&65535)+(d.highOrder&65535)+(e.highOrder&65535)+(f.highOrder&65535)+(h>>>16);h=(a.highOrder>>>16)+(c.highOrder>>>16)+(d.highOrder>>>16)+(e.highOrder>>>16)+(f.highOrder>>>16)+(g>>>16);return new b((h&65535)<<16|g&65535,k)},A=function(a,b){var c=[],d,e,f,h,k,j,l,m,p,s=[1732584193,4023233417,2562383102,271733878,3285377520],
|
|
|
|
|
o=[1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,
|
|
|
|
|
2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782];a[b>>5]|=128<<24-b%32;a[(b+65>>9<<4)+15]=b;p=a.length;for(l=0;l<p;l+=16){d=s[0];e=s[1];f=s[2];h=s[3];k=s[4];for(m=0;80>m;m+=1)c[m]=
|
|
|
|
|
16>m?a[m+l]:g(c[m-3]^c[m-8]^c[m-14]^c[m-16],1),j=20>m?K(g(d,5),e&f^~e&h,k,o[m],c[m]):40>m?K(g(d,5),e^f^h,k,o[m],c[m]):60>m?K(g(d,5),r(e,f,h),k,o[m],c[m]):K(g(d,5),e^f^h,k,o[m],c[m]),k=h,h=f,f=g(e,30),e=d,d=j;s[0]=D(d,s[0]);s[1]=D(e,s[1]);s[2]=D(f,s[2]);s[3]=D(h,s[3]);s[4]=D(k,s[4])}return s},B=function(a,c,d){var e,f,g,h,k,j,A,B,C,s,da,Y,L,ea,ca,O,fa,ga,ha,ia,ja,ka,la,ma,q,na,Z=[],sa;if("SHA-224"===d||"SHA-256"===d)da=64,e=(c+65>>9<<4)+15,ea=16,ca=1,q=Number,O=D,fa=M,ga=K,ha=u,ia=E,ja=m,ka=x,ma=r,
|
|
|
|
|
h;f=(a.lowOrder&65535)+(c.lowOrder&65535)+(d.lowOrder&65535)+(e.lowOrder&65535);g=(a.lowOrder>>>16)+(c.lowOrder>>>16)+(d.lowOrder>>>16)+(e.lowOrder>>>16)+(f>>>16);h=(g&65535)<<16|f&65535;f=(a.highOrder&65535)+(c.highOrder&65535)+(d.highOrder&65535)+(e.highOrder&65535)+(g>>>16);g=(a.highOrder>>>16)+(c.highOrder>>>16)+(d.highOrder>>>16)+(e.highOrder>>>16)+(f>>>16);return new b((g&65535)<<16|f&65535,h)},T=function(a,c,d,e,f){var g,h,j;g=(a.lowOrder&65535)+(c.lowOrder&65535)+(d.lowOrder&65535)+(e.lowOrder&
|
|
|
|
|
65535)+(f.lowOrder&65535);h=(a.lowOrder>>>16)+(c.lowOrder>>>16)+(d.lowOrder>>>16)+(e.lowOrder>>>16)+(f.lowOrder>>>16)+(g>>>16);j=(h&65535)<<16|g&65535;g=(a.highOrder&65535)+(c.highOrder&65535)+(d.highOrder&65535)+(e.highOrder&65535)+(f.highOrder&65535)+(h>>>16);h=(a.highOrder>>>16)+(c.highOrder>>>16)+(d.highOrder>>>16)+(e.highOrder>>>16)+(f.highOrder>>>16)+(g>>>16);return new b((h&65535)<<16|g&65535,j)},A=function(a,b){var c=[],d,e,f,h,j,k,l,m,o,s=[1732584193,4023233417,2562383102,271733878,3285377520],
|
|
|
|
|
p=[1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,
|
|
|
|
|
2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782];a[b>>5]|=128<<24-b%32;a[(b+65>>9<<4)+15]=b;o=a.length;for(l=0;l<o;l+=16){d=s[0];e=s[1];f=s[2];h=s[3];j=s[4];for(m=0;80>m;m+=1)c[m]=
|
|
|
|
|
16>m?a[m+l]:g(c[m-3]^c[m-8]^c[m-14]^c[m-16],1),k=20>m?K(g(d,5),e&f^~e&h,j,p[m],c[m]):40>m?K(g(d,5),e^f^h,j,p[m],c[m]):60>m?K(g(d,5),r(e,f,h),j,p[m],c[m]):K(g(d,5),e^f^h,j,p[m],c[m]),j=h,h=f,f=g(e,30),e=d,d=k;s[0]=D(d,s[0]);s[1]=D(e,s[1]);s[2]=D(f,s[2]);s[3]=D(h,s[3]);s[4]=D(j,s[4])}return s},B=function(a,c,d){var e,f,g,h,j,k,A,B,C,s,da,Y,L,ea,ca,O,fa,ga,ha,ia,ja,ka,la,ma,q,na,Z=[],sa;if("SHA-224"===d||"SHA-256"===d)da=64,e=(c+65>>9<<4)+15,ea=16,ca=1,q=Number,O=D,fa=M,ga=K,ha=u,ia=E,ja=o,ka=x,ma=r,
|
|
|
|
|
la=l,na=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,
|
|
|
|
|
4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],s="SHA-224"===d?[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]:[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];else if("SHA-384"===d||"SHA-512"===d)da=80,e=(c+128>>10<<5)+31,ea=32,ca=2,q=b,O=w,fa=z,ga=T,ha=t,ia=Q,ja=y,ka=v,ma=
|
|
|
|
|
p,la=o,na=[new q(1116352408,3609767458),new q(1899447441,602891725),new q(3049323471,3964484399),new q(3921009573,2173295548),new q(961987163,4081628472),new q(1508970993,3053834265),new q(2453635748,2937671579),new q(2870763221,3664609560),new q(3624381080,2734883394),new q(310598401,1164996542),new q(607225278,1323610764),new q(1426881987,3590304994),new q(1925078388,4068182383),new q(2162078206,991336113),new q(2614888103,633803317),new q(3248222580,3479774868),new q(3835390401,2666613458),new q(4022224774,
|
|
|
|
|
p,la=m,na=[new q(1116352408,3609767458),new q(1899447441,602891725),new q(3049323471,3964484399),new q(3921009573,2173295548),new q(961987163,4081628472),new q(1508970993,3053834265),new q(2453635748,2937671579),new q(2870763221,3664609560),new q(3624381080,2734883394),new q(310598401,1164996542),new q(607225278,1323610764),new q(1426881987,3590304994),new q(1925078388,4068182383),new q(2162078206,991336113),new q(2614888103,633803317),new q(3248222580,3479774868),new q(3835390401,2666613458),new q(4022224774,
|
|
|
|
|
944711139),new q(264347078,2341262773),new q(604807628,2007800933),new q(770255983,1495990901),new q(1249150122,1856431235),new q(1555081692,3175218132),new q(1996064986,2198950837),new q(2554220882,3999719339),new q(2821834349,766784016),new q(2952996808,2566594879),new q(3210313671,3203337956),new q(3336571891,1034457026),new q(3584528711,2466948901),new q(113926993,3758326383),new q(338241895,168717936),new q(666307205,1188179964),new q(773529912,1546045734),new q(1294757372,1522805485),new q(1396182291,
|
|
|
|
|
2643833823),new q(1695183700,2343527390),new q(1986661051,1014477480),new q(2177026350,1206759142),new q(2456956037,344077627),new q(2730485921,1290863460),new q(2820302411,3158454273),new q(3259730800,3505952657),new q(3345764771,106217008),new q(3516065817,3606008344),new q(3600352804,1432725776),new q(4094571909,1467031594),new q(275423344,851169720),new q(430227734,3100823752),new q(506948616,1363258195),new q(659060556,3750685593),new q(883997877,3785050280),new q(958139571,3318307427),new q(1322822218,
|
|
|
|
|
3812723403),new q(1537002063,2003034995),new q(1747873779,3602036899),new q(1955562222,1575990012),new q(2024104815,1125592928),new q(2227730452,2716904306),new q(2361852424,442776044),new q(2428436474,593698344),new q(2756734187,3733110249),new q(3204031479,2999351573),new q(3329325298,3815920427),new q(3391569614,3928383900),new q(3515267271,566280711),new q(3940187606,3454069534),new q(4118630271,4000239992),new q(116418474,1914138554),new q(174292421,2731055270),new q(289380356,3203993006),new q(460393269,
|
|
|
|
|
320620315),new q(685471733,587496836),new q(852142971,1086792851),new q(1017036298,365543100),new q(1126000580,2618297676),new q(1288033470,3409855158),new q(1501505948,4234509866),new q(1607167915,987167468),new q(1816402316,1246189591)],s="SHA-384"===d?[new q(3418070365,3238371032),new q(1654270250,914150663),new q(2438529370,812702999),new q(355462360,4144912697),new q(1731405415,4290775857),new q(41048885895,1750603025),new q(3675008525,1694076839),new q(1203062813,3204075428)]:[new q(1779033703,
|
|
|
|
|
4089235720),new q(3144134277,2227873595),new q(1013904242,4271175723),new q(2773480762,1595750129),new q(1359893119,2917565137),new q(2600822924,725511199),new q(528734635,4215389547),new q(1541459225,327033209)];a[c>>5]|=128<<24-c%32;a[e]=c;sa=a.length;for(Y=0;Y<sa;Y+=ea){c=s[0];e=s[1];f=s[2];g=s[3];h=s[4];k=s[5];j=s[6];A=s[7];for(L=0;L<da;L+=1)Z[L]=16>L?new q(a[L*ca+Y],a[L*ca+Y+1]):fa(ia(Z[L-2]),Z[L-7],ha(Z[L-15]),Z[L-16]),B=ga(A,ka(h),la(h,k,j),na[L],Z[L]),C=O(ja(c),ma(c,e,f)),A=j,j=k,k=h,h=O(g,
|
|
|
|
|
B),g=f,f=e,e=c,c=O(B,C);s[0]=O(c,s[0]);s[1]=O(e,s[1]);s[2]=O(f,s[2]);s[3]=O(g,s[3]);s[4]=O(h,s[4]);s[5]=O(k,s[5]);s[6]=O(j,s[6]);s[7]=O(A,s[7])}switch(d){case "SHA-224":return[s[0],s[1],s[2],s[3],s[4],s[5],s[6]];case "SHA-256":return s;case "SHA-384":return[s[0].highOrder,s[0].lowOrder,s[1].highOrder,s[1].lowOrder,s[2].highOrder,s[2].lowOrder,s[3].highOrder,s[3].lowOrder,s[4].highOrder,s[4].lowOrder,s[5].highOrder,s[5].lowOrder];case "SHA-512":return[s[0].highOrder,s[0].lowOrder,s[1].highOrder,s[1].lowOrder,
|
|
|
|
|
4089235720),new q(3144134277,2227873595),new q(1013904242,4271175723),new q(2773480762,1595750129),new q(1359893119,2917565137),new q(2600822924,725511199),new q(528734635,4215389547),new q(1541459225,327033209)];a[c>>5]|=128<<24-c%32;a[e]=c;sa=a.length;for(Y=0;Y<sa;Y+=ea){c=s[0];e=s[1];f=s[2];g=s[3];h=s[4];j=s[5];k=s[6];A=s[7];for(L=0;L<da;L+=1)Z[L]=16>L?new q(a[L*ca+Y],a[L*ca+Y+1]):fa(ia(Z[L-2]),Z[L-7],ha(Z[L-15]),Z[L-16]),B=ga(A,ka(h),la(h,j,k),na[L],Z[L]),C=O(ja(c),ma(c,e,f)),A=k,k=j,j=h,h=O(g,
|
|
|
|
|
B),g=f,f=e,e=c,c=O(B,C);s[0]=O(c,s[0]);s[1]=O(e,s[1]);s[2]=O(f,s[2]);s[3]=O(g,s[3]);s[4]=O(h,s[4]);s[5]=O(j,s[5]);s[6]=O(k,s[6]);s[7]=O(A,s[7])}switch(d){case "SHA-224":return[s[0],s[1],s[2],s[3],s[4],s[5],s[6]];case "SHA-256":return s;case "SHA-384":return[s[0].highOrder,s[0].lowOrder,s[1].highOrder,s[1].lowOrder,s[2].highOrder,s[2].lowOrder,s[3].highOrder,s[3].lowOrder,s[4].highOrder,s[4].lowOrder,s[5].highOrder,s[5].lowOrder];case "SHA-512":return[s[0].highOrder,s[0].lowOrder,s[1].highOrder,s[1].lowOrder,
|
|
|
|
|
s[2].highOrder,s[2].lowOrder,s[3].highOrder,s[3].lowOrder,s[4].highOrder,s[4].lowOrder,s[5].highOrder,s[5].lowOrder,s[6].highOrder,s[6].lowOrder,s[7].highOrder,s[7].lowOrder];default:return[]}},C=function(b,d){this.strToHash=this.strBinLen=this.sha512=this.sha384=this.sha256=this.sha224=this.sha1=null;if("HEX"===d){if(0!==b.length%2)return"TEXT MUST BE IN BYTE INCREMENTS";this.strBinLen=4*b.length;this.strToHash=c(b)}else if("ASCII"===d||"undefined"===typeof d)this.strBinLen=8*b.length,this.strToHash=
|
|
|
|
|
a(b);else return"UNKNOWN TEXT INPUT TYPE"};C.prototype={getHash:function(a,b){var c=null,g=this.strToHash.slice();switch(b){case "HEX":c=d;break;case "B64":c=e;break;case "ASCII":c=f;break;default:return"FORMAT NOT RECOGNIZED"}switch(a){case "SHA-1":if(null===this.sha1)this.sha1=A(g,this.strBinLen);return c(this.sha1);case "SHA-224":if(null===this.sha224)this.sha224=B(g,this.strBinLen,a);return c(this.sha224);case "SHA-256":if(null===this.sha256)this.sha256=B(g,this.strBinLen,a);return c(this.sha256);
|
|
|
|
|
case "SHA-384":if(null===this.sha384)this.sha384=B(g,this.strBinLen,a);return c(this.sha384);case "SHA-512":if(null===this.sha512)this.sha512=B(g,this.strBinLen,a);return c(this.sha512);default:return"HASH NOT RECOGNIZED"}},getHMAC:function(b,g,h,k){var j,m,l,p,o;m=[];var t=[];switch(k){case "HEX":k=d;break;case "B64":k=e;break;case "ASCII":k=f;break;default:return"FORMAT NOT RECOGNIZED"}switch(h){case "SHA-1":j=64;o=160;break;case "SHA-224":j=64;o=224;break;case "SHA-256":j=64;o=256;break;case "SHA-384":j=
|
|
|
|
|
128;o=384;break;case "SHA-512":j=128;o=512;break;default:return"HASH NOT RECOGNIZED"}if("HEX"===g){if(0!==b.length%2)return"KEY MUST BE IN BYTE INCREMENTS";g=c(b);p=4*b.length}else if("ASCII"===g)g=a(b),p=8*b.length;else return"UNKNOWN KEY INPUT TYPE";b=8*j;l=j/4-1;j<p/8?(g="SHA-1"===h?A(g,p):B(g,p,h),g[l]&=4294967040):j>p/8&&(g[l]&=4294967040);for(j=0;j<=l;j+=1)m[j]=g[j]^909522486,t[j]=g[j]^1549556828;"SHA-1"===h?(m=A(m.concat(this.strToHash),b+this.strBinLen),m=A(t.concat(m),b+o)):(m=B(m.concat(this.strToHash),
|
|
|
|
|
b+this.strBinLen,h),m=B(t.concat(m),b+o,h));return k(m)}};return C}();function str_sha1(b){return(new jsSHA(b,"ASCII")).getHash("SHA-1","ASCII")}function str_sha224(b){return(new jsSHA(b,"ASCII")).getHash("SHA-224","ASCII")}function str_sha256(b){return(new jsSHA(b,"ASCII")).getHash("SHA-256","ASCII")}function str_sha384(b){return(new jsSHA(b,"ASCII")).getHash("SHA-384","ASCII")}function str_sha512(b){return(new jsSHA(b,"ASCII")).getHash("SHA-512","ASCII")}
|
|
|
|
|
function openpgp_cfb_encrypt(b,a,c,d,e,f){var g=Array(d),h=Array(d),b=b+b.charAt(d-2)+b.charAt(d-1);util.print_debug("prefixrandom:"+util.hexstrdump(b));for(var k="",j=0;j<d;j++)g[j]=0;h=a(g,e);for(j=0;j<d;j++)k+=String.fromCharCode(h[j]^b.charCodeAt(j));for(j=0;j<d;j++)g[j]=k.charCodeAt(j);h=a(g,e);k+=String.fromCharCode(h[0]^b.charCodeAt(d));k+=String.fromCharCode(h[1]^b.charCodeAt(d+1));if(f)for(j=0;j<d;j++)g[j]=k.charCodeAt(j+2);else for(j=0;j<d;j++)g[j]=k.charCodeAt(j);h=a(g,e);if(f){for(j=0;j<
|
|
|
|
|
d;j++)k+=String.fromCharCode(h[j]^c.charCodeAt(j));for(n=d+2;n<c.length;n+=d){for(j=0;j<d;j++)g[j]=k.charCodeAt(n+j);h=a(g,e);for(j=0;j<d;j++)k+=String.fromCharCode(h[j]^c.charCodeAt(n-2+j))}}else{c=" "+c;for(j=2;j<d;j++)k+=String.fromCharCode(h[j]^c.charCodeAt(j));b=k.substring(0,2*d).split("");k=k.substring(d);for(n=d;n<c.length;n+=d){for(j=0;j<d;j++)g[j]=k.charCodeAt(j);k="";h=a(g,e);for(j=0;j<d;j++)b.push(String.fromCharCode(h[j]^c.charCodeAt(n+j))),k+=String.fromCharCode(h[j]^c.charCodeAt(n+
|
|
|
|
|
j))}k=b.join("")}return k}function openpgp_cfb_mdc(b,a,c,d){var e=Array(a),f=Array(a),g;for(g=0;g<a;g++)e[g]=0;e=b(e,c);for(g=0;g<a;g++)f[g]=d.charCodeAt(g),e[g]^=f[g];f=b(f,c);return util.bin2str(e)+String.fromCharCode(f[0]^d.charCodeAt(a))+String.fromCharCode(f[1]^d.charCodeAt(a+1))}
|
|
|
|
|
function openpgp_cfb_decrypt(b,a,c,d,e){util.print_debug("resync:"+e);var f=Array(a),g=Array(a),h,k="",j=[];for(h=0;h<a;h++)f[h]=0;f=b(f,c);for(h=0;h<a;h++)g[h]=d.charCodeAt(h),f[h]^=g[h];g=b(g,c);util.print_debug("openpgp_cfb_decrypt:\niblock:"+util.hexidump(f)+"\nablock:"+util.hexidump(g)+"\n");util.print_debug((g[0]^d.charCodeAt(a)).toString(16)+(g[1]^d.charCodeAt(a+1)).toString(16));if(f[a-2]!=(g[0]^d.charCodeAt(a))||f[a-1]!=(g[1]^d.charCodeAt(a+1)))return util.print_eror("error duding decryption. Symmectric encrypted data not valid."),
|
|
|
|
|
j.join("");if(e){for(h=0;h<a;h++)f[h]=d.charCodeAt(h+2);k=a+2}else{for(h=0;h<a;h++)f[h]=d.charCodeAt(h);k=a}for(;k<d.length;k+=a){g=b(f,c);for(h=0;h<a&&h+k<d.length;h++)f[h]=d.charCodeAt(k+h),j.push(String.fromCharCode(g[h]^f[h]))}return j.join("")}
|
|
|
|
|
function normal_cfb_encrypt(b,a,c,d,e){for(var f="",f="",g=0,h=[],k=[],f=e.substring(0,a);d.length>a*g;){for(var e=b(f,c),f=d.substring(g*a,g*a+a),j=0;j<f.length;j++)k.push(String.fromCharCode(f.charCodeAt(j)^e[j]));f=k.join("");k=[];h.push(f);g++}return h.join("")}
|
|
|
|
|
function normal_cfb_decrypt(b,a,c,d,e){var f="",g=0,h=[];if(null==e)for(e=0;e<a;e++)f+=String.fromCharCode(0);else f=e.substring(0,a);for(;d.length>a*g;){for(var k=b(f,c),f=d.substring(g*a+0,g*a+a+0),e=0;e<f.length;e++)h.push(String.fromCharCode(f.charCodeAt(e)^k[e]));g++}return h.join("")}
|
|
|
|
|
case "SHA-384":if(null===this.sha384)this.sha384=B(g,this.strBinLen,a);return c(this.sha384);case "SHA-512":if(null===this.sha512)this.sha512=B(g,this.strBinLen,a);return c(this.sha512);default:return"HASH NOT RECOGNIZED"}},getHMAC:function(b,g,h,j){var k,l,m,o,p;l=[];var t=[];switch(j){case "HEX":j=d;break;case "B64":j=e;break;case "ASCII":j=f;break;default:return"FORMAT NOT RECOGNIZED"}switch(h){case "SHA-1":k=64;p=160;break;case "SHA-224":k=64;p=224;break;case "SHA-256":k=64;p=256;break;case "SHA-384":k=
|
|
|
|
|
128;p=384;break;case "SHA-512":k=128;p=512;break;default:return"HASH NOT RECOGNIZED"}if("HEX"===g){if(0!==b.length%2)return"KEY MUST BE IN BYTE INCREMENTS";g=c(b);o=4*b.length}else if("ASCII"===g)g=a(b),o=8*b.length;else return"UNKNOWN KEY INPUT TYPE";b=8*k;m=k/4-1;k<o/8?(g="SHA-1"===h?A(g,o):B(g,o,h),g[m]&=4294967040):k>o/8&&(g[m]&=4294967040);for(k=0;k<=m;k+=1)l[k]=g[k]^909522486,t[k]=g[k]^1549556828;"SHA-1"===h?(l=A(l.concat(this.strToHash),b+this.strBinLen),l=A(t.concat(l),b+p)):(l=B(l.concat(this.strToHash),
|
|
|
|
|
b+this.strBinLen,h),l=B(t.concat(l),b+p,h));return j(l)}};return C}();function str_sha1(b){return(new jsSHA(b,"ASCII")).getHash("SHA-1","ASCII")}function str_sha224(b){return(new jsSHA(b,"ASCII")).getHash("SHA-224","ASCII")}function str_sha256(b){return(new jsSHA(b,"ASCII")).getHash("SHA-256","ASCII")}function str_sha384(b){return(new jsSHA(b,"ASCII")).getHash("SHA-384","ASCII")}function str_sha512(b){return(new jsSHA(b,"ASCII")).getHash("SHA-512","ASCII")}
|
|
|
|
|
function openpgp_cfb_encrypt(b,a,c,d,e,f){var g=Array(d),h=Array(d),b=b+b.charAt(d-2)+b.charAt(d-1);util.print_debug("prefixrandom:"+util.hexstrdump(b));for(var j="",k=0;k<d;k++)g[k]=0;h=a(g,e);for(k=0;k<d;k++)j+=String.fromCharCode(h[k]^b.charCodeAt(k));for(k=0;k<d;k++)g[k]=j.charCodeAt(k);h=a(g,e);j+=String.fromCharCode(h[0]^b.charCodeAt(d));j+=String.fromCharCode(h[1]^b.charCodeAt(d+1));if(f)for(k=0;k<d;k++)g[k]=j.charCodeAt(k+2);else for(k=0;k<d;k++)g[k]=j.charCodeAt(k);h=a(g,e);if(f){for(k=0;k<
|
|
|
|
|
d;k++)j+=String.fromCharCode(h[k]^c.charCodeAt(k));for(n=d+2;n<c.length;n+=d){for(k=0;k<d;k++)g[k]=j.charCodeAt(n+k);h=a(g,e);for(k=0;k<d;k++)j+=String.fromCharCode(h[k]^c.charCodeAt(n-2+k))}}else{c=" "+c;for(k=2;k<d;k++)j+=String.fromCharCode(h[k]^c.charCodeAt(k));b=j.substring(0,2*d).split("");j=j.substring(d);for(n=d;n<c.length;n+=d){for(k=0;k<d;k++)g[k]=j.charCodeAt(k);j="";h=a(g,e);for(k=0;k<d;k++)b.push(String.fromCharCode(h[k]^c.charCodeAt(n+k))),j+=String.fromCharCode(h[k]^c.charCodeAt(n+
|
|
|
|
|
k))}j=b.join("")}return j}function openpgp_cfb_mdc(b,a,c,d){var e=Array(a),f=Array(a),g;for(g=0;g<a;g++)e[g]=0;e=b(e,c);for(g=0;g<a;g++)f[g]=d.charCodeAt(g),e[g]^=f[g];f=b(f,c);return util.bin2str(e)+String.fromCharCode(f[0]^d.charCodeAt(a))+String.fromCharCode(f[1]^d.charCodeAt(a+1))}
|
|
|
|
|
function openpgp_cfb_decrypt(b,a,c,d,e){util.print_debug("resync:"+e);var f=Array(a),g=Array(a),h,j="",k=[];for(h=0;h<a;h++)f[h]=0;f=b(f,c);for(h=0;h<a;h++)g[h]=d.charCodeAt(h),f[h]^=g[h];g=b(g,c);util.print_debug("openpgp_cfb_decrypt:\niblock:"+util.hexidump(f)+"\nablock:"+util.hexidump(g)+"\n");util.print_debug((g[0]^d.charCodeAt(a)).toString(16)+(g[1]^d.charCodeAt(a+1)).toString(16));if(f[a-2]!=(g[0]^d.charCodeAt(a))||f[a-1]!=(g[1]^d.charCodeAt(a+1)))return util.print_eror("error duding decryption. Symmectric encrypted data not valid."),
|
|
|
|
|
k.join("");if(e){for(h=0;h<a;h++)f[h]=d.charCodeAt(h+2);j=a+2}else{for(h=0;h<a;h++)f[h]=d.charCodeAt(h);j=a}for(;j<d.length;j+=a){g=b(f,c);for(h=0;h<a&&h+j<d.length;h++)f[h]=d.charCodeAt(j+h),k.push(String.fromCharCode(g[h]^f[h]))}return k.join("")}
|
|
|
|
|
function normal_cfb_encrypt(b,a,c,d,e){for(var f="",f="",g=0,h=[],j=[],f=e.substring(0,a);d.length>a*g;){for(var e=b(f,c),f=d.substring(g*a,g*a+a),k=0;k<f.length;k++)j.push(String.fromCharCode(f.charCodeAt(k)^e[k]));f=j.join("");j=[];h.push(f);g++}return h.join("")}
|
|
|
|
|
function normal_cfb_decrypt(b,a,c,d,e){var f="",g=0,h=[];if(null==e)for(e=0;e<a;e++)f+=String.fromCharCode(0);else f=e.substring(0,a);for(;d.length>a*g;){for(var j=b(f,c),f=d.substring(g*a+0,g*a+a+0),e=0;e<f.length;e++)h.push(String.fromCharCode(f.charCodeAt(e)^j[e]));g++}return h.join("")}
|
|
|
|
|
function openpgp_crypto_asymetricEncrypt(b,a,c){switch(b){case 1:case 2:case 3:var b=new RSA,d=a[0].toBigInteger(),a=a[1].toBigInteger(),c=c.toBigInteger();return b.encrypt(c,a,d).toMPI();case 16:var b=new Elgamal,d=a[0].toBigInteger(),e=a[1].toBigInteger(),a=a[2].toBigInteger(),c=c.toBigInteger();return b.encrypt(c,e,d,a);default:return null}}
|
|
|
|
|
function openpgp_crypto_asymetricDecrypt(b,a,c,d){switch(b){case 1:case 2:case 3:var b=new RSA,e=c[0].toBigInteger(),a=c[1].toBigInteger(),f=c[2].toBigInteger(),c=c[3].toBigInteger(),d=d[0].toBigInteger();return b.decrypt(d,e,a,f,c);case 16:return b=new Elgamal,c=c[0].toBigInteger(),e=d[0].toBigInteger(),d=d[1].toBigInteger(),a=a[0].toBigInteger(),b.decrypt(e,d,a,c);default:return null}}
|
|
|
|
|
function openpgp_crypto_getPrefixRandom(b){switch(b){case 2:case 3:case 4:return openpgp_crypto_getRandomBytes(8);case 7:case 8:case 9:case 10:return openpgp_crypto_getRandomBytes(16);default:return null}}
|
|
|
|
|
function openpgp_crypto_MDCSystemBytes(b,a,c){util.print_debug_hexstr_dump("openpgp_crypto_symmetricDecrypt:\nencrypteddata:",c);switch(b){case 0:return c;case 2:return openpgp_cfb_mdc(desede,8,a,c,openpgp_cfb);case 3:return openpgp_cfb_mdc(cast5_encrypt,8,a,c);case 4:return openpgp_cfb_mdc(BFencrypt,8,a,c);case 7:case 8:case 9:return openpgp_cfb_mdc(AESencrypt,16,keyExpansion(a),c);case 10:return openpgp_cfb_mdc(TFencrypt,16,a,c);case 1:util.print_error(""+(1==b?"IDEA Algorithm not implemented":
|
|
|
|
|
"Twofish Algorithm not implemented"))}return null}function openpgp_crypto_generateSessionKey(b){switch(b){case 2:case 8:return openpgp_crypto_getRandomBytes(24);case 3:case 4:case 7:return util.print_debug("length = 16:\n"+util.hexstrdump(openpgp_crypto_getRandomBytes(16))),openpgp_crypto_getRandomBytes(16);case 9:case 10:return openpgp_crypto_getRandomBytes(32)}return null}
|
|
|
|
|
function openpgp_crypto_verifySignature(b,a,c,d,e){var f=openpgp_crypto_hashData(a,e);switch(b){case 1:case 2:case 3:e=new RSA;b=d[0].toBigInteger();d=d[1].toBigInteger();c=c[0].toBigInteger();d=e.verify(c,d,b);a=openpgp_encoding_emsa_pkcs1_decode(a,d.toMPI().substring(2));return-1==a?(util.print_error("PKCS1 padding in message or key incorrect. Aborting..."),!1):a==f;case 16:return util.print_error("signing with Elgamal is not defined in the OpenPGP standard."),null;case 17:var b=new DSA,f=c[0].toBigInteger(),
|
|
|
|
|
c=c[1].toBigInteger(),g=d[0].toBigInteger(),h=d[1].toBigInteger(),k=d[2].toBigInteger(),d=d[3].toBigInteger(),d=b.verify(a,f,c,e,g,h,k,d);return 0==d.compareTo(f);default:return null}}
|
|
|
|
|
c=c[1].toBigInteger(),g=d[0].toBigInteger(),h=d[1].toBigInteger(),j=d[2].toBigInteger(),d=d[3].toBigInteger(),d=b.verify(a,f,c,e,g,h,j,d);return 0==d.compareTo(f);default:return null}}
|
|
|
|
|
function openpgp_crypto_signData(b,a,c,d,e){switch(a){case 1:case 2:case 3:var a=new RSA,d=d[0].toBigInteger(),f=c[0].toBigInteger(),b=openpgp_encoding_emsa_pkcs1_encode(b,e,c[0].mpiByteLength);util.print_debug("signing using RSA");return a.sign(b,d,f).toMPI();case 17:a=new DSA;util.print_debug("DSA Sign: q size in Bytes:"+c[1].getByteLength());var f=c[0].toBigInteger(),g=c[1].toBigInteger(),h=c[2].toBigInteger();c[3].toBigInteger();c=d[0].toBigInteger();b=a.sign(b,e,h,f,g,c);util.print_debug("signing using DSA\n result:"+
|
|
|
|
|
util.hexstrdump(b[0])+"|"+util.hexstrdump(b[1]));return b[0]+b[1];case 16:return util.print_debug("signing with Elgamal is not defined in the OpenPGP standard."),null;default:return null}}function openpgp_crypto_hashData(b,a){var c=null;switch(b){case 1:c=MD5(a);break;case 2:c=str_sha1(a);break;case 3:c=RMDstring(a);break;case 8:c=str_sha256(a);break;case 9:c=str_sha384(a);break;case 10:c=str_sha512(a);break;case 11:c=str_sha224(a)}return c}
|
|
|
|
|
function openpgp_crypto_getHashByteLength(b){switch(b){case 1:return 16;case 2:case 3:return 20;case 8:return 32;case 9:return 48;case 10:return 64;case 11:return 28}return null}function openpgp_crypto_getRandomBytes(b){for(var a="",c=0;c<b;c++)a+=String.fromCharCode(openpgp_crypto_getSecureRandomOctet());return a}function openpgp_crypto_getPseudoRandom(b,a){return Math.round(Math.random()*(a-b))+b}
|
|
|
|
@ -151,10 +151,10 @@ var Rcon=[1,2,4,8,16,32,64,128,27,54,108,216,171,77,154,47,94,188,99,198,151,53,
|
|
|
|
|
967348625,832869781,3543655652,4069226873,3576883175,2336475336,1851340599,3669454189,25988493,2976175573,2631028302,1239460265,3635702892,2902087254,4077384948,3475368682,3400492389,4102978170,1206496942,270010376,1876277946,4035475576,1248797989,1550986798,941890588,1475454630,1942467764,2538718918,3408128232,2709315037,3902567540,1042358047,2531085131,1641856445,226921355,260409994,3767562352,2084716094,1908716981,3433719398,2430093384,100991747,4144101110,470945294,3265487201,1784624437,2935576407,
|
|
|
|
|
1775286713,395413126,2572730817,975641885,666476190,3644383713,3943954680,733190296,573772049,3535497577,2842745305,126455438,866620564,766942107,1008868894,361924487,3374377449,2269761230,2868860245,1350051880,2776293343,59739276,1509466529,159418761,437718285,1708834751,3610371814,2227585602,3501746280,2193834305,699439513,1517759789,504434447,2076946608,2835108948,1842789307,742004246];function B0(b){return b&255}function B1(b){return b>>8&255}function B2(b){return b>>16&255}
|
|
|
|
|
function B3(b){return b>>24&255}function F1(b,a,c,d){return B1(T1[b&255])|B1(T1[a>>8&255])<<8|B1(T1[c>>16&255])<<16|B1(T1[d>>>24])<<24}function packBytes(b){var a,c,d=b.length,e=Array(d/4);if(b&&!(d%4)){for(a=0,c=0;c<d;c+=4)e[a++]=b[c]|b[c+1]<<8|b[c+2]<<16|b[c+3]<<24;return e}}function unpackBytes(b){var a,c=0,d=b.length,e=Array(4*d);for(a=0;a<d;a++)e[c++]=B0(b[a]),e[c++]=B1(b[a]),e[c++]=B2(b[a]),e[c++]=B3(b[a]);return e}var maxkc=8,maxrk=14;
|
|
|
|
|
function keyExpansion(b){var a,c,d,e,f=Array(maxrk+1),g=b.length,h=Array(maxkc),k=Array(maxkc),j=0;if(16==g)e=10,a=4;else if(24==g)e=12,a=6;else if(32==g)e=14,a=8;else{util.print_error("aes.js: Invalid key-length for AES key:"+g);return}for(c=0;c<maxrk+1;c++)f[c]=Array(4);for(c=0,d=0;d<g;d++,c+=4)h[d]=b.charCodeAt(c)|b.charCodeAt(c+1)<<8|b.charCodeAt(c+2)<<16|b.charCodeAt(c+3)<<24;for(d=a-1;0<=d;d--)k[d]=h[d];for(d=c=b=0;d<a&&b<e+1;){for(;d<a&&4>c;d++,c++)f[b][c]=k[d];4==c&&(b++,c=0)}for(;b<e+1;){d=
|
|
|
|
|
k[a-1];k[0]^=S[B1(d)]|S[B2(d)]<<8|S[B3(d)]<<16|S[B0(d)]<<24;k[0]^=Rcon[j++];if(8!=a)d=1;else{for(d=1;d<a/2;d++)k[d]^=k[d-1];d=k[a/2-1];k[a/2]^=S[B0(d)]|S[B1(d)]<<8|S[B2(d)]<<16|S[B3(d)]<<24;d=a/2+1}for(;d<a;d++)k[d]^=k[d-1];for(d=0;d<a&&b<e+1;){for(;d<a&&4>c;d++,c++)f[b][c]=k[d];4==c&&(b++,c=0)}}this.rounds=e;this.rk=f;return this}
|
|
|
|
|
function AESencrypt(b,a){var c,d,e,f,g,h=packBytes(b),k=a.rounds,j=h[0],l=h[1],o=h[2];g=h[3];for(c=0;c<k-1;c++)d=j^a.rk[c][0],e=l^a.rk[c][1],f=o^a.rk[c][2],g^=a.rk[c][3],j=T1[d&255]^T2[e>>8&255]^T3[f>>16&255]^T4[g>>>24],l=T1[e&255]^T2[f>>8&255]^T3[g>>16&255]^T4[d>>>24],o=T1[f&255]^T2[g>>8&255]^T3[d>>16&255]^T4[e>>>24],g=T1[g&255]^T2[d>>8&255]^T3[e>>16&255]^T4[f>>>24];c=k-1;d=j^a.rk[c][0];e=l^a.rk[c][1];f=o^a.rk[c][2];g^=a.rk[c][3];h[0]=F1(d,e,f,g)^a.rk[k][0];h[1]=F1(e,f,g,d)^a.rk[k][1];h[2]=F1(f,
|
|
|
|
|
g,d,e)^a.rk[k][2];h[3]=F1(g,d,e,f)^a.rk[k][3];return unpackBytes(h)}function Blowfish(){}Blowfish.prototype.BLOCKSIZE=8;
|
|
|
|
|
function keyExpansion(b){var a,c,d,e,f=Array(maxrk+1),g=b.length,h=Array(maxkc),j=Array(maxkc),k=0;if(16==g)e=10,a=4;else if(24==g)e=12,a=6;else if(32==g)e=14,a=8;else{util.print_error("aes.js: Invalid key-length for AES key:"+g);return}for(c=0;c<maxrk+1;c++)f[c]=Array(4);for(c=0,d=0;d<g;d++,c+=4)h[d]=b.charCodeAt(c)|b.charCodeAt(c+1)<<8|b.charCodeAt(c+2)<<16|b.charCodeAt(c+3)<<24;for(d=a-1;0<=d;d--)j[d]=h[d];for(d=c=b=0;d<a&&b<e+1;){for(;d<a&&4>c;d++,c++)f[b][c]=j[d];4==c&&(b++,c=0)}for(;b<e+1;){d=
|
|
|
|
|
j[a-1];j[0]^=S[B1(d)]|S[B2(d)]<<8|S[B3(d)]<<16|S[B0(d)]<<24;j[0]^=Rcon[k++];if(8!=a)d=1;else{for(d=1;d<a/2;d++)j[d]^=j[d-1];d=j[a/2-1];j[a/2]^=S[B0(d)]|S[B1(d)]<<8|S[B2(d)]<<16|S[B3(d)]<<24;d=a/2+1}for(;d<a;d++)j[d]^=j[d-1];for(d=0;d<a&&b<e+1;){for(;d<a&&4>c;d++,c++)f[b][c]=j[d];4==c&&(b++,c=0)}}this.rounds=e;this.rk=f;return this}
|
|
|
|
|
function AESencrypt(b,a){var c,d,e,f,g,h=packBytes(b),j=a.rounds,k=h[0],l=h[1],m=h[2];g=h[3];for(c=0;c<j-1;c++)d=k^a.rk[c][0],e=l^a.rk[c][1],f=m^a.rk[c][2],g^=a.rk[c][3],k=T1[d&255]^T2[e>>8&255]^T3[f>>16&255]^T4[g>>>24],l=T1[e&255]^T2[f>>8&255]^T3[g>>16&255]^T4[d>>>24],m=T1[f&255]^T2[g>>8&255]^T3[d>>16&255]^T4[e>>>24],g=T1[g&255]^T2[d>>8&255]^T3[e>>16&255]^T4[f>>>24];c=j-1;d=k^a.rk[c][0];e=l^a.rk[c][1];f=m^a.rk[c][2];g^=a.rk[c][3];h[0]=F1(d,e,f,g)^a.rk[j][0];h[1]=F1(e,f,g,d)^a.rk[j][1];h[2]=F1(f,
|
|
|
|
|
g,d,e)^a.rk[j][2];h[3]=F1(g,d,e,f)^a.rk[j][3];return unpackBytes(h)}function Blowfish(){}Blowfish.prototype.BLOCKSIZE=8;
|
|
|
|
|
Blowfish.prototype.SBOXES=[[3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110,
|
|
|
|
|
2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486,1724537150,
|
|
|
|
|
2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882,
|
|
|
|
@ -183,15 +183,15 @@ Blowfish.prototype._decrypt_block=function(b){var a=b[0],c=b[1],d;for(d=this.NN+
|
|
|
|
|
Blowfish.prototype.init=function(b){var a,c=0;this.parray=[];for(a=0;a<this.NN+2;++a){var d=0,e;for(e=0;4>e;++e)d=d<<8|b[c]&255,++c>=b.length&&(c=0);this.parray[a]=this.PARRAY[a]^d}this.sboxes=[];for(a=0;4>a;++a){this.sboxes[a]=[];for(c=0;256>c;++c)this.sboxes[a][c]=this.SBOXES[a][c]}b=[0,0];for(a=0;a<this.NN+2;a+=2)this._encrypt_block(b),this.parray[a+0]=b[0],this.parray[a+1]=b[1];for(a=0;4>a;++a)for(c=0;256>c;c+=2)this._encrypt_block(b),this.sboxes[a][c+0]=b[0],this.sboxes[a][c+1]=b[1]};
|
|
|
|
|
function BFencrypt(b,a){var c=new Blowfish;c.init(util.str2bin(a));return c.encrypt_block(b)}function cast5_encrypt(b,a){var c=new openpgp_symenc_cast5;c.setKey(util.str2bin(a));return c.encrypt(b)}
|
|
|
|
|
function openpgp_symenc_cast5(){function b(a,b,c){a=b+a;c=a<<c|a>>>32-c;return(f[0][c>>>24]^f[1][c>>>16&255])-f[2][c>>>8&255]+f[3][c&255]}function a(a,b,c){a^=b;c=a<<c|a>>>32-c;return f[0][c>>>24]-f[1][c>>>16&255]+f[2][c>>>8&255]^f[3][c&255]}function c(a,b,c){a=b-a;c=a<<c|a>>>32-c;return(f[0][c>>>24]+f[1][c>>>16&255]^f[2][c>>>8&255])-f[3][c&255]}this.BlockSize=8;this.KeySize=16;this.setKey=function(a){this.masking=Array(16);this.rotate=Array(16);this.reset();if(a.length==this.KeySize)this.keySchedule(a);
|
|
|
|
|
else return util.print_error("cast5.js: CAST-128: keys must be 16 bytes"),!1;return!0};this.reset=function(){for(var a=0;16>a;a++)this.masking[a]=0,this.rotate[a]=0};this.getBlockSize=function(){return BlockSize};this.encrypt=function(d){var e=Array(d.length);for(i=0;i<d.length;i+=8){var f=d[i]<<24|d[i+1]<<16|d[i+2]<<8|d[i+3],j=d[i+4]<<24|d[i+5]<<16|d[i+6]<<8|d[i+7],l;l=j;j=f^b(j,this.masking[0],this.rotate[0]);f=l;l=j;j=f^a(j,this.masking[1],this.rotate[1]);f=l;l=j;j=f^c(j,this.masking[2],this.rotate[2]);
|
|
|
|
|
f=l;l=j;j=f^b(j,this.masking[3],this.rotate[3]);f=l;l=j;j=f^a(j,this.masking[4],this.rotate[4]);f=l;l=j;j=f^c(j,this.masking[5],this.rotate[5]);f=l;l=j;j=f^b(j,this.masking[6],this.rotate[6]);f=l;l=j;j=f^a(j,this.masking[7],this.rotate[7]);f=l;l=j;j=f^c(j,this.masking[8],this.rotate[8]);f=l;l=j;j=f^b(j,this.masking[9],this.rotate[9]);f=l;l=j;j=f^a(j,this.masking[10],this.rotate[10]);f=l;l=j;j=f^c(j,this.masking[11],this.rotate[11]);f=l;l=j;j=f^b(j,this.masking[12],this.rotate[12]);f=l;l=j;j=f^a(j,
|
|
|
|
|
this.masking[13],this.rotate[13]);f=l;l=j;j=f^c(j,this.masking[14],this.rotate[14]);f=l;l=j;j=f^b(j,this.masking[15],this.rotate[15]);f=l;e[i]=j>>>24&255;e[i+1]=j>>>16&255;e[i+2]=j>>>8&255;e[i+3]=j&255;e[i+4]=f>>>24&255;e[i+5]=f>>>16&255;e[i+6]=f>>>8&255;e[i+7]=f&255}return e};this.decrypt=function(d){var e=Array(d.length);for(i=0;i<d.length;i+=8){var f=d[i]<<24|d[i+1]<<16|d[i+2]<<8|d[i+3],j=d[i+4]<<24|d[i+5]<<16|d[i+6]<<8|d[i+7],l;l=j;j=f^b(j,this.masking[15],this.rotate[15]);f=l;l=j;j=f^c(j,this.masking[14],
|
|
|
|
|
this.rotate[14]);f=l;l=j;j=f^a(j,this.masking[13],this.rotate[13]);f=l;l=j;j=f^b(j,this.masking[12],this.rotate[12]);f=l;l=j;j=f^c(j,this.masking[11],this.rotate[11]);f=l;l=j;j=f^a(j,this.masking[10],this.rotate[10]);f=l;l=j;j=f^b(j,this.masking[9],this.rotate[9]);f=l;l=j;j=f^c(j,this.masking[8],this.rotate[8]);f=l;l=j;j=f^a(j,this.masking[7],this.rotate[7]);f=l;l=j;j=f^b(j,this.masking[6],this.rotate[6]);f=l;l=j;j=f^c(j,this.masking[5],this.rotate[5]);f=l;l=j;j=f^a(j,this.masking[4],this.rotate[4]);
|
|
|
|
|
f=l;l=j;j=f^b(j,this.masking[3],this.rotate[3]);f=l;l=j;j=f^c(j,this.masking[2],this.rotate[2]);f=l;l=j;j=f^a(j,this.masking[1],this.rotate[1]);f=l;l=j;j=f^b(j,this.masking[0],this.rotate[0]);f=l;e[i]=j>>>24&255;e[i+1]=j>>>16&255;e[i+2]=j>>>8&255;e[i+3]=j&255;e[i+4]=f>>>24&255;e[i+5]=f>>16&255;e[i+6]=f>>8&255;e[i+7]=f&255}return e};var d=Array(4);d[0]=Array(4);d[0][0]=[4,0,13,15,12,14,8];d[0][1]=[5,2,16,18,17,19,10];d[0][2]=[6,3,23,22,21,20,9];d[0][3]=[7,1,26,25,27,24,11];d[1]=Array(4);d[1][0]=[0,
|
|
|
|
|
else return util.print_error("cast5.js: CAST-128: keys must be 16 bytes"),!1;return!0};this.reset=function(){for(var a=0;16>a;a++)this.masking[a]=0,this.rotate[a]=0};this.getBlockSize=function(){return BlockSize};this.encrypt=function(d){for(var e=Array(d.length),f=0;f<d.length;f+=8){var k=d[f]<<24|d[f+1]<<16|d[f+2]<<8|d[f+3],l=d[f+4]<<24|d[f+5]<<16|d[f+6]<<8|d[f+7],m;m=l;l=k^b(l,this.masking[0],this.rotate[0]);k=m;m=l;l=k^a(l,this.masking[1],this.rotate[1]);k=m;m=l;l=k^c(l,this.masking[2],this.rotate[2]);
|
|
|
|
|
k=m;m=l;l=k^b(l,this.masking[3],this.rotate[3]);k=m;m=l;l=k^a(l,this.masking[4],this.rotate[4]);k=m;m=l;l=k^c(l,this.masking[5],this.rotate[5]);k=m;m=l;l=k^b(l,this.masking[6],this.rotate[6]);k=m;m=l;l=k^a(l,this.masking[7],this.rotate[7]);k=m;m=l;l=k^c(l,this.masking[8],this.rotate[8]);k=m;m=l;l=k^b(l,this.masking[9],this.rotate[9]);k=m;m=l;l=k^a(l,this.masking[10],this.rotate[10]);k=m;m=l;l=k^c(l,this.masking[11],this.rotate[11]);k=m;m=l;l=k^b(l,this.masking[12],this.rotate[12]);k=m;m=l;l=k^a(l,
|
|
|
|
|
this.masking[13],this.rotate[13]);k=m;m=l;l=k^c(l,this.masking[14],this.rotate[14]);k=m;m=l;l=k^b(l,this.masking[15],this.rotate[15]);k=m;e[f]=l>>>24&255;e[f+1]=l>>>16&255;e[f+2]=l>>>8&255;e[f+3]=l&255;e[f+4]=k>>>24&255;e[f+5]=k>>>16&255;e[f+6]=k>>>8&255;e[f+7]=k&255}return e};this.decrypt=function(d){for(var e=Array(d.length),f=0;f<d.length;f+=8){var k=d[f]<<24|d[f+1]<<16|d[f+2]<<8|d[f+3],l=d[f+4]<<24|d[f+5]<<16|d[f+6]<<8|d[f+7],m;m=l;l=k^b(l,this.masking[15],this.rotate[15]);k=m;m=l;l=k^c(l,this.masking[14],
|
|
|
|
|
this.rotate[14]);k=m;m=l;l=k^a(l,this.masking[13],this.rotate[13]);k=m;m=l;l=k^b(l,this.masking[12],this.rotate[12]);k=m;m=l;l=k^c(l,this.masking[11],this.rotate[11]);k=m;m=l;l=k^a(l,this.masking[10],this.rotate[10]);k=m;m=l;l=k^b(l,this.masking[9],this.rotate[9]);k=m;m=l;l=k^c(l,this.masking[8],this.rotate[8]);k=m;m=l;l=k^a(l,this.masking[7],this.rotate[7]);k=m;m=l;l=k^b(l,this.masking[6],this.rotate[6]);k=m;m=l;l=k^c(l,this.masking[5],this.rotate[5]);k=m;m=l;l=k^a(l,this.masking[4],this.rotate[4]);
|
|
|
|
|
k=m;m=l;l=k^b(l,this.masking[3],this.rotate[3]);k=m;m=l;l=k^c(l,this.masking[2],this.rotate[2]);k=m;m=l;l=k^a(l,this.masking[1],this.rotate[1]);k=m;m=l;l=k^b(l,this.masking[0],this.rotate[0]);k=m;e[f]=l>>>24&255;e[f+1]=l>>>16&255;e[f+2]=l>>>8&255;e[f+3]=l&255;e[f+4]=k>>>24&255;e[f+5]=k>>16&255;e[f+6]=k>>8&255;e[f+7]=k&255}return e};var d=Array(4);d[0]=Array(4);d[0][0]=[4,0,13,15,12,14,8];d[0][1]=[5,2,16,18,17,19,10];d[0][2]=[6,3,23,22,21,20,9];d[0][3]=[7,1,26,25,27,24,11];d[1]=Array(4);d[1][0]=[0,
|
|
|
|
|
6,21,23,20,22,16];d[1][1]=[1,4,0,2,1,3,18];d[1][2]=[2,5,7,6,5,4,17];d[1][3]=[3,7,10,9,11,8,19];d[2]=Array(4);d[2][0]=[4,0,13,15,12,14,8];d[2][1]=[5,2,16,18,17,19,10];d[2][2]=[6,3,23,22,21,20,9];d[2][3]=[7,1,26,25,27,24,11];d[3]=Array(4);d[3][0]=[0,6,21,23,20,22,16];d[3][1]=[1,4,0,2,1,3,18];d[3][2]=[2,5,7,6,5,4,17];d[3][3]=[3,7,10,9,11,8,19];var e=Array(4);e[0]=Array(4);e[0][0]=[24,25,23,22,18];e[0][1]=[26,27,21,20,22];e[0][2]=[28,29,19,18,25];e[0][3]=[30,31,17,16,28];e[1]=Array(4);e[1][0]=[3,2,12,
|
|
|
|
|
13,8];e[1][1]=[1,0,14,15,13];e[1][2]=[7,6,8,9,3];e[1][3]=[5,4,10,11,7];e[2]=Array(4);e[2][0]=[19,18,28,29,25];e[2][1]=[17,16,30,31,28];e[2][2]=[23,22,24,25,18];e[2][3]=[21,20,26,27,22];e[3]=Array(4);e[3][0]=[8,9,7,6,3];e[3][1]=[10,11,5,4,7];e[3][2]=[12,13,3,2,8];e[3][3]=[14,15,1,0,13];this.keySchedule=function(a){for(var b=Array(8),c=Array(32),j=0;4>j;j++){var l=4*j;b[j]=a[l]<<24|a[l+1]<<16|a[l+2]<<8|a[l+3]}for(var a=[6,7,4,5],o=j=0;2>o;o++)for(var r=0;4>r;r++){for(l=0;4>l;l++){var p=d[r][l],m=b[p[1]],
|
|
|
|
|
m=m^f[4][b[p[2]>>>2]>>>24-8*(p[2]&3)&255],m=m^f[5][b[p[3]>>>2]>>>24-8*(p[3]&3)&255],m=m^f[6][b[p[4]>>>2]>>>24-8*(p[4]&3)&255],m=m^f[7][b[p[5]>>>2]>>>24-8*(p[5]&3)&255],m=m^f[a[l]][b[p[6]>>>2]>>>24-8*(p[6]&3)&255];b[p[0]]=m}for(l=0;4>l;l++)p=e[r][l],m=f[4][b[p[0]>>>2]>>>24-8*(p[0]&3)&255],m^=f[5][b[p[1]>>>2]>>>24-8*(p[1]&3)&255],m^=f[6][b[p[2]>>>2]>>>24-8*(p[2]&3)&255],m^=f[7][b[p[3]>>>2]>>>24-8*(p[3]&3)&255],m^=f[4+l][b[p[4]>>>2]>>>24-8*(p[4]&3)&255],c[j]=m,j++}for(j=0;16>j;j++)this.masking[j]=c[j],
|
|
|
|
|
this.rotate[j]=c[16+j]&31};var f=Array(8);f[0]=[821772500,2678128395,1810681135,1059425402,505495343,2617265619,1610868032,3483355465,3218386727,2294005173,3791863952,2563806837,1852023008,365126098,3269944861,584384398,677919599,3229601881,4280515016,2002735330,1136869587,3744433750,2289869850,2731719981,2714362070,879511577,1639411079,575934255,717107937,2857637483,576097850,2731753936,1725645E3,2810460463,5111599,767152862,2543075244,1251459544,1383482551,3052681127,3089939183,3612463449,1878520045,
|
|
|
|
|
13,8];e[1][1]=[1,0,14,15,13];e[1][2]=[7,6,8,9,3];e[1][3]=[5,4,10,11,7];e[2]=Array(4);e[2][0]=[19,18,28,29,25];e[2][1]=[17,16,30,31,28];e[2][2]=[23,22,24,25,18];e[2][3]=[21,20,26,27,22];e[3]=Array(4);e[3][0]=[8,9,7,6,3];e[3][1]=[10,11,5,4,7];e[3][2]=[12,13,3,2,8];e[3][3]=[14,15,1,0,13];this.keySchedule=function(a){for(var b=Array(8),c=Array(32),k=0;4>k;k++){var l=4*k;b[k]=a[l]<<24|a[l+1]<<16|a[l+2]<<8|a[l+3]}for(var a=[6,7,4,5],m=k=0;2>m;m++)for(var r=0;4>r;r++){for(l=0;4>l;l++){var p=d[r][l],o=b[p[1]],
|
|
|
|
|
o=o^f[4][b[p[2]>>>2]>>>24-8*(p[2]&3)&255],o=o^f[5][b[p[3]>>>2]>>>24-8*(p[3]&3)&255],o=o^f[6][b[p[4]>>>2]>>>24-8*(p[4]&3)&255],o=o^f[7][b[p[5]>>>2]>>>24-8*(p[5]&3)&255],o=o^f[a[l]][b[p[6]>>>2]>>>24-8*(p[6]&3)&255];b[p[0]]=o}for(l=0;4>l;l++)p=e[r][l],o=f[4][b[p[0]>>>2]>>>24-8*(p[0]&3)&255],o^=f[5][b[p[1]>>>2]>>>24-8*(p[1]&3)&255],o^=f[6][b[p[2]>>>2]>>>24-8*(p[2]&3)&255],o^=f[7][b[p[3]>>>2]>>>24-8*(p[3]&3)&255],o^=f[4+l][b[p[4]>>>2]>>>24-8*(p[4]&3)&255],c[k]=o,k++}for(k=0;16>k;k++)this.masking[k]=c[k],
|
|
|
|
|
this.rotate[k]=c[16+k]&31};var f=Array(8);f[0]=[821772500,2678128395,1810681135,1059425402,505495343,2617265619,1610868032,3483355465,3218386727,2294005173,3791863952,2563806837,1852023008,365126098,3269944861,584384398,677919599,3229601881,4280515016,2002735330,1136869587,3744433750,2289869850,2731719981,2714362070,879511577,1639411079,575934255,717107937,2857637483,576097850,2731753936,1725645E3,2810460463,5111599,767152862,2543075244,1251459544,1383482551,3052681127,3089939183,3612463449,1878520045,
|
|
|
|
|
1510570527,2189125840,2431448366,582008916,3163445557,1265446783,1354458274,3529918736,3202711853,3073581712,3912963487,3029263377,1275016285,4249207360,2905708351,3304509486,1442611557,3585198765,2712415662,2731849581,3248163920,2283946226,208555832,2766454743,1331405426,1447828783,3315356441,3108627284,2957404670,2981538698,3339933917,1669711173,286233437,1465092821,1782121619,3862771680,710211251,980974943,1651941557,430374111,2051154026,704238805,4128970897,3144820574,2857402727,948965521,3333752299,
|
|
|
|
|
2227686284,718756367,2269778983,2731643755,718440111,2857816721,3616097120,1113355533,2478022182,410092745,1811985197,1944238868,2696854588,1415722873,1682284203,1060277122,1998114690,1503841958,82706478,2315155686,1068173648,845149890,2167947013,1768146376,1993038550,3566826697,3390574031,940016341,3355073782,2328040721,904371731,1205506512,4094660742,2816623006,825647681,85914773,2857843460,1249926541,1417871568,3287612,3211054559,3126306446,1975924523,1353700161,2814456437,2438597621,1800716203,
|
|
|
|
|
722146342,2873936343,1151126914,4160483941,2877670899,458611604,2866078500,3483680063,770352098,2652916994,3367839148,3940505011,3585973912,3809620402,718646636,2504206814,2914927912,3631288169,2857486607,2860018678,575749918,2857478043,718488780,2069512688,3548183469,453416197,1106044049,3032691430,52586708,3378514636,3459808877,3211506028,1785789304,218356169,3571399134,3759170522,1194783844,1523787992,3007827094,1975193539,2555452411,1341901877,3045838698,3776907964,3217423946,2802510864,2889438986,
|
|
|
|
@ -238,54 +238,54 @@ f[2]=[2381300288,637164959,3952098751,3893414151,1197506559,916448331,2350892612
|
|
|
|
|
function desede(b,a){var c=a.substring(0,8),d=a.substring(8,16),e=a.substring(16,24);return util.str2bin(des(des_createKeys(e),des(des_createKeys(d),des(des_createKeys(c),util.bin2str(b),!0,0,null,null),!1,0,null,null),!0,0,null,null))}
|
|
|
|
|
function des(b,a,c,d,e,f){var g=[16843776,0,65536,16843780,16842756,66564,4,65536,1024,16843776,16843780,1024,16778244,16842756,16777216,4,1028,16778240,16778240,66560,66560,16842752,16842752,16778244,65540,16777220,16777220,65540,0,1028,66564,16777216,65536,16843780,4,16842752,16843776,16777216,16777216,1024,16842756,65536,66560,16777220,1024,4,16778244,66564,16843780,65540,16842752,16778244,16777220,1028,66564,16843776,1028,16778240,16778240,0,65540,66560,0,16842756],h=[-2146402272,-2147450880,
|
|
|
|
|
32768,1081376,1048576,32,-2146435040,-2147450848,-2147483616,-2146402272,-2146402304,-2147483648,-2147450880,1048576,32,-2146435040,1081344,1048608,-2147450848,0,-2147483648,32768,1081376,-2146435072,1048608,-2147483616,0,1081344,32800,-2146402304,-2146435072,32800,0,1081376,-2146435040,1048576,-2147450848,-2146435072,-2146402304,32768,-2146435072,-2147450880,32,-2146402272,1081376,32,32768,-2147483648,32800,-2146402304,1048576,-2147483616,1048608,-2147450848,-2147483616,1048608,1081344,0,-2147450880,
|
|
|
|
|
32800,-2147483648,-2146435040,-2146402272,1081344],k=[520,134349312,0,134348808,134218240,0,131592,134218240,131080,134217736,134217736,131072,134349320,131080,134348800,520,134217728,8,134349312,512,131584,134348800,134348808,131592,134218248,131584,131072,134218248,8,134349320,512,134217728,134349312,134217728,131080,520,131072,134349312,134218240,0,512,131080,134349320,134218240,134217736,512,0,134348808,134218248,131072,134217728,134349320,8,131592,131584,134217736,134348800,134218248,520,134348800,
|
|
|
|
|
131592,8,134348808,131584],j=[8396801,8321,8321,128,8396928,8388737,8388609,8193,0,8396800,8396800,8396929,129,0,8388736,8388609,1,8192,8388608,8396801,128,8388608,8193,8320,8388737,1,8320,8388736,8192,8396928,8396929,129,8388736,8388609,8396800,8396929,129,0,0,8396800,8320,8388736,8388737,1,8396801,8321,8321,128,8396929,129,1,8192,8388609,8193,8396928,8388737,8193,8320,8388608,8396801,128,8388608,8192,8396928],l=[256,34078976,34078720,1107296512,524288,256,1073741824,34078720,1074266368,524288,33554688,
|
|
|
|
|
1074266368,1107296512,1107820544,524544,1073741824,33554432,1074266112,1074266112,0,1073742080,1107820800,1107820800,33554688,1107820544,1073742080,0,1107296256,34078976,33554432,1107296256,524544,524288,1107296512,256,33554432,1073741824,34078720,1107296512,1074266368,33554688,1073741824,1107820544,34078976,1074266368,256,33554432,1107820544,1107820800,524544,1107296256,1107820800,34078720,0,1074266112,1107296256,524544,33554688,1073742080,524288,0,1074266112,34078976,1073742080],o=[536870928,541065216,
|
|
|
|
|
32800,-2147483648,-2146435040,-2146402272,1081344],j=[520,134349312,0,134348808,134218240,0,131592,134218240,131080,134217736,134217736,131072,134349320,131080,134348800,520,134217728,8,134349312,512,131584,134348800,134348808,131592,134218248,131584,131072,134218248,8,134349320,512,134217728,134349312,134217728,131080,520,131072,134349312,134218240,0,512,131080,134349320,134218240,134217736,512,0,134348808,134218248,131072,134217728,134349320,8,131592,131584,134217736,134348800,134218248,520,134348800,
|
|
|
|
|
131592,8,134348808,131584],k=[8396801,8321,8321,128,8396928,8388737,8388609,8193,0,8396800,8396800,8396929,129,0,8388736,8388609,1,8192,8388608,8396801,128,8388608,8193,8320,8388737,1,8320,8388736,8192,8396928,8396929,129,8388736,8388609,8396800,8396929,129,0,0,8396800,8320,8388736,8388737,1,8396801,8321,8321,128,8396929,129,1,8192,8388609,8193,8396928,8388737,8193,8320,8388608,8396801,128,8388608,8192,8396928],l=[256,34078976,34078720,1107296512,524288,256,1073741824,34078720,1074266368,524288,33554688,
|
|
|
|
|
1074266368,1107296512,1107820544,524544,1073741824,33554432,1074266112,1074266112,0,1073742080,1107820800,1107820800,33554688,1107820544,1073742080,0,1107296256,34078976,33554432,1107296256,524544,524288,1107296512,256,33554432,1073741824,34078720,1107296512,1074266368,33554688,1073741824,1107820544,34078976,1074266368,256,33554432,1107820544,1107820800,524544,1107296256,1107820800,34078720,0,1074266112,1107296256,524544,33554688,1073742080,524288,0,1074266112,34078976,1073742080],m=[536870928,541065216,
|
|
|
|
|
16384,541081616,541065216,16,541081616,4194304,536887296,4210704,4194304,536870928,4194320,536887296,536870912,16400,0,4194320,536887312,16384,4210688,536887312,16,541065232,541065232,0,4210704,541081600,16400,4210688,541081600,536870912,536887296,16,541065232,4210688,541081616,4194304,16400,536870928,4194304,536887296,536870912,16400,536870928,541081616,4210688,541065216,4210704,541081600,0,541065232,16,16384,541065216,4210704,16384,4194320,536887312,0,541081600,536870912,4194320,536887312],r=[2097152,
|
|
|
|
|
69206018,67110914,0,2048,67110914,2099202,69208064,69208066,2097152,0,67108866,2,67108864,69206018,2050,67110912,2099202,2097154,67110912,67108866,69206016,69208064,2097154,69206016,2048,2050,69208066,2099200,2,67108864,2099200,67108864,2099200,2097152,67110914,67110914,69206018,69206018,2,2097154,67108864,67110912,2097152,69208064,2050,2099202,69208064,2050,67108866,69208066,69206016,2099200,0,2,69208066,0,2099202,69206016,2048,67108866,67110912,2048,2097154],p=[268439616,4096,262144,268701760,268435456,
|
|
|
|
|
268439616,64,268435456,262208,268697600,268701760,266240,268701696,266304,4096,64,268697600,268435520,268439552,4160,266240,262208,268697664,268701696,4160,0,0,268697664,268435520,268439552,266304,262144,266304,262144,268701696,4096,64,268697664,4096,266304,268439552,64,268435520,268697600,268697664,268435456,262144,268439616,0,268701760,262208,268435520,268697600,268439552,268439616,0,268701760,266240,266240,4160,4160,262208,268435456,268701696],m=0,y,x,v,u,t,E,Q,D,M,K,w,z,T=a.length,A=0,B=32==b.length?
|
|
|
|
|
3:9;E=3==B?c?[0,32,2]:[30,-2,-2]:c?[0,32,2,62,30,-2,64,96,2]:[94,62,-2,32,64,2,30,-2,-2];2==f?a+=" ":1==f?(f=8-T%8,a+=String.fromCharCode(f,f,f,f,f,f,f,f),8==f&&(T+=8)):f||(a+="\x00\x00\x00\x00\x00\x00\x00\x00");tempresult=result="";1==d&&(Q=e.charCodeAt(m++)<<24|e.charCodeAt(m++)<<16|e.charCodeAt(m++)<<8|e.charCodeAt(m++),M=e.charCodeAt(m++)<<24|e.charCodeAt(m++)<<16|e.charCodeAt(m++)<<8|e.charCodeAt(m++),m=0);for(;m<T;){u=a.charCodeAt(m++)<<24|a.charCodeAt(m++)<<16|a.charCodeAt(m++)<<8|a.charCodeAt(m++);
|
|
|
|
|
t=a.charCodeAt(m++)<<24|a.charCodeAt(m++)<<16|a.charCodeAt(m++)<<8|a.charCodeAt(m++);1==d&&(c?(u^=Q,t^=M):(D=Q,K=M,Q=u,M=t));f=(u>>>4^t)&252645135;t^=f;u^=f<<4;f=(u>>>16^t)&65535;t^=f;u^=f<<16;f=(t>>>2^u)&858993459;u^=f;t^=f<<2;f=(t>>>8^u)&16711935;u^=f;t^=f<<8;f=(u>>>1^t)&1431655765;t^=f;u^=f<<1;u=u<<1|u>>>31;t=t<<1|t>>>31;for(y=0;y<B;y+=3){w=E[y+1];z=E[y+2];for(e=E[y];e!=w;e+=z)x=t^b[e],v=(t>>>4|t<<28)^b[e+1],f=u,u=t,t=f^(h[x>>>24&63]|j[x>>>16&63]|o[x>>>8&63]|p[x&63]|g[v>>>24&63]|k[v>>>16&63]|l[v>>>
|
|
|
|
|
268439616,64,268435456,262208,268697600,268701760,266240,268701696,266304,4096,64,268697600,268435520,268439552,4160,266240,262208,268697664,268701696,4160,0,0,268697664,268435520,268439552,266304,262144,266304,262144,268701696,4096,64,268697664,4096,266304,268439552,64,268435520,268697600,268697664,268435456,262144,268439616,0,268701760,262208,268435520,268697600,268439552,268439616,0,268701760,266240,266240,4160,4160,262208,268435456,268701696],o=0,y,x,v,u,t,E,Q,D,M,K,w,z,T=a.length,A=0,B=32==b.length?
|
|
|
|
|
3:9;E=3==B?c?[0,32,2]:[30,-2,-2]:c?[0,32,2,62,30,-2,64,96,2]:[94,62,-2,32,64,2,30,-2,-2];2==f?a+=" ":1==f?(f=8-T%8,a+=String.fromCharCode(f,f,f,f,f,f,f,f),8==f&&(T+=8)):f||(a+="\x00\x00\x00\x00\x00\x00\x00\x00");tempresult=result="";1==d&&(Q=e.charCodeAt(o++)<<24|e.charCodeAt(o++)<<16|e.charCodeAt(o++)<<8|e.charCodeAt(o++),M=e.charCodeAt(o++)<<24|e.charCodeAt(o++)<<16|e.charCodeAt(o++)<<8|e.charCodeAt(o++),o=0);for(;o<T;){u=a.charCodeAt(o++)<<24|a.charCodeAt(o++)<<16|a.charCodeAt(o++)<<8|a.charCodeAt(o++);
|
|
|
|
|
t=a.charCodeAt(o++)<<24|a.charCodeAt(o++)<<16|a.charCodeAt(o++)<<8|a.charCodeAt(o++);1==d&&(c?(u^=Q,t^=M):(D=Q,K=M,Q=u,M=t));f=(u>>>4^t)&252645135;t^=f;u^=f<<4;f=(u>>>16^t)&65535;t^=f;u^=f<<16;f=(t>>>2^u)&858993459;u^=f;t^=f<<2;f=(t>>>8^u)&16711935;u^=f;t^=f<<8;f=(u>>>1^t)&1431655765;t^=f;u^=f<<1;u=u<<1|u>>>31;t=t<<1|t>>>31;for(y=0;y<B;y+=3){w=E[y+1];z=E[y+2];for(e=E[y];e!=w;e+=z)x=t^b[e],v=(t>>>4|t<<28)^b[e+1],f=u,u=t,t=f^(h[x>>>24&63]|k[x>>>16&63]|m[x>>>8&63]|p[x&63]|g[v>>>24&63]|j[v>>>16&63]|l[v>>>
|
|
|
|
|
8&63]|r[v&63]);f=u;u=t;t=f}u=u>>>1|u<<31;t=t>>>1|t<<31;f=(u>>>1^t)&1431655765;t^=f;u^=f<<1;f=(t>>>8^u)&16711935;u^=f;t^=f<<8;f=(t>>>2^u)&858993459;u^=f;t^=f<<2;f=(u>>>16^t)&65535;t^=f;u^=f<<16;f=(u>>>4^t)&252645135;t^=f;u^=f<<4;1==d&&(c?(Q=u,M=t):(u^=D,t^=K));tempresult+=String.fromCharCode(u>>>24,u>>>16&255,u>>>8&255,u&255,t>>>24,t>>>16&255,t>>>8&255,t&255);A+=8;512==A&&(result+=tempresult,tempresult="",A=0)}result+=tempresult;return result=result.replace(/\0*$/g,"")}
|
|
|
|
|
function des_createKeys(b){pc2bytes0=[0,4,536870912,536870916,65536,65540,536936448,536936452,512,516,536871424,536871428,66048,66052,536936960,536936964];pc2bytes1=[0,1,1048576,1048577,67108864,67108865,68157440,68157441,256,257,1048832,1048833,67109120,67109121,68157696,68157697];pc2bytes2=[0,8,2048,2056,16777216,16777224,16779264,16779272,0,8,2048,2056,16777216,16777224,16779264,16779272];pc2bytes3=[0,2097152,134217728,136314880,8192,2105344,134225920,136323072,131072,2228224,134348800,136445952,
|
|
|
|
|
139264,2236416,134356992,136454144];pc2bytes4=[0,262144,16,262160,0,262144,16,262160,4096,266240,4112,266256,4096,266240,4112,266256];pc2bytes5=[0,1024,32,1056,0,1024,32,1056,33554432,33555456,33554464,33555488,33554432,33555456,33554464,33555488];pc2bytes6=[0,268435456,524288,268959744,2,268435458,524290,268959746,0,268435456,524288,268959744,2,268435458,524290,268959746];pc2bytes7=[0,65536,2048,67584,536870912,536936448,536872960,536938496,131072,196608,133120,198656,537001984,537067520,537004032,
|
|
|
|
|
537069568];pc2bytes8=[0,262144,0,262144,2,262146,2,262146,33554432,33816576,33554432,33816576,33554434,33816578,33554434,33816578];pc2bytes9=[0,268435456,8,268435464,0,268435456,8,268435464,1024,268436480,1032,268436488,1024,268436480,1032,268436488];pc2bytes10=[0,32,0,32,1048576,1048608,1048576,1048608,8192,8224,8192,8224,1056768,1056800,1056768,1056800];pc2bytes11=[0,16777216,512,16777728,2097152,18874368,2097664,18874880,67108864,83886080,67109376,83886592,69206016,85983232,69206528,85983744];
|
|
|
|
|
pc2bytes12=[0,4096,134217728,134221824,524288,528384,134742016,134746112,16,4112,134217744,134221840,524304,528400,134742032,134746128];pc2bytes13=[0,4,256,260,0,4,256,260,1,5,257,261,1,5,257,261];for(var a=8<b.length?3:1,c=Array(32*a),d=[0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0],e,f,g=0,h=0,k,j=0;j<a;j++){left=b.charCodeAt(g++)<<24|b.charCodeAt(g++)<<16|b.charCodeAt(g++)<<8|b.charCodeAt(g++);right=b.charCodeAt(g++)<<24|b.charCodeAt(g++)<<16|b.charCodeAt(g++)<<8|b.charCodeAt(g++);k=(left>>>4^right)&252645135;
|
|
|
|
|
right^=k;left^=k<<4;k=(right>>>-16^left)&65535;left^=k;right^=k<<-16;k=(left>>>2^right)&858993459;right^=k;left^=k<<2;k=(right>>>-16^left)&65535;left^=k;right^=k<<-16;k=(left>>>1^right)&1431655765;right^=k;left^=k<<1;k=(right>>>8^left)&16711935;left^=k;right^=k<<8;k=(left>>>1^right)&1431655765;right^=k;left^=k<<1;k=left<<8|right>>>20&240;left=right<<24|right<<8&16711680|right>>>8&65280|right>>>24&240;right=k;for(i=0;i<d.length;i++)d[i]?(left=left<<2|left>>>26,right=right<<2|right>>>26):(left=left<<
|
|
|
|
|
1|left>>>27,right=right<<1|right>>>27),left&=-15,right&=-15,e=pc2bytes0[left>>>28]|pc2bytes1[left>>>24&15]|pc2bytes2[left>>>20&15]|pc2bytes3[left>>>16&15]|pc2bytes4[left>>>12&15]|pc2bytes5[left>>>8&15]|pc2bytes6[left>>>4&15],f=pc2bytes7[right>>>28]|pc2bytes8[right>>>24&15]|pc2bytes9[right>>>20&15]|pc2bytes10[right>>>16&15]|pc2bytes11[right>>>12&15]|pc2bytes12[right>>>8&15]|pc2bytes13[right>>>4&15],k=(f>>>16^e)&65535,c[h++]=e^k,c[h++]=f^k<<16}return c}
|
|
|
|
|
pc2bytes12=[0,4096,134217728,134221824,524288,528384,134742016,134746112,16,4112,134217744,134221840,524304,528400,134742032,134746128];pc2bytes13=[0,4,256,260,0,4,256,260,1,5,257,261,1,5,257,261];for(var a=8<b.length?3:1,c=Array(32*a),d=[0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0],e,f,g=0,h=0,j,k=0;k<a;k++){left=b.charCodeAt(g++)<<24|b.charCodeAt(g++)<<16|b.charCodeAt(g++)<<8|b.charCodeAt(g++);right=b.charCodeAt(g++)<<24|b.charCodeAt(g++)<<16|b.charCodeAt(g++)<<8|b.charCodeAt(g++);j=(left>>>4^right)&252645135;
|
|
|
|
|
right^=j;left^=j<<4;j=(right>>>-16^left)&65535;left^=j;right^=j<<-16;j=(left>>>2^right)&858993459;right^=j;left^=j<<2;j=(right>>>-16^left)&65535;left^=j;right^=j<<-16;j=(left>>>1^right)&1431655765;right^=j;left^=j<<1;j=(right>>>8^left)&16711935;left^=j;right^=j<<8;j=(left>>>1^right)&1431655765;right^=j;left^=j<<1;j=left<<8|right>>>20&240;left=right<<24|right<<8&16711680|right>>>8&65280|right>>>24&240;right=j;for(i=0;i<d.length;i++)d[i]?(left=left<<2|left>>>26,right=right<<2|right>>>26):(left=left<<
|
|
|
|
|
1|left>>>27,right=right<<1|right>>>27),left&=-15,right&=-15,e=pc2bytes0[left>>>28]|pc2bytes1[left>>>24&15]|pc2bytes2[left>>>20&15]|pc2bytes3[left>>>16&15]|pc2bytes4[left>>>12&15]|pc2bytes5[left>>>8&15]|pc2bytes6[left>>>4&15],f=pc2bytes7[right>>>28]|pc2bytes8[right>>>24&15]|pc2bytes9[right>>>20&15]|pc2bytes10[right>>>16&15]|pc2bytes11[right>>>12&15]|pc2bytes12[right>>>8&15]|pc2bytes13[right>>>4&15],j=(f>>>16^e)&65535,c[h++]=e^j,c[h++]=f^j<<16}return c}
|
|
|
|
|
function TFencrypt(b,a){var c=[].concat(b),d=createTwofish();d.open(util.str2bin(a),0);c=d.encrypt(c,0);d.close();return c}var MAXINT=4294967295;function rotb(b,a){return(b<<a|b>>>8-a)&255}function rotw(b,a){return(b<<a|b>>>32-a)&MAXINT}function getW(b,a){return b[a]|b[a+1]<<8|b[a+2]<<16|b[a+3]<<24}function setW(b,a,c){b.splice(a,4,c&255,c>>>8&255,c>>>16&255,c>>>24&255)}function setWInv(b,a,c){b.splice(a,4,c>>>24&255,c>>>16&255,c>>>8&255,c&255)}function getB(b,a){return b>>>8*a&255}
|
|
|
|
|
function getNrBits(b){for(var a=0;0<b;)a++,b>>>=1;return a}function getMask(b){return(1<<b)-1}function randByte(){return Math.floor(256*Math.random())}
|
|
|
|
|
function createTwofish(){function b(a){return g[0][getB(a,0)]^g[1][getB(a,1)]^g[2][getB(a,2)]^g[3][getB(a,3)]}function a(a){return g[0][getB(a,3)]^g[1][getB(a,0)]^g[2][getB(a,1)]^g[3][getB(a,2)]}var c=null,d=null,e=-1,f=[],g=[[],[],[],[]];return{name:"twofish",blocksize:16,open:function(a){function b(a,c){var d,e,f;for(d=0;8>d;d++)e=c>>>24,c=c<<8&MAXINT|a>>>24,a=a<<8&MAXINT,f=e<<1,e&128&&(f^=333),c^=e^f<<16,f^=e>>>1,e&1&&(f^=166),c^=f<<24|f<<8;return c}function d(a,b){var c,e,f;c=b>>4;e=b&15;f=t[a][c^
|
|
|
|
|
e];c=E[a][M[e]^K[c]];return D[a][M[c]^K[f]]<<4|Q[a][f^c]}function e(a,b){var c=getB(a,0),d=getB(a,1),f=getB(a,2),g=getB(a,3);switch(x){case 4:c=w[1][c]^getB(b[3],0),d=w[0][d]^getB(b[3],1),f=w[0][f]^getB(b[3],2),g=w[1][g]^getB(b[3],3);case 3:c=w[1][c]^getB(b[2],0),d=w[1][d]^getB(b[2],1),f=w[0][f]^getB(b[2],2),g=w[0][g]^getB(b[2],3);case 2:c=w[0][w[0][c]^getB(b[1],0)]^getB(b[0],0),d=w[0][w[1][d]^getB(b[1],1)]^getB(b[0],1),f=w[1][w[0][f]^getB(b[1],2)]^getB(b[0],2),g=w[1][w[1][g]^getB(b[1],3)]^getB(b[0],
|
|
|
|
|
3)}return z[0][c]^z[1][d]^z[2][f]^z[3][g]}c=a;var o,r,p,m;p=[];m=[];var y=[],x,v=[],u,t=[[8,1,7,13,6,15,3,2,0,11,5,9,14,12,10,4],[2,8,11,13,15,7,6,14,3,1,9,4,0,10,12,5]],E=[[14,12,11,8,1,2,3,5,15,4,10,6,7,0,9,13],[1,14,2,11,4,12,3,7,6,13,10,5,15,9,0,8]],Q=[[11,10,5,14,6,13,9,0,12,8,15,3,2,4,7,1],[4,12,7,5,1,6,9,10,0,14,13,8,2,11,3,15]],D=[[13,7,15,4,1,2,6,14,9,11,3,0,8,5,12,10],[11,9,5,1,12,3,13,14,6,4,7,15,2,0,8,10]],M=[0,8,1,9,2,10,3,11,4,12,5,13,6,14,7,15],K=[0,9,2,11,4,13,6,15,8,1,10,3,12,5,14,
|
|
|
|
|
7],w=[[],[]],z=[[],[],[],[]];c=c.slice(0,32);for(a=c.length;16!=a&&24!=a&&32!=a;)c[a++]=0;for(a=0;a<c.length;a+=4)y[a>>2]=getW(c,a);for(a=0;256>a;a++)w[0][a]=d(0,a),w[1][a]=d(1,a);for(a=0;256>a;a++)o=w[1][a],r=o^o>>2^[0,90,180,238][o&3],u=o^o>>1^o>>2^[0,238,180,90][o&3],z[0][a]=o+(r<<8)+(u<<16)+(u<<24),z[2][a]=r+(u<<8)+(o<<16)+(u<<24),o=w[0][a],r=o^o>>2^[0,90,180,238][o&3],u=o^o>>1^o>>2^[0,238,180,90][o&3],z[1][a]=u+(u<<8)+(r<<16)+(o<<24),z[3][a]=r+(o<<8)+(u<<16)+(r<<24);x=y.length/2;for(a=0;a<x;a++)o=
|
|
|
|
|
y[a+a],p[a]=o,r=y[a+a+1],m[a]=r,v[x-a-1]=b(o,r);for(a=0;40>a;a+=2)o=16843009*a,r=o+16843009,o=e(o,p),r=rotw(e(r,m),8),f[a]=o+r&MAXINT,f[a+1]=rotw(o+2*r,9);for(a=0;256>a;a++)switch(o=r=p=m=a,x){case 4:o=w[1][o]^getB(v[3],0),r=w[0][r]^getB(v[3],1),p=w[0][p]^getB(v[3],2),m=w[1][m]^getB(v[3],3);case 3:o=w[1][o]^getB(v[2],0),r=w[1][r]^getB(v[2],1),p=w[0][p]^getB(v[2],2),m=w[0][m]^getB(v[2],3);case 2:g[0][a]=z[0][w[0][w[0][o]^getB(v[1],0)]^getB(v[0],0)],g[1][a]=z[1][w[0][w[1][r]^getB(v[1],1)]^getB(v[0],
|
|
|
|
|
1)],g[2][a]=z[2][w[1][w[0][p]^getB(v[1],2)]^getB(v[0],2)],g[3][a]=z[3][w[1][w[1][m]^getB(v[1],3)]^getB(v[0],3)]}},close:function(){f=[];g=[[],[],[],[]]},encrypt:function(c,g){d=c;e=g;for(var j=[getW(d,e)^f[0],getW(d,e+4)^f[1],getW(d,e+8)^f[2],getW(d,e+12)^f[3]],l=0;8>l;l++){var o=l,r=j,p=b(r[0]),m=a(r[1]);r[2]=rotw(r[2]^p+m+f[4*o+8]&MAXINT,31);r[3]=rotw(r[3],1)^p+2*m+f[4*o+9]&MAXINT;p=b(r[2]);m=a(r[3]);r[0]=rotw(r[0]^p+m+f[4*o+10]&MAXINT,31);r[1]=rotw(r[1],1)^p+2*m+f[4*o+11]&MAXINT}setW(d,e,j[2]^
|
|
|
|
|
f[4]);setW(d,e+4,j[3]^f[5]);setW(d,e+8,j[0]^f[6]);setW(d,e+12,j[1]^f[7]);e+=16;return d},decrypt:function(c,g){d=c;e=g;for(var j=[getW(d,e)^f[4],getW(d,e+4)^f[5],getW(d,e+8)^f[6],getW(d,e+12)^f[7]],l=7;0<=l;l--){var o=l,r=j,p=b(r[0]),m=a(r[1]);r[2]=rotw(r[2],1)^p+m+f[4*o+10]&MAXINT;r[3]=rotw(r[3]^p+2*m+f[4*o+11]&MAXINT,31);p=b(r[2]);m=a(r[3]);r[0]=rotw(r[0],1)^p+m+f[4*o+8]&MAXINT;r[1]=rotw(r[1]^p+2*m+f[4*o+9]&MAXINT,31)}setW(d,e,j[2]^f[0]);setW(d,e+4,j[3]^f[1]);setW(d,e+8,j[0]^f[2]);setW(d,e+12,j[1]^
|
|
|
|
|
3)}return z[0][c]^z[1][d]^z[2][f]^z[3][g]}c=a;var m,r,p,o;p=[];o=[];var y=[],x,v=[],u,t=[[8,1,7,13,6,15,3,2,0,11,5,9,14,12,10,4],[2,8,11,13,15,7,6,14,3,1,9,4,0,10,12,5]],E=[[14,12,11,8,1,2,3,5,15,4,10,6,7,0,9,13],[1,14,2,11,4,12,3,7,6,13,10,5,15,9,0,8]],Q=[[11,10,5,14,6,13,9,0,12,8,15,3,2,4,7,1],[4,12,7,5,1,6,9,10,0,14,13,8,2,11,3,15]],D=[[13,7,15,4,1,2,6,14,9,11,3,0,8,5,12,10],[11,9,5,1,12,3,13,14,6,4,7,15,2,0,8,10]],M=[0,8,1,9,2,10,3,11,4,12,5,13,6,14,7,15],K=[0,9,2,11,4,13,6,15,8,1,10,3,12,5,14,
|
|
|
|
|
7],w=[[],[]],z=[[],[],[],[]];c=c.slice(0,32);for(a=c.length;16!=a&&24!=a&&32!=a;)c[a++]=0;for(a=0;a<c.length;a+=4)y[a>>2]=getW(c,a);for(a=0;256>a;a++)w[0][a]=d(0,a),w[1][a]=d(1,a);for(a=0;256>a;a++)m=w[1][a],r=m^m>>2^[0,90,180,238][m&3],u=m^m>>1^m>>2^[0,238,180,90][m&3],z[0][a]=m+(r<<8)+(u<<16)+(u<<24),z[2][a]=r+(u<<8)+(m<<16)+(u<<24),m=w[0][a],r=m^m>>2^[0,90,180,238][m&3],u=m^m>>1^m>>2^[0,238,180,90][m&3],z[1][a]=u+(u<<8)+(r<<16)+(m<<24),z[3][a]=r+(m<<8)+(u<<16)+(r<<24);x=y.length/2;for(a=0;a<x;a++)m=
|
|
|
|
|
y[a+a],p[a]=m,r=y[a+a+1],o[a]=r,v[x-a-1]=b(m,r);for(a=0;40>a;a+=2)m=16843009*a,r=m+16843009,m=e(m,p),r=rotw(e(r,o),8),f[a]=m+r&MAXINT,f[a+1]=rotw(m+2*r,9);for(a=0;256>a;a++)switch(m=r=p=o=a,x){case 4:m=w[1][m]^getB(v[3],0),r=w[0][r]^getB(v[3],1),p=w[0][p]^getB(v[3],2),o=w[1][o]^getB(v[3],3);case 3:m=w[1][m]^getB(v[2],0),r=w[1][r]^getB(v[2],1),p=w[0][p]^getB(v[2],2),o=w[0][o]^getB(v[2],3);case 2:g[0][a]=z[0][w[0][w[0][m]^getB(v[1],0)]^getB(v[0],0)],g[1][a]=z[1][w[0][w[1][r]^getB(v[1],1)]^getB(v[0],
|
|
|
|
|
1)],g[2][a]=z[2][w[1][w[0][p]^getB(v[1],2)]^getB(v[0],2)],g[3][a]=z[3][w[1][w[1][o]^getB(v[1],3)]^getB(v[0],3)]}},close:function(){f=[];g=[[],[],[],[]]},encrypt:function(c,g){d=c;e=g;for(var k=[getW(d,e)^f[0],getW(d,e+4)^f[1],getW(d,e+8)^f[2],getW(d,e+12)^f[3]],l=0;8>l;l++){var m=l,r=k,p=b(r[0]),o=a(r[1]);r[2]=rotw(r[2]^p+o+f[4*m+8]&MAXINT,31);r[3]=rotw(r[3],1)^p+2*o+f[4*m+9]&MAXINT;p=b(r[2]);o=a(r[3]);r[0]=rotw(r[0]^p+o+f[4*m+10]&MAXINT,31);r[1]=rotw(r[1],1)^p+2*o+f[4*m+11]&MAXINT}setW(d,e,k[2]^
|
|
|
|
|
f[4]);setW(d,e+4,k[3]^f[5]);setW(d,e+8,k[0]^f[6]);setW(d,e+12,k[1]^f[7]);e+=16;return d},decrypt:function(c,g){d=c;e=g;for(var k=[getW(d,e)^f[4],getW(d,e+4)^f[5],getW(d,e+8)^f[6],getW(d,e+12)^f[7]],l=7;0<=l;l--){var m=l,r=k,p=b(r[0]),o=a(r[1]);r[2]=rotw(r[2],1)^p+o+f[4*m+10]&MAXINT;r[3]=rotw(r[3]^p+2*o+f[4*m+11]&MAXINT,31);p=b(r[2]);o=a(r[3]);r[0]=rotw(r[0],1)^p+o+f[4*m+8]&MAXINT;r[1]=rotw(r[1]^p+2*o+f[4*m+9]&MAXINT,31)}setW(d,e,k[2]^f[0]);setW(d,e+4,k[3]^f[1]);setW(d,e+8,k[0]^f[2]);setW(d,e+12,k[1]^
|
|
|
|
|
f[3]);e+=16},finalize:function(){return d}}}JXG={exists:function(b){return function(a){return!(a===b||null===a)}}()};JXG.decompress=function(b){return unescape((new JXG.Util.Unzip(JXG.Util.Base64.decodeAsArray(b))).unzip()[0][0])};JXG.Util={};
|
|
|
|
|
JXG.Util.Unzip=function(b){function a(){aa+=8;return B<A.length?A[B++]:-1}function c(){var b;aa++;b=C&1;C>>=1;0==C&&(C=a(),b=C&1,C=C>>1|128);return b}function d(a){for(var b=0,d=a;d--;)b=b<<1|c();a&&(b=D[b]>>8-a);return b}function e(a){Q++;u[t++]=a;p.push(String.fromCharCode(a));32768==t&&(t=0)}function f(){this.b1=this.b0=0;this.jump=null;this.jumppos=-1}function g(){for(;;){if(W[N]>=ra)return-1;if(qa[W[N]]==N)return W[N]++;W[N]++}}function h(){var a=V[U],b;m&&document.write("<br>len:"+N+" treepos:"+
|
|
|
|
|
U);if(17==N)return-1;U++;N++;b=g();m&&document.write("<br>IsPat "+b);if(0<=b)a.b0=b,m&&document.write("<br>b0 "+a.b0);else if(a.b0=32768,m&&document.write("<br>b0 "+a.b0),h())return-1;b=g();if(0<=b)a.b1=b,m&&document.write("<br>b1 "+a.b1),a.jump=null;else if(a.b1=32768,m&&document.write("<br>b1 "+a.b1),a.jump=V[U],a.jumppos=U,h())return-1;N--;return 0}function k(a,b,c,d){m&&document.write("currentTree "+a+" numval "+b+" lengths "+c+" show "+d);V=a;U=0;qa=c;ra=b;for(a=0;17>a;a++)W[a]=0;N=0;if(h())return m&&
|
|
|
|
|
alert("invalid huffman tree\n"),-1;if(m){document.write("<br>Tree: "+V.length);for(a=0;32>a;a++)document.write("Places["+a+"].b0="+V[a].b0+"<br>"),document.write("Places["+a+"].b1="+V[a].b1+"<br>")}return 0}function j(a){for(var b,d,e=0,f=a[e];;)if(b=c(),m&&document.write("b="+b),b){if(!(f.b1&32768))return m&&document.write("ret1"),f.b1;f=f.jump;b=a.length;for(d=0;d<b;d++)if(a[d]===f){e=d;break}}else{if(!(f.b0&32768))return m&&document.write("ret2"),f.b0;e++;f=a[e]}m&&document.write("ret3");return-1}
|
|
|
|
|
function l(){var b,g,h,l,p;do{b=c();h=d(2);switch(h){case 0:m&&alert("Stored\n");break;case 1:m&&alert("Fixed Huffman codes\n");break;case 2:m&&alert("Dynamic Huffman codes\n");break;case 3:m&&alert("Reserved block type!!\n");break;default:m&&alert("Unexpected value %d!\n",h)}if(0==h){C=1;h=a();h|=a()<<8;g=a();g|=a()<<8;for((h^~g)&65535&&document.write("BlockLen checksum mismatch\n");h--;)g=a(),e(g)}else if(1==h)for(;;)if(h=D[d(7)]>>1,23<h?(h=h<<1|c(),199<h?(h-=128,h=h<<1|c()):(h-=48,143<h&&(h+=136))):
|
|
|
|
|
h+=256,256>h)e(h);else if(256==h)break;else{var o;h-=257;p=d(K[h])+M[h];h=D[d(5)]>>3;8<z[h]?(o=d(8),o|=d(z[h]-8)<<8):o=d(z[h]);o+=w[h];for(h=0;h<p;h++)g=u[t-o&32767],e(g)}else if(2==h){var r=Array(320);g=257+d(5);o=1+d(5);l=4+d(4);for(h=0;19>h;h++)r[h]=0;for(h=0;h<l;h++)r[T[h]]=d(3);p=P.length;for(l=0;l<p;l++)P[l]=new f;if(k(P,19,r,0))return t=0,1;if(m){document.write("<br>distanceTree");for(h=0;h<P.length;h++)document.write("<br>"+P[h].b0+" "+P[h].b1+" "+P[h].jump+" "+P[h].jumppos)}p=g+o;l=0;var v=
|
|
|
|
|
-1;for(m&&document.write("<br>n="+p+" bits: "+aa+"<br>");l<p;)if(v++,h=j(P),m&&document.write("<br>"+v+" i:"+l+" decode: "+h+" bits "+aa+"<br>"),16>h)r[l++]=h;else if(16==h){var x;h=3+d(2);if(l+h>p)return t=0,1;for(x=l?r[l-1]:0;h--;)r[l++]=x}else{h=17==h?3+d(3):11+d(7);if(l+h>p)return t=0,1;for(;h--;)r[l++]=0}p=ba.length;for(l=0;l<p;l++)ba[l]=new f;if(k(ba,g,r,0))return t=0,1;p=ba.length;for(l=0;l<p;l++)P[l]=new f;h=[];for(l=g;l<r.length;l++)h[l-g]=r[l];if(k(P,o,h,0))return t=0,1;m&&document.write("<br>literalTree");
|
|
|
|
|
a:for(;;)if(h=j(ba),256<=h){h-=256;if(0==h)break;h--;p=d(K[h])+M[h];h=j(P);8<z[h]?(o=d(8),o|=d(z[h]-8)<<8):o=d(z[h]);for(o+=w[h];p--;){if(0>t-o)break a;g=u[t-o&32767];e(g)}}else e(h)}}while(!b);t=0;C=1;return 0}function o(){m&&alert("NEXTFILE");p=[];var b=[];E=!1;b[0]=a();b[1]=a();m&&alert("type: "+b[0]+" "+b[1]);120==b[0]&&218==b[1]&&(m&&alert("GEONExT-GZIP"),l(),m&&alert(p.join("")),v[x]=Array(2),v[x][0]=p.join(""),v[x][1]="geonext.gxt",x++);120==b[0]&&156==b[1]&&(m&&alert("ZLIB"),l(),m&&alert(p.join("")),
|
|
|
|
|
v[x]=Array(2),v[x][0]=p.join(""),v[x][1]="ZLIB",x++);31==b[0]&&139==b[1]&&(m&&alert("GZIP"),r(),m&&alert(p.join("")),v[x]=Array(2),v[x][0]=p.join(""),v[x][1]="file",x++);if(80==b[0]&&75==b[1]&&(E=!0,b[2]=a(),b[3]=a(),3==b[2]&&4==b[3])){b[0]=a();b[1]=a();m&&alert("ZIP-Version: "+b[1]+" "+b[0]/10+"."+b[0]%10);y=a();y|=a()<<8;m&&alert("gpflags: "+y);b=a();b|=a()<<8;m&&alert("method: "+b);a();a();a();a();var c=a(),c=c|a()<<8,c=c|a()<<16,c=c|a()<<24,d=a(),d=d|a()<<8,d=d|a()<<16,d=d|a()<<24,e=a(),e=e|a()<<
|
|
|
|
|
8,e=e|a()<<16,e=e|a()<<24;m&&alert("local CRC: "+c+"\nlocal Size: "+e+"\nlocal CompSize: "+d);c=a();c|=a()<<8;d=a();d|=a()<<8;m&&alert("filelen "+c);f=0;for(R=[];c--;)e=a(),"/"==e|":"==e?f=0:f<oa-1&&(R[f++]=String.fromCharCode(e));m&&alert("nameBuf: "+R);pa||(pa=R);for(var f=0;f<d;)a(),f++;Q=0;8==b&&(l(),m&&alert(p.join("")),v[x]=Array(2),v[x][0]=p.join(""),v[x][1]=R.join(""),x++);r()}}function r(){var b=[],c;y&8&&(b[0]=a(),b[1]=a(),b[2]=a(),b[3]=a(),80==b[0]&&75==b[1]&&7==b[2]&&8==b[3]&&(a(),a(),
|
|
|
|
|
a(),a()),a(),a(),a(),a(),a(),a(),a(),a(),m&&alert("CRC:"));E&&o();b[0]=a();if(8!=b[0])return m&&alert("Unknown compression method!"),0;y=a();m&&y&-32&&alert("Unknown flags set!");a();a();a();a();a();a();if(y&4){b[0]=a();b[2]=a();N=b[0]+256*b[1];m&&alert("Extra field size: "+N);for(b=0;b<N;b++)a()}if(y&8){b=0;for(R=[];c=a();){if("7"==c||":"==c)b=0;b<oa-1&&(R[b++]=c)}m&&alert("original file name: "+R)}if(y&16)for(;a(););y&2&&(a(),a());l();a();a();a();a();a();a();a();a();E&&o()}var p=[],m=!1,y,x=0,v=
|
|
|
|
|
JXG.Util.Unzip=function(b){function a(){aa+=8;return B<A.length?A[B++]:-1}function c(){var b;aa++;b=C&1;C>>=1;0==C&&(C=a(),b=C&1,C=C>>1|128);return b}function d(a){for(var b=0,d=a;d--;)b=b<<1|c();a&&(b=D[b]>>8-a);return b}function e(a){Q++;u[t++]=a;p.push(String.fromCharCode(a));32768==t&&(t=0)}function f(){this.b1=this.b0=0;this.jump=null;this.jumppos=-1}function g(){for(;;){if(W[N]>=ra)return-1;if(qa[W[N]]==N)return W[N]++;W[N]++}}function h(){var a=V[U],b;o&&document.write("<br>len:"+N+" treepos:"+
|
|
|
|
|
U);if(17==N)return-1;U++;N++;b=g();o&&document.write("<br>IsPat "+b);if(0<=b)a.b0=b,o&&document.write("<br>b0 "+a.b0);else if(a.b0=32768,o&&document.write("<br>b0 "+a.b0),h())return-1;b=g();if(0<=b)a.b1=b,o&&document.write("<br>b1 "+a.b1),a.jump=null;else if(a.b1=32768,o&&document.write("<br>b1 "+a.b1),a.jump=V[U],a.jumppos=U,h())return-1;N--;return 0}function j(a,b,c,d){o&&document.write("currentTree "+a+" numval "+b+" lengths "+c+" show "+d);V=a;U=0;qa=c;ra=b;for(a=0;17>a;a++)W[a]=0;N=0;if(h())return o&&
|
|
|
|
|
alert("invalid huffman tree\n"),-1;if(o){document.write("<br>Tree: "+V.length);for(a=0;32>a;a++)document.write("Places["+a+"].b0="+V[a].b0+"<br>"),document.write("Places["+a+"].b1="+V[a].b1+"<br>")}return 0}function k(a){for(var b,d,e=0,f=a[e];;)if(b=c(),o&&document.write("b="+b),b){if(!(f.b1&32768))return o&&document.write("ret1"),f.b1;f=f.jump;b=a.length;for(d=0;d<b;d++)if(a[d]===f){e=d;break}}else{if(!(f.b0&32768))return o&&document.write("ret2"),f.b0;e++;f=a[e]}o&&document.write("ret3");return-1}
|
|
|
|
|
function l(){var b,g,h,l,m;do{b=c();h=d(2);switch(h){case 0:o&&alert("Stored\n");break;case 1:o&&alert("Fixed Huffman codes\n");break;case 2:o&&alert("Dynamic Huffman codes\n");break;case 3:o&&alert("Reserved block type!!\n");break;default:o&&alert("Unexpected value %d!\n",h)}if(0==h){C=1;h=a();h|=a()<<8;g=a();g|=a()<<8;for((h^~g)&65535&&document.write("BlockLen checksum mismatch\n");h--;)g=a(),e(g)}else if(1==h)for(;;)if(h=D[d(7)]>>1,23<h?(h=h<<1|c(),199<h?(h-=128,h=h<<1|c()):(h-=48,143<h&&(h+=136))):
|
|
|
|
|
h+=256,256>h)e(h);else if(256==h)break;else{var p;h-=257;m=d(K[h])+M[h];h=D[d(5)]>>3;8<z[h]?(p=d(8),p|=d(z[h]-8)<<8):p=d(z[h]);p+=w[h];for(h=0;h<m;h++)g=u[t-p&32767],e(g)}else if(2==h){var r=Array(320);g=257+d(5);p=1+d(5);l=4+d(4);for(h=0;19>h;h++)r[h]=0;for(h=0;h<l;h++)r[T[h]]=d(3);m=P.length;for(l=0;l<m;l++)P[l]=new f;if(j(P,19,r,0))return t=0,1;if(o){document.write("<br>distanceTree");for(h=0;h<P.length;h++)document.write("<br>"+P[h].b0+" "+P[h].b1+" "+P[h].jump+" "+P[h].jumppos)}m=g+p;l=0;var v=
|
|
|
|
|
-1;for(o&&document.write("<br>n="+m+" bits: "+aa+"<br>");l<m;)if(v++,h=k(P),o&&document.write("<br>"+v+" i:"+l+" decode: "+h+" bits "+aa+"<br>"),16>h)r[l++]=h;else if(16==h){var x;h=3+d(2);if(l+h>m)return t=0,1;for(x=l?r[l-1]:0;h--;)r[l++]=x}else{h=17==h?3+d(3):11+d(7);if(l+h>m)return t=0,1;for(;h--;)r[l++]=0}m=ba.length;for(l=0;l<m;l++)ba[l]=new f;if(j(ba,g,r,0))return t=0,1;m=ba.length;for(l=0;l<m;l++)P[l]=new f;h=[];for(l=g;l<r.length;l++)h[l-g]=r[l];if(j(P,p,h,0))return t=0,1;o&&document.write("<br>literalTree");
|
|
|
|
|
a:for(;;)if(h=k(ba),256<=h){h-=256;if(0==h)break;h--;m=d(K[h])+M[h];h=k(P);8<z[h]?(p=d(8),p|=d(z[h]-8)<<8):p=d(z[h]);for(p+=w[h];m--;){if(0>t-p)break a;g=u[t-p&32767];e(g)}}else e(h)}}while(!b);t=0;C=1;return 0}function m(){o&&alert("NEXTFILE");p=[];var b=[];E=!1;b[0]=a();b[1]=a();o&&alert("type: "+b[0]+" "+b[1]);120==b[0]&&218==b[1]&&(o&&alert("GEONExT-GZIP"),l(),o&&alert(p.join("")),v[x]=Array(2),v[x][0]=p.join(""),v[x][1]="geonext.gxt",x++);120==b[0]&&156==b[1]&&(o&&alert("ZLIB"),l(),o&&alert(p.join("")),
|
|
|
|
|
v[x]=Array(2),v[x][0]=p.join(""),v[x][1]="ZLIB",x++);31==b[0]&&139==b[1]&&(o&&alert("GZIP"),r(),o&&alert(p.join("")),v[x]=Array(2),v[x][0]=p.join(""),v[x][1]="file",x++);if(80==b[0]&&75==b[1]&&(E=!0,b[2]=a(),b[3]=a(),3==b[2]&&4==b[3])){b[0]=a();b[1]=a();o&&alert("ZIP-Version: "+b[1]+" "+b[0]/10+"."+b[0]%10);y=a();y|=a()<<8;o&&alert("gpflags: "+y);b=a();b|=a()<<8;o&&alert("method: "+b);a();a();a();a();var c=a(),c=c|a()<<8,c=c|a()<<16,c=c|a()<<24,d=a(),d=d|a()<<8,d=d|a()<<16,d=d|a()<<24,e=a(),e=e|a()<<
|
|
|
|
|
8,e=e|a()<<16,e=e|a()<<24;o&&alert("local CRC: "+c+"\nlocal Size: "+e+"\nlocal CompSize: "+d);c=a();c|=a()<<8;d=a();d|=a()<<8;o&&alert("filelen "+c);f=0;for(R=[];c--;)e=a(),"/"==e|":"==e?f=0:f<oa-1&&(R[f++]=String.fromCharCode(e));o&&alert("nameBuf: "+R);pa||(pa=R);for(var f=0;f<d;)a(),f++;Q=0;8==b&&(l(),o&&alert(p.join("")),v[x]=Array(2),v[x][0]=p.join(""),v[x][1]=R.join(""),x++);r()}}function r(){var b=[],c;y&8&&(b[0]=a(),b[1]=a(),b[2]=a(),b[3]=a(),80==b[0]&&75==b[1]&&7==b[2]&&8==b[3]&&(a(),a(),
|
|
|
|
|
a(),a()),a(),a(),a(),a(),a(),a(),a(),a(),o&&alert("CRC:"));E&&m();b[0]=a();if(8!=b[0])return o&&alert("Unknown compression method!"),0;y=a();o&&y&-32&&alert("Unknown flags set!");a();a();a();a();a();a();if(y&4){b[0]=a();b[2]=a();N=b[0]+256*b[1];o&&alert("Extra field size: "+N);for(b=0;b<N;b++)a()}if(y&8){b=0;for(R=[];c=a();){if("7"==c||":"==c)b=0;b<oa-1&&(R[b++]=c)}o&&alert("original file name: "+R)}if(y&16)for(;a(););y&2&&(a(),a());l();a();a();a();a();a();a();a();a();E&&m()}var p=[],o=!1,y,x=0,v=
|
|
|
|
|
[],u=Array(32768),t=0,E=!1,Q,D=[0,128,64,192,32,160,96,224,16,144,80,208,48,176,112,240,8,136,72,200,40,168,104,232,24,152,88,216,56,184,120,248,4,132,68,196,36,164,100,228,20,148,84,212,52,180,116,244,12,140,76,204,44,172,108,236,28,156,92,220,60,188,124,252,2,130,66,194,34,162,98,226,18,146,82,210,50,178,114,242,10,138,74,202,42,170,106,234,26,154,90,218,58,186,122,250,6,134,70,198,38,166,102,230,22,150,86,214,54,182,118,246,14,142,78,206,46,174,110,238,30,158,94,222,62,190,126,254,1,129,65,193,
|
|
|
|
|
33,161,97,225,17,145,81,209,49,177,113,241,9,137,73,201,41,169,105,233,25,153,89,217,57,185,121,249,5,133,69,197,37,165,101,229,21,149,85,213,53,181,117,245,13,141,77,205,45,173,109,237,29,157,93,221,61,189,125,253,3,131,67,195,35,163,99,227,19,147,83,211,51,179,115,243,11,139,75,203,43,171,107,235,27,155,91,219,59,187,123,251,7,135,71,199,39,167,103,231,23,151,87,215,55,183,119,247,15,143,79,207,47,175,111,239,31,159,95,223,63,191,127,255],M=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,
|
|
|
|
|
67,83,99,115,131,163,195,227,258,0,0],K=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,99,99],w=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],z=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],T=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],A=b,B=0,C=1,aa=0,oa=256,R=[],pa,ba=Array(288),P=Array(32),U=0,V=null,N=0,W=Array(17);W[0]=0;var qa,ra;JXG.Util.Unzip.prototype.unzipFile=function(a){var b;this.unzip();
|
|
|
|
|
for(b=0;b<v.length;b++)if(v[b][1]==a)return v[b][0]};JXG.Util.Unzip.prototype.deflate=function(){p=[];E=!1;l();m&&alert(p.join(""));v[x]=Array(2);v[x][0]=p.join("");v[x][1]="DEFLATE";x++;return v};JXG.Util.Unzip.prototype.unzip=function(){m&&alert(A);o();return v}};
|
|
|
|
|
JXG.Util.Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(b){for(var a=[],c,d,e,f,g,h,k=0,b=JXG.Util.Base64._utf8_encode(b);k<b.length;)c=b.charCodeAt(k++),d=b.charCodeAt(k++),e=b.charCodeAt(k++),f=c>>2,c=(c&3)<<4|d>>4,g=(d&15)<<2|e>>6,h=e&63,isNaN(d)?g=h=64:isNaN(e)&&(h=64),a.push([this._keyStr.charAt(f),this._keyStr.charAt(c),this._keyStr.charAt(g),this._keyStr.charAt(h)].join(""));return a.join("")},decode:function(b,a){for(var c=[],d,e,f,g,h,
|
|
|
|
|
k=0,b=b.replace(/[^A-Za-z0-9\+\/\=]/g,"");k<b.length;)d=this._keyStr.indexOf(b.charAt(k++)),e=this._keyStr.indexOf(b.charAt(k++)),g=this._keyStr.indexOf(b.charAt(k++)),h=this._keyStr.indexOf(b.charAt(k++)),d=d<<2|e>>4,e=(e&15)<<4|g>>2,f=(g&3)<<6|h,c.push(String.fromCharCode(d)),64!=g&&c.push(String.fromCharCode(e)),64!=h&&c.push(String.fromCharCode(f));c=c.join("");a&&(c=JXG.Util.Base64._utf8_decode(c));return c},_utf8_encode:function(b){for(var b=b.replace(/\r\n/g,"\n"),a="",c=0;c<b.length;c++){var d=
|
|
|
|
|
for(b=0;b<v.length;b++)if(v[b][1]==a)return v[b][0]};JXG.Util.Unzip.prototype.deflate=function(){p=[];E=!1;l();o&&alert(p.join(""));v[x]=Array(2);v[x][0]=p.join("");v[x][1]="DEFLATE";x++;return v};JXG.Util.Unzip.prototype.unzip=function(){o&&alert(A);m();return v}};
|
|
|
|
|
JXG.Util.Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(b){for(var a=[],c,d,e,f,g,h,j=0,b=JXG.Util.Base64._utf8_encode(b);j<b.length;)c=b.charCodeAt(j++),d=b.charCodeAt(j++),e=b.charCodeAt(j++),f=c>>2,c=(c&3)<<4|d>>4,g=(d&15)<<2|e>>6,h=e&63,isNaN(d)?g=h=64:isNaN(e)&&(h=64),a.push([this._keyStr.charAt(f),this._keyStr.charAt(c),this._keyStr.charAt(g),this._keyStr.charAt(h)].join(""));return a.join("")},decode:function(b,a){for(var c=[],d,e,f,g,h,
|
|
|
|
|
j=0,b=b.replace(/[^A-Za-z0-9\+\/\=]/g,"");j<b.length;)d=this._keyStr.indexOf(b.charAt(j++)),e=this._keyStr.indexOf(b.charAt(j++)),g=this._keyStr.indexOf(b.charAt(j++)),h=this._keyStr.indexOf(b.charAt(j++)),d=d<<2|e>>4,e=(e&15)<<4|g>>2,f=(g&3)<<6|h,c.push(String.fromCharCode(d)),64!=g&&c.push(String.fromCharCode(e)),64!=h&&c.push(String.fromCharCode(f));c=c.join("");a&&(c=JXG.Util.Base64._utf8_decode(c));return c},_utf8_encode:function(b){for(var b=b.replace(/\r\n/g,"\n"),a="",c=0;c<b.length;c++){var d=
|
|
|
|
|
b.charCodeAt(c);128>d?a+=String.fromCharCode(d):(127<d&&2048>d?a+=String.fromCharCode(d>>6|192):(a+=String.fromCharCode(d>>12|224),a+=String.fromCharCode(d>>6&63|128)),a+=String.fromCharCode(d&63|128))}return a},_utf8_decode:function(b){for(var a=[],c=0,d=0,e=0,f=0;c<b.length;)d=b.charCodeAt(c),128>d?(a.push(String.fromCharCode(d)),c++):191<d&&224>d?(e=b.charCodeAt(c+1),a.push(String.fromCharCode((d&31)<<6|e&63)),c+=2):(e=b.charCodeAt(c+1),f=b.charCodeAt(c+2),a.push(String.fromCharCode((d&15)<<12|
|
|
|
|
|
(e&63)<<6|f&63)),c+=3);return a.join("")},_destrip:function(b,a){var c=[],d,e,f=[];null==a&&(a=76);b.replace(/ /g,"");d=b.length/a;for(e=0;e<d;e++)c[e]=b.substr(e*a,a);d!=b.length/a&&(c[c.length]=b.substr(d*a,b.length-d*a));for(e=0;e<c.length;e++)f.push(c[e]);return f.join("\n")},decodeAsArray:function(b){var b=this.decode(b),a=[],c;for(c=0;c<b.length;c++)a[c]=b.charCodeAt(c);return a},decodeGEONExT:function(b){return decodeAsArray(destrip(b),!1)}};
|
|
|
|
|
JXG.Util.asciiCharCodeAt=function(b,a){var c=b.charCodeAt(a);if(255<c)switch(c){case 8364:c=128;break;case 8218:c=130;break;case 402:c=131;break;case 8222:c=132;break;case 8230:c=133;break;case 8224:c=134;break;case 8225:c=135;break;case 710:c=136;break;case 8240:c=137;break;case 352:c=138;break;case 8249:c=139;break;case 338:c=140;break;case 381:c=142;break;case 8216:c=145;break;case 8217:c=146;break;case 8220:c=147;break;case 8221:c=148;break;case 8226:c=149;break;case 8211:c=150;break;case 8212:c=
|
|
|
|
|
151;break;case 732:c=152;break;case 8482:c=153;break;case 353:c=154;break;case 8250:c=155;break;case 339:c=156;break;case 382:c=158;break;case 376:c=159}return c};
|
|
|
|
|
JXG.Util.utf8Decode=function(b){var a=[],c=0,d=0,e=0,f;if(!JXG.exists(b))return"";for(;c<b.length;)d=b.charCodeAt(c),128>d?(a.push(String.fromCharCode(d)),c++):191<d&&224>d?(e=b.charCodeAt(c+1),a.push(String.fromCharCode((d&31)<<6|e&63)),c+=2):(e=b.charCodeAt(c+1),f=b.charCodeAt(c+2),a.push(String.fromCharCode((d&15)<<12|(e&63)<<6|f&63)),c+=3);return a.join("")};
|
|
|
|
|
JXG.Util.genUUID=function(){for(var b="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),a=Array(36),c=0,d,e=0;36>e;e++)8==e||13==e||18==e||23==e?a[e]="-":14==e?a[e]="4":(2>=c&&(c=33554432+16777216*Math.random()|0),d=c&15,c>>=4,a[e]=b[19==e?d&3|8:d]);return a.join("")};
|
|
|
|
|
function openpgp_config(){this.config=null;this.default_config={prefer_hash_algorithm:2,encryption_cipher:9,compression:1,show_version:!0,show_comment:!0,integrity_protect:!0,composition_behavior:0,keyserver:"keyserver.linux.it"};this.versionstring="OpenPGP.js v.1.20130114";this.commentstring="http://openpgpjs.org";this.debug=!1;this.read=function(){var b=JSON.parse(window.localStorage.getItem("config"));null==b?(this.config=this.default_config,this.write()):this.config=b};this.write=function(){window.localStorage.setItem("config",
|
|
|
|
|
function openpgp_config(){this.config=null;this.default_config={prefer_hash_algorithm:2,encryption_cipher:9,compression:1,show_version:!0,show_comment:!0,integrity_protect:!0,composition_behavior:0,keyserver:"keyserver.linux.it"};this.versionstring="OpenPGP.js v.1.20130213";this.commentstring="http://openpgpjs.org";this.debug=!1;this.read=function(){var b=JSON.parse(window.localStorage.getItem("config"));null==b?(this.config=this.default_config,this.write()):this.config=b};this.write=function(){window.localStorage.setItem("config",
|
|
|
|
|
JSON.stringify(this.config))}}var b64s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function s2r(b){var a,c,d,e="",f=0,g=0,h=b.length;for(d=0;d<h;d++)c=b.charCodeAt(d),0==g?(e+=b64s.charAt(c>>2&63),a=(c&3)<<4):1==g?(e+=b64s.charAt(a|c>>4&15),a=(c&15)<<2):2==g&&(e+=b64s.charAt(a|c>>6&3),f+=1,0==f%60&&(e+="\n"),e+=b64s.charAt(c&63)),f+=1,0==f%60&&(e+="\n"),g+=1,3==g&&(g=0);0<g&&(e+=b64s.charAt(a),f+=1,0==f%60&&(e+="\n"),e+="=",f+=1);1==g&&(0==f%60&&(e+="\n"),e+="=");return e}
|
|
|
|
|
function r2s(b){var a,c,d="",e=0,f=0,g=b.length;for(c=0;c<g;c++)a=b64s.indexOf(b.charAt(c)),0<=a&&(e&&(d+=String.fromCharCode(f|a>>6-e&255)),e=e+2&7,f=a<<e&255);return d}
|
|
|
|
|
function openpgp_encoding_deArmor(b){var a=getPGPMessageType(b);if(2!=a){b=b.split("-----");data={openpgp:openpgp_encoding_base64_decode(b[2].split("\n\n")[1].split("\n=")[0].replace(/\n- /g,"\n")),type:a};if(verifyCheckSum(data.openpgp,b[2].split("\n\n")[1].split("\n=")[1].split("\n")[0]))return data;util.print_error("Ascii armor integrity check on message failed: '"+b[2].split("\n\n")[1].split("\n=")[1].split("\n")[0]+"' should be '"+getCheckSum(data))}else{b=b.split("-----");a={text:b[2].replace(/\n- /g,
|
|
|
|
@ -309,14 +309,14 @@ function openpgp_encoding_eme_pkcs1_decode(b,a){b.length<a&&(b=String.fromCharCo
|
|
|
|
|
hash_headers[9]=[48,65,48,13,6,9,96,134,72,1,101,3,4,2,2,5,0,4,48];hash_headers[10]=[48,81,48,13,6,9,96,134,72,1,101,3,4,2,3,5,0,4,64];hash_headers[11]=[48,49,48,13,6,9,96,134,72,1,101,3,4,2,4,5,0,4,28];
|
|
|
|
|
function openpgp_encoding_emsa_pkcs1_encode(b,a,c){var d;d=""+String.fromCharCode(0);d+=String.fromCharCode(1);for(var e=0;e<c-hash_headers[b].length-3-openpgp_crypto_getHashByteLength(b);e++)d+=String.fromCharCode(255);d+=String.fromCharCode(0);for(e=0;e<hash_headers[b].length;e++)d+=String.fromCharCode(hash_headers[b][e]);d+=openpgp_crypto_hashData(b,a);return new BigInteger(util.hexstrdump(d),16)}
|
|
|
|
|
function openpgp_encoding_emsa_pkcs1_decode(b,a){var c=0;if(0!=a.charCodeAt(0)&&1!=a.charCodeAt(0))return-1;for(c++;255==a.charCodeAt(c);)c++;if(0!=a.charCodeAt(c++))return-1;for(var d=0,d=0;d<hash_headers[b].length&&d+c<a.length;d++)if(a.charCodeAt(d+c)!=hash_headers[b][d])return-1;c+=d;return a.substring(c).length<openpgp_crypto_getHashByteLength(b)?-1:a.substring(c)}
|
|
|
|
|
function _openpgp(){function b(a){for(var b=a.openpgp,d=a.text,e=[],f=0,g=0,h=b.length;g<b.length;){var k=openpgp_packet.read_packet(b,g,h);if(!k)break;if(1==k.tagType||2==k.tagType&&16>k.signatureType||3==k.tagType||4==k.tagType||8==k.tagType||9==k.tagType||10==k.tagType||11==k.tagType||18==k.tagType||19==k.tagType)if(e[e.length]=new openpgp_msg_message,e[f].messagePacket=k,e[f].type=a.type,9==k.tagType||1==k.tagType||3==k.tagType||18==k.tagType)if(9==k.tagType){util.print_error("unexpected openpgp packet");
|
|
|
|
|
break}else if(1==k.tagType){util.print_debug("session key found:\n "+k.toString());var j=!0;e[f].sessionKeys=[];for(var l=0;j;)e[f].sessionKeys[l]=k,g+=k.packetLength+k.headerLength,h-=k.packetLength+k.headerLength,k=openpgp_packet.read_packet(b,g,h),1!=k.tagType&&3!=k.tagType&&(j=!1),l++;18==k.tagType||9==k.tagType?(util.print_debug("encrypted data found:\n "+k.toString()),e[f].encryptedData=k,g+=k.packetLength+k.headerLength,h-=k.packetLength+k.headerLength,f++):util.print_debug("something is wrong: "+
|
|
|
|
|
k.tagType)}else{if(18==k.tagType){util.print_debug("symmetric encrypted data");break}}else 2==k.tagType&&3>k.signatureType?(g+=k.packetLength+k.headerLength,h-=k.packetLength+k.headerLength,e[f].text=d,e[f].signature=k,f++):4==k.tagType?(g+=k.packetLength+k.headerLength,h-=k.packetLength+k.headerLength):8==k.tagType?(g+=k.packetLength+k.headerLength,h-=k.packetLength+k.headerLength,k=k.decompress(),e=e.concat(openpgp.read_messages_dearmored({text:k,openpgp:k}))):10==k.tagType?(e.length=0,g+=k.packetLength+
|
|
|
|
|
k.headerLength,h-=k.packetLength+k.headerLength):11==k.tagType?(g+=k.packetLength+k.headerLength,h-=k.packetLength+k.headerLength,d=k.data,e[f].data=k.data,f++):19==k.tagType&&(g+=k.packetLength+k.headerLength,h-=k.packetLength+k.headerLength);else return util.print_error("no message found!"),null}return e}this.tostring="";this.generate_key_pair=function(a,b,d,e){var f=(new openpgp_packet_userid).write_packet(d),b=openpgp_crypto_generateKeyPair(a,b,e,openpgp.config.config.prefer_hash_algorithm,3),
|
|
|
|
|
function _openpgp(){function b(a){for(var b=a.openpgp,d=a.text,e=[],f=0,g=0,h=b.length;g<b.length;){var j=openpgp_packet.read_packet(b,g,h);if(!j)break;if(1==j.tagType||2==j.tagType&&16>j.signatureType||3==j.tagType||4==j.tagType||8==j.tagType||9==j.tagType||10==j.tagType||11==j.tagType||18==j.tagType||19==j.tagType)if(e[e.length]=new openpgp_msg_message,e[f].messagePacket=j,e[f].type=a.type,9==j.tagType||1==j.tagType||3==j.tagType||18==j.tagType)if(9==j.tagType){util.print_error("unexpected openpgp packet");
|
|
|
|
|
break}else if(1==j.tagType){util.print_debug("session key found:\n "+j.toString());var k=!0;e[f].sessionKeys=[];for(var l=0;k;)e[f].sessionKeys[l]=j,g+=j.packetLength+j.headerLength,h-=j.packetLength+j.headerLength,j=openpgp_packet.read_packet(b,g,h),1!=j.tagType&&3!=j.tagType&&(k=!1),l++;18==j.tagType||9==j.tagType?(util.print_debug("encrypted data found:\n "+j.toString()),e[f].encryptedData=j,g+=j.packetLength+j.headerLength,h-=j.packetLength+j.headerLength,f++):util.print_debug("something is wrong: "+
|
|
|
|
|
j.tagType)}else{if(18==j.tagType){util.print_debug("symmetric encrypted data");break}}else 2==j.tagType&&3>j.signatureType?(g+=j.packetLength+j.headerLength,h-=j.packetLength+j.headerLength,e[f].text=d,e[f].signature=j,f++):4==j.tagType?(g+=j.packetLength+j.headerLength,h-=j.packetLength+j.headerLength):8==j.tagType?(g+=j.packetLength+j.headerLength,h-=j.packetLength+j.headerLength,j=j.decompress(),e=e.concat(openpgp.read_messages_dearmored({text:j,openpgp:j}))):10==j.tagType?(e.length=0,g+=j.packetLength+
|
|
|
|
|
j.headerLength,h-=j.packetLength+j.headerLength):11==j.tagType?(g+=j.packetLength+j.headerLength,h-=j.packetLength+j.headerLength,d=j.data,e[f].data=j.data,f++):19==j.tagType&&(g+=j.packetLength+j.headerLength,h-=j.packetLength+j.headerLength);else return util.print_error("no message found!"),null}return e}this.tostring="";this.generate_key_pair=function(a,b,d,e){var f=(new openpgp_packet_userid).write_packet(d),b=openpgp_crypto_generateKeyPair(a,b,e,openpgp.config.config.prefer_hash_algorithm,3),
|
|
|
|
|
a=b.privateKey,g=(new openpgp_packet_keymaterial).read_priv_key(a.string,3,a.string.length);g.decryptSecretMPIs(e)||util.print_error("Issue creating key. Unable to read resulting private key");e=new openpgp_msg_privatekey;e.privateKeyPacket=g;e.getPreferredSignatureHashAlgorithm=function(){return openpgp.config.config.prefer_hash_algorithm};g=e.privateKeyPacket.publicKey.data;g=String.fromCharCode(153)+String.fromCharCode(g.length>>8&255)+String.fromCharCode(g.length&255)+g+String.fromCharCode(180)+
|
|
|
|
|
String.fromCharCode(d.length>>24)+String.fromCharCode(d.length>>16&255)+String.fromCharCode(d.length>>8&255)+String.fromCharCode(d.length&255)+d;d=new openpgp_packet_signature;d=d.write_message_signature(16,g,e);b=openpgp_encoding_armor(4,b.publicKey.string+f+d.openpgp);f=openpgp_encoding_armor(5,a.string+f+d.openpgp);return{privateKey:e,privateKeyArmored:f,publicKeyArmored:b}};this.write_signed_message=function(a,b){var d=(new openpgp_packet_signature).write_message_signature(1,b.replace(/\r\n/g,
|
|
|
|
|
"\n").replace(/\n/,"\r\n"),a),d={text:b.replace(/\r\n/g,"\n").replace(/\n/,"\r\n"),openpgp:d.openpgp,hash:d.hash};return openpgp_encoding_armor(2,d,null,null)};this.write_signed_and_encrypted_message=function(a,b,d){var e="",f=(new openpgp_packet_literaldata).write_packet(d.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"));util.print_debug_hexstr_dump("literal_packet: |"+f+"|\n",f);for(var g=0;g<b.length;g++){var h="",h=(new openpgp_packet_onepasssignature).write_packet(1,openpgp.config.config.prefer_hash_algorithm,
|
|
|
|
|
a,!1);util.print_debug_hexstr_dump("onepasssigstr: |"+h+"|\n",h);var k=(new openpgp_packet_signature).write_message_signature(1,d.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"),a);util.print_debug_hexstr_dump("datasignature: |"+k.openpgp+"|\n",k.openpgp);e=0==g?h+f+k.openpgp:h+e+k.openpgp}util.print_debug_hexstr_dump("signed packet: |"+e+"|\n",e);a=openpgp_crypto_generateSessionKey(openpgp.config.config.encryption_cipher);d="";for(g=0;g<b.length;g++){f=b[g].getEncryptionKey();if(null==f)return util.print_error("no encryption key found! Key is for signing only."),
|
|
|
|
|
a,!1);util.print_debug_hexstr_dump("onepasssigstr: |"+h+"|\n",h);var j=(new openpgp_packet_signature).write_message_signature(1,d.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"),a);util.print_debug_hexstr_dump("datasignature: |"+j.openpgp+"|\n",j.openpgp);e=0==g?h+f+j.openpgp:h+e+j.openpgp}util.print_debug_hexstr_dump("signed packet: |"+e+"|\n",e);a=openpgp_crypto_generateSessionKey(openpgp.config.config.encryption_cipher);d="";for(g=0;g<b.length;g++){f=b[g].getEncryptionKey();if(null==f)return util.print_error("no encryption key found! Key is for signing only."),
|
|
|
|
|
null;d+=(new openpgp_packet_encryptedsessionkey).write_pub_key_packet(f.getKeyId(),f.MPIs,f.publicKeyAlgorithm,openpgp.config.config.encryption_cipher,a)}d=openpgp.config.config.integrity_protect?d+(new openpgp_packet_encryptedintegrityprotecteddata).write_packet(openpgp.config.config.encryption_cipher,a,e):d+(new openpgp_packet_encrypteddata).write_packet(openpgp.config.config.encryption_cipher,a,e);return openpgp_encoding_armor(3,d,null,null)};this.write_encrypted_message=function(a,b){var d="",
|
|
|
|
|
d=(new openpgp_packet_literaldata).write_packet(b.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"));util.print_debug_hexstr_dump("literal_packet: |"+d+"|\n",d);for(var e=openpgp_crypto_generateSessionKey(openpgp.config.config.encryption_cipher),f="",g=0;g<a.length;g++){var h=a[g].getEncryptionKey();if(null==h)return util.print_error("no encryption key found! Key is for signing only."),null;f+=(new openpgp_packet_encryptedsessionkey).write_pub_key_packet(h.getKeyId(),h.MPIs,h.publicKeyAlgorithm,openpgp.config.config.encryption_cipher,
|
|
|
|
|
e)}f=openpgp.config.config.integrity_protect?f+(new openpgp_packet_encryptedintegrityprotecteddata).write_packet(openpgp.config.config.encryption_cipher,e,d):f+(new openpgp_packet_encrypteddata).write_packet(openpgp.config.config.encryption_cipher,e,d);return openpgp_encoding_armor(3,f,null,null)};this.read_message=function(a){var c;try{c=openpgp_encoding_deArmor(a.replace(/\r/g,""))}catch(d){return util.print_error("no message found!"),null}return b(c)};this.read_messages_dearmored=b;this.read_publicKey=
|
|
|
|
@ -326,12 +326,13 @@ e+=b[d].read_nodes(g,a,e,f);else return util.print_error("no block packet found!
|
|
|
|
|
function openpgp_keyring(){this.init=function(){var b=JSON.parse(window.localStorage.getItem("privatekeys")),a=JSON.parse(window.localStorage.getItem("publickeys"));if(null==b||0==b.length)b=[];if(null==a||0==a.length)a=[];this.publicKeys=[];this.privateKeys=[];for(var c=0,d=0;d<b.length;d++){var e=openpgp.read_privateKey(b[d]);this.privateKeys[c]={armored:b[d],obj:e[0],keyId:e[0].getKeyId()};c++}for(d=c=0;d<a.length;d++)e=openpgp.read_publicKey(a[d]),null!=e[0]&&(this.publicKeys[c]={armored:a[d],
|
|
|
|
|
obj:e[0],keyId:e[0].getKeyId()},c++)};this.hasPrivateKey=function(){return 0<this.privateKeys.length};this.store=function(){for(var b=[],a=0;a<this.privateKeys.length;a++)b[a]=this.privateKeys[a].armored;for(var c=[],a=0;a<this.publicKeys.length;a++)c[a]=this.publicKeys[a].armored;window.localStorage.setItem("privatekeys",JSON.stringify(b));window.localStorage.setItem("publickeys",JSON.stringify(c))};this.getPublicKeyForAddress=function(b){var a=[],c=b.split("<"),d="",d=1<c.length?c[1].split(">")[0]:
|
|
|
|
|
b.trim(),d=d.toLowerCase();if(!util.emailRegEx.test(d))return a;for(b=0;b<this.publicKeys.length;b++)for(c=0;c<this.publicKeys[b].obj.userIds.length;c++)0<=this.publicKeys[b].obj.userIds[c].text.toLowerCase().indexOf(d)&&(a[a.length]=this.publicKeys[b]);return a};this.getPrivateKeyForAddress=function(b){var a=[],c=b.split("<"),d="",d=1<c.length?c[1].split(">")[0]:b.trim(),d=d.toLowerCase();if(!util.emailRegEx.test(d))return a;for(b=0;b<this.privateKeys.length;b++)for(c=0;c<this.privateKeys[b].obj.userIds.length;c++)0<=
|
|
|
|
|
this.privateKeys[b].obj.userIds[c].text.toLowerCase().indexOf(d)&&(a[a.length]=this.privateKeys[b]);return a};this.getPublicKeysForKeyId=function(b){for(var a=[],c=0;c<this.publicKeys.length;c++)b==this.publicKeys[c].obj.getKeyId()&&(a[a.length]=this.publicKeys[c]);return a};this.getPrivateKeyForKeyId=function(b){for(var a=[],c=0;c<this.privateKeys.length;c++)if(b==this.privateKeys[c].obj.getKeyId()&&(a[a.length]={key:this.privateKeys[c],keymaterial:this.privateKeys[c].obj.privateKeyPacket}),null!=
|
|
|
|
|
this.privateKeys[c].obj.subKeys)for(var d=this.privateKeys[c].obj.getSubKeyIds(),e=0;e<d.length;e++)b==util.hexstrdump(d[e])&&(a[a.length]={key:this.privateKeys[c],keymaterial:this.privateKeys[c].obj.subKeys[e]});return a};this.importPublicKey=function(b){for(var a=openpgp.read_publicKey(b),c=0;c<a.length;c++)this.publicKeys[this.publicKeys.length]={armored:b,obj:a[c],keyId:a[c].getKeyId()};return!0};this.importPrivateKey=function(b,a){var c=openpgp.read_privateKey(b);if(!c[0].decryptSecretMPIs(a))return!1;
|
|
|
|
|
for(var d=0;d<c.length;d++)this.privateKeys[this.privateKeys.length]={armored:b,obj:c[d],keyId:c[d].getKeyId()};return!0};this.exportPublicKey=function(b){return this.publicKey[b]};this.removePublicKey=function(b){b=this.publicKeys.splice(b,1);this.store();return b};this.exportPrivateKey=function(b){return this.privateKeys[b]};this.removePrivateKey=function(b){b=this.privateKeys.splice(b,1);this.store();return b}}
|
|
|
|
|
this.privateKeys[b].obj.userIds[c].text.toLowerCase().indexOf(d)&&(a[a.length]=this.privateKeys[b]);return a};this.getPublicKeysForKeyId=function(b){for(var a=[],c=0;c<this.publicKeys.length;c++){var d=this.publicKeys[c];if(b==d.obj.getKeyId())a[a.length]=d;else if(null!=d.obj.subKeys)for(var e=0;e<d.obj.subKeys.length;e++){var f=d.obj.subKeys[e];b==f.getKeyId()&&(a[a.length]={obj:d.obj.getSubKeyAsKey(e),keyId:f.getKeyId()})}}return a};this.getPrivateKeyForKeyId=function(b){for(var a=[],c=0;c<this.privateKeys.length;c++)if(b==
|
|
|
|
|
this.privateKeys[c].obj.getKeyId()&&(a[a.length]={key:this.privateKeys[c],keymaterial:this.privateKeys[c].obj.privateKeyPacket}),null!=this.privateKeys[c].obj.subKeys)for(var d=this.privateKeys[c].obj.getSubKeyIds(),e=0;e<d.length;e++)b==util.hexstrdump(d[e])&&(a[a.length]={key:this.privateKeys[c],keymaterial:this.privateKeys[c].obj.subKeys[e]});return a};this.importPublicKey=function(b){for(var a=openpgp.read_publicKey(b),c=0;c<a.length;c++)this.publicKeys[this.publicKeys.length]={armored:b,obj:a[c],
|
|
|
|
|
keyId:a[c].getKeyId()};return!0};this.importPrivateKey=function(b,a){var c=openpgp.read_privateKey(b);if(!c[0].decryptSecretMPIs(a))return!1;for(var d=0;d<c.length;d++)this.privateKeys[this.privateKeys.length]={armored:b,obj:c[d],keyId:c[d].getKeyId()};return!0};this.exportPublicKey=function(b){return this.publicKey[b]};this.removePublicKey=function(b){b=this.publicKeys.splice(b,1);this.store();return b};this.exportPrivateKey=function(b){return this.privateKeys[b]};this.removePrivateKey=function(b){b=
|
|
|
|
|
this.privateKeys.splice(b,1);this.store();return b}}
|
|
|
|
|
function openpgp_msg_message(){this.text="";this.type=this.messagePacket=null;this.decrypt=function(b,a){return this.decryptAndVerifySignature(b,a).text};this.decryptAndVerifySignature=function(b,a,c){if(null==b||null==a||""==a)return null;a=a.decrypt(this,b.keymaterial);if(null==a)return null;b=[];util.print_debug_hexstr_dump("openpgp.msg.messge decrypt:\n",a);var a=openpgp.read_messages_dearmored({text:a,openpgp:a}),d;for(d in a){if(a[d].data)this.text=a[d].data;a[d].signature&&b.push(a[d].verifySignature(c))}return{text:this.text,
|
|
|
|
|
validSignatures:b}};this.verifySignature=function(b){var a=!1;if(2==this.signature.tagType){if(!b||0==b.length)if(4==this.signature.version)b=openpgp.keyring.getPublicKeysForKeyId(this.signature.issuerKeyId);else if(3==this.signature.version)b=openpgp.keyring.getPublicKeysForKeyId(this.signature.keyId);else return util.print_error("unknown signature type on message!"),!1;if(0==b.length)util.print_warning("Unable to verify signature of issuer: "+util.hexstrdump(this.signature.issuerKeyId)+". Public key not found in keyring.");
|
|
|
|
|
else for(var c=0;c<b.length;c++)this.signature.verify(this.text.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"),b[c])?(util.print_info("Found Good Signature from "+b[c].obj.userIds[c].text+" (0x"+util.hexstrdump(b[c].obj.getKeyId()).substring(8)+")"),a=!0):util.print_error("Signature verification failed: Bad Signature from "+b[c].obj.userIds[0].text+" (0x"+util.hexstrdump(b[0].obj.getKeyId()).substring(8)+")")}return a};this.toString=function(){var b="Session Keys:\n";if(null!=this.sessionKeys)for(var a=
|
|
|
|
|
else for(var c=0;c<b.length;c++)this.signature.verify(this.text.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"),b[c])?(util.print_info("Found Good Signature from "+b[c].obj.userIds[0].text+" (0x"+util.hexstrdump(b[c].obj.getKeyId()).substring(8)+")"),a=!0):util.print_error("Signature verification failed: Bad Signature from "+b[c].obj.userIds[0].text+" (0x"+util.hexstrdump(b[0].obj.getKeyId()).substring(8)+")")}return a};this.toString=function(){var b="Session Keys:\n";if(null!=this.sessionKeys)for(var a=
|
|
|
|
|
0;a<this.sessionKeys.length;a++)b+=this.sessionKeys[a].toString();b+="\n\n EncryptedData:\n";null!=this.encryptedData&&(b+=this.encryptedData.toString());b+="\n\n Signature:\n";null!=this.signature&&(b+=this.signature.toString());b+="\n\n Text:\n";null!=this.signature&&(b+=this.text);return b}}
|
|
|
|
|
function openpgp_msg_privatekey(){this.subKeys=[];this.privateKeyPacket=null;this.userIds=[];this.userAttributes=[];this.revocationSignatures=[];this.subKeys=[];this.extractPublicKey=function(){for(var b=this.privateKeyPacket.publicKey.header+this.privateKeyPacket.publicKey.data,a=0;a<this.userIds.length;a++){if(0===this.userIds[a].certificationSignatures.length)return util.print_error("extractPublicKey - missing certification signatures"),null;for(var c=new openpgp_packet_userid,b=b+c.write_packet(this.userIds[a].text),
|
|
|
|
|
c=0;c<this.userIds[a].certificationSignatures.length;c++)var d=this.userIds[a].certificationSignatures[c],b=b+(openpgp_packet.write_packet_header(2,d.data.length)+d.data)}for(a=0;a<this.subKeys.length;a++)if(c=this.subKeys[a].publicKey,b+=openpgp_packet.write_old_packet_header(14,c.data.length)+c.data,c=this.subKeys[a].subKeySignature,null!==c)b+=openpgp_packet.write_packet_header(2,c.data.length)+c.data;else return util.print_error("extractPublicKey - missing subkey signature"),null;return openpgp_encoding_armor(4,
|
|
|
|
@ -349,7 +350,7 @@ a.length-b);break;case 17:this.userAttributes[this.userAttributes.length]=e;b+=e
|
|
|
|
|
return this.len=b-c};this.write=function(){};this.toString=function(){for(var b=" OPENPGP Public Key\n length: "+this.len+"\n",b=b+" Revocation Signatures:\n",a=0;a<this.revocationSignatures.length;a++)b+=" "+this.revocationSignatures[a].toString();b+=" User Ids:\n";for(a=0;a<this.userIds.length;a++)b+=" "+this.userIds[a].toString();b+=" User Attributes:\n";for(a=0;a<this.userAttributes.length;a++)b+=" "+this.userAttributes[a].toString();b+=" Public Key SubKeys:\n";for(a=0;a<
|
|
|
|
|
this.subKeys.length;a++)b+=" "+this.subKeys[a].toString();return b};this.validate=function(){for(var b=0;b<this.revocationSignatures.length;b++)if(this.revocationSignatures[b].verify(this.publicKeyPacket.header+this.publicKeyPacket.data,this.publicKeyPacket))return!1;if(0!=this.subKeys.length){for(var a=!1,b=0;b<this.subKeys.length;b++)if(3==this.subKeys[b].verifyKey()){a=!0;break}if(!a)return!1}a=!1;for(b=0;b<this.userIds.length;b++)if(0==this.userIds[b].verify(this.publicKeyPacket)){a=!0;break}return!a?
|
|
|
|
|
!1:!0};this.getFingerprint=function(){return this.publicKeyPacket.getFingerprint()};this.getKeyId=function(){return this.publicKeyPacket.getKeyId()};this.verifyBasicSignatures=function(){for(var b=0;b<this.revocationSignatures.length;b++)if(this.revocationSignatures[b].verify(this.publicKeyPacket.header+this.publicKeyPacket.data,this.publicKeyPacket))return!1;if(0!=this.subKeys.length){for(var a=!1,b=0;b<this.subKeys.length;b++)if(null!=this.subKeys[b]&&3==this.subKeys[b].verifyKey()){a=!0;break}if(!a)return!1}a=
|
|
|
|
|
this.getKeyId();for(b=0;b<this.userIds.length;b++)for(var c=0;c<this.userIds[b].certificationRevocationSignatures.length;c++)if(this.userIds[b].certificationSignatures[c].getIssuer==a&&4!=this.userIds[b].certificationSignatures[c].verifyBasic(this.publicKeyPacket))return!1;return!0}}
|
|
|
|
|
this.getKeyId();for(b=0;b<this.userIds.length;b++)for(var c=0;c<this.userIds[b].certificationRevocationSignatures.length;c++)if(this.userIds[b].certificationSignatures[c].getIssuer==a&&4!=this.userIds[b].certificationSignatures[c].verifyBasic(this.publicKeyPacket))return!1;return!0};this.getSubKeyAsKey=function(b){var a=new openpgp_msg_publickey;a.userIds=this.userIds;a.userAttributes=this.userAttributes;a.publicKeyPacket=this.subKeys[b];return a}}
|
|
|
|
|
function openpgp_packet_compressed(){this.tagType=8;this.decompressedData=null;this.read_packet=function(b,a,c){this.packetLength=c;var d=a;this.type=b.charCodeAt(d++);this.compressedData=b.substring(a+1,a+c);return this};this.toString=function(){return"5.6. Compressed Data Packet (Tag 8)\n length: "+this.packetLength+"\n Compression Algorithm = "+this.type+"\n Compressed Data: Byte ["+util.hexstrdump(this.compressedData)+"]\n"};this.compress=function(b,a){this.type=b;this.decompressedData=
|
|
|
|
|
a;switch(this.type){case 0:this.compressedData=this.decompressedData;break;case 1:util.print_error("Compression algorithm ZIP [RFC1951] is not implemented.");break;case 2:util.print_error("Compression algorithm ZLIB [RFC1950] is not implemented.");break;case 3:util.print_error("Compression algorithm BZip2 [BZ2] is not implemented.");break;default:util.print_error("Compression algorithm unknown :"+this.type)}this.packetLength=this.compressedData.length+1;return this.compressedData};this.decompress=
|
|
|
|
|
function(){if(null!=this.decompressedData)return this.decompressedData;if(null==this.type)return null;switch(this.type){case 0:this.decompressedData=this.compressedData;break;case 1:util.print_info("Decompressed packet [Type 1-ZIP]: "+this.toString());var b=this.compressedData,b=s2r(b).replace(/\n/g,""),b=new JXG.Util.Unzip(JXG.Util.Base64.decodeAsArray(b));this.decompressedData=unescape(b.deflate()[0][0]);break;case 2:util.print_info("Decompressed packet [Type 2-ZLIB]: "+this.toString());if(8==this.compressedData.charCodeAt(0)%
|
|
|
|
@ -369,14 +370,14 @@ this.packetLength+"\n version:"+this.version+"\n symKeyA:"+this.symmetricK
|
|
|
|
|
b.encryptedData.decrypt(d,c):b.encryptedData.decrypt_sym(d,c)}if(3==this.tagType)return util.print_error("Symmetric encrypted sessionkey is not supported!"),null}}
|
|
|
|
|
function _openpgp_packet(){function b(a){result="";192>a?result+=String.fromCharCode(a):191<a&&8384>a?(result+=String.fromCharCode((a-192>>8)+192),result+=String.fromCharCode(a-192&255)):(result+=String.fromCharCode(255),result+=String.fromCharCode(a>>24&255),result+=String.fromCharCode(a>>16&255),result+=String.fromCharCode(a>>8&255),result+=String.fromCharCode(a&255));return result}this.encode_length=b;this.write_old_packet_header=function(a,b){var d="";256>b?(d+=String.fromCharCode(128|a<<2),d+=
|
|
|
|
|
String.fromCharCode(b)):(65536>b?(d+=String.fromCharCode(a<<2|129),d+=String.fromCharCode(b>>8)):(d+=String.fromCharCode(a<<2|130),d+=String.fromCharCode(b>>24&255),d+=String.fromCharCode(b>>16&255),d+=String.fromCharCode(b>>8&255)),d+=String.fromCharCode(b&255));return d};this.write_packet_header=function(a,c){var d;d=""+String.fromCharCode(192|a);return d+=b(c)};this.read_packet=function(a,b,d){if(null==a||a.length<=b||2>a.substring(b).length||0==(a[b].charCodeAt()&128))return util.print_error("Error during parsing. This message / key is probably not containing a valid OpenPGP format."),
|
|
|
|
|
null;var e=b,f=-1,g=-1,g=0;0!=(a[e].charCodeAt()&64)&&(g=1);var h;g?f=a[e].charCodeAt()&63:(f=(a[e].charCodeAt()&63)>>2,h=a[e].charCodeAt()&3);e++;var k=null,j=-1;if(g)if(192>a[e].charCodeAt())packet_length=a[e++].charCodeAt(),util.print_debug("1 byte length:"+packet_length);else if(192<=a[e].charCodeAt()&&224>a[e].charCodeAt())packet_length=(a[e++].charCodeAt()-192<<8)+a[e++].charCodeAt()+192,util.print_debug("2 byte length:"+packet_length);else if(223<a[e].charCodeAt()&&255>a[e].charCodeAt()){packet_length=
|
|
|
|
|
1<<(a[e++].charCodeAt()&31);util.print_debug("4 byte length:"+packet_length);j=e+packet_length;for(k=a.substring(e,e+packet_length);;)if(192>a[j].charCodeAt()){d=a[j++].charCodeAt();packet_length+=d;k+=a.substring(j,j+d);j+=d;break}else if(192<=a[j].charCodeAt()&&224>a[j].charCodeAt()){d=(a[j++].charCodeAt()-192<<8)+a[j++].charCodeAt()+192;packet_length+=d;k+=a.substring(j,j+d);j+=d;break}else if(223<a[j].charCodeAt()&&255>a[j].charCodeAt())d=1<<(a[j++].charCodeAt()&31),packet_length+=d,k+=a.substring(j,
|
|
|
|
|
j+d),j+=d;else{j++;d=a[j++].charCodeAt()<<24|a[j++].charCodeAt()<<16|a[j++].charCodeAt()<<8|a[j++].charCodeAt();k+=a.substring(j,j+d);packet_length+=d;j+=d;break}}else e++,packet_length=a[e++].charCodeAt()<<24|a[e++].charCodeAt()<<16|a[e++].charCodeAt()<<8|a[e++].charCodeAt();else switch(h){case 0:packet_length=a[e++].charCodeAt();break;case 1:packet_length=a[e++].charCodeAt()<<8|a[e++].charCodeAt();break;case 2:packet_length=a[e++].charCodeAt()<<24|a[e++].charCodeAt()<<16|a[e++].charCodeAt()<<8|
|
|
|
|
|
a[e++].charCodeAt();break;default:packet_length=d}-1==j&&(j=packet_length);null==k&&(k=a.substring(e,e+j));switch(f){case 0:break;case 1:f=new openpgp_packet_encryptedsessionkey;if(null!=f.read_pub_key_packet(k,0,packet_length))return f.headerLength=e-b,f.packetLength=j,f;break;case 2:f=new openpgp_packet_signature;if(null!=f.read_packet(k,0,packet_length))return f.headerLength=e-b,f.packetLength=j,f;break;case 3:f=new openpgp_packet_encryptedsessionkey;if(null!=f.read_symmetric_key_packet(k,0,packet_length))return f.headerLength=
|
|
|
|
|
e-b,f.packetLength=j,f;break;case 4:f=new openpgp_packet_onepasssignature;if(f.read_packet(k,0,packet_length))return f.headerLength=e-b,f.packetLength=j,f;break;case 5:f=new openpgp_packet_keymaterial;f.header=a.substring(b,e);if(null!=f.read_tag5(k,0,packet_length))return f.headerLength=e-b,f.packetLength=j,f;break;case 6:f=new openpgp_packet_keymaterial;f.header=a.substring(b,e);if(null!=f.read_tag6(k,0,packet_length))return f.headerLength=e-b,f.packetLength=j,f;break;case 7:f=new openpgp_packet_keymaterial;
|
|
|
|
|
if(null!=f.read_tag7(k,0,packet_length))return f.headerLength=e-b,f.packetLength=j,f;break;case 8:f=new openpgp_packet_compressed;if(null!=f.read_packet(k,0,packet_length))return f.headerLength=e-b,f.packetLength=j,f;break;case 9:f=new openpgp_packet_encrypteddata;if(null!=f.read_packet(k,0,packet_length))return f.headerLength=e-b,f.packetLength=j,f;break;case 10:f=new openpgp_packet_marker;if(null!=f.read_packet(k,0,packet_length))return f.headerLength=e-b,f.packetLength=j,f;break;case 11:f=new openpgp_packet_literaldata;
|
|
|
|
|
if(null!=f.read_packet(k,0,packet_length))return f.headerLength=e-b,f.header=a.substring(b,e),f.packetLength=j,f;break;case 12:break;case 13:f=new openpgp_packet_userid;if(null!=f.read_packet(k,0,packet_length))return f.headerLength=e-b,f.packetLength=j,f;break;case 14:f=new openpgp_packet_keymaterial;f.header=a.substring(b,e);if(null!=f.read_tag14(k,0,packet_length))return f.headerLength=e-b,f.packetLength=j,f;break;case 17:f=new openpgp_packet_userattribute;if(null!=f.read_packet(k,0,packet_length))return f.headerLength=
|
|
|
|
|
e-b,f.packetLength=j,f;break;case 18:f=new openpgp_packet_encryptedintegrityprotecteddata;if(null!=f.read_packet(k,0,packet_length))return f.headerLength=e-b,f.packetLength=j,f;break;case 19:f=new openpgp_packet_modificationdetectioncode;if(null!=f.read_packet(k,0,packet_length))return f.headerLength=e-b,f.packetLength=j,f;break;default:return util.print_error("openpgp.packet.js\n[ERROR] openpgp_packet: failed to parse packet @:"+e+"\nchar:'"+util.hexstrdump(a.substring(e))+"'\ninput:"+util.hexstrdump(a)),
|
|
|
|
|
null;var e=b,f=-1,g=-1,g=0;0!=(a[e].charCodeAt()&64)&&(g=1);var h;g?f=a[e].charCodeAt()&63:(f=(a[e].charCodeAt()&63)>>2,h=a[e].charCodeAt()&3);e++;var j=null,k=-1;if(g)if(192>a[e].charCodeAt())packet_length=a[e++].charCodeAt(),util.print_debug("1 byte length:"+packet_length);else if(192<=a[e].charCodeAt()&&224>a[e].charCodeAt())packet_length=(a[e++].charCodeAt()-192<<8)+a[e++].charCodeAt()+192,util.print_debug("2 byte length:"+packet_length);else if(223<a[e].charCodeAt()&&255>a[e].charCodeAt()){packet_length=
|
|
|
|
|
1<<(a[e++].charCodeAt()&31);util.print_debug("4 byte length:"+packet_length);k=e+packet_length;for(j=a.substring(e,e+packet_length);;)if(192>a[k].charCodeAt()){d=a[k++].charCodeAt();packet_length+=d;j+=a.substring(k,k+d);k+=d;break}else if(192<=a[k].charCodeAt()&&224>a[k].charCodeAt()){d=(a[k++].charCodeAt()-192<<8)+a[k++].charCodeAt()+192;packet_length+=d;j+=a.substring(k,k+d);k+=d;break}else if(223<a[k].charCodeAt()&&255>a[k].charCodeAt())d=1<<(a[k++].charCodeAt()&31),packet_length+=d,j+=a.substring(k,
|
|
|
|
|
k+d),k+=d;else{k++;d=a[k++].charCodeAt()<<24|a[k++].charCodeAt()<<16|a[k++].charCodeAt()<<8|a[k++].charCodeAt();j+=a.substring(k,k+d);packet_length+=d;k+=d;break}}else e++,packet_length=a[e++].charCodeAt()<<24|a[e++].charCodeAt()<<16|a[e++].charCodeAt()<<8|a[e++].charCodeAt();else switch(h){case 0:packet_length=a[e++].charCodeAt();break;case 1:packet_length=a[e++].charCodeAt()<<8|a[e++].charCodeAt();break;case 2:packet_length=a[e++].charCodeAt()<<24|a[e++].charCodeAt()<<16|a[e++].charCodeAt()<<8|
|
|
|
|
|
a[e++].charCodeAt();break;default:packet_length=d}-1==k&&(k=packet_length);null==j&&(j=a.substring(e,e+k));switch(f){case 0:break;case 1:f=new openpgp_packet_encryptedsessionkey;if(null!=f.read_pub_key_packet(j,0,packet_length))return f.headerLength=e-b,f.packetLength=k,f;break;case 2:f=new openpgp_packet_signature;if(null!=f.read_packet(j,0,packet_length))return f.headerLength=e-b,f.packetLength=k,f;break;case 3:f=new openpgp_packet_encryptedsessionkey;if(null!=f.read_symmetric_key_packet(j,0,packet_length))return f.headerLength=
|
|
|
|
|
e-b,f.packetLength=k,f;break;case 4:f=new openpgp_packet_onepasssignature;if(f.read_packet(j,0,packet_length))return f.headerLength=e-b,f.packetLength=k,f;break;case 5:f=new openpgp_packet_keymaterial;f.header=a.substring(b,e);if(null!=f.read_tag5(j,0,packet_length))return f.headerLength=e-b,f.packetLength=k,f;break;case 6:f=new openpgp_packet_keymaterial;f.header=a.substring(b,e);if(null!=f.read_tag6(j,0,packet_length))return f.headerLength=e-b,f.packetLength=k,f;break;case 7:f=new openpgp_packet_keymaterial;
|
|
|
|
|
if(null!=f.read_tag7(j,0,packet_length))return f.headerLength=e-b,f.packetLength=k,f;break;case 8:f=new openpgp_packet_compressed;if(null!=f.read_packet(j,0,packet_length))return f.headerLength=e-b,f.packetLength=k,f;break;case 9:f=new openpgp_packet_encrypteddata;if(null!=f.read_packet(j,0,packet_length))return f.headerLength=e-b,f.packetLength=k,f;break;case 10:f=new openpgp_packet_marker;if(null!=f.read_packet(j,0,packet_length))return f.headerLength=e-b,f.packetLength=k,f;break;case 11:f=new openpgp_packet_literaldata;
|
|
|
|
|
if(null!=f.read_packet(j,0,packet_length))return f.headerLength=e-b,f.header=a.substring(b,e),f.packetLength=k,f;break;case 12:break;case 13:f=new openpgp_packet_userid;if(null!=f.read_packet(j,0,packet_length))return f.headerLength=e-b,f.packetLength=k,f;break;case 14:f=new openpgp_packet_keymaterial;f.header=a.substring(b,e);if(null!=f.read_tag14(j,0,packet_length))return f.headerLength=e-b,f.packetLength=k,f;break;case 17:f=new openpgp_packet_userattribute;if(null!=f.read_packet(j,0,packet_length))return f.headerLength=
|
|
|
|
|
e-b,f.packetLength=k,f;break;case 18:f=new openpgp_packet_encryptedintegrityprotecteddata;if(null!=f.read_packet(j,0,packet_length))return f.headerLength=e-b,f.packetLength=k,f;break;case 19:f=new openpgp_packet_modificationdetectioncode;if(null!=f.read_packet(j,0,packet_length))return f.headerLength=e-b,f.packetLength=k,f;break;default:return util.print_error("openpgp.packet.js\n[ERROR] openpgp_packet: failed to parse packet @:"+e+"\nchar:'"+util.hexstrdump(a.substring(e))+"'\ninput:"+util.hexstrdump(a)),
|
|
|
|
|
null}}}var openpgp_packet=new _openpgp_packet;
|
|
|
|
|
function openpgp_packet_keymaterial(){this.subKeyRevocationSignature=this.subKeySignature=this.parentNode=this.checksum=this.hasUnencryptedSecretKeyData=this.encryptedMPIData=this.IVLength=this.s2kUsageConventions=this.symmetricEncryptionAlgorithm=this.publicKey=this.secMPIs=this.MPIs=this.expiration=this.version=this.creationTime=this.tagType=this.publicKeyAlgorithm=null;this.read_tag5=function(b,a,c){this.tagType=5;this.read_priv_key(b,a,c);return this};this.read_tag6=function(b,a,c){this.tagType=
|
|
|
|
|
6;this.packetLength=c;this.read_pub_key(b,a,c);return this};this.read_tag7=function(b,a,c){this.tagType=7;this.packetLength=c;return this.read_priv_key(b,a,c)};this.read_tag14=function(b,a,c){this.subKeySignature=null;this.subKeyRevocationSignature=[];this.tagType=14;this.packetLength=c;this.read_pub_key(b,a,c);return this};this.toString=function(){var b="";switch(this.tagType){case 6:b+="5.5.1.1. Public-Key Packet (Tag 6)\n length: "+this.packetLength+"\n version: "+
|
|
|
|
@ -387,24 +388,25 @@ this.subKeySignature.toString());null!=this.subKeyRevocationSignature&&(b+="subK
|
|
|
|
|
4>this.publicKeyAlgorithm?d=2:16==this.publicKeyAlgorithm?d=3:17==this.publicKeyAlgorithm&&(d=4);this.MPIs=[];for(var e=0;e<d;e++)this.MPIs[e]=new openpgp_type_mpi,null!=this.MPIs[e].read(b,c,c-a)&&!this.packetLength<c-a?c+=this.MPIs[e].packetLength:util.print_error("openpgp.packet.keymaterial.js\nerror reading MPI @:"+c);this.packetLength=c-a}else if(4==this.version){this.creationTime=new Date(1E3*(b[c++].charCodeAt()<<24|b[c++].charCodeAt()<<16|b[c++].charCodeAt()<<8|b[c++].charCodeAt()));this.publicKeyAlgorithm=
|
|
|
|
|
b[c++].charCodeAt();d=0;0<this.publicKeyAlgorithm&&4>this.publicKeyAlgorithm?d=2:16==this.publicKeyAlgorithm?d=3:17==this.publicKeyAlgorithm&&(d=4);this.MPIs=[];for(e=0;e<d;e++)this.MPIs[e]=new openpgp_type_mpi,null!=this.MPIs[e].read(b,c,c-a)&&!this.packetLength<c-a?c+=this.MPIs[e].packetLength:util.print_error("openpgp.packet.keymaterial.js\nerror reading MPI @:"+c);this.packetLength=c-a}else return null;this.data=b.substring(a,c);this.packetdata=b.substring(a,c);return this};this.read_priv_key=
|
|
|
|
|
function(b,a,c){this.publicKey=new openpgp_packet_keymaterial;if(null==this.publicKey.read_pub_key(b,a,c))return util.print_error("openpgp.packet.keymaterial.js\nFailed reading public key portion of a private key: "+b[a].charCodeAt()+" "+a+" "+c+"\n Aborting here..."),null;this.publicKey.header=openpgp_packet.write_old_packet_header(6,this.publicKey.packetLength);var d=a+this.publicKey.data.length;this.packetLength=c;this.s2kUsageConventions=b[d++].charCodeAt();if(0==this.s2kUsageConventions)this.hasUnencryptedSecretKeyData=
|
|
|
|
|
!0;if(255==this.s2kUsageConventions||254==this.s2kUsageConventions)this.symmetricEncryptionAlgorithm=b[d++].charCodeAt();if(255==this.s2kUsageConventions||254==this.s2kUsageConventions)this.s2k=new openpgp_type_s2k,this.s2k.read(b,d),d+=this.s2k.s2kLength;this.symkeylength=0;if(0!=this.s2kUsageConventions&&255!=this.s2kUsageConventions&&254!=this.s2kUsageConventions)this.symmetricEncryptionAlgorithm=this.s2kUsageConventions;if(0!=this.s2kUsageConventions){this.hasIV=!0;switch(this.symmetricEncryptionAlgorithm){case 1:return util.print_error("openpgp.packet.keymaterial.js\nsymmetric encrytryption algorithim: IDEA is not implemented"),
|
|
|
|
|
null;case 2:case 3:this.IVLength=8;break;case 4:case 7:case 8:case 9:this.IVLength=16;break;case 10:this.IVLength=32;break;default:return util.print_error("openpgp.packet.keymaterial.js\nunknown encryption algorithm for secret key :"+this.symmetricEncryptionAlgorithm),null}d++;this.IV=b.substring(d,d+this.IVLength);d+=this.IVLength}if(this.hasUnencryptedSecretKeyData){if(0<this.publicKey.publicKeyAlgorithm&&4>this.publicKey.publicKeyAlgorithm)this.secMPIs=[],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(b,
|
|
|
|
|
d,c-2-(d-a)),d+=this.secMPIs[0].packetLength,this.secMPIs[1]=new openpgp_type_mpi,this.secMPIs[1].read(b,d,c-2-(d-a)),d+=this.secMPIs[1].packetLength,this.secMPIs[2]=new openpgp_type_mpi,this.secMPIs[2].read(b,d,c-2-(d-a)),d+=this.secMPIs[2].packetLength,this.secMPIs[3]=new openpgp_type_mpi,this.secMPIs[3].read(b,d,c-2-(d-a)),d+=this.secMPIs[3].packetLength;else if(16==this.publicKey.publicKeyAlgorithm)this.secMPIs=[],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(b,d,c-2-(d-a)),d+=this.secMPIs[0].packetLength;
|
|
|
|
|
else if(17==this.publicKey.publicKeyAlgorithm)this.secMPIs=[],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(b,d,c-2-(d-a)),d+=this.secMPIs[0].packetLength;this.checksum=[];this.checksum[0]=b[d++].charCodeAt();this.checksum[1]=b[d++].charCodeAt()}else this.encryptedMPIData=b.substring(d,c);return this};this.decryptSecretMPIs=function(b){if(this.hasUnencryptedSecretKeyData)return this.secMPIs;var a=this.s2k.produce_key(b),c="";switch(this.symmetricEncryptionAlgorithm){case 1:return util.print_error("openpgp.packet.keymaterial.js\nsymmetric encryption algorithim: IDEA is not implemented"),
|
|
|
|
|
!1;case 2:c=normal_cfb_decrypt(function(a,b){return des(b,a,1,null,0)},this.IVLength,a,this.encryptedMPIData,this.IV);break;case 3:c=normal_cfb_decrypt(function(a,b){var c=new openpgp_symenc_cast5;c.setKey(b);return c.encrypt(util.str2bin(a))},this.IVLength,util.str2bin(a.substring(0,16)),this.encryptedMPIData,this.IV);break;case 4:c=normal_cfb_decrypt(function(a,b){return(new Blowfish(b)).encrypt(a)},this.IVLength,a,this.encryptedMPIData,this.IV);break;case 7:case 8:case 9:c=16;8==this.symmetricEncryptionAlgorithm&&
|
|
|
|
|
(c=24,a=this.s2k.produce_key(b,c));9==this.symmetricEncryptionAlgorithm&&(c=32,a=this.s2k.produce_key(b,c));c=normal_cfb_decrypt(function(a,b){return AESencrypt(util.str2bin(a),b)},this.IVLength,keyExpansion(a.substring(0,c)),this.encryptedMPIData,this.IV);break;case 10:return util.print_error("openpgp.packet.keymaterial.js\nKey material is encrypted with twofish: not implemented"),!1;default:return util.print_error("openpgp.packet.keymaterial.js\nunknown encryption algorithm for secret key :"+this.symmetricEncryptionAlgorithm),
|
|
|
|
|
!1}if(null==c)return util.print_error("openpgp.packet.keymaterial.js\ncleartextMPIs was null"),!1;b=c.length;if(254==this.s2kUsageConventions&&str_sha1(c.substring(0,c.length-20))==c.substring(c.length-20))b-=20;else if(254!=this.s2kUsageConventions&&util.calc_checksum(c.substring(0,c.length-2))==(c.charCodeAt(c.length-2)<<8|c.charCodeAt(c.length-1)))b-=2;else return!1;if(0<this.publicKey.publicKeyAlgorithm&&4>this.publicKey.publicKeyAlgorithm)a=0,this.secMPIs=[],this.secMPIs[0]=new openpgp_type_mpi,
|
|
|
|
|
this.secMPIs[0].read(c,0,b),a+=this.secMPIs[0].packetLength,this.secMPIs[1]=new openpgp_type_mpi,this.secMPIs[1].read(c,a,b-a),a+=this.secMPIs[1].packetLength,this.secMPIs[2]=new openpgp_type_mpi,this.secMPIs[2].read(c,a,b-a),a+=this.secMPIs[2].packetLength,this.secMPIs[3]=new openpgp_type_mpi,this.secMPIs[3].read(c,a,b-a),a+=this.secMPIs[3].packetLength;else if(16==this.publicKey.publicKeyAlgorithm)this.secMPIs=[],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(c,0,c);else if(17==this.publicKey.publicKeyAlgorithm)this.secMPIs=
|
|
|
|
|
[],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(c,0,b);return!0};this.read_nodes=function(b,a,c,d){this.parentNode=b;if(14==this.tagType){for(var b=c,e=null;a.length!=b;)if(d=a.length-b,e=openpgp_packet.read_packet(a,b,d),null==e){util.print_error("openpgp.packet.keymaterial.js\n[user_keymat_pub]parsing ends here @:"+b+" l:"+d);break}else switch(e.tagType){case 2:if(24==e.signatureType){this.subKeySignature=e;b+=e.packetLength+e.headerLength;break}else if(40==e.signatureType){this.subKeyRevocationSignature[this.subKeyRevocationSignature.length]=
|
|
|
|
|
e;b+=e.packetLength+e.headerLength;break}else util.print_error("openpgp.packet.keymaterial.js\nunknown signature:"+e.toString());default:return this.data=a,this.position=c-this.parentNode.packetLength,this.len=b-c}this.data=a;this.position=c-this.parentNode.packetLength;return this.len=b-c}if(7==this.tagType){for(b=c;a.length!=b;)if(e=openpgp_packet.read_packet(a,b,d-(b-c)),null==e){util.print_error("openpgp.packet.keymaterial.js\n[user_keymat_priv] parsing ends here @:"+b);break}else switch(e.tagType){case 2:24==
|
|
|
|
|
e.signatureType?this.subKeySignature=e:40==e.signatureType&&(this.subKeyRevocationSignature[this.subKeyRevocationSignature.length]=e);b+=e.packetLength+e.headerLength;break;default:return this.data=a,this.position=c-this.parentNode.packetLength,this.len=b-c}this.data=a;this.position=c-this.parentNode.packetLength;return this.len=b-c}util.print_error("openpgp.packet.keymaterial.js\nunknown parent node for a key material packet "+b.tagType)};this.verifyKey=function(){if(14==this.tagType){if(null==this.subKeySignature)return 0;
|
|
|
|
|
if(4==this.subKeySignature.version&&null!=this.subKeySignature.keyNeverExpires&&!this.subKeySignature.keyNeverExpires&&new Date(1E3*this.subKeySignature.keyExpirationTime+this.creationTime.getTime())<new Date)return 1;if(!this.subKeySignature.verify(String.fromCharCode(153)+this.parentNode.header.substring(1)+this.parentNode.data+String.fromCharCode(153)+this.header.substring(1)+this.packetdata,this.parentNode))return 0;for(var b=0;b<this.subKeyRevocationSignature.length;b++)if(this.getKeyId()==this.subKeyRevocationSignature[b].keyId)return 2}return 3};
|
|
|
|
|
this.getKeyId=function(){if(4==this.version)return this.getFingerprint().substring(12,20);if(3==this.version&&0<this.publicKeyAlgorithm&&4>this.publicKeyAlgorithm){var b=this.MPIs[0].substring(this.MPIs[0].mpiByteLength-8);util.print_debug("openpgp.msg.publickey read_nodes:\nV3 key ID: "+b);return b}};this.getFingerprint=function(){if(4==this.version)return tohash=String.fromCharCode(153)+String.fromCharCode(this.packetdata.length>>8&255)+String.fromCharCode(this.packetdata.length&255)+this.packetdata,
|
|
|
|
|
util.print_debug("openpgp.msg.publickey creating subkey fingerprint by hashing:"+util.hexstrdump(tohash)+"\npublickeyalgorithm: "+this.publicKeyAlgorithm),str_sha1(tohash,tohash.length);if(3==this.version&&0<this.publicKeyAlgorithm&&4>this.publicKeyAlgorithm)return MD5(this.MPIs[0].MPI)};this.write_private_key=function(b,a,c,d,e,f){this.symmetricEncryptionAlgorithm=e;e=String.fromCharCode(4);e+=f;switch(b){case 1:e+=String.fromCharCode(b);e+=a.n.toMPI();e+=a.ee.toMPI();if(c)switch(e+=String.fromCharCode(254),
|
|
|
|
|
e+=String.fromCharCode(this.symmetricEncryptionAlgorithm),e+=String.fromCharCode(3),e+=String.fromCharCode(d),b=a.d.toMPI()+a.p.toMPI()+a.q.toMPI()+a.u.toMPI(),a=str_sha1(b),util.print_debug_hexstr_dump("write_private_key sha1: ",a),f=openpgp_crypto_getRandomBytes(8),util.print_debug_hexstr_dump("write_private_key Salt: ",f),e=e+f+String.fromCharCode(96),util.print_debug("write_private_key c: 96"),c=(new openpgp_type_s2k).write(3,d,c,f,96),this.symmetricEncryptionAlgorithm){case 3:this.IVLength=8;
|
|
|
|
|
this.IV=openpgp_crypto_getRandomBytes(this.IVLength);ciphertextMPIs=normal_cfb_encrypt(function(a,b){var c=new openpgp_symenc_cast5;c.setKey(b);return c.encrypt(util.str2bin(a))},this.IVLength,util.str2bin(c.substring(0,16)),b+a,this.IV);e+=this.IV+ciphertextMPIs;break;case 7:case 8:case 9:this.IVLength=16,this.IV=openpgp_crypto_getRandomBytes(this.IVLength),ciphertextMPIs=normal_cfb_encrypt(AESencrypt,this.IVLength,c,b+a,this.IV),e+=this.IV+ciphertextMPIs}else e+=String.fromCharCode(0),e+=a.d.toMPI()+
|
|
|
|
|
a.p.toMPI()+a.q.toMPI()+a.u.toMPI(),c=util.calc_checksum(a.d.toMPI()+a.p.toMPI()+a.q.toMPI()+a.u.toMPI()),e+=String.fromCharCode(c/256)+String.fromCharCode(c%256),util.print_debug_hexstr_dump("write_private_key basic checksum: "+c);break;default:e="",util.print_error("openpgp.packet.keymaterial.js\nerror writing private key, unknown type :"+b)}c=openpgp_packet.write_packet_header(5,e.length);return{string:c+e,header:c,body:e}};this.write_public_key=function(b,a,c){var d=String.fromCharCode(4),d=d+
|
|
|
|
|
c;switch(b){case 1:d+=String.fromCharCode(1);d+=a.n.toMPI();d+=a.ee.toMPI();break;default:util.print_error("openpgp.packet.keymaterial.js\nerror writing private key, unknown type :"+b)}b=openpgp_packet.write_packet_header(6,d.length);return{string:b+d,header:b,body:d}}}
|
|
|
|
|
!0;if(255==this.s2kUsageConventions||254==this.s2kUsageConventions)this.symmetricEncryptionAlgorithm=b[d++].charCodeAt();if(255==this.s2kUsageConventions||254==this.s2kUsageConventions)this.s2k=new openpgp_type_s2k,this.s2k.read(b,d),d+=this.s2k.s2kLength;this.symkeylength=0;if(0!=this.s2kUsageConventions&&255!=this.s2kUsageConventions&&254!=this.s2kUsageConventions)this.symmetricEncryptionAlgorithm=this.s2kUsageConventions;if(0!=this.s2kUsageConventions&&1001!=this.s2k.type){this.hasIV=!0;switch(this.symmetricEncryptionAlgorithm){case 1:return util.print_error("openpgp.packet.keymaterial.js\nsymmetric encrytryption algorithim: IDEA is not implemented"),
|
|
|
|
|
null;case 2:case 3:this.IVLength=8;break;case 4:case 7:case 8:case 9:this.IVLength=16;break;case 10:this.IVLength=32;break;default:return util.print_error("openpgp.packet.keymaterial.js\nunknown encryption algorithm for secret key :"+this.symmetricEncryptionAlgorithm),null}d++;this.IV=b.substring(d,d+this.IVLength);d+=this.IVLength}if(1001==this.s2k.type)this.encryptedMPIData=this.secMPIs=null;else if(this.hasUnencryptedSecretKeyData){if(0<this.publicKey.publicKeyAlgorithm&&4>this.publicKey.publicKeyAlgorithm)this.secMPIs=
|
|
|
|
|
[],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(b,d,c-2-(d-a)),d+=this.secMPIs[0].packetLength,this.secMPIs[1]=new openpgp_type_mpi,this.secMPIs[1].read(b,d,c-2-(d-a)),d+=this.secMPIs[1].packetLength,this.secMPIs[2]=new openpgp_type_mpi,this.secMPIs[2].read(b,d,c-2-(d-a)),d+=this.secMPIs[2].packetLength,this.secMPIs[3]=new openpgp_type_mpi,this.secMPIs[3].read(b,d,c-2-(d-a)),d+=this.secMPIs[3].packetLength;else if(16==this.publicKey.publicKeyAlgorithm)this.secMPIs=[],this.secMPIs[0]=
|
|
|
|
|
new openpgp_type_mpi,this.secMPIs[0].read(b,d,c-2-(d-a)),d+=this.secMPIs[0].packetLength;else if(17==this.publicKey.publicKeyAlgorithm)this.secMPIs=[],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(b,d,c-2-(d-a)),d+=this.secMPIs[0].packetLength;this.checksum=[];this.checksum[0]=b[d++].charCodeAt();this.checksum[1]=b[d++].charCodeAt()}else this.encryptedMPIData=b.substring(d,c);return this};this.decryptSecretMPIs=function(b){if(this.hasUnencryptedSecretKeyData)return this.secMPIs;var a=
|
|
|
|
|
this.s2k.produce_key(b),c="";switch(this.symmetricEncryptionAlgorithm){case 1:return util.print_error("openpgp.packet.keymaterial.js\nsymmetric encryption algorithim: IDEA is not implemented"),!1;case 2:c=normal_cfb_decrypt(function(a,b){return des(b,a,1,null,0)},this.IVLength,a,this.encryptedMPIData,this.IV);break;case 3:c=normal_cfb_decrypt(function(a,b){var c=new openpgp_symenc_cast5;c.setKey(b);return c.encrypt(util.str2bin(a))},this.IVLength,util.str2bin(a.substring(0,16)),this.encryptedMPIData,
|
|
|
|
|
this.IV);break;case 4:c=normal_cfb_decrypt(function(a,b){return(new Blowfish(b)).encrypt(a)},this.IVLength,a,this.encryptedMPIData,this.IV);break;case 7:case 8:case 9:c=16;8==this.symmetricEncryptionAlgorithm&&(c=24,a=this.s2k.produce_key(b,c));9==this.symmetricEncryptionAlgorithm&&(c=32,a=this.s2k.produce_key(b,c));c=normal_cfb_decrypt(function(a,b){return AESencrypt(util.str2bin(a),b)},this.IVLength,keyExpansion(a.substring(0,c)),this.encryptedMPIData,this.IV);break;case 10:return util.print_error("openpgp.packet.keymaterial.js\nKey material is encrypted with twofish: not implemented"),
|
|
|
|
|
!1;default:return util.print_error("openpgp.packet.keymaterial.js\nunknown encryption algorithm for secret key :"+this.symmetricEncryptionAlgorithm),!1}if(null==c)return util.print_error("openpgp.packet.keymaterial.js\ncleartextMPIs was null"),!1;b=c.length;if(254==this.s2kUsageConventions&&str_sha1(c.substring(0,c.length-20))==c.substring(c.length-20))b-=20;else if(254!=this.s2kUsageConventions&&util.calc_checksum(c.substring(0,c.length-2))==(c.charCodeAt(c.length-2)<<8|c.charCodeAt(c.length-1)))b-=
|
|
|
|
|
2;else return!1;if(0<this.publicKey.publicKeyAlgorithm&&4>this.publicKey.publicKeyAlgorithm)a=0,this.secMPIs=[],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(c,0,b),a+=this.secMPIs[0].packetLength,this.secMPIs[1]=new openpgp_type_mpi,this.secMPIs[1].read(c,a,b-a),a+=this.secMPIs[1].packetLength,this.secMPIs[2]=new openpgp_type_mpi,this.secMPIs[2].read(c,a,b-a),a+=this.secMPIs[2].packetLength,this.secMPIs[3]=new openpgp_type_mpi,this.secMPIs[3].read(c,a,b-a),a+=this.secMPIs[3].packetLength;
|
|
|
|
|
else if(16==this.publicKey.publicKeyAlgorithm)this.secMPIs=[],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(c,0,c);else if(17==this.publicKey.publicKeyAlgorithm)this.secMPIs=[],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(c,0,b);return!0};this.read_nodes=function(b,a,c,d){this.parentNode=b;if(14==this.tagType){for(var b=c,e=null;a.length!=b;)if(d=a.length-b,e=openpgp_packet.read_packet(a,b,d),null==e){util.print_error("openpgp.packet.keymaterial.js\n[user_keymat_pub]parsing ends here @:"+
|
|
|
|
|
b+" l:"+d);break}else switch(e.tagType){case 2:if(24==e.signatureType){this.subKeySignature=e;b+=e.packetLength+e.headerLength;break}else if(40==e.signatureType){this.subKeyRevocationSignature[this.subKeyRevocationSignature.length]=e;b+=e.packetLength+e.headerLength;break}else util.print_error("openpgp.packet.keymaterial.js\nunknown signature:"+e.toString());default:return this.data=a,this.position=c-this.parentNode.packetLength,this.len=b-c}this.data=a;this.position=c-this.parentNode.packetLength;
|
|
|
|
|
return this.len=b-c}if(7==this.tagType){for(b=c;a.length!=b;)if(e=openpgp_packet.read_packet(a,b,d-(b-c)),null==e){util.print_error("openpgp.packet.keymaterial.js\n[user_keymat_priv] parsing ends here @:"+b);break}else switch(e.tagType){case 2:24==e.signatureType?this.subKeySignature=e:40==e.signatureType&&(this.subKeyRevocationSignature[this.subKeyRevocationSignature.length]=e);b+=e.packetLength+e.headerLength;break;default:return this.data=a,this.position=c-this.parentNode.packetLength,this.len=
|
|
|
|
|
b-c}this.data=a;this.position=c-this.parentNode.packetLength;return this.len=b-c}util.print_error("openpgp.packet.keymaterial.js\nunknown parent node for a key material packet "+b.tagType)};this.verifyKey=function(){if(14==this.tagType){if(null==this.subKeySignature)return 0;if(4==this.subKeySignature.version&&null!=this.subKeySignature.keyNeverExpires&&!this.subKeySignature.keyNeverExpires&&new Date(1E3*this.subKeySignature.keyExpirationTime+this.creationTime.getTime())<new Date)return 1;if(!this.subKeySignature.verify(String.fromCharCode(153)+
|
|
|
|
|
this.parentNode.header.substring(1)+this.parentNode.data+String.fromCharCode(153)+this.header.substring(1)+this.packetdata,this.parentNode))return 0;for(var b=0;b<this.subKeyRevocationSignature.length;b++)if(this.getKeyId()==this.subKeyRevocationSignature[b].keyId)return 2}return 3};this.getKeyId=function(){if(4==this.version)return this.getFingerprint().substring(12,20);if(3==this.version&&0<this.publicKeyAlgorithm&&4>this.publicKeyAlgorithm){var b=this.MPIs[0].substring(this.MPIs[0].mpiByteLength-
|
|
|
|
|
8);util.print_debug("openpgp.msg.publickey read_nodes:\nV3 key ID: "+b);return b}};this.getFingerprint=function(){if(4==this.version)return tohash=String.fromCharCode(153)+String.fromCharCode(this.packetdata.length>>8&255)+String.fromCharCode(this.packetdata.length&255)+this.packetdata,util.print_debug("openpgp.msg.publickey creating subkey fingerprint by hashing:"+util.hexstrdump(tohash)+"\npublickeyalgorithm: "+this.publicKeyAlgorithm),str_sha1(tohash,tohash.length);if(3==this.version&&0<this.publicKeyAlgorithm&&
|
|
|
|
|
4>this.publicKeyAlgorithm)return MD5(this.MPIs[0].MPI)};this.write_private_key=function(b,a,c,d,e,f){this.symmetricEncryptionAlgorithm=e;e=String.fromCharCode(4);e+=f;switch(b){case 1:e+=String.fromCharCode(b);e+=a.n.toMPI();e+=a.ee.toMPI();if(c)switch(e+=String.fromCharCode(254),e+=String.fromCharCode(this.symmetricEncryptionAlgorithm),e+=String.fromCharCode(3),e+=String.fromCharCode(d),b=a.d.toMPI()+a.p.toMPI()+a.q.toMPI()+a.u.toMPI(),a=str_sha1(b),util.print_debug_hexstr_dump("write_private_key sha1: ",
|
|
|
|
|
a),f=openpgp_crypto_getRandomBytes(8),util.print_debug_hexstr_dump("write_private_key Salt: ",f),e=e+f+String.fromCharCode(96),util.print_debug("write_private_key c: 96"),c=(new openpgp_type_s2k).write(3,d,c,f,96),this.symmetricEncryptionAlgorithm){case 3:this.IVLength=8;this.IV=openpgp_crypto_getRandomBytes(this.IVLength);ciphertextMPIs=normal_cfb_encrypt(function(a,b){var c=new openpgp_symenc_cast5;c.setKey(b);return c.encrypt(util.str2bin(a))},this.IVLength,util.str2bin(c.substring(0,16)),b+a,
|
|
|
|
|
this.IV);e+=this.IV+ciphertextMPIs;break;case 7:case 8:case 9:this.IVLength=16,this.IV=openpgp_crypto_getRandomBytes(this.IVLength),ciphertextMPIs=normal_cfb_encrypt(AESencrypt,this.IVLength,c,b+a,this.IV),e+=this.IV+ciphertextMPIs}else e+=String.fromCharCode(0),e+=a.d.toMPI()+a.p.toMPI()+a.q.toMPI()+a.u.toMPI(),c=util.calc_checksum(a.d.toMPI()+a.p.toMPI()+a.q.toMPI()+a.u.toMPI()),e+=String.fromCharCode(c/256)+String.fromCharCode(c%256),util.print_debug_hexstr_dump("write_private_key basic checksum: "+
|
|
|
|
|
c);break;default:e="",util.print_error("openpgp.packet.keymaterial.js\nerror writing private key, unknown type :"+b)}c=openpgp_packet.write_packet_header(5,e.length);return{string:c+e,header:c,body:e}};this.write_public_key=function(b,a,c){var d=String.fromCharCode(4),d=d+c;switch(b){case 1:d+=String.fromCharCode(1);d+=a.n.toMPI();d+=a.ee.toMPI();break;default:util.print_error("openpgp.packet.keymaterial.js\nerror writing private key, unknown type :"+b)}b=openpgp_packet.write_packet_header(6,d.length);
|
|
|
|
|
return{string:b+d,header:b,body:d}}}
|
|
|
|
|
function openpgp_packet_literaldata(){this.tagType=11;this.read_packet=function(b,a,c){this.packetLength=c;this.format=b[a];this.filename=b.substr(a+2,b.charCodeAt(a+1));this.date=new Date(1E3*parseInt(b.substr(a+2+b.charCodeAt(a+1),4)));this.data=b.substring(a+6+b.charCodeAt(a+1));return this};this.toString=function(){return"5.9. Literal Data Packet (Tag 11)\n length: "+this.packetLength+"\n format: "+this.format+"\n filename:"+this.filename+"\n date: "+this.date+"\n data: |"+
|
|
|
|
|
this.data+"|\n rdata: |"+this.real_data+"|\n"};this.write_packet=function(b){b=b.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n");this.filename="msg.txt";this.date=new Date;this.format="t";var a=openpgp_packet.write_packet_header(11,b.length+6+this.filename.length),a=a+this.format,a=a+String.fromCharCode(this.filename.length),a=a+this.filename,a=a+String.fromCharCode(Math.round(this.date.getTime()/1E3)>>24&255),a=a+String.fromCharCode(Math.round(this.date.getTime()/1E3)>>16&255),a=a+String.fromCharCode(Math.round(this.date.getTime()/
|
|
|
|
|
1E3)>>8&255),a=a+String.fromCharCode(Math.round(this.date.getTime()/1E3)&255);this.data=b;return a+b}}function openpgp_packet_marker(){this.tagType=10;this.read_packet=function(b,a){this.packetLength=3;return 80==b[a].charCodeAt()&&71==b[a+1].charCodeAt()&&80==b[a+2].charCodeAt()?this:null};this.toString=function(){return'5.8. Marker Packet (Obsolete Literal Packet) (Tag 10)\n packet reads: "PGP"\n'}}
|
|
|
|
@ -424,20 +426,20 @@ this.signatureTargetHashAlgorithm=a[e++].charCodeAt();f=0;switch(this.signatureT
|
|
|
|
|
b)),e+this.embeddedSignature.packetLength-b;case 100:case 101:case 102:case 103:case 104:case 105:case 106:case 107:case 108:case 109:case 110:return util.print_error("openpgp.packet.signature.js\nprivate or experimental signature subpacket type "+g+" @:"+e+" subplen:"+f+" len:"+d),f+1;default:return util.print_error("openpgp.packet.signature.js\nunknown signature subpacket type "+g+" @:"+e+" subplen:"+f+" len:"+d),f+1}return e-b};this.getIssuerKey=function(){var a=null;if(4==this.version)a=openpgp.keyring.getPublicKeysForKeyId(this.issuerKeyId);
|
|
|
|
|
else if(3==this.version)a=openpgp.keyring.getPublicKeysForKeyId(this.keyId);else return null;return 0==a.length?null:a[0]};this.getIssuer=function(){return 4==this.version?this.issuerKeyId:4==this.verions?this.keyId:null};this.write_message_signature=function(a,c,d){var e=d.privateKeyPacket.publicKey,f=d.getPreferredSignatureHashAlgorithm(),g=String.fromCharCode(4),g=g+String.fromCharCode(a),g=g+String.fromCharCode(e.publicKeyAlgorithm),g=g+String.fromCharCode(f),a=Math.round((new Date).getTime()/
|
|
|
|
|
1E3),a=b(2,""+String.fromCharCode(a>>24&255)+String.fromCharCode(a>>16&255)+String.fromCharCode(a>>8&255)+String.fromCharCode(a&255)),h=b(16,d.getKeyId()),g=g+String.fromCharCode(a.length+h.length>>8&255),g=g+String.fromCharCode(a.length+h.length&255),g=g+a+h,a=""+String.fromCharCode(4),a=a+String.fromCharCode(255),a=a+String.fromCharCode(g.length>>24),a=a+String.fromCharCode(g.length>>16&255),a=a+String.fromCharCode(g.length>>8&255),a=a+String.fromCharCode(g.length&255),h=String.fromCharCode(0),
|
|
|
|
|
h=h+String.fromCharCode(0),k=openpgp_crypto_hashData(f,c+g+a);util.print_debug("DSA Signature is calculated with:|"+c+g+a+"|\n"+util.hexstrdump(c+g+a)+"\n hash:"+util.hexstrdump(k));h+=k.charAt(0);h+=k.charAt(1);h+=openpgp_crypto_signData(f,d.privateKeyPacket.publicKey.publicKeyAlgorithm,e.MPIs,d.privateKeyPacket.secMPIs,c+g+a);return{openpgp:openpgp_packet.write_packet_header(2,(g+h).length)+g+h,hash:util.get_hashAlgorithmString(f)}};this.verify=function(a,b){var d;d=""+String.fromCharCode(this.version);
|
|
|
|
|
d+=String.fromCharCode(255);d+=String.fromCharCode(this.signatureData.length>>24);d+=String.fromCharCode(this.signatureData.length>>16&255);d+=String.fromCharCode(this.signatureData.length>>8&255);d+=String.fromCharCode(this.signatureData.length&255);switch(this.signatureType){case 0:if(4==this.version)this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,a.substring(i)+this.signatureData+d);break;case 1:if(4==this.version){this.verified=
|
|
|
|
|
openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,a+this.signatureData+d);break}break;case 2:if(3==this.version){this.verified=!1;break}this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,this.signatureData+d);break;case 16:case 17:case 18:case 19:case 48:this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.MPIs,a+this.signatureData+
|
|
|
|
|
d);break;case 24:if(3==this.version){this.verified=!1;break}this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.MPIs,a+this.signatureData+d);break;case 25:case 31:case 32:case 40:this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.MPIs,a+this.signatureData+d);break;default:util.print_error("openpgp.packet.signature.js\nsignature verification for type"+this.signatureType+" not implemented")}return this.verified};
|
|
|
|
|
this.read_packet=function(a,b,d){this.data=a.substring(b,b+d);if(0>d)return util.print_debug("openpgp.packet.signature.js\nopenpgp_packet_signature read_packet length < 0 @:"+b),null;var e=b;this.packetLength=d;this.version=a[e++].charCodeAt();switch(this.version){case 3:5!=a[e++].charCodeAt()&&util.print_debug("openpgp.packet.signature.js\ninvalid One-octet length of following hashed material. MUST be 5. @:"+(e-1));this.signatureType=a[e++].charCodeAt();this.creationTime=new Date(1E3*(a[e++].charCodeAt()<<
|
|
|
|
|
24|a[e++].charCodeAt()<<16|a[e++].charCodeAt()<<8|a[e++].charCodeAt()));this.signatureData=a.substring(b,e);this.keyId=a.substring(e,e+8);e+=8;this.publicKeyAlgorithm=a[e++].charCodeAt();this.hashAlgorithm=a[e++].charCodeAt();this.signedHashValue=a[e++].charCodeAt()<<8|a[e++].charCodeAt();d=0;0<this.publicKeyAlgorithm&&4>this.publicKeyAlgorithm?d=1:17==this.publicKeyAlgorithm&&(d=2);this.MPIs=[];for(var f=0;f<d;f++)this.MPIs[f]=new openpgp_type_mpi,null!=this.MPIs[f].read(a,e,e-b)&&!this.packetLength<
|
|
|
|
|
e-b?e+=this.MPIs[f].packetLength:util.print_error("signature contains invalid MPI @:"+e);break;case 4:this.signatureType=a[e++].charCodeAt();this.publicKeyAlgorithm=a[e++].charCodeAt();this.hashAlgorithm=a[e++].charCodeAt();f=(a[e++].charCodeAt()<<8)+a[e++].charCodeAt();for(d=0;f!=d;)f<d&&util.print_debug("openpgp.packet.signature.js\nhashed missed something: "+e+" c:"+f+" l:"+d),d+=this._raw_read_signature_sub_packet(a,e+d,f-d);e+=f;this.signatureData=a.substring(b,e);f=(a[e++].charCodeAt()<<8)+
|
|
|
|
|
a[e++].charCodeAt();for(d=0;f!=d;)f<d&&util.print_debug("openpgp.packet.signature.js\nmissed something: "+d+" c:"+f+" l:"+d),d+=this._raw_read_signature_sub_packet(a,e+d,f-d);e+=f;this.signedHashValue=a[e++].charCodeAt()<<8|a[e++].charCodeAt();d=0;0<this.publicKeyAlgorithm&&4>this.publicKeyAlgorithm?d=1:17==this.publicKeyAlgorithm&&(d=2);this.MPIs=[];for(f=0;f<d;f++)this.MPIs[f]=new openpgp_type_mpi,null!=this.MPIs[f].read(a,e,e-b)&&!this.packetLength<e-b?e+=this.MPIs[f].packetLength:util.print_error("signature contains invalid MPI @:"+
|
|
|
|
|
e);break;default:util.print_error("openpgp.packet.signature.js\nunknown signature packet version"+this.version)}return this};this.toString=function(){for(var a=3==this.version?"5.2. Signature Packet (Tag 2)\nPacket Length: :"+this.packetLength+"\nPacket version: :"+this.version+"\nOne-octet signature type :"+this.signatureType+"\nFour-octet creation time. :"+this.creationTime+"\nEight-octet Key ID of signer. :"+util.hexidump(this.keyId)+
|
|
|
|
|
"\nOne-octet public-key algorithm. :"+this.publicKeyAlgorithm+"\nOne-octet hash algorithm. :"+this.hashAlgorithm+"\nTwo-octet field holding left\n 16 bits of signed hash value. :"+this.signedHashValue+"\n":"5.2. Signature Packet (Tag 2)\nPacket Length: :"+this.packetLength+"\nPacket version: :"+this.version+"\nOne-octet signature type :"+this.signatureType+"\nOne-octet public-key algorithm. :"+this.publicKeyAlgorithm+"\nOne-octet hash algorithm. :"+
|
|
|
|
|
this.hashAlgorithm+"\nTwo-octet field holding left\n 16 bits of signed hash value. :"+this.signedHashValue+"\nSignature Creation Time :"+this.creationTime+"\nSignature Expiration Time :"+this.signatureExpirationTime+"\nSignature Never Expires :"+this.signatureNeverExpires+"\nExportable Certification :"+this.exportable+"\nTrust Signature level: :"+this.trustLevel+" amount"+this.trustAmount+"\nRegular Expression :"+this.regular_expression+
|
|
|
|
|
"\nRevocable :"+this.revocable+"\nKey Expiration Time :"+this.keyExpirationTime+" "+this.keyNeverExpires+"\nPreferred Symmetric Algorithms :"+this.preferredSymmetricAlgorithms+"\nRevocation Key\n ( 1 octet of class, :"+this.revocationKeyClass+"\n 1 octet of public-key ID, :"+this.revocationKeyAlgorithm+"\n 20 octets of fingerprint) :"+this.revocationKeyFingerprint+"\nIssuer :"+util.hexstrdump(this.issuerKeyId)+
|
|
|
|
|
"\nPreferred Hash Algorithms :"+this.preferredHashAlgorithms+"\nPreferred Compression Alg. :"+this.preferredCompressionAlgorithms+"\nKey Server Preferences :"+this.keyServerPreferences+"\nPreferred Key Server :"+this.preferredKeyServer+"\nPrimary User ID :"+this.isPrimaryUserID+"\nPolicy URI :"+this.policyURI+"\nKey Flags :"+this.keyFlags+"\nSigner's User ID :"+this.signersUserId+
|
|
|
|
|
"\nNotation :"+this.notationName+" = "+this.notationValue+"\nReason for Revocation\n Flag :"+this.reasonForRevocationFlag+"\n Reason :"+this.reasonForRevocationString+"\nMPI:\n",b=0;b<this.MPIs.length;b++)a+=this.MPIs[b].toString();return a}}
|
|
|
|
|
h=h+String.fromCharCode(0),j=openpgp_crypto_hashData(f,c+g+a);util.print_debug("DSA Signature is calculated with:|"+c+g+a+"|\n"+util.hexstrdump(c+g+a)+"\n hash:"+util.hexstrdump(j));h+=j.charAt(0);h+=j.charAt(1);h+=openpgp_crypto_signData(f,d.privateKeyPacket.publicKey.publicKeyAlgorithm,e.MPIs,d.privateKeyPacket.secMPIs,c+g+a);return{openpgp:openpgp_packet.write_packet_header(2,(g+h).length)+g+h,hash:util.get_hashAlgorithmString(f)}};this.verify=function(a,b){var d;d=""+String.fromCharCode(this.version);
|
|
|
|
|
d+=String.fromCharCode(255);d+=String.fromCharCode(this.signatureData.length>>24);d+=String.fromCharCode(this.signatureData.length>>16&255);d+=String.fromCharCode(this.signatureData.length>>8&255);d+=String.fromCharCode(this.signatureData.length&255);switch(this.signatureType){case 0:if(4==this.version)this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,a+this.signatureData+d);break;case 1:if(4==this.version){this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,
|
|
|
|
|
this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,a+this.signatureData+d);break}break;case 2:if(3==this.version){this.verified=!1;break}this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,this.signatureData+d);break;case 16:case 17:case 18:case 19:case 48:this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.MPIs,a+this.signatureData+d);break;case 24:if(3==this.version){this.verified=
|
|
|
|
|
!1;break}this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.MPIs,a+this.signatureData+d);break;case 25:case 31:case 32:case 40:this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.MPIs,a+this.signatureData+d);break;default:util.print_error("openpgp.packet.signature.js\nsignature verification for type"+this.signatureType+" not implemented")}return this.verified};this.read_packet=function(a,b,d){this.data=
|
|
|
|
|
a.substring(b,b+d);if(0>d)return util.print_debug("openpgp.packet.signature.js\nopenpgp_packet_signature read_packet length < 0 @:"+b),null;var e=b;this.packetLength=d;this.version=a[e++].charCodeAt();switch(this.version){case 3:5!=a[e++].charCodeAt()&&util.print_debug("openpgp.packet.signature.js\ninvalid One-octet length of following hashed material. MUST be 5. @:"+(e-1));this.signatureType=a[e++].charCodeAt();this.creationTime=new Date(1E3*(a[e++].charCodeAt()<<24|a[e++].charCodeAt()<<16|a[e++].charCodeAt()<<
|
|
|
|
|
8|a[e++].charCodeAt()));this.signatureData=a.substring(b,e);this.keyId=a.substring(e,e+8);e+=8;this.publicKeyAlgorithm=a[e++].charCodeAt();this.hashAlgorithm=a[e++].charCodeAt();this.signedHashValue=a[e++].charCodeAt()<<8|a[e++].charCodeAt();d=0;0<this.publicKeyAlgorithm&&4>this.publicKeyAlgorithm?d=1:17==this.publicKeyAlgorithm&&(d=2);this.MPIs=[];for(var f=0;f<d;f++)this.MPIs[f]=new openpgp_type_mpi,null!=this.MPIs[f].read(a,e,e-b)&&!this.packetLength<e-b?e+=this.MPIs[f].packetLength:util.print_error("signature contains invalid MPI @:"+
|
|
|
|
|
e);break;case 4:this.signatureType=a[e++].charCodeAt();this.publicKeyAlgorithm=a[e++].charCodeAt();this.hashAlgorithm=a[e++].charCodeAt();f=(a[e++].charCodeAt()<<8)+a[e++].charCodeAt();for(d=0;f!=d;)f<d&&util.print_debug("openpgp.packet.signature.js\nhashed missed something: "+e+" c:"+f+" l:"+d),d+=this._raw_read_signature_sub_packet(a,e+d,f-d);e+=f;this.signatureData=a.substring(b,e);f=(a[e++].charCodeAt()<<8)+a[e++].charCodeAt();for(d=0;f!=d;)f<d&&util.print_debug("openpgp.packet.signature.js\nmissed something: "+
|
|
|
|
|
d+" c:"+f+" l:"+d),d+=this._raw_read_signature_sub_packet(a,e+d,f-d);e+=f;this.signedHashValue=a[e++].charCodeAt()<<8|a[e++].charCodeAt();d=0;0<this.publicKeyAlgorithm&&4>this.publicKeyAlgorithm?d=1:17==this.publicKeyAlgorithm&&(d=2);this.MPIs=[];for(f=0;f<d;f++)this.MPIs[f]=new openpgp_type_mpi,null!=this.MPIs[f].read(a,e,e-b)&&!this.packetLength<e-b?e+=this.MPIs[f].packetLength:util.print_error("signature contains invalid MPI @:"+e);break;default:util.print_error("openpgp.packet.signature.js\nunknown signature packet version"+
|
|
|
|
|
this.version)}return this};this.toString=function(){for(var a=3==this.version?"5.2. Signature Packet (Tag 2)\nPacket Length: :"+this.packetLength+"\nPacket version: :"+this.version+"\nOne-octet signature type :"+this.signatureType+"\nFour-octet creation time. :"+this.creationTime+"\nEight-octet Key ID of signer. :"+util.hexidump(this.keyId)+"\nOne-octet public-key algorithm. :"+this.publicKeyAlgorithm+"\nOne-octet hash algorithm. :"+
|
|
|
|
|
this.hashAlgorithm+"\nTwo-octet field holding left\n 16 bits of signed hash value. :"+this.signedHashValue+"\n":"5.2. Signature Packet (Tag 2)\nPacket Length: :"+this.packetLength+"\nPacket version: :"+this.version+"\nOne-octet signature type :"+this.signatureType+"\nOne-octet public-key algorithm. :"+this.publicKeyAlgorithm+"\nOne-octet hash algorithm. :"+this.hashAlgorithm+"\nTwo-octet field holding left\n 16 bits of signed hash value. :"+
|
|
|
|
|
this.signedHashValue+"\nSignature Creation Time :"+this.creationTime+"\nSignature Expiration Time :"+this.signatureExpirationTime+"\nSignature Never Expires :"+this.signatureNeverExpires+"\nExportable Certification :"+this.exportable+"\nTrust Signature level: :"+this.trustLevel+" amount"+this.trustAmount+"\nRegular Expression :"+this.regular_expression+"\nRevocable :"+this.revocable+"\nKey Expiration Time :"+
|
|
|
|
|
this.keyExpirationTime+" "+this.keyNeverExpires+"\nPreferred Symmetric Algorithms :"+this.preferredSymmetricAlgorithms+"\nRevocation Key\n ( 1 octet of class, :"+this.revocationKeyClass+"\n 1 octet of public-key ID, :"+this.revocationKeyAlgorithm+"\n 20 octets of fingerprint) :"+this.revocationKeyFingerprint+"\nIssuer :"+util.hexstrdump(this.issuerKeyId)+"\nPreferred Hash Algorithms :"+this.preferredHashAlgorithms+"\nPreferred Compression Alg. :"+
|
|
|
|
|
this.preferredCompressionAlgorithms+"\nKey Server Preferences :"+this.keyServerPreferences+"\nPreferred Key Server :"+this.preferredKeyServer+"\nPrimary User ID :"+this.isPrimaryUserID+"\nPolicy URI :"+this.policyURI+"\nKey Flags :"+this.keyFlags+"\nSigner's User ID :"+this.signersUserId+"\nNotation :"+this.notationName+" = "+this.notationValue+"\nReason for Revocation\n Flag :"+
|
|
|
|
|
this.reasonForRevocationFlag+"\n Reason :"+this.reasonForRevocationString+"\nMPI:\n",b=0;b<this.MPIs.length;b++)a+=this.MPIs[b].toString();return a}}
|
|
|
|
|
function openpgp_packet_userattribute(){this.tagType=17;this.certificationSignatures=[];this.certificationRevocationSignatures=[];this.revocationSignatures=[];this.parentNode=null;this.read_packet=function(b,a,c){var d=0;this.packetLength=c;this.userattributes=[];for(var e=a;c!=d;){var f=0;192>b[e].charCodeAt()?(packet_length=b[e++].charCodeAt(),f=1):192<=b[e].charCodeAt()&&224>b[e].charCodeAt()?(packet_length=(b[e++].charCodeAt()-192<<8)+b[e++].charCodeAt()+192,f=2):223<b[e].charCodeAt()&&255>b[e].charCodeAt()?
|
|
|
|
|
(packet_length=1<<(b[e++].charCodeAt()&31),f=1):(f=5,e++,packet_length=b[e++].charCodeAt()<<24|b[e++].charCodeAt()<<16|b[e++].charCodeAt()<<8|b[e++].charCodeAt());b[e++].charCodeAt();packet_length--;f++;this.userattributes[0]=[];this.userattributes[0]=b.substring(e,e+packet_length);e+=packet_length;d+=f+packet_length}this.packetLength=e-a;return this};this.read_nodes=function(b,a,c,d){this.parentNode=b;for(var e=c,f=d;a.length!=e;){var g=openpgp_packet.read_packet(a,e,f);if(null==g){util.print_error("openpgp.packet.userattribute.js\n[user_attr] parsing ends here @:"+
|
|
|
|
|
e+" l:"+f);break}else switch(g.tagType){case 2:15<g.signatureType&&20>g.signatureType?this.certificationSignatures[this.certificationSignatures.length]=g:32==g.signatureType&&(this.certificationRevocationSignatures[this.certificationRevocationSignatures.length]=g);e+=g.packetLength+g.headerLength;f=d-(e-c);break;default:return this.data=a,this.position=c-b.packetLength,this.len=e-c}}this.data=a;this.position=c-b.packetLength;return this.len=e-c};this.toString=function(){for(var b="5.12. User Attribute Packet (Tag 17)\n AttributePackets: (count = "+
|
|
|
|
@ -455,9 +457,10 @@ default:return this.data=a,this.position=c-b.packetLength,this.len=e-c-(g.header
|
|
|
|
|
g:48==g.signatureType&&(this.certificationRevocationSignatures[this.certificationRevocationSignatures.length]=g);default:return this.data=a,this.position=c-b.packetLength,this.len=e-c-(g.headerLength+g.packetLength)}}else util.print_error("unknown parent node for a userId packet "+b.tagType)}}function openpgp_type_keyid(){this.read_packet=function(b,a){this.bytes=b.substring(a,a+8);return this};this.toString=function(){return util.hexstrdump(this.bytes)}}
|
|
|
|
|
function openpgp_type_mpi(){this.data=this.mpiByteLength=this.mpiBitLength=this.MPI=null;this.read=function(b,a){var c=a;this.mpiBitLength=b[c++].charCodeAt()<<8|b[c++].charCodeAt();this.mpiByteLength=(this.mpiBitLength-this.mpiBitLength%8)/8;0!=this.mpiBitLength%8&&this.mpiByteLength++;this.MPI=b.substring(c,c+this.mpiByteLength);this.data=b.substring(a,a+2+this.mpiByteLength);this.packetLength=this.mpiByteLength+2;return this};this.toBigInteger=function(){return new BigInteger(util.hexstrdump(this.MPI),
|
|
|
|
|
16)};this.toString=function(){var b=" MPI("+this.mpiBitLength+"b/"+this.mpiByteLength+"B) : 0x",b=b+util.hexstrdump(this.MPI);return b+"\n"};this.create=function(b){this.MPI=b;var a=8*(b.length-1),c;a:for(var d=b.charCodeAt(0),e=0;9>e;e++)if(0==d>>e){c=e;break a}this.mpiBitLength=a+c;this.mpiByteLength=b.length;return this};this.toBin=function(){var b=String.fromCharCode(this.mpiBitLength>>8&255),b=b+String.fromCharCode(this.mpiBitLength&255);return b+=this.MPI};this.getByteLength=function(){return this.mpiByteLength}}
|
|
|
|
|
function openpgp_type_s2k(){this.read=function(b,a){var c=a;this.type=b[c++].charCodeAt();switch(this.type){case 0:this.hashAlgorithm=b[c++].charCodeAt();this.s2kLength=1;break;case 1:this.hashAlgorithm=b[c++].charCodeAt();this.saltValue=b.substring(c,c+8);this.s2kLength=9;break;case 3:this.hashAlgorithm=b[c++].charCodeAt();this.saltValue=b.substring(c,c+8);c+=8;this.EXPBIAS=6;c=b[c++].charCodeAt();this.count=16+(c&15)<<(c>>4)+this.EXPBIAS;this.s2kLength=10;break;default:util.print_error("unknown s2k type! "+
|
|
|
|
|
this.type)}return this};this.write=function(b,a,c,d,e){this.type=b;if(3==this.type)this.saltValue=d,this.hashAlgorithm=a,this.count=16+(e&15)<<(e>>4)+6,this.s2kLength=10;return this.produce_key(c)};this.produce_key=function(b,a){if(0==this.type)return openpgp_crypto_hashData(this.hashAlgorithm,b);if(1==this.type)return openpgp_crypto_hashData(this.hashAlgorithm,this.saltValue+b);if(3==this.type){var c=[];for(c[0]=this.saltValue+b;c.length*(this.saltValue+b).length<this.count;)c.push(this.saltValue+
|
|
|
|
|
b);c=c.join("");c.length>this.count&&(c=c.substr(0,this.count));return a&&(24==a||32==a)?openpgp_crypto_hashData(this.hashAlgorithm,c)+openpgp_crypto_hashData(this.hashAlgorithm,String.fromCharCode(0)+c):openpgp_crypto_hashData(this.hashAlgorithm,c)}return null}}
|
|
|
|
|
function openpgp_type_s2k(){this.read=function(b,a){var c=a;this.type=b[c++].charCodeAt();switch(this.type){case 0:this.hashAlgorithm=b[c++].charCodeAt();this.s2kLength=1;break;case 1:this.hashAlgorithm=b[c++].charCodeAt();this.saltValue=b.substring(c,c+8);this.s2kLength=9;break;case 3:this.hashAlgorithm=b[c++].charCodeAt();this.saltValue=b.substring(c,c+8);c+=8;this.EXPBIAS=6;c=b[c++].charCodeAt();this.count=16+(c&15)<<(c>>4)+this.EXPBIAS;this.s2kLength=10;break;case 101:"GNU"==b.substring(c+1,c+
|
|
|
|
|
4)?(this.hashAlgorithm=b[c++].charCodeAt(),c+=3,c=1E3+b[c++].charCodeAt(),1001==c?(this.type=c,this.s2kLength=5):util.print_error("unknown s2k gnu protection mode! "+this.type)):util.print_error("unknown s2k type! "+this.type);break;default:util.print_error("unknown s2k type! "+this.type)}return this};this.write=function(b,a,c,d,e){this.type=b;if(3==this.type)this.saltValue=d,this.hashAlgorithm=a,this.count=16+(e&15)<<(e>>4)+6,this.s2kLength=10;return this.produce_key(c)};this.produce_key=function(b,
|
|
|
|
|
a){if(0==this.type)return openpgp_crypto_hashData(this.hashAlgorithm,b);if(1==this.type)return openpgp_crypto_hashData(this.hashAlgorithm,this.saltValue+b);if(3==this.type){var c=[];for(c[0]=this.saltValue+b;c.length*(this.saltValue+b).length<this.count;)c.push(this.saltValue+b);c=c.join("");c.length>this.count&&(c=c.substr(0,this.count));return a&&(24==a||32==a)?openpgp_crypto_hashData(this.hashAlgorithm,c)+openpgp_crypto_hashData(this.hashAlgorithm,String.fromCharCode(0)+c):openpgp_crypto_hashData(this.hashAlgorithm,
|
|
|
|
|
c)}return null}}
|
|
|
|
|
var Util=function(){this.emailRegEx=/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;this.hexdump=function(b){for(var a=[],c=b.length,d=0,e,f=0;d<c;){for(e=b.charCodeAt(d++).toString(16);2>e.length;)e="0"+e;a.push(" "+e);f++;0==f%32&&a.push("\n ")}return a.join("")};this.hexstrdump=function(b){if(null==b)return"";for(var a=[],c=b.length,d=0,e;d<c;){for(e=b[d++].charCodeAt().toString(16);2>e.length;)e=
|
|
|
|
|
"0"+e;a.push(""+e)}return a.join("")};this.hex2bin=function(b){for(var a="",c=0;c<b.length;c+=2)a+=String.fromCharCode(parseInt(b.substr(c,2),16));return a};this.hexidump=function(b){for(var a=[],c=b.length,d=0,e;d<c;){for(e=b[d++].toString(16);2>e.length;)e="0"+e;a.push(""+e)}return a.join("")};this.str2bin=function(b){for(var a=[],c=0;c<b.length;c++)a[c]=b.charCodeAt(c);return a};this.bin2str=function(b){for(var a=[],c=0;c<b.length;c++)a.push(String.fromCharCode(b[c]));return a.join("")};this.str2Uint8Array=
|
|
|
|
|
function(b){for(var a=new Uint8Array(new ArrayBuffer(b.length)),c=0;c<b.length;c++)a[c]=b.charCodeAt(c);return a};this.Uint8Array2str=function(b){var a=[];for(n=0;n<b.length;n++)a[n]=String.fromCharCode(b[n]);return a.join("")};this.calc_checksum=function(b){for(var a={s:0,add:function(a){this.s=(this.s+a)%65536}},c=0;c<b.length;c++)a.add(b.charCodeAt(c));return a.s};this.print_debug=function(b){openpgp.config.debug&&(b=openpgp_encoding_html_encode(b),showMessages('<tt><p style="background-color: #ffffff; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;">'+
|
|
|
|
|