fix as suggested by amatus:
authorChristian Grothoff <christian@grothoff.org>
Thu, 14 Oct 2010 08:06:57 +0000 (08:06 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 14 Oct 2010 08:06:57 +0000 (08:06 +0000)
src/util/crypto_ksk.c
src/util/test_crypto_ksk.c

index 687aece16e7d7f9c6645ced48bbd574b48fe27ce..2a49966b41131e68a4003393df32d4a39c3f007f 100644 (file)
@@ -95,7 +95,7 @@ mpz_randomize (gcry_mpi_t n, unsigned int nbits, GNUNET_HashCode * rnd)
          gcry_mpi_mul_ui(n, n, 1 << (sizeof(uint32_t)*4));
          gcry_mpi_mul_ui(n, n, 1 << (sizeof(uint32_t)*4));
 #endif
-          gcry_mpi_add_ui(n, n, ((uint32_t *) &tmp)[j]);
+          gcry_mpi_add_ui(n, n, ntohl (((uint32_t *) &tmp)[j]));
         }
       hc = tmp;
     }
index 952b1dcaca2c7a43e4907d82800d312206cb4572..d5a965d4234b4e456ab95d6c47663dd5889b7286 100644 (file)
 #define ITER 25
 
 
+static int
+testCorrectKey ()
+{
+  const char *want = "010601000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b73c215f7a5e6b09bec55713c901786c09324a150980e014bdb0d04426934929c3b4971a9711af5455536cd6eeb8bfa004ee904972a737455f53c752987d8e5e1396e5e5a4ed694fb1d45e15ae68d8756e525cbaf6ab6ed0269ac402f2a6b8a73627e3797496b43a851271cb7d7b60b6acf4324ba72be5cafcef98dca8d71d1b01010000";
+  GNUNET_HashCode in;
+  struct GNUNET_CRYPTO_RsaPrivateKey *hostkey;
+  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
+  int i;
+  char out[3];
+
+  fprintf (stderr, "Testing KBlock key correctness");
+  GNUNET_CRYPTO_hash ("X", strlen ("X"), &in);
+  hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in);
+  if (hostkey == NULL)
+    {
+      GNUNET_break (0);
+      return GNUNET_SYSERR;
+    }
+  GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey);
+  GNUNET_CRYPTO_rsa_key_free (hostkey);
+  for (i=0;i<sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);i++)
+    {
+      snprintf(out, sizeof (out), "%02x", ((unsigned char*) &pkey)[i]);
+      if (0 != strncmp (out, &want[i*2], 2))
+       {
+         fprintf (stderr,
+                  "Wanted %.2s but got %2s\n",
+                  &want[i*2],
+                  out);
+         return GNUNET_SYSERR;
+       }
+    }
+  fprintf (stderr, " OK\n");
+  return GNUNET_OK;
+}
+
+
 static int
 testMultiKey (const char *word)
 {
@@ -201,6 +238,8 @@ main (int argc, char *argv[])
       return 1;
     }
 
+  if (GNUNET_OK != testCorrectKey ())
+    failureCount++;
   if (GNUNET_OK != testMultiKey ("foo"))
     failureCount++;
   if (GNUNET_OK != testMultiKey ("bar"))