Struct 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)
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)

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)
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 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)
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 mul_vec(z: &mut G1, x: &[G1], y: &[Fr])

Trait Implementations§

Source§

impl<'a> Add for &'a G1

Source§

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

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 G1

Source§

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 Freeze for G1

§

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