[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r30793 - gnunet/src/util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r30793 - gnunet/src/util |
Date: |
Tue, 19 Nov 2013 11:52:12 +0100 |
Author: dold
Date: 2013-11-19 11:52:12 +0100 (Tue, 19 Nov 2013)
New Revision: 30793
Modified:
gnunet/src/util/gnunet-ecc.c
Log:
- Added the '-E' option to gnunet-ecc, which prints reference results of
ecc operations
Modified: gnunet/src/util/gnunet-ecc.c
===================================================================
--- gnunet/src/util/gnunet-ecc.c 2013-11-18 20:58:26 UTC (rev 30792)
+++ gnunet/src/util/gnunet-ecc.c 2013-11-19 10:52:12 UTC (rev 30793)
@@ -45,6 +45,11 @@
static int print_public_key;
/**
+ * Flag for printing the output of random example operations.
+ */
+static int print_examples_flag;
+
+/**
* Flag for printing hash of public key.
*/
static int print_peer_identity;
@@ -108,6 +113,58 @@
static void
+print_examples_ecdh (void)
+{
+ struct GNUNET_CRYPTO_EcdhePrivateKey *dh_priv1;
+ struct GNUNET_CRYPTO_EcdhePublicKey *dh_pub1;
+ struct GNUNET_CRYPTO_EcdhePrivateKey *dh_priv2;
+ struct GNUNET_CRYPTO_EcdhePublicKey *dh_pub2;
+ struct GNUNET_HashCode hash;
+ char buf[128];
+
+ dh_pub1 = GNUNET_new (struct GNUNET_CRYPTO_EcdhePublicKey);
+ dh_priv1 = GNUNET_CRYPTO_ecdhe_key_create ();
+ dh_pub2 = GNUNET_new (struct GNUNET_CRYPTO_EcdhePublicKey);
+ dh_priv2 = GNUNET_CRYPTO_ecdhe_key_create ();
+ GNUNET_CRYPTO_ecdhe_key_get_public (dh_priv1, dh_pub1);
+ GNUNET_CRYPTO_ecdhe_key_get_public (dh_priv2, dh_pub2);
+
+ GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_priv1, 32, buf,
128));
+ printf ("ECDHE key 1:\n");
+ printf ("private: %s\n", buf);
+ GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_pub1, 32, buf,
128));
+ printf ("public: %s\n", buf);
+
+ GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_priv2, 32, buf,
128));
+ printf ("ECDHE key 2:\n");
+ printf ("private: %s\n", buf);
+ GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_pub2, 32, buf,
128));
+ printf ("public: %s\n", buf);
+
+ GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecc_ecdh (dh_priv1, dh_pub2,
&hash));
+ GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (&hash, 64, buf, 128));
+ printf ("ECDH shared secret: %s\n", buf);
+
+ GNUNET_free (dh_priv1);
+ GNUNET_free (dh_priv2);
+ GNUNET_free (dh_pub1);
+ GNUNET_free (dh_pub2);
+}
+
+
+/**
+ * Print some random example operations to stdout.
+ */
+static void
+print_examples (void)
+{
+ print_examples_ecdh ();
+ // print_examples_ecdsa ();
+ // print_examples_eddsa ();
+}
+
+
+static void
print_key (const char *filename)
{
struct GNUNET_DISK_FileHandle *fd;
@@ -193,6 +250,11 @@
struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
struct GNUNET_CRYPTO_EddsaPublicKey pub;
+ if (print_examples_flag)
+ {
+ print_examples ();
+ return;
+ }
if (NULL == args[0])
{
FPRINTF (stderr,
@@ -202,7 +264,7 @@
}
if (list_keys)
{
- print_key(args[0]);
+ print_key (args[0]);
return;
}
if (make_keys > 0)
@@ -266,6 +328,9 @@
{ 'P', "print-peer-identity", NULL,
gettext_noop ("print the hash of the public key in ASCII format"),
0, &GNUNET_GETOPT_set_one, &print_peer_identity },
+ { 'E', "examples", NULL,
+ gettext_noop ("print examples of ECC operations (used for compatibility
testing)"),
+ 0, &GNUNET_GETOPT_set_one, &print_examples_flag },
GNUNET_GETOPT_OPTION_END
};
int ret;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r30793 - gnunet/src/util,
gnunet <=