diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2013-12-04 10:03:57 +0900 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2013-12-04 10:31:31 +0900 |
commit | c56080c26186d25dec05f01831494c77d8d07e13 (patch) | |
tree | e2957ceb59382e54d7d438a472782eb519e53933 /tests/mpitests.c | |
parent | 2ff86db2e1b0f6cc22a1ca86037b526c5fa3be51 (diff) | |
download | libgcrypt-c56080c26186d25dec05f01831494c77d8d07e13.tar.gz |
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@fsij.org>
Diffstat (limited to 'tests/mpitests.c')
-rw-r--r-- | tests/mpitests.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/mpitests.c b/tests/mpitests.c index 1c4edb66..9d1206e5 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); |