tolerate additional IPv4 address now available for gnunet.org
[oweals/gnunet.git] / src / util / test_crypto_paillier.c
index e1c440c8ae3d3559534913d3f699f6c3fd9cd658..d196963721cecac51a6fe9e37d31f2a4dc012e31 100644 (file)
@@ -1,21 +1,21 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2014 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2014 GNUnet e.V.
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     or (at your option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
+     Affero General Public License for more details.
+    
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     SPDX-License-Identifier: AGPL3.0-or-later
 
 */
 /**
@@ -37,6 +37,7 @@ test_crypto ()
   struct GNUNET_CRYPTO_PaillierCiphertext ciphertext;
   struct GNUNET_CRYPTO_PaillierPublicKey public_key;
   struct GNUNET_CRYPTO_PaillierPrivateKey private_key;
+  int ret = 0;
 
   GNUNET_CRYPTO_paillier_create (&public_key,
                                  &private_key);
@@ -54,7 +55,6 @@ test_crypto ()
                                   &public_key,
                                   &ciphertext,
                                   plaintext_result);
-
   if (0 != gcry_mpi_cmp (plaintext,
                          plaintext_result))
   {
@@ -65,9 +65,11 @@ test_crypto ()
                        plaintext);
     gcry_log_debugmpi ("\n",
                        plaintext_result);
-    return 1;
+    ret = 1;
   }
-  return 0;
+  gcry_mpi_release (plaintext);
+  gcry_mpi_release (plaintext_result);
+  return ret;
 }
 
 
@@ -84,6 +86,7 @@ test_hom_simple (unsigned int a,
   struct GNUNET_CRYPTO_PaillierCiphertext c_result;
   struct GNUNET_CRYPTO_PaillierPublicKey public_key;
   struct GNUNET_CRYPTO_PaillierPrivateKey private_key;
+  int ret = 0;
 
   GNUNET_CRYPTO_paillier_create (&public_key,
                                  &private_key);
@@ -119,9 +122,13 @@ test_hom_simple (unsigned int a,
              "GNUNET_CRYPTO_paillier failed simple math!\n");
     gcry_log_debugmpi ("got ", hom_result);
     gcry_log_debugmpi ("wanted ", result);
-    return 1;
+    ret = 1;
   }
-  return 0;
+  gcry_mpi_release (m1);
+  gcry_mpi_release (m2);
+  gcry_mpi_release (result);
+  gcry_mpi_release (hom_result);
+  return ret;
 }
 
 
@@ -168,7 +175,8 @@ test_hom ()
     fprintf (stderr,
              "GNUNET_CRYPTO_paillier_encrypt 1 failed, should return 1 allowed operation, got %d!\n",
              ret);
-    return 1;
+    ret = 1;
+    goto out;
   }
   if (2 != (ret = GNUNET_CRYPTO_paillier_encrypt (&public_key,
                                                   m2,
@@ -178,7 +186,8 @@ test_hom ()
     fprintf (stderr,
              "GNUNET_CRYPTO_paillier_encrypt 2 failed, should return 2 allowed operation, got %d!\n",
              ret);
-    return 1;
+    ret = 1;
+    goto out;
   }
 
   if (0 != (ret = GNUNET_CRYPTO_paillier_hom_add (&public_key,
@@ -189,7 +198,8 @@ test_hom ()
     fprintf (stderr,
              "GNUNET_CRYPTO_paillier_hom_add failed, expected 0 remaining operations, got %d!\n",
              ret);
-    return 1;
+    ret = 1;
+    goto out;
   }
 
   GNUNET_CRYPTO_paillier_decrypt (&private_key,
@@ -203,9 +213,14 @@ test_hom ()
              "GNUNET_CRYPTO_paillier miscalculated with large numbers!\n");
     gcry_log_debugmpi ("got", hom_result);
     gcry_log_debugmpi ("wanted", result);
-    return 1;
+    ret = 1;
   }
-  return 0;
+out:
+  gcry_mpi_release (m1);
+  gcry_mpi_release (m2);
+  gcry_mpi_release (result);
+  gcry_mpi_release (hom_result);
+  return ret;
 }