aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/unit_ecc.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-08-02 17:33:55 -0400
committerJack Lloyd <[email protected]>2018-08-02 17:33:55 -0400
commit5ed67bfbf96a80af77807443177b4925e0a94797 (patch)
tree11194ab8d279f2f4da59828eccfd6136b171d2da /src/tests/unit_ecc.cpp
parent408512a65b169786777846a825b5b010bdb73aaa (diff)
Misc EC_Group tests
Diffstat (limited to 'src/tests/unit_ecc.cpp')
-rw-r--r--src/tests/unit_ecc.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/tests/unit_ecc.cpp b/src/tests/unit_ecc.cpp
index 5802a4d66..b60845212 100644
--- a/src/tests/unit_ecc.cpp
+++ b/src/tests/unit_ecc.cpp
@@ -119,7 +119,7 @@ std::vector<Test::Result> ECC_Randomized_Tests::run()
Botan::EC_Group group(group_name);
- const Botan::PointGFp& pt = create_random_point(Test::rng(), group);
+ const Botan::PointGFp pt = create_random_point(Test::rng(), group);
const Botan::BigInt& group_order = group.get_order();
std::vector<Botan::BigInt> blind_ws;
@@ -292,6 +292,14 @@ class EC_Group_Tests : public Test
result.test_eq("EC_Group has correct bit size", group.get_p().bits(), group.get_p_bits());
result.test_eq("EC_Group has byte size", group.get_p().bytes(), group.get_p_bytes());
+ result.confirm("Same group is same", group == group);
+
+ const Botan::EC_Group copy(group.get_p(), group.get_a(), group.get_b(),
+ group.get_g_x(), group.get_g_y(),
+ group.get_order(), group.get_cofactor());
+
+ result.confirm("Same group is same even with copy", group == copy);
+
const auto pt_mult_by_order = group.get_base_point() * group.get_order();
result.confirm("Multiplying point by the order results in zero point", pt_mult_by_order.is_zero());
@@ -379,7 +387,13 @@ class EC_Group_Tests : public Test
void test_zeropoint(Test::Result& result, const Botan::EC_Group& group)
{
- const Botan::PointGFp zero = group.zero_point();
+ Botan::PointGFp zero = group.zero_point();
+
+ result.test_throws("Zero point throws", "Cannot convert zero point to affine",
+ [&]() { zero.get_affine_x(); });
+ result.test_throws("Zero point throws", "Cannot convert zero point to affine",
+ [&]() { zero.get_affine_y(); });
+
const Botan::PointGFp p1 = group.get_base_point() * 2;
result.confirm("point is on the curve", p1.on_the_curve());
@@ -558,10 +572,7 @@ Test::Result test_basic_operations()
result.test_eq("point addition", simplePlus, exp_simplePlus);
const Botan::PointGFp simpleMinus = p1 - p0;
- const Botan::PointGFp exp_simpleMinus= secp160r1.point(Botan::BigInt("425826231723888350446541592701409065913635568770"),
- Botan::BigInt("203520114162904107873991457957346892027982641970"));
-
- result.test_eq("point subtraction", simpleMinus, exp_simpleMinus);
+ result.test_eq("point subtraction", simpleMinus, p_G);
const Botan::PointGFp simpleMult = p1 * 123456789;
@@ -579,12 +590,9 @@ Test::Result test_enc_dec_compressed_160()
// Test for compressed conversion (02/03) 160bit
Botan::EC_Group secp160r1("secp160r1");
-
const std::vector<uint8_t> G_comp = Botan::hex_decode("024A96B5688EF573284664698968C38BB913CBFC82");
-
const Botan::PointGFp p = secp160r1.OS2ECP(G_comp);
-
- std::vector<uint8_t> sv_result = p.encode(Botan::PointGFp::COMPRESSED);
+ const std::vector<uint8_t> sv_result = p.encode(Botan::PointGFp::COMPRESSED);
result.test_eq("result", sv_result, G_comp);
return result;