Returns now GNUNET_SYSERR
[oweals/gnunet.git] / src / util / test_crypto_ksk.c
index d5a965d4234b4e456ab95d6c47663dd5889b7286..74f88d5bf934fc4bc5d937904f7f9fb7d614e274 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;
@@ -55,15 +55,20 @@ testCorrectKey ()
     }
   GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey);
   GNUNET_CRYPTO_rsa_key_free (hostkey);
+#if 0
+  for (i=0;i<sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);i++)
+    printf("%02x", ((unsigned char*) &pkey)[i]);
+  printf ("\n");
+#endif
   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",
+                  " Failed! Wanted %.2s but got %2s at %d\n",
                   &want[i*2],
-                  out);
+                  out, i);
          return GNUNET_SYSERR;
        }
     }
@@ -166,7 +171,7 @@ testEncryptDecrypt (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
   printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n",
           ITER,
           (unsigned long long)
-          GNUNET_TIME_absolute_get_duration (start).value, ok);
+          GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
   if (ok == 0)
     return GNUNET_OK;
   else
@@ -217,7 +222,7 @@ testSignVerify (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
   printf ("%d RSA sign/verify operations %llums\n",
           ITER,
           (unsigned long long)
-          GNUNET_TIME_absolute_get_duration (start).value);
+          GNUNET_TIME_absolute_get_duration (start).rel_value);
   return ok;
 }
 
@@ -230,6 +235,8 @@ main (int argc, char *argv[])
   struct GNUNET_CRYPTO_RsaPrivateKey *hostkey;
 
   GNUNET_log_setup ("test-crypto-ksk", "WARNING", NULL);
+  if (GNUNET_OK != testCorrectKey ())
+    failureCount++;
   GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &in);
   hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in);
   if (hostkey == NULL)
@@ -237,9 +244,6 @@ main (int argc, char *argv[])
       printf ("\nGNUNET_CRYPTO_rsa_key_create_from_hash failed!\n");
       return 1;
     }
-
-  if (GNUNET_OK != testCorrectKey ())
-    failureCount++;
   if (GNUNET_OK != testMultiKey ("foo"))
     failureCount++;
   if (GNUNET_OK != testMultiKey ("bar"))