petrelic.petlib package¶
Submodules¶
petrelic.petlib.pairing module¶
This module provides a Python wrapper around RELIC’s pairings using petlib’s
interface: operations in petrelic.native.pairings.G1
and
petrelic.native.pairings.G2
are written additively, whereas operations in
petrelic.native.pairings.GT
are written multiplicatively.
-
class
petrelic.petlib.pairing.
BilinearGroupPair
[source]¶ Bases:
object
A bilinear group pair.
Contains two origin groups G1, G2 and the image group GT. The underlying
bplib.bp.BpGroup
object is also embedded.
-
class
petrelic.petlib.pairing.
G1Elem
[source]¶ Bases:
petrelic.native.pairing.G1Element
Element of the G1 group
-
export
(compressed=True)¶ Serialize the element of G1 into a binary representation.
- Example:
>>> generator = G1.generator() >>> bin_repr = generator.to_binary() >>> elem = G1Element.from_binary(bin_repr) >>> generator == elem True
-
classmethod
from_binary
(sbin, group=None)[source]¶ Deserialize a binary representation of the element of G1.
- Example:
>>> generator = G1.generator() >>> bin_repr = generator.to_binary() >>> elem = G1Element.from_binary(bin_repr) >>> generator == elem True
-
get_affine
()¶ Return the affine coordinates (x,y) of this EC Point.
- Example:
>>> generator = G1.generator() >>> x, y = generator.get_affine_coordinates() >>> x Bn(3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507) >>> y Bn(1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569)
-
is_infinite
()¶ Check if the object is the neutral element of G1.
- Example:
>>> generator = G1.generator() >>> order = G1.order() >>> elem = order * generator >>> elem.is_neutral_element() True
-
pair
(other)[source]¶ Computes bilinear pairing with self and otherwise
- Examples:
>>> G1 = G1Group() >>> G2 = G2Group() >>> GT = GTGroup() >>> G1.generator().pair(G2.generator()) == GT.generator() True
>>> p = 100 * G1.generator() >>> q = 200 * G2.generator() >>> p.pair(q) == GT.generator() ** 20000 True
-
pt_add
(other)¶ Add two points together.
This method is aliased by a + b.
- Examples:
>>> a = 10 * G1.generator() >>> b = 40 * G1.generator() >>> a + b == 50 * G1.generator() True >>> a.add(b) == 50 * G1.generator() True
-
pt_add_inplace
(other)¶ Inplace add another point.
- Examples:
>>> a = 10 * G1.generator() >>> b = 10 * G1.generator() >>> a += 3 * G1.generator() >>> _ = b.iadd(3 * G1.generator()) >>> a == b True >>> a == 13 * G1.generator() True
-
pt_double
()¶ Return double of the current element
- Example:
>>> generator = G1.generator() >>> elem = generator.double() >>> elem == 2 * generator True
-
pt_double_inplace
()¶ Inplace double the current element.
- Example:
>>> generator = G1.generator() >>> elem = G1.generator() >>> _ = elem.idouble() >>> elem == 2 * generator True
-
pt_eq
(other)¶ Check point equality.
-
pt_mul
(other)¶ Multiply point by a scalar
This method is aliased by n * pt.
- Examples:
>>> g = G1.generator() >>> g + g == 2 * g True
-
pt_mul_inplace
(other)¶ Inplace point multiplication by a scalar
- Examples:
>>> a = G1.generator() >>> b = G1.generator() >>> a *= 10 >>> _ = b.imul(10) >>> a == b True >>> a == 10 * G1.generator() True
-
pt_neg
()¶ Return the inverse of the element.
- Examples:
>>> a = 30 >>> elem = a * G1.generator() >>> -elem == elem.inverse() True >>> elem.inverse() == (G1.order() - a) * G1.generator() True
-
pt_neg_inplace
()¶ Inplace inverse of the current element
- Examples:
>>> a = 30 >>> elem1 = a * G1.generator() >>> elem2 = a * G1.generator() >>> _ = elem1.iinverse() >>> elem1 == elem2.inverse() True
-
pt_sub
(other)¶ Substract two points
This method is aliased by a - b.
- Examples:
>>> a = 50 * G1.generator() >>> b = 13 * G1.generator() >>> a - b == 37 * G1.generator() True >>> a.sub(b) == 37 * G1.generator() True
-
-
class
petrelic.petlib.pairing.
G1Group
[source]¶ Bases:
petrelic.native.pairing.G1
G1 group
-
class
petrelic.petlib.pairing.
G2Elem
[source]¶ Bases:
petrelic.native.pairing.G2Element
Element of the G2 group
-
export
(compressed=True)¶ Serialize the element of G2 into a binary representation.
- Example:
>>> generator = G2.generator() >>> bin_repr = generator.to_binary() >>> elem = G2Element.from_binary(bin_repr) >>> generator == elem True
-
classmethod
from_binary
(sbin, group=None)[source]¶ Deserialize a binary representation of the element of G2.
- Example:
>>> generator = G2.generator() >>> bin_repr = generator.to_binary() >>> elem = G2Element.from_binary(bin_repr) >>> generator == elem True
-
is_infinite
()¶ Check if the object is the neutral element of G2.
- Example:
>>> generator = G2.generator() >>> order = G2.order() >>> elem = order * generator >>> elem.is_neutral_element() True
-
pt_add
(other)¶ Add two points together.
This method is aliased by a + b.
- Examples:
>>> a = 10 * G2.generator() >>> b = 40 * G2.generator() >>> a + b == 50 * G2.generator() True >>> a.add(b) == 50 * G2.generator() True
-
pt_add_inplace
(other)¶ Add two points together.
This method is aliased by a + b.
- Examples:
>>> a = 10 * G2.generator() >>> b = 40 * G2.generator() >>> a + b == 50 * G2.generator() True >>> a.add(b) == 50 * G2.generator() True
-
pt_double
()¶ Return double of the current element
- Example:
>>> generator = G2.generator() >>> elem = generator.double() >>> elem == 2 * generator True
-
pt_double_inplace
()¶ Inplace double the current element.
- Example:
>>> generator = G2.generator() >>> elem = G2.generator() >>> _ = elem.idouble() >>> elem == 2 * generator True
-
pt_eq
(other)¶ Check that the points on the EC are equal.
-
pt_mul
(other)¶ Multiply point by a scalar
This method is aliased by n * pt.
- Examples:
>>> g = G2.generator() >>> g + g == 2 * g True
-
pt_mul_inplace
(other)¶ Inplace point multiplication by a scalar
- Examples:
>>> a = G2.generator() >>> b = G2.generator() >>> a *= 10 >>> _ = b.imul(10) >>> a == b True >>> a == 10 * G2.generator() True
-
pt_neg
()¶ Return the inverse of the element.
- Examples:
>>> a = 30 >>> elem = a * G2.generator() >>> -elem == elem.inverse() True >>> elem.inverse() == (G2.order() - a) * G2.generator() True
-
pt_neg_inplace
()¶ Inplace inverse of the current element
- Examples:
>>> a = 30 >>> elem1 = a * G2.generator() >>> elem2 = a * G2.generator() >>> _ = elem1.iinverse() >>> elem1 == elem2.inverse() True
-
pt_sub
(other)¶ Substract two points
This method is aliased by a - b.
- Examples:
>>> a = 50 * G2.generator() >>> b = 13 * G2.generator() >>> a - b == 37 * G2.generator() True >>> a.sub(b) == 37 * G2.generator() True
-
-
class
petrelic.petlib.pairing.
G2Group
[source]¶ Bases:
petrelic.native.pairing.G2
G2 group
-
class
petrelic.petlib.pairing.
GTElem
[source]¶ Bases:
petrelic.native.pairing.GTElement
GT element
-
exp
(other)¶ Raise element to the power of a scalar
This method is aliased by el ** n.
- Examples:
>>> g = GT.generator() >>> g * g == g ** 2 True >>> g * g == g.pow(2) True
-
exp_inplace
(other)¶ Inplace raise element to the power of a scalar
- Examples:
>>> g = GT.generator() >>> a = GT.generator() >>> _ = a.ipow(3) >>> g * g * g == a True
-
export
(compressed=True)¶ Serialize the element of GT into a binary representation.
- Example:
>>> generator = GT.generator() >>> bin_repr = generator.to_binary() >>> elem = GTElement.from_binary(bin_repr) >>> generator == elem True
-
classmethod
from_binary
(sbin, group=None)[source]¶ Create an element from a byte sequence.
It accepts (but ignores) group as extra argument.
- Example:
>>> G = GTGroup() >>> byte_string = G.generator().export() # Export EC point as byte string >>> GTElem.from_binary(byte_string, G) == G.generator() # Import EC point from binary string True >>> GTElem.from_binary(byte_string) == G.generator() # Import EC point from binary string True
-
inv
()¶ Return the inverse of the element.
- Examples:
>>> a = 30 >>> elem = GT.generator() ** a >>> elem.inverse() == GT.generator() ** (G1.order() - a) True
-
inv_inplace
()¶ Inplace inverse of the current element
- Examples:
>>> a = 30 >>> elem1 = GT.generator() ** a >>> elem2 = GT.generator() ** a >>> _ = elem1.iinverse() >>> elem1 == elem2.inverse() True
-
mul_inplace
(other)¶ Inplace multiplication by another element
- Examples:
>>> a = GT.generator() ** 10 >>> b = GT.generator() ** 10 >>> a *= GT.generator() ** 3 >>> _ = b.imul(GT.generator() ** 3) >>> a == b True >>> a == GT.generator() ** 13 True
-
sqr
()¶ Return the square of the current element
- Example:
>>> generator = GT.generator() >>> elem = generator.square() >>> elem == generator ** 2 True
-
sqr_inplace
()¶ Inplace square of the current element.
- Example:
>>> elem = GT.generator() >>> _ = elem.isquare() >>> elem == GT.generator() ** 2 True
-
-
class
petrelic.petlib.pairing.
GTGroup
[source]¶ Bases:
petrelic.native.pairing.GT
GT group