Esempio n. 1
0
 def setUp(self):
     self.tp = ThresholdParameters(3, 5)
     self.cp = CurveParameters()
     self.pk, self.shares = central.create_public_key_and_shares_centralized(self.cp, self.tp)
     self.message = 'Some secret message'
     self.em = central.encrypt_message(self.message, self.pk)
     self.reconstruct_shares = [self.shares[i] for i in [0, 2, 4]]  # choose 3 of 5 key shares
     self.partial_decryptions = [participant.compute_partial_decryption(self.em, share) for share in self.reconstruct_shares]
Esempio n. 2
0
    def test_complete_process_without_enough_shares(self):
        curve_params = CurveParameters()
        thresh_params = ThresholdParameters(3, 5)

        pub_key, key_shares = central.create_public_key_and_shares_centralized(curve_params, thresh_params)

        message = 'Some secret message to be encrypted!'
        encrypted_message = central.encrypt_message(message, pub_key)

        reconstruct_shares = [key_shares[i] for i in [3, 4]]  # choose 2 of 5 key shares
        partial_decryptions = [participant.compute_partial_decryption(encrypted_message, share) for share in reconstruct_shares]

        with self.assertRaises(ThresholdCryptoError):
            central.decrypt_message(partial_decryptions, encrypted_message, thresh_params)
Esempio n. 3
0
    def test_distributed_key_generation(self):
        participant_ids = list(range(1, self.tp.n + 1))
        participants = [participant.Participant(id, participant_ids, self.cp, self.tp) for id in participant_ids]

        # via broadcast
        for pi in participants:
            for pj in participants:
                if pj != pi:
                    closed_commitment = pj.closed_commmitment()
                    pi.receive_closed_commitment(closed_commitment)

        # via broadcast
        for pi in participants:
            for pj in participants:
                if pj != pi:
                    open_commitment = pj.open_commitment()
                    pi.receive_open_commitment(open_commitment)

        public_key = participants[0].compute_public_key()
        for pk in [p.compute_public_key() for p in participants[1:]]:
            self.assertEqual(public_key, pk)

        # via broadcast
        for pi in participants:
            for pj in participants:
                if pj != pi:
                    F_ij = pj.F_ij_value()
                    pi.receive_F_ij_value(F_ij)

        # SECRETLY from i to j
        for pi in participants:
            for pj in participants:
                if pj != pi:
                    s_ij = pj.s_ij_value_for_participant(pi.id)
                    pi.receive_sij(s_ij)

        shares = [p.compute_share() for p in participants]

        # test encryption/decryption

        em = central.encrypt_message(self.message, public_key)

        pdms = [participant.compute_partial_decryption(em, ks) for ks in shares[:self.tp.t]]
        dm = central.decrypt_message(pdms, em, self.tp)

        self.assertEqual(dm, self.message)
Esempio n. 4
0
    def test_message_encryption(self):
        em = central.encrypt_message(self.message, self.pk)

        self.assertTrue(em.C1)
        self.assertTrue(em.C2)
        self.assertTrue(em.ciphertext)