{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Creating new ephemeral ratchet key (DHRs)\n");
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_ecdhe_key_create2 (&ax->DHRs));
+ GNUNET_CRYPTO_ecdhe_key_create (&ax->DHRs);
}
t->kx_retry_delay = INITIAL_KX_RETRY_DELAY;
new_ephemeral (&t->ax);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_ecdhe_key_create2 (&t->ax.kx_0));
+ GNUNET_CRYPTO_ecdhe_key_create (&t->ax.kx_0);
t->destination = destination;
t->channels = GNUNET_CONTAINER_multihashmap32_create (8);
t->maintain_connections_task
const struct GNUNET_CONFIGURATION_Handle *c,
struct GNUNET_SERVICE_Handle *service)
{
- struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
+ struct GNUNET_CRYPTO_EddsaPrivateKey pk;
char *keyfile;
GSC_cfg = c;
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (GSC_cfg,
- "PEER",
- "PRIVATE_KEY",
- &keyfile))
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (GSC_cfg,
+ "PEER",
+ "PRIVATE_KEY",
+ &keyfile))
{
GNUNET_log (
GNUNET_ERROR_TYPE_ERROR,
GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
GNUNET_SERVICE_suspend (service);
GSC_TYPEMAP_init ();
- pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
+ if (GNUNET_SYSERR ==
+ GNUNET_CRYPTO_eddsa_key_from_file (keyfile,
+ GNUNET_YES,
+ &pk))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to setup peer's private key\n");
+ GNUNET_SCHEDULER_shutdown ();
+ GNUNET_free (keyfile);
+ return;
+ }
GNUNET_free (keyfile);
- GNUNET_assert (NULL != pk);
- if (GNUNET_OK != GSC_KX_init (pk))
+ if (GNUNET_OK != GSC_KX_init (&pk))
{
GNUNET_SCHEDULER_shutdown ();
return;
/**
* Our private key.
*/
-static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
+static struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key;
/**
* Our ephemeral private key.
*/
-static struct GNUNET_CRYPTO_EcdhePrivateKey *my_ephemeral_key;
+static struct GNUNET_CRYPTO_EcdhePrivateKey my_ephemeral_key;
/**
* Current message we send for a key exchange.
{
struct GNUNET_HashCode key_material;
- if (GNUNET_OK != GNUNET_CRYPTO_ecc_ecdh (my_ephemeral_key,
- &kx->other_ephemeral_key,
- &key_material))
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_ecc_ecdh (&my_ephemeral_key,
+ &kx->other_ephemeral_key,
+ &key_material))
{
GNUNET_break (0);
return;
current_ekm.expiration_time =
GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS);
}
- GNUNET_CRYPTO_ecdhe_key_get_public (my_ephemeral_key,
+ GNUNET_CRYPTO_ecdhe_key_get_public (&my_ephemeral_key,
¤t_ekm.ephemeral_key);
current_ekm.origin_identity = GSC_my_identity;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_eddsa_sign_ (my_private_key,
+ GNUNET_CRYPTO_eddsa_sign_ (&my_private_key,
¤t_ekm.purpose,
¤t_ekm.signature));
}
struct GSC_KeyExchangeInfo *pos;
rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY, &do_rekey, NULL);
- if (NULL != my_ephemeral_key)
- GNUNET_free (my_ephemeral_key);
- my_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create ();
- GNUNET_assert (NULL != my_ephemeral_key);
+ GNUNET_CRYPTO_ecdhe_key_create (&my_ephemeral_key);
sign_ephemeral_key ();
{
struct GNUNET_HashCode eh;
NULL),
GNUNET_MQ_handler_end () };
- my_private_key = pk;
- GNUNET_CRYPTO_eddsa_key_get_public (my_private_key,
+ my_private_key = *pk;
+ GNUNET_CRYPTO_eddsa_key_get_public (&my_private_key,
&GSC_my_identity.public_key);
- my_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create ();
- if (NULL == my_ephemeral_key)
- {
- GNUNET_break (0);
- GNUNET_free (my_private_key);
- my_private_key = NULL;
- return GNUNET_SYSERR;
- }
+ GNUNET_CRYPTO_ecdhe_key_create (&my_ephemeral_key);
sign_ephemeral_key ();
{
struct GNUNET_HashCode eh;
GNUNET_SCHEDULER_cancel (rekey_task);
rekey_task = NULL;
}
- if (NULL != my_ephemeral_key)
- {
- GNUNET_free (my_ephemeral_key);
- my_ephemeral_key = NULL;
- }
- if (NULL != my_private_key)
- {
- GNUNET_free (my_private_key);
- my_private_key = NULL;
- }
+ memset (&my_ephemeral_key,
+ 0,
+ sizeof (my_ephemeral_key));
+ memset (&my_private_key,
+ 0,
+ sizeof (my_private_key));
if (NULL != nc)
{
GNUNET_notification_context_destroy (nc);
/**
* Private key of this peer. Used to sign LOC URI requests.
*/
-static struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
+static struct GNUNET_CRYPTO_EddsaPrivateKey pk;
/**
* ID of our task that we use to age the cover counters.
base.data.chk.chk = msg->chk;
base.data.chk.file_length = GNUNET_ntohll (msg->file_length);
loc = GNUNET_FS_uri_loc_create (&base,
- pk,
+ &pk,
GNUNET_TIME_absolute_ntoh (
msg->expiration_time));
env = GNUNET_MQ_msg (resp,
GNUNET_SCHEDULER_shutdown ();
return GNUNET_SYSERR;
}
- pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
+ if (GNUNET_SYSERR ==
+ GNUNET_CRYPTO_eddsa_key_from_file (keyfile,
+ GNUNET_YES,
+ &pk))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to setup peer's private key\n");
+ GNUNET_SCHEDULER_shutdown ();
+ GNUNET_free (keyfile);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (keyfile);
- GNUNET_assert (NULL != pk);
- GNUNET_CRYPTO_eddsa_key_get_public (pk,
+ GNUNET_CRYPTO_eddsa_key_get_public (&pk,
&GSF_my_id.public_key);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
adv_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
{
struct GNUNET_CONTAINER_MetaData *meta;
- struct GNUNET_CRYPTO_EcdsaPrivateKey *ns;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey ns;
struct GNUNET_FS_BlockOptions bo;
if (NULL != emsg)
GNUNET_FS_stop (fs);
return;
}
- ns = GNUNET_CRYPTO_ecdsa_key_create ();
+ GNUNET_CRYPTO_ecdsa_key_create (&ns);
meta = GNUNET_CONTAINER_meta_data_create ();
sks_expect_uri = GNUNET_FS_uri_dup (uri);
bo.content_priority = 1;
bo.replication_level = 0;
bo.expiration_time =
GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
- GNUNET_CRYPTO_ecdsa_key_get_public (ns, &nsid);
- GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri,
+ GNUNET_CRYPTO_ecdsa_key_get_public (&ns,
+ &nsid);
+ GNUNET_FS_publish_sks (fs,
+ &ns, "this", "next", meta, uri,
&bo, GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont, NULL);
GNUNET_CONTAINER_meta_data_destroy (meta);
- GNUNET_free (ns);
}
static void
-testNamespace ()
+testNamespace (void)
{
- struct GNUNET_CRYPTO_EcdsaPrivateKey *ns;
struct GNUNET_FS_BlockOptions bo;
struct GNUNET_CONTAINER_MetaData *meta;
struct GNUNET_FS_Uri *ksk_uri;
struct GNUNET_FS_Uri *sks_uri;
- ns = GNUNET_CRYPTO_ecdsa_key_create ();
meta = GNUNET_CONTAINER_meta_data_create ();
ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/testnsa", NULL);
bo.content_priority = 1;
NULL);
GNUNET_FS_uri_destroy (ksk_uri);
GNUNET_CONTAINER_meta_data_destroy (meta);
- GNUNET_free (ns);
}
static int err;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *ns;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey ns;
static struct GNUNET_CONTAINER_MetaData *meta;
GNUNET_FS_uri_destroy (uri_this);
if (uri_next != NULL)
GNUNET_FS_uri_destroy (uri_next);
- if (ns != NULL)
- GNUNET_free (ns);
if (meta != NULL)
GNUNET_CONTAINER_meta_data_destroy (meta);
}
GNUNET_break (0 == strcmp (next_id, "next"));
err -= 2;
err += 4;
- GNUNET_FS_namespace_list_updateable (fs, ns, next_id, &check_next, NULL);
+ GNUNET_FS_namespace_list_updateable (fs, &ns, next_id, &check_next, NULL);
}
{
GNUNET_assert (NULL == emsg);
err += 2;
- GNUNET_FS_namespace_list_updateable (fs, ns, NULL, &check_this_next, NULL);
+ GNUNET_FS_namespace_list_updateable (fs, &ns, NULL, &check_this_next, NULL);
}
{
GNUNET_assert (NULL == emsg);
err = 1;
- GNUNET_FS_namespace_list_updateable (fs, ns, NULL, &check_this, NULL);
- GNUNET_FS_publish_sks (fs, ns, "next", "future", meta, uri_next, &bo,
+ GNUNET_FS_namespace_list_updateable (fs, &ns, NULL, &check_this, NULL);
+ GNUNET_FS_publish_sks (fs,
+ &ns, "next", "future", meta, uri_next, &bo,
GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_next, NULL);
}
static void
-testNamespace ()
+testNamespace (void)
{
- ns = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (NULL != ns);
+ GNUNET_CRYPTO_ecdsa_key_create (&ns);
bo.content_priority = 1;
bo.anonymity_level = 1;
bo.replication_level = 0;
(
"gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.43",
NULL);
- GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri_this, &bo,
+ GNUNET_FS_publish_sks (fs,
+ &ns, "this", "next", meta, uri_this, &bo,
GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_this, NULL);
}
struct GNUNET_FS_Uri *uri2;
struct GNUNET_FS_Uri *baseURI;
char *emsg;
- struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
+ struct GNUNET_CRYPTO_EddsaPrivateKey pk;
baseURI =
GNUNET_FS_uri_parse
&emsg);
GNUNET_assert (baseURI != NULL);
GNUNET_assert (emsg == NULL);
- pk = GNUNET_CRYPTO_eddsa_key_create ();
+ GNUNET_CRYPTO_eddsa_key_create (&pk);
uri = GNUNET_FS_uri_loc_create (baseURI,
- pk,
+ &pk,
GNUNET_TIME_absolute_get ());
- GNUNET_free (pk);
if (NULL == uri)
{
GNUNET_break (0);
char *uri;
struct GNUNET_FS_Uri *ret;
char *emsg;
- struct GNUNET_CRYPTO_EcdsaPrivateKey *ph;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey ph;
struct GNUNET_CRYPTO_EcdsaPublicKey id;
char buf[1024];
char ubuf[1024];
GNUNET_assert (0);
}
GNUNET_free (emsg);
- ph = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_CRYPTO_ecdsa_key_get_public (ph, &id);
+ GNUNET_CRYPTO_ecdsa_key_create (&ph);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&ph,
+ &id);
sret = GNUNET_STRINGS_data_to_string (&id, sizeof(id),
ubuf, sizeof(ubuf) - 1);
GNUNET_assert (NULL != sret);
struct GNUNET_GNSRECORD_Data *s_rd;
const char *s_name;
struct GNUNET_TIME_Absolute start_time;
- struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey privkey;
struct GNUNET_TIME_Absolute expire;
(void) cls;
(void) cfgfile;
(void) cfg;
expire = GNUNET_TIME_absolute_get ();
- privkey = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (NULL != privkey);
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey);
/* test block creation */
s_name = "DUMMY.dummy.gnunet";
for (unsigned int i = 0; i < ROUNDS; i++)
{
GNUNET_assert (NULL != (block =
- GNUNET_GNSRECORD_block_create2 (privkey,
+ GNUNET_GNSRECORD_block_create2 (&privkey,
expire,
s_name,
s_rd,
RECORDS)));
- GNUNET_GNSRECORD_query_from_private_key (privkey,
+ GNUNET_GNSRECORD_query_from_private_key (&privkey,
s_name,
&query);
GNUNET_free (block);
for (unsigned int i = 0; i < RECORDS; i++)
GNUNET_free ((void *) s_rd[i].data);
GNUNET_free (s_rd);
- GNUNET_free (privkey);
}
#define TEST_REMOVE_RECORD_DATA 'b'
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
-
static struct GNUNET_GNSRECORD_Data *s_rd;
static char *s_name;
struct GNUNET_HashCode query_pub;
struct GNUNET_HashCode query_priv;
struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get ();
+ struct GNUNET_CRYPTO_EcdsaPrivateKey privkey;
+
- privkey = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (NULL != privkey);
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey);
/* get public key */
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ GNUNET_CRYPTO_ecdsa_key_get_public (&privkey,
&pubkey);
/* test query derivation */
- GNUNET_GNSRECORD_query_from_private_key (privkey,
+ GNUNET_GNSRECORD_query_from_private_key (&privkey,
"testlabel",
&query_priv);
GNUNET_GNSRECORD_query_from_public_key (&pubkey,
/* Create block */
GNUNET_assert (NULL != (block =
- GNUNET_GNSRECORD_block_create (privkey,
+ GNUNET_GNSRECORD_block_create (&privkey,
expire,
s_name,
s_rd,
&rd_decrypt_cb,
s_name));
GNUNET_free (block);
- GNUNET_free (privkey);
}
#include "gnunet_peerinfo_service.h"
#include "gnunet-daemon-hostlist.h"
#include "gnunet_resolver_service.h"
+#include "gnunet_mhd_compat.h"
/**
* @param addrlen length of @a addr
* @return #MHD_YES if connection is allowed, #MHD_NO if not (we are not ready)
*/
-static int
+static MHD_RESULT
accept_policy_callback (void *cls,
const struct sockaddr *addr,
socklen_t addrlen)
* #MHD_NO if the socket must be closed due to a serios
* error while handling the request
*/
-static int
+static MHD_RESULT
access_handler_callback (void *cls,
struct MHD_Connection *connection,
const char *url,
/**
* Private key of the ego.
*/
- struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey pk;
/**
* String identifier for the ego.
while (NULL != (e = ego_head))
{
GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, e);
- GNUNET_free (e->pk);
GNUNET_free (e->identifier);
GNUNET_free (e);
}
env = GNUNET_MQ_msg_extra (um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
um->name_len = htons (name_len);
um->end_of_list = htons (GNUNET_NO);
- um->private_key = *ego->pk;
+ um->private_key = ego->pk;
GNUNET_memcpy (&um[1], ego->identifier, name_len);
return env;
}
GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
sdm->name_len = htons (name_len);
sdm->reserved = htons (0);
- sdm->private_key = *ego->pk;
+ sdm->private_key = ego->pk;
GNUNET_memcpy (&sdm[1], servicename, name_len);
return env;
}
str);
for (ego = ego_head; NULL != ego; ego = ego->next)
{
- if (0 == key_cmp (ego->pk, &sdm->private_key))
+ if (0 == key_cmp (&ego->pk,
+ &sdm->private_key))
{
GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
str,
um->header.size = htons (sizeof(struct UpdateMessage) + name_len);
um->name_len = htons (name_len);
um->end_of_list = htons (GNUNET_NO);
- um->private_key = *ego->pk;
+ um->private_key = ego->pk;
GNUNET_memcpy (&um[1], ego->identifier, name_len);
GNUNET_notification_context_broadcast (nc, &um->header, GNUNET_NO);
GNUNET_free (um);
}
}
ego = GNUNET_new (struct Ego);
- ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey);
- *ego->pk = crm->private_key;
+ ego->pk = crm->private_key;
ego->identifier = GNUNET_strdup (str);
GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
send_result_code (client, 0, NULL);
GNUNET_free (ego->identifier);
ego->identifier = NULL;
notify_listeners (ego);
- GNUNET_free (ego->pk);
GNUNET_free (ego);
GNUNET_free (name);
send_result_code (client, 0, NULL);
* #GNUNET_SYSERR to abort iteration with error!
*/
static int
-process_ego_file (void *cls, const char *filename)
+process_ego_file (void *cls,
+ const char *filename)
{
struct Ego *ego;
const char *fn;
return GNUNET_OK;
}
ego = GNUNET_new (struct Ego);
- ego->pk = GNUNET_CRYPTO_ecdsa_key_create_from_file (filename);
- if (NULL == ego->pk)
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_ecdsa_key_from_file (filename,
+ GNUNET_NO,
+ &ego->pk))
{
GNUNET_free (ego);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
filename);
return GNUNET_OK;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded ego `%s'\n", fn + 1);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Loaded ego `%s'\n",
+ fn + 1);
ego->identifier = GNUNET_strdup (fn + 1);
GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
return GNUNET_OK;
_ ("Failed to create directory `%s' for storing egos\n"),
ego_directory);
}
- GNUNET_DISK_directory_scan (ego_directory, &process_ego_file, NULL);
+ GNUNET_DISK_directory_scan (ego_directory,
+ &process_ego_file,
+ NULL);
GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
/**
* Private key associated with this ego.
*/
- struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey pk;
/**
* Current name associated with this ego.
/**
* Private key to return to @e create_cont, or NULL.
*/
- struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey pk;
/**
* Continuation to invoke with the result of the transmission for
GNUNET_IDENTITY_ego_get_anonymous ()
{
static struct GNUNET_IDENTITY_Ego anon;
+ static int setup;
struct GNUNET_CRYPTO_EcdsaPublicKey pub;
- if (NULL != anon.pk)
+ if (setup)
return &anon;
- anon.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *)
- GNUNET_CRYPTO_ecdsa_key_get_anonymous ();
- GNUNET_CRYPTO_ecdsa_key_get_public (anon.pk, &pub);
- GNUNET_CRYPTO_hash (&pub, sizeof(pub), &anon.id);
+ anon.pk = *GNUNET_CRYPTO_ecdsa_key_get_anonymous ();
+ GNUNET_CRYPTO_ecdsa_key_get_public (&anon.pk,
+ &pub);
+ GNUNET_CRYPTO_hash (&pub,
+ sizeof(pub),
+ &anon.id);
+ setup = 1;
return &anon;
}
if (NULL != h->cb)
h->cb (h->cb_cls, ego, &ego->ctx, NULL);
- GNUNET_free (ego->pk);
GNUNET_free (ego->name);
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_remove (h->egos, key, value));
op->create_cont (op->cls,
NULL,
"Failed to communicate with the identity service");
- GNUNET_free_non_null (op->pk);
GNUNET_free (op);
}
GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h);
else if (NULL != op->cb)
op->cb (op->cls, NULL, NULL, NULL);
else if (NULL != op->create_cont)
- op->create_cont (op->cls, (NULL == str) ? op->pk : NULL, str);
- GNUNET_free_non_null (op->pk);
+ op->create_cont (op->cls, (NULL == str) ? &op->pk : NULL, str);
GNUNET_free (op);
}
return;
}
ego = GNUNET_new (struct GNUNET_IDENTITY_Ego);
- ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey);
- *ego->pk = um->private_key;
+ ego->pk = um->private_key;
ego->name = GNUNET_strdup (str);
ego->id = id;
GNUNET_assert (GNUNET_YES ==
/* complete deletion */
if (NULL == str)
{
- GNUNET_free (ego->pk);
GNUNET_free (ego->name);
GNUNET_free (ego);
}
const struct GNUNET_CRYPTO_EcdsaPrivateKey *
GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego)
{
- return ego->pk;
+ return &ego->pk;
}
GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego,
struct GNUNET_CRYPTO_EcdsaPublicKey *pk)
{
- GNUNET_CRYPTO_ecdsa_key_get_public (ego->pk, pk);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&ego->pk,
+ pk);
}
GNUNET_MQ_msg_extra (sdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
sdm->name_len = htons (slen);
sdm->reserved = htons (0);
- sdm->private_key = *ego->pk;
+ sdm->private_key = ego->pk;
GNUNET_memcpy (&sdm[1], service_name, slen);
GNUNET_MQ_send (h->mq, env);
return op;
struct GNUNET_IDENTITY_Operation *op;
struct GNUNET_MQ_Envelope *env;
struct CreateRequestMessage *crm;
- struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
size_t slen;
if (NULL == h->mq)
env = GNUNET_MQ_msg_extra (crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE);
crm->name_len = htons (slen);
crm->reserved = htons (0);
- pk = GNUNET_CRYPTO_ecdsa_key_create ();
- crm->private_key = *pk;
- op->pk = pk;
+ GNUNET_CRYPTO_ecdsa_key_create (&crm->private_key);
+ op->pk = crm->private_key;
GNUNET_memcpy (&crm[1], name, slen);
GNUNET_MQ_send (h->mq, env);
return op;
op->cont = NULL;
op->cb = NULL;
op->create_cont = NULL;
- if (NULL != op->pk)
- {
- GNUNET_free (op->pk);
- op->pk = NULL;
- }
+ memset (&op->pk,
+ 0,
+ sizeof (op->pk));
}
{
GNUNET_break (NULL == op->cont);
GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
- GNUNET_free_non_null (op->pk);
+ memset (&op->pk,
+ 0,
+ sizeof (op->pk));
GNUNET_free (op);
}
if (NULL != h->mq)
GNUNET_break (GNUNET_YES != ntohs (um->end_of_list));
GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub);
GNUNET_CRYPTO_hash (&pub, sizeof(pub), &id);
- ego.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *) &um->private_key;
+ ego.pk = um->private_key;
ego.name = (char *) str;
ego.id = id;
el->cb (el->cb_cls, &ego);
/**
* @ingroup crypto
- * Create a new private key by reading it from a file. If the
- * files does not exist, create a new key and write it to the
- * file. Caller must free return value. Note that this function
- * can not guarantee that another process might not be trying
- * the same operation on the same file at the same time.
- * If the contents of the file
- * are invalid the old file is deleted and a fresh key is
- * created.
+ * @brief Create a new private key by reading it from a file.
+ *
+ * If the files does not exist and @a do_create is set, creates a new key and
+ * write it to the file.
+ *
+ * If the contents of the file are invalid, an error is returned.
*
* @param filename name of file to use to store the key
- * @return new private key, NULL on error (for example,
- * permission denied); free using #GNUNET_free
+ * @param do_create should a file be created?
+ * @param[out] pkey set to the private key from @a filename on success
+ * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but
+ * we found an existing file, #GNUNET_SYSERR on failure
*/
-struct GNUNET_CRYPTO_EcdsaPrivateKey *
-GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename);
+int
+GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename,
+ int do_create,
+ struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey);
/**
* @ingroup crypto
- * Create a new private key by reading it from a file. If the
- * files does not exist, create a new key and write it to the
- * file. Caller must free return value. Note that this function
- * can not guarantee that another process might not be trying
- * the same operation on the same file at the same time.
- * If the contents of the file
- * are invalid the old file is deleted and a fresh key is
- * created.
+ * @brief Create a new private key by reading it from a file.
+ *
+ * If the files does not exist and @a do_create is set, creates a new key and
+ * write it to the file.
+ *
+ * If the contents of the file are invalid, an error is returned.
*
* @param filename name of file to use to store the key
- * @return new private key, NULL on error (for example,
- * permission denied); free using #GNUNET_free
+ * @param do_create should a file be created?
+ * @param[out] pkey set to the private key from @a filename on success
+ * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but
+ * we found an existing file, #GNUNET_SYSERR on failure
*/
-struct GNUNET_CRYPTO_EddsaPrivateKey *
-GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename);
+int
+GNUNET_CRYPTO_eddsa_key_from_file (const char *filename,
+ int do_create,
+ struct GNUNET_CRYPTO_EddsaPrivateKey *pkey);
/**
/**
* @ingroup crypto
- * Create a new private key. Caller must free return value.
+ * Create a new private key.
*
- * @return fresh private key; free using #GNUNET_free
+ * @param[out] pk private key to initialize
*/
-struct GNUNET_CRYPTO_EcdsaPrivateKey *
-GNUNET_CRYPTO_ecdsa_key_create (void);
+void
+GNUNET_CRYPTO_ecdsa_key_create (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk);
/**
* @ingroup crypto
- * Create a new private key. Caller must free return value.
+ * Create a new private key.
*
- * @return fresh private key; free using #GNUNET_free
+ * @param[out] pk private key to initialize
*/
-struct GNUNET_CRYPTO_EddsaPrivateKey *
-GNUNET_CRYPTO_eddsa_key_create (void);
+void
+GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk);
/**
* Create a new private key. Clear with #GNUNET_CRYPTO_ecdhe_key_clear().
*
* @param[out] pk set to fresh private key;
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
-int
-GNUNET_CRYPTO_ecdhe_key_create2 (struct GNUNET_CRYPTO_EcdhePrivateKey *pk);
-
-
-/**
- * @ingroup crypto
- * Create a new private key. Caller must free return value.
- *
- * @return fresh private key; free using #GNUNET_free
- */
-struct GNUNET_CRYPTO_EcdhePrivateKey *
-GNUNET_CRYPTO_ecdhe_key_create (void);
+void
+GNUNET_CRYPTO_ecdhe_key_create (struct GNUNET_CRYPTO_EcdhePrivateKey *pk);
/**
GNUNET_DISK_directory_create (const char *dir);
-/**
- * Lock a part of a file.
- *
- * @param fh file handle
- * @param lock_start absolute position from where to lock
- * @param lock_end absolute position until where to lock
- * @param excl #GNUNET_YES for an exclusive lock
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
- */
-int
-GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh,
- off_t lock_start,
- off_t lock_end, int excl);
-
-
-/**
- * Unlock a part of a file.
- *
- * @param fh file handle
- * @param unlock_start absolute position from where to unlock
- * @param unlock_end absolute position until where to unlock
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
- */
-int
-GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh,
- off_t unlock_start,
- off_t unlock_end);
-
-
/**
* @brief Removes special characters as ':' from a filename.
* @param fn the filename to canonicalize
* NULL if the user just deleted the ego and it
* must thus no longer be used
*/
-typedef void (*GNUNET_IDENTITY_Callback) (void *cls,
- struct GNUNET_IDENTITY_Ego *ego,
- void **ctx,
- const char *name);
+typedef void
+(*GNUNET_IDENTITY_Callback) (void *cls,
+ struct GNUNET_IDENTITY_Ego *ego,
+ void **ctx,
+ const char *name);
/**
* @param cls closure
* @param emsg NULL on success, otherwise an error message
*/
-typedef void (*GNUNET_IDENTITY_Continuation) (void *cls, const char *emsg);
+typedef void
+(*GNUNET_IDENTITY_Continuation) (void *cls,
+ const char *emsg);
/**
* @param pk private key, NULL on error
* @param emsg error message, NULL on success
*/
-typedef void (*GNUNET_IDENTITY_CreateContinuation) (
+typedef void
+(*GNUNET_IDENTITY_CreateContinuation) (
void *cls,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
const char *emsg);
* @param cls closure
* @param ego NULL on error / ego not found
*/
-typedef void (*GNUNET_IDENTITY_EgoCallback) (
- void *cls,
- const struct GNUNET_IDENTITY_Ego *ego);
+typedef void
+(*GNUNET_IDENTITY_EgoCallback) (void *cls,
+ const struct GNUNET_IDENTITY_Ego *ego);
/**
* Handle for ego lookup.
* @param ego NULL on error / ego not found
* @param ego_name NULL on error, name of the ego otherwise
*/
-typedef void (*GNUNET_IDENTITY_EgoSuffixCallback) (
+typedef void
+(*GNUNET_IDENTITY_EgoSuffixCallback) (
void *cls,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
const char *ego_name);
* @param el handle for lookup to abort
*/
void
-GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (struct
- GNUNET_IDENTITY_EgoSuffixLookup *el);
+GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (
+ struct GNUNET_IDENTITY_EgoSuffixLookup *el);
+
#if 0 /* keep Emacsens' auto-indent happy */
{
static struct GNUNET_SCHEDULER_Task *t;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey;
static struct GNUNET_NAMESTORE_ZoneIterator *zi;
GNUNET_SCHEDULER_cancel (timeout_task);
timeout_task = NULL;
}
- if (NULL != privkey)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
}
}
GNUNET_free (wrd);
if (0 != GNUNET_memcmp (zone,
- privkey))
+ &privkey))
{
res = 5;
GNUNET_break (0);
"l%u",
off);
qe = GNUNET_NAMESTORE_records_store (nsh,
- privkey,
+ &privkey,
label,
1, rd,
&put_cont,
NULL);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_assert (NULL != nsh);
- privkey = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (NULL != privkey);
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey);
start = GNUNET_TIME_absolute_get ();
t = GNUNET_SCHEDULER_add_now (&publish_record,
NULL);
static struct GNUNET_SCHEDULER_Task *endbadly_task;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey;
static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
GNUNET_NAMESTORE_disconnect (nsh);
nsh = NULL;
}
- if (NULL != privkey)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
GNUNET_SCHEDULER_shutdown ();
}
int found_record = GNUNET_NO;
int found_nick = GNUNET_NO;
- if (0 != GNUNET_memcmp (privkey, zone))
+ if (0 != GNUNET_memcmp (&privkey, zone))
{
GNUNET_break (0);
GNUNET_SCHEDULER_cancel (endbadly_task);
}
/* Lookup */
nsqe = GNUNET_NAMESTORE_records_lookup (nsh,
- privkey,
+ &privkey,
name,
&fail_cb,
NULL,
rd_orig.flags = 0;
memset ((char *) rd_orig.data, 'a', TEST_RECORD_DATALEN);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
- 1, &rd_orig, &put_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh, &privkey,
+ name,
+ 1,
+ &rd_orig,
+ &put_cont, (void *) name);
}
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
- privkey = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&privkey,
&pubkey);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
nsqe = GNUNET_NAMESTORE_set_nick (nsh,
- privkey,
+ &privkey,
TEST_NICK,
&nick_cont,
(void *) name);
static struct GNUNET_SCHEDULER_Task *endbadly_task;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey;
static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
GNUNET_NAMESTORE_disconnect (nsh);
nsh = NULL;
}
- if (NULL != privkey)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
GNUNET_SCHEDULER_shutdown ();
}
{
nsqe = NULL;
- if (0 != GNUNET_memcmp (privkey,
+ if (0 != GNUNET_memcmp (&privkey,
zone))
{
GNUNET_break (0);
}
/* Lookup */
nsqe = GNUNET_NAMESTORE_records_lookup (nsh,
- privkey,
+ &privkey,
name,
&fail_cb,
NULL,
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
- privkey = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, &pubkey);
rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us;
rd.record_type = TEST_RECORD_TYPE;
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
nsqe = GNUNET_NAMESTORE_records_store (nsh,
- privkey,
+ &privkey,
name,
1,
&rd,
static struct GNUNET_SCHEDULER_Task *endbadly_task;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey;
static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
GNUNET_NAMECACHE_disconnect (nch);
nch = NULL;
}
- if (NULL != privkey)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
GNUNET_SCHEDULER_shutdown ();
}
(success == GNUNET_OK) ? "SUCCESS" : "FAIL");
/* Create derived hash */
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&privkey,
+ &pubkey);
GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &derived_hash);
ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash,
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
- privkey = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&privkey,
&pubkey);
rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000;
nch = GNUNET_NAMECACHE_connect (cfg);
GNUNET_break (NULL != nsh);
GNUNET_break (NULL != nch);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
- 1, &rd, &put_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ &privkey,
+ name,
+ 1,
+ &rd,
+ &put_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
static struct GNUNET_SCHEDULER_Task *endbadly_task;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey;
static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
GNUNET_NAMECACHE_disconnect (nch);
nch = NULL;
}
- if (NULL != privkey)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
GNUNET_SCHEDULER_shutdown ();
}
(success == GNUNET_OK) ? "SUCCESS" : "FAIL");
/* Create derived hash */
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
- GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &derived_hash);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&privkey,
+ &pubkey);
+ GNUNET_GNSRECORD_query_from_public_key (&pubkey,
+ name,
+ &derived_hash);
- ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash,
+ ncqe = GNUNET_NAMECACHE_lookup_block (nch,
+ &derived_hash,
&name_lookup_proc, (void *) name);
}
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
- privkey = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&privkey,
&pubkey);
rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000;
rd.record_type = TEST_RECORD_TYPE;
GNUNET_break (NULL != nsh);
GNUNET_break (NULL != nch);
nsqe = GNUNET_NAMESTORE_records_store (nsh,
- privkey,
+ &privkey,
name,
1,
&rd,
static struct GNUNET_SCHEDULER_Task *delayed_lookup_task;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey;
static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
GNUNET_NAMECACHE_disconnect (nch);
nch = NULL;
}
- if (NULL != privkey)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
GNUNET_SCHEDULER_shutdown ();
}
(success == GNUNET_OK) ? "SUCCESS" : "FAIL");
/* Create derived hash */
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&privkey,
+ &pubkey);
GNUNET_GNSRECORD_query_from_public_key (&pubkey, TEST_NAME, &derived_hash);
if (0 == GNUNET_TIME_absolute_get_remaining (record_expiration).rel_value_us)
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
- privkey = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&privkey,
&pubkey);
record_expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
nch = GNUNET_NAMECACHE_connect (cfg);
GNUNET_break (NULL != nsh);
GNUNET_break (NULL != nch);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, TEST_NAME,
- 2, records, &put_cont, NULL);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ &privkey,
+ TEST_NAME,
+ 2,
+ records,
+ &put_cont,
+ NULL);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
static struct GNUNET_SCHEDULER_Task *endbadly_task;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey2;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey2;
static struct GNUNET_NAMESTORE_ZoneMonitor *zm;
GNUNET_free ((void *) s_rd_3->data);
GNUNET_free (s_rd_3);
}
-
- if (NULL != privkey)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
- if (NULL != privkey2)
- {
- GNUNET_free (privkey2);
- privkey2 = NULL;
- }
}
"Comparing results name %s\n",
name);
if (0 != GNUNET_memcmp (zone_key,
- privkey))
+ &privkey))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Monitoring returned wrong zone key\n");
struct GNUNET_TESTING_Peer *peer)
{
res = 1;
- privkey = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (privkey != NULL);
-
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey);
/* Start monitoring */
zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
- privkey,
+ &privkey,
GNUNET_YES,
&fail_cb,
NULL,
return;
}
- privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (privkey2 != NULL);
-
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey2);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created record 3\n");
s_rd_3 = create_record (1);
GNUNET_assert (NULL != (ns_ops[2] =
GNUNET_NAMESTORE_records_store (nsh,
- privkey2,
+ &privkey2,
s_name_3,
1,
s_rd_3,
s_rd_1 = create_record (1);
GNUNET_assert (NULL != (ns_ops[0] =
GNUNET_NAMESTORE_records_store (nsh,
- privkey,
+ &privkey,
s_name_1,
1,
s_rd_1,
s_rd_2 = create_record (1);
GNUNET_assert (NULL != (ns_ops[1] =
GNUNET_NAMESTORE_records_store (nsh,
- privkey,
+ &privkey,
s_name_2,
1,
s_rd_2,
static struct GNUNET_SCHEDULER_Task *endbadly_task;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey2;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey2;
static struct GNUNET_NAMESTORE_ZoneMonitor *zm;
GNUNET_free ((void *) s_rd_3->data);
GNUNET_free (s_rd_3);
}
- if (NULL != privkey)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
- if (NULL != privkey2)
- {
- GNUNET_free (privkey2);
- privkey2 = NULL;
- }
}
"Comparing results name %s\n",
name);
if (0 != GNUNET_memcmp (zone_key,
- privkey))
+ &privkey))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Monitoring returned wrong zone key\n");
{
/* Start monitoring */
zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
- privkey,
+ &privkey,
GNUNET_YES,
&fail_cb,
NULL,
struct GNUNET_TESTING_Peer *peer)
{
res = 1;
- privkey = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (NULL != privkey);
- privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (NULL != privkey2);
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey);
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey2);
cfg = mycfg;
GNUNET_SCHEDULER_add_shutdown (&end,
s_rd_3 = create_record (1);
GNUNET_assert (NULL != (ns_ops[2] =
GNUNET_NAMESTORE_records_store (nsh,
- privkey2,
+ &privkey2,
s_name_3,
1,
s_rd_3,
s_rd_1 = create_record (1);
GNUNET_assert (NULL != (ns_ops[0] =
GNUNET_NAMESTORE_records_store (nsh,
- privkey,
+ &privkey,
s_name_1,
1,
s_rd_1,
s_rd_2 = create_record (1);
GNUNET_assert (NULL != (ns_ops[1] =
GNUNET_NAMESTORE_records_store (nsh,
- privkey,
+ &privkey,
s_name_2,
1,
s_rd_2,
static struct GNUNET_SCHEDULER_Task *endbadly_task;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey;
static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
GNUNET_NAMESTORE_disconnect (nsh);
nsh = NULL;
}
- if (NULL != privkey)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
GNUNET_SCHEDULER_shutdown ();
}
name,
(success == GNUNET_OK) ? "SUCCESS" : "FAIL");
nsqe = GNUNET_NAMESTORE_records_store (nsh,
- privkey,
+ &privkey,
name,
0, NULL,
&remove_cont, (void *) name);
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
- privkey = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&privkey,
&pubkey);
removed = GNUNET_NO;
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
nsqe = GNUNET_NAMESTORE_records_store (nsh,
- privkey,
+ &privkey,
name,
1,
&rd,
static struct GNUNET_SCHEDULER_Task *endbadly_task;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey;
static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
static void
-cleanup ()
+cleanup (void)
{
if (NULL != nsh)
{
GNUNET_NAMESTORE_disconnect (nsh);
nsh = NULL;
}
- if (NULL != privkey)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
GNUNET_SCHEDULER_shutdown ();
}
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
- privkey = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, &pubkey);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ &privkey,
+ name,
0, NULL,
&put_cont, (void *) name);
if (NULL == nsqe)
static struct GNUNET_SCHEDULER_Task *endbadly_task;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey;
static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
GNUNET_NAMESTORE_disconnect (nsh);
nsh = NULL;
}
- if (NULL != privkey)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
GNUNET_SCHEDULER_shutdown ();
}
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly, NULL);
- privkey = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, &pubkey);
rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us;
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
nsqe = GNUNET_NAMESTORE_records_store (nsh,
- privkey,
+ &privkey,
name,
1,
&rd,
static struct GNUNET_SCHEDULER_Task *endbadly_task;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey;
static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
GNUNET_NAMECACHE_disconnect (nch);
nch = NULL;
}
- if (NULL != privkey)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
}
TEST_RECORD_DATALEN2);
nsqe = GNUNET_NAMESTORE_records_store (nsh,
- privkey,
+ &privkey,
name,
1,
&rd_new,
name,
(success == GNUNET_OK) ? "SUCCESS" : "FAIL");
/* Create derived hash */
- GNUNET_GNSRECORD_query_from_private_key (privkey,
+ GNUNET_GNSRECORD_query_from_private_key (&privkey,
name,
&derived_hash);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
- privkey = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&privkey,
&pubkey);
rd.flags = GNUNET_GNSRECORD_RF_NONE;
rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000;
nch = GNUNET_NAMECACHE_connect (cfg);
GNUNET_break (NULL != nch);
nsqe = GNUNET_NAMESTORE_records_store (nsh,
- privkey,
+ &privkey,
name,
1,
&rd,
static struct GNUNET_NAMESTORE_Handle *nsh;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey2;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey2;
static struct GNUNET_NAMESTORE_ZoneIterator *zi;
GNUNET_free ((void *) s_rd_3->data);
GNUNET_free (s_rd_3);
}
-
- if (privkey != NULL)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
- if (privkey2 != NULL)
- {
- GNUNET_free (privkey2);
- privkey2 = NULL;
- }
}
int failed = GNUNET_NO;
GNUNET_assert (NULL != zone);
- if (0 == GNUNET_memcmp (zone, privkey))
+ if (0 == GNUNET_memcmp (zone, &privkey))
{
failed = check_zone_1 (label, rd_count, rd);
if (GNUNET_YES == failed)
GNUNET_break (0);
}
- else if (0 == GNUNET_memcmp (zone, privkey2))
+ else if (0 == GNUNET_memcmp (zone, &privkey2))
{
failed = check_zone_2 (label, rd_count, rd);
if (GNUNET_YES == failed)
GNUNET_asprintf (&s_name_1, "dummy1");
s_rd_1 = create_record (1);
- GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_1,
+ GNUNET_NAMESTORE_records_store (nsh, &privkey, s_name_1,
1, s_rd_1,
&put_cont, NULL);
"Created record 2 \n");
GNUNET_asprintf (&s_name_2, "dummy2");
s_rd_2 = create_record (1);
- GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_2,
+ GNUNET_NAMESTORE_records_store (nsh, &privkey, s_name_2,
1, s_rd_2, &put_cont, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
/* name in different zone */
GNUNET_asprintf (&s_name_3, "dummy3");
s_rd_3 = create_record (1);
- GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3,
+ GNUNET_NAMESTORE_records_store (nsh, &privkey2, s_name_3,
1, s_rd_3,
&put_cont, NULL);
}
"Nick 1 added : %s\n",
(success == GNUNET_OK) ? "SUCCESS" : "FAIL");
- nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey2, ZONE_NICK_2, &nick_2_cont,
+ nsqe = GNUNET_NAMESTORE_set_nick (nsh,
+ &privkey2, ZONE_NICK_2, &nick_2_cont,
&privkey2);
if (NULL == nsqe)
{
{
GNUNET_assert (nsh == cls);
zi = NULL;
- privkey = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (privkey != NULL);
- privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (privkey2 != NULL);
-
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey);
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey2);
nsqe = GNUNET_NAMESTORE_set_nick (nsh,
- privkey,
+ &privkey,
ZONE_NICK_1,
&nick_1_cont,
- &privkey);
+ NULL);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
static struct GNUNET_SCHEDULER_Task *endbadly_task;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey2;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey2;
static struct GNUNET_NAMESTORE_ZoneIterator *zi;
GNUNET_SCHEDULER_cancel (endbadly_task);
endbadly_task = NULL;
}
- if (NULL != privkey)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
- if (NULL != privkey2)
- {
- GNUNET_free (privkey2);
- privkey2 = NULL;
- }
GNUNET_free_non_null (s_name_1);
GNUNET_free_non_null (s_name_2);
GNUNET_free_non_null (s_name_3);
GNUNET_assert (NULL != zone);
if (0 == GNUNET_memcmp (zone,
- privkey))
+ &privkey))
{
if (0 == strcmp (label, s_name_1))
{
GNUNET_break (0);
}
}
- else if (0 == GNUNET_memcmp (zone, privkey2))
+ else if (0 == GNUNET_memcmp (zone, &privkey2))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Received data for not requested zone\n");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"All records created, starting iteration over all zones \n");
zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
- privkey,
+ &privkey,
&fail_cb,
NULL,
&zone_proc,
empty_zone_proc_end (void *cls)
{
zi = NULL;
- privkey = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (privkey != NULL);
- privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (privkey2 != NULL);
-
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey);
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey2);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created record 1\n");
GNUNET_asprintf (&s_name_1,
"dummy1");
s_rd_1 = create_record (1);
GNUNET_NAMESTORE_records_store (nsh,
- privkey,
+ &privkey,
s_name_1,
1,
s_rd_1,
"dummy2");
s_rd_2 = create_record (1);
GNUNET_NAMESTORE_records_store (nsh,
- privkey,
+ &privkey,
s_name_2,
1,
s_rd_2,
"dummy3");
s_rd_3 = create_record (1);
GNUNET_NAMESTORE_records_store (nsh,
- privkey2,
+ &privkey2,
s_name_3,
1, s_rd_3,
&put_cont,
static struct GNUNET_SCHEDULER_Task *endbadly_task;
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey;
static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
GNUNET_SCHEDULER_cancel (endbadly_task);
endbadly_task = NULL;
}
- if (NULL != privkey)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
if (NULL != nsh)
{
GNUNET_NAMESTORE_disconnect (nsh);
}
if ((NULL == zone_key) ||
(0 != GNUNET_memcmp (zone_key,
- privkey)))
+ &privkey)))
{
fail = GNUNET_YES;
GNUNET_break (0);
res = 0;
qe = GNUNET_NAMESTORE_zone_to_name (nsh,
- privkey,
+ &privkey,
&s_zone_value,
&error_cb,
NULL,
GNUNET_SCHEDULER_add_shutdown (&end,
NULL);
GNUNET_asprintf (&s_name, "dummy");
- privkey = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (NULL != privkey);
+ GNUNET_CRYPTO_ecdsa_key_create (&privkey);
/* get public key */
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ GNUNET_CRYPTO_ecdsa_key_get_public (&privkey,
&pubkey);
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
GNUNET_NAMESTORE_records_store (nsh,
- privkey,
+ &privkey,
s_name,
1,
&rd,
uint32_t nonce;
uint32_t nonce_tmp;
struct GNUNET_CRYPTO_EccSignaturePurpose *purpose;
- struct GNUNET_CRYPTO_EcdhePrivateKey *ecdh_priv;
+ struct GNUNET_CRYPTO_EcdhePrivateKey ecdh_priv;
struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pub;
/** PLAINTEXT **/
code_payload_len);
// Generate ECDH key
- ecdh_priv = GNUNET_CRYPTO_ecdhe_key_create ();
- GNUNET_CRYPTO_ecdhe_key_get_public (ecdh_priv, &ecdh_pub);
+ GNUNET_CRYPTO_ecdhe_key_create (&ecdh_priv);
+ GNUNET_CRYPTO_ecdhe_key_get_public (&ecdh_priv, &ecdh_pub);
// Initialize code payload
code_payload = GNUNET_malloc (code_payload_len);
GNUNET_assert (NULL != code_payload);
memcpy (buf_ptr, &ecdh_pub, sizeof(ecdh_pub));
buf_ptr += sizeof(ecdh_pub);
// Encrypt plaintext and store
- encrypt_payload (&ticket->audience, ecdh_priv, payload, payload_len, buf_ptr);
- GNUNET_free (ecdh_priv);
+ encrypt_payload (&ticket->audience,
+ &ecdh_priv,
+ payload,
+ payload_len,
+ buf_ptr);
GNUNET_free (payload);
buf_ptr += payload_len;
// Sign and store signature
unsigned int off)
{
const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data;
- char *buf;
+ void *buf;
size_t buf_size;
GNUNET_break (NULL == cls);
unsigned int off)
{
const struct GNUNET_CRYPTO_RsaSignature *sig = data;
- char *buf;
+ void *buf;
size_t buf_size;
GNUNET_break (NULL == cls);
GNUNET_assert (0 == queue->pwrite_off);
memset (&rekey, 0, sizeof(rekey));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral));
+ GNUNET_CRYPTO_ecdhe_key_create (&queue->ephemeral);
rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY);
rekey.header.size = ntohs (sizeof(rekey));
GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &rekey.ephemeral);
{
struct GNUNET_CRYPTO_EcdhePublicKey epub;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral));
+ GNUNET_CRYPTO_ecdhe_key_create (&queue->ephemeral);
GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &epub);
setup_out_cipher (queue);
transmit_kx (queue, &epub);
struct SharedSecret *ss;
/* setup key material */
- GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdhe_key_create2 (&epriv));
+ GNUNET_CRYPTO_ecdhe_key_create (&epriv);
ss = setup_shared_secret_enc (&epriv, receiver);
setup_cipher (&ss->master, 0, &out_cipher);
dv->monotime = GNUNET_TIME_absolute_get_monotonic (GST_cfg);
dv->ephemeral_validity =
GNUNET_TIME_absolute_add (dv->monotime, EPHEMERAL_VALIDITY);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_ecdhe_key_create2 (&dv->private_key));
+ GNUNET_CRYPTO_ecdhe_key_create (&dv->private_key);
GNUNET_CRYPTO_ecdhe_key_get_public (&dv->private_key, &dv->ephemeral_key);
ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL);
ec.purpose.size = htonl (sizeof(ec));
/**
* Our private key.
*/
-struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key;
+struct GNUNET_CRYPTO_EddsaPrivateKey GST_my_private_key;
/**
* ATS scheduling handle.
GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
GST_stats = NULL;
}
- if (NULL != GST_my_private_key)
- {
- GNUNET_free (GST_my_private_key);
- GST_my_private_key = NULL;
- }
}
struct GNUNET_SERVICE_Handle *service)
{
char *keyfile;
- struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
long long unsigned int max_fd_cfg;
int max_fd_rlimit;
int max_fd;
{
hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
}
- pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
+ if (GNUNET_SYSERR ==
+ GNUNET_CRYPTO_eddsa_key_from_file (keyfile,
+ GNUNET_YES,
+ &GST_my_private_key))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to setup peer's private key\n");
+ GNUNET_SCHEDULER_shutdown ();
+ GNUNET_free (keyfile);
+ return;
+ }
GNUNET_free (keyfile);
- GNUNET_assert (NULL != pk);
- GST_my_private_key = pk;
-
GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg);
- GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key,
+ GNUNET_CRYPTO_eddsa_key_get_public (&GST_my_private_key,
&GST_my_identity.public_key);
- GNUNET_assert (NULL != GST_my_private_key);
-
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"My identity is `%s'\n",
GNUNET_i2s_full (&GST_my_identity));
/**
* Our private key.
*/
-extern struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key;
+extern struct GNUNET_CRYPTO_EddsaPrivateKey GST_my_private_key;
/**
* ATS handle.
GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
disconnect_msg.public_key = GST_my_identity.public_key;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_eddsa_sign_ (GST_my_private_key,
+ GNUNET_CRYPTO_eddsa_sign_ (&GST_my_private_key,
&disconnect_msg.purpose,
&disconnect_msg.signature));
*sig_cache_exp = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME);
pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
if (GNUNET_OK !=
- GNUNET_CRYPTO_eddsa_sign_ (GST_my_private_key,
+ GNUNET_CRYPTO_eddsa_sign_ (&GST_my_private_key,
&pong->purpose,
sig_cache))
{
/**
- * Create a new private key. Caller must free return value.
+ * Create a new private key.
*
- * @return fresh private key
+ * @param[out] pk fresh private key
*/
-struct GNUNET_CRYPTO_EcdhePrivateKey *
-GNUNET_CRYPTO_ecdhe_key_create ()
-{
- struct GNUNET_CRYPTO_EcdhePrivateKey *priv;
-
- priv = GNUNET_new (struct GNUNET_CRYPTO_EcdhePrivateKey);
- if (GNUNET_OK != GNUNET_CRYPTO_ecdhe_key_create2 (priv))
- {
- GNUNET_free (priv);
- return NULL;
- }
- return priv;
-}
-
-
-/**
- * @ingroup crypto
- * Create a new private key. Clear with #GNUNET_CRYPTO_ecdhe_key_clear().
- *
- * @param[out] pk set to fresh private key;
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
- */
-int
-GNUNET_CRYPTO_ecdhe_key_create2 (struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
+void
+GNUNET_CRYPTO_ecdhe_key_create (struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
{
BENCHMARK_START (ecdhe_key_create);
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
pk,
sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey));
BENCHMARK_END (ecdhe_key_create);
- return GNUNET_OK;
}
/**
- * Create a new private key. Caller must free return value.
+ * Create a new private key.
*
- * @return fresh private key
+ * @param[out] pk private key to initialize
*/
-struct GNUNET_CRYPTO_EcdsaPrivateKey *
-GNUNET_CRYPTO_ecdsa_key_create ()
+void
+GNUNET_CRYPTO_ecdsa_key_create (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
{
- struct GNUNET_CRYPTO_EcdsaPrivateKey *priv;
gcry_sexp_t priv_sexp;
gcry_sexp_t s_keyparam;
gcry_mpi_t d;
int rc;
BENCHMARK_START (ecdsa_key_create);
-
if (0 != (rc = gcry_sexp_build (&s_keyparam,
NULL,
"(genkey(ecc(curve \"" CURVE "\")"
"(flags)))")))
{
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
- return NULL;
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
+ "gcry_sexp_build",
+ rc);
+ GNUNET_assert (0);
}
- if (0 != (rc = gcry_pk_genkey (&priv_sexp, s_keyparam)))
+ if (0 != (rc = gcry_pk_genkey (&priv_sexp,
+ s_keyparam)))
{
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_genkey", rc);
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
+ "gcry_pk_genkey",
+ rc);
gcry_sexp_release (s_keyparam);
- return NULL;
+ GNUNET_assert (0);
}
gcry_sexp_release (s_keyparam);
#if EXTRA_CHECKS
if (0 != (rc = gcry_pk_testkey (priv_sexp)))
{
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc);
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
+ "gcry_pk_testkey",
+ rc);
gcry_sexp_release (priv_sexp);
- return NULL;
+ GNUNET_assert (0);
}
#endif
- if (0 != (rc = key_from_sexp (&d, priv_sexp, "private-key", "d")))
+ if (0 != (rc = key_from_sexp (&d, priv_sexp,
+ "private-key",
+ "d")))
{
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "key_from_sexp", rc);
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
+ "key_from_sexp",
+ rc);
gcry_sexp_release (priv_sexp);
- return NULL;
+ GNUNET_assert (0);
}
gcry_sexp_release (priv_sexp);
- priv = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey);
- GNUNET_CRYPTO_mpi_print_unsigned (priv->d, sizeof(priv->d), d);
+ GNUNET_CRYPTO_mpi_print_unsigned (pk->d,
+ sizeof(pk->d),
+ d);
gcry_mpi_release (d);
-
BENCHMARK_END (ecdsa_key_create);
-
- return priv;
}
/**
- * Create a new private key. Caller must free return value.
+ * Create a new private key.
*
- * @return fresh private key
+ * @param[out] pk set to fresh private key
*/
-struct GNUNET_CRYPTO_EddsaPrivateKey *
-GNUNET_CRYPTO_eddsa_key_create ()
+void
+GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
{
- struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
-
BENCHMARK_START (eddsa_key_create);
- priv = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey);
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
- priv,
+ pk,
sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
+ // FIXME: should we not do the clamping here? Or is this done elsewhere?
BENCHMARK_END (eddsa_key_create);
-
- return priv;
}
/*
This file is part of GNUnet.
- Copyright (C) 2012, 2013, 2015 GNUnet e.V.
+ Copyright (C) 2012, 2013, 2015, 2020 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
/**
- * Wait for a short time (we're trying to lock a file or want
- * to give another process a shot at finishing a disk write, etc.).
- * Sleeps for 100ms (as that should be long enough for virtually all
- * modern systems to context switch and allow another process to do
- * some 'real' work).
+ * Read file to @a buf. Fails if the file does not exist or
+ * does not have precisely @a buf_size bytes.
+ *
+ * @param filename file to read
+ * @param[out] buf where to write the file contents
+ * @param buf_size number of bytes in @a buf
+ * @return #GNUNET_OK on success
*/
-static void
-short_wait ()
+static int
+read_from_file (const char *filename,
+ void *buf,
+ size_t buf_size)
{
- struct GNUNET_TIME_Relative timeout;
+ int fd;
+ struct stat sb;
- timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 100);
- (void) GNUNET_NETWORK_socket_select (NULL, NULL, NULL, timeout);
+ fd = open (filename,
+ O_RDONLY);
+ if (-1 == fd)
+ {
+ memset (buf,
+ 0,
+ buf_size);
+ return GNUNET_SYSERR;
+ }
+ if (0 != fstat (fd,
+ &sb))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "stat",
+ filename);
+ GNUNET_assert (0 == close (fd));
+ memset (buf,
+ 0,
+ buf_size);
+ return GNUNET_SYSERR;
+ }
+ if (sb.st_size != buf_size)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "File `%s' has wrong size (%llu), expected %llu bytes\n",
+ filename,
+ (unsigned long long) sb.st_size,
+ (unsigned long long) buf_size);
+ GNUNET_assert (0 == close (fd));
+ memset (buf,
+ 0,
+ buf_size);
+ return GNUNET_SYSERR;
+ }
+ if (buf_size !=
+ read (fd,
+ buf,
+ buf_size))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "read",
+ filename);
+ GNUNET_assert (0 == close (fd));
+ memset (buf,
+ 0,
+ buf_size);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_assert (0 == close (fd));
+ return GNUNET_OK;
}
/**
- * Create a new private key by reading it from a file. If the
- * files does not exist, create a new key and write it to the
- * file. Caller must free return value. Note that this function
- * can not guarantee that another process might not be trying
- * the same operation on the same file at the same time.
- * If the contents of the file
- * are invalid the old file is deleted and a fresh key is
- * created.
+ * Write contents of @a buf atomically to @a filename.
+ * Fail if @a filename already exists or if not exactly
+ * @a buf with @a buf_size bytes could be written to
+ * @a filename.
*
- * @param filename name of file to use to store the key
- * @return new private key, NULL on error (for example,
- * permission denied)
+ * @param filename where to write
+ * @param buf buffer to write
+ * @param buf_size number of bytes in @a buf to write
+ * @return #GNUNET_OK on success,
+ * #GNUNET_NO if a file existed under @a filename
+ * #GNUNET_SYSERR on failure
*/
-struct GNUNET_CRYPTO_EddsaPrivateKey *
-GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
+static int
+atomic_write_to_file (const char *filename,
+ const void *buf,
+ size_t buf_size)
{
- struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
- struct GNUNET_DISK_FileHandle *fd;
- unsigned int cnt;
- int ec;
- uint64_t fs;
- ssize_t sret;
+ char *tmpl;
+ int fd;
- if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename))
- return NULL;
- while (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
- fd =
- GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE
- | GNUNET_DISK_OPEN_FAILIFEXISTS,
- GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
- if (NULL == fd)
- {
- if (EEXIST == errno)
- {
- if (GNUNET_YES != GNUNET_DISK_file_test (filename))
- {
- /* must exist but not be accessible, fail for good! */
- if (0 != access (filename, R_OK))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename);
- else
- GNUNET_break (0); /* what is going on!? */
- return NULL;
- }
- continue;
- }
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
- return NULL;
- }
- cnt = 0;
- while (GNUNET_YES !=
- GNUNET_DISK_file_lock (fd,
- 0,
- sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey),
- GNUNET_YES))
- {
- short_wait ();
- if (0 == ++cnt % 10)
- {
- ec = errno;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _ ("Could not acquire lock on file `%s': %s...\n"),
- filename,
- strerror (ec));
- }
- }
- LOG (GNUNET_ERROR_TYPE_INFO,
- _ ("Creating a new private key. This may take a while.\n"));
- priv = GNUNET_CRYPTO_eddsa_key_create ();
- GNUNET_assert (NULL != priv);
- GNUNET_assert (sizeof(*priv) ==
- GNUNET_DISK_file_write (fd, priv, sizeof(*priv)));
- GNUNET_DISK_file_sync (fd);
- if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd,
- 0,
- sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
- GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
- return priv;
+ char *dname;
+
+ dname = GNUNET_strdup (filename);
+ GNUNET_asprintf (&tmpl,
+ "%s/XXXXXX",
+ dirname (dname));
+ GNUNET_free (dname);
}
- /* key file exists already, read it! */
- fd = GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
- if (NULL == fd)
+ fd = mkstemp (tmpl);
+ if (-1 == fd)
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
- return NULL;
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "mkstemp",
+ tmpl);
+ GNUNET_free (tmpl);
+ return GNUNET_SYSERR;
}
- cnt = 0;
- while (1)
+ if (0 != fchmod (fd,
+ S_IRUSR))
{
- if (GNUNET_YES !=
- GNUNET_DISK_file_lock (fd,
- 0,
- sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey),
- GNUNET_NO))
- {
- if (0 == ++cnt % 60)
- {
- ec = errno;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _ ("Could not acquire lock on file `%s': %s...\n"),
- filename,
- strerror (ec));
- LOG (
- GNUNET_ERROR_TYPE_ERROR,
- _ (
- "This may be ok if someone is currently generating a private key.\n"));
- }
- short_wait ();
- continue;
- }
- if (GNUNET_YES != GNUNET_DISK_file_test (filename))
- {
- /* eh, what!? File we opened is now gone!? */
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
- if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd,
- 0,
- sizeof(
- struct GNUNET_CRYPTO_EddsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
- GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
-
- return NULL;
- }
- if (GNUNET_OK !=
- GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
- fs = 0;
- if (fs < sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey))
- {
- /* maybe we got the read lock before the key generating
- * process had a chance to get the write lock; give it up! */
- if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd,
- 0,
- sizeof(
- struct GNUNET_CRYPTO_EddsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
- if (0 == ++cnt % 10)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _ (
- "When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
- filename,
- (unsigned int) fs,
- (unsigned int) sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey));
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _ ("This may be ok if someone is currently generating a key.\n"));
- }
- short_wait (); /* wait a bit longer! */
- continue;
- }
- break;
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "chmod",
+ tmpl);
+ GNUNET_assert (0 == close (fd));
+ if (0 != unlink (tmpl))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "unlink",
+ tmpl);
+ GNUNET_free (tmpl);
+ return GNUNET_SYSERR;
}
- fs = sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey);
- priv = GNUNET_malloc (fs);
- sret = GNUNET_DISK_file_read (fd, priv, fs);
- GNUNET_assert ((sret >= 0) && (fs == (size_t) sret));
- if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd,
- 0,
- sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
- GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
-#if CRYPTO_BUG
- if (GNUNET_OK != check_eddsa_key (priv))
+ if (buf_size !=
+ write (fd,
+ buf,
+ buf_size))
{
- GNUNET_break (0);
- GNUNET_free (priv);
- return NULL;
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "write",
+ tmpl);
+ GNUNET_assert (0 == close (fd));
+ if (0 != unlink (tmpl))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "unlink",
+ tmpl);
+ GNUNET_free (tmpl);
+ return GNUNET_SYSERR;
}
-#endif
- return priv;
+ GNUNET_assert (0 == close (fd));
+
+ if (0 != link (tmpl,
+ filename))
+ {
+ if (0 != unlink (tmpl))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "unlink",
+ tmpl);
+ GNUNET_free (tmpl);
+ return GNUNET_NO;
+ }
+ if (0 != unlink (tmpl))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "unlink",
+ tmpl);
+ GNUNET_free (tmpl);
+ return GNUNET_OK;
}
/**
- * Create a new private key by reading it from a file. If the
- * files does not exist, create a new key and write it to the
- * file. Caller must free return value. Note that this function
- * can not guarantee that another process might not be trying
- * the same operation on the same file at the same time.
- * If the contents of the file
- * are invalid the old file is deleted and a fresh key is
- * created.
+ * @ingroup crypto
+ * @brief Create a new private key by reading it from a file.
+ *
+ * If the files does not exist and @a do_create is set, creates a new key and
+ * write it to the file.
+ *
+ * If the contents of the file are invalid, an error is returned.
*
* @param filename name of file to use to store the key
- * @return new private key, NULL on error (for example,
- * permission denied)
+ * @param do_create should a file be created?
+ * @param[out] pkey set to the private key from @a filename on success
+ * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but
+ * we found an existing file, #GNUNET_SYSERR on failure
*/
-struct GNUNET_CRYPTO_EcdsaPrivateKey *
-GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
+int
+GNUNET_CRYPTO_eddsa_key_from_file (const char *filename,
+ int do_create,
+ struct GNUNET_CRYPTO_EddsaPrivateKey *pkey)
{
- struct GNUNET_CRYPTO_EcdsaPrivateKey *priv;
- struct GNUNET_DISK_FileHandle *fd;
- unsigned int cnt;
- int ec;
- uint64_t fs;
- ssize_t sret;
-
- if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename))
- return NULL;
- while (GNUNET_YES != GNUNET_DISK_file_test (filename))
+ int ret;
+
+ if (GNUNET_OK ==
+ read_from_file (filename,
+ pkey,
+ sizeof (*pkey)))
{
- fd =
- GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE
- | GNUNET_DISK_OPEN_FAILIFEXISTS,
- GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
- if (NULL == fd)
- {
- if (EEXIST == errno)
- {
- if (GNUNET_YES != GNUNET_DISK_file_test (filename))
- {
- /* must exist but not be accessible, fail for good! */
- if (0 != access (filename, R_OK))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename);
- else
- GNUNET_break (0); /* what is going on!? */
- return NULL;
- }
- continue;
- }
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
- return NULL;
- }
- cnt = 0;
- while (GNUNET_YES !=
- GNUNET_DISK_file_lock (fd,
- 0,
- sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey),
- GNUNET_YES))
- {
- short_wait ();
- if (0 == ++cnt % 10)
- {
- ec = errno;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _ ("Could not acquire lock on file `%s': %s...\n"),
- filename,
- strerror (ec));
- }
- }
- LOG (GNUNET_ERROR_TYPE_INFO,
- _ ("Creating a new private key. This may take a while.\n"));
- priv = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_assert (NULL != priv);
- GNUNET_assert (sizeof(*priv) ==
- GNUNET_DISK_file_write (fd, priv, sizeof(*priv)));
- GNUNET_DISK_file_sync (fd);
- if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd,
- 0,
- sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
- GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
- return priv;
+ /* file existed, report that we didn't create it... */
+ return (do_create) ? GNUNET_NO : GNUNET_OK;
}
- /* key file exists already, read it! */
- fd = GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
- if (NULL == fd)
+ GNUNET_CRYPTO_eddsa_key_create (pkey);
+ ret = atomic_write_to_file (filename,
+ pkey,
+ sizeof (*pkey));
+ if ( (GNUNET_OK == ret) ||
+ (GNUNET_SYSERR == ret) )
+ return ret;
+ /* maybe another process succeeded in the meantime, try reading one more time */
+ if (GNUNET_OK ==
+ read_from_file (filename,
+ pkey,
+ sizeof (*pkey)))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
- return NULL;
+ /* file existed, report that *we* didn't create it... */
+ return (do_create) ? GNUNET_NO : GNUNET_OK;
}
- cnt = 0;
- while (1)
+ /* give up */
+ return GNUNET_SYSERR;
+}
+
+
+/**
+ * @ingroup crypto
+ * @brief Create a new private key by reading it from a file.
+ *
+ * If the files does not exist and @a do_create is set, creates a new key and
+ * write it to the file.
+ *
+ * If the contents of the file are invalid, an error is returned.
+ *
+ * @param filename name of file to use to store the key
+ * @param do_create should a file be created?
+ * @param[out] pkey set to the private key from @a filename on success
+ * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but
+ * we found an existing file, #GNUNET_SYSERR on failure
+ */
+int
+GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename,
+ int do_create,
+ struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey)
+{
+ if (GNUNET_OK ==
+ read_from_file (filename,
+ pkey,
+ sizeof (*pkey)))
{
- if (GNUNET_YES !=
- GNUNET_DISK_file_lock (fd,
- 0,
- sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey),
- GNUNET_NO))
- {
- if (0 == ++cnt % 60)
- {
- ec = errno;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _ ("Could not acquire lock on file `%s': %s...\n"),
- filename,
- strerror (ec));
- LOG (
- GNUNET_ERROR_TYPE_ERROR,
- _ (
- "This may be ok if someone is currently generating a private key.\n"));
- }
- short_wait ();
- continue;
- }
- if (GNUNET_YES != GNUNET_DISK_file_test (filename))
- {
- /* eh, what!? File we opened is now gone!? */
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
- if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd,
- 0,
- sizeof(
- struct GNUNET_CRYPTO_EcdsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
- GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
-
- return NULL;
- }
- if (GNUNET_OK !=
- GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
- fs = 0;
- if (fs < sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey))
- {
- /* maybe we got the read lock before the key generating
- * process had a chance to get the write lock; give it up! */
- if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd,
- 0,
- sizeof(
- struct GNUNET_CRYPTO_EcdsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
- if (0 == ++cnt % 10)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _ (
- "When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
- filename,
- (unsigned int) fs,
- (unsigned int) sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey));
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _ ("This may be ok if someone is currently generating a key.\n"));
- }
- short_wait (); /* wait a bit longer! */
- continue;
- }
- break;
+ /* file existed, report that we didn't create it... */
+ return (do_create) ? GNUNET_NO : GNUNET_OK;
}
- fs = sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey);
- priv = GNUNET_malloc (fs);
- sret = GNUNET_DISK_file_read (fd, priv, fs);
- GNUNET_assert ((sret >= 0) && (fs == (size_t) sret));
- if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd,
- 0,
- sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
- GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
- return priv;
+ GNUNET_CRYPTO_ecdsa_key_create (pkey);
+ if (GNUNET_OK ==
+ atomic_write_to_file (filename,
+ pkey,
+ sizeof (*pkey)))
+ return GNUNET_OK;
+ /* maybe another process succeeded in the meantime, try reading one more time */
+ if (GNUNET_OK ==
+ read_from_file (filename,
+ pkey,
+ sizeof (*pkey)))
+ {
+ /* file existed, report that *we* didn't create it... */
+ return (do_create) ? GNUNET_NO : GNUNET_OK;
+ }
+ /* give up */
+ return GNUNET_SYSERR;
}
char *fn;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER", "PRIVATE_KEY", &fn))
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "PEER",
+ "PRIVATE_KEY",
+ &fn))
return NULL;
- priv = GNUNET_CRYPTO_eddsa_key_create_from_file (fn);
+ priv = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey);
+ GNUNET_CRYPTO_eddsa_key_from_file (fn,
+ GNUNET_YES,
+ priv);
GNUNET_free (fn);
return priv;
}
_ ("Could not load peer's private key\n"));
return GNUNET_SYSERR;
}
- GNUNET_CRYPTO_eddsa_key_get_public (priv, &dst->public_key);
+ GNUNET_CRYPTO_eddsa_key_get_public (priv,
+ &dst->public_key);
GNUNET_free (priv);
return GNUNET_OK;
}
}
-/**
- * Lock a part of a file
- *
- * @param fh file handle
- * @param lock_start absolute position from where to lock
- * @param lock_end absolute position until where to lock
- * @param excl #GNUNET_YES for an exclusive lock
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
- */
-int
-GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh,
- off_t lock_start,
- off_t lock_end,
- int excl)
-{
- if (fh == NULL)
- {
- errno = EINVAL;
- return GNUNET_SYSERR;
- }
-
- struct flock fl;
-
- memset (&fl, 0, sizeof(struct flock));
- fl.l_type = excl ? F_WRLCK : F_RDLCK;
- fl.l_whence = SEEK_SET;
- fl.l_start = lock_start;
- fl.l_len = lock_end;
-
- return fcntl (fh->fd, F_SETLK, &fl) != 0 ? GNUNET_SYSERR : GNUNET_OK;
-}
-
-
-/**
- * Unlock a part of a file
- *
- * @param fh file handle
- * @param unlock_start absolute position from where to unlock
- * @param unlock_end absolute position until where to unlock
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
- */
-int
-GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh,
- off_t unlock_start,
- off_t unlock_end)
-{
- if (fh == NULL)
- {
- errno = EINVAL;
- return GNUNET_SYSERR;
- }
-
- struct flock fl;
-
- memset (&fl, 0, sizeof(struct flock));
- fl.l_type = F_UNLCK;
- fl.l_whence = SEEK_SET;
- fl.l_start = unlock_start;
- fl.l_len = unlock_end;
-
- return fcntl (fh->fd, F_SETLK, &fl) != 0 ? GNUNET_SYSERR : GNUNET_OK;
-}
-
-
/**
* Open a file. Note that the access permissions will only be
* used if a new file is created and if the underlying operating
display_data (" output", &hc, sizeof (struct GNUNET_HashCode));
}
{
- struct GNUNET_CRYPTO_EcdhePrivateKey *priv1;
+ struct GNUNET_CRYPTO_EcdhePrivateKey priv1;
struct GNUNET_CRYPTO_EcdhePublicKey pub1;
- struct GNUNET_CRYPTO_EcdhePrivateKey *priv2;
+ struct GNUNET_CRYPTO_EcdhePrivateKey priv2;
struct GNUNET_HashCode skm;
- priv1 = GNUNET_CRYPTO_ecdhe_key_create ();
- priv2 = GNUNET_CRYPTO_ecdhe_key_create ();
- GNUNET_CRYPTO_ecdhe_key_get_public (priv1, &pub1);
- GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecc_ecdh (priv2, &pub1, &skm));
+
+ GNUNET_CRYPTO_ecdhe_key_create (&priv1);
+ GNUNET_CRYPTO_ecdhe_key_create (&priv2);
+ GNUNET_CRYPTO_ecdhe_key_get_public (&priv1,
+ &pub1);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_ecc_ecdh (&priv2,
+ &pub1,
+ &skm));
printf ("ecdhe key:\n");
- display_data (" priv1", priv1, sizeof (struct
- GNUNET_CRYPTO_EcdhePrivateKey));
- display_data (" pub1", &pub1, sizeof (struct
- GNUNET_CRYPTO_EcdhePublicKey));
- display_data (" priv2", priv2, sizeof (struct
- GNUNET_CRYPTO_EcdhePrivateKey));
- display_data (" skm", &skm, sizeof (struct GNUNET_HashCode));
- GNUNET_free (priv1);
- GNUNET_free (priv2);
+ display_data (" priv1",
+ &priv1,
+ sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey));
+ display_data (" pub1",
+ &pub1,
+ sizeof (struct GNUNET_CRYPTO_EcdhePublicKey));
+ display_data (" priv2",
+ &priv2,
+ sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey));
+ display_data (" skm",
+ &skm,
+ sizeof (struct GNUNET_HashCode));
}
{
- struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
+ struct GNUNET_CRYPTO_EddsaPrivateKey priv;
struct GNUNET_CRYPTO_EddsaPublicKey pub;
- priv = GNUNET_CRYPTO_eddsa_key_create ();
- GNUNET_CRYPTO_eddsa_key_get_public (priv, &pub);
+
+ GNUNET_CRYPTO_eddsa_key_create (&priv);
+ GNUNET_CRYPTO_eddsa_key_get_public (&priv,
+ &pub);
printf ("eddsa key:\n");
- display_data (" priv", priv, sizeof (struct
- GNUNET_CRYPTO_EddsaPrivateKey));
- display_data (" pub", &pub, sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
- GNUNET_free (priv);
+ display_data (" priv",
+ &priv,
+ sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
+ display_data (" pub",
+ &pub,
+ sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
}
{
- struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
+ struct GNUNET_CRYPTO_EddsaPrivateKey priv;
struct GNUNET_CRYPTO_EddsaPublicKey pub;
struct GNUNET_CRYPTO_EddsaSignature sig;
struct TestSignatureDataPS data = { 0 };
- priv = GNUNET_CRYPTO_eddsa_key_create ();
- GNUNET_CRYPTO_eddsa_key_get_public (priv, &pub);
+ GNUNET_CRYPTO_eddsa_key_create (&priv);
+ GNUNET_CRYPTO_eddsa_key_get_public (&priv,
+ &pub);
data.purpose.size = htonl (sizeof (data));
data.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
- GNUNET_CRYPTO_eddsa_sign (priv,
+ GNUNET_CRYPTO_eddsa_sign (&priv,
&data,
&sig);
GNUNET_assert (GNUNET_OK ==
&pub));
printf ("eddsa sig:\n");
- display_data (" priv", priv, sizeof (struct
- GNUNET_CRYPTO_EddsaPrivateKey));
- display_data (" pub", &pub, sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
- display_data (" data", &data, sizeof (struct TestSignatureDataPS));
- display_data (" sig", &sig, sizeof (struct GNUNET_CRYPTO_EddsaSignature));
- GNUNET_free (priv);
+ display_data (" priv",
+ &priv,
+ sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
+ display_data (" pub",
+ &pub,
+ sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
+ display_data (" data",
+ &data,
+ sizeof (struct TestSignatureDataPS));
+ display_data (" sig",
+ &sig,
+ sizeof (struct GNUNET_CRYPTO_EddsaSignature));
}
{
display_data (" out", out, out_len);
}
{
- struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ecdhe;
+ struct GNUNET_CRYPTO_EcdhePrivateKey priv_ecdhe;
struct GNUNET_CRYPTO_EcdhePublicKey pub_ecdhe;
- struct GNUNET_CRYPTO_EddsaPrivateKey *priv_eddsa;
+ struct GNUNET_CRYPTO_EddsaPrivateKey priv_eddsa;
struct GNUNET_CRYPTO_EddsaPublicKey pub_eddsa;
struct GNUNET_HashCode key_material;
- priv_ecdhe = GNUNET_CRYPTO_ecdhe_key_create ();
- GNUNET_CRYPTO_ecdhe_key_get_public (priv_ecdhe, &pub_ecdhe);
- priv_eddsa = GNUNET_CRYPTO_eddsa_key_create ();
- GNUNET_CRYPTO_eddsa_key_get_public (priv_eddsa, &pub_eddsa);
- GNUNET_CRYPTO_ecdh_eddsa (priv_ecdhe, &pub_eddsa, &key_material);
+
+ GNUNET_CRYPTO_ecdhe_key_create (&priv_ecdhe);
+ GNUNET_CRYPTO_ecdhe_key_get_public (&priv_ecdhe, &pub_ecdhe);
+ GNUNET_CRYPTO_eddsa_key_create (&priv_eddsa);
+ GNUNET_CRYPTO_eddsa_key_get_public (&priv_eddsa, &pub_eddsa);
+ GNUNET_CRYPTO_ecdh_eddsa (&priv_ecdhe, &pub_eddsa, &key_material);
printf ("eddsa_ecdh:\n");
- display_data (" priv_ecdhe", priv_ecdhe, sizeof (struct
- GNUNET_CRYPTO_EcdhePrivateKey));
- display_data (" pub_ecdhe", &pub_ecdhe, sizeof (struct
- GNUNET_CRYPTO_EcdhePublicKey));
- display_data (" priv_eddsa", priv_eddsa, sizeof (struct
- GNUNET_CRYPTO_EddsaPrivateKey));
- display_data (" pub_eddsa", &pub_eddsa, sizeof (struct
- GNUNET_CRYPTO_EddsaPublicKey));
- display_data (" key_material", &key_material, sizeof (struct
- GNUNET_HashCode));
+ display_data (" priv_ecdhe",
+ &priv_ecdhe,
+ sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey));
+ display_data (" pub_ecdhe",
+ &pub_ecdhe,
+ sizeof (struct GNUNET_CRYPTO_EcdhePublicKey));
+ display_data (" priv_eddsa",
+ &priv_eddsa,
+ sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
+ display_data (" pub_eddsa",
+ &pub_eddsa,
+ sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
+ display_data (" key_material",
+ &key_material,
+ sizeof (struct GNUNET_HashCode));
}
{
create_keys (const char *fn, const char *prefix)
{
FILE *f;
- struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
+ struct GNUNET_CRYPTO_EddsaPrivateKey pk;
struct GNUNET_CRYPTO_EddsaPublicKey target_pub;
static char vanity[KEY_STR_LEN + 1];
size_t len;
while (0 < make_keys--)
{
fprintf (stderr, ".");
- if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create ()))
- {
- GNUNET_break (0);
- break;
- }
+ GNUNET_CRYPTO_eddsa_key_create (&pk);
if (NULL != prefix)
{
struct GNUNET_CRYPTO_EddsaPublicKey newkey;
- GNUNET_CRYPTO_eddsa_key_get_public (pk, &newkey);
- if (0 != memcmp (&target_pub, &newkey, n))
+ GNUNET_CRYPTO_eddsa_key_get_public (&pk,
+ &newkey);
+ if (0 != memcmp (&target_pub,
+ &newkey,
+ n))
{
make_keys++;
continue;
}
}
if (GNUNET_TESTING_HOSTKEYFILESIZE !=
- fwrite (pk, 1, GNUNET_TESTING_HOSTKEYFILESIZE, f))
+ fwrite (&pk,
+ 1,
+ GNUNET_TESTING_HOSTKEYFILESIZE,
+ f))
{
fprintf (stderr,
_ ("\nFailed to write to `%s': %s\n"),
fn,
strerror (errno));
- GNUNET_free (pk);
break;
}
- GNUNET_free (pk);
}
if (UINT_MAX == make_keys)
fprintf (stderr, _ ("\nFinished!\n"));
static void
-print_examples_ecdh ()
+print_examples_ecdh (void)
{
- struct GNUNET_CRYPTO_EcdhePrivateKey *dh_priv1;
- struct GNUNET_CRYPTO_EcdhePublicKey *dh_pub1;
- struct GNUNET_CRYPTO_EcdhePrivateKey *dh_priv2;
- struct GNUNET_CRYPTO_EcdhePublicKey *dh_pub2;
+ struct GNUNET_CRYPTO_EcdhePrivateKey dh_priv1;
+ struct GNUNET_CRYPTO_EcdhePublicKey dh_pub1;
+ struct GNUNET_CRYPTO_EcdhePrivateKey dh_priv2;
+ struct GNUNET_CRYPTO_EcdhePublicKey dh_pub2;
struct GNUNET_HashCode hash;
char buf[128];
- dh_pub1 = GNUNET_new (struct GNUNET_CRYPTO_EcdhePublicKey);
- dh_priv1 = GNUNET_CRYPTO_ecdhe_key_create ();
- dh_pub2 = GNUNET_new (struct GNUNET_CRYPTO_EcdhePublicKey);
- dh_priv2 = GNUNET_CRYPTO_ecdhe_key_create ();
- GNUNET_CRYPTO_ecdhe_key_get_public (dh_priv1, dh_pub1);
- GNUNET_CRYPTO_ecdhe_key_get_public (dh_priv2, dh_pub2);
+ GNUNET_CRYPTO_ecdhe_key_create (&dh_priv1);
+ GNUNET_CRYPTO_ecdhe_key_create (&dh_priv2);
+ GNUNET_CRYPTO_ecdhe_key_get_public (&dh_priv1,
+ &dh_pub1);
+ GNUNET_CRYPTO_ecdhe_key_get_public (&dh_priv2,
+ &dh_pub2);
GNUNET_assert (NULL !=
- GNUNET_STRINGS_data_to_string (dh_priv1, 32, buf, 128));
+ GNUNET_STRINGS_data_to_string (&dh_priv1,
+ sizeof (dh_priv1),
+ buf,
+ sizeof (buf)));
printf ("ECDHE key 1:\n");
- printf ("private: %s\n", buf);
- print_hex ("private(hex)", dh_priv1, sizeof *dh_priv1);
- GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_pub1, 32, buf, 128));
- printf ("public: %s\n", buf);
- print_hex ("public(hex)", dh_pub1, sizeof *dh_pub1);
+ printf ("private: %s\n",
+ buf);
+ print_hex ("private(hex)",
+ &dh_priv1, sizeof (dh_priv1));
+ GNUNET_assert (NULL !=
+ GNUNET_STRINGS_data_to_string (&dh_pub1,
+ sizeof (dh_pub1),
+ buf,
+ sizeof (buf)));
+ printf ("public: %s\n",
+ buf);
+ print_hex ("public(hex)",
+ &dh_pub1,
+ sizeof (dh_pub1));
GNUNET_assert (NULL !=
- GNUNET_STRINGS_data_to_string (dh_priv2, 32, buf, 128));
+ GNUNET_STRINGS_data_to_string (&dh_priv2,
+ sizeof (dh_priv2),
+ buf,
+ sizeof (buf)));
printf ("ECDHE key 2:\n");
printf ("private: %s\n", buf);
- print_hex ("private(hex)", dh_priv2, sizeof *dh_priv2);
- GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_pub2, 32, buf, 128));
+ print_hex ("private(hex)",
+ &dh_priv2,
+ sizeof (dh_priv2));
+ GNUNET_assert (NULL !=
+ GNUNET_STRINGS_data_to_string (&dh_pub2,
+ sizeof (dh_pub2),
+ buf,
+ sizeof (buf)));
printf ("public: %s\n", buf);
- print_hex ("public(hex)", dh_pub2, sizeof *dh_pub2);
+ print_hex ("public(hex)",
+ &dh_pub2,
+ sizeof (dh_pub2));
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_ecc_ecdh (dh_priv1, dh_pub2, &hash));
- GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (&hash, 64, buf, 128));
- printf ("ECDH shared secret: %s\n", buf);
-
- GNUNET_free (dh_priv1);
- GNUNET_free (dh_priv2);
- GNUNET_free (dh_pub1);
- GNUNET_free (dh_pub2);
+ GNUNET_CRYPTO_ecc_ecdh (&dh_priv1,
+ &dh_pub2,
+ &hash));
+ GNUNET_assert (NULL !=
+ GNUNET_STRINGS_data_to_string (&hash,
+ sizeof (hash),
+ buf,
+ sizeof (buf)));
+ printf ("ECDH shared secret: %s\n",
+ buf);
+
}
* Print some random example operations to stdout.
*/
static void
-print_examples ()
+print_examples (void)
{
print_examples_ecdh ();
// print_examples_ecdsa ();
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *config)
{
- struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
+ struct GNUNET_CRYPTO_EddsaPrivateKey pk;
char *pids;
(void) cls;
}
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Private Key file: %s\n", pkfn);
- if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create_from_file (pkfn)))
+ if (GNUNET_SYSERR ==
+ GNUNET_CRYPTO_eddsa_key_from_file (pkfn,
+ GNUNET_YES,
+ &pk))
{
fprintf (stderr, _ ("Loading hostkey from `%s' failed.\n"), pkfn);
GNUNET_free (pkfn);
return;
}
GNUNET_free (pkfn);
- GNUNET_CRYPTO_eddsa_key_get_public (pk, &pub);
- GNUNET_free (pk);
+ GNUNET_CRYPTO_eddsa_key_get_public (&pk,
+ &pub);
pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer ID: %s\n", pids);
GNUNET_free (pids);
* @param proc pointer to process structure
* @param type status type
* @param code return code/signal number
- * @return #GNUNET_OK on success, #GNUNET_NO if the process is still running, #GNUNET_SYSERR otherwise
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
*/
int
GNUNET_OS_process_wait_status (struct GNUNET_OS_Process *proc,
static int
test_ecdh ()
{
- struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_dsa;
- struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ecdh;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey priv_dsa;
+ struct GNUNET_CRYPTO_EcdhePrivateKey priv_ecdh;
struct GNUNET_CRYPTO_EcdsaPublicKey id1;
struct GNUNET_CRYPTO_EcdhePublicKey id2;
struct GNUNET_HashCode dh[2];
/* Generate keys */
- priv_dsa = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_CRYPTO_ecdsa_key_get_public (priv_dsa,
+ GNUNET_CRYPTO_ecdsa_key_create (&priv_dsa);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&priv_dsa,
&id1);
for (unsigned int j = 0; j < 4; j++)
{
fprintf (stderr, ",");
- priv_ecdh = GNUNET_CRYPTO_ecdhe_key_create ();
+ GNUNET_CRYPTO_ecdhe_key_create (&priv_ecdh);
/* Extract public keys */
- GNUNET_CRYPTO_ecdhe_key_get_public (priv_ecdh,
+ GNUNET_CRYPTO_ecdhe_key_get_public (&priv_ecdh,
&id2);
/* Do ECDH */
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_ecdsa_ecdh (priv_dsa,
+ GNUNET_CRYPTO_ecdsa_ecdh (&priv_dsa,
&id2,
&dh[0]));
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_ecdh_ecdsa (priv_ecdh,
+ GNUNET_CRYPTO_ecdh_ecdsa (&priv_ecdh,
&id1,
&dh[1]));
/* Check that both DH results are equal. */
- GNUNET_assert (0 == memcmp (&dh[0],
- &dh[1],
- sizeof(struct GNUNET_HashCode)));
- GNUNET_free (priv_ecdh);
+ GNUNET_assert (0 ==
+ GNUNET_memcmp (&dh[0],
+ &dh[1]));
}
- GNUNET_free (priv_dsa);
return 0;
}
if (! gcry_check_version ("1.6.0"))
{
fprintf (stderr,
- _ (
- "libgcrypt has not the expected version (version %s is required).\n"),
+ "libgcrypt has not the expected version (version %s is required).\n",
"1.6.0");
return 0;
}
static int
test_ecdh ()
{
- struct GNUNET_CRYPTO_EddsaPrivateKey *priv_dsa;
- struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ecdh;
+ struct GNUNET_CRYPTO_EddsaPrivateKey priv_dsa;
+ struct GNUNET_CRYPTO_EcdhePrivateKey priv_ecdh;
struct GNUNET_CRYPTO_EddsaPublicKey id1;
struct GNUNET_CRYPTO_EcdhePublicKey id2;
struct GNUNET_HashCode dh[2];
/* Generate keys */
- priv_dsa = GNUNET_CRYPTO_eddsa_key_create ();
- GNUNET_CRYPTO_eddsa_key_get_public (priv_dsa,
+ GNUNET_CRYPTO_eddsa_key_create (&priv_dsa);
+ GNUNET_CRYPTO_eddsa_key_get_public (&priv_dsa,
&id1);
for (unsigned int j = 0; j < 4; j++)
{
fprintf (stderr, ",");
- priv_ecdh = GNUNET_CRYPTO_ecdhe_key_create ();
+ GNUNET_CRYPTO_ecdhe_key_create (&priv_ecdh);
/* Extract public keys */
- GNUNET_CRYPTO_ecdhe_key_get_public (priv_ecdh,
+ GNUNET_CRYPTO_ecdhe_key_get_public (&priv_ecdh,
&id2);
/* Do ECDH */
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_eddsa_ecdh (priv_dsa,
+ GNUNET_CRYPTO_eddsa_ecdh (&priv_dsa,
&id2,
&dh[0]));
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_ecdh_eddsa (priv_ecdh,
+ GNUNET_CRYPTO_ecdh_eddsa (&priv_ecdh,
&id1,
&dh[1]));
/* Check that both DH results are equal. */
- GNUNET_assert (0 == memcmp (&dh[0],
- &dh[1],
- sizeof(struct GNUNET_HashCode)));
- GNUNET_free (priv_ecdh);
+ GNUNET_assert (0 ==
+ GNUNET_memcmp (&dh[0],
+ &dh[1]));
}
- GNUNET_free (priv_dsa);
return 0;
}
int
main (int argc, char *argv[])
{
- struct GNUNET_CRYPTO_EcdhePrivateKey *priv1;
- struct GNUNET_CRYPTO_EcdhePrivateKey *priv2;
+ struct GNUNET_CRYPTO_EcdhePrivateKey priv1;
+ struct GNUNET_CRYPTO_EcdhePrivateKey priv2;
struct GNUNET_CRYPTO_EcdhePublicKey pub1;
struct GNUNET_CRYPTO_EcdhePublicKey pub2;
struct GNUNET_HashCode ecdh1;
if (! gcry_check_version ("1.6.0"))
{
fprintf (stderr,
- _
- (
- "libgcrypt has not the expected version (version %s is required).\n"),
+ "libgcrypt has not the expected version (version %s is required).\n",
"1.6.0");
return 0;
}
{
fprintf (stderr,
".");
- priv1 = GNUNET_CRYPTO_ecdhe_key_create ();
- priv2 = GNUNET_CRYPTO_ecdhe_key_create ();
- GNUNET_CRYPTO_ecdhe_key_get_public (priv1, &pub1);
- GNUNET_CRYPTO_ecdhe_key_get_public (priv2, &pub2);
- GNUNET_CRYPTO_ecc_ecdh (priv1, &pub2, &ecdh1);
- GNUNET_CRYPTO_ecc_ecdh (priv2, &pub1, &ecdh2);
- GNUNET_assert (0 == memcmp (&ecdh1, &ecdh2,
- sizeof(struct GNUNET_HashCode)));
- GNUNET_free (priv1);
- GNUNET_free (priv2);
+ GNUNET_CRYPTO_ecdhe_key_create (&priv1);
+ GNUNET_CRYPTO_ecdhe_key_create (&priv2);
+ GNUNET_CRYPTO_ecdhe_key_get_public (&priv1, &pub1);
+ GNUNET_CRYPTO_ecdhe_key_get_public (&priv2, &pub2);
+ GNUNET_CRYPTO_ecc_ecdh (&priv1, &pub2, &ecdh1);
+ GNUNET_CRYPTO_ecc_ecdh (&priv2, &pub1, &ecdh2);
+ GNUNET_assert (0 ==
+ GNUNET_memcmp (&ecdh1,
+ &ecdh2));
}
return 0;
}
#define PERF GNUNET_YES
-static struct GNUNET_CRYPTO_EcdsaPrivateKey *key;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey key;
static int
-testSignVerify ()
+testSignVerify (void)
{
struct GNUNET_CRYPTO_EcdsaSignature sig;
struct GNUNET_CRYPTO_EccSignaturePurpose purp;
struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
- int i;
struct GNUNET_TIME_Absolute start;
int ok = GNUNET_OK;
fprintf (stderr, "%s", "W");
- GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&key,
+ &pkey);
start = GNUNET_TIME_absolute_get ();
purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose));
purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
- for (i = 0; i < ITER; i++)
+ for (unsigned int i = 0; i < ITER; i++)
{
- fprintf (stderr, "%s", "."); fflush (stderr);
+ fprintf (stderr, "%s", ".");
+ fflush (stderr);
if (GNUNET_SYSERR ==
- GNUNET_CRYPTO_ecdsa_sign_ (key, &purp, &sig))
+ GNUNET_CRYPTO_ecdsa_sign_ (&key,
+ &purp,
+ &sig))
{
fprintf (stderr,
- "%s",
"GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n");
ok = GNUNET_SYSERR;
continue;
}
if (GNUNET_SYSERR ==
GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TEST,
- &purp, &sig,
+ &purp,
+ &sig,
&pkey))
{
- printf ("GNUNET_CRYPTO_ecdsa_verify failed!\n");
+ fprintf (stderr,
+ "GNUNET_CRYPTO_ecdsa_verify failed!\n");
ok = GNUNET_SYSERR;
continue;
}
if (GNUNET_SYSERR !=
GNUNET_CRYPTO_ecdsa_verify_ (
GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
- &purp, &sig, &pkey))
+ &purp,
+ &sig,
+ &pkey))
{
- printf ("GNUNET_CRYPTO_ecdsa_verify failed to fail!\n");
+ fprintf (stderr,
+ "GNUNET_CRYPTO_ecdsa_verify failed to fail!\n");
ok = GNUNET_SYSERR;
continue;
}
}
- printf ("%d ECDSA sign/verify operations %s\n", ITER,
+ printf ("%d ECDSA sign/verify operations %s\n",
+ ITER,
GNUNET_STRINGS_relative_time_to_string (
- GNUNET_TIME_absolute_get_duration (start), GNUNET_YES));
+ GNUNET_TIME_absolute_get_duration (start),
+ GNUNET_YES));
return ok;
}
static int
-testDeriveSignVerify ()
+testDeriveSignVerify (void)
{
struct GNUNET_CRYPTO_EcdsaSignature sig;
struct GNUNET_CRYPTO_EccSignaturePurpose purp;
struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
struct GNUNET_CRYPTO_EcdsaPublicKey dpub;
- dpriv = GNUNET_CRYPTO_ecdsa_private_key_derive (key, "test-derive",
+ dpriv = GNUNET_CRYPTO_ecdsa_private_key_derive (&key,
+ "test-derive",
"test-CTX");
- GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey);
- GNUNET_CRYPTO_ecdsa_public_key_derive (&pkey, "test-derive", "test-CTX",
+ GNUNET_CRYPTO_ecdsa_key_get_public (&key,
+ &pkey);
+ GNUNET_CRYPTO_ecdsa_public_key_derive (&pkey,
+ "test-derive",
+ "test-CTX",
&dpub);
purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose));
purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
- if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign_ (dpriv, &purp, &sig))
+ if (GNUNET_SYSERR ==
+ GNUNET_CRYPTO_ecdsa_sign_ (dpriv,
+ &purp,
+ &sig))
{
fprintf (stderr, "%s", "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n");
GNUNET_free (dpriv);
}
if (GNUNET_SYSERR ==
GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TEST,
- &purp, &sig,
+ &purp,
+ &sig,
&dpub))
{
- printf ("GNUNET_CRYPTO_ecdsa_verify failed!\n");
+ fprintf (stderr,
+ "GNUNET_CRYPTO_ecdsa_verify failed!\n");
GNUNET_free (dpriv);
return GNUNET_SYSERR;
}
if (GNUNET_SYSERR !=
GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TEST,
- &purp, &sig,
+ &purp,
+ &sig,
&pkey))
{
- printf ("GNUNET_CRYPTO_ecdsa_verify failed to fail!\n");
+ fprintf (stderr,
+ "GNUNET_CRYPTO_ecdsa_verify failed to fail!\n");
GNUNET_free (dpriv);
return GNUNET_SYSERR;
}
if (GNUNET_SYSERR !=
GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
- &purp, &sig, &dpub))
+ &purp,
+ &sig,
+ &dpub))
{
- printf ("GNUNET_CRYPTO_ecdsa_verify failed to fail!\n");
+ fprintf (stderr,
+ "GNUNET_CRYPTO_ecdsa_verify failed to fail!\n");
GNUNET_free (dpriv);
return GNUNET_SYSERR;
}
#if PERF
static int
-testSignPerformance ()
+testSignPerformance (void)
{
struct GNUNET_CRYPTO_EccSignaturePurpose purp;
struct GNUNET_CRYPTO_EcdsaSignature sig;
static void
-perf_keygen ()
+perf_keygen (void)
{
struct GNUNET_TIME_Absolute start;
- struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
- int i;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey pk;
fprintf (stderr, "%s", "W");
start = GNUNET_TIME_absolute_get ();
- for (i = 0; i < 10; i++)
+ for (unsigned int i = 0; i < 10; i++)
{
- fprintf (stderr, "."); fflush (stderr);
- pk = GNUNET_CRYPTO_ecdsa_key_create ();
- GNUNET_free (pk);
- }
- for (; i < 25; i++)
fprintf (stderr, ".");
+ fflush (stderr);
+ GNUNET_CRYPTO_ecdsa_key_create (&pk);
+ }
fflush (stderr);
printf ("10 ECDSA keys created in %s\n",
GNUNET_STRINGS_relative_time_to_string (
- GNUNET_TIME_absolute_get_duration (start), GNUNET_YES));
+ GNUNET_TIME_absolute_get_duration (start),
+ GNUNET_YES));
}
if (! gcry_check_version ("1.6.0"))
{
fprintf (stderr,
- _
- (
- "libgcrypt has not the expected version (version %s is required).\n"),
+ "libgcrypt has not the expected version (version %s is required).\n",
"1.6.0");
return 0;
}
if (getenv ("GNUNET_GCRYPT_DEBUG"))
gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0);
GNUNET_log_setup ("test-crypto-ecc", "WARNING", NULL);
- key = GNUNET_CRYPTO_ecdsa_key_create ();
+ GNUNET_CRYPTO_ecdsa_key_create (&key);
if (GNUNET_OK != testDeriveSignVerify ())
{
failure_count++;
#endif
if (GNUNET_OK != testSignVerify ())
failure_count++;
- GNUNET_free (key);
perf_keygen ();
if (0 != failure_count)
#define PERF GNUNET_YES
-static struct GNUNET_CRYPTO_EddsaPrivateKey *key;
+static struct GNUNET_CRYPTO_EddsaPrivateKey key;
static int
-testSignVerify ()
+testSignVerify (void)
{
struct GNUNET_CRYPTO_EddsaSignature sig;
struct GNUNET_CRYPTO_EccSignaturePurpose purp;
int ok = GNUNET_OK;
fprintf (stderr, "%s", "W");
- GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey);
+ GNUNET_CRYPTO_eddsa_key_get_public (&key,
+ &pkey);
start = GNUNET_TIME_absolute_get ();
purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose));
purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
for (unsigned int i = 0; i < ITER; i++)
{
fprintf (stderr, "%s", "."); fflush (stderr);
- if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign_ (key, &purp, &sig))
+ if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign_ (&key,
+ &purp,
+ &sig))
{
- fprintf (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n");
+ fprintf (stderr,
+ "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n");
ok = GNUNET_SYSERR;
continue;
}
if (GNUNET_SYSERR ==
- GNUNET_CRYPTO_eddsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TEST, &purp, &sig,
+ GNUNET_CRYPTO_eddsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TEST,
+ &purp,
+ &sig,
&pkey))
{
- printf ("GNUNET_CRYPTO_eddsa_verify failed!\n");
+ fprintf (stderr,
+ "GNUNET_CRYPTO_eddsa_verify failed!\n");
ok = GNUNET_SYSERR;
continue;
}
if (GNUNET_SYSERR !=
GNUNET_CRYPTO_eddsa_verify_ (
GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
- &purp, &sig, &pkey))
+ &purp,
+ &sig,
+ &pkey))
{
- printf ("GNUNET_CRYPTO_eddsa_verify failed to fail!\n");
+ fprintf (stderr,
+ "GNUNET_CRYPTO_eddsa_verify failed to fail!\n");
ok = GNUNET_SYSERR;
continue;
}
}
fprintf (stderr, "\n");
- printf ("%d EdDSA sign/verify operations %s\n", ITER,
+ printf ("%d EdDSA sign/verify operations %s\n",
+ ITER,
GNUNET_STRINGS_relative_time_to_string (
- GNUNET_TIME_absolute_get_duration (start), GNUNET_YES));
+ GNUNET_TIME_absolute_get_duration (start),
+ GNUNET_YES));
return ok;
}
purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose));
purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
fprintf (stderr, "%s", "W");
- GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey);
+ GNUNET_CRYPTO_eddsa_key_get_public (&key,
+ &pkey);
start = GNUNET_TIME_absolute_get ();
for (unsigned int i = 0; i < ITER; i++)
{
- fprintf (stderr, "%s", "."); fflush (stderr);
- if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign_ (key, &purp, &sig))
+ fprintf (stderr, "%s", ".");
+ fflush (stderr);
+ if (GNUNET_SYSERR ==
+ GNUNET_CRYPTO_eddsa_sign_ (&key,
+ &purp,
+ &sig))
{
fprintf (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n");
ok = GNUNET_SYSERR;
}
}
fprintf (stderr, "\n");
- printf ("%d EdDSA sign operations %s\n", ITER,
+ printf ("%d EdDSA sign operations %s\n",
+ ITER,
GNUNET_STRINGS_relative_time_to_string (
GNUNET_TIME_absolute_get_duration (start),
GNUNET_YES));
static int
-testCreateFromFile ()
+testCreateFromFile (void)
{
struct GNUNET_CRYPTO_EddsaPublicKey p1;
struct GNUNET_CRYPTO_EddsaPublicKey p2;
- key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE);
- GNUNET_assert (NULL != key);
- GNUNET_CRYPTO_eddsa_key_get_public (key, &p1);
- GNUNET_free (key);
- key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE);
- GNUNET_assert (NULL != key);
- GNUNET_CRYPTO_eddsa_key_get_public (key, &p2);
- GNUNET_assert (0 == memcmp (&p1, &p2, sizeof(p1)));
- GNUNET_free (key);
+ GNUNET_assert (0 <=
+ GNUNET_CRYPTO_eddsa_key_from_file (KEYFILE,
+ GNUNET_YES,
+ &key));
+ GNUNET_CRYPTO_eddsa_key_get_public (&key,
+ &p1);
+ GNUNET_assert (GNUNET_NO ==
+ GNUNET_CRYPTO_eddsa_key_from_file (KEYFILE,
+ GNUNET_YES,
+ &key));
+ GNUNET_CRYPTO_eddsa_key_get_public (&key,
+ &p2);
+ GNUNET_assert (0 ==
+ GNUNET_memcmp (&p1,
+ &p2));
GNUNET_assert (0 == unlink (KEYFILE));
- key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE);
- GNUNET_assert (NULL != key);
- GNUNET_CRYPTO_eddsa_key_get_public (key, &p2);
- GNUNET_assert (0 != memcmp (&p1, &p2, sizeof(p1)));
- GNUNET_free (key);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_eddsa_key_from_file (KEYFILE,
+ GNUNET_NO,
+ &key));
+ GNUNET_CRYPTO_eddsa_key_get_public (&key,
+ &p2);
+ GNUNET_assert (0 !=
+ GNUNET_memcmp (&p1,
+ &p2));
return GNUNET_OK;
}
static void
-perf_keygen ()
+perf_keygen (void)
{
struct GNUNET_TIME_Absolute start;
- struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
+ struct GNUNET_CRYPTO_EddsaPrivateKey pk;
fprintf (stderr, "%s", "W");
start = GNUNET_TIME_absolute_get ();
for (unsigned int i = 0; i < 10; i++)
{
- fprintf (stderr, "."); fflush (stderr);
- pk = GNUNET_CRYPTO_eddsa_key_create ();
- GNUNET_free (pk);
+ fprintf (stderr, ".");
+ fflush (stderr);
+ GNUNET_CRYPTO_eddsa_key_create (&pk);
}
fprintf (stderr, "\n");
printf ("10 EdDSA keys created in %s\n",
if (! gcry_check_version ("1.6.0"))
{
fprintf (stderr,
- _ (
- "libgcrypt has not the expected version (version %s is required).\n"),
+ "libgcrypt has not the expected version (version %s is required).\n",
"1.6.0");
return 0;
}
if (getenv ("GNUNET_GCRYPT_DEBUG"))
gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0);
- GNUNET_log_setup ("test-crypto-eddsa", "WARNING", NULL);
- key = GNUNET_CRYPTO_eddsa_key_create ();
+ GNUNET_log_setup ("test-crypto-eddsa",
+ "WARNING",
+ NULL);
+ GNUNET_CRYPTO_eddsa_key_create (&key);
#if PERF
if (GNUNET_OK != testSignPerformance ())
failure_count++;
#endif
if (GNUNET_OK != testSignVerify ())
failure_count++;
- GNUNET_free (key);
if (GNUNET_OK != testCreateFromFile ())
failure_count++;
GNUNET_assert (0 == unlink (KEYFILE));