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