gnunet-svn
[Top][All Lists]
Advanced

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

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


From: grothoff
Subject: [GNUnet-SVN] r407 - GNUnet/src/util
Date: Mon, 7 Mar 2005 20:06:43 -0800 (PST)

Author: grothoff
Date: 2005-03-07 20:06:42 -0800 (Mon, 07 Mar 2005)
New Revision: 407

Modified:
   GNUnet/src/util/hostkey_gcrypt.c
   GNUnet/src/util/hostkey_openssl.c
   GNUnet/src/util/hostkeytest.c
   GNUnet/src/util/kblockkey_test.c
Log:
workaround libgcrypt pcks padding problems

Modified: GNUnet/src/util/hostkey_gcrypt.c
===================================================================
--- GNUnet/src/util/hostkey_gcrypt.c    2005-03-08 02:35:24 UTC (rev 406)
+++ GNUnet/src/util/hostkey_gcrypt.c    2005-03-08 04:06:42 UTC (rev 407)
@@ -700,7 +700,7 @@
 int decryptPrivateKey(const struct PrivateKey * hostkey, 
                      const RSAEncryptedData * block,
                      void * result,
-                     unsigned int max) {
+                     unsigned short max) {
   gcry_sexp_t resultsexp;
   gcry_sexp_t data;
   size_t erroff;
@@ -774,39 +774,8 @@
   }
 
   endp = tmp;
-  if (*endp == 0) {
-    endp++;
-    size--;
-  }
-  if ( (!size) || 
-       (*endp != 0x02 )) {
-    LOG(LOG_ERROR,
-       _("Received plaintext not in pkcs-1 block type 2 format (size=%d, 
*tmp=%d)!\n"),
-       size, (int)*tmp);
-    FREE(tmp);
-    unlockGcrypt();
-    return SYSERR;
-  }
-  /* serach the end of the padding */
-  while ( (size > 0) && 
-         ((*endp) != 0) ) {
-    size--;
-    endp++;
-  }
-  if ( (size == 0) || 
-       (*endp != 0x0) ) {
-    LOG(LOG_ERROR,
-       _("Received plaintext not in pkcs-1 block type 2 format (size=%d, 
*endp=%d)!\n"),
-       size, (int) *endp);
-    FREE(tmp);
-    unlockGcrypt();
-    return SYSERR;
-  }
-  size--;
-  endp++;
-
-  if (size > max)
-    size = max;
+  endp += (size - max);
+  size = max;
   memcpy(result,
         endp,
         size);
@@ -946,7 +915,8 @@
   memcpy(buff,
         FORMATSTRING,
         bufSize);
-  memcpy(&buff[strlen(FORMATSTRING) - 
strlen("0123456789012345678901234567890123456789012345678901234567890123))")],
+  memcpy(&buff[strlen(FORMATSTRING) - 
+              
strlen("0123456789012345678901234567890123456789012345678901234567890123))")],
         &hc,
         sizeof(HashCode512));
   rc = gcry_sexp_new(&data,

Modified: GNUnet/src/util/hostkey_openssl.c
===================================================================
--- GNUnet/src/util/hostkey_openssl.c   2005-03-08 02:35:24 UTC (rev 406)
+++ GNUnet/src/util/hostkey_openssl.c   2005-03-08 04:06:42 UTC (rev 407)
@@ -373,7 +373,7 @@
 int decryptPrivateKey(const struct PrivateKey * hostkey, 
                      const RSAEncryptedData * block,
                      void * result,
-                     unsigned int max) {
+                     unsigned short max) {
   RSAEncryptedData tmp; /* this is as big as the result can possibly get */
   int size;
 

Modified: GNUnet/src/util/hostkeytest.c
===================================================================
--- GNUnet/src/util/hostkeytest.c       2005-03-08 02:35:24 UTC (rev 406)
+++ GNUnet/src/util/hostkeytest.c       2005-03-08 04:06:42 UTC (rev 407)
@@ -29,22 +29,23 @@
   for (i=0;i<ITER;i++) {
     fprintf(stderr, ".");
     if (SYSERR == encryptPrivateKey(TESTSTRING,
-                                strlen(TESTSTRING)+1,
-                                &pkey,
-                                &target)) {
+                                   strlen(TESTSTRING)+1,
+                                   &pkey,
+                                   &target)) {
       fprintf(stderr, 
              "encryptPrivateKey returned SYSERR\n");
       ok++;
       continue;
     }
     if (-1 == decryptPrivateKey(hostkey,
-                            &target, 
-                            result,
-                            MAX_TESTVAL)) {
+                               &target, 
+                               result,
+                               strlen(TESTSTRING)+1)) {
      fprintf(stderr, 
              "decryptPrivateKey returned SYSERR\n");
       ok++;
       continue;
+
     }
     if (strncmp(TESTSTRING, result,
                strlen(TESTSTRING)) != 0) {
@@ -138,13 +139,19 @@
   TIME(&start);
   for (i=0;i<ITER;i++) {
     fprintf(stderr, ".");
-    if (SYSERR == sign(hostkey, strlen(TESTSTRING), TESTSTRING, &sig)) {
+    if (SYSERR == sign(hostkey, 
+                      strlen(TESTSTRING), 
+                      TESTSTRING, 
+                      &sig)) {
       fprintf(stderr,
              "sign returned SYSERR\n");
       ok = SYSERR;
       continue;
     }
-    if (SYSERR == verifySig(TESTSTRING, strlen(TESTSTRING), &sig, &pkey)) {
+    if (SYSERR == verifySig(TESTSTRING, 
+                           strlen(TESTSTRING), 
+                           &sig,
+                           &pkey)) {
       printf("testSignVerify failed!\n");
       ok = SYSERR;
       continue;
@@ -175,9 +182,9 @@
     fprintf(stderr, ".");
     getPublicKey(hostkey, &pkey);
     if (SYSERR == encryptPrivateKey(TESTSTRING,
-                                strlen(TESTSTRING)+1,
-                                &pkey,
-                                &target)) {
+                                   strlen(TESTSTRING)+1,
+                                   &pkey,
+                                   &target)) {
       fprintf(stderr,
              "encryptPrivateKey returned SYSERR\n");
       ok = SYSERR;
@@ -193,7 +200,10 @@
     }
     hostkey = decodePrivateKey(encoding);
     FREE(encoding);
-    if (SYSERR == decryptPrivateKey(hostkey, &target, result, MAX_TESTVAL)) {
+    if (SYSERR == decryptPrivateKey(hostkey, 
+                                   &target, 
+                                   result, 
+                                   strlen(TESTSTRING)+1)) {
       fprintf(stderr,
              "decryptPrivateKey returned SYSERR\n");
       ok = SYSERR;

Modified: GNUnet/src/util/kblockkey_test.c
===================================================================
--- GNUnet/src/util/kblockkey_test.c    2005-03-08 02:35:24 UTC (rev 406)
+++ GNUnet/src/util/kblockkey_test.c    2005-03-08 04:06:42 UTC (rev 407)
@@ -73,18 +73,18 @@
   for (i=0;i<ITER;i++) {
     fprintf(stderr, ".");
     if (SYSERR == encryptPrivateKey(TESTSTRING,
-                                strlen(TESTSTRING)+1,
-                                &pkey,
-                                &target)) {
+                                   strlen(TESTSTRING)+1,
+                                   &pkey,
+                                   &target)) {
       fprintf(stderr, 
              "encryptPrivateKey returned SYSERR\n");
       ok++;
       continue;
     }
     if (-1 == decryptPrivateKey(hostkey,
-                            &target, 
-                            result,
-                            MAX_TESTVAL)) {
+                               &target, 
+                               result,
+                               strlen(TESTSTRING)+1)) {
      fprintf(stderr, 
              "decryptPrivateKey returned SYSERR\n");
       ok++;
@@ -122,13 +122,18 @@
   TIME(&start);
   for (i=0;i<ITER;i++) {
     fprintf(stderr, ".");
-    if (SYSERR == sign(hostkey, strlen(TESTSTRING), TESTSTRING, &sig)) {
+    if (SYSERR == sign(hostkey,
+                      strlen(TESTSTRING),
+                      TESTSTRING, &sig)) {
       fprintf(stderr,
              "sign returned SYSERR\n");
       ok = SYSERR;
       continue;
     }
-    if (SYSERR == verifySig(TESTSTRING, strlen(TESTSTRING), &sig, &pkey)) {
+    if (SYSERR == verifySig(TESTSTRING, 
+                           strlen(TESTSTRING), 
+                           &sig, 
+                           &pkey)) {
       printf("testSignVerify failed!\n");
       ok = SYSERR;
       continue;
@@ -156,9 +161,9 @@
     fprintf(stderr, ".");
     getPublicKey(hostkey, &pkey);
     if (SYSERR == encryptPrivateKey(TESTSTRING,
-                                strlen(TESTSTRING)+1,
-                                &pkey,
-                                &target)) {
+                                   strlen(TESTSTRING)+1,
+                                   &pkey,
+                                   &target)) {
       fprintf(stderr,
              "encryptPrivateKey returned SYSERR\n");
       ok = SYSERR;
@@ -173,7 +178,10 @@
     }
     hostkey = decodePrivateKey(encoding);
     FREE(encoding);
-    if (SYSERR == decryptPrivateKey(hostkey, &target, result, MAX_TESTVAL)) {
+    if (SYSERR == decryptPrivateKey(hostkey, 
+                                   &target,
+                                   result, 
+                                   strlen(TESTSTRING)+1)) {
       fprintf(stderr,
              "decryptPrivateKey returned SYSERR\n");
       ok = SYSERR;
@@ -232,14 +240,15 @@
   if (OK != testPrivateKeyEncoding(hostkey)) 
     failureCount++;
   freePrivateKey(hostkey);
-#if ! USE_OPENSSL
+#if USE_GCRYPT
   doneLockingGcrypt();
 #endif
 
-  if (failureCount == 0)
+  if (failureCount == 0) {
     return 0;
-  else {
-    printf("\n\n%d TESTS FAILED!\n\n",failureCount);
+  } else {
+    printf("\n\n%d TESTS FAILED!\n\n",
+          failureCount);
     return -1;
   }  
 }





reply via email to

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