summaryrefslogtreecommitdiff
path: root/mpi
diff options
context:
space:
mode:
Diffstat (limited to 'mpi')
-rw-r--r--mpi/ChangeLog5
-rw-r--r--mpi/mpiutil.c21
2 files changed, 21 insertions, 5 deletions
diff --git a/mpi/ChangeLog b/mpi/ChangeLog
index 3f5ac813..3037538a 100644
--- a/mpi/ChangeLog
+++ b/mpi/ChangeLog
@@ -1,3 +1,8 @@
+2003-12-19 Werner Koch <wk@gnupg.org>
+
+ * mpiutil.c (gcry_mpi_randomize): Use gcry_create_nonce if WEAK
+ random has been requested.
+
2003-10-31 Werner Koch <wk@gnupg.org>
* i386/mpih-rshift.S, i386/mpih-lshift.S: Use %dl and not %edx for
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);
}