aboutsummaryrefslogtreecommitdiff
path: root/src/util/gnunet-ecc.c
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2013-11-19 10:52:12 +0000
committerFlorian Dold <florian.dold@gmail.com>2013-11-19 10:52:12 +0000
commit8dda13088674ec864e3133e8a5770e01704e8409 (patch)
treea585bd7caa0f1ca77e5f95d6bb93a46f8c5b5302 /src/util/gnunet-ecc.c
parent52a8cdf68084f35bde47132849cf0243eca35c35 (diff)
downloadgnunet-8dda13088674ec864e3133e8a5770e01704e8409.tar.gz
gnunet-8dda13088674ec864e3133e8a5770e01704e8409.zip
- Added the '-E' option to gnunet-ecc, which prints reference results of
ecc operations
Diffstat (limited to 'src/util/gnunet-ecc.c')
-rw-r--r--src/util/gnunet-ecc.c67
1 files changed, 66 insertions, 1 deletions
diff --git a/src/util/gnunet-ecc.c b/src/util/gnunet-ecc.c
index f2d2756fb..092dc7b38 100644
--- a/src/util/gnunet-ecc.c
+++ b/src/util/gnunet-ecc.c
@@ -45,6 +45,11 @@ static int list_keys_count;
45static int print_public_key; 45static int print_public_key;
46 46
47/** 47/**
48 * Flag for printing the output of random example operations.
49 */
50static int print_examples_flag;
51
52/**
48 * Flag for printing hash of public key. 53 * Flag for printing hash of public key.
49 */ 54 */
50static int print_peer_identity; 55static int print_peer_identity;
@@ -108,6 +113,58 @@ create_keys (const char *fn)
108 113
109 114
110static void 115static void
116print_examples_ecdh (void)
117{
118 struct GNUNET_CRYPTO_EcdhePrivateKey *dh_priv1;
119 struct GNUNET_CRYPTO_EcdhePublicKey *dh_pub1;
120 struct GNUNET_CRYPTO_EcdhePrivateKey *dh_priv2;
121 struct GNUNET_CRYPTO_EcdhePublicKey *dh_pub2;
122 struct GNUNET_HashCode hash;
123 char buf[128];
124
125 dh_pub1 = GNUNET_new (struct GNUNET_CRYPTO_EcdhePublicKey);
126 dh_priv1 = GNUNET_CRYPTO_ecdhe_key_create ();
127 dh_pub2 = GNUNET_new (struct GNUNET_CRYPTO_EcdhePublicKey);
128 dh_priv2 = GNUNET_CRYPTO_ecdhe_key_create ();
129 GNUNET_CRYPTO_ecdhe_key_get_public (dh_priv1, dh_pub1);
130 GNUNET_CRYPTO_ecdhe_key_get_public (dh_priv2, dh_pub2);
131
132 GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_priv1, 32, buf, 128));
133 printf ("ECDHE key 1:\n");
134 printf ("private: %s\n", buf);
135 GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_pub1, 32, buf, 128));
136 printf ("public: %s\n", buf);
137
138 GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_priv2, 32, buf, 128));
139 printf ("ECDHE key 2:\n");
140 printf ("private: %s\n", buf);
141 GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_pub2, 32, buf, 128));
142 printf ("public: %s\n", buf);
143
144 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecc_ecdh (dh_priv1, dh_pub2, &hash));
145 GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (&hash, 64, buf, 128));
146 printf ("ECDH shared secret: %s\n", buf);
147
148 GNUNET_free (dh_priv1);
149 GNUNET_free (dh_priv2);
150 GNUNET_free (dh_pub1);
151 GNUNET_free (dh_pub2);
152}
153
154
155/**
156 * Print some random example operations to stdout.
157 */
158static void
159print_examples (void)
160{
161 print_examples_ecdh ();
162 // print_examples_ecdsa ();
163 // print_examples_eddsa ();
164}
165
166
167static void
111print_key (const char *filename) 168print_key (const char *filename)
112{ 169{
113 struct GNUNET_DISK_FileHandle *fd; 170 struct GNUNET_DISK_FileHandle *fd;
@@ -193,6 +250,11 @@ run (void *cls, char *const *args, const char *cfgfile,
193 struct GNUNET_CRYPTO_EddsaPrivateKey *pk; 250 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
194 struct GNUNET_CRYPTO_EddsaPublicKey pub; 251 struct GNUNET_CRYPTO_EddsaPublicKey pub;
195 252
253 if (print_examples_flag)
254 {
255 print_examples ();
256 return;
257 }
196 if (NULL == args[0]) 258 if (NULL == args[0])
197 { 259 {
198 FPRINTF (stderr, 260 FPRINTF (stderr,
@@ -202,7 +264,7 @@ run (void *cls, char *const *args, const char *cfgfile,
202 } 264 }
203 if (list_keys) 265 if (list_keys)
204 { 266 {
205 print_key(args[0]); 267 print_key (args[0]);
206 return; 268 return;
207 } 269 }
208 if (make_keys > 0) 270 if (make_keys > 0)
@@ -266,6 +328,9 @@ main (int argc, char *const *argv)
266 { 'P', "print-peer-identity", NULL, 328 { 'P', "print-peer-identity", NULL,
267 gettext_noop ("print the hash of the public key in ASCII format"), 329 gettext_noop ("print the hash of the public key in ASCII format"),
268 0, &GNUNET_GETOPT_set_one, &print_peer_identity }, 330 0, &GNUNET_GETOPT_set_one, &print_peer_identity },
331 { 'E', "examples", NULL,
332 gettext_noop ("print examples of ECC operations (used for compatibility testing)"),
333 0, &GNUNET_GETOPT_set_one, &print_examples_flag },
269 GNUNET_GETOPT_OPTION_END 334 GNUNET_GETOPT_OPTION_END
270 }; 335 };
271 int ret; 336 int ret;