aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_mp.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-02-20 06:19:58 -0500
committerJack Lloyd <[email protected]>2016-02-20 12:33:11 -0500
commitf794b638a4059d3c004f092b6bd89d27cf4ffefa (patch)
tree2e773b0ff4da8f953c78e4bcf3fa691af1df80ad /src/tests/test_mp.cpp
parent99f2c04783b0a33d606531b73b1b3d0d1f52daa3 (diff)
For odd moduli use a input-independent modular inverse algorithm.
Also adds a (not const time) implementation of almost Montgomery reduction.
Diffstat (limited to 'src/tests/test_mp.cpp')
-rw-r--r--src/tests/test_mp.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/tests/test_mp.cpp b/src/tests/test_mp.cpp
index b52d93406..cbaf465a4 100644
--- a/src/tests/test_mp.cpp
+++ b/src/tests/test_mp.cpp
@@ -26,6 +26,7 @@ class MP_Unit_Tests : public Test
results.push_back(test_cnd_swap());
results.push_back(test_cnd_add());
results.push_back(test_cnd_sub());
+ results.push_back(test_cnd_abs());
return results;
}
@@ -75,6 +76,37 @@ class MP_Unit_Tests : public Test
return result;
}
+ Result test_cnd_abs()
+ {
+ Result result("bigint_cnd_abs");
+
+ using namespace Botan;
+
+ word x1 = MP_WORD_MAX;
+ bigint_cnd_abs(1, &x1, 1);
+ result.test_int_eq(x1, 1, "Abs");
+
+ x1 = 0;
+ bigint_cnd_abs(1, &x1, 1);
+ result.test_int_eq(x1, 0, "Abs");
+
+ x1 = 1;
+ bigint_cnd_abs(1, &x1, 1);
+ result.test_int_eq(x1, MP_WORD_MAX, "Abs");
+
+ x1 = 1;
+ bigint_cnd_abs(0, &x1, 1);
+ result.test_int_eq(x1, 1, "No change");
+
+ word x2[2] = { MP_WORD_MAX, MP_WORD_MAX };
+
+ bigint_cnd_abs(1, x2, 2);
+ result.test_int_eq(x2[0], 1, "Abs");
+ result.test_int_eq(x2[1], 0, "Abs");
+
+ return result;
+ }
+
Result test_cnd_swap()
{
Result result("bigint_cnd_swap");