diff options
Diffstat (limited to 'src')
53 files changed, 927 insertions, 1154 deletions
diff --git a/src/cadet/gnunet-service-cadet_tunnels.c b/src/cadet/gnunet-service-cadet_tunnels.c index ae201ed2d..f1f2ec81f 100644 --- a/src/cadet/gnunet-service-cadet_tunnels.c +++ b/src/cadet/gnunet-service-cadet_tunnels.c | |||
@@ -677,8 +677,7 @@ new_ephemeral (struct CadetTunnelAxolotl *ax) | |||
677 | { | 677 | { |
678 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 678 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
679 | "Creating new ephemeral ratchet key (DHRs)\n"); | 679 | "Creating new ephemeral ratchet key (DHRs)\n"); |
680 | GNUNET_assert (GNUNET_OK == | 680 | GNUNET_CRYPTO_ecdhe_key_create (&ax->DHRs); |
681 | GNUNET_CRYPTO_ecdhe_key_create2 (&ax->DHRs)); | ||
682 | } | 681 | } |
683 | 682 | ||
684 | 683 | ||
@@ -3186,8 +3185,7 @@ GCT_create_tunnel (struct CadetPeer *destination) | |||
3186 | 3185 | ||
3187 | t->kx_retry_delay = INITIAL_KX_RETRY_DELAY; | 3186 | t->kx_retry_delay = INITIAL_KX_RETRY_DELAY; |
3188 | new_ephemeral (&t->ax); | 3187 | new_ephemeral (&t->ax); |
3189 | GNUNET_assert (GNUNET_OK == | 3188 | GNUNET_CRYPTO_ecdhe_key_create (&t->ax.kx_0); |
3190 | GNUNET_CRYPTO_ecdhe_key_create2 (&t->ax.kx_0)); | ||
3191 | t->destination = destination; | 3189 | t->destination = destination; |
3192 | t->channels = GNUNET_CONTAINER_multihashmap32_create (8); | 3190 | t->channels = GNUNET_CONTAINER_multihashmap32_create (8); |
3193 | t->maintain_connections_task | 3191 | t->maintain_connections_task |
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 04e6d0141..34f8440ae 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c | |||
@@ -912,14 +912,15 @@ run (void *cls, | |||
912 | const struct GNUNET_CONFIGURATION_Handle *c, | 912 | const struct GNUNET_CONFIGURATION_Handle *c, |
913 | struct GNUNET_SERVICE_Handle *service) | 913 | struct GNUNET_SERVICE_Handle *service) |
914 | { | 914 | { |
915 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 915 | struct GNUNET_CRYPTO_EddsaPrivateKey pk; |
916 | char *keyfile; | 916 | char *keyfile; |
917 | 917 | ||
918 | GSC_cfg = c; | 918 | GSC_cfg = c; |
919 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (GSC_cfg, | 919 | if (GNUNET_OK != |
920 | "PEER", | 920 | GNUNET_CONFIGURATION_get_value_filename (GSC_cfg, |
921 | "PRIVATE_KEY", | 921 | "PEER", |
922 | &keyfile)) | 922 | "PRIVATE_KEY", |
923 | &keyfile)) | ||
923 | { | 924 | { |
924 | GNUNET_log ( | 925 | GNUNET_log ( |
925 | GNUNET_ERROR_TYPE_ERROR, | 926 | GNUNET_ERROR_TYPE_ERROR, |
@@ -931,10 +932,19 @@ run (void *cls, | |||
931 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 932 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
932 | GNUNET_SERVICE_suspend (service); | 933 | GNUNET_SERVICE_suspend (service); |
933 | GSC_TYPEMAP_init (); | 934 | GSC_TYPEMAP_init (); |
934 | pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); | 935 | if (GNUNET_SYSERR == |
936 | GNUNET_CRYPTO_eddsa_key_from_file (keyfile, | ||
937 | GNUNET_YES, | ||
938 | &pk)) | ||
939 | { | ||
940 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
941 | "Failed to setup peer's private key\n"); | ||
942 | GNUNET_SCHEDULER_shutdown (); | ||
943 | GNUNET_free (keyfile); | ||
944 | return; | ||
945 | } | ||
935 | GNUNET_free (keyfile); | 946 | GNUNET_free (keyfile); |
936 | GNUNET_assert (NULL != pk); | 947 | if (GNUNET_OK != GSC_KX_init (&pk)) |
937 | if (GNUNET_OK != GSC_KX_init (pk)) | ||
938 | { | 948 | { |
939 | GNUNET_SCHEDULER_shutdown (); | 949 | GNUNET_SCHEDULER_shutdown (); |
940 | return; | 950 | return; |
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c index 315095938..cafe658e8 100644 --- a/src/core/gnunet-service-core_kx.c +++ b/src/core/gnunet-service-core_kx.c | |||
@@ -366,12 +366,12 @@ static struct GNUNET_TRANSPORT_CoreHandle *transport; | |||
366 | /** | 366 | /** |
367 | * Our private key. | 367 | * Our private key. |
368 | */ | 368 | */ |
369 | static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key; | 369 | static struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key; |
370 | 370 | ||
371 | /** | 371 | /** |
372 | * Our ephemeral private key. | 372 | * Our ephemeral private key. |
373 | */ | 373 | */ |
374 | static struct GNUNET_CRYPTO_EcdhePrivateKey *my_ephemeral_key; | 374 | static struct GNUNET_CRYPTO_EcdhePrivateKey my_ephemeral_key; |
375 | 375 | ||
376 | /** | 376 | /** |
377 | * Current message we send for a key exchange. | 377 | * Current message we send for a key exchange. |
@@ -935,9 +935,10 @@ derive_session_keys (struct GSC_KeyExchangeInfo *kx) | |||
935 | { | 935 | { |
936 | struct GNUNET_HashCode key_material; | 936 | struct GNUNET_HashCode key_material; |
937 | 937 | ||
938 | if (GNUNET_OK != GNUNET_CRYPTO_ecc_ecdh (my_ephemeral_key, | 938 | if (GNUNET_OK != |
939 | &kx->other_ephemeral_key, | 939 | GNUNET_CRYPTO_ecc_ecdh (&my_ephemeral_key, |
940 | &key_material)) | 940 | &kx->other_ephemeral_key, |
941 | &key_material)) | ||
941 | { | 942 | { |
942 | GNUNET_break (0); | 943 | GNUNET_break (0); |
943 | return; | 944 | return; |
@@ -1850,11 +1851,11 @@ sign_ephemeral_key () | |||
1850 | current_ekm.expiration_time = | 1851 | current_ekm.expiration_time = |
1851 | GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS); | 1852 | GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS); |
1852 | } | 1853 | } |
1853 | GNUNET_CRYPTO_ecdhe_key_get_public (my_ephemeral_key, | 1854 | GNUNET_CRYPTO_ecdhe_key_get_public (&my_ephemeral_key, |
1854 | ¤t_ekm.ephemeral_key); | 1855 | ¤t_ekm.ephemeral_key); |
1855 | current_ekm.origin_identity = GSC_my_identity; | 1856 | current_ekm.origin_identity = GSC_my_identity; |
1856 | GNUNET_assert (GNUNET_OK == | 1857 | GNUNET_assert (GNUNET_OK == |
1857 | GNUNET_CRYPTO_eddsa_sign_ (my_private_key, | 1858 | GNUNET_CRYPTO_eddsa_sign_ (&my_private_key, |
1858 | ¤t_ekm.purpose, | 1859 | ¤t_ekm.purpose, |
1859 | ¤t_ekm.signature)); | 1860 | ¤t_ekm.signature)); |
1860 | } | 1861 | } |
@@ -1871,10 +1872,7 @@ do_rekey (void *cls) | |||
1871 | struct GSC_KeyExchangeInfo *pos; | 1872 | struct GSC_KeyExchangeInfo *pos; |
1872 | 1873 | ||
1873 | rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY, &do_rekey, NULL); | 1874 | rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY, &do_rekey, NULL); |
1874 | if (NULL != my_ephemeral_key) | 1875 | GNUNET_CRYPTO_ecdhe_key_create (&my_ephemeral_key); |
1875 | GNUNET_free (my_ephemeral_key); | ||
1876 | my_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create (); | ||
1877 | GNUNET_assert (NULL != my_ephemeral_key); | ||
1878 | sign_ephemeral_key (); | 1876 | sign_ephemeral_key (); |
1879 | { | 1877 | { |
1880 | struct GNUNET_HashCode eh; | 1878 | struct GNUNET_HashCode eh; |
@@ -1931,17 +1929,10 @@ GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) | |||
1931 | NULL), | 1929 | NULL), |
1932 | GNUNET_MQ_handler_end () }; | 1930 | GNUNET_MQ_handler_end () }; |
1933 | 1931 | ||
1934 | my_private_key = pk; | 1932 | my_private_key = *pk; |
1935 | GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, | 1933 | GNUNET_CRYPTO_eddsa_key_get_public (&my_private_key, |
1936 | &GSC_my_identity.public_key); | 1934 | &GSC_my_identity.public_key); |
1937 | my_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create (); | 1935 | GNUNET_CRYPTO_ecdhe_key_create (&my_ephemeral_key); |
1938 | if (NULL == my_ephemeral_key) | ||
1939 | { | ||
1940 | GNUNET_break (0); | ||
1941 | GNUNET_free (my_private_key); | ||
1942 | my_private_key = NULL; | ||
1943 | return GNUNET_SYSERR; | ||
1944 | } | ||
1945 | sign_ephemeral_key (); | 1936 | sign_ephemeral_key (); |
1946 | { | 1937 | { |
1947 | struct GNUNET_HashCode eh; | 1938 | struct GNUNET_HashCode eh; |
@@ -1989,16 +1980,12 @@ GSC_KX_done () | |||
1989 | GNUNET_SCHEDULER_cancel (rekey_task); | 1980 | GNUNET_SCHEDULER_cancel (rekey_task); |
1990 | rekey_task = NULL; | 1981 | rekey_task = NULL; |
1991 | } | 1982 | } |
1992 | if (NULL != my_ephemeral_key) | 1983 | memset (&my_ephemeral_key, |
1993 | { | 1984 | 0, |
1994 | GNUNET_free (my_ephemeral_key); | 1985 | sizeof (my_ephemeral_key)); |
1995 | my_ephemeral_key = NULL; | 1986 | memset (&my_private_key, |
1996 | } | 1987 | 0, |
1997 | if (NULL != my_private_key) | 1988 | sizeof (my_private_key)); |
1998 | { | ||
1999 | GNUNET_free (my_private_key); | ||
2000 | my_private_key = NULL; | ||
2001 | } | ||
2002 | if (NULL != nc) | 1989 | if (NULL != nc) |
2003 | { | 1990 | { |
2004 | GNUNET_notification_context_destroy (nc); | 1991 | GNUNET_notification_context_destroy (nc); |
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 29e6de9d5..cf9069918 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c | |||
@@ -315,7 +315,7 @@ static struct GNUNET_CONFIGURATION_Handle *block_cfg; | |||
315 | /** | 315 | /** |
316 | * Private key of this peer. Used to sign LOC URI requests. | 316 | * Private key of this peer. Used to sign LOC URI requests. |
317 | */ | 317 | */ |
318 | static struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 318 | static struct GNUNET_CRYPTO_EddsaPrivateKey pk; |
319 | 319 | ||
320 | /** | 320 | /** |
321 | * ID of our task that we use to age the cover counters. | 321 | * ID of our task that we use to age the cover counters. |
@@ -939,7 +939,7 @@ handle_client_loc_sign (void *cls, | |||
939 | base.data.chk.chk = msg->chk; | 939 | base.data.chk.chk = msg->chk; |
940 | base.data.chk.file_length = GNUNET_ntohll (msg->file_length); | 940 | base.data.chk.file_length = GNUNET_ntohll (msg->file_length); |
941 | loc = GNUNET_FS_uri_loc_create (&base, | 941 | loc = GNUNET_FS_uri_loc_create (&base, |
942 | pk, | 942 | &pk, |
943 | GNUNET_TIME_absolute_ntoh ( | 943 | GNUNET_TIME_absolute_ntoh ( |
944 | msg->expiration_time)); | 944 | msg->expiration_time)); |
945 | env = GNUNET_MQ_msg (resp, | 945 | env = GNUNET_MQ_msg (resp, |
@@ -1283,10 +1283,19 @@ main_init (const struct GNUNET_CONFIGURATION_Handle *c) | |||
1283 | GNUNET_SCHEDULER_shutdown (); | 1283 | GNUNET_SCHEDULER_shutdown (); |
1284 | return GNUNET_SYSERR; | 1284 | return GNUNET_SYSERR; |
1285 | } | 1285 | } |
1286 | pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); | 1286 | if (GNUNET_SYSERR == |
1287 | GNUNET_CRYPTO_eddsa_key_from_file (keyfile, | ||
1288 | GNUNET_YES, | ||
1289 | &pk)) | ||
1290 | { | ||
1291 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1292 | "Failed to setup peer's private key\n"); | ||
1293 | GNUNET_SCHEDULER_shutdown (); | ||
1294 | GNUNET_free (keyfile); | ||
1295 | return GNUNET_SYSERR; | ||
1296 | } | ||
1287 | GNUNET_free (keyfile); | 1297 | GNUNET_free (keyfile); |
1288 | GNUNET_assert (NULL != pk); | 1298 | GNUNET_CRYPTO_eddsa_key_get_public (&pk, |
1289 | GNUNET_CRYPTO_eddsa_key_get_public (pk, | ||
1290 | &GSF_my_id.public_key); | 1299 | &GSF_my_id.public_key); |
1291 | 1300 | ||
1292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1301 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
diff --git a/src/fs/test_fs_namespace.c b/src/fs/test_fs_namespace.c index cdcb4d8fd..484884243 100644 --- a/src/fs/test_fs_namespace.c +++ b/src/fs/test_fs_namespace.c | |||
@@ -239,7 +239,7 @@ static void | |||
239 | adv_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) | 239 | adv_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) |
240 | { | 240 | { |
241 | struct GNUNET_CONTAINER_MetaData *meta; | 241 | struct GNUNET_CONTAINER_MetaData *meta; |
242 | struct GNUNET_CRYPTO_EcdsaPrivateKey *ns; | 242 | struct GNUNET_CRYPTO_EcdsaPrivateKey ns; |
243 | struct GNUNET_FS_BlockOptions bo; | 243 | struct GNUNET_FS_BlockOptions bo; |
244 | 244 | ||
245 | if (NULL != emsg) | 245 | if (NULL != emsg) |
@@ -249,7 +249,7 @@ adv_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) | |||
249 | GNUNET_FS_stop (fs); | 249 | GNUNET_FS_stop (fs); |
250 | return; | 250 | return; |
251 | } | 251 | } |
252 | ns = GNUNET_CRYPTO_ecdsa_key_create (); | 252 | GNUNET_CRYPTO_ecdsa_key_create (&ns); |
253 | meta = GNUNET_CONTAINER_meta_data_create (); | 253 | meta = GNUNET_CONTAINER_meta_data_create (); |
254 | sks_expect_uri = GNUNET_FS_uri_dup (uri); | 254 | sks_expect_uri = GNUNET_FS_uri_dup (uri); |
255 | bo.content_priority = 1; | 255 | bo.content_priority = 1; |
@@ -257,24 +257,23 @@ adv_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) | |||
257 | bo.replication_level = 0; | 257 | bo.replication_level = 0; |
258 | bo.expiration_time = | 258 | bo.expiration_time = |
259 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); | 259 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); |
260 | GNUNET_CRYPTO_ecdsa_key_get_public (ns, &nsid); | 260 | GNUNET_CRYPTO_ecdsa_key_get_public (&ns, |
261 | GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri, | 261 | &nsid); |
262 | GNUNET_FS_publish_sks (fs, | ||
263 | &ns, "this", "next", meta, uri, | ||
262 | &bo, GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont, NULL); | 264 | &bo, GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont, NULL); |
263 | GNUNET_CONTAINER_meta_data_destroy (meta); | 265 | GNUNET_CONTAINER_meta_data_destroy (meta); |
264 | GNUNET_free (ns); | ||
265 | } | 266 | } |
266 | 267 | ||
267 | 268 | ||
268 | static void | 269 | static void |
269 | testNamespace () | 270 | testNamespace (void) |
270 | { | 271 | { |
271 | struct GNUNET_CRYPTO_EcdsaPrivateKey *ns; | ||
272 | struct GNUNET_FS_BlockOptions bo; | 272 | struct GNUNET_FS_BlockOptions bo; |
273 | struct GNUNET_CONTAINER_MetaData *meta; | 273 | struct GNUNET_CONTAINER_MetaData *meta; |
274 | struct GNUNET_FS_Uri *ksk_uri; | 274 | struct GNUNET_FS_Uri *ksk_uri; |
275 | struct GNUNET_FS_Uri *sks_uri; | 275 | struct GNUNET_FS_Uri *sks_uri; |
276 | 276 | ||
277 | ns = GNUNET_CRYPTO_ecdsa_key_create (); | ||
278 | meta = GNUNET_CONTAINER_meta_data_create (); | 277 | meta = GNUNET_CONTAINER_meta_data_create (); |
279 | ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/testnsa", NULL); | 278 | ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/testnsa", NULL); |
280 | bo.content_priority = 1; | 279 | bo.content_priority = 1; |
@@ -293,7 +292,6 @@ testNamespace () | |||
293 | NULL); | 292 | NULL); |
294 | GNUNET_FS_uri_destroy (ksk_uri); | 293 | GNUNET_FS_uri_destroy (ksk_uri); |
295 | GNUNET_CONTAINER_meta_data_destroy (meta); | 294 | GNUNET_CONTAINER_meta_data_destroy (meta); |
296 | GNUNET_free (ns); | ||
297 | } | 295 | } |
298 | 296 | ||
299 | 297 | ||
diff --git a/src/fs/test_fs_namespace_list_updateable.c b/src/fs/test_fs_namespace_list_updateable.c index 4311f0110..2132220fb 100644 --- a/src/fs/test_fs_namespace_list_updateable.c +++ b/src/fs/test_fs_namespace_list_updateable.c | |||
@@ -33,7 +33,7 @@ static struct GNUNET_FS_Handle *fs; | |||
33 | 33 | ||
34 | static int err; | 34 | static int err; |
35 | 35 | ||
36 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *ns; | 36 | static struct GNUNET_CRYPTO_EcdsaPrivateKey ns; |
37 | 37 | ||
38 | static struct GNUNET_CONTAINER_MetaData *meta; | 38 | static struct GNUNET_CONTAINER_MetaData *meta; |
39 | 39 | ||
@@ -58,8 +58,6 @@ do_shutdown () | |||
58 | GNUNET_FS_uri_destroy (uri_this); | 58 | GNUNET_FS_uri_destroy (uri_this); |
59 | if (uri_next != NULL) | 59 | if (uri_next != NULL) |
60 | GNUNET_FS_uri_destroy (uri_next); | 60 | GNUNET_FS_uri_destroy (uri_next); |
61 | if (ns != NULL) | ||
62 | GNUNET_free (ns); | ||
63 | if (meta != NULL) | 61 | if (meta != NULL) |
64 | GNUNET_CONTAINER_meta_data_destroy (meta); | 62 | GNUNET_CONTAINER_meta_data_destroy (meta); |
65 | } | 63 | } |
@@ -87,7 +85,7 @@ check_this_next (void *cls, const char *last_id, | |||
87 | GNUNET_break (0 == strcmp (next_id, "next")); | 85 | GNUNET_break (0 == strcmp (next_id, "next")); |
88 | err -= 2; | 86 | err -= 2; |
89 | err += 4; | 87 | err += 4; |
90 | GNUNET_FS_namespace_list_updateable (fs, ns, next_id, &check_next, NULL); | 88 | GNUNET_FS_namespace_list_updateable (fs, &ns, next_id, &check_next, NULL); |
91 | } | 89 | } |
92 | 90 | ||
93 | 91 | ||
@@ -96,7 +94,7 @@ sks_cont_next (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) | |||
96 | { | 94 | { |
97 | GNUNET_assert (NULL == emsg); | 95 | GNUNET_assert (NULL == emsg); |
98 | err += 2; | 96 | err += 2; |
99 | GNUNET_FS_namespace_list_updateable (fs, ns, NULL, &check_this_next, NULL); | 97 | GNUNET_FS_namespace_list_updateable (fs, &ns, NULL, &check_this_next, NULL); |
100 | } | 98 | } |
101 | 99 | ||
102 | 100 | ||
@@ -117,17 +115,17 @@ sks_cont_this (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) | |||
117 | { | 115 | { |
118 | GNUNET_assert (NULL == emsg); | 116 | GNUNET_assert (NULL == emsg); |
119 | err = 1; | 117 | err = 1; |
120 | GNUNET_FS_namespace_list_updateable (fs, ns, NULL, &check_this, NULL); | 118 | GNUNET_FS_namespace_list_updateable (fs, &ns, NULL, &check_this, NULL); |
121 | GNUNET_FS_publish_sks (fs, ns, "next", "future", meta, uri_next, &bo, | 119 | GNUNET_FS_publish_sks (fs, |
120 | &ns, "next", "future", meta, uri_next, &bo, | ||
122 | GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_next, NULL); | 121 | GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_next, NULL); |
123 | } | 122 | } |
124 | 123 | ||
125 | 124 | ||
126 | static void | 125 | static void |
127 | testNamespace () | 126 | testNamespace (void) |
128 | { | 127 | { |
129 | ns = GNUNET_CRYPTO_ecdsa_key_create (); | 128 | GNUNET_CRYPTO_ecdsa_key_create (&ns); |
130 | GNUNET_assert (NULL != ns); | ||
131 | bo.content_priority = 1; | 129 | bo.content_priority = 1; |
132 | bo.anonymity_level = 1; | 130 | bo.anonymity_level = 1; |
133 | bo.replication_level = 0; | 131 | bo.replication_level = 0; |
@@ -145,7 +143,8 @@ testNamespace () | |||
145 | ( | 143 | ( |
146 | "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.43", | 144 | "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.43", |
147 | NULL); | 145 | NULL); |
148 | GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri_this, &bo, | 146 | GNUNET_FS_publish_sks (fs, |
147 | &ns, "this", "next", meta, uri_this, &bo, | ||
149 | GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_this, NULL); | 148 | GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_this, NULL); |
150 | } | 149 | } |
151 | 150 | ||
diff --git a/src/fs/test_fs_uri.c b/src/fs/test_fs_uri.c index 2a324af9a..30eafab9a 100644 --- a/src/fs/test_fs_uri.c +++ b/src/fs/test_fs_uri.c | |||
@@ -81,7 +81,7 @@ testLocation () | |||
81 | struct GNUNET_FS_Uri *uri2; | 81 | struct GNUNET_FS_Uri *uri2; |
82 | struct GNUNET_FS_Uri *baseURI; | 82 | struct GNUNET_FS_Uri *baseURI; |
83 | char *emsg; | 83 | char *emsg; |
84 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 84 | struct GNUNET_CRYPTO_EddsaPrivateKey pk; |
85 | 85 | ||
86 | baseURI = | 86 | baseURI = |
87 | GNUNET_FS_uri_parse | 87 | GNUNET_FS_uri_parse |
@@ -90,11 +90,10 @@ testLocation () | |||
90 | &emsg); | 90 | &emsg); |
91 | GNUNET_assert (baseURI != NULL); | 91 | GNUNET_assert (baseURI != NULL); |
92 | GNUNET_assert (emsg == NULL); | 92 | GNUNET_assert (emsg == NULL); |
93 | pk = GNUNET_CRYPTO_eddsa_key_create (); | 93 | GNUNET_CRYPTO_eddsa_key_create (&pk); |
94 | uri = GNUNET_FS_uri_loc_create (baseURI, | 94 | uri = GNUNET_FS_uri_loc_create (baseURI, |
95 | pk, | 95 | &pk, |
96 | GNUNET_TIME_absolute_get ()); | 96 | GNUNET_TIME_absolute_get ()); |
97 | GNUNET_free (pk); | ||
98 | if (NULL == uri) | 97 | if (NULL == uri) |
99 | { | 98 | { |
100 | GNUNET_break (0); | 99 | GNUNET_break (0); |
@@ -154,7 +153,7 @@ testNamespace (int i) | |||
154 | char *uri; | 153 | char *uri; |
155 | struct GNUNET_FS_Uri *ret; | 154 | struct GNUNET_FS_Uri *ret; |
156 | char *emsg; | 155 | char *emsg; |
157 | struct GNUNET_CRYPTO_EcdsaPrivateKey *ph; | 156 | struct GNUNET_CRYPTO_EcdsaPrivateKey ph; |
158 | struct GNUNET_CRYPTO_EcdsaPublicKey id; | 157 | struct GNUNET_CRYPTO_EcdsaPublicKey id; |
159 | char buf[1024]; | 158 | char buf[1024]; |
160 | char ubuf[1024]; | 159 | char ubuf[1024]; |
@@ -187,8 +186,9 @@ testNamespace (int i) | |||
187 | GNUNET_assert (0); | 186 | GNUNET_assert (0); |
188 | } | 187 | } |
189 | GNUNET_free (emsg); | 188 | GNUNET_free (emsg); |
190 | ph = GNUNET_CRYPTO_ecdsa_key_create (); | 189 | GNUNET_CRYPTO_ecdsa_key_create (&ph); |
191 | GNUNET_CRYPTO_ecdsa_key_get_public (ph, &id); | 190 | GNUNET_CRYPTO_ecdsa_key_get_public (&ph, |
191 | &id); | ||
192 | sret = GNUNET_STRINGS_data_to_string (&id, sizeof(id), | 192 | sret = GNUNET_STRINGS_data_to_string (&id, sizeof(id), |
193 | ubuf, sizeof(ubuf) - 1); | 193 | ubuf, sizeof(ubuf) - 1); |
194 | GNUNET_assert (NULL != sret); | 194 | GNUNET_assert (NULL != sret); |
diff --git a/src/gnsrecord/perf_gnsrecord_crypto.c b/src/gnsrecord/perf_gnsrecord_crypto.c index 3bb4ca4e1..b2614eb77 100644 --- a/src/gnsrecord/perf_gnsrecord_crypto.c +++ b/src/gnsrecord/perf_gnsrecord_crypto.c | |||
@@ -73,7 +73,7 @@ run (void *cls, | |||
73 | struct GNUNET_GNSRECORD_Data *s_rd; | 73 | struct GNUNET_GNSRECORD_Data *s_rd; |
74 | const char *s_name; | 74 | const char *s_name; |
75 | struct GNUNET_TIME_Absolute start_time; | 75 | struct GNUNET_TIME_Absolute start_time; |
76 | struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 76 | struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
77 | struct GNUNET_TIME_Absolute expire; | 77 | struct GNUNET_TIME_Absolute expire; |
78 | 78 | ||
79 | (void) cls; | 79 | (void) cls; |
@@ -81,8 +81,7 @@ run (void *cls, | |||
81 | (void) cfgfile; | 81 | (void) cfgfile; |
82 | (void) cfg; | 82 | (void) cfg; |
83 | expire = GNUNET_TIME_absolute_get (); | 83 | expire = GNUNET_TIME_absolute_get (); |
84 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 84 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); |
85 | GNUNET_assert (NULL != privkey); | ||
86 | 85 | ||
87 | /* test block creation */ | 86 | /* test block creation */ |
88 | s_name = "DUMMY.dummy.gnunet"; | 87 | s_name = "DUMMY.dummy.gnunet"; |
@@ -91,12 +90,12 @@ run (void *cls, | |||
91 | for (unsigned int i = 0; i < ROUNDS; i++) | 90 | for (unsigned int i = 0; i < ROUNDS; i++) |
92 | { | 91 | { |
93 | GNUNET_assert (NULL != (block = | 92 | GNUNET_assert (NULL != (block = |
94 | GNUNET_GNSRECORD_block_create2 (privkey, | 93 | GNUNET_GNSRECORD_block_create2 (&privkey, |
95 | expire, | 94 | expire, |
96 | s_name, | 95 | s_name, |
97 | s_rd, | 96 | s_rd, |
98 | RECORDS))); | 97 | RECORDS))); |
99 | GNUNET_GNSRECORD_query_from_private_key (privkey, | 98 | GNUNET_GNSRECORD_query_from_private_key (&privkey, |
100 | s_name, | 99 | s_name, |
101 | &query); | 100 | &query); |
102 | GNUNET_free (block); | 101 | GNUNET_free (block); |
@@ -110,7 +109,6 @@ run (void *cls, | |||
110 | for (unsigned int i = 0; i < RECORDS; i++) | 109 | for (unsigned int i = 0; i < RECORDS; i++) |
111 | GNUNET_free ((void *) s_rd[i].data); | 110 | GNUNET_free ((void *) s_rd[i].data); |
112 | GNUNET_free (s_rd); | 111 | GNUNET_free (s_rd); |
113 | GNUNET_free (privkey); | ||
114 | } | 112 | } |
115 | 113 | ||
116 | 114 | ||
diff --git a/src/gnsrecord/test_gnsrecord_crypto.c b/src/gnsrecord/test_gnsrecord_crypto.c index 0da19fbe9..b67e9a123 100644 --- a/src/gnsrecord/test_gnsrecord_crypto.c +++ b/src/gnsrecord/test_gnsrecord_crypto.c | |||
@@ -41,8 +41,6 @@ | |||
41 | #define TEST_REMOVE_RECORD_DATA 'b' | 41 | #define TEST_REMOVE_RECORD_DATA 'b' |
42 | 42 | ||
43 | 43 | ||
44 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | ||
45 | |||
46 | static struct GNUNET_GNSRECORD_Data *s_rd; | 44 | static struct GNUNET_GNSRECORD_Data *s_rd; |
47 | 45 | ||
48 | static char *s_name; | 46 | static char *s_name; |
@@ -106,15 +104,16 @@ run (void *cls, | |||
106 | struct GNUNET_HashCode query_pub; | 104 | struct GNUNET_HashCode query_pub; |
107 | struct GNUNET_HashCode query_priv; | 105 | struct GNUNET_HashCode query_priv; |
108 | struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get (); | 106 | struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get (); |
107 | struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | ||
108 | |||
109 | 109 | ||
110 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 110 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); |
111 | GNUNET_assert (NULL != privkey); | ||
112 | /* get public key */ | 111 | /* get public key */ |
113 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, | 112 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, |
114 | &pubkey); | 113 | &pubkey); |
115 | 114 | ||
116 | /* test query derivation */ | 115 | /* test query derivation */ |
117 | GNUNET_GNSRECORD_query_from_private_key (privkey, | 116 | GNUNET_GNSRECORD_query_from_private_key (&privkey, |
118 | "testlabel", | 117 | "testlabel", |
119 | &query_priv); | 118 | &query_priv); |
120 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, | 119 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, |
@@ -129,7 +128,7 @@ run (void *cls, | |||
129 | 128 | ||
130 | /* Create block */ | 129 | /* Create block */ |
131 | GNUNET_assert (NULL != (block = | 130 | GNUNET_assert (NULL != (block = |
132 | GNUNET_GNSRECORD_block_create (privkey, | 131 | GNUNET_GNSRECORD_block_create (&privkey, |
133 | expire, | 132 | expire, |
134 | s_name, | 133 | s_name, |
135 | s_rd, | 134 | s_rd, |
@@ -143,7 +142,6 @@ run (void *cls, | |||
143 | &rd_decrypt_cb, | 142 | &rd_decrypt_cb, |
144 | s_name)); | 143 | s_name)); |
145 | GNUNET_free (block); | 144 | GNUNET_free (block); |
146 | GNUNET_free (privkey); | ||
147 | } | 145 | } |
148 | 146 | ||
149 | 147 | ||
diff --git a/src/hostlist/gnunet-daemon-hostlist_server.c b/src/hostlist/gnunet-daemon-hostlist_server.c index b2b7dac72..999730e3e 100644 --- a/src/hostlist/gnunet-daemon-hostlist_server.c +++ b/src/hostlist/gnunet-daemon-hostlist_server.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include "gnunet_peerinfo_service.h" | 32 | #include "gnunet_peerinfo_service.h" |
33 | #include "gnunet-daemon-hostlist.h" | 33 | #include "gnunet-daemon-hostlist.h" |
34 | #include "gnunet_resolver_service.h" | 34 | #include "gnunet_resolver_service.h" |
35 | #include "gnunet_mhd_compat.h" | ||
35 | 36 | ||
36 | 37 | ||
37 | /** | 38 | /** |
@@ -294,7 +295,7 @@ host_processor (void *cls, | |||
294 | * @param addrlen length of @a addr | 295 | * @param addrlen length of @a addr |
295 | * @return #MHD_YES if connection is allowed, #MHD_NO if not (we are not ready) | 296 | * @return #MHD_YES if connection is allowed, #MHD_NO if not (we are not ready) |
296 | */ | 297 | */ |
297 | static int | 298 | static MHD_RESULT |
298 | accept_policy_callback (void *cls, | 299 | accept_policy_callback (void *cls, |
299 | const struct sockaddr *addr, | 300 | const struct sockaddr *addr, |
300 | socklen_t addrlen) | 301 | socklen_t addrlen) |
@@ -345,7 +346,7 @@ accept_policy_callback (void *cls, | |||
345 | * #MHD_NO if the socket must be closed due to a serios | 346 | * #MHD_NO if the socket must be closed due to a serios |
346 | * error while handling the request | 347 | * error while handling the request |
347 | */ | 348 | */ |
348 | static int | 349 | static MHD_RESULT |
349 | access_handler_callback (void *cls, | 350 | access_handler_callback (void *cls, |
350 | struct MHD_Connection *connection, | 351 | struct MHD_Connection *connection, |
351 | const char *url, | 352 | const char *url, |
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c index b509e7e9a..42ad94df1 100644 --- a/src/identity/gnunet-service-identity.c +++ b/src/identity/gnunet-service-identity.c | |||
@@ -57,7 +57,7 @@ struct Ego | |||
57 | /** | 57 | /** |
58 | * Private key of the ego. | 58 | * Private key of the ego. |
59 | */ | 59 | */ |
60 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; | 60 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * String identifier for the ego. | 63 | * String identifier for the ego. |
@@ -190,7 +190,6 @@ shutdown_task (void *cls) | |||
190 | while (NULL != (e = ego_head)) | 190 | while (NULL != (e = ego_head)) |
191 | { | 191 | { |
192 | GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, e); | 192 | GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, e); |
193 | GNUNET_free (e->pk); | ||
194 | GNUNET_free (e->identifier); | 193 | GNUNET_free (e->identifier); |
195 | GNUNET_free (e); | 194 | GNUNET_free (e); |
196 | } | 195 | } |
@@ -247,7 +246,7 @@ create_update_message (struct Ego *ego) | |||
247 | env = GNUNET_MQ_msg_extra (um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); | 246 | env = GNUNET_MQ_msg_extra (um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); |
248 | um->name_len = htons (name_len); | 247 | um->name_len = htons (name_len); |
249 | um->end_of_list = htons (GNUNET_NO); | 248 | um->end_of_list = htons (GNUNET_NO); |
250 | um->private_key = *ego->pk; | 249 | um->private_key = ego->pk; |
251 | GNUNET_memcpy (&um[1], ego->identifier, name_len); | 250 | GNUNET_memcpy (&um[1], ego->identifier, name_len); |
252 | return env; | 251 | return env; |
253 | } | 252 | } |
@@ -273,7 +272,7 @@ create_set_default_message (struct Ego *ego, const char *servicename) | |||
273 | GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); | 272 | GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); |
274 | sdm->name_len = htons (name_len); | 273 | sdm->name_len = htons (name_len); |
275 | sdm->reserved = htons (0); | 274 | sdm->reserved = htons (0); |
276 | sdm->private_key = *ego->pk; | 275 | sdm->private_key = ego->pk; |
277 | GNUNET_memcpy (&sdm[1], servicename, name_len); | 276 | GNUNET_memcpy (&sdm[1], servicename, name_len); |
278 | return env; | 277 | return env; |
279 | } | 278 | } |
@@ -584,7 +583,8 @@ handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm) | |||
584 | str); | 583 | str); |
585 | for (ego = ego_head; NULL != ego; ego = ego->next) | 584 | for (ego = ego_head; NULL != ego; ego = ego->next) |
586 | { | 585 | { |
587 | if (0 == key_cmp (ego->pk, &sdm->private_key)) | 586 | if (0 == key_cmp (&ego->pk, |
587 | &sdm->private_key)) | ||
588 | { | 588 | { |
589 | GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, | 589 | GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, |
590 | str, | 590 | str, |
@@ -627,7 +627,7 @@ notify_listeners (struct Ego *ego) | |||
627 | um->header.size = htons (sizeof(struct UpdateMessage) + name_len); | 627 | um->header.size = htons (sizeof(struct UpdateMessage) + name_len); |
628 | um->name_len = htons (name_len); | 628 | um->name_len = htons (name_len); |
629 | um->end_of_list = htons (GNUNET_NO); | 629 | um->end_of_list = htons (GNUNET_NO); |
630 | um->private_key = *ego->pk; | 630 | um->private_key = ego->pk; |
631 | GNUNET_memcpy (&um[1], ego->identifier, name_len); | 631 | GNUNET_memcpy (&um[1], ego->identifier, name_len); |
632 | GNUNET_notification_context_broadcast (nc, &um->header, GNUNET_NO); | 632 | GNUNET_notification_context_broadcast (nc, &um->header, GNUNET_NO); |
633 | GNUNET_free (um); | 633 | GNUNET_free (um); |
@@ -704,8 +704,7 @@ handle_create_message (void *cls, const struct CreateRequestMessage *crm) | |||
704 | } | 704 | } |
705 | } | 705 | } |
706 | ego = GNUNET_new (struct Ego); | 706 | ego = GNUNET_new (struct Ego); |
707 | ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); | 707 | ego->pk = crm->private_key; |
708 | *ego->pk = crm->private_key; | ||
709 | ego->identifier = GNUNET_strdup (str); | 708 | ego->identifier = GNUNET_strdup (str); |
710 | GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego); | 709 | GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego); |
711 | send_result_code (client, 0, NULL); | 710 | send_result_code (client, 0, NULL); |
@@ -997,7 +996,6 @@ handle_delete_message (void *cls, const struct DeleteMessage *dm) | |||
997 | GNUNET_free (ego->identifier); | 996 | GNUNET_free (ego->identifier); |
998 | ego->identifier = NULL; | 997 | ego->identifier = NULL; |
999 | notify_listeners (ego); | 998 | notify_listeners (ego); |
1000 | GNUNET_free (ego->pk); | ||
1001 | GNUNET_free (ego); | 999 | GNUNET_free (ego); |
1002 | GNUNET_free (name); | 1000 | GNUNET_free (name); |
1003 | send_result_code (client, 0, NULL); | 1001 | send_result_code (client, 0, NULL); |
@@ -1023,7 +1021,8 @@ handle_delete_message (void *cls, const struct DeleteMessage *dm) | |||
1023 | * #GNUNET_SYSERR to abort iteration with error! | 1021 | * #GNUNET_SYSERR to abort iteration with error! |
1024 | */ | 1022 | */ |
1025 | static int | 1023 | static int |
1026 | process_ego_file (void *cls, const char *filename) | 1024 | process_ego_file (void *cls, |
1025 | const char *filename) | ||
1027 | { | 1026 | { |
1028 | struct Ego *ego; | 1027 | struct Ego *ego; |
1029 | const char *fn; | 1028 | const char *fn; |
@@ -1035,8 +1034,10 @@ process_ego_file (void *cls, const char *filename) | |||
1035 | return GNUNET_OK; | 1034 | return GNUNET_OK; |
1036 | } | 1035 | } |
1037 | ego = GNUNET_new (struct Ego); | 1036 | ego = GNUNET_new (struct Ego); |
1038 | ego->pk = GNUNET_CRYPTO_ecdsa_key_create_from_file (filename); | 1037 | if (GNUNET_OK != |
1039 | if (NULL == ego->pk) | 1038 | GNUNET_CRYPTO_ecdsa_key_from_file (filename, |
1039 | GNUNET_NO, | ||
1040 | &ego->pk)) | ||
1040 | { | 1041 | { |
1041 | GNUNET_free (ego); | 1042 | GNUNET_free (ego); |
1042 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1043 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -1044,7 +1045,9 @@ process_ego_file (void *cls, const char *filename) | |||
1044 | filename); | 1045 | filename); |
1045 | return GNUNET_OK; | 1046 | return GNUNET_OK; |
1046 | } | 1047 | } |
1047 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded ego `%s'\n", fn + 1); | 1048 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1049 | "Loaded ego `%s'\n", | ||
1050 | fn + 1); | ||
1048 | ego->identifier = GNUNET_strdup (fn + 1); | 1051 | ego->identifier = GNUNET_strdup (fn + 1); |
1049 | GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego); | 1052 | GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego); |
1050 | return GNUNET_OK; | 1053 | return GNUNET_OK; |
@@ -1108,7 +1111,9 @@ run (void *cls, | |||
1108 | _ ("Failed to create directory `%s' for storing egos\n"), | 1111 | _ ("Failed to create directory `%s' for storing egos\n"), |
1109 | ego_directory); | 1112 | ego_directory); |
1110 | } | 1113 | } |
1111 | GNUNET_DISK_directory_scan (ego_directory, &process_ego_file, NULL); | 1114 | GNUNET_DISK_directory_scan (ego_directory, |
1115 | &process_ego_file, | ||
1116 | NULL); | ||
1112 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 1117 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
1113 | } | 1118 | } |
1114 | 1119 | ||
diff --git a/src/identity/identity.h b/src/identity/identity.h index b3c03d1ce..2303bf214 100644 --- a/src/identity/identity.h +++ b/src/identity/identity.h | |||
@@ -247,7 +247,7 @@ struct GNUNET_IDENTITY_Ego | |||
247 | /** | 247 | /** |
248 | * Private key associated with this ego. | 248 | * Private key associated with this ego. |
249 | */ | 249 | */ |
250 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; | 250 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; |
251 | 251 | ||
252 | /** | 252 | /** |
253 | * Current name associated with this ego. | 253 | * Current name associated with this ego. |
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c index 29d9b9011..9176acc27 100644 --- a/src/identity/identity_api.c +++ b/src/identity/identity_api.c | |||
@@ -74,7 +74,7 @@ struct GNUNET_IDENTITY_Operation | |||
74 | /** | 74 | /** |
75 | * Private key to return to @e create_cont, or NULL. | 75 | * Private key to return to @e create_cont, or NULL. |
76 | */ | 76 | */ |
77 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; | 77 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * Continuation to invoke with the result of the transmission for | 80 | * Continuation to invoke with the result of the transmission for |
@@ -156,14 +156,18 @@ const struct GNUNET_IDENTITY_Ego * | |||
156 | GNUNET_IDENTITY_ego_get_anonymous () | 156 | GNUNET_IDENTITY_ego_get_anonymous () |
157 | { | 157 | { |
158 | static struct GNUNET_IDENTITY_Ego anon; | 158 | static struct GNUNET_IDENTITY_Ego anon; |
159 | static int setup; | ||
159 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 160 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
160 | 161 | ||
161 | if (NULL != anon.pk) | 162 | if (setup) |
162 | return &anon; | 163 | return &anon; |
163 | anon.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *) | 164 | anon.pk = *GNUNET_CRYPTO_ecdsa_key_get_anonymous (); |
164 | GNUNET_CRYPTO_ecdsa_key_get_anonymous (); | 165 | GNUNET_CRYPTO_ecdsa_key_get_public (&anon.pk, |
165 | GNUNET_CRYPTO_ecdsa_key_get_public (anon.pk, &pub); | 166 | &pub); |
166 | GNUNET_CRYPTO_hash (&pub, sizeof(pub), &anon.id); | 167 | GNUNET_CRYPTO_hash (&pub, |
168 | sizeof(pub), | ||
169 | &anon.id); | ||
170 | setup = 1; | ||
167 | return &anon; | 171 | return &anon; |
168 | } | 172 | } |
169 | 173 | ||
@@ -193,7 +197,6 @@ free_ego (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
193 | 197 | ||
194 | if (NULL != h->cb) | 198 | if (NULL != h->cb) |
195 | h->cb (h->cb_cls, ego, &ego->ctx, NULL); | 199 | h->cb (h->cb_cls, ego, &ego->ctx, NULL); |
196 | GNUNET_free (ego->pk); | ||
197 | GNUNET_free (ego->name); | 200 | GNUNET_free (ego->name); |
198 | GNUNET_assert (GNUNET_YES == | 201 | GNUNET_assert (GNUNET_YES == |
199 | GNUNET_CONTAINER_multihashmap_remove (h->egos, key, value)); | 202 | GNUNET_CONTAINER_multihashmap_remove (h->egos, key, value)); |
@@ -230,7 +233,6 @@ reschedule_connect (struct GNUNET_IDENTITY_Handle *h) | |||
230 | op->create_cont (op->cls, | 233 | op->create_cont (op->cls, |
231 | NULL, | 234 | NULL, |
232 | "Failed to communicate with the identity service"); | 235 | "Failed to communicate with the identity service"); |
233 | GNUNET_free_non_null (op->pk); | ||
234 | GNUNET_free (op); | 236 | GNUNET_free (op); |
235 | } | 237 | } |
236 | GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h); | 238 | GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h); |
@@ -304,8 +306,7 @@ handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | |||
304 | else if (NULL != op->cb) | 306 | else if (NULL != op->cb) |
305 | op->cb (op->cls, NULL, NULL, NULL); | 307 | op->cb (op->cls, NULL, NULL, NULL); |
306 | else if (NULL != op->create_cont) | 308 | else if (NULL != op->create_cont) |
307 | op->create_cont (op->cls, (NULL == str) ? op->pk : NULL, str); | 309 | op->create_cont (op->cls, (NULL == str) ? &op->pk : NULL, str); |
308 | GNUNET_free_non_null (op->pk); | ||
309 | GNUNET_free (op); | 310 | GNUNET_free (op); |
310 | } | 311 | } |
311 | 312 | ||
@@ -371,8 +372,7 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) | |||
371 | return; | 372 | return; |
372 | } | 373 | } |
373 | ego = GNUNET_new (struct GNUNET_IDENTITY_Ego); | 374 | ego = GNUNET_new (struct GNUNET_IDENTITY_Ego); |
374 | ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); | 375 | ego->pk = um->private_key; |
375 | *ego->pk = um->private_key; | ||
376 | ego->name = GNUNET_strdup (str); | 376 | ego->name = GNUNET_strdup (str); |
377 | ego->id = id; | 377 | ego->id = id; |
378 | GNUNET_assert (GNUNET_YES == | 378 | GNUNET_assert (GNUNET_YES == |
@@ -401,7 +401,6 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) | |||
401 | /* complete deletion */ | 401 | /* complete deletion */ |
402 | if (NULL == str) | 402 | if (NULL == str) |
403 | { | 403 | { |
404 | GNUNET_free (ego->pk); | ||
405 | GNUNET_free (ego->name); | 404 | GNUNET_free (ego->name); |
406 | GNUNET_free (ego); | 405 | GNUNET_free (ego); |
407 | } | 406 | } |
@@ -554,7 +553,7 @@ GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
554 | const struct GNUNET_CRYPTO_EcdsaPrivateKey * | 553 | const struct GNUNET_CRYPTO_EcdsaPrivateKey * |
555 | GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego) | 554 | GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego) |
556 | { | 555 | { |
557 | return ego->pk; | 556 | return &ego->pk; |
558 | } | 557 | } |
559 | 558 | ||
560 | 559 | ||
@@ -568,7 +567,8 @@ void | |||
568 | GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego, | 567 | GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego, |
569 | struct GNUNET_CRYPTO_EcdsaPublicKey *pk) | 568 | struct GNUNET_CRYPTO_EcdsaPublicKey *pk) |
570 | { | 569 | { |
571 | GNUNET_CRYPTO_ecdsa_key_get_public (ego->pk, pk); | 570 | GNUNET_CRYPTO_ecdsa_key_get_public (&ego->pk, |
571 | pk); | ||
572 | } | 572 | } |
573 | 573 | ||
574 | 574 | ||
@@ -657,7 +657,7 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h, | |||
657 | GNUNET_MQ_msg_extra (sdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); | 657 | GNUNET_MQ_msg_extra (sdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); |
658 | sdm->name_len = htons (slen); | 658 | sdm->name_len = htons (slen); |
659 | sdm->reserved = htons (0); | 659 | sdm->reserved = htons (0); |
660 | sdm->private_key = *ego->pk; | 660 | sdm->private_key = ego->pk; |
661 | GNUNET_memcpy (&sdm[1], service_name, slen); | 661 | GNUNET_memcpy (&sdm[1], service_name, slen); |
662 | GNUNET_MQ_send (h->mq, env); | 662 | GNUNET_MQ_send (h->mq, env); |
663 | return op; | 663 | return op; |
@@ -682,7 +682,6 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, | |||
682 | struct GNUNET_IDENTITY_Operation *op; | 682 | struct GNUNET_IDENTITY_Operation *op; |
683 | struct GNUNET_MQ_Envelope *env; | 683 | struct GNUNET_MQ_Envelope *env; |
684 | struct CreateRequestMessage *crm; | 684 | struct CreateRequestMessage *crm; |
685 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; | ||
686 | size_t slen; | 685 | size_t slen; |
687 | 686 | ||
688 | if (NULL == h->mq) | 687 | if (NULL == h->mq) |
@@ -701,9 +700,8 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, | |||
701 | env = GNUNET_MQ_msg_extra (crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE); | 700 | env = GNUNET_MQ_msg_extra (crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE); |
702 | crm->name_len = htons (slen); | 701 | crm->name_len = htons (slen); |
703 | crm->reserved = htons (0); | 702 | crm->reserved = htons (0); |
704 | pk = GNUNET_CRYPTO_ecdsa_key_create (); | 703 | GNUNET_CRYPTO_ecdsa_key_create (&crm->private_key); |
705 | crm->private_key = *pk; | 704 | op->pk = crm->private_key; |
706 | op->pk = pk; | ||
707 | GNUNET_memcpy (&crm[1], name, slen); | 705 | GNUNET_memcpy (&crm[1], name, slen); |
708 | GNUNET_MQ_send (h->mq, env); | 706 | GNUNET_MQ_send (h->mq, env); |
709 | return op; | 707 | return op; |
@@ -820,11 +818,9 @@ GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op) | |||
820 | op->cont = NULL; | 818 | op->cont = NULL; |
821 | op->cb = NULL; | 819 | op->cb = NULL; |
822 | op->create_cont = NULL; | 820 | op->create_cont = NULL; |
823 | if (NULL != op->pk) | 821 | memset (&op->pk, |
824 | { | 822 | 0, |
825 | GNUNET_free (op->pk); | 823 | sizeof (op->pk)); |
826 | op->pk = NULL; | ||
827 | } | ||
828 | } | 824 | } |
829 | 825 | ||
830 | 826 | ||
@@ -854,7 +850,9 @@ GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h) | |||
854 | { | 850 | { |
855 | GNUNET_break (NULL == op->cont); | 851 | GNUNET_break (NULL == op->cont); |
856 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 852 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); |
857 | GNUNET_free_non_null (op->pk); | 853 | memset (&op->pk, |
854 | 0, | ||
855 | sizeof (op->pk)); | ||
858 | GNUNET_free (op); | 856 | GNUNET_free (op); |
859 | } | 857 | } |
860 | if (NULL != h->mq) | 858 | if (NULL != h->mq) |
diff --git a/src/identity/identity_api_lookup.c b/src/identity/identity_api_lookup.c index 108fc7fcf..6c61d3977 100644 --- a/src/identity/identity_api_lookup.c +++ b/src/identity/identity_api_lookup.c | |||
@@ -134,7 +134,7 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) | |||
134 | GNUNET_break (GNUNET_YES != ntohs (um->end_of_list)); | 134 | GNUNET_break (GNUNET_YES != ntohs (um->end_of_list)); |
135 | GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub); | 135 | GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub); |
136 | GNUNET_CRYPTO_hash (&pub, sizeof(pub), &id); | 136 | GNUNET_CRYPTO_hash (&pub, sizeof(pub), &id); |
137 | ego.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *) &um->private_key; | 137 | ego.pk = um->private_key; |
138 | ego.name = (char *) str; | 138 | ego.name = (char *) str; |
139 | ego.id = id; | 139 | ego.id = id; |
140 | el->cb (el->cb_cls, &ego); | 140 | el->cb (el->cb_cls, &ego); |
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index ba992ed56..a5a50e749 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h | |||
@@ -1210,40 +1210,44 @@ GNUNET_CRYPTO_eddsa_public_key_from_string ( | |||
1210 | 1210 | ||
1211 | /** | 1211 | /** |
1212 | * @ingroup crypto | 1212 | * @ingroup crypto |
1213 | * Create a new private key by reading it from a file. If the | 1213 | * @brief Create a new private key by reading it from a file. |
1214 | * files does not exist, create a new key and write it to the | 1214 | * |
1215 | * file. Caller must free return value. Note that this function | 1215 | * If the files does not exist and @a do_create is set, creates a new key and |
1216 | * can not guarantee that another process might not be trying | 1216 | * write it to the file. |
1217 | * the same operation on the same file at the same time. | 1217 | * |
1218 | * If the contents of the file | 1218 | * If the contents of the file are invalid, an error is returned. |
1219 | * are invalid the old file is deleted and a fresh key is | ||
1220 | * created. | ||
1221 | * | 1219 | * |
1222 | * @param filename name of file to use to store the key | 1220 | * @param filename name of file to use to store the key |
1223 | * @return new private key, NULL on error (for example, | 1221 | * @param do_create should a file be created? |
1224 | * permission denied); free using #GNUNET_free | 1222 | * @param[out] pkey set to the private key from @a filename on success |
1223 | * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but | ||
1224 | * we found an existing file, #GNUNET_SYSERR on failure | ||
1225 | */ | 1225 | */ |
1226 | struct GNUNET_CRYPTO_EcdsaPrivateKey * | 1226 | int |
1227 | GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename); | 1227 | GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename, |
1228 | int do_create, | ||
1229 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey); | ||
1228 | 1230 | ||
1229 | 1231 | ||
1230 | /** | 1232 | /** |
1231 | * @ingroup crypto | 1233 | * @ingroup crypto |
1232 | * Create a new private key by reading it from a file. If the | 1234 | * @brief Create a new private key by reading it from a file. |
1233 | * files does not exist, create a new key and write it to the | 1235 | * |
1234 | * file. Caller must free return value. Note that this function | 1236 | * If the files does not exist and @a do_create is set, creates a new key and |
1235 | * can not guarantee that another process might not be trying | 1237 | * write it to the file. |
1236 | * the same operation on the same file at the same time. | 1238 | * |
1237 | * If the contents of the file | 1239 | * If the contents of the file are invalid, an error is returned. |
1238 | * are invalid the old file is deleted and a fresh key is | ||
1239 | * created. | ||
1240 | * | 1240 | * |
1241 | * @param filename name of file to use to store the key | 1241 | * @param filename name of file to use to store the key |
1242 | * @return new private key, NULL on error (for example, | 1242 | * @param do_create should a file be created? |
1243 | * permission denied); free using #GNUNET_free | 1243 | * @param[out] pkey set to the private key from @a filename on success |
1244 | * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but | ||
1245 | * we found an existing file, #GNUNET_SYSERR on failure | ||
1244 | */ | 1246 | */ |
1245 | struct GNUNET_CRYPTO_EddsaPrivateKey * | 1247 | int |
1246 | GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename); | 1248 | GNUNET_CRYPTO_eddsa_key_from_file (const char *filename, |
1249 | int do_create, | ||
1250 | struct GNUNET_CRYPTO_EddsaPrivateKey *pkey); | ||
1247 | 1251 | ||
1248 | 1252 | ||
1249 | /** | 1253 | /** |
@@ -1268,22 +1272,22 @@ GNUNET_CRYPTO_eddsa_key_create_from_configuration ( | |||
1268 | 1272 | ||
1269 | /** | 1273 | /** |
1270 | * @ingroup crypto | 1274 | * @ingroup crypto |
1271 | * Create a new private key. Caller must free return value. | 1275 | * Create a new private key. |
1272 | * | 1276 | * |
1273 | * @return fresh private key; free using #GNUNET_free | 1277 | * @param[out] pk private key to initialize |
1274 | */ | 1278 | */ |
1275 | struct GNUNET_CRYPTO_EcdsaPrivateKey * | 1279 | void |
1276 | GNUNET_CRYPTO_ecdsa_key_create (void); | 1280 | GNUNET_CRYPTO_ecdsa_key_create (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk); |
1277 | 1281 | ||
1278 | 1282 | ||
1279 | /** | 1283 | /** |
1280 | * @ingroup crypto | 1284 | * @ingroup crypto |
1281 | * Create a new private key. Caller must free return value. | 1285 | * Create a new private key. |
1282 | * | 1286 | * |
1283 | * @return fresh private key; free using #GNUNET_free | 1287 | * @param[out] pk private key to initialize |
1284 | */ | 1288 | */ |
1285 | struct GNUNET_CRYPTO_EddsaPrivateKey * | 1289 | void |
1286 | GNUNET_CRYPTO_eddsa_key_create (void); | 1290 | GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk); |
1287 | 1291 | ||
1288 | 1292 | ||
1289 | /** | 1293 | /** |
@@ -1291,20 +1295,9 @@ GNUNET_CRYPTO_eddsa_key_create (void); | |||
1291 | * Create a new private key. Clear with #GNUNET_CRYPTO_ecdhe_key_clear(). | 1295 | * Create a new private key. Clear with #GNUNET_CRYPTO_ecdhe_key_clear(). |
1292 | * | 1296 | * |
1293 | * @param[out] pk set to fresh private key; | 1297 | * @param[out] pk set to fresh private key; |
1294 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | ||
1295 | */ | 1298 | */ |
1296 | int | 1299 | void |
1297 | GNUNET_CRYPTO_ecdhe_key_create2 (struct GNUNET_CRYPTO_EcdhePrivateKey *pk); | 1300 | GNUNET_CRYPTO_ecdhe_key_create (struct GNUNET_CRYPTO_EcdhePrivateKey *pk); |
1298 | |||
1299 | |||
1300 | /** | ||
1301 | * @ingroup crypto | ||
1302 | * Create a new private key. Caller must free return value. | ||
1303 | * | ||
1304 | * @return fresh private key; free using #GNUNET_free | ||
1305 | */ | ||
1306 | struct GNUNET_CRYPTO_EcdhePrivateKey * | ||
1307 | GNUNET_CRYPTO_ecdhe_key_create (void); | ||
1308 | 1301 | ||
1309 | 1302 | ||
1310 | /** | 1303 | /** |
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h index b79be5f70..f43cf8943 100644 --- a/src/include/gnunet_disk_lib.h +++ b/src/include/gnunet_disk_lib.h | |||
@@ -691,35 +691,6 @@ GNUNET_DISK_directory_create (const char *dir); | |||
691 | 691 | ||
692 | 692 | ||
693 | /** | 693 | /** |
694 | * Lock a part of a file. | ||
695 | * | ||
696 | * @param fh file handle | ||
697 | * @param lock_start absolute position from where to lock | ||
698 | * @param lock_end absolute position until where to lock | ||
699 | * @param excl #GNUNET_YES for an exclusive lock | ||
700 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
701 | */ | ||
702 | int | ||
703 | GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, | ||
704 | off_t lock_start, | ||
705 | off_t lock_end, int excl); | ||
706 | |||
707 | |||
708 | /** | ||
709 | * Unlock a part of a file. | ||
710 | * | ||
711 | * @param fh file handle | ||
712 | * @param unlock_start absolute position from where to unlock | ||
713 | * @param unlock_end absolute position until where to unlock | ||
714 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
715 | */ | ||
716 | int | ||
717 | GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, | ||
718 | off_t unlock_start, | ||
719 | off_t unlock_end); | ||
720 | |||
721 | |||
722 | /** | ||
723 | * @brief Removes special characters as ':' from a filename. | 694 | * @brief Removes special characters as ':' from a filename. |
724 | * @param fn the filename to canonicalize | 695 | * @param fn the filename to canonicalize |
725 | */ | 696 | */ |
diff --git a/src/include/gnunet_identity_service.h b/src/include/gnunet_identity_service.h index 674176e0e..e09e2f196 100644 --- a/src/include/gnunet_identity_service.h +++ b/src/include/gnunet_identity_service.h | |||
@@ -137,10 +137,11 @@ GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego, | |||
137 | * NULL if the user just deleted the ego and it | 137 | * NULL if the user just deleted the ego and it |
138 | * must thus no longer be used | 138 | * must thus no longer be used |
139 | */ | 139 | */ |
140 | typedef void (*GNUNET_IDENTITY_Callback) (void *cls, | 140 | typedef void |
141 | struct GNUNET_IDENTITY_Ego *ego, | 141 | (*GNUNET_IDENTITY_Callback) (void *cls, |
142 | void **ctx, | 142 | struct GNUNET_IDENTITY_Ego *ego, |
143 | const char *name); | 143 | void **ctx, |
144 | const char *name); | ||
144 | 145 | ||
145 | 146 | ||
146 | /** | 147 | /** |
@@ -180,7 +181,9 @@ GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *id, | |||
180 | * @param cls closure | 181 | * @param cls closure |
181 | * @param emsg NULL on success, otherwise an error message | 182 | * @param emsg NULL on success, otherwise an error message |
182 | */ | 183 | */ |
183 | typedef void (*GNUNET_IDENTITY_Continuation) (void *cls, const char *emsg); | 184 | typedef void |
185 | (*GNUNET_IDENTITY_Continuation) (void *cls, | ||
186 | const char *emsg); | ||
184 | 187 | ||
185 | 188 | ||
186 | /** | 189 | /** |
@@ -218,7 +221,8 @@ GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h); | |||
218 | * @param pk private key, NULL on error | 221 | * @param pk private key, NULL on error |
219 | * @param emsg error message, NULL on success | 222 | * @param emsg error message, NULL on success |
220 | */ | 223 | */ |
221 | typedef void (*GNUNET_IDENTITY_CreateContinuation) ( | 224 | typedef void |
225 | (*GNUNET_IDENTITY_CreateContinuation) ( | ||
222 | void *cls, | 226 | void *cls, |
223 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 227 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
224 | const char *emsg); | 228 | const char *emsg); |
@@ -294,9 +298,9 @@ GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op); | |||
294 | * @param cls closure | 298 | * @param cls closure |
295 | * @param ego NULL on error / ego not found | 299 | * @param ego NULL on error / ego not found |
296 | */ | 300 | */ |
297 | typedef void (*GNUNET_IDENTITY_EgoCallback) ( | 301 | typedef void |
298 | void *cls, | 302 | (*GNUNET_IDENTITY_EgoCallback) (void *cls, |
299 | const struct GNUNET_IDENTITY_Ego *ego); | 303 | const struct GNUNET_IDENTITY_Ego *ego); |
300 | 304 | ||
301 | /** | 305 | /** |
302 | * Handle for ego lookup. | 306 | * Handle for ego lookup. |
@@ -335,7 +339,8 @@ GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el); | |||
335 | * @param ego NULL on error / ego not found | 339 | * @param ego NULL on error / ego not found |
336 | * @param ego_name NULL on error, name of the ego otherwise | 340 | * @param ego_name NULL on error, name of the ego otherwise |
337 | */ | 341 | */ |
338 | typedef void (*GNUNET_IDENTITY_EgoSuffixCallback) ( | 342 | typedef void |
343 | (*GNUNET_IDENTITY_EgoSuffixCallback) ( | ||
339 | void *cls, | 344 | void *cls, |
340 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, | 345 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, |
341 | const char *ego_name); | 346 | const char *ego_name); |
@@ -373,8 +378,9 @@ GNUNET_IDENTITY_ego_lookup_by_suffix (const struct | |||
373 | * @param el handle for lookup to abort | 378 | * @param el handle for lookup to abort |
374 | */ | 379 | */ |
375 | void | 380 | void |
376 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (struct | 381 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel ( |
377 | GNUNET_IDENTITY_EgoSuffixLookup *el); | 382 | struct GNUNET_IDENTITY_EgoSuffixLookup *el); |
383 | |||
378 | 384 | ||
379 | #if 0 /* keep Emacsens' auto-indent happy */ | 385 | #if 0 /* keep Emacsens' auto-indent happy */ |
380 | { | 386 | { |
diff --git a/src/namestore/perf_namestore_api_zone_iteration.c b/src/namestore/perf_namestore_api_zone_iteration.c index e8277ae65..c1012de62 100644 --- a/src/namestore/perf_namestore_api_zone_iteration.c +++ b/src/namestore/perf_namestore_api_zone_iteration.c | |||
@@ -64,7 +64,7 @@ static struct GNUNET_SCHEDULER_Task *timeout_task; | |||
64 | 64 | ||
65 | static struct GNUNET_SCHEDULER_Task *t; | 65 | static struct GNUNET_SCHEDULER_Task *t; |
66 | 66 | ||
67 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 67 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
68 | 68 | ||
69 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 69 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
70 | 70 | ||
@@ -115,11 +115,6 @@ end (void *cls) | |||
115 | GNUNET_SCHEDULER_cancel (timeout_task); | 115 | GNUNET_SCHEDULER_cancel (timeout_task); |
116 | timeout_task = NULL; | 116 | timeout_task = NULL; |
117 | } | 117 | } |
118 | if (NULL != privkey) | ||
119 | { | ||
120 | GNUNET_free (privkey); | ||
121 | privkey = NULL; | ||
122 | } | ||
123 | } | 118 | } |
124 | 119 | ||
125 | 120 | ||
@@ -243,7 +238,7 @@ zone_proc (void *cls, | |||
243 | } | 238 | } |
244 | GNUNET_free (wrd); | 239 | GNUNET_free (wrd); |
245 | if (0 != GNUNET_memcmp (zone, | 240 | if (0 != GNUNET_memcmp (zone, |
246 | privkey)) | 241 | &privkey)) |
247 | { | 242 | { |
248 | res = 5; | 243 | res = 5; |
249 | GNUNET_break (0); | 244 | GNUNET_break (0); |
@@ -324,7 +319,7 @@ publish_record (void *cls) | |||
324 | "l%u", | 319 | "l%u", |
325 | off); | 320 | off); |
326 | qe = GNUNET_NAMESTORE_records_store (nsh, | 321 | qe = GNUNET_NAMESTORE_records_store (nsh, |
327 | privkey, | 322 | &privkey, |
328 | label, | 323 | label, |
329 | 1, rd, | 324 | 1, rd, |
330 | &put_cont, | 325 | &put_cont, |
@@ -346,8 +341,7 @@ run (void *cls, | |||
346 | NULL); | 341 | NULL); |
347 | nsh = GNUNET_NAMESTORE_connect (cfg); | 342 | nsh = GNUNET_NAMESTORE_connect (cfg); |
348 | GNUNET_assert (NULL != nsh); | 343 | GNUNET_assert (NULL != nsh); |
349 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 344 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); |
350 | GNUNET_assert (NULL != privkey); | ||
351 | start = GNUNET_TIME_absolute_get (); | 345 | start = GNUNET_TIME_absolute_get (); |
352 | t = GNUNET_SCHEDULER_add_now (&publish_record, | 346 | t = GNUNET_SCHEDULER_add_now (&publish_record, |
353 | NULL); | 347 | NULL); |
diff --git a/src/namestore/test_namestore_api_lookup_nick.c b/src/namestore/test_namestore_api_lookup_nick.c index b3946de34..145a3e885 100644 --- a/src/namestore/test_namestore_api_lookup_nick.c +++ b/src/namestore/test_namestore_api_lookup_nick.c | |||
@@ -40,7 +40,7 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
40 | 40 | ||
41 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 41 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
42 | 42 | ||
43 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 43 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
44 | 44 | ||
45 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 45 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
46 | 46 | ||
@@ -63,11 +63,6 @@ cleanup () | |||
63 | GNUNET_NAMESTORE_disconnect (nsh); | 63 | GNUNET_NAMESTORE_disconnect (nsh); |
64 | nsh = NULL; | 64 | nsh = NULL; |
65 | } | 65 | } |
66 | if (NULL != privkey) | ||
67 | { | ||
68 | GNUNET_free (privkey); | ||
69 | privkey = NULL; | ||
70 | } | ||
71 | GNUNET_SCHEDULER_shutdown (); | 66 | GNUNET_SCHEDULER_shutdown (); |
72 | } | 67 | } |
73 | 68 | ||
@@ -111,7 +106,7 @@ lookup_it (void *cls, | |||
111 | int found_record = GNUNET_NO; | 106 | int found_record = GNUNET_NO; |
112 | int found_nick = GNUNET_NO; | 107 | int found_nick = GNUNET_NO; |
113 | 108 | ||
114 | if (0 != GNUNET_memcmp (privkey, zone)) | 109 | if (0 != GNUNET_memcmp (&privkey, zone)) |
115 | { | 110 | { |
116 | GNUNET_break (0); | 111 | GNUNET_break (0); |
117 | GNUNET_SCHEDULER_cancel (endbadly_task); | 112 | GNUNET_SCHEDULER_cancel (endbadly_task); |
@@ -247,7 +242,7 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
247 | } | 242 | } |
248 | /* Lookup */ | 243 | /* Lookup */ |
249 | nsqe = GNUNET_NAMESTORE_records_lookup (nsh, | 244 | nsqe = GNUNET_NAMESTORE_records_lookup (nsh, |
250 | privkey, | 245 | &privkey, |
251 | name, | 246 | name, |
252 | &fail_cb, | 247 | &fail_cb, |
253 | NULL, | 248 | NULL, |
@@ -272,8 +267,11 @@ nick_cont (void *cls, int32_t success, const char *emsg) | |||
272 | rd_orig.flags = 0; | 267 | rd_orig.flags = 0; |
273 | memset ((char *) rd_orig.data, 'a', TEST_RECORD_DATALEN); | 268 | memset ((char *) rd_orig.data, 'a', TEST_RECORD_DATALEN); |
274 | 269 | ||
275 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, | 270 | nsqe = GNUNET_NAMESTORE_records_store (nsh, &privkey, |
276 | 1, &rd_orig, &put_cont, (void *) name); | 271 | name, |
272 | 1, | ||
273 | &rd_orig, | ||
274 | &put_cont, (void *) name); | ||
277 | } | 275 | } |
278 | 276 | ||
279 | 277 | ||
@@ -285,16 +283,15 @@ run (void *cls, | |||
285 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 283 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
286 | &endbadly, | 284 | &endbadly, |
287 | NULL); | 285 | NULL); |
288 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 286 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); |
289 | GNUNET_assert (privkey != NULL); | 287 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, |
290 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, | ||
291 | &pubkey); | 288 | &pubkey); |
292 | 289 | ||
293 | nsh = GNUNET_NAMESTORE_connect (cfg); | 290 | nsh = GNUNET_NAMESTORE_connect (cfg); |
294 | GNUNET_break (NULL != nsh); | 291 | GNUNET_break (NULL != nsh); |
295 | 292 | ||
296 | nsqe = GNUNET_NAMESTORE_set_nick (nsh, | 293 | nsqe = GNUNET_NAMESTORE_set_nick (nsh, |
297 | privkey, | 294 | &privkey, |
298 | TEST_NICK, | 295 | TEST_NICK, |
299 | &nick_cont, | 296 | &nick_cont, |
300 | (void *) name); | 297 | (void *) name); |
diff --git a/src/namestore/test_namestore_api_lookup_private.c b/src/namestore/test_namestore_api_lookup_private.c index e2600855c..98fdb1b43 100644 --- a/src/namestore/test_namestore_api_lookup_private.c +++ b/src/namestore/test_namestore_api_lookup_private.c | |||
@@ -38,7 +38,7 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
38 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
40 | 40 | ||
41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
42 | 42 | ||
43 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 43 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
44 | 44 | ||
@@ -58,11 +58,6 @@ cleanup () | |||
58 | GNUNET_NAMESTORE_disconnect (nsh); | 58 | GNUNET_NAMESTORE_disconnect (nsh); |
59 | nsh = NULL; | 59 | nsh = NULL; |
60 | } | 60 | } |
61 | if (NULL != privkey) | ||
62 | { | ||
63 | GNUNET_free (privkey); | ||
64 | privkey = NULL; | ||
65 | } | ||
66 | GNUNET_SCHEDULER_shutdown (); | 61 | GNUNET_SCHEDULER_shutdown (); |
67 | } | 62 | } |
68 | 63 | ||
@@ -103,7 +98,7 @@ lookup_it (void *cls, | |||
103 | { | 98 | { |
104 | nsqe = NULL; | 99 | nsqe = NULL; |
105 | 100 | ||
106 | if (0 != GNUNET_memcmp (privkey, | 101 | if (0 != GNUNET_memcmp (&privkey, |
107 | zone)) | 102 | zone)) |
108 | { | 103 | { |
109 | GNUNET_break (0); | 104 | GNUNET_break (0); |
@@ -173,7 +168,7 @@ put_cont (void *cls, | |||
173 | } | 168 | } |
174 | /* Lookup */ | 169 | /* Lookup */ |
175 | nsqe = GNUNET_NAMESTORE_records_lookup (nsh, | 170 | nsqe = GNUNET_NAMESTORE_records_lookup (nsh, |
176 | privkey, | 171 | &privkey, |
177 | name, | 172 | name, |
178 | &fail_cb, | 173 | &fail_cb, |
179 | NULL, | 174 | NULL, |
@@ -192,9 +187,8 @@ run (void *cls, | |||
192 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 187 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
193 | &endbadly, | 188 | &endbadly, |
194 | NULL); | 189 | NULL); |
195 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 190 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); |
196 | GNUNET_assert (privkey != NULL); | 191 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, &pubkey); |
197 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | ||
198 | 192 | ||
199 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; | 193 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; |
200 | rd.record_type = TEST_RECORD_TYPE; | 194 | rd.record_type = TEST_RECORD_TYPE; |
@@ -206,7 +200,7 @@ run (void *cls, | |||
206 | nsh = GNUNET_NAMESTORE_connect (cfg); | 200 | nsh = GNUNET_NAMESTORE_connect (cfg); |
207 | GNUNET_break (NULL != nsh); | 201 | GNUNET_break (NULL != nsh); |
208 | nsqe = GNUNET_NAMESTORE_records_store (nsh, | 202 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
209 | privkey, | 203 | &privkey, |
210 | name, | 204 | name, |
211 | 1, | 205 | 1, |
212 | &rd, | 206 | &rd, |
diff --git a/src/namestore/test_namestore_api_lookup_public.c b/src/namestore/test_namestore_api_lookup_public.c index 6640f47ed..83a5a78f6 100644 --- a/src/namestore/test_namestore_api_lookup_public.c +++ b/src/namestore/test_namestore_api_lookup_public.c | |||
@@ -42,7 +42,7 @@ static struct GNUNET_NAMECACHE_Handle *nch; | |||
42 | 42 | ||
43 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 43 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
44 | 44 | ||
45 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 45 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
46 | 46 | ||
47 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 47 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
48 | 48 | ||
@@ -66,11 +66,6 @@ cleanup () | |||
66 | GNUNET_NAMECACHE_disconnect (nch); | 66 | GNUNET_NAMECACHE_disconnect (nch); |
67 | nch = NULL; | 67 | nch = NULL; |
68 | } | 68 | } |
69 | if (NULL != privkey) | ||
70 | { | ||
71 | GNUNET_free (privkey); | ||
72 | privkey = NULL; | ||
73 | } | ||
74 | GNUNET_SCHEDULER_shutdown (); | 69 | GNUNET_SCHEDULER_shutdown (); |
75 | } | 70 | } |
76 | 71 | ||
@@ -178,7 +173,8 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
178 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 173 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
179 | 174 | ||
180 | /* Create derived hash */ | 175 | /* Create derived hash */ |
181 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | 176 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, |
177 | &pubkey); | ||
182 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &derived_hash); | 178 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &derived_hash); |
183 | 179 | ||
184 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, | 180 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, |
@@ -197,9 +193,8 @@ run (void *cls, | |||
197 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 193 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
198 | &endbadly, | 194 | &endbadly, |
199 | NULL); | 195 | NULL); |
200 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 196 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); |
201 | GNUNET_assert (privkey != NULL); | 197 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, |
202 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, | ||
203 | &pubkey); | 198 | &pubkey); |
204 | 199 | ||
205 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; | 200 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; |
@@ -213,8 +208,13 @@ run (void *cls, | |||
213 | nch = GNUNET_NAMECACHE_connect (cfg); | 208 | nch = GNUNET_NAMECACHE_connect (cfg); |
214 | GNUNET_break (NULL != nsh); | 209 | GNUNET_break (NULL != nsh); |
215 | GNUNET_break (NULL != nch); | 210 | GNUNET_break (NULL != nch); |
216 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, | 211 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
217 | 1, &rd, &put_cont, (void *) name); | 212 | &privkey, |
213 | name, | ||
214 | 1, | ||
215 | &rd, | ||
216 | &put_cont, | ||
217 | (void *) name); | ||
218 | if (NULL == nsqe) | 218 | if (NULL == nsqe) |
219 | { | 219 | { |
220 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 220 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
diff --git a/src/namestore/test_namestore_api_lookup_shadow.c b/src/namestore/test_namestore_api_lookup_shadow.c index 7daa6987c..08c428731 100644 --- a/src/namestore/test_namestore_api_lookup_shadow.c +++ b/src/namestore/test_namestore_api_lookup_shadow.c | |||
@@ -44,7 +44,7 @@ static struct GNUNET_NAMECACHE_Handle *nch; | |||
44 | 44 | ||
45 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 45 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
46 | 46 | ||
47 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 47 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
48 | 48 | ||
49 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 49 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
50 | 50 | ||
@@ -68,11 +68,6 @@ cleanup () | |||
68 | GNUNET_NAMECACHE_disconnect (nch); | 68 | GNUNET_NAMECACHE_disconnect (nch); |
69 | nch = NULL; | 69 | nch = NULL; |
70 | } | 70 | } |
71 | if (NULL != privkey) | ||
72 | { | ||
73 | GNUNET_free (privkey); | ||
74 | privkey = NULL; | ||
75 | } | ||
76 | GNUNET_SCHEDULER_shutdown (); | 71 | GNUNET_SCHEDULER_shutdown (); |
77 | } | 72 | } |
78 | 73 | ||
@@ -210,10 +205,14 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
210 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 205 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
211 | 206 | ||
212 | /* Create derived hash */ | 207 | /* Create derived hash */ |
213 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | 208 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, |
214 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &derived_hash); | 209 | &pubkey); |
210 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, | ||
211 | name, | ||
212 | &derived_hash); | ||
215 | 213 | ||
216 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, | 214 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, |
215 | &derived_hash, | ||
217 | &name_lookup_proc, (void *) name); | 216 | &name_lookup_proc, (void *) name); |
218 | } | 217 | } |
219 | 218 | ||
@@ -229,9 +228,8 @@ run (void *cls, | |||
229 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 228 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
230 | &endbadly, | 229 | &endbadly, |
231 | NULL); | 230 | NULL); |
232 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 231 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); |
233 | GNUNET_assert (privkey != NULL); | 232 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, |
234 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, | ||
235 | &pubkey); | 233 | &pubkey); |
236 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; | 234 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; |
237 | rd.record_type = TEST_RECORD_TYPE; | 235 | rd.record_type = TEST_RECORD_TYPE; |
@@ -245,7 +243,7 @@ run (void *cls, | |||
245 | GNUNET_break (NULL != nsh); | 243 | GNUNET_break (NULL != nsh); |
246 | GNUNET_break (NULL != nch); | 244 | GNUNET_break (NULL != nch); |
247 | nsqe = GNUNET_NAMESTORE_records_store (nsh, | 245 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
248 | privkey, | 246 | &privkey, |
249 | name, | 247 | name, |
250 | 1, | 248 | 1, |
251 | &rd, | 249 | &rd, |
diff --git a/src/namestore/test_namestore_api_lookup_shadow_filter.c b/src/namestore/test_namestore_api_lookup_shadow_filter.c index 694c189e1..634a6a3c4 100644 --- a/src/namestore/test_namestore_api_lookup_shadow_filter.c +++ b/src/namestore/test_namestore_api_lookup_shadow_filter.c | |||
@@ -48,7 +48,7 @@ static struct GNUNET_SCHEDULER_Task *endbadly_task; | |||
48 | 48 | ||
49 | static struct GNUNET_SCHEDULER_Task *delayed_lookup_task; | 49 | static struct GNUNET_SCHEDULER_Task *delayed_lookup_task; |
50 | 50 | ||
51 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 51 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
52 | 52 | ||
53 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 53 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
54 | 54 | ||
@@ -82,11 +82,6 @@ cleanup () | |||
82 | GNUNET_NAMECACHE_disconnect (nch); | 82 | GNUNET_NAMECACHE_disconnect (nch); |
83 | nch = NULL; | 83 | nch = NULL; |
84 | } | 84 | } |
85 | if (NULL != privkey) | ||
86 | { | ||
87 | GNUNET_free (privkey); | ||
88 | privkey = NULL; | ||
89 | } | ||
90 | GNUNET_SCHEDULER_shutdown (); | 85 | GNUNET_SCHEDULER_shutdown (); |
91 | } | 86 | } |
92 | 87 | ||
@@ -272,7 +267,8 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
272 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 267 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
273 | 268 | ||
274 | /* Create derived hash */ | 269 | /* Create derived hash */ |
275 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | 270 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, |
271 | &pubkey); | ||
276 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, TEST_NAME, &derived_hash); | 272 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, TEST_NAME, &derived_hash); |
277 | 273 | ||
278 | if (0 == GNUNET_TIME_absolute_get_remaining (record_expiration).rel_value_us) | 274 | if (0 == GNUNET_TIME_absolute_get_remaining (record_expiration).rel_value_us) |
@@ -301,9 +297,8 @@ run (void *cls, | |||
301 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 297 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
302 | &endbadly, | 298 | &endbadly, |
303 | NULL); | 299 | NULL); |
304 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 300 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); |
305 | GNUNET_assert (privkey != NULL); | 301 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, |
306 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, | ||
307 | &pubkey); | 302 | &pubkey); |
308 | 303 | ||
309 | record_expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), | 304 | record_expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), |
@@ -328,8 +323,13 @@ run (void *cls, | |||
328 | nch = GNUNET_NAMECACHE_connect (cfg); | 323 | nch = GNUNET_NAMECACHE_connect (cfg); |
329 | GNUNET_break (NULL != nsh); | 324 | GNUNET_break (NULL != nsh); |
330 | GNUNET_break (NULL != nch); | 325 | GNUNET_break (NULL != nch); |
331 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, TEST_NAME, | 326 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
332 | 2, records, &put_cont, NULL); | 327 | &privkey, |
328 | TEST_NAME, | ||
329 | 2, | ||
330 | records, | ||
331 | &put_cont, | ||
332 | NULL); | ||
333 | if (NULL == nsqe) | 333 | if (NULL == nsqe) |
334 | { | 334 | { |
335 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 335 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
diff --git a/src/namestore/test_namestore_api_monitoring.c b/src/namestore/test_namestore_api_monitoring.c index a23424d30..d26492517 100644 --- a/src/namestore/test_namestore_api_monitoring.c +++ b/src/namestore/test_namestore_api_monitoring.c | |||
@@ -37,9 +37,9 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
37 | 37 | ||
38 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 38 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
39 | 39 | ||
40 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 40 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
41 | 41 | ||
42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey2; | 42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey2; |
43 | 43 | ||
44 | static struct GNUNET_NAMESTORE_ZoneMonitor *zm; | 44 | static struct GNUNET_NAMESTORE_ZoneMonitor *zm; |
45 | 45 | ||
@@ -107,17 +107,6 @@ do_shutdown () | |||
107 | GNUNET_free ((void *) s_rd_3->data); | 107 | GNUNET_free ((void *) s_rd_3->data); |
108 | GNUNET_free (s_rd_3); | 108 | GNUNET_free (s_rd_3); |
109 | } | 109 | } |
110 | |||
111 | if (NULL != privkey) | ||
112 | { | ||
113 | GNUNET_free (privkey); | ||
114 | privkey = NULL; | ||
115 | } | ||
116 | if (NULL != privkey2) | ||
117 | { | ||
118 | GNUNET_free (privkey2); | ||
119 | privkey2 = NULL; | ||
120 | } | ||
121 | } | 110 | } |
122 | 111 | ||
123 | 112 | ||
@@ -156,7 +145,7 @@ zone_proc (void *cls, | |||
156 | "Comparing results name %s\n", | 145 | "Comparing results name %s\n", |
157 | name); | 146 | name); |
158 | if (0 != GNUNET_memcmp (zone_key, | 147 | if (0 != GNUNET_memcmp (zone_key, |
159 | privkey)) | 148 | &privkey)) |
160 | { | 149 | { |
161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
162 | "Monitoring returned wrong zone key\n"); | 151 | "Monitoring returned wrong zone key\n"); |
@@ -284,12 +273,10 @@ run (void *cls, | |||
284 | struct GNUNET_TESTING_Peer *peer) | 273 | struct GNUNET_TESTING_Peer *peer) |
285 | { | 274 | { |
286 | res = 1; | 275 | res = 1; |
287 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 276 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); |
288 | GNUNET_assert (privkey != NULL); | ||
289 | |||
290 | /* Start monitoring */ | 277 | /* Start monitoring */ |
291 | zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, | 278 | zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, |
292 | privkey, | 279 | &privkey, |
293 | GNUNET_YES, | 280 | GNUNET_YES, |
294 | &fail_cb, | 281 | &fail_cb, |
295 | NULL, | 282 | NULL, |
@@ -317,9 +304,7 @@ run (void *cls, | |||
317 | return; | 304 | return; |
318 | } | 305 | } |
319 | 306 | ||
320 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); | 307 | GNUNET_CRYPTO_ecdsa_key_create (&privkey2); |
321 | GNUNET_assert (privkey2 != NULL); | ||
322 | |||
323 | 308 | ||
324 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 309 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
325 | "Created record 3\n"); | 310 | "Created record 3\n"); |
@@ -328,7 +313,7 @@ run (void *cls, | |||
328 | s_rd_3 = create_record (1); | 313 | s_rd_3 = create_record (1); |
329 | GNUNET_assert (NULL != (ns_ops[2] = | 314 | GNUNET_assert (NULL != (ns_ops[2] = |
330 | GNUNET_NAMESTORE_records_store (nsh, | 315 | GNUNET_NAMESTORE_records_store (nsh, |
331 | privkey2, | 316 | &privkey2, |
332 | s_name_3, | 317 | s_name_3, |
333 | 1, | 318 | 1, |
334 | s_rd_3, | 319 | s_rd_3, |
@@ -340,7 +325,7 @@ run (void *cls, | |||
340 | s_rd_1 = create_record (1); | 325 | s_rd_1 = create_record (1); |
341 | GNUNET_assert (NULL != (ns_ops[0] = | 326 | GNUNET_assert (NULL != (ns_ops[0] = |
342 | GNUNET_NAMESTORE_records_store (nsh, | 327 | GNUNET_NAMESTORE_records_store (nsh, |
343 | privkey, | 328 | &privkey, |
344 | s_name_1, | 329 | s_name_1, |
345 | 1, | 330 | 1, |
346 | s_rd_1, | 331 | s_rd_1, |
@@ -353,7 +338,7 @@ run (void *cls, | |||
353 | s_rd_2 = create_record (1); | 338 | s_rd_2 = create_record (1); |
354 | GNUNET_assert (NULL != (ns_ops[1] = | 339 | GNUNET_assert (NULL != (ns_ops[1] = |
355 | GNUNET_NAMESTORE_records_store (nsh, | 340 | GNUNET_NAMESTORE_records_store (nsh, |
356 | privkey, | 341 | &privkey, |
357 | s_name_2, | 342 | s_name_2, |
358 | 1, | 343 | 1, |
359 | s_rd_2, | 344 | s_rd_2, |
diff --git a/src/namestore/test_namestore_api_monitoring_existing.c b/src/namestore/test_namestore_api_monitoring_existing.c index a0951b943..040a63f91 100644 --- a/src/namestore/test_namestore_api_monitoring_existing.c +++ b/src/namestore/test_namestore_api_monitoring_existing.c | |||
@@ -38,9 +38,9 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
38 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
40 | 40 | ||
41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
42 | 42 | ||
43 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey2; | 43 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey2; |
44 | 44 | ||
45 | static struct GNUNET_NAMESTORE_ZoneMonitor *zm; | 45 | static struct GNUNET_NAMESTORE_ZoneMonitor *zm; |
46 | 46 | ||
@@ -124,16 +124,6 @@ end (void *cls) | |||
124 | GNUNET_free ((void *) s_rd_3->data); | 124 | GNUNET_free ((void *) s_rd_3->data); |
125 | GNUNET_free (s_rd_3); | 125 | GNUNET_free (s_rd_3); |
126 | } | 126 | } |
127 | if (NULL != privkey) | ||
128 | { | ||
129 | GNUNET_free (privkey); | ||
130 | privkey = NULL; | ||
131 | } | ||
132 | if (NULL != privkey2) | ||
133 | { | ||
134 | GNUNET_free (privkey2); | ||
135 | privkey2 = NULL; | ||
136 | } | ||
137 | } | 127 | } |
138 | 128 | ||
139 | 129 | ||
@@ -151,7 +141,7 @@ zone_proc (void *cls, | |||
151 | "Comparing results name %s\n", | 141 | "Comparing results name %s\n", |
152 | name); | 142 | name); |
153 | if (0 != GNUNET_memcmp (zone_key, | 143 | if (0 != GNUNET_memcmp (zone_key, |
154 | privkey)) | 144 | &privkey)) |
155 | { | 145 | { |
156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 146 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
157 | "Monitoring returned wrong zone key\n"); | 147 | "Monitoring returned wrong zone key\n"); |
@@ -262,7 +252,7 @@ put_cont (void *cls, | |||
262 | { | 252 | { |
263 | /* Start monitoring */ | 253 | /* Start monitoring */ |
264 | zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, | 254 | zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, |
265 | privkey, | 255 | &privkey, |
266 | GNUNET_YES, | 256 | GNUNET_YES, |
267 | &fail_cb, | 257 | &fail_cb, |
268 | NULL, | 258 | NULL, |
@@ -312,10 +302,8 @@ run (void *cls, | |||
312 | struct GNUNET_TESTING_Peer *peer) | 302 | struct GNUNET_TESTING_Peer *peer) |
313 | { | 303 | { |
314 | res = 1; | 304 | res = 1; |
315 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 305 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); |
316 | GNUNET_assert (NULL != privkey); | 306 | GNUNET_CRYPTO_ecdsa_key_create (&privkey2); |
317 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); | ||
318 | GNUNET_assert (NULL != privkey2); | ||
319 | 307 | ||
320 | cfg = mycfg; | 308 | cfg = mycfg; |
321 | GNUNET_SCHEDULER_add_shutdown (&end, | 309 | GNUNET_SCHEDULER_add_shutdown (&end, |
@@ -342,7 +330,7 @@ run (void *cls, | |||
342 | s_rd_3 = create_record (1); | 330 | s_rd_3 = create_record (1); |
343 | GNUNET_assert (NULL != (ns_ops[2] = | 331 | GNUNET_assert (NULL != (ns_ops[2] = |
344 | GNUNET_NAMESTORE_records_store (nsh, | 332 | GNUNET_NAMESTORE_records_store (nsh, |
345 | privkey2, | 333 | &privkey2, |
346 | s_name_3, | 334 | s_name_3, |
347 | 1, | 335 | 1, |
348 | s_rd_3, | 336 | s_rd_3, |
@@ -355,7 +343,7 @@ run (void *cls, | |||
355 | s_rd_1 = create_record (1); | 343 | s_rd_1 = create_record (1); |
356 | GNUNET_assert (NULL != (ns_ops[0] = | 344 | GNUNET_assert (NULL != (ns_ops[0] = |
357 | GNUNET_NAMESTORE_records_store (nsh, | 345 | GNUNET_NAMESTORE_records_store (nsh, |
358 | privkey, | 346 | &privkey, |
359 | s_name_1, | 347 | s_name_1, |
360 | 1, | 348 | 1, |
361 | s_rd_1, | 349 | s_rd_1, |
@@ -367,7 +355,7 @@ run (void *cls, | |||
367 | s_rd_2 = create_record (1); | 355 | s_rd_2 = create_record (1); |
368 | GNUNET_assert (NULL != (ns_ops[1] = | 356 | GNUNET_assert (NULL != (ns_ops[1] = |
369 | GNUNET_NAMESTORE_records_store (nsh, | 357 | GNUNET_NAMESTORE_records_store (nsh, |
370 | privkey, | 358 | &privkey, |
371 | s_name_2, | 359 | s_name_2, |
372 | 1, | 360 | 1, |
373 | s_rd_2, | 361 | s_rd_2, |
diff --git a/src/namestore/test_namestore_api_remove.c b/src/namestore/test_namestore_api_remove.c index ff826804e..3f0c4c123 100644 --- a/src/namestore/test_namestore_api_remove.c +++ b/src/namestore/test_namestore_api_remove.c | |||
@@ -39,7 +39,7 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
39 | 39 | ||
40 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 40 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
41 | 41 | ||
42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
43 | 43 | ||
44 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 44 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
45 | 45 | ||
@@ -58,11 +58,6 @@ cleanup () | |||
58 | GNUNET_NAMESTORE_disconnect (nsh); | 58 | GNUNET_NAMESTORE_disconnect (nsh); |
59 | nsh = NULL; | 59 | nsh = NULL; |
60 | } | 60 | } |
61 | if (NULL != privkey) | ||
62 | { | ||
63 | GNUNET_free (privkey); | ||
64 | privkey = NULL; | ||
65 | } | ||
66 | GNUNET_SCHEDULER_shutdown (); | 61 | GNUNET_SCHEDULER_shutdown (); |
67 | } | 62 | } |
68 | 63 | ||
@@ -145,7 +140,7 @@ put_cont (void *cls, | |||
145 | name, | 140 | name, |
146 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 141 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
147 | nsqe = GNUNET_NAMESTORE_records_store (nsh, | 142 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
148 | privkey, | 143 | &privkey, |
149 | name, | 144 | name, |
150 | 0, NULL, | 145 | 0, NULL, |
151 | &remove_cont, (void *) name); | 146 | &remove_cont, (void *) name); |
@@ -163,9 +158,8 @@ run (void *cls, | |||
163 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 158 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
164 | &endbadly, | 159 | &endbadly, |
165 | NULL); | 160 | NULL); |
166 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 161 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); |
167 | GNUNET_assert (privkey != NULL); | 162 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, |
168 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, | ||
169 | &pubkey); | 163 | &pubkey); |
170 | 164 | ||
171 | removed = GNUNET_NO; | 165 | removed = GNUNET_NO; |
@@ -182,7 +176,7 @@ run (void *cls, | |||
182 | nsh = GNUNET_NAMESTORE_connect (cfg); | 176 | nsh = GNUNET_NAMESTORE_connect (cfg); |
183 | GNUNET_break (NULL != nsh); | 177 | GNUNET_break (NULL != nsh); |
184 | nsqe = GNUNET_NAMESTORE_records_store (nsh, | 178 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
185 | privkey, | 179 | &privkey, |
186 | name, | 180 | name, |
187 | 1, | 181 | 1, |
188 | &rd, | 182 | &rd, |
diff --git a/src/namestore/test_namestore_api_remove_not_existing_record.c b/src/namestore/test_namestore_api_remove_not_existing_record.c index 217f8a51a..75e1cc3ed 100644 --- a/src/namestore/test_namestore_api_remove_not_existing_record.c +++ b/src/namestore/test_namestore_api_remove_not_existing_record.c | |||
@@ -38,7 +38,7 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
38 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
40 | 40 | ||
41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
42 | 42 | ||
43 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 43 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
44 | 44 | ||
@@ -48,18 +48,13 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | |||
48 | 48 | ||
49 | 49 | ||
50 | static void | 50 | static void |
51 | cleanup () | 51 | cleanup (void) |
52 | { | 52 | { |
53 | if (NULL != nsh) | 53 | if (NULL != nsh) |
54 | { | 54 | { |
55 | GNUNET_NAMESTORE_disconnect (nsh); | 55 | GNUNET_NAMESTORE_disconnect (nsh); |
56 | nsh = NULL; | 56 | nsh = NULL; |
57 | } | 57 | } |
58 | if (NULL != privkey) | ||
59 | { | ||
60 | GNUNET_free (privkey); | ||
61 | privkey = NULL; | ||
62 | } | ||
63 | GNUNET_SCHEDULER_shutdown (); | 58 | GNUNET_SCHEDULER_shutdown (); |
64 | } | 59 | } |
65 | 60 | ||
@@ -137,13 +132,14 @@ run (void *cls, | |||
137 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 132 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
138 | &endbadly, | 133 | &endbadly, |
139 | NULL); | 134 | NULL); |
140 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 135 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); |
141 | GNUNET_assert (privkey != NULL); | 136 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, &pubkey); |
142 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | ||
143 | 137 | ||
144 | nsh = GNUNET_NAMESTORE_connect (cfg); | 138 | nsh = GNUNET_NAMESTORE_connect (cfg); |
145 | GNUNET_break (NULL != nsh); | 139 | GNUNET_break (NULL != nsh); |
146 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, | 140 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
141 | &privkey, | ||
142 | name, | ||
147 | 0, NULL, | 143 | 0, NULL, |
148 | &put_cont, (void *) name); | 144 | &put_cont, (void *) name); |
149 | if (NULL == nsqe) | 145 | if (NULL == nsqe) |
diff --git a/src/namestore/test_namestore_api_store.c b/src/namestore/test_namestore_api_store.c index 5bd0c3472..ab211aeae 100644 --- a/src/namestore/test_namestore_api_store.c +++ b/src/namestore/test_namestore_api_store.c | |||
@@ -39,7 +39,7 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
39 | 39 | ||
40 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 40 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
41 | 41 | ||
42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
43 | 43 | ||
44 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 44 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
45 | 45 | ||
@@ -56,11 +56,6 @@ cleanup () | |||
56 | GNUNET_NAMESTORE_disconnect (nsh); | 56 | GNUNET_NAMESTORE_disconnect (nsh); |
57 | nsh = NULL; | 57 | nsh = NULL; |
58 | } | 58 | } |
59 | if (NULL != privkey) | ||
60 | { | ||
61 | GNUNET_free (privkey); | ||
62 | privkey = NULL; | ||
63 | } | ||
64 | GNUNET_SCHEDULER_shutdown (); | 59 | GNUNET_SCHEDULER_shutdown (); |
65 | } | 60 | } |
66 | 61 | ||
@@ -118,9 +113,8 @@ run (void *cls, | |||
118 | 113 | ||
119 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 114 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
120 | &endbadly, NULL); | 115 | &endbadly, NULL); |
121 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 116 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); |
122 | GNUNET_assert (privkey != NULL); | 117 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, &pubkey); |
123 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | ||
124 | 118 | ||
125 | 119 | ||
126 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; | 120 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; |
@@ -133,7 +127,7 @@ run (void *cls, | |||
133 | nsh = GNUNET_NAMESTORE_connect (cfg); | 127 | nsh = GNUNET_NAMESTORE_connect (cfg); |
134 | GNUNET_break (NULL != nsh); | 128 | GNUNET_break (NULL != nsh); |
135 | nsqe = GNUNET_NAMESTORE_records_store (nsh, | 129 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
136 | privkey, | 130 | &privkey, |
137 | name, | 131 | name, |
138 | 1, | 132 | 1, |
139 | &rd, | 133 | &rd, |
diff --git a/src/namestore/test_namestore_api_store_update.c b/src/namestore/test_namestore_api_store_update.c index b0244453a..65dbdbd8c 100644 --- a/src/namestore/test_namestore_api_store_update.c +++ b/src/namestore/test_namestore_api_store_update.c | |||
@@ -48,7 +48,7 @@ static struct GNUNET_NAMECACHE_Handle *nch; | |||
48 | 48 | ||
49 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 49 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
50 | 50 | ||
51 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 51 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
52 | 52 | ||
53 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 53 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
54 | 54 | ||
@@ -106,11 +106,6 @@ end (void *cls) | |||
106 | GNUNET_NAMECACHE_disconnect (nch); | 106 | GNUNET_NAMECACHE_disconnect (nch); |
107 | nch = NULL; | 107 | nch = NULL; |
108 | } | 108 | } |
109 | if (NULL != privkey) | ||
110 | { | ||
111 | GNUNET_free (privkey); | ||
112 | privkey = NULL; | ||
113 | } | ||
114 | } | 109 | } |
115 | 110 | ||
116 | 111 | ||
@@ -157,7 +152,7 @@ rd_decrypt_cb (void *cls, | |||
157 | TEST_RECORD_DATALEN2); | 152 | TEST_RECORD_DATALEN2); |
158 | 153 | ||
159 | nsqe = GNUNET_NAMESTORE_records_store (nsh, | 154 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
160 | privkey, | 155 | &privkey, |
161 | name, | 156 | name, |
162 | 1, | 157 | 1, |
163 | &rd_new, | 158 | &rd_new, |
@@ -226,7 +221,7 @@ put_cont (void *cls, | |||
226 | name, | 221 | name, |
227 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 222 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
228 | /* Create derived hash */ | 223 | /* Create derived hash */ |
229 | GNUNET_GNSRECORD_query_from_private_key (privkey, | 224 | GNUNET_GNSRECORD_query_from_private_key (&privkey, |
230 | name, | 225 | name, |
231 | &derived_hash); | 226 | &derived_hash); |
232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 227 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -251,9 +246,8 @@ run (void *cls, | |||
251 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 246 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
252 | &endbadly, | 247 | &endbadly, |
253 | NULL); | 248 | NULL); |
254 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 249 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); |
255 | GNUNET_assert (privkey != NULL); | 250 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, |
256 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, | ||
257 | &pubkey); | 251 | &pubkey); |
258 | rd.flags = GNUNET_GNSRECORD_RF_NONE; | 252 | rd.flags = GNUNET_GNSRECORD_RF_NONE; |
259 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; | 253 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; |
@@ -269,7 +263,7 @@ run (void *cls, | |||
269 | nch = GNUNET_NAMECACHE_connect (cfg); | 263 | nch = GNUNET_NAMECACHE_connect (cfg); |
270 | GNUNET_break (NULL != nch); | 264 | GNUNET_break (NULL != nch); |
271 | nsqe = GNUNET_NAMESTORE_records_store (nsh, | 265 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
272 | privkey, | 266 | &privkey, |
273 | name, | 267 | name, |
274 | 1, | 268 | 1, |
275 | &rd, | 269 | &rd, |
diff --git a/src/namestore/test_namestore_api_zone_iteration_nick.c b/src/namestore/test_namestore_api_zone_iteration_nick.c index 35eab2735..f5ffe3899 100644 --- a/src/namestore/test_namestore_api_zone_iteration_nick.c +++ b/src/namestore/test_namestore_api_zone_iteration_nick.c | |||
@@ -37,9 +37,9 @@ | |||
37 | 37 | ||
38 | static struct GNUNET_NAMESTORE_Handle *nsh; | 38 | static struct GNUNET_NAMESTORE_Handle *nsh; |
39 | 39 | ||
40 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 40 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
41 | 41 | ||
42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey2; | 42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey2; |
43 | 43 | ||
44 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 44 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
45 | 45 | ||
@@ -100,17 +100,6 @@ end (void *cls) | |||
100 | GNUNET_free ((void *) s_rd_3->data); | 100 | GNUNET_free ((void *) s_rd_3->data); |
101 | GNUNET_free (s_rd_3); | 101 | GNUNET_free (s_rd_3); |
102 | } | 102 | } |
103 | |||
104 | if (privkey != NULL) | ||
105 | { | ||
106 | GNUNET_free (privkey); | ||
107 | privkey = NULL; | ||
108 | } | ||
109 | if (privkey2 != NULL) | ||
110 | { | ||
111 | GNUNET_free (privkey2); | ||
112 | privkey2 = NULL; | ||
113 | } | ||
114 | } | 103 | } |
115 | 104 | ||
116 | 105 | ||
@@ -171,13 +160,13 @@ zone_proc (void *cls, | |||
171 | int failed = GNUNET_NO; | 160 | int failed = GNUNET_NO; |
172 | 161 | ||
173 | GNUNET_assert (NULL != zone); | 162 | GNUNET_assert (NULL != zone); |
174 | if (0 == GNUNET_memcmp (zone, privkey)) | 163 | if (0 == GNUNET_memcmp (zone, &privkey)) |
175 | { | 164 | { |
176 | failed = check_zone_1 (label, rd_count, rd); | 165 | failed = check_zone_1 (label, rd_count, rd); |
177 | if (GNUNET_YES == failed) | 166 | if (GNUNET_YES == failed) |
178 | GNUNET_break (0); | 167 | GNUNET_break (0); |
179 | } | 168 | } |
180 | else if (0 == GNUNET_memcmp (zone, privkey2)) | 169 | else if (0 == GNUNET_memcmp (zone, &privkey2)) |
181 | { | 170 | { |
182 | failed = check_zone_2 (label, rd_count, rd); | 171 | failed = check_zone_2 (label, rd_count, rd); |
183 | if (GNUNET_YES == failed) | 172 | if (GNUNET_YES == failed) |
@@ -295,7 +284,7 @@ nick_2_cont (void *cls, | |||
295 | 284 | ||
296 | GNUNET_asprintf (&s_name_1, "dummy1"); | 285 | GNUNET_asprintf (&s_name_1, "dummy1"); |
297 | s_rd_1 = create_record (1); | 286 | s_rd_1 = create_record (1); |
298 | GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_1, | 287 | GNUNET_NAMESTORE_records_store (nsh, &privkey, s_name_1, |
299 | 1, s_rd_1, | 288 | 1, s_rd_1, |
300 | &put_cont, NULL); | 289 | &put_cont, NULL); |
301 | 290 | ||
@@ -303,7 +292,7 @@ nick_2_cont (void *cls, | |||
303 | "Created record 2 \n"); | 292 | "Created record 2 \n"); |
304 | GNUNET_asprintf (&s_name_2, "dummy2"); | 293 | GNUNET_asprintf (&s_name_2, "dummy2"); |
305 | s_rd_2 = create_record (1); | 294 | s_rd_2 = create_record (1); |
306 | GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_2, | 295 | GNUNET_NAMESTORE_records_store (nsh, &privkey, s_name_2, |
307 | 1, s_rd_2, &put_cont, NULL); | 296 | 1, s_rd_2, &put_cont, NULL); |
308 | 297 | ||
309 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 298 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -312,7 +301,7 @@ nick_2_cont (void *cls, | |||
312 | /* name in different zone */ | 301 | /* name in different zone */ |
313 | GNUNET_asprintf (&s_name_3, "dummy3"); | 302 | GNUNET_asprintf (&s_name_3, "dummy3"); |
314 | s_rd_3 = create_record (1); | 303 | s_rd_3 = create_record (1); |
315 | GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3, | 304 | GNUNET_NAMESTORE_records_store (nsh, &privkey2, s_name_3, |
316 | 1, s_rd_3, | 305 | 1, s_rd_3, |
317 | &put_cont, NULL); | 306 | &put_cont, NULL); |
318 | } | 307 | } |
@@ -325,7 +314,8 @@ nick_1_cont (void *cls, int32_t success, const char *emsg) | |||
325 | "Nick 1 added : %s\n", | 314 | "Nick 1 added : %s\n", |
326 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 315 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
327 | 316 | ||
328 | nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey2, ZONE_NICK_2, &nick_2_cont, | 317 | nsqe = GNUNET_NAMESTORE_set_nick (nsh, |
318 | &privkey2, ZONE_NICK_2, &nick_2_cont, | ||
329 | &privkey2); | 319 | &privkey2); |
330 | if (NULL == nsqe) | 320 | if (NULL == nsqe) |
331 | { | 321 | { |
@@ -374,16 +364,13 @@ empty_zone_end (void *cls) | |||
374 | { | 364 | { |
375 | GNUNET_assert (nsh == cls); | 365 | GNUNET_assert (nsh == cls); |
376 | zi = NULL; | 366 | zi = NULL; |
377 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 367 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); |
378 | GNUNET_assert (privkey != NULL); | 368 | GNUNET_CRYPTO_ecdsa_key_create (&privkey2); |
379 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); | ||
380 | GNUNET_assert (privkey2 != NULL); | ||
381 | |||
382 | nsqe = GNUNET_NAMESTORE_set_nick (nsh, | 369 | nsqe = GNUNET_NAMESTORE_set_nick (nsh, |
383 | privkey, | 370 | &privkey, |
384 | ZONE_NICK_1, | 371 | ZONE_NICK_1, |
385 | &nick_1_cont, | 372 | &nick_1_cont, |
386 | &privkey); | 373 | NULL); |
387 | if (NULL == nsqe) | 374 | if (NULL == nsqe) |
388 | { | 375 | { |
389 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 376 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
diff --git a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c index d37fb8cd3..97093cb71 100644 --- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c +++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c | |||
@@ -38,9 +38,9 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
38 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
40 | 40 | ||
41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
42 | 42 | ||
43 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey2; | 43 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey2; |
44 | 44 | ||
45 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 45 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
46 | 46 | ||
@@ -88,16 +88,6 @@ end (void *cls) | |||
88 | GNUNET_SCHEDULER_cancel (endbadly_task); | 88 | GNUNET_SCHEDULER_cancel (endbadly_task); |
89 | endbadly_task = NULL; | 89 | endbadly_task = NULL; |
90 | } | 90 | } |
91 | if (NULL != privkey) | ||
92 | { | ||
93 | GNUNET_free (privkey); | ||
94 | privkey = NULL; | ||
95 | } | ||
96 | if (NULL != privkey2) | ||
97 | { | ||
98 | GNUNET_free (privkey2); | ||
99 | privkey2 = NULL; | ||
100 | } | ||
101 | GNUNET_free_non_null (s_name_1); | 91 | GNUNET_free_non_null (s_name_1); |
102 | GNUNET_free_non_null (s_name_2); | 92 | GNUNET_free_non_null (s_name_2); |
103 | GNUNET_free_non_null (s_name_3); | 93 | GNUNET_free_non_null (s_name_3); |
@@ -143,7 +133,7 @@ zone_proc (void *cls, | |||
143 | 133 | ||
144 | GNUNET_assert (NULL != zone); | 134 | GNUNET_assert (NULL != zone); |
145 | if (0 == GNUNET_memcmp (zone, | 135 | if (0 == GNUNET_memcmp (zone, |
146 | privkey)) | 136 | &privkey)) |
147 | { | 137 | { |
148 | if (0 == strcmp (label, s_name_1)) | 138 | if (0 == strcmp (label, s_name_1)) |
149 | { | 139 | { |
@@ -188,7 +178,7 @@ zone_proc (void *cls, | |||
188 | GNUNET_break (0); | 178 | GNUNET_break (0); |
189 | } | 179 | } |
190 | } | 180 | } |
191 | else if (0 == GNUNET_memcmp (zone, privkey2)) | 181 | else if (0 == GNUNET_memcmp (zone, &privkey2)) |
192 | { | 182 | { |
193 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 183 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
194 | "Received data for not requested zone\n"); | 184 | "Received data for not requested zone\n"); |
@@ -271,7 +261,7 @@ put_cont (void *cls, | |||
271 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 261 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
272 | "All records created, starting iteration over all zones \n"); | 262 | "All records created, starting iteration over all zones \n"); |
273 | zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, | 263 | zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, |
274 | privkey, | 264 | &privkey, |
275 | &fail_cb, | 265 | &fail_cb, |
276 | NULL, | 266 | NULL, |
277 | &zone_proc, | 267 | &zone_proc, |
@@ -351,18 +341,15 @@ static void | |||
351 | empty_zone_proc_end (void *cls) | 341 | empty_zone_proc_end (void *cls) |
352 | { | 342 | { |
353 | zi = NULL; | 343 | zi = NULL; |
354 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 344 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); |
355 | GNUNET_assert (privkey != NULL); | 345 | GNUNET_CRYPTO_ecdsa_key_create (&privkey2); |
356 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); | ||
357 | GNUNET_assert (privkey2 != NULL); | ||
358 | |||
359 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 346 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
360 | "Created record 1\n"); | 347 | "Created record 1\n"); |
361 | GNUNET_asprintf (&s_name_1, | 348 | GNUNET_asprintf (&s_name_1, |
362 | "dummy1"); | 349 | "dummy1"); |
363 | s_rd_1 = create_record (1); | 350 | s_rd_1 = create_record (1); |
364 | GNUNET_NAMESTORE_records_store (nsh, | 351 | GNUNET_NAMESTORE_records_store (nsh, |
365 | privkey, | 352 | &privkey, |
366 | s_name_1, | 353 | s_name_1, |
367 | 1, | 354 | 1, |
368 | s_rd_1, | 355 | s_rd_1, |
@@ -375,7 +362,7 @@ empty_zone_proc_end (void *cls) | |||
375 | "dummy2"); | 362 | "dummy2"); |
376 | s_rd_2 = create_record (1); | 363 | s_rd_2 = create_record (1); |
377 | GNUNET_NAMESTORE_records_store (nsh, | 364 | GNUNET_NAMESTORE_records_store (nsh, |
378 | privkey, | 365 | &privkey, |
379 | s_name_2, | 366 | s_name_2, |
380 | 1, | 367 | 1, |
381 | s_rd_2, | 368 | s_rd_2, |
@@ -390,7 +377,7 @@ empty_zone_proc_end (void *cls) | |||
390 | "dummy3"); | 377 | "dummy3"); |
391 | s_rd_3 = create_record (1); | 378 | s_rd_3 = create_record (1); |
392 | GNUNET_NAMESTORE_records_store (nsh, | 379 | GNUNET_NAMESTORE_records_store (nsh, |
393 | privkey2, | 380 | &privkey2, |
394 | s_name_3, | 381 | s_name_3, |
395 | 1, s_rd_3, | 382 | 1, s_rd_3, |
396 | &put_cont, | 383 | &put_cont, |
diff --git a/src/namestore/test_namestore_api_zone_to_name.c b/src/namestore/test_namestore_api_zone_to_name.c index 65366e267..94cc5c285 100644 --- a/src/namestore/test_namestore_api_zone_to_name.c +++ b/src/namestore/test_namestore_api_zone_to_name.c | |||
@@ -42,7 +42,7 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
42 | 42 | ||
43 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 43 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
44 | 44 | ||
45 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 45 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
46 | 46 | ||
47 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 47 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
48 | 48 | ||
@@ -82,11 +82,6 @@ end (void *cls) | |||
82 | GNUNET_SCHEDULER_cancel (endbadly_task); | 82 | GNUNET_SCHEDULER_cancel (endbadly_task); |
83 | endbadly_task = NULL; | 83 | endbadly_task = NULL; |
84 | } | 84 | } |
85 | if (NULL != privkey) | ||
86 | { | ||
87 | GNUNET_free (privkey); | ||
88 | privkey = NULL; | ||
89 | } | ||
90 | if (NULL != nsh) | 85 | if (NULL != nsh) |
91 | { | 86 | { |
92 | GNUNET_NAMESTORE_disconnect (nsh); | 87 | GNUNET_NAMESTORE_disconnect (nsh); |
@@ -133,7 +128,7 @@ zone_to_name_proc (void *cls, | |||
133 | } | 128 | } |
134 | if ((NULL == zone_key) || | 129 | if ((NULL == zone_key) || |
135 | (0 != GNUNET_memcmp (zone_key, | 130 | (0 != GNUNET_memcmp (zone_key, |
136 | privkey))) | 131 | &privkey))) |
137 | { | 132 | { |
138 | fail = GNUNET_YES; | 133 | fail = GNUNET_YES; |
139 | GNUNET_break (0); | 134 | GNUNET_break (0); |
@@ -176,7 +171,7 @@ put_cont (void *cls, | |||
176 | res = 0; | 171 | res = 0; |
177 | 172 | ||
178 | qe = GNUNET_NAMESTORE_zone_to_name (nsh, | 173 | qe = GNUNET_NAMESTORE_zone_to_name (nsh, |
179 | privkey, | 174 | &privkey, |
180 | &s_zone_value, | 175 | &s_zone_value, |
181 | &error_cb, | 176 | &error_cb, |
182 | NULL, | 177 | NULL, |
@@ -208,10 +203,9 @@ run (void *cls, | |||
208 | GNUNET_SCHEDULER_add_shutdown (&end, | 203 | GNUNET_SCHEDULER_add_shutdown (&end, |
209 | NULL); | 204 | NULL); |
210 | GNUNET_asprintf (&s_name, "dummy"); | 205 | GNUNET_asprintf (&s_name, "dummy"); |
211 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 206 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); |
212 | GNUNET_assert (NULL != privkey); | ||
213 | /* get public key */ | 207 | /* get public key */ |
214 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, | 208 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, |
215 | &pubkey); | 209 | &pubkey); |
216 | 210 | ||
217 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, | 211 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, |
@@ -229,7 +223,7 @@ run (void *cls, | |||
229 | nsh = GNUNET_NAMESTORE_connect (cfg); | 223 | nsh = GNUNET_NAMESTORE_connect (cfg); |
230 | GNUNET_break (NULL != nsh); | 224 | GNUNET_break (NULL != nsh); |
231 | GNUNET_NAMESTORE_records_store (nsh, | 225 | GNUNET_NAMESTORE_records_store (nsh, |
232 | privkey, | 226 | &privkey, |
233 | s_name, | 227 | s_name, |
234 | 1, | 228 | 1, |
235 | &rd, | 229 | &rd, |
diff --git a/src/reclaim/oidc_helper.c b/src/reclaim/oidc_helper.c index dded06389..29e8cb2ef 100644 --- a/src/reclaim/oidc_helper.c +++ b/src/reclaim/oidc_helper.c | |||
@@ -449,7 +449,7 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, | |||
449 | uint32_t nonce; | 449 | uint32_t nonce; |
450 | uint32_t nonce_tmp; | 450 | uint32_t nonce_tmp; |
451 | struct GNUNET_CRYPTO_EccSignaturePurpose *purpose; | 451 | struct GNUNET_CRYPTO_EccSignaturePurpose *purpose; |
452 | struct GNUNET_CRYPTO_EcdhePrivateKey *ecdh_priv; | 452 | struct GNUNET_CRYPTO_EcdhePrivateKey ecdh_priv; |
453 | struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pub; | 453 | struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pub; |
454 | 454 | ||
455 | /** PLAINTEXT **/ | 455 | /** PLAINTEXT **/ |
@@ -531,8 +531,8 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, | |||
531 | code_payload_len); | 531 | code_payload_len); |
532 | 532 | ||
533 | // Generate ECDH key | 533 | // Generate ECDH key |
534 | ecdh_priv = GNUNET_CRYPTO_ecdhe_key_create (); | 534 | GNUNET_CRYPTO_ecdhe_key_create (&ecdh_priv); |
535 | GNUNET_CRYPTO_ecdhe_key_get_public (ecdh_priv, &ecdh_pub); | 535 | GNUNET_CRYPTO_ecdhe_key_get_public (&ecdh_priv, &ecdh_pub); |
536 | // Initialize code payload | 536 | // Initialize code payload |
537 | code_payload = GNUNET_malloc (code_payload_len); | 537 | code_payload = GNUNET_malloc (code_payload_len); |
538 | GNUNET_assert (NULL != code_payload); | 538 | GNUNET_assert (NULL != code_payload); |
@@ -545,8 +545,11 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, | |||
545 | memcpy (buf_ptr, &ecdh_pub, sizeof(ecdh_pub)); | 545 | memcpy (buf_ptr, &ecdh_pub, sizeof(ecdh_pub)); |
546 | buf_ptr += sizeof(ecdh_pub); | 546 | buf_ptr += sizeof(ecdh_pub); |
547 | // Encrypt plaintext and store | 547 | // Encrypt plaintext and store |
548 | encrypt_payload (&ticket->audience, ecdh_priv, payload, payload_len, buf_ptr); | 548 | encrypt_payload (&ticket->audience, |
549 | GNUNET_free (ecdh_priv); | 549 | &ecdh_priv, |
550 | payload, | ||
551 | payload_len, | ||
552 | buf_ptr); | ||
550 | GNUNET_free (payload); | 553 | GNUNET_free (payload); |
551 | buf_ptr += payload_len; | 554 | buf_ptr += payload_len; |
552 | // Sign and store signature | 555 | // Sign and store signature |
diff --git a/src/sq/sq_query_helper.c b/src/sq/sq_query_helper.c index c9e4bf031..1f7662b95 100644 --- a/src/sq/sq_query_helper.c +++ b/src/sq/sq_query_helper.c | |||
@@ -151,7 +151,7 @@ bind_rsa_pub (void *cls, | |||
151 | unsigned int off) | 151 | unsigned int off) |
152 | { | 152 | { |
153 | const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data; | 153 | const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data; |
154 | char *buf; | 154 | void *buf; |
155 | size_t buf_size; | 155 | size_t buf_size; |
156 | 156 | ||
157 | GNUNET_break (NULL == cls); | 157 | GNUNET_break (NULL == cls); |
@@ -211,7 +211,7 @@ bind_rsa_sig (void *cls, | |||
211 | unsigned int off) | 211 | unsigned int off) |
212 | { | 212 | { |
213 | const struct GNUNET_CRYPTO_RsaSignature *sig = data; | 213 | const struct GNUNET_CRYPTO_RsaSignature *sig = data; |
214 | char *buf; | 214 | void *buf; |
215 | size_t buf_size; | 215 | size_t buf_size; |
216 | 216 | ||
217 | GNUNET_break (NULL == cls); | 217 | GNUNET_break (NULL == cls); |
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c index 2786ba184..82ee309a5 100644 --- a/src/transport/gnunet-communicator-tcp.c +++ b/src/transport/gnunet-communicator-tcp.c | |||
@@ -1270,8 +1270,7 @@ inject_rekey (struct Queue *queue) | |||
1270 | 1270 | ||
1271 | GNUNET_assert (0 == queue->pwrite_off); | 1271 | GNUNET_assert (0 == queue->pwrite_off); |
1272 | memset (&rekey, 0, sizeof(rekey)); | 1272 | memset (&rekey, 0, sizeof(rekey)); |
1273 | GNUNET_assert (GNUNET_OK == | 1273 | GNUNET_CRYPTO_ecdhe_key_create (&queue->ephemeral); |
1274 | GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral)); | ||
1275 | rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY); | 1274 | rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY); |
1276 | rekey.header.size = ntohs (sizeof(rekey)); | 1275 | rekey.header.size = ntohs (sizeof(rekey)); |
1277 | GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &rekey.ephemeral); | 1276 | GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &rekey.ephemeral); |
@@ -1610,8 +1609,7 @@ start_initial_kx_out (struct Queue *queue) | |||
1610 | { | 1609 | { |
1611 | struct GNUNET_CRYPTO_EcdhePublicKey epub; | 1610 | struct GNUNET_CRYPTO_EcdhePublicKey epub; |
1612 | 1611 | ||
1613 | GNUNET_assert (GNUNET_OK == | 1612 | GNUNET_CRYPTO_ecdhe_key_create (&queue->ephemeral); |
1614 | GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral)); | ||
1615 | GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &epub); | 1613 | GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &epub); |
1616 | setup_out_cipher (queue); | 1614 | setup_out_cipher (queue); |
1617 | transmit_kx (queue, &epub); | 1615 | transmit_kx (queue, &epub); |
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c index 1542a7702..e0b14f669 100644 --- a/src/transport/gnunet-communicator-udp.c +++ b/src/transport/gnunet-communicator-udp.c | |||
@@ -1918,7 +1918,7 @@ mq_send (struct GNUNET_MQ_Handle *mq, | |||
1918 | struct SharedSecret *ss; | 1918 | struct SharedSecret *ss; |
1919 | 1919 | ||
1920 | /* setup key material */ | 1920 | /* setup key material */ |
1921 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdhe_key_create2 (&epriv)); | 1921 | GNUNET_CRYPTO_ecdhe_key_create (&epriv); |
1922 | 1922 | ||
1923 | ss = setup_shared_secret_enc (&epriv, receiver); | 1923 | ss = setup_shared_secret_enc (&epriv, receiver); |
1924 | setup_cipher (&ss->master, 0, &out_cipher); | 1924 | setup_cipher (&ss->master, 0, &out_cipher); |
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c index 75763fd9d..5f3178939 100644 --- a/src/transport/gnunet-service-tng.c +++ b/src/transport/gnunet-service-tng.c | |||
@@ -4130,8 +4130,7 @@ update_ephemeral (struct DistanceVector *dv) | |||
4130 | dv->monotime = GNUNET_TIME_absolute_get_monotonic (GST_cfg); | 4130 | dv->monotime = GNUNET_TIME_absolute_get_monotonic (GST_cfg); |
4131 | dv->ephemeral_validity = | 4131 | dv->ephemeral_validity = |
4132 | GNUNET_TIME_absolute_add (dv->monotime, EPHEMERAL_VALIDITY); | 4132 | GNUNET_TIME_absolute_add (dv->monotime, EPHEMERAL_VALIDITY); |
4133 | GNUNET_assert (GNUNET_OK == | 4133 | GNUNET_CRYPTO_ecdhe_key_create (&dv->private_key); |
4134 | GNUNET_CRYPTO_ecdhe_key_create2 (&dv->private_key)); | ||
4135 | GNUNET_CRYPTO_ecdhe_key_get_public (&dv->private_key, &dv->ephemeral_key); | 4134 | GNUNET_CRYPTO_ecdhe_key_get_public (&dv->private_key, &dv->ephemeral_key); |
4136 | ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); | 4135 | ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); |
4137 | ec.purpose.size = htonl (sizeof(ec)); | 4136 | ec.purpose.size = htonl (sizeof(ec)); |
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 927a8753c..93fa031f4 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -384,7 +384,7 @@ struct GNUNET_PEERINFO_Handle *GST_peerinfo; | |||
384 | /** | 384 | /** |
385 | * Our private key. | 385 | * Our private key. |
386 | */ | 386 | */ |
387 | struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key; | 387 | struct GNUNET_CRYPTO_EddsaPrivateKey GST_my_private_key; |
388 | 388 | ||
389 | /** | 389 | /** |
390 | * ATS scheduling handle. | 390 | * ATS scheduling handle. |
@@ -2183,11 +2183,6 @@ shutdown_task (void *cls) | |||
2183 | GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO); | 2183 | GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO); |
2184 | GST_stats = NULL; | 2184 | GST_stats = NULL; |
2185 | } | 2185 | } |
2186 | if (NULL != GST_my_private_key) | ||
2187 | { | ||
2188 | GNUNET_free (GST_my_private_key); | ||
2189 | GST_my_private_key = NULL; | ||
2190 | } | ||
2191 | } | 2186 | } |
2192 | 2187 | ||
2193 | 2188 | ||
@@ -2611,7 +2606,6 @@ run (void *cls, | |||
2611 | struct GNUNET_SERVICE_Handle *service) | 2606 | struct GNUNET_SERVICE_Handle *service) |
2612 | { | 2607 | { |
2613 | char *keyfile; | 2608 | char *keyfile; |
2614 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | ||
2615 | long long unsigned int max_fd_cfg; | 2609 | long long unsigned int max_fd_cfg; |
2616 | int max_fd_rlimit; | 2610 | int max_fd_rlimit; |
2617 | int max_fd; | 2611 | int max_fd; |
@@ -2638,17 +2632,22 @@ run (void *cls, | |||
2638 | { | 2632 | { |
2639 | hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; | 2633 | hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; |
2640 | } | 2634 | } |
2641 | pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); | 2635 | if (GNUNET_SYSERR == |
2636 | GNUNET_CRYPTO_eddsa_key_from_file (keyfile, | ||
2637 | GNUNET_YES, | ||
2638 | &GST_my_private_key)) | ||
2639 | { | ||
2640 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2641 | "Failed to setup peer's private key\n"); | ||
2642 | GNUNET_SCHEDULER_shutdown (); | ||
2643 | GNUNET_free (keyfile); | ||
2644 | return; | ||
2645 | } | ||
2642 | GNUNET_free (keyfile); | 2646 | GNUNET_free (keyfile); |
2643 | GNUNET_assert (NULL != pk); | ||
2644 | GST_my_private_key = pk; | ||
2645 | |||
2646 | GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); | 2647 | GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); |
2647 | GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg); | 2648 | GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg); |
2648 | GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key, | 2649 | GNUNET_CRYPTO_eddsa_key_get_public (&GST_my_private_key, |
2649 | &GST_my_identity.public_key); | 2650 | &GST_my_identity.public_key); |
2650 | GNUNET_assert (NULL != GST_my_private_key); | ||
2651 | |||
2652 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2651 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
2653 | "My identity is `%s'\n", | 2652 | "My identity is `%s'\n", |
2654 | GNUNET_i2s_full (&GST_my_identity)); | 2653 | GNUNET_i2s_full (&GST_my_identity)); |
diff --git a/src/transport/gnunet-service-transport.h b/src/transport/gnunet-service-transport.h index acb1de395..ea9e71e4b 100644 --- a/src/transport/gnunet-service-transport.h +++ b/src/transport/gnunet-service-transport.h | |||
@@ -56,7 +56,7 @@ extern struct GNUNET_PEERINFO_Handle *GST_peerinfo; | |||
56 | /** | 56 | /** |
57 | * Our private key. | 57 | * Our private key. |
58 | */ | 58 | */ |
59 | extern struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key; | 59 | extern struct GNUNET_CRYPTO_EddsaPrivateKey GST_my_private_key; |
60 | 60 | ||
61 | /** | 61 | /** |
62 | * ATS handle. | 62 | * ATS handle. |
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index ec64ca607..ca1b4d1da 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -1045,7 +1045,7 @@ send_disconnect (struct NeighbourMapEntry *n) | |||
1045 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | 1045 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); |
1046 | disconnect_msg.public_key = GST_my_identity.public_key; | 1046 | disconnect_msg.public_key = GST_my_identity.public_key; |
1047 | GNUNET_assert (GNUNET_OK == | 1047 | GNUNET_assert (GNUNET_OK == |
1048 | GNUNET_CRYPTO_eddsa_sign_ (GST_my_private_key, | 1048 | GNUNET_CRYPTO_eddsa_sign_ (&GST_my_private_key, |
1049 | &disconnect_msg.purpose, | 1049 | &disconnect_msg.purpose, |
1050 | &disconnect_msg.signature)); | 1050 | &disconnect_msg.signature)); |
1051 | 1051 | ||
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index 610c45a21..e5d670889 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c | |||
@@ -1271,7 +1271,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, | |||
1271 | *sig_cache_exp = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME); | 1271 | *sig_cache_exp = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME); |
1272 | pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp); | 1272 | pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp); |
1273 | if (GNUNET_OK != | 1273 | if (GNUNET_OK != |
1274 | GNUNET_CRYPTO_eddsa_sign_ (GST_my_private_key, | 1274 | GNUNET_CRYPTO_eddsa_sign_ (&GST_my_private_key, |
1275 | &pong->purpose, | 1275 | &pong->purpose, |
1276 | sig_cache)) | 1276 | sig_cache)) |
1277 | { | 1277 | { |
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index 4c1169f43..851a45f93 100644 --- a/src/util/crypto_ecc.c +++ b/src/util/crypto_ecc.c | |||
@@ -491,118 +491,98 @@ GNUNET_CRYPTO_eddsa_key_clear (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) | |||
491 | 491 | ||
492 | 492 | ||
493 | /** | 493 | /** |
494 | * Create a new private key. Caller must free return value. | 494 | * Create a new private key. |
495 | * | 495 | * |
496 | * @return fresh private key | 496 | * @param[out] pk fresh private key |
497 | */ | 497 | */ |
498 | struct GNUNET_CRYPTO_EcdhePrivateKey * | 498 | void |
499 | GNUNET_CRYPTO_ecdhe_key_create () | 499 | GNUNET_CRYPTO_ecdhe_key_create (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) |
500 | { | ||
501 | struct GNUNET_CRYPTO_EcdhePrivateKey *priv; | ||
502 | |||
503 | priv = GNUNET_new (struct GNUNET_CRYPTO_EcdhePrivateKey); | ||
504 | if (GNUNET_OK != GNUNET_CRYPTO_ecdhe_key_create2 (priv)) | ||
505 | { | ||
506 | GNUNET_free (priv); | ||
507 | return NULL; | ||
508 | } | ||
509 | return priv; | ||
510 | } | ||
511 | |||
512 | |||
513 | /** | ||
514 | * @ingroup crypto | ||
515 | * Create a new private key. Clear with #GNUNET_CRYPTO_ecdhe_key_clear(). | ||
516 | * | ||
517 | * @param[out] pk set to fresh private key; | ||
518 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | ||
519 | */ | ||
520 | int | ||
521 | GNUNET_CRYPTO_ecdhe_key_create2 (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) | ||
522 | { | 500 | { |
523 | BENCHMARK_START (ecdhe_key_create); | 501 | BENCHMARK_START (ecdhe_key_create); |
524 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, | 502 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, |
525 | pk, | 503 | pk, |
526 | sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey)); | 504 | sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey)); |
527 | BENCHMARK_END (ecdhe_key_create); | 505 | BENCHMARK_END (ecdhe_key_create); |
528 | return GNUNET_OK; | ||
529 | } | 506 | } |
530 | 507 | ||
531 | 508 | ||
532 | /** | 509 | /** |
533 | * Create a new private key. Caller must free return value. | 510 | * Create a new private key. |
534 | * | 511 | * |
535 | * @return fresh private key | 512 | * @param[out] pk private key to initialize |
536 | */ | 513 | */ |
537 | struct GNUNET_CRYPTO_EcdsaPrivateKey * | 514 | void |
538 | GNUNET_CRYPTO_ecdsa_key_create () | 515 | GNUNET_CRYPTO_ecdsa_key_create (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk) |
539 | { | 516 | { |
540 | struct GNUNET_CRYPTO_EcdsaPrivateKey *priv; | ||
541 | gcry_sexp_t priv_sexp; | 517 | gcry_sexp_t priv_sexp; |
542 | gcry_sexp_t s_keyparam; | 518 | gcry_sexp_t s_keyparam; |
543 | gcry_mpi_t d; | 519 | gcry_mpi_t d; |
544 | int rc; | 520 | int rc; |
545 | 521 | ||
546 | BENCHMARK_START (ecdsa_key_create); | 522 | BENCHMARK_START (ecdsa_key_create); |
547 | |||
548 | if (0 != (rc = gcry_sexp_build (&s_keyparam, | 523 | if (0 != (rc = gcry_sexp_build (&s_keyparam, |
549 | NULL, | 524 | NULL, |
550 | "(genkey(ecc(curve \"" CURVE "\")" | 525 | "(genkey(ecc(curve \"" CURVE "\")" |
551 | "(flags)))"))) | 526 | "(flags)))"))) |
552 | { | 527 | { |
553 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); | 528 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, |
554 | return NULL; | 529 | "gcry_sexp_build", |
530 | rc); | ||
531 | GNUNET_assert (0); | ||
555 | } | 532 | } |
556 | if (0 != (rc = gcry_pk_genkey (&priv_sexp, s_keyparam))) | 533 | if (0 != (rc = gcry_pk_genkey (&priv_sexp, |
534 | s_keyparam))) | ||
557 | { | 535 | { |
558 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_genkey", rc); | 536 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, |
537 | "gcry_pk_genkey", | ||
538 | rc); | ||
559 | gcry_sexp_release (s_keyparam); | 539 | gcry_sexp_release (s_keyparam); |
560 | return NULL; | 540 | GNUNET_assert (0); |
561 | } | 541 | } |
562 | gcry_sexp_release (s_keyparam); | 542 | gcry_sexp_release (s_keyparam); |
563 | #if EXTRA_CHECKS | 543 | #if EXTRA_CHECKS |
564 | if (0 != (rc = gcry_pk_testkey (priv_sexp))) | 544 | if (0 != (rc = gcry_pk_testkey (priv_sexp))) |
565 | { | 545 | { |
566 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc); | 546 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, |
547 | "gcry_pk_testkey", | ||
548 | rc); | ||
567 | gcry_sexp_release (priv_sexp); | 549 | gcry_sexp_release (priv_sexp); |
568 | return NULL; | 550 | GNUNET_assert (0); |
569 | } | 551 | } |
570 | #endif | 552 | #endif |
571 | if (0 != (rc = key_from_sexp (&d, priv_sexp, "private-key", "d"))) | 553 | if (0 != (rc = key_from_sexp (&d, priv_sexp, |
554 | "private-key", | ||
555 | "d"))) | ||
572 | { | 556 | { |
573 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "key_from_sexp", rc); | 557 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, |
558 | "key_from_sexp", | ||
559 | rc); | ||
574 | gcry_sexp_release (priv_sexp); | 560 | gcry_sexp_release (priv_sexp); |
575 | return NULL; | 561 | GNUNET_assert (0); |
576 | } | 562 | } |
577 | gcry_sexp_release (priv_sexp); | 563 | gcry_sexp_release (priv_sexp); |
578 | priv = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); | 564 | GNUNET_CRYPTO_mpi_print_unsigned (pk->d, |
579 | GNUNET_CRYPTO_mpi_print_unsigned (priv->d, sizeof(priv->d), d); | 565 | sizeof(pk->d), |
566 | d); | ||
580 | gcry_mpi_release (d); | 567 | gcry_mpi_release (d); |
581 | |||
582 | BENCHMARK_END (ecdsa_key_create); | 568 | BENCHMARK_END (ecdsa_key_create); |
583 | |||
584 | return priv; | ||
585 | } | 569 | } |
586 | 570 | ||
587 | 571 | ||
588 | /** | 572 | /** |
589 | * Create a new private key. Caller must free return value. | 573 | * Create a new private key. |
590 | * | 574 | * |
591 | * @return fresh private key | 575 | * @param[out] pk set to fresh private key |
592 | */ | 576 | */ |
593 | struct GNUNET_CRYPTO_EddsaPrivateKey * | 577 | void |
594 | GNUNET_CRYPTO_eddsa_key_create () | 578 | GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) |
595 | { | 579 | { |
596 | struct GNUNET_CRYPTO_EddsaPrivateKey *priv; | ||
597 | |||
598 | BENCHMARK_START (eddsa_key_create); | 580 | BENCHMARK_START (eddsa_key_create); |
599 | priv = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey); | ||
600 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, | 581 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, |
601 | priv, | 582 | pk, |
602 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); | 583 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); |
584 | // FIXME: should we not do the clamping here? Or is this done elsewhere? | ||
603 | BENCHMARK_END (eddsa_key_create); | 585 | BENCHMARK_END (eddsa_key_create); |
604 | |||
605 | return priv; | ||
606 | } | 586 | } |
607 | 587 | ||
608 | 588 | ||
diff --git a/src/util/crypto_ecc_setup.c b/src/util/crypto_ecc_setup.c index b3d410b7a..5167a33fb 100644 --- a/src/util/crypto_ecc_setup.c +++ b/src/util/crypto_ecc_setup.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2012, 2013, 2015 GNUnet e.V. | 3 | Copyright (C) 2012, 2013, 2015, 2020 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 6 | under the terms of the GNU Affero General Public License as published |
@@ -53,375 +53,261 @@ | |||
53 | 53 | ||
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Wait for a short time (we're trying to lock a file or want | 56 | * Read file to @a buf. Fails if the file does not exist or |
57 | * to give another process a shot at finishing a disk write, etc.). | 57 | * does not have precisely @a buf_size bytes. |
58 | * Sleeps for 100ms (as that should be long enough for virtually all | 58 | * |
59 | * modern systems to context switch and allow another process to do | 59 | * @param filename file to read |
60 | * some 'real' work). | 60 | * @param[out] buf where to write the file contents |
61 | * @param buf_size number of bytes in @a buf | ||
62 | * @return #GNUNET_OK on success | ||
61 | */ | 63 | */ |
62 | static void | 64 | static int |
63 | short_wait () | 65 | read_from_file (const char *filename, |
66 | void *buf, | ||
67 | size_t buf_size) | ||
64 | { | 68 | { |
65 | struct GNUNET_TIME_Relative timeout; | 69 | int fd; |
70 | struct stat sb; | ||
66 | 71 | ||
67 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 100); | 72 | fd = open (filename, |
68 | (void) GNUNET_NETWORK_socket_select (NULL, NULL, NULL, timeout); | 73 | O_RDONLY); |
74 | if (-1 == fd) | ||
75 | { | ||
76 | memset (buf, | ||
77 | 0, | ||
78 | buf_size); | ||
79 | return GNUNET_SYSERR; | ||
80 | } | ||
81 | if (0 != fstat (fd, | ||
82 | &sb)) | ||
83 | { | ||
84 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
85 | "stat", | ||
86 | filename); | ||
87 | GNUNET_assert (0 == close (fd)); | ||
88 | memset (buf, | ||
89 | 0, | ||
90 | buf_size); | ||
91 | return GNUNET_SYSERR; | ||
92 | } | ||
93 | if (sb.st_size != buf_size) | ||
94 | { | ||
95 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
96 | "File `%s' has wrong size (%llu), expected %llu bytes\n", | ||
97 | filename, | ||
98 | (unsigned long long) sb.st_size, | ||
99 | (unsigned long long) buf_size); | ||
100 | GNUNET_assert (0 == close (fd)); | ||
101 | memset (buf, | ||
102 | 0, | ||
103 | buf_size); | ||
104 | return GNUNET_SYSERR; | ||
105 | } | ||
106 | if (buf_size != | ||
107 | read (fd, | ||
108 | buf, | ||
109 | buf_size)) | ||
110 | { | ||
111 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
112 | "read", | ||
113 | filename); | ||
114 | GNUNET_assert (0 == close (fd)); | ||
115 | memset (buf, | ||
116 | 0, | ||
117 | buf_size); | ||
118 | return GNUNET_SYSERR; | ||
119 | } | ||
120 | GNUNET_assert (0 == close (fd)); | ||
121 | return GNUNET_OK; | ||
69 | } | 122 | } |
70 | 123 | ||
71 | 124 | ||
72 | /** | 125 | /** |
73 | * Create a new private key by reading it from a file. If the | 126 | * Write contents of @a buf atomically to @a filename. |
74 | * files does not exist, create a new key and write it to the | 127 | * Fail if @a filename already exists or if not exactly |
75 | * file. Caller must free return value. Note that this function | 128 | * @a buf with @a buf_size bytes could be written to |
76 | * can not guarantee that another process might not be trying | 129 | * @a filename. |
77 | * the same operation on the same file at the same time. | ||
78 | * If the contents of the file | ||
79 | * are invalid the old file is deleted and a fresh key is | ||
80 | * created. | ||
81 | * | 130 | * |
82 | * @param filename name of file to use to store the key | 131 | * @param filename where to write |
83 | * @return new private key, NULL on error (for example, | 132 | * @param buf buffer to write |
84 | * permission denied) | 133 | * @param buf_size number of bytes in @a buf to write |
134 | * @return #GNUNET_OK on success, | ||
135 | * #GNUNET_NO if a file existed under @a filename | ||
136 | * #GNUNET_SYSERR on failure | ||
85 | */ | 137 | */ |
86 | struct GNUNET_CRYPTO_EddsaPrivateKey * | 138 | static int |
87 | GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename) | 139 | atomic_write_to_file (const char *filename, |
140 | const void *buf, | ||
141 | size_t buf_size) | ||
88 | { | 142 | { |
89 | struct GNUNET_CRYPTO_EddsaPrivateKey *priv; | 143 | char *tmpl; |
90 | struct GNUNET_DISK_FileHandle *fd; | 144 | int fd; |
91 | unsigned int cnt; | ||
92 | int ec; | ||
93 | uint64_t fs; | ||
94 | ssize_t sret; | ||
95 | 145 | ||
96 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) | ||
97 | return NULL; | ||
98 | while (GNUNET_YES != GNUNET_DISK_file_test (filename)) | ||
99 | { | 146 | { |
100 | fd = | 147 | char *dname; |
101 | GNUNET_DISK_file_open (filename, | 148 | |
102 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | 149 | dname = GNUNET_strdup (filename); |
103 | | GNUNET_DISK_OPEN_FAILIFEXISTS, | 150 | GNUNET_asprintf (&tmpl, |
104 | GNUNET_DISK_PERM_USER_READ | 151 | "%s/XXXXXX", |
105 | | GNUNET_DISK_PERM_USER_WRITE); | 152 | dirname (dname)); |
106 | if (NULL == fd) | 153 | GNUNET_free (dname); |
107 | { | ||
108 | if (EEXIST == errno) | ||
109 | { | ||
110 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | ||
111 | { | ||
112 | /* must exist but not be accessible, fail for good! */ | ||
113 | if (0 != access (filename, R_OK)) | ||
114 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename); | ||
115 | else | ||
116 | GNUNET_break (0); /* what is going on!? */ | ||
117 | return NULL; | ||
118 | } | ||
119 | continue; | ||
120 | } | ||
121 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); | ||
122 | return NULL; | ||
123 | } | ||
124 | cnt = 0; | ||
125 | while (GNUNET_YES != | ||
126 | GNUNET_DISK_file_lock (fd, | ||
127 | 0, | ||
128 | sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey), | ||
129 | GNUNET_YES)) | ||
130 | { | ||
131 | short_wait (); | ||
132 | if (0 == ++cnt % 10) | ||
133 | { | ||
134 | ec = errno; | ||
135 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
136 | _ ("Could not acquire lock on file `%s': %s...\n"), | ||
137 | filename, | ||
138 | strerror (ec)); | ||
139 | } | ||
140 | } | ||
141 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
142 | _ ("Creating a new private key. This may take a while.\n")); | ||
143 | priv = GNUNET_CRYPTO_eddsa_key_create (); | ||
144 | GNUNET_assert (NULL != priv); | ||
145 | GNUNET_assert (sizeof(*priv) == | ||
146 | GNUNET_DISK_file_write (fd, priv, sizeof(*priv))); | ||
147 | GNUNET_DISK_file_sync (fd); | ||
148 | if (GNUNET_YES != | ||
149 | GNUNET_DISK_file_unlock (fd, | ||
150 | 0, | ||
151 | sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey))) | ||
152 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); | ||
153 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); | ||
154 | return priv; | ||
155 | } | 154 | } |
156 | /* key file exists already, read it! */ | 155 | fd = mkstemp (tmpl); |
157 | fd = GNUNET_DISK_file_open (filename, | 156 | if (-1 == fd) |
158 | GNUNET_DISK_OPEN_READ, | ||
159 | GNUNET_DISK_PERM_NONE); | ||
160 | if (NULL == fd) | ||
161 | { | 157 | { |
162 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); | 158 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
163 | return NULL; | 159 | "mkstemp", |
160 | tmpl); | ||
161 | GNUNET_free (tmpl); | ||
162 | return GNUNET_SYSERR; | ||
164 | } | 163 | } |
165 | cnt = 0; | 164 | if (0 != fchmod (fd, |
166 | while (1) | 165 | S_IRUSR)) |
167 | { | 166 | { |
168 | if (GNUNET_YES != | 167 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
169 | GNUNET_DISK_file_lock (fd, | 168 | "chmod", |
170 | 0, | 169 | tmpl); |
171 | sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey), | 170 | GNUNET_assert (0 == close (fd)); |
172 | GNUNET_NO)) | 171 | if (0 != unlink (tmpl)) |
173 | { | 172 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, |
174 | if (0 == ++cnt % 60) | 173 | "unlink", |
175 | { | 174 | tmpl); |
176 | ec = errno; | 175 | GNUNET_free (tmpl); |
177 | LOG (GNUNET_ERROR_TYPE_ERROR, | 176 | return GNUNET_SYSERR; |
178 | _ ("Could not acquire lock on file `%s': %s...\n"), | ||
179 | filename, | ||
180 | strerror (ec)); | ||
181 | LOG ( | ||
182 | GNUNET_ERROR_TYPE_ERROR, | ||
183 | _ ( | ||
184 | "This may be ok if someone is currently generating a private key.\n")); | ||
185 | } | ||
186 | short_wait (); | ||
187 | continue; | ||
188 | } | ||
189 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | ||
190 | { | ||
191 | /* eh, what!? File we opened is now gone!? */ | ||
192 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename); | ||
193 | if (GNUNET_YES != | ||
194 | GNUNET_DISK_file_unlock (fd, | ||
195 | 0, | ||
196 | sizeof( | ||
197 | struct GNUNET_CRYPTO_EddsaPrivateKey))) | ||
198 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); | ||
199 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); | ||
200 | |||
201 | return NULL; | ||
202 | } | ||
203 | if (GNUNET_OK != | ||
204 | GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) | ||
205 | fs = 0; | ||
206 | if (fs < sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey)) | ||
207 | { | ||
208 | /* maybe we got the read lock before the key generating | ||
209 | * process had a chance to get the write lock; give it up! */ | ||
210 | if (GNUNET_YES != | ||
211 | GNUNET_DISK_file_unlock (fd, | ||
212 | 0, | ||
213 | sizeof( | ||
214 | struct GNUNET_CRYPTO_EddsaPrivateKey))) | ||
215 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); | ||
216 | if (0 == ++cnt % 10) | ||
217 | { | ||
218 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
219 | _ ( | ||
220 | "When trying to read key file `%s' I found %u bytes but I need at least %u.\n"), | ||
221 | filename, | ||
222 | (unsigned int) fs, | ||
223 | (unsigned int) sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey)); | ||
224 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
225 | _ ("This may be ok if someone is currently generating a key.\n")); | ||
226 | } | ||
227 | short_wait (); /* wait a bit longer! */ | ||
228 | continue; | ||
229 | } | ||
230 | break; | ||
231 | } | 177 | } |
232 | fs = sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey); | 178 | if (buf_size != |
233 | priv = GNUNET_malloc (fs); | 179 | write (fd, |
234 | sret = GNUNET_DISK_file_read (fd, priv, fs); | 180 | buf, |
235 | GNUNET_assert ((sret >= 0) && (fs == (size_t) sret)); | 181 | buf_size)) |
236 | if (GNUNET_YES != | ||
237 | GNUNET_DISK_file_unlock (fd, | ||
238 | 0, | ||
239 | sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey))) | ||
240 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); | ||
241 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); | ||
242 | #if CRYPTO_BUG | ||
243 | if (GNUNET_OK != check_eddsa_key (priv)) | ||
244 | { | 182 | { |
245 | GNUNET_break (0); | 183 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
246 | GNUNET_free (priv); | 184 | "write", |
247 | return NULL; | 185 | tmpl); |
186 | GNUNET_assert (0 == close (fd)); | ||
187 | if (0 != unlink (tmpl)) | ||
188 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
189 | "unlink", | ||
190 | tmpl); | ||
191 | GNUNET_free (tmpl); | ||
192 | return GNUNET_SYSERR; | ||
248 | } | 193 | } |
249 | #endif | 194 | GNUNET_assert (0 == close (fd)); |
250 | return priv; | 195 | |
196 | if (0 != link (tmpl, | ||
197 | filename)) | ||
198 | { | ||
199 | if (0 != unlink (tmpl)) | ||
200 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
201 | "unlink", | ||
202 | tmpl); | ||
203 | GNUNET_free (tmpl); | ||
204 | return GNUNET_NO; | ||
205 | } | ||
206 | if (0 != unlink (tmpl)) | ||
207 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
208 | "unlink", | ||
209 | tmpl); | ||
210 | GNUNET_free (tmpl); | ||
211 | return GNUNET_OK; | ||
251 | } | 212 | } |
252 | 213 | ||
253 | 214 | ||
254 | /** | 215 | /** |
255 | * Create a new private key by reading it from a file. If the | 216 | * @ingroup crypto |
256 | * files does not exist, create a new key and write it to the | 217 | * @brief Create a new private key by reading it from a file. |
257 | * file. Caller must free return value. Note that this function | 218 | * |
258 | * can not guarantee that another process might not be trying | 219 | * If the files does not exist and @a do_create is set, creates a new key and |
259 | * the same operation on the same file at the same time. | 220 | * write it to the file. |
260 | * If the contents of the file | 221 | * |
261 | * are invalid the old file is deleted and a fresh key is | 222 | * If the contents of the file are invalid, an error is returned. |
262 | * created. | ||
263 | * | 223 | * |
264 | * @param filename name of file to use to store the key | 224 | * @param filename name of file to use to store the key |
265 | * @return new private key, NULL on error (for example, | 225 | * @param do_create should a file be created? |
266 | * permission denied) | 226 | * @param[out] pkey set to the private key from @a filename on success |
227 | * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but | ||
228 | * we found an existing file, #GNUNET_SYSERR on failure | ||
267 | */ | 229 | */ |
268 | struct GNUNET_CRYPTO_EcdsaPrivateKey * | 230 | int |
269 | GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename) | 231 | GNUNET_CRYPTO_eddsa_key_from_file (const char *filename, |
232 | int do_create, | ||
233 | struct GNUNET_CRYPTO_EddsaPrivateKey *pkey) | ||
270 | { | 234 | { |
271 | struct GNUNET_CRYPTO_EcdsaPrivateKey *priv; | 235 | int ret; |
272 | struct GNUNET_DISK_FileHandle *fd; | 236 | |
273 | unsigned int cnt; | 237 | if (GNUNET_OK == |
274 | int ec; | 238 | read_from_file (filename, |
275 | uint64_t fs; | 239 | pkey, |
276 | ssize_t sret; | 240 | sizeof (*pkey))) |
277 | |||
278 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) | ||
279 | return NULL; | ||
280 | while (GNUNET_YES != GNUNET_DISK_file_test (filename)) | ||
281 | { | 241 | { |
282 | fd = | 242 | /* file existed, report that we didn't create it... */ |
283 | GNUNET_DISK_file_open (filename, | 243 | return (do_create) ? GNUNET_NO : GNUNET_OK; |
284 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | ||
285 | | GNUNET_DISK_OPEN_FAILIFEXISTS, | ||
286 | GNUNET_DISK_PERM_USER_READ | ||
287 | | GNUNET_DISK_PERM_USER_WRITE); | ||
288 | if (NULL == fd) | ||
289 | { | ||
290 | if (EEXIST == errno) | ||
291 | { | ||
292 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | ||
293 | { | ||
294 | /* must exist but not be accessible, fail for good! */ | ||
295 | if (0 != access (filename, R_OK)) | ||
296 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename); | ||
297 | else | ||
298 | GNUNET_break (0); /* what is going on!? */ | ||
299 | return NULL; | ||
300 | } | ||
301 | continue; | ||
302 | } | ||
303 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); | ||
304 | return NULL; | ||
305 | } | ||
306 | cnt = 0; | ||
307 | while (GNUNET_YES != | ||
308 | GNUNET_DISK_file_lock (fd, | ||
309 | 0, | ||
310 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey), | ||
311 | GNUNET_YES)) | ||
312 | { | ||
313 | short_wait (); | ||
314 | if (0 == ++cnt % 10) | ||
315 | { | ||
316 | ec = errno; | ||
317 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
318 | _ ("Could not acquire lock on file `%s': %s...\n"), | ||
319 | filename, | ||
320 | strerror (ec)); | ||
321 | } | ||
322 | } | ||
323 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
324 | _ ("Creating a new private key. This may take a while.\n")); | ||
325 | priv = GNUNET_CRYPTO_ecdsa_key_create (); | ||
326 | GNUNET_assert (NULL != priv); | ||
327 | GNUNET_assert (sizeof(*priv) == | ||
328 | GNUNET_DISK_file_write (fd, priv, sizeof(*priv))); | ||
329 | GNUNET_DISK_file_sync (fd); | ||
330 | if (GNUNET_YES != | ||
331 | GNUNET_DISK_file_unlock (fd, | ||
332 | 0, | ||
333 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey))) | ||
334 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); | ||
335 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); | ||
336 | return priv; | ||
337 | } | 244 | } |
338 | /* key file exists already, read it! */ | 245 | GNUNET_CRYPTO_eddsa_key_create (pkey); |
339 | fd = GNUNET_DISK_file_open (filename, | 246 | ret = atomic_write_to_file (filename, |
340 | GNUNET_DISK_OPEN_READ, | 247 | pkey, |
341 | GNUNET_DISK_PERM_NONE); | 248 | sizeof (*pkey)); |
342 | if (NULL == fd) | 249 | if ( (GNUNET_OK == ret) || |
250 | (GNUNET_SYSERR == ret) ) | ||
251 | return ret; | ||
252 | /* maybe another process succeeded in the meantime, try reading one more time */ | ||
253 | if (GNUNET_OK == | ||
254 | read_from_file (filename, | ||
255 | pkey, | ||
256 | sizeof (*pkey))) | ||
343 | { | 257 | { |
344 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); | 258 | /* file existed, report that *we* didn't create it... */ |
345 | return NULL; | 259 | return (do_create) ? GNUNET_NO : GNUNET_OK; |
346 | } | 260 | } |
347 | cnt = 0; | 261 | /* give up */ |
348 | while (1) | 262 | return GNUNET_SYSERR; |
263 | } | ||
264 | |||
265 | |||
266 | /** | ||
267 | * @ingroup crypto | ||
268 | * @brief Create a new private key by reading it from a file. | ||
269 | * | ||
270 | * If the files does not exist and @a do_create is set, creates a new key and | ||
271 | * write it to the file. | ||
272 | * | ||
273 | * If the contents of the file are invalid, an error is returned. | ||
274 | * | ||
275 | * @param filename name of file to use to store the key | ||
276 | * @param do_create should a file be created? | ||
277 | * @param[out] pkey set to the private key from @a filename on success | ||
278 | * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but | ||
279 | * we found an existing file, #GNUNET_SYSERR on failure | ||
280 | */ | ||
281 | int | ||
282 | GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename, | ||
283 | int do_create, | ||
284 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey) | ||
285 | { | ||
286 | if (GNUNET_OK == | ||
287 | read_from_file (filename, | ||
288 | pkey, | ||
289 | sizeof (*pkey))) | ||
349 | { | 290 | { |
350 | if (GNUNET_YES != | 291 | /* file existed, report that we didn't create it... */ |
351 | GNUNET_DISK_file_lock (fd, | 292 | return (do_create) ? GNUNET_NO : GNUNET_OK; |
352 | 0, | ||
353 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey), | ||
354 | GNUNET_NO)) | ||
355 | { | ||
356 | if (0 == ++cnt % 60) | ||
357 | { | ||
358 | ec = errno; | ||
359 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
360 | _ ("Could not acquire lock on file `%s': %s...\n"), | ||
361 | filename, | ||
362 | strerror (ec)); | ||
363 | LOG ( | ||
364 | GNUNET_ERROR_TYPE_ERROR, | ||
365 | _ ( | ||
366 | "This may be ok if someone is currently generating a private key.\n")); | ||
367 | } | ||
368 | short_wait (); | ||
369 | continue; | ||
370 | } | ||
371 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | ||
372 | { | ||
373 | /* eh, what!? File we opened is now gone!? */ | ||
374 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename); | ||
375 | if (GNUNET_YES != | ||
376 | GNUNET_DISK_file_unlock (fd, | ||
377 | 0, | ||
378 | sizeof( | ||
379 | struct GNUNET_CRYPTO_EcdsaPrivateKey))) | ||
380 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); | ||
381 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); | ||
382 | |||
383 | return NULL; | ||
384 | } | ||
385 | if (GNUNET_OK != | ||
386 | GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) | ||
387 | fs = 0; | ||
388 | if (fs < sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)) | ||
389 | { | ||
390 | /* maybe we got the read lock before the key generating | ||
391 | * process had a chance to get the write lock; give it up! */ | ||
392 | if (GNUNET_YES != | ||
393 | GNUNET_DISK_file_unlock (fd, | ||
394 | 0, | ||
395 | sizeof( | ||
396 | struct GNUNET_CRYPTO_EcdsaPrivateKey))) | ||
397 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); | ||
398 | if (0 == ++cnt % 10) | ||
399 | { | ||
400 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
401 | _ ( | ||
402 | "When trying to read key file `%s' I found %u bytes but I need at least %u.\n"), | ||
403 | filename, | ||
404 | (unsigned int) fs, | ||
405 | (unsigned int) sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)); | ||
406 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
407 | _ ("This may be ok if someone is currently generating a key.\n")); | ||
408 | } | ||
409 | short_wait (); /* wait a bit longer! */ | ||
410 | continue; | ||
411 | } | ||
412 | break; | ||
413 | } | 293 | } |
414 | fs = sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey); | 294 | GNUNET_CRYPTO_ecdsa_key_create (pkey); |
415 | priv = GNUNET_malloc (fs); | 295 | if (GNUNET_OK == |
416 | sret = GNUNET_DISK_file_read (fd, priv, fs); | 296 | atomic_write_to_file (filename, |
417 | GNUNET_assert ((sret >= 0) && (fs == (size_t) sret)); | 297 | pkey, |
418 | if (GNUNET_YES != | 298 | sizeof (*pkey))) |
419 | GNUNET_DISK_file_unlock (fd, | 299 | return GNUNET_OK; |
420 | 0, | 300 | /* maybe another process succeeded in the meantime, try reading one more time */ |
421 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey))) | 301 | if (GNUNET_OK == |
422 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); | 302 | read_from_file (filename, |
423 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); | 303 | pkey, |
424 | return priv; | 304 | sizeof (*pkey))) |
305 | { | ||
306 | /* file existed, report that *we* didn't create it... */ | ||
307 | return (do_create) ? GNUNET_NO : GNUNET_OK; | ||
308 | } | ||
309 | /* give up */ | ||
310 | return GNUNET_SYSERR; | ||
425 | } | 311 | } |
426 | 312 | ||
427 | 313 | ||
@@ -441,9 +327,15 @@ GNUNET_CRYPTO_eddsa_key_create_from_configuration ( | |||
441 | char *fn; | 327 | char *fn; |
442 | 328 | ||
443 | if (GNUNET_OK != | 329 | if (GNUNET_OK != |
444 | GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER", "PRIVATE_KEY", &fn)) | 330 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
331 | "PEER", | ||
332 | "PRIVATE_KEY", | ||
333 | &fn)) | ||
445 | return NULL; | 334 | return NULL; |
446 | priv = GNUNET_CRYPTO_eddsa_key_create_from_file (fn); | 335 | priv = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey); |
336 | GNUNET_CRYPTO_eddsa_key_from_file (fn, | ||
337 | GNUNET_YES, | ||
338 | priv); | ||
447 | GNUNET_free (fn); | 339 | GNUNET_free (fn); |
448 | return priv; | 340 | return priv; |
449 | } | 341 | } |
@@ -469,7 +361,8 @@ GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
469 | _ ("Could not load peer's private key\n")); | 361 | _ ("Could not load peer's private key\n")); |
470 | return GNUNET_SYSERR; | 362 | return GNUNET_SYSERR; |
471 | } | 363 | } |
472 | GNUNET_CRYPTO_eddsa_key_get_public (priv, &dst->public_key); | 364 | GNUNET_CRYPTO_eddsa_key_get_public (priv, |
365 | &dst->public_key); | ||
473 | GNUNET_free (priv); | 366 | GNUNET_free (priv); |
474 | return GNUNET_OK; | 367 | return GNUNET_OK; |
475 | } | 368 | } |
diff --git a/src/util/disk.c b/src/util/disk.c index b98c81e4b..9018aa955 100644 --- a/src/util/disk.c +++ b/src/util/disk.c | |||
@@ -1188,70 +1188,6 @@ GNUNET_DISK_file_change_owner (const char *filename, const char *user) | |||
1188 | 1188 | ||
1189 | 1189 | ||
1190 | /** | 1190 | /** |
1191 | * Lock a part of a file | ||
1192 | * | ||
1193 | * @param fh file handle | ||
1194 | * @param lock_start absolute position from where to lock | ||
1195 | * @param lock_end absolute position until where to lock | ||
1196 | * @param excl #GNUNET_YES for an exclusive lock | ||
1197 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1198 | */ | ||
1199 | int | ||
1200 | GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, | ||
1201 | off_t lock_start, | ||
1202 | off_t lock_end, | ||
1203 | int excl) | ||
1204 | { | ||
1205 | if (fh == NULL) | ||
1206 | { | ||
1207 | errno = EINVAL; | ||
1208 | return GNUNET_SYSERR; | ||
1209 | } | ||
1210 | |||
1211 | struct flock fl; | ||
1212 | |||
1213 | memset (&fl, 0, sizeof(struct flock)); | ||
1214 | fl.l_type = excl ? F_WRLCK : F_RDLCK; | ||
1215 | fl.l_whence = SEEK_SET; | ||
1216 | fl.l_start = lock_start; | ||
1217 | fl.l_len = lock_end; | ||
1218 | |||
1219 | return fcntl (fh->fd, F_SETLK, &fl) != 0 ? GNUNET_SYSERR : GNUNET_OK; | ||
1220 | } | ||
1221 | |||
1222 | |||
1223 | /** | ||
1224 | * Unlock a part of a file | ||
1225 | * | ||
1226 | * @param fh file handle | ||
1227 | * @param unlock_start absolute position from where to unlock | ||
1228 | * @param unlock_end absolute position until where to unlock | ||
1229 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1230 | */ | ||
1231 | int | ||
1232 | GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, | ||
1233 | off_t unlock_start, | ||
1234 | off_t unlock_end) | ||
1235 | { | ||
1236 | if (fh == NULL) | ||
1237 | { | ||
1238 | errno = EINVAL; | ||
1239 | return GNUNET_SYSERR; | ||
1240 | } | ||
1241 | |||
1242 | struct flock fl; | ||
1243 | |||
1244 | memset (&fl, 0, sizeof(struct flock)); | ||
1245 | fl.l_type = F_UNLCK; | ||
1246 | fl.l_whence = SEEK_SET; | ||
1247 | fl.l_start = unlock_start; | ||
1248 | fl.l_len = unlock_end; | ||
1249 | |||
1250 | return fcntl (fh->fd, F_SETLK, &fl) != 0 ? GNUNET_SYSERR : GNUNET_OK; | ||
1251 | } | ||
1252 | |||
1253 | |||
1254 | /** | ||
1255 | * Open a file. Note that the access permissions will only be | 1191 | * Open a file. Note that the access permissions will only be |
1256 | * used if a new file is created and if the underlying operating | 1192 | * used if a new file is created and if the underlying operating |
1257 | * system supports the given permissions. | 1193 | * system supports the given permissions. |
diff --git a/src/util/gnunet-crypto-tvg.c b/src/util/gnunet-crypto-tvg.c index e0ef9a622..c3fead62e 100644 --- a/src/util/gnunet-crypto-tvg.c +++ b/src/util/gnunet-crypto-tvg.c | |||
@@ -86,50 +86,63 @@ run (void *cls, | |||
86 | display_data (" output", &hc, sizeof (struct GNUNET_HashCode)); | 86 | display_data (" output", &hc, sizeof (struct GNUNET_HashCode)); |
87 | } | 87 | } |
88 | { | 88 | { |
89 | struct GNUNET_CRYPTO_EcdhePrivateKey *priv1; | 89 | struct GNUNET_CRYPTO_EcdhePrivateKey priv1; |
90 | struct GNUNET_CRYPTO_EcdhePublicKey pub1; | 90 | struct GNUNET_CRYPTO_EcdhePublicKey pub1; |
91 | struct GNUNET_CRYPTO_EcdhePrivateKey *priv2; | 91 | struct GNUNET_CRYPTO_EcdhePrivateKey priv2; |
92 | struct GNUNET_HashCode skm; | 92 | struct GNUNET_HashCode skm; |
93 | priv1 = GNUNET_CRYPTO_ecdhe_key_create (); | 93 | |
94 | priv2 = GNUNET_CRYPTO_ecdhe_key_create (); | 94 | GNUNET_CRYPTO_ecdhe_key_create (&priv1); |
95 | GNUNET_CRYPTO_ecdhe_key_get_public (priv1, &pub1); | 95 | GNUNET_CRYPTO_ecdhe_key_create (&priv2); |
96 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecc_ecdh (priv2, &pub1, &skm)); | 96 | GNUNET_CRYPTO_ecdhe_key_get_public (&priv1, |
97 | &pub1); | ||
98 | GNUNET_assert (GNUNET_OK == | ||
99 | GNUNET_CRYPTO_ecc_ecdh (&priv2, | ||
100 | &pub1, | ||
101 | &skm)); | ||
97 | 102 | ||
98 | printf ("ecdhe key:\n"); | 103 | printf ("ecdhe key:\n"); |
99 | display_data (" priv1", priv1, sizeof (struct | 104 | display_data (" priv1", |
100 | GNUNET_CRYPTO_EcdhePrivateKey)); | 105 | &priv1, |
101 | display_data (" pub1", &pub1, sizeof (struct | 106 | sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey)); |
102 | GNUNET_CRYPTO_EcdhePublicKey)); | 107 | display_data (" pub1", |
103 | display_data (" priv2", priv2, sizeof (struct | 108 | &pub1, |
104 | GNUNET_CRYPTO_EcdhePrivateKey)); | 109 | sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); |
105 | display_data (" skm", &skm, sizeof (struct GNUNET_HashCode)); | 110 | display_data (" priv2", |
106 | GNUNET_free (priv1); | 111 | &priv2, |
107 | GNUNET_free (priv2); | 112 | sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey)); |
113 | display_data (" skm", | ||
114 | &skm, | ||
115 | sizeof (struct GNUNET_HashCode)); | ||
108 | } | 116 | } |
109 | 117 | ||
110 | { | 118 | { |
111 | struct GNUNET_CRYPTO_EddsaPrivateKey *priv; | 119 | struct GNUNET_CRYPTO_EddsaPrivateKey priv; |
112 | struct GNUNET_CRYPTO_EddsaPublicKey pub; | 120 | struct GNUNET_CRYPTO_EddsaPublicKey pub; |
113 | priv = GNUNET_CRYPTO_eddsa_key_create (); | 121 | |
114 | GNUNET_CRYPTO_eddsa_key_get_public (priv, &pub); | 122 | GNUNET_CRYPTO_eddsa_key_create (&priv); |
123 | GNUNET_CRYPTO_eddsa_key_get_public (&priv, | ||
124 | &pub); | ||
115 | 125 | ||
116 | printf ("eddsa key:\n"); | 126 | printf ("eddsa key:\n"); |
117 | display_data (" priv", priv, sizeof (struct | 127 | display_data (" priv", |
118 | GNUNET_CRYPTO_EddsaPrivateKey)); | 128 | &priv, |
119 | display_data (" pub", &pub, sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); | 129 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); |
120 | GNUNET_free (priv); | 130 | display_data (" pub", |
131 | &pub, | ||
132 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); | ||
121 | } | 133 | } |
122 | { | 134 | { |
123 | struct GNUNET_CRYPTO_EddsaPrivateKey *priv; | 135 | struct GNUNET_CRYPTO_EddsaPrivateKey priv; |
124 | struct GNUNET_CRYPTO_EddsaPublicKey pub; | 136 | struct GNUNET_CRYPTO_EddsaPublicKey pub; |
125 | struct GNUNET_CRYPTO_EddsaSignature sig; | 137 | struct GNUNET_CRYPTO_EddsaSignature sig; |
126 | struct TestSignatureDataPS data = { 0 }; | 138 | struct TestSignatureDataPS data = { 0 }; |
127 | 139 | ||
128 | priv = GNUNET_CRYPTO_eddsa_key_create (); | 140 | GNUNET_CRYPTO_eddsa_key_create (&priv); |
129 | GNUNET_CRYPTO_eddsa_key_get_public (priv, &pub); | 141 | GNUNET_CRYPTO_eddsa_key_get_public (&priv, |
142 | &pub); | ||
130 | data.purpose.size = htonl (sizeof (data)); | 143 | data.purpose.size = htonl (sizeof (data)); |
131 | data.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); | 144 | data.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
132 | GNUNET_CRYPTO_eddsa_sign (priv, | 145 | GNUNET_CRYPTO_eddsa_sign (&priv, |
133 | &data, | 146 | &data, |
134 | &sig); | 147 | &sig); |
135 | GNUNET_assert (GNUNET_OK == | 148 | GNUNET_assert (GNUNET_OK == |
@@ -139,12 +152,18 @@ run (void *cls, | |||
139 | &pub)); | 152 | &pub)); |
140 | 153 | ||
141 | printf ("eddsa sig:\n"); | 154 | printf ("eddsa sig:\n"); |
142 | display_data (" priv", priv, sizeof (struct | 155 | display_data (" priv", |
143 | GNUNET_CRYPTO_EddsaPrivateKey)); | 156 | &priv, |
144 | display_data (" pub", &pub, sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); | 157 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); |
145 | display_data (" data", &data, sizeof (struct TestSignatureDataPS)); | 158 | display_data (" pub", |
146 | display_data (" sig", &sig, sizeof (struct GNUNET_CRYPTO_EddsaSignature)); | 159 | &pub, |
147 | GNUNET_free (priv); | 160 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); |
161 | display_data (" data", | ||
162 | &data, | ||
163 | sizeof (struct TestSignatureDataPS)); | ||
164 | display_data (" sig", | ||
165 | &sig, | ||
166 | sizeof (struct GNUNET_CRYPTO_EddsaSignature)); | ||
148 | } | 167 | } |
149 | 168 | ||
150 | { | 169 | { |
@@ -173,28 +192,34 @@ run (void *cls, | |||
173 | display_data (" out", out, out_len); | 192 | display_data (" out", out, out_len); |
174 | } | 193 | } |
175 | { | 194 | { |
176 | struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ecdhe; | 195 | struct GNUNET_CRYPTO_EcdhePrivateKey priv_ecdhe; |
177 | struct GNUNET_CRYPTO_EcdhePublicKey pub_ecdhe; | 196 | struct GNUNET_CRYPTO_EcdhePublicKey pub_ecdhe; |
178 | struct GNUNET_CRYPTO_EddsaPrivateKey *priv_eddsa; | 197 | struct GNUNET_CRYPTO_EddsaPrivateKey priv_eddsa; |
179 | struct GNUNET_CRYPTO_EddsaPublicKey pub_eddsa; | 198 | struct GNUNET_CRYPTO_EddsaPublicKey pub_eddsa; |
180 | struct GNUNET_HashCode key_material; | 199 | struct GNUNET_HashCode key_material; |
181 | priv_ecdhe = GNUNET_CRYPTO_ecdhe_key_create (); | 200 | |
182 | GNUNET_CRYPTO_ecdhe_key_get_public (priv_ecdhe, &pub_ecdhe); | 201 | GNUNET_CRYPTO_ecdhe_key_create (&priv_ecdhe); |
183 | priv_eddsa = GNUNET_CRYPTO_eddsa_key_create (); | 202 | GNUNET_CRYPTO_ecdhe_key_get_public (&priv_ecdhe, &pub_ecdhe); |
184 | GNUNET_CRYPTO_eddsa_key_get_public (priv_eddsa, &pub_eddsa); | 203 | GNUNET_CRYPTO_eddsa_key_create (&priv_eddsa); |
185 | GNUNET_CRYPTO_ecdh_eddsa (priv_ecdhe, &pub_eddsa, &key_material); | 204 | GNUNET_CRYPTO_eddsa_key_get_public (&priv_eddsa, &pub_eddsa); |
205 | GNUNET_CRYPTO_ecdh_eddsa (&priv_ecdhe, &pub_eddsa, &key_material); | ||
186 | 206 | ||
187 | printf ("eddsa_ecdh:\n"); | 207 | printf ("eddsa_ecdh:\n"); |
188 | display_data (" priv_ecdhe", priv_ecdhe, sizeof (struct | 208 | display_data (" priv_ecdhe", |
189 | GNUNET_CRYPTO_EcdhePrivateKey)); | 209 | &priv_ecdhe, |
190 | display_data (" pub_ecdhe", &pub_ecdhe, sizeof (struct | 210 | sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey)); |
191 | GNUNET_CRYPTO_EcdhePublicKey)); | 211 | display_data (" pub_ecdhe", |
192 | display_data (" priv_eddsa", priv_eddsa, sizeof (struct | 212 | &pub_ecdhe, |
193 | GNUNET_CRYPTO_EddsaPrivateKey)); | 213 | sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); |
194 | display_data (" pub_eddsa", &pub_eddsa, sizeof (struct | 214 | display_data (" priv_eddsa", |
195 | GNUNET_CRYPTO_EddsaPublicKey)); | 215 | &priv_eddsa, |
196 | display_data (" key_material", &key_material, sizeof (struct | 216 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); |
197 | GNUNET_HashCode)); | 217 | display_data (" pub_eddsa", |
218 | &pub_eddsa, | ||
219 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); | ||
220 | display_data (" key_material", | ||
221 | &key_material, | ||
222 | sizeof (struct GNUNET_HashCode)); | ||
198 | } | 223 | } |
199 | 224 | ||
200 | { | 225 | { |
diff --git a/src/util/gnunet-ecc.c b/src/util/gnunet-ecc.c index 02d2020ad..764a507b6 100644 --- a/src/util/gnunet-ecc.c +++ b/src/util/gnunet-ecc.c | |||
@@ -79,7 +79,7 @@ static void | |||
79 | create_keys (const char *fn, const char *prefix) | 79 | create_keys (const char *fn, const char *prefix) |
80 | { | 80 | { |
81 | FILE *f; | 81 | FILE *f; |
82 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 82 | struct GNUNET_CRYPTO_EddsaPrivateKey pk; |
83 | struct GNUNET_CRYPTO_EddsaPublicKey target_pub; | 83 | struct GNUNET_CRYPTO_EddsaPublicKey target_pub; |
84 | static char vanity[KEY_STR_LEN + 1]; | 84 | static char vanity[KEY_STR_LEN + 1]; |
85 | size_t len; | 85 | size_t len; |
@@ -141,17 +141,16 @@ create_keys (const char *fn, const char *prefix) | |||
141 | while (0 < make_keys--) | 141 | while (0 < make_keys--) |
142 | { | 142 | { |
143 | fprintf (stderr, "."); | 143 | fprintf (stderr, "."); |
144 | if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create ())) | 144 | GNUNET_CRYPTO_eddsa_key_create (&pk); |
145 | { | ||
146 | GNUNET_break (0); | ||
147 | break; | ||
148 | } | ||
149 | if (NULL != prefix) | 145 | if (NULL != prefix) |
150 | { | 146 | { |
151 | struct GNUNET_CRYPTO_EddsaPublicKey newkey; | 147 | struct GNUNET_CRYPTO_EddsaPublicKey newkey; |
152 | 148 | ||
153 | GNUNET_CRYPTO_eddsa_key_get_public (pk, &newkey); | 149 | GNUNET_CRYPTO_eddsa_key_get_public (&pk, |
154 | if (0 != memcmp (&target_pub, &newkey, n)) | 150 | &newkey); |
151 | if (0 != memcmp (&target_pub, | ||
152 | &newkey, | ||
153 | n)) | ||
155 | { | 154 | { |
156 | make_keys++; | 155 | make_keys++; |
157 | continue; | 156 | continue; |
@@ -169,16 +168,17 @@ create_keys (const char *fn, const char *prefix) | |||
169 | } | 168 | } |
170 | } | 169 | } |
171 | if (GNUNET_TESTING_HOSTKEYFILESIZE != | 170 | if (GNUNET_TESTING_HOSTKEYFILESIZE != |
172 | fwrite (pk, 1, GNUNET_TESTING_HOSTKEYFILESIZE, f)) | 171 | fwrite (&pk, |
172 | 1, | ||
173 | GNUNET_TESTING_HOSTKEYFILESIZE, | ||
174 | f)) | ||
173 | { | 175 | { |
174 | fprintf (stderr, | 176 | fprintf (stderr, |
175 | _ ("\nFailed to write to `%s': %s\n"), | 177 | _ ("\nFailed to write to `%s': %s\n"), |
176 | fn, | 178 | fn, |
177 | strerror (errno)); | 179 | strerror (errno)); |
178 | GNUNET_free (pk); | ||
179 | break; | 180 | break; |
180 | } | 181 | } |
181 | GNUNET_free (pk); | ||
182 | } | 182 | } |
183 | if (UINT_MAX == make_keys) | 183 | if (UINT_MAX == make_keys) |
184 | fprintf (stderr, _ ("\nFinished!\n")); | 184 | fprintf (stderr, _ ("\nFinished!\n")); |
@@ -201,49 +201,75 @@ print_hex (const char *msg, const void *buf, size_t size) | |||
201 | 201 | ||
202 | 202 | ||
203 | static void | 203 | static void |
204 | print_examples_ecdh () | 204 | print_examples_ecdh (void) |
205 | { | 205 | { |
206 | struct GNUNET_CRYPTO_EcdhePrivateKey *dh_priv1; | 206 | struct GNUNET_CRYPTO_EcdhePrivateKey dh_priv1; |
207 | struct GNUNET_CRYPTO_EcdhePublicKey *dh_pub1; | 207 | struct GNUNET_CRYPTO_EcdhePublicKey dh_pub1; |
208 | struct GNUNET_CRYPTO_EcdhePrivateKey *dh_priv2; | 208 | struct GNUNET_CRYPTO_EcdhePrivateKey dh_priv2; |
209 | struct GNUNET_CRYPTO_EcdhePublicKey *dh_pub2; | 209 | struct GNUNET_CRYPTO_EcdhePublicKey dh_pub2; |
210 | struct GNUNET_HashCode hash; | 210 | struct GNUNET_HashCode hash; |
211 | char buf[128]; | 211 | char buf[128]; |
212 | 212 | ||
213 | dh_pub1 = GNUNET_new (struct GNUNET_CRYPTO_EcdhePublicKey); | 213 | GNUNET_CRYPTO_ecdhe_key_create (&dh_priv1); |
214 | dh_priv1 = GNUNET_CRYPTO_ecdhe_key_create (); | 214 | GNUNET_CRYPTO_ecdhe_key_create (&dh_priv2); |
215 | dh_pub2 = GNUNET_new (struct GNUNET_CRYPTO_EcdhePublicKey); | 215 | GNUNET_CRYPTO_ecdhe_key_get_public (&dh_priv1, |
216 | dh_priv2 = GNUNET_CRYPTO_ecdhe_key_create (); | 216 | &dh_pub1); |
217 | GNUNET_CRYPTO_ecdhe_key_get_public (dh_priv1, dh_pub1); | 217 | GNUNET_CRYPTO_ecdhe_key_get_public (&dh_priv2, |
218 | GNUNET_CRYPTO_ecdhe_key_get_public (dh_priv2, dh_pub2); | 218 | &dh_pub2); |
219 | 219 | ||
220 | GNUNET_assert (NULL != | 220 | GNUNET_assert (NULL != |
221 | GNUNET_STRINGS_data_to_string (dh_priv1, 32, buf, 128)); | 221 | GNUNET_STRINGS_data_to_string (&dh_priv1, |
222 | sizeof (dh_priv1), | ||
223 | buf, | ||
224 | sizeof (buf))); | ||
222 | printf ("ECDHE key 1:\n"); | 225 | printf ("ECDHE key 1:\n"); |
223 | printf ("private: %s\n", buf); | 226 | printf ("private: %s\n", |
224 | print_hex ("private(hex)", dh_priv1, sizeof *dh_priv1); | 227 | buf); |
225 | GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_pub1, 32, buf, 128)); | 228 | print_hex ("private(hex)", |
226 | printf ("public: %s\n", buf); | 229 | &dh_priv1, sizeof (dh_priv1)); |
227 | print_hex ("public(hex)", dh_pub1, sizeof *dh_pub1); | 230 | GNUNET_assert (NULL != |
231 | GNUNET_STRINGS_data_to_string (&dh_pub1, | ||
232 | sizeof (dh_pub1), | ||
233 | buf, | ||
234 | sizeof (buf))); | ||
235 | printf ("public: %s\n", | ||
236 | buf); | ||
237 | print_hex ("public(hex)", | ||
238 | &dh_pub1, | ||
239 | sizeof (dh_pub1)); | ||
228 | 240 | ||
229 | GNUNET_assert (NULL != | 241 | GNUNET_assert (NULL != |
230 | GNUNET_STRINGS_data_to_string (dh_priv2, 32, buf, 128)); | 242 | GNUNET_STRINGS_data_to_string (&dh_priv2, |
243 | sizeof (dh_priv2), | ||
244 | buf, | ||
245 | sizeof (buf))); | ||
231 | printf ("ECDHE key 2:\n"); | 246 | printf ("ECDHE key 2:\n"); |
232 | printf ("private: %s\n", buf); | 247 | printf ("private: %s\n", buf); |
233 | print_hex ("private(hex)", dh_priv2, sizeof *dh_priv2); | 248 | print_hex ("private(hex)", |
234 | GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_pub2, 32, buf, 128)); | 249 | &dh_priv2, |
250 | sizeof (dh_priv2)); | ||
251 | GNUNET_assert (NULL != | ||
252 | GNUNET_STRINGS_data_to_string (&dh_pub2, | ||
253 | sizeof (dh_pub2), | ||
254 | buf, | ||
255 | sizeof (buf))); | ||
235 | printf ("public: %s\n", buf); | 256 | printf ("public: %s\n", buf); |
236 | print_hex ("public(hex)", dh_pub2, sizeof *dh_pub2); | 257 | print_hex ("public(hex)", |
258 | &dh_pub2, | ||
259 | sizeof (dh_pub2)); | ||
237 | 260 | ||
238 | GNUNET_assert (GNUNET_OK == | 261 | GNUNET_assert (GNUNET_OK == |
239 | GNUNET_CRYPTO_ecc_ecdh (dh_priv1, dh_pub2, &hash)); | 262 | GNUNET_CRYPTO_ecc_ecdh (&dh_priv1, |
240 | GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (&hash, 64, buf, 128)); | 263 | &dh_pub2, |
241 | printf ("ECDH shared secret: %s\n", buf); | 264 | &hash)); |
242 | 265 | GNUNET_assert (NULL != | |
243 | GNUNET_free (dh_priv1); | 266 | GNUNET_STRINGS_data_to_string (&hash, |
244 | GNUNET_free (dh_priv2); | 267 | sizeof (hash), |
245 | GNUNET_free (dh_pub1); | 268 | buf, |
246 | GNUNET_free (dh_pub2); | 269 | sizeof (buf))); |
270 | printf ("ECDH shared secret: %s\n", | ||
271 | buf); | ||
272 | |||
247 | } | 273 | } |
248 | 274 | ||
249 | 275 | ||
@@ -251,7 +277,7 @@ print_examples_ecdh () | |||
251 | * Print some random example operations to stdout. | 277 | * Print some random example operations to stdout. |
252 | */ | 278 | */ |
253 | static void | 279 | static void |
254 | print_examples () | 280 | print_examples (void) |
255 | { | 281 | { |
256 | print_examples_ecdh (); | 282 | print_examples_ecdh (); |
257 | // print_examples_ecdsa (); | 283 | // print_examples_ecdsa (); |
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c index bc8ce83c0..8c46136b9 100644 --- a/src/util/gnunet-scrypt.c +++ b/src/util/gnunet-scrypt.c | |||
@@ -174,7 +174,7 @@ run (void *cls, | |||
174 | const char *cfgfile, | 174 | const char *cfgfile, |
175 | const struct GNUNET_CONFIGURATION_Handle *config) | 175 | const struct GNUNET_CONFIGURATION_Handle *config) |
176 | { | 176 | { |
177 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 177 | struct GNUNET_CRYPTO_EddsaPrivateKey pk; |
178 | char *pids; | 178 | char *pids; |
179 | 179 | ||
180 | (void) cls; | 180 | (void) cls; |
@@ -214,15 +214,18 @@ run (void *cls, | |||
214 | } | 214 | } |
215 | } | 215 | } |
216 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Private Key file: %s\n", pkfn); | 216 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Private Key file: %s\n", pkfn); |
217 | if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create_from_file (pkfn))) | 217 | if (GNUNET_SYSERR == |
218 | GNUNET_CRYPTO_eddsa_key_from_file (pkfn, | ||
219 | GNUNET_YES, | ||
220 | &pk)) | ||
218 | { | 221 | { |
219 | fprintf (stderr, _ ("Loading hostkey from `%s' failed.\n"), pkfn); | 222 | fprintf (stderr, _ ("Loading hostkey from `%s' failed.\n"), pkfn); |
220 | GNUNET_free (pkfn); | 223 | GNUNET_free (pkfn); |
221 | return; | 224 | return; |
222 | } | 225 | } |
223 | GNUNET_free (pkfn); | 226 | GNUNET_free (pkfn); |
224 | GNUNET_CRYPTO_eddsa_key_get_public (pk, &pub); | 227 | GNUNET_CRYPTO_eddsa_key_get_public (&pk, |
225 | GNUNET_free (pk); | 228 | &pub); |
226 | pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub); | 229 | pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub); |
227 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer ID: %s\n", pids); | 230 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer ID: %s\n", pids); |
228 | GNUNET_free (pids); | 231 | GNUNET_free (pids); |
diff --git a/src/util/os_priority.c b/src/util/os_priority.c index 722aac872..36f0d8e30 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c | |||
@@ -975,7 +975,7 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, | |||
975 | * @param proc pointer to process structure | 975 | * @param proc pointer to process structure |
976 | * @param type status type | 976 | * @param type status type |
977 | * @param code return code/signal number | 977 | * @param code return code/signal number |
978 | * @return #GNUNET_OK on success, #GNUNET_NO if the process is still running, #GNUNET_SYSERR otherwise | 978 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
979 | */ | 979 | */ |
980 | int | 980 | int |
981 | GNUNET_OS_process_wait_status (struct GNUNET_OS_Process *proc, | 981 | GNUNET_OS_process_wait_status (struct GNUNET_OS_Process *proc, |
diff --git a/src/util/test_crypto_ecdh_ecdsa.c b/src/util/test_crypto_ecdh_ecdsa.c index 8a581ef73..3cc12de9b 100644 --- a/src/util/test_crypto_ecdh_ecdsa.c +++ b/src/util/test_crypto_ecdh_ecdsa.c | |||
@@ -32,39 +32,37 @@ | |||
32 | static int | 32 | static int |
33 | test_ecdh () | 33 | test_ecdh () |
34 | { | 34 | { |
35 | struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_dsa; | 35 | struct GNUNET_CRYPTO_EcdsaPrivateKey priv_dsa; |
36 | struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ecdh; | 36 | struct GNUNET_CRYPTO_EcdhePrivateKey priv_ecdh; |
37 | struct GNUNET_CRYPTO_EcdsaPublicKey id1; | 37 | struct GNUNET_CRYPTO_EcdsaPublicKey id1; |
38 | struct GNUNET_CRYPTO_EcdhePublicKey id2; | 38 | struct GNUNET_CRYPTO_EcdhePublicKey id2; |
39 | struct GNUNET_HashCode dh[2]; | 39 | struct GNUNET_HashCode dh[2]; |
40 | 40 | ||
41 | /* Generate keys */ | 41 | /* Generate keys */ |
42 | priv_dsa = GNUNET_CRYPTO_ecdsa_key_create (); | 42 | GNUNET_CRYPTO_ecdsa_key_create (&priv_dsa); |
43 | GNUNET_CRYPTO_ecdsa_key_get_public (priv_dsa, | 43 | GNUNET_CRYPTO_ecdsa_key_get_public (&priv_dsa, |
44 | &id1); | 44 | &id1); |
45 | for (unsigned int j = 0; j < 4; j++) | 45 | for (unsigned int j = 0; j < 4; j++) |
46 | { | 46 | { |
47 | fprintf (stderr, ","); | 47 | fprintf (stderr, ","); |
48 | priv_ecdh = GNUNET_CRYPTO_ecdhe_key_create (); | 48 | GNUNET_CRYPTO_ecdhe_key_create (&priv_ecdh); |
49 | /* Extract public keys */ | 49 | /* Extract public keys */ |
50 | GNUNET_CRYPTO_ecdhe_key_get_public (priv_ecdh, | 50 | GNUNET_CRYPTO_ecdhe_key_get_public (&priv_ecdh, |
51 | &id2); | 51 | &id2); |
52 | /* Do ECDH */ | 52 | /* Do ECDH */ |
53 | GNUNET_assert (GNUNET_OK == | 53 | GNUNET_assert (GNUNET_OK == |
54 | GNUNET_CRYPTO_ecdsa_ecdh (priv_dsa, | 54 | GNUNET_CRYPTO_ecdsa_ecdh (&priv_dsa, |
55 | &id2, | 55 | &id2, |
56 | &dh[0])); | 56 | &dh[0])); |
57 | GNUNET_assert (GNUNET_OK == | 57 | GNUNET_assert (GNUNET_OK == |
58 | GNUNET_CRYPTO_ecdh_ecdsa (priv_ecdh, | 58 | GNUNET_CRYPTO_ecdh_ecdsa (&priv_ecdh, |
59 | &id1, | 59 | &id1, |
60 | &dh[1])); | 60 | &dh[1])); |
61 | /* Check that both DH results are equal. */ | 61 | /* Check that both DH results are equal. */ |
62 | GNUNET_assert (0 == memcmp (&dh[0], | 62 | GNUNET_assert (0 == |
63 | &dh[1], | 63 | GNUNET_memcmp (&dh[0], |
64 | sizeof(struct GNUNET_HashCode))); | 64 | &dh[1])); |
65 | GNUNET_free (priv_ecdh); | ||
66 | } | 65 | } |
67 | GNUNET_free (priv_dsa); | ||
68 | return 0; | 66 | return 0; |
69 | } | 67 | } |
70 | 68 | ||
@@ -75,8 +73,7 @@ main (int argc, char *argv[]) | |||
75 | if (! gcry_check_version ("1.6.0")) | 73 | if (! gcry_check_version ("1.6.0")) |
76 | { | 74 | { |
77 | fprintf (stderr, | 75 | fprintf (stderr, |
78 | _ ( | 76 | "libgcrypt has not the expected version (version %s is required).\n", |
79 | "libgcrypt has not the expected version (version %s is required).\n"), | ||
80 | "1.6.0"); | 77 | "1.6.0"); |
81 | return 0; | 78 | return 0; |
82 | } | 79 | } |
diff --git a/src/util/test_crypto_ecdh_eddsa.c b/src/util/test_crypto_ecdh_eddsa.c index 68f8c4671..6efd4d2fe 100644 --- a/src/util/test_crypto_ecdh_eddsa.c +++ b/src/util/test_crypto_ecdh_eddsa.c | |||
@@ -32,39 +32,37 @@ | |||
32 | static int | 32 | static int |
33 | test_ecdh () | 33 | test_ecdh () |
34 | { | 34 | { |
35 | struct GNUNET_CRYPTO_EddsaPrivateKey *priv_dsa; | 35 | struct GNUNET_CRYPTO_EddsaPrivateKey priv_dsa; |
36 | struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ecdh; | 36 | struct GNUNET_CRYPTO_EcdhePrivateKey priv_ecdh; |
37 | struct GNUNET_CRYPTO_EddsaPublicKey id1; | 37 | struct GNUNET_CRYPTO_EddsaPublicKey id1; |
38 | struct GNUNET_CRYPTO_EcdhePublicKey id2; | 38 | struct GNUNET_CRYPTO_EcdhePublicKey id2; |
39 | struct GNUNET_HashCode dh[2]; | 39 | struct GNUNET_HashCode dh[2]; |
40 | 40 | ||
41 | /* Generate keys */ | 41 | /* Generate keys */ |
42 | priv_dsa = GNUNET_CRYPTO_eddsa_key_create (); | 42 | GNUNET_CRYPTO_eddsa_key_create (&priv_dsa); |
43 | GNUNET_CRYPTO_eddsa_key_get_public (priv_dsa, | 43 | GNUNET_CRYPTO_eddsa_key_get_public (&priv_dsa, |
44 | &id1); | 44 | &id1); |
45 | for (unsigned int j = 0; j < 4; j++) | 45 | for (unsigned int j = 0; j < 4; j++) |
46 | { | 46 | { |
47 | fprintf (stderr, ","); | 47 | fprintf (stderr, ","); |
48 | priv_ecdh = GNUNET_CRYPTO_ecdhe_key_create (); | 48 | GNUNET_CRYPTO_ecdhe_key_create (&priv_ecdh); |
49 | /* Extract public keys */ | 49 | /* Extract public keys */ |
50 | GNUNET_CRYPTO_ecdhe_key_get_public (priv_ecdh, | 50 | GNUNET_CRYPTO_ecdhe_key_get_public (&priv_ecdh, |
51 | &id2); | 51 | &id2); |
52 | /* Do ECDH */ | 52 | /* Do ECDH */ |
53 | GNUNET_assert (GNUNET_OK == | 53 | GNUNET_assert (GNUNET_OK == |
54 | GNUNET_CRYPTO_eddsa_ecdh (priv_dsa, | 54 | GNUNET_CRYPTO_eddsa_ecdh (&priv_dsa, |
55 | &id2, | 55 | &id2, |
56 | &dh[0])); | 56 | &dh[0])); |
57 | GNUNET_assert (GNUNET_OK == | 57 | GNUNET_assert (GNUNET_OK == |
58 | GNUNET_CRYPTO_ecdh_eddsa (priv_ecdh, | 58 | GNUNET_CRYPTO_ecdh_eddsa (&priv_ecdh, |
59 | &id1, | 59 | &id1, |
60 | &dh[1])); | 60 | &dh[1])); |
61 | /* Check that both DH results are equal. */ | 61 | /* Check that both DH results are equal. */ |
62 | GNUNET_assert (0 == memcmp (&dh[0], | 62 | GNUNET_assert (0 == |
63 | &dh[1], | 63 | GNUNET_memcmp (&dh[0], |
64 | sizeof(struct GNUNET_HashCode))); | 64 | &dh[1])); |
65 | GNUNET_free (priv_ecdh); | ||
66 | } | 65 | } |
67 | GNUNET_free (priv_dsa); | ||
68 | return 0; | 66 | return 0; |
69 | } | 67 | } |
70 | 68 | ||
diff --git a/src/util/test_crypto_ecdhe.c b/src/util/test_crypto_ecdhe.c index 6f91be746..1144f1fe5 100644 --- a/src/util/test_crypto_ecdhe.c +++ b/src/util/test_crypto_ecdhe.c | |||
@@ -31,8 +31,8 @@ | |||
31 | int | 31 | int |
32 | main (int argc, char *argv[]) | 32 | main (int argc, char *argv[]) |
33 | { | 33 | { |
34 | struct GNUNET_CRYPTO_EcdhePrivateKey *priv1; | 34 | struct GNUNET_CRYPTO_EcdhePrivateKey priv1; |
35 | struct GNUNET_CRYPTO_EcdhePrivateKey *priv2; | 35 | struct GNUNET_CRYPTO_EcdhePrivateKey priv2; |
36 | struct GNUNET_CRYPTO_EcdhePublicKey pub1; | 36 | struct GNUNET_CRYPTO_EcdhePublicKey pub1; |
37 | struct GNUNET_CRYPTO_EcdhePublicKey pub2; | 37 | struct GNUNET_CRYPTO_EcdhePublicKey pub2; |
38 | struct GNUNET_HashCode ecdh1; | 38 | struct GNUNET_HashCode ecdh1; |
@@ -41,9 +41,7 @@ main (int argc, char *argv[]) | |||
41 | if (! gcry_check_version ("1.6.0")) | 41 | if (! gcry_check_version ("1.6.0")) |
42 | { | 42 | { |
43 | fprintf (stderr, | 43 | fprintf (stderr, |
44 | _ | 44 | "libgcrypt has not the expected version (version %s is required).\n", |
45 | ( | ||
46 | "libgcrypt has not the expected version (version %s is required).\n"), | ||
47 | "1.6.0"); | 45 | "1.6.0"); |
48 | return 0; | 46 | return 0; |
49 | } | 47 | } |
@@ -55,16 +53,15 @@ main (int argc, char *argv[]) | |||
55 | { | 53 | { |
56 | fprintf (stderr, | 54 | fprintf (stderr, |
57 | "."); | 55 | "."); |
58 | priv1 = GNUNET_CRYPTO_ecdhe_key_create (); | 56 | GNUNET_CRYPTO_ecdhe_key_create (&priv1); |
59 | priv2 = GNUNET_CRYPTO_ecdhe_key_create (); | 57 | GNUNET_CRYPTO_ecdhe_key_create (&priv2); |
60 | GNUNET_CRYPTO_ecdhe_key_get_public (priv1, &pub1); | 58 | GNUNET_CRYPTO_ecdhe_key_get_public (&priv1, &pub1); |
61 | GNUNET_CRYPTO_ecdhe_key_get_public (priv2, &pub2); | 59 | GNUNET_CRYPTO_ecdhe_key_get_public (&priv2, &pub2); |
62 | GNUNET_CRYPTO_ecc_ecdh (priv1, &pub2, &ecdh1); | 60 | GNUNET_CRYPTO_ecc_ecdh (&priv1, &pub2, &ecdh1); |
63 | GNUNET_CRYPTO_ecc_ecdh (priv2, &pub1, &ecdh2); | 61 | GNUNET_CRYPTO_ecc_ecdh (&priv2, &pub1, &ecdh2); |
64 | GNUNET_assert (0 == memcmp (&ecdh1, &ecdh2, | 62 | GNUNET_assert (0 == |
65 | sizeof(struct GNUNET_HashCode))); | 63 | GNUNET_memcmp (&ecdh1, |
66 | GNUNET_free (priv1); | 64 | &ecdh2)); |
67 | GNUNET_free (priv2); | ||
68 | } | 65 | } |
69 | return 0; | 66 | return 0; |
70 | } | 67 | } |
diff --git a/src/util/test_crypto_ecdsa.c b/src/util/test_crypto_ecdsa.c index 190c58d7d..cfa236d6d 100644 --- a/src/util/test_crypto_ecdsa.c +++ b/src/util/test_crypto_ecdsa.c | |||
@@ -33,65 +33,74 @@ | |||
33 | #define PERF GNUNET_YES | 33 | #define PERF GNUNET_YES |
34 | 34 | ||
35 | 35 | ||
36 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *key; | 36 | static struct GNUNET_CRYPTO_EcdsaPrivateKey key; |
37 | 37 | ||
38 | 38 | ||
39 | static int | 39 | static int |
40 | testSignVerify () | 40 | testSignVerify (void) |
41 | { | 41 | { |
42 | struct GNUNET_CRYPTO_EcdsaSignature sig; | 42 | struct GNUNET_CRYPTO_EcdsaSignature sig; |
43 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; | 43 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; |
44 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 44 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
45 | int i; | ||
46 | struct GNUNET_TIME_Absolute start; | 45 | struct GNUNET_TIME_Absolute start; |
47 | int ok = GNUNET_OK; | 46 | int ok = GNUNET_OK; |
48 | 47 | ||
49 | fprintf (stderr, "%s", "W"); | 48 | fprintf (stderr, "%s", "W"); |
50 | GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey); | 49 | GNUNET_CRYPTO_ecdsa_key_get_public (&key, |
50 | &pkey); | ||
51 | start = GNUNET_TIME_absolute_get (); | 51 | start = GNUNET_TIME_absolute_get (); |
52 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); | 52 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); |
53 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); | 53 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
54 | 54 | ||
55 | for (i = 0; i < ITER; i++) | 55 | for (unsigned int i = 0; i < ITER; i++) |
56 | { | 56 | { |
57 | fprintf (stderr, "%s", "."); fflush (stderr); | 57 | fprintf (stderr, "%s", "."); |
58 | fflush (stderr); | ||
58 | if (GNUNET_SYSERR == | 59 | if (GNUNET_SYSERR == |
59 | GNUNET_CRYPTO_ecdsa_sign_ (key, &purp, &sig)) | 60 | GNUNET_CRYPTO_ecdsa_sign_ (&key, |
61 | &purp, | ||
62 | &sig)) | ||
60 | { | 63 | { |
61 | fprintf (stderr, | 64 | fprintf (stderr, |
62 | "%s", | ||
63 | "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n"); | 65 | "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n"); |
64 | ok = GNUNET_SYSERR; | 66 | ok = GNUNET_SYSERR; |
65 | continue; | 67 | continue; |
66 | } | 68 | } |
67 | if (GNUNET_SYSERR == | 69 | if (GNUNET_SYSERR == |
68 | GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TEST, | 70 | GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TEST, |
69 | &purp, &sig, | 71 | &purp, |
72 | &sig, | ||
70 | &pkey)) | 73 | &pkey)) |
71 | { | 74 | { |
72 | printf ("GNUNET_CRYPTO_ecdsa_verify failed!\n"); | 75 | fprintf (stderr, |
76 | "GNUNET_CRYPTO_ecdsa_verify failed!\n"); | ||
73 | ok = GNUNET_SYSERR; | 77 | ok = GNUNET_SYSERR; |
74 | continue; | 78 | continue; |
75 | } | 79 | } |
76 | if (GNUNET_SYSERR != | 80 | if (GNUNET_SYSERR != |
77 | GNUNET_CRYPTO_ecdsa_verify_ ( | 81 | GNUNET_CRYPTO_ecdsa_verify_ ( |
78 | GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, | 82 | GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, |
79 | &purp, &sig, &pkey)) | 83 | &purp, |
84 | &sig, | ||
85 | &pkey)) | ||
80 | { | 86 | { |
81 | printf ("GNUNET_CRYPTO_ecdsa_verify failed to fail!\n"); | 87 | fprintf (stderr, |
88 | "GNUNET_CRYPTO_ecdsa_verify failed to fail!\n"); | ||
82 | ok = GNUNET_SYSERR; | 89 | ok = GNUNET_SYSERR; |
83 | continue; | 90 | continue; |
84 | } | 91 | } |
85 | } | 92 | } |
86 | printf ("%d ECDSA sign/verify operations %s\n", ITER, | 93 | printf ("%d ECDSA sign/verify operations %s\n", |
94 | ITER, | ||
87 | GNUNET_STRINGS_relative_time_to_string ( | 95 | GNUNET_STRINGS_relative_time_to_string ( |
88 | GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); | 96 | GNUNET_TIME_absolute_get_duration (start), |
97 | GNUNET_YES)); | ||
89 | return ok; | 98 | return ok; |
90 | } | 99 | } |
91 | 100 | ||
92 | 101 | ||
93 | static int | 102 | static int |
94 | testDeriveSignVerify () | 103 | testDeriveSignVerify (void) |
95 | { | 104 | { |
96 | struct GNUNET_CRYPTO_EcdsaSignature sig; | 105 | struct GNUNET_CRYPTO_EcdsaSignature sig; |
97 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; | 106 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; |
@@ -99,15 +108,22 @@ testDeriveSignVerify () | |||
99 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 108 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
100 | struct GNUNET_CRYPTO_EcdsaPublicKey dpub; | 109 | struct GNUNET_CRYPTO_EcdsaPublicKey dpub; |
101 | 110 | ||
102 | dpriv = GNUNET_CRYPTO_ecdsa_private_key_derive (key, "test-derive", | 111 | dpriv = GNUNET_CRYPTO_ecdsa_private_key_derive (&key, |
112 | "test-derive", | ||
103 | "test-CTX"); | 113 | "test-CTX"); |
104 | GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey); | 114 | GNUNET_CRYPTO_ecdsa_key_get_public (&key, |
105 | GNUNET_CRYPTO_ecdsa_public_key_derive (&pkey, "test-derive", "test-CTX", | 115 | &pkey); |
116 | GNUNET_CRYPTO_ecdsa_public_key_derive (&pkey, | ||
117 | "test-derive", | ||
118 | "test-CTX", | ||
106 | &dpub); | 119 | &dpub); |
107 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); | 120 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); |
108 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); | 121 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
109 | 122 | ||
110 | if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign_ (dpriv, &purp, &sig)) | 123 | if (GNUNET_SYSERR == |
124 | GNUNET_CRYPTO_ecdsa_sign_ (dpriv, | ||
125 | &purp, | ||
126 | &sig)) | ||
111 | { | 127 | { |
112 | fprintf (stderr, "%s", "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n"); | 128 | fprintf (stderr, "%s", "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n"); |
113 | GNUNET_free (dpriv); | 129 | GNUNET_free (dpriv); |
@@ -115,27 +131,34 @@ testDeriveSignVerify () | |||
115 | } | 131 | } |
116 | if (GNUNET_SYSERR == | 132 | if (GNUNET_SYSERR == |
117 | GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TEST, | 133 | GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TEST, |
118 | &purp, &sig, | 134 | &purp, |
135 | &sig, | ||
119 | &dpub)) | 136 | &dpub)) |
120 | { | 137 | { |
121 | printf ("GNUNET_CRYPTO_ecdsa_verify failed!\n"); | 138 | fprintf (stderr, |
139 | "GNUNET_CRYPTO_ecdsa_verify failed!\n"); | ||
122 | GNUNET_free (dpriv); | 140 | GNUNET_free (dpriv); |
123 | return GNUNET_SYSERR; | 141 | return GNUNET_SYSERR; |
124 | } | 142 | } |
125 | if (GNUNET_SYSERR != | 143 | if (GNUNET_SYSERR != |
126 | GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TEST, | 144 | GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TEST, |
127 | &purp, &sig, | 145 | &purp, |
146 | &sig, | ||
128 | &pkey)) | 147 | &pkey)) |
129 | { | 148 | { |
130 | printf ("GNUNET_CRYPTO_ecdsa_verify failed to fail!\n"); | 149 | fprintf (stderr, |
150 | "GNUNET_CRYPTO_ecdsa_verify failed to fail!\n"); | ||
131 | GNUNET_free (dpriv); | 151 | GNUNET_free (dpriv); |
132 | return GNUNET_SYSERR; | 152 | return GNUNET_SYSERR; |
133 | } | 153 | } |
134 | if (GNUNET_SYSERR != | 154 | if (GNUNET_SYSERR != |
135 | GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, | 155 | GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, |
136 | &purp, &sig, &dpub)) | 156 | &purp, |
157 | &sig, | ||
158 | &dpub)) | ||
137 | { | 159 | { |
138 | printf ("GNUNET_CRYPTO_ecdsa_verify failed to fail!\n"); | 160 | fprintf (stderr, |
161 | "GNUNET_CRYPTO_ecdsa_verify failed to fail!\n"); | ||
139 | GNUNET_free (dpriv); | 162 | GNUNET_free (dpriv); |
140 | return GNUNET_SYSERR; | 163 | return GNUNET_SYSERR; |
141 | } | 164 | } |
@@ -146,7 +169,7 @@ testDeriveSignVerify () | |||
146 | 169 | ||
147 | #if PERF | 170 | #if PERF |
148 | static int | 171 | static int |
149 | testSignPerformance () | 172 | testSignPerformance (void) |
150 | { | 173 | { |
151 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; | 174 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; |
152 | struct GNUNET_CRYPTO_EcdsaSignature sig; | 175 | struct GNUNET_CRYPTO_EcdsaSignature sig; |
@@ -183,26 +206,24 @@ testSignPerformance () | |||
183 | 206 | ||
184 | 207 | ||
185 | static void | 208 | static void |
186 | perf_keygen () | 209 | perf_keygen (void) |
187 | { | 210 | { |
188 | struct GNUNET_TIME_Absolute start; | 211 | struct GNUNET_TIME_Absolute start; |
189 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; | 212 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; |
190 | int i; | ||
191 | 213 | ||
192 | fprintf (stderr, "%s", "W"); | 214 | fprintf (stderr, "%s", "W"); |
193 | start = GNUNET_TIME_absolute_get (); | 215 | start = GNUNET_TIME_absolute_get (); |
194 | for (i = 0; i < 10; i++) | 216 | for (unsigned int i = 0; i < 10; i++) |
195 | { | 217 | { |
196 | fprintf (stderr, "."); fflush (stderr); | ||
197 | pk = GNUNET_CRYPTO_ecdsa_key_create (); | ||
198 | GNUNET_free (pk); | ||
199 | } | ||
200 | for (; i < 25; i++) | ||
201 | fprintf (stderr, "."); | 218 | fprintf (stderr, "."); |
219 | fflush (stderr); | ||
220 | GNUNET_CRYPTO_ecdsa_key_create (&pk); | ||
221 | } | ||
202 | fflush (stderr); | 222 | fflush (stderr); |
203 | printf ("10 ECDSA keys created in %s\n", | 223 | printf ("10 ECDSA keys created in %s\n", |
204 | GNUNET_STRINGS_relative_time_to_string ( | 224 | GNUNET_STRINGS_relative_time_to_string ( |
205 | GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); | 225 | GNUNET_TIME_absolute_get_duration (start), |
226 | GNUNET_YES)); | ||
206 | } | 227 | } |
207 | 228 | ||
208 | 229 | ||
@@ -214,16 +235,14 @@ main (int argc, char *argv[]) | |||
214 | if (! gcry_check_version ("1.6.0")) | 235 | if (! gcry_check_version ("1.6.0")) |
215 | { | 236 | { |
216 | fprintf (stderr, | 237 | fprintf (stderr, |
217 | _ | 238 | "libgcrypt has not the expected version (version %s is required).\n", |
218 | ( | ||
219 | "libgcrypt has not the expected version (version %s is required).\n"), | ||
220 | "1.6.0"); | 239 | "1.6.0"); |
221 | return 0; | 240 | return 0; |
222 | } | 241 | } |
223 | if (getenv ("GNUNET_GCRYPT_DEBUG")) | 242 | if (getenv ("GNUNET_GCRYPT_DEBUG")) |
224 | gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0); | 243 | gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0); |
225 | GNUNET_log_setup ("test-crypto-ecc", "WARNING", NULL); | 244 | GNUNET_log_setup ("test-crypto-ecc", "WARNING", NULL); |
226 | key = GNUNET_CRYPTO_ecdsa_key_create (); | 245 | GNUNET_CRYPTO_ecdsa_key_create (&key); |
227 | if (GNUNET_OK != testDeriveSignVerify ()) | 246 | if (GNUNET_OK != testDeriveSignVerify ()) |
228 | { | 247 | { |
229 | failure_count++; | 248 | failure_count++; |
@@ -237,7 +256,6 @@ main (int argc, char *argv[]) | |||
237 | #endif | 256 | #endif |
238 | if (GNUNET_OK != testSignVerify ()) | 257 | if (GNUNET_OK != testSignVerify ()) |
239 | failure_count++; | 258 | failure_count++; |
240 | GNUNET_free (key); | ||
241 | perf_keygen (); | 259 | perf_keygen (); |
242 | 260 | ||
243 | if (0 != failure_count) | 261 | if (0 != failure_count) |
diff --git a/src/util/test_crypto_eddsa.c b/src/util/test_crypto_eddsa.c index 87990cbac..5baf696b1 100644 --- a/src/util/test_crypto_eddsa.c +++ b/src/util/test_crypto_eddsa.c | |||
@@ -35,11 +35,11 @@ | |||
35 | #define PERF GNUNET_YES | 35 | #define PERF GNUNET_YES |
36 | 36 | ||
37 | 37 | ||
38 | static struct GNUNET_CRYPTO_EddsaPrivateKey *key; | 38 | static struct GNUNET_CRYPTO_EddsaPrivateKey key; |
39 | 39 | ||
40 | 40 | ||
41 | static int | 41 | static int |
42 | testSignVerify () | 42 | testSignVerify (void) |
43 | { | 43 | { |
44 | struct GNUNET_CRYPTO_EddsaSignature sig; | 44 | struct GNUNET_CRYPTO_EddsaSignature sig; |
45 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; | 45 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; |
@@ -48,7 +48,8 @@ testSignVerify () | |||
48 | int ok = GNUNET_OK; | 48 | int ok = GNUNET_OK; |
49 | 49 | ||
50 | fprintf (stderr, "%s", "W"); | 50 | fprintf (stderr, "%s", "W"); |
51 | GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey); | 51 | GNUNET_CRYPTO_eddsa_key_get_public (&key, |
52 | &pkey); | ||
52 | start = GNUNET_TIME_absolute_get (); | 53 | start = GNUNET_TIME_absolute_get (); |
53 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); | 54 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); |
54 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); | 55 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
@@ -56,34 +57,45 @@ testSignVerify () | |||
56 | for (unsigned int i = 0; i < ITER; i++) | 57 | for (unsigned int i = 0; i < ITER; i++) |
57 | { | 58 | { |
58 | fprintf (stderr, "%s", "."); fflush (stderr); | 59 | fprintf (stderr, "%s", "."); fflush (stderr); |
59 | if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign_ (key, &purp, &sig)) | 60 | if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign_ (&key, |
61 | &purp, | ||
62 | &sig)) | ||
60 | { | 63 | { |
61 | fprintf (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n"); | 64 | fprintf (stderr, |
65 | "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n"); | ||
62 | ok = GNUNET_SYSERR; | 66 | ok = GNUNET_SYSERR; |
63 | continue; | 67 | continue; |
64 | } | 68 | } |
65 | if (GNUNET_SYSERR == | 69 | if (GNUNET_SYSERR == |
66 | GNUNET_CRYPTO_eddsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TEST, &purp, &sig, | 70 | GNUNET_CRYPTO_eddsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TEST, |
71 | &purp, | ||
72 | &sig, | ||
67 | &pkey)) | 73 | &pkey)) |
68 | { | 74 | { |
69 | printf ("GNUNET_CRYPTO_eddsa_verify failed!\n"); | 75 | fprintf (stderr, |
76 | "GNUNET_CRYPTO_eddsa_verify failed!\n"); | ||
70 | ok = GNUNET_SYSERR; | 77 | ok = GNUNET_SYSERR; |
71 | continue; | 78 | continue; |
72 | } | 79 | } |
73 | if (GNUNET_SYSERR != | 80 | if (GNUNET_SYSERR != |
74 | GNUNET_CRYPTO_eddsa_verify_ ( | 81 | GNUNET_CRYPTO_eddsa_verify_ ( |
75 | GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, | 82 | GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, |
76 | &purp, &sig, &pkey)) | 83 | &purp, |
84 | &sig, | ||
85 | &pkey)) | ||
77 | { | 86 | { |
78 | printf ("GNUNET_CRYPTO_eddsa_verify failed to fail!\n"); | 87 | fprintf (stderr, |
88 | "GNUNET_CRYPTO_eddsa_verify failed to fail!\n"); | ||
79 | ok = GNUNET_SYSERR; | 89 | ok = GNUNET_SYSERR; |
80 | continue; | 90 | continue; |
81 | } | 91 | } |
82 | } | 92 | } |
83 | fprintf (stderr, "\n"); | 93 | fprintf (stderr, "\n"); |
84 | printf ("%d EdDSA sign/verify operations %s\n", ITER, | 94 | printf ("%d EdDSA sign/verify operations %s\n", |
95 | ITER, | ||
85 | GNUNET_STRINGS_relative_time_to_string ( | 96 | GNUNET_STRINGS_relative_time_to_string ( |
86 | GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); | 97 | GNUNET_TIME_absolute_get_duration (start), |
98 | GNUNET_YES)); | ||
87 | return ok; | 99 | return ok; |
88 | } | 100 | } |
89 | 101 | ||
@@ -101,12 +113,17 @@ testSignPerformance () | |||
101 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); | 113 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); |
102 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); | 114 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
103 | fprintf (stderr, "%s", "W"); | 115 | fprintf (stderr, "%s", "W"); |
104 | GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey); | 116 | GNUNET_CRYPTO_eddsa_key_get_public (&key, |
117 | &pkey); | ||
105 | start = GNUNET_TIME_absolute_get (); | 118 | start = GNUNET_TIME_absolute_get (); |
106 | for (unsigned int i = 0; i < ITER; i++) | 119 | for (unsigned int i = 0; i < ITER; i++) |
107 | { | 120 | { |
108 | fprintf (stderr, "%s", "."); fflush (stderr); | 121 | fprintf (stderr, "%s", "."); |
109 | if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign_ (key, &purp, &sig)) | 122 | fflush (stderr); |
123 | if (GNUNET_SYSERR == | ||
124 | GNUNET_CRYPTO_eddsa_sign_ (&key, | ||
125 | &purp, | ||
126 | &sig)) | ||
110 | { | 127 | { |
111 | fprintf (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n"); | 128 | fprintf (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n"); |
112 | ok = GNUNET_SYSERR; | 129 | ok = GNUNET_SYSERR; |
@@ -114,7 +131,8 @@ testSignPerformance () | |||
114 | } | 131 | } |
115 | } | 132 | } |
116 | fprintf (stderr, "\n"); | 133 | fprintf (stderr, "\n"); |
117 | printf ("%d EdDSA sign operations %s\n", ITER, | 134 | printf ("%d EdDSA sign operations %s\n", |
135 | ITER, | ||
118 | GNUNET_STRINGS_relative_time_to_string ( | 136 | GNUNET_STRINGS_relative_time_to_string ( |
119 | GNUNET_TIME_absolute_get_duration (start), | 137 | GNUNET_TIME_absolute_get_duration (start), |
120 | GNUNET_YES)); | 138 | GNUNET_YES)); |
@@ -126,43 +144,53 @@ testSignPerformance () | |||
126 | 144 | ||
127 | 145 | ||
128 | static int | 146 | static int |
129 | testCreateFromFile () | 147 | testCreateFromFile (void) |
130 | { | 148 | { |
131 | struct GNUNET_CRYPTO_EddsaPublicKey p1; | 149 | struct GNUNET_CRYPTO_EddsaPublicKey p1; |
132 | struct GNUNET_CRYPTO_EddsaPublicKey p2; | 150 | struct GNUNET_CRYPTO_EddsaPublicKey p2; |
133 | 151 | ||
134 | key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE); | 152 | GNUNET_assert (0 <= |
135 | GNUNET_assert (NULL != key); | 153 | GNUNET_CRYPTO_eddsa_key_from_file (KEYFILE, |
136 | GNUNET_CRYPTO_eddsa_key_get_public (key, &p1); | 154 | GNUNET_YES, |
137 | GNUNET_free (key); | 155 | &key)); |
138 | key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE); | 156 | GNUNET_CRYPTO_eddsa_key_get_public (&key, |
139 | GNUNET_assert (NULL != key); | 157 | &p1); |
140 | GNUNET_CRYPTO_eddsa_key_get_public (key, &p2); | 158 | GNUNET_assert (GNUNET_NO == |
141 | GNUNET_assert (0 == memcmp (&p1, &p2, sizeof(p1))); | 159 | GNUNET_CRYPTO_eddsa_key_from_file (KEYFILE, |
142 | GNUNET_free (key); | 160 | GNUNET_YES, |
161 | &key)); | ||
162 | GNUNET_CRYPTO_eddsa_key_get_public (&key, | ||
163 | &p2); | ||
164 | GNUNET_assert (0 == | ||
165 | GNUNET_memcmp (&p1, | ||
166 | &p2)); | ||
143 | GNUNET_assert (0 == unlink (KEYFILE)); | 167 | GNUNET_assert (0 == unlink (KEYFILE)); |
144 | key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE); | 168 | GNUNET_assert (GNUNET_OK == |
145 | GNUNET_assert (NULL != key); | 169 | GNUNET_CRYPTO_eddsa_key_from_file (KEYFILE, |
146 | GNUNET_CRYPTO_eddsa_key_get_public (key, &p2); | 170 | GNUNET_NO, |
147 | GNUNET_assert (0 != memcmp (&p1, &p2, sizeof(p1))); | 171 | &key)); |
148 | GNUNET_free (key); | 172 | GNUNET_CRYPTO_eddsa_key_get_public (&key, |
173 | &p2); | ||
174 | GNUNET_assert (0 != | ||
175 | GNUNET_memcmp (&p1, | ||
176 | &p2)); | ||
149 | return GNUNET_OK; | 177 | return GNUNET_OK; |
150 | } | 178 | } |
151 | 179 | ||
152 | 180 | ||
153 | static void | 181 | static void |
154 | perf_keygen () | 182 | perf_keygen (void) |
155 | { | 183 | { |
156 | struct GNUNET_TIME_Absolute start; | 184 | struct GNUNET_TIME_Absolute start; |
157 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 185 | struct GNUNET_CRYPTO_EddsaPrivateKey pk; |
158 | 186 | ||
159 | fprintf (stderr, "%s", "W"); | 187 | fprintf (stderr, "%s", "W"); |
160 | start = GNUNET_TIME_absolute_get (); | 188 | start = GNUNET_TIME_absolute_get (); |
161 | for (unsigned int i = 0; i < 10; i++) | 189 | for (unsigned int i = 0; i < 10; i++) |
162 | { | 190 | { |
163 | fprintf (stderr, "."); fflush (stderr); | 191 | fprintf (stderr, "."); |
164 | pk = GNUNET_CRYPTO_eddsa_key_create (); | 192 | fflush (stderr); |
165 | GNUNET_free (pk); | 193 | GNUNET_CRYPTO_eddsa_key_create (&pk); |
166 | } | 194 | } |
167 | fprintf (stderr, "\n"); | 195 | fprintf (stderr, "\n"); |
168 | printf ("10 EdDSA keys created in %s\n", | 196 | printf ("10 EdDSA keys created in %s\n", |
@@ -179,22 +207,22 @@ main (int argc, char *argv[]) | |||
179 | if (! gcry_check_version ("1.6.0")) | 207 | if (! gcry_check_version ("1.6.0")) |
180 | { | 208 | { |
181 | fprintf (stderr, | 209 | fprintf (stderr, |
182 | _ ( | 210 | "libgcrypt has not the expected version (version %s is required).\n", |
183 | "libgcrypt has not the expected version (version %s is required).\n"), | ||
184 | "1.6.0"); | 211 | "1.6.0"); |
185 | return 0; | 212 | return 0; |
186 | } | 213 | } |
187 | if (getenv ("GNUNET_GCRYPT_DEBUG")) | 214 | if (getenv ("GNUNET_GCRYPT_DEBUG")) |
188 | gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0); | 215 | gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0); |
189 | GNUNET_log_setup ("test-crypto-eddsa", "WARNING", NULL); | 216 | GNUNET_log_setup ("test-crypto-eddsa", |
190 | key = GNUNET_CRYPTO_eddsa_key_create (); | 217 | "WARNING", |
218 | NULL); | ||
219 | GNUNET_CRYPTO_eddsa_key_create (&key); | ||
191 | #if PERF | 220 | #if PERF |
192 | if (GNUNET_OK != testSignPerformance ()) | 221 | if (GNUNET_OK != testSignPerformance ()) |
193 | failure_count++; | 222 | failure_count++; |
194 | #endif | 223 | #endif |
195 | if (GNUNET_OK != testSignVerify ()) | 224 | if (GNUNET_OK != testSignVerify ()) |
196 | failure_count++; | 225 | failure_count++; |
197 | GNUNET_free (key); | ||
198 | if (GNUNET_OK != testCreateFromFile ()) | 226 | if (GNUNET_OK != testCreateFromFile ()) |
199 | failure_count++; | 227 | failure_count++; |
200 | GNUNET_assert (0 == unlink (KEYFILE)); | 228 | GNUNET_assert (0 == unlink (KEYFILE)); |