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
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)
def distribute_encrypt(public_key, X): """ encrypt X :param X: DTable :return: a dictionary """ X2 = X.mapValues(lambda x: encrypt_matrix(public_key, x)) val = X2.collect() val = dict(val) return val