Skip to content

Commit

Permalink
Rename Gt back to GT
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterl committed Mar 12, 2020
1 parent 95de267 commit 4b7376e
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 117 deletions.
4 changes: 2 additions & 2 deletions bench/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time
import secrets

from petrelic.additive.pairing import G1, G2, Gt
from petrelic.additive.pairing import G1, G2, GT
from petrelic.bn import Bn

# WARNING: If changing from 1000 the results will no longer be in milliseconds
Expand Down Expand Up @@ -105,5 +105,5 @@ def bench_pair():
if __name__ == "__main__":
bench_group("G1", G1())
bench_group("G2", G2())
bench_group("GT", Gt())
bench_group("GT", GT())
bench_pair()
66 changes: 33 additions & 33 deletions petrelic/additive/pairing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ class BilinearGroupPair:
"""
A bilinear group pair.
Contains two origin groups G1, G2 and the image group Gt.
Contains two origin groups G1, G2 and the image group GT.
"""

def __init__(self):
"""Initialise a bilinear group pair."""
self.GT = Gt()
self.GT = GT()
self.G1 = G1()
self.G2 = G2()

def groups(self):
"""
Returns the three groups in the following order : G1, G2, Gt.
Returns the three groups in the following order : G1, G2, GT.
"""
return self.G1, self.G2, self.GT

Expand All @@ -45,17 +45,17 @@ class G1Element(native.G1Element):
group = G1

def pair(self, other):
res = GtElement()
res = GTElement()
_C.pc_map(res.pt, self.pt, other.pt)
return res


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

@classmethod
def _element_type(cls):
return GtElement
return GTElement

@classmethod
def sum(cls, elems):
Expand All @@ -64,8 +64,8 @@ def sum(cls, elems):
In the current implementation this function is not optimized.
Example:
>>> elems = [ x * Gt.generator() for x in [10, 25, 13]]
>>> Gt.sum(elems) == (10 + 25 + 13) * Gt.generator()
>>> elems = [ x * GT.generator() for x in [10, 25, 13]]
>>> GT.sum(elems) == (10 + 25 + 13) * GT.generator()
True
"""
res = cls.neutral_element()
Expand All @@ -82,8 +82,8 @@ def wsum(cls, weights, elems):
Example:
>>> weights = [1, 2, 3]
>>> elems = [ x * Gt.generator() for x in [10, 25, 13]]
>>> Gt.wsum(weights, elems) == (1 * 10 + 2 * 25 + 3 * 13) * Gt.generator()
>>> elems = [ x * GT.generator() for x in [10, 25, 13]]
>>> GT.wsum(weights, elems) == (1 * 10 + 2 * 25 + 3 * 13) * GT.generator()
True
"""
res = cls.neutral_element()
Expand All @@ -92,38 +92,38 @@ def wsum(cls, weights, elems):

return res

infinity = native.Gt.neutral_element
infinity = native.GT.neutral_element


class GtElement(native.GtElement):
"""Gt element."""
class GTElement(native.GTElement):
"""GT element."""

group = Gt
group = GT

def iinverse(self):
"""Inverse the element of Gt."""
"""Inverse the element of GT."""
_C.gt_inv(self.pt, self.pt)
return self

def double(self):
"""Return an element which is the double of the current one.
Example:
>>> generator = Gt.generator()
>>> generator = GT.generator()
>>> elem = generator.double()
>>> elem == generator * 2
True
"""
res = GtElement()
res = GTElement()
_C.gt_sqr(res.pt, self.pt)
return res

def idouble(self):
"""Double the current element.
Example:
>>> generator = Gt.generator()
>>> elem = Gt.generator().idouble()
>>> generator = GT.generator()
>>> elem = GT.generator().idouble()
>>> elem == generator * 2
True
"""
Expand All @@ -136,31 +136,31 @@ def idouble(self):
#

def __neg__(self):
"""Return the inverse of the element of Gt."""
res = GtElement()
"""Return the inverse of the element of GT."""
res = GTElement()
_C.gt_inv(res.pt, self.pt)
return res

#
# Binary operators
#

double = native.GtElement.square
idouble = native.GtElement.isquare
double = native.GTElement.square
idouble = native.GTElement.isquare

__add__ = native.GtElement.__mul__
__iadd__ = native.GtElement.__imul__
__add__ = native.GTElement.__mul__
__iadd__ = native.GTElement.__imul__

__sub__ = native.GtElement.__truediv__
__isub__ = native.GtElement.__itruediv__
__sub__ = native.GTElement.__truediv__
__isub__ = native.GTElement.__itruediv__

__mul__ = native.GtElement.__pow__
__imul__ = native.GtElement.__ipow__
__mul__ = native.GTElement.__pow__
__imul__ = native.GTElement.__ipow__

@force_Bn_other
def __rmul__(self, other):
res = GtElement()
exponent = other.mod(Gt.order())
res = GTElement()
exponent = other.mod(GT.order())
_C.gt_exp(res.pt, self.pt, exponent.bn)
return res

Expand Down Expand Up @@ -198,4 +198,4 @@ def dec(data):
# 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(GTElement, 116, pt_enc, pt_dec(GTElement))
22 changes: 11 additions & 11 deletions petrelic/multiplicative/pairing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ class BilinearGroupPair:
"""
A bilinear group pair.
Contains two origin groups G1, G2 and the image group Gt.
Contains two origin groups G1, G2 and the image group GT.
"""

def __init__(self):
"""Initialise a bilinear group pair."""
self.GT = Gt()
self.GT = GT()
self.G1 = G1()
self.G2 = G2()

def groups(self):
"""
Returns the three groups in the following order : G1, G2, Gt.
Returns the three groups in the following order : G1, G2, GT.
"""
return self.G1, self.G2, self.GT

Expand Down Expand Up @@ -80,7 +80,7 @@ class G1Element(native.G1Element):
group = G1

def pair(self, other):
res = GtElement()
res = GTElement()
_C.pc_map(res.pt, self.pt, other.pt)
return res

Expand Down Expand Up @@ -142,18 +142,18 @@ class G2Element(native.G2Element):



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

@classmethod
def _element_type(cls):
return GtElement
return GTElement


class GtElement(native.GtElement):
"""Gt element."""
class GTElement(native.GTElement):
"""GT element."""

group = Gt
group = GT


def pt_enc(obj):
Expand All @@ -177,4 +177,4 @@ def dec(data):
# Register encoders and decoders for pairing points
# pack.register_coders(G1Element, 118, pt_enc, pt_dec(G1Element))
# pack.register_coders(G2Element, 119, pt_enc, pt_dec(G2Element))
# pack.register_coders(GtElement, 120, pt_enc, pt_dec(GtElement))
# pack.register_coders(GTElement, 120, pt_enc, pt_dec(GTElement))
Loading

0 comments on commit 4b7376e

Please sign in to comment.