2 This file is part of GNUnet.
3 Copyright (C) 2018 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file gnsrecord/test_gnsrecord_crypto.c
22 * @brief testcase for block creation, verification and decryption
25 #include "gnunet_util_lib.h"
26 #include "gnunet_gnsrecord_lib.h"
32 #define TEST_RECORD_TYPE 1234
34 #define TEST_RECORD_DATALEN 123
36 #define TEST_RECORD_DATA 'a'
38 #define TEST_REMOVE_RECORD_TYPE 4321
40 #define TEST_REMOVE_RECORD_DATALEN 255
42 #define TEST_REMOVE_RECORD_DATA 'b'
45 static struct GNUNET_GNSRECORD_Data *
46 create_record (int count)
48 struct GNUNET_GNSRECORD_Data *rd;
50 rd = GNUNET_new_array (count,
51 struct GNUNET_GNSRECORD_Data);
52 for (unsigned int c = 0; c < count; c++)
54 rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
55 rd[c].record_type = TEST_RECORD_TYPE;
56 rd[c].data_size = TEST_RECORD_DATALEN;
57 rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN);
58 memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
68 const struct GNUNET_CONFIGURATION_Handle *cfg)
70 struct GNUNET_GNSRECORD_Block *block;
71 struct GNUNET_HashCode query;
72 struct GNUNET_GNSRECORD_Data *s_rd;
74 struct GNUNET_TIME_Absolute start_time;
75 struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey;
76 struct GNUNET_TIME_Absolute expire;
82 expire = GNUNET_TIME_absolute_get();
83 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
84 GNUNET_assert (NULL != privkey);
86 /* test block creation */
87 s_name = "DUMMY.dummy.gnunet";
88 s_rd = create_record (RECORDS);
89 start_time = GNUNET_TIME_absolute_get ();
90 for (unsigned int i=0;i<ROUNDS;i++)
92 GNUNET_assert (NULL != (block =
93 GNUNET_GNSRECORD_block_create2 (privkey,
98 GNUNET_GNSRECORD_query_from_private_key (privkey,
104 "Took %s to produce %u GNS blocks for the DHT\n",
105 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start_time),
108 for (unsigned int i=0;i<RECORDS;i++)
109 GNUNET_free ((void *) s_rd[i].data);
111 GNUNET_free (privkey);
116 main (int argc, char *argv[])
118 static char *const argvx[] = {
119 "perf-gnsrecord-crypto",
122 static struct GNUNET_GETOPT_CommandLineOption options[] = {
123 GNUNET_GETOPT_OPTION_END
127 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
129 "perf-gnsrecord-crypto",
137 /* end of test_gnsrecord_crypto.c */