gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r27635 - in gnunet/src: include util


From: gnunet
Subject: [GNUnet-SVN] r27635 - in gnunet/src: include util
Date: Wed, 26 Jun 2013 19:17:35 +0200

Author: grothoff
Date: 2013-06-26 19:17:35 +0200 (Wed, 26 Jun 2013)
New Revision: 27635

Modified:
   gnunet/src/include/gnunet_crypto_lib.h
   gnunet/src/util/crypto_ecc.c
Log:
-introducing convenience function to load private key of peer

Modified: gnunet/src/include/gnunet_crypto_lib.h
===================================================================
--- gnunet/src/include/gnunet_crypto_lib.h      2013-06-26 17:13:01 UTC (rev 
27634)
+++ gnunet/src/include/gnunet_crypto_lib.h      2013-06-26 17:17:35 UTC (rev 
27635)
@@ -267,7 +267,7 @@
   /**
    * Overall size of the signature data.
    */
-  uint16_t size;
+  uint16_t size GNUNET_PACKED;
 
   /**
    * S-expression, padded with zeros.
@@ -285,12 +285,12 @@
   /**
    * Size of the encoding, in network byte order.
    */
-  uint16_t size;
+  uint16_t size GNUNET_PACKED;
 
   /**
    * Actual length of the q-point binary encoding.
    */
-  uint16_t len;
+  uint16_t len GNUNET_PACKED;
 
   /**
    * 0-padded q-point in binary encoding (GCRYPT_MPI_FMT_USG).
@@ -1277,6 +1277,17 @@
 
 
 /**
+ * Create a new private key by reading our peer's key from
+ * the file specified in the configuration.
+ *
+ * @return new private key, NULL on error (for example,
+ *   permission denied)
+ */
+struct GNUNET_CRYPTO_EccPrivateKey *
+GNUNET_CRYPTO_ecc_key_create_from_configuration (const struct 
GNUNET_CONFIGURATION_Handle *cfg);
+
+
+/**
  * Handle to cancel private key generation and state for the
  * key generation operation.
  */

Modified: gnunet/src/util/crypto_ecc.c
===================================================================
--- gnunet/src/util/crypto_ecc.c        2013-06-26 17:13:01 UTC (rev 27634)
+++ gnunet/src/util/crypto_ecc.c        2013-06-26 17:17:35 UTC (rev 27635)
@@ -890,6 +890,28 @@
 
 
 /**
+ * Create a new private key by reading our peer's key from
+ * the file specified in the configuration.
+ *
+ * @return new private key, NULL on error (for example,
+ *   permission denied)
+ */
+struct GNUNET_CRYPTO_EccPrivateKey *
+GNUNET_CRYPTO_ecc_key_create_from_configuration (const struct 
GNUNET_CONFIGURATION_Handle *cfg)
+{
+  struct GNUNET_CRYPTO_EccPrivateKey *pk;
+  char *fn;
+
+  if (GNUNET_OK != 
+      GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER", "PRIVATE_KEY", 
&fn))
+    return NULL;
+  pk = GNUNET_CRYPTO_ecc_key_create_from_file (fn);
+  GNUNET_free (fn);
+  return pk;
+}
+
+
+/**
  * Setup a key file for a peer given the name of the
  * configuration file (!).  This function is used so that
  * at a later point code can be certain that reading a
@@ -902,18 +924,12 @@
 {
   struct GNUNET_CONFIGURATION_Handle *cfg;
   struct GNUNET_CRYPTO_EccPrivateKey *pk;
-  char *fn;
 
   cfg = GNUNET_CONFIGURATION_create ();
   (void) GNUNET_CONFIGURATION_load (cfg, cfg_name);
-  if (GNUNET_OK == 
-      GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER", "PRIVATE_KEY", 
&fn))
-  {
-    pk = GNUNET_CRYPTO_ecc_key_create_from_file (fn);
-    if (NULL != pk)
-      GNUNET_CRYPTO_ecc_key_free (pk);
-    GNUNET_free (fn);
-  }
+  pk = GNUNET_CRYPTO_ecc_key_create_from_configuration (cfg);
+  if (NULL != pk)
+    GNUNET_CRYPTO_ecc_key_free (pk);
   GNUNET_CONFIGURATION_destroy (cfg);
 }
 
@@ -932,24 +948,13 @@
 {
   struct GNUNET_CRYPTO_EccPrivateKey *my_private_key;
   struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key;
-  char *keyfile;
 
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER", "PRIVATE_KEY",
-                                               &keyfile))
+  if (NULL == (my_private_key = 
GNUNET_CRYPTO_ecc_key_create_from_configuration (cfg)))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Lacking key configuration settings.\n"));
+                _("Could not load peer's private key\n"));
     return GNUNET_SYSERR;
   }
-  if (NULL == (my_private_key = GNUNET_CRYPTO_ecc_key_create_from_file 
(keyfile)))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Could not access hostkey file `%s'.\n"), keyfile);
-    GNUNET_free (keyfile);
-    return GNUNET_SYSERR;
-  }
-  GNUNET_free (keyfile);
   GNUNET_CRYPTO_ecc_key_get_public (my_private_key, &my_public_key);
   GNUNET_CRYPTO_ecc_key_free (my_private_key);
   GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), 
&dst->hashPubKey);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]