test_psi_bench.py 686 B

123456789101112131415161718192021222324252627282930313233
  1. import random
  2. import hashlib
  3. from fate_crypto.psi import Curve25519
  4. def ecdh(k, m):
  5. return k.encrypt(m)
  6. def dh(k, e):
  7. return k.diffie_hellman(e)
  8. def sha256(value):
  9. return hashlib.sha256(bytes(value, encoding="utf-8")).digest()
  10. def test_ecdh_encrypt_bench(benchmark):
  11. k = Curve25519()
  12. m = random.SystemRandom().getrandbits(256).to_bytes(32, "little")
  13. result = benchmark(ecdh, k, m)
  14. def test_ecdh_dh_bench(benchmark):
  15. k = Curve25519()
  16. m = random.SystemRandom().getrandbits(256).to_bytes(32, "little")
  17. e = k.encrypt(m)
  18. result = benchmark(dh, k, e)
  19. def test_sha256_bench(benchmark):
  20. m = "1000000000"
  21. result = benchmark(sha256, m)