Struct mcl_rust::G1

source ·
#[repr(C)]
pub struct G1 { pub x: Fp, pub y: Fp, pub z: Fp, }

Fields§

§x: Fp§y: Fp§z: Fp

Implementations§

source§

impl G1

source

pub fn zero() -> G1

source

pub unsafe fn uninit() -> G1

Examples found in repository?
examples/main.rs (line 51)
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
fn main() {
    println!("mcl version={:04x}", get_version());
    let b = init(CurveType::BN254);
    if !b {
        println!("init err");
    }
    let mut x = Fr::zero();
    println!("x={}", x.get_str(10));
    x.set_int(123456);
    println!("x={}", x.get_str(10));
    x.set_int(0xfff);
    println!("x={}", x.get_str(16));
    x.clear();
    println!("x={}", x.get_str(10));
    x.set_str("0x123", 0);
    println!("x={}", x.get_str(16));
    let buf = x.serialize();
    println!("serialize={:x?}", buf); // put hex byte
    let mut y = Fr::zero();
    if y.deserialize(&buf) {
        println!("y={}", y.get_str(16));
    } else {
        println!("err deserialize");
    }
    if x != y {
        println!("ng");
    }
    x.set_int(1);
    if x == y {
        println!("ng");
    }
    if !x.is_one() {
        println!("ng");
    }
    x.set_int(123);
    y.set_int(567);
    let mut z = unsafe { Fr::uninit() };
    Fr::add(&mut z, &x, &y);

    let x1 = Fr::from_str("1234", 10).unwrap();
    println!("x1={}", x1.get_str(10));

    println!("z={}", z.get_str(10));
    println!("x={}", x.get_str(10));
    println!("y={}", y.get_str(10));

    let mut P1 = unsafe { G1::uninit() };
    let mut P2 = unsafe { G1::uninit() };
    let mut Q1 = unsafe { G2::uninit() };
    let mut Q2 = unsafe { G2::uninit() };
    let mut e1 = unsafe { GT::uninit() };
    let mut e2 = unsafe { GT::uninit() };
    let mut e3 = unsafe { GT::uninit() };
    P1.set_hash_of("abc".as_bytes());
    Q1.set_hash_of("abc".as_bytes());
    pairing(&mut e1, &P1, &Q1);
    x.set_by_csprng();
    y.set_by_csprng();
    G1::mul(&mut P2, &P1, &x);
    G2::mul(&mut Q2, &Q1, &y);
    pairing(&mut e2, &P2, &Q2);
    GT::pow(&mut e3, &e1, &x);
    GT::pow(&mut e1, &e3, &y);
    if e1 == e2 {
        println!("ok");
    } else {
        println!("ng");
    }
}
source

pub fn clear(&mut self)

source

pub fn is_zero(&self) -> bool

source§

impl G1

source

pub fn is_valid(&self) -> bool

source§

impl G1

source

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

source

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

source§

impl G1

source

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

source

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

source

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

source§

impl G1

source

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

source

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

source

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

source§

impl G1

source

pub fn dbl(y: &mut G1, x: &G1)

source

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

Examples found in repository?
examples/main.rs (line 63)
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
fn main() {
    println!("mcl version={:04x}", get_version());
    let b = init(CurveType::BN254);
    if !b {
        println!("init err");
    }
    let mut x = Fr::zero();
    println!("x={}", x.get_str(10));
    x.set_int(123456);
    println!("x={}", x.get_str(10));
    x.set_int(0xfff);
    println!("x={}", x.get_str(16));
    x.clear();
    println!("x={}", x.get_str(10));
    x.set_str("0x123", 0);
    println!("x={}", x.get_str(16));
    let buf = x.serialize();
    println!("serialize={:x?}", buf); // put hex byte
    let mut y = Fr::zero();
    if y.deserialize(&buf) {
        println!("y={}", y.get_str(16));
    } else {
        println!("err deserialize");
    }
    if x != y {
        println!("ng");
    }
    x.set_int(1);
    if x == y {
        println!("ng");
    }
    if !x.is_one() {
        println!("ng");
    }
    x.set_int(123);
    y.set_int(567);
    let mut z = unsafe { Fr::uninit() };
    Fr::add(&mut z, &x, &y);

    let x1 = Fr::from_str("1234", 10).unwrap();
    println!("x1={}", x1.get_str(10));

    println!("z={}", z.get_str(10));
    println!("x={}", x.get_str(10));
    println!("y={}", y.get_str(10));

    let mut P1 = unsafe { G1::uninit() };
    let mut P2 = unsafe { G1::uninit() };
    let mut Q1 = unsafe { G2::uninit() };
    let mut Q2 = unsafe { G2::uninit() };
    let mut e1 = unsafe { GT::uninit() };
    let mut e2 = unsafe { GT::uninit() };
    let mut e3 = unsafe { GT::uninit() };
    P1.set_hash_of("abc".as_bytes());
    Q1.set_hash_of("abc".as_bytes());
    pairing(&mut e1, &P1, &Q1);
    x.set_by_csprng();
    y.set_by_csprng();
    G1::mul(&mut P2, &P1, &x);
    G2::mul(&mut Q2, &Q1, &y);
    pairing(&mut e2, &P2, &Q2);
    GT::pow(&mut e3, &e1, &x);
    GT::pow(&mut e1, &e3, &y);
    if e1 == e2 {
        println!("ok");
    } else {
        println!("ng");
    }
}
source

pub fn normalize(y: &mut G1, x: &G1)

source

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

Examples found in repository?
examples/main.rs (line 58)
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
fn main() {
    println!("mcl version={:04x}", get_version());
    let b = init(CurveType::BN254);
    if !b {
        println!("init err");
    }
    let mut x = Fr::zero();
    println!("x={}", x.get_str(10));
    x.set_int(123456);
    println!("x={}", x.get_str(10));
    x.set_int(0xfff);
    println!("x={}", x.get_str(16));
    x.clear();
    println!("x={}", x.get_str(10));
    x.set_str("0x123", 0);
    println!("x={}", x.get_str(16));
    let buf = x.serialize();
    println!("serialize={:x?}", buf); // put hex byte
    let mut y = Fr::zero();
    if y.deserialize(&buf) {
        println!("y={}", y.get_str(16));
    } else {
        println!("err deserialize");
    }
    if x != y {
        println!("ng");
    }
    x.set_int(1);
    if x == y {
        println!("ng");
    }
    if !x.is_one() {
        println!("ng");
    }
    x.set_int(123);
    y.set_int(567);
    let mut z = unsafe { Fr::uninit() };
    Fr::add(&mut z, &x, &y);

    let x1 = Fr::from_str("1234", 10).unwrap();
    println!("x1={}", x1.get_str(10));

    println!("z={}", z.get_str(10));
    println!("x={}", x.get_str(10));
    println!("y={}", y.get_str(10));

    let mut P1 = unsafe { G1::uninit() };
    let mut P2 = unsafe { G1::uninit() };
    let mut Q1 = unsafe { G2::uninit() };
    let mut Q2 = unsafe { G2::uninit() };
    let mut e1 = unsafe { GT::uninit() };
    let mut e2 = unsafe { GT::uninit() };
    let mut e3 = unsafe { GT::uninit() };
    P1.set_hash_of("abc".as_bytes());
    Q1.set_hash_of("abc".as_bytes());
    pairing(&mut e1, &P1, &Q1);
    x.set_by_csprng();
    y.set_by_csprng();
    G1::mul(&mut P2, &P1, &x);
    G2::mul(&mut Q2, &Q1, &y);
    pairing(&mut e2, &P2, &Q2);
    GT::pow(&mut e3, &e1, &x);
    GT::pow(&mut e1, &e3, &y);
    if e1 == e2 {
        println!("ok");
    } else {
        println!("ng");
    }
}
source

pub fn mul_vec(z: &mut G1, x: &[G1], y: &[Fr])

Trait Implementations§

source§

impl<'a> Add for &'a G1

§

type Output = G1

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

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

source§

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

Performs the += operation. Read more
source§

impl Clone for G1

source§

fn clone(&self) -> G1

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 G1

source§

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

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

impl Default for G1

source§

fn default() -> G1

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

impl PartialEq for G1

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Sub for &'a G1

§

type Output = G1

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

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

source§

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

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for G1

§

impl Send for G1

§

impl Sync for G1

§

impl Unpin for G1

§

impl UnwindSafe for G1

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> 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,

§

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>,

§

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>,

§

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.