summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtc%google.com <devnull@localhost>2008-11-18 00:14:48 +0000
committerwtc%google.com <devnull@localhost>2008-11-18 00:14:48 +0000
commite8155aee66d556c153e6d470fff0b120cbd913df (patch)
tree8f11d704473b2fad5fd83b0122648018db46313a
parent54e996e6957c06f16f6e09c079825dfdf368c8e7 (diff)
downloadnss-hg-e8155aee66d556c153e6d470fff0b120cbd913df.tar.gz
Bug 335016: In mpp_pprime, do not choose 0 or 1 as 'x' (the random integer
in the Miller-Rabin probabilistic primality test). r=nelson.
-rw-r--r--security/nss/lib/freebl/mpi/mpprime.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/security/nss/lib/freebl/mpi/mpprime.c b/security/nss/lib/freebl/mpi/mpprime.c
index 4d6428118..ae8e49618 100644
--- a/security/nss/lib/freebl/mpi/mpprime.c
+++ b/security/nss/lib/freebl/mpi/mpprime.c
@@ -329,10 +329,14 @@ mp_err mpp_pprime(mp_int *a, int nt)
/* Do the test nt times... */
for(iter = 0; iter < nt; iter++) {
- /* Choose a random value for x < a */
+ /* Choose a random value for 1 < x < a */
s_mp_pad(&x, USED(a));
mpp_random(&x);
MP_CHECKOK( mp_mod(&x, a, &x) );
+ if(mp_cmp_d(&x, 1) <= 0) {
+ iter--; /* don't count this iteration */
+ continue; /* choose a new x */
+ }
/* Compute z = (x ** m) mod a */
MP_CHECKOK( mp_exptmod(&x, &m, a, &z) );