-docu, style fixes
[oweals/gnunet.git] / src / util / gnunet-ecc.c
index 25852dc6753d67beef1376392b70cb0066a0eca0..f725e4ff3e3c436477b64402c76ec83ef8c32769 100644 (file)
@@ -74,6 +74,7 @@ create_keys (const char *fn, const char *prefix)
   int rest;
   unsigned char mask;
   unsigned target_byte;
+  char *s;
 
   if (NULL == (f = fopen (fn, "w+")))
   {
@@ -83,11 +84,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);
+    vanity[KEY_STR_LEN] = '\0';
     GNUNET_assert (GNUNET_OK ==
                    GNUNET_CRYPTO_eddsa_public_key_from_string (vanity,
                                                                KEY_STR_LEN,
@@ -105,14 +107,28 @@ create_keys (const char *fn, const char *prefix)
       mask = ~ ((int)pow (2, 8 - rest) - 1);
       target_byte = ((unsigned char *) &target_pub)[n] & mask;
     }
+    else
+    {
+      /* 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,
              _("Generating %u keys like %s, please wait"),
-             make_keys, GNUNET_CRYPTO_eddsa_public_key_to_string (&target_pub));
-    fprintf (stderr, "\nattempt %s [%d, %X]\n", vanity, n, mask);
+             make_keys,
+             s);
+    GNUNET_free (s);
+    fprintf (stderr,
+             "\nattempt %s [%d, %X]\n",
+             vanity,
+             n,
+             mask);
   }
   else
   {
-    fprintf (stderr, _("Generating %u keys, please wait"), make_keys);
+    fprintf (stderr,
+             _("Generating %u keys, please wait"),
+             make_keys);
     /* Just so old (debian) versions of GCC calm down with the warnings. */
     n = rest = target_byte = mask = 0;
   }
@@ -165,19 +181,23 @@ create_keys (const char *fn, const char *prefix)
             _("\nFinished!\n"));
   else
     fprintf (stderr,
-            _("\nError, %u keys not generated\n"), make_keys);
+            _("\nError, %u keys not generated\n"),
+             make_keys);
   fclose (f);
 }
 
 
 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");
 }