michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 452008; michael@0: var summary = 'Bad math with JIT'; michael@0: var actual = ''; michael@0: var expect = ''; michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: function test() michael@0: { michael@0: enterFunc ('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: jit(true); michael@0: michael@0: // regression test for Bug 452008 - TM: SRP in Clipperz crypto library fails when JIT (TraceMonkey) is enabled. michael@0: michael@0: var x = [9385, 32112, 25383, 16317, 30138, 14565, 17812, 24500, 2719, 30174, 3546, 9096, 15352, 19120, 20648, 14334, 7426, 0, 0, 0]; michael@0: var n = [27875, 25925, 30422, 12227, 27798, 32170, 10873, 21748, 30629, 26296, 20697, 5125, 4815, 2221, 14392, 23369, 5560, 2, 0, 0]; michael@0: var np = 18229; michael@0: var expected = [18770, 31456, 17999, 32635, 27508, 29131, 2856, 16233, 5439, 27580, 7093, 18192, 30804, 5472, 8529, 28649, 14852, 0, 0, 0]; michael@0: michael@0: //globals michael@0: bpe=0; //bits stored per array element michael@0: mask=0; //AND this with an array element to chop it down to bpe bits michael@0: michael@0: //initialize the global variables michael@0: for (bpe=0; (1<<(bpe+1)) > (1<>=1; //bpe=number of bits in one element of the array representing the bigInt michael@0: mask=(1<>=bpe; michael@0: } michael@0: } michael@0: michael@0: //is x > y? (x and y both nonnegative) michael@0: function greater(x,y) { michael@0: var i; michael@0: var k=(x.length=0;i--) michael@0: if (x[i]>y[i]) michael@0: return 1; michael@0: else if (x[i]0 && n[kn-1]==0;kn--); //ignore leading zeros of n michael@0: for (;ky>0 && y[ky-1]==0;ky--); //ignore leading zeros of y michael@0: michael@0: copyInt_(sa,0); michael@0: michael@0: //the following loop consumes 95% of the runtime for randTruePrime_() and powMod_() for large keys michael@0: for (i=0; i> bpe; michael@0: t=x[i]; michael@0: michael@0: //do sa=(sa+x[i]*y+ui*n)/b where b=2**bpe michael@0: for (j=1;j>=bpe; michael@0: } michael@0: for (;j>=bpe; michael@0: } michael@0: sa[j-1]=c & mask; michael@0: } michael@0: michael@0: if (!greater(n,sa)) michael@0: sub_(sa,n); michael@0: copy_(x,sa); michael@0: } michael@0: michael@0: mont_(x, x, n, np); michael@0: michael@0: var passed = expected.length == x.length; michael@0: for (var i = 0; i < expected.length; i++) { michael@0: if (passed) michael@0: passed = expected[i] == x[i]; michael@0: } michael@0: print(passed); michael@0: michael@0: jit(false); michael@0: michael@0: expect = true; michael@0: actual = passed; michael@0: michael@0: reportCompare(expect, actual, summary); michael@0: michael@0: exitFunc ('test'); michael@0: }