fix
authorChristian Grothoff <christian@grothoff.org>
Fri, 8 Oct 2010 15:42:50 +0000 (15:42 +0000)
committerChristian Grothoff <christian@grothoff.org>
Fri, 8 Oct 2010 15:42:50 +0000 (15:42 +0000)
src/util/crypto_hash.c
src/util/crypto_ksk.c

index 2217e622367da5bdf976ee1f809e68206f15068b..ab6fc28cfcb35e1c46c5673e1999e44122b5a3b3 100644 (file)
@@ -127,6 +127,7 @@ file_hash_finish (struct GNUNET_CRYPTO_FileHashContext *fhc,
   GNUNET_free (fhc->filename);
   if (!GNUNET_DISK_handle_invalid (fhc->fh))
     GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fhc->fh));
+  gcry_md_close (fhc->md);
   GNUNET_free (fhc);            /* also frees fhc->buffer */
 }
 
@@ -162,7 +163,6 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     {
       res = (GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512);
       file_hash_finish (fhc, res);
-      gcry_md_close (fhc->md);
       return;
     }
   fhc->task 
index 3c4830b76d56d7392de5df940015f57f217f4106..e8f827540cd8b68fa762e95b40f99b133c3e8247 100644 (file)
@@ -87,14 +87,15 @@ mpz_randomize (gcry_mpi_t n, unsigned int nbits, GNUNET_HashCode * rnd)
 
       if (i > 0)
        GNUNET_CRYPTO_hash (&hc, sizeof (GNUNET_HashCode), &tmp);
-      for (j = sizeof(GNUNET_HashCode) / sizeof(unsigned int); j > 0; j--)
+      for (j=0;j<sizeof(GNUNET_HashCode) / sizeof(uint32_t); j++)
         {
-#if HAVE_GCRY_MPI_LSHIFT
-          gcry_mpi_lshift (n, n, sizeof(unsigned int));
+#if HAVE_GCRY_MPI_LSHIFT 
+          gcry_mpi_lshift (n, n, sizeof(uint32_t)*8);
 #else
-          gcry_mpi_mul_ui(n, n, pow (2, sizeof(unsigned int)));
+         gcry_mpi_mul_ui(n, n, 1 << (sizeof(uint32_t)*4));
+         gcry_mpi_mul_ui(n, n, 1 << (sizeof(uint32_t)*4));
 #endif
-          gcry_mpi_add_ui(n, n, ((unsigned int *) &tmp)[j]);
+          gcry_mpi_add_ui(n, n, ((uint32_t *) &tmp)[j]);
         }
       hc = tmp;
     }
@@ -301,7 +302,7 @@ gen_prime (gcry_mpi_t *ptest, unsigned int nbits, GNUNET_HashCode * hc)
   /* Make nbits fit into mpz_t implementation. */
   val_2 = gcry_mpi_set_ui (NULL, 2);
   val_3 = gcry_mpi_set_ui (NULL, 3);
-  prime = gcry_mpi_new(0);
+  prime = gcry_mpi_snew(0);
   result = gcry_mpi_new(0);
   pminus1 = gcry_mpi_new(0);
   *ptest = gcry_mpi_new(0);