mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
Fixed a few bugs
This commit is contained in:
parent
c8f12e218f
commit
899b8378ec
33 changed files with 152 additions and 80 deletions
|
@ -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@
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue