From b046a916a4f3a79d69fb01e45e05ed51ce3e9dcd Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Sat, 2 Sep 2017 05:38:05 -0400 Subject: Support a negative base in power_mod Closes #1168 --- src/tests/data/bn/powmod.vec | 22 ++++++++++++++++++++++ src/tests/test_bigint.cpp | 6 ++++++ 2 files changed, 28 insertions(+) (limited to 'src/tests') diff --git a/src/tests/data/bn/powmod.vec b/src/tests/data/bn/powmod.vec index 024a2d36b..2165ed52c 100644 --- a/src/tests/data/bn/powmod.vec +++ b/src/tests/data/bn/powmod.vec @@ -216,3 +216,25 @@ Exponent = 0x2000000000000000000000000000000000000000000000000000000000060800000 Modulus = 0x40000000000000000000000000000000000000000000000000000000000c100000000000000fffd Output = 0x9943fa648c48cb4cd01756bed11e3382aca74d84fb0bf8cf8d56cd4524f80538d4888cbd23b8e2 +# Check support for negative base (GH #1168) + +Base = -5 +Exponent = 10 +Modulus = 37 +Output = 30 + +Base = -5 +Exponent = 11 +Modulus = 37 +Output = 35 + +Base = -0xFFE0000FFF80003F00000000FF +Exponent = 0x7FF7C00200 +Modulus = 0xFFFFFFC00000000000003FFFFF +Output = 0xCAEB2FF794C6783C4F1F06E684 + +Base = -0xF9FFFFF000000FFFFFFFFFFFFFFFC0000000 +Exponent = 0x83FFFF000000000000000003FFFFFFFFFFFF +Modulus = 0xFFE007FFF9F83FFFFF8F000FFFFFFFFFFFFF +Output = 7559902530247723476756105022122181875899018 + diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp index 0dc07aabf..61be15d15 100644 --- a/src/tests/test_bigint.cpp +++ b/src/tests/test_bigint.cpp @@ -492,6 +492,12 @@ class BigInt_Powmod_Test : public Text_Based_Test result.test_eq("power_mod", Botan::power_mod(base, exponent, modulus), expected); + /* + * Only the basic power_mod interface supports negative base + */ + if(base.is_negative()) + return result; + Botan::Power_Mod pow_mod1(modulus); pow_mod1.set_base(base); -- cgit v1.2.3