forked from AntelopeIO/leap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbls_primitives_test.cpp
138 lines (128 loc) · 5.54 KB
/
bls_primitives_test.cpp
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "bls_primitives_test.hpp"
#include <eosio/transaction.hpp>
using namespace eosio;
void bls_primitives_test::testg1add(const std::vector<uint8_t>& op1, const std::vector<uint8_t>& op2, const std::vector<uint8_t>& res, int32_t expected_error)
{
bls_g1 r;
int32_t error = internal_use_do_not_use::bls_g1_add(
reinterpret_cast<const char*>(op1.data()),
sizeof(bls_g1),
reinterpret_cast<const char*>(op2.data()),
sizeof(bls_g1),
reinterpret_cast<char*>(r),
sizeof(bls_g1)
);
check(error == expected_error, "bls_g1_add: Error does not match");
check(0 == std::memcmp(r, res.data(), sizeof(bls_g1)), "bls_g1_add: Result does not match");
}
void bls_primitives_test::testg2add(const std::vector<uint8_t>& op1, const std::vector<uint8_t>& op2, const std::vector<uint8_t>& res, int32_t expected_error)
{
bls_g2 r;
int32_t error = internal_use_do_not_use::bls_g2_add(
reinterpret_cast<const char*>(op1.data()),
sizeof(bls_g2),
reinterpret_cast<const char*>(op2.data()),
sizeof(bls_g2),
reinterpret_cast<char*>(r),
sizeof(bls_g2)
);
check(error == expected_error, "bls_g2_add: Error does not match");
check(0 == std::memcmp(r, res.data(), sizeof(bls_g2)), "bls_g2_add: Result does not match");
}
void bls_primitives_test::testg1mul(const std::vector<uint8_t>& point, const std::vector<uint8_t>& scalar, const std::vector<uint8_t>& res, int32_t expected_error)
{
bls_g1 r;
int32_t error = internal_use_do_not_use::bls_g1_mul(
reinterpret_cast<const char*>(point.data()),
sizeof(bls_g1),
reinterpret_cast<const char*>(scalar.data()),
sizeof(bls_scalar),
reinterpret_cast<char*>(r),
sizeof(bls_g1)
);
check(error == expected_error, "bls_g1_mul: Error does not match");
check(0 == std::memcmp(r, res.data(), sizeof(bls_g1)), "bls_g1_mul: Result does not match");
}
void bls_primitives_test::testg2mul(const std::vector<uint8_t>& point, const std::vector<uint8_t>& scalar, const std::vector<uint8_t>& res, int32_t expected_error)
{
bls_g2 r;
int32_t error = internal_use_do_not_use::bls_g2_mul(
reinterpret_cast<const char*>(point.data()),
sizeof(bls_g2),
reinterpret_cast<const char*>(scalar.data()),
sizeof(bls_scalar),
reinterpret_cast<char*>(r),
sizeof(bls_g2)
);
check(error == expected_error, "bls_g2_mul: Error does not match");
check(0 == std::memcmp(r, res.data(), sizeof(bls_g2)), "bls_g2_mul: Result does not match");
}
void bls_primitives_test::testg1exp(const std::vector<uint8_t>& points, const std::vector<uint8_t>& scalars, const uint32_t num, const std::vector<uint8_t>& res, int32_t expected_error)
{
bls_g1 r;
int32_t error = internal_use_do_not_use::bls_g1_exp(
reinterpret_cast<const char*>(points.data()),
num * sizeof(bls_g1),
reinterpret_cast<const char*>(scalars.data()),
num * sizeof(bls_scalar),
num,
reinterpret_cast<char*>(r),
sizeof(bls_g1)
);
check(error == expected_error, "bls_g1_exp: Error does not match");
check(0 == std::memcmp(r, res.data(), sizeof(bls_g1)), "bls_g1_exp: Result does not match");
}
void bls_primitives_test::testg2exp(const std::vector<uint8_t>& points, const std::vector<uint8_t>& scalars, const uint32_t num, const std::vector<uint8_t>& res, int32_t expected_error)
{
bls_g2 r;
int32_t error = internal_use_do_not_use::bls_g2_exp(
reinterpret_cast<const char*>(points.data()),
num * sizeof(bls_g2),
reinterpret_cast<const char*>(scalars.data()),
num * sizeof(bls_scalar),
num,
reinterpret_cast<char*>(r),
sizeof(bls_g2)
);
check(error == expected_error, "bls_g2_exp: Error does not match");
check(0 == std::memcmp(r, res.data(), sizeof(bls_g2)), "bls_g2_exp: Result does not match");
}
void bls_primitives_test::testpairing(const std::vector<uint8_t>& g1_points, const std::vector<uint8_t>& g2_points, const uint32_t num, const std::vector<uint8_t>& res, int32_t expected_error)
{
bls_gt r;
int32_t error = internal_use_do_not_use::bls_pairing(
reinterpret_cast<const char*>(g1_points.data()),
num * sizeof(bls_g1),
reinterpret_cast<const char*>(g2_points.data()),
num * sizeof(bls_g2),
num,
reinterpret_cast<char*>(r),
sizeof(bls_gt)
);
check(error == expected_error, "bls_pairing: Error does not match");
check(0 == std::memcmp(r, res.data(), sizeof(bls_gt)), "bls_pairing: Result does not match");
}
void bls_primitives_test::testg1map(const std::vector<uint8_t>& e, const std::vector<uint8_t>& res, int32_t expected_error)
{
bls_g1 r;
int32_t error = internal_use_do_not_use::bls_g1_map(
reinterpret_cast<const char*>(e.data()),
sizeof(bls_fp),
reinterpret_cast<char*>(r),
sizeof(bls_g1)
);
check(error == expected_error, "bls_g1_map: Error does not match");
check(0 == std::memcmp(r, res.data(), sizeof(bls_g1)), "bls_g1_map: Result does not match");
}
void bls_primitives_test::testg2map(const std::vector<uint8_t>& e, const std::vector<uint8_t>& res, int32_t expected_error)
{
bls_g2 r;
int32_t error = internal_use_do_not_use::bls_g2_map(
reinterpret_cast<const char*>(e.data()),
sizeof(bls_fp2),
reinterpret_cast<char*>(r),
sizeof(bls_g2)
);
check(error == expected_error, "bls_g2_map: Error does not match");
check(0 == std::memcmp(r, res.data(), sizeof(bls_g2)), "bls_g2_map: Result does not match");
}