diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-06-26 12:16:12 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-06-26 12:16:12 +0000 |
commit | 248fc3245a98731cf6fbb1bf460cd4e2e2d56de8 (patch) | |
tree | c0606c24a1c74d5f507d267b03d267a5cfaf4009 /src/regex/regex_block_lib.c | |
parent | c0101989bb0864a3688f57370e712c91c14ab1cd (diff) | |
download | gnunet-248fc3245a98731cf6fbb1bf460cd4e2e2d56de8.tar.gz gnunet-248fc3245a98731cf6fbb1bf460cd4e2e2d56de8.zip |
-moving REGEX_INTERNAL_check_proof to libgnunetregexblock, integrating proof check into block plugin
Diffstat (limited to 'src/regex/regex_block_lib.c')
-rw-r--r-- | src/regex/regex_block_lib.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/regex/regex_block_lib.c b/src/regex/regex_block_lib.c index 3a18a731f..83b61b7c6 100644 --- a/src/regex/regex_block_lib.c +++ b/src/regex/regex_block_lib.c | |||
@@ -28,6 +28,35 @@ | |||
28 | 28 | ||
29 | #define LOG(kind,...) GNUNET_log_from (kind,"regex-bck",__VA_ARGS__) | 29 | #define LOG(kind,...) GNUNET_log_from (kind,"regex-bck",__VA_ARGS__) |
30 | 30 | ||
31 | |||
32 | /** | ||
33 | * Check if the given 'proof' matches the given 'key'. | ||
34 | * | ||
35 | * @param proof partial regex of a state | ||
36 | * @param proof_len number of bytes in 'proof' | ||
37 | * @param key hash of a state. | ||
38 | * | ||
39 | * @return GNUNET_OK if the proof is valid for the given key. | ||
40 | */ | ||
41 | int | ||
42 | REGEX_INTERNAL_check_proof (const char *proof, | ||
43 | size_t proof_len, | ||
44 | const struct GNUNET_HashCode *key) | ||
45 | { | ||
46 | struct GNUNET_HashCode key_check; | ||
47 | |||
48 | if ( (NULL == proof) || (NULL == key)) | ||
49 | { | ||
50 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Proof check failed, was NULL.\n"); | ||
51 | return GNUNET_NO; | ||
52 | } | ||
53 | |||
54 | GNUNET_CRYPTO_hash (proof, proof_len, &key_check); | ||
55 | return (0 == | ||
56 | GNUNET_CRYPTO_hash_cmp (key, &key_check)) ? GNUNET_OK : GNUNET_NO; | ||
57 | } | ||
58 | |||
59 | |||
31 | /** | 60 | /** |
32 | * Struct to keep track of the xquery while iterating all the edges in a block. | 61 | * Struct to keep track of the xquery while iterating all the edges in a block. |
33 | */ | 62 | */ |
@@ -100,11 +129,22 @@ REGEX_BLOCK_check (const struct RegexBlock *block, | |||
100 | { | 129 | { |
101 | struct CheckEdgeContext ctx; | 130 | struct CheckEdgeContext ctx; |
102 | int res; | 131 | int res; |
132 | uint32_t len; | ||
103 | 133 | ||
104 | // FIXME: fails to check the proof! | ||
105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 134 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
106 | "Checking block with xquery `%s'\n", | 135 | "Checking block with xquery `%s'\n", |
107 | NULL != xquery ? xquery : "NULL"); | 136 | NULL != xquery ? xquery : "NULL"); |
137 | len = ntohl (block->n_proof); | ||
138 | if (size < sizeof (struct RegexBlock) + len) | ||
139 | { | ||
140 | GNUNET_break_op (0); | ||
141 | return GNUNET_SYSERR; | ||
142 | } | ||
143 | if (GNUNET_OK != REGEX_INTERNAL_check_proof ((const char *) &block[1], len, &block->key)) | ||
144 | { | ||
145 | GNUNET_break_op (0); | ||
146 | return GNUNET_SYSERR; | ||
147 | } | ||
108 | if ( (GNUNET_YES == ntohl (block->accepting)) && | 148 | if ( (GNUNET_YES == ntohl (block->accepting)) && |
109 | ( (NULL == xquery) || ('\0' == xquery[0]) ) ) | 149 | ( (NULL == xquery) || ('\0' == xquery[0]) ) ) |
110 | return GNUNET_OK; | 150 | return GNUNET_OK; |