diff options
Diffstat (limited to 'src/gnsrecord/test_gnsrecord_crypto.c')
-rw-r--r-- | src/gnsrecord/test_gnsrecord_crypto.c | 123 |
1 files changed, 61 insertions, 62 deletions
diff --git a/src/gnsrecord/test_gnsrecord_crypto.c b/src/gnsrecord/test_gnsrecord_crypto.c index 35cc5d34b..6be870e17 100644 --- a/src/gnsrecord/test_gnsrecord_crypto.c +++ b/src/gnsrecord/test_gnsrecord_crypto.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gnsrecord/test_gnsrecord_crypto.c | 21 | * @file gnsrecord/test_gnsrecord_crypto.c |
22 | * @brief testcase for block creation, verification and decryption | 22 | * @brief testcase for block creation, verification and decryption |
@@ -51,54 +51,53 @@ static int res; | |||
51 | 51 | ||
52 | 52 | ||
53 | static struct GNUNET_GNSRECORD_Data * | 53 | static struct GNUNET_GNSRECORD_Data * |
54 | create_record (int count) | 54 | create_record(int count) |
55 | { | 55 | { |
56 | struct GNUNET_GNSRECORD_Data *rd; | 56 | struct GNUNET_GNSRECORD_Data *rd; |
57 | 57 | ||
58 | rd = GNUNET_new_array (count, struct GNUNET_GNSRECORD_Data); | 58 | rd = GNUNET_new_array(count, struct GNUNET_GNSRECORD_Data); |
59 | for (unsigned int c = 0; c < count; c++) | 59 | for (unsigned int c = 0; c < count; c++) |
60 | { | 60 | { |
61 | rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; | 61 | rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; |
62 | rd[c].record_type = TEST_RECORD_TYPE; | 62 | rd[c].record_type = TEST_RECORD_TYPE; |
63 | rd[c].data_size = TEST_RECORD_DATALEN; | 63 | rd[c].data_size = TEST_RECORD_DATALEN; |
64 | rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN); | 64 | rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN); |
65 | memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); | 65 | memset((char *)rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); |
66 | } | 66 | } |
67 | return rd; | 67 | return rd; |
68 | } | 68 | } |
69 | 69 | ||
70 | 70 | ||
71 | static void | 71 | static void |
72 | rd_decrypt_cb (void *cls, | 72 | rd_decrypt_cb(void *cls, |
73 | unsigned int rd_count, | 73 | unsigned int rd_count, |
74 | const struct GNUNET_GNSRECORD_Data *rd) | 74 | const struct GNUNET_GNSRECORD_Data *rd) |
75 | { | 75 | { |
76 | char rd_cmp_data[TEST_RECORD_DATALEN]; | 76 | char rd_cmp_data[TEST_RECORD_DATALEN]; |
77 | 77 | ||
78 | GNUNET_assert (RECORDS == rd_count); | 78 | GNUNET_assert(RECORDS == rd_count); |
79 | GNUNET_assert (NULL != rd); | 79 | GNUNET_assert(NULL != rd); |
80 | memset (rd_cmp_data, | 80 | memset(rd_cmp_data, |
81 | 'a', | 81 | 'a', |
82 | TEST_RECORD_DATALEN); | 82 | TEST_RECORD_DATALEN); |
83 | for (unsigned int c = 0; c < rd_count; c++) | 83 | for (unsigned int c = 0; c < rd_count; c++) |
84 | { | 84 | { |
85 | GNUNET_assert (TEST_RECORD_TYPE == rd[c].record_type); | 85 | GNUNET_assert(TEST_RECORD_TYPE == rd[c].record_type); |
86 | GNUNET_assert (TEST_RECORD_DATALEN == rd[c].data_size); | 86 | GNUNET_assert(TEST_RECORD_DATALEN == rd[c].data_size); |
87 | GNUNET_assert (0 == memcmp (&rd_cmp_data, | 87 | GNUNET_assert(0 == memcmp(&rd_cmp_data, |
88 | rd[c].data, | 88 | rd[c].data, |
89 | TEST_RECORD_DATALEN)); | 89 | TEST_RECORD_DATALEN)); |
90 | } | 90 | } |
91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 91 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
92 | "Block was decrypted successfully \n"); | 92 | "Block was decrypted successfully \n"); |
93 | res = 0; | 93 | res = 0; |
94 | |||
95 | } | 94 | } |
96 | 95 | ||
97 | static void | 96 | static void |
98 | run (void *cls, | 97 | run(void *cls, |
99 | char *const *args, | 98 | char *const *args, |
100 | const char *cfgfile, | 99 | const char *cfgfile, |
101 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 100 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
102 | { | 101 | { |
103 | struct GNUNET_GNSRECORD_Block *block; | 102 | struct GNUNET_GNSRECORD_Block *block; |
104 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 103 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
@@ -106,48 +105,48 @@ run (void *cls, | |||
106 | struct GNUNET_HashCode query_priv; | 105 | struct GNUNET_HashCode query_priv; |
107 | struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get(); | 106 | struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get(); |
108 | 107 | ||
109 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 108 | privkey = GNUNET_CRYPTO_ecdsa_key_create(); |
110 | GNUNET_assert (NULL != privkey); | 109 | GNUNET_assert(NULL != privkey); |
111 | /* get public key */ | 110 | /* get public key */ |
112 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, | 111 | GNUNET_CRYPTO_ecdsa_key_get_public(privkey, |
113 | &pubkey); | 112 | &pubkey); |
114 | 113 | ||
115 | /* test query derivation */ | 114 | /* test query derivation */ |
116 | GNUNET_GNSRECORD_query_from_private_key (privkey, | 115 | GNUNET_GNSRECORD_query_from_private_key(privkey, |
117 | "testlabel", | ||
118 | &query_priv); | ||
119 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, | ||
120 | "testlabel", | 116 | "testlabel", |
121 | &query_pub); | 117 | &query_priv); |
122 | GNUNET_assert (0 == memcmp (&query_priv, | 118 | GNUNET_GNSRECORD_query_from_public_key(&pubkey, |
123 | &query_pub, | 119 | "testlabel", |
124 | sizeof (struct GNUNET_HashCode))); | 120 | &query_pub); |
121 | GNUNET_assert(0 == memcmp(&query_priv, | ||
122 | &query_pub, | ||
123 | sizeof(struct GNUNET_HashCode))); | ||
125 | /* create record */ | 124 | /* create record */ |
126 | s_name = "DUMMY.dummy.gnunet"; | 125 | s_name = "DUMMY.dummy.gnunet"; |
127 | s_rd = create_record (RECORDS); | 126 | s_rd = create_record(RECORDS); |
128 | 127 | ||
129 | /* Create block */ | 128 | /* Create block */ |
130 | GNUNET_assert (NULL != (block = | 129 | GNUNET_assert(NULL != (block = |
131 | GNUNET_GNSRECORD_block_create (privkey, | 130 | GNUNET_GNSRECORD_block_create(privkey, |
132 | expire, | 131 | expire, |
133 | s_name, | 132 | s_name, |
134 | s_rd, | 133 | s_rd, |
135 | RECORDS))); | 134 | RECORDS))); |
136 | GNUNET_assert (GNUNET_OK == | 135 | GNUNET_assert(GNUNET_OK == |
137 | GNUNET_GNSRECORD_block_verify (block)); | 136 | GNUNET_GNSRECORD_block_verify(block)); |
138 | GNUNET_assert (GNUNET_OK == | 137 | GNUNET_assert(GNUNET_OK == |
139 | GNUNET_GNSRECORD_block_decrypt (block, | 138 | GNUNET_GNSRECORD_block_decrypt(block, |
140 | &pubkey, | 139 | &pubkey, |
141 | s_name, | 140 | s_name, |
142 | &rd_decrypt_cb, | 141 | &rd_decrypt_cb, |
143 | s_name)); | 142 | s_name)); |
144 | GNUNET_free (block); | 143 | GNUNET_free(block); |
145 | GNUNET_free (privkey); | 144 | GNUNET_free(privkey); |
146 | } | 145 | } |
147 | 146 | ||
148 | 147 | ||
149 | int | 148 | int |
150 | main (int argc, char *argv[]) | 149 | main(int argc, char *argv[]) |
151 | { | 150 | { |
152 | static char *const argvx[] = { | 151 | static char *const argvx[] = { |
153 | "test-gnsrecord-crypto", | 152 | "test-gnsrecord-crypto", |
@@ -158,11 +157,11 @@ main (int argc, char *argv[]) | |||
158 | }; | 157 | }; |
159 | 158 | ||
160 | res = 1; | 159 | res = 1; |
161 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, | 160 | GNUNET_PROGRAM_run((sizeof(argvx) / sizeof(char *)) - 1, |
162 | argvx, | 161 | argvx, |
163 | "test-gnsrecord-crypto", | 162 | "test-gnsrecord-crypto", |
164 | "nohelp", options, | 163 | "nohelp", options, |
165 | &run, &res); | 164 | &run, &res); |
166 | return res; | 165 | return res; |
167 | } | 166 | } |
168 | 167 | ||