def run(self, data_instances): LOGGER.info("Start rsa intersection") encrypt_operator = RsaEncrypt() encrypt_operator.generate_key(rsa_bit=1024) self.e, self.d, self.n = encrypt_operator.get_key_pair() LOGGER.info("Generate rsa keys.") public_key = {"e": self.e, "n": self.n} remote(public_key, name=self.transfer_variable.rsa_pubkey.name, tag=self.transfer_variable.generate_transferid(self.transfer_variable.rsa_pubkey), role=consts.GUEST, idx=0) LOGGER.info("Remote public key to Guest.") # (host_id_process, 1) host_ids_process_pair = data_instances.map( lambda k, v: ( RsaIntersectionHost.hash(gmpy_math.powmod(int(RsaIntersectionHost.hash(k), 16), self.d, self.n)), k) ) host_ids_process = host_ids_process_pair.mapValues(lambda v: 1) remote(host_ids_process, name=self.transfer_variable.intersect_host_ids_process.name, tag=self.transfer_variable.generate_transferid(self.transfer_variable.intersect_host_ids_process), role=consts.GUEST, idx=0) LOGGER.info("Remote host_ids_process to Guest.") # Recv guest ids guest_ids = get(name=self.transfer_variable.intersect_guest_ids.name, tag=self.transfer_variable.generate_transferid(self.transfer_variable.intersect_guest_ids), idx=0) LOGGER.info("Get guest_ids from guest") # Process guest ids and return to guest guest_ids_process = guest_ids.map(lambda k, v: (k, gmpy_math.powmod(int(k), self.d, self.n))) remote(guest_ids_process, name=self.transfer_variable.intersect_guest_ids_process.name, tag=self.transfer_variable.generate_transferid(self.transfer_variable.intersect_guest_ids_process), role=consts.GUEST, idx=0) LOGGER.info("Remote guest_ids_process to Guest.") # recv intersect ids intersect_ids = None if self.get_intersect_ids_flag: encrypt_intersect_ids = get(name=self.transfer_variable.intersect_ids.name, tag=self.transfer_variable.generate_transferid( self.transfer_variable.intersect_ids), idx=0) intersect_ids_pair = encrypt_intersect_ids.join(host_ids_process_pair, lambda e, h: h) intersect_ids = intersect_ids_pair.map(lambda k, v: (v, "intersect_id")) LOGGER.info("Get intersect ids from Guest") if not self.only_output_key: intersect_ids = self._get_value_from_data(intersect_ids, data_instances) return intersect_ids
def run(self, data_instances): LOGGER.info("Start ras intersection") encrypt_operator = RsaEncrypt() encrypt_operator.generate_key(rsa_bit=1028) self.e, self.d, self.n = encrypt_operator.get_key_pair() LOGGER.info("Generate rsa keys.") public_key = {"e": self.e, "n": self.n} remote(public_key, name=self.transfer_variable.rsa_pubkey.name, tag=self.transfer_variable.generate_transferid(self.transfer_variable.rsa_pubkey), role=consts.GUEST, idx=0) LOGGER.info("Remote public key to Guest.") # (host_id_process, 1) table_host_ids_process = data_instances.map( lambda k, v: ( RsaIntersectionHost.hash(gmpy_math.powmod(int(RsaIntersectionHost.hash(k), 16), self.d, self.n)), 1) ) remote(table_host_ids_process, name=self.transfer_variable.intersect_host_ids_process.name, tag=self.transfer_variable.generate_transferid(self.transfer_variable.intersect_host_ids_process), role=consts.GUEST, idx=0) LOGGER.info("Remote host_ids_process to Guest.") # Recv guest ids guest_ids = get(name=self.transfer_variable.intersect_guest_ids.name, tag=self.transfer_variable.generate_transferid(self.transfer_variable.intersect_guest_ids), idx=0) LOGGER.info("Get guest_ids from guest") # Process guest ids and return to guest guest_ids_process = guest_ids.map(lambda k, v: (k, gmpy_math.powmod(int(k), self.d, self.n))) remote(guest_ids_process, name=self.transfer_variable.intersect_guest_ids_process.name, tag=self.transfer_variable.generate_transferid(self.transfer_variable.intersect_guest_ids_process), role=consts.GUEST, idx=0) LOGGER.info("Remote guest_ids_process to Guest.") # recv intersect ids intersect_ids = None if self.get_intersect_ids_flag: intersect_ids = get(name=self.transfer_variable.intersect_ids.name, tag=self.transfer_variable.generate_transferid(self.transfer_variable.intersect_ids), idx=0) LOGGER.info("Get intersect ids from Guest") return intersect_ids
def generate_rsa_key(self, rsa_bit=1024): encrypt_operator = RsaEncrypt() encrypt_operator.generate_key(rsa_bit) return encrypt_operator.get_key_pair()
def generate_rsa_key(rsa_bit=1024): LOGGER.info(f"Generate {rsa_bit}-bit RSA key.") encrypt_operator = RsaEncrypt() encrypt_operator.generate_key(rsa_bit) return encrypt_operator.get_key_pair()