aboutsummaryrefslogtreecommitdiffstats
path: root/cipher/elgamal.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>1997-12-19 11:41:47 +0000
committerWerner Koch <[email protected]>1997-12-19 11:41:47 +0000
commitee8d92fefa5902f97e92856b9c657fb18d0dd93e (patch)
treecf86cf2d45d7dbeb3f8c01a53402435ac1257f88 /cipher/elgamal.c
parentadded some stuff for signing keys (diff)
downloadgnupg-ee8d92fefa5902f97e92856b9c657fb18d0dd93e.tar.gz
gnupg-ee8d92fefa5902f97e92856b9c657fb18d0dd93e.zip
better prime number generator. improved ELG key generation
Diffstat (limited to 'cipher/elgamal.c')
-rw-r--r--cipher/elgamal.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/cipher/elgamal.c b/cipher/elgamal.c
index 4252b48d1..3cc632525 100644
--- a/cipher/elgamal.c
+++ b/cipher/elgamal.c
@@ -94,7 +94,7 @@ gen_k( MPI p )
for(;;) {
if( DBG_CIPHER )
fputc('.', stderr);
- mpi_set_bytes( k, nbits, get_random_byte, 1 );
+ mpi_set_bytes( k, nbits , get_random_byte, 1 );
if( !(mpi_cmp( k, p_1 ) < 0) ) /* check: k < (p-1) */
continue; /* no */
if( !(mpi_cmp_ui( k, 0 ) > 0) ) /* check: k > 0 */
@@ -123,19 +123,23 @@ elg_generate( ELG_public_key *pk, ELG_secret_key *sk, unsigned nbits )
MPI x; /* the secret exponent */
MPI y;
MPI temp;
+ unsigned qbits;
- p = NULL;
p_min1 = mpi_alloc( (nbits+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );
temp = mpi_alloc( (nbits+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );
- /*do {*/
- mpi_free(p);
- /* FIXME!!!! Should generate a strong prime */
- p = generate_public_prime( nbits );
- mpi_sub_ui(p_min1, p, 1);
- /*} while if( mpi_gcd( temp, k, p_1 ) )*/
+ if( nbits < 512 )
+ qbits = 120;
+ else if( nbits <= 1024 )
+ qbits = 160;
+ else if( nbits <= 2048 )
+ qbits = 200;
+ else
+ qbits = 240;
+ g = mpi_alloc(1);
+ p = generate_elg_prime( nbits, qbits, g );
+ mpi_sub_ui(p_min1, p, 1);
- g = mpi_alloc_set_ui(3); /* fixme: 3 is bad (but better than 2)*/
/* select a random number which has these properties:
* 0 < x < p-1
*/