summaryrefslogtreecommitdiff
path: root/mpi/mpiutil.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2006-08-04 10:18:14 +0000
committerWerner Koch <wk@gnupg.org>2006-08-04 10:18:14 +0000
commit5681a844ea16e74ededb45db7e9665b4ffd29045 (patch)
tree2c4d42728b1289c77b2ffe25c6f078ddeae3b19f /mpi/mpiutil.c
parent3c74909c185426e8d794424ff51d62fdbcc19076 (diff)
downloadlibgcrypt-5681a844ea16e74ededb45db7e9665b4ffd29045.tar.gz
Fixed gcry_mpi_set_bit and enhanced mpi_rshift.
Cleaned up andom-daemon initialization.
Diffstat (limited to 'mpi/mpiutil.c')
-rw-r--r--mpi/mpiutil.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c
index f6f9a8b2..fe1b7617 100644
--- a/mpi/mpiutil.c
+++ b/mpi/mpiutil.c
@@ -115,17 +115,30 @@ _gcry_mpi_assign_limb_space( gcry_mpi_t a, mpi_ptr_t ap, unsigned int nlimbs )
/****************
- * Resize the array of A to NLIMBS. the additional space is cleared
- * (set to 0) [done by gcry_realloc()]
+ * Resize the array of A to NLIMBS. The additional space is cleared
+ * (set to 0).
*/
void
_gcry_mpi_resize (gcry_mpi_t a, unsigned nlimbs)
{
+ size_t i;
+
if (nlimbs <= a->alloced)
- return; /* no need to do it */
+ {
+ /* We only need to clear the new space (this is a nop if the
+ limb space is already of the correct size. */
+ for (i=a->nlimbs; i < a->alloced; i++)
+ a->d[i] = 0;
+ return;
+ }
+ /* Actually resize the limb space. */
if (a->d)
- a->d = gcry_xrealloc (a->d, nlimbs * sizeof (mpi_limb_t));
+ {
+ a->d = gcry_xrealloc (a->d, nlimbs * sizeof (mpi_limb_t));
+ for (i=a->alloced; i < nlimbs; i++)
+ a->d[i] = 0;
+ }
else
{
if (a->flags & 1)