aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-06 14:18:31 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-06 14:18:31 +0000
commitfe76c075e315c0351e2fe465434ae39087daf014 (patch)
tree436887ccaf331932a3c13a8b9d2a2a710dad4be6 /src/testing
parent7eb2835d8a494c83aedb720a2ac6f6e5ba23f22f (diff)
downloadgnunet-fe76c075e315c0351e2fe465434ae39087daf014.tar.gz
gnunet-fe76c075e315c0351e2fe465434ae39087daf014.zip
moving to new, fixed-size encoding of public and private ECC keys everywhere, also improving ECC API to better support ECRS/GADS operations
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/gnunet-testing.c15
-rw-r--r--src/testing/testing.c14
2 files changed, 9 insertions, 20 deletions
diff --git a/src/testing/gnunet-testing.c b/src/testing/gnunet-testing.c
index 574b585fc..45ca4978c 100644
--- a/src/testing/gnunet-testing.c
+++ b/src/testing/gnunet-testing.c
@@ -118,13 +118,10 @@ create_unique_cfgs (const char * template, const unsigned int no)
118static int 118static int
119create_hostkeys (const unsigned int no) 119create_hostkeys (const unsigned int no)
120{ 120{
121 static char pad[GNUNET_TESTING_HOSTKEYFILESIZE];
122 struct GNUNET_TESTING_System *system; 121 struct GNUNET_TESTING_System *system;
123 struct GNUNET_PeerIdentity id; 122 struct GNUNET_PeerIdentity id;
124 struct GNUNET_DISK_FileHandle *fd; 123 struct GNUNET_DISK_FileHandle *fd;
125 struct GNUNET_CRYPTO_EccPrivateKey *pk; 124 struct GNUNET_CRYPTO_EccPrivateKey *pk;
126 struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *pkb;
127 ssize_t ret;
128 125
129 system = GNUNET_TESTING_system_create ("testing", NULL, NULL, NULL); 126 system = GNUNET_TESTING_system_create ("testing", NULL, NULL, NULL);
130 pk = GNUNET_TESTING_hostkey_get (system, create_no, &id); 127 pk = GNUNET_TESTING_hostkey_get (system, create_no, &id);
@@ -141,19 +138,11 @@ create_hostkeys (const unsigned int no)
141 GNUNET_DISK_PERM_USER_READ | 138 GNUNET_DISK_PERM_USER_READ |
142 GNUNET_DISK_PERM_USER_WRITE); 139 GNUNET_DISK_PERM_USER_WRITE);
143 GNUNET_assert (fd != NULL); 140 GNUNET_assert (fd != NULL);
144 pkb = GNUNET_CRYPTO_ecc_encode_key (pk); 141 ret = GNUNET_DISK_file_write (fd, pk,
145 ret = GNUNET_DISK_file_write (fd, pkb, 142 sizeof (struct GNUNET_CRYPTO_EccPrivateKey));
146 ntohs (pkb->size));
147 GNUNET_assert (ntohs (pkb->size) == ret);
148 GNUNET_assert (ntohs (pkb->size) < GNUNET_TESTING_HOSTKEYFILESIZE);
149 GNUNET_assert (GNUNET_TESTING_HOSTKEYFILESIZE - ret ==
150 GNUNET_DISK_file_write (fd, pad,
151 GNUNET_TESTING_HOSTKEYFILESIZE - ret));
152
153 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); 143 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
154 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", 144 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
155 "Wrote hostkey to file: `%s'\n", create_hostkey); 145 "Wrote hostkey to file: `%s'\n", create_hostkey);
156 GNUNET_free (pkb);
157 GNUNET_CRYPTO_ecc_key_free (pk); 146 GNUNET_CRYPTO_ecc_key_free (pk);
158 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 147 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
159 return 0; 148 return 0;
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 898af1674..73b2a4ee1 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -712,7 +712,7 @@ GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system,
712 struct GNUNET_PeerIdentity *id) 712 struct GNUNET_PeerIdentity *id)
713{ 713{
714 struct GNUNET_CRYPTO_EccPrivateKey *private_key; 714 struct GNUNET_CRYPTO_EccPrivateKey *private_key;
715 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded public_key; 715 struct GNUNET_CRYPTO_EccPublicKey public_key;
716 716
717 if ((NULL == id) || (NULL == system->hostkeys_data)) 717 if ((NULL == id) || (NULL == system->hostkeys_data))
718 return NULL; 718 return NULL;
@@ -722,11 +722,11 @@ GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system,
722 _("Key number %u does not exist\n"), key_number); 722 _("Key number %u does not exist\n"), key_number);
723 return NULL; 723 return NULL;
724 } 724 }
725 private_key = GNUNET_CRYPTO_ecc_decode_key (system->hostkeys_data + 725 private_key = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
726 (key_number * 726 memcpy (private_key,
727 GNUNET_TESTING_HOSTKEYFILESIZE), 727 system->hostkeys_data +
728 GNUNET_TESTING_HOSTKEYFILESIZE, 728 (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
729 GNUNET_NO); 729 GNUNET_TESTING_HOSTKEYFILESIZE);
730 if (NULL == private_key) 730 if (NULL == private_key)
731 { 731 {
732 LOG (GNUNET_ERROR_TYPE_ERROR, 732 LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -735,7 +735,7 @@ GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system,
735 } 735 }
736 GNUNET_CRYPTO_ecc_key_get_public (private_key, &public_key); 736 GNUNET_CRYPTO_ecc_key_get_public (private_key, &public_key);
737 GNUNET_CRYPTO_hash (&public_key, 737 GNUNET_CRYPTO_hash (&public_key,
738 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), 738 sizeof (struct GNUNET_CRYPTO_EccPublicKey),
739 &(id->hashPubKey)); 739 &(id->hashPubKey));
740 return private_key; 740 return private_key;
741} 741}