1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*
* (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>
#endif
#if defined(BOTAN_HAS_ECC_GROUP)
#include <botan/ec_group.h>
#endif
namespace Botan_Tests {
namespace {
#if defined(BOTAN_HAS_ECC_GROUP)
class ECC_Basepoint_Mul_Tests final : public Text_Based_Test
{
public:
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 base point multiply " + group_id);
const Botan::BigInt m = vars.get_req_bn("m");
const Botan::BigInt X = vars.get_req_bn("X");
const Botan::BigInt Y = vars.get_req_bn("Y");
Botan::EC_Group group(Botan::OID::from_string(group_id));
const Botan::PointGFp& base_point = group.get_base_point();
const Botan::PointGFp p1 = base_point * m;
result.test_eq("p1 affine X", p1.get_affine_x(), X);
result.test_eq("p1 affine Y", p1.get_affine_y(), Y);
std::vector<Botan::BigInt> ws;
const Botan::PointGFp p2 = group.blinded_base_point_multiply(m, Test::rng(), ws);
result.test_eq("p2 affine X", p2.get_affine_x(), X);
result.test_eq("p2 affine Y", p2.get_affine_y(), Y);
const Botan::PointGFp p3 = group.blinded_var_point_multiply(base_point, m, Test::rng(), ws);
result.test_eq("p3 affine X", p3.get_affine_x(), X);
result.test_eq("p3 affine Y", p3.get_affine_y(), Y);
return result;
}
};
BOTAN_REGISTER_TEST("pubkey", "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("pubkey", "ecc_varmul", ECC_Varpoint_Mul_Tests);
#endif
}
}
|