aboutsummaryrefslogtreecommitdiff
path: root/src/gnsrecord
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-04-24 23:28:24 +0200
committerChristian Grothoff <christian@grothoff.org>2018-04-24 23:28:24 +0200
commitbdbb7c684f2c9711989d2543ecc08a95be23e6c4 (patch)
tree28c453ab36c79aa5058ec64f4b42889216098c5a /src/gnsrecord
parent72b802f9173bdd0f5d6830c56d7c51c3349073fe (diff)
downloadgnunet-bdbb7c684f2c9711989d2543ecc08a95be23e6c4.tar.gz
gnunet-bdbb7c684f2c9711989d2543ecc08a95be23e6c4.zip
code cleanup, more diagnostics, more statistics
Diffstat (limited to 'src/gnsrecord')
-rw-r--r--src/gnsrecord/gnsrecord_crypto.c66
1 files changed, 41 insertions, 25 deletions
diff --git a/src/gnsrecord/gnsrecord_crypto.c b/src/gnsrecord/gnsrecord_crypto.c
index 0fab97f06..dd628ea76 100644
--- a/src/gnsrecord/gnsrecord_crypto.c
+++ b/src/gnsrecord/gnsrecord_crypto.c
@@ -85,7 +85,8 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
85 const struct GNUNET_GNSRECORD_Data *rd, 85 const struct GNUNET_GNSRECORD_Data *rd,
86 unsigned int rd_count) 86 unsigned int rd_count)
87{ 87{
88 size_t payload_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); 88 size_t payload_len = GNUNET_GNSRECORD_records_get_size (rd_count,
89 rd);
89 char payload[sizeof (uint32_t) + payload_len]; 90 char payload[sizeof (uint32_t) + payload_len];
90 struct GNUNET_GNSRECORD_Block *block; 91 struct GNUNET_GNSRECORD_Block *block;
91 struct GNUNET_CRYPTO_EcdsaPublicKey pkey; 92 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
@@ -94,14 +95,13 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
94 struct GNUNET_CRYPTO_SymmetricSessionKey skey; 95 struct GNUNET_CRYPTO_SymmetricSessionKey skey;
95 struct GNUNET_GNSRECORD_Data rdc[rd_count]; 96 struct GNUNET_GNSRECORD_Data rdc[rd_count];
96 uint32_t rd_count_nbo; 97 uint32_t rd_count_nbo;
97 unsigned int i;
98 struct GNUNET_TIME_Absolute now; 98 struct GNUNET_TIME_Absolute now;
99 99
100 if (payload_len > GNUNET_GNSRECORD_MAX_BLOCK_SIZE) 100 if (payload_len > GNUNET_GNSRECORD_MAX_BLOCK_SIZE)
101 return NULL; 101 return NULL;
102 /* convert relative to absolute times */ 102 /* convert relative to absolute times */
103 now = GNUNET_TIME_absolute_get (); 103 now = GNUNET_TIME_absolute_get ();
104 for (i=0;i<rd_count;i++) 104 for (unsigned int i=0;i<rd_count;i++)
105 { 105 {
106 rdc[i] = rd[i]; 106 rdc[i] = rd[i];
107 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) 107 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
@@ -116,13 +116,19 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
116 } 116 }
117 /* serialize */ 117 /* serialize */
118 rd_count_nbo = htonl (rd_count); 118 rd_count_nbo = htonl (rd_count);
119 GNUNET_memcpy (payload, &rd_count_nbo, sizeof (uint32_t)); 119 GNUNET_memcpy (payload,
120 &rd_count_nbo,
121 sizeof (uint32_t));
120 GNUNET_assert (payload_len == 122 GNUNET_assert (payload_len ==
121 GNUNET_GNSRECORD_records_serialize (rd_count, rdc, 123 GNUNET_GNSRECORD_records_serialize (rd_count,
122 payload_len, &payload[sizeof (uint32_t)])); 124 rdc,
125 payload_len,
126 &payload[sizeof (uint32_t)]));
123 block = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Block) + 127 block = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Block) +
124 sizeof (uint32_t) + payload_len); 128 sizeof (uint32_t) +
125 block->purpose.size = htonl (sizeof (uint32_t) + payload_len + 129 payload_len);
130 block->purpose.size = htonl (sizeof (uint32_t) +
131 payload_len +
126 sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + 132 sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
127 sizeof (struct GNUNET_TIME_AbsoluteNBO)); 133 sizeof (struct GNUNET_TIME_AbsoluteNBO));
128 block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); 134 block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN);
@@ -132,18 +138,23 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
132 label, 138 label,
133 "gns"); 139 "gns");
134 GNUNET_CRYPTO_ecdsa_key_get_public (dkey, 140 GNUNET_CRYPTO_ecdsa_key_get_public (dkey,
135 &block->derived_key); 141 &block->derived_key);
136 GNUNET_CRYPTO_ecdsa_key_get_public (key, 142 GNUNET_CRYPTO_ecdsa_key_get_public (key,
137 &pkey); 143 &pkey);
138 derive_block_aes_key (&iv, &skey, label, &pkey); 144 derive_block_aes_key (&iv,
145 &skey,
146 label,
147 &pkey);
139 GNUNET_break (payload_len + sizeof (uint32_t) == 148 GNUNET_break (payload_len + sizeof (uint32_t) ==
140 GNUNET_CRYPTO_symmetric_encrypt (payload, payload_len + sizeof (uint32_t), 149 GNUNET_CRYPTO_symmetric_encrypt (payload,
141 &skey, &iv, 150 payload_len + sizeof (uint32_t),
151 &skey,
152 &iv,
142 &block[1])); 153 &block[1]));
143 if (GNUNET_OK != 154 if (GNUNET_OK !=
144 GNUNET_CRYPTO_ecdsa_sign (dkey, 155 GNUNET_CRYPTO_ecdsa_sign (dkey,
145 &block->purpose, 156 &block->purpose,
146 &block->signature)) 157 &block->signature))
147 { 158 {
148 GNUNET_break (0); 159 GNUNET_break (0);
149 GNUNET_free (dkey); 160 GNUNET_free (dkey);
@@ -166,9 +177,9 @@ int
166GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block) 177GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block)
167{ 178{
168 return GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN, 179 return GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN,
169 &block->purpose, 180 &block->purpose,
170 &block->signature, 181 &block->signature,
171 &block->derived_key); 182 &block->derived_key);
172} 183}
173 184
174 185
@@ -224,9 +235,7 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
224 } 235 }
225 { 236 {
226 struct GNUNET_GNSRECORD_Data rd[rd_count]; 237 struct GNUNET_GNSRECORD_Data rd[rd_count];
227 unsigned int i;
228 unsigned int j; 238 unsigned int j;
229 unsigned int k;
230 struct GNUNET_TIME_Absolute now; 239 struct GNUNET_TIME_Absolute now;
231 240
232 if (GNUNET_OK != 241 if (GNUNET_OK !=
@@ -241,7 +250,7 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
241 /* hide expired records */ 250 /* hide expired records */
242 now = GNUNET_TIME_absolute_get (); 251 now = GNUNET_TIME_absolute_get ();
243 j = 0; 252 j = 0;
244 for (i=0;i<rd_count;i++) 253 for (unsigned int i=0;i<rd_count;i++)
245 { 254 {
246 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) 255 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
247 { 256 {
@@ -254,7 +263,7 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
254 { 263 {
255 int include_record = GNUNET_YES; 264 int include_record = GNUNET_YES;
256 /* Shadow record, figure out if we have a not expired active record */ 265 /* Shadow record, figure out if we have a not expired active record */
257 for (k=0;k<rd_count;k++) 266 for (unsigned int k=0;k<rd_count;k++)
258 { 267 {
259 if (k == i) 268 if (k == i)
260 continue; 269 continue;
@@ -283,7 +292,9 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
283 } 292 }
284 rd_count = j; 293 rd_count = j;
285 if (NULL != proc) 294 if (NULL != proc)
286 proc (proc_cls, rd_count, (0 != rd_count) ? rd : NULL); 295 proc (proc_cls,
296 rd_count,
297 (0 != rd_count) ? rd : NULL);
287 } 298 }
288 } 299 }
289 return GNUNET_OK; 300 return GNUNET_OK;
@@ -323,8 +334,13 @@ GNUNET_GNSRECORD_query_from_public_key (const struct GNUNET_CRYPTO_EcdsaPublicKe
323{ 334{
324 struct GNUNET_CRYPTO_EcdsaPublicKey pd; 335 struct GNUNET_CRYPTO_EcdsaPublicKey pd;
325 336
326 GNUNET_CRYPTO_ecdsa_public_key_derive (pub, label, "gns", &pd); 337 GNUNET_CRYPTO_ecdsa_public_key_derive (pub,
327 GNUNET_CRYPTO_hash (&pd, sizeof (pd), query); 338 label,
339 "gns",
340 &pd);
341 GNUNET_CRYPTO_hash (&pd,
342 sizeof (pd),
343 query);
328} 344}
329 345
330 346