aboutsummaryrefslogtreecommitdiffstats
path: root/cipher/elgamal.c
diff options
context:
space:
mode:
Diffstat (limited to 'cipher/elgamal.c')
-rw-r--r--cipher/elgamal.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/cipher/elgamal.c b/cipher/elgamal.c
index 2141db0cc..b211d7f6c 100644
--- a/cipher/elgamal.c
+++ b/cipher/elgamal.c
@@ -152,9 +152,14 @@ elg_generate( ELG_public_key *pk, ELG_secret_key *sk,
if( DBG_CIPHER )
log_debug("choosing a random x ");
do {
+ byte *rndbuf;
if( DBG_CIPHER )
fputc('.', stderr);
- mpi_set_bytes( x, nbits, get_random_byte, 2 );
+ rndbuf = get_random_bits( nbits, 2, 1 );
+ mpi_set_buffer( x, rndbuf, (nbits+7)/8, 0 );
+ m_free(rndbuf);
+ mpi_clear_highbit( x, nbits+1 );
+ log_mpidump(" x: ", x );
} while( !( mpi_cmp_ui( x, 0 )>0 && mpi_cmp( x, p_min1 )<0 ) );
y = mpi_alloc(nbits/BITS_PER_MPI_LIMB);