[git] GCRYPT - branch, master, updated. libgcrypt-1.5.0-336-g6c6d481

by Werner Koch cvs at cvs.gnupg.org
Fri Oct 25 11:45:12 CEST 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU crypto library".

The branch, master has been updated
       via  6c6d4810927de7310ae7bac61b4ff5467d7cb485 (commit)
      from  c630fd71b336eb9209e914d24dc1e26a34521882 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 6c6d4810927de7310ae7bac61b4ff5467d7cb485
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Oct 25 11:43:31 2013 +0200

    tests: Add tests for mpi_cmp.
    
    * tests/mpitests.c (die): Modernize.
    (fail): New.
    (test_opaque, test_add, test_sub, test_mul): Use gcry_log_xx
    (main): Return error count.
    (test_cmp): New.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/tests/mpitests.c b/tests/mpitests.c
index e1c51d1..c5c60d7 100644
--- a/tests/mpitests.c
+++ b/tests/mpitests.c
@@ -1,5 +1,6 @@
 /* mpitests.c  -  basic mpi tests
  *	Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+ * Copyright (C) 2013 g10 Code GmbH
  *
  * This file is part of Libgcrypt.
  *
@@ -14,9 +15,7 @@
  * GNU Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
- * USA.
+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -33,23 +32,46 @@
 # include <gcrypt.h>
 #endif
 
+#define PGM "mpitests"
+
 static int verbose;
 static int debug;
+static int error_count;
 
 
 static void
 die (const char *format, ...)
 {
+  va_list arg_ptr ;
+
+  fflush (stdout);
+  fprintf (stderr, "%s: ", PGM);
+  va_start (arg_ptr, format) ;
+  vfprintf (stderr, format, arg_ptr );
+  va_end(arg_ptr);
+  if (*format && format[strlen(format)-1] != '\n')
+    putc ('\n', stderr);
+  exit (1);
+}
+
+static void
+fail (const char *format, ...)
+{
   va_list arg_ptr;
 
+  fflush (stdout);
+  fprintf (stderr, "%s: ", PGM);
   va_start (arg_ptr, format);
   vfprintf (stderr, format, arg_ptr);
   va_end (arg_ptr);
-  exit (1);
+  if (*format && format[strlen(format)-1] != '\n')
+    putc ('\n', stderr);
+  error_count++;
+  if (error_count >= 50)
+    die ("stopped after 50 errors.");
 }
 
 
-
 /* Set up some test patterns */
 
 /* 48 bytes with value 1: this results in 8 limbs for 64bit limbs, 16limb for 32 bit limbs */
@@ -188,17 +210,118 @@ test_opaque (void)
   if (strcmp (p, "This is a test buffer"))
     die ("gcry_mpi_get_opaque returned a changed buffer\n");
 
-  if (verbose)
-    {
-      fprintf (stderr, "mpi: ");
-      gcry_mpi_dump (a);
-      putc ('\n', stderr);
-    }
+  if (debug)
+    gcry_log_debugmpi ("mpi", a);
 
   gcry_mpi_release (a);
 }
 
 
+static void
+test_cmp (void)
+{
+  gpg_error_t rc;
+  gcry_mpi_t zero, zero2;
+  gcry_mpi_t one;
+  gcry_mpi_t two;
+  gcry_mpi_t all_ones;
+  gcry_mpi_t opa1, opa2;
+  gcry_mpi_t opa1s, opa2s;
+  gcry_mpi_t opa0, opa02;
+
+  zero = gcry_mpi_new (0);
+  zero2= gcry_mpi_set_ui (NULL, 0);
+  one  = gcry_mpi_set_ui (NULL, 1);
+  two  = gcry_mpi_set_ui (NULL, 2);
+  rc = gcry_mpi_scan (&all_ones, GCRYMPI_FMT_USG, ones, sizeof(ones), NULL);
+  if (rc)
+    die ("scanning number failed at line %d", __LINE__);
+  opa0  = gcry_mpi_set_opaque (NULL, gcry_xstrdup ("a"), 0);
+  opa02 = gcry_mpi_set_opaque (NULL, gcry_xstrdup ("b"), 0);
+  opa1  = gcry_mpi_set_opaque (NULL, gcry_xstrdup ("aaaaaaaaaaaaaaaa"), 16*8);
+  opa1s = gcry_mpi_set_opaque (NULL, gcry_xstrdup ("a"), 1*8);
+  opa2  = gcry_mpi_set_opaque (NULL, gcry_xstrdup ("bbbbbbbbbbbbbbbb"), 16*8);
+  opa2s = gcry_mpi_set_opaque (NULL, gcry_xstrdup ("b"), 1*8);
+
+
+  /* Single limb test with cmp_ui */
+  if (gcry_mpi_cmp_ui (zero, 0))
+    fail ("mpi_cmp_ui failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp_ui (zero, 1) < 0))
+    fail ("mpi_cmp_ui failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp_ui (zero, (-1)) < 0))
+    fail ("mpi_cmp_ui failed at line %d", __LINE__);
+
+  if (gcry_mpi_cmp_ui (two, 2))
+    fail ("mpi_cmp_ui failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp_ui (two, 3) < 0))
+    fail ("mpi_cmp_ui failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp_ui (two, 1) > 0))
+    fail ("mpi_cmp_ui failed at line %d", __LINE__);
+
+  /* Multi limb tests with cmp_ui.  */
+  if (!(gcry_mpi_cmp_ui (all_ones, 0) > 0))
+    fail ("mpi_cmp_ui failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp_ui (all_ones, (-1)) > 0))
+    fail ("mpi_cmp_ui failed at line %d", __LINE__);
+
+  /* Single limb test with cmp */
+  if (gcry_mpi_cmp (zero, zero2))
+    fail ("mpi_cmp failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp (zero, one) < 0))
+    fail ("mpi_cmp failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp (one, zero) > 0))
+    fail ("mpi_cmp failed at line %d", __LINE__);
+
+  gcry_mpi_neg (one, one);
+  if (!(gcry_mpi_cmp (zero, one) > 0))
+    fail ("mpi_cmp failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp (one, zero) < 0))
+    fail ("mpi_cmp failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp (one, two) < 0))
+    fail ("mpi_cmp failed at line %d", __LINE__);
+  gcry_mpi_neg (one, one);
+
+  if (!(gcry_mpi_cmp (one, two) < 0))
+    fail ("mpi_cmp failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp (two, one) > 0))
+    fail ("mpi_cmp failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp (one, all_ones) < 0))
+    fail ("mpi_cmp failed at line %d", __LINE__);
+
+  /* Tests with opaque values.  */
+  if (!(gcry_mpi_cmp (opa1, one) < 0))
+    fail ("mpi_cmp failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp (one, opa1) > 0))
+    fail ("mpi_cmp failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp (opa0, opa02) == 0))
+    fail ("mpi_cmp failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp (opa1s, opa1) < 0))
+    fail ("mpi_cmp failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp (opa2, opa1s) > 0))
+    fail ("mpi_cmp failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp (opa1, opa2) < 0))
+    fail ("mpi_cmp failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp (opa2, opa1) > 0))
+    fail ("mpi_cmp failed at line %d", __LINE__);
+  if (!(gcry_mpi_cmp (opa1, opa1) == 0))
+    fail ("mpi_cmp failed at line %d", __LINE__);
+
+
+  gcry_mpi_release(opa2s);
+  gcry_mpi_release(opa2);
+  gcry_mpi_release(opa1s);
+  gcry_mpi_release(opa1);
+  gcry_mpi_release(opa02);
+  gcry_mpi_release(opa0);
+  gcry_mpi_release(all_ones);
+  gcry_mpi_release(two);
+  gcry_mpi_release(one);
+  gcry_mpi_release(zero2);
+  gcry_mpi_release(zero);
+}
+
+
 static int
 test_add (void)
 {
@@ -215,14 +338,14 @@ test_add (void)
 
   gcry_mpi_add(result, one, two);
   gcry_mpi_aprint(GCRYMPI_FMT_HEX, &pc, NULL, result);
-  if (verbose)
-    printf("Result of one plus two:\n%s\n", pc);
+  if (debug)
+    gcry_log_debug ("Result of one plus two:\n%s\n", pc);
   gcry_free(pc);
 
   gcry_mpi_add(result, ff, one);
   gcry_mpi_aprint(GCRYMPI_FMT_HEX, &pc, NULL, result);
-  if (verbose)
-    printf("Result of ff plus one:\n%s\n", pc);
+  if (debug)
+    gcry_log_debug ("Result of ff plus one:\n%s\n", pc);
   gcry_free(pc);
 
   gcry_mpi_release(one);
@@ -247,8 +370,8 @@ test_sub (void)
   gcry_mpi_sub(result, two, one);
 
   gcry_mpi_aprint(GCRYMPI_FMT_HEX, &pc, NULL, result);
-  if (verbose)
-    printf("Result of two minus one:\n%s\n", pc);
+  if (debug)
+    gcry_log_debug ("Result of two minus one:\n%s\n", pc);
   gcry_free(pc);
 
   gcry_mpi_release(one);
@@ -272,8 +395,8 @@ test_mul (void)
   gcry_mpi_mul(result, two, three);
 
   gcry_mpi_aprint(GCRYMPI_FMT_HEX, &pc, NULL, result);
-  if (verbose)
-    printf("Result of two mul three:\n%s\n", pc);
+  if (debug)
+    gcry_log_debug ("Result of two mul three:\n%s\n", pc);
   gcry_free(pc);
 
   gcry_mpi_release(two);
@@ -408,10 +531,11 @@ main (int argc, char* argv[])
 
   test_const_and_immutable ();
   test_opaque ();
+  test_cmp ();
   test_add ();
   test_sub ();
   test_mul ();
   test_powm ();
 
-  return 0;
+  return !!error_count;
 }

-----------------------------------------------------------------------

Summary of changes:
 tests/mpitests.c |  164 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 144 insertions(+), 20 deletions(-)


hooks/post-receive
-- 
The GNU crypto library
http://git.gnupg.org


_______________________________________________
Gnupg-commits mailing list
Gnupg-commits at gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-commits




More information about the Gcrypt-devel mailing list