Пример #1
0
def test_key_exchange():
    commu.init(fed_conf_host)
    var_chan = make_variable_channel('test_key_exchange', fed_conf_host["federation"]["host"][0],
                                     fed_conf_host["federation"]["guest"][0])

    for times in range(5):
        for each in [2048, 3072, 4096, 6144, 8192]:
            k = make_agreement(remote_id='zhibang-d-014011', key_size=each)
            var_chan.send(k, tag="k")
Пример #2
0
 def _do_exchange(self, theta: Union[list, np.ndarray, torch.Tensor],
                  remote_id: str) -> Union[list, np.ndarray, torch.Tensor]:
     # step1
     seed = make_agreement(remote_id,
                           key_size=self.sec_param.key_exchange_size)
     encryptor, decryptor = generate_paillier_encryptor_decryptor(
         self.sec_param.he_key_length, seed)
     # step2
     enc_theta = iterative_encryption(encryptor, theta)
     self.broadcast_chan.gather(enc_theta, tag="theta")
     # step4
     enc_sum_theta = self.broadcast_chan.broadcast(tag="sum_theta")
     sum_theta = iterative_decryption(decryptor, enc_sum_theta)
     avg_theta = iterative_divide(sum_theta, 2.0)
     return avg_theta
Пример #3
0
    def __init__(self, federal_info: dict, sec_param: dict):
        """

        Args:
            federal_info:
            sec_param:
        """
        if sec_param is not None:
            self.load_default_sec_param(
                path.join(path.dirname(__file__), 'sec_param.json'))
        super().__init__(federal_info, sec_param)
        self._make_channel()

        self.seed = make_agreement(remote_id=self.federal_info.host[0],
                                   key_size=self.sec_param.key_exchange_size)
        # step1
        self.encryptor = generate_onetime_pad_encryptor(
            hashlib.sha512(str(self.seed).encode('utf-8')).digest())
Пример #4
0
import os
import json

from flex.tools.ionic import commu
from flex.crypto.key_exchange.api import make_agreement
from test.fed_config_example import fed_conf_host

if __name__ == '__main__':
    commu.init(fed_conf_host)

    k = make_agreement(remote_id='zhibang-d-014011', key_size=2048)
    print(k)
Пример #5
0
 def _encrypt(self, ids):
     seed = make_agreement(self.remote_id, self.key_size)
     seed_bytes = seed.to_bytes(math.ceil(seed.bit_length() / 8), 'big')
     aes = AES.new(hashlib.md5(seed_bytes).digest(), AES.MODE_ECB)
     encrypted_ids = list(map(lambda x: aes.encrypt(hashlib.md5(str(x).encode('utf-8')).digest()), ids))
     return encrypted_ids