示例#1
0
    def test_parallel_sequence_running_time(self):
        X = np.ones((50, 50))

        curr_time1 = time.time()
        encryption.encrypt_matrix(self.publickey, X)
        curr_time2 = time.time()
        seq_running_time = curr_time2 - curr_time1
        distribute_encrypt_matrix(self.publickey, X)
        curr_time3 = time.time()
        parallel_running_time = curr_time3 - curr_time2

        assert seq_running_time - parallel_running_time > 0
示例#2
0
    def send_components(self):
        if self.is_min_gen_enc:
            self.logger.debug("using min_gen_enc")

            self._compute_components()

            # phi has shape (1, feature_dim)
            # phi_2 has shape (feature_dim, feature_dim)
            enc_phi = encryption.encrypt_matrix(self.public_key, self.phi)
            enc_phi_2 = distribute_encrypt_matmul_2_ob(self.phi.transpose(),
                                                       enc_phi)

            # enc_y_overlap_2_phi_2 = 0.25 * np.expand_dims(self.y_overlap_2, axis=2) * enc_phi_2
            # enc_y_overlap_phi = -0.5 * self.y_overlap * enc_phi
            enc_y_overlap_2_phi_2 = distribute_compute_XY(
                0.25 * np.expand_dims(self.y_overlap_2, axis=2),
                np.tile(enc_phi_2, (self.y_overlap_2.shape[0], 1, 1)))
            enc_y_overlap_phi = distribute_compute_XY(
                -0.5 * self.y_overlap,
                np.tile(enc_phi, (self.y_overlap.shape[0], 1)))
            enc_mapping_comp_A = distribute_encrypt_matrix(
                self.public_key, self.mapping_comp_A)

            return [
                enc_y_overlap_2_phi_2, enc_y_overlap_phi, enc_mapping_comp_A
            ]
        else:
            components = super(EncryptedFTLGuestModel, self).send_components()
            return self.__encrypt_components(components)
示例#3
0
    def send_components(self):
        if self.is_min_gen_enc:
            self.logger.debug("using min_gen_enc")

            self._compute_components()

            # enc_uB_overlap has shape (len(overlap_indexes), feature_dim)
            # enc_uB_overlap_2 has shape (len(overlap_indexes), feature_dim, feature_dim)
            enc_uB_overlap = distribute_encrypt_matrix(self.public_key,
                                                       self.uB_overlap)
            enc_uB_overlap_2 = distribute_encrypt_matmul_3(
                np.expand_dims(self.uB_overlap, axis=2),
                np.expand_dims(enc_uB_overlap, axis=1))

            # enc_mapping_comp_B has shape (len(overlap_indexes), feature_dim)
            scale_factor = np.tile(
                (-1 / self.feature_dim),
                (enc_uB_overlap.shape[0], enc_uB_overlap.shape[1]))
            enc_mapping_comp_B = distribute_compute_XY(enc_uB_overlap,
                                                       scale_factor)
            # enc_mapping_comp_B = enc_uB_overlap * (-1 / self.feature_dim)
            # enc_mapping_comp_B = encrypt_matrix(self.public_key, self.mapping_comp_B)

            return [
                enc_uB_overlap, enc_uB_overlap_2, enc_mapping_comp_B,
                self.uB_overlap
            ]  #New!!!just for testing difference with the plaintext(for loss)
        else:
            components = super(EncryptedFTLHostModel, self).send_components()
            return self.__encrypt_components(components)
    def __test(self, matrix):
        paillierEncrypt = PaillierEncrypt()
        paillierEncrypt.generate_key()
        publickey = paillierEncrypt.get_public_key()
        privatekey = paillierEncrypt.get_privacy_key()

        result = distribute_encrypt_matrix(publickey, matrix)
        decrypted_result = distribute_decrypt_matrix(privatekey, result)
        assert_matrix(matrix, decrypted_result)
示例#5
0
    def __test_matrix(self, matrix):

        paillierEncrypt = PaillierEncrypt()
        paillierEncrypt.generate_key()
        publickey = paillierEncrypt.get_public_key()
        privatekey = paillierEncrypt.get_privacy_key()

        enc_matrix = distribute_encrypt_matrix(publickey, matrix)
        masked_enc_matrix, mask = add_random_mask(enc_matrix)

        cleared_enc_matrix = remove_random_mask(masked_enc_matrix, mask)
        cleared_matrix = distribute_decrypt_matrix(privatekey, cleared_enc_matrix)
        assert_matrix(matrix, cleared_matrix)
示例#6
0
 def __encrypt_components(self, components):
     enc_comp_0 = distribute_encrypt_matrix(self.public_key, components[0])
     enc_comp_1 = distribute_encrypt_matrix(self.public_key, components[1])
     enc_comp_2 = distribute_encrypt_matrix(self.public_key, components[2])
     return [enc_comp_0, enc_comp_1, enc_comp_2]