(self, target_num)
return key_list
Derive a list of keys for encryption and transmission
        :param target_num: N in k-N OT
        :return: List[ObliviousTransferKey]
Derive a list of keys for encryption and transmission
        :param target_num: N in k-N OT
        :return: List[ObliviousTransferKey]
Derive a list of keys for encryption and transmission : param target_num : N in k - N OT : return : List [ ObliviousTransferKey ]
def key_derivation(self, target_num):
        """
        Derive a list of keys for encryption and transmission
        :param target_num: N in k-N OT
        :return: List[ObliviousTransferKey]
        """
        LOGGER.info("enter sender key derivation phase for target num = {}".format(target_num))
        # 1. Choose a random scalar (y) from Z^q, calculate S and T to verify its legality
        y, s, t = self._gen_legal_y_s_t()

        # 2. Send S to the receiver, if it is illegal addressed by the receiver, regenerate y, S, T
        attempt_count = 0
        while True:
            self.transfer_variable.s.remote(s,
                                            suffix=(attempt_count,),
                                            role=consts.GUEST,
                                            idx=0)
            # federation.remote(obj=s,
            #                   name=self.transfer_variable.s.name,
            #                   tag=self.transfer_variable.generate_transferid(self.transfer_variable.s, attempt_count),
            #                   role=consts.GUEST,
            #                   idx=0)
            LOGGER.info("sent S to guest for the {}-th time".format(attempt_count))
            s_legal = self.transfer_variable.s_legal.get(idx=0,
                                                         suffix=(attempt_count,))
            # s_legal = federation.get(name=self.transfer_variable.s_legal.name,
            #                          tag=self.transfer_variable.generate_transferid(self.transfer_variable.s_legal,
            #                                                                         attempt_count),
            #                          idx=0)
            if s_legal:
                LOGGER.info("receiver confirms the legality of S at {} attempt, will proceed".format(attempt_count))
                break
            else:
                LOGGER.info("receiver rejects this S at {} attempt, will regenerate S".format(attempt_count))
                y, s, t = self._gen_legal_y_s_t()
                attempt_count += 1

        # 3. Wait for the receiver to hash S to get T
        LOGGER.info("waiting for the receiver to hash S to get T")

        # 4. Get R = cT + xG from the receiver, also init the MAC
        r = self.transfer_variable.r.get(idx=0)
        # r = federation.get(name=self.transfer_variable.r.name,
        #                    tag=self.transfer_variable.generate_transferid(self.transfer_variable.r),
        #                    idx=0)
        LOGGER.info("got from guest R = " + r.output())
        self._init_mac(s, r)

        # 5. MAC and output the key list
        key_list = []
        yt = self.tec_arithmetic.mul(scalar=y, a=t)    # yT
        yr = self.tec_arithmetic.mul(scalar=y, a=r)    # yR
        for i in range(target_num):
            iyt = self.tec_arithmetic.mul(scalar=i, a=yt)    # iyT
            diff = self.tec_arithmetic.sub(a=yr, b=iyt)    # yR - iyT
            key = self._mac_tec_element(diff)
            # LOGGER.info("{}-th key generated".format(i))
            # LOGGER.info("key before MAC = " + diff.output())
            # LOGGER.info("key = {}".format(key))
            key_list.append(ObliviousTransferKey(i, key))

        LOGGER.info("all keys successfully generated")

        return key_list
def key_derivation ( self , target_num ) : LOGGER . info ( "enter sender key derivation phase for target num = {}" . format ( target_num ) ) # 1. Choose a random scalar (y) from Z^q, calculate S and T to verify its legality y , s , t = self . _gen_legal_y_s_t ( ) # 2. Send S to the receiver, if it is illegal addressed by the receiver, regenerate y, S, T attempt_count = 0 while True : self . transfer_variable . s . remote ( s , suffix = ( attempt_count , ) , role = consts . GUEST , idx = 0 ) # federation.remote(obj=s, #                   name=self.transfer_variable.s.name, #                   tag=self.transfer_variable.generate_transferid(self.transfer_variable.s, attempt_count), #                   role=consts.GUEST, #                   idx=0) LOGGER . info ( "sent S to guest for the {}-th time" . format ( attempt_count ) ) s_legal = self . transfer_variable . s_legal . get ( idx = 0 , suffix = ( attempt_count , ) ) # s_legal = federation.get(name=self.transfer_variable.s_legal.name, #                          tag=self.transfer_variable.generate_transferid(self.transfer_variable.s_legal, #                                                                         attempt_count), #                          idx=0) if s_legal : LOGGER . info ( "receiver confirms the legality of S at {} attempt, will proceed" . format ( attempt_count ) ) break else : LOGGER . info ( "receiver rejects this S at {} attempt, will regenerate S" . format ( attempt_count ) ) y , s , t = self . _gen_legal_y_s_t ( ) attempt_count += 1 # 3. Wait for the receiver to hash S to get T LOGGER . info ( "waiting for the receiver to hash S to get T" ) # 4. Get R = cT + xG from the receiver, also init the MAC r = self . transfer_variable . r . get ( idx = 0 ) # r = federation.get(name=self.transfer_variable.r.name, #                    tag=self.transfer_variable.generate_transferid(self.transfer_variable.r), #                    idx=0) LOGGER . info ( "got from guest R = " + r . output ( ) ) self . _init_mac ( s , r ) # 5. MAC and output the key list key_list = [ ] yt = self . tec_arithmetic . mul ( scalar = y , a = t ) # yT yr = self . tec_arithmetic . mul ( scalar = y , a = r ) # yR for i in range ( target_num ) : iyt = self . tec_arithmetic . mul ( scalar = i , a = yt ) # iyT diff = self . tec_arithmetic . sub ( a = yr , b = iyt ) # yR - iyT key = self . _mac_tec_element ( diff ) # LOGGER.info("{}-th key generated".format(i)) # LOGGER.info("key before MAC = " + diff.output()) # LOGGER.info("key = {}".format(key)) key_list . append ( ObliviousTransferKey ( i , key ) ) LOGGER . info ( "all keys successfully generated" ) return key_list