gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r406 - GNUnet/src/util


From: grothoff
Subject: [GNUnet-SVN] r406 - GNUnet/src/util
Date: Mon, 7 Mar 2005 18:35:26 -0800 (PST)

Author: grothoff
Date: 2005-03-07 18:35:24 -0800 (Mon, 07 Mar 2005)
New Revision: 406

Modified:
   GNUnet/src/util/hostkeytest.c
Log:
testcase for gcrypt RSA failures

Modified: GNUnet/src/util/hostkeytest.c
===================================================================
--- GNUnet/src/util/hostkeytest.c       2005-03-07 12:31:31 UTC (rev 405)
+++ GNUnet/src/util/hostkeytest.c       2005-03-08 02:35:24 UTC (rev 406)
@@ -67,6 +67,63 @@
     return SYSERR;
 }
 
+
+static int testEncryptDecryptSK() {
+  struct PrivateKey * hostkey;
+  PublicKey pkey;
+  RSAEncryptedData target;
+  SESSIONKEY insk;
+  SESSIONKEY outsk;
+  int i;
+  TIME_T start;
+  int ok;
+
+  fprintf(stderr, "W");
+  hostkey = makePrivateKey();
+  getPublicKey(hostkey, &pkey);
+
+  ok = 0;
+  TIME(&start);
+  for (i=0;i<ITER;i++) {
+    fprintf(stderr, ".");
+    makeSessionkey(&insk);
+    if (SYSERR == encryptPrivateKey(&insk,
+                                   sizeof(SESSIONKEY),
+                                   &pkey,
+                                   &target)) {
+      fprintf(stderr, 
+             "encryptPrivateKey returned SYSERR\n");
+      ok++;
+      continue;
+    }
+    if (-1 == decryptPrivateKey(hostkey,
+                               &target, 
+                               &outsk,
+                               sizeof(SESSIONKEY))) {
+      fprintf(stderr, 
+             "decryptPrivateKey returned SYSERR\n");
+      ok++;
+      continue;
+    }
+    if (0 != memcmp(&insk,
+                   &outsk,
+                   sizeof(SESSIONKEY))) {
+      printf("testEncryptDecryptSK failed!\n");
+      ok++;
+      continue;
+    }
+  }
+  printf("%d RSA encrypt/decrypt SK operations %ds (%d failures)\n", 
+        ITER,
+        (int) (TIME(NULL)-start),
+        ok);
+  freePrivateKey(hostkey);
+  if (ok == 0)
+    return OK;
+  else
+    return SYSERR;
+}
+
 static int testSignVerify() {
   struct PrivateKey * hostkey;
   Signature sig;
@@ -173,6 +230,8 @@
   initLockingGcrypt();
 #endif
   initRAND();  
+  if (OK != testEncryptDecryptSK())
+     failureCount++;
   if (OK != testEncryptDecrypt())
      failureCount++;
   if (OK != testSignVerify())





reply via email to

[Prev in Thread] Current Thread [Next in Thread]