Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // |jit-test| error: TypeError |
michael@0 | 2 | function BigInteger(a,b,c) { |
michael@0 | 3 | this.array = new Array(); |
michael@0 | 4 | if(a != null) |
michael@0 | 5 | if("number" == typeof a) this.fromNumber(a,b,c); |
michael@0 | 6 | else this.fromString(a,b); |
michael@0 | 7 | } |
michael@0 | 8 | function nbi() { return new BigInteger(null); } |
michael@0 | 9 | function am3(i,x,w,j,c,n) {} |
michael@0 | 10 | setupEngine = function(fn, bits) { |
michael@0 | 11 | dbits = bits; |
michael@0 | 12 | BI_DB = dbits; |
michael@0 | 13 | BI_DM = ((1<<dbits)-1); |
michael@0 | 14 | } |
michael@0 | 15 | function intAt(s,i) {} |
michael@0 | 16 | function bnpFromInt(x) {} |
michael@0 | 17 | function nbv(i) { var r = nbi(); r.fromInt(i); return r; } |
michael@0 | 18 | function bnpFromString(s,b) { |
michael@0 | 19 | var this_array = this.array; |
michael@0 | 20 | if(b == 16) k = 4; |
michael@0 | 21 | this.t = 0; |
michael@0 | 22 | var i = s.length, mi = false, sh = 0; |
michael@0 | 23 | while(--i >= 0) { |
michael@0 | 24 | var x = (k==8)?s[i]&0xff:intAt(s,i); |
michael@0 | 25 | if(sh == 0) |
michael@0 | 26 | this_array[this.t++] = x; |
michael@0 | 27 | else if(sh+k > BI_DB) { |
michael@0 | 28 | this_array[this.t++] = (x>>(BI_DB-sh)); |
michael@0 | 29 | } |
michael@0 | 30 | sh += k; |
michael@0 | 31 | } |
michael@0 | 32 | } |
michael@0 | 33 | function bnAbs() { return (this.s<0)?this.negate():this; } |
michael@0 | 34 | function nbits(x) { |
michael@0 | 35 | var r = 1, t; |
michael@0 | 36 | return r; |
michael@0 | 37 | } |
michael@0 | 38 | function bnBitLength() {} |
michael@0 | 39 | function bnpDLShiftTo(n,r) { |
michael@0 | 40 | var this_array = this.array; |
michael@0 | 41 | var r_array = r.array; |
michael@0 | 42 | for(i = this.t-1; i >= 0; --i) r_array[i+n] = this_array[i]; |
michael@0 | 43 | r.t = this.t+n; |
michael@0 | 44 | } |
michael@0 | 45 | function bnpLShiftTo(n,r) { |
michael@0 | 46 | var bs = n%BI_DB; |
michael@0 | 47 | var ds = Math.floor(n/BI_DB), c = (this.s<<bs)&BI_DM, i; |
michael@0 | 48 | r.t = this.t+ds+1; |
michael@0 | 49 | } |
michael@0 | 50 | function bnpDivRemTo(m,q,r) { |
michael@0 | 51 | var pm = m.abs(); |
michael@0 | 52 | var pt = this.abs(); |
michael@0 | 53 | var y = nbi(), ts = this.s, ms = m.s; |
michael@0 | 54 | var pm_array = pm.array; |
michael@0 | 55 | var nsh = BI_DB-nbits(pm_array[pm.t-1]); |
michael@0 | 56 | if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); } |
michael@0 | 57 | var ys = y.t; |
michael@0 | 58 | var i = r.t, j = i-ys, t = (q==null)?nbi():q; |
michael@0 | 59 | y.dlShiftTo(j,t); |
michael@0 | 60 | BigInteger.ONE.dlShiftTo(ys,t); |
michael@0 | 61 | } |
michael@0 | 62 | function bnMod(a) { |
michael@0 | 63 | var r = nbi(); |
michael@0 | 64 | this.abs().divRemTo(a,null,r); |
michael@0 | 65 | } |
michael@0 | 66 | function Montgomery(m) { |
michael@0 | 67 | this.m = m; |
michael@0 | 68 | } |
michael@0 | 69 | function montConvert(x) { |
michael@0 | 70 | var r = nbi(); |
michael@0 | 71 | x.abs().dlShiftTo(this.m.t,r); |
michael@0 | 72 | r.divRemTo(this.m,null,r); |
michael@0 | 73 | } |
michael@0 | 74 | function montRevert(x) { |
michael@0 | 75 | var r = nbi(); |
michael@0 | 76 | return r; |
michael@0 | 77 | } |
michael@0 | 78 | Montgomery.prototype.convert = montConvert; |
michael@0 | 79 | Montgomery.prototype.revert = montRevert; |
michael@0 | 80 | function bnpIsEven() {} |
michael@0 | 81 | function bnpExp(e,z) { |
michael@0 | 82 | var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1; |
michael@0 | 83 | return z.revert(r); |
michael@0 | 84 | } |
michael@0 | 85 | function bnModPowInt(e,m) { |
michael@0 | 86 | if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m); |
michael@0 | 87 | return this.exp(e,z); |
michael@0 | 88 | } |
michael@0 | 89 | BigInteger.prototype.fromInt = bnpFromInt; |
michael@0 | 90 | BigInteger.prototype.fromString = bnpFromString; |
michael@0 | 91 | BigInteger.prototype.dlShiftTo = bnpDLShiftTo; |
michael@0 | 92 | BigInteger.prototype.lShiftTo = bnpLShiftTo; |
michael@0 | 93 | BigInteger.prototype.divRemTo = bnpDivRemTo; |
michael@0 | 94 | BigInteger.prototype.isEven = bnpIsEven; |
michael@0 | 95 | BigInteger.prototype.exp = bnpExp; |
michael@0 | 96 | BigInteger.prototype.abs = bnAbs; |
michael@0 | 97 | BigInteger.prototype.bitLength = bnBitLength; |
michael@0 | 98 | BigInteger.prototype.mod = bnMod; |
michael@0 | 99 | BigInteger.prototype.modPowInt = bnModPowInt; |
michael@0 | 100 | BigInteger.ONE = nbv(1); |
michael@0 | 101 | function parseBigInt(str,r) { |
michael@0 | 102 | return new BigInteger(str,r); |
michael@0 | 103 | } |
michael@0 | 104 | function pkcs1pad2(s,n) { |
michael@0 | 105 | var ba = new Array(); |
michael@0 | 106 | return new BigInteger(ba); |
michael@0 | 107 | } |
michael@0 | 108 | function RSAKey() { |
michael@0 | 109 | } |
michael@0 | 110 | function RSASetPublic(N,E) { |
michael@0 | 111 | this.n = parseBigInt(N,16); |
michael@0 | 112 | } |
michael@0 | 113 | function RSADoPublic(x) { |
michael@0 | 114 | return x.modPowInt(this.e, this.n); |
michael@0 | 115 | } |
michael@0 | 116 | function RSAEncrypt(text) { |
michael@0 | 117 | var m = pkcs1pad2(text,(this.n.bitLength()+7)>>3); |
michael@0 | 118 | var c = this.doPublic(m); |
michael@0 | 119 | var h = c.toString(16); |
michael@0 | 120 | if((h.length & 1) == 0) return h; else return "0" + h; |
michael@0 | 121 | } |
michael@0 | 122 | RSAKey.prototype.doPublic = RSADoPublic; |
michael@0 | 123 | RSAKey.prototype.setPublic = RSASetPublic; |
michael@0 | 124 | RSAKey.prototype.encrypt = RSAEncrypt; |
michael@0 | 125 | function RSASetPrivateEx(N,E,D,P,Q,DP,DQ,C) { |
michael@0 | 126 | this.p = parseBigInt(P,16); |
michael@0 | 127 | } |
michael@0 | 128 | function RSADoPrivate(x) { |
michael@0 | 129 | var xp = x.mod(this.p).modPow(this.dmp1, this.p); |
michael@0 | 130 | } |
michael@0 | 131 | function RSADecrypt(ctext) { |
michael@0 | 132 | var c = parseBigInt(ctext, 16); |
michael@0 | 133 | var m = this.doPrivate(c); |
michael@0 | 134 | } |
michael@0 | 135 | RSAKey.prototype.doPrivate = RSADoPrivate; |
michael@0 | 136 | RSAKey.prototype.setPrivateEx = RSASetPrivateEx; |
michael@0 | 137 | RSAKey.prototype.decrypt = RSADecrypt; |
michael@0 | 138 | nValue="a5261939975948bb7a58dffe5ff54e65f0498f9175f5a09288810b8975871e99af3b5dd94057b0fc07535f5f97444504fa35169d461d0d30cf0192e307727c065168c788771c561a9400fb49175e9e6aa4e23fe11af69e9412dd23b0cb6684c4c2429bce139e848ab26d0829073351f4acd36074eafd036a5eb83359d2a698d3"; |
michael@0 | 139 | eValue="10001"; |
michael@0 | 140 | dValue="8e9912f6d3645894e8d38cb58c0db81ff516cf4c7e5a14c7f1eddb1459d2cded4d8d293fc97aee6aefb861859c8b6a3d1dfe710463e1f9ddc72048c09751971c4a580aa51eb523357a3cc48d31cfad1d4a165066ed92d4748fb6571211da5cb14bc11b6e2df7c1a559e6d5ac1cd5c94703a22891464fba23d0d965086277a161"; |
michael@0 | 141 | pValue="d090ce58a92c75233a6486cb0a9209bf3583b64f540c76f5294bb97d285eed33aec220bde14b2417951178ac152ceab6da7090905b478195498b352048f15e7d"; |
michael@0 | 142 | qValue="cab575dc652bb66df15a0359609d51d1db184750c00c6698b90ef3465c99655103edbf0d54c56aec0ce3c4d22592338092a126a0cc49f65a4a30d222b411e58f"; |
michael@0 | 143 | dmp1Value="1a24bca8e273df2f0e47c199bbf678604e7df7215480c77c8db39f49b000ce2cf7500038acfff5433b7d582a01f1826e6f4d42e1c57f5e1fef7b12aabc59fd25"; |
michael@0 | 144 | dmq1Value="3d06982efbbe47339e1f6d36b1216b8a741d410b0c662f54f7118b27b9a4ec9d914337eb39841d8666f3034408cf94f5b62f11c402fc994fe15a05493150d9fd"; |
michael@0 | 145 | coeffValue="3a3e731acd8960b7ff9eb81a7ff93bd1cfa74cbd56987db58b4594fb09c09084db1734c8143f98b602b981aaa9243ca28deb69b5b280ee8dcee0fd2625e53250"; |
michael@0 | 146 | setupEngine(am3, 28); |
michael@0 | 147 | function check_correctness(text, hash) { |
michael@0 | 148 | var RSA = new RSAKey(); |
michael@0 | 149 | RSA.setPublic(nValue, eValue); |
michael@0 | 150 | RSA.setPrivateEx(nValue, eValue, dValue, pValue, qValue, dmp1Value, dmq1Value, coeffValue); |
michael@0 | 151 | var encrypted = RSA.encrypt(text); |
michael@0 | 152 | var decrypted = RSA.decrypt(encrypted); |
michael@0 | 153 | } |
michael@0 | 154 | check_correctness("Hello! I am some text.", "142b19b40fee712ab9468be296447d38c7dfe81a7850f11ae6aa21e49396a4e90bd6ba4aa385105e15960a59f95447dfad89671da6e08ed42229939583753be84d07558abb4feee4d46a92fd31d962679a1a5f4bf0fb7af414b9a756e18df7e6d1e96971cc66769f3b27d61ad932f2211373e0de388dc040557d4c3c3fe74320"); |