1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/ion/bug761835.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,154 @@ 1.4 +// |jit-test| error: TypeError 1.5 +function BigInteger(a,b,c) { 1.6 + this.array = new Array(); 1.7 + if(a != null) 1.8 + if("number" == typeof a) this.fromNumber(a,b,c); 1.9 + else this.fromString(a,b); 1.10 +} 1.11 +function nbi() { return new BigInteger(null); } 1.12 +function am3(i,x,w,j,c,n) {} 1.13 +setupEngine = function(fn, bits) { 1.14 + dbits = bits; 1.15 + BI_DB = dbits; 1.16 + BI_DM = ((1<<dbits)-1); 1.17 +} 1.18 +function intAt(s,i) {} 1.19 +function bnpFromInt(x) {} 1.20 +function nbv(i) { var r = nbi(); r.fromInt(i); return r; } 1.21 +function bnpFromString(s,b) { 1.22 + var this_array = this.array; 1.23 + if(b == 16) k = 4; 1.24 + this.t = 0; 1.25 + var i = s.length, mi = false, sh = 0; 1.26 + while(--i >= 0) { 1.27 + var x = (k==8)?s[i]&0xff:intAt(s,i); 1.28 + if(sh == 0) 1.29 + this_array[this.t++] = x; 1.30 + else if(sh+k > BI_DB) { 1.31 + this_array[this.t++] = (x>>(BI_DB-sh)); 1.32 + } 1.33 + sh += k; 1.34 + } 1.35 +} 1.36 +function bnAbs() { return (this.s<0)?this.negate():this; } 1.37 +function nbits(x) { 1.38 + var r = 1, t; 1.39 + return r; 1.40 +} 1.41 +function bnBitLength() {} 1.42 +function bnpDLShiftTo(n,r) { 1.43 + var this_array = this.array; 1.44 + var r_array = r.array; 1.45 + for(i = this.t-1; i >= 0; --i) r_array[i+n] = this_array[i]; 1.46 + r.t = this.t+n; 1.47 +} 1.48 +function bnpLShiftTo(n,r) { 1.49 + var bs = n%BI_DB; 1.50 + var ds = Math.floor(n/BI_DB), c = (this.s<<bs)&BI_DM, i; 1.51 + r.t = this.t+ds+1; 1.52 +} 1.53 +function bnpDivRemTo(m,q,r) { 1.54 + var pm = m.abs(); 1.55 + var pt = this.abs(); 1.56 + var y = nbi(), ts = this.s, ms = m.s; 1.57 + var pm_array = pm.array; 1.58 + var nsh = BI_DB-nbits(pm_array[pm.t-1]); 1.59 + if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); } 1.60 + var ys = y.t; 1.61 + var i = r.t, j = i-ys, t = (q==null)?nbi():q; 1.62 + y.dlShiftTo(j,t); 1.63 + BigInteger.ONE.dlShiftTo(ys,t); 1.64 +} 1.65 +function bnMod(a) { 1.66 + var r = nbi(); 1.67 + this.abs().divRemTo(a,null,r); 1.68 +} 1.69 +function Montgomery(m) { 1.70 + this.m = m; 1.71 +} 1.72 +function montConvert(x) { 1.73 + var r = nbi(); 1.74 + x.abs().dlShiftTo(this.m.t,r); 1.75 + r.divRemTo(this.m,null,r); 1.76 +} 1.77 +function montRevert(x) { 1.78 + var r = nbi(); 1.79 + return r; 1.80 +} 1.81 +Montgomery.prototype.convert = montConvert; 1.82 +Montgomery.prototype.revert = montRevert; 1.83 +function bnpIsEven() {} 1.84 +function bnpExp(e,z) { 1.85 + var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1; 1.86 + return z.revert(r); 1.87 +} 1.88 +function bnModPowInt(e,m) { 1.89 + if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m); 1.90 + return this.exp(e,z); 1.91 +} 1.92 +BigInteger.prototype.fromInt = bnpFromInt; 1.93 +BigInteger.prototype.fromString = bnpFromString; 1.94 +BigInteger.prototype.dlShiftTo = bnpDLShiftTo; 1.95 +BigInteger.prototype.lShiftTo = bnpLShiftTo; 1.96 +BigInteger.prototype.divRemTo = bnpDivRemTo; 1.97 +BigInteger.prototype.isEven = bnpIsEven; 1.98 +BigInteger.prototype.exp = bnpExp; 1.99 +BigInteger.prototype.abs = bnAbs; 1.100 +BigInteger.prototype.bitLength = bnBitLength; 1.101 +BigInteger.prototype.mod = bnMod; 1.102 +BigInteger.prototype.modPowInt = bnModPowInt; 1.103 +BigInteger.ONE = nbv(1); 1.104 +function parseBigInt(str,r) { 1.105 + return new BigInteger(str,r); 1.106 +} 1.107 +function pkcs1pad2(s,n) { 1.108 + var ba = new Array(); 1.109 + return new BigInteger(ba); 1.110 +} 1.111 +function RSAKey() { 1.112 +} 1.113 +function RSASetPublic(N,E) { 1.114 + this.n = parseBigInt(N,16); 1.115 +} 1.116 +function RSADoPublic(x) { 1.117 + return x.modPowInt(this.e, this.n); 1.118 +} 1.119 +function RSAEncrypt(text) { 1.120 + var m = pkcs1pad2(text,(this.n.bitLength()+7)>>3); 1.121 + var c = this.doPublic(m); 1.122 + var h = c.toString(16); 1.123 + if((h.length & 1) == 0) return h; else return "0" + h; 1.124 +} 1.125 +RSAKey.prototype.doPublic = RSADoPublic; 1.126 +RSAKey.prototype.setPublic = RSASetPublic; 1.127 +RSAKey.prototype.encrypt = RSAEncrypt; 1.128 +function RSASetPrivateEx(N,E,D,P,Q,DP,DQ,C) { 1.129 + this.p = parseBigInt(P,16); 1.130 +} 1.131 +function RSADoPrivate(x) { 1.132 + var xp = x.mod(this.p).modPow(this.dmp1, this.p); 1.133 +} 1.134 +function RSADecrypt(ctext) { 1.135 + var c = parseBigInt(ctext, 16); 1.136 + var m = this.doPrivate(c); 1.137 +} 1.138 +RSAKey.prototype.doPrivate = RSADoPrivate; 1.139 +RSAKey.prototype.setPrivateEx = RSASetPrivateEx; 1.140 +RSAKey.prototype.decrypt = RSADecrypt; 1.141 +nValue="a5261939975948bb7a58dffe5ff54e65f0498f9175f5a09288810b8975871e99af3b5dd94057b0fc07535f5f97444504fa35169d461d0d30cf0192e307727c065168c788771c561a9400fb49175e9e6aa4e23fe11af69e9412dd23b0cb6684c4c2429bce139e848ab26d0829073351f4acd36074eafd036a5eb83359d2a698d3"; 1.142 +eValue="10001"; 1.143 +dValue="8e9912f6d3645894e8d38cb58c0db81ff516cf4c7e5a14c7f1eddb1459d2cded4d8d293fc97aee6aefb861859c8b6a3d1dfe710463e1f9ddc72048c09751971c4a580aa51eb523357a3cc48d31cfad1d4a165066ed92d4748fb6571211da5cb14bc11b6e2df7c1a559e6d5ac1cd5c94703a22891464fba23d0d965086277a161"; 1.144 +pValue="d090ce58a92c75233a6486cb0a9209bf3583b64f540c76f5294bb97d285eed33aec220bde14b2417951178ac152ceab6da7090905b478195498b352048f15e7d"; 1.145 +qValue="cab575dc652bb66df15a0359609d51d1db184750c00c6698b90ef3465c99655103edbf0d54c56aec0ce3c4d22592338092a126a0cc49f65a4a30d222b411e58f"; 1.146 +dmp1Value="1a24bca8e273df2f0e47c199bbf678604e7df7215480c77c8db39f49b000ce2cf7500038acfff5433b7d582a01f1826e6f4d42e1c57f5e1fef7b12aabc59fd25"; 1.147 +dmq1Value="3d06982efbbe47339e1f6d36b1216b8a741d410b0c662f54f7118b27b9a4ec9d914337eb39841d8666f3034408cf94f5b62f11c402fc994fe15a05493150d9fd"; 1.148 +coeffValue="3a3e731acd8960b7ff9eb81a7ff93bd1cfa74cbd56987db58b4594fb09c09084db1734c8143f98b602b981aaa9243ca28deb69b5b280ee8dcee0fd2625e53250"; 1.149 +setupEngine(am3, 28); 1.150 +function check_correctness(text, hash) { 1.151 + var RSA = new RSAKey(); 1.152 + RSA.setPublic(nValue, eValue); 1.153 + RSA.setPrivateEx(nValue, eValue, dValue, pValue, qValue, dmp1Value, dmq1Value, coeffValue); 1.154 + var encrypted = RSA.encrypt(text); 1.155 + var decrypted = RSA.decrypt(encrypted); 1.156 +} 1.157 +check_correctness("Hello! I am some text.", "142b19b40fee712ab9468be296447d38c7dfe81a7850f11ae6aa21e49396a4e90bd6ba4aa385105e15960a59f95447dfad89671da6e08ed42229939583753be84d07558abb4feee4d46a92fd31d962679a1a5f4bf0fb7af414b9a756e18df7e6d1e96971cc66769f3b27d61ad932f2211373e0de388dc040557d4c3c3fe74320");