diff options
author | Werner Koch <wk@gnupg.org> | 1998-02-03 13:09:20 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 1998-02-03 13:09:20 +0100 |
commit | 899b8378eca7a3801d02bab5fb4cd13dfb6a8595 (patch) | |
tree | 71b685933a39dfbdc7d6801775dc2c6ff99aeddf /cipher/primegen.c | |
parent | changed structure of trustdb (diff) | |
download | gnupg2-899b8378eca7a3801d02bab5fb4cd13dfb6a8595.tar.xz gnupg2-899b8378eca7a3801d02bab5fb4cd13dfb6a8595.zip |
Fixed a few bugs
Diffstat (limited to 'cipher/primegen.c')
-rw-r--r-- | cipher/primegen.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/cipher/primegen.c b/cipher/primegen.c index 9514fdae8..9d91ae4df 100644 --- a/cipher/primegen.c +++ b/cipher/primegen.c @@ -58,6 +58,12 @@ generate_public_prime( unsigned nbits ) } +/**************** + * We do not need to use the strongest RNG because we gain no extra + * security from it - The prime number is public and we could also + * offer the factors for those who are willing to check that it is + * indeed a strong prime. + */ MPI generate_elg_prime( unsigned pbits, unsigned qbits, MPI g ) { @@ -87,7 +93,7 @@ generate_elg_prime( unsigned pbits, unsigned qbits, MPI g ) pbits, qbits, fbits, n ); prime = mpi_alloc( (pbits + BITS_PER_MPI_LIMB - 1) / BITS_PER_MPI_LIMB ); - q = gen_prime( qbits, 0, 2 ); + q = gen_prime( qbits, 0, 1 ); /* allocate an array to hold the factors + 2 for later usage */ factors = m_alloc_clear( (n+2) * sizeof *factors ); @@ -112,7 +118,7 @@ generate_elg_prime( unsigned pbits, unsigned qbits, MPI g ) perms = m_alloc_clear( m ); for(i=0; i < n; i++ ) { perms[i] = 1; - pool[i] = gen_prime( fbits, 0, 2 ); + pool[i] = gen_prime( fbits, 0, 1 ); factors[i] = pool[i]; } } @@ -121,7 +127,7 @@ generate_elg_prime( unsigned pbits, unsigned qbits, MPI g ) for(i=j=0; i < m && j < n ; i++ ) if( perms[i] ) { if( !pool[i] ) - pool[i] = gen_prime( fbits, 0, 2 ); + pool[i] = gen_prime( fbits, 0, 1 ); factors[j++] = pool[i]; } if( i == n ) { @@ -142,7 +148,7 @@ generate_elg_prime( unsigned pbits, unsigned qbits, MPI g ) count1 = 0; qbits++; fputc('>', stderr); - q = gen_prime( qbits, 0, 2 ); + q = gen_prime( qbits, 0, 1 ); goto next_try; } } @@ -153,7 +159,7 @@ generate_elg_prime( unsigned pbits, unsigned qbits, MPI g ) count2 = 0; qbits--; fputc('<', stderr); - q = gen_prime( qbits, 0, 2 ); + q = gen_prime( qbits, 0, 1 ); goto next_try; } } @@ -379,8 +385,9 @@ is_prime( MPI n, int steps, int *count ) else { mpi_set_bytes( x, nbits-1, get_random_byte, 0 ); /* work around a bug in mpi_set_bytes */ - if( mpi_test_bit( x, nbits-2 ) ) + if( mpi_test_bit( x, nbits-2 ) ) { mpi_set_highbit( x, nbits-2 ); /* clear all higher bits */ + } else { mpi_set_highbit( x, nbits-2 ); mpi_clear_bit( x, nbits-2 ); |