diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-09-20 10:10:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-09-20 10:10:04 +0000 |
commit | 1aa42a97fb4310dd72a31aad114b6ebe26aebd8a (patch) | |
tree | ed076a8a4dd413efa4cbd67ec6482834b7ebc581 /src/gns/plugin_block_gns.c | |
parent | 37c4704049df39026b5fb043bcebcd7a15ecf1a2 (diff) | |
download | gnunet-1aa42a97fb4310dd72a31aad114b6ebe26aebd8a.tar.gz gnunet-1aa42a97fb4310dd72a31aad114b6ebe26aebd8a.zip |
-core review
Diffstat (limited to 'src/gns/plugin_block_gns.c')
-rw-r--r-- | src/gns/plugin_block_gns.c | 57 |
1 files changed, 24 insertions, 33 deletions
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index 637467a5c..a2faecf2d 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include "gnunet_namestore_service.h" | 29 | #include "gnunet_namestore_service.h" |
30 | #include "block_gns.h" | 30 | #include "block_gns.h" |
31 | #include "gnunet_signatures.h" | 31 | #include "gnunet_signatures.h" |
32 | #include "gns_common.h" | ||
32 | 33 | ||
33 | /** | 34 | /** |
34 | * Number of bits we set per entry in the bloomfilter. | 35 | * Number of bits we set per entry in the bloomfilter. |
@@ -62,15 +63,14 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, | |||
62 | size_t xquery_size, const void *reply_block, | 63 | size_t xquery_size, const void *reply_block, |
63 | size_t reply_block_size) | 64 | size_t reply_block_size) |
64 | { | 65 | { |
65 | char* name; | 66 | const char* name; |
66 | struct GNUNET_HashCode pkey_hash_double; | ||
67 | struct GNUNET_HashCode query_key; | 67 | struct GNUNET_HashCode query_key; |
68 | struct GNUNET_HashCode name_hash_double; | ||
69 | struct GNUNET_HashCode mhash; | 68 | struct GNUNET_HashCode mhash; |
70 | struct GNUNET_HashCode chash; | 69 | struct GNUNET_HashCode chash; |
71 | struct GNUNET_CRYPTO_ShortHashCode pkey_hash; | 70 | struct GNUNET_CRYPTO_ShortHashCode pkey_hash; |
72 | struct GNUNET_CRYPTO_ShortHashCode name_hash; | ||
73 | struct GNSNameRecordBlock *nrb; | 71 | struct GNSNameRecordBlock *nrb; |
72 | struct GNUNET_CRYPTO_HashAsciiEncoded xor_exp; | ||
73 | struct GNUNET_CRYPTO_HashAsciiEncoded xor_got; | ||
74 | uint32_t rd_count; | 74 | uint32_t rd_count; |
75 | char* rd_data = NULL; | 75 | char* rd_data = NULL; |
76 | int rd_len; | 76 | int rd_len; |
@@ -98,20 +98,13 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, | |||
98 | /* this is a reply */ | 98 | /* this is a reply */ |
99 | 99 | ||
100 | nrb = (struct GNSNameRecordBlock *)reply_block; | 100 | nrb = (struct GNSNameRecordBlock *)reply_block; |
101 | name = (char*)&nrb[1]; | 101 | name = (const char*)&nrb[1]; |
102 | GNUNET_CRYPTO_short_hash(&nrb->public_key, | ||
103 | sizeof(nrb->public_key), | ||
104 | &pkey_hash); | ||
105 | |||
106 | GNUNET_CRYPTO_short_hash(name, strlen(name), &name_hash); | ||
107 | 102 | ||
108 | GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double); | 103 | GNUNET_CRYPTO_short_hash (&nrb->public_key, |
109 | GNUNET_CRYPTO_short_hash_double(&pkey_hash, &pkey_hash_double); | 104 | sizeof(nrb->public_key), |
110 | 105 | &pkey_hash); | |
111 | GNUNET_CRYPTO_hash_xor(&pkey_hash_double, &name_hash_double, &query_key); | 106 | GNUNET_GNS_get_key_for_record (name, &pkey_hash, &query_key); |
112 | 107 | ||
113 | struct GNUNET_CRYPTO_HashAsciiEncoded xor_exp; | ||
114 | struct GNUNET_CRYPTO_HashAsciiEncoded xor_got; | ||
115 | GNUNET_CRYPTO_hash_to_enc (&query_key, &xor_exp); | 108 | GNUNET_CRYPTO_hash_to_enc (&query_key, &xor_exp); |
116 | GNUNET_CRYPTO_hash_to_enc (query, &xor_got); | 109 | GNUNET_CRYPTO_hash_to_enc (query, &xor_got); |
117 | 110 | ||
@@ -220,25 +213,23 @@ block_plugin_gns_get_key (void *cls, enum GNUNET_BLOCK_Type type, | |||
220 | const void *block, size_t block_size, | 213 | const void *block, size_t block_size, |
221 | struct GNUNET_HashCode * key) | 214 | struct GNUNET_HashCode * key) |
222 | { | 215 | { |
223 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) | ||
224 | return GNUNET_SYSERR; | ||
225 | struct GNUNET_CRYPTO_ShortHashCode name_hash; | ||
226 | struct GNUNET_CRYPTO_ShortHashCode pkey_hash; | 216 | struct GNUNET_CRYPTO_ShortHashCode pkey_hash; |
227 | struct GNUNET_HashCode name_hash_double; | 217 | const struct GNSNameRecordBlock *nrb = (const struct GNSNameRecordBlock *)block; |
228 | struct GNUNET_HashCode pkey_hash_double; | 218 | const char *name; |
229 | |||
230 | struct GNSNameRecordBlock *nrb = (struct GNSNameRecordBlock *)block; | ||
231 | 219 | ||
232 | GNUNET_CRYPTO_short_hash(&nrb[1], strlen((char*)&nrb[1]), &name_hash); | 220 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) |
233 | GNUNET_CRYPTO_short_hash(&nrb->public_key, | 221 | return GNUNET_SYSERR; |
234 | sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 222 | name = (const char *) &nrb[1]; |
235 | &pkey_hash); | 223 | if (NULL == memchr (name, '\0', block_size - sizeof (struct GNSNameRecordBlock))) |
236 | 224 | { | |
237 | GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double); | 225 | /* malformed, no 0-termination in name */ |
238 | GNUNET_CRYPTO_short_hash_double(&pkey_hash, &pkey_hash_double); | 226 | GNUNET_break_op (0); |
239 | 227 | return GNUNET_SYSERR; | |
240 | GNUNET_CRYPTO_hash_xor(&name_hash_double, &pkey_hash_double, key); | 228 | } |
241 | 229 | GNUNET_CRYPTO_short_hash (&nrb->public_key, | |
230 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
231 | &pkey_hash); | ||
232 | GNUNET_GNS_get_key_for_record (name, &pkey_hash, key); | ||
242 | return GNUNET_OK; | 233 | return GNUNET_OK; |
243 | } | 234 | } |
244 | 235 | ||