Skip to content

Commit 960288a

Browse files
committed
we were copying private into ciphertext object accidentally
1 parent 1876686 commit 960288a

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

lightphe/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import multiprocessing
66
from contextlib import closing
77
import traceback
8+
import copy
89

910
# 3rd party dependencies
1011
from tqdm import tqdm
@@ -178,9 +179,14 @@ def encrypt(
178179
value=plaintext, modulo=self.cs.plaintext_modulo
179180
)
180181
)
182+
183+
public_keys = self.cs.keys.copy()
184+
if public_keys.get("private_key") is not None:
185+
del public_keys["private_key"]
186+
181187
return Ciphertext(
182188
algorithm_name=self.algorithm_name,
183-
keys=self.cs.keys,
189+
keys=public_keys,
184190
value=ciphertext,
185191
form=self.form,
186192
curve=self.curve,
@@ -254,9 +260,13 @@ def __encrypt_tensors(self, tensor: list, silent: bool = False) -> EncryptedTens
254260
toc = time.time()
255261
logger.debug(f"encryption took {toc - tic} seconds")
256262

263+
public_cs = copy.deepcopy(self.cs)
264+
if public_cs.keys.get("private_key") is not None:
265+
del public_cs.keys["private_key"]
266+
257267
return EncryptedTensor(
258268
fractions=encrypted_tensor,
259-
cs=self.cs,
269+
cs=public_cs,
260270
precision=self.precision,
261271
)
262272

tests/test_ciphertexts.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# 3rd party dependencies
2+
from lightphe import LightPHE
3+
4+
# project dependencies
5+
from lightphe.commons.logger import Logger
6+
7+
logger = Logger(module="tests/test_ciphertexts.py")
8+
9+
10+
def test_private_key_not_available_in_ciphertext():
11+
onprem_cs = LightPHE(algorithm_name="Paillier")
12+
13+
m = 17
14+
15+
c = onprem_cs.encrypt(m)
16+
17+
assert c.cs.keys.get("private_key") is None
18+
assert onprem_cs.cs.keys.get("private_key") is not None
19+
20+
logger.info("✅ Private key not available in ciphertext tests done")
21+
22+
23+
def test_private_key_not_available_in_encrypted_tensor():
24+
onprem_cs = LightPHE(algorithm_name="Paillier")
25+
26+
t = [1.5, 2.4, 3.3, 4.2, 5.1]
27+
28+
c = onprem_cs.encrypt(t, silent=True)
29+
30+
assert c.cs.keys.get("private_key") is None
31+
assert onprem_cs.cs.keys.get("private_key") is not None
32+
33+
logger.info("✅ Private key not available in encrypted tensor tests done")

0 commit comments

Comments
 (0)