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
Exemplo n.º 2
0
    def __init__(self):
        super(HomoLRArbiter, self).__init__()
        self.re_encrypt_times = []  # Record the times needed for each host

        self.loss_history = []
        self.is_converged = False
        self.role = consts.ARBITER
        self.aggregator = aggregator.Arbiter()
        self.model_weights = None
        self.cipher = paillier_cipher.Arbiter()
        self.host_predict_results = []