├── .project ├── README.md ├── js ├── crypto │ ├── sm2-1.0.js │ ├── sm3-1.0.js │ └── sm4-1.0.js ├── ext │ ├── ec-patch.js │ ├── ec.js │ ├── jsbn.js │ ├── jsbn2.js │ ├── prng4.js │ └── rng.js └── utils │ ├── byteUtil.js │ ├── core.js │ ├── hex.js │ └── jquery-3.3.1.min.js ├── sm2Test.html ├── sm3Test.html └── sm4Test.html /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | gmjs 4 | Create By HBuilder 5 | 6 | 7 | 8 | 9 | com.aptana.ide.core.unifiedBuilder 10 | 11 | 12 | 13 | 14 | 15 | com.aptana.projects.webnature 16 | 17 | 18 | 19 | 1555394216609 20 | 21 | 10 22 | 23 | org.eclipse.ui.ide.orFilterMatcher 24 | 25 | 26 | org.eclipse.ui.ide.multiFilter 27 | 1.0-projectRelativePath-matches-false-false-bin 28 | 29 | 30 | org.eclipse.ui.ide.multiFilter 31 | 1.0-projectRelativePath-matches-false-false-setting 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gmjs 2 | js版国密算法,包括sm2/sm3/sm4算法 3 | 4 | 注意:加密前的数据和解密后的数据,字符编码要保持一致,否则会有问题,如:加密前的数据是utf8字符集,那解密后的数据重新编码也要使用utf8字符集才能正确还原数据 5 | -------------------------------------------------------------------------------- /js/crypto/sm2-1.0.js: -------------------------------------------------------------------------------- 1 | /* 2 | * sm2-1.0.js 3 | * 4 | * Copyright (c) 2019 RuXing Liang 5 | */ 6 | /** 7 | * @name sm2-1.0.js 8 | * @author RuXing Liang 9 | * @version 1.0.0 (2019-04-16) 10 | */ 11 | 12 | var debug = false; 13 | //国密推荐曲线 14 | var sm2_ecParams = { 15 | "p":"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF", 16 | "a":"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC", 17 | "b":"28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93", 18 | "n":"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123", 19 | "gx":"32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7", 20 | "gy":"BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0", 21 | "keylen":256 22 | }; 23 | 24 | function SM2(){ 25 | 26 | this.ecc_p = new BigInteger(sm2_ecParams['p'],16); 27 | this.ecc_a = new BigInteger(sm2_ecParams['a'],16); 28 | this.ecc_b = new BigInteger(sm2_ecParams['b'],16); 29 | this.ecc_n = new BigInteger(sm2_ecParams['n'],16); 30 | this.ecc_gx = new BigInteger(sm2_ecParams['gx'],16); 31 | this.ecc_gy = new BigInteger(sm2_ecParams['gy'],16); 32 | this.rng = new SecureRandom(); 33 | 34 | this.ecCurve = new ECCurveFp(this.ecc_p, this.ecc_a, this.ecc_b); 35 | this.ecPointG = ECPointFp.decodeFromHex(this.ecCurve,"04"+sm2_ecParams['gx']+sm2_ecParams['gy']); 36 | if(debug == true){ 37 | console.log("ax1="+this.ecCurve.getA().toBigInteger().toString(16)); 38 | console.log("by1="+this.ecCurve.getB().toBigInteger().toString(16)); 39 | console.log("gx1="+this.ecPointG.getX().toBigInteger().toString(16)); 40 | console.log("gy1="+this.ecPointG.getY().toBigInteger().toString(16)); 41 | } 42 | } 43 | 44 | SM2.prototype = { 45 | getBigRandom:function(limit) { 46 | return new BigInteger(limit.bitLength(), this.rng) 47 | .mod(limit.subtract(BigInteger.ONE)) 48 | .add(BigInteger.ONE) 49 | ; 50 | }, 51 | generateKeyPairHex:function(){ 52 | var key = this.generateKeyPairBigInteger(); 53 | var biX = key['pubkey'].getX().toBigInteger(); 54 | var biY = key['pubkey'].getY().toBigInteger(); 55 | 56 | var charlen = sm2_ecParams['keylen'] / 4; 57 | var hPrv = ("0000000000" + key['privkey'].toString(16)).slice(- charlen); 58 | var hX = ("0000000000" + biX.toString(16)).slice(- charlen); 59 | var hY = ("0000000000" + biY.toString(16)).slice(- charlen); 60 | var hPub = "04" + hX + hY; 61 | 62 | return {'privkeyhex': hPrv, 'pubkeyhex': hPub}; 63 | }, 64 | generateKeyPairBigInteger:function(){ 65 | var biN = this.ecc_n; 66 | var biPrv = null; 67 | var epPub = null; 68 | while(true){ 69 | do 70 | { 71 | biPrv = this.getBigRandom(biN); 72 | } 73 | while (biPrv.equals(BigInteger.ZERO) || biPrv.compareTo(biN) >= 0 || biPrv.bitLength() < 249); 74 | 75 | epPub = this.ecPointG.multiply(biPrv); 76 | if(epPub.getX().toBigInteger().bitLength() >= 249 && epPub.getY().toBigInteger().bitLength() >= 249){ 77 | 78 | break; 79 | } 80 | } 81 | return {'privkey': biPrv, "pubkey":epPub}; 82 | }, 83 | formartXY:function(bg,needLength) { 84 | 85 | var tmp = new Array(needLength); 86 | for(var i = 0;i needLength) { 95 | arrayCopy(bgByte, bgByte.length - needLength, tmp, 0, needLength); 96 | }else if(bgByte.length == needLength) { 97 | tmp = bgByte; 98 | }else { 99 | arrayCopy(bgByte, 0, tmp, needLength - bgByte.length, bgByte.length); 100 | } 101 | 102 | return tmp; 103 | }, 104 | kdf:function(xy,data) { 105 | 106 | // int ct = 1; 107 | // var loop = data.length%32!=0 ? (data.length/32+1):data.length/32; 108 | var loop = Math.ceil(data.length/32);//向上取整 109 | var sm3; 110 | var hash = new Array(32); 111 | 112 | for(var i = 0;i>>(32-9)))^(x<<17|(x>>>(32-17))); 75 | }, 76 | p1:function(x) { 77 | //这里的公式是:对于一个二进制有n位的数字循环左移(循环右移)m位, 78 | //可以将此数字左移(无符号右移)m位的结果与此数字 无符号 右移(左移)n-m位的结果进行或操作。 79 | return x^(x<<15|(x>>>(32-15)))^(x<<23|(x>>>(32-23))); 80 | }, 81 | 82 | 83 | /** 84 | * 循环左移 85 | */ 86 | cycleLeft:function(x,moveLen) { 87 | return x<>>(32-moveLen)); 88 | }, 89 | 90 | 91 | 92 | /** 93 | * 消息填充函数 94 | * @param data 95 | * @return 96 | */ 97 | padding:function(data) { 98 | var k = 0; 99 | var len = data.length; 100 | var padding; 101 | 102 | k = 64 - (len + 1 + 8)%64; 103 | if(k>=64) { 104 | k = 0; 105 | } 106 | padding = new Array(k+1+len+8); 107 | padding[len] = 1<<7; 108 | 109 | 110 | arrayCopy(data, 0, padding, 0, len); 111 | arrayCopy(longToByte(this.totalLen<<3), 0, padding, len+k+1, 8); 112 | 113 | return padding; 114 | }, 115 | 116 | /** 117 | * 对数据进行分组迭代,每64个字节迭代一次 118 | *
1、对消息进行分组,由于是int类型,则每16个分一组,对每一组再调用{@link #expand}进行拓展 119 | *
2、使用上一轮的迭代结果V,调用{@link #cf}进行本轮迭代 120 | *
3、最后一轮迭代结果复制进缓冲区vbuf 121 | * @param message 122 | */ 123 | iterate:function(message) { 124 | var len = message.length; 125 | var n = parseInt(len/16); 126 | var v,b; 127 | var ep; 128 | 129 | v = this.vbuf; 130 | b = new Array(16); 131 | 132 | for(var i = 0;i>>(32-13))) ^ (bint<<23|(bint>>>(32-23))); 72 | return rk; 73 | }, 74 | one_encrypt:function(rk, data){ 75 | var x = new Array(36); 76 | x[0] = byteToInt(data, 0); 77 | x[1] = byteToInt(data, 4); 78 | x[2] = byteToInt(data, 8); 79 | x[3] = byteToInt(data, 12); 80 | for(var i = 0;i < 32;i++) 81 | { 82 | x[(i + 4)] = x[i] ^ this.T0(x[(i + 1)]^x[(i + 2)]^x[(i + 3)]^rk[i]); 83 | } 84 | var tmpx = new Array(4); 85 | for(var i = 35;i >= 32;i--){ 86 | tmpx[35-i] = x[i]; 87 | } 88 | var xbyte = intArrayToByteArray(tmpx); 89 | 90 | return xbyte; 91 | }, 92 | T0:function(ta){ 93 | var a = intToByte(ta); 94 | var b = new Array(4); 95 | b[0] = this.sbox[a[0] & 0xFF]; 96 | b[1] = this.sbox[a[1] & 0xFF]; 97 | b[2] = this.sbox[a[2] & 0xFF]; 98 | b[3] = this.sbox[a[3] & 0xFF]; 99 | var bint = byteToInt(b,0); 100 | var c = bint ^ (bint<<2|(bint>>>(32-2))) ^ (bint<<10|(bint>>>(32-10))) ^ (bint<<18|(bint>>>(32-18))) ^ (bint<<24|(bint>>>(32-24))); 101 | return c; 102 | }, 103 | pkcs7padding:function(input,mode){ 104 | if (input == null) 105 | { 106 | return null; 107 | } 108 | 109 | var ret = null; 110 | if (mode == 1)//填充 111 | { 112 | var p = 16 - input.length % 16; 113 | ret = new Array(input.length + p); 114 | arrayCopy(input, 0, ret, 0, input.length); 115 | for (var i = 0; i < p; i++) 116 | { 117 | ret[input.length + i] = p; 118 | } 119 | } 120 | else//去除填充 121 | { 122 | var p = input[input.length - 1]; 123 | ret = new Array(input.length - p); 124 | arrayCopy(input, 0, ret, 0, input.length - p); 125 | } 126 | return ret; 127 | }, 128 | encrypt_ecb:function(key,data){ 129 | if(key == undefined || key == null || key.length%16 != 0){ 130 | console.log("sm4 key is error!"); 131 | return null; 132 | } 133 | if(data == undefined || data == null || data.length <= 0){ 134 | console.log("data is error!"); 135 | return null; 136 | } 137 | var rk = this.expandKey(key); 138 | /*if(debug){ 139 | var rkb = intArrayToByteArray(rk); 140 | console.log(Hex.encode(rkb,0,rkb.length)); 141 | }*/ 142 | 143 | var blockLen = 16; 144 | var loop = parseInt(data.length/blockLen);//注意不能整除会有小数,要取整 145 | var cipher = new Array((loop+1)*blockLen); 146 | var tmp = new Array(blockLen); 147 | var oneCipher = null; 148 | 149 | for(var i = 0;i 0){ 157 | arrayCopy(data,loop*blockLen,lessData,0,data.length%blockLen); 158 | } 159 | var padding = this.pkcs7padding(lessData,1); 160 | oneCipher = this.one_encrypt(rk,padding); 161 | arrayCopy(oneCipher,0,cipher,loop*blockLen,blockLen); 162 | 163 | return cipher; 164 | }, 165 | decrypt_ecb:function(key,data){ 166 | if(key == undefined || key == null || key.length%16 != 0){ 167 | console.log("sm4 key is error!"); 168 | return null; 169 | } 170 | if(data == undefined || data == null || data.length%16 != 0){ 171 | console.log("data is error!"); 172 | return null; 173 | } 174 | var rk = this.expandKey(key); 175 | var nrk = new Array(32); 176 | for(var i = 0;i 0){ 241 | arrayCopy(data,loop*blockLen,lessData,0,data.length%blockLen); 242 | } 243 | var padding = this.pkcs7padding(lessData,1); 244 | for(var i = 0;i bytes.length) { 19 | bytes.unshift(0); 20 | } 21 | return bytes; 22 | }; 23 | 24 | var x = this.getX().toBigInteger(); 25 | var y = this.getY().toBigInteger(); 26 | 27 | // Get value as a 32-byte Buffer 28 | // Fixed length based on a patch by bitaddress.org and Casascius 29 | var enc = integerToBytes(x, 32); 30 | 31 | if (compressed) { 32 | if (y.isEven()) { 33 | // Compressed even pubkey 34 | // M = 02 || X 35 | enc.unshift(0x02); 36 | } else { 37 | // Compressed uneven pubkey 38 | // M = 03 || X 39 | enc.unshift(0x03); 40 | } 41 | } else { 42 | // Uncompressed pubkey 43 | // M = 04 || X || Y 44 | enc.unshift(0x04); 45 | enc = enc.concat(integerToBytes(y, 32)); 46 | } 47 | return enc; 48 | }; 49 | 50 | ECPointFp.decodeFrom = function (curve, enc) { 51 | var type = enc[0]; 52 | var dataLen = enc.length-1; 53 | 54 | // Extract x and y as byte arrays 55 | var xBa = enc.slice(1, 1 + dataLen/2); 56 | var yBa = enc.slice(1 + dataLen/2, 1 + dataLen); 57 | 58 | // Prepend zero byte to prevent interpretation as negative integer 59 | xBa.unshift(0); 60 | yBa.unshift(0); 61 | 62 | // Convert to BigIntegers 63 | var x = new BigInteger(xBa); 64 | var y = new BigInteger(yBa); 65 | 66 | // Return point 67 | return new ECPointFp(curve, curve.fromBigInteger(x), curve.fromBigInteger(y)); 68 | }; 69 | 70 | /* 71 | * @since ec-patch.js 1.0.1 72 | */ 73 | ECPointFp.decodeFromHex = function (curve, encHex) { 74 | var type = encHex.substr(0, 2); // shall be "04" 75 | var dataLen = encHex.length - 2; 76 | 77 | // Extract x and y as byte arrays 78 | var xHex = encHex.substr(2, dataLen / 2); 79 | var yHex = encHex.substr(2 + dataLen / 2, dataLen / 2); 80 | 81 | // Convert to BigIntegers 82 | var x = new BigInteger(xHex, 16); 83 | var y = new BigInteger(yHex, 16); 84 | 85 | // Return point 86 | return new ECPointFp(curve, curve.fromBigInteger(x), curve.fromBigInteger(y)); 87 | }; 88 | 89 | ECPointFp.prototype.add2D = function (b) { 90 | if(this.isInfinity()) return b; 91 | if(b.isInfinity()) return this; 92 | 93 | if (this.x.equals(b.x)) { 94 | if (this.y.equals(b.y)) { 95 | // this = b, i.e. this must be doubled 96 | return this.twice(); 97 | } 98 | // this = -b, i.e. the result is the point at infinity 99 | return this.curve.getInfinity(); 100 | } 101 | 102 | var x_x = b.x.subtract(this.x); 103 | var y_y = b.y.subtract(this.y); 104 | var gamma = y_y.divide(x_x); 105 | 106 | var x3 = gamma.square().subtract(this.x).subtract(b.x); 107 | var y3 = gamma.multiply(this.x.subtract(x3)).subtract(this.y); 108 | 109 | return new ECPointFp(this.curve, x3, y3); 110 | }; 111 | 112 | ECPointFp.prototype.twice2D = function () { 113 | if (this.isInfinity()) return this; 114 | if (this.y.toBigInteger().signum() == 0) { 115 | // if y1 == 0, then (x1, y1) == (x1, -y1) 116 | // and hence this = -this and thus 2(x1, y1) == infinity 117 | return this.curve.getInfinity(); 118 | } 119 | 120 | var TWO = this.curve.fromBigInteger(BigInteger.valueOf(2)); 121 | var THREE = this.curve.fromBigInteger(BigInteger.valueOf(3)); 122 | var gamma = this.x.square().multiply(THREE).add(this.curve.a).divide(this.y.multiply(TWO)); 123 | 124 | var x3 = gamma.square().subtract(this.x.multiply(TWO)); 125 | var y3 = gamma.multiply(this.x.subtract(x3)).subtract(this.y); 126 | 127 | return new ECPointFp(this.curve, x3, y3); 128 | }; 129 | 130 | ECPointFp.prototype.multiply2D = function (k) { 131 | if(this.isInfinity()) return this; 132 | if(k.signum() == 0) return this.curve.getInfinity(); 133 | 134 | var e = k; 135 | var h = e.multiply(new BigInteger("3")); 136 | 137 | var neg = this.negate(); 138 | var R = this; 139 | 140 | var i; 141 | for (i = h.bitLength() - 2; i > 0; --i) { 142 | R = R.twice(); 143 | 144 | var hBit = h.testBit(i); 145 | var eBit = e.testBit(i); 146 | 147 | if (hBit != eBit) { 148 | R = R.add2D(hBit ? this : neg); 149 | } 150 | } 151 | 152 | return R; 153 | }; 154 | 155 | ECPointFp.prototype.isOnCurve = function () { 156 | var x = this.getX().toBigInteger(); 157 | var y = this.getY().toBigInteger(); 158 | var a = this.curve.getA().toBigInteger(); 159 | var b = this.curve.getB().toBigInteger(); 160 | var n = this.curve.getQ(); 161 | var lhs = y.multiply(y).mod(n); 162 | var rhs = x.multiply(x).multiply(x) 163 | .add(a.multiply(x)).add(b).mod(n); 164 | return lhs.equals(rhs); 165 | }; 166 | 167 | ECPointFp.prototype.toString = function () { 168 | return '('+this.getX().toBigInteger().toString()+','+ 169 | this.getY().toBigInteger().toString()+')'; 170 | }; 171 | 172 | /** 173 | * Validate an elliptic curve point. 174 | * 175 | * See SEC 1, section 3.2.2.1: Elliptic Curve Public Key Validation Primitive 176 | */ 177 | ECPointFp.prototype.validate = function () { 178 | var n = this.curve.getQ(); 179 | 180 | // Check Q != O 181 | if (this.isInfinity()) { 182 | throw new Error("Point is at infinity."); 183 | } 184 | 185 | // Check coordinate bounds 186 | var x = this.getX().toBigInteger(); 187 | var y = this.getY().toBigInteger(); 188 | if (x.compareTo(BigInteger.ONE) < 0 || 189 | x.compareTo(n.subtract(BigInteger.ONE)) > 0) { 190 | throw new Error('x coordinate out of bounds'); 191 | } 192 | if (y.compareTo(BigInteger.ONE) < 0 || 193 | y.compareTo(n.subtract(BigInteger.ONE)) > 0) { 194 | throw new Error('y coordinate out of bounds'); 195 | } 196 | 197 | // Check y^2 = x^3 + ax + b (mod n) 198 | if (!this.isOnCurve()) { 199 | throw new Error("Point is not on the curve."); 200 | } 201 | 202 | // Check nQ = 0 (Q is a scalar multiple of G) 203 | if (this.multiply(n).isInfinity()) { 204 | // TODO: This check doesn't work - fix. 205 | throw new Error("Point is not a scalar multiple of G."); 206 | } 207 | 208 | return true; 209 | }; 210 | -------------------------------------------------------------------------------- /js/ext/ec.js: -------------------------------------------------------------------------------- 1 | /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ 2 | */ 3 | // Basic Javascript Elliptic Curve implementation 4 | // Ported loosely from BouncyCastle's Java EC code 5 | // Only Fp curves implemented for now 6 | 7 | // Requires jsbn.js and jsbn2.js 8 | 9 | // ---------------- 10 | // ECFieldElementFp 11 | 12 | // constructor 13 | function ECFieldElementFp(q,x) { 14 | this.x = x; 15 | // TODO if(x.compareTo(q) >= 0) error 16 | this.q = q; 17 | } 18 | 19 | function feFpEquals(other) { 20 | if(other == this) return true; 21 | return (this.q.equals(other.q) && this.x.equals(other.x)); 22 | } 23 | 24 | function feFpToBigInteger() { 25 | return this.x; 26 | } 27 | 28 | function feFpNegate() { 29 | return new ECFieldElementFp(this.q, this.x.negate().mod(this.q)); 30 | } 31 | 32 | function feFpAdd(b) { 33 | return new ECFieldElementFp(this.q, this.x.add(b.toBigInteger()).mod(this.q)); 34 | } 35 | 36 | function feFpSubtract(b) { 37 | return new ECFieldElementFp(this.q, this.x.subtract(b.toBigInteger()).mod(this.q)); 38 | } 39 | 40 | function feFpMultiply(b) { 41 | return new ECFieldElementFp(this.q, this.x.multiply(b.toBigInteger()).mod(this.q)); 42 | } 43 | 44 | function feFpSquare() { 45 | return new ECFieldElementFp(this.q, this.x.square().mod(this.q)); 46 | } 47 | 48 | function feFpDivide(b) { 49 | return new ECFieldElementFp(this.q, this.x.multiply(b.toBigInteger().modInverse(this.q)).mod(this.q)); 50 | } 51 | 52 | ECFieldElementFp.prototype.equals = feFpEquals; 53 | ECFieldElementFp.prototype.toBigInteger = feFpToBigInteger; 54 | ECFieldElementFp.prototype.negate = feFpNegate; 55 | ECFieldElementFp.prototype.add = feFpAdd; 56 | ECFieldElementFp.prototype.subtract = feFpSubtract; 57 | ECFieldElementFp.prototype.multiply = feFpMultiply; 58 | ECFieldElementFp.prototype.square = feFpSquare; 59 | ECFieldElementFp.prototype.divide = feFpDivide; 60 | 61 | // ---------------- 62 | // ECPointFp 63 | 64 | // constructor 65 | function ECPointFp(curve,x,y,z) { 66 | this.curve = curve; 67 | this.x = x; 68 | this.y = y; 69 | // Projective coordinates: either zinv == null or z * zinv == 1 70 | // z and zinv are just BigIntegers, not fieldElements 71 | if(z == null) { 72 | this.z = BigInteger.ONE; 73 | } 74 | else { 75 | this.z = z; 76 | } 77 | this.zinv = null; 78 | //TODO: compression flag 79 | } 80 | 81 | function pointFpGetX() { 82 | if(this.zinv == null) { 83 | this.zinv = this.z.modInverse(this.curve.q); 84 | } 85 | return this.curve.fromBigInteger(this.x.toBigInteger().multiply(this.zinv).mod(this.curve.q)); 86 | } 87 | 88 | function pointFpGetY() { 89 | if(this.zinv == null) { 90 | this.zinv = this.z.modInverse(this.curve.q); 91 | } 92 | return this.curve.fromBigInteger(this.y.toBigInteger().multiply(this.zinv).mod(this.curve.q)); 93 | } 94 | 95 | function pointFpEquals(other) { 96 | if(other == this) return true; 97 | if(this.isInfinity()) return other.isInfinity(); 98 | if(other.isInfinity()) return this.isInfinity(); 99 | var u, v; 100 | // u = Y2 * Z1 - Y1 * Z2 101 | u = other.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(other.z)).mod(this.curve.q); 102 | if(!u.equals(BigInteger.ZERO)) return false; 103 | // v = X2 * Z1 - X1 * Z2 104 | v = other.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(other.z)).mod(this.curve.q); 105 | return v.equals(BigInteger.ZERO); 106 | } 107 | 108 | function pointFpIsInfinity() { 109 | if((this.x == null) && (this.y == null)) return true; 110 | return this.z.equals(BigInteger.ZERO) && !this.y.toBigInteger().equals(BigInteger.ZERO); 111 | } 112 | 113 | function pointFpNegate() { 114 | return new ECPointFp(this.curve, this.x, this.y.negate(), this.z); 115 | } 116 | 117 | function pointFpAdd(b) { 118 | if(this.isInfinity()) return b; 119 | if(b.isInfinity()) return this; 120 | 121 | // u = Y2 * Z1 - Y1 * Z2 122 | var u = b.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(b.z)).mod(this.curve.q); 123 | // v = X2 * Z1 - X1 * Z2 124 | var v = b.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(b.z)).mod(this.curve.q); 125 | 126 | if(BigInteger.ZERO.equals(v)) { 127 | if(BigInteger.ZERO.equals(u)) { 128 | return this.twice(); // this == b, so double 129 | } 130 | return this.curve.getInfinity(); // this = -b, so infinity 131 | } 132 | 133 | var THREE = new BigInteger("3"); 134 | var x1 = this.x.toBigInteger(); 135 | var y1 = this.y.toBigInteger(); 136 | var x2 = b.x.toBigInteger(); 137 | var y2 = b.y.toBigInteger(); 138 | 139 | var v2 = v.square(); 140 | var v3 = v2.multiply(v); 141 | var x1v2 = x1.multiply(v2); 142 | var zu2 = u.square().multiply(this.z); 143 | 144 | // x3 = v * (z2 * (z1 * u^2 - 2 * x1 * v^2) - v^3) 145 | var x3 = zu2.subtract(x1v2.shiftLeft(1)).multiply(b.z).subtract(v3).multiply(v).mod(this.curve.q); 146 | // y3 = z2 * (3 * x1 * u * v^2 - y1 * v^3 - z1 * u^3) + u * v^3 147 | var y3 = x1v2.multiply(THREE).multiply(u).subtract(y1.multiply(v3)).subtract(zu2.multiply(u)).multiply(b.z).add(u.multiply(v3)).mod(this.curve.q); 148 | // z3 = v^3 * z1 * z2 149 | var z3 = v3.multiply(this.z).multiply(b.z).mod(this.curve.q); 150 | 151 | return new ECPointFp(this.curve, this.curve.fromBigInteger(x3), this.curve.fromBigInteger(y3), z3); 152 | } 153 | 154 | function pointFpTwice() { 155 | if(this.isInfinity()) return this; 156 | if(this.y.toBigInteger().signum() == 0) return this.curve.getInfinity(); 157 | 158 | // TODO: optimized handling of constants 159 | var THREE = new BigInteger("3"); 160 | var x1 = this.x.toBigInteger(); 161 | var y1 = this.y.toBigInteger(); 162 | 163 | var y1z1 = y1.multiply(this.z); 164 | var y1sqz1 = y1z1.multiply(y1).mod(this.curve.q); 165 | var a = this.curve.a.toBigInteger(); 166 | 167 | // w = 3 * x1^2 + a * z1^2 168 | var w = x1.square().multiply(THREE); 169 | if(!BigInteger.ZERO.equals(a)) { 170 | w = w.add(this.z.square().multiply(a)); 171 | } 172 | w = w.mod(this.curve.q); 173 | // x3 = 2 * y1 * z1 * (w^2 - 8 * x1 * y1^2 * z1) 174 | var x3 = w.square().subtract(x1.shiftLeft(3).multiply(y1sqz1)).shiftLeft(1).multiply(y1z1).mod(this.curve.q); 175 | // y3 = 4 * y1^2 * z1 * (3 * w * x1 - 2 * y1^2 * z1) - w^3 176 | var y3 = w.multiply(THREE).multiply(x1).subtract(y1sqz1.shiftLeft(1)).shiftLeft(2).multiply(y1sqz1).subtract(w.square().multiply(w)).mod(this.curve.q); 177 | // z3 = 8 * (y1 * z1)^3 178 | var z3 = y1z1.square().multiply(y1z1).shiftLeft(3).mod(this.curve.q); 179 | 180 | return new ECPointFp(this.curve, this.curve.fromBigInteger(x3), this.curve.fromBigInteger(y3), z3); 181 | } 182 | 183 | // Simple NAF (Non-Adjacent Form) multiplication algorithm 184 | // TODO: modularize the multiplication algorithm 185 | function pointFpMultiply(k) { 186 | if(this.isInfinity()) return this; 187 | if(k.signum() == 0) return this.curve.getInfinity(); 188 | 189 | var e = k; 190 | var h = e.multiply(new BigInteger("3")); 191 | 192 | var neg = this.negate(); 193 | var R = this; 194 | 195 | var i; 196 | for(i = h.bitLength() - 2; i > 0; --i) { 197 | R = R.twice(); 198 | 199 | var hBit = h.testBit(i); 200 | var eBit = e.testBit(i); 201 | 202 | if (hBit != eBit) { 203 | R = R.add(hBit ? this : neg); 204 | } 205 | } 206 | 207 | return R; 208 | } 209 | 210 | // Compute this*j + x*k (simultaneous multiplication) 211 | function pointFpMultiplyTwo(j,x,k) { 212 | var i; 213 | if(j.bitLength() > k.bitLength()) 214 | i = j.bitLength() - 1; 215 | else 216 | i = k.bitLength() - 1; 217 | 218 | var R = this.curve.getInfinity(); 219 | var both = this.add(x); 220 | while(i >= 0) { 221 | R = R.twice(); 222 | if(j.testBit(i)) { 223 | if(k.testBit(i)) { 224 | R = R.add(both); 225 | } 226 | else { 227 | R = R.add(this); 228 | } 229 | } 230 | else { 231 | if(k.testBit(i)) { 232 | R = R.add(x); 233 | } 234 | } 235 | --i; 236 | } 237 | 238 | return R; 239 | } 240 | 241 | ECPointFp.prototype.getX = pointFpGetX; 242 | ECPointFp.prototype.getY = pointFpGetY; 243 | ECPointFp.prototype.equals = pointFpEquals; 244 | ECPointFp.prototype.isInfinity = pointFpIsInfinity; 245 | ECPointFp.prototype.negate = pointFpNegate; 246 | ECPointFp.prototype.add = pointFpAdd; 247 | ECPointFp.prototype.twice = pointFpTwice; 248 | ECPointFp.prototype.multiply = pointFpMultiply; 249 | ECPointFp.prototype.multiplyTwo = pointFpMultiplyTwo; 250 | 251 | // ---------------- 252 | // ECCurveFp 253 | 254 | // constructor 255 | function ECCurveFp(q,a,b) { 256 | this.q = q; 257 | this.a = this.fromBigInteger(a); 258 | this.b = this.fromBigInteger(b); 259 | this.infinity = new ECPointFp(this, null, null); 260 | } 261 | 262 | function curveFpGetQ() { 263 | return this.q; 264 | } 265 | 266 | function curveFpGetA() { 267 | return this.a; 268 | } 269 | 270 | function curveFpGetB() { 271 | return this.b; 272 | } 273 | 274 | function curveFpEquals(other) { 275 | if(other == this) return true; 276 | return(this.q.equals(other.q) && this.a.equals(other.a) && this.b.equals(other.b)); 277 | } 278 | 279 | function curveFpGetInfinity() { 280 | return this.infinity; 281 | } 282 | 283 | function curveFpFromBigInteger(x) { 284 | return new ECFieldElementFp(this.q, x); 285 | } 286 | 287 | // for now, work with hex strings because they're easier in JS 288 | function curveFpDecodePointHex(s) { 289 | switch(parseInt(s.substr(0,2), 16)) { // first byte 290 | case 0: 291 | return this.infinity; 292 | case 2: 293 | case 3: 294 | // point compression not supported yet 295 | return null; 296 | case 4: 297 | case 6: 298 | case 7: 299 | var len = (s.length - 2) / 2; 300 | var xHex = s.substr(2, len); 301 | var yHex = s.substr(len+2, len); 302 | 303 | return new ECPointFp(this, 304 | this.fromBigInteger(new BigInteger(xHex, 16)), 305 | this.fromBigInteger(new BigInteger(yHex, 16))); 306 | 307 | default: // unsupported 308 | return null; 309 | } 310 | } 311 | 312 | ECCurveFp.prototype.getQ = curveFpGetQ; 313 | ECCurveFp.prototype.getA = curveFpGetA; 314 | ECCurveFp.prototype.getB = curveFpGetB; 315 | ECCurveFp.prototype.equals = curveFpEquals; 316 | ECCurveFp.prototype.getInfinity = curveFpGetInfinity; 317 | ECCurveFp.prototype.fromBigInteger = curveFpFromBigInteger; 318 | ECCurveFp.prototype.decodePointHex = curveFpDecodePointHex; 319 | -------------------------------------------------------------------------------- /js/ext/jsbn.js: -------------------------------------------------------------------------------- 1 | /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ 2 | */ 3 | // Copyright (c) 2005 Tom Wu 4 | // All Rights Reserved. 5 | // See "LICENSE" for details. 6 | 7 | // Basic JavaScript BN library - subset useful for RSA encryption. 8 | 9 | // Bits per digit 10 | var dbits; 11 | 12 | // JavaScript engine analysis 13 | var canary = 0xdeadbeefcafe; 14 | var j_lm = ((canary&0xffffff)==0xefcafe); 15 | 16 | // (public) Constructor 17 | function BigInteger(a,b,c) { 18 | if(a != null) 19 | if("number" == typeof a) this.fromNumber(a,b,c); 20 | else if(b == null && "string" != typeof a) this.fromString(a,256); 21 | else this.fromString(a,b); 22 | } 23 | 24 | // return new, unset BigInteger 25 | function nbi() { return new BigInteger(null); } 26 | 27 | // am: Compute w_j += (x*this_i), propagate carries, 28 | // c is initial carry, returns final carry. 29 | // c < 3*dvalue, x < 2*dvalue, this_i < dvalue 30 | // We need to select the fastest one that works in this environment. 31 | 32 | // am1: use a single mult and divide to get the high bits, 33 | // max digit bits should be 26 because 34 | // max internal value = 2*dvalue^2-2*dvalue (< 2^53) 35 | function am1(i,x,w,j,c,n) { 36 | while(--n >= 0) { 37 | var v = x*this[i++]+w[j]+c; 38 | c = Math.floor(v/0x4000000); 39 | w[j++] = v&0x3ffffff; 40 | } 41 | return c; 42 | } 43 | // am2 avoids a big mult-and-extract completely. 44 | // Max digit bits should be <= 30 because we do bitwise ops 45 | // on values up to 2*hdvalue^2-hdvalue-1 (< 2^31) 46 | function am2(i,x,w,j,c,n) { 47 | var xl = x&0x7fff, xh = x>>15; 48 | while(--n >= 0) { 49 | var l = this[i]&0x7fff; 50 | var h = this[i++]>>15; 51 | var m = xh*l+h*xl; 52 | l = xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff); 53 | c = (l>>>30)+(m>>>15)+xh*h+(c>>>30); 54 | w[j++] = l&0x3fffffff; 55 | } 56 | return c; 57 | } 58 | // Alternately, set max digit bits to 28 since some 59 | // browsers slow down when dealing with 32-bit numbers. 60 | function am3(i,x,w,j,c,n) { 61 | var xl = x&0x3fff, xh = x>>14; 62 | while(--n >= 0) { 63 | var l = this[i]&0x3fff; 64 | var h = this[i++]>>14; 65 | var m = xh*l+h*xl; 66 | l = xl*l+((m&0x3fff)<<14)+w[j]+c; 67 | c = (l>>28)+(m>>14)+xh*h; 68 | w[j++] = l&0xfffffff; 69 | } 70 | return c; 71 | } 72 | if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) { 73 | BigInteger.prototype.am = am2; 74 | dbits = 30; 75 | } 76 | else if(j_lm && (navigator.appName != "Netscape")) { 77 | BigInteger.prototype.am = am1; 78 | dbits = 26; 79 | } 80 | else { // Mozilla/Netscape seems to prefer am3 81 | BigInteger.prototype.am = am3; 82 | dbits = 28; 83 | } 84 | 85 | BigInteger.prototype.DB = dbits; 86 | BigInteger.prototype.DM = ((1<= 0; --i) r[i] = this[i]; 114 | r.t = this.t; 115 | r.s = this.s; 116 | } 117 | 118 | // (protected) set from integer value x, -DV <= x < DV 119 | function bnpFromInt(x) { 120 | this.t = 1; 121 | this.s = (x<0)?-1:0; 122 | if(x > 0) this[0] = x; 123 | else if(x < -1) this[0] = x+this.DV; 124 | else this.t = 0; 125 | } 126 | 127 | // return bigint initialized to value 128 | function nbv(i) { var r = nbi(); r.fromInt(i); return r; } 129 | 130 | // (protected) set from string and radix 131 | function bnpFromString(s,b) { 132 | var k; 133 | if(b == 16) k = 4; 134 | else if(b == 8) k = 3; 135 | else if(b == 256) k = 8; // byte array 136 | else if(b == 2) k = 1; 137 | else if(b == 32) k = 5; 138 | else if(b == 4) k = 2; 139 | else { this.fromRadix(s,b); return; } 140 | this.t = 0; 141 | this.s = 0; 142 | var i = s.length, mi = false, sh = 0; 143 | while(--i >= 0) { 144 | var x = (k==8)?s[i]&0xff:intAt(s,i); 145 | if(x < 0) { 146 | if(s.charAt(i) == "-") mi = true; 147 | continue; 148 | } 149 | mi = false; 150 | if(sh == 0) 151 | this[this.t++] = x; 152 | else if(sh+k > this.DB) { 153 | this[this.t-1] |= (x&((1<<(this.DB-sh))-1))<>(this.DB-sh)); 155 | } 156 | else 157 | this[this.t-1] |= x<= this.DB) sh -= this.DB; 160 | } 161 | if(k == 8 && (s[0]&0x80) != 0) { 162 | this.s = -1; 163 | if(sh > 0) this[this.t-1] |= ((1<<(this.DB-sh))-1)< 0 && this[this.t-1] == c) --this.t; 173 | } 174 | 175 | // (public) return string representation in given radix 176 | function bnToString(b) { 177 | if(this.s < 0) return "-"+this.negate().toString(b); 178 | var k; 179 | if(b == 16) k = 4; 180 | else if(b == 8) k = 3; 181 | else if(b == 2) k = 1; 182 | else if(b == 32) k = 5; 183 | else if(b == 4) k = 2; 184 | else return this.toRadix(b); 185 | var km = (1< 0) { 188 | if(p < this.DB && (d = this[i]>>p) > 0) { m = true; r = int2char(d); } 189 | while(i >= 0) { 190 | if(p < k) { 191 | d = (this[i]&((1<>(p+=this.DB-k); 193 | } 194 | else { 195 | d = (this[i]>>(p-=k))&km; 196 | if(p <= 0) { p += this.DB; --i; } 197 | } 198 | if(d > 0) m = true; 199 | if(m) r += int2char(d); 200 | } 201 | } 202 | return m?r:"0"; 203 | } 204 | 205 | // (public) -this 206 | function bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this,r); return r; } 207 | 208 | // (public) |this| 209 | function bnAbs() { return (this.s<0)?this.negate():this; } 210 | 211 | // (public) return + if this > a, - if this < a, 0 if equal 212 | function bnCompareTo(a) { 213 | var r = this.s-a.s; 214 | if(r != 0) return r; 215 | var i = this.t; 216 | r = i-a.t; 217 | if(r != 0) return (this.s<0)?-r:r; 218 | while(--i >= 0) if((r=this[i]-a[i]) != 0) return r; 219 | return 0; 220 | } 221 | 222 | // returns bit length of the integer x 223 | function nbits(x) { 224 | var r = 1, t; 225 | if((t=x>>>16) != 0) { x = t; r += 16; } 226 | if((t=x>>8) != 0) { x = t; r += 8; } 227 | if((t=x>>4) != 0) { x = t; r += 4; } 228 | if((t=x>>2) != 0) { x = t; r += 2; } 229 | if((t=x>>1) != 0) { x = t; r += 1; } 230 | return r; 231 | } 232 | 233 | // (public) return the number of bits in "this" 234 | function bnBitLength() { 235 | if(this.t <= 0) return 0; 236 | return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM)); 237 | } 238 | 239 | // (protected) r = this << n*DB 240 | function bnpDLShiftTo(n,r) { 241 | var i; 242 | for(i = this.t-1; i >= 0; --i) r[i+n] = this[i]; 243 | for(i = n-1; i >= 0; --i) r[i] = 0; 244 | r.t = this.t+n; 245 | r.s = this.s; 246 | } 247 | 248 | // (protected) r = this >> n*DB 249 | function bnpDRShiftTo(n,r) { 250 | for(var i = n; i < this.t; ++i) r[i-n] = this[i]; 251 | r.t = Math.max(this.t-n,0); 252 | r.s = this.s; 253 | } 254 | 255 | // (protected) r = this << n 256 | function bnpLShiftTo(n,r) { 257 | var bs = n%this.DB; 258 | var cbs = this.DB-bs; 259 | var bm = (1<= 0; --i) { 262 | r[i+ds+1] = (this[i]>>cbs)|c; 263 | c = (this[i]&bm)<= 0; --i) r[i] = 0; 266 | r[ds] = c; 267 | r.t = this.t+ds+1; 268 | r.s = this.s; 269 | r.clamp(); 270 | } 271 | 272 | // (protected) r = this >> n 273 | function bnpRShiftTo(n,r) { 274 | r.s = this.s; 275 | var ds = Math.floor(n/this.DB); 276 | if(ds >= this.t) { r.t = 0; return; } 277 | var bs = n%this.DB; 278 | var cbs = this.DB-bs; 279 | var bm = (1<>bs; 281 | for(var i = ds+1; i < this.t; ++i) { 282 | r[i-ds-1] |= (this[i]&bm)<>bs; 284 | } 285 | if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<>= this.DB; 297 | } 298 | if(a.t < this.t) { 299 | c -= a.s; 300 | while(i < this.t) { 301 | c += this[i]; 302 | r[i++] = c&this.DM; 303 | c >>= this.DB; 304 | } 305 | c += this.s; 306 | } 307 | else { 308 | c += this.s; 309 | while(i < a.t) { 310 | c -= a[i]; 311 | r[i++] = c&this.DM; 312 | c >>= this.DB; 313 | } 314 | c -= a.s; 315 | } 316 | r.s = (c<0)?-1:0; 317 | if(c < -1) r[i++] = this.DV+c; 318 | else if(c > 0) r[i++] = c; 319 | r.t = i; 320 | r.clamp(); 321 | } 322 | 323 | // (protected) r = this * a, r != this,a (HAC 14.12) 324 | // "this" should be the larger one if appropriate. 325 | function bnpMultiplyTo(a,r) { 326 | var x = this.abs(), y = a.abs(); 327 | var i = x.t; 328 | r.t = i+y.t; 329 | while(--i >= 0) r[i] = 0; 330 | for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t); 331 | r.s = 0; 332 | r.clamp(); 333 | if(this.s != a.s) BigInteger.ZERO.subTo(r,r); 334 | } 335 | 336 | // (protected) r = this^2, r != this (HAC 14.16) 337 | function bnpSquareTo(r) { 338 | var x = this.abs(); 339 | var i = r.t = 2*x.t; 340 | while(--i >= 0) r[i] = 0; 341 | for(i = 0; i < x.t-1; ++i) { 342 | var c = x.am(i,x[i],r,2*i,0,1); 343 | if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x.DV) { 344 | r[i+x.t] -= x.DV; 345 | r[i+x.t+1] = 1; 346 | } 347 | } 348 | if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1); 349 | r.s = 0; 350 | r.clamp(); 351 | } 352 | 353 | // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20) 354 | // r != q, this != m. q or r may be null. 355 | function bnpDivRemTo(m,q,r) { 356 | var pm = m.abs(); 357 | if(pm.t <= 0) return; 358 | var pt = this.abs(); 359 | if(pt.t < pm.t) { 360 | if(q != null) q.fromInt(0); 361 | if(r != null) this.copyTo(r); 362 | return; 363 | } 364 | if(r == null) r = nbi(); 365 | var y = nbi(), ts = this.s, ms = m.s; 366 | var nsh = this.DB-nbits(pm[pm.t-1]); // normalize modulus 367 | if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); } 368 | else { pm.copyTo(y); pt.copyTo(r); } 369 | var ys = y.t; 370 | var y0 = y[ys-1]; 371 | if(y0 == 0) return; 372 | var yt = y0*(1<1)?y[ys-2]>>this.F2:0); 373 | var d1 = this.FV/yt, d2 = (1<= 0) { 377 | r[r.t++] = 1; 378 | r.subTo(t,r); 379 | } 380 | BigInteger.ONE.dlShiftTo(ys,t); 381 | t.subTo(y,y); // "negative" y so we can replace sub with am later 382 | while(y.t < ys) y[y.t++] = 0; 383 | while(--j >= 0) { 384 | // Estimate quotient digit 385 | var qd = (r[--i]==y0)?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2); 386 | if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) { // Try it out 387 | y.dlShiftTo(j,t); 388 | r.subTo(t,r); 389 | while(r[i] < --qd) r.subTo(t,r); 390 | } 391 | } 392 | if(q != null) { 393 | r.drShiftTo(ys,q); 394 | if(ts != ms) BigInteger.ZERO.subTo(q,q); 395 | } 396 | r.t = ys; 397 | r.clamp(); 398 | if(nsh > 0) r.rShiftTo(nsh,r); // Denormalize remainder 399 | if(ts < 0) BigInteger.ZERO.subTo(r,r); 400 | } 401 | 402 | // (public) this mod a 403 | function bnMod(a) { 404 | var r = nbi(); 405 | this.abs().divRemTo(a,null,r); 406 | if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r,r); 407 | return r; 408 | } 409 | 410 | // Modular reduction using "classic" algorithm 411 | function Classic(m) { this.m = m; } 412 | function cConvert(x) { 413 | if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m); 414 | else return x; 415 | } 416 | function cRevert(x) { return x; } 417 | function cReduce(x) { x.divRemTo(this.m,null,x); } 418 | function cMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); } 419 | function cSqrTo(x,r) { x.squareTo(r); this.reduce(r); } 420 | 421 | Classic.prototype.convert = cConvert; 422 | Classic.prototype.revert = cRevert; 423 | Classic.prototype.reduce = cReduce; 424 | Classic.prototype.mulTo = cMulTo; 425 | Classic.prototype.sqrTo = cSqrTo; 426 | 427 | // (protected) return "-1/this % 2^DB"; useful for Mont. reduction 428 | // justification: 429 | // xy == 1 (mod m) 430 | // xy = 1+km 431 | // xy(2-xy) = (1+km)(1-km) 432 | // x[y(2-xy)] = 1-k^2m^2 433 | // x[y(2-xy)] == 1 (mod m^2) 434 | // if y is 1/x mod m, then y(2-xy) is 1/x mod m^2 435 | // should reduce x and y(2-xy) by m^2 at each step to keep size bounded. 436 | // JS multiply "overflows" differently from C/C++, so care is needed here. 437 | function bnpInvDigit() { 438 | if(this.t < 1) return 0; 439 | var x = this[0]; 440 | if((x&1) == 0) return 0; 441 | var y = x&3; // y == 1/x mod 2^2 442 | y = (y*(2-(x&0xf)*y))&0xf; // y == 1/x mod 2^4 443 | y = (y*(2-(x&0xff)*y))&0xff; // y == 1/x mod 2^8 444 | y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; // y == 1/x mod 2^16 445 | // last step - calculate inverse mod DV directly; 446 | // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints 447 | y = (y*(2-x*y%this.DV))%this.DV; // y == 1/x mod 2^dbits 448 | // we really want the negative inverse, and -DV < y < DV 449 | return (y>0)?this.DV-y:-y; 450 | } 451 | 452 | // Montgomery reduction 453 | function Montgomery(m) { 454 | this.m = m; 455 | this.mp = m.invDigit(); 456 | this.mpl = this.mp&0x7fff; 457 | this.mph = this.mp>>15; 458 | this.um = (1<<(m.DB-15))-1; 459 | this.mt2 = 2*m.t; 460 | } 461 | 462 | // xR mod m 463 | function montConvert(x) { 464 | var r = nbi(); 465 | x.abs().dlShiftTo(this.m.t,r); 466 | r.divRemTo(this.m,null,r); 467 | if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r); 468 | return r; 469 | } 470 | 471 | // x/R mod m 472 | function montRevert(x) { 473 | var r = nbi(); 474 | x.copyTo(r); 475 | this.reduce(r); 476 | return r; 477 | } 478 | 479 | // x = x/R mod m (HAC 14.32) 480 | function montReduce(x) { 481 | while(x.t <= this.mt2) // pad x so am has enough room later 482 | x[x.t++] = 0; 483 | for(var i = 0; i < this.m.t; ++i) { 484 | // faster way of calculating u0 = x[i]*mp mod DV 485 | var j = x[i]&0x7fff; 486 | var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.DM; 487 | // use am to combine the multiply-shift-add into one call 488 | j = i+this.m.t; 489 | x[j] += this.m.am(0,u0,x,i,0,this.m.t); 490 | // propagate carry 491 | while(x[j] >= x.DV) { x[j] -= x.DV; x[++j]++; } 492 | } 493 | x.clamp(); 494 | x.drShiftTo(this.m.t,x); 495 | if(x.compareTo(this.m) >= 0) x.subTo(this.m,x); 496 | } 497 | 498 | // r = "x^2/R mod m"; x != r 499 | function montSqrTo(x,r) { x.squareTo(r); this.reduce(r); } 500 | 501 | // r = "xy/R mod m"; x,y != r 502 | function montMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); } 503 | 504 | Montgomery.prototype.convert = montConvert; 505 | Montgomery.prototype.revert = montRevert; 506 | Montgomery.prototype.reduce = montReduce; 507 | Montgomery.prototype.mulTo = montMulTo; 508 | Montgomery.prototype.sqrTo = montSqrTo; 509 | 510 | // (protected) true iff this is even 511 | function bnpIsEven() { return ((this.t>0)?(this[0]&1):this.s) == 0; } 512 | 513 | // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79) 514 | function bnpExp(e,z) { 515 | if(e > 0xffffffff || e < 1) return BigInteger.ONE; 516 | var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1; 517 | g.copyTo(r); 518 | while(--i >= 0) { 519 | z.sqrTo(r,r2); 520 | if((e&(1< 0) z.mulTo(r2,g,r); 521 | else { var t = r; r = r2; r2 = t; } 522 | } 523 | return z.revert(r); 524 | } 525 | 526 | // (public) this^e % m, 0 <= e < 2^32 527 | function bnModPowInt(e,m) { 528 | var z; 529 | if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m); 530 | return this.exp(e,z); 531 | } 532 | 533 | // protected 534 | BigInteger.prototype.copyTo = bnpCopyTo; 535 | BigInteger.prototype.fromInt = bnpFromInt; 536 | BigInteger.prototype.fromString = bnpFromString; 537 | BigInteger.prototype.clamp = bnpClamp; 538 | BigInteger.prototype.dlShiftTo = bnpDLShiftTo; 539 | BigInteger.prototype.drShiftTo = bnpDRShiftTo; 540 | BigInteger.prototype.lShiftTo = bnpLShiftTo; 541 | BigInteger.prototype.rShiftTo = bnpRShiftTo; 542 | BigInteger.prototype.subTo = bnpSubTo; 543 | BigInteger.prototype.multiplyTo = bnpMultiplyTo; 544 | BigInteger.prototype.squareTo = bnpSquareTo; 545 | BigInteger.prototype.divRemTo = bnpDivRemTo; 546 | BigInteger.prototype.invDigit = bnpInvDigit; 547 | BigInteger.prototype.isEven = bnpIsEven; 548 | BigInteger.prototype.exp = bnpExp; 549 | 550 | // public 551 | BigInteger.prototype.toString = bnToString; 552 | BigInteger.prototype.negate = bnNegate; 553 | BigInteger.prototype.abs = bnAbs; 554 | BigInteger.prototype.compareTo = bnCompareTo; 555 | BigInteger.prototype.bitLength = bnBitLength; 556 | BigInteger.prototype.mod = bnMod; 557 | BigInteger.prototype.modPowInt = bnModPowInt; 558 | 559 | // "constants" 560 | BigInteger.ZERO = nbv(0); 561 | BigInteger.ONE = nbv(1); 562 | -------------------------------------------------------------------------------- /js/ext/jsbn2.js: -------------------------------------------------------------------------------- 1 | /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ 2 | */ 3 | // Copyright (c) 2005-2009 Tom Wu 4 | // All Rights Reserved. 5 | // See "LICENSE" for details. 6 | 7 | // Extended JavaScript BN functions, required for RSA private ops. 8 | 9 | // Version 1.1: new BigInteger("0", 10) returns "proper" zero 10 | // Version 1.2: square() API, isProbablePrime fix 11 | 12 | // (public) 13 | function bnClone() { var r = nbi(); this.copyTo(r); return r; } 14 | 15 | // (public) return value as integer 16 | function bnIntValue() { 17 | if(this.s < 0) { 18 | if(this.t == 1) return this[0]-this.DV; 19 | else if(this.t == 0) return -1; 20 | } 21 | else if(this.t == 1) return this[0]; 22 | else if(this.t == 0) return 0; 23 | // assumes 16 < DB < 32 24 | return ((this[1]&((1<<(32-this.DB))-1))<>24; } 29 | 30 | // (public) return value as short (assumes DB>=16) 31 | function bnShortValue() { return (this.t==0)?this.s:(this[0]<<16)>>16; } 32 | 33 | // (protected) return x s.t. r^x < DV 34 | function bnpChunkSize(r) { return Math.floor(Math.LN2*this.DB/Math.log(r)); } 35 | 36 | // (public) 0 if this == 0, 1 if this > 0 37 | function bnSigNum() { 38 | if(this.s < 0) return -1; 39 | else if(this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0; 40 | else return 1; 41 | } 42 | 43 | // (protected) convert to radix string 44 | function bnpToRadix(b) { 45 | if(b == null) b = 10; 46 | if(this.signum() == 0 || b < 2 || b > 36) return "0"; 47 | var cs = this.chunkSize(b); 48 | var a = Math.pow(b,cs); 49 | var d = nbv(a), y = nbi(), z = nbi(), r = ""; 50 | this.divRemTo(d,y,z); 51 | while(y.signum() > 0) { 52 | r = (a+z.intValue()).toString(b).substr(1) + r; 53 | y.divRemTo(d,y,z); 54 | } 55 | return z.intValue().toString(b) + r; 56 | } 57 | 58 | // (protected) convert from radix string 59 | function bnpFromRadix(s,b) { 60 | this.fromInt(0); 61 | if(b == null) b = 10; 62 | var cs = this.chunkSize(b); 63 | var d = Math.pow(b,cs), mi = false, j = 0, w = 0; 64 | for(var i = 0; i < s.length; ++i) { 65 | var x = intAt(s,i); 66 | if(x < 0) { 67 | if(s.charAt(i) == "-" && this.signum() == 0) mi = true; 68 | continue; 69 | } 70 | w = b*w+x; 71 | if(++j >= cs) { 72 | this.dMultiply(d); 73 | this.dAddOffset(w,0); 74 | j = 0; 75 | w = 0; 76 | } 77 | } 78 | if(j > 0) { 79 | this.dMultiply(Math.pow(b,j)); 80 | this.dAddOffset(w,0); 81 | } 82 | if(mi) BigInteger.ZERO.subTo(this,this); 83 | } 84 | 85 | // (protected) alternate constructor 86 | function bnpFromNumber(a,b,c) { 87 | if("number" == typeof b) { 88 | // new BigInteger(int,int,RNG) 89 | if(a < 2) this.fromInt(1); 90 | else { 91 | this.fromNumber(a,c); 92 | if(!this.testBit(a-1)) // force MSB set 93 | this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this); 94 | if(this.isEven()) this.dAddOffset(1,0); // force odd 95 | while(!this.isProbablePrime(b)) { 96 | this.dAddOffset(2,0); 97 | if(this.bitLength() > a) this.subTo(BigInteger.ONE.shiftLeft(a-1),this); 98 | } 99 | } 100 | } 101 | else { 102 | // new BigInteger(int,RNG) 103 | var x = new Array(), t = a&7; 104 | x.length = (a>>3)+1; 105 | b.nextBytes(x); 106 | if(t > 0) x[0] &= ((1< 0) { 117 | if(p < this.DB && (d = this[i]>>p) != (this.s&this.DM)>>p) 118 | r[k++] = d|(this.s<<(this.DB-p)); 119 | while(i >= 0) { 120 | if(p < 8) { 121 | d = (this[i]&((1<>(p+=this.DB-8); 123 | } 124 | else { 125 | d = (this[i]>>(p-=8))&0xff; 126 | if(p <= 0) { p += this.DB; --i; } 127 | } 128 | if((d&0x80) != 0) d |= -256; 129 | if(k == 0 && (this.s&0x80) != (d&0x80)) ++k; 130 | if(k > 0 || d != this.s) r[k++] = d; 131 | } 132 | } 133 | return r; 134 | } 135 | 136 | function bnEquals(a) { return(this.compareTo(a)==0); } 137 | function bnMin(a) { return(this.compareTo(a)<0)?this:a; } 138 | function bnMax(a) { return(this.compareTo(a)>0)?this:a; } 139 | 140 | // (protected) r = this op a (bitwise) 141 | function bnpBitwiseTo(a,op,r) { 142 | var i, f, m = Math.min(a.t,this.t); 143 | for(i = 0; i < m; ++i) r[i] = op(this[i],a[i]); 144 | if(a.t < this.t) { 145 | f = a.s&this.DM; 146 | for(i = m; i < this.t; ++i) r[i] = op(this[i],f); 147 | r.t = this.t; 148 | } 149 | else { 150 | f = this.s&this.DM; 151 | for(i = m; i < a.t; ++i) r[i] = op(f,a[i]); 152 | r.t = a.t; 153 | } 154 | r.s = op(this.s,a.s); 155 | r.clamp(); 156 | } 157 | 158 | // (public) this & a 159 | function op_and(x,y) { return x&y; } 160 | function bnAnd(a) { var r = nbi(); this.bitwiseTo(a,op_and,r); return r; } 161 | 162 | // (public) this | a 163 | function op_or(x,y) { return x|y; } 164 | function bnOr(a) { var r = nbi(); this.bitwiseTo(a,op_or,r); return r; } 165 | 166 | // (public) this ^ a 167 | function op_xor(x,y) { return x^y; } 168 | function bnXor(a) { var r = nbi(); this.bitwiseTo(a,op_xor,r); return r; } 169 | 170 | // (public) this & ~a 171 | function op_andnot(x,y) { return x&~y; } 172 | function bnAndNot(a) { var r = nbi(); this.bitwiseTo(a,op_andnot,r); return r; } 173 | 174 | // (public) ~this 175 | function bnNot() { 176 | var r = nbi(); 177 | for(var i = 0; i < this.t; ++i) r[i] = this.DM&~this[i]; 178 | r.t = this.t; 179 | r.s = ~this.s; 180 | return r; 181 | } 182 | 183 | // (public) this << n 184 | function bnShiftLeft(n) { 185 | var r = nbi(); 186 | if(n < 0) this.rShiftTo(-n,r); else this.lShiftTo(n,r); 187 | return r; 188 | } 189 | 190 | // (public) this >> n 191 | function bnShiftRight(n) { 192 | var r = nbi(); 193 | if(n < 0) this.lShiftTo(-n,r); else this.rShiftTo(n,r); 194 | return r; 195 | } 196 | 197 | // return index of lowest 1-bit in x, x < 2^31 198 | function lbit(x) { 199 | if(x == 0) return -1; 200 | var r = 0; 201 | if((x&0xffff) == 0) { x >>= 16; r += 16; } 202 | if((x&0xff) == 0) { x >>= 8; r += 8; } 203 | if((x&0xf) == 0) { x >>= 4; r += 4; } 204 | if((x&3) == 0) { x >>= 2; r += 2; } 205 | if((x&1) == 0) ++r; 206 | return r; 207 | } 208 | 209 | // (public) returns index of lowest 1-bit (or -1 if none) 210 | function bnGetLowestSetBit() { 211 | for(var i = 0; i < this.t; ++i) 212 | if(this[i] != 0) return i*this.DB+lbit(this[i]); 213 | if(this.s < 0) return this.t*this.DB; 214 | return -1; 215 | } 216 | 217 | // return number of 1 bits in x 218 | function cbit(x) { 219 | var r = 0; 220 | while(x != 0) { x &= x-1; ++r; } 221 | return r; 222 | } 223 | 224 | // (public) return number of set bits 225 | function bnBitCount() { 226 | var r = 0, x = this.s&this.DM; 227 | for(var i = 0; i < this.t; ++i) r += cbit(this[i]^x); 228 | return r; 229 | } 230 | 231 | // (public) true iff nth bit is set 232 | function bnTestBit(n) { 233 | var j = Math.floor(n/this.DB); 234 | if(j >= this.t) return(this.s!=0); 235 | return((this[j]&(1<<(n%this.DB)))!=0); 236 | } 237 | 238 | // (protected) this op (1<>= this.DB; 261 | } 262 | if(a.t < this.t) { 263 | c += a.s; 264 | while(i < this.t) { 265 | c += this[i]; 266 | r[i++] = c&this.DM; 267 | c >>= this.DB; 268 | } 269 | c += this.s; 270 | } 271 | else { 272 | c += this.s; 273 | while(i < a.t) { 274 | c += a[i]; 275 | r[i++] = c&this.DM; 276 | c >>= this.DB; 277 | } 278 | c += a.s; 279 | } 280 | r.s = (c<0)?-1:0; 281 | if(c > 0) r[i++] = c; 282 | else if(c < -1) r[i++] = this.DV+c; 283 | r.t = i; 284 | r.clamp(); 285 | } 286 | 287 | // (public) this + a 288 | function bnAdd(a) { var r = nbi(); this.addTo(a,r); return r; } 289 | 290 | // (public) this - a 291 | function bnSubtract(a) { var r = nbi(); this.subTo(a,r); return r; } 292 | 293 | // (public) this * a 294 | function bnMultiply(a) { var r = nbi(); this.multiplyTo(a,r); return r; } 295 | 296 | // (public) this^2 297 | function bnSquare() { var r = nbi(); this.squareTo(r); return r; } 298 | 299 | // (public) this / a 300 | function bnDivide(a) { var r = nbi(); this.divRemTo(a,r,null); return r; } 301 | 302 | // (public) this % a 303 | function bnRemainder(a) { var r = nbi(); this.divRemTo(a,null,r); return r; } 304 | 305 | // (public) [this/a,this%a] 306 | function bnDivideAndRemainder(a) { 307 | var q = nbi(), r = nbi(); 308 | this.divRemTo(a,q,r); 309 | return new Array(q,r); 310 | } 311 | 312 | // (protected) this *= n, this >= 0, 1 < n < DV 313 | function bnpDMultiply(n) { 314 | this[this.t] = this.am(0,n-1,this,0,0,this.t); 315 | ++this.t; 316 | this.clamp(); 317 | } 318 | 319 | // (protected) this += n << w words, this >= 0 320 | function bnpDAddOffset(n,w) { 321 | if(n == 0) return; 322 | while(this.t <= w) this[this.t++] = 0; 323 | this[w] += n; 324 | while(this[w] >= this.DV) { 325 | this[w] -= this.DV; 326 | if(++w >= this.t) this[this.t++] = 0; 327 | ++this[w]; 328 | } 329 | } 330 | 331 | // A "null" reducer 332 | function NullExp() {} 333 | function nNop(x) { return x; } 334 | function nMulTo(x,y,r) { x.multiplyTo(y,r); } 335 | function nSqrTo(x,r) { x.squareTo(r); } 336 | 337 | NullExp.prototype.convert = nNop; 338 | NullExp.prototype.revert = nNop; 339 | NullExp.prototype.mulTo = nMulTo; 340 | NullExp.prototype.sqrTo = nSqrTo; 341 | 342 | // (public) this^e 343 | function bnPow(e) { return this.exp(e,new NullExp()); } 344 | 345 | // (protected) r = lower n words of "this * a", a.t <= n 346 | // "this" should be the larger one if appropriate. 347 | function bnpMultiplyLowerTo(a,n,r) { 348 | var i = Math.min(this.t+a.t,n); 349 | r.s = 0; // assumes a,this >= 0 350 | r.t = i; 351 | while(i > 0) r[--i] = 0; 352 | var j; 353 | for(j = r.t-this.t; i < j; ++i) r[i+this.t] = this.am(0,a[i],r,i,0,this.t); 354 | for(j = Math.min(a.t,n); i < j; ++i) this.am(0,a[i],r,i,0,n-i); 355 | r.clamp(); 356 | } 357 | 358 | // (protected) r = "this * a" without lower n words, n > 0 359 | // "this" should be the larger one if appropriate. 360 | function bnpMultiplyUpperTo(a,n,r) { 361 | --n; 362 | var i = r.t = this.t+a.t-n; 363 | r.s = 0; // assumes a,this >= 0 364 | while(--i >= 0) r[i] = 0; 365 | for(i = Math.max(n-this.t,0); i < a.t; ++i) 366 | r[this.t+i-n] = this.am(n-i,a[i],r,0,0,this.t+i-n); 367 | r.clamp(); 368 | r.drShiftTo(1,r); 369 | } 370 | 371 | // Barrett modular reduction 372 | function Barrett(m) { 373 | // setup Barrett 374 | this.r2 = nbi(); 375 | this.q3 = nbi(); 376 | BigInteger.ONE.dlShiftTo(2*m.t,this.r2); 377 | this.mu = this.r2.divide(m); 378 | this.m = m; 379 | } 380 | 381 | function barrettConvert(x) { 382 | if(x.s < 0 || x.t > 2*this.m.t) return x.mod(this.m); 383 | else if(x.compareTo(this.m) < 0) return x; 384 | else { var r = nbi(); x.copyTo(r); this.reduce(r); return r; } 385 | } 386 | 387 | function barrettRevert(x) { return x; } 388 | 389 | // x = x mod m (HAC 14.42) 390 | function barrettReduce(x) { 391 | x.drShiftTo(this.m.t-1,this.r2); 392 | if(x.t > this.m.t+1) { x.t = this.m.t+1; x.clamp(); } 393 | this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3); 394 | this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2); 395 | while(x.compareTo(this.r2) < 0) x.dAddOffset(1,this.m.t+1); 396 | x.subTo(this.r2,x); 397 | while(x.compareTo(this.m) >= 0) x.subTo(this.m,x); 398 | } 399 | 400 | // r = x^2 mod m; x != r 401 | function barrettSqrTo(x,r) { x.squareTo(r); this.reduce(r); } 402 | 403 | // r = x*y mod m; x,y != r 404 | function barrettMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); } 405 | 406 | Barrett.prototype.convert = barrettConvert; 407 | Barrett.prototype.revert = barrettRevert; 408 | Barrett.prototype.reduce = barrettReduce; 409 | Barrett.prototype.mulTo = barrettMulTo; 410 | Barrett.prototype.sqrTo = barrettSqrTo; 411 | 412 | // (public) this^e % m (HAC 14.85) 413 | function bnModPow(e,m) { 414 | var i = e.bitLength(), k, r = nbv(1), z; 415 | if(i <= 0) return r; 416 | else if(i < 18) k = 1; 417 | else if(i < 48) k = 3; 418 | else if(i < 144) k = 4; 419 | else if(i < 768) k = 5; 420 | else k = 6; 421 | if(i < 8) 422 | z = new Classic(m); 423 | else if(m.isEven()) 424 | z = new Barrett(m); 425 | else 426 | z = new Montgomery(m); 427 | 428 | // precomputation 429 | var g = new Array(), n = 3, k1 = k-1, km = (1< 1) { 432 | var g2 = nbi(); 433 | z.sqrTo(g[1],g2); 434 | while(n <= km) { 435 | g[n] = nbi(); 436 | z.mulTo(g2,g[n-2],g[n]); 437 | n += 2; 438 | } 439 | } 440 | 441 | var j = e.t-1, w, is1 = true, r2 = nbi(), t; 442 | i = nbits(e[j])-1; 443 | while(j >= 0) { 444 | if(i >= k1) w = (e[j]>>(i-k1))&km; 445 | else { 446 | w = (e[j]&((1<<(i+1))-1))<<(k1-i); 447 | if(j > 0) w |= e[j-1]>>(this.DB+i-k1); 448 | } 449 | 450 | n = k; 451 | while((w&1) == 0) { w >>= 1; --n; } 452 | if((i -= n) < 0) { i += this.DB; --j; } 453 | if(is1) { // ret == 1, don't bother squaring or multiplying it 454 | g[w].copyTo(r); 455 | is1 = false; 456 | } 457 | else { 458 | while(n > 1) { z.sqrTo(r,r2); z.sqrTo(r2,r); n -= 2; } 459 | if(n > 0) z.sqrTo(r,r2); else { t = r; r = r2; r2 = t; } 460 | z.mulTo(r2,g[w],r); 461 | } 462 | 463 | while(j >= 0 && (e[j]&(1< 0) { 480 | x.rShiftTo(g,x); 481 | y.rShiftTo(g,y); 482 | } 483 | while(x.signum() > 0) { 484 | if((i = x.getLowestSetBit()) > 0) x.rShiftTo(i,x); 485 | if((i = y.getLowestSetBit()) > 0) y.rShiftTo(i,y); 486 | if(x.compareTo(y) >= 0) { 487 | x.subTo(y,x); 488 | x.rShiftTo(1,x); 489 | } 490 | else { 491 | y.subTo(x,y); 492 | y.rShiftTo(1,y); 493 | } 494 | } 495 | if(g > 0) y.lShiftTo(g,y); 496 | return y; 497 | } 498 | 499 | // (protected) this % n, n < 2^26 500 | function bnpModInt(n) { 501 | if(n <= 0) return 0; 502 | var d = this.DV%n, r = (this.s<0)?n-1:0; 503 | if(this.t > 0) 504 | if(d == 0) r = this[0]%n; 505 | else for(var i = this.t-1; i >= 0; --i) r = (d*r+this[i])%n; 506 | return r; 507 | } 508 | 509 | // (public) 1/this % m (HAC 14.61) 510 | function bnModInverse(m) { 511 | var ac = m.isEven(); 512 | if((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO; 513 | var u = m.clone(), v = this.clone(); 514 | var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1); 515 | while(u.signum() != 0) { 516 | while(u.isEven()) { 517 | u.rShiftTo(1,u); 518 | if(ac) { 519 | if(!a.isEven() || !b.isEven()) { a.addTo(this,a); b.subTo(m,b); } 520 | a.rShiftTo(1,a); 521 | } 522 | else if(!b.isEven()) b.subTo(m,b); 523 | b.rShiftTo(1,b); 524 | } 525 | while(v.isEven()) { 526 | v.rShiftTo(1,v); 527 | if(ac) { 528 | if(!c.isEven() || !d.isEven()) { c.addTo(this,c); d.subTo(m,d); } 529 | c.rShiftTo(1,c); 530 | } 531 | else if(!d.isEven()) d.subTo(m,d); 532 | d.rShiftTo(1,d); 533 | } 534 | if(u.compareTo(v) >= 0) { 535 | u.subTo(v,u); 536 | if(ac) a.subTo(c,a); 537 | b.subTo(d,b); 538 | } 539 | else { 540 | v.subTo(u,v); 541 | if(ac) c.subTo(a,c); 542 | d.subTo(b,d); 543 | } 544 | } 545 | if(v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO; 546 | if(d.compareTo(m) >= 0) return d.subtract(m); 547 | if(d.signum() < 0) d.addTo(m,d); else return d; 548 | if(d.signum() < 0) return d.add(m); else return d; 549 | } 550 | 551 | var lowprimes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997]; 552 | var lplim = (1<<26)/lowprimes[lowprimes.length-1]; 553 | 554 | // (public) test primality with certainty >= 1-.5^t 555 | function bnIsProbablePrime(t) { 556 | var i, x = this.abs(); 557 | if(x.t == 1 && x[0] <= lowprimes[lowprimes.length-1]) { 558 | for(i = 0; i < lowprimes.length; ++i) 559 | if(x[0] == lowprimes[i]) return true; 560 | return false; 561 | } 562 | if(x.isEven()) return false; 563 | i = 1; 564 | while(i < lowprimes.length) { 565 | var m = lowprimes[i], j = i+1; 566 | while(j < lowprimes.length && m < lplim) m *= lowprimes[j++]; 567 | m = x.modInt(m); 568 | while(i < j) if(m%lowprimes[i++] == 0) return false; 569 | } 570 | return x.millerRabin(t); 571 | } 572 | 573 | // (protected) true if probably prime (HAC 4.24, Miller-Rabin) 574 | function bnpMillerRabin(t) { 575 | var n1 = this.subtract(BigInteger.ONE); 576 | var k = n1.getLowestSetBit(); 577 | if(k <= 0) return false; 578 | var r = n1.shiftRight(k); 579 | t = (t+1)>>1; 580 | if(t > lowprimes.length) t = lowprimes.length; 581 | var a = nbi(); 582 | for(var i = 0; i < t; ++i) { 583 | //Pick bases at random, instead of starting at 2 584 | a.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]); 585 | var y = a.modPow(r,this); 586 | if(y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) { 587 | var j = 1; 588 | while(j++ < k && y.compareTo(n1) != 0) { 589 | y = y.modPowInt(2,this); 590 | if(y.compareTo(BigInteger.ONE) == 0) return false; 591 | } 592 | if(y.compareTo(n1) != 0) return false; 593 | } 594 | } 595 | return true; 596 | } 597 | 598 | // protected 599 | BigInteger.prototype.chunkSize = bnpChunkSize; 600 | BigInteger.prototype.toRadix = bnpToRadix; 601 | BigInteger.prototype.fromRadix = bnpFromRadix; 602 | BigInteger.prototype.fromNumber = bnpFromNumber; 603 | BigInteger.prototype.bitwiseTo = bnpBitwiseTo; 604 | BigInteger.prototype.changeBit = bnpChangeBit; 605 | BigInteger.prototype.addTo = bnpAddTo; 606 | BigInteger.prototype.dMultiply = bnpDMultiply; 607 | BigInteger.prototype.dAddOffset = bnpDAddOffset; 608 | BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo; 609 | BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo; 610 | BigInteger.prototype.modInt = bnpModInt; 611 | BigInteger.prototype.millerRabin = bnpMillerRabin; 612 | 613 | // public 614 | BigInteger.prototype.clone = bnClone; 615 | BigInteger.prototype.intValue = bnIntValue; 616 | BigInteger.prototype.byteValue = bnByteValue; 617 | BigInteger.prototype.shortValue = bnShortValue; 618 | BigInteger.prototype.signum = bnSigNum; 619 | BigInteger.prototype.toByteArray = bnToByteArray; 620 | BigInteger.prototype.equals = bnEquals; 621 | BigInteger.prototype.min = bnMin; 622 | BigInteger.prototype.max = bnMax; 623 | BigInteger.prototype.and = bnAnd; 624 | BigInteger.prototype.or = bnOr; 625 | BigInteger.prototype.xor = bnXor; 626 | BigInteger.prototype.andNot = bnAndNot; 627 | BigInteger.prototype.not = bnNot; 628 | BigInteger.prototype.shiftLeft = bnShiftLeft; 629 | BigInteger.prototype.shiftRight = bnShiftRight; 630 | BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit; 631 | BigInteger.prototype.bitCount = bnBitCount; 632 | BigInteger.prototype.testBit = bnTestBit; 633 | BigInteger.prototype.setBit = bnSetBit; 634 | BigInteger.prototype.clearBit = bnClearBit; 635 | BigInteger.prototype.flipBit = bnFlipBit; 636 | BigInteger.prototype.add = bnAdd; 637 | BigInteger.prototype.subtract = bnSubtract; 638 | BigInteger.prototype.multiply = bnMultiply; 639 | BigInteger.prototype.divide = bnDivide; 640 | BigInteger.prototype.remainder = bnRemainder; 641 | BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder; 642 | BigInteger.prototype.modPow = bnModPow; 643 | BigInteger.prototype.modInverse = bnModInverse; 644 | BigInteger.prototype.pow = bnPow; 645 | BigInteger.prototype.gcd = bnGCD; 646 | BigInteger.prototype.isProbablePrime = bnIsProbablePrime; 647 | 648 | // JSBN-specific extension 649 | BigInteger.prototype.square = bnSquare; 650 | 651 | // BigInteger interfaces not implemented in jsbn: 652 | 653 | // BigInteger(int signum, byte[] magnitude) 654 | // double doubleValue() 655 | // float floatValue() 656 | // int hashCode() 657 | // long longValue() 658 | // static BigInteger valueOf(long val) 659 | -------------------------------------------------------------------------------- /js/ext/prng4.js: -------------------------------------------------------------------------------- 1 | /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ 2 | */ 3 | // prng4.js - uses Arcfour as a PRNG 4 | 5 | function Arcfour() { 6 | this.i = 0; 7 | this.j = 0; 8 | this.S = new Array(); 9 | } 10 | 11 | // Initialize arcfour context from key, an array of ints, each from [0..255] 12 | function ARC4init(key) { 13 | var i, j, t; 14 | for(i = 0; i < 256; ++i) 15 | this.S[i] = i; 16 | j = 0; 17 | for(i = 0; i < 256; ++i) { 18 | j = (j + this.S[i] + key[i % key.length]) & 255; 19 | t = this.S[i]; 20 | this.S[i] = this.S[j]; 21 | this.S[j] = t; 22 | } 23 | this.i = 0; 24 | this.j = 0; 25 | } 26 | 27 | function ARC4next() { 28 | var t; 29 | this.i = (this.i + 1) & 255; 30 | this.j = (this.j + this.S[this.i]) & 255; 31 | t = this.S[this.i]; 32 | this.S[this.i] = this.S[this.j]; 33 | this.S[this.j] = t; 34 | return this.S[(t + this.S[this.i]) & 255]; 35 | } 36 | 37 | Arcfour.prototype.init = ARC4init; 38 | Arcfour.prototype.next = ARC4next; 39 | 40 | // Plug in your RNG constructor here 41 | function prng_newstate() { 42 | return new Arcfour(); 43 | } 44 | 45 | // Pool size must be a multiple of 4 and greater than 32. 46 | // An array of bytes the size of the pool will be passed to init() 47 | var rng_psize = 256; 48 | -------------------------------------------------------------------------------- /js/ext/rng.js: -------------------------------------------------------------------------------- 1 | /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ 2 | */ 3 | // Random number generator - requires a PRNG backend, e.g. prng4.js 4 | 5 | // For best results, put code like 6 | // 7 | // in your main HTML document. 8 | 9 | var rng_state; 10 | var rng_pool; 11 | var rng_pptr; 12 | 13 | // Mix in a 32-bit integer into the pool 14 | function rng_seed_int(x) { 15 | rng_pool[rng_pptr++] ^= x & 255; 16 | rng_pool[rng_pptr++] ^= (x >> 8) & 255; 17 | rng_pool[rng_pptr++] ^= (x >> 16) & 255; 18 | rng_pool[rng_pptr++] ^= (x >> 24) & 255; 19 | if(rng_pptr >= rng_psize) rng_pptr -= rng_psize; 20 | } 21 | 22 | // Mix in the current time (w/milliseconds) into the pool 23 | function rng_seed_time() { 24 | rng_seed_int(new Date().getTime()); 25 | } 26 | 27 | // Initialize the pool with junk if needed. 28 | if(rng_pool == null) { 29 | rng_pool = new Array(); 30 | rng_pptr = 0; 31 | var t; 32 | if(navigator.appName == "Netscape" && navigator.appVersion < "5" && window.crypto) { 33 | // Extract entropy (256 bits) from NS4 RNG if available 34 | var z = window.crypto.random(32); 35 | for(t = 0; t < z.length; ++t) 36 | rng_pool[rng_pptr++] = z.charCodeAt(t) & 255; 37 | } 38 | while(rng_pptr < rng_psize) { // extract some randomness from Math.random() 39 | t = Math.floor(65536 * Math.random()); 40 | rng_pool[rng_pptr++] = t >>> 8; 41 | rng_pool[rng_pptr++] = t & 255; 42 | } 43 | rng_pptr = 0; 44 | rng_seed_time(); 45 | //rng_seed_int(window.screenX); 46 | //rng_seed_int(window.screenY); 47 | } 48 | 49 | function rng_get_byte() { 50 | if(rng_state == null) { 51 | rng_seed_time(); 52 | rng_state = prng_newstate(); 53 | rng_state.init(rng_pool); 54 | for(rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr) 55 | rng_pool[rng_pptr] = 0; 56 | rng_pptr = 0; 57 | //rng_pool = null; 58 | } 59 | // TODO: allow reseeding after first request 60 | return rng_state.next(); 61 | } 62 | 63 | function rng_get_bytes(ba) { 64 | var i; 65 | for(i = 0; i < ba.length; ++i) ba[i] = rng_get_byte(); 66 | } 67 | 68 | function SecureRandom() {} 69 | 70 | SecureRandom.prototype.nextBytes = rng_get_bytes; 71 | -------------------------------------------------------------------------------- /js/utils/byteUtil.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * 字节流转换工具js 4 | * 5 | */ 6 | 7 | /* 8 | * 数组复制 9 | */ 10 | function arrayCopy(src,pos1,dest,pos2,len){ 11 | var realLen = len; 12 | if(pos1+len>src.length&&pos2+len<=dest.length){ 13 | realLen = src.length-pos1; 14 | }else if(pos2+len>dest.length&&pos1+len<=src.length){ 15 | realLen = dest.length-pos2; 16 | }else if(pos1+len<=src.length&&pos2+len<=dest.length){ 17 | realLen = len; 18 | }else if(dest.length> 24)&0x000000FF, 41 | (num >> 16)&0x000000FF, 42 | (num >> 8)&0x000000FF, 43 | (num)&0x000000FF 44 | ); 45 | } 46 | 47 | /* 48 | * int数转成byte数组 49 | * 事实上只不过转成byte大小的数,实际占用空间还是4字节 50 | * 返回:字节数组 51 | */ 52 | function intToByte(num) { 53 | return new Array( 54 | (num >> 24)&0x000000FF, 55 | (num >> 16)&0x000000FF, 56 | (num >> 8)&0x000000FF, 57 | (num)&0x000000FF 58 | ); 59 | } 60 | 61 | /* 62 | * int数组转成byte数组,一个int数值转成四个byte 63 | * 返回:byte数组 64 | */ 65 | function intArrayToByteArray(nums) { 66 | var b = new Array(nums.length*4); 67 | 68 | for(var i = 0;i>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 217 | thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); 218 | } 219 | } else if (thatWords.length > 0xffff) { 220 | // Copy one word at a time 221 | for (var i = 0; i < thatSigBytes; i += 4) { 222 | thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; 223 | } 224 | } else { 225 | // Copy all words at once 226 | thisWords.push.apply(thisWords, thatWords); 227 | } 228 | this.sigBytes += thatSigBytes; 229 | 230 | // Chainable 231 | return this; 232 | }, 233 | 234 | /** 235 | * Removes insignificant bits. 236 | * 237 | * @example 238 | * 239 | * wordArray.clamp(); 240 | */ 241 | clamp: function () { 242 | // Shortcuts 243 | var words = this.words; 244 | var sigBytes = this.sigBytes; 245 | 246 | // Clamp 247 | words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); 248 | words.length = Math.ceil(sigBytes / 4); 249 | }, 250 | 251 | /** 252 | * Creates a copy of this word array. 253 | * 254 | * @return {WordArray} The clone. 255 | * 256 | * @example 257 | * 258 | * var clone = wordArray.clone(); 259 | */ 260 | clone: function () { 261 | var clone = Base.clone.call(this); 262 | clone.words = this.words.slice(0); 263 | 264 | return clone; 265 | }, 266 | 267 | /** 268 | * Creates a word array filled with random bytes. 269 | * 270 | * @param {number} nBytes The number of random bytes to generate. 271 | * 272 | * @return {WordArray} The random word array. 273 | * 274 | * @static 275 | * 276 | * @example 277 | * 278 | * var wordArray = CryptoJS.lib.WordArray.random(16); 279 | */ 280 | random: function (nBytes) { 281 | var words = []; 282 | for (var i = 0; i < nBytes; i += 4) { 283 | words.push((Math.random() * 0x100000000) | 0); 284 | } 285 | 286 | return new WordArray.init(words, nBytes); 287 | } 288 | }); 289 | 290 | /** 291 | * Encoder namespace. 292 | */ 293 | var C_enc = C.enc = {}; 294 | 295 | /** 296 | * Hex encoding strategy. 297 | */ 298 | var Hex = C_enc.Hex = { 299 | /** 300 | * Converts a word array to a hex string. 301 | * 302 | * @param {WordArray} wordArray The word array. 303 | * 304 | * @return {string} The hex string. 305 | * 306 | * @static 307 | * 308 | * @example 309 | * 310 | * var hexString = CryptoJS.enc.Hex.stringify(wordArray); 311 | */ 312 | stringify: function (wordArray) { 313 | // Shortcuts 314 | var words = wordArray.words; 315 | var sigBytes = wordArray.sigBytes; 316 | 317 | // Convert 318 | var hexChars = []; 319 | for (var i = 0; i < sigBytes; i++) { 320 | var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 321 | hexChars.push((bite >>> 4).toString(16)); 322 | hexChars.push((bite & 0x0f).toString(16)); 323 | } 324 | 325 | return hexChars.join(''); 326 | }, 327 | 328 | /** 329 | * Converts a hex string to a word array. 330 | * 331 | * @param {string} hexStr The hex string. 332 | * 333 | * @return {WordArray} The word array. 334 | * 335 | * @static 336 | * 337 | * @example 338 | * 339 | * var wordArray = CryptoJS.enc.Hex.parse(hexString); 340 | */ 341 | parse: function (hexStr) { 342 | // Shortcut 343 | var hexStrLength = hexStr.length; 344 | 345 | // Convert 346 | var words = []; 347 | for (var i = 0; i < hexStrLength; i += 2) { 348 | words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); 349 | } 350 | 351 | return new WordArray.init(words, hexStrLength / 2); 352 | } 353 | }; 354 | 355 | /** 356 | * Latin1 encoding strategy. 357 | */ 358 | var Latin1 = C_enc.Latin1 = { 359 | /** 360 | * Converts a word array to a Latin1 string. 361 | * 362 | * @param {WordArray} wordArray The word array. 363 | * 364 | * @return {string} The Latin1 string. 365 | * 366 | * @static 367 | * 368 | * @example 369 | * 370 | * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); 371 | */ 372 | stringify: function (wordArray) { 373 | // Shortcuts 374 | var words = wordArray.words; 375 | var sigBytes = wordArray.sigBytes; 376 | 377 | // Convert 378 | var latin1Chars = []; 379 | for (var i = 0; i < sigBytes; i++) { 380 | var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 381 | latin1Chars.push(String.fromCharCode(bite)); 382 | } 383 | 384 | return latin1Chars.join(''); 385 | }, 386 | 387 | /** 388 | * Converts a Latin1 string to a word array. 389 | * 390 | * @param {string} latin1Str The Latin1 string. 391 | * 392 | * @return {WordArray} The word array. 393 | * 394 | * @static 395 | * 396 | * @example 397 | * 398 | * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); 399 | */ 400 | parse: function (latin1Str) { 401 | // Shortcut 402 | var latin1StrLength = latin1Str.length; 403 | 404 | // Convert 405 | var words = []; 406 | for (var i = 0; i < latin1StrLength; i++) { 407 | words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); 408 | } 409 | 410 | return new WordArray.init(words, latin1StrLength); 411 | } 412 | }; 413 | 414 | /** 415 | * UTF-8 encoding strategy. 416 | */ 417 | var Utf8 = C_enc.Utf8 = { 418 | /** 419 | * Converts a word array to a UTF-8 string. 420 | * 421 | * @param {WordArray} wordArray The word array. 422 | * 423 | * @return {string} The UTF-8 string. 424 | * 425 | * @static 426 | * 427 | * @example 428 | * 429 | * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); 430 | */ 431 | stringify: function (wordArray) { 432 | try { 433 | return decodeURIComponent(escape(Latin1.stringify(wordArray))); 434 | } catch (e) { 435 | throw new Error('Malformed UTF-8 data'); 436 | } 437 | }, 438 | 439 | /** 440 | * Converts a UTF-8 string to a word array. 441 | * 442 | * @param {string} utf8Str The UTF-8 string. 443 | * 444 | * @return {WordArray} The word array. 445 | * 446 | * @static 447 | * 448 | * @example 449 | * 450 | * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); 451 | */ 452 | parse: function (utf8Str) { 453 | var ens = encodeURIComponent(utf8Str); 454 | var es = unescape(ens); 455 | return Latin1.parse(es); 456 | } 457 | }; 458 | 459 | /** 460 | * Abstract buffered block algorithm template. 461 | * 462 | * The property blockSize must be implemented in a concrete subtype. 463 | * 464 | * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 465 | */ 466 | var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ 467 | /** 468 | * Resets this block algorithm's data buffer to its initial state. 469 | * 470 | * @example 471 | * 472 | * bufferedBlockAlgorithm.reset(); 473 | */ 474 | reset: function () { 475 | // Initial values 476 | this._data = new WordArray.init(); 477 | this._nDataBytes = 0; 478 | }, 479 | 480 | /** 481 | * Adds new data to this block algorithm's buffer. 482 | * 483 | * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. 484 | * 485 | * @example 486 | * 487 | * bufferedBlockAlgorithm._append('data'); 488 | * bufferedBlockAlgorithm._append(wordArray); 489 | */ 490 | _append: function (data) { 491 | // Convert string to WordArray, else assume WordArray already 492 | if (typeof data == 'string') { 493 | data = Utf8.parse(data); 494 | } 495 | 496 | // Append 497 | this._data.concat(data); 498 | this._nDataBytes += data.sigBytes; 499 | }, 500 | 501 | /** 502 | * Processes available data blocks. 503 | * 504 | * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. 505 | * 506 | * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. 507 | * 508 | * @return {WordArray} The processed data. 509 | * 510 | * @example 511 | * 512 | * var processedData = bufferedBlockAlgorithm._process(); 513 | * var processedData = bufferedBlockAlgorithm._process(!!'flush'); 514 | */ 515 | _process: function (doFlush) { 516 | // Shortcuts 517 | var data = this._data; 518 | var dataWords = data.words; 519 | var dataSigBytes = data.sigBytes; 520 | var blockSize = this.blockSize; 521 | var blockSizeBytes = blockSize * 4; 522 | 523 | // Count blocks ready 524 | var nBlocksReady = dataSigBytes / blockSizeBytes; 525 | if (doFlush) { 526 | // Round up to include partial blocks 527 | nBlocksReady = Math.ceil(nBlocksReady); 528 | } else { 529 | // Round down to include only full blocks, 530 | // less the number of blocks that must remain in the buffer 531 | nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); 532 | } 533 | 534 | // Count words ready 535 | var nWordsReady = nBlocksReady * blockSize; 536 | 537 | // Count bytes ready 538 | var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); 539 | 540 | // Process blocks 541 | if (nWordsReady) { 542 | for (var offset = 0; offset < nWordsReady; offset += blockSize) { 543 | // Perform concrete-algorithm logic 544 | this._doProcessBlock(dataWords, offset); 545 | } 546 | 547 | // Remove processed words 548 | var processedWords = dataWords.splice(0, nWordsReady); 549 | data.sigBytes -= nBytesReady; 550 | } 551 | 552 | // Return processed words 553 | return new WordArray.init(processedWords, nBytesReady); 554 | }, 555 | 556 | /** 557 | * Creates a copy of this object. 558 | * 559 | * @return {Object} The clone. 560 | * 561 | * @example 562 | * 563 | * var clone = bufferedBlockAlgorithm.clone(); 564 | */ 565 | clone: function () { 566 | var clone = Base.clone.call(this); 567 | clone._data = this._data.clone(); 568 | 569 | return clone; 570 | }, 571 | 572 | _minBufferSize: 0 573 | }); 574 | 575 | /** 576 | * Abstract hasher template. 577 | * 578 | * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) 579 | */ 580 | var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ 581 | /** 582 | * Configuration options. 583 | */ 584 | cfg: Base.extend(), 585 | 586 | /** 587 | * Initializes a newly created hasher. 588 | * 589 | * @param {Object} cfg (Optional) The configuration options to use for this hash computation. 590 | * 591 | * @example 592 | * 593 | * var hasher = CryptoJS.algo.SHA256.create(); 594 | */ 595 | init: function (cfg) { 596 | // Apply config defaults 597 | this.cfg = this.cfg.extend(cfg); 598 | 599 | // Set initial values 600 | this.reset(); 601 | }, 602 | 603 | /** 604 | * Resets this hasher to its initial state. 605 | * 606 | * @example 607 | * 608 | * hasher.reset(); 609 | */ 610 | reset: function () { 611 | // Reset data buffer 612 | BufferedBlockAlgorithm.reset.call(this); 613 | 614 | // Perform concrete-hasher logic 615 | this._doReset(); 616 | }, 617 | 618 | /** 619 | * Updates this hasher with a message. 620 | * 621 | * @param {WordArray|string} messageUpdate The message to append. 622 | * 623 | * @return {Hasher} This hasher. 624 | * 625 | * @example 626 | * 627 | * hasher.update('message'); 628 | * hasher.update(wordArray); 629 | */ 630 | update: function (messageUpdate) { 631 | // Append 632 | this._append(messageUpdate); 633 | 634 | // Update the hash 635 | this._process(); 636 | 637 | // Chainable 638 | return this; 639 | }, 640 | 641 | /** 642 | * Finalizes the hash computation. 643 | * Note that the finalize operation is effectively a destructive, read-once operation. 644 | * 645 | * @param {WordArray|string} messageUpdate (Optional) A final message update. 646 | * 647 | * @return {WordArray} The hash. 648 | * 649 | * @example 650 | * 651 | * var hash = hasher.finalize(); 652 | * var hash = hasher.finalize('message'); 653 | * var hash = hasher.finalize(wordArray); 654 | */ 655 | finalize: function (messageUpdate) { 656 | // Final message update 657 | if (messageUpdate) { 658 | this._append(messageUpdate); 659 | } 660 | 661 | // Perform concrete-hasher logic 662 | var hash = this._doFinalize(); 663 | 664 | return hash; 665 | }, 666 | 667 | blockSize: 512/32, 668 | 669 | /** 670 | * Creates a shortcut function to a hasher's object interface. 671 | * 672 | * @param {Hasher} hasher The hasher to create a helper for. 673 | * 674 | * @return {Function} The shortcut function. 675 | * 676 | * @static 677 | * 678 | * @example 679 | * 680 | * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); 681 | */ 682 | _createHelper: function (hasher) { 683 | return function (message, cfg) { 684 | return new hasher.init(cfg).finalize(message); 685 | }; 686 | }, 687 | 688 | /** 689 | * Creates a shortcut function to the HMAC's object interface. 690 | * 691 | * @param {Hasher} hasher The hasher to use in this HMAC helper. 692 | * 693 | * @return {Function} The shortcut function. 694 | * 695 | * @static 696 | * 697 | * @example 698 | * 699 | * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); 700 | */ 701 | _createHmacHelper: function (hasher) { 702 | return function (message, key) { 703 | return new C_algo.HMAC.init(hasher, key).finalize(message); 704 | }; 705 | } 706 | }); 707 | 708 | /** 709 | * Algorithm namespace. 710 | */ 711 | var C_algo = C.algo = {}; 712 | 713 | return C; 714 | }(Math)); 715 | -------------------------------------------------------------------------------- /js/utils/hex.js: -------------------------------------------------------------------------------- 1 | function Hex(){ 2 | 3 | } 4 | 5 | Hex.encode = function(b,pos,len) { 6 | var hexCh = new Array(len*2); 7 | var hexCode = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); 8 | 9 | for(var i = pos,j = 0;i>4]; 11 | hexCh[++j] = hexCode[(b[i]&0x0F)]; 12 | } 13 | 14 | return hexCh.join(''); 15 | } 16 | 17 | Hex.decode = function(hex) { 18 | 19 | if(hex == null || hex == '') { 20 | return null; 21 | } 22 | if(hex.length%2 != 0) { 23 | return null; 24 | } 25 | 26 | var ascLen = hex.length/2; 27 | var hexCh = this.toCharCodeArray(hex); 28 | var asc = new Array(ascLen); 29 | 30 | for(var i = 0;i=0x30 && hexCh[2*i]<=0x39) { 33 | asc[i] = ((hexCh[2*i]-0x30)<<4); 34 | }else if(hexCh[2*i]>=0x41 && hexCh[2*i]<=0x46) {//A-F : 0x41-0x46 35 | asc[i] = ((hexCh[2*i]-0x41+10)<<4); 36 | }else if(hexCh[2*i]>=0x61 && hexCh[2*i]<=0x66) {//a-f : 0x61-0x66 37 | asc[i] = ((hexCh[2*i]-0x61+10)<<4); 38 | }else { 39 | return null; 40 | } 41 | 42 | if(hexCh[2*i+1]>=0x30 && hexCh[2*i+1]<=0x39) { 43 | asc[i] = (asc[i] | (hexCh[2*i+1]-0x30)); 44 | }else if(hexCh[2*i+1]>=0x41 && hexCh[2*i+1]<=0x46) { 45 | asc[i] = (asc[i] | (hexCh[2*i+1]-0x41+10)); 46 | }else if(hexCh[2*i+1]>=0x61 && hexCh[2*i+1]<=0x66) { 47 | asc[i] = (asc[i] | (hexCh[2*i+1]-0x61+10)); 48 | }else { 49 | return null; 50 | } 51 | 52 | 53 | } 54 | 55 | return asc; 56 | } 57 | 58 | Hex.utf8StrToHex = function(utf8Str){ 59 | var ens = encodeURIComponent(utf8Str); 60 | var es = unescape(ens); 61 | 62 | 63 | var esLen = es.length; 64 | 65 | // Convert 66 | var words = []; 67 | for (var i = 0; i < esLen; i++) { 68 | words[i] = (es.charCodeAt(i).toString(16)); 69 | } 70 | return words.join(''); 71 | } 72 | 73 | Hex.utf8StrToBytes = function(utf8Str){ 74 | var ens = encodeURIComponent(utf8Str); 75 | var es = unescape(ens); 76 | 77 | 78 | var esLen = es.length; 79 | 80 | // Convert 81 | var words = []; 82 | for (var i = 0; i < esLen; i++) { 83 | words[i] = es.charCodeAt(i); 84 | } 85 | return words; 86 | } 87 | 88 | Hex.hexToUtf8Str = function(utf8Str){ 89 | 90 | var utf8Byte = Hex.decode(utf8Str); 91 | var latin1Chars = []; 92 | for (var i = 0; i < utf8Byte.length; i++) { 93 | latin1Chars.push(String.fromCharCode(utf8Byte[i])); 94 | } 95 | return decodeURIComponent(escape(latin1Chars.join(''))); 96 | } 97 | 98 | Hex.bytesToUtf8Str = function(bytesArray){ 99 | 100 | var utf8Byte = bytesArray; 101 | var latin1Chars = []; 102 | for (var i = 0; i < utf8Byte.length; i++) { 103 | latin1Chars.push(String.fromCharCode(utf8Byte[i])); 104 | } 105 | return decodeURIComponent(escape(latin1Chars.join(''))); 106 | } 107 | 108 | Hex.toCharCodeArray = function(chs){ 109 | var chArr = new Array(chs.length); 110 | for(var i = 0;i=0&&n0&&t-1 in e)}var E=function(e){var t,n,r,i,o,a,s,u,l,c,f,p,d,h,g,y,v,m,x,b="sizzle"+1*new Date,w=e.document,T=0,C=0,E=ae(),k=ae(),S=ae(),D=function(e,t){return e===t&&(f=!0),0},N={}.hasOwnProperty,A=[],j=A.pop,q=A.push,L=A.push,H=A.slice,O=function(e,t){for(var n=0,r=e.length;n+~]|"+M+")"+M+"*"),z=new RegExp("="+M+"*([^\\]'\"]*?)"+M+"*\\]","g"),X=new RegExp(W),U=new RegExp("^"+R+"$"),V={ID:new RegExp("^#("+R+")"),CLASS:new RegExp("^\\.("+R+")"),TAG:new RegExp("^("+R+"|[*])"),ATTR:new RegExp("^"+I),PSEUDO:new RegExp("^"+W),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+P+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},G=/^(?:input|select|textarea|button)$/i,Y=/^h\d$/i,Q=/^[^{]+\{\s*\[native \w/,J=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,K=/[+~]/,Z=new RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),ee=function(e,t,n){var r="0x"+t-65536;return r!==r||n?t:r<0?String.fromCharCode(r+65536):String.fromCharCode(r>>10|55296,1023&r|56320)},te=/([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-\uFFFF\w-]/g,ne=function(e,t){return t?"\0"===e?"\ufffd":e.slice(0,-1)+"\\"+e.charCodeAt(e.length-1).toString(16)+" ":"\\"+e},re=function(){p()},ie=me(function(e){return!0===e.disabled&&("form"in e||"label"in e)},{dir:"parentNode",next:"legend"});try{L.apply(A=H.call(w.childNodes),w.childNodes),A[w.childNodes.length].nodeType}catch(e){L={apply:A.length?function(e,t){q.apply(e,H.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function oe(e,t,r,i){var o,s,l,c,f,h,v,m=t&&t.ownerDocument,T=t?t.nodeType:9;if(r=r||[],"string"!=typeof e||!e||1!==T&&9!==T&&11!==T)return r;if(!i&&((t?t.ownerDocument||t:w)!==d&&p(t),t=t||d,g)){if(11!==T&&(f=J.exec(e)))if(o=f[1]){if(9===T){if(!(l=t.getElementById(o)))return r;if(l.id===o)return r.push(l),r}else if(m&&(l=m.getElementById(o))&&x(t,l)&&l.id===o)return r.push(l),r}else{if(f[2])return L.apply(r,t.getElementsByTagName(e)),r;if((o=f[3])&&n.getElementsByClassName&&t.getElementsByClassName)return L.apply(r,t.getElementsByClassName(o)),r}if(n.qsa&&!S[e+" "]&&(!y||!y.test(e))){if(1!==T)m=t,v=e;else if("object"!==t.nodeName.toLowerCase()){(c=t.getAttribute("id"))?c=c.replace(te,ne):t.setAttribute("id",c=b),s=(h=a(e)).length;while(s--)h[s]="#"+c+" "+ve(h[s]);v=h.join(","),m=K.test(e)&&ge(t.parentNode)||t}if(v)try{return L.apply(r,m.querySelectorAll(v)),r}catch(e){}finally{c===b&&t.removeAttribute("id")}}}return u(e.replace(B,"$1"),t,r,i)}function ae(){var e=[];function t(n,i){return e.push(n+" ")>r.cacheLength&&delete t[e.shift()],t[n+" "]=i}return t}function se(e){return e[b]=!0,e}function ue(e){var t=d.createElement("fieldset");try{return!!e(t)}catch(e){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function le(e,t){var n=e.split("|"),i=n.length;while(i--)r.attrHandle[n[i]]=t}function ce(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&e.sourceIndex-t.sourceIndex;if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function fe(e){return function(t){return"input"===t.nodeName.toLowerCase()&&t.type===e}}function pe(e){return function(t){var n=t.nodeName.toLowerCase();return("input"===n||"button"===n)&&t.type===e}}function de(e){return function(t){return"form"in t?t.parentNode&&!1===t.disabled?"label"in t?"label"in t.parentNode?t.parentNode.disabled===e:t.disabled===e:t.isDisabled===e||t.isDisabled!==!e&&ie(t)===e:t.disabled===e:"label"in t&&t.disabled===e}}function he(e){return se(function(t){return t=+t,se(function(n,r){var i,o=e([],n.length,t),a=o.length;while(a--)n[i=o[a]]&&(n[i]=!(r[i]=n[i]))})})}function ge(e){return e&&"undefined"!=typeof e.getElementsByTagName&&e}n=oe.support={},o=oe.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return!!t&&"HTML"!==t.nodeName},p=oe.setDocument=function(e){var t,i,a=e?e.ownerDocument||e:w;return a!==d&&9===a.nodeType&&a.documentElement?(d=a,h=d.documentElement,g=!o(d),w!==d&&(i=d.defaultView)&&i.top!==i&&(i.addEventListener?i.addEventListener("unload",re,!1):i.attachEvent&&i.attachEvent("onunload",re)),n.attributes=ue(function(e){return e.className="i",!e.getAttribute("className")}),n.getElementsByTagName=ue(function(e){return e.appendChild(d.createComment("")),!e.getElementsByTagName("*").length}),n.getElementsByClassName=Q.test(d.getElementsByClassName),n.getById=ue(function(e){return h.appendChild(e).id=b,!d.getElementsByName||!d.getElementsByName(b).length}),n.getById?(r.filter.ID=function(e){var t=e.replace(Z,ee);return function(e){return e.getAttribute("id")===t}},r.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&g){var n=t.getElementById(e);return n?[n]:[]}}):(r.filter.ID=function(e){var t=e.replace(Z,ee);return function(e){var n="undefined"!=typeof e.getAttributeNode&&e.getAttributeNode("id");return n&&n.value===t}},r.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&g){var n,r,i,o=t.getElementById(e);if(o){if((n=o.getAttributeNode("id"))&&n.value===e)return[o];i=t.getElementsByName(e),r=0;while(o=i[r++])if((n=o.getAttributeNode("id"))&&n.value===e)return[o]}return[]}}),r.find.TAG=n.getElementsByTagName?function(e,t){return"undefined"!=typeof t.getElementsByTagName?t.getElementsByTagName(e):n.qsa?t.querySelectorAll(e):void 0}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},r.find.CLASS=n.getElementsByClassName&&function(e,t){if("undefined"!=typeof t.getElementsByClassName&&g)return t.getElementsByClassName(e)},v=[],y=[],(n.qsa=Q.test(d.querySelectorAll))&&(ue(function(e){h.appendChild(e).innerHTML="",e.querySelectorAll("[msallowcapture^='']").length&&y.push("[*^$]="+M+"*(?:''|\"\")"),e.querySelectorAll("[selected]").length||y.push("\\["+M+"*(?:value|"+P+")"),e.querySelectorAll("[id~="+b+"-]").length||y.push("~="),e.querySelectorAll(":checked").length||y.push(":checked"),e.querySelectorAll("a#"+b+"+*").length||y.push(".#.+[+~]")}),ue(function(e){e.innerHTML="";var t=d.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("name","D"),e.querySelectorAll("[name=d]").length&&y.push("name"+M+"*[*^$|!~]?="),2!==e.querySelectorAll(":enabled").length&&y.push(":enabled",":disabled"),h.appendChild(e).disabled=!0,2!==e.querySelectorAll(":disabled").length&&y.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),y.push(",.*:")})),(n.matchesSelector=Q.test(m=h.matches||h.webkitMatchesSelector||h.mozMatchesSelector||h.oMatchesSelector||h.msMatchesSelector))&&ue(function(e){n.disconnectedMatch=m.call(e,"*"),m.call(e,"[s!='']:x"),v.push("!=",W)}),y=y.length&&new RegExp(y.join("|")),v=v.length&&new RegExp(v.join("|")),t=Q.test(h.compareDocumentPosition),x=t||Q.test(h.contains)?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},D=t?function(e,t){if(e===t)return f=!0,0;var r=!e.compareDocumentPosition-!t.compareDocumentPosition;return r||(1&(r=(e.ownerDocument||e)===(t.ownerDocument||t)?e.compareDocumentPosition(t):1)||!n.sortDetached&&t.compareDocumentPosition(e)===r?e===d||e.ownerDocument===w&&x(w,e)?-1:t===d||t.ownerDocument===w&&x(w,t)?1:c?O(c,e)-O(c,t):0:4&r?-1:1)}:function(e,t){if(e===t)return f=!0,0;var n,r=0,i=e.parentNode,o=t.parentNode,a=[e],s=[t];if(!i||!o)return e===d?-1:t===d?1:i?-1:o?1:c?O(c,e)-O(c,t):0;if(i===o)return ce(e,t);n=e;while(n=n.parentNode)a.unshift(n);n=t;while(n=n.parentNode)s.unshift(n);while(a[r]===s[r])r++;return r?ce(a[r],s[r]):a[r]===w?-1:s[r]===w?1:0},d):d},oe.matches=function(e,t){return oe(e,null,null,t)},oe.matchesSelector=function(e,t){if((e.ownerDocument||e)!==d&&p(e),t=t.replace(z,"='$1']"),n.matchesSelector&&g&&!S[t+" "]&&(!v||!v.test(t))&&(!y||!y.test(t)))try{var r=m.call(e,t);if(r||n.disconnectedMatch||e.document&&11!==e.document.nodeType)return r}catch(e){}return oe(t,d,null,[e]).length>0},oe.contains=function(e,t){return(e.ownerDocument||e)!==d&&p(e),x(e,t)},oe.attr=function(e,t){(e.ownerDocument||e)!==d&&p(e);var i=r.attrHandle[t.toLowerCase()],o=i&&N.call(r.attrHandle,t.toLowerCase())?i(e,t,!g):void 0;return void 0!==o?o:n.attributes||!g?e.getAttribute(t):(o=e.getAttributeNode(t))&&o.specified?o.value:null},oe.escape=function(e){return(e+"").replace(te,ne)},oe.error=function(e){throw new Error("Syntax error, unrecognized expression: "+e)},oe.uniqueSort=function(e){var t,r=[],i=0,o=0;if(f=!n.detectDuplicates,c=!n.sortStable&&e.slice(0),e.sort(D),f){while(t=e[o++])t===e[o]&&(i=r.push(o));while(i--)e.splice(r[i],1)}return c=null,e},i=oe.getText=function(e){var t,n="",r=0,o=e.nodeType;if(o){if(1===o||9===o||11===o){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=i(e)}else if(3===o||4===o)return e.nodeValue}else while(t=e[r++])n+=i(t);return n},(r=oe.selectors={cacheLength:50,createPseudo:se,match:V,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(Z,ee),e[3]=(e[3]||e[4]||e[5]||"").replace(Z,ee),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||oe.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&oe.error(e[0]),e},PSEUDO:function(e){var t,n=!e[6]&&e[2];return V.CHILD.test(e[0])?null:(e[3]?e[2]=e[4]||e[5]||"":n&&X.test(n)&&(t=a(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(Z,ee).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=E[e+" "];return t||(t=new RegExp("(^|"+M+")"+e+"("+M+"|$)"))&&E(e,function(e){return t.test("string"==typeof e.className&&e.className||"undefined"!=typeof e.getAttribute&&e.getAttribute("class")||"")})},ATTR:function(e,t,n){return function(r){var i=oe.attr(r,e);return null==i?"!="===t:!t||(i+="","="===t?i===n:"!="===t?i!==n:"^="===t?n&&0===i.indexOf(n):"*="===t?n&&i.indexOf(n)>-1:"$="===t?n&&i.slice(-n.length)===n:"~="===t?(" "+i.replace($," ")+" ").indexOf(n)>-1:"|="===t&&(i===n||i.slice(0,n.length+1)===n+"-"))}},CHILD:function(e,t,n,r,i){var o="nth"!==e.slice(0,3),a="last"!==e.slice(-4),s="of-type"===t;return 1===r&&0===i?function(e){return!!e.parentNode}:function(t,n,u){var l,c,f,p,d,h,g=o!==a?"nextSibling":"previousSibling",y=t.parentNode,v=s&&t.nodeName.toLowerCase(),m=!u&&!s,x=!1;if(y){if(o){while(g){p=t;while(p=p[g])if(s?p.nodeName.toLowerCase()===v:1===p.nodeType)return!1;h=g="only"===e&&!h&&"nextSibling"}return!0}if(h=[a?y.firstChild:y.lastChild],a&&m){x=(d=(l=(c=(f=(p=y)[b]||(p[b]={}))[p.uniqueID]||(f[p.uniqueID]={}))[e]||[])[0]===T&&l[1])&&l[2],p=d&&y.childNodes[d];while(p=++d&&p&&p[g]||(x=d=0)||h.pop())if(1===p.nodeType&&++x&&p===t){c[e]=[T,d,x];break}}else if(m&&(x=d=(l=(c=(f=(p=t)[b]||(p[b]={}))[p.uniqueID]||(f[p.uniqueID]={}))[e]||[])[0]===T&&l[1]),!1===x)while(p=++d&&p&&p[g]||(x=d=0)||h.pop())if((s?p.nodeName.toLowerCase()===v:1===p.nodeType)&&++x&&(m&&((c=(f=p[b]||(p[b]={}))[p.uniqueID]||(f[p.uniqueID]={}))[e]=[T,x]),p===t))break;return(x-=i)===r||x%r==0&&x/r>=0}}},PSEUDO:function(e,t){var n,i=r.pseudos[e]||r.setFilters[e.toLowerCase()]||oe.error("unsupported pseudo: "+e);return i[b]?i(t):i.length>1?(n=[e,e,"",t],r.setFilters.hasOwnProperty(e.toLowerCase())?se(function(e,n){var r,o=i(e,t),a=o.length;while(a--)e[r=O(e,o[a])]=!(n[r]=o[a])}):function(e){return i(e,0,n)}):i}},pseudos:{not:se(function(e){var t=[],n=[],r=s(e.replace(B,"$1"));return r[b]?se(function(e,t,n,i){var o,a=r(e,null,i,[]),s=e.length;while(s--)(o=a[s])&&(e[s]=!(t[s]=o))}):function(e,i,o){return t[0]=e,r(t,null,o,n),t[0]=null,!n.pop()}}),has:se(function(e){return function(t){return oe(e,t).length>0}}),contains:se(function(e){return e=e.replace(Z,ee),function(t){return(t.textContent||t.innerText||i(t)).indexOf(e)>-1}}),lang:se(function(e){return U.test(e||"")||oe.error("unsupported lang: "+e),e=e.replace(Z,ee).toLowerCase(),function(t){var n;do{if(n=g?t.lang:t.getAttribute("xml:lang")||t.getAttribute("lang"))return(n=n.toLowerCase())===e||0===n.indexOf(e+"-")}while((t=t.parentNode)&&1===t.nodeType);return!1}}),target:function(t){var n=e.location&&e.location.hash;return n&&n.slice(1)===t.id},root:function(e){return e===h},focus:function(e){return e===d.activeElement&&(!d.hasFocus||d.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:de(!1),disabled:de(!0),checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,!0===e.selected},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeType<6)return!1;return!0},parent:function(e){return!r.pseudos.empty(e)},header:function(e){return Y.test(e.nodeName)},input:function(e){return G.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||"text"===t.toLowerCase())},first:he(function(){return[0]}),last:he(function(e,t){return[t-1]}),eq:he(function(e,t,n){return[n<0?n+t:n]}),even:he(function(e,t){for(var n=0;n=0;)e.push(r);return e}),gt:he(function(e,t,n){for(var r=n<0?n+t:n;++r1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function be(e,t,n){for(var r=0,i=t.length;r-1&&(o[l]=!(a[l]=f))}}else v=we(v===a?v.splice(h,v.length):v),i?i(null,a,v,u):L.apply(a,v)})}function Ce(e){for(var t,n,i,o=e.length,a=r.relative[e[0].type],s=a||r.relative[" "],u=a?1:0,c=me(function(e){return e===t},s,!0),f=me(function(e){return O(t,e)>-1},s,!0),p=[function(e,n,r){var i=!a&&(r||n!==l)||((t=n).nodeType?c(e,n,r):f(e,n,r));return t=null,i}];u1&&xe(p),u>1&&ve(e.slice(0,u-1).concat({value:" "===e[u-2].type?"*":""})).replace(B,"$1"),n,u0,i=e.length>0,o=function(o,a,s,u,c){var f,h,y,v=0,m="0",x=o&&[],b=[],w=l,C=o||i&&r.find.TAG("*",c),E=T+=null==w?1:Math.random()||.1,k=C.length;for(c&&(l=a===d||a||c);m!==k&&null!=(f=C[m]);m++){if(i&&f){h=0,a||f.ownerDocument===d||(p(f),s=!g);while(y=e[h++])if(y(f,a||d,s)){u.push(f);break}c&&(T=E)}n&&((f=!y&&f)&&v--,o&&x.push(f))}if(v+=m,n&&m!==v){h=0;while(y=t[h++])y(x,b,a,s);if(o){if(v>0)while(m--)x[m]||b[m]||(b[m]=j.call(u));b=we(b)}L.apply(u,b),c&&!o&&b.length>0&&v+t.length>1&&oe.uniqueSort(u)}return c&&(T=E,l=w),x};return n?se(o):o}return s=oe.compile=function(e,t){var n,r=[],i=[],o=S[e+" "];if(!o){t||(t=a(e)),n=t.length;while(n--)(o=Ce(t[n]))[b]?r.push(o):i.push(o);(o=S(e,Ee(i,r))).selector=e}return o},u=oe.select=function(e,t,n,i){var o,u,l,c,f,p="function"==typeof e&&e,d=!i&&a(e=p.selector||e);if(n=n||[],1===d.length){if((u=d[0]=d[0].slice(0)).length>2&&"ID"===(l=u[0]).type&&9===t.nodeType&&g&&r.relative[u[1].type]){if(!(t=(r.find.ID(l.matches[0].replace(Z,ee),t)||[])[0]))return n;p&&(t=t.parentNode),e=e.slice(u.shift().value.length)}o=V.needsContext.test(e)?0:u.length;while(o--){if(l=u[o],r.relative[c=l.type])break;if((f=r.find[c])&&(i=f(l.matches[0].replace(Z,ee),K.test(u[0].type)&&ge(t.parentNode)||t))){if(u.splice(o,1),!(e=i.length&&ve(u)))return L.apply(n,i),n;break}}}return(p||s(e,d))(i,t,!g,n,!t||K.test(e)&&ge(t.parentNode)||t),n},n.sortStable=b.split("").sort(D).join("")===b,n.detectDuplicates=!!f,p(),n.sortDetached=ue(function(e){return 1&e.compareDocumentPosition(d.createElement("fieldset"))}),ue(function(e){return e.innerHTML="","#"===e.firstChild.getAttribute("href")})||le("type|href|height|width",function(e,t,n){if(!n)return e.getAttribute(t,"type"===t.toLowerCase()?1:2)}),n.attributes&&ue(function(e){return e.innerHTML="",e.firstChild.setAttribute("value",""),""===e.firstChild.getAttribute("value")})||le("value",function(e,t,n){if(!n&&"input"===e.nodeName.toLowerCase())return e.defaultValue}),ue(function(e){return null==e.getAttribute("disabled")})||le(P,function(e,t,n){var r;if(!n)return!0===e[t]?t.toLowerCase():(r=e.getAttributeNode(t))&&r.specified?r.value:null}),oe}(e);w.find=E,w.expr=E.selectors,w.expr[":"]=w.expr.pseudos,w.uniqueSort=w.unique=E.uniqueSort,w.text=E.getText,w.isXMLDoc=E.isXML,w.contains=E.contains,w.escapeSelector=E.escape;var k=function(e,t,n){var r=[],i=void 0!==n;while((e=e[t])&&9!==e.nodeType)if(1===e.nodeType){if(i&&w(e).is(n))break;r.push(e)}return r},S=function(e,t){for(var n=[];e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n},D=w.expr.match.needsContext;function N(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()}var A=/^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i;function j(e,t,n){return g(t)?w.grep(e,function(e,r){return!!t.call(e,r,e)!==n}):t.nodeType?w.grep(e,function(e){return e===t!==n}):"string"!=typeof t?w.grep(e,function(e){return u.call(t,e)>-1!==n}):w.filter(t,e,n)}w.filter=function(e,t,n){var r=t[0];return n&&(e=":not("+e+")"),1===t.length&&1===r.nodeType?w.find.matchesSelector(r,e)?[r]:[]:w.find.matches(e,w.grep(t,function(e){return 1===e.nodeType}))},w.fn.extend({find:function(e){var t,n,r=this.length,i=this;if("string"!=typeof e)return this.pushStack(w(e).filter(function(){for(t=0;t1?w.uniqueSort(n):n},filter:function(e){return this.pushStack(j(this,e||[],!1))},not:function(e){return this.pushStack(j(this,e||[],!0))},is:function(e){return!!j(this,"string"==typeof e&&D.test(e)?w(e):e||[],!1).length}});var q,L=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/;(w.fn.init=function(e,t,n){var i,o;if(!e)return this;if(n=n||q,"string"==typeof e){if(!(i="<"===e[0]&&">"===e[e.length-1]&&e.length>=3?[null,e,null]:L.exec(e))||!i[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(i[1]){if(t=t instanceof w?t[0]:t,w.merge(this,w.parseHTML(i[1],t&&t.nodeType?t.ownerDocument||t:r,!0)),A.test(i[1])&&w.isPlainObject(t))for(i in t)g(this[i])?this[i](t[i]):this.attr(i,t[i]);return this}return(o=r.getElementById(i[2]))&&(this[0]=o,this.length=1),this}return e.nodeType?(this[0]=e,this.length=1,this):g(e)?void 0!==n.ready?n.ready(e):e(w):w.makeArray(e,this)}).prototype=w.fn,q=w(r);var H=/^(?:parents|prev(?:Until|All))/,O={children:!0,contents:!0,next:!0,prev:!0};w.fn.extend({has:function(e){var t=w(e,this),n=t.length;return this.filter(function(){for(var e=0;e-1:1===n.nodeType&&w.find.matchesSelector(n,e))){o.push(n);break}return this.pushStack(o.length>1?w.uniqueSort(o):o)},index:function(e){return e?"string"==typeof e?u.call(w(e),this[0]):u.call(this,e.jquery?e[0]:e):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){return this.pushStack(w.uniqueSort(w.merge(this.get(),w(e,t))))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}});function P(e,t){while((e=e[t])&&1!==e.nodeType);return e}w.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return k(e,"parentNode")},parentsUntil:function(e,t,n){return k(e,"parentNode",n)},next:function(e){return P(e,"nextSibling")},prev:function(e){return P(e,"previousSibling")},nextAll:function(e){return k(e,"nextSibling")},prevAll:function(e){return k(e,"previousSibling")},nextUntil:function(e,t,n){return k(e,"nextSibling",n)},prevUntil:function(e,t,n){return k(e,"previousSibling",n)},siblings:function(e){return S((e.parentNode||{}).firstChild,e)},children:function(e){return S(e.firstChild)},contents:function(e){return N(e,"iframe")?e.contentDocument:(N(e,"template")&&(e=e.content||e),w.merge([],e.childNodes))}},function(e,t){w.fn[e]=function(n,r){var i=w.map(this,t,n);return"Until"!==e.slice(-5)&&(r=n),r&&"string"==typeof r&&(i=w.filter(r,i)),this.length>1&&(O[e]||w.uniqueSort(i),H.test(e)&&i.reverse()),this.pushStack(i)}});var M=/[^\x20\t\r\n\f]+/g;function R(e){var t={};return w.each(e.match(M)||[],function(e,n){t[n]=!0}),t}w.Callbacks=function(e){e="string"==typeof e?R(e):w.extend({},e);var t,n,r,i,o=[],a=[],s=-1,u=function(){for(i=i||e.once,r=t=!0;a.length;s=-1){n=a.shift();while(++s-1)o.splice(n,1),n<=s&&s--}),this},has:function(e){return e?w.inArray(e,o)>-1:o.length>0},empty:function(){return o&&(o=[]),this},disable:function(){return i=a=[],o=n="",this},disabled:function(){return!o},lock:function(){return i=a=[],n||t||(o=n=""),this},locked:function(){return!!i},fireWith:function(e,n){return i||(n=[e,(n=n||[]).slice?n.slice():n],a.push(n),t||u()),this},fire:function(){return l.fireWith(this,arguments),this},fired:function(){return!!r}};return l};function I(e){return e}function W(e){throw e}function $(e,t,n,r){var i;try{e&&g(i=e.promise)?i.call(e).done(t).fail(n):e&&g(i=e.then)?i.call(e,t,n):t.apply(void 0,[e].slice(r))}catch(e){n.apply(void 0,[e])}}w.extend({Deferred:function(t){var n=[["notify","progress",w.Callbacks("memory"),w.Callbacks("memory"),2],["resolve","done",w.Callbacks("once memory"),w.Callbacks("once memory"),0,"resolved"],["reject","fail",w.Callbacks("once memory"),w.Callbacks("once memory"),1,"rejected"]],r="pending",i={state:function(){return r},always:function(){return o.done(arguments).fail(arguments),this},"catch":function(e){return i.then(null,e)},pipe:function(){var e=arguments;return w.Deferred(function(t){w.each(n,function(n,r){var i=g(e[r[4]])&&e[r[4]];o[r[1]](function(){var e=i&&i.apply(this,arguments);e&&g(e.promise)?e.promise().progress(t.notify).done(t.resolve).fail(t.reject):t[r[0]+"With"](this,i?[e]:arguments)})}),e=null}).promise()},then:function(t,r,i){var o=0;function a(t,n,r,i){return function(){var s=this,u=arguments,l=function(){var e,l;if(!(t=o&&(r!==W&&(s=void 0,u=[e]),n.rejectWith(s,u))}};t?c():(w.Deferred.getStackHook&&(c.stackTrace=w.Deferred.getStackHook()),e.setTimeout(c))}}return w.Deferred(function(e){n[0][3].add(a(0,e,g(i)?i:I,e.notifyWith)),n[1][3].add(a(0,e,g(t)?t:I)),n[2][3].add(a(0,e,g(r)?r:W))}).promise()},promise:function(e){return null!=e?w.extend(e,i):i}},o={};return w.each(n,function(e,t){var a=t[2],s=t[5];i[t[1]]=a.add,s&&a.add(function(){r=s},n[3-e][2].disable,n[3-e][3].disable,n[0][2].lock,n[0][3].lock),a.add(t[3].fire),o[t[0]]=function(){return o[t[0]+"With"](this===o?void 0:this,arguments),this},o[t[0]+"With"]=a.fireWith}),i.promise(o),t&&t.call(o,o),o},when:function(e){var t=arguments.length,n=t,r=Array(n),i=o.call(arguments),a=w.Deferred(),s=function(e){return function(n){r[e]=this,i[e]=arguments.length>1?o.call(arguments):n,--t||a.resolveWith(r,i)}};if(t<=1&&($(e,a.done(s(n)).resolve,a.reject,!t),"pending"===a.state()||g(i[n]&&i[n].then)))return a.then();while(n--)$(i[n],s(n),a.reject);return a.promise()}});var B=/^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;w.Deferred.exceptionHook=function(t,n){e.console&&e.console.warn&&t&&B.test(t.name)&&e.console.warn("jQuery.Deferred exception: "+t.message,t.stack,n)},w.readyException=function(t){e.setTimeout(function(){throw t})};var F=w.Deferred();w.fn.ready=function(e){return F.then(e)["catch"](function(e){w.readyException(e)}),this},w.extend({isReady:!1,readyWait:1,ready:function(e){(!0===e?--w.readyWait:w.isReady)||(w.isReady=!0,!0!==e&&--w.readyWait>0||F.resolveWith(r,[w]))}}),w.ready.then=F.then;function _(){r.removeEventListener("DOMContentLoaded",_),e.removeEventListener("load",_),w.ready()}"complete"===r.readyState||"loading"!==r.readyState&&!r.documentElement.doScroll?e.setTimeout(w.ready):(r.addEventListener("DOMContentLoaded",_),e.addEventListener("load",_));var z=function(e,t,n,r,i,o,a){var s=0,u=e.length,l=null==n;if("object"===x(n)){i=!0;for(s in n)z(e,t,s,n[s],!0,o,a)}else if(void 0!==r&&(i=!0,g(r)||(a=!0),l&&(a?(t.call(e,r),t=null):(l=t,t=function(e,t,n){return l.call(w(e),n)})),t))for(;s1,null,!0)},removeData:function(e){return this.each(function(){K.remove(this,e)})}}),w.extend({queue:function(e,t,n){var r;if(e)return t=(t||"fx")+"queue",r=J.get(e,t),n&&(!r||Array.isArray(n)?r=J.access(e,t,w.makeArray(n)):r.push(n)),r||[]},dequeue:function(e,t){t=t||"fx";var n=w.queue(e,t),r=n.length,i=n.shift(),o=w._queueHooks(e,t),a=function(){w.dequeue(e,t)};"inprogress"===i&&(i=n.shift(),r--),i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,a,o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return J.get(e,n)||J.access(e,n,{empty:w.Callbacks("once memory").add(function(){J.remove(e,[t+"queue",n])})})}}),w.fn.extend({queue:function(e,t){var n=2;return"string"!=typeof e&&(t=e,e="fx",n--),arguments.length\x20\t\r\n\f]+)/i,he=/^$|^module$|\/(?:java|ecma)script/i,ge={option:[1,""],thead:[1,"","
"],col:[2,"","
"],tr:[2,"","
"],td:[3,"","
"],_default:[0,"",""]};ge.optgroup=ge.option,ge.tbody=ge.tfoot=ge.colgroup=ge.caption=ge.thead,ge.th=ge.td;function ye(e,t){var n;return n="undefined"!=typeof e.getElementsByTagName?e.getElementsByTagName(t||"*"):"undefined"!=typeof e.querySelectorAll?e.querySelectorAll(t||"*"):[],void 0===t||t&&N(e,t)?w.merge([e],n):n}function ve(e,t){for(var n=0,r=e.length;n-1)i&&i.push(o);else if(l=w.contains(o.ownerDocument,o),a=ye(f.appendChild(o),"script"),l&&ve(a),n){c=0;while(o=a[c++])he.test(o.type||"")&&n.push(o)}return f}!function(){var e=r.createDocumentFragment().appendChild(r.createElement("div")),t=r.createElement("input");t.setAttribute("type","radio"),t.setAttribute("checked","checked"),t.setAttribute("name","t"),e.appendChild(t),h.checkClone=e.cloneNode(!0).cloneNode(!0).lastChild.checked,e.innerHTML="",h.noCloneChecked=!!e.cloneNode(!0).lastChild.defaultValue}();var be=r.documentElement,we=/^key/,Te=/^(?:mouse|pointer|contextmenu|drag|drop)|click/,Ce=/^([^.]*)(?:\.(.+)|)/;function Ee(){return!0}function ke(){return!1}function Se(){try{return r.activeElement}catch(e){}}function De(e,t,n,r,i,o){var a,s;if("object"==typeof t){"string"!=typeof n&&(r=r||n,n=void 0);for(s in t)De(e,s,n,r,t[s],o);return e}if(null==r&&null==i?(i=n,r=n=void 0):null==i&&("string"==typeof n?(i=r,r=void 0):(i=r,r=n,n=void 0)),!1===i)i=ke;else if(!i)return e;return 1===o&&(a=i,(i=function(e){return w().off(e),a.apply(this,arguments)}).guid=a.guid||(a.guid=w.guid++)),e.each(function(){w.event.add(this,t,i,r,n)})}w.event={global:{},add:function(e,t,n,r,i){var o,a,s,u,l,c,f,p,d,h,g,y=J.get(e);if(y){n.handler&&(n=(o=n).handler,i=o.selector),i&&w.find.matchesSelector(be,i),n.guid||(n.guid=w.guid++),(u=y.events)||(u=y.events={}),(a=y.handle)||(a=y.handle=function(t){return"undefined"!=typeof w&&w.event.triggered!==t.type?w.event.dispatch.apply(e,arguments):void 0}),l=(t=(t||"").match(M)||[""]).length;while(l--)d=g=(s=Ce.exec(t[l])||[])[1],h=(s[2]||"").split(".").sort(),d&&(f=w.event.special[d]||{},d=(i?f.delegateType:f.bindType)||d,f=w.event.special[d]||{},c=w.extend({type:d,origType:g,data:r,handler:n,guid:n.guid,selector:i,needsContext:i&&w.expr.match.needsContext.test(i),namespace:h.join(".")},o),(p=u[d])||((p=u[d]=[]).delegateCount=0,f.setup&&!1!==f.setup.call(e,r,h,a)||e.addEventListener&&e.addEventListener(d,a)),f.add&&(f.add.call(e,c),c.handler.guid||(c.handler.guid=n.guid)),i?p.splice(p.delegateCount++,0,c):p.push(c),w.event.global[d]=!0)}},remove:function(e,t,n,r,i){var o,a,s,u,l,c,f,p,d,h,g,y=J.hasData(e)&&J.get(e);if(y&&(u=y.events)){l=(t=(t||"").match(M)||[""]).length;while(l--)if(s=Ce.exec(t[l])||[],d=g=s[1],h=(s[2]||"").split(".").sort(),d){f=w.event.special[d]||{},p=u[d=(r?f.delegateType:f.bindType)||d]||[],s=s[2]&&new RegExp("(^|\\.)"+h.join("\\.(?:.*\\.|)")+"(\\.|$)"),a=o=p.length;while(o--)c=p[o],!i&&g!==c.origType||n&&n.guid!==c.guid||s&&!s.test(c.namespace)||r&&r!==c.selector&&("**"!==r||!c.selector)||(p.splice(o,1),c.selector&&p.delegateCount--,f.remove&&f.remove.call(e,c));a&&!p.length&&(f.teardown&&!1!==f.teardown.call(e,h,y.handle)||w.removeEvent(e,d,y.handle),delete u[d])}else for(d in u)w.event.remove(e,d+t[l],n,r,!0);w.isEmptyObject(u)&&J.remove(e,"handle events")}},dispatch:function(e){var t=w.event.fix(e),n,r,i,o,a,s,u=new Array(arguments.length),l=(J.get(this,"events")||{})[t.type]||[],c=w.event.special[t.type]||{};for(u[0]=t,n=1;n=1))for(;l!==this;l=l.parentNode||this)if(1===l.nodeType&&("click"!==e.type||!0!==l.disabled)){for(o=[],a={},n=0;n-1:w.find(i,this,null,[l]).length),a[i]&&o.push(r);o.length&&s.push({elem:l,handlers:o})}return l=this,u\x20\t\r\n\f]*)[^>]*)\/>/gi,Ae=/\s*$/g;function Le(e,t){return N(e,"table")&&N(11!==t.nodeType?t:t.firstChild,"tr")?w(e).children("tbody")[0]||e:e}function He(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function Oe(e){return"true/"===(e.type||"").slice(0,5)?e.type=e.type.slice(5):e.removeAttribute("type"),e}function Pe(e,t){var n,r,i,o,a,s,u,l;if(1===t.nodeType){if(J.hasData(e)&&(o=J.access(e),a=J.set(t,o),l=o.events)){delete a.handle,a.events={};for(i in l)for(n=0,r=l[i].length;n1&&"string"==typeof y&&!h.checkClone&&je.test(y))return e.each(function(i){var o=e.eq(i);v&&(t[0]=y.call(this,i,o.html())),Re(o,t,n,r)});if(p&&(i=xe(t,e[0].ownerDocument,!1,e,r),o=i.firstChild,1===i.childNodes.length&&(i=o),o||r)){for(u=(s=w.map(ye(i,"script"),He)).length;f")},clone:function(e,t,n){var r,i,o,a,s=e.cloneNode(!0),u=w.contains(e.ownerDocument,e);if(!(h.noCloneChecked||1!==e.nodeType&&11!==e.nodeType||w.isXMLDoc(e)))for(a=ye(s),r=0,i=(o=ye(e)).length;r0&&ve(a,!u&&ye(e,"script")),s},cleanData:function(e){for(var t,n,r,i=w.event.special,o=0;void 0!==(n=e[o]);o++)if(Y(n)){if(t=n[J.expando]){if(t.events)for(r in t.events)i[r]?w.event.remove(n,r):w.removeEvent(n,r,t.handle);n[J.expando]=void 0}n[K.expando]&&(n[K.expando]=void 0)}}}),w.fn.extend({detach:function(e){return Ie(this,e,!0)},remove:function(e){return Ie(this,e)},text:function(e){return z(this,function(e){return void 0===e?w.text(this):this.empty().each(function(){1!==this.nodeType&&11!==this.nodeType&&9!==this.nodeType||(this.textContent=e)})},null,e,arguments.length)},append:function(){return Re(this,arguments,function(e){1!==this.nodeType&&11!==this.nodeType&&9!==this.nodeType||Le(this,e).appendChild(e)})},prepend:function(){return Re(this,arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=Le(this,e);t.insertBefore(e,t.firstChild)}})},before:function(){return Re(this,arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this)})},after:function(){return Re(this,arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this.nextSibling)})},empty:function(){for(var e,t=0;null!=(e=this[t]);t++)1===e.nodeType&&(w.cleanData(ye(e,!1)),e.textContent="");return this},clone:function(e,t){return e=null!=e&&e,t=null==t?e:t,this.map(function(){return w.clone(this,e,t)})},html:function(e){return z(this,function(e){var t=this[0]||{},n=0,r=this.length;if(void 0===e&&1===t.nodeType)return t.innerHTML;if("string"==typeof e&&!Ae.test(e)&&!ge[(de.exec(e)||["",""])[1].toLowerCase()]){e=w.htmlPrefilter(e);try{for(;n=0&&(u+=Math.max(0,Math.ceil(e["offset"+t[0].toUpperCase()+t.slice(1)]-o-u-s-.5))),u}function et(e,t,n){var r=$e(e),i=Fe(e,t,r),o="border-box"===w.css(e,"boxSizing",!1,r),a=o;if(We.test(i)){if(!n)return i;i="auto"}return a=a&&(h.boxSizingReliable()||i===e.style[t]),("auto"===i||!parseFloat(i)&&"inline"===w.css(e,"display",!1,r))&&(i=e["offset"+t[0].toUpperCase()+t.slice(1)],a=!0),(i=parseFloat(i)||0)+Ze(e,t,n||(o?"border":"content"),a,r,i)+"px"}w.extend({cssHooks:{opacity:{get:function(e,t){if(t){var n=Fe(e,"opacity");return""===n?"1":n}}}},cssNumber:{animationIterationCount:!0,columnCount:!0,fillOpacity:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{},style:function(e,t,n,r){if(e&&3!==e.nodeType&&8!==e.nodeType&&e.style){var i,o,a,s=G(t),u=Xe.test(t),l=e.style;if(u||(t=Je(s)),a=w.cssHooks[t]||w.cssHooks[s],void 0===n)return a&&"get"in a&&void 0!==(i=a.get(e,!1,r))?i:l[t];"string"==(o=typeof n)&&(i=ie.exec(n))&&i[1]&&(n=ue(e,t,i),o="number"),null!=n&&n===n&&("number"===o&&(n+=i&&i[3]||(w.cssNumber[s]?"":"px")),h.clearCloneStyle||""!==n||0!==t.indexOf("background")||(l[t]="inherit"),a&&"set"in a&&void 0===(n=a.set(e,n,r))||(u?l.setProperty(t,n):l[t]=n))}},css:function(e,t,n,r){var i,o,a,s=G(t);return Xe.test(t)||(t=Je(s)),(a=w.cssHooks[t]||w.cssHooks[s])&&"get"in a&&(i=a.get(e,!0,n)),void 0===i&&(i=Fe(e,t,r)),"normal"===i&&t in Ve&&(i=Ve[t]),""===n||n?(o=parseFloat(i),!0===n||isFinite(o)?o||0:i):i}}),w.each(["height","width"],function(e,t){w.cssHooks[t]={get:function(e,n,r){if(n)return!ze.test(w.css(e,"display"))||e.getClientRects().length&&e.getBoundingClientRect().width?et(e,t,r):se(e,Ue,function(){return et(e,t,r)})},set:function(e,n,r){var i,o=$e(e),a="border-box"===w.css(e,"boxSizing",!1,o),s=r&&Ze(e,t,r,a,o);return a&&h.scrollboxSize()===o.position&&(s-=Math.ceil(e["offset"+t[0].toUpperCase()+t.slice(1)]-parseFloat(o[t])-Ze(e,t,"border",!1,o)-.5)),s&&(i=ie.exec(n))&&"px"!==(i[3]||"px")&&(e.style[t]=n,n=w.css(e,t)),Ke(e,n,s)}}}),w.cssHooks.marginLeft=_e(h.reliableMarginLeft,function(e,t){if(t)return(parseFloat(Fe(e,"marginLeft"))||e.getBoundingClientRect().left-se(e,{marginLeft:0},function(){return e.getBoundingClientRect().left}))+"px"}),w.each({margin:"",padding:"",border:"Width"},function(e,t){w.cssHooks[e+t]={expand:function(n){for(var r=0,i={},o="string"==typeof n?n.split(" "):[n];r<4;r++)i[e+oe[r]+t]=o[r]||o[r-2]||o[0];return i}},"margin"!==e&&(w.cssHooks[e+t].set=Ke)}),w.fn.extend({css:function(e,t){return z(this,function(e,t,n){var r,i,o={},a=0;if(Array.isArray(t)){for(r=$e(e),i=t.length;a1)}});function tt(e,t,n,r,i){return new tt.prototype.init(e,t,n,r,i)}w.Tween=tt,tt.prototype={constructor:tt,init:function(e,t,n,r,i,o){this.elem=e,this.prop=n,this.easing=i||w.easing._default,this.options=t,this.start=this.now=this.cur(),this.end=r,this.unit=o||(w.cssNumber[n]?"":"px")},cur:function(){var e=tt.propHooks[this.prop];return e&&e.get?e.get(this):tt.propHooks._default.get(this)},run:function(e){var t,n=tt.propHooks[this.prop];return this.options.duration?this.pos=t=w.easing[this.easing](e,this.options.duration*e,0,1,this.options.duration):this.pos=t=e,this.now=(this.end-this.start)*t+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),n&&n.set?n.set(this):tt.propHooks._default.set(this),this}},tt.prototype.init.prototype=tt.prototype,tt.propHooks={_default:{get:function(e){var t;return 1!==e.elem.nodeType||null!=e.elem[e.prop]&&null==e.elem.style[e.prop]?e.elem[e.prop]:(t=w.css(e.elem,e.prop,""))&&"auto"!==t?t:0},set:function(e){w.fx.step[e.prop]?w.fx.step[e.prop](e):1!==e.elem.nodeType||null==e.elem.style[w.cssProps[e.prop]]&&!w.cssHooks[e.prop]?e.elem[e.prop]=e.now:w.style(e.elem,e.prop,e.now+e.unit)}}},tt.propHooks.scrollTop=tt.propHooks.scrollLeft={set:function(e){e.elem.nodeType&&e.elem.parentNode&&(e.elem[e.prop]=e.now)}},w.easing={linear:function(e){return e},swing:function(e){return.5-Math.cos(e*Math.PI)/2},_default:"swing"},w.fx=tt.prototype.init,w.fx.step={};var nt,rt,it=/^(?:toggle|show|hide)$/,ot=/queueHooks$/;function at(){rt&&(!1===r.hidden&&e.requestAnimationFrame?e.requestAnimationFrame(at):e.setTimeout(at,w.fx.interval),w.fx.tick())}function st(){return e.setTimeout(function(){nt=void 0}),nt=Date.now()}function ut(e,t){var n,r=0,i={height:e};for(t=t?1:0;r<4;r+=2-t)i["margin"+(n=oe[r])]=i["padding"+n]=e;return t&&(i.opacity=i.width=e),i}function lt(e,t,n){for(var r,i=(pt.tweeners[t]||[]).concat(pt.tweeners["*"]),o=0,a=i.length;o1)},removeAttr:function(e){return this.each(function(){w.removeAttr(this,e)})}}),w.extend({attr:function(e,t,n){var r,i,o=e.nodeType;if(3!==o&&8!==o&&2!==o)return"undefined"==typeof e.getAttribute?w.prop(e,t,n):(1===o&&w.isXMLDoc(e)||(i=w.attrHooks[t.toLowerCase()]||(w.expr.match.bool.test(t)?dt:void 0)),void 0!==n?null===n?void w.removeAttr(e,t):i&&"set"in i&&void 0!==(r=i.set(e,n,t))?r:(e.setAttribute(t,n+""),n):i&&"get"in i&&null!==(r=i.get(e,t))?r:null==(r=w.find.attr(e,t))?void 0:r)},attrHooks:{type:{set:function(e,t){if(!h.radioValue&&"radio"===t&&N(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}}},removeAttr:function(e,t){var n,r=0,i=t&&t.match(M);if(i&&1===e.nodeType)while(n=i[r++])e.removeAttribute(n)}}),dt={set:function(e,t,n){return!1===t?w.removeAttr(e,n):e.setAttribute(n,n),n}},w.each(w.expr.match.bool.source.match(/\w+/g),function(e,t){var n=ht[t]||w.find.attr;ht[t]=function(e,t,r){var i,o,a=t.toLowerCase();return r||(o=ht[a],ht[a]=i,i=null!=n(e,t,r)?a:null,ht[a]=o),i}});var gt=/^(?:input|select|textarea|button)$/i,yt=/^(?:a|area)$/i;w.fn.extend({prop:function(e,t){return z(this,w.prop,e,t,arguments.length>1)},removeProp:function(e){return this.each(function(){delete this[w.propFix[e]||e]})}}),w.extend({prop:function(e,t,n){var r,i,o=e.nodeType;if(3!==o&&8!==o&&2!==o)return 1===o&&w.isXMLDoc(e)||(t=w.propFix[t]||t,i=w.propHooks[t]),void 0!==n?i&&"set"in i&&void 0!==(r=i.set(e,n,t))?r:e[t]=n:i&&"get"in i&&null!==(r=i.get(e,t))?r:e[t]},propHooks:{tabIndex:{get:function(e){var t=w.find.attr(e,"tabindex");return t?parseInt(t,10):gt.test(e.nodeName)||yt.test(e.nodeName)&&e.href?0:-1}}},propFix:{"for":"htmlFor","class":"className"}}),h.optSelected||(w.propHooks.selected={get:function(e){var t=e.parentNode;return t&&t.parentNode&&t.parentNode.selectedIndex,null},set:function(e){var t=e.parentNode;t&&(t.selectedIndex,t.parentNode&&t.parentNode.selectedIndex)}}),w.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){w.propFix[this.toLowerCase()]=this});function vt(e){return(e.match(M)||[]).join(" ")}function mt(e){return e.getAttribute&&e.getAttribute("class")||""}function xt(e){return Array.isArray(e)?e:"string"==typeof e?e.match(M)||[]:[]}w.fn.extend({addClass:function(e){var t,n,r,i,o,a,s,u=0;if(g(e))return this.each(function(t){w(this).addClass(e.call(this,t,mt(this)))});if((t=xt(e)).length)while(n=this[u++])if(i=mt(n),r=1===n.nodeType&&" "+vt(i)+" "){a=0;while(o=t[a++])r.indexOf(" "+o+" ")<0&&(r+=o+" ");i!==(s=vt(r))&&n.setAttribute("class",s)}return this},removeClass:function(e){var t,n,r,i,o,a,s,u=0;if(g(e))return this.each(function(t){w(this).removeClass(e.call(this,t,mt(this)))});if(!arguments.length)return this.attr("class","");if((t=xt(e)).length)while(n=this[u++])if(i=mt(n),r=1===n.nodeType&&" "+vt(i)+" "){a=0;while(o=t[a++])while(r.indexOf(" "+o+" ")>-1)r=r.replace(" "+o+" "," ");i!==(s=vt(r))&&n.setAttribute("class",s)}return this},toggleClass:function(e,t){var n=typeof e,r="string"===n||Array.isArray(e);return"boolean"==typeof t&&r?t?this.addClass(e):this.removeClass(e):g(e)?this.each(function(n){w(this).toggleClass(e.call(this,n,mt(this),t),t)}):this.each(function(){var t,i,o,a;if(r){i=0,o=w(this),a=xt(e);while(t=a[i++])o.hasClass(t)?o.removeClass(t):o.addClass(t)}else void 0!==e&&"boolean"!==n||((t=mt(this))&&J.set(this,"__className__",t),this.setAttribute&&this.setAttribute("class",t||!1===e?"":J.get(this,"__className__")||""))})},hasClass:function(e){var t,n,r=0;t=" "+e+" ";while(n=this[r++])if(1===n.nodeType&&(" "+vt(mt(n))+" ").indexOf(t)>-1)return!0;return!1}});var bt=/\r/g;w.fn.extend({val:function(e){var t,n,r,i=this[0];{if(arguments.length)return r=g(e),this.each(function(n){var i;1===this.nodeType&&(null==(i=r?e.call(this,n,w(this).val()):e)?i="":"number"==typeof i?i+="":Array.isArray(i)&&(i=w.map(i,function(e){return null==e?"":e+""})),(t=w.valHooks[this.type]||w.valHooks[this.nodeName.toLowerCase()])&&"set"in t&&void 0!==t.set(this,i,"value")||(this.value=i))});if(i)return(t=w.valHooks[i.type]||w.valHooks[i.nodeName.toLowerCase()])&&"get"in t&&void 0!==(n=t.get(i,"value"))?n:"string"==typeof(n=i.value)?n.replace(bt,""):null==n?"":n}}}),w.extend({valHooks:{option:{get:function(e){var t=w.find.attr(e,"value");return null!=t?t:vt(w.text(e))}},select:{get:function(e){var t,n,r,i=e.options,o=e.selectedIndex,a="select-one"===e.type,s=a?null:[],u=a?o+1:i.length;for(r=o<0?u:a?o:0;r-1)&&(n=!0);return n||(e.selectedIndex=-1),o}}}}),w.each(["radio","checkbox"],function(){w.valHooks[this]={set:function(e,t){if(Array.isArray(t))return e.checked=w.inArray(w(e).val(),t)>-1}},h.checkOn||(w.valHooks[this].get=function(e){return null===e.getAttribute("value")?"on":e.value})}),h.focusin="onfocusin"in e;var wt=/^(?:focusinfocus|focusoutblur)$/,Tt=function(e){e.stopPropagation()};w.extend(w.event,{trigger:function(t,n,i,o){var a,s,u,l,c,p,d,h,v=[i||r],m=f.call(t,"type")?t.type:t,x=f.call(t,"namespace")?t.namespace.split("."):[];if(s=h=u=i=i||r,3!==i.nodeType&&8!==i.nodeType&&!wt.test(m+w.event.triggered)&&(m.indexOf(".")>-1&&(m=(x=m.split(".")).shift(),x.sort()),c=m.indexOf(":")<0&&"on"+m,t=t[w.expando]?t:new w.Event(m,"object"==typeof t&&t),t.isTrigger=o?2:3,t.namespace=x.join("."),t.rnamespace=t.namespace?new RegExp("(^|\\.)"+x.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,t.result=void 0,t.target||(t.target=i),n=null==n?[t]:w.makeArray(n,[t]),d=w.event.special[m]||{},o||!d.trigger||!1!==d.trigger.apply(i,n))){if(!o&&!d.noBubble&&!y(i)){for(l=d.delegateType||m,wt.test(l+m)||(s=s.parentNode);s;s=s.parentNode)v.push(s),u=s;u===(i.ownerDocument||r)&&v.push(u.defaultView||u.parentWindow||e)}a=0;while((s=v[a++])&&!t.isPropagationStopped())h=s,t.type=a>1?l:d.bindType||m,(p=(J.get(s,"events")||{})[t.type]&&J.get(s,"handle"))&&p.apply(s,n),(p=c&&s[c])&&p.apply&&Y(s)&&(t.result=p.apply(s,n),!1===t.result&&t.preventDefault());return t.type=m,o||t.isDefaultPrevented()||d._default&&!1!==d._default.apply(v.pop(),n)||!Y(i)||c&&g(i[m])&&!y(i)&&((u=i[c])&&(i[c]=null),w.event.triggered=m,t.isPropagationStopped()&&h.addEventListener(m,Tt),i[m](),t.isPropagationStopped()&&h.removeEventListener(m,Tt),w.event.triggered=void 0,u&&(i[c]=u)),t.result}},simulate:function(e,t,n){var r=w.extend(new w.Event,n,{type:e,isSimulated:!0});w.event.trigger(r,null,t)}}),w.fn.extend({trigger:function(e,t){return this.each(function(){w.event.trigger(e,t,this)})},triggerHandler:function(e,t){var n=this[0];if(n)return w.event.trigger(e,t,n,!0)}}),h.focusin||w.each({focus:"focusin",blur:"focusout"},function(e,t){var n=function(e){w.event.simulate(t,e.target,w.event.fix(e))};w.event.special[t]={setup:function(){var r=this.ownerDocument||this,i=J.access(r,t);i||r.addEventListener(e,n,!0),J.access(r,t,(i||0)+1)},teardown:function(){var r=this.ownerDocument||this,i=J.access(r,t)-1;i?J.access(r,t,i):(r.removeEventListener(e,n,!0),J.remove(r,t))}}});var Ct=e.location,Et=Date.now(),kt=/\?/;w.parseXML=function(t){var n;if(!t||"string"!=typeof t)return null;try{n=(new e.DOMParser).parseFromString(t,"text/xml")}catch(e){n=void 0}return n&&!n.getElementsByTagName("parsererror").length||w.error("Invalid XML: "+t),n};var St=/\[\]$/,Dt=/\r?\n/g,Nt=/^(?:submit|button|image|reset|file)$/i,At=/^(?:input|select|textarea|keygen)/i;function jt(e,t,n,r){var i;if(Array.isArray(t))w.each(t,function(t,i){n||St.test(e)?r(e,i):jt(e+"["+("object"==typeof i&&null!=i?t:"")+"]",i,n,r)});else if(n||"object"!==x(t))r(e,t);else for(i in t)jt(e+"["+i+"]",t[i],n,r)}w.param=function(e,t){var n,r=[],i=function(e,t){var n=g(t)?t():t;r[r.length]=encodeURIComponent(e)+"="+encodeURIComponent(null==n?"":n)};if(Array.isArray(e)||e.jquery&&!w.isPlainObject(e))w.each(e,function(){i(this.name,this.value)});else for(n in e)jt(n,e[n],t,i);return r.join("&")},w.fn.extend({serialize:function(){return w.param(this.serializeArray())},serializeArray:function(){return this.map(function(){var e=w.prop(this,"elements");return e?w.makeArray(e):this}).filter(function(){var e=this.type;return this.name&&!w(this).is(":disabled")&&At.test(this.nodeName)&&!Nt.test(e)&&(this.checked||!pe.test(e))}).map(function(e,t){var n=w(this).val();return null==n?null:Array.isArray(n)?w.map(n,function(e){return{name:t.name,value:e.replace(Dt,"\r\n")}}):{name:t.name,value:n.replace(Dt,"\r\n")}}).get()}});var qt=/%20/g,Lt=/#.*$/,Ht=/([?&])_=[^&]*/,Ot=/^(.*?):[ \t]*([^\r\n]*)$/gm,Pt=/^(?:about|app|app-storage|.+-extension|file|res|widget):$/,Mt=/^(?:GET|HEAD)$/,Rt=/^\/\//,It={},Wt={},$t="*/".concat("*"),Bt=r.createElement("a");Bt.href=Ct.href;function Ft(e){return function(t,n){"string"!=typeof t&&(n=t,t="*");var r,i=0,o=t.toLowerCase().match(M)||[];if(g(n))while(r=o[i++])"+"===r[0]?(r=r.slice(1)||"*",(e[r]=e[r]||[]).unshift(n)):(e[r]=e[r]||[]).push(n)}}function _t(e,t,n,r){var i={},o=e===Wt;function a(s){var u;return i[s]=!0,w.each(e[s]||[],function(e,s){var l=s(t,n,r);return"string"!=typeof l||o||i[l]?o?!(u=l):void 0:(t.dataTypes.unshift(l),a(l),!1)}),u}return a(t.dataTypes[0])||!i["*"]&&a("*")}function zt(e,t){var n,r,i=w.ajaxSettings.flatOptions||{};for(n in t)void 0!==t[n]&&((i[n]?e:r||(r={}))[n]=t[n]);return r&&w.extend(!0,e,r),e}function Xt(e,t,n){var r,i,o,a,s=e.contents,u=e.dataTypes;while("*"===u[0])u.shift(),void 0===r&&(r=e.mimeType||t.getResponseHeader("Content-Type"));if(r)for(i in s)if(s[i]&&s[i].test(r)){u.unshift(i);break}if(u[0]in n)o=u[0];else{for(i in n){if(!u[0]||e.converters[i+" "+u[0]]){o=i;break}a||(a=i)}o=o||a}if(o)return o!==u[0]&&u.unshift(o),n[o]}function Ut(e,t,n,r){var i,o,a,s,u,l={},c=e.dataTypes.slice();if(c[1])for(a in e.converters)l[a.toLowerCase()]=e.converters[a];o=c.shift();while(o)if(e.responseFields[o]&&(n[e.responseFields[o]]=t),!u&&r&&e.dataFilter&&(t=e.dataFilter(t,e.dataType)),u=o,o=c.shift())if("*"===o)o=u;else if("*"!==u&&u!==o){if(!(a=l[u+" "+o]||l["* "+o]))for(i in l)if((s=i.split(" "))[1]===o&&(a=l[u+" "+s[0]]||l["* "+s[0]])){!0===a?a=l[i]:!0!==l[i]&&(o=s[0],c.unshift(s[1]));break}if(!0!==a)if(a&&e["throws"])t=a(t);else try{t=a(t)}catch(e){return{state:"parsererror",error:a?e:"No conversion from "+u+" to "+o}}}return{state:"success",data:t}}w.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:Ct.href,type:"GET",isLocal:Pt.test(Ct.protocol),global:!0,processData:!0,async:!0,contentType:"application/x-www-form-urlencoded; charset=UTF-8",accepts:{"*":$t,text:"text/plain",html:"text/html",xml:"application/xml, text/xml",json:"application/json, text/javascript"},contents:{xml:/\bxml\b/,html:/\bhtml/,json:/\bjson\b/},responseFields:{xml:"responseXML",text:"responseText",json:"responseJSON"},converters:{"* text":String,"text html":!0,"text json":JSON.parse,"text xml":w.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(e,t){return t?zt(zt(e,w.ajaxSettings),t):zt(w.ajaxSettings,e)},ajaxPrefilter:Ft(It),ajaxTransport:Ft(Wt),ajax:function(t,n){"object"==typeof t&&(n=t,t=void 0),n=n||{};var i,o,a,s,u,l,c,f,p,d,h=w.ajaxSetup({},n),g=h.context||h,y=h.context&&(g.nodeType||g.jquery)?w(g):w.event,v=w.Deferred(),m=w.Callbacks("once memory"),x=h.statusCode||{},b={},T={},C="canceled",E={readyState:0,getResponseHeader:function(e){var t;if(c){if(!s){s={};while(t=Ot.exec(a))s[t[1].toLowerCase()]=t[2]}t=s[e.toLowerCase()]}return null==t?null:t},getAllResponseHeaders:function(){return c?a:null},setRequestHeader:function(e,t){return null==c&&(e=T[e.toLowerCase()]=T[e.toLowerCase()]||e,b[e]=t),this},overrideMimeType:function(e){return null==c&&(h.mimeType=e),this},statusCode:function(e){var t;if(e)if(c)E.always(e[E.status]);else for(t in e)x[t]=[x[t],e[t]];return this},abort:function(e){var t=e||C;return i&&i.abort(t),k(0,t),this}};if(v.promise(E),h.url=((t||h.url||Ct.href)+"").replace(Rt,Ct.protocol+"//"),h.type=n.method||n.type||h.method||h.type,h.dataTypes=(h.dataType||"*").toLowerCase().match(M)||[""],null==h.crossDomain){l=r.createElement("a");try{l.href=h.url,l.href=l.href,h.crossDomain=Bt.protocol+"//"+Bt.host!=l.protocol+"//"+l.host}catch(e){h.crossDomain=!0}}if(h.data&&h.processData&&"string"!=typeof h.data&&(h.data=w.param(h.data,h.traditional)),_t(It,h,n,E),c)return E;(f=w.event&&h.global)&&0==w.active++&&w.event.trigger("ajaxStart"),h.type=h.type.toUpperCase(),h.hasContent=!Mt.test(h.type),o=h.url.replace(Lt,""),h.hasContent?h.data&&h.processData&&0===(h.contentType||"").indexOf("application/x-www-form-urlencoded")&&(h.data=h.data.replace(qt,"+")):(d=h.url.slice(o.length),h.data&&(h.processData||"string"==typeof h.data)&&(o+=(kt.test(o)?"&":"?")+h.data,delete h.data),!1===h.cache&&(o=o.replace(Ht,"$1"),d=(kt.test(o)?"&":"?")+"_="+Et+++d),h.url=o+d),h.ifModified&&(w.lastModified[o]&&E.setRequestHeader("If-Modified-Since",w.lastModified[o]),w.etag[o]&&E.setRequestHeader("If-None-Match",w.etag[o])),(h.data&&h.hasContent&&!1!==h.contentType||n.contentType)&&E.setRequestHeader("Content-Type",h.contentType),E.setRequestHeader("Accept",h.dataTypes[0]&&h.accepts[h.dataTypes[0]]?h.accepts[h.dataTypes[0]]+("*"!==h.dataTypes[0]?", "+$t+"; q=0.01":""):h.accepts["*"]);for(p in h.headers)E.setRequestHeader(p,h.headers[p]);if(h.beforeSend&&(!1===h.beforeSend.call(g,E,h)||c))return E.abort();if(C="abort",m.add(h.complete),E.done(h.success),E.fail(h.error),i=_t(Wt,h,n,E)){if(E.readyState=1,f&&y.trigger("ajaxSend",[E,h]),c)return E;h.async&&h.timeout>0&&(u=e.setTimeout(function(){E.abort("timeout")},h.timeout));try{c=!1,i.send(b,k)}catch(e){if(c)throw e;k(-1,e)}}else k(-1,"No Transport");function k(t,n,r,s){var l,p,d,b,T,C=n;c||(c=!0,u&&e.clearTimeout(u),i=void 0,a=s||"",E.readyState=t>0?4:0,l=t>=200&&t<300||304===t,r&&(b=Xt(h,E,r)),b=Ut(h,b,E,l),l?(h.ifModified&&((T=E.getResponseHeader("Last-Modified"))&&(w.lastModified[o]=T),(T=E.getResponseHeader("etag"))&&(w.etag[o]=T)),204===t||"HEAD"===h.type?C="nocontent":304===t?C="notmodified":(C=b.state,p=b.data,l=!(d=b.error))):(d=C,!t&&C||(C="error",t<0&&(t=0))),E.status=t,E.statusText=(n||C)+"",l?v.resolveWith(g,[p,C,E]):v.rejectWith(g,[E,C,d]),E.statusCode(x),x=void 0,f&&y.trigger(l?"ajaxSuccess":"ajaxError",[E,h,l?p:d]),m.fireWith(g,[E,C]),f&&(y.trigger("ajaxComplete",[E,h]),--w.active||w.event.trigger("ajaxStop")))}return E},getJSON:function(e,t,n){return w.get(e,t,n,"json")},getScript:function(e,t){return w.get(e,void 0,t,"script")}}),w.each(["get","post"],function(e,t){w[t]=function(e,n,r,i){return g(n)&&(i=i||r,r=n,n=void 0),w.ajax(w.extend({url:e,type:t,dataType:i,data:n,success:r},w.isPlainObject(e)&&e))}}),w._evalUrl=function(e){return w.ajax({url:e,type:"GET",dataType:"script",cache:!0,async:!1,global:!1,"throws":!0})},w.fn.extend({wrapAll:function(e){var t;return this[0]&&(g(e)&&(e=e.call(this[0])),t=w(e,this[0].ownerDocument).eq(0).clone(!0),this[0].parentNode&&t.insertBefore(this[0]),t.map(function(){var e=this;while(e.firstElementChild)e=e.firstElementChild;return e}).append(this)),this},wrapInner:function(e){return g(e)?this.each(function(t){w(this).wrapInner(e.call(this,t))}):this.each(function(){var t=w(this),n=t.contents();n.length?n.wrapAll(e):t.append(e)})},wrap:function(e){var t=g(e);return this.each(function(n){w(this).wrapAll(t?e.call(this,n):e)})},unwrap:function(e){return this.parent(e).not("body").each(function(){w(this).replaceWith(this.childNodes)}),this}}),w.expr.pseudos.hidden=function(e){return!w.expr.pseudos.visible(e)},w.expr.pseudos.visible=function(e){return!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)},w.ajaxSettings.xhr=function(){try{return new e.XMLHttpRequest}catch(e){}};var Vt={0:200,1223:204},Gt=w.ajaxSettings.xhr();h.cors=!!Gt&&"withCredentials"in Gt,h.ajax=Gt=!!Gt,w.ajaxTransport(function(t){var n,r;if(h.cors||Gt&&!t.crossDomain)return{send:function(i,o){var a,s=t.xhr();if(s.open(t.type,t.url,t.async,t.username,t.password),t.xhrFields)for(a in t.xhrFields)s[a]=t.xhrFields[a];t.mimeType&&s.overrideMimeType&&s.overrideMimeType(t.mimeType),t.crossDomain||i["X-Requested-With"]||(i["X-Requested-With"]="XMLHttpRequest");for(a in i)s.setRequestHeader(a,i[a]);n=function(e){return function(){n&&(n=r=s.onload=s.onerror=s.onabort=s.ontimeout=s.onreadystatechange=null,"abort"===e?s.abort():"error"===e?"number"!=typeof s.status?o(0,"error"):o(s.status,s.statusText):o(Vt[s.status]||s.status,s.statusText,"text"!==(s.responseType||"text")||"string"!=typeof s.responseText?{binary:s.response}:{text:s.responseText},s.getAllResponseHeaders()))}},s.onload=n(),r=s.onerror=s.ontimeout=n("error"),void 0!==s.onabort?s.onabort=r:s.onreadystatechange=function(){4===s.readyState&&e.setTimeout(function(){n&&r()})},n=n("abort");try{s.send(t.hasContent&&t.data||null)}catch(e){if(n)throw e}},abort:function(){n&&n()}}}),w.ajaxPrefilter(function(e){e.crossDomain&&(e.contents.script=!1)}),w.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/\b(?:java|ecma)script\b/},converters:{"text script":function(e){return w.globalEval(e),e}}}),w.ajaxPrefilter("script",function(e){void 0===e.cache&&(e.cache=!1),e.crossDomain&&(e.type="GET")}),w.ajaxTransport("script",function(e){if(e.crossDomain){var t,n;return{send:function(i,o){t=w(" 12 | 13 | 14 | 15 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 32 | 37 | 38 | 39 |
40 |
41 |
42 | 43 | 44 | 45 | 48 | 51 | 52 | 53 | 56 | 59 | 60 | 61 | 64 | 67 | 68 | 69 | 72 | 75 | 76 | 92 | 93 | 99 | 100 |
46 | sm2公钥: 47 | 49 | 50 |
54 | sm2私钥: 55 | 57 | 58 |
62 | 输入数据: 63 | 65 | 66 |
70 | 结果: 71 | 73 | 74 |
94 | 95 | 96 | 97 | 98 |
101 | 102 |
103 |
104 |
105 | 248 | 249 | 250 | -------------------------------------------------------------------------------- /sm3Test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 |
17 | 18 | 19 | 20 | 23 | 26 | 27 | 28 | 31 | 34 | 35 | 36 | 37 | 41 | 42 |
21 | 输入数据: 22 | 24 | 25 |
29 | 结果: 30 | 32 | 33 |
38 | 39 | 40 |
43 | 44 |
45 |
46 | 47 | 83 | 84 | -------------------------------------------------------------------------------- /sm4Test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 |
24 | 25 | 26 | 27 | 30 | 33 | 34 | 35 | 38 | 41 | 42 | 43 | 46 | 49 | 50 | 51 | 54 | 57 | 58 | 59 | 60 | 65 | 66 | 67 | 73 | 74 |
28 | 输入密钥
(16进制): 29 |
31 | 32 |
36 | 输入数据: 37 | 39 | 40 |
44 | cbc模式IV
(16进制): 45 |
47 | 48 |
52 | 结果: 53 | 55 | 56 |
61 | 62 | 63 | 64 |
68 | 69 | 70 | 71 | 72 |
75 | 76 |
77 |
78 | 340 | 341 | --------------------------------------------------------------------------------