MinGW
[oweals/gnunet.git] / src / util / crypto_hash.c
index 0370d74fbe0b6cf87e2648584907520ca5ccf411..dcee545f79e811b20ff2fc1f0272a8d48e25e9c9 100644 (file)
@@ -283,8 +283,6 @@ sha512_final (struct sha512_ctx *sctx, unsigned char *hash)
   unsigned long long t2;
   int i, j;
 
-  i = j = 0;
-
   /* Save number of bits */
   t = sctx->count[0];
   bits[15] = t;
@@ -361,11 +359,10 @@ sha512_final (struct sha512_ctx *sctx, unsigned char *hash)
  * @param ret pointer to where to write the hashcode
  */
 void
-GNUNET_CRYPTO_hash (const void *block, unsigned int size,
-                    GNUNET_HashCode * ret)
+GNUNET_CRYPTO_hash (const void *block, size_t size, GNUNET_HashCode * ret)
 {
   struct sha512_ctx ctx;
-  
+
   sha512_init (&ctx);
   sha512_update (&ctx, block, size);
   sha512_final (&ctx, (unsigned char *) ret);
@@ -417,11 +414,6 @@ struct FileHashContext
    * Current offset.
    */
   uint64_t offset;
-  
-  /**
-   * Run on shutdown?
-   */
-  int run_on_shutdown;
 
   /**
    * File descriptor.
@@ -479,10 +471,7 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
       return;
     }
   GNUNET_SCHEDULER_add_after (tc->sched,
-                              fhc->run_on_shutdown,
-                              GNUNET_SCHEDULER_PRIORITY_KEEP,
-                              GNUNET_SCHEDULER_NO_TASK,
-                              &file_hash_task, fhc);
+                              GNUNET_SCHEDULER_NO_TASK, &file_hash_task, fhc);
 }
 
 
@@ -491,7 +480,6 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  *
  * @param sched scheduler to use
  * @param priority scheduling priority to use
- * @param run_on_shutdown should we complete even on shutdown?
  * @param filename name of file to hash
  * @param blocksize number of bytes to process in one task
  * @param callback function to call upon completion
@@ -500,7 +488,6 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 void
 GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched,
                          enum GNUNET_SCHEDULER_Priority priority,
-                         int run_on_shutdown,
                          const char *filename,
                          size_t blocksize,
                          GNUNET_CRYPTO_HashCompletedCallback callback,
@@ -522,19 +509,15 @@ GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched,
       file_hash_finish (fhc, NULL);
       return;
     }
-  fhc->run_on_shutdown = run_on_shutdown;
   fhc->fh = GNUNET_DISK_file_open (filename,
-      GNUNET_DISK_OPEN_READ);
+                                   GNUNET_DISK_OPEN_READ,
+                                   GNUNET_DISK_PERM_NONE);
   if (!fhc->fh)
     {
       file_hash_finish (fhc, NULL);
       return;
     }
-  GNUNET_SCHEDULER_add_after (sched,
-                              run_on_shutdown,
-                              priority,
-                              GNUNET_SCHEDULER_NO_TASK,
-                              &file_hash_task, fhc);
+  GNUNET_SCHEDULER_add_with_priority (sched, priority, &file_hash_task, fhc);
 }
 
 
@@ -562,9 +545,9 @@ getValue__ (unsigned char a)
  * small number of characters.  The GNUnet encoding uses 102
  * characters plus a null terminator.
  *
- * @param block the GNUNET_CRYPTO_hash code
+ * @param block the hash code
  * @param result where to store the encoding (struct GNUNET_CRYPTO_HashAsciiEncoded can be
- *  safely cast to char*, a '\0' termination is set).
+ *  safely cast to char*, a '\\0' termination is set).
  */
 void
 GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block,
@@ -662,12 +645,12 @@ GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a,
 }
 
 void
-GNUNET_CRYPTO_hash_create_random (GNUNET_HashCode * result)
+GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
+                                  GNUNET_HashCode * result)
 {
   int i;
-  for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
-       i--)
-    result->bits[i] = rand ();
+  for (i = (sizeof (GNUNET_HashCode) / sizeof (uint32_t)) - 1; i >= 0; i--)
+    result->bits[i] = GNUNET_CRYPTO_random_u32 (mode, (uint32_t) - 1);
 }
 
 void
@@ -786,4 +769,4 @@ GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1,
   return 0;
 }
 
-/* end of hashing.c */
+/* end of crypto_hash.c */