test_psi_ecdh.py 703 B

12345678910111213141516171819202122232425
  1. from fate_crypto.psi import Curve25519
  2. import pickle
  3. import unittest
  4. import random
  5. class TestStringMethods(unittest.TestCase):
  6. def test_ecdh(self):
  7. k1 = Curve25519()
  8. k2 = Curve25519()
  9. m = random.SystemRandom().getrandbits(33 * 8).to_bytes(33, "little")
  10. self.assertEqual(
  11. k2.diffie_hellman(k1.encrypt(m)), k1.diffie_hellman(k2.encrypt(m))
  12. )
  13. def test_pickle(self):
  14. k1 = Curve25519()
  15. m = random.SystemRandom().getrandbits(33 * 8).to_bytes(33, "little")
  16. pickled = pickle.dumps(k1)
  17. k2 = pickle.loads(pickled)
  18. self.assertEqual(k1.encrypt(m), k2.encrypt(m))
  19. if __name__ == "__main__":
  20. unittest.main()