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
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
extern crate libc;
use self::libc::{c_void};
use fp12::wrappers::*;
use ecp::wrappers::*;
use ecp2::wrappers::*;
extern {
pub fn PAIR_ate(r: *mut FP12, P: *mut ECP2, Q: *mut ECP) -> c_void;
pub fn PAIR_fexp(r: *const FP12) -> c_void;
}
#[cfg(test)]
mod tests {
use super::*;
use big::wrappers::*;
use fp2::wrappers::*;
#[test]
fn test_pair() {
let mut a: BIG = BIG::default();
let mut b: BIG = BIG::default();
let mut xa: BIG = BIG::default();
let mut xb: BIG = BIG::default();
let mut ya: BIG = BIG::default();
let mut yb: BIG = BIG::default();
let mut P: ECP2 = Default::default();
let mut Q: ECP = Default::default();
let mut g: FP12 = Default::default();
let mut x: FP2 = Default::default();
let mut y: FP2 = Default::default();
let mut X: FP2 = Default::default();
unsafe {
BIG_rcopy(&mut a, &CURVE_Fra);
BIG_rcopy(&mut b, &CURVE_Frb);
FP2_from_BIGs(&mut X, &a, &b);
BIG_rcopy(&mut xa, &CURVE_Gx);
BIG_rcopy(&mut ya, &CURVE_Gy);
ECP_set(&mut Q, &xa, &ya);
}
if Q.inf != 0 {
println!("Failed to set - point not on curve");
} else {
println!("G1 set success");
}
print!("Q= ");
unsafe {
ECP_output(&Q);
}
println!("");
unsafe {
BIG_rcopy(&mut xa, &CURVE_Pxa);
BIG_rcopy(&mut xb, &CURVE_Pxb);
BIG_rcopy(&mut ya, &CURVE_Pya);
BIG_rcopy(&mut yb, &CURVE_Pyb);
FP2_from_BIGs(&mut x, &xa, &xb);
FP2_from_BIGs(&mut y, &ya, &yb);
ECP2_set(&mut P, &x, &y);
}
if P.inf != 0 {
println!("Failed to set - point not on curve");
} else {
println!("G2 set success");
}
print!("P= ");
unsafe {
ECP2_output(&P);
}
println!("");
for _ in 0..1000 {
unsafe {
PAIR_ate(&mut g, &mut P, &mut Q);
PAIR_fexp(&mut g);
}
}
print!("g= ");
unsafe {
FP12_output(&g);
}
println!("");
}
}