Link libgnunetblockgroup to libgnunetblock
[oweals/gnunet.git] / src / util / gnunet-ecc.c
index 1a183e854fcb3d9126429d54d6f9737c622ac7ef..ddfd9b1c3082c540d416170f3512e9ade7ed32b4 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2012, 2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2012, 2013 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 
 /**
@@ -28,6 +28,9 @@
 #include "gnunet_testing_lib.h"
 #include <gcrypt.h>
 
+/**
+ * Number of characters a Base32-encoded public key requires.
+ */
 #define KEY_STR_LEN sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)*8/5+1
 
 /**
@@ -69,9 +72,9 @@ create_keys (const char *fn, const char *prefix)
   struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
   struct GNUNET_CRYPTO_EddsaPublicKey target_pub;
   static char vanity[KEY_STR_LEN + 1];
-  int len;
-  int n;
-  int rest;
+  size_t len;
+  size_t n;
+  size_t rest;
   unsigned char mask;
   unsigned target_byte;
   char *s;
@@ -84,11 +87,12 @@ create_keys (const char *fn, const char *prefix)
   if (NULL != prefix)
   {
     strncpy (vanity, prefix, KEY_STR_LEN);
-    len = strlen (vanity);
+    len = GNUNET_MIN (strlen (prefix), KEY_STR_LEN);
     n = len * 5 / 8;
     rest = len * 5 % 8;
 
-    memset (&vanity[len], 0, KEY_STR_LEN - len);
+    memset (&vanity[len], '0', KEY_STR_LEN - len);
+    vanity[KEY_STR_LEN] = '\0';
     GNUNET_assert (GNUNET_OK ==
                    GNUNET_CRYPTO_eddsa_public_key_from_string (vanity,
                                                                KEY_STR_LEN,
@@ -108,7 +112,8 @@ create_keys (const char *fn, const char *prefix)
     }
     else
     {
-      mask = 0;
+      /* Just so old (debian) versions of GCC calm down with the warnings. */
+      mask = target_byte = 0;
     }
     s = GNUNET_CRYPTO_eddsa_public_key_to_string (&target_pub);
     fprintf (stderr,
@@ -117,9 +122,9 @@ create_keys (const char *fn, const char *prefix)
              s);
     GNUNET_free (s);
     fprintf (stderr,
-             "\nattempt %s [%d, %X]\n",
+             "\nattempt %s [%u, %X]\n",
              vanity,
-             n,
+             (unsigned int) n,
              mask);
   }
   else
@@ -186,13 +191,16 @@ create_keys (const char *fn, const char *prefix)
 
 
 static void
-print_hex (char *msg, void *buf, size_t size)
+print_hex (const char *msg,
+           const void *buf,
+           size_t size)
 {
   size_t i;
+
   printf ("%s: ", msg);
   for (i = 0; i < size; i++)
   {
-    printf ("%02hhx", ((char *)buf)[i]);
+    printf ("%02hhx", ((const char *)buf)[i]);
   }
   printf ("\n");
 }
@@ -315,7 +323,7 @@ print_key (const char *filename)
   total_hostkeys = fs / GNUNET_TESTING_HOSTKEYFILESIZE;
   for (c = 0; (c < total_hostkeys) && (c < list_keys_count); c++)
   {
-    memcpy (&private_key,
+    GNUNET_memcpy (&private_key,
             hostkeys_data + (c * GNUNET_TESTING_HOSTKEYFILESIZE),
             GNUNET_TESTING_HOSTKEYFILESIZE);
     GNUNET_CRYPTO_eddsa_key_get_public (&private_key, &public_key);