aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-09-10 13:04:46 +0000
committerChristian Grothoff <christian@grothoff.org>2013-09-10 13:04:46 +0000
commite689ee017aa0a144439d7eb067b0308e8eff526a (patch)
tree6ce686b62dc34dd8bb01883274ad19bbcc427ca9 /src
parentab956c7af36d37f41c676da4c90e20a6df639bc8 (diff)
downloadgnunet-e689ee017aa0a144439d7eb067b0308e8eff526a.tar.gz
gnunet-e689ee017aa0a144439d7eb067b0308e8eff526a.zip
change .zkey encoding in anticipation of compact point encodings
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_namestore_service.h8
-rw-r--r--src/namestore/namestore_api_common.c40
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);
613 * This is one of the very few calls in the entire API that is 613 * This is one of the very few calls in the entire API that is
614 * NOT reentrant! 614 * NOT reentrant!
615 * 615 *
616 * @param pkey a public key with (x,y) on the eliptic curve 616 * @param pkey a public key with a point on the eliptic curve
617 * @return string "Y.X.zkey" where X and Y are the coordinates of the public 617 * @return string "X.zkey" where X is the coordinates of the public
618 * key in an encoding suitable for DNS labels. 618 * key in an encoding suitable for DNS labels.
619 */ 619 */
620const char * 620const char *
@@ -625,9 +625,9 @@ GNUNET_NAMESTORE_pkey_to_zkey (const struct GNUNET_CRYPTO_EccPublicKey *pkey);
625 * Convert an absolute domain name in the ".zkey" pTLD to the 625 * Convert an absolute domain name in the ".zkey" pTLD to the
626 * respective public key. 626 * respective public key.
627 * 627 *
628 * @param zkey string "Y.X.zkey" where X and Y are the coordinates of the public 628 * @param zkey string "X.zkey" where X is the public
629 * key in an encoding suitable for DNS labels. 629 * key in an encoding suitable for DNS labels.
630 * @param pkey set to a public key with (x,y) on the eliptic curve 630 * @param pkey set to a public key on the eliptic curve
631 * @return #GNUNET_SYSERR if @a zkey has the wrong syntax 631 * @return #GNUNET_SYSERR if @a zkey has the wrong syntax
632 */ 632 */
633int 633int
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
960 * This is one of the very few calls in the entire API that is 960 * This is one of the very few calls in the entire API that is
961 * NOT reentrant! 961 * NOT reentrant!
962 * 962 *
963 * @param pkey a public key with (x,y) on the eliptic curve 963 * @param pkey a public key with a point on the eliptic curve
964 * @return string "Y.X.zkey" where X and Y are the coordinates of the public 964 * @return string "X.zkey" where X is the public
965 * key in an encoding suitable for DNS labels. 965 * key in an encoding suitable for DNS labels.
966 */ 966 */
967const char * 967const char *
968GNUNET_NAMESTORE_pkey_to_zkey (const struct GNUNET_CRYPTO_EccPublicKey *pkey) 968GNUNET_NAMESTORE_pkey_to_zkey (const struct GNUNET_CRYPTO_EccPublicKey *pkey)
969{ 969{
970 static char ret[256]; 970 static char ret[128];
971 char *pkeys; 971 char *pkeys;
972 size_t slen;
973 972
974 pkeys = GNUNET_CRYPTO_ecc_public_key_to_string (pkey); 973 pkeys = GNUNET_CRYPTO_ecc_public_key_to_string (pkey);
975 slen = strlen (pkeys);
976 GNUNET_snprintf (ret, 974 GNUNET_snprintf (ret,
977 sizeof (ret), 975 sizeof (ret),
978 "%s.%.*s.zkey", 976 "%s.zkey",
979 &pkeys[slen / 2],
980 (int) (slen / 2),
981 pkeys); 977 pkeys);
982 GNUNET_free (pkeys); 978 GNUNET_free (pkeys);
983 return ret; 979 return ret;
@@ -988,9 +984,9 @@ GNUNET_NAMESTORE_pkey_to_zkey (const struct GNUNET_CRYPTO_EccPublicKey *pkey)
988 * Convert an absolute domain name in the ".zkey" pTLD to the 984 * Convert an absolute domain name in the ".zkey" pTLD to the
989 * respective public key. 985 * respective public key.
990 * 986 *
991 * @param zkey string "Y.X.zkey" where X and Y are the coordinates of the public 987 * @param zkey string "X.zkey" where X is the coordinates of the public
992 * key in an encoding suitable for DNS labels. 988 * key in an encoding suitable for DNS labels.
993 * @param pkey set to a public key with (x,y) on the eliptic curve 989 * @param pkey set to a public key on the eliptic curve
994 * @return #GNUNET_SYSERR if @a zkey has the wrong syntax 990 * @return #GNUNET_SYSERR if @a zkey has the wrong syntax
995 */ 991 */
996int 992int
@@ -1000,34 +996,22 @@ GNUNET_NAMESTORE_zkey_to_pkey (const char *zkey,
1000 char *cpy; 996 char *cpy;
1001 char *dot; 997 char *dot;
1002 const char *x; 998 const char *x;
1003 const char *y;
1004 char *pkeys;
1005 999
1006 cpy = GNUNET_strdup (zkey); 1000 cpy = GNUNET_strdup (zkey);
1007 y = cpy; 1001 x = cpy;
1008 if (NULL == (dot = strchr (y, (int) '.')))
1009 goto error;
1010 *dot = '\0';
1011 x = dot + 1;
1012 if (NULL == (dot = strchr (x, (int) '.'))) 1002 if (NULL == (dot = strchr (x, (int) '.')))
1013 goto error; 1003 goto error;
1014 *dot = '\0'; 1004 *dot = '\0';
1015 if (0 != strcasecmp (dot + 1, 1005 if (0 != strcasecmp (dot + 1,
1016 "zkey")) 1006 "zkey"))
1017 goto error; 1007 goto error;
1018 GNUNET_asprintf (&pkeys, 1008
1019 "%s%s",
1020 x, y);
1021 GNUNET_free (cpy);
1022 if (GNUNET_OK != 1009 if (GNUNET_OK !=
1023 GNUNET_CRYPTO_ecc_public_key_from_string (pkeys, 1010 GNUNET_CRYPTO_ecc_public_key_from_string (x,
1024 strlen (pkeys), 1011 strlen (x),
1025 pkey)) 1012 pkey))
1026 { 1013 goto error;
1027 GNUNET_free (pkeys); 1014 GNUNET_free (cpy);
1028 return GNUNET_SYSERR;
1029 }
1030 GNUNET_free (pkeys);
1031 return GNUNET_OK; 1015 return GNUNET_OK;
1032 error: 1016 error:
1033 GNUNET_free (cpy); 1017 GNUNET_free (cpy);