aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-09-25 17:31:49 -0400
committerJack Lloyd <[email protected]>2017-09-25 17:31:49 -0400
commit549c4dcc4116f3947e47f613781c0441ae499c1a (patch)
treef14fd65cf0b44fa8dbf04a517a7d33fbd63172af /src
parent1858171bb142103c79e7f44603b8213d22b38d90 (diff)
Add a GCD test
Diffstat (limited to 'src')
-rw-r--r--src/tests/data/bn/divide.vec8
-rw-r--r--src/tests/data/bn/gcd.vec4
-rw-r--r--src/tests/test_bigint.cpp22
3 files changed, 34 insertions, 0 deletions
diff --git a/src/tests/data/bn/divide.vec b/src/tests/data/bn/divide.vec
index 481c0fc6c..a5470f41d 100644
--- a/src/tests/data/bn/divide.vec
+++ b/src/tests/data/bn/divide.vec
@@ -1,4 +1,8 @@
[Division]
+In1 = 0x1234567
+In2 = 0x103
+Output = 73701
+
In1 = 0x100000000000000000000000000000000000000000000000000000000000000000000000
In2 = 0x1000000000000000000000000000000000000000000000000000000000000000000000
Output = 0x100
@@ -7,6 +11,10 @@ In1 = 0x100000000000000000000000000000000000000000000000000000000000000000000000
In2 = 0x1110000000000000000000000000000000000000000000000000000000000000000000
Output = 0xF0
+In1 = 0x8000000000000000000103
+In2 = 0x1234567
+Output = 8106479557646752034
+
In1 = 0x1A923B3406CBE81B093CE418F6A73107F504502B2E3D1B200762FCF6062723DE405CAB0AEA00000000000000000000000000000000
In2 = 0x184F03E93FF9F4DAA797ED6E38ED64BF6A1F010000000000000000
Output = 0x117D3DB34AD005954459BE9ABEDD0E5DEB4EA0000000000000000
diff --git a/src/tests/data/bn/gcd.vec b/src/tests/data/bn/gcd.vec
new file mode 100644
index 000000000..c7f630231
--- /dev/null
+++ b/src/tests/data/bn/gcd.vec
@@ -0,0 +1,4 @@
+[GCD]
+X = 259
+Y = 4943984437
+GCD = 259
diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp
index 6151d72de..80d95a8ee 100644
--- a/src/tests/test_bigint.cpp
+++ b/src/tests/test_bigint.cpp
@@ -426,6 +426,28 @@ class BigInt_Mod_Test final : public Text_Based_Test
BOTAN_REGISTER_TEST("bn_mod", BigInt_Mod_Test);
+class BigInt_GCD_Test final : public Text_Based_Test
+ {
+ public:
+ BigInt_GCD_Test() : Text_Based_Test("bn/gcd.vec", "X,Y,GCD") {}
+
+ Test::Result run_one_test(const std::string&, const VarMap& vars) override
+ {
+ Test::Result result("BigInt Mod");
+
+ const BigInt x = get_req_bn(vars, "X");
+ const BigInt y = get_req_bn(vars, "Y");
+ const BigInt expected = get_req_bn(vars, "GCD");
+
+ const BigInt g = Botan::gcd(x, y);
+
+ result.test_eq("gcd", expected, g);
+ return result;
+ }
+ };
+
+BOTAN_REGISTER_TEST("bn_gcd", BigInt_GCD_Test);
+
class BigInt_Lshift_Test final : public Text_Based_Test
{
public: