Struct Fr

Source
#[repr(C)]
pub struct Fr { /* private fields */ }

Implementations§

Source§

impl Fr

Source§

impl Fr

Source

pub fn zero() -> Fr

Examples found in repository?
examples/main.rs (line 11)
5fn main() {
6    println!("mcl version={:04x}", get_version());
7    let b = init(CurveType::BN254);
8    if !b {
9        println!("init err");
10    }
11    let mut x = Fr::zero();
12    println!("x={}", x.get_str(10));
13    x.set_int(123456);
14    println!("x={}", x.get_str(10));
15    x.set_int(0xfff);
16    println!("x={}", x.get_str(16));
17    x.clear();
18    println!("x={}", x.get_str(10));
19    x.set_str("0x123", 0);
20    println!("x={}", x.get_str(16));
21    let buf = x.serialize();
22    println!("serialize={:x?}", buf); // put hex byte
23    let mut y = Fr::zero();
24    if y.deserialize(&buf) {
25        println!("y={}", y.get_str(16));
26    } else {
27        println!("err deserialize");
28    }
29    if x != y {
30        println!("ng");
31    }
32    x.set_int(1);
33    if x == y {
34        println!("ng");
35    }
36    if !x.is_one() {
37        println!("ng");
38    }
39    x.set_int(123);
40    y.set_int(567);
41    let mut z = unsafe { Fr::uninit() };
42    Fr::add(&mut z, &x, &y);
43
44    let x1 = Fr::from_str("1234", 10).unwrap();
45    println!("x1={}", x1.get_str(10));
46
47    println!("z={}", z.get_str(10));
48    println!("x={}", x.get_str(10));
49    println!("y={}", y.get_str(10));
50
51    let mut P1 = unsafe { G1::uninit() };
52    let mut P2 = unsafe { G1::uninit() };
53    let mut Q1 = unsafe { G2::uninit() };
54    let mut Q2 = unsafe { G2::uninit() };
55    let mut e1 = unsafe { GT::uninit() };
56    let mut e2 = unsafe { GT::uninit() };
57    let mut e3 = unsafe { GT::uninit() };
58    P1.set_hash_of("abc".as_bytes());
59    Q1.set_hash_of("abc".as_bytes());
60    pairing(&mut e1, &P1, &Q1);
61    x.set_by_csprng();
62    y.set_by_csprng();
63    G1::mul(&mut P2, &P1, &x);
64    G2::mul(&mut Q2, &Q1, &y);
65    pairing(&mut e2, &P2, &Q2);
66    GT::pow(&mut e3, &e1, &x);
67    GT::pow(&mut e1, &e3, &y);
68    if e1 == e2 {
69        println!("ok");
70    } else {
71        println!("ng");
72    }
73}
Source

pub unsafe fn uninit() -> Fr

Examples found in repository?
examples/main.rs (line 41)
5fn main() {
6    println!("mcl version={:04x}", get_version());
7    let b = init(CurveType::BN254);
8    if !b {
9        println!("init err");
10    }
11    let mut x = Fr::zero();
12    println!("x={}", x.get_str(10));
13    x.set_int(123456);
14    println!("x={}", x.get_str(10));
15    x.set_int(0xfff);
16    println!("x={}", x.get_str(16));
17    x.clear();
18    println!("x={}", x.get_str(10));
19    x.set_str("0x123", 0);
20    println!("x={}", x.get_str(16));
21    let buf = x.serialize();
22    println!("serialize={:x?}", buf); // put hex byte
23    let mut y = Fr::zero();
24    if y.deserialize(&buf) {
25        println!("y={}", y.get_str(16));
26    } else {
27        println!("err deserialize");
28    }
29    if x != y {
30        println!("ng");
31    }
32    x.set_int(1);
33    if x == y {
34        println!("ng");
35    }
36    if !x.is_one() {
37        println!("ng");
38    }
39    x.set_int(123);
40    y.set_int(567);
41    let mut z = unsafe { Fr::uninit() };
42    Fr::add(&mut z, &x, &y);
43
44    let x1 = Fr::from_str("1234", 10).unwrap();
45    println!("x1={}", x1.get_str(10));
46
47    println!("z={}", z.get_str(10));
48    println!("x={}", x.get_str(10));
49    println!("y={}", y.get_str(10));
50
51    let mut P1 = unsafe { G1::uninit() };
52    let mut P2 = unsafe { G1::uninit() };
53    let mut Q1 = unsafe { G2::uninit() };
54    let mut Q2 = unsafe { G2::uninit() };
55    let mut e1 = unsafe { GT::uninit() };
56    let mut e2 = unsafe { GT::uninit() };
57    let mut e3 = unsafe { GT::uninit() };
58    P1.set_hash_of("abc".as_bytes());
59    Q1.set_hash_of("abc".as_bytes());
60    pairing(&mut e1, &P1, &Q1);
61    x.set_by_csprng();
62    y.set_by_csprng();
63    G1::mul(&mut P2, &P1, &x);
64    G2::mul(&mut Q2, &Q1, &y);
65    pairing(&mut e2, &P2, &Q2);
66    GT::pow(&mut e3, &e1, &x);
67    GT::pow(&mut e1, &e3, &y);
68    if e1 == e2 {
69        println!("ok");
70    } else {
71        println!("ng");
72    }
73}
Source

pub fn clear(&mut self)

Examples found in repository?
examples/main.rs (line 17)
5fn main() {
6    println!("mcl version={:04x}", get_version());
7    let b = init(CurveType::BN254);
8    if !b {
9        println!("init err");
10    }
11    let mut x = Fr::zero();
12    println!("x={}", x.get_str(10));
13    x.set_int(123456);
14    println!("x={}", x.get_str(10));
15    x.set_int(0xfff);
16    println!("x={}", x.get_str(16));
17    x.clear();
18    println!("x={}", x.get_str(10));
19    x.set_str("0x123", 0);
20    println!("x={}", x.get_str(16));
21    let buf = x.serialize();
22    println!("serialize={:x?}", buf); // put hex byte
23    let mut y = Fr::zero();
24    if y.deserialize(&buf) {
25        println!("y={}", y.get_str(16));
26    } else {
27        println!("err deserialize");
28    }
29    if x != y {
30        println!("ng");
31    }
32    x.set_int(1);
33    if x == y {
34        println!("ng");
35    }
36    if !x.is_one() {
37        println!("ng");
38    }
39    x.set_int(123);
40    y.set_int(567);
41    let mut z = unsafe { Fr::uninit() };
42    Fr::add(&mut z, &x, &y);
43
44    let x1 = Fr::from_str("1234", 10).unwrap();
45    println!("x1={}", x1.get_str(10));
46
47    println!("z={}", z.get_str(10));
48    println!("x={}", x.get_str(10));
49    println!("y={}", y.get_str(10));
50
51    let mut P1 = unsafe { G1::uninit() };
52    let mut P2 = unsafe { G1::uninit() };
53    let mut Q1 = unsafe { G2::uninit() };
54    let mut Q2 = unsafe { G2::uninit() };
55    let mut e1 = unsafe { GT::uninit() };
56    let mut e2 = unsafe { GT::uninit() };
57    let mut e3 = unsafe { GT::uninit() };
58    P1.set_hash_of("abc".as_bytes());
59    Q1.set_hash_of("abc".as_bytes());
60    pairing(&mut e1, &P1, &Q1);
61    x.set_by_csprng();
62    y.set_by_csprng();
63    G1::mul(&mut P2, &P1, &x);
64    G2::mul(&mut Q2, &Q1, &y);
65    pairing(&mut e2, &P2, &Q2);
66    GT::pow(&mut e3, &e1, &x);
67    GT::pow(&mut e1, &e3, &y);
68    if e1 == e2 {
69        println!("ok");
70    } else {
71        println!("ng");
72    }
73}
Source

pub fn is_zero(&self) -> bool

Source§

impl Fr

Source

pub fn is_valid(&self) -> bool

Source§

impl Fr

Source

pub fn deserialize(&mut self, buf: &[u8]) -> bool

Examples found in repository?
examples/main.rs (line 24)
5fn main() {
6    println!("mcl version={:04x}", get_version());
7    let b = init(CurveType::BN254);
8    if !b {
9        println!("init err");
10    }
11    let mut x = Fr::zero();
12    println!("x={}", x.get_str(10));
13    x.set_int(123456);
14    println!("x={}", x.get_str(10));
15    x.set_int(0xfff);
16    println!("x={}", x.get_str(16));
17    x.clear();
18    println!("x={}", x.get_str(10));
19    x.set_str("0x123", 0);
20    println!("x={}", x.get_str(16));
21    let buf = x.serialize();
22    println!("serialize={:x?}", buf); // put hex byte
23    let mut y = Fr::zero();
24    if y.deserialize(&buf) {
25        println!("y={}", y.get_str(16));
26    } else {
27        println!("err deserialize");
28    }
29    if x != y {
30        println!("ng");
31    }
32    x.set_int(1);
33    if x == y {
34        println!("ng");
35    }
36    if !x.is_one() {
37        println!("ng");
38    }
39    x.set_int(123);
40    y.set_int(567);
41    let mut z = unsafe { Fr::uninit() };
42    Fr::add(&mut z, &x, &y);
43
44    let x1 = Fr::from_str("1234", 10).unwrap();
45    println!("x1={}", x1.get_str(10));
46
47    println!("z={}", z.get_str(10));
48    println!("x={}", x.get_str(10));
49    println!("y={}", y.get_str(10));
50
51    let mut P1 = unsafe { G1::uninit() };
52    let mut P2 = unsafe { G1::uninit() };
53    let mut Q1 = unsafe { G2::uninit() };
54    let mut Q2 = unsafe { G2::uninit() };
55    let mut e1 = unsafe { GT::uninit() };
56    let mut e2 = unsafe { GT::uninit() };
57    let mut e3 = unsafe { GT::uninit() };
58    P1.set_hash_of("abc".as_bytes());
59    Q1.set_hash_of("abc".as_bytes());
60    pairing(&mut e1, &P1, &Q1);
61    x.set_by_csprng();
62    y.set_by_csprng();
63    G1::mul(&mut P2, &P1, &x);
64    G2::mul(&mut Q2, &Q1, &y);
65    pairing(&mut e2, &P2, &Q2);
66    GT::pow(&mut e3, &e1, &x);
67    GT::pow(&mut e1, &e3, &y);
68    if e1 == e2 {
69        println!("ok");
70    } else {
71        println!("ng");
72    }
73}
Source

pub fn serialize(&self) -> Vec<u8>

Examples found in repository?
examples/main.rs (line 21)
5fn main() {
6    println!("mcl version={:04x}", get_version());
7    let b = init(CurveType::BN254);
8    if !b {
9        println!("init err");
10    }
11    let mut x = Fr::zero();
12    println!("x={}", x.get_str(10));
13    x.set_int(123456);
14    println!("x={}", x.get_str(10));
15    x.set_int(0xfff);
16    println!("x={}", x.get_str(16));
17    x.clear();
18    println!("x={}", x.get_str(10));
19    x.set_str("0x123", 0);
20    println!("x={}", x.get_str(16));
21    let buf = x.serialize();
22    println!("serialize={:x?}", buf); // put hex byte
23    let mut y = Fr::zero();
24    if y.deserialize(&buf) {
25        println!("y={}", y.get_str(16));
26    } else {
27        println!("err deserialize");
28    }
29    if x != y {
30        println!("ng");
31    }
32    x.set_int(1);
33    if x == y {
34        println!("ng");
35    }
36    if !x.is_one() {
37        println!("ng");
38    }
39    x.set_int(123);
40    y.set_int(567);
41    let mut z = unsafe { Fr::uninit() };
42    Fr::add(&mut z, &x, &y);
43
44    let x1 = Fr::from_str("1234", 10).unwrap();
45    println!("x1={}", x1.get_str(10));
46
47    println!("z={}", z.get_str(10));
48    println!("x={}", x.get_str(10));
49    println!("y={}", y.get_str(10));
50
51    let mut P1 = unsafe { G1::uninit() };
52    let mut P2 = unsafe { G1::uninit() };
53    let mut Q1 = unsafe { G2::uninit() };
54    let mut Q2 = unsafe { G2::uninit() };
55    let mut e1 = unsafe { GT::uninit() };
56    let mut e2 = unsafe { GT::uninit() };
57    let mut e3 = unsafe { GT::uninit() };
58    P1.set_hash_of("abc".as_bytes());
59    Q1.set_hash_of("abc".as_bytes());
60    pairing(&mut e1, &P1, &Q1);
61    x.set_by_csprng();
62    y.set_by_csprng();
63    G1::mul(&mut P2, &P1, &x);
64    G2::mul(&mut Q2, &Q1, &y);
65    pairing(&mut e2, &P2, &Q2);
66    GT::pow(&mut e3, &e1, &x);
67    GT::pow(&mut e1, &e3, &y);
68    if e1 == e2 {
69        println!("ok");
70    } else {
71        println!("ng");
72    }
73}
Source§

impl Fr

Source

pub fn from_str(s: &str, base: i32) -> Option<Fr>

Examples found in repository?
examples/main.rs (line 44)
5fn main() {
6    println!("mcl version={:04x}", get_version());
7    let b = init(CurveType::BN254);
8    if !b {
9        println!("init err");
10    }
11    let mut x = Fr::zero();
12    println!("x={}", x.get_str(10));
13    x.set_int(123456);
14    println!("x={}", x.get_str(10));
15    x.set_int(0xfff);
16    println!("x={}", x.get_str(16));
17    x.clear();
18    println!("x={}", x.get_str(10));
19    x.set_str("0x123", 0);
20    println!("x={}", x.get_str(16));
21    let buf = x.serialize();
22    println!("serialize={:x?}", buf); // put hex byte
23    let mut y = Fr::zero();
24    if y.deserialize(&buf) {
25        println!("y={}", y.get_str(16));
26    } else {
27        println!("err deserialize");
28    }
29    if x != y {
30        println!("ng");
31    }
32    x.set_int(1);
33    if x == y {
34        println!("ng");
35    }
36    if !x.is_one() {
37        println!("ng");
38    }
39    x.set_int(123);
40    y.set_int(567);
41    let mut z = unsafe { Fr::uninit() };
42    Fr::add(&mut z, &x, &y);
43
44    let x1 = Fr::from_str("1234", 10).unwrap();
45    println!("x1={}", x1.get_str(10));
46
47    println!("z={}", z.get_str(10));
48    println!("x={}", x.get_str(10));
49    println!("y={}", y.get_str(10));
50
51    let mut P1 = unsafe { G1::uninit() };
52    let mut P2 = unsafe { G1::uninit() };
53    let mut Q1 = unsafe { G2::uninit() };
54    let mut Q2 = unsafe { G2::uninit() };
55    let mut e1 = unsafe { GT::uninit() };
56    let mut e2 = unsafe { GT::uninit() };
57    let mut e3 = unsafe { GT::uninit() };
58    P1.set_hash_of("abc".as_bytes());
59    Q1.set_hash_of("abc".as_bytes());
60    pairing(&mut e1, &P1, &Q1);
61    x.set_by_csprng();
62    y.set_by_csprng();
63    G1::mul(&mut P2, &P1, &x);
64    G2::mul(&mut Q2, &Q1, &y);
65    pairing(&mut e2, &P2, &Q2);
66    GT::pow(&mut e3, &e1, &x);
67    GT::pow(&mut e1, &e3, &y);
68    if e1 == e2 {
69        println!("ok");
70    } else {
71        println!("ng");
72    }
73}
Source

pub fn set_str(&mut self, s: &str, base: i32) -> bool

Examples found in repository?
examples/main.rs (line 19)
5fn main() {
6    println!("mcl version={:04x}", get_version());
7    let b = init(CurveType::BN254);
8    if !b {
9        println!("init err");
10    }
11    let mut x = Fr::zero();
12    println!("x={}", x.get_str(10));
13    x.set_int(123456);
14    println!("x={}", x.get_str(10));
15    x.set_int(0xfff);
16    println!("x={}", x.get_str(16));
17    x.clear();
18    println!("x={}", x.get_str(10));
19    x.set_str("0x123", 0);
20    println!("x={}", x.get_str(16));
21    let buf = x.serialize();
22    println!("serialize={:x?}", buf); // put hex byte
23    let mut y = Fr::zero();
24    if y.deserialize(&buf) {
25        println!("y={}", y.get_str(16));
26    } else {
27        println!("err deserialize");
28    }
29    if x != y {
30        println!("ng");
31    }
32    x.set_int(1);
33    if x == y {
34        println!("ng");
35    }
36    if !x.is_one() {
37        println!("ng");
38    }
39    x.set_int(123);
40    y.set_int(567);
41    let mut z = unsafe { Fr::uninit() };
42    Fr::add(&mut z, &x, &y);
43
44    let x1 = Fr::from_str("1234", 10).unwrap();
45    println!("x1={}", x1.get_str(10));
46
47    println!("z={}", z.get_str(10));
48    println!("x={}", x.get_str(10));
49    println!("y={}", y.get_str(10));
50
51    let mut P1 = unsafe { G1::uninit() };
52    let mut P2 = unsafe { G1::uninit() };
53    let mut Q1 = unsafe { G2::uninit() };
54    let mut Q2 = unsafe { G2::uninit() };
55    let mut e1 = unsafe { GT::uninit() };
56    let mut e2 = unsafe { GT::uninit() };
57    let mut e3 = unsafe { GT::uninit() };
58    P1.set_hash_of("abc".as_bytes());
59    Q1.set_hash_of("abc".as_bytes());
60    pairing(&mut e1, &P1, &Q1);
61    x.set_by_csprng();
62    y.set_by_csprng();
63    G1::mul(&mut P2, &P1, &x);
64    G2::mul(&mut Q2, &Q1, &y);
65    pairing(&mut e2, &P2, &Q2);
66    GT::pow(&mut e3, &e1, &x);
67    GT::pow(&mut e1, &e3, &y);
68    if e1 == e2 {
69        println!("ok");
70    } else {
71        println!("ng");
72    }
73}
Source

pub fn get_str(&self, io_mode: i32) -> String

Examples found in repository?
examples/main.rs (line 12)
5fn main() {
6    println!("mcl version={:04x}", get_version());
7    let b = init(CurveType::BN254);
8    if !b {
9        println!("init err");
10    }
11    let mut x = Fr::zero();
12    println!("x={}", x.get_str(10));
13    x.set_int(123456);
14    println!("x={}", x.get_str(10));
15    x.set_int(0xfff);
16    println!("x={}", x.get_str(16));
17    x.clear();
18    println!("x={}", x.get_str(10));
19    x.set_str("0x123", 0);
20    println!("x={}", x.get_str(16));
21    let buf = x.serialize();
22    println!("serialize={:x?}", buf); // put hex byte
23    let mut y = Fr::zero();
24    if y.deserialize(&buf) {
25        println!("y={}", y.get_str(16));
26    } else {
27        println!("err deserialize");
28    }
29    if x != y {
30        println!("ng");
31    }
32    x.set_int(1);
33    if x == y {
34        println!("ng");
35    }
36    if !x.is_one() {
37        println!("ng");
38    }
39    x.set_int(123);
40    y.set_int(567);
41    let mut z = unsafe { Fr::uninit() };
42    Fr::add(&mut z, &x, &y);
43
44    let x1 = Fr::from_str("1234", 10).unwrap();
45    println!("x1={}", x1.get_str(10));
46
47    println!("z={}", z.get_str(10));
48    println!("x={}", x.get_str(10));
49    println!("y={}", y.get_str(10));
50
51    let mut P1 = unsafe { G1::uninit() };
52    let mut P2 = unsafe { G1::uninit() };
53    let mut Q1 = unsafe { G2::uninit() };
54    let mut Q2 = unsafe { G2::uninit() };
55    let mut e1 = unsafe { GT::uninit() };
56    let mut e2 = unsafe { GT::uninit() };
57    let mut e3 = unsafe { GT::uninit() };
58    P1.set_hash_of("abc".as_bytes());
59    Q1.set_hash_of("abc".as_bytes());
60    pairing(&mut e1, &P1, &Q1);
61    x.set_by_csprng();
62    y.set_by_csprng();
63    G1::mul(&mut P2, &P1, &x);
64    G2::mul(&mut Q2, &Q1, &y);
65    pairing(&mut e2, &P2, &Q2);
66    GT::pow(&mut e3, &e1, &x);
67    GT::pow(&mut e1, &e3, &y);
68    if e1 == e2 {
69        println!("ok");
70    } else {
71        println!("ng");
72    }
73}
Source§

impl Fr

Source

pub fn from_int(x: i32) -> Fr

Source

pub fn set_int(&mut self, x: i32)

Examples found in repository?
examples/main.rs (line 13)
5fn main() {
6    println!("mcl version={:04x}", get_version());
7    let b = init(CurveType::BN254);
8    if !b {
9        println!("init err");
10    }
11    let mut x = Fr::zero();
12    println!("x={}", x.get_str(10));
13    x.set_int(123456);
14    println!("x={}", x.get_str(10));
15    x.set_int(0xfff);
16    println!("x={}", x.get_str(16));
17    x.clear();
18    println!("x={}", x.get_str(10));
19    x.set_str("0x123", 0);
20    println!("x={}", x.get_str(16));
21    let buf = x.serialize();
22    println!("serialize={:x?}", buf); // put hex byte
23    let mut y = Fr::zero();
24    if y.deserialize(&buf) {
25        println!("y={}", y.get_str(16));
26    } else {
27        println!("err deserialize");
28    }
29    if x != y {
30        println!("ng");
31    }
32    x.set_int(1);
33    if x == y {
34        println!("ng");
35    }
36    if !x.is_one() {
37        println!("ng");
38    }
39    x.set_int(123);
40    y.set_int(567);
41    let mut z = unsafe { Fr::uninit() };
42    Fr::add(&mut z, &x, &y);
43
44    let x1 = Fr::from_str("1234", 10).unwrap();
45    println!("x1={}", x1.get_str(10));
46
47    println!("z={}", z.get_str(10));
48    println!("x={}", x.get_str(10));
49    println!("y={}", y.get_str(10));
50
51    let mut P1 = unsafe { G1::uninit() };
52    let mut P2 = unsafe { G1::uninit() };
53    let mut Q1 = unsafe { G2::uninit() };
54    let mut Q2 = unsafe { G2::uninit() };
55    let mut e1 = unsafe { GT::uninit() };
56    let mut e2 = unsafe { GT::uninit() };
57    let mut e3 = unsafe { GT::uninit() };
58    P1.set_hash_of("abc".as_bytes());
59    Q1.set_hash_of("abc".as_bytes());
60    pairing(&mut e1, &P1, &Q1);
61    x.set_by_csprng();
62    y.set_by_csprng();
63    G1::mul(&mut P2, &P1, &x);
64    G2::mul(&mut Q2, &Q1, &y);
65    pairing(&mut e2, &P2, &Q2);
66    GT::pow(&mut e3, &e1, &x);
67    GT::pow(&mut e1, &e3, &y);
68    if e1 == e2 {
69        println!("ok");
70    } else {
71        println!("ng");
72    }
73}
Source

pub fn is_one(&self) -> bool

Examples found in repository?
examples/main.rs (line 36)
5fn main() {
6    println!("mcl version={:04x}", get_version());
7    let b = init(CurveType::BN254);
8    if !b {
9        println!("init err");
10    }
11    let mut x = Fr::zero();
12    println!("x={}", x.get_str(10));
13    x.set_int(123456);
14    println!("x={}", x.get_str(10));
15    x.set_int(0xfff);
16    println!("x={}", x.get_str(16));
17    x.clear();
18    println!("x={}", x.get_str(10));
19    x.set_str("0x123", 0);
20    println!("x={}", x.get_str(16));
21    let buf = x.serialize();
22    println!("serialize={:x?}", buf); // put hex byte
23    let mut y = Fr::zero();
24    if y.deserialize(&buf) {
25        println!("y={}", y.get_str(16));
26    } else {
27        println!("err deserialize");
28    }
29    if x != y {
30        println!("ng");
31    }
32    x.set_int(1);
33    if x == y {
34        println!("ng");
35    }
36    if !x.is_one() {
37        println!("ng");
38    }
39    x.set_int(123);
40    y.set_int(567);
41    let mut z = unsafe { Fr::uninit() };
42    Fr::add(&mut z, &x, &y);
43
44    let x1 = Fr::from_str("1234", 10).unwrap();
45    println!("x1={}", x1.get_str(10));
46
47    println!("z={}", z.get_str(10));
48    println!("x={}", x.get_str(10));
49    println!("y={}", y.get_str(10));
50
51    let mut P1 = unsafe { G1::uninit() };
52    let mut P2 = unsafe { G1::uninit() };
53    let mut Q1 = unsafe { G2::uninit() };
54    let mut Q2 = unsafe { G2::uninit() };
55    let mut e1 = unsafe { GT::uninit() };
56    let mut e2 = unsafe { GT::uninit() };
57    let mut e3 = unsafe { GT::uninit() };
58    P1.set_hash_of("abc".as_bytes());
59    Q1.set_hash_of("abc".as_bytes());
60    pairing(&mut e1, &P1, &Q1);
61    x.set_by_csprng();
62    y.set_by_csprng();
63    G1::mul(&mut P2, &P1, &x);
64    G2::mul(&mut Q2, &Q1, &y);
65    pairing(&mut e2, &P2, &Q2);
66    GT::pow(&mut e3, &e1, &x);
67    GT::pow(&mut e1, &e3, &y);
68    if e1 == e2 {
69        println!("ok");
70    } else {
71        println!("ng");
72    }
73}
Source§

impl Fr

Source

pub fn set_little_endian(&mut self, buf: &[u8]) -> bool

Source

pub fn set_little_endian_mod(&mut self, buf: &[u8]) -> bool

Source

pub fn set_hash_of(&mut self, buf: &[u8]) -> bool

Source

pub fn set_by_csprng(&mut self)

Examples found in repository?
examples/main.rs (line 61)
5fn main() {
6    println!("mcl version={:04x}", get_version());
7    let b = init(CurveType::BN254);
8    if !b {
9        println!("init err");
10    }
11    let mut x = Fr::zero();
12    println!("x={}", x.get_str(10));
13    x.set_int(123456);
14    println!("x={}", x.get_str(10));
15    x.set_int(0xfff);
16    println!("x={}", x.get_str(16));
17    x.clear();
18    println!("x={}", x.get_str(10));
19    x.set_str("0x123", 0);
20    println!("x={}", x.get_str(16));
21    let buf = x.serialize();
22    println!("serialize={:x?}", buf); // put hex byte
23    let mut y = Fr::zero();
24    if y.deserialize(&buf) {
25        println!("y={}", y.get_str(16));
26    } else {
27        println!("err deserialize");
28    }
29    if x != y {
30        println!("ng");
31    }
32    x.set_int(1);
33    if x == y {
34        println!("ng");
35    }
36    if !x.is_one() {
37        println!("ng");
38    }
39    x.set_int(123);
40    y.set_int(567);
41    let mut z = unsafe { Fr::uninit() };
42    Fr::add(&mut z, &x, &y);
43
44    let x1 = Fr::from_str("1234", 10).unwrap();
45    println!("x1={}", x1.get_str(10));
46
47    println!("z={}", z.get_str(10));
48    println!("x={}", x.get_str(10));
49    println!("y={}", y.get_str(10));
50
51    let mut P1 = unsafe { G1::uninit() };
52    let mut P2 = unsafe { G1::uninit() };
53    let mut Q1 = unsafe { G2::uninit() };
54    let mut Q2 = unsafe { G2::uninit() };
55    let mut e1 = unsafe { GT::uninit() };
56    let mut e2 = unsafe { GT::uninit() };
57    let mut e3 = unsafe { GT::uninit() };
58    P1.set_hash_of("abc".as_bytes());
59    Q1.set_hash_of("abc".as_bytes());
60    pairing(&mut e1, &P1, &Q1);
61    x.set_by_csprng();
62    y.set_by_csprng();
63    G1::mul(&mut P2, &P1, &x);
64    G2::mul(&mut Q2, &Q1, &y);
65    pairing(&mut e2, &P2, &Q2);
66    GT::pow(&mut e3, &e1, &x);
67    GT::pow(&mut e1, &e3, &y);
68    if e1 == e2 {
69        println!("ok");
70    } else {
71        println!("ng");
72    }
73}
Source

pub fn is_odd(&self) -> bool

Source

pub fn is_negative(&self) -> bool

Source

pub fn cmp(&self, rhs: &Fr) -> i32

Source

pub fn square_root(y: &mut Fr, x: &Fr) -> bool

Source§

impl Fr

Source

pub fn add(z: &mut Fr, x: &Fr, y: &Fr)

Examples found in repository?
examples/main.rs (line 42)
5fn main() {
6    println!("mcl version={:04x}", get_version());
7    let b = init(CurveType::BN254);
8    if !b {
9        println!("init err");
10    }
11    let mut x = Fr::zero();
12    println!("x={}", x.get_str(10));
13    x.set_int(123456);
14    println!("x={}", x.get_str(10));
15    x.set_int(0xfff);
16    println!("x={}", x.get_str(16));
17    x.clear();
18    println!("x={}", x.get_str(10));
19    x.set_str("0x123", 0);
20    println!("x={}", x.get_str(16));
21    let buf = x.serialize();
22    println!("serialize={:x?}", buf); // put hex byte
23    let mut y = Fr::zero();
24    if y.deserialize(&buf) {
25        println!("y={}", y.get_str(16));
26    } else {
27        println!("err deserialize");
28    }
29    if x != y {
30        println!("ng");
31    }
32    x.set_int(1);
33    if x == y {
34        println!("ng");
35    }
36    if !x.is_one() {
37        println!("ng");
38    }
39    x.set_int(123);
40    y.set_int(567);
41    let mut z = unsafe { Fr::uninit() };
42    Fr::add(&mut z, &x, &y);
43
44    let x1 = Fr::from_str("1234", 10).unwrap();
45    println!("x1={}", x1.get_str(10));
46
47    println!("z={}", z.get_str(10));
48    println!("x={}", x.get_str(10));
49    println!("y={}", y.get_str(10));
50
51    let mut P1 = unsafe { G1::uninit() };
52    let mut P2 = unsafe { G1::uninit() };
53    let mut Q1 = unsafe { G2::uninit() };
54    let mut Q2 = unsafe { G2::uninit() };
55    let mut e1 = unsafe { GT::uninit() };
56    let mut e2 = unsafe { GT::uninit() };
57    let mut e3 = unsafe { GT::uninit() };
58    P1.set_hash_of("abc".as_bytes());
59    Q1.set_hash_of("abc".as_bytes());
60    pairing(&mut e1, &P1, &Q1);
61    x.set_by_csprng();
62    y.set_by_csprng();
63    G1::mul(&mut P2, &P1, &x);
64    G2::mul(&mut Q2, &Q1, &y);
65    pairing(&mut e2, &P2, &Q2);
66    GT::pow(&mut e3, &e1, &x);
67    GT::pow(&mut e1, &e3, &y);
68    if e1 == e2 {
69        println!("ok");
70    } else {
71        println!("ng");
72    }
73}
Source

pub fn sub(z: &mut Fr, x: &Fr, y: &Fr)

Source

pub fn neg(y: &mut Fr, x: &Fr)

Source§

impl Fr

Source

pub fn mul(z: &mut Fr, x: &Fr, y: &Fr)

Source

pub fn div(z: &mut Fr, x: &Fr, y: &Fr)

Source

pub fn inv(y: &mut Fr, x: &Fr)

Source

pub fn sqr(y: &mut Fr, x: &Fr)

Trait Implementations§

Source§

impl<'a> Add for &'a Fr

Source§

type Output = Fr

The resulting type after applying the + operator.
Source§

fn add(self, other: &Fr) -> Fr

Performs the + operation. Read more
Source§

impl<'a> AddAssign<&'a Fr> for Fr

Source§

fn add_assign(&mut self, other: &Fr)

Performs the += operation. Read more
Source§

impl Clone for Fr

Source§

fn clone(&self) -> Fr

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Fr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Fr

Source§

fn default() -> Fr

Returns the “default value” for a type. Read more
Source§

impl<'a> Div for &'a Fr

Source§

type Output = Fr

The resulting type after applying the / operator.
Source§

fn div(self, other: &Fr) -> Fr

Performs the / operation. Read more
Source§

impl<'a> DivAssign<&'a Fr> for Fr

Source§

fn div_assign(&mut self, other: &Fr)

Performs the /= operation. Read more
Source§

impl<'a> Mul for &'a Fr

Source§

type Output = Fr

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Fr) -> Fr

Performs the * operation. Read more
Source§

impl<'a> MulAssign<&'a Fr> for Fr

Source§

fn mul_assign(&mut self, other: &Fr)

Performs the *= operation. Read more
Source§

impl PartialEq for Fr

Source§

fn eq(&self, rhs: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Sub for &'a Fr

Source§

type Output = Fr

The resulting type after applying the - operator.
Source§

fn sub(self, other: &Fr) -> Fr

Performs the - operation. Read more
Source§

impl<'a> SubAssign<&'a Fr> for Fr

Source§

fn sub_assign(&mut self, other: &Fr)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl Freeze for Fr

§

impl RefUnwindSafe for Fr

§

impl Send for Fr

§

impl Sync for Fr

§

impl Unpin for Fr

§

impl UnwindSafe for Fr

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.