- doc
[oweals/gnunet.git] / src / util / test_crypto_ecc.c
index d61ba816e497e3625f0daf647577ddc6aac401d9..d8329a0ae523a2309312427df0059878cce58fee 100644 (file)
@@ -27,6 +27,7 @@
 #include "gnunet_common.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_signatures.h"
+#include <gcrypt.h>
 
 #define TESTSTRING "Hello World\0"
 #define MAX_TESTVAL sizeof(struct GNUNET_CRYPTO_AesSessionKey)
 static struct GNUNET_CRYPTO_EccPrivateKey *key;
 
 
-static int
-testEncryptDecrypt ()
-{
-  struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
-  struct GNUNET_CRYPTO_EccEncryptedData target;
-  char result[MAX_TESTVAL];
-  int i;
-  struct GNUNET_TIME_Absolute start;
-  int ok;
-
-  FPRINTF (stderr, "%s",  "W");
-  GNUNET_CRYPTO_ecc_key_get_public (key, &pkey);
-  ok = 0;
-  start = GNUNET_TIME_absolute_get ();
-  for (i = 0; i < ITER; i++)
-  {
-    FPRINTF (stderr, "%s",  ".");
-    if (GNUNET_SYSERR ==
-        GNUNET_CRYPTO_ecc_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &pkey,
-                                   &target))
-    {
-      FPRINTF (stderr, "%s",  "GNUNET_CRYPTO_ecc_encrypt returned SYSERR\n");
-      ok++;
-      continue;
-    }
-    if (-1 ==
-        GNUNET_CRYPTO_ecc_decrypt (key, &target, result,
-                                   strlen (TESTSTRING) + 1))
-    {
-      FPRINTF (stderr, "%s",  "GNUNET_CRYPTO_ecc_decrypt returned SYSERR\n");
-      ok++;
-      continue;
-
-    }
-    if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0)
-    {
-      printf ("%s != %.*s - testEncryptDecrypt failed!\n", TESTSTRING,
-              (int) MAX_TESTVAL, result);
-      ok++;
-      continue;
-    }
-  }
-  printf ("%d ECC encrypt/decrypt operations %s (%d failures)\n", 
-         ITER,
-          GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES), 
-         ok);
-  if (ok == 0)
-    return GNUNET_OK;
-  return GNUNET_SYSERR;
-}
-
-
-#if PERF
-static int
-testEncryptPerformance ()
-{
-  struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
-  struct GNUNET_CRYPTO_EccEncryptedData target;
-  int i;
-  struct GNUNET_TIME_Absolute start;
-  int ok;
-
-  FPRINTF (stderr, "%s",  "W");
-  GNUNET_CRYPTO_ecc_key_get_public (key, &pkey);
-  ok = 0;
-  start = GNUNET_TIME_absolute_get ();
-  for (i = 0; i < ITER; i++)
-  {
-    FPRINTF (stderr, "%s",  ".");
-    if (GNUNET_SYSERR ==
-        GNUNET_CRYPTO_ecc_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &pkey,
-                                   &target))
-    {
-      FPRINTF (stderr, "%s",  "GNUNET_CRYPTO_ecc_encrypt returned SYSERR\n");
-      ok++;
-      continue;
-    }
-  }
-  printf ("%d ECC encrypt operations %llu ms (%d failures)\n", ITER,
-          (unsigned long long)
-          GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
-  if (ok != 0)
-    return GNUNET_SYSERR;
-  return GNUNET_OK;
-}
-#endif
-
-static int
-testEncryptDecryptSK ()
-{
-  struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
-  struct GNUNET_CRYPTO_EccEncryptedData target;
-  struct GNUNET_CRYPTO_AesSessionKey insk;
-  struct GNUNET_CRYPTO_AesSessionKey outsk;
-  int i;
-  struct GNUNET_TIME_Absolute start;
-  int ok;
-
-  FPRINTF (stderr, "%s",  "W");
-  GNUNET_CRYPTO_ecc_key_get_public (key, &pkey);
-  ok = 0;
-  start = GNUNET_TIME_absolute_get ();
-  for (i = 0; i < ITER; i++)
-  {
-    FPRINTF (stderr, "%s",  ".");
-    GNUNET_CRYPTO_aes_create_session_key (&insk);
-    if (GNUNET_SYSERR ==
-        GNUNET_CRYPTO_ecc_encrypt (&insk,
-                                   sizeof (struct GNUNET_CRYPTO_AesSessionKey),
-                                   &pkey, &target))
-    {
-      FPRINTF (stderr, "%s",  "GNUNET_CRYPTO_ecc_encrypt returned SYSERR\n");
-      ok++;
-      continue;
-    }
-    if (-1 ==
-        GNUNET_CRYPTO_ecc_decrypt (key, &target, &outsk,
-                                   sizeof (struct GNUNET_CRYPTO_AesSessionKey)))
-    {
-      FPRINTF (stderr, "%s",  "GNUNET_CRYPTO_ecc_decrypt returned SYSERR\n");
-      ok++;
-      continue;
-    }
-    if (0 !=
-        memcmp (&insk, &outsk, sizeof (struct GNUNET_CRYPTO_AesSessionKey)))
-    {
-      printf ("testEncryptDecryptSK failed!\n");
-      ok++;
-      continue;
-    }
-  }
-  printf ("%d ECC encrypt/decrypt SK operations %s (%d failures)\n", 
-         ITER,
-          GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES), 
-         ok);
-  if (ok != 0)
-    return GNUNET_SYSERR;
-  return GNUNET_OK;
-}
-
-
 static int
 testSignVerify ()
 {
@@ -324,21 +184,23 @@ main (int argc, char *argv[])
 {
   int failureCount = 0;
 
+  if (!gcry_check_version ("1.5.0"))
+  {
+    FPRINTF (stderr,
+             _
+             ("libgcrypt has not the expected version (version %s is required).\n"),
+             "1.5.0");
+    return 0;
+  }
   GNUNET_log_setup ("test-crypto-ecc", "WARNING", NULL);
   GNUNET_CRYPTO_random_disable_entropy_gathering ();
   if (GNUNET_OK != testCreateFromFile ())
     failureCount++;
   GNUNET_SCHEDULER_run (&test_async_creation, NULL);
 #if PERF
-  if (GNUNET_OK != testEncryptPerformance ())
-    failureCount++;
   if (GNUNET_OK != testSignPerformance ())
     failureCount++;
 #endif
-  if (GNUNET_OK != testEncryptDecryptSK ())
-    failureCount++;
-  if (GNUNET_OK != testEncryptDecrypt ())
-    failureCount++;
   if (GNUNET_OK != testSignVerify ())
     failureCount++;
   GNUNET_CRYPTO_ecc_key_free (key);
@@ -350,4 +212,6 @@ main (int argc, char *argv[])
     return -1;
   }
   return 0;
-}                               /* end of main */
+}
+
+/* end of test_crypto_ecc.c */