diff --git a/petrelic/additive/pairing.py b/petrelic/additive/pairing.py index d741aac..261b991 100644 --- a/petrelic/additive/pairing.py +++ b/petrelic/additive/pairing.py @@ -6,12 +6,10 @@ from petrelic.bindings import _FFI, _C from petrelic.bn import Bn, force_Bn_other +from petrelic.native.pairing import NoAffineCoordinateForECPoint -from petrelic.pairing import G2 -from petrelic.pairing import G2Element -from petrelic.pairing import NoAffineCoordinateForECPoint - -import petrelic.pairing as mulpairing +import petrelic.native.pairing as native +from petrelic.native.pairing import G2, G2Element class BilinearGroupPair: """ @@ -33,7 +31,7 @@ def groups(self): return self.G1, self.G2, self.GT -class G1(mulpairing.G1): +class G1(native.G1): """G1 group.""" @classmethod @@ -41,7 +39,7 @@ def _element_type(cls): return G1Element -class G1Element(mulpairing.G1Element): +class G1Element(native.G1Element): """Element of the G1 group.""" group = G1 @@ -52,7 +50,7 @@ def pair(self, other): return res -class Gt(mulpairing.Gt): +class Gt(native.Gt): """Gt group.""" @classmethod @@ -94,10 +92,10 @@ def wsum(cls, weights, elems): return res - infinity = mulpairing.Gt.neutral_element + infinity = native.Gt.neutral_element -class GtElement(mulpairing.GtElement): +class GtElement(native.GtElement): """Gt element.""" group = Gt @@ -147,17 +145,17 @@ def __neg__(self): # Binary operators # - double = mulpairing.GtElement.square - idouble = mulpairing.GtElement.isquare + double = native.GtElement.square + idouble = native.GtElement.isquare - __add__ = mulpairing.GtElement.__mul__ - __iadd__ = mulpairing.GtElement.__imul__ + __add__ = native.GtElement.__mul__ + __iadd__ = native.GtElement.__imul__ - __sub__ = mulpairing.GtElement.__truediv__ - __isub__ = mulpairing.GtElement.__itruediv__ + __sub__ = native.GtElement.__truediv__ + __isub__ = native.GtElement.__itruediv__ - __mul__ = mulpairing.GtElement.__pow__ - __imul__ = mulpairing.GtElement.__ipow__ + __mul__ = native.GtElement.__pow__ + __imul__ = native.GtElement.__ipow__ @force_Bn_other def __rmul__(self, other): @@ -198,6 +196,6 @@ def dec(data): return dec # Register encoders and decoders for pairing points -pack.register_coders(G1Element, 114, pt_enc, pt_dec(G1Element)) -pack.register_coders(G2Element, 115, pt_enc, pt_dec(G2Element)) -pack.register_coders(GtElement, 116, pt_enc, pt_dec(GtElement)) +# pack.register_coders(G1Element, 114, pt_enc, pt_dec(G1Element)) +# pack.register_coders(G2Element, 115, pt_enc, pt_dec(G2Element)) +# pack.register_coders(GtElement, 116, pt_enc, pt_dec(GtElement)) diff --git a/petrelic/multiplicative/__init__.py b/petrelic/multiplicative/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/petrelic/multiplicative/pairing.py b/petrelic/multiplicative/pairing.py index 259710e..1aca74b 100644 --- a/petrelic/multiplicative/pairing.py +++ b/petrelic/multiplicative/pairing.py @@ -6,12 +6,9 @@ from petrelic.bindings import _FFI, _C from petrelic.bn import Bn, force_Bn_other +from petrelic.native.pairing import NoAffineCoordinateForECPoint -from petrelic.pairing import G2 -from petrelic.pairing import G2Element -from petrelic.pairing import NoAffineCoordinateForECPoint - -import petrelic.pairing as basepairing +import petrelic.native.pairing as native class BilinearGroupPair: @@ -34,7 +31,7 @@ def groups(self): return self.G1, self.G2, self.GT -class G1(basepairing.G1): +class G1(native.G1): """G1 group.""" @classmethod @@ -74,10 +71,10 @@ def wprod(cls, weights, elems): return res - unity = basepairing.G1.neutral_element + unity = native.G1.neutral_element -class G1Element(basepairing.G1Element): +class G1Element(native.G1Element): """Element of the G1 group.""" group = G1 @@ -87,17 +84,17 @@ def pair(self, other): _C.pc_map(res.pt, self.pt, other.pt) return res - square = basepairing.G1Element.double - isquare = basepairing.G1Element.idouble + square = native.G1Element.double + isquare = native.G1Element.idouble - __mul__ = basepairing.G1Element.__add__ - __imul__ = basepairing.G1Element.__iadd__ + __mul__ = native.G1Element.__add__ + __imul__ = native.G1Element.__iadd__ - __truediv__ = basepairing.G1Element.__sub__ - __itruediv__ = basepairing.G1Element.__isub__ + __truediv__ = native.G1Element.__sub__ + __itruediv__ = native.G1Element.__isub__ - __pow__ = basepairing.G1Element.__mul__ - __ipow__ = basepairing.G1Element.__imul__ + __pow__ = native.G1Element.__mul__ + __ipow__ = native.G1Element.__imul__ mul = __mul__ imul = __imul__ @@ -109,30 +106,30 @@ def pair(self, other): ipow = __ipow__ -class G2(basepairing.G2): +class G2(native.G2): @classmethod def _element_type(cls): return G2Element - unity = basepairing.G2.neutral_element + unity = native.G2.neutral_element -class G2Element(basepairing.G2Element): +class G2Element(native.G2Element): """Element of the G2 group.""" group = G2 - square = basepairing.G2Element.double - isquare = basepairing.G2Element.idouble + square = native.G2Element.double + isquare = native.G2Element.idouble - __mul__ = basepairing.G2Element.__add__ - __imul__ = basepairing.G2Element.__iadd__ + __mul__ = native.G2Element.__add__ + __imul__ = native.G2Element.__iadd__ - __truediv__ = basepairing.G2Element.__sub__ - __itruediv__ = basepairing.G2Element.__isub__ + __truediv__ = native.G2Element.__sub__ + __itruediv__ = native.G2Element.__isub__ - __pow__ = basepairing.G2Element.__mul__ - __ipow__ = basepairing.G2Element.__imul__ + __pow__ = native.G2Element.__mul__ + __ipow__ = native.G2Element.__imul__ mul = __mul__ imul = __imul__ @@ -145,7 +142,7 @@ class G2Element(basepairing.G2Element): -class Gt(basepairing.Gt): +class Gt(native.Gt): """Gt group.""" @classmethod @@ -153,7 +150,7 @@ def _element_type(cls): return GtElement -class GtElement(basepairing.GtElement): +class GtElement(native.GtElement): """Gt element.""" group = Gt diff --git a/petrelic/native/__init__.py b/petrelic/native/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/petrelic/pairing.py b/petrelic/native/pairing.py similarity index 99% rename from petrelic/pairing.py rename to petrelic/native/pairing.py index 1ad5c1c..479cfce 100644 --- a/petrelic/pairing.py +++ b/petrelic/native/pairing.py @@ -1037,7 +1037,7 @@ def inverse(self): Examples: >>> a = 30 - >>> elem = G1.generator() ** a + >>> elem = Gt.generator() ** a >>> elem.inverse() == Gt.generator() ** (G1.order() - a) True """ @@ -1050,8 +1050,8 @@ def iinverse(self): Examples: >>> a = 30 - >>> elem1 = G1.generator() ** a - >>> elem2 = G1.generator() ** a + >>> elem1 = Gt.generator() ** a + >>> elem2 = Gt.generator() ** a >>> _ = elem1.iinverse() >>> elem1 == elem2.inverse() True