-moving REGEX_INTERNAL_check_proof to libgnunetregexblock, integrating proof check...
authorChristian Grothoff <christian@grothoff.org>
Wed, 26 Jun 2013 12:16:12 +0000 (12:16 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 26 Jun 2013 12:16:12 +0000 (12:16 +0000)
src/regex/Makefile.am
src/regex/regex_block_lib.c
src/regex/regex_block_lib.h
src/regex/regex_internal.c
src/regex/regex_internal_dht.c
src/regex/regex_internal_lib.h
src/regex/test_regex_iterate_api.c

index 2c20c59049c7338ca18b1d6fb86323ec8b7aa05d..fac89e38db7060f1c93d41eae8153304dfe7abca 100644 (file)
@@ -183,8 +183,8 @@ test_regex_iterate_api_SOURCES = \
   test_regex_iterate_api.c
 test_regex_iterate_api_LDADD = -lm \
   $(top_builddir)/src/regex/libgnunetregex_internal.a \
-  $(top_builddir)/src/dht/libgnunetdht.la \
   $(top_builddir)/src/regex/libgnunetregexblock.la \
+  $(top_builddir)/src/dht/libgnunetdht.la \
   $(top_builddir)/src/util/libgnunetutil.la
 
 test_regex_proofs_SOURCES = \
index 3a18a731ff00e98651c6ed8aea6cbe7fc0a6fa40..83b61b7c624089e22f78ad198d88c3dace5aea86 100644 (file)
 
 #define LOG(kind,...) GNUNET_log_from (kind,"regex-bck",__VA_ARGS__)
 
+
+/**
+ * Check if the given 'proof' matches the given 'key'.
+ *
+ * @param proof partial regex of a state
+ * @param proof_len number of bytes in 'proof'
+ * @param key hash of a state.
+ *
+ * @return GNUNET_OK if the proof is valid for the given key.
+ */
+int
+REGEX_INTERNAL_check_proof (const char *proof,
+                           size_t proof_len,
+                           const struct GNUNET_HashCode *key)
+{
+  struct GNUNET_HashCode key_check;
+
+  if ( (NULL == proof) || (NULL == key))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Proof check failed, was NULL.\n");
+    return GNUNET_NO;
+  }
+
+  GNUNET_CRYPTO_hash (proof, proof_len, &key_check);
+  return (0 ==
+          GNUNET_CRYPTO_hash_cmp (key, &key_check)) ? GNUNET_OK : GNUNET_NO;
+}
+
+
 /**
  * Struct to keep track of the xquery while iterating all the edges in a block.
  */
@@ -100,11 +129,22 @@ REGEX_BLOCK_check (const struct RegexBlock *block,
 {
   struct CheckEdgeContext ctx;
   int res;
+  uint32_t len;
 
-  // FIXME: fails to check the proof!
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Checking block with xquery `%s'\n",
               NULL != xquery ? xquery : "NULL");
+  len = ntohl (block->n_proof);
+  if (size < sizeof (struct RegexBlock) + len)
+  {
+    GNUNET_break_op (0);
+    return GNUNET_SYSERR;
+  }
+  if (GNUNET_OK != REGEX_INTERNAL_check_proof ((const char *) &block[1], len, &block->key))
+  {
+    GNUNET_break_op (0);
+    return GNUNET_SYSERR;
+  }
   if ( (GNUNET_YES == ntohl (block->accepting)) &&
        ( (NULL == xquery) || ('\0' == xquery[0]) ) )
     return GNUNET_OK;
index 79bd20a1e992269346b60665d83663460f26041f..fb1c91353540ebade6dd09bd054f211ae03335b8 100644 (file)
@@ -57,6 +57,21 @@ struct REGEX_BLOCK_Edge
 };
 
 
+/**
+ * Check if the given 'proof' matches the given 'key'.
+ *
+ * @param proof partial regex of a state
+ * @param proof_len number of bytes in 'proof'
+ * @param key hash of a state.
+ *
+ * @return GNUNET_OK if the proof is valid for the given key.
+ */
+int
+REGEX_INTERNAL_check_proof (const char *proof,
+                           size_t proof_len,
+                           const struct GNUNET_HashCode *key);
+
+
 /**
  * Check if the regex block is well formed, including all edges.
  *
@@ -71,8 +86,8 @@ struct REGEX_BLOCK_Edge
  */
 int
 REGEX_BLOCK_check (const struct RegexBlock *block,
-                           size_t size,
-                           const char *xquery);
+                  size_t size,
+                  const char *xquery);
 
 
 /* FIXME: might want to use 'struct REGEX_BLOCK_Edge' here instead of 3 arguments! */
@@ -88,9 +103,9 @@ REGEX_BLOCK_check (const struct RegexBlock *block,
  * @return GNUNET_YES if should keep iterating, GNUNET_NO otherwise.
  */
 typedef int (*REGEX_INTERNAL_EgdeIterator)(void *cls,
-                                         const char *token,
-                                         size_t len,
-                                         const struct GNUNET_HashCode *key);
+                                          const char *token,
+                                          size_t len,
+                                          const struct GNUNET_HashCode *key);
 
 
 /**
index 059aaaed6a65af6950a1770adf542b64b23de935..4ad27c4414f325d3be0d897ac7ab43e730958bef 100644 (file)
@@ -3328,31 +3328,6 @@ REGEX_INTERNAL_get_first_key (const char *input_string, size_t string_len,
 }
 
 
-/**
- * Check if the given 'proof' matches the given 'key'.
- *
- * @param proof partial regex of a state.
- * @param key hash of a state.
- *
- * @return GNUNET_OK if the proof is valid for the given key.
- */
-int
-REGEX_INTERNAL_check_proof (const char *proof, const struct GNUNET_HashCode *key)
-{
-  struct GNUNET_HashCode key_check;
-
-  if (NULL == proof || NULL == key)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Proof check failed, was NULL.\n");
-    return GNUNET_NO;
-  }
-
-  GNUNET_CRYPTO_hash (proof, strlen (proof), &key_check);
-  return (0 ==
-          GNUNET_CRYPTO_hash_cmp (key, &key_check)) ? GNUNET_OK : GNUNET_NO;
-}
-
-
 /**
  * Recursive function that calls the iterator for each synthetic start state.
  *
index bf15b9a967a94564ecab841913c3501107173137..af775ef95cd86765288ae1cb2dc04a241d35a5f0 100644 (file)
@@ -423,18 +423,6 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp,
                                        &((struct RegexBlock *)copy)->key, copy,
                                        GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)
                );
-  len = ntohl (block->n_proof);
-  {
-    char proof[len + 1];
-
-    memcpy (proof, &block[1], len);
-    proof[len] = '\0';
-    if (GNUNET_OK != REGEX_INTERNAL_check_proof (proof, key))
-    {
-      GNUNET_break_op (0);
-      return;
-    }
-  }
   len = strlen (info->description);
   if (len == ctx->position) // String processed
   {
index 1c8946449a08d5850a440dc4447998a3602bc8e6..3d4a1b65c201829743357ea276c4dce40ae9885f 100644 (file)
@@ -107,25 +107,12 @@ REGEX_INTERNAL_get_first_key (const char *input_string, size_t string_len,
                             struct GNUNET_HashCode * key);
 
 
-/**
- * Check if the given 'proof' matches the given 'key'.
- *
- * @param proof partial regex of a state.
- * @param key hash of a state.
- *
- * @return GNUNET_OK if the proof is valid for the given key.
- */
-int
-REGEX_INTERNAL_check_proof (const char *proof,
-                          const struct GNUNET_HashCode *key);
-
-
 /**
  * Iterator callback function.
  *
  * @param cls closure.
  * @param key hash for current state.
- * @param proof proof for current state.
+ * @param proof proof for current state
  * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not.
  * @param num_edges number of edges leaving current state.
  * @param edges edges leaving current state.
index fa94c58ab1e5df2616d14a68f7c7bc12644096e0..06028889761815d51b80169183563f1242aab659 100644 (file)
@@ -26,6 +26,7 @@
 #include <time.h>
 #include "platform.h"
 #include "regex_internal_lib.h"
+#include "regex_block_lib.h"
 #include "regex_internal.h"
 
 /**
@@ -59,7 +60,8 @@ struct RegexStringPair
 
 
 static void
-key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof,
+key_iterator (void *cls, const struct GNUNET_HashCode *key, 
+             const char *proof,
               int accepting, unsigned int num_edges,
               const struct REGEX_BLOCK_Edge *edges)
 {
@@ -101,7 +103,7 @@ key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof,
       ctx->match_count++;
   }
 
-  if (GNUNET_OK != REGEX_INTERNAL_check_proof (proof, key))
+  if (GNUNET_OK != REGEX_INTERNAL_check_proof (proof, strlen (proof), key))
   {
     ctx->error++;
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,