Skip to content

Parameters are ignored in PairingGroup.random when the type of the element to be generated randomly is GT #313

@yueryang

Description

@yueryang

Parameters are ignored in PairingGroup.random when the type of the element to be generated randomly is GT.

According to the developer document, it is expected to generate 3 elements of GT when calling group.random(GT, 3), where the symbol group is an object belonging to PairingGroup. However, when executing a, b, c = group.random(GT, 3), it does not work as a, b, c = group.random(ZR, 3) and other types. In the document, there are no related statements indicating that it is a special case when the function is called for generating multiple elements belonging to GT.

The related codes are from https://github.com/JHUISI/charm/blob/dev/charm/toolbox/pairinggroup.py.

    def random(self, _type=ZR, count=1, seed=None):
        """selects a random element in ZR, G1, G2 and GT"""
        if _type == GT: return self.__randomGT()
        elif _type in [ZR, G1, G2]:
            if seed != None and count == 1:
                return random(self.Pairing, _type, seed)
            elif count > 1:
                return tuple([random(self.Pairing, _type) for i in range(count)])                
            return random(self.Pairing, _type)
        return None

        
    def __randomGT(self):
        if not hasattr(self, 'gt'):
            self.gt = pair(self.random(G1), self.random(G2))
        z = self.random(ZR)
        return self.gt ** z

If there are no special meanings for count or seed in this case, the following codes may be helpful.

    def random(self:object, _type:int = ZR, count:int = 1, seed:object = None) -> object:
        """selects a random element in ZR, G1, G2 and GT"""
        if _type == GT: return self.__randomGT(count = count, seed = seed)
        elif _type in [ZR, G1, G2]:
            if seed != None and count == 1:
                return random(self.Pairing, _type, seed)
            elif count > 1:
                return tuple([random(self.Pairing, _type) for i in range(count)])                
            return random(self.Pairing, _type)
        return None

        
    def __randomGT(self:object, count:int = 1, seed:object = None) -> object:
        if not hasattr(self, 'gt'): # it is recommended to generate that when an instance is constructed
            self.gt = pair(self.random(G1, seed = seed), self.random(G2, seed = seed))
            # self.gt = pair(self.random(G1), self.random(G2))
        z = self.random(ZR, count = count, seed = seed)
        return tuple(self.gt ** ele for ele in z) if count > 1 else self.gt ** z

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions