File tree Expand file tree Collapse file tree 1 file changed +17
-7
lines changed
core/src/test/java/org/bouncycastle/math/ec/test Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -431,15 +431,25 @@ private void implSqrtTest(ECCurve c)
431431 BigInteger pMinusOne = p .subtract (ECConstants .ONE );
432432 BigInteger legendreExponent = p .shiftRight (1 );
433433
434- int count = 0 ;
435- while (count < 10 )
434+ ECFieldElement zero = c .fromBigInteger (BigInteger .ZERO );
435+ assertEquals (zero , zero .sqrt ());
436+
437+ ECFieldElement one = c .fromBigInteger (BigInteger .ONE );
438+ assertEquals (one , one .sqrt ());
439+
440+ for (int i = 0 ; i < 20 ; ++i )
436441 {
437- BigInteger nonSquare = BigIntegers .createRandomInRange (ECConstants .TWO , pMinusOne , secRand );
438- if (!nonSquare .modPow (legendreExponent , p ).equals (ECConstants .ONE ))
442+ BigInteger x = BigIntegers .createRandomInRange (ECConstants .TWO , pMinusOne , secRand );
443+ ECFieldElement fe = c .fromBigInteger (x );
444+ ECFieldElement root = fe .sqrt ();
445+
446+ if (root == null )
447+ {
448+ assertEquals (pMinusOne , x .modPow (legendreExponent , p ));
449+ }
450+ else
439451 {
440- ECFieldElement root = c .fromBigInteger (nonSquare ).sqrt ();
441- assertNull (root );
442- ++count ;
452+ assertEquals (fe , root .square ());
443453 }
444454 }
445455 }
You can’t perform that action at this time.
0 commit comments