RtsPsiManager#
- class RtsPsiManager#
Client side of the PSI for federated learning module.
- compaction(self: pyhelayers.RtsPsiManager, final_indicator_vector: pyhelayers.CTileTensor) pyhelayers.CTileTensor #
Given the final indicator vector, encrypted under the flHe’s key, outputs a CTileTensor with original shape as the given data DoubleTensor shape, that contains the samples which are in the intersection in the first rows, and where all the other rows are encryptions of 0s.
- Parameters:
final_indicator_vector – The final indicator vector
- generate_indicator_vector(self: pyhelayers.RtsPsiManager, source_rts_id: int, masked_hash_table: pyhelayers.CTileTensor) pyhelayers.CTileTensor #
The RTS will receive from the aggregator the CTileTensor originated from other RTS to process. It should process it using this method and send the result back to the aggregator.
- Parameters:
source_rts_id – ID of the RTS that generated the hash table
masked_hash_table – The CTileTensor received from the aggregator.
- get_uids_mapping(self: pyhelayers.RtsPsiManager) numpy.ndarray[numpy.uint64] #
The first step to be run by the RTS. Insert the UIDs of the client to hash table and encrypt it. The result should be sent to the aggregator. This CTileTensor will then be sent to the other RTS.
- get_uninserted_uids(self: pyhelayers.RtsPsiManager) numpy.ndarray[numpy.uint64] #
Returns the list of UIDs that were not inserted to the hash table. A UID might not be inserted in the case where all the mappings that were generated using the Cuckoo hashing hash function, led to collision with some other UID.
- get_verbosity(self: pyhelayers.RtsPsiManager) pyhelayers.Verbosity #
Get the Verbosity level.
- insert_to_hash(self: pyhelayers.RtsPsiManager) pyhelayers.CTileTensor #
The first step to be run by the RTS. Insert the UIDs of the client to hash table and encrypt it. The result should be sent to the aggregator. This CTileTensor will then be sent to the other RTS.
- multiply_indicator_vectors(self: pyhelayers.RtsPsiManager, rtss_ids: numpy.ndarray[numpy.uint8], masked_indicator_vectors: pyhelayers.CTileTensorVector) pyhelayers.CTileTensor #
Given the indicator vectors generated by the other RTSs, encrypted under the flHe’s key, outputs a single indicator vector which is the product of all of them. Notice that the result of this function is not masked, and thus must not be shared with the aggregator, but only passed as an argument to the compaction function.
- Parameters:
rtss_ids – IDs of the RTSs that generated the indicator vector
masked_indicator_vectors – The indicator vectors. The order of the these must match the order of the RTSs IDs.
- set_verbosity(self: pyhelayers.RtsPsiManager, verbosity: pyhelayers.Verbosity) None #
Sets the verbosity level
- Parameters:
verbosity – Verbosity level
-
class RtsPsiManager#
A class for managing the Private Set Intersection for Federated Learning protocol between two parties.
The class is initialized by each party (a.k.a Remote Training System - RTS), and the protocol runs between them with a third player, the aggregator, acting as a mediator. The output of the protocol for each RTS is a CTileTensor encrypted under the public key of the aggregator, containing only the samples which are in the intersection of the samples of each RTS, in the same order.
Public Functions
-
RtsPsiManager(const HeContext &psiHe, const HeContext &flHe, uint8_t rtsId, const std::vector<uint64_t> &uids, const DoubleTensor &data, const std::vector<uint64_t> &clientsSecret, uint8_t uidBits = 64)#
A constructor.
- Parameters:
psiHe – The HeContext of the aggregator to be used in the Private Set Intersection algorithm.
flHe – The HeContext of the aggregator to be used in the Federated Learning algorithm.
rtsId – Unique ID of this RTS
uids – Unique Identifiers (UIDs) of the samples of the RTS
data – The samples of the RTS
clientsSecret – A secret that is shared between all the RTSs, and unknown by the aggregator
uidBits – The max width of every UID in bits. Default is 64
- Throws:
runtime_error – if number of UIDs doesn’t match number of samples
invalid_argument – if uidBits is bigger than 64 bits
invalid_argument – if clientsSecret size is not 2
-
inline const HeContext &getPsiHeContext()#
Returns the heContext of the aggregator to be used in the Private Set Intersection algorithm.
-
inline const HeContext &getFlHeContext()#
Returns the heContext of the aggregator to be used in the Federated Learning algorithm.
-
void insertToHash(CTileTensor &res)#
The first step to be run by the RTS.
Insert the UIDs of the client to hash table, mask it with a One Time Pad (OTP) and encrypt it. The result should be sent to the aggregator.
- Parameters:
res – An empty CTileTensor.
- Returns:
The mapping from UID index to the index it has been put to in the hash table
-
inline const std::vector<size_t> &getUidsMapping()#
Returns the mapping of the UIDs in the hash table.
The RTS needs to send it along with the hash table to the aggregator.
-
inline const std::vector<uint64_t> &getUninsertedUids()#
Returns the list of UIDs that were not inserted to the hash table.
A UID might not be inserted in the case where all the mappings that were generated using the Cuckoo hashing hash function, led to collision with some other UID.
-
void generateIndicatorVector(uint8_t sourceRtsId, CTileTensor &res, const CTileTensor &maskedHashTable) const#
The RTS will receive from the aggregator the encrypted and masked hash table originated from other RTS.
It should process it using this method and send the resulted encrypted and masked indicator vector back to the aggregator.
- Parameters:
sourceRtsId – ID of the RTS that generated the hash table
res – An empty CTileTensor.
maskedHashTable – The CTileTensor received from the aggregator.
-
void multiplyIndicatorVectors(CTileTensor &res, const std::vector<uint8_t> &rtssIds, const std::vector<CTileTensor> &maskedIndicatorVectors) const#
Given the indicator vectors generated by the other RTSs, encrypted under the flHe’s key, outputs a single indicator vector which is the product of all of them.
Notice that the result of this function is not masked, and thus must not be shared with the aggregator, but only passed as an argument to the compaction function.
- Parameters:
res – An empty CTileTensor
rtssIds – IDs of the RTSs that generated the indicator vector
maskedIndicatorVectors – The indicator vectors. The order of the these must match the order of the RTSs IDs.
-
void compaction(CTileTensor &res, const CTileTensor &finalIndicatorVector) const#
Given the final indicator vector, encrypted under the flHe’s key, outputs a CTileTensor with original shape as the given data DoubleTensor shape, that contains the samples which are in the intersection in the first rows, and where all the other rows are encryptions of 0s.
- Parameters:
res – An empty CTileTensor
finalIndicatorVector – The final indicator vector
-
RtsPsiManager(const HeContext &psiHe, const HeContext &flHe, uint8_t rtsId, const std::vector<uint64_t> &uids, const DoubleTensor &data, const std::vector<uint64_t> &clientsSecret, uint8_t uidBits = 64)#