stuff
authorChristian Grothoff <christian@grothoff.org>
Thu, 14 Oct 2010 09:51:29 +0000 (09:51 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 14 Oct 2010 09:51:29 +0000 (09:51 +0000)
src/util/crypto_ksk.c
src/util/test_crypto_ksk.c

index 07ac939b43e10f5629bd224175a3d8ef43130df6..b44c8e992beed5a97809a3a49fb2e387297d1f67 100644 (file)
@@ -201,6 +201,22 @@ leave:
   return rc;
 }
 
+/**
+ * If target != size, move target bytes to the
+ * end of the size-sized buffer and zero out the
+ * first target-size bytes.
+ */
+static void
+adjust (unsigned char *buf, size_t size, size_t target)
+{
+  if (size < target)
+    {
+      memmove (&buf[target - size], buf, size);
+      memset (buf, 0, target - size);
+    }
+}
+
+
 static void
 gen_prime (gcry_mpi_t *ptest, unsigned int nbits, GNUNET_HashCode * hc)
 {
@@ -334,6 +350,8 @@ gen_prime (gcry_mpi_t *ptest, unsigned int nbits, GNUNET_HashCode * hc)
                         gcry_mpi_print (GCRYMPI_FMT_USG, 
                                         (unsigned char*) &mods[i], written, &written, 
                                         tmp));
+         adjust ( (unsigned char*) &mods[i], written, sizeof (unsigned int));
+         mods[i] = ntohl (mods[i]);
        }
       /* Now try some primes starting with prime. */
       for (step = 0; step < 20000; step += 2)
index 96e6fee5ca51b30036ac4be817bc740d36c06e8f..1e3b06f6aa7de4192bb7247d7e799557f5ae7542 100644 (file)
@@ -38,7 +38,7 @@
 static int
 testCorrectKey ()
 {
-  const char *want = "010601000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b73c215f7a5e6b09bec55713c901786c09324a150980e014bdb0d04426934929c3b4971a9711af5455536cd6eeb8bfa004ee904972a737455f53c752987d8e5e1396e5e5a4ed694fb1d45e15ae68d8756e525cbaf6ab6ed0269ac402f2a6b8a73627e3797496b43a851271cb7d7b60b6acf4324ba72be5cafcef98dca8d71d1b01010000";
+  const char *want = "010601000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b73c215f7a5e6b09bec55713c901786c09324a150980e014bdb0d04426934929c3b4971a9711af5455536cd6eeb8bfa004ee904972a737455f53c752987d8c82b755bc02882b44950c4acdc1672ba74c3b94d81a4c1ea3d74e7700ae5594c3a4f3c559e4bff2df6844fac302e4b66175e14dc8bad3ce44281d2fec1a1abef06301010000";
   GNUNET_HashCode in;
   struct GNUNET_CRYPTO_RsaPrivateKey *hostkey;
   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
@@ -57,7 +57,7 @@ testCorrectKey ()
   GNUNET_CRYPTO_rsa_key_free (hostkey);
 #if 1
   for (i=0;i<sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);i++)
-    printf(out, sizeof (out), "%02x", ((unsigned char*) &pkey)[i]);
+    printf("%02x", ((unsigned char*) &pkey)[i]);
   printf ("\n");
 #endif
   for (i=0;i<sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);i++)