From e689ee017aa0a144439d7eb067b0308e8eff526a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 10 Sep 2013 13:04:46 +0000 Subject: [PATCH] change .zkey encoding in anticipation of compact point encodings --- src/include/gnunet_namestore_service.h | 8 +++--- src/namestore/namestore_api_common.c | 40 ++++++++------------------ 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index 8982df2bc..ef7d516af 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h @@ -613,8 +613,8 @@ GNUNET_NAMESTORE_z2s (const struct GNUNET_CRYPTO_EccPublicKey *z); * This is one of the very few calls in the entire API that is * NOT reentrant! * - * @param pkey a public key with (x,y) on the eliptic curve - * @return string "Y.X.zkey" where X and Y are the coordinates of the public + * @param pkey a public key with a point on the eliptic curve + * @return string "X.zkey" where X is the coordinates of the public * key in an encoding suitable for DNS labels. */ const char * @@ -625,9 +625,9 @@ GNUNET_NAMESTORE_pkey_to_zkey (const struct GNUNET_CRYPTO_EccPublicKey *pkey); * Convert an absolute domain name in the ".zkey" pTLD to the * respective public key. * - * @param zkey string "Y.X.zkey" where X and Y are the coordinates of the public + * @param zkey string "X.zkey" where X is the public * key in an encoding suitable for DNS labels. - * @param pkey set to a public key with (x,y) on the eliptic curve + * @param pkey set to a public key on the eliptic curve * @return #GNUNET_SYSERR if @a zkey has the wrong syntax */ int diff --git a/src/namestore/namestore_api_common.c b/src/namestore/namestore_api_common.c index 9f964e320..c55902b3d 100644 --- a/src/namestore/namestore_api_common.c +++ b/src/namestore/namestore_api_common.c @@ -960,24 +960,20 @@ GNUNET_NAMESTORE_query_from_public_key (const struct GNUNET_CRYPTO_EccPublicKey * This is one of the very few calls in the entire API that is * NOT reentrant! * - * @param pkey a public key with (x,y) on the eliptic curve - * @return string "Y.X.zkey" where X and Y are the coordinates of the public + * @param pkey a public key with a point on the eliptic curve + * @return string "X.zkey" where X is the public * key in an encoding suitable for DNS labels. */ const char * GNUNET_NAMESTORE_pkey_to_zkey (const struct GNUNET_CRYPTO_EccPublicKey *pkey) { - static char ret[256]; + static char ret[128]; char *pkeys; - size_t slen; pkeys = GNUNET_CRYPTO_ecc_public_key_to_string (pkey); - slen = strlen (pkeys); GNUNET_snprintf (ret, sizeof (ret), - "%s.%.*s.zkey", - &pkeys[slen / 2], - (int) (slen / 2), + "%s.zkey", pkeys); GNUNET_free (pkeys); return ret; @@ -988,9 +984,9 @@ GNUNET_NAMESTORE_pkey_to_zkey (const struct GNUNET_CRYPTO_EccPublicKey *pkey) * Convert an absolute domain name in the ".zkey" pTLD to the * respective public key. * - * @param zkey string "Y.X.zkey" where X and Y are the coordinates of the public + * @param zkey string "X.zkey" where X is the coordinates of the public * key in an encoding suitable for DNS labels. - * @param pkey set to a public key with (x,y) on the eliptic curve + * @param pkey set to a public key on the eliptic curve * @return #GNUNET_SYSERR if @a zkey has the wrong syntax */ int @@ -1000,34 +996,22 @@ GNUNET_NAMESTORE_zkey_to_pkey (const char *zkey, char *cpy; char *dot; const char *x; - const char *y; - char *pkeys; cpy = GNUNET_strdup (zkey); - y = cpy; - if (NULL == (dot = strchr (y, (int) '.'))) - goto error; - *dot = '\0'; - x = dot + 1; + x = cpy; if (NULL == (dot = strchr (x, (int) '.'))) goto error; *dot = '\0'; if (0 != strcasecmp (dot + 1, "zkey")) goto error; - GNUNET_asprintf (&pkeys, - "%s%s", - x, y); - GNUNET_free (cpy); + if (GNUNET_OK != - GNUNET_CRYPTO_ecc_public_key_from_string (pkeys, - strlen (pkeys), + GNUNET_CRYPTO_ecc_public_key_from_string (x, + strlen (x), pkey)) - { - GNUNET_free (pkeys); - return GNUNET_SYSERR; - } - GNUNET_free (pkeys); + goto error; + GNUNET_free (cpy); return GNUNET_OK; error: GNUNET_free (cpy); -- 2.25.1