Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_groups.cpp
Go to the documentation of this file.
1
11#ifdef CURVE_BN128
13#endif
14#include <sstream>
15
17
18using namespace libff;
19
20#ifndef NDEBUG
21template<typename GroupT>
23{
24 GroupT base, el, result;
25
26 base = GroupT::zero();
27 el = GroupT::zero();
28 el.to_special();
29 result = base.mixed_add(el);
30 assert(result == base + el);
31
32 base = GroupT::zero();
33 el = GroupT::random_element();
34 el.to_special();
35 result = base.mixed_add(el);
36 assert(result == base + el);
37
38 base = GroupT::random_element();
39 el = GroupT::zero();
40 el.to_special();
41 result = base.mixed_add(el);
42 assert(result == base + el);
43
44 base = GroupT::random_element();
45 el = GroupT::random_element();
46 el.to_special();
47 result = base.mixed_add(el);
48 assert(result == base + el);
49
50 base = GroupT::random_element();
51 el = base;
52 el.to_special();
53 result = base.mixed_add(el);
54 assert(result == base.dbl());
55}
56
57template<typename GroupT>
59{
60 bigint<1> rand1 = bigint<1>("76749407");
61 bigint<1> rand2 = bigint<1>("44410867");
62 bigint<1> randsum = bigint<1>("121160274");
63
64 GroupT zero = GroupT::zero();
65 assert(zero == zero);
66 GroupT one = GroupT::one();
67 assert(one == one);
68 GroupT two = bigint<1>(2l) * GroupT::one();
69 assert(two == two);
70 GroupT five = bigint<1>(5l) * GroupT::one();
71
72 GroupT three = bigint<1>(3l) * GroupT::one();
73 GroupT four = bigint<1>(4l) * GroupT::one();
74
75 assert(two+five == three+four);
76
77 GroupT a = GroupT::random_element();
78 GroupT b = GroupT::random_element();
79
80 assert(one != zero);
81 assert(a != zero);
82 assert(a != one);
83
84 assert(b != zero);
85 assert(b != one);
86
87 assert(a.dbl() == a + a);
88 assert(b.dbl() == b + b);
89 assert(one.add(two) == three);
90 assert(two.add(one) == three);
91 assert(a + b == b + a);
92 assert(a - a == zero);
93 assert(a - b == a + (-b));
94 assert(a - b == (-b) + a);
95
96 // handle special cases
97 assert(zero + (-a) == -a);
98 assert(zero - a == -a);
99 assert(a - zero == a);
100 assert(a + zero == a);
101 assert(zero + a == a);
102
103 assert((a + b).dbl() == (a + b) + (b + a));
104 assert(bigint<1>("2") * (a + b) == (a + b) + (b + a));
105
106 assert((rand1 * a) + (rand2 * a) == (randsum * a));
107
108 assert(GroupT::order() * a == zero);
109 assert(GroupT::order() * one == zero);
110 assert((GroupT::order() * a) - a != zero);
111 assert((GroupT::order() * one) - one != zero);
112
114}
115
116template<typename GroupT>
118{
119 GroupT a = GroupT::random_element();
120 assert((GroupT::base_field_char()*a) == a.mul_by_q());
121}
122
123template<typename GroupT>
125{
126 GroupT g = GroupT::zero();
127
128 for (size_t i = 0; i < 1000; ++i)
129 {
130 std::stringstream ss;
131 ss << g;
132 GroupT gg;
133 ss >> gg;
134 assert(g == gg);
135 /* use a random point in next iteration */
136 g = GroupT::random_element();
137 }
138}
139
178
179#else // NDEBUG
180
181int main()
182{
183 printf("All tests here depend on assert() which is disabled by -DNDEBUG. Please recompile and run again.\n");
184}
185#endif // NDEBUG
std::string one()
static void init_public_params()
static void init_public_params()
Definition bn128_pp.cpp:13
static void init_public_params()
static void init_public_params()
Definition mnt4_pp.cpp:18
static void init_public_params()
Definition mnt6_pp.cpp:18
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
int main(void)
void test_group()
void test_output()
void test_mul_by_q()
void test_mixed_add()