pryvx 2.4.8__py3-none-any.whl → 2.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pryvx/fl_client.py +2 -0
- pryvx/phe.py +6 -0
- pryvx/smpc.py +19 -44
- {pryvx-2.4.8.dist-info → pryvx-2.5.0.dist-info}/METADATA +1 -1
- {pryvx-2.4.8.dist-info → pryvx-2.5.0.dist-info}/RECORD +8 -8
- {pryvx-2.4.8.dist-info → pryvx-2.5.0.dist-info}/LICENSE +0 -0
- {pryvx-2.4.8.dist-info → pryvx-2.5.0.dist-info}/WHEEL +0 -0
- {pryvx-2.4.8.dist-info → pryvx-2.5.0.dist-info}/top_level.txt +0 -0
pryvx/fl_client.py
CHANGED
pryvx/phe.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import random
|
2
2
|
from sympy import mod_inverse, isprime, nextprime
|
3
3
|
import math
|
4
|
+
import hashlib
|
4
5
|
|
5
6
|
def generate_prime(bits=512):
|
6
7
|
while True:
|
@@ -29,6 +30,11 @@ class PHE:
|
|
29
30
|
@staticmethod
|
30
31
|
def encode(value, scale_factor=1000):
|
31
32
|
return int(round(value * scale_factor))
|
33
|
+
|
34
|
+
@staticmethod
|
35
|
+
def hash_to_bigint(data: str) -> int:
|
36
|
+
digest = hashlib.sha256(data.encode()).hexdigest()
|
37
|
+
return int(digest, 16)
|
32
38
|
|
33
39
|
@staticmethod
|
34
40
|
def decode(value, scale_factor=1000):
|
pryvx/smpc.py
CHANGED
@@ -1,59 +1,34 @@
|
|
1
1
|
import random
|
2
|
-
|
2
|
+
import hashlib
|
3
|
+
|
3
4
|
def getAdditiveShares(secret, N, fieldSize):
|
4
|
-
shares = [random.randrange(fieldSize) for
|
5
|
+
shares = [random.randrange(fieldSize) for _ in range(N-1)]
|
5
6
|
shares.append((secret - sum(shares)) % fieldSize )
|
6
7
|
return shares
|
7
|
-
|
8
|
-
def reconstructSecret(shares, fieldSize):
|
9
|
-
return sum(shares) % fieldSize
|
10
|
-
|
11
8
|
|
12
9
|
class SMPC:
|
13
10
|
def __init__(self) -> None:
|
14
|
-
self.BASE = 10
|
15
|
-
self.PRECISION_INTEGRAL = 8
|
16
|
-
self.PRECISION_FRACTIONAL = 8
|
17
11
|
self.fieldSize = 293973345475167247070445277780365744413
|
18
12
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
def
|
23
|
-
upscaled
|
24
|
-
field_element = upscaled % self.fieldSize
|
25
|
-
return field_element
|
13
|
+
def encode(self, secret, scale_factor=1000):
|
14
|
+
return int(secret * scale_factor)
|
15
|
+
|
16
|
+
def decode(self, upscaled, scale_factor=1000):
|
17
|
+
return upscaled / scale_factor
|
26
18
|
|
27
|
-
def
|
28
|
-
|
29
|
-
rational = upscaled / self.BASE**self.PRECISION_FRACTIONAL
|
30
|
-
return rational
|
19
|
+
def get_field_size(self):
|
20
|
+
return self.fieldSize
|
31
21
|
|
32
|
-
def get_secret_shares(self,
|
33
|
-
|
34
|
-
shares = getAdditiveShares(self.encode(m), N, self.fieldSize)
|
22
|
+
def get_secret_shares(self, secret, N):
|
23
|
+
shares = getAdditiveShares(secret, N, self.fieldSize)
|
35
24
|
return shares
|
36
25
|
|
37
|
-
def
|
38
|
-
|
39
|
-
return
|
40
|
-
|
41
|
-
def multiplication(self):
|
42
|
-
pass
|
43
|
-
|
44
|
-
def difference(self, shares_a, shares_b):
|
45
|
-
difference_shares = [(a - b) % self.fieldSize for a, b in zip(shares_a, shares_b)]
|
46
|
-
return self.decode(reconstructSecret(difference_shares, self.fieldSize))
|
26
|
+
def hash_to_bigint(self, data: str) -> int:
|
27
|
+
digest = hashlib.sha256(data.encode()).hexdigest()
|
28
|
+
return int(digest, 16)
|
47
29
|
|
48
|
-
def
|
49
|
-
|
50
|
-
reconstructed_difference = self.decode(reconstructSecret(difference_shares, self.fieldSize))
|
30
|
+
def reconstruct(self, share):
|
31
|
+
return share % self.fieldSize
|
51
32
|
|
52
|
-
|
53
|
-
|
54
|
-
elif reconstructed_difference > 0:
|
55
|
-
comparison_result = "a is greater than b"
|
56
|
-
else:
|
57
|
-
comparison_result = "a is less than b"
|
58
|
-
|
59
|
-
return comparison_result
|
33
|
+
def additive_reconstruct(self, shares):
|
34
|
+
return sum(shares) % self.fieldSize
|
@@ -1,16 +1,16 @@
|
|
1
1
|
pryvx/__init__.py,sha256=QvpYISJ8MH7XnbxC5iTMTycq7Svsld0NIbMozcndYjo,111
|
2
|
-
pryvx/fl_client.py,sha256=
|
2
|
+
pryvx/fl_client.py,sha256=9MFIlpdLbNemhiXvYPhJlJGZLdA2U8AzfxGuuNHlIaE,1301
|
3
3
|
pryvx/fl_ensemble.py,sha256=lvgvd-zJDSBh-RyMAjTyJZwu0eFiUNXfCU7J2Vk7g0g,715
|
4
4
|
pryvx/fl_server.py,sha256=LJdJkj2BJdXrMczy1qZBHN_fY-ZveH-vHvljwwgDv8k,2039
|
5
5
|
pryvx/gdp.py,sha256=ToLtWNvBKtSs-3Na1pGe_J6dWvBxXhV2raUJkNtKMg4,925
|
6
6
|
pryvx/ldp.py,sha256=WxBQLnZ_b2wNV1rlN7rtKXaQ5waUPPvnRus-4tUnCB8,810
|
7
|
-
pryvx/phe.py,sha256=
|
7
|
+
pryvx/phe.py,sha256=q4MhHVZaRacW_-iIJD3iveogh_xiEcQiAcRVpGH-MyI,3150
|
8
8
|
pryvx/pryvx_pb2.py,sha256=HlwY1zRVFReIaK8WZ8opJ1kd3_PQWSJEx-PZImWYlCM,1621
|
9
9
|
pryvx/pryvx_pb2_grpc.py,sha256=yn4mThL3XY8glPvZ9b1Fmj_c8JtAs1pTNp3m0JV9d3s,3425
|
10
10
|
pryvx/psi.py,sha256=V0BUJwYfiFWhKtEL27q45yxY7U-I7B4olKQhaGbgN50,1346
|
11
|
-
pryvx/smpc.py,sha256=
|
12
|
-
pryvx-2.
|
13
|
-
pryvx-2.
|
14
|
-
pryvx-2.
|
15
|
-
pryvx-2.
|
16
|
-
pryvx-2.
|
11
|
+
pryvx/smpc.py,sha256=MDHo53sOtz9hdRzKIlzp7qtAsLcBRyMkcaiq0t-ENMg,1051
|
12
|
+
pryvx-2.5.0.dist-info/LICENSE,sha256=pbIMXbaorAIVW-fDch2tvtZRkVA3mz-UnXQqeCf4LDg,1086
|
13
|
+
pryvx-2.5.0.dist-info/METADATA,sha256=4K48DR0a6n6qU7McakHRy_GDvtXVGEyEXjwAgh2E7hk,1066
|
14
|
+
pryvx-2.5.0.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
15
|
+
pryvx-2.5.0.dist-info/top_level.txt,sha256=1iHoeevu_FoFjdPg8HyMlgvHNUm1--9QEpFMaJEa4hw,6
|
16
|
+
pryvx-2.5.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|