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 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 __test(self, matrix): paillierEncrypt = PaillierEncrypt() paillierEncrypt.generate_key() publickey = paillierEncrypt.get_public_key() privatekey = paillierEncrypt.get_privacy_key() result = encrypt_matrix(publickey, matrix) decrypted_result = decrypt_matrix(privatekey, result) assert_matrix(matrix, decrypted_result)
def __test_matrix(self, matrix): paillierEncrypt = PaillierEncrypt() paillierEncrypt.generate_key() publickey = paillierEncrypt.get_public_key() privatekey = paillierEncrypt.get_privacy_key() enc_matrix = 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 = decrypt_matrix(privatekey, cleared_enc_matrix) assert_matrix(matrix, cleared_matrix)
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 = 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 = 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 = compute_XY(-0.5 * self.y_overlap, np.tile(enc_phi, (self.y_overlap.shape[0], 1))) enc_mapping_comp_A = 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 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 = encrypt_matrix(self.public_key, self.uB_overlap) enc_uB_overlap_2 = 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 = 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] else: components = super(EncryptedFTLHostModel, self).send_components() return self.__encrypt_components(components)
def __encrypt_components(self, components): encrypt_comp_0 = encrypt_matrix(self.public_key, components[0]) encrypt_comp_1 = encrypt_matrix(self.public_key, components[1]) encrypt_comp_2 = encrypt_matrix(self.public_key, components[2]) return [encrypt_comp_0, encrypt_comp_1, encrypt_comp_2]
def __encrypt_components(self, components): encrypt_UB_1 = encrypt_matrix(self.public_key, components[0]) encrypt_UB_2 = encrypt_matrix(self.public_key, components[1]) encrypt_mapping_comp_B = encrypt_matrix(self.public_key, components[2]) return [encrypt_UB_1, encrypt_UB_2, encrypt_mapping_comp_B]