aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2019-08-01 19:34:44 -0400
committerJack Lloyd <[email protected]>2019-08-01 19:34:44 -0400
commitf988e92d6f4587f53775b4da3e984edcc79496d5 (patch)
treeab4883720831e5d68203d24ddcba0813ed6776ca /src
parent402b727b251b5f451ffb790fa29db84e5e6a06fb (diff)
Add Jacobi fn tests
Diffstat (limited to 'src')
-rw-r--r--src/tests/data/bn/jacobi.vec21
-rw-r--r--src/tests/test_bigint.cpp28
2 files changed, 49 insertions, 0 deletions
diff --git a/src/tests/data/bn/jacobi.vec b/src/tests/data/bn/jacobi.vec
new file mode 100644
index 000000000..722c237c2
--- /dev/null
+++ b/src/tests/data/bn/jacobi.vec
@@ -0,0 +1,21 @@
+# Generated by Sage
+
+A = 5
+N = 9
+J = 1
+
+A = 1
+N = 27
+J = 1
+
+A = 2
+N = 27
+J = -1
+
+A = 3
+N = 27
+J = 0
+
+A = 4
+N = 27
+J = 1
diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp
index 8c35b8238..3ea57d584 100644
--- a/src/tests/test_bigint.cpp
+++ b/src/tests/test_bigint.cpp
@@ -453,6 +453,34 @@ class BigInt_GCD_Test final : public Text_Based_Test
BOTAN_REGISTER_TEST("bn_gcd", BigInt_GCD_Test);
+class BigInt_Jacobi_Test final : public Text_Based_Test
+ {
+ public:
+ BigInt_Jacobi_Test() : Text_Based_Test("bn/jacobi.vec", "A,N,J") {}
+
+ Test::Result run_one_test(const std::string&, const VarMap& vars) override
+ {
+ Test::Result result("BigInt Jacobi");
+
+ const BigInt a = vars.get_req_bn("A");
+ const BigInt n = vars.get_req_bn("N");
+ const std::string expected = vars.get_req_str("J");
+
+ const int32_t j = Botan::jacobi(a, n);
+
+ if(j == 0)
+ result.test_eq("jacobi", expected, "0");
+ else if(j == -1)
+ result.test_eq("jacobi", expected, "-1");
+ else
+ result.test_eq("jacobi", expected, "1");
+
+ return result;
+ }
+ };
+
+BOTAN_REGISTER_TEST("bn_jacobi", BigInt_Jacobi_Test);
+
class BigInt_Lshift_Test final : public Text_Based_Test
{
public: