gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r34854 - in gnunet/src: include util


From: gnunet
Subject: [GNUnet-SVN] r34854 - in gnunet/src: include util
Date: Fri, 9 Jan 2015 17:27:28 +0100

Author: grothoff
Date: 2015-01-09 17:27:28 +0100 (Fri, 09 Jan 2015)
New Revision: 34854

Modified:
   gnunet/src/include/gnunet_crypto_lib.h
   gnunet/src/util/crypto_hash.c
Log:
adding API for incremental hashing (from Taler)

Modified: gnunet/src/include/gnunet_crypto_lib.h
===================================================================
--- gnunet/src/include/gnunet_crypto_lib.h      2015-01-09 15:51:57 UTC (rev 
34853)
+++ gnunet/src/include/gnunet_crypto_lib.h      2015-01-09 16:27:28 UTC (rev 
34854)
@@ -633,10 +633,60 @@
  * @param ret pointer to where to write the hashcode
  */
 void
-GNUNET_CRYPTO_hash (const void *block, size_t size, struct GNUNET_HashCode * 
ret);
+GNUNET_CRYPTO_hash (const void *block,
+                    size_t size,
+                    struct GNUNET_HashCode *ret);
 
 
 /**
+ * Context for cummulative hashing.
+ */
+struct GNUNET_HashContext;
+
+
+/**
+ * Start incremental hashing operation.
+ *
+ * @return context for incremental hash computation
+ */
+struct GNUNET_HashContext *
+GNUNET_CRYPTO_hash_context_start (void);
+
+
+/**
+ * Add data to be hashed.
+ *
+ * @param hc cummulative hash context
+ * @param buf data to add
+ * @param size number of bytes in @a buf
+ */
+void
+GNUNET_CRYPTO_hash_context_read (struct GNUNET_HashContext *hc,
+                         const void *buf,
+                         size_t size);
+
+
+/**
+ * Finish the hash computation.
+ *
+ * @param hc hash context to use, is freed in the process
+ * @param r_hash where to write the latest / final hash code
+ */
+void
+GNUNET_CRYPTO_hash_context_finish (struct GNUNET_HashContext *hc,
+                           struct GNUNET_HashCode *r_hash);
+
+
+/**
+ * Abort hashing, do not bother calculating final result.
+ *
+ * @param hc hash context to destroy
+ */
+void
+GNUNET_CRYPTO_hash_context_abort (struct GNUNET_HashContext *hc);
+
+
+/**
  * @ingroup hash
  * Calculate HMAC of a message (RFC 2104)
  *

Modified: gnunet/src/util/crypto_hash.c
===================================================================
--- gnunet/src/util/crypto_hash.c       2015-01-09 15:51:57 UTC (rev 34853)
+++ gnunet/src/util/crypto_hash.c       2015-01-09 16:27:28 UTC (rev 34854)
@@ -588,4 +588,85 @@
 }
 
 
+/**
+ * Context for cummulative hashing.
+ */
+struct GNUNET_HashContext
+{
+  /**
+   * Internal state of the hash function.
+   */
+  gcry_md_hd_t hd;
+};
+
+
+/**
+ * Start incremental hashing operation.
+ *
+ * @return context for incremental hash computation
+ */
+struct GNUNET_HashContext *
+GNUNET_CRYPTO_hash_context_start ()
+{
+  struct GNUNET_HashContext *hc;
+
+  hc = GNUNET_new (struct GNUNET_HashContext);
+  GNUNET_assert (0 ==
+                 gcry_md_open (&hc->hd,
+                               GCRY_MD_SHA512,
+                               0));
+  return hc;
+}
+
+
+/**
+ * Add data to be hashed.
+ *
+ * @param hc cummulative hash context
+ * @param buf data to add
+ * @param size number of bytes in @a buf
+ */
+void
+GNUNET_CRYPTO_hash_context_read (struct GNUNET_HashContext *hc,
+                         const void *buf,
+                         size_t size)
+{
+  gcry_md_write (hc->hd, buf, size);
+}
+
+
+/**
+ * Finish the hash computation.
+ *
+ * @param hc hash context to use
+ * @param r_hash where to write the latest / final hash code
+ */
+void
+GNUNET_CRYPTO_hash_context_finish (struct GNUNET_HashContext *hc,
+                           struct GNUNET_HashCode *r_hash)
+{
+  const void *res = gcry_md_read (hc->hd, 0);
+
+  GNUNET_assert (NULL != res);
+  if (NULL != r_hash)
+    memcpy (r_hash,
+            res,
+            sizeof (struct GNUNET_HashCode));
+  GNUNET_CRYPTO_hash_context_abort (hc);
+}
+
+
+/**
+ * Abort hashing, do not bother calculating final result.
+ *
+ * @param hc hash context to destroy
+ */
+void
+GNUNET_CRYPTO_hash_context_abort (struct GNUNET_HashContext *hc)
+{
+  gcry_md_close (hc->hd);
+  GNUNET_free (hc);
+}
+
+
 /* end of crypto_hash.c */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]