Skip to content

Commit

Permalink
Rename to native
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterl committed Mar 12, 2020
1 parent ca0a93a commit 95de267
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 53 deletions.
40 changes: 19 additions & 21 deletions petrelic/additive/pairing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -33,15 +31,15 @@ def groups(self):
return self.G1, self.G2, self.GT


class G1(mulpairing.G1):
class G1(native.G1):
"""G1 group."""

@classmethod
def _element_type(cls):
return G1Element


class G1Element(mulpairing.G1Element):
class G1Element(native.G1Element):
"""Element of the G1 group."""

group = G1
Expand All @@ -52,7 +50,7 @@ def pair(self, other):
return res


class Gt(mulpairing.Gt):
class Gt(native.Gt):
"""Gt group."""

@classmethod
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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))
Empty file.
55 changes: 26 additions & 29 deletions petrelic/multiplicative/pairing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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__
Expand All @@ -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__
Expand All @@ -145,15 +142,15 @@ class G2Element(basepairing.G2Element):



class Gt(basepairing.Gt):
class Gt(native.Gt):
"""Gt group."""

@classmethod
def _element_type(cls):
return GtElement


class GtElement(basepairing.GtElement):
class GtElement(native.GtElement):
"""Gt element."""

group = Gt
Expand Down
Empty file added petrelic/native/__init__.py
Empty file.
6 changes: 3 additions & 3 deletions petrelic/pairing.py → petrelic/native/pairing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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
Expand Down

0 comments on commit 95de267

Please sign in to comment.