Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
java_api.cpp File Reference
#include "../java/bn254_if.hpp"
#include <iostream>
Include dependency graph for java_api.cpp:

Go to the source code of this file.

Classes

struct  G2
 

Macros

#define PUT(x)
 

Functions

void assertBool (const char *msg, bool b)
 
template<class T , class S >
void assertEqual (const char *msg, const T &a, const S &b)
 
int main ()
 

Variables

struct G2 g2c
 

Macro Definition Documentation

◆ PUT

#define PUT ( x)
Value:
std::cout << #x "\t=" << (x).toString() << std::endl

Definition at line 8 of file java_api.cpp.

Function Documentation

◆ assertBool()

void assertBool ( const char * msg,
bool b )

Definition at line 12 of file java_api.cpp.

13{
14 if (b) {
15 printf("%s : ok\n", msg);
16 } else {
17 printf("%s : ng\n", msg);
18 errNum++;
19 }
20}
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30
Here is the caller graph for this function:

◆ assertEqual()

template<class T , class S >
void assertEqual ( const char * msg,
const T & a,
const S & b )

Definition at line 23 of file java_api.cpp.

24{
25 if (a.equals(b)) {
26 printf("%s : ok\n", msg);
27 } else {
28 PUT(a);
29 PUT(b);
30 errNum++;
31 }
32}
#define PUT(x)
Definition java_api.cpp:8
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
Here is the caller graph for this function:

◆ main()

int main ( void )

Definition at line 46 of file java_api.cpp.

47{
48 SystemInit();
49 const Ec1 g1(-1, 1);
50 const Ec2 g2(
51 Fp2(Fp(g2c.aa), Fp(g2c.ab)),
52 Fp2(Fp(g2c.ba), Fp(g2c.bb))
53 );
54 // assertBool g2 and g1 on curve
55 assertBool("g1 is on EC", g1.isValid());
56 assertBool("g2 is on twist EC", g2.isValid());
57 puts("order of group");
58 const Mpz& r = GetParamR();
59 PUT(r);
60 {
61 Ec1 t = g1;
62 t.mul(r);
63 assertBool("orgder of g1 == r", t.isZero());
64 }
65 {
66 Ec2 t = g2;
67 t.mul(r);
68 assertBool("order of g2 == r", t.isZero());
69 }
70 const Mpz a("123456789012345");
71 const Mpz b("998752342342342342424242421");
72
73 // scalar-multiplication sample
74 {
75 Mpz c = a;
76 c.add(b);
77 Ec1 Pa = g1; Pa.mul(a);
78 Ec1 Pb = g1; Pb.mul(b);
79 Ec1 Pc = g1; Pc.mul(c);
80 Ec1 out = Pa;
81 out.add(Pb);
82
83 assertEqual("check g1 * c = g1 * a + g1 * b", Pc, out);
84 }
85
86 Fp12 e;
87 // calc e : G2 x G1 -> G3 pairing
88 e.pairing(g2, g1); // e = e(g2, g1)
89 PUT(e);
90 {
91 Fp12 t = e;
92 t.power(r);
93 assertEqual("order of e == r", t, Fp12(1));
94 }
95 Ec2 g2a = g2;
96 g2a.mul(a);
97 Fp12 ea1;
98 ea1.pairing(g2a, g1);
99 Fp12 ea2 = e;
100 ea2.power(a); // ea2 = e^a
101 assertEqual("e(g2 * a, g1) = e(g2, g1)^a", ea1, ea2);
102
103 Ec1 g1b = g1;
104 g1b.mul(b);
105 Fp12 eb1;
106 eb1.pairing(g2, g1b); // eb1 = e(g2, g1b)
107 Fp12 eb2 = e;
108 eb2.power(b); // eb2 = e^b
109 assertEqual("e(g2a, g1 * b) = e(g2, g1)^b", eb1, eb2);
110
111 Ec1 q1 = g1;
112 q1.mul(12345);
113 assertBool("q1 is on EC", q1.isValid());
114 Fp12 e1, e2;
115 e1.pairing(g2, g1); // e1 = e(g2, g1)
116 e2.pairing(g2, q1); // e2 = e(g2, q1)
117 Ec1 q2 = g1;
118 q2.add(q1);
119 e.pairing(g2, q2); // e = e(g2, q2)
120 e1.mul(e2);
121 assertEqual("e = e1 * e2", e, e1);
122 /*
123 reduce one copy as the following
124 */
125 g2a = g2;
126 g2a.mul(a);
127 g1b = g1;
128 g1b.mul(b);
129 Ec2 g2at = g2; g2at.mul(a);
130 Ec1 g1bt = g1; g1bt.mul(b);
131 assertEqual("g2a == g2 * a", g2a, g2at);
132 assertEqual("g1b == g1 * b", g1b, g1bt);
133 printf("errNum = %d\n", errNum);
134}
const Mpz & GetParamR()
Definition bn254_if.hpp:250
void SystemInit()
Definition bn254_if.hpp:14
const mie::Vuint & r
Definition bn.cpp:28
bool isZero() const
Definition bn254_if.hpp:186
bool isValid() const
Definition bn254_if.hpp:165
void mul(const Mpz &rhs)
Definition bn254_if.hpp:192
void add(const Ec1 &rhs)
Definition bn254_if.hpp:190
void mul(const Mpz &rhs)
Definition bn254_if.hpp:239
bool isZero() const
Definition bn254_if.hpp:233
void mul(const Fp12 &rhs)
Definition bn254_if.hpp:143
void pairing(const Ec2 &ec2, const Ec1 &ec1)
Definition bn254_if.hpp:245
void power(const Mpz &x)
Definition bn254_if.hpp:145
void add(const Mpz &rhs)
Definition bn254_if.hpp:50
void assertBool(const char *msg, bool b)
Definition java_api.cpp:12
void assertEqual(const char *msg, const T &a, const S &b)
Definition java_api.cpp:23
struct G2 g2c
Here is the call graph for this function:

Variable Documentation

◆ g2c

struct G2 g2c
Initial value:
= {
"12723517038133731887338407189719511622662176727675373276651903807414909099441",
"4168783608814932154536427934509895782246573715297911553964171371032945126671",
"13891744915211034074451795021214165905772212241412891944830863846330766296736",
"7937318970632701341203597196594272556916396164729705624521405069090520231616",
}