aboutsummaryrefslogtreecommitdiff
path: root/src/gnsrecord/gnunet-gnsrecord-tvg.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnsrecord/gnunet-gnsrecord-tvg.c')
-rw-r--r--src/gnsrecord/gnunet-gnsrecord-tvg.c60
1 files changed, 47 insertions, 13 deletions
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c
index 9e3dea921..7a78580d2 100644
--- a/src/gnsrecord/gnunet-gnsrecord-tvg.c
+++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c
@@ -31,6 +31,7 @@
31#include "gnunet_dnsparser_lib.h" 31#include "gnunet_dnsparser_lib.h"
32#include "gnunet_testing_lib.h" 32#include "gnunet_testing_lib.h"
33#include <inttypes.h> 33#include <inttypes.h>
34#include "gnsrecord_crypto.h"
34 35
35#define TEST_RECORD_LABEL "test" 36#define TEST_RECORD_LABEL "test"
36#define TEST_RECORD_A "1.2.3.4" 37#define TEST_RECORD_A "1.2.3.4"
@@ -38,9 +39,9 @@
38 39
39static void 40static void
40print_bytes_ (void *buf, 41print_bytes_ (void *buf,
41 size_t buf_len, 42 size_t buf_len,
42 int fold, 43 int fold,
43 int in_be) 44 int in_be)
44{ 45{
45 int i; 46 int i;
46 47
@@ -114,14 +115,16 @@ run_pkey (void)
114 size_t rdata_size; 115 size_t rdata_size;
115 uint32_t rd_count_nbo; 116 uint32_t rd_count_nbo;
116 char ztld[128]; 117 char ztld[128];
118 unsigned char ctr[GNUNET_CRYPTO_AES_KEY_LENGTH / 2];
119 unsigned char skey[GNUNET_CRYPTO_AES_KEY_LENGTH];
117 120
118 /* 121 /*
119 * Make two different expiration times 122 * Make two different expiration times
120 */ 123 */
121 delta1 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, 124 delta1 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS,
122 420); //420 years 125 420); // 420 years
123 delta2 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, 126 delta2 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS,
124 777); //777 years 127 777); // 777 years
125 exp1 = GNUNET_TIME_absolute_add (now, delta1); 128 exp1 = GNUNET_TIME_absolute_add (now, delta1);
126 exp2 = GNUNET_TIME_absolute_add (now, delta2); 129 exp2 = GNUNET_TIME_absolute_add (now, delta2);
127 130
@@ -131,7 +134,8 @@ run_pkey (void)
131 &id_pub); 134 &id_pub);
132 fprintf (stdout, 135 fprintf (stdout,
133 "Zone private key (d, big-endian):\n"); 136 "Zone private key (d, big-endian):\n");
134 print_bytes (&id_priv.ecdsa_key, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 8); 137 print_bytes (&id_priv.ecdsa_key, sizeof (struct
138 GNUNET_CRYPTO_EcdsaPrivateKey), 8);
135 fprintf (stdout, "\n"); 139 fprintf (stdout, "\n");
136 fprintf (stdout, "Zone identifier (ztype|zkey):\n"); 140 fprintf (stdout, "Zone identifier (ztype|zkey):\n");
137 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); 141 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8);
@@ -171,7 +175,7 @@ run_pkey (void)
171 rdata_size = GNUNET_GNSRECORD_records_get_size (TEST_RRCOUNT, 175 rdata_size = GNUNET_GNSRECORD_records_get_size (TEST_RRCOUNT,
172 rd); 176 rd);
173 rdata = GNUNET_malloc (rdata_size); 177 rdata = GNUNET_malloc (rdata_size);
174 rd_count_nbo = htonl(2); 178 rd_count_nbo = htonl (2);
175 GNUNET_memcpy (rdata, 179 GNUNET_memcpy (rdata,
176 &rd_count_nbo, 180 &rd_count_nbo,
177 sizeof (uint32_t)); 181 sizeof (uint32_t));
@@ -183,6 +187,20 @@ run_pkey (void)
183 print_bytes (rdata, rdata_size, 8); 187 print_bytes (rdata, rdata_size, 8);
184 fprintf (stdout, "\n"); 188 fprintf (stdout, "\n");
185 expire = GNUNET_GNSRECORD_record_get_expiration_time (TEST_RRCOUNT, rd); 189 expire = GNUNET_GNSRECORD_record_get_expiration_time (TEST_RRCOUNT, rd);
190 GNR_derive_block_aes_key (ctr,
191 skey,
192 TEST_RECORD_LABEL,
193 GNUNET_TIME_absolute_hton (
194 expire).abs_value_us__,
195 &id_pub.ecdsa_key);
196
197 fprintf (stdout, "Encryption NONCE|EXPIRATION|BLOCK COUNTER:\n");
198 print_bytes (ctr, sizeof (ctr), 8);
199 fprintf (stdout, "\n");
200 fprintf (stdout, "Encryption key (K):\n");
201 print_bytes (skey, sizeof (skey), 8);
202
203
186 rrblock = GNUNET_GNSRECORD_block_create (&id_priv, 204 rrblock = GNUNET_GNSRECORD_block_create (&id_priv,
187 expire, 205 expire,
188 TEST_RECORD_LABEL, 206 TEST_RECORD_LABEL,
@@ -237,14 +255,16 @@ run_edkey (void)
237 size_t rdata_size; 255 size_t rdata_size;
238 uint32_t rd_count_nbo; 256 uint32_t rd_count_nbo;
239 char ztld[128]; 257 char ztld[128];
258 unsigned char nonce[crypto_secretbox_NONCEBYTES];
259 unsigned char skey[crypto_secretbox_KEYBYTES];
240 260
241 /* 261 /*
242 * Make two different expiration times 262 * Make two different expiration times
243 */ 263 */
244 delta1 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, 264 delta1 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS,
245 420); //420 years 265 420); // 420 years
246 delta2 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, 266 delta2 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS,
247 777); //777 years 267 777); // 777 years
248 exp1 = GNUNET_TIME_absolute_add (now, delta1); 268 exp1 = GNUNET_TIME_absolute_add (now, delta1);
249 exp2 = GNUNET_TIME_absolute_add (now, delta2); 269 exp2 = GNUNET_TIME_absolute_add (now, delta2);
250 270
@@ -259,7 +279,8 @@ run_edkey (void)
259 &id_pub); 279 &id_pub);
260 fprintf (stdout, 280 fprintf (stdout,
261 "Zone private key (d):\n"); 281 "Zone private key (d):\n");
262 print_bytes (&id_priv.eddsa_key, sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey), 8); 282 print_bytes (&id_priv.eddsa_key, sizeof (struct
283 GNUNET_CRYPTO_EddsaPrivateKey), 8);
263 fprintf (stdout, "\n"); 284 fprintf (stdout, "\n");
264 fprintf (stdout, "Zone identifier (ztype|zkey):\n"); 285 fprintf (stdout, "Zone identifier (ztype|zkey):\n");
265 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); 286 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8);
@@ -301,7 +322,7 @@ run_edkey (void)
301 expire = GNUNET_GNSRECORD_record_get_expiration_time (TEST_RRCOUNT, 322 expire = GNUNET_GNSRECORD_record_get_expiration_time (TEST_RRCOUNT,
302 rd); 323 rd);
303 rdata = GNUNET_malloc (sizeof (uint32_t) + rdata_size); 324 rdata = GNUNET_malloc (sizeof (uint32_t) + rdata_size);
304 rd_count_nbo = htonl(2); 325 rd_count_nbo = htonl (2);
305 GNUNET_memcpy (rdata, 326 GNUNET_memcpy (rdata,
306 &rd_count_nbo, 327 &rd_count_nbo,
307 sizeof (uint32_t)); 328 sizeof (uint32_t));
@@ -312,6 +333,19 @@ run_edkey (void)
312 fprintf (stdout, "RDATA:\n"); 333 fprintf (stdout, "RDATA:\n");
313 print_bytes (rdata, rdata_size, 8); 334 print_bytes (rdata, rdata_size, 8);
314 fprintf (stdout, "\n"); 335 fprintf (stdout, "\n");
336 GNR_derive_block_xsalsa_key (nonce,
337 skey,
338 TEST_RECORD_LABEL,
339 GNUNET_TIME_absolute_hton (
340 expire).abs_value_us__,
341 &id_pub.eddsa_key);
342 fprintf (stdout, "Encryption NONCE|EXPIRATION:\n");
343 print_bytes (nonce, sizeof (nonce), 8);
344 fprintf (stdout, "\n");
345 fprintf (stdout, "Encryption key (K):\n");
346 print_bytes (skey, sizeof (skey), 8);
347 fprintf (stdout, "\n");
348
315 rrblock = GNUNET_GNSRECORD_block_create (&id_priv, 349 rrblock = GNUNET_GNSRECORD_block_create (&id_priv,
316 expire, 350 expire,
317 TEST_RECORD_LABEL, 351 TEST_RECORD_LABEL,
@@ -350,8 +384,8 @@ run (void *cls,
350 const char *cfgfile, 384 const char *cfgfile,
351 const struct GNUNET_CONFIGURATION_Handle *cfg) 385 const struct GNUNET_CONFIGURATION_Handle *cfg)
352{ 386{
353 run_pkey(); 387 run_pkey ();
354 run_edkey(); 388 run_edkey ();
355} 389}
356 390
357 391