aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_bigint.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test_bigint.cpp')
-rw-r--r--src/tests/test_bigint.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp
index ad0af03f4..33c617239 100644
--- a/src/tests/test_bigint.cpp
+++ b/src/tests/test_bigint.cpp
@@ -36,6 +36,7 @@ class BigInt_Unit_Tests final : public Test
results.push_back(test_random_prime());
results.push_back(test_encode());
results.push_back(test_bigint_io());
+ results.push_back(test_get_substring());
return results;
}
@@ -206,6 +207,34 @@ class BigInt_Unit_Tests final : public Test
return result;
}
+ Test::Result test_get_substring()
+ {
+ const size_t trials = 1000;
+
+ Test::Result result("BigInt get_substring");
+
+ const Botan::BigInt r(Test::rng(), 250);
+
+ for(size_t s = 1; s <= 32; ++s)
+ {
+ for(size_t trial = 0; trial != trials; ++trial)
+ {
+ const size_t offset = Test::rng().next_byte();
+
+ const uint32_t val = r.get_substring(offset, s);
+
+ Botan::BigInt t = r >> offset;
+ t.mask_bits(s);
+
+ const uint32_t cmp = t.to_u32bit();
+
+ result.test_eq("Same value", size_t(val), size_t(cmp));
+ }
+ }
+
+ return result;
+ }
+
Test::Result test_bigint_io()
{
Test::Result result("BigInt IO operators");