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 it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @file gnsrecord/test_gnsrecord_crypto.c
20 * @brief testcase for block creation, verification and decryption
23 #include "gnunet_util_lib.h"
24 #include "gnunet_gnsrecord_lib.h"
30 #define TEST_RECORD_TYPE 1234
32 #define TEST_RECORD_DATALEN 123
34 #define TEST_RECORD_DATA 'a'
36 #define TEST_REMOVE_RECORD_TYPE 4321
38 #define TEST_REMOVE_RECORD_DATALEN 255
40 #define TEST_REMOVE_RECORD_DATA 'b'
43 static struct GNUNET_GNSRECORD_Data *
44 create_record (int count)
46 struct GNUNET_GNSRECORD_Data *rd;
48 rd = GNUNET_new_array (count,
49 struct GNUNET_GNSRECORD_Data);
50 for (unsigned int c = 0; c < count; c++)
52 rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
53 rd[c].record_type = TEST_RECORD_TYPE;
54 rd[c].data_size = TEST_RECORD_DATALEN;
55 rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN);
56 memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
66 const struct GNUNET_CONFIGURATION_Handle *cfg)
68 struct GNUNET_GNSRECORD_Block *block;
69 struct GNUNET_HashCode query;
70 struct GNUNET_GNSRECORD_Data *s_rd;
72 struct GNUNET_TIME_Absolute start_time;
73 struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey;
74 struct GNUNET_TIME_Absolute expire;
80 expire = GNUNET_TIME_absolute_get();
81 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
82 GNUNET_assert (NULL != privkey);
84 /* test block creation */
85 s_name = "DUMMY.dummy.gnunet";
86 s_rd = create_record (RECORDS);
87 start_time = GNUNET_TIME_absolute_get ();
88 for (unsigned int i=0;i<ROUNDS;i++)
90 GNUNET_assert (NULL != (block =
91 GNUNET_GNSRECORD_block_create2 (privkey,
96 GNUNET_GNSRECORD_query_from_private_key (privkey,
102 "Took %s to produce %u GNS blocks for the DHT\n",
103 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start_time),
106 for (unsigned int i=0;i<RECORDS;i++)
107 GNUNET_free ((void *) s_rd[i].data);
109 GNUNET_free (privkey);
114 main (int argc, char *argv[])
116 static char *const argvx[] = {
117 "perf-gnsrecord-crypto",
120 static struct GNUNET_GETOPT_CommandLineOption options[] = {
121 GNUNET_GETOPT_OPTION_END
125 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
127 "perf-gnsrecord-crypto",
135 /* end of test_gnsrecord_crypto.c */