diff options
author | Werner Koch <wk@gnupg.org> | 2003-12-19 10:30:48 +0000 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2003-12-19 10:30:48 +0000 |
commit | 0a4eb6a4c9cb42136ec2d9c216e0df4b3cf9f28f (patch) | |
tree | 4435f79bef6c7aa7ae9d15a4e18d5d49b2ea2e29 /mpi/mpiutil.c | |
parent | abc0b0e989f2f2cbaef1ed64816843f112a96fed (diff) | |
download | libgcrypt-0a4eb6a4c9cb42136ec2d9c216e0df4b3cf9f28f.tar.gz |
(gcry_mpi_randomize): Use gcry_create_nonce if WEAK
random has been requested.
Diffstat (limited to 'mpi/mpiutil.c')
-rw-r--r-- | mpi/mpiutil.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c index d04c35e5..cfa0f6d4 100644 --- a/mpi/mpiutil.c +++ b/mpi/mpiutil.c @@ -366,11 +366,22 @@ void gcry_mpi_randomize( gcry_mpi_t w, unsigned int nbits, enum gcry_random_level level ) { - char *p = mpi_is_secure(w) ? gcry_random_bytes( (nbits+7)/8, level ) - : gcry_random_bytes_secure( (nbits+7)/8, level ); -#warning use gcry_create_nonce if the random level is WEAK - _gcry_mpi_set_buffer( w, p, (nbits+7)/8, 0 ); - gcry_free(p); + char *p; + size_t nbytes = (nbits+7)/8; + + if (level == GCRY_WEAK_RANDOM) + { + p = mpi_is_secure(w) ? gcry_xmalloc (nbytes) + : gcry_xmalloc_secure (nbytes); + gcry_create_nonce (p, nbytes); + } + else + { + p = mpi_is_secure(w) ? gcry_random_bytes (nbytes, level) + : gcry_random_bytes_secure (nbytes, level); + } + _gcry_mpi_set_buffer( w, p, nbytes, 0 ); + gcry_free (p); } |