pub struct Bls12_381 { /* private fields */ }
Expand description
Bls12_381 provides access to curve and field arithmetics on the BLS12-381 curve.
Implementations§
Source§impl Bls12_381
impl Bls12_381
pub fn env(&self) -> &Env
Sourcepub fn g1_is_in_subgroup(&self, p: &G1Affine) -> bool
pub fn g1_is_in_subgroup(&self, p: &G1Affine) -> bool
Checks if a point p
in G1 is in the correct subgroup.
Sourcepub fn g1_add(&self, p0: &G1Affine, p1: &G1Affine) -> G1Affine
pub fn g1_add(&self, p0: &G1Affine, p1: &G1Affine) -> G1Affine
Adds two points p0
and p1
in G1.
Sourcepub fn g1_checked_add(&self, p0: &G1Affine, p1: &G1Affine) -> Option<G1Affine>
pub fn g1_checked_add(&self, p0: &G1Affine, p1: &G1Affine) -> Option<G1Affine>
Adds two points p0
and p1
in G1, ensuring that the result is in the
correct subgroup. Note the subgroup check is computationally expensive,
so if want to perform a series of additions i.e. agg = p0 + p1 + .. + pn
,
it may make sense to only call g1_checked_add on the final addition,
while using g1_add
(non-checked version) on the intermediate ones.
Sourcepub fn g1_mul(&self, p0: &G1Affine, scalar: &Fr) -> G1Affine
pub fn g1_mul(&self, p0: &G1Affine, scalar: &Fr) -> G1Affine
Multiplies a point p0
in G1 by a scalar.
Sourcepub fn g1_msm(&self, vp: Vec<G1Affine>, vs: Vec<Fr>) -> G1Affine
pub fn g1_msm(&self, vp: Vec<G1Affine>, vs: Vec<Fr>) -> G1Affine
Performs a multi-scalar multiplication (MSM) operation in G1.
Sourcepub fn map_fp_to_g1(&self, fp: &Fp) -> G1Affine
pub fn map_fp_to_g1(&self, fp: &Fp) -> G1Affine
Maps an element in the base field Fp
to a point in G1.
Sourcepub fn hash_to_g1(&self, msg: &Bytes, dst: &Bytes) -> G1Affine
pub fn hash_to_g1(&self, msg: &Bytes, dst: &Bytes) -> G1Affine
Hashes a message msg
to a point in G1, using a domain separation tag dst
.
Sourcepub fn g2_is_in_subgroup(&self, p: &G2Affine) -> bool
pub fn g2_is_in_subgroup(&self, p: &G2Affine) -> bool
Checks if a point p
in G2 is in the correct subgroup.
Sourcepub fn g2_add(&self, p0: &G2Affine, p1: &G2Affine) -> G2Affine
pub fn g2_add(&self, p0: &G2Affine, p1: &G2Affine) -> G2Affine
Adds two points p0
and p1
in G2.
Sourcepub fn g2_checked_add(&self, p0: &G2Affine, p1: &G2Affine) -> Option<G2Affine>
pub fn g2_checked_add(&self, p0: &G2Affine, p1: &G2Affine) -> Option<G2Affine>
Adds two points p0
and p1
in G2, ensuring that the result is in the
correct subgroup. Note the subgroup check is computationally expensive,
so if want to perform a series of additions i.e. agg = p0 + p1 + .. +pn
,
it may make sense to only call g2_checked_add on the final addition,
while using g2_add
(non-checked version) on the intermediate ones.
Sourcepub fn g2_mul(&self, p0: &G2Affine, scalar: &Fr) -> G2Affine
pub fn g2_mul(&self, p0: &G2Affine, scalar: &Fr) -> G2Affine
Multiplies a point p0
in G2 by a scalar.
Sourcepub fn g2_msm(&self, vp: Vec<G2Affine>, vs: Vec<Fr>) -> G2Affine
pub fn g2_msm(&self, vp: Vec<G2Affine>, vs: Vec<Fr>) -> G2Affine
Performs a multi-scalar multiplication (MSM) operation in G2.
Sourcepub fn map_fp2_to_g2(&self, fp2: &Fp2) -> G2Affine
pub fn map_fp2_to_g2(&self, fp2: &Fp2) -> G2Affine
Maps an element in the base field Fp2
to a point in G2.
Sourcepub fn hash_to_g2(&self, msg: &Bytes, dst: &Bytes) -> G2Affine
pub fn hash_to_g2(&self, msg: &Bytes, dst: &Bytes) -> G2Affine
Hashes a message msg
to a point in G2, using a domain separation tag dst
.
Sourcepub fn pairing_check(&self, vp1: Vec<G1Affine>, vp2: Vec<G2Affine>) -> bool
pub fn pairing_check(&self, vp1: Vec<G1Affine>, vp2: Vec<G2Affine>) -> bool
Performs a pairing check between vectors of points in G1 and G2.
This function computes the pairing for each pair of points in the
provided vectors vp1
(G1 points) and vp2
(G2 points) and verifies if
the overall pairing result is equal to the identity in the target group.
§Returns:
true
if the pairing check holds (i.e., the pairing result is valid and equal to the identity element), otherwisefalse
.
§Panics:
- If the lengths of
vp1
andvp2
are not equal or if they are empty.
Sourcepub fn fr_add(&self, lhs: &Fr, rhs: &Fr) -> Fr
pub fn fr_add(&self, lhs: &Fr, rhs: &Fr) -> Fr
Adds two scalars in the BLS12-381 scalar field Fr
.
Sourcepub fn fr_sub(&self, lhs: &Fr, rhs: &Fr) -> Fr
pub fn fr_sub(&self, lhs: &Fr, rhs: &Fr) -> Fr
Subtracts one scalar from another in the BLS12-381 scalar field Fr
.
Sourcepub fn fr_mul(&self, lhs: &Fr, rhs: &Fr) -> Fr
pub fn fr_mul(&self, lhs: &Fr, rhs: &Fr) -> Fr
Multiplies two scalars in the BLS12-381 scalar field Fr
.
Auto Trait Implementations§
impl Freeze for Bls12_381
impl !RefUnwindSafe for Bls12_381
impl !Send for Bls12_381
impl !Sync for Bls12_381
impl Unpin for Bls12_381
impl !UnwindSafe for Bls12_381
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
impl<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W), b: &(T, U, V, W), ) -> Result<Ordering, <C as Compare<(T, U, V, W)>>::Error>
Source§impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W, X), b: &(T, U, V, W, X), ) -> Result<Ordering, <C as Compare<(T, U, V, W, X)>>::Error>
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more