From 4b7376ebb3ee28b8dc6f4002982e10c23e8addc9 Mon Sep 17 00:00:00 2001 From: Wouter Lueks Date: Thu, 12 Mar 2020 16:54:54 +0100 Subject: [PATCH] Rename Gt back to GT --- bench/group.py | 4 +- petrelic/additive/pairing.py | 66 +++++++------- petrelic/multiplicative/pairing.py | 22 ++--- petrelic/native/pairing.py | 128 +++++++++++++-------------- tests/test_additive_pairing.py | 4 +- tests/test_multiplicative_pairing.py | 10 +-- 6 files changed, 117 insertions(+), 117 deletions(-) diff --git a/bench/group.py b/bench/group.py index b6e6539..e562049 100644 --- a/bench/group.py +++ b/bench/group.py @@ -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 @@ -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() diff --git a/petrelic/additive/pairing.py b/petrelic/additive/pairing.py index 261b991..f738f21 100644 --- a/petrelic/additive/pairing.py +++ b/petrelic/additive/pairing.py @@ -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 @@ -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): @@ -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() @@ -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() @@ -92,16 +92,16 @@ 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 @@ -109,12 +109,12 @@ 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 @@ -122,8 +122,8 @@ 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 """ @@ -136,8 +136,8 @@ 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 @@ -145,22 +145,22 @@ def __neg__(self): # 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 @@ -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)) diff --git a/petrelic/multiplicative/pairing.py b/petrelic/multiplicative/pairing.py index 1aca74b..5f14369 100644 --- a/petrelic/multiplicative/pairing.py +++ b/petrelic/multiplicative/pairing.py @@ -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 @@ -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 @@ -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): @@ -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)) diff --git a/petrelic/native/pairing.py b/petrelic/native/pairing.py index 479cfce..841c529 100644 --- a/petrelic/native/pairing.py +++ b/petrelic/native/pairing.py @@ -4,7 +4,7 @@ This module provides a Python wrapper around RELIC's pairings using a native interface: operations in :py:obj:`petrelic.pairings.G1` and :py:obj:`petrelic.pairings.G2` are written additively, whereas operations in -:py:obj:`petrelic.pairings.Gt` are written multiplicatively. +:py:obj:`petrelic.pairings.GT` are written multiplicatively. Let's see how we can use this interface to implement the Boney-Lynn-Shacham signature scheme for type III pairings. First we generate a private key: @@ -72,16 +72,16 @@ class NoAffineCoordinateForECPoint(Exception): # class BilinearGroupPair: - """A bilinear group pair used to wrap the three groups G1, G2, Gt.""" + """A bilinear group pair used to wrap the three groups G1, G2, GT.""" def __init__(self): - 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 @@ -324,7 +324,7 @@ def pair(self, other): if not type(other) == G2Element: raise TypeError("Second parameter should be of type G2Element is {}".format(type(other))) - res = GtElement() + res = GTElement() _C.pc_map(res.pt, self.pt, other.pt) return res @@ -882,12 +882,12 @@ def __imul__(self, other): imul = __imul__ -class Gt: - """Gt group.""" +class GT: + """GT group.""" @classmethod def _element_type(cls): - return GtElement + return GTElement @classmethod def _new_element(cls): @@ -899,9 +899,9 @@ def order(cls): """Return the order of the EC group as a Bn large integer. Example: - >>> generator = Gt.generator() - >>> neutral = Gt.neutral_element() - >>> order = Gt.order() + >>> generator = GT.generator() + >>> neutral = GT.neutral_element() + >>> order = GT.order() >>> generator ** order == neutral True """ @@ -914,8 +914,8 @@ def generator(cls): """Return generator of the EC group. Example: - >>> generator = Gt.generator() - >>> neutral = Gt.neutral_element() + >>> generator = GT.generator() + >>> neutral = GT.neutral_element() >>> generator * neutral == generator True """ @@ -925,12 +925,12 @@ def generator(cls): @classmethod def neutral_element(cls): - """Return the neutral element of the group Gt. + """Return the neutral element of the group GT. In this case, the unity point. Example: - >>> generator = Gt.generator() - >>> neutral = Gt.neutral_element() + >>> generator = GT.generator() + >>> neutral = GT.neutral_element() >>> generator * neutral == generator True """ @@ -945,8 +945,8 @@ def prod(cls, elems): In the current implementation this function is not optimized. Example: - >>> elems = [ Gt.generator() ** x for x in [10, 25, 13]] - >>> Gt.prod(elems) == Gt.generator() ** (10 + 25 + 13) + >>> elems = [ GT.generator() ** x for x in [10, 25, 13]] + >>> GT.prod(elems) == GT.generator() ** (10 + 25 + 13) True """ res = cls.neutral_element() @@ -962,8 +962,8 @@ def wprod(cls, weights, elems): Example: >>> weights = [1, 2, 3] - >>> elems = [ Gt.generator() ** x for x in [10, 25, 13]] - >>> Gt.wprod(weights, elems) == Gt.generator() ** (1 * 10 + 2 * 25 + 3 * 13) + >>> elems = [ GT.generator() ** x for x in [10, 25, 13]] + >>> GT.wprod(weights, elems) == GT.generator() ** (1 * 10 + 2 * 25 + 3 * 13) True """ res = cls.neutral_element() @@ -980,24 +980,24 @@ def wprod(cls, weights, elems): def unity(cls): """The unity elements - Alias for :py:meth:`Gt.neutral_element` + Alias for :py:meth:`GT.neutral_element` """ return cls.neutral_element() -class GtElement(): - """Gt element.""" +class GTElement(): + """GT element.""" - group = Gt + group = GT def __init__(self): - """Initialize a new element of Gt.""" + """Initialize a new element of GT.""" self.pt = _FFI.new("gt_t") _C.gt_null(self.pt) _C.gt_new(self.pt) def __copy__(self): - """Clone an element of Gt.""" + """Clone an element of GT.""" copy = self.__class__() _C.gt_copy(copy.pt, self.pt) return copy @@ -1010,7 +1010,7 @@ def is_valid(self): """Check if the element is in the group Example: - >>> elem = Gt.generator() ** 1337 + >>> elem = GT.generator() ** 1337 >>> elem.is_valid() True """ @@ -1021,11 +1021,11 @@ def is_valid(self): return bool(_C.gt_is_valid(self.pt)) def is_neutral_element(self): - """Check if the object is the neutral element of Gt. + """Check if the object is the neutral element of GT. Example: - >>> generator = Gt.generator() - >>> order = Gt.order() + >>> generator = GT.generator() + >>> order = GT.order() >>> elem = generator ** order >>> elem.is_neutral_element() True @@ -1037,8 +1037,8 @@ def inverse(self): Examples: >>> a = 30 - >>> elem = Gt.generator() ** a - >>> elem.inverse() == Gt.generator() ** (G1.order() - a) + >>> elem = GT.generator() ** a + >>> elem.inverse() == GT.generator() ** (G1.order() - a) True """ res = self.__class__() @@ -1050,8 +1050,8 @@ def iinverse(self): Examples: >>> a = 30 - >>> elem1 = Gt.generator() ** a - >>> elem2 = Gt.generator() ** a + >>> elem1 = GT.generator() ** a + >>> elem2 = GT.generator() ** a >>> _ = elem1.iinverse() >>> elem1 == elem2.inverse() True @@ -1063,7 +1063,7 @@ def square(self): """Return the square of the current element Example: - >>> generator = Gt.generator() + >>> generator = GT.generator() >>> elem = generator.square() >>> elem == generator ** 2 True @@ -1076,9 +1076,9 @@ def isquare(self): """Inplace square of the current element. Example: - >>> elem = Gt.generator() + >>> elem = GT.generator() >>> _ = elem.isquare() - >>> elem == Gt.generator() ** 2 + >>> elem == GT.generator() ** 2 True """ _C.gt_sqr(self.pt, self.pt) @@ -1091,7 +1091,7 @@ def __hash__(self): def __repr__(self): """String representation of the element of G2.""" pt_hex = self.to_binary().hex() - return 'GtElement({})'.format(pt_hex) + return 'GTElement({})'.format(pt_hex) # # Serialization @@ -1099,12 +1099,12 @@ def __repr__(self): @classmethod def from_binary(cls, sbin): - """Deserialize a binary representation of the element of Gt. + """Deserialize a binary representation of the element of GT. Example: - >>> generator = Gt.generator() + >>> generator = GT.generator() >>> bin_repr = generator.to_binary() - >>> elem = GtElement.from_binary(bin_repr) + >>> elem = GTElement.from_binary(bin_repr) >>> generator == elem True """ @@ -1119,7 +1119,7 @@ def to_binary(self, compressed=True): _C.gt_write_bin(buf, length, self.pt, flag) return _FFI.unpack(buf, length) - to_binary.__doc__ = G1Element.to_binary.__doc__.replace("G1", "Gt") + to_binary.__doc__ = G1Element.to_binary.__doc__.replace("G1", "GT") # # Comparison operators @@ -1150,11 +1150,11 @@ def __mul__(self, other): This method is aliased by `a * b`. Examples: - >>> a = Gt.generator() ** 10 - >>> b = Gt.generator() ** 40 - >>> a * b == Gt.generator() ** 50 + >>> a = GT.generator() ** 10 + >>> b = GT.generator() ** 40 + >>> a * b == GT.generator() ** 50 True - >>> a.mul(b) == Gt.generator() ** 50 + >>> a.mul(b) == GT.generator() ** 50 True """ res = self.__class__() @@ -1166,13 +1166,13 @@ def __imul__(self, 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 = GT.generator() ** 10 + >>> b = GT.generator() ** 10 + >>> a *= GT.generator() ** 3 + >>> _ = b.imul(GT.generator() ** 3) >>> a == b True - >>> a == Gt.generator() ** 13 + >>> a == GT.generator() ** 13 True """ _C.gt_mul(self.pt, self.pt, other.pt) @@ -1185,13 +1185,13 @@ def __truediv__(self, other): This method is aliased by `a / b` and `a // b`. Examples: - >>> a = Gt.generator() ** 50 - >>> b = Gt.generator() ** 13 - >>> a / b == Gt.generator() ** 37 + >>> a = GT.generator() ** 50 + >>> b = GT.generator() ** 13 + >>> a / b == GT.generator() ** 37 True - >>> a // b == Gt.generator() ** 37 + >>> a // b == GT.generator() ** 37 True - >>> a.div(b) == Gt.generator() ** 37 + >>> a.div(b) == GT.generator() ** 37 True """ res = other.inverse() @@ -1203,13 +1203,13 @@ def __itruediv__(self, other): """Inplace division by another point Examples: - >>> a = Gt.generator() ** 10 - >>> b = Gt.generator() ** 10 - >>> a /= Gt.generator() ** 3 - >>> _ = b.idiv(Gt.generator() ** 3) + >>> a = GT.generator() ** 10 + >>> b = GT.generator() ** 10 + >>> a /= GT.generator() ** 3 + >>> _ = b.idiv(GT.generator() ** 3) >>> a == b True - >>> a == Gt.generator() ** 7 + >>> a == GT.generator() ** 7 True """ other_inv = other.inverse() @@ -1223,7 +1223,7 @@ def __pow__(self, other): This method is aliased by `el ** n`. Examples: - >>> g = Gt.generator() + >>> g = GT.generator() >>> g * g == g ** 2 True """ @@ -1237,8 +1237,8 @@ def __ipow__(self, other): """Inplace raise element to the power of a scalar Examples: - >>> g = Gt.generator() - >>> a = Gt.generator() + >>> g = GT.generator() + >>> a = GT.generator() >>> _ = a.ipow(3) >>> g * g * g == a True diff --git a/tests/test_additive_pairing.py b/tests/test_additive_pairing.py index d319676..55bac3c 100644 --- a/tests/test_additive_pairing.py +++ b/tests/test_additive_pairing.py @@ -1,10 +1,10 @@ import pytest -from petrelic.additive.pairing import G1, G1Element, G2, G2Element, Gt, GtElement, NoAffineCoordinateForECPoint +from petrelic.additive.pairing import G1, G1Element, G2, G2Element, GT, GTElement, NoAffineCoordinateForECPoint from petrelic.bn import Bn -@pytest.fixture(params=[G1, G2, Gt]) +@pytest.fixture(params=[G1, G2, GT]) def group(request): return request.param diff --git a/tests/test_multiplicative_pairing.py b/tests/test_multiplicative_pairing.py index 9956285..b6dcae5 100644 --- a/tests/test_multiplicative_pairing.py +++ b/tests/test_multiplicative_pairing.py @@ -5,24 +5,24 @@ G1Element, G2, G2Element, - Gt, - GtElement, + GT, + GTElement, NoAffineCoordinateForECPoint, ) from petrelic.bn import Bn -@pytest.fixture(params=[G1, G2, Gt]) +@pytest.fixture(params=[G1, G2, GT]) def generator(request): return request.param.generator() -@pytest.fixture(params=[G1, G2, Gt]) +@pytest.fixture(params=[G1, G2, GT]) def group(request): return request.param -@pytest.fixture(params=[G1Element, G2Element, GtElement]) +@pytest.fixture(params=[G1Element, G2Element, GTElement]) def element(request): return request.param