2
* (C) 2015,2016 Jack Lloyd
4
* Botan is released under the Simplified BSD License (see license.txt)
11
#include <botan/curve_gfp.h>
12
#include <botan/ec_group.h>
13
#include <botan/reducer.h>
17
inline std::ostream& operator<<(std::ostream& o, const Botan::PointGFp& point)
19
o << point.get_affine_x() << "," << point.get_affine_y();
23
void check_ecc_math(const Botan::EC_Group& group,
24
const uint8_t in[], size_t len)
26
// These depend only on the group, which is also static
27
static const Botan::PointGFp base_point = group.get_base_point();
28
static Botan::Blinded_Point_Multiply blind(base_point, group.get_order(), 4);
30
const size_t hlen = len / 2;
31
const Botan::BigInt a = Botan::BigInt::decode(in, hlen);
32
const Botan::BigInt b = Botan::BigInt::decode(in + hlen, len - hlen);
34
const Botan::BigInt c = a + b;
36
const Botan::PointGFp P = base_point * a;
37
const Botan::PointGFp Q = base_point * b;
38
const Botan::PointGFp R = base_point * c;
40
const Botan::PointGFp A1 = P + Q;
41
const Botan::PointGFp A2 = Q + P;
43
FUZZER_ASSERT_EQUAL(A1, A2);
45
const Botan::PointGFp P1 = blind.blinded_multiply(a, fuzzer_rng());
46
const Botan::PointGFp Q1 = blind.blinded_multiply(b, fuzzer_rng());
47
const Botan::PointGFp R1 = blind.blinded_multiply(c, fuzzer_rng());
49
const Botan::PointGFp S1 = P1 + Q1;
50
const Botan::PointGFp S2 = Q1 + P1;
52
FUZZER_ASSERT_EQUAL(S1, S2);
53
FUZZER_ASSERT_EQUAL(S1, A1);