Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
loop_test.cpp
Go to the documentation of this file.
1/*
2 loop test
3*/
4#include "bn.h"
5#include "test_point.hpp"
6
7using namespace bn;
8using namespace ecop;
9
10int main()
11{
12#ifdef BN_SUPPORT_SNARK
13 puts("snark");
14 bn::CurveParam cp = bn::CurveSNARK1;
15#else
16 puts("fp254BNb");
18#endif
19 // init my library
21 // prepair a generator
22 const Point& pt = selectPoint(cp);
23 const Ec2 g2(
24 Fp2(Fp(pt.g2.aa), Fp(pt.g2.ab)),
25 Fp2(Fp(pt.g2.ba), Fp(pt.g2.bb))
26 );
27 const Ec1 g1(pt.g1.a, pt.g1.b);
28 Fp12 e, ea, ea1, ea2;
29 Ec2 g2a;
30 Ec1 g1a;
31 // calc e : G2 x G1 -> G3 pairing
32 opt_atePairing(e, g2, g1); // e = e(g2, g1)
33 mie::Vuint a("0x18b48dddfb2f81cc829b4b9acd393ccb1e90909aabe126bcdbe6a96438eaf313");
34 for (int i = 0; i < 3000; i++) {
35 ea = power(e, a);
36 g1a = g1 * a;
37 g2a = g2 * a;
38 opt_atePairing(ea1, g2, g1a); // ea1 = e(g2, g1a)
39 opt_atePairing(ea2, g2a, g1); // ea2 = e(g2a, g1)
40 if (ea != ea1 || ea != ea2) {
41 printf("ERR i=%d\n", i);
42 PUT(a);
43 PUT(ea);
44 PUT(ea1);
45 PUT(ea2);
46 exit(1);
47 }
48 a -= 1;
49 }
50 puts("ok");
51}
BN parameter.
#define PUT(x)
Definition java_api.cpp:8
int main()
Definition loop_test.cpp:10
Definition bn.h:56
mie::Fp Fp
Definition bn.h:2952
const CurveParam CurveFp254BNb
Definition bn.h:84
void opt_atePairing(Fp12T< Fp6T< Fp2T< Fp > > > &f, const Fp2T< Fp > Q[2], const Fp P[2])
Definition bn.h:2720
Fp2T< Fp > Fp2
Definition bn.h:2954
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
struct Point::G2 g2
struct Point::G1 g1
static void init(const CurveParam &cp, int mode=-1, bool useMulx=true)
Definition bn.h:206
const Point & selectPoint(const bn::CurveParam &cp)