当前位置: 首页>>代码示例>>Python>>正文


Python PairingGroup.init方法代码示例

本文整理汇总了Python中charm.toolbox.pairinggroup.PairingGroup.init方法的典型用法代码示例。如果您正苦于以下问题:Python PairingGroup.init方法的具体用法?Python PairingGroup.init怎么用?Python PairingGroup.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在charm.toolbox.pairinggroup.PairingGroup的用法示例。


在下文中一共展示了PairingGroup.init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testSecretShare

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import init [as 别名]
    def testSecretShare(self):
        # Testing Secret sharing python API
          k = 3
          n = 4
          group = PairingGroup('SS512')

          s = SecretShare(group, False)
          sec = group.random(ZR)
          shares = s.genShares(sec, k, n)

          K = shares[0]
          if debug: print('\nOriginal secret: %s' % K)
          y = {group.init(ZR, long(1)):shares[1], group.init(ZR, long(2)):shares[2], group.init(ZR, long(3)):shares[3]}

          secret = s.recoverSecret(y)

          assert K == secret, "Could not recover the secret!"
          if debug: print("Successfully recovered secret: ", secret)
开发者ID:SRI-CSL,项目名称:ENCODERS,代码行数:20,代码来源:secretshare_test.py

示例2: PairingGroup

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import init [as 别名]
        secret = self.elem.init(ZR, 0)
#        secret = 0
        for i in list:
            secret += (coeff[i] * shares[i])

        return secret

if __name__ == "__main__":

# Testing Secret sharing python API
  k = 3
  n = 4
  group = PairingGroup('SS512')

  s = SecretShare(group, True)
  sec = group.random(ZR)
  shares = s.genShares(sec, k, n)

  K = shares[0]
  print('\nOriginal secret: %s' % K)
  y = {group.init(ZR, 1):shares[1], group.init(ZR, 2):shares[2], group.init(ZR, 3):shares[3]}

  secret = s.recoverSecret(y)

  if(K == secret):
    print('\nSuccessfully recovered secret: %s' % secret)
  else:
    print('\nCould not recover the secret!')


开发者ID:SRI-CSL,项目名称:ENCODERS,代码行数:30,代码来源:secretshare.py

示例3: ObliviousTransfer

# 需要导入模块: from charm.toolbox.pairinggroup import PairingGroup [as 别名]
# 或者: from charm.toolbox.pairinggroup.PairingGroup import init [as 别名]
class ObliviousTransfer(Protocol):
    def __init__(self, messages=None, groupObj=None, common_input=None):        
        Protocol.__init__(self, None)        
        receiver_states = { 2:self.receiver_init2, 4:self.receiver_transfer4, 6:self.receiver_transfer6, 8:self.receiver_transfer8 }
        sender_states = { 1:self.sender_init1, 3:self.sender_init3, 5:self.sender_transfer5, 7:self.sender_transfer7, 9:self.sender_transfer9 }

        receiver_trans = { 2:4, 4:6, 6:8 }
        sender_trans = { 1:3, 3:[3,5], 5:7, 7:9 }
        # describe the parties involved and the valid transitions
        Protocol.addPartyType(self, RECEIVER, receiver_states, receiver_trans)
        Protocol.addPartyType(self, SENDER, sender_states, sender_trans, True)
#        Protocol.setSerializers(self, self.serialize, self.deserialize)
        # make sure 
        if groupObj == None:
            self.group = PairingGroup('SS512')
        else:
            self.group = groupObj
        # proof parameter generation
        if common_input == None: # generate common parameters to P and V
            db = {}
            self.__gen_setup = True
        else: # can be used as a sub-protocol if common_input is specified by caller
            db = common_input
            self.__gen_setup = False
        Protocol.setSubclassVars(self, self.group, db) 
        if messages != None:
            self.M, self.sig = [], []
            for i in range(0, len(messages)):
                self.M.append( bytes(messages[i], 'utf8') )
                print("bytes =>", self.M[i],", message =>", messages[i])                
#                self.M.append(self.group.hash(messages[i], ZR))
#                self.sig.append(messages[i])
        # dict to hold variables from interaction        

    def get_common(self):
        if self.__gen_setup:
            g, h = self.group.random(G1), self.group.random(G2)
            H = pair(g, h)
            Protocol.store(self, ('g', g), ('h', h), ('H', H) )
            return (g, h, H)
        else: # common parameters generated already
            return Protocol.get(self, ['g', 'h', 'H'])
    
    # msgs => dict of M -> H(M)
    def sender_init1(self):
        M = self.M
        print("SENDER 1: ")
        (g, h, H) = self.get_common()  
        x = self.group.random(ZR)
        y = g ** x
        print("send g =>", g)
        print("send h =>", h)
        print("send H =>", H)
        print("send x =>", x)
        print("send y =>", y)
        A, B, C = {}, {}, {}
        for i in range(0, len(self.M)):
            j = self.group.init(ZR, i+1)
            print("j =>", j)
            A[i] = g ** ~(x + j)
            B[i] = pair(A[i], h)  #, M[i])
            C[i] = { 'A':A[i], 'B':B[i] }
        
        S = { 'g':g, 'h':h, 'H':H, 'y':y }        
        Protocol.store(self, ('x', y), ('y',y), ('C', C) )
        Protocol.setState(self, 3)
        return { 'S':S, 'C':C , 'PoK':'SigmaProtocol1' }
    
    def sender_init3(self, input):
        print("SENDER 3: ", input)
        result = 'FAIL'
        pk = Protocol.get(self, ['g', 'H', 'h'], dict)
        if input == 'GO':
            PoK1 = SigmaProtocol1(self.group, pk)
            PoK1.setup( {'name':'prover', 'type':PoK1.PROVER, 'socket':self._socket} )
            PoK1.execute(PoK1.PROVER, close_sock=False)
#            print("PoK1 prover result =>", PoK1.result)

            if PoK1.result == 'OK':
           # transition to transfer phase
                Protocol.setState(self, 5)
                result = PoK1.result
#        else: # JAA - something to this effect (Error case doesn't work yet)
#           Protocol.setState(self, 3); return {'PoK': 'REDO' }
        # need store and get functions for db        
        return {'PoK': result }
    
    def sender_transfer5(self, input):
        print("SENDER 5: query =>", input)
        
        if input.get('PoK') != None: # continue
            Protocol.setState(self, 7)
            return 'OK'    
        Protocol.setState(self, None)
        return None
    
    def sender_transfer7(self, input):
#        print("SENDER 7: input =>", input)
        if input.get('PoK2') != None: 
#            pk = Protocol.get(self, ['g','g2','y'], dict)           
#.........这里部分代码省略.........
开发者ID:FinalF,项目名称:charm,代码行数:103,代码来源:protocol_cns07.py


注:本文中的charm.toolbox.pairinggroup.PairingGroup.init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。