Beispiel #1
0
 def _send_histograms(self, name, hists):
     msg = tree_pb2.Histograms()
     for hist in hists:
         ciphertext = _encode_encrypted_numbers(hist)
         msg.hists.append(
             tree_pb2.EncryptedNumbers(ciphertext=ciphertext))
     self._bridge.send_proto(self._bridge.current_iter_id, name, msg)
Beispiel #2
0
def _encrypt_and_send_numbers(bridge, name, public_key, numbers):
    num_parts = (len(numbers) + MAX_PARTITION_SIZE - 1) // MAX_PARTITION_SIZE
    bridge.send_proto(bridge.current_iter_id, '%s_partition_info' % name,
                      tree_pb2.PartitionInfo(num_partitions=num_parts))
    for i in range(num_parts):
        part = numbers[i * MAX_PARTITION_SIZE:(i + 1) * MAX_PARTITION_SIZE]
        msg = tree_pb2.EncryptedNumbers()
        msg.ciphertext.extend(_encrypt_numbers(public_key, part))
        bridge.send_proto(bridge.current_iter_id, '%s_part_%d' % (name, i),
                          msg)
Beispiel #3
0
def _receive_encrypted_numbers(bridge, name, public_key):
    part_info = tree_pb2.PartitionInfo()
    bridge.receive_proto(bridge.current_iter_id,
                         '%s_partition_info' % name).Unpack(part_info)
    ret = []
    for i in range(part_info.num_partitions):
        msg = tree_pb2.EncryptedNumbers()
        bridge.receive_proto(bridge.current_iter_id,
                             '%s_part_%d' % (name, i)).Unpack(msg)
        ret.extend(_from_ciphertext(public_key, msg.ciphertext))
    return ret
Beispiel #4
0
def _receive_public_key(bridge):
    msg = tree_pb2.EncryptedNumbers()
    bridge.receive_proto(bridge.current_iter_id, 'public_key').Unpack(msg)
    return paillier.PaillierPublicKey(
        int.from_bytes(msg.ciphertext[0], 'little'))
Beispiel #5
0
def _send_public_key(bridge, public_key):
    msg = tree_pb2.EncryptedNumbers()
    msg.ciphertext.append(public_key.n.to_bytes(KEY_NBITS // 8, 'little'))
    bridge.send_proto(bridge.current_iter_id, 'public_key', msg)
Beispiel #6
0
def _receive_encrypted_numbers(bridge, name, public_key):
    msg = tree_pb2.EncryptedNumbers()
    bridge.receive_proto(bridge.current_iter_id, name).Unpack(msg)
    return _from_ciphertext(public_key, msg.ciphertext)
Beispiel #7
0
def _encrypt_and_send_numbers(bridge, name, public_key, numbers):
    msg = tree_pb2.EncryptedNumbers()
    msg.ciphertext.extend(_encrypt_numbers(public_key, numbers))
    bridge.send_proto(bridge.current_iter_id, name, msg)