[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
java.security expert?
From: |
Andrew Haley |
Subject: |
java.security expert? |
Date: |
Sat, 6 Mar 2004 11:38:30 +0000 |
Tom Tromey writes:
> While debugging gcjx, I ran across some strange code in Prime.java.
> I think the intention was for the code to resemble the result of the
> appended patch. The patch looks big, but it just wraps the body in a
> `while (true)' and changes a `break' to `continue'.
--text follows this line--
`diff -w' is your friend.
Index: Prime.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/security/util/Prime.java,v
retrieving revision 1.3
diff -u -w -r1.3 Prime.java
--- Prime.java 11 Aug 2002 16:34:44 -0000 1.3
+++ Prime.java 6 Mar 2004 11:24:58 -0000
@@ -1,5 +1,5 @@
/* Prime.java --- Prime number generation utilities
- Copyright (C) 1999 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -105,14 +105,19 @@
/*
See IEEE P1363 A.15.5 (10/05/98 Draft)
*/
- public static BigInteger generateRandomPrime( BigInteger r, BigInteger a,
int pmin, int pmax, BigInteger f )
+ public static BigInteger generateRandomPrime( BigInteger r, BigInteger a,
+ int pmin, int pmax,
+ BigInteger f )
{
BigInteger d, w;
//Step 1 - generate prime
BigInteger p = new BigInteger( (pmax + pmin)/2, new Random() );
- steptwo:{ //Step 2
+ steptwo:
+ while (true)
+ {
+ //Step 2
w = p.mod( r.multiply( BigInteger.valueOf(2) ));
//Step 3
@@ -121,7 +126,8 @@
p = p.add(a);
//Step 4 - test for even
- if( p.mod( BigInteger.valueOf(2) ).compareTo( BigInteger.valueOf( 0 ))
== 0)
+ if( p.mod( BigInteger.valueOf(2) ).compareTo( BigInteger.valueOf( 0 ))
+ == 0)
p.add( r );
for(;;)
@@ -135,7 +141,7 @@
p = p.subtract( BigInteger.valueOf( 1 ) );
//Step 5.2 - goto to Step 2
- break steptwo;
+ continue steptwo;
}
//Step 6
@@ -158,7 +164,5 @@
//Step 9
}
}
- //Should never reach here but makes the compiler happy
- return BigInteger.valueOf(0);
}
}
> Any comments on this? I didn't look up the IEEE spec that this
> references, for all I know the comments are the only part that are
> wrong.
Your patch looks right to me.
Andrew.