aboutsummaryrefslogtreecommitdiff
path: root/src/gnsrecord
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2022-03-29 17:04:15 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2022-03-29 17:04:15 +0200
commita5b0a1d36de55202fb4225e35ddd0a6676189367 (patch)
treec744a42a7ae51b0601697481abb88af4ec6cc6f1 /src/gnsrecord
parenta6e38df1a0d142e9341f818bd94e07eabb730da8 (diff)
downloadgnunet-a5b0a1d36de55202fb4225e35ddd0a6676189367.tar.gz
gnunet-a5b0a1d36de55202fb4225e35ddd0a6676189367.zip
-update testvector generation
Diffstat (limited to 'src/gnsrecord')
-rw-r--r--src/gnsrecord/gnunet-gnsrecord-tvg.c120
1 files changed, 66 insertions, 54 deletions
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c
index 87de32066..7fef6f8e7 100644
--- a/src/gnsrecord/gnunet-gnsrecord-tvg.c
+++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c
@@ -96,20 +96,22 @@ static void
96print_record (const struct GNUNET_GNSRECORD_Data *rd) 96print_record (const struct GNUNET_GNSRECORD_Data *rd)
97{ 97{
98 uint16_t flags = htons (rd->flags); 98 uint16_t flags = htons (rd->flags);
99 fprintf (stdout, 99 uint64_t abs_nbo = GNUNET_htonll (rd->expiration_time);
100 "EXPIRATION: %" PRIu64 "\n", rd->expiration_time); 100 uint16_t size_nbo = htons (rd->data_size);
101 fprintf (stdout, 101 uint32_t type_nbo = htonl (rd->record_type);
102 "DATA_SIZE: %zu\n", rd->data_size); 102 printf ("EXPIRATION:\n");
103 fprintf (stdout, 103 print_bytes (&abs_nbo, sizeof (abs_nbo), 8);
104 "TYPE: %d\n", rd->record_type); 104 printf ("\nDATA_SIZE:\n");
105 fprintf (stdout, 105 print_bytes (&size_nbo, sizeof (size_nbo), 8);
106 "FLAGS: "); 106 printf ("\nTYPE:\n");
107 print_bytes(&type_nbo, sizeof (type_nbo), 8);
108 printf ("\nFLAGS: ");
107 print_bytes ((void*) &flags, sizeof (flags), 8); 109 print_bytes ((void*) &flags, sizeof (flags), 8);
108 printf ("\n"); 110 printf ("\n");
109 fprintf (stdout, 111 fprintf (stdout,
110 "DATA:\n"); 112 "DATA:\n");
111 print_bytes ((char*) rd->data, rd->data_size, 8); 113 print_bytes ((char*) rd->data, rd->data_size, 8);
112 fprintf (stdout, "\n"); 114 printf ("\n");
113} 115}
114 116
115 117
@@ -133,6 +135,7 @@ run_pkey (struct GNUNET_GNSRECORD_Data *rd, int rd_count, const char *label)
133 struct GNUNET_IDENTITY_PublicKey pkey_data; 135 struct GNUNET_IDENTITY_PublicKey pkey_data;
134 struct GNUNET_HashCode query; 136 struct GNUNET_HashCode query;
135 char *rdata; 137 char *rdata;
138 char *conv_lbl;
136 size_t rdata_size; 139 size_t rdata_size;
137 char ztld[128]; 140 char ztld[128];
138 unsigned char ctr[GNUNET_CRYPTO_AES_KEY_LENGTH / 2]; 141 unsigned char ctr[GNUNET_CRYPTO_AES_KEY_LENGTH / 2];
@@ -146,34 +149,37 @@ run_pkey (struct GNUNET_GNSRECORD_Data *rd, int rd_count, const char *label)
146 149
147 GNUNET_IDENTITY_key_get_public (&id_priv, 150 GNUNET_IDENTITY_key_get_public (&id_priv,
148 &id_pub); 151 &id_pub);
149 fprintf (stdout, 152 printf ("Zone private key (d, big-endian):\n");
150 "Zone private key (d, big-endian):\n");
151 print_bytes_ (&id_priv.ecdsa_key, 153 print_bytes_ (&id_priv.ecdsa_key,
152 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 8, 1); 154 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 8, 1);
153 fprintf (stdout, "\n"); 155 printf ("\n");
154 fprintf (stdout, "Zone identifier (ztype|zkey):\n"); 156 printf ("Zone identifier (ztype|zkey):\n");
155 GNUNET_assert (0 < GNUNET_IDENTITY_key_get_length (&id_pub)); 157 GNUNET_assert (0 < GNUNET_IDENTITY_key_get_length (&id_pub));
156 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); 158 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8);
157 GNUNET_STRINGS_data_to_string (&id_pub, 159 GNUNET_STRINGS_data_to_string (&id_pub,
158 GNUNET_IDENTITY_key_get_length (&id_pub), 160 GNUNET_IDENTITY_key_get_length (&id_pub),
159 ztld, 161 ztld,
160 sizeof (ztld)); 162 sizeof (ztld));
161 fprintf (stdout, "\n"); 163 printf ("\n");
162 fprintf (stdout, "zTLD:\n"); 164 printf ("zTLD:\n");
163 fprintf (stdout, "%s\n", ztld); 165 printf ("%s\n", ztld);
164 fprintf (stdout, "\n"); 166 printf ("\n");
165 167
166 pkey_data_p.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); 168 pkey_data_p.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
167 GNUNET_CRYPTO_ecdsa_key_create (&pkey_data_p.ecdsa_key); 169 GNUNET_CRYPTO_ecdsa_key_create (&pkey_data_p.ecdsa_key);
168 GNUNET_IDENTITY_key_get_public (&pkey_data_p, 170 GNUNET_IDENTITY_key_get_public (&pkey_data_p,
169 &pkey_data); 171 &pkey_data);
170 fprintf (stdout, 172 conv_lbl = GNUNET_GNSRECORD_string_normalize (label);
171 "Label: %s\nRRCOUNT: %d\n\n", label, rd_count); 173 printf ("Label:\n");
174 print_bytes (conv_lbl, strlen (conv_lbl), 8);
175 GNUNET_free (conv_lbl);
176 printf ("\nNumber of records (integer): %d\n\n", rd_count);
172 177
173 for (int i = 0; i < rd_count; i++) 178 for (int i = 0; i < rd_count; i++)
174 { 179 {
175 fprintf (stdout, "Record #%d\n", i); 180 printf ("Record #%d := (\n", i);
176 print_record (&rd[i]); 181 print_record (&rd[i]);
182 printf (")\n\n");
177 } 183 }
178 184
179 rdata_size = GNUNET_GNSRECORD_records_get_size (rd_count, 185 rdata_size = GNUNET_GNSRECORD_records_get_size (rd_count,
@@ -183,11 +189,11 @@ run_pkey (struct GNUNET_GNSRECORD_Data *rd, int rd_count, const char *label)
183 rd, 189 rd,
184 (size_t) rdata_size, 190 (size_t) rdata_size,
185 rdata); 191 rdata);
186 fprintf (stdout, "RDATA:\n"); 192 printf ("RDATA:\n");
187 print_bytes (rdata, 193 print_bytes (rdata,
188 (size_t) rdata_size, 194 (size_t) rdata_size,
189 8); 195 8);
190 fprintf (stdout, "\n"); 196 printf ("\n");
191 expire = GNUNET_GNSRECORD_record_get_expiration_time (rd_count, rd, 197 expire = GNUNET_GNSRECORD_record_get_expiration_time (rd_count, rd,
192 GNUNET_TIME_UNIT_ZERO_ABS); 198 GNUNET_TIME_UNIT_ZERO_ABS);
193 GNR_derive_block_aes_key (ctr, 199 GNR_derive_block_aes_key (ctr,
@@ -197,18 +203,18 @@ run_pkey (struct GNUNET_GNSRECORD_Data *rd, int rd_count, const char *label)
197 expire).abs_value_us__, 203 expire).abs_value_us__,
198 &id_pub.ecdsa_key); 204 &id_pub.ecdsa_key);
199 205
200 fprintf (stdout, "Encryption NONCE|EXPIRATION|BLOCK COUNTER:\n"); 206 printf ("Encryption NONCE|EXPIRATION|BLOCK COUNTER:\n");
201 print_bytes (ctr, sizeof (ctr), 8); 207 print_bytes (ctr, sizeof (ctr), 8);
202 fprintf (stdout, "\n"); 208 printf ("\n");
203 fprintf (stdout, "Encryption key (K):\n"); 209 printf ("Encryption key (K):\n");
204 print_bytes (skey, sizeof (skey), 8); 210 print_bytes (skey, sizeof (skey), 8);
205 fprintf (stdout, "\n"); 211 printf ("\n");
206 GNUNET_GNSRECORD_query_from_public_key (&id_pub, 212 GNUNET_GNSRECORD_query_from_public_key (&id_pub,
207 label, 213 label,
208 &query); 214 &query);
209 fprintf (stdout, "Storage key (q):\n"); 215 printf ("Storage key (q):\n");
210 print_bytes (&query, sizeof (query), 8); 216 print_bytes (&query, sizeof (query), 8);
211 fprintf (stdout, "\n"); 217 printf ("\n");
212 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create (&id_priv, 218 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create (&id_priv,
213 expire, 219 expire,
214 label, 220 label,
@@ -219,12 +225,12 @@ run_pkey (struct GNUNET_GNSRECORD_Data *rd, int rd_count, const char *label)
219 GNUNET_GNSRECORD_Block); 225 GNUNET_GNSRECORD_Block);
220 226
221 bdata = (char*) &(&rrblock->ecdsa_block)[1]; 227 bdata = (char*) &(&rrblock->ecdsa_block)[1];
222 fprintf (stdout, "BDATA:\n"); 228 printf ("BDATA:\n");
223 print_bytes (bdata, bdata_size, 8); 229 print_bytes (bdata, bdata_size, 8);
224 fprintf (stdout, "\n"); 230 printf ("\n");
225 fprintf (stdout, "RRBLOCK:\n"); 231 printf ("RRBLOCK:\n");
226 print_bytes (rrblock, ntohl (rrblock->size), 8); 232 print_bytes (rrblock, ntohl (rrblock->size), 8);
227 fprintf (stdout, "\n"); 233 printf ("\n");
228 GNUNET_free (rdata); 234 GNUNET_free (rdata);
229} 235}
230 236
@@ -249,6 +255,7 @@ run_edkey (struct GNUNET_GNSRECORD_Data *rd, int rd_count, const char*label)
249 struct GNUNET_IDENTITY_PublicKey pkey_data; 255 struct GNUNET_IDENTITY_PublicKey pkey_data;
250 struct GNUNET_HashCode query; 256 struct GNUNET_HashCode query;
251 char *rdata; 257 char *rdata;
258 char *conv_lbl;
252 size_t rdata_size; 259 size_t rdata_size;
253 260
254 char ztld[128]; 261 char ztld[128];
@@ -271,30 +278,35 @@ run_edkey (struct GNUNET_GNSRECORD_Data *rd, int rd_count, const char*label)
271 "Zone private key (d):\n"); 278 "Zone private key (d):\n");
272 print_bytes (&id_priv.eddsa_key, sizeof (struct 279 print_bytes (&id_priv.eddsa_key, sizeof (struct
273 GNUNET_CRYPTO_EddsaPrivateKey), 8); 280 GNUNET_CRYPTO_EddsaPrivateKey), 8);
274 fprintf (stdout, "\n"); 281 printf ("\n");
275 fprintf (stdout, "Zone identifier (ztype|zkey):\n"); 282 printf ("Zone identifier (ztype|zkey):\n");
276 GNUNET_assert (0 < GNUNET_IDENTITY_key_get_length (&id_pub)); 283 GNUNET_assert (0 < GNUNET_IDENTITY_key_get_length (&id_pub));
277 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); 284 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8);
278 GNUNET_STRINGS_data_to_string (&id_pub, 285 GNUNET_STRINGS_data_to_string (&id_pub,
279 GNUNET_IDENTITY_key_get_length (&id_pub), 286 GNUNET_IDENTITY_key_get_length (&id_pub),
280 ztld, 287 ztld,
281 sizeof (ztld)); 288 sizeof (ztld));
282 fprintf (stdout, "\n"); 289 printf ("\n");
283 fprintf (stdout, "zTLD:\n"); 290 printf ("zTLD:\n");
284 fprintf (stdout, "%s\n", ztld); 291 printf ("%s\n", ztld);
285 fprintf (stdout, "\n"); 292 printf ("\n");
286 293
287 pkey_data_p.type = htonl (GNUNET_GNSRECORD_TYPE_EDKEY); 294 pkey_data_p.type = htonl (GNUNET_GNSRECORD_TYPE_EDKEY);
288 GNUNET_CRYPTO_eddsa_key_create (&pkey_data_p.eddsa_key); 295 GNUNET_CRYPTO_eddsa_key_create (&pkey_data_p.eddsa_key);
289 GNUNET_IDENTITY_key_get_public (&pkey_data_p, 296 GNUNET_IDENTITY_key_get_public (&pkey_data_p,
290 &pkey_data); 297 &pkey_data);
298 conv_lbl = GNUNET_GNSRECORD_string_normalize (label);
299 printf ("Label:\n");
300 print_bytes (conv_lbl, strlen (conv_lbl), 8);
301 GNUNET_free (conv_lbl);
291 fprintf (stdout, 302 fprintf (stdout,
292 "Label: %s\nRRCOUNT: %d\n\n", label, rd_count); 303 "\nNumber of records (integer): %d\n\n", rd_count);
293 304
294 for (int i = 0; i < rd_count; i++) 305 for (int i = 0; i < rd_count; i++)
295 { 306 {
296 fprintf (stdout, "Record #%d\n", i); 307 printf ("Record #%d := (\n", i);
297 print_record (&rd[i]); 308 print_record (&rd[i]);
309 printf (")\n\n");
298 } 310 }
299 311
300 rdata_size = GNUNET_GNSRECORD_records_get_size (rd_count, 312 rdata_size = GNUNET_GNSRECORD_records_get_size (rd_count,
@@ -308,29 +320,29 @@ run_edkey (struct GNUNET_GNSRECORD_Data *rd, int rd_count, const char*label)
308 rd, 320 rd,
309 (size_t) rdata_size, 321 (size_t) rdata_size,
310 rdata); 322 rdata);
311 fprintf (stdout, "RDATA:\n"); 323 printf ("RDATA:\n");
312 print_bytes (rdata, 324 print_bytes (rdata,
313 (size_t) rdata_size, 325 (size_t) rdata_size,
314 8); 326 8);
315 fprintf (stdout, "\n"); 327 printf ("\n");
316 GNR_derive_block_xsalsa_key (nonce, 328 GNR_derive_block_xsalsa_key (nonce,
317 skey, 329 skey,
318 label, 330 label,
319 GNUNET_TIME_absolute_hton ( 331 GNUNET_TIME_absolute_hton (
320 expire).abs_value_us__, 332 expire).abs_value_us__,
321 &id_pub.eddsa_key); 333 &id_pub.eddsa_key);
322 fprintf (stdout, "Encryption NONCE|EXPIRATION:\n"); 334 printf ("Encryption NONCE|EXPIRATION:\n");
323 print_bytes (nonce, sizeof (nonce), 8); 335 print_bytes (nonce, sizeof (nonce), 8);
324 fprintf (stdout, "\n"); 336 printf ("\n");
325 fprintf (stdout, "Encryption key (K):\n"); 337 printf ("Encryption key (K):\n");
326 print_bytes (skey, sizeof (skey), 8); 338 print_bytes (skey, sizeof (skey), 8);
327 fprintf (stdout, "\n"); 339 printf ("\n");
328 GNUNET_GNSRECORD_query_from_public_key (&id_pub, 340 GNUNET_GNSRECORD_query_from_public_key (&id_pub,
329 label, 341 label,
330 &query); 342 &query);
331 fprintf (stdout, "Storage key (q):\n"); 343 printf ("Storage key (q):\n");
332 print_bytes (&query, sizeof (query), 8); 344 print_bytes (&query, sizeof (query), 8);
333 fprintf (stdout, "\n"); 345 printf ("\n");
334 346
335 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create (&id_priv, 347 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create (&id_priv,
336 expire, 348 expire,
@@ -342,12 +354,12 @@ run_edkey (struct GNUNET_GNSRECORD_Data *rd, int rd_count, const char*label)
342 GNUNET_GNSRECORD_Block); 354 GNUNET_GNSRECORD_Block);
343 355
344 bdata = (char*) &(&rrblock->eddsa_block)[1]; 356 bdata = (char*) &(&rrblock->eddsa_block)[1];
345 fprintf (stdout, "BDATA:\n"); 357 printf ("BDATA:\n");
346 print_bytes (bdata, bdata_size, 8); 358 print_bytes (bdata, bdata_size, 8);
347 fprintf (stdout, "\n"); 359 printf ("\n");
348 fprintf (stdout, "RRBLOCK:\n"); 360 printf ("RRBLOCK:\n");
349 print_bytes (rrblock, ntohl (rrblock->size), 8); 361 print_bytes (rrblock, ntohl (rrblock->size), 8);
350 fprintf (stdout, "\n"); 362 printf ("\n");
351 GNUNET_free (rdata); 363 GNUNET_free (rdata);
352} 364}
353 365
@@ -424,9 +436,9 @@ run (void *cls,
424 | GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 436 | GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
425 437
426 run_pkey (&rd_pkey, 1, "testdelegation"); 438 run_pkey (&rd_pkey, 1, "testdelegation");
427 run_pkey (rd, 3, "namesystem"); 439 run_pkey (rd, 3, "\u5929\u4e0b\u7121\u6575");
428 run_edkey (&rd_pkey, 1, "testdelegation"); 440 run_edkey (&rd_pkey, 1, "testdelegation");
429 run_edkey (rd, 3, "namesystem"); 441 run_edkey (rd, 3, "\u5929\u4e0b\u7121\u6575");
430} 442}
431 443
432 444