[git] GCRYPT - branch, master, updated. libgcrypt-1.5.0-415-gc56080c

by NIIBE Yutaka cvs at cvs.gnupg.org
Wed Dec 4 04:02:01 CET 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  c56080c26186d25dec05f01831494c77d8d07e13 (commit)
      from  2ff86db2e1b0f6cc22a1ca86037b526c5fa3be51 (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 c56080c26186d25dec05f01831494c77d8d07e13
Author: NIIBE Yutaka <gniibe at fsij.org>
Date:   Wed Dec 4 10:03:57 2013 +0900

    mpi: fix gcry_mpi_powm for negative base.
    
    * mpi/mpi-pow.c (gcry_mpi_powm) [USE_ALGORITHM_SIMPLE_EXPONENTIATION]:
    Fix for the case where BASE is negative.
    * tests/mpitests.c (test_powm): Add a test case of (-17)^6 mod 19.
    
    Signed-off-by: NIIBE Yutaka <gniibe at fsij.org>

diff --git a/mpi/mpi-pow.c b/mpi/mpi-pow.c
index 469c382..4bf0233 100644
--- a/mpi/mpi-pow.c
+++ b/mpi/mpi-pow.c
@@ -177,7 +177,7 @@ gcry_mpi_powm (gcry_mpi_t res,
     }
   MPN_COPY ( rp, bp, bsize );
   rsize = bsize;
-  rsign = bsign;
+  rsign = 0;
 
   /* Main processing.  */
   {
@@ -192,7 +192,7 @@ gcry_mpi_powm (gcry_mpi_t res,
     xp = xp_marker = mpi_alloc_limb_space( 2 * (msize + 1), msec );
 
     memset( &karactx, 0, sizeof karactx );
-    negative_result = (ep[0] & 1) && base->sign;
+    negative_result = (ep[0] & 1) && bsign;
 
     i = esize - 1;
     e = ep[i];
diff --git a/tests/mpitests.c b/tests/mpitests.c
index 1c4edb6..9d1206e 100644
--- a/tests/mpitests.c
+++ b/tests/mpitests.c
@@ -520,6 +520,25 @@ test_powm (void)
   if (gcry_mpi_cmp (res, base))
     die ("test_powm failed at %d\n", __LINE__);
 
+  /* Check for a case: base is negative and expo is even.  */
+  gcry_mpi_set_ui (base, b_int);
+  gcry_mpi_neg (base, base);
+  gcry_mpi_set_ui (exp, e_int * 2);
+  gcry_mpi_set_ui(mod, m_int);
+  gcry_mpi_powm (res, base, exp, mod);
+  /* Result should be positive and it's 7 = (-17)^6 mod 19.  */
+  if (gcry_mpi_is_neg (res) || gcry_mpi_cmp_ui (res, 7))
+    {
+      if (verbose)
+        {
+          fprintf (stderr, "is_neg: %d\n", gcry_mpi_is_neg (res));
+          fprintf (stderr, "mpi: ");
+          gcry_mpi_dump (res);
+          putc ('\n', stderr);
+        }
+      die ("test_powm failed for negative base at %d\n", __LINE__);
+    }
+
   gcry_mpi_release (base);
   gcry_mpi_release (exp);
   gcry_mpi_release (mod);

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

Summary of changes:
 mpi/mpi-pow.c    |    4 ++--
 tests/mpitests.c |   19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 2 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