aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_ecc_pointmul.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2019-09-12 09:31:26 -0400
committerJack Lloyd <[email protected]>2019-09-12 09:35:43 -0400
commit321a50789e6eeda6898af114492445f0882ee70f (patch)
treea1f27ca37d1ba8cecc510813b7112108393a4a2a /src/tests/test_ecc_pointmul.cpp
parent71a92630ac1e3d995a017610e82a62ad6c54d246 (diff)
Support loading an EC point with affine zero coordinates.
For example it is possible to construct a point with x coordinate of zero whenenver b has a square root modulo p. Found during integration with https://github.com/catenacyber/elliptic-curve-differential-fuzzer
Diffstat (limited to 'src/tests/test_ecc_pointmul.cpp')
-rw-r--r--src/tests/test_ecc_pointmul.cpp55
1 files changed, 47 insertions, 8 deletions
diff --git a/src/tests/test_ecc_pointmul.cpp b/src/tests/test_ecc_pointmul.cpp
index 460c43ee5..0e4e18015 100644
--- a/src/tests/test_ecc_pointmul.cpp
+++ b/src/tests/test_ecc_pointmul.cpp
@@ -1,28 +1,29 @@
/*
-* (C) 2014,2015 Jack Lloyd
+* (C) 2014,2015,2019 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include "tests.h"
-#if defined(BOTAN_HAS_ECDSA)
- #include <botan/ecdsa.h>
+#if defined(BOTAN_HAS_ECC_GROUP)
+ #include <botan/ec_group.h>
#endif
namespace Botan_Tests {
namespace {
-#if defined(BOTAN_HAS_ECDSA)
-class ECC_Pointmult_Tests final : public Text_Based_Test
+#if defined(BOTAN_HAS_ECC_GROUP)
+
+class ECC_Basepoint_Mul_Tests final : public Text_Based_Test
{
public:
- ECC_Pointmult_Tests() : Text_Based_Test("pubkey/ecc.vec", "m,X,Y") {}
+ ECC_Basepoint_Mul_Tests() : Text_Based_Test("pubkey/ecc_base_point_mul.vec", "m,X,Y") {}
Test::Result run_one_test(const std::string& group_id, const VarMap& vars) override
{
- Test::Result result("ECC Scalarmult " + group_id);
+ Test::Result result("ECC base point multiply " + group_id);
const Botan::BigInt m = vars.get_req_bn("m");
const Botan::BigInt X = vars.get_req_bn("X");
@@ -49,7 +50,45 @@ class ECC_Pointmult_Tests final : public Text_Based_Test
}
};
-BOTAN_REGISTER_TEST("ecc_pointmul", ECC_Pointmult_Tests);
+BOTAN_REGISTER_TEST("ecc_basemul", ECC_Basepoint_Mul_Tests);
+
+class ECC_Varpoint_Mul_Tests final : public Text_Based_Test
+ {
+ public:
+ ECC_Varpoint_Mul_Tests() : Text_Based_Test("pubkey/ecc_var_point_mul.vec", "X,Y,k,kX,kY") {}
+
+ Test::Result run_one_test(const std::string& group_id, const VarMap& vars) override
+ {
+ Test::Result result("ECC var point multiply " + group_id);
+
+ const Botan::BigInt X = vars.get_req_bn("X");
+ const Botan::BigInt Y = vars.get_req_bn("Y");
+ const Botan::BigInt k = vars.get_req_bn("k");
+ const Botan::BigInt kX = vars.get_req_bn("kX");
+ const Botan::BigInt kY = vars.get_req_bn("kY");
+
+ Botan::EC_Group group(Botan::OID::from_string(group_id));
+
+ const Botan::PointGFp pt = group.point(X, Y);
+
+ result.confirm("Input point is on the curve", pt.on_the_curve());
+
+ const Botan::PointGFp p1 = pt * k;
+ result.test_eq("p1 affine X", p1.get_affine_x(), kX);
+ result.test_eq("p1 affine Y", p1.get_affine_y(), kY);
+
+ result.confirm("Output point is on the curve", p1.on_the_curve());
+
+ std::vector<Botan::BigInt> ws;
+ const Botan::PointGFp p2 = group.blinded_var_point_multiply(pt, k, Test::rng(), ws);
+ result.test_eq("p2 affine X", p2.get_affine_x(), kX);
+ result.test_eq("p2 affine Y", p2.get_affine_y(), kY);
+
+ return result;
+ }
+ };
+
+BOTAN_REGISTER_TEST("ecc_varmul", ECC_Varpoint_Mul_Tests);
#endif