def call(cls, role, transfer_variable, ind, *args):
        iter_num = 7
        re_encrypt_batches = 3
        encrypt_rate = 0.3
        key_size = 1024

        if role == consts.ARBITER:
            agg = paillier_cipher.Arbiter()
            agg.register_paillier_cipher(transfer_variable)
            cipher_dict = agg.paillier_keygen(key_size)
            re_cipher_time = agg.set_re_cipher_time(cipher_dict)
            agg.re_cipher(iter_num, re_cipher_time, cipher_dict, re_encrypt_batches)
            return re_cipher_time, cipher_dict

        elif role == consts.HOST:
            import random
            enable = random.random() > encrypt_rate
            agg = paillier_cipher.Host()
            agg.register_paillier_cipher(transfer_variable)
            host_cipher = agg.gen_paillier_pubkey(enable)
            if enable:
                re_cipher_time = random.randint(1, 5)
                agg.set_re_cipher_time(re_encrypt_times=re_cipher_time)
                init_w = [random.random()]
                w = [host_cipher.encrypt(v) for v in init_w]
                for i in range(re_cipher_time):
                    w = agg.re_cipher(w, iter_num, i * re_encrypt_batches)
                return re_cipher_time, init_w, w

        else:
            pass
Example #2
0
 def __init__(self):
     super(HomoLRHost, self).__init__()
     self.gradient_operator = None
     self.loss_history = []
     self.is_converged = False
     self.role = consts.HOST
     self.aggregator = aggregator.Host()
     self.model_weights = None
     self.cipher = paillier_cipher.Host()
Example #3
0
 def _init_model(self, params):
     super()._init_model(params)
     if self.component_properties.has_arbiter:
         self.cipher = paillier_cipher.Host()
     if params.encrypt_param.method in [consts.PAILLIER]:
         self.cipher.register_paillier_cipher(self.transfer_variable)
         self.use_encrypt = True
         self.gradient_operator = TaylorLogisticGradient()
         self.re_encrypt_batches = params.re_encrypt_batches
     else:
         self.use_encrypt = False
         self.gradient_operator = LogisticGradient()