Skip to content

Commit

Permalink
chore: add benchmark and readme (FederatedAI#3859)
Browse files Browse the repository at this point in the history
Signed-off-by: weiwee <[email protected]>
  • Loading branch information
sagewe committed Jun 21, 2022
1 parent 02bd9f2 commit 6a5f446
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
- name: Test Install
run: |
pip install -U pip
pip install --find-link=. fate_crypto
pip install --find-link=dist/ fate_crypto
- name: Upload to PyPI Test
if: ${{ github.event.inputs.type == 'testpypi' }}
run: |
Expand Down
4 changes: 4 additions & 0 deletions rust/fate_crypto/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# fate_crypto

This package contains some crypto algorithms implemented or wrapped
using Rust. It's for FATE use only!
4 changes: 2 additions & 2 deletions rust/fate_crypto/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ build-backend = "maturin"

[project]
name = "fate_crypto"
description = "crypto implemented or wrapped using rust"
readme = "README.md"
requires-python = ">=3.6"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]

33 changes: 33 additions & 0 deletions rust/fate_crypto/tests/test_psi_bench.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import random
import hashlib
from fate_crypto.psi import Curve25519


def ecdh(k, m):
return k.encrypt(m)


def dh(k, e):
return k.diffie_hellman(e)


def sha256(value):
return hashlib.sha256(bytes(value, encoding="utf-8")).digest()


def test_ecdh_encrypt_bench(benchmark):
k = Curve25519()
m = random.SystemRandom().getrandbits(256).to_bytes(32, "little")
result = benchmark(ecdh, k, m)


def test_ecdh_dh_bench(benchmark):
k = Curve25519()
m = random.SystemRandom().getrandbits(256).to_bytes(32, "little")
e = k.encrypt(m)
result = benchmark(dh, k, e)


def test_sha256_bench(benchmark):
m = "1000000000"
result = benchmark(sha256, m)

0 comments on commit 6a5f446

Please sign in to comment.