diff options
Diffstat (limited to 'cipher')
-rw-r--r-- | cipher/Makefile.in | 1 | ||||
-rw-r--r-- | cipher/elgamal.c | 3 | ||||
-rw-r--r-- | cipher/md.c | 1 | ||||
-rw-r--r-- | cipher/primegen.c | 19 | ||||
-rw-r--r-- | cipher/random.c | 1 |
5 files changed, 19 insertions, 6 deletions
diff --git a/cipher/Makefile.in b/cipher/Makefile.in index a1cfa5acd..9e4860f6a 100644 --- a/cipher/Makefile.in +++ b/cipher/Makefile.in @@ -72,6 +72,7 @@ G10_LOCALEDIR = @G10_LOCALEDIR@ GENCAT = @GENCAT@ GMOFILES = @GMOFILES@ GMSGFMT = @GMSGFMT@ +HAVE_ZLIB_H = @HAVE_ZLIB_H@ INSTOBJEXT = @INSTOBJEXT@ INTLDEPS = @INTLDEPS@ INTLLIBS = @INTLLIBS@ diff --git a/cipher/elgamal.c b/cipher/elgamal.c index 1f1699f8f..9e6805d62 100644 --- a/cipher/elgamal.c +++ b/cipher/elgamal.c @@ -142,6 +142,9 @@ elg_generate( ELG_public_key *pk, ELG_secret_key *sk, unsigned nbits ) /* select a random number which has these properties: * 0 < x < p-1 + * This must be a very good random number because this is the + * secret part. The prime is public and may be shared anyware, + * so a random generator level of 1 has been used for the prime */ x = mpi_alloc_secure( nbits/BITS_PER_MPI_LIMB ); if( DBG_CIPHER ) diff --git a/cipher/md.c b/cipher/md.c index eb7b7b845..221cf7199 100644 --- a/cipher/md.c +++ b/cipher/md.c @@ -21,6 +21,7 @@ #include <config.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include "util.h" #include "cipher.h" 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 ); diff --git a/cipher/random.c b/cipher/random.c index 3355abf1a..ac98f54c2 100644 --- a/cipher/random.c +++ b/cipher/random.c @@ -26,6 +26,7 @@ #include <sys/time.h> #include <sys/types.h> #include <sys/stat.h> +#include <string.h> #include <unistd.h> #include <fcntl.h> #include "util.h" |