check_PROGRAMS = \
test_gnunet_prefix
+if ENABLE_TEST_RUN
TESTS = $(check_PROGRAMS)
+endif
test_gnunet_prefix_SOURCES = \
test_gnunet_prefix.c
dns \
identity \
set \
- fs \
$(LINUX_DIR) \
$(MINGW_DIR) \
gns \
* Ephemeral public ECC key (always for NIST P-521) encoded in a format suitable
* for network transmission as created using 'gcry_sexp_sprint'.
*/
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded ephemeral_key;
+ struct GNUNET_CRYPTO_EccPublicKey ephemeral_key;
/**
* Public key of the signing peer (persistent version, not the ephemeral public key).
*/
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded origin_public_key;
+ struct GNUNET_CRYPTO_EccPublicKey origin_public_key;
};
/**
* Our public key.
*/
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key;
+static struct GNUNET_CRYPTO_EccPublicKey my_public_key;
/**
* Our message stream tokenizer (for encrypted payload).
"Core service receives `%s' request from `%4s'.\n", "EPHEMERAL_KEY",
GNUNET_i2s (&kx->peer));
GNUNET_CRYPTO_hash (&m->origin_public_key,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&signer_id.hashPubKey);
if (0 !=
memcmp (&signer_id, &kx->peer,
sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
sizeof (struct GNUNET_TIME_AbsoluteNBO) +
sizeof (struct GNUNET_TIME_AbsoluteNBO) +
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded) +
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)) ||
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey) +
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey)) ||
(GNUNET_OK !=
GNUNET_CRYPTO_ecc_verify (GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY,
&m->purpose,
current_ekm.purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
sizeof (struct GNUNET_TIME_AbsoluteNBO) +
sizeof (struct GNUNET_TIME_AbsoluteNBO) +
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded) +
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded));
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey) +
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey));
current_ekm.creation_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (GSC_cfg,
#include <fenv.h>
#include "dht.h"
-#include "../regex/regex_block_lib.h"
-
-
#define LOG_TRAFFIC(kind,...) GNUNET_log_from (kind, "dht-traffic",__VA_ARGS__)
/**
*/
struct Issuer
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+ struct GNUNET_CRYPTO_EccPublicKey pubkey;
};
char *pubkey;
char *pos;
struct GNUNET_PeerIdentity issuer_ID;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub;
+ struct GNUNET_CRYPTO_EccPublicKey pub;
struct GNUNET_HashCode hash;
/* Load valid issuer */
/**
* Identity of the peer sharing the file.
*/
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded peer;
+ struct GNUNET_CRYPTO_EccPublicKey peer;
/**
* Time when this location URI expires.
static struct GNUNET_FS_pseudonym_DiscoveryHandle *disco_tail;
/**
- * Pointer to indiate 'anonymous' pseudonym (global static, all
- * zeros). We actually use pointer comparisson to detect the
- * "anonymous" pseudonym handle.
+ * Pointer to indiate 'anonymous' pseudonym (global static,
+ * d=1, public key = G (generator).
*/
static struct GNUNET_FS_PseudonymHandle anonymous;
struct GNUNET_FS_PseudonymHandle *
GNUNET_FS_pseudonym_get_anonymous_pseudonym_handle ()
{
+ static int once;
+ gcry_mpi_t d;
+ size_t size;
+ gcry_ctx_t ctx;
+ int rc;
+ gcry_mpi_t g_x;
+ gcry_mpi_t g_y;
+ gcry_mpi_point_t g;
+
+ if (once)
+ return &anonymous;
+ d = gcry_mpi_new (1);
+ gcry_mpi_set_ui (d, 1);
+ size = sizeof (anonymous.d);
+ GNUNET_assert (0 ==
+ gcry_mpi_print (GCRYMPI_FMT_USG, anonymous.d, size, &size,
+ d));
+ gcry_mpi_release (d);
+ adjust (anonymous.d, size, sizeof (anonymous.d));
+
+ /* create basic ECC context */
+ if (0 != (rc = gcry_mpi_ec_new (&ctx, NULL, "NIST P-256")))
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
+ "gcry_mpi_ec_new", rc);
+ return NULL;
+ }
+
+ g = gcry_mpi_ec_get_point ("g", ctx, 0);
+ g_x = gcry_mpi_new (256);
+ g_y = gcry_mpi_new (256);
+ gcry_mpi_ec_get_affine (g_x, g_y, g, ctx);
+ gcry_mpi_point_release (g);
+ gcry_ctx_release (ctx);
+
+ /* store g_x/g_y in public key */
+ size = sizeof (anonymous.public_key.q_x);
+ if (0 !=
+ gcry_mpi_print (GCRYMPI_FMT_USG, anonymous.public_key.q_x, size, &size,
+ g_x))
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_print", rc);
+ gcry_mpi_release (g_x);
+ gcry_mpi_release (g_y);
+ return NULL;
+ }
+ adjust (anonymous.public_key.q_x, size, sizeof (anonymous.public_key.q_x));
+ gcry_mpi_release (g_x);
+
+ size = sizeof (anonymous.public_key.q_y);
+ if (0 !=
+ gcry_mpi_print (GCRYMPI_FMT_USG, anonymous.public_key.q_y, size, &size,
+ g_y))
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_print", rc);
+ gcry_mpi_release (g_y);
+ return NULL;
+ }
+ adjust (anonymous.public_key.q_y, size, sizeof (anonymous.public_key.q_y));
+ gcry_mpi_release (g_y);
+
+ once = 1;
return &anonymous;
}
int rc;
/* get private key 'd' from pseudonym */
- if (&anonymous == ph)
- {
- d = gcry_mpi_new (0);
- gcry_mpi_set_ui (d, 0);
- }
- else
+ size = sizeof (ph->d);
+ if (0 != (rc = gcry_mpi_scan (&d, GCRYMPI_FMT_USG,
+ &ph->d,
+ size, &size)))
{
- size = sizeof (ph->d);
- if (0 != (rc = gcry_mpi_scan (&d, GCRYMPI_FMT_USG,
- &ph->d,
- size, &size)))
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
- return GNUNET_SYSERR;
- }
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+ return GNUNET_SYSERR;
}
/* get 'x' value from signing key */
size = sizeof (struct GNUNET_HashCode);
return GNUNET_SYSERR;
}
- /* calculate dx = d + h mod n */
+ /* calculate dh = d * h mod n */
dh = gcry_mpi_new (256);
- gcry_mpi_addm (dh, d, h, n);
+ gcry_mpi_mulm (dh, d, h, n);
gcry_mpi_release (d);
gcry_mpi_release (h);
gcry_mpi_release (n);
LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_ec_new", rc); /* erroff gives more info */
return NULL;
}
- /* initialize 'ctx' with 'q' = 0 */
+ /* FIXME: initialize 'ctx' with 'q' = G */
zero = gcry_mpi_new (0);
gcry_mpi_set_ui (zero, 0);
q = gcry_mpi_point_new (0);
* @param pseudonym the public key (dQ in ECDSA)
* @param signing_key input to derive 'h' (see section 2.4 of #2564)
* @param verification_key resulting public key to verify the signature
- * created from the '(d+h)' of 'pseudonym' and the 'signing_key';
+ * created from the '(d*h)' of 'pseudonym' and the 'signing_key';
* the value stored here can then be given to GNUNET_FS_pseudonym_verify.
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
size_t size;
int rc;
gcry_ctx_t ctx;
- gcry_mpi_point_t g;
gcry_mpi_point_t q;
- gcry_mpi_point_t hg;
gcry_mpi_point_t v;
gcry_mpi_t v_x;
gcry_mpi_t v_y;
+ gcry_mpi_t h_mod_n;
+ gcry_mpi_t n; /* n from P-256 */
/* get 'h' value from signing key */
size = sizeof (struct GNUNET_HashCode);
gcry_mpi_release (h);
return GNUNET_SYSERR;
}
- /* get G */
- g = gcry_mpi_ec_get_point ("g", ctx, 0);
-
- /* then call the 'multiply' function, to compute the product hG */
- hg = gcry_mpi_point_new (0);
- gcry_mpi_ec_mul (hg, h, g, ctx);
- gcry_mpi_point_release (g);
+ /* initialize 'n' from P-256; hex copied from libgcrypt code */
+ if (0 != (rc = gcry_mpi_scan (&n, GCRYMPI_FMT_HEX,
+ "0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551", 0, NULL)))
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+ gcry_mpi_release (h);
+ return GNUNET_SYSERR;
+ }
+ h_mod_n = gcry_mpi_new (0);
+ gcry_mpi_mod (h_mod_n, h, n);
gcry_mpi_release (h);
/* get Q = dG from 'pseudonym' */
q = gcry_mpi_ec_get_point ("q", ctx, 0);
- /* calculate V = Q + hG = dG + hG = (d + h)G*/
+ /* calculate V = hQ = hdG */
v = gcry_mpi_point_new (0);
- gcry_mpi_ec_add (v, q, hg, ctx);
- gcry_mpi_point_release (hg);
+ gcry_mpi_ec_mul (v, h_mod_n, q, ctx);
+ gcry_mpi_release (h_mod_n);
+
/* store 'v' point in "verification_key" */
v_x = gcry_mpi_new (256);
v_y = gcry_mpi_new (256);
GNUNET_FS_pseudonym_get_identifier (struct GNUNET_FS_PseudonymHandle *ph,
struct GNUNET_FS_PseudonymIdentifier *pseudonym)
{
- if (&anonymous == ph)
- memset (pseudonym, 0, sizeof (struct GNUNET_FS_PseudonymIdentifier));
- else
- memcpy (pseudonym, &ph->public_key,
- sizeof (struct GNUNET_FS_PseudonymIdentifier));
+ memcpy (pseudonym, &ph->public_key,
+ sizeof (struct GNUNET_FS_PseudonymIdentifier));
}
struct UBlock *ub_dst;
pkc->ksk_task = GNUNET_SCHEDULER_NO_TASK;
- if ((pkc->i == pkc->ksk_uri->data.ksk.keywordCount) || (NULL == pkc->dsh))
+ if ( (pkc->i == pkc->ksk_uri->data.ksk.keywordCount) ||
+ (NULL == pkc->dsh) )
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "KSK PUT operation complete\n");
pkc->cont (pkc->cont_cls, pkc->ksk_uri, NULL);
GNUNET_FS_publish_ksk_cancel (pkc);
return;
}
+ keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
+ pkc->sks_task = GNUNET_FS_publish_sks (pkc->h,
+ anonymous,
+ keyword, NULL,
+ pkc->meta,
+ pkc->uri,
+ &pkc->bo,
+ pkc->options,
+ &publish_ksk_cont, pkc);
+
+
/* derive signing seed from plaintext */
GNUNET_CRYPTO_hash (&pkc->ub[1],
1 + pkc->slen + pkc->mdsize,
&seed);
- keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing under keyword `%s'\n",
&keyword[1]);
/* first character of keyword indicates if it is
* mandatory or not -- ignore for hashing */
GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key);
+
GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
ub_dst = pkc->cpy;
GNUNET_CRYPTO_aes_encrypt (&pkc->ub[1],
&ub_dst[1]);
ph = GNUNET_FS_pseudonym_get_anonymous_pseudonym_handle ();
GNUNET_CRYPTO_hash (&key, sizeof (key), &signing_key);
- ub_dst->purpose.size = htonl (1 + pkc->slen + pkc->mdsize + sizeof (struct UBlock)
- - sizeof (struct GNUNET_FS_PseudonymSignature));
+ ub_dst->purpose.size = htonl (1 + pkc->slen + pkc->mdsize +
+ sizeof (struct UBlock)
+ - sizeof (struct GNUNET_FS_PseudonymSignature));
ub_dst->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK);
GNUNET_FS_pseudonym_get_identifier (ph, &pseudonym);
case GNUNET_FS_URI_LOC:
GNUNET_CRYPTO_hash (&uri->data.loc.fi,
sizeof (struct FileIdentifier) +
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
key);
break;
default:
struct FileIdentifier fi;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded peer;
+ struct GNUNET_CRYPTO_EccPublicKey peer;
};
npos++;
ret =
enc2bin (&s[npos], &ass.peer,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded));
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey));
if (ret == -1)
{
*emsg =
if (uri->type != GNUNET_FS_URI_LOC)
return GNUNET_SYSERR;
GNUNET_CRYPTO_hash (&uri->data.loc.peer,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&peer->hashPubKey);
return GNUNET_OK;
}
{
struct GNUNET_FS_Uri *uri;
struct GNUNET_CRYPTO_EccPrivateKey *my_private_key;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key;
+ struct GNUNET_CRYPTO_EccPublicKey my_public_key;
char *keyfile;
struct LocUriAssembly ass;
if (memcmp
(&u1->data.loc, &u2->data.loc,
sizeof (struct FileIdentifier) +
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded) +
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey) +
sizeof (struct GNUNET_TIME_Absolute) + sizeof (unsigned short) +
sizeof (unsigned short)) != 0)
return GNUNET_NO;
GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash);
peerId =
bin2enc (&uri->data.loc.peer,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded));
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey));
peerSig =
bin2enc (&uri->data.loc.contentSignature,
sizeof (struct GNUNET_CRYPTO_EccSignature));
[consensus]
AUTOSTART = NO
+
+[mesh]
+REFRESH_PATH_TIME = 30 min
+
uint32_t only_cached GNUNET_PACKED;
/**
- * Should we look up in the default zone?
+ * Should we look up in the given zone, instead of the default zone?
*/
- uint32_t use_default_zone GNUNET_PACKED;
+ uint32_t have_zone GNUNET_PACKED;
/**
* Is a shorten key attached?
* the type of record to look up
*/
/* enum GNUNET_GNS_RecordType */ uint32_t type;
-
- /* Followed by the key for shorten (optional) see have_key */
+
+ /**
+ * The key for shorten, if 'have_key' is set
+ */
+ struct GNUNET_CRYPTO_EccPrivateKey shorten_key;
/* Followed by the name to look up */
};
struct GNUNET_GNS_LookupRequest *lr;
size_t msize;
struct PendingMessage *pending;
- struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *pkey_enc;
- size_t key_len;
- char* pkey_tmp;
if (NULL == name)
{
GNUNET_break (0);
return NULL;
}
- if (NULL != shorten_key)
- {
- pkey_enc = GNUNET_CRYPTO_ecc_encode_key (shorten_key);
- GNUNET_assert (pkey_enc != NULL);
- key_len = ntohs (pkey_enc->size);
- }
- else
- {
- pkey_enc = NULL;
- key_len = 0;
- }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Trying to lookup `%s' in GNS\n",
name);
msize = sizeof (struct GNUNET_GNS_ClientLookupMessage)
- + key_len + strlen (name) + 1;
+ + strlen (name) + 1;
if (msize > UINT16_MAX)
{
GNUNET_break (0);
- GNUNET_free (pkey_enc);
return NULL;
}
lr = GNUNET_malloc (sizeof (struct GNUNET_GNS_LookupRequest) +
lookup_msg->only_cached = htonl (only_cached);
if (NULL != zone)
{
- lookup_msg->use_default_zone = htonl (GNUNET_NO);
- memcpy (&lookup_msg->zone, zone, sizeof (struct GNUNET_CRYPTO_ShortHashCode));
+ lookup_msg->have_zone = htonl (GNUNET_YES);
+ lookup_msg->zone = *zone;
}
- else
- {
- lookup_msg->use_default_zone = htonl (GNUNET_YES);
- memset (&lookup_msg->zone, 0, sizeof(struct GNUNET_CRYPTO_ShortHashCode));
- }
lookup_msg->type = htonl (type);
- pkey_tmp = (char *) &lookup_msg[1];
- if (pkey_enc != NULL)
+ if (NULL != shorten_key)
{
lookup_msg->have_key = htonl (GNUNET_YES);
- memcpy (pkey_tmp, pkey_enc, key_len);
+ lookup_msg->shorten_key = *shorten_key;
}
- else
- lookup_msg->have_key = htonl (GNUNET_NO);
- GNUNET_free_non_null (pkey_enc);
- memcpy (&pkey_tmp[key_len], name, strlen (name) + 1);
-
+ memcpy (&lookup_msg[1], name, strlen (name) + 1);
GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head,
handle->pending_tail,
pending);
static void
iterate_cb (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_len,
*/
static void
zone_to_name_cb (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_count,
*/
static void
lookup_result_processor (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_count,
{
char *keyfile;
unsigned long long port;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub;
+ struct GNUNET_CRYPTO_EccPublicKey pub;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg,
char* keyfile;
struct GNUNET_CRYPTO_EccPrivateKey *key = NULL;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
+ struct GNUNET_CRYPTO_EccPublicKey pkey;
struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
GNUNET_CRYPTO_ecc_key_get_public (key, &pkey);
GNUNET_CRYPTO_short_hash(&pkey,
- sizeof(struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof(struct GNUNET_CRYPTO_EccPublicKey),
&user_zone);
zone = &user_zone;
GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
{
char *keyfile;
struct GNUNET_CRYPTO_EccPrivateKey *key;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
+ struct GNUNET_CRYPTO_EccPublicKey pkey;
struct GNUNET_CRYPTO_ShortHashCode *zone;
struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
GNUNET_CRYPTO_ecc_key_get_public (key, &pkey);
local_gns_zone = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_ShortHashCode));
- GNUNET_CRYPTO_short_hash(&pkey,
- sizeof(struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
- local_gns_zone);
+ GNUNET_CRYPTO_short_hash (&pkey,
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
+ local_gns_zone);
zone = local_gns_zone;
GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
GNUNET_CRYPTO_ecc_key_get_public (key, &pkey);
local_private_zone = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_ShortHashCode));
- GNUNET_CRYPTO_short_hash(&pkey,
- sizeof(struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
- local_private_zone);
+ GNUNET_CRYPTO_short_hash (&pkey,
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
+ local_private_zone);
GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Using private zone: %s!\n", &zonename);
key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
GNUNET_CRYPTO_ecc_key_get_public (key, &pkey);
local_shorten_zone = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_ShortHashCode));
- GNUNET_CRYPTO_short_hash(&pkey,
- sizeof(struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
- local_shorten_zone);
+ GNUNET_CRYPTO_short_hash (&pkey,
+ sizeof(struct GNUNET_CRYPTO_EccPublicKey),
+ local_shorten_zone);
GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Using shorten zone: %s!\n", &zonename);
{
char* keyfile;
struct GNUNET_CRYPTO_EccPrivateKey *key = NULL;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
+ struct GNUNET_CRYPTO_EccPublicKey pkey;
struct GNUNET_CRYPTO_ShortHashCode *zone = NULL;
struct GNUNET_CRYPTO_ShortHashCode user_zone;
struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
GNUNET_CRYPTO_ecc_key_get_public (key, &pkey);
GNUNET_CRYPTO_short_hash (&pkey,
- sizeof(struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof(struct GNUNET_CRYPTO_EccPublicKey),
&user_zone);
zone = &user_zone;
GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
GNUNET_CRYPTO_ecc_key_get_public (shorten_key, &pkey);
shorten_zone = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_ShortHashCode));
GNUNET_CRYPTO_short_hash(&pkey,
- sizeof(struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof(struct GNUNET_CRYPTO_EccPublicKey),
shorten_zone);
GNUNET_CRYPTO_short_hash_to_enc (shorten_zone, &zonename);
if (! raw)
{
private_key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
GNUNET_CRYPTO_ecc_key_get_public (private_key, &pkey);
- private_zone = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_ShortHashCode));
- GNUNET_CRYPTO_short_hash(&pkey,
- sizeof(struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
- private_zone);
+ private_zone = GNUNET_new (struct GNUNET_CRYPTO_ShortHashCode);
+ GNUNET_CRYPTO_short_hash (&pkey,
+ sizeof(struct GNUNET_CRYPTO_EccPublicKey),
+ private_zone);
GNUNET_CRYPTO_short_hash_to_enc (private_zone, &zonename);
if (! raw)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
*/
static void
put_gns_record (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
+ const struct GNUNET_CRYPTO_EccPublicKey *key,
struct GNUNET_TIME_Absolute expiration,
const char *name,
unsigned int rd_count,
nrb_data += namelen;
rd_payload_length += sizeof(struct GNSNameRecordBlock) + namelen;
GNUNET_CRYPTO_short_hash (key,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&zhash);
if (-1 == GNUNET_NAMESTORE_records_serialize (rd_count,
rd,
*/
static void
process_shorten_in_private_zone_lookup (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
+ const struct GNUNET_CRYPTO_EccPublicKey *key,
struct GNUNET_TIME_Absolute expiration,
const char *name,
unsigned int rd_count,
*/
static void
process_shorten_in_root_zone_lookup (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
+ const struct GNUNET_CRYPTO_EccPublicKey *key,
struct GNUNET_TIME_Absolute expiration,
const char *name,
unsigned int rd_count,
*/
static void
process_private_in_root_zone_lookup (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
+ const struct GNUNET_CRYPTO_EccPublicKey *key,
struct GNUNET_TIME_Absolute expiration,
const char *name,
unsigned int rd_count,
char* nameptr = name;
const char *utf_in;
int only_cached;
- struct GNUNET_CRYPTO_EccPrivateKey *key;
- struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *pkey;
- char* tmp_pkey;
+ const struct GNUNET_CRYPTO_EccPrivateKey *key;
uint16_t msg_size;
const struct GNUNET_GNS_ClientLookupMessage *sh_msg;
GNUNET_SERVER_notification_context_add (nc, client);
if (GNUNET_YES == ntohl (sh_msg->have_key))
{
- pkey = (struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *) &sh_msg[1];
- tmp_pkey = (char*) &sh_msg[1];
- key = GNUNET_CRYPTO_ecc_decode_key (tmp_pkey, ntohs (pkey->size),
- GNUNET_NO);
- GNUNET_STRINGS_utf8_tolower (&tmp_pkey[ntohs (pkey->size)], &nameptr);
+ key = &sh_msg->shorten_key;
}
else
{
key = NULL;
- utf_in = (const char *) &sh_msg[1];
- if ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientLookupMessage) - 1])
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- GNUNET_STRINGS_utf8_tolower (utf_in, &nameptr);
}
+ utf_in = (const char *) &sh_msg[1];
+ if ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientLookupMessage) - 1])
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ GNUNET_STRINGS_utf8_tolower (utf_in, &nameptr);
namelen = strlen (name) + 1;
clh = GNUNET_malloc (sizeof (struct ClientLookupHandle));
strcpy (clh->name, name);
clh->request_id = sh_msg->id;
clh->type = ntohl (sh_msg->type);
- clh->shorten_key = key;
-
+ if (NULL != key)
+ {
+ clh->shorten_key = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
+ *clh->shorten_key = *key;
+ }
only_cached = ntohl (sh_msg->only_cached);
if (strlen (name) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) {
return;
}
- if (1 == ntohl (sh_msg->use_default_zone))
+ if (GNUNET_NO == ntohl (sh_msg->have_zone))
clh->zone = zone_hash; /* Default zone */
else
clh->zone = sh_msg->zone;
{&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0}
};
char* keyfile;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
+ struct GNUNET_CRYPTO_EccPublicKey pkey;
unsigned long long max_parallel_bg_queries = 0;
int ignore_pending = GNUNET_NO;
zone_key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
GNUNET_CRYPTO_ecc_key_get_public (zone_key, &pkey);
- GNUNET_CRYPTO_short_hash(&pkey,
- sizeof(struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
- &zone_hash);
+ GNUNET_CRYPTO_short_hash (&pkey,
+ sizeof(struct GNUNET_CRYPTO_EccPublicKey),
+ &zone_hash);
GNUNET_free(keyfile);
namestore_handle = GNUNET_NAMESTORE_connect (c);
if (NULL == namestore_handle)
*/
static void
process_pseu_lookup_ns (void* cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
+ const struct GNUNET_CRYPTO_EccPublicKey *key,
struct GNUNET_TIME_Absolute expiration,
const char *name, unsigned int rd_count,
const struct GNUNET_NAMESTORE_RecordData *rd,
*/
static void
process_auth_discovery_ns_result (void* cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
- struct GNUNET_TIME_Absolute expiration,
- const char *name,
- unsigned int rd_count,
- const struct GNUNET_NAMESTORE_RecordData *rd,
- const struct GNUNET_CRYPTO_EccSignature *signature)
+ const struct GNUNET_CRYPTO_EccPublicKey *key,
+ struct GNUNET_TIME_Absolute expiration,
+ const char *name,
+ unsigned int rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ const struct GNUNET_CRYPTO_EccSignature *signature)
{
struct GetPseuAuthorityHandle* gph = cls;
struct GNUNET_HashCode lookup_key;
*/
static void
process_zone_to_name_discover (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_len,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"GNS_AUTO_PSEU: New authority %s discovered\n",
gph->auth->name);
-
gph->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
- &gph->our_zone,
- &gph->auth->zone,
- &process_zone_to_name_discover,
- gph);
+ &gph->our_zone,
+ &gph->auth->zone,
+ &process_zone_to_name_discover,
+ gph);
}
const struct GNUNET_CRYPTO_EccPrivateKey *key)
{
struct GetPseuAuthorityHandle *gph;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
- struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *pb_key;
+ struct GNUNET_CRYPTO_EccPublicKey pkey;
GNUNET_CRYPTO_ecc_key_get_public (key, &pkey);
- if (NULL == (pb_key = GNUNET_CRYPTO_ecc_encode_key (key)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to encode ECC key on shorten\n");
- return;
- }
gph = GNUNET_new (struct GetPseuAuthorityHandle);
- gph->key = GNUNET_CRYPTO_ecc_decode_key ((const char*) pb_key,
- ntohs (pb_key->size),
- GNUNET_YES);
- GNUNET_free (pb_key);
+ gph->key = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
+ *gph->key = *key;
if (NULL == gph->key)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
return;
}
GNUNET_CRYPTO_short_hash (&pkey,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&gph->our_zone);
gph->auth = GNUNET_malloc (sizeof (struct AuthorityChain));
memcpy (gph->auth, auth, sizeof (struct AuthorityChain));
*/
static void
process_record_result_ns (void* cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
+ const struct GNUNET_CRYPTO_EccPublicKey *key,
struct GNUNET_TIME_Absolute expiration,
const char *name, unsigned int rd_count,
const struct GNUNET_NAMESTORE_RecordData *rd,
rh->namestore_task = NULL;
GNUNET_CRYPTO_short_hash (key,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&zone);
remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
rh->status = 0;
*/
static void
process_pkey_revocation_result_ns (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
+ const struct GNUNET_CRYPTO_EccPublicKey *key,
struct GNUNET_TIME_Absolute expiration,
const char *name,
unsigned int rd_count,
*/
static void
process_delegation_result_ns (void* cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
+ const struct GNUNET_CRYPTO_EccPublicKey *key,
struct GNUNET_TIME_Absolute expiration,
const char *name,
unsigned int rd_count,
rh->namestore_task = NULL;
GNUNET_CRYPTO_short_hash (key,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&zone);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"GNS_PHASE_DELEGATE_NS-%llu: Got %d records from authority lookup for `%s' in zone %s\n",
*/
static void
process_zone_to_name_shorten_root (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_len,
*/
static void
process_zone_to_name_shorten_shorten (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
- struct GNUNET_TIME_Absolute expire,
- const char *name,
- unsigned int rd_len,
- const struct GNUNET_NAMESTORE_RecordData *rd,
- const struct GNUNET_CRYPTO_EccSignature *signature)
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
+ struct GNUNET_TIME_Absolute expire,
+ const char *name,
+ unsigned int rd_len,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ const struct GNUNET_CRYPTO_EccSignature *signature)
{
struct ResolverHandle *rh = cls;
struct NameShortenHandle* nsh = rh->proc_cls;
*/
static void
process_zone_to_name_shorten_private (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
- struct GNUNET_TIME_Absolute expire,
- const char *name,
- unsigned int rd_len,
- const struct GNUNET_NAMESTORE_RecordData *rd,
- const struct GNUNET_CRYPTO_EccSignature *signature)
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
+ struct GNUNET_TIME_Absolute expire,
+ const char *name,
+ unsigned int rd_len,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ const struct GNUNET_CRYPTO_EccSignature *signature)
{
struct ResolverHandle *rh = cls;
struct NameShortenHandle* nsh = rh->proc_cls;
*/
static void
process_zone_to_name_shorten_root (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
- struct GNUNET_TIME_Absolute expire,
- const char *name,
- unsigned int rd_len,
- const struct GNUNET_NAMESTORE_RecordData *rd,
- const struct GNUNET_CRYPTO_EccSignature *signature)
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
+ struct GNUNET_TIME_Absolute expire,
+ const char *name,
+ unsigned int rd_len,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ const struct GNUNET_CRYPTO_EccSignature *signature)
{
struct ResolverHandle *rh = cls;
struct NameShortenHandle* nsh = rh->proc_cls;
* @param signature the signature for the record data
*/
static void
-process_zone_to_name_zkey(void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
- struct GNUNET_TIME_Absolute expire,
- const char *name,
- unsigned int rd_len,
- const struct GNUNET_NAMESTORE_RecordData *rd,
- const struct GNUNET_CRYPTO_EccSignature *signature)
+process_zone_to_name_zkey (void *cls,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
+ struct GNUNET_TIME_Absolute expire,
+ const char *name,
+ unsigned int rd_len,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ const struct GNUNET_CRYPTO_EccSignature *signature)
{
struct ResolverHandle *rh = cls;
struct NameShortenHandle *nsh = rh->proc_cls;
return GNUNET_SYSERR;
}
GNUNET_CRYPTO_short_hash (&nrb->public_key,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&pkey_hash);
GNUNET_GNS_get_key_for_record (name, &pkey_hash, key);
return GNUNET_OK;
const struct GNUNET_CONFIGURATION_Handle *ccfg,
struct GNUNET_TESTING_Peer *peer)
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded alice_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey alice_pkey;
struct GNUNET_CRYPTO_EccPrivateKey *alice_key;
struct GNUNET_CRYPTO_EccPrivateKey *bob_key;
char* alice_keyfile;
static const struct GNUNET_CONFIGURATION_Handle *cfg;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded alice_pkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded bob_pkey;
+static struct GNUNET_CRYPTO_EccPublicKey alice_pkey;
+static struct GNUNET_CRYPTO_EccPublicKey bob_pkey;
static struct GNUNET_CRYPTO_EccPrivateKey *alice_key;
static struct GNUNET_CRYPTO_EccPrivateKey *bob_key;
}
GNUNET_CRYPTO_short_hash(TEST_RECORD_NAME, strlen(TEST_RECORD_NAME), &name_hash);
GNUNET_CRYPTO_short_hash(&bob_pkey,
- sizeof(struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof(struct GNUNET_CRYPTO_EccPublicKey),
&zone_hash);
GNUNET_CRYPTO_short_hash_double(&zone_hash, &zone_hash_double);
GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
{
char* keyfile;
struct GNUNET_CRYPTO_EccPrivateKey *key;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
+ struct GNUNET_CRYPTO_EccPublicKey pkey;
struct in_addr *web;
struct GNUNET_NAMESTORE_RecordData rd;
{
char* keyfile;
struct GNUNET_CRYPTO_EccPrivateKey *key;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
+ struct GNUNET_CRYPTO_EccPublicKey pkey;
struct GNUNET_NAMESTORE_RecordData rd;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up bob\n");
const struct GNUNET_CONFIGURATION_Handle *ccfg,
struct GNUNET_TESTING_Peer *peer)
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded alice_pkey;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded bob_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey alice_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey bob_pkey;
struct GNUNET_CRYPTO_EccPrivateKey *alice_key;
struct GNUNET_CRYPTO_EccPrivateKey *bob_key;
char* alice_keyfile;
const struct GNUNET_CONFIGURATION_Handle *ccfg,
struct GNUNET_TESTING_Peer *peer)
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded alice_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey alice_pkey;
char* alice_keyfile;
struct GNUNET_NAMESTORE_RecordData rd[2];
struct in_addr ns;
static const struct GNUNET_CONFIGURATION_Handle *cfg;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded alice_pkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded bob_pkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded our_pkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded priv_pkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded short_pkey;
+static struct GNUNET_CRYPTO_EccPublicKey alice_pkey;
+static struct GNUNET_CRYPTO_EccPublicKey bob_pkey;
+static struct GNUNET_CRYPTO_EccPublicKey our_pkey;
+static struct GNUNET_CRYPTO_EccPublicKey priv_pkey;
+static struct GNUNET_CRYPTO_EccPublicKey short_pkey;
static struct GNUNET_CRYPTO_EccPrivateKey *alice_key;
static struct GNUNET_CRYPTO_EccPrivateKey *bob_key;
static struct GNUNET_CRYPTO_EccPrivateKey *our_key;
}
GNUNET_CRYPTO_short_hash(GNUNET_GNS_MASTERZONE_STR, strlen(GNUNET_GNS_MASTERZONE_STR), &name_hash);
GNUNET_CRYPTO_short_hash(&alice_pkey,
- sizeof(struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof(struct GNUNET_CRYPTO_EccPublicKey),
&zone_hash);
GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
}
GNUNET_CRYPTO_short_hash(TEST_RECORD_NAME, strlen(TEST_RECORD_NAME), &name_hash);
GNUNET_CRYPTO_short_hash(&alice_pkey,
- sizeof(struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof(struct GNUNET_CRYPTO_EccPublicKey),
&zone_hash);
GNUNET_CRYPTO_short_hash_double(&zone_hash, &zone_hash_double);
GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
GNUNET_CRYPTO_short_hash (TEST_AUTHORITY_ALICE,
strlen (TEST_AUTHORITY_ALICE), &name_hash);
GNUNET_CRYPTO_short_hash (&bob_pkey,
- sizeof(struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof(struct GNUNET_CRYPTO_EccPublicKey),
&zone_hash);
GNUNET_CRYPTO_short_hash_double(&zone_hash, &zone_hash_double);
GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
const struct GNUNET_CONFIGURATION_Handle *ccfg,
struct GNUNET_TESTING_Peer *peer)
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded alice_pkey;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded bob_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey alice_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey bob_pkey;
struct GNUNET_CRYPTO_EccPrivateKey *alice_key;
struct GNUNET_CRYPTO_EccPrivateKey *bob_key;
struct GNUNET_CRYPTO_ShortHashCode bob_hash;
const struct GNUNET_CONFIGURATION_Handle *ccfg,
struct GNUNET_TESTING_Peer *peer)
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded alice_pkey;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded bob_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey alice_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey bob_pkey;
struct GNUNET_CRYPTO_EccPrivateKey *alice_key;
struct GNUNET_CRYPTO_EccPrivateKey *bob_key;
struct GNUNET_CRYPTO_ShortHashCode bob_hash;
const struct GNUNET_CONFIGURATION_Handle *ccfg,
struct GNUNET_TESTING_Peer *peer)
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded our_pkey;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded alice_pkey;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded bob_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey our_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey alice_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey bob_pkey;
struct GNUNET_CRYPTO_EccPrivateKey *our_key;
struct GNUNET_CRYPTO_EccPrivateKey *alice_key;
struct GNUNET_CRYPTO_EccPrivateKey *bob_key;
const struct GNUNET_CONFIGURATION_Handle *ccfg,
struct GNUNET_TESTING_Peer *peer)
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded alice_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey alice_pkey;
struct GNUNET_CRYPTO_EccPrivateKey *alice_key;
struct GNUNET_NAMESTORE_RecordData rd;
char* alice_keyfile;
const struct GNUNET_CONFIGURATION_Handle *ccfg,
struct GNUNET_TESTING_Peer *peer)
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded alice_pkey;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded bob_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey alice_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey bob_pkey;
struct GNUNET_CRYPTO_EccPrivateKey *alice_key;
struct GNUNET_CRYPTO_EccPrivateKey *bob_key;
struct GNUNET_CRYPTO_ShortHashCode bob_hash;
const struct GNUNET_CONFIGURATION_Handle *cfg;
-struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded priv_pkey;
-struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded short_pkey;
+struct GNUNET_CRYPTO_EccPublicKey priv_pkey;
+struct GNUNET_CRYPTO_EccPublicKey short_pkey;
struct GNUNET_CRYPTO_EccPrivateKey *priv_key;
struct GNUNET_CRYPTO_EccPrivateKey *short_key;
const struct GNUNET_CONFIGURATION_Handle *ccfg,
struct GNUNET_TESTING_Peer *peer)
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded our_pkey;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded alice_pkey;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded bob_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey our_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey alice_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey bob_pkey;
struct GNUNET_CRYPTO_EccPrivateKey *our_key;
struct GNUNET_CRYPTO_EccPrivateKey *alice_key;
struct GNUNET_CRYPTO_EccPrivateKey *bob_key;
const struct GNUNET_CONFIGURATION_Handle *ccfg,
struct GNUNET_TESTING_Peer *peer)
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded alice_pkey;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded bob_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey alice_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey bob_pkey;
struct GNUNET_CRYPTO_EccPrivateKey *alice_key;
struct GNUNET_CRYPTO_EccPrivateKey *bob_key;
struct GNUNET_CRYPTO_ShortHashCode bob_hash;
const struct GNUNET_CONFIGURATION_Handle *ccfg,
struct GNUNET_TESTING_Peer *peer)
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded alice_pkey;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded bob_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey alice_pkey;
+ struct GNUNET_CRYPTO_EccPublicKey bob_pkey;
struct GNUNET_CRYPTO_EccPrivateKey *alice_key;
struct GNUNET_CRYPTO_EccPrivateKey *bob_key;
struct GNUNET_CRYPTO_EccSignature *sig;
struct GNUNET_DISK_FileHandle *fh;
struct GNUNET_HELLO_Message *orig;
struct GNUNET_HELLO_Message *result;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pk;
+ struct GNUNET_CRYPTO_EccPublicKey pk;
uint64_t fsize;
GNUNET_log_setup ("gnunet-hello", "INFO", NULL);
/**
* The public key of the peer.
*/
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded publicKey;
+ struct GNUNET_CRYPTO_EccPublicKey publicKey;
};
GNUNET_NETWORK_STRUCT_END
* @return the hello message
*/
struct GNUNET_HELLO_Message *
-GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
- *publicKey,
+GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EccPublicKey *publicKey,
GNUNET_HELLO_GenerateAddressListCallback addrgen,
void *addrgen_cls,
int friend_only)
hello->friend_only = htonl (friend_only);
memcpy (&hello->publicKey, publicKey,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded));
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey));
memcpy (&hello[1], buffer, used);
return hello;
}
wpos = 0;
woff = (ret != NULL) ? (char *) &ret[1] : NULL;
GNUNET_CRYPTO_hash (&msg->publicKey,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&address.peer.hashPubKey);
while (insize > 0)
{
*/
int
GNUNET_HELLO_get_key (const struct GNUNET_HELLO_Message *hello,
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *publicKey)
+ struct GNUNET_CRYPTO_EccPublicKey *publicKey)
{
uint16_t ret = ntohs (hello->header.size);
(ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
return GNUNET_SYSERR;
GNUNET_CRYPTO_hash (&hello->publicKey,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&peer->hashPubKey);
return GNUNET_OK;
}
if (0 !=
memcmp (&h1->publicKey, &h2->publicKey,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)))
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey)))
return GNUNET_TIME_UNIT_ZERO_ABS;
ec.expiration_limit = now;
ec.result = GNUNET_TIME_UNIT_FOREVER_ABS;
*/
int
GNUNET_HELLO_parse_uri (const char *uri,
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pubkey,
+ struct GNUNET_CRYPTO_EccPublicKey *pubkey,
struct GNUNET_HELLO_Message **hello,
GNUNET_HELLO_TransportPluginsFind plugins_find)
{
struct GNUNET_HELLO_Message *msg1;
struct GNUNET_HELLO_Message *msg2;
struct GNUNET_HELLO_Message *msg3;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded publicKey;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pk;
+ struct GNUNET_CRYPTO_EccPublicKey publicKey;
+ struct GNUNET_CRYPTO_EccPublicKey pk;
struct GNUNET_TIME_Absolute startup_time;
unsigned int i;
struct GNUNET_HELLO_Message *msg1;
struct GNUNET_HELLO_Message *msg2;
struct GNUNET_HELLO_Message *msg3;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded publicKey;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pk;
+ struct GNUNET_CRYPTO_EccPublicKey publicKey;
+ struct GNUNET_CRYPTO_EccPublicKey pk;
struct GNUNET_TIME_Absolute startup_time;
unsigned int i;
create_update_message (struct Ego *ego)
{
struct GNUNET_IDENTITY_UpdateMessage *um;
- char *str;
- uint16_t pk_len;
size_t name_len;
- struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
-
+
name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
- enc = GNUNET_CRYPTO_ecc_encode_key (ego->pk);
- pk_len = ntohs (enc->size);
- um = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + pk_len + name_len);
+ um = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + name_len);
um->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
- um->header.size = htons (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + pk_len + name_len);
+ um->header.size = htons (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + name_len);
um->name_len = htons (name_len);
- um->pk_len = htons (pk_len);
- str = (char *) &um[1];
- memcpy (str, enc, pk_len);
- memcpy (&str[pk_len], ego->identifier, name_len);
- GNUNET_free (enc);
+ um->end_of_list = htons (GNUNET_NO);
+ um->private_key = *ego->pk;
+ memcpy (&um[1], ego->identifier, name_len);
return um;
}
const char *servicename)
{
struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
- char *str;
- uint16_t pk_len;
size_t name_len;
- struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
name_len = (NULL == servicename) ? 0 : (strlen (servicename) + 1);
- enc = GNUNET_CRYPTO_ecc_encode_key (ego->pk);
- pk_len = ntohs (enc->size);
- sdm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + pk_len + name_len);
+ sdm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + name_len);
sdm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
- sdm->header.size = htons (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + pk_len + name_len);
+ sdm->header.size = htons (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + name_len);
sdm->name_len = htons (name_len);
- sdm->pk_len = htons (pk_len);
- str = (char *) &sdm[1];
- memcpy (str, enc, pk_len);
- memcpy (&str[pk_len], servicename, name_len);
- GNUNET_free (enc);
+ sdm->reserved = htons (0);
+ sdm->private_key = *ego->pk;
+ memcpy (&sdm[1], servicename, name_len);
return sdm;
}
GNUNET_SERVER_notification_context_unicast (nc, client, &um->header, GNUNET_NO);
GNUNET_free (um);
}
+ memset (&ume, 0, sizeof (ume));
ume.header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
ume.header.size = htons (sizeof (struct GNUNET_IDENTITY_UpdateMessage));
- ume.pk_len = htons (0);
+ ume.end_of_list = htons (GNUNET_YES);
ume.name_len = htons (0);
GNUNET_SERVER_notification_context_unicast (nc, client, &ume.header, GNUNET_NO);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
key_cmp (const struct GNUNET_CRYPTO_EccPrivateKey *pk1,
const struct GNUNET_CRYPTO_EccPrivateKey *pk2)
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded p1;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded p2;
-
- GNUNET_CRYPTO_ecc_key_get_public (pk1, &p1);
- GNUNET_CRYPTO_ecc_key_get_public (pk2, &p2);
- return memcmp (&p1, &p2, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded));
+ return memcmp (pk1, pk2, sizeof (struct GNUNET_CRYPTO_EccPrivateKey));
}
const struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
uint16_t size;
uint16_t name_len;
- uint16_t pk_len;
struct Ego *ego;
const char *str;
- struct GNUNET_CRYPTO_EccPrivateKey *pk;
size = ntohs (message->size);
if (size <= sizeof (struct GNUNET_IDENTITY_SetDefaultMessage))
}
sdm = (const struct GNUNET_IDENTITY_SetDefaultMessage *) message;
name_len = ntohs (sdm->name_len);
- pk_len = ntohs (sdm->pk_len);
- str = (const char *) &sdm[1];
- if ( (name_len + pk_len + sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) != size) ||
- (NULL == (pk = GNUNET_CRYPTO_ecc_decode_key (str, pk_len, GNUNET_YES))) )
+ GNUNET_break (0 == ntohs (sdm->reserved));
+ if (name_len + sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) != size)
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- str = &str[pk_len];
+ str = (const char *) &sdm[1];
if ('\0' != str[name_len - 1])
{
GNUNET_break (0);
for (ego = ego_head; NULL != ego; ego = ego->next)
{
if (0 == key_cmp (ego->pk,
- pk))
+ &sdm->private_key))
{
GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
str,
subsystem_cfg_file);
send_result_code (client, 0, NULL);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
- GNUNET_CRYPTO_ecc_key_free (pk);
return;
}
}
send_result_code (client, 1, _("Unknown ego specified for service (internal error)"));
GNUNET_SERVER_receive_done (client, GNUNET_OK);
- GNUNET_CRYPTO_ecc_key_free (pk);
}
const struct GNUNET_IDENTITY_CreateRequestMessage *crm;
uint16_t size;
uint16_t name_len;
- uint16_t pk_len;
struct Ego *ego;
- const char *pks;
const char *str;
- struct GNUNET_CRYPTO_EccPrivateKey *pk;
char *fn;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
}
crm = (const struct GNUNET_IDENTITY_CreateRequestMessage *) message;
name_len = ntohs (crm->name_len);
- pk_len = ntohs (crm->pk_len);
- pks = (const char *) &crm[1];
- if ( (name_len + pk_len + sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) != size) ||
- (NULL == (pk = GNUNET_CRYPTO_ecc_decode_key (pks, pk_len, GNUNET_YES))) )
+ GNUNET_break (0 == ntohs (crm->reserved));
+ if (name_len + sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) != size)
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- str = &pks[pk_len];
+ str = (const char *) &crm[1];
if ('\0' != str[name_len - 1])
{
GNUNET_break (0);
{
send_result_code (client, 1, gettext_noop ("identifier already in use for another ego"));
GNUNET_SERVER_receive_done (client, GNUNET_OK);
- GNUNET_CRYPTO_ecc_key_free (pk);
return;
}
}
ego = GNUNET_new (struct Ego);
- ego->pk = pk;
+ ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
+ *ego->pk = crm->private_key;
ego->identifier = GNUNET_strdup (str);
GNUNET_CONTAINER_DLL_insert (ego_head,
ego_tail,
send_result_code (client, 0, NULL);
fn = get_ego_filename (ego);
(void) GNUNET_DISK_directory_create_for_file (fn);
- if (pk_len !=
- GNUNET_DISK_fn_write (fn, pks, pk_len,
+ if (sizeof (struct GNUNET_CRYPTO_EccPrivateKey) !=
+ GNUNET_DISK_fn_write (fn,
+ &crm->private_key,
+ sizeof (struct GNUNET_CRYPTO_EccPrivateKey),
GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
uint16_t name_len GNUNET_PACKED;
/**
- * Number of bytes of private key data that follow, in NBO.
+ * Usually GNUNET_NO, GNUNET_YES to signal end of list.
*/
- uint16_t pk_len GNUNET_PACKED;
+ uint16_t end_of_list GNUNET_PACKED;
- /* followed by private key */
+ /**
+ * The private key
+ */
+ struct GNUNET_CRYPTO_EccPrivateKey private_key;
/* followed by 0-terminated identity name */
uint16_t name_len GNUNET_PACKED;
/**
- * Number of bytes of private key data that follow, in NBO.
+ * Always zero.
*/
- uint16_t pk_len GNUNET_PACKED;
+ uint16_t reserved GNUNET_PACKED;
- /* followed by private key */
+ /**
+ * The private key
+ */
+ struct GNUNET_CRYPTO_EccPrivateKey private_key;
/* followed by 0-terminated service name */
uint16_t name_len GNUNET_PACKED;
/**
- * Number of bytes of private key data that follow, in NBO.
+ * Always zero.
*/
- uint16_t pk_len GNUNET_PACKED;
+ uint16_t reserved GNUNET_PACKED;
- /* followed by private key */
+ /**
+ * The private key
+ */
+ struct GNUNET_CRYPTO_EccPrivateKey private_key;
/* followed by 0-terminated identity name */
struct GNUNET_CRYPTO_EccPrivateKey *pk;
/**
- * Current identifier (name) associated with this ego.
+ * Current name associated with this ego.
*/
- char *identifier;
+ char *name;
/**
* Client context associated with this ego.
const struct GNUNET_IDENTITY_ResultCodeMessage *rcm;
const struct GNUNET_IDENTITY_UpdateMessage *um;
const struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
- struct GNUNET_CRYPTO_EccPrivateKey *priv;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub;
+ struct GNUNET_CRYPTO_EccPublicKey pub;
struct GNUNET_HashCode id;
const char *str;
uint16_t size;
- uint16_t pk_len;
uint16_t name_len;
if (NULL == msg)
return;
}
um = (const struct GNUNET_IDENTITY_UpdateMessage *) msg;
- pk_len = ntohs (um->pk_len);
- name_len = ntohs (um->name_len);
+ name_len = ntohs (um->name_len);
+
str = (const char *) &um[1];
- if ( (size != pk_len + name_len + sizeof (struct GNUNET_IDENTITY_UpdateMessage)) ||
+ if ( (size != name_len + sizeof (struct GNUNET_IDENTITY_UpdateMessage)) ||
( (0 != name_len) &&
- ('\0' != str[pk_len + name_len - 1])) )
+ ('\0' != str[name_len - 1])) )
{
GNUNET_break (0);
reschedule_connect (h);
return;
}
- if ( (0 == pk_len) &&
- (0 == name_len) )
+ if (GNUNET_YES == ntohs (um->end_of_list))
{
/* end of initial list of data */
if (NULL != h->cb)
h->cb (h->cb_cls, NULL, NULL, NULL);
break;
}
- priv = GNUNET_CRYPTO_ecc_decode_key (str, pk_len, GNUNET_YES);
- if (NULL == priv)
- {
- GNUNET_break (0);
- reschedule_connect (h);
- return;
- }
- GNUNET_CRYPTO_ecc_key_get_public (priv,
+ GNUNET_CRYPTO_ecc_key_get_public (&um->private_key,
&pub);
GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id);
if (0 == name_len)
str = NULL;
else
- str = &str[pk_len];
+ str = (const char *) &um[1];
ego = GNUNET_CONTAINER_multihashmap_get (h->egos,
&id);
if (NULL == ego)
{
/* deletion of unknown ego? not allowed */
GNUNET_break (0);
- GNUNET_CRYPTO_ecc_key_free (priv);
reschedule_connect (h);
return;
}
ego = GNUNET_new (struct GNUNET_IDENTITY_Ego);
- ego->pk = priv;
- ego->identifier = GNUNET_strdup (str);
+ ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
+ *ego->pk = um->private_key;
+ ego->name = GNUNET_strdup (str);
ego->id = id;
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_put (h->egos,
ego,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
}
- else
- {
- GNUNET_CRYPTO_ecc_key_free (priv);
- }
/* inform application about change */
if (NULL != h->cb)
h->cb (h->cb_cls,
&ego->id,
ego));
GNUNET_CRYPTO_ecc_key_free (ego->pk);
- GNUNET_free (ego->identifier);
+ GNUNET_free (ego->name);
GNUNET_free (ego);
}
else
{
/* ego changed name */
- GNUNET_free (ego->identifier);
- ego->identifier = GNUNET_strdup (str);
+ GNUNET_free (ego->name);
+ ego->name = GNUNET_strdup (str);
}
break;
case GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT:
return;
}
sdm = (const struct GNUNET_IDENTITY_SetDefaultMessage *) msg;
- pk_len = ntohs (sdm->pk_len);
+ GNUNET_break (0 == ntohs (sdm->reserved));
name_len = ntohs (sdm->name_len);
str = (const char *) &sdm[1];
- if ( (size != pk_len + name_len + sizeof (struct GNUNET_IDENTITY_SetDefaultMessage)) ||
+ if ( (size != name_len + sizeof (struct GNUNET_IDENTITY_SetDefaultMessage)) ||
( (0 != name_len) &&
- ('\0' != str[pk_len + name_len - 1]) ) )
+ ('\0' != str[name_len - 1]) ) )
{
GNUNET_break (0);
reschedule_connect (h);
return;
}
- priv = GNUNET_CRYPTO_ecc_decode_key (str, pk_len, GNUNET_YES);
- if (NULL == priv)
- {
- GNUNET_break (0);
- reschedule_connect (h);
- return;
- }
- GNUNET_CRYPTO_ecc_key_get_public (priv,
+ GNUNET_CRYPTO_ecc_key_get_public (&sdm->private_key,
&pub);
- GNUNET_CRYPTO_ecc_key_free (priv);
GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id);
if (0 == name_len)
str = NULL;
else
- str = &str[pk_len];
+ str = (const char *) &sdm[1];
ego = GNUNET_CONTAINER_multihashmap_get (h->egos,
&id);
if (NULL == ego)
op->cb (op->cls,
ego,
&ego->ctx,
- ego->identifier);
+ ego->name);
GNUNET_free (op);
break;
default:
* @return associated ECC key, valid as long as the ego is valid
*/
const struct GNUNET_CRYPTO_EccPrivateKey *
-GNUNET_IDENTITY_ego_get_key (struct GNUNET_IDENTITY_Ego *ego)
+GNUNET_IDENTITY_ego_get_private_key (struct GNUNET_IDENTITY_Ego *ego)
{
return ego->pk;
}
+/**
+ * Get the identifier (public key) of an ego.
+ *
+ * @param ego identity handle with the private key
+ * @param pk set to ego's public key
+ */
+void
+GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego,
+ struct GNUNET_CRYPTO_EccPublicKey *pk)
+{
+ GNUNET_assert (0);
+}
+
+
/**
* Obtain the identity that is currently preferred/default
* for a service.
GNUNET_IDENTITY_Continuation cont,
void *cont_cls)
{
- struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
struct GNUNET_IDENTITY_Operation *op;
struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
- char *str;
- uint16_t enc_len;
size_t slen;
slen = strlen (service_name) + 1;
- enc = GNUNET_CRYPTO_ecc_encode_key (ego->pk);
- enc_len = ntohs (enc->size);
-
- if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) - enc_len)
+ if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_SetDefaultMessage))
{
GNUNET_break (0);
- GNUNET_free (enc);
return NULL;
}
op = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_Operation) +
sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) +
- enc_len + slen);
+ slen);
op->h = id;
op->cont = cont;
op->cls = cont_cls;
sdm = (struct GNUNET_IDENTITY_SetDefaultMessage *) &op[1];
sdm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
sdm->header.size = htons (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) +
- slen + enc_len);
+ slen);
sdm->name_len = htons (slen);
- sdm->pk_len = htons (enc_len);
- str = (char *) &sdm[1];
- memcpy (str, enc, enc_len);
- memcpy (&str[enc_len], service_name, slen);
+ sdm->reserved = htons (0);
+ sdm->private_key = *ego->pk;
+ memcpy (&sdm[1], service_name, slen);
op->msg = &sdm->header;
GNUNET_CONTAINER_DLL_insert_tail (id->op_head,
id->op_tail,
/**
- * Create a new identity with the given identifier.
+ * Create a new identity with the given name.
*
* @param id identity service to use
- * @param identifier desired identifier
+ * @param name desired name
* @param cont function to call with the result (will only be called once)
* @param cont_cls closure for cont
* @return handle to abort the operation
*/
struct GNUNET_IDENTITY_Operation *
GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id,
- const char *identifier,
+ const char *name,
GNUNET_IDENTITY_Continuation cont,
void *cont_cls)
{
- struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
struct GNUNET_IDENTITY_Operation *op;
struct GNUNET_IDENTITY_CreateRequestMessage *crm;
struct GNUNET_CRYPTO_EccPrivateKey *pk;
- char *str;
- uint16_t enc_len;
size_t slen;
- slen = strlen (identifier) + 1;
+ slen = strlen (name) + 1;
pk = GNUNET_CRYPTO_ecc_key_create ();
- enc = GNUNET_CRYPTO_ecc_encode_key (pk);
- GNUNET_CRYPTO_ecc_key_free (pk);
- enc_len = ntohs (enc->size);
- if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) - enc_len)
+ if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_CreateRequestMessage))
{
GNUNET_break (0);
- GNUNET_free (enc);
+ GNUNET_CRYPTO_ecc_key_free (pk);
return NULL;
}
op = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_Operation) +
sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) +
- enc_len + slen);
+ slen);
op->h = id;
op->cont = cont;
op->cls = cont_cls;
crm = (struct GNUNET_IDENTITY_CreateRequestMessage *) &op[1];
crm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_CREATE);
crm->header.size = htons (sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) +
- slen + enc_len);
+ slen);
crm->name_len = htons (slen);
- crm->pk_len = htons (enc_len);
- str = (char *) &crm[1];
- memcpy (str, enc, enc_len);
- memcpy (&str[enc_len], identifier, slen);
+ crm->reserved = htons (0);
+ crm->private_key = *pk;
+ memcpy (&crm[1], name, slen);
op->msg = &crm->header;
GNUNET_CONTAINER_DLL_insert_tail (id->op_head,
id->op_tail,
op);
if (NULL == id->th)
transmit_next (id);
+ GNUNET_CRYPTO_ecc_key_free (pk);
return op;
}
* Renames an existing identity.
*
* @param id identity service to use
- * @param old_identifier old identifier
- * @param new_identifier desired new identifier
+ * @param old_name old name
+ * @param new_name desired new name
* @param cb function to call with the result (will only be called once)
* @param cb_cls closure for cb
* @return handle to abort the operation
*/
struct GNUNET_IDENTITY_Operation *
GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *id,
- const char *old_identifier,
- const char *new_identifier,
+ const char *old_name,
+ const char *new_name,
GNUNET_IDENTITY_Continuation cb,
void *cb_cls)
{
size_t slen_new;
char *dst;
- slen_old = strlen (old_identifier) + 1;
- slen_new = strlen (new_identifier) + 1;
+ slen_old = strlen (old_name) + 1;
+ slen_new = strlen (new_name) + 1;
if ( (slen_old >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
(slen_new >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
(slen_old + slen_new >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_RenameMessage)) )
grm->old_name_len = htons (slen_old);
grm->new_name_len = htons (slen_new);
dst = (char *) &grm[1];
- memcpy (dst, old_identifier, slen_old);
- memcpy (&dst[slen_old], new_identifier, slen_new);
+ memcpy (dst, old_name, slen_old);
+ memcpy (&dst[slen_old], new_name, slen_new);
op->msg = &grm->header;
GNUNET_CONTAINER_DLL_insert_tail (id->op_head,
id->op_tail,
* Delete an existing identity.
*
* @param id identity service to use
- * @param identifier identifier of the identity to delete
+ * @param name name of the identity to delete
* @param cb function to call with the result (will only be called once)
* @param cb_cls closure for cb
* @return handle to abort the operation
*/
struct GNUNET_IDENTITY_Operation *
GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *id,
- const char *identifier,
+ const char *name,
GNUNET_IDENTITY_Continuation cb,
void *cb_cls)
{
struct GNUNET_IDENTITY_DeleteMessage *gdm;
size_t slen;
- slen = strlen (identifier) + 1;
+ slen = strlen (name) + 1;
if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_DeleteMessage))
{
GNUNET_break (0);
slen);
gdm->name_len = htons (slen);
gdm->reserved = htons (0);
- memcpy (&gdm[1], identifier, slen);
+ memcpy (&gdm[1], name, slen);
op->msg = &gdm->header;
GNUNET_CONTAINER_DLL_insert_tail (id->op_head,
id->op_tail,
&ego->ctx,
NULL);
GNUNET_CRYPTO_ecc_key_free (ego->pk);
- GNUNET_free (ego->identifier);
+ GNUNET_free (ego->name);
GNUNET_free (ego);
return GNUNET_OK;
}
/**
* The peer providing this service
*/
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded peer;
+ struct GNUNET_CRYPTO_EccPublicKey peer;
/**
* The descriptor for the service
/**
* The public key of the authority
*/
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded public_key;
+ struct GNUNET_CRYPTO_EccPublicKey public_key;
/**
* GNUNET_RSA_Signature using RSA-key generated from the records.
*/
struct GNUNET_CRYPTO_EccSignature signature;
- /* number of records that follow */
+ /**
+ * number of records that follow
+ */
uint32_t rd_count GNUNET_PACKED;
/* 0-terminated name here */
/**
* Public key of the peer signing.
*/
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded public_key;
+ struct GNUNET_CRYPTO_EccPublicKey public_key;
/**
* The signature.
GNUNET_CONTAINER_MetaData *
member_info,
const struct
- GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
+ GNUNET_CRYPTO_RsaPublicKey
* member_id,
enum GNUNET_CHAT_MsgOptions
options);
void
GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room, const char *message,
enum GNUNET_CHAT_MsgOptions options,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
+ const struct GNUNET_CRYPTO_RsaPublicKey
*receiver, uint32_t * sequence_number);
#include "gnunet_common.h"
#include "gnunet_scheduler_lib.h"
+
+/**
+ * Maximum length of an ECC signature.
+ * Note: round up to multiple of 8 minus 2 for alignment.
+ */
+#define GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH 126
+
+
/**
* Desired quality level for cryptographic operations.
*/
*/
#define GNUNET_CRYPTO_HASH_LENGTH (512/8)
-/**
- * Maximum length of an ECC signature.
- * Note: round up to multiple of 8 minus 2 for alignment.
- */
-#define GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH 126
-
-/**
- * Maximum length of the public key (q-point, Q = dP) when encoded.
- */
-#define GNUNET_CRYPTO_ECC_MAX_PUBLIC_KEY_LENGTH 76
-
-
-/**
- * The private information of an ECC private key.
- */
-struct GNUNET_CRYPTO_EccPrivateKey;
-
-
/**
* @brief 0-terminated ASCII encoding of a struct GNUNET_HashCode.
*/
};
-
GNUNET_NETWORK_STRUCT_BEGIN
*/
struct GNUNET_CRYPTO_EccSignature
{
+
/**
- * Overall size of the signature data.
+ * R value.
*/
- uint16_t size GNUNET_PACKED;
+ unsigned char r[256 / 8];
/**
- * S-expression, padded with zeros.
+ * S value.
*/
- char sexpr[GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH];
+ unsigned char s[256 / 8];
+
};
/**
* Public ECC key (always for NIST P-521) encoded in a format suitable
- * for network transmission as created using 'gcry_sexp_sprint'.
+ * for network transmission.
*/
-struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
+struct GNUNET_CRYPTO_EccPublicKey
{
/**
- * Size of the encoding, in network byte order.
+ * Q consists of an x- and a y-value, each mod p (256 bits),
+ * given here in affine coordinates.
*/
- uint16_t size GNUNET_PACKED;
+ unsigned char q_x[256 / 8];
/**
- * Actual length of the q-point binary encoding.
+ * Q consists of an x- and a y-value, each mod p (256 bits),
+ * given here in affine coordinates.
*/
- uint16_t len GNUNET_PACKED;
+ unsigned char q_y[256 / 8];
- /**
- * 0-padded q-point in binary encoding (GCRYPT_MPI_FMT_USG).
- */
- unsigned char key[GNUNET_CRYPTO_ECC_MAX_PUBLIC_KEY_LENGTH];
};
/**
- * Private ECC key encoded for transmission (with length prefix).
+ * Private ECC key encoded for transmission.
*/
-struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded
+struct GNUNET_CRYPTO_EccPrivateKey
{
/**
- * Overall size of the private key in network byte order.
+ * d is a value mod n, where n has at most 256 bits.
*/
- uint16_t size;
-
- /* followd by S-expression, opaque to applications */
-
- /* FIXME: consider defining padding to make this a fixed-size struct */
+ unsigned char d[256 / 8];
};
/**
* Free memory occupied by ECC key
*
- * @param privatekey pointer to the memory to free
+ * @param priv pointer to the memory to free
*/
void
-GNUNET_CRYPTO_ecc_key_free (struct GNUNET_CRYPTO_EccPrivateKey *privatekey);
+GNUNET_CRYPTO_ecc_key_free (struct GNUNET_CRYPTO_EccPrivateKey *priv);
/**
*/
void
GNUNET_CRYPTO_ecc_key_get_public (const struct GNUNET_CRYPTO_EccPrivateKey *priv,
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pub);
+ struct GNUNET_CRYPTO_EccPublicKey *pub);
/**
* @return string representing 'pub'
*/
char *
-GNUNET_CRYPTO_ecc_public_key_to_string (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pub);
+GNUNET_CRYPTO_ecc_public_key_to_string (const struct GNUNET_CRYPTO_EccPublicKey *pub);
/**
int
GNUNET_CRYPTO_ecc_public_key_from_string (const char *enc,
size_t enclen,
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pub);
-
-
-/**
- * Encode the private key in a format suitable for
- * storing it into a file.
- *
- * @param key key to encode
- * @return encoding of the private key.
- * The first 4 bytes give the size of the array, as usual.
- */
-struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *
-GNUNET_CRYPTO_ecc_encode_key (const struct GNUNET_CRYPTO_EccPrivateKey *key);
-
-
-/**
- * Decode the private key from the file-format back
- * to the "normal", internal format.
- *
- * @param buf the buffer where the private key data is stored
- * @param len the length of the data in 'buffer'
- * @param validate GNUNET_YES to validate that the key is well-formed,
- * GNUNET_NO if the key comes from a totally trusted source
- * and validation is considered too expensive
- * @return NULL on error
- */
-struct GNUNET_CRYPTO_EccPrivateKey *
-GNUNET_CRYPTO_ecc_decode_key (const char *buf,
- size_t len,
- int validate);
+ struct GNUNET_CRYPTO_EccPublicKey *pub);
/**
*/
int
GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EccPrivateKey *key,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pub,
+ const struct GNUNET_CRYPTO_EccPublicKey *pub,
struct GNUNET_HashCode *key_material);
/**
* Sign a given block.
*
- * @param key private key to use for the signing
+ * @param priv private key to use for the signing
* @param purpose what to sign (size, purpose)
* @param sig where to write the signature
* @return GNUNET_SYSERR on error, GNUNET_OK on success
*/
int
-GNUNET_CRYPTO_ecc_sign (const struct GNUNET_CRYPTO_EccPrivateKey *key,
+GNUNET_CRYPTO_ecc_sign (const struct GNUNET_CRYPTO_EccPrivateKey *priv,
const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
struct GNUNET_CRYPTO_EccSignature *sig);
* @param purpose what is the purpose that the signature should have?
* @param validate block to validate (size, purpose, data)
* @param sig signature that is being validated
- * @param publicKey public key of the signer
+ * @param pub public key of the signer
* @returns GNUNET_OK if ok, GNUNET_SYSERR if invalid
*/
int
const struct GNUNET_CRYPTO_EccSignaturePurpose
*validate,
const struct GNUNET_CRYPTO_EccSignature *sig,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
- *publicKey);
+ const struct GNUNET_CRYPTO_EccPublicKey *pub);
+
+
+/**
+ * Derive a private key from a given private key and a label.
+ * Essentially calculates a private key 'h = H(l,P) * d mod n'
+ * where n is the size of the ECC group and P is the public
+ * key associated with the private key 'd'.
+ *
+ * @param priv original private key
+ * @param label label to use for key deriviation
+ * @return derived private key
+ */
+struct GNUNET_CRYPTO_EccPrivateKey *
+GNUNET_CRYPTO_ecc_key_derive (const struct GNUNET_CRYPTO_EccPrivateKey *priv,
+ const char *label);
+
+
+/**
+ * Derive a public key from a given public key and a label.
+ * Essentially calculates a public key 'V = H(l,P) * P'.
+ *
+ * @param pub original public key
+ * @param label label to use for key deriviation
+ * @param result where to write the derived public key
+ */
+void
+GNUNET_CRYPTO_ecc_public_key_derive (const struct GNUNET_CRYPTO_EccPublicKey *pub,
+ const char *label,
+ struct GNUNET_CRYPTO_EccPublicKey *result);
#if 0 /* keep Emacsens' auto-indent happy */
/**
- * Identifier for a GNUnet pseudonym (the public key). Q-point, Q=dp.
- * Note that we (ab)use an identifier of 'all zeros' to mean the
- * 'anonymous' pseudonym, where the value is actually the point at
- * infinity; however, that value cannot be represented here. We do
- * not handle the case where the actual q-Value of some pseudonym
- * happens to be all zeros as well (as the chance of that is
- * negligible).
+ * Identifier for a GNUnet pseudonym (the public key). Q-point, Q=dP.
+ * Note that we (ab)use an identifier of 'Q=G=1P' to mean the
+ * 'anonymous' pseudonym.
*/
struct GNUNET_FS_PseudonymIdentifier
{
*/
void
GNUNET_FS_pseudonym_get_identifier (struct GNUNET_FS_PseudonymHandle *ph,
- struct GNUNET_FS_PseudonymIdentifier *pseudonym);
+ struct GNUNET_FS_PseudonymIdentifier *pseudonym);
struct GNUNET_FS_Uri *
GNUNET_FS_uri_parse (const char *uri, char **emsg);
+
/**
* Free URI.
*
* @return GNUNET_OK on success, GNUNET_SYSERR on error (see errno for details)
*/
int
-GNUNET_FS_namespace_rename (struct GNUNET_FS_Handle *h, const char *old_name,
- const char *new_name);
+GNUNET_FS_namespace_rename (struct GNUNET_FS_Handle *h,
+ const char *old_name,
+ const char *new_name);
/**
* @return the hello message
*/
struct GNUNET_HELLO_Message *
-GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
- *publicKey,
+GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EccPublicKey *publicKey,
GNUNET_HELLO_GenerateAddressListCallback addrgen,
void *addrgen_cls,
int friend_only);
*/
int
GNUNET_HELLO_get_key (const struct GNUNET_HELLO_Message *hello,
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
- *publicKey);
+ struct GNUNET_CRYPTO_EccPublicKey *publicKey);
/**
*/
int
GNUNET_HELLO_parse_uri (const char *uri,
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pubkey,
+ struct GNUNET_CRYPTO_EccPublicKey *pubkey,
struct GNUNET_HELLO_Message **hello,
GNUNET_HELLO_TransportPluginsFind plugins_find);
* @return associated ECC key, valid as long as the ego is valid
*/
const struct GNUNET_CRYPTO_EccPrivateKey *
-GNUNET_IDENTITY_ego_get_key (struct GNUNET_IDENTITY_Ego *ego);
+GNUNET_IDENTITY_ego_get_private_key (struct GNUNET_IDENTITY_Ego *ego);
+
+
+/**
+ * Get the identifier (public key) of an ego.
+ *
+ * @param ego identity handle with the private key
+ * @param pk set to ego's public key
+ */
+void
+GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego,
+ struct GNUNET_CRYPTO_EccPublicKey *pk);
/**
*
* When used with 'GNUNET_IDENTITY_connect', this function is
* initially called for all egos and then again whenever a
- * ego's identifier changes or if it is deleted. At the end of
+ * ego's name changes or if it is deleted. At the end of
* the initial pass over all egos, the function is once called
* with 'NULL' for 'ego'. That does NOT mean that the callback won't
* be invoked in the future or that there was an error.
* that one was not NULL).
*
* When an identity is renamed, this function is called with the
- * (known) ego but the NEW identifier.
+ * (known) ego but the NEW name.
*
* When an identity is deleted, this function is called with the
- * (known) ego and "NULL" for the 'identifier'. In this case,
+ * (known) ego and "NULL" for the 'name'. In this case,
* the 'ego' is henceforth invalid (and the 'ctx' should also be
* cleaned up).
*
* @param ego ego handle
* @param ego_ctx context for application to store data for this ego
* (during the lifetime of this process, initially NULL)
- * @param identifier identifier assigned by the user for this ego,
+ * @param name name assigned by the user for this ego,
* 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 *identifier);
+ const char *name);
/**
/**
- * Create a new identity with the given identifier.
+ * Create a new identity with the given name.
*
* @param id identity service to use
- * @param identifier desired identifier
+ * @param name desired name
* @param cont function to call with the result (will only be called once)
* @param cont_cls closure for cont
* @return handle to abort the operation
*/
struct GNUNET_IDENTITY_Operation *
GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id,
- const char *identifier,
+ const char *name,
GNUNET_IDENTITY_Continuation cont,
void *cont_cls);
* Renames an existing identity.
*
* @param id identity service to use
- * @param old_identifier old identifier
- * @param new_identifier desired new identifier
+ * @param old_name old name
+ * @param new_name desired new name
* @param cb function to call with the result (will only be called once)
* @param cb_cls closure for cb
* @return handle to abort the operation
*/
struct GNUNET_IDENTITY_Operation *
GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *id,
- const char *old_identifier,
- const char *new_identifier,
+ const char *old_name,
+ const char *new_name,
GNUNET_IDENTITY_Continuation cb,
void *cb_cls);
* Delete an existing identity.
*
* @param id identity service to use
- * @param identifier identifier of the identity to delete
+ * @param name name of the identity to delete
* @param cb function to call with the result (will only be called once)
* @param cb_cls closure for cb
* @return handle to abort the operation
*/
struct GNUNET_IDENTITY_Operation *
GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *id,
- const char *identifier,
+ const char *name,
GNUNET_IDENTITY_Continuation cb,
void *cb_cls);
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 2, or (at your
+ by the Free Software Foundation; either version 3, or (at your
option) any later version.
GNUnet is distributed in the hope that it will be useful, but
* because the user queried for a particular record type only)
*/
typedef void (*GNUNET_NAMESTORE_RecordIterator) (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_len,
* @return GNUNET_OK on success, else GNUNET_SYSERR
*/
int (*put_records) (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_len,
*/
struct GNUNET_NAMESTORE_QueueEntry *
GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
const char *name,
struct GNUNET_TIME_Absolute freshness,
unsigned int rd_count,
* @return GNUNET_OK if the signature is valid
*/
int
-GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *public_key,
+GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_EccPublicKey *public_key,
const struct GNUNET_TIME_Absolute freshness,
const char *name,
unsigned int rd_count,
* because the user queried for a particular record type only)
*/
typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute freshness,
const char *name,
unsigned int rd_count,
* @param signature signature of the record block
*/
typedef void (*GNUNET_NAMESTORE_RecordMonitor)(void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute freshness,
const char *name,
unsigned int rd_len,
#endif
/**
- * Size of each hostkey in the hostkey file (in BYTES). This is the
- * maximum length of the S-expressions generated by libgcrypt for the
- * curves (rounded up to the next full KB to make IO nicer); it is NOT
- * the number of bits in the key.
+ * Size of each hostkey in the hostkey file (in BYTES).
*/
-#define GNUNET_TESTING_HOSTKEYFILESIZE 1024
+#define GNUNET_TESTING_HOSTKEYFILESIZE sizeof (struct GNUNET_CRYPTO_EccPrivateKey)
/**
* Handle for a system on which GNUnet peers are executed;
/**
* Local peer ephemeral public key
*/
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *my_eph;
+ struct GNUNET_CRYPTO_EccPublicKey *my_eph;
/**
* Remote peer's public key.
*/
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *peers_eph;
+ struct GNUNET_CRYPTO_EccPublicKey *peers_eph;
/**
* Encryption ("our") key.
/**
* Own public key.
*/
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key;
+static struct GNUNET_CRYPTO_EccPublicKey my_public_key;
/**
* All ports clients of this peer have opened.
/**
* Own public key.
*/
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key;
+static struct GNUNET_CRYPTO_EccPublicKey my_public_key;
/**
* Tunnel ID for the next created tunnel (global tunnel number).
*/
static void
display_record (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_len,
*/
static void
get_existing_record (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute freshness,
const char *rec_name,
unsigned int rd_count,
int result)
{
const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub;
+ struct GNUNET_CRYPTO_EccPublicKey pub;
struct GNUNET_NAMESTORE_RecordData rd;
if (GNUNET_YES != result)
struct GNUNET_NAMESTORE_CryptoContainer *c)
{
struct GNUNET_CRYPTO_EccPrivateKey *ret = c->privkey;
- struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
struct GNUNET_DISK_FileHandle *fd;
struct GNUNET_CRYPTO_ShortHashCode zone;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+ struct GNUNET_CRYPTO_EccPublicKey pubkey;
struct GNUNET_CRYPTO_EccPrivateKey *privkey;
fd = GNUNET_DISK_file_open (filename,
}
GNUNET_CRYPTO_ecc_key_get_public (privkey, &pubkey);
GNUNET_CRYPTO_short_hash (&pubkey,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&zone);
GNUNET_CRYPTO_ecc_key_free (privkey);
if (0 == memcmp (&zone, &c->zone, sizeof(zone)))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
return GNUNET_SYSERR;
}
- if (GNUNET_YES != GNUNET_DISK_file_lock (fd, 0, sizeof (struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded), GNUNET_YES))
+ if (GNUNET_YES !=
+ GNUNET_DISK_file_lock (fd, 0,
+ sizeof (struct GNUNET_CRYPTO_EccPrivateKey),
+ GNUNET_YES))
{
GNUNET_break (GNUNET_YES == GNUNET_DISK_file_close (fd));
return GNUNET_SYSERR;
}
- enc = GNUNET_CRYPTO_ecc_encode_key (ret);
- GNUNET_assert (NULL != enc);
- GNUNET_assert (ntohs (enc->size) == GNUNET_DISK_file_write (fd, enc, ntohs (enc->size)));
- GNUNET_free (enc);
+ GNUNET_assert (sizeof (struct GNUNET_CRYPTO_EccPrivateKey) ==
+ GNUNET_DISK_file_write (fd, ret,
+ sizeof (struct GNUNET_CRYPTO_EccPrivateKey)));
GNUNET_DISK_file_sync (fd);
- if (GNUNET_YES != GNUNET_DISK_file_unlock (fd, 0, sizeof (struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded)))
+ if (GNUNET_YES !=
+ GNUNET_DISK_file_unlock (fd, 0,
+ sizeof (struct GNUNET_CRYPTO_EccPrivateKey)))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
static void
learn_private_key (struct GNUNET_CRYPTO_EccPrivateKey *pkey)
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub;
+ struct GNUNET_CRYPTO_EccPublicKey pub;
struct GNUNET_HashCode long_hash;
struct GNUNET_CRYPTO_ShortHashCode pubkey_hash;
struct GNUNET_NAMESTORE_CryptoContainer *cc;
GNUNET_CRYPTO_ecc_key_get_public (pkey, &pub);
GNUNET_CRYPTO_short_hash (&pub,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&pubkey_hash);
GNUNET_CRYPTO_short_hash_double (&pubkey_hash, &long_hash);
*/
static void
handle_lookup_name_it (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_count,
if (NULL != zone_key)
{
GNUNET_CRYPTO_short_hash (zone_key,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&zone_key_hash);
GNUNET_CRYPTO_short_hash_double (&zone_key_hash, &long_hash);
if (NULL != (cc = GNUNET_CONTAINER_multihashmap_get (zonekeys, &long_hash)))
send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc,
struct GNUNET_SERVER_Client *client,
uint32_t request_id,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_count,
size_t msg_size;
size_t msg_size_exp;
size_t rd_ser_len;
- size_t key_len;
uint32_t rid;
- const char *pkey_tmp;
const char *name_tmp;
char *conv_name;
const char *rd_ser;
unsigned int rd_count;
int res;
struct GNUNET_CRYPTO_ShortHashCode pubkey_hash;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+ struct GNUNET_CRYPTO_EccPublicKey pubkey;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received `%s' message\n", "NAMESTORE_RECORD_CREATE");
msg_size = ntohs (message->size);
rd_count = ntohs (rp_msg->rd_count);
rd_ser_len = ntohs (rp_msg->rd_len);
- key_len = ntohs (rp_msg->pkey_len);
- msg_size_exp = sizeof (struct RecordCreateMessage) + key_len + name_len + rd_ser_len;
+ GNUNET_break (0 == ntohs (rp_msg->reserved));
+ msg_size_exp = sizeof (struct RecordCreateMessage) + name_len + rd_ser_len;
if (msg_size != msg_size_exp)
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- pkey_tmp = (const char *) &rp_msg[1];
- name_tmp = &pkey_tmp[key_len];
+ name_tmp = (const char *) &rp_msg[1];
rd_ser = &name_tmp[name_len];
if ('\0' != name_tmp[name_len -1])
{
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- if (NULL == (pkey = GNUNET_CRYPTO_ecc_decode_key (pkey_tmp, key_len,
- GNUNET_NO)))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ pkey = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
+ memcpy (pkey, &rp_msg->private_key, sizeof (struct GNUNET_CRYPTO_EccPrivateKey));
{
struct GNUNET_NAMESTORE_RecordData rd[rd_count];
/* Extracting and converting private key */
GNUNET_CRYPTO_ecc_key_get_public (pkey, &pubkey);
GNUNET_CRYPTO_short_hash (&pubkey,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&pubkey_hash);
learn_private_key (pkey);
conv_name = GNUNET_NAMESTORE_normalize_string (name_tmp);
*/
static void
handle_zone_to_name_it (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_count,
*/
static void
zone_iteraterate_proc (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_count,
/* compute / obtain signature, but only if we (a) have records and (b) expiration times were
converted to absolute expiration times */
GNUNET_CRYPTO_short_hash (zone_key,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&zone_hash);
GNUNET_CRYPTO_short_hash_double (&zone_hash, &long_hash);
if (NULL != (cc = GNUNET_CONTAINER_multihashmap_get (zonekeys, &long_hash)))
*/
static void
monitor_iterate_cb (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_count,
/**
* The public key for the name
*/
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded public_key;
+ struct GNUNET_CRYPTO_EccPublicKey public_key;
/* 0-terminated name and serialized record data */
/* rd_len bytes serialized record data */
/**
* The public key
*/
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded public_key;
+ struct GNUNET_CRYPTO_EccPublicKey public_key;
/* name (0-terminated) followed by "rd_count" serialized records */
uint16_t rd_count;
/**
- * private key length
+ * always zero
*/
- uint16_t pkey_len;
+ uint16_t reserved;
+
+ struct GNUNET_CRYPTO_EccPrivateKey private_key;
/* followed by:
- * GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded private key with length pkey_len
* name with length name_len
* serialized record data with length rd_len
- * */
+ */
};
/**
* Publik key
*/
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded zone_key;
+ struct GNUNET_CRYPTO_EccPublicKey zone_key;
};
const char * rd_tmp;
const struct GNUNET_CRYPTO_EccSignature *signature;
struct GNUNET_TIME_Absolute expire;
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *public_key_tmp;
+ const struct GNUNET_CRYPTO_EccPublicKey *public_key_tmp;
size_t exp_msg_len;
size_t msg_len;
size_t name_len;
const struct LookupNameResponseMessage *msg,
size_t size)
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubdummy;
+ struct GNUNET_CRYPTO_EccPublicKey pubdummy;
size_t msg_len;
size_t exp_msg_len;
size_t name_len;
*/
struct GNUNET_NAMESTORE_QueueEntry *
GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
const char *name,
struct GNUNET_TIME_Absolute freshness,
unsigned int rd_count,
* @return GNUNET_OK if the signature is valid
*/
int
-GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *public_key,
+GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_EccPublicKey *public_key,
const struct GNUNET_TIME_Absolute freshness,
const char *name,
unsigned int rd_count,
{
struct GNUNET_NAMESTORE_QueueEntry *qe;
struct PendingMessage *pe;
- char * name_tmp;
- char * pkey_tmp;
- char * rd_ser;
+ char *name_tmp;
+ char *rd_ser;
size_t rd_ser_len;
size_t msg_size;
size_t name_len;
- size_t key_len;
uint32_t rid;
- struct RecordCreateMessage * msg;
- struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded * pkey_enc;
+ struct RecordCreateMessage *msg;
GNUNET_assert (NULL != h);
GNUNET_assert (NULL != pkey);
qe->op_id = rid;
GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
- pkey_enc = GNUNET_CRYPTO_ecc_encode_key (pkey);
- GNUNET_assert (NULL != pkey_enc);
-
/* setup msg */
- key_len = ntohs (pkey_enc->size);
rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
- msg_size = sizeof (struct RecordCreateMessage) + key_len + name_len + rd_ser_len;
+ msg_size = sizeof (struct RecordCreateMessage) + name_len + rd_ser_len;
pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size);
pe->size = msg_size;
pe->is_init = GNUNET_NO;
msg->name_len = htons (name_len);
msg->rd_count = htons (rd_count);
msg->rd_len = htons (rd_ser_len);
- msg->pkey_len = htons (key_len);
+ msg->reserved = htons (0);
msg->expire = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS);
- pkey_tmp = (char *) &msg[1];
- memcpy (pkey_tmp, pkey_enc, key_len);
- name_tmp = &pkey_tmp[key_len];
+ msg->private_key = *pkey;
+
+ name_tmp = (char *) &msg[1];
memcpy (name_tmp, name, name_len);
rd_ser = &name_tmp[name_len];
GNUNET_break (rd_ser_len == GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser));
- GNUNET_free (pkey_enc);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Sending `%s' message for name `%s' with size %u\n",
/*
* This file is part of GNUnet
- * (C) 2009, 2011, 2012 Christian Grothoff (and other contributing authors)
+ * (C) 2009-2013 Christian Grothoff (and other contributing authors)
*
* GNUnet is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
*/
static int
namestore_postgres_put_records (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_count,
unsigned int i;
GNUNET_CRYPTO_short_hash (zone_key,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&zone);
(void) namestore_postgres_remove_records (plugin, &zone, name);
name_len = strlen (name);
(const char *) &rvalue_be
};
int paramLengths[] = {
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
name_len,
sizeof (uint32_t),
data_size,
{
unsigned int record_count;
size_t data_size;
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key;
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key;
const struct GNUNET_CRYPTO_EccSignature *sig;
struct GNUNET_TIME_Absolute expiration;
const char *data;
}
GNUNET_assert (1 == cnt);
if ((6 != PQnfields (res)) ||
- (sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded) != PQgetlength (res, 0, 0)) ||
+ (sizeof (struct GNUNET_CRYPTO_EccPublicKey) != PQgetlength (res, 0, 0)) ||
(sizeof (uint32_t) != PQfsize (res, 2)) ||
(sizeof (uint64_t) != PQfsize (res, 4)) ||
(sizeof (struct GNUNET_CRYPTO_EccSignature) != PQgetlength (res, 0, 5)))
PQclear (res);
return GNUNET_SYSERR;
}
- zone_key = (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *) PQgetvalue (res, 0, 0);
+ zone_key = (const struct GNUNET_CRYPTO_EccPublicKey *) PQgetvalue (res, 0, 0);
name = PQgetvalue (res, 0, 1);
name_len = PQgetlength (res, 0, 1);
record_count = ntohl (*(uint32_t *) PQgetvalue (res, 0, 2));
/*
* This file is part of GNUnet
- * (C) 2009, 2011, 2012 Christian Grothoff (and other contributing authors)
+ * (C) 2009-2013 Christian Grothoff (and other contributing authors)
*
* GNUnet is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
*/
static int
namestore_sqlite_put_records (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_count,
size_t data_size;
unsigned int i;
- GNUNET_CRYPTO_short_hash (zone_key, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), &zone);
+ GNUNET_CRYPTO_short_hash (zone_key, sizeof (struct GNUNET_CRYPTO_EccPublicKey), &zone);
(void) namestore_sqlite_remove_records (plugin, &zone, name);
name_len = strlen (name);
GNUNET_CRYPTO_short_hash (name, name_len, &nh);
GNUNET_break (0);
return GNUNET_SYSERR;
}
- if ((SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 1, zone_key, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), SQLITE_STATIC)) ||
+ if ((SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 1, zone_key, sizeof (struct GNUNET_CRYPTO_EccPublicKey), SQLITE_STATIC)) ||
(SQLITE_OK != sqlite3_bind_text (plugin->put_records, 2, name, -1, SQLITE_STATIC)) ||
(SQLITE_OK != sqlite3_bind_int (plugin->put_records, 3, rd_count)) ||
(SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 4, data, data_size, SQLITE_STATIC)) ||
int sret;
unsigned int record_count;
size_t data_size;
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key;
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key;
const struct GNUNET_CRYPTO_EccSignature *sig;
struct GNUNET_TIME_Absolute expiration;
const char *data;
expiration.abs_value = (uint64_t) sqlite3_column_int64 (stmt, 4);
sig = sqlite3_column_blob (stmt, 5);
- if ( (sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded) != sqlite3_column_bytes (stmt, 0)) ||
+ if ( (sizeof (struct GNUNET_CRYPTO_EccPublicKey) != sqlite3_column_bytes (stmt, 0)) ||
(sizeof (struct GNUNET_CRYPTO_EccSignature) != sqlite3_column_bytes (stmt, 5)) )
{
GNUNET_break (0);
static struct GNUNET_CRYPTO_EccPrivateKey *privkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey;
static struct GNUNET_CRYPTO_ShortHashCode zone;
static void
name_lookup_proc (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_count,
static struct GNUNET_CRYPTO_EccPrivateKey * privkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey;
static struct GNUNET_CRYPTO_ShortHashCode s_zone;
static void
name_lookup_second_proc (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *n,
unsigned int rd_count,
if (n != NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking returned results\n");
- if (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)))
+ if (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKey)))
{
GNUNET_break (0);
failed = GNUNET_YES;
static void
name_lookup_initial_proc (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *n,
unsigned int rd_count,
if (n != NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking returned results\n");
- if (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)))
+ if (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKey)))
{
GNUNET_break (0);
failed = GNUNET_YES;
GNUNET_NAMESTORE_records_serialize(1, s_first_record, rd_ser_len, rd_ser);
/* create random zone hash */
- GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), &s_zone);
+ GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKey), &s_zone);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name: `%s' Zone: `%s' \n", s_name, GNUNET_NAMESTORE_short_h2s (&s_zone));
nsh = GNUNET_NAMESTORE_connect (cfg);
static struct GNUNET_CRYPTO_EccPrivateKey * privkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey;
static struct GNUNET_CRYPTO_EccSignature *s_signature;
s_signature = GNUNET_NAMESTORE_create_signature(privkey, et, s_name, s_first_record, 1);
/* create random zone hash */
- GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), &s_zone);
+ GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKey), &s_zone);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name: `%s' Zone: `%s' \n", s_name, GNUNET_NAMESTORE_short_h2s (&s_zone));
nsh = GNUNET_NAMESTORE_connect (cfg);
static struct GNUNET_CRYPTO_EccPrivateKey * privkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey;
static struct GNUNET_CRYPTO_EccSignature *s_signature;
static void
name_lookup_proc (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *n,
unsigned int rd_count,
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking returned results\n");
if (0 != memcmp (zone_key, &pubkey,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)))
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey)))
{
GNUNET_break (0);
}
/* create random zone hash */
GNUNET_CRYPTO_short_hash (&pubkey,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&s_zone);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
static struct GNUNET_CRYPTO_EccPrivateKey * privkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey;
static struct GNUNET_CRYPTO_EccSignature *s_signature;
static void
name_lookup_existing_record_type (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *n,
unsigned int rd_count,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore returned %u records\n", rd_count);
- if ((NULL == n) || (0 != memcmp(zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded))))
+ if ((NULL == n) || (0 != memcmp(zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKey))))
{
GNUNET_break(0);
failed = GNUNET_YES;
static void
name_lookup_non_existing_record_type (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *n,
unsigned int rd_count,
s_signature = GNUNET_NAMESTORE_create_signature(privkey, et, s_name, s_rd, RECORDS);
/* create random zone hash */
- GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), &s_zone);
+ GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKey), &s_zone);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
GNUNET_break (s_rd != NULL);
static struct GNUNET_CRYPTO_EccPrivateKey * privkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey;
static struct GNUNET_HashCode zone;
static struct GNUNET_CRYPTO_EccPrivateKey * privkey2;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey2;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey2;
static struct GNUNET_HashCode zone2;
static void
zone_proc (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_count,
static struct GNUNET_CRYPTO_EccPrivateKey * privkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey;
static struct GNUNET_NAMESTORE_RecordData *s_rd;
static struct GNUNET_CRYPTO_EccPrivateKey * privkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey;
static struct GNUNET_CRYPTO_EccSignature *s_signature;
static void
name_lookup_proc (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *n,
unsigned int rd_count,
"Lookup for name `%s' returned %u records\n", n, rd_count);
if (0 != memcmp (zone_key,
&pubkey,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)))
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey)))
{
GNUNET_break (0);
failed = GNUNET_YES;
s_signature = GNUNET_NAMESTORE_create_signature(privkey, et, s_name, s_rd, RECORDS);
/* create random zone hash */
- GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), &s_zone);
+ GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKey), &s_zone);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name: `%s' Zone: `%s' \n", s_name, GNUNET_NAMESTORE_short_h2s (&s_zone));
nsh = GNUNET_NAMESTORE_connect (cfg);
static struct GNUNET_CRYPTO_EccPrivateKey * privkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey;
static struct GNUNET_CRYPTO_EccSignature *s_signature;
s_signature = GNUNET_NAMESTORE_create_signature(privkey, et, s_name, s_rd, RECORDS);
/* create random zone hash */
- GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), &s_zone);
+ GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKey), &s_zone);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name: `%s' Zone: `%s' \n", s_name, GNUNET_h2s_full(&s_zone));
nsh = GNUNET_NAMESTORE_connect (cfg);
static struct GNUNET_CRYPTO_EccPrivateKey * privkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey;
static struct GNUNET_NAMESTORE_RecordData *s_rd;
static struct GNUNET_CRYPTO_EccPrivateKey * privkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey;
static struct GNUNET_HashCode zone;
static struct GNUNET_CRYPTO_EccPrivateKey * privkey2;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey2;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey2;
static struct GNUNET_HashCode zone2;
static void
zone_proc (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_count,
if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (zone_key, expire, name, rd_count, rd, signature))
{
struct GNUNET_HashCode zone_key_hash;
- GNUNET_CRYPTO_hash (zone_key, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), &zone_key_hash);
+ GNUNET_CRYPTO_hash (zone_key, sizeof (struct GNUNET_CRYPTO_EccPublicKey), &zone_key_hash);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Verifying signature for `%s' in zone `%s' with %u records and expiration %llu failed\n", name, GNUNET_h2s(&zone_key_hash), rd_count, expire.abs_value);
failed = GNUNET_YES;
*/
static void
empty_zone_proc (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_count,
static struct GNUNET_CRYPTO_EccPrivateKey * privkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey;
static struct GNUNET_CRYPTO_ShortHashCode zone;
static struct GNUNET_CRYPTO_EccPrivateKey * privkey2;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey2;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey2;
static struct GNUNET_CRYPTO_ShortHashCode zone2;
static void
zone_proc (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_count,
static struct GNUNET_CRYPTO_EccPrivateKey * privkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey;
static struct GNUNET_HashCode zone;
static struct GNUNET_CRYPTO_EccPrivateKey * privkey2;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey2;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey2;
static struct GNUNET_HashCode zone2;
static void
zone_proc (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_count,
static struct GNUNET_CRYPTO_EccPrivateKey * privkey;
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+static struct GNUNET_CRYPTO_EccPublicKey pubkey;
static struct GNUNET_TIME_Absolute expire;
static void
zone_to_name_proc (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *n,
unsigned int rd_count,
fail = GNUNET_YES;
GNUNET_break (0);
}
- if ((zone_key == NULL) || (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded))))
+ if ((zone_key == NULL) || (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKey))))
{
fail = GNUNET_YES;
GNUNET_break (0);
GNUNET_CRYPTO_ecc_key_get_public(privkey, &pubkey);
/* zone hash */
- GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), &s_zone);
+ GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKey), &s_zone);
GNUNET_CRYPTO_short_hash (s_name, strlen (s_name) + 1, &s_zone_value);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using PKEY `%s' \n", GNUNET_NAMESTORE_short_h2s (&s_zone_value));
*/
static void
test_record (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+ const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
unsigned int rd_count,
{
int *idp = cls;
int id = *idp;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded tzone_key;
+ struct GNUNET_CRYPTO_EccPublicKey tzone_key;
char tname[64];
unsigned int trd_count = 1 + (id % 1024);
struct GNUNET_CRYPTO_EccSignature tsignature;
memset (&tzone_key, (id % 241), sizeof (tzone_key));
memset (&tsignature, (id % 243), sizeof (tsignature));
GNUNET_assert (0 == strcmp (name, tname));
- GNUNET_assert (0 == memcmp (&tzone_key, zone_key, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)));
+ GNUNET_assert (0 == memcmp (&tzone_key, zone_key, sizeof (struct GNUNET_CRYPTO_EccPublicKey)));
GNUNET_assert (0 == memcmp (&tsignature, signature, sizeof (struct GNUNET_CRYPTO_EccSignature)));
}
static void
put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded zone_key;
+ struct GNUNET_CRYPTO_EccPublicKey zone_key;
struct GNUNET_TIME_Absolute expire;
char name[64];
unsigned int rd_count = 1 + (id % 1024);
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_NAMESTORE_PluginFunctions *nsp;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded zone_key;
+ struct GNUNET_CRYPTO_EccPublicKey zone_key;
struct GNUNET_CRYPTO_ShortHashCode zone;
ok = 0;
/**
* Public key of the originator.
*/
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
+ struct GNUNET_CRYPTO_EccPublicKey pkey;
/**
* Proof of work, causing leading zeros when hashed with pkey.
/**
* The public key of this peer.
*/
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key;
+static struct GNUNET_CRYPTO_EccPublicKey my_public_key;
/**
* The private key of this peer.
* @return GNUNET_YES if valid, GNUNET_NO if not
*/
static int
-check_proof_of_work (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pkey,
+check_proof_of_work (const struct GNUNET_CRYPTO_EccPublicKey *pkey,
uint64_t val)
{
- char buf[sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded) +
+ char buf[sizeof (struct GNUNET_CRYPTO_EccPublicKey) +
sizeof (val)] GNUNET_ALIGN;
struct GNUNET_HashCode result;
memcpy (buf, &val, sizeof (val));
memcpy (&buf[sizeof (val)], pkey,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded));
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey));
pow_hash (buf, sizeof (buf), &result);
return (count_leading_zeroes (&result) >=
nse_work_required) ? GNUNET_YES : GNUNET_NO;
{
#define ROUND_SIZE 10
uint64_t counter;
- char buf[sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded) +
+ char buf[sizeof (struct GNUNET_CRYPTO_EccPublicKey) +
sizeof (uint64_t)] GNUNET_ALIGN;
struct GNUNET_HashCode result;
unsigned int i;
proof_task = GNUNET_SCHEDULER_NO_TASK;
memcpy (&buf[sizeof (uint64_t)], &my_public_key,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded));
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey));
i = 0;
counter = my_proof;
while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
struct GNUNET_PeerIdentity os;
GNUNET_CRYPTO_hash (&incoming_flood->pkey,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&os.hashPubKey);
GNUNET_snprintf (origin, sizeof (origin), "%s", GNUNET_i2s (&os));
GNUNET_snprintf (pred, sizeof (pred), "%s", GNUNET_i2s (peer));
/**
* My public key.
*/
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key;
+static struct GNUNET_CRYPTO_EccPublicKey my_public_key;
/**
* Head of list of print contexts.
{
struct GNUNET_HELLO_Message * res;
struct GNUNET_HELLO_Message * tmp;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pk;
+ struct GNUNET_CRYPTO_EccPublicKey pk;
if (NULL != friend_hello)
{
static void
add_peer (size_t i)
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
+ struct GNUNET_CRYPTO_EccPublicKey pkey;
struct GNUNET_HELLO_Message *h2;
memset (&pkey, i, sizeof (pkey));
static void
add_peer ()
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
+ struct GNUNET_CRYPTO_EccPublicKey pkey;
struct GNUNET_HELLO_Message *h2;
size_t agc;
static void
add_peer ()
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
+ struct GNUNET_CRYPTO_EccPublicKey pkey;
struct GNUNET_HELLO_Message *h2;
size_t agc;
static void
add_peer ()
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
+ struct GNUNET_CRYPTO_EccPublicKey pkey;
struct GNUNET_HELLO_Message *h2;
size_t agc;
"# regex accepting block bytes found",
size, GNUNET_NO);
GNUNET_CRYPTO_hash (&block->public_key,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&pid.hashPubKey);
info->callback (info->callback_cls,
&pid,
static int
create_hostkeys (const unsigned int no)
{
- static char pad[GNUNET_TESTING_HOSTKEYFILESIZE];
struct GNUNET_TESTING_System *system;
struct GNUNET_PeerIdentity id;
struct GNUNET_DISK_FileHandle *fd;
struct GNUNET_CRYPTO_EccPrivateKey *pk;
- struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *pkb;
- ssize_t ret;
system = GNUNET_TESTING_system_create ("testing", NULL, NULL, NULL);
pk = GNUNET_TESTING_hostkey_get (system, create_no, &id);
GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE);
GNUNET_assert (fd != NULL);
- pkb = GNUNET_CRYPTO_ecc_encode_key (pk);
- ret = GNUNET_DISK_file_write (fd, pkb,
- ntohs (pkb->size));
- GNUNET_assert (ntohs (pkb->size) == ret);
- GNUNET_assert (ntohs (pkb->size) < GNUNET_TESTING_HOSTKEYFILESIZE);
- GNUNET_assert (GNUNET_TESTING_HOSTKEYFILESIZE - ret ==
- GNUNET_DISK_file_write (fd, pad,
- GNUNET_TESTING_HOSTKEYFILESIZE - ret));
-
+ ret = GNUNET_DISK_file_write (fd, pk,
+ sizeof (struct GNUNET_CRYPTO_EccPrivateKey));
GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
"Wrote hostkey to file: `%s'\n", create_hostkey);
- GNUNET_free (pkb);
GNUNET_CRYPTO_ecc_key_free (pk);
GNUNET_TESTING_system_destroy (system, GNUNET_YES);
return 0;
struct GNUNET_PeerIdentity *id)
{
struct GNUNET_CRYPTO_EccPrivateKey *private_key;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded public_key;
+ struct GNUNET_CRYPTO_EccPublicKey public_key;
if ((NULL == id) || (NULL == system->hostkeys_data))
return NULL;
_("Key number %u does not exist\n"), key_number);
return NULL;
}
- private_key = GNUNET_CRYPTO_ecc_decode_key (system->hostkeys_data +
- (key_number *
- GNUNET_TESTING_HOSTKEYFILESIZE),
- GNUNET_TESTING_HOSTKEYFILESIZE,
- GNUNET_NO);
+ private_key = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
+ memcpy (private_key,
+ system->hostkeys_data +
+ (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
+ GNUNET_TESTING_HOSTKEYFILESIZE);
if (NULL == private_key)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
}
GNUNET_CRYPTO_ecc_key_get_public (private_key, &public_key);
GNUNET_CRYPTO_hash (&public_key,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&(id->hashPubKey));
return private_key;
}
/**
* Our public key.
*/
-struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded GST_my_public_key;
+struct GNUNET_CRYPTO_EccPublicKey GST_my_public_key;
/**
* Our private key.
/**
* Our public key.
*/
-extern struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded GST_my_public_key;
+extern struct GNUNET_CRYPTO_EccPublicKey GST_my_public_key;
/**
* Our private key.
/**
* Public key of the sender.
*/
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded public_key;
+ struct GNUNET_CRYPTO_EccPublicKey public_key;
/**
* Signature of the peer that sends us the disconnect. Only
disconnect_msg.reserved = htonl (0);
disconnect_msg.purpose.size =
htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded) +
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey) +
sizeof (struct GNUNET_TIME_AbsoluteNBO));
disconnect_msg.purpose.purpose =
htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
return;
}
GNUNET_CRYPTO_hash (&sdm->public_key,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
&hc);
if (0 != memcmp (peer, &hc, sizeof (struct GNUNET_PeerIdentity)))
{
}
if (ntohl (sdm->purpose.size) !=
sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded) +
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey) +
sizeof (struct GNUNET_TIME_AbsoluteNBO))
{
GNUNET_break_op (0);
/**
* Public key of the peer.
*/
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded public_key;
+ struct GNUNET_CRYPTO_EccPublicKey public_key;
/**
* The identity of the peer. FIXME: duplicated (also in 'address')
* if we don't have an existing entry and no public key was given
*/
static struct ValidationEntry *
-find_validation_entry (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
- *public_key, const struct GNUNET_HELLO_Address *address)
+find_validation_entry (const struct GNUNET_CRYPTO_EccPublicKey *public_key,
+ const struct GNUNET_HELLO_Address *address)
{
struct ValidationEntryMatchContext vemc;
struct ValidationEntry *ve;
struct ValidationEntry *ve;
struct GNUNET_PeerIdentity pid;
struct GNUNET_ATS_Information ats;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded public_key;
+ struct GNUNET_CRYPTO_EccPublicKey public_key;
if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0)
return GNUNET_OK; /* expired */
*/
static void
multicast_pong (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
- *public_key, struct GNUNET_TIME_Absolute valid_until,
+ const struct GNUNET_CRYPTO_EccPublicKey *public_key,
+ struct GNUNET_TIME_Absolute valid_until,
struct GNUNET_TIME_Absolute validation_block,
const struct GNUNET_HELLO_Address *address)
{
/**
* Public key of the peer whose address is being validated.
*/
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded public_key;
+ struct GNUNET_CRYPTO_EccPublicKey public_key;
};
*/
typedef void (*GST_ValidationAddressCallback) (void *cls,
const struct
- GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
- * public_key,
+ GNUNET_CRYPTO_EccPublicKey *public_key,
struct GNUNET_TIME_Absolute
valid_until,
struct GNUNET_TIME_Absolute
/**
* Our public key.
*/
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key;
+static struct GNUNET_CRYPTO_EccPublicKey my_public_key;
/**
* Our identity.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 2, or (at your
+ by the Free Software Foundation; either version 3, or (at your
option) any later version.
GNUnet is distributed in the hope that it will be useful, but
#define EXTRA_CHECKS ALLOW_EXTRA_CHECKS
+/**
+ * Name of the curve we are using. Note that we have hard-coded
+ * structs that use 256 bits, so using a bigger curve will require
+ * changes that break stuff badly. The name of the curve given here
+ * must be agreed by all peers and be supported by libgcrypt.
+ */
#define CURVE "NIST P-256"
#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
#define LOG_GCRY(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, gcry_strerror(rc)); } while(0);
-/**
- * The private information of an ECC private key.
- */
-struct GNUNET_CRYPTO_EccPrivateKey
-{
-
- /**
- * Libgcrypt S-expression for the ECC key.
- */
- gcry_sexp_t sexp;
-};
-
-
/**
* Free memory occupied by ECC key
*
- * @param privatekey pointer to the memory to free
+ * @param priv pointer to the memory to free
*/
void
-GNUNET_CRYPTO_ecc_key_free (struct GNUNET_CRYPTO_EccPrivateKey *privatekey)
+GNUNET_CRYPTO_ecc_key_free (struct GNUNET_CRYPTO_EccPrivateKey *priv)
{
- gcry_sexp_release (privatekey->sexp);
- GNUNET_free (privatekey);
+ GNUNET_free (priv);
}
}
+/**
+ * If target != size, move target bytes to the end of the size-sized
+ * buffer and zero out the first target-size bytes.
+ *
+ * @param buf original buffer
+ * @param size number of bytes in the buffer
+ * @param target target size of the buffer
+ */
+static void
+adjust (unsigned char *buf,
+ size_t size,
+ size_t target)
+{
+ if (size < target)
+ {
+ memmove (&buf[target - size], buf, size);
+ memset (buf, 0, target - size);
+ }
+}
+
+
+/**
+ * Output the given MPI value to the given buffer.
+ *
+ * @param buf where to output to
+ * @param size number of bytes in buf
+ * @param val value to write to buf
+ */
+static void
+mpi_print (unsigned char *buf,
+ size_t size,
+ gcry_mpi_t val)
+{
+ size_t rsize;
+
+ rsize = size;
+ GNUNET_assert (0 ==
+ gcry_mpi_print (GCRYMPI_FMT_USG, buf, rsize, &rsize,
+ val));
+ adjust (buf, rsize, size);
+}
+
+
+/**
+ * Convert data buffer into MPI value.
+ *
+ * @param result where to store MPI value (allocated)
+ * @param data raw data (GCRYMPI_FMT_USG)
+ * @param size number of bytes in data
+ */
+static void
+mpi_scan (gcry_mpi_t *result,
+ const unsigned char *data,
+ size_t size)
+{
+ int rc;
+
+ if (0 != (rc = gcry_mpi_scan (result,
+ GCRYMPI_FMT_USG,
+ data, size, &size)))
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+ GNUNET_assert (0);
+ }
+}
+
+
+/**
+ * Convert the given private key from the network format to the
+ * S-expression that can be used by libgcrypt.
+ *
+ * @param priv private key to decode
+ * @return NULL on error
+ */
+static gcry_sexp_t
+decode_private_key (const struct GNUNET_CRYPTO_EccPrivateKey *priv)
+{
+ gcry_sexp_t result;
+ gcry_mpi_t d;
+ size_t erroff;
+ int rc;
+
+ mpi_scan (&d,
+ priv->d,
+ sizeof (priv->d));
+ rc = gcry_sexp_build (&result, &erroff,
+ "(private-key(ecdsa(curve \"" CURVE "\")(d %m)))",
+ d);
+ gcry_mpi_release (d);
+ if (0 != rc)
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); /* erroff gives more info */
+ GNUNET_assert (0);
+ }
+#if EXTRA_CHECKS
+ if (0 != (rc = gcry_pk_testkey (result)))
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc);
+ GNUNET_assert (0);
+ }
+#endif
+ return result;
+}
+
+
+/**
+ * Initialize public key struct from the respective point
+ * on the curve.
+ *
+ * @param q point on curve
+ * @param pub public key struct to initialize
+ * @param ctx context to use for ECC operations
+ */
+static void
+point_to_public_key (gcry_mpi_point_t q,
+ gcry_ctx_t ctx,
+ struct GNUNET_CRYPTO_EccPublicKey *pub)
+{
+ gcry_mpi_t q_x;
+ gcry_mpi_t q_y;
+
+ q_x = gcry_mpi_new (256);
+ q_y = gcry_mpi_new (256);
+ if (gcry_mpi_ec_get_affine (q_x, q_y, q, ctx))
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "get_affine failed", 0);
+ return;
+ }
+ mpi_print (pub->q_x, sizeof (pub->q_x), q_x);
+ mpi_print (pub->q_y, sizeof (pub->q_y), q_y);
+ gcry_mpi_release (q_x);
+ gcry_mpi_release (q_y);
+}
+
+
/**
* Extract the public key for the given private key.
*
*/
void
GNUNET_CRYPTO_ecc_key_get_public (const struct GNUNET_CRYPTO_EccPrivateKey *priv,
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pub)
+ struct GNUNET_CRYPTO_EccPublicKey *pub)
{
- gcry_mpi_t skey;
- size_t size;
+ gcry_sexp_t sexp;
+ gcry_ctx_t ctx;
+ gcry_mpi_point_t q;
int rc;
- memset (pub, 0, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded));
- rc = key_from_sexp (&skey, priv->sexp, "public-key", "q");
- if (rc)
- rc = key_from_sexp (&skey, priv->sexp, "private-key", "q");
- if (rc)
- rc = key_from_sexp (&skey, priv->sexp, "ecc", "q");
- GNUNET_assert (0 == rc);
- pub->size = htons (sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded));
- size = GNUNET_CRYPTO_ECC_MAX_PUBLIC_KEY_LENGTH;
- GNUNET_assert (0 ==
- gcry_mpi_print (GCRYMPI_FMT_USG, pub->key, size, &size,
- skey));
- pub->len = htons (size);
- gcry_mpi_release (skey);
+ sexp = decode_private_key (priv);
+ GNUNET_assert (NULL != sexp);
+ if (0 != (rc = gcry_mpi_ec_new (&ctx, sexp, NULL)))
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_ec_new", rc); /* erroff gives more info */
+ return;
+ }
+ gcry_sexp_release (sexp);
+ q = gcry_mpi_ec_get_point ("q", ctx, 0);
+ point_to_public_key (q, ctx, pub);
+ gcry_ctx_release (ctx);
+ gcry_mpi_point_release (q);
}
* @return string representing 'pub'
*/
char *
-GNUNET_CRYPTO_ecc_public_key_to_string (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pub)
+GNUNET_CRYPTO_ecc_public_key_to_string (const struct GNUNET_CRYPTO_EccPublicKey *pub)
{
char *pubkeybuf;
- size_t keylen = (sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)) * 8;
+ size_t keylen = (sizeof (struct GNUNET_CRYPTO_EccPublicKey)) * 8;
char *end;
if (keylen % 5 > 0)
keylen /= 5;
pubkeybuf = GNUNET_malloc (keylen + 1);
end = GNUNET_STRINGS_data_to_string ((unsigned char *) pub,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
pubkeybuf,
keylen);
if (NULL == end)
int
GNUNET_CRYPTO_ecc_public_key_from_string (const char *enc,
size_t enclen,
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pub)
+ struct GNUNET_CRYPTO_EccPublicKey *pub)
{
- size_t keylen = (sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)) * 8;
+ size_t keylen = (sizeof (struct GNUNET_CRYPTO_EccPublicKey)) * 8;
if (keylen % 5 > 0)
keylen += 5 - keylen % 5;
if (GNUNET_OK != GNUNET_STRINGS_string_to_data (enc, enclen,
pub,
- sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)))
- return GNUNET_SYSERR;
- if ( (ntohs (pub->size) != sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)) ||
- (ntohs (pub->len) > GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH) )
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey)))
return GNUNET_SYSERR;
return GNUNET_OK;
}
* Convert the given public key from the network format to the
* S-expression that can be used by libgcrypt.
*
- * @param publicKey public key to decode
+ * @param pub public key to decode
* @return NULL on error
*/
static gcry_sexp_t
-decode_public_key (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *publicKey)
+decode_public_key (const struct GNUNET_CRYPTO_EccPublicKey *pub)
{
- gcry_sexp_t result;
- gcry_mpi_t q;
- size_t size;
- size_t erroff;
+ gcry_sexp_t pub_sexp;
+ gcry_mpi_t q_x;
+ gcry_mpi_t q_y;
+ gcry_mpi_point_t q;
+ gcry_ctx_t ctx;
int rc;
- if (ntohs (publicKey->len) > GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH)
- {
- GNUNET_break (0);
- return NULL;
- }
- size = ntohs (publicKey->len);
- if (0 != (rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG, publicKey->key, size, &size)))
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
- return NULL;
- }
-
- rc = gcry_sexp_build (&result, &erroff,
- "(public-key(ecdsa(curve \"" CURVE "\")(q %m)))",
- q);
- gcry_mpi_release (q);
- if (0 != rc)
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); /* erroff gives more info */
- return NULL;
- }
-#if EXTRA_CHECKS
- if (0 != (rc = gcry_pk_testkey (result)))
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc);
- gcry_sexp_release (result);
- return NULL;
- }
-#endif
- return result;
-}
-
-
-/**
- * Encode the private key in a format suitable for
- * storing it into a file.
- *
- * @param key key to encode
- * @return encoding of the private key.
- * The first 4 bytes give the size of the array, as usual.
- */
-struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *
-GNUNET_CRYPTO_ecc_encode_key (const struct GNUNET_CRYPTO_EccPrivateKey *key)
-{
- struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *retval;
- char buf[65536];
- uint16_t be;
- size_t size;
-
-#if EXTRA_CHECKS
- if (0 != gcry_pk_testkey (key->sexp))
- {
- GNUNET_break (0);
- return NULL;
- }
-#endif
- size = gcry_sexp_sprint (key->sexp,
- GCRYSEXP_FMT_DEFAULT,
- &buf[2], sizeof (buf) - sizeof (uint16_t));
- if (0 == size)
- {
- GNUNET_break (0);
- return NULL;
- }
- GNUNET_assert (size < 65536 - sizeof (uint16_t));
- be = htons ((uint16_t) size + (sizeof (be)));
- memcpy (buf, &be, sizeof (be));
- size += sizeof (be);
- retval = GNUNET_malloc (size);
- memcpy (retval, buf, size);
- return retval;
-}
-
-
-/**
- * Decode the private key from the file-format back
- * to the "normal", internal format.
- *
- * @param buf the buffer where the private key data is stored
- * @param len the length of the data in 'buffer'
- * @param validate GNUNET_YES to validate that the key is well-formed,
- * GNUNET_NO if the key comes from a totally trusted source
- * and validation is considered too expensive
- * @return NULL on error
- */
-struct GNUNET_CRYPTO_EccPrivateKey *
-GNUNET_CRYPTO_ecc_decode_key (const char *buf,
- size_t len,
- int validate)
-{
- struct GNUNET_CRYPTO_EccPrivateKey *ret;
- uint16_t be;
- gcry_sexp_t sexp;
- int rc;
- size_t erroff;
+ mpi_scan (&q_x, pub->q_x, sizeof (pub->q_x));
+ mpi_scan (&q_y, pub->q_y, sizeof (pub->q_y));
+ q = gcry_mpi_point_new (256);
+ gcry_mpi_point_set (q, q_x, q_y, GCRYMPI_CONST_ONE);
+ gcry_mpi_release (q_x);
+ gcry_mpi_release (q_y);
- if (len < sizeof (uint16_t))
- return NULL;
- memcpy (&be, buf, sizeof (be));
- if (len < ntohs (be))
- return NULL;
- len = ntohs (be);
- if (0 != (rc = gcry_sexp_sscan (&sexp,
- &erroff,
- &buf[2],
- len - sizeof (uint16_t))))
+ /* create basic ECC context */
+ if (0 != (rc = gcry_mpi_ec_new (&ctx, NULL, CURVE)))
{
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_scan", rc);
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_ec_new", rc); /* erroff gives more info */
+ gcry_mpi_point_release (q);
return NULL;
}
- if ( (GNUNET_YES == validate) &&
- (0 != (rc = gcry_pk_testkey (sexp))) )
+ /* initialize 'ctx' with 'q' */
+ gcry_mpi_ec_set_point ("q", q, ctx);
+ gcry_mpi_point_release (q);
+
+ /* convert 'ctx' to 'sexp' */
+ if (0 != (rc = gcry_pubkey_get_sexp (&pub_sexp, GCRY_PK_GET_PUBKEY, ctx)))
{
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc);
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_from_context", rc);
+ gcry_ctx_release (ctx);
return NULL;
}
- ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EccPrivateKey));
- ret->sexp = sexp;
- return ret;
+ gcry_ctx_release (ctx);
+ return pub_sexp;
}
struct GNUNET_CRYPTO_EccPrivateKey *
GNUNET_CRYPTO_ecc_key_create ()
{
- struct GNUNET_CRYPTO_EccPrivateKey *ret;
- gcry_sexp_t s_key;
+ struct GNUNET_CRYPTO_EccPrivateKey *priv;
+ gcry_sexp_t priv_sexp;
gcry_sexp_t s_keyparam;
+ gcry_mpi_t d;
int rc;
if (0 != (rc = gcry_sexp_build (&s_keyparam, NULL,
LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
return NULL;
}
- if (0 != (rc = gcry_pk_genkey (&s_key, s_keyparam)))
+ if (0 != (rc = gcry_pk_genkey (&priv_sexp, s_keyparam)))
{
LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_genkey", rc);
gcry_sexp_release (s_keyparam);
}
gcry_sexp_release (s_keyparam);
#if EXTRA_CHECKS
- if (0 != (rc = gcry_pk_testkey (s_key)))
+ if (0 != (rc = gcry_pk_testkey (priv_sexp)))
{
LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc);
- gcry_sexp_release (s_key);
+ gcry_sexp_release (priv_sexp);
return NULL;
}
#endif
- ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EccPrivateKey));
- ret->sexp = s_key;
- return ret;
+ if (0 != (rc = key_from_sexp (&d, priv_sexp, "private-key", "d")))
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "key_from_sexp", rc);
+ gcry_sexp_release (priv_sexp);
+ return NULL;
+ }
+ gcry_sexp_release (priv_sexp);
+ priv = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EccPrivateKey));
+ mpi_print (priv->d, sizeof (priv->d), d);
+ gcry_mpi_release (d);
+ return priv;
}
struct GNUNET_CRYPTO_EccPrivateKey *
GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename)
{
- struct GNUNET_CRYPTO_EccPrivateKey *ret;
- struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
- uint16_t len;
+ struct GNUNET_CRYPTO_EccPrivateKey *priv;
struct GNUNET_DISK_FileHandle *fd;
unsigned int cnt;
int ec;
uint64_t fs;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub;
- struct GNUNET_PeerIdentity pid;
if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename))
return NULL;
while (GNUNET_YES !=
GNUNET_DISK_file_lock (fd, 0,
- sizeof (struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPrivateKey),
GNUNET_YES))
{
short_wait ();
}
LOG (GNUNET_ERROR_TYPE_INFO,
_("Creating a new private key. This may take a while.\n"));
- ret = GNUNET_CRYPTO_ecc_key_create ();
- GNUNET_assert (ret != NULL);
- enc = GNUNET_CRYPTO_ecc_encode_key (ret);
- GNUNET_assert (enc != NULL);
- GNUNET_assert (ntohs (enc->size) ==
- GNUNET_DISK_file_write (fd, enc, ntohs (enc->size)));
- GNUNET_free (enc);
-
+ priv = GNUNET_CRYPTO_ecc_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_EccPrivateKeyBinaryEncoded)))
+ sizeof (struct GNUNET_CRYPTO_EccPrivateKey)))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
- GNUNET_CRYPTO_ecc_key_get_public (ret, &pub);
- GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
- return ret;
+ return priv;
}
/* key file exists already, read it! */
fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
{
if (GNUNET_YES !=
GNUNET_DISK_file_lock (fd, 0,
- sizeof (struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded),
+ sizeof (struct GNUNET_CRYPTO_EccPrivateKey),
GNUNET_NO))
{
if (0 == ++cnt % 60)
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
if (GNUNET_YES !=
GNUNET_DISK_file_unlock (fd, 0,
- sizeof (struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded)))
+ sizeof (struct GNUNET_CRYPTO_EccPrivateKey)))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
}
if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
fs = 0;
- if (fs < sizeof (struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded))
+ if (fs < sizeof (struct GNUNET_CRYPTO_EccPrivateKey))
{
/* 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_EccPrivateKeyBinaryEncoded)))
+ sizeof (struct GNUNET_CRYPTO_EccPrivateKey)))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
if (0 == ++cnt % 10)
{
_
("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_EccPrivateKeyBinaryEncoded));
+ (unsigned int) sizeof (struct GNUNET_CRYPTO_EccPrivateKey));
LOG (GNUNET_ERROR_TYPE_ERROR,
_
("This may be ok if someone is currently generating a key.\n"));
}
break;
}
- enc = GNUNET_malloc (fs);
- GNUNET_assert (fs == GNUNET_DISK_file_read (fd, enc, fs));
- len = ntohs (enc->size);
- ret = NULL;
- if ((len > fs) ||
- (NULL == (ret = GNUNET_CRYPTO_ecc_decode_key ((char *) enc, len, GNUNET_YES))))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("File `%s' does not contain a valid private key. Deleting it.\n"),
- filename);
- if (0 != UNLINK (filename))
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
- }
- }
- GNUNET_free (enc);
+ fs = sizeof (struct GNUNET_CRYPTO_EccPrivateKey);
+ priv = GNUNET_malloc (fs);
+ GNUNET_assert (fs == GNUNET_DISK_file_read (fd, priv, fs));
if (GNUNET_YES !=
GNUNET_DISK_file_unlock (fd, 0,
- sizeof (struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded)))
+ sizeof (struct GNUNET_CRYPTO_EccPrivateKey)))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
- if (ret != NULL)
- {
- GNUNET_CRYPTO_ecc_key_get_public (ret, &pub);
- GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
- }
- return ret;
+ return priv;
}
struct GNUNET_CRYPTO_EccPrivateKey *
GNUNET_CRYPTO_ecc_key_create_from_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- struct GNUNET_CRYPTO_EccPrivateKey *pk;
+ struct GNUNET_CRYPTO_EccPrivateKey *priv;
char *fn;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER", "PRIVATE_KEY", &fn))
return NULL;
- pk = GNUNET_CRYPTO_ecc_key_create_from_file (fn);
+ priv = GNUNET_CRYPTO_ecc_key_create_from_file (fn);
GNUNET_free (fn);
- return pk;
+ return priv;
}
GNUNET_CRYPTO_ecc_setup_key (const char *cfg_name)
{
struct GNUNET_CONFIGURATION_Handle *cfg;
- struct GNUNET_CRYPTO_EccPrivateKey *pk;
+ struct GNUNET_CRYPTO_EccPrivateKey *priv;
cfg = GNUNET_CONFIGURATION_create ();
(void) GNUNET_CONFIGURATION_load (cfg, cfg_name);
- pk = GNUNET_CRYPTO_ecc_key_create_from_configuration (cfg);
- if (NULL != pk)
- GNUNET_CRYPTO_ecc_key_free (pk);
+ priv = GNUNET_CRYPTO_ecc_key_create_from_configuration (cfg);
+ if (NULL != priv)
+ GNUNET_CRYPTO_ecc_key_free (priv);
GNUNET_CONFIGURATION_destroy (cfg);
}
GNUNET_CRYPTO_get_host_identity (const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_PeerIdentity *dst)
{
- struct GNUNET_CRYPTO_EccPrivateKey *my_private_key;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key;
+ struct GNUNET_CRYPTO_EccPrivateKey *priv;
+ struct GNUNET_CRYPTO_EccPublicKey pub;
- if (NULL == (my_private_key = GNUNET_CRYPTO_ecc_key_create_from_configuration (cfg)))
+ if (NULL == (priv = GNUNET_CRYPTO_ecc_key_create_from_configuration (cfg)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Could not load peer's private key\n"));
return GNUNET_SYSERR;
}
- GNUNET_CRYPTO_ecc_key_get_public (my_private_key, &my_public_key);
- GNUNET_CRYPTO_ecc_key_free (my_private_key);
- GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), &dst->hashPubKey);
+ GNUNET_CRYPTO_ecc_key_get_public (priv, &pub);
+ GNUNET_CRYPTO_ecc_key_free (priv);
+ GNUNET_CRYPTO_hash (&pub, sizeof (pub), &dst->hashPubKey);
return GNUNET_OK;
}
data_to_pkcs1 (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose)
{
struct GNUNET_CRYPTO_ShortHashCode hc;
- size_t bufSize;
gcry_sexp_t data;
+ int rc;
GNUNET_CRYPTO_short_hash (purpose, ntohl (purpose->size), &hc);
-#define FORMATSTRING "(4:data(5:flags3:raw)(5:value32:01234567890123456789012345678901))"
- bufSize = strlen (FORMATSTRING) + 1;
+ if (0 != (rc = gcry_sexp_build (&data, NULL,
+ "(data(flags rfc6979)(hash %s %b))",
+ "sha256",
+ sizeof (hc),
+ &hc)))
{
- char buff[bufSize];
-
- memcpy (buff, FORMATSTRING, bufSize);
- memcpy (&buff
- [bufSize -
- strlen
- ("01234567890123456789012345678901))")
- - 1], &hc, sizeof (struct GNUNET_CRYPTO_ShortHashCode));
- GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0));
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
+ return NULL;
}
-#undef FORMATSTRING
return data;
}
/**
* Sign a given block.
*
- * @param key private key to use for the signing
+ * @param priv private key to use for the signing
* @param purpose what to sign (size, purpose)
* @param sig where to write the signature
* @return GNUNET_SYSERR on error, GNUNET_OK on success
*/
int
-GNUNET_CRYPTO_ecc_sign (const struct GNUNET_CRYPTO_EccPrivateKey *key,
+GNUNET_CRYPTO_ecc_sign (const struct GNUNET_CRYPTO_EccPrivateKey *priv,
const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
struct GNUNET_CRYPTO_EccSignature *sig)
{
- gcry_sexp_t result;
+ gcry_sexp_t priv_sexp;
+ gcry_sexp_t sig_sexp;
gcry_sexp_t data;
- size_t ssize;
int rc;
+ gcry_mpi_t rs[2];
+ priv_sexp = decode_private_key (priv);
data = data_to_pkcs1 (purpose);
- if (0 != (rc = gcry_pk_sign (&result, data, key->sexp)))
+ if (0 != (rc = gcry_pk_sign (&sig_sexp, data, priv_sexp)))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
_("ECC signing failed at %s:%d: %s\n"), __FILE__,
__LINE__, gcry_strerror (rc));
gcry_sexp_release (data);
+ gcry_sexp_release (priv_sexp);
return GNUNET_SYSERR;
}
+ gcry_sexp_release (priv_sexp);
gcry_sexp_release (data);
- ssize = gcry_sexp_sprint (result,
- GCRYSEXP_FMT_DEFAULT,
- sig->sexpr,
- GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH);
- if (0 == ssize)
+
+ /* extract 'r' and 's' values from sexpression 'sig_sexp' and store in
+ 'signature' */
+ if (0 != (rc = key_from_sexp (rs, sig_sexp, "sig-val", "rs")))
{
GNUNET_break (0);
+ gcry_sexp_release (sig_sexp);
return GNUNET_SYSERR;
}
- sig->size = htons ((uint16_t) (ssize + sizeof (uint16_t)));
- /* padd with zeros */
- memset (&sig->sexpr[ssize], 0, GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH - ssize);
- gcry_sexp_release (result);
+ gcry_sexp_release (sig_sexp);
+ mpi_print (sig->r, sizeof (sig->r), rs[0]);
+ mpi_print (sig->s, sizeof (sig->s), rs[1]);
+ gcry_mpi_release (rs[0]);
+ gcry_mpi_release (rs[1]);
return GNUNET_OK;
}
* @param purpose what is the purpose that the signature should have?
* @param validate block to validate (size, purpose, data)
* @param sig signature that is being validated
- * @param publicKey public key of the signer
+ * @param pub public key of the signer
* @returns GNUNET_OK if ok, GNUNET_SYSERR if invalid
*/
int
const struct GNUNET_CRYPTO_EccSignaturePurpose
*validate,
const struct GNUNET_CRYPTO_EccSignature *sig,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
- *publicKey)
+ const struct GNUNET_CRYPTO_EccPublicKey *pub)
{
gcry_sexp_t data;
- gcry_sexp_t sigdata;
- size_t size;
- gcry_sexp_t psexp;
+ gcry_sexp_t sig_sexpr;
+ gcry_sexp_t pub_sexpr;
size_t erroff;
int rc;
+ gcry_mpi_t r;
+ gcry_mpi_t s;
if (purpose != ntohl (validate->purpose))
return GNUNET_SYSERR; /* purpose mismatch */
- size = ntohs (sig->size);
- if ( (size < sizeof (uint16_t)) ||
- (size > GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH - sizeof (uint16_t)) )
- return GNUNET_SYSERR; /* size out of range */
+
+ /* build s-expression for signature */
+ mpi_scan (&r, sig->r, sizeof (sig->r));
+ mpi_scan (&s, sig->s, sizeof (sig->s));
+ if (0 != (rc = gcry_sexp_build (&sig_sexpr, &erroff, "(sig-val(ecdsa(r %m)(s %m)))",
+ r, s)))
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
+ gcry_mpi_release (r);
+ gcry_mpi_release (s);
+ return GNUNET_SYSERR;
+ }
+ gcry_mpi_release (r);
+ gcry_mpi_release (s);
data = data_to_pkcs1 (validate);
- GNUNET_assert (0 ==
- gcry_sexp_sscan (&sigdata, &erroff,
- sig->sexpr, size - sizeof (uint16_t)));
- if (! (psexp = decode_public_key (publicKey)))
+ if (! (pub_sexpr = decode_public_key (pub)))
{
gcry_sexp_release (data);
- gcry_sexp_release (sigdata);
+ gcry_sexp_release (sig_sexpr);
return GNUNET_SYSERR;
}
- rc = gcry_pk_verify (sigdata, data, psexp);
- gcry_sexp_release (psexp);
+ rc = gcry_pk_verify (sig_sexpr, data, pub_sexpr);
+ gcry_sexp_release (pub_sexpr);
gcry_sexp_release (data);
- gcry_sexp_release (sigdata);
+ gcry_sexp_release (sig_sexpr);
if (0 != rc)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
/**
* Derive key material from a public and a private ECC key.
*
- * @param key private key to use for the ECDH (x)
- * @param pub public key to use for the ECDY (yG)
+ * @param priv private key to use for the ECDH (x)
+ * @param pub public key to use for the ECDH (yG)
* @param key_material where to write the key material (xyG)
* @return GNUNET_SYSERR on error, GNUNET_OK on success
*/
int
-GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EccPrivateKey *key,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pub,
+GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EccPrivateKey *priv,
+ const struct GNUNET_CRYPTO_EccPublicKey *pub,
struct GNUNET_HashCode *key_material)
{
size_t slen;
gcry_mpi_point_t q;
gcry_mpi_t d;
gcry_ctx_t ctx;
- gcry_sexp_t psexp;
+ gcry_sexp_t pub_sexpr;
+ gcry_sexp_t ecdh_sexp;
gcry_mpi_t result_x;
gcry_mpi_t result_y;
/* first, extract the q = dP value from the public key */
- if (! (psexp = decode_public_key (pub)))
+ if (! (pub_sexpr = decode_public_key (pub)))
return GNUNET_SYSERR;
- if (0 != (rc = gcry_mpi_ec_new (&ctx, psexp, NULL)))
+ if (0 != (rc = gcry_mpi_ec_new (&ctx, pub_sexpr, NULL)))
{
LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_ec_new", rc); /* erroff gives more info */
return GNUNET_SYSERR;
}
- gcry_sexp_release (psexp);
+ gcry_sexp_release (pub_sexpr);
q = gcry_mpi_ec_get_point ("q", ctx, 0);
gcry_ctx_release (ctx);
/* second, extract the d value from our private key */
- rc = key_from_sexp (&d, key->sexp, "private-key", "d");
- if (rc)
- rc = key_from_sexp (&d, key->sexp, "ecc", "d");
- if (0 != rc)
- {
- GNUNET_break (0);
- gcry_mpi_point_release (q);
- return GNUNET_SYSERR;
- }
+ mpi_scan (&d, priv->d, sizeof (priv->d));
/* create a new context for definitively the correct curve;
theoretically the 'public_key' might not use the right curve */
- if (0 != (rc = gcry_mpi_ec_new (&ctx, NULL, "NIST P-256")))
+ if (0 != (rc = gcry_mpi_ec_new (&ctx, NULL, CURVE)))
{
LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_ec_new", rc); /* erroff gives more info */
gcry_mpi_release (d);
}
gcry_mpi_point_release (result);
gcry_ctx_release (ctx);
- if (0 != (rc = gcry_sexp_build (&psexp, &erroff,
+ if (0 != (rc = gcry_sexp_build (&ecdh_sexp, &erroff,
"(dh-shared-secret (x %m)(y %m))",
result_x,
result_y)))
}
gcry_mpi_release (result_x);
gcry_mpi_release (result_y);
- slen = gcry_sexp_sprint (psexp, GCRYSEXP_FMT_DEFAULT, sdata_buf, sizeof (sdata_buf));
+ slen = gcry_sexp_sprint (ecdh_sexp,
+ GCRYSEXP_FMT_DEFAULT,
+ sdata_buf, sizeof (sdata_buf));
GNUNET_assert (0 != slen);
- gcry_sexp_release (psexp);
- /* finally, get a string of the resulting S-expression and hash it to generate the key material */
+ gcry_sexp_release (ecdh_sexp);
+ /* finally, get a string of the resulting S-expression and hash it
+ to generate the key material */
GNUNET_CRYPTO_hash (sdata_buf, slen, key_material);
return GNUNET_OK;
}
+/**
+ * Derive the 'h' value for key derivation, where
+ * 'h = H(l,P)'.
+ *
+ * @param pub public key for deriviation
+ * @param label label for deriviation
+ * @return h value
+ */
+static gcry_mpi_t
+derive_h (const struct GNUNET_CRYPTO_EccPublicKey *pub,
+ const char *label)
+{
+ gcry_mpi_t h;
+ struct GNUNET_HashCode hc;
+
+ GNUNET_CRYPTO_kdf (&hc, sizeof (hc),
+ "key-derivation", strlen ("key-derivation"),
+ pub, sizeof (*pub),
+ label, sizeof (label),
+ NULL, 0);
+ mpi_scan (&h, (unsigned char *) &hc, sizeof (hc));
+ return h;
+}
+
+
+/**
+ * Derive a private key from a given private key and a label.
+ * Essentially calculates a private key 'd = H(l,P) * x mod n'
+ * where n is the size of the ECC group and P is the public
+ * key associated with the private key 'd'.
+ *
+ * @param priv original private key
+ * @param label label to use for key deriviation
+ * @return derived private key
+ */
+struct GNUNET_CRYPTO_EccPrivateKey *
+GNUNET_CRYPTO_ecc_key_derive (const struct GNUNET_CRYPTO_EccPrivateKey *priv,
+ const char *label)
+{
+ struct GNUNET_CRYPTO_EccPublicKey pub;
+ struct GNUNET_CRYPTO_EccPrivateKey *ret;
+ gcry_mpi_t h;
+ gcry_mpi_t x;
+ gcry_mpi_t d;
+ gcry_mpi_t n;
+ int rc;
+
+ GNUNET_CRYPTO_ecc_key_get_public (priv, &pub);
+ h = derive_h (&pub, label);
+ mpi_scan (&x, priv->d, sizeof (priv->d));
+ /* initialize 'n' from P-256; hex copied from libgcrypt code */
+ if (0 != (rc = gcry_mpi_scan (&n, GCRYMPI_FMT_HEX,
+ "0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551", 0, NULL)))
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+ gcry_mpi_release (h);
+ return NULL;
+ }
+ d = gcry_mpi_new (256);
+ gcry_mpi_mulm (d, h, x, n);
+ gcry_mpi_release (h);
+ gcry_mpi_release (x);
+ gcry_mpi_release (n);
+ ret = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
+ mpi_print (ret->d, sizeof (ret->d), d);
+ gcry_mpi_release (d);
+ return ret;
+}
+
+
+/**
+ * Derive a public key from a given public key and a label.
+ * Essentially calculates a public key 'V = H(l,P) * P'.
+ *
+ * @param pub original public key
+ * @param label label to use for key deriviation
+ * @param result where to write the derived public key
+ */
+void
+GNUNET_CRYPTO_ecc_public_key_derive (const struct GNUNET_CRYPTO_EccPublicKey *pub,
+ const char *label,
+ struct GNUNET_CRYPTO_EccPublicKey *result)
+{
+ gcry_mpi_t h;
+ gcry_ctx_t ctx;
+ gcry_mpi_t q_x;
+ gcry_mpi_t q_y;
+ gcry_mpi_point_t q;
+ gcry_mpi_point_t v;
+ int rc;
+
+ h = derive_h (pub, label);
+ mpi_scan (&q_x, pub->q_x, sizeof (pub->q_x));
+ mpi_scan (&q_y, pub->q_y, sizeof (pub->q_y));
+ q = gcry_mpi_point_new (256);
+ gcry_mpi_point_set (q, q_x, q_y, GCRYMPI_CONST_ONE);
+ gcry_mpi_release (q_x);
+ gcry_mpi_release (q_y);
+
+ /* create basic ECC context */
+ if (0 != (rc = gcry_mpi_ec_new (&ctx, NULL, CURVE)))
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_ec_new", rc);
+ gcry_mpi_point_release (q);
+ gcry_mpi_release (h);
+ return;
+ }
+ v = gcry_mpi_point_new (256);
+ /* we could calculate 'h mod n' here first, but hopefully
+ libgcrypt is smart enough to do that for us... */
+ gcry_mpi_ec_mul (v, h, q, ctx);
+ gcry_mpi_release (h);
+ gcry_mpi_point_release (q);
+ point_to_public_key (v, ctx, result);
+ gcry_mpi_point_release (v);
+ gcry_ctx_release (ctx);
+}
+
+
/* end of crypto_ecc.c */
/*
This file is part of GNUnet.
- (C) 2012 Christian Grothoff (and other contributing authors)
+ (C) 2012, 2013 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
*/
static unsigned int make_keys;
-/**
- * The private information of an ECC key pair.
- * NOTE: this must match the definition in crypto_ksk.c and crypto_ecc.c!
- */
-struct GNUNET_CRYPTO_EccPrivateKey
-{
- gcry_sexp_t sexp;
-};
-
/**
* Create a flat file with a large number of key pairs for testing.
static void
create_keys (const char *fn)
{
- static char pad[GNUNET_TESTING_HOSTKEYFILESIZE];
FILE *f;
struct GNUNET_CRYPTO_EccPrivateKey *pk;
- struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
if (NULL == (f = fopen (fn, "w+")))
{
GNUNET_break (0);
break;
}
- enc = GNUNET_CRYPTO_ecc_encode_key (pk);
- GNUNET_assert (ntohs (enc->size) <= GNUNET_TESTING_HOSTKEYFILESIZE);
- if ( (ntohs (enc->size) != fwrite (enc, 1, ntohs (enc->size), f)) ||
- (GNUNET_TESTING_HOSTKEYFILESIZE - ntohs (enc->size)
- != fwrite (pad, 1, GNUNET_TESTING_HOSTKEYFILESIZE - ntohs (enc->size), f)) )
+ if (GNUNET_TESTING_HOSTKEYFILESIZE !=
+ fwrite (pk, 1,
+ GNUNET_TESTING_HOSTKEYFILESIZE, f))
{
fprintf (stderr,
_("\nFailed to write to `%s': %s\n"),
fn,
STRERROR (errno));
GNUNET_CRYPTO_ecc_key_free (pk);
- GNUNET_free (enc);
break;
}
GNUNET_CRYPTO_ecc_key_free (pk);
- GNUNET_free (enc);
}
if (UINT_MAX == make_keys)
fprintf (stderr,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_CRYPTO_EccPrivateKey *pk;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub;
+ struct GNUNET_CRYPTO_EccPublicKey pub;
struct GNUNET_PeerIdentity pid;
if (NULL == args[0])
/*
This file is part of GNUnet.
- (C) 2002, 2003, 2004, 2006, 2009 Christian Grothoff (and other contributing authors)
+ (C) 2002-2013 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
{
struct GNUNET_CRYPTO_EccSignature sig;
struct GNUNET_CRYPTO_EccSignaturePurpose purp;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
+ struct GNUNET_CRYPTO_EccPublicKey pkey;
int i;
struct GNUNET_TIME_Absolute start;
int ok = GNUNET_OK;
{
struct GNUNET_CRYPTO_EccSignaturePurpose purp;
struct GNUNET_CRYPTO_EccSignature sig;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
+ struct GNUNET_CRYPTO_EccPublicKey pkey;
int i;
struct GNUNET_TIME_Absolute start;
int ok = GNUNET_OK;
static int
testCreateFromFile ()
{
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded p1;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded p2;
+ struct GNUNET_CRYPTO_EccPublicKey p1;
+ struct GNUNET_CRYPTO_EccPublicKey p2;
key = GNUNET_CRYPTO_ecc_key_create_from_file (KEYFILE);
GNUNET_assert (NULL != key);
{
struct GNUNET_CRYPTO_EccPrivateKey *priv1;
struct GNUNET_CRYPTO_EccPrivateKey *priv2;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub1;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub2;
+ struct GNUNET_CRYPTO_EccPublicKey pub1;
+ struct GNUNET_CRYPTO_EccPublicKey pub2;
struct GNUNET_HashCode ecdh1;
struct GNUNET_HashCode ecdh2;