-more rsa refactoring
authorChristian Grothoff <christian@grothoff.org>
Wed, 17 Oct 2012 15:23:57 +0000 (15:23 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 17 Oct 2012 15:23:57 +0000 (15:23 +0000)
src/gns/test_gns_proxy.c
src/include/gnunet_crypto_lib.h
src/pt/test_gns_vpn.c
src/pt/test_gnunet_vpn.c
src/util/crypto_rsa.c

index 5e3d09d68f1ac6a46f88a1f0c5d06382ce35f91d..545551411ebeab1a544cbff175a5a0d0c42a2f98 100644 (file)
@@ -457,7 +457,7 @@ main (int argc, char *const *argv)
     return 0;
   }
 
-  GNUNET_CRYPTO_setup_hostkey ("test_gns_proxy.conf");
+  GNUNET_CRYPTO_rsa_setup_hostkey ("test_gns_proxy.conf");
   
   if (0 != curl_global_init (CURL_GLOBAL_WIN32))
   {
index 57fcf8bc01a19b3e175e70cf9839c6cf83f4e502..f73c1ae760e7ff2de55a4b44b748dd453f6208e2 100644 (file)
@@ -887,6 +887,7 @@ GNUNET_CRYPTO_rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
  *
  * @param buf the buffer where the private key data is stored
  * @param len the length of the data in 'buffer'
+ * @return NULL on error
  */
 struct GNUNET_CRYPTO_RsaPrivateKey *
 GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len);
@@ -964,7 +965,7 @@ GNUNET_CRYPTO_rsa_key_create_stop (struct GNUNET_CRYPTO_RsaKeyGenerationContext
  * @param cfg_name name of the configuration file to use
  */
 void
-GNUNET_CRYPTO_setup_hostkey (const char *cfg_name);
+GNUNET_CRYPTO_rsa_setup_hostkey (const char *cfg_name);
 
 
 /**
@@ -975,15 +976,16 @@ GNUNET_CRYPTO_setup_hostkey (const char *cfg_name);
  * @return some private key purely dependent on input
  */
 struct GNUNET_CRYPTO_RsaPrivateKey *
-GNUNET_CRYPTO_rsa_key_create_from_hash (const struct GNUNET_HashCode * hc);
+GNUNET_CRYPTO_rsa_key_create_from_hash (const struct GNUNET_HashCode *hc);
 
 
 /**
  * Free memory occupied by the private key.
- * @param hostkey pointer to the memory to free
+ *
+ * @param key pointer to the memory to free
  */
 void
-GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey);
+GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *key);
 
 
 /**
index e67801298bbf751cbb916c092f52a0d71b2081b7..7d2cd7ba4b45265e198a294c80ae2a5507c1f834 100644 (file)
@@ -573,7 +573,7 @@ main (int argc, char *const *argv)
             "Change $PATH ('.' in $PATH before $GNUNET_PREFIX/bin is problematic) or permissions (run 'make install' as root) to fix this!\n");
     return 0;
   }
-  GNUNET_CRYPTO_setup_hostkey ("test_gns_vpn.conf");
+  GNUNET_CRYPTO_rsa_setup_hostkey ("test_gns_vpn.conf");
   
   dest_ip = "169.254.86.1";
   dest_af = AF_INET;
index f40a363b7d1f924d6d32110bc20f3b06f61b13af..72551e35318510b23af8c813471830757400d688 100644 (file)
@@ -436,7 +436,7 @@ main (int argc, char *const *argv)
              "Change $PATH ('.' in $PATH before $GNUNET_PREFIX/bin is problematic) or permissions (run 'make install' as root) to fix this!\n");
     return 0;
   }
-  GNUNET_CRYPTO_setup_hostkey ("test_gnunet_vpn.conf");
+  GNUNET_CRYPTO_rsa_setup_hostkey ("test_gnunet_vpn.conf");
   bin = argv[0];
   if (NULL != strstr (bin, "lt-"))
     bin = strstr (bin, "lt-") + 4;
index 042af08938e92a4ef4cdafbfcf87d16cd60d2fa2..949c0e430052b387a0b58dd90662e8ab1278cb89 100644 (file)
@@ -407,6 +407,7 @@ GNUNET_CRYPTO_rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
  *
  * @param buf the buffer where the private key data is stored
  * @param len the length of the data in 'buffer'
+ * @return NULL on error
  */
 struct GNUNET_CRYPTO_RsaPrivateKey *
 GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len)
@@ -423,8 +424,9 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len)
   gcry_mpi_t u;
   int rc;
   size_t size;
-  int pos;
+  size_t pos;
   uint16_t enc_len;
+  size_t erroff;
 
   enc_len = ntohs (encoding->len);
   if (len != enc_len)
@@ -530,7 +532,7 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len)
 
   if ((NULL != p) && (NULL != q) && (NULL != u))
   {
-    rc = gcry_sexp_build (&res, &size,  /* erroff */
+    rc = gcry_sexp_build (&res, &erroff,
                           "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)(u %m)))",
                           n, e, d, p, q, u);
   }
@@ -538,13 +540,13 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len)
   {
     if ((NULL != p) && (NULL != q))
     {
-      rc = gcry_sexp_build (&res, &size,        /* erroff */
+      rc = gcry_sexp_build (&res, &erroff,
                             "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)))",
                             n, e, d, p, q);
     }
     else
     {
-      rc = gcry_sexp_build (&res, &size,        /* erroff */
+      rc = gcry_sexp_build (&res, &erroff,
                             "(private-key(rsa(n %m)(e %m)(d %m)))", n, e, d);
     }
   }
@@ -561,7 +563,7 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len)
   if (0 != rc)
     LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
 #if EXTRA_CHECKS
-  if (gcry_pk_testkey (res))
+  if (0 != (rc = gcry_pk_testkey (res)))
   {
     LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc);
     return NULL;
@@ -1111,7 +1113,7 @@ GNUNET_CRYPTO_rsa_key_create_stop (struct GNUNET_CRYPTO_RsaKeyGenerationContext
  * @param cfg_name name of the configuration file to use
  */
 void
-GNUNET_CRYPTO_setup_hostkey (const char *cfg_name)
+GNUNET_CRYPTO_rsa_setup_hostkey (const char *cfg_name)
 {
   struct GNUNET_CONFIGURATION_Handle *cfg;
   struct GNUNET_CRYPTO_RsaPrivateKey *pk;