Tell core that we want to have this packet delivered
[oweals/gnunet.git] / src / util / crypto_hkdf.c
index 0aa653658503d373dc1d79e809a6e616f9fd2825..315a192ba084d98d9f5efb59633c139efca0825e 100644 (file)
  * - Matthias Wachs (08.10.2010)
  */
 
-#include <gcrypt.h>
+/**
+ * Set this to 0 if you compile this code outside of GNUnet.
+ */
+#define GNUNET_BUILD 1
+
+/**
+ * Enable debugging.
+ */
+#define DEBUG_HKDF 0
 
+
+#if GNUNET_BUILD
 #include "platform.h"
 #include "gnunet_crypto_lib.h"
+#else
+#define GNUNET_NO 0
+#define GNUNET_YES 1
+#define GNUNET_SYSERR -1
+#include <stdlib.h>
+#endif
+
+#include <gcrypt.h>
 
-#define DEBUG_HKDF GNUNET_NO
 
 /**
  * @brief Compute the HMAC
@@ -144,10 +161,6 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len,
   if (k == 0)
     return GNUNET_SYSERR;
 
-  // FIXME: what is the check for?
-  if (out_len > (2 ^ 32 * k))
-    return GNUNET_SYSERR;
-
   if (gcry_md_open(&xtr, xtr_algo, GCRY_MD_FLAG_HMAC) != GPG_ERR_NO_ERROR)
     return GNUNET_SYSERR;
 
@@ -229,8 +242,11 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len,
   if (d > 0)
     {
       if (t > 0)
-        memcpy (plain, result - k, k);
-      memset (plain + k + ctx_len, i + 1, 1);
+        {
+          memcpy (plain, result - k, k);
+          i++;
+        }
+      memset (plain + k + ctx_len, i, 1);
       gcry_md_reset (prf);
 #if DEBUG_HKDF
       dump("K(t):d", plain, plain_len);