lightphe 0.0.24__tar.gz → 0.0.25__tar.gz
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.
- {lightphe-0.0.24 → lightphe-0.0.25}/PKG-INFO +13 -18
- {lightphe-0.0.24 → lightphe-0.0.25}/README.md +12 -17
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/__init__.py +1 -2
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/cryptosystems/NaccacheStern.py +9 -7
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe.egg-info/PKG-INFO +13 -18
- {lightphe-0.0.24 → lightphe-0.0.25}/setup.py +1 -1
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_naccache.py +4 -5
- {lightphe-0.0.24 → lightphe-0.0.25}/LICENSE +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/commons/__init__.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/commons/key_validator.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/commons/logger.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/commons/phe_utils.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/cryptosystems/Benaloh.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/cryptosystems/BonehGohNissim.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/cryptosystems/DamgardJurik.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/cryptosystems/ElGamal.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/cryptosystems/EllipticCurveElGamal.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/cryptosystems/GoldwasserMicali.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/cryptosystems/OkamotoUchiyama.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/cryptosystems/Paillier.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/cryptosystems/RSA.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/cryptosystems/SanderYoungYung.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/cryptosystems/__init__.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/models/Algorithm.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/models/Ciphertext.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/models/Homomorphic.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/models/Tensor.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe/models/__init__.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe.egg-info/SOURCES.txt +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe.egg-info/dependency_links.txt +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe.egg-info/requires.txt +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/lightphe.egg-info/top_level.txt +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/requirements.txt +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/setup.cfg +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/__init__.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_benaloh.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_bonehgohnissim.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_ciphertexts.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_cloud.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_damgard.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_elgamal.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_ellipticcurveelgamal.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_exporting_keys.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_goldwasser.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_key_validator.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_keys.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_large_keys.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_okamoto.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_paillier.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_rsa.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_salary.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_sanderyoungyung.py +0 -0
- {lightphe-0.0.24 → lightphe-0.0.25}/tests/test_tensors.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: lightphe
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.25
|
|
4
4
|
Summary: A Lightweight Partially Homomorphic Encryption Library for Python
|
|
5
5
|
Home-page: https://github.com/serengil/LightPHE
|
|
6
6
|
Author: Sefik Ilkin Serengil
|
|
@@ -65,7 +65,7 @@ from lightphe import LightPHE
|
|
|
65
65
|
|
|
66
66
|
# Summary of Homomorphic Features of Different Cryptosystems in LightPHE
|
|
67
67
|
|
|
68
|
-
In summary, LightPHE is covering following algorithms and these are partially homomorphic with respect to the operations mentioned in the following table.
|
|
68
|
+
In summary, LightPHE is covering following algorithms and these are partially homomorphic and somewhat homomorphic with respect to the operations mentioned in the following table.
|
|
69
69
|
|
|
70
70
|
| Algorithm | Multiplicatively<br>Homomorphic | Additively<br>Homomorphic | Scalar Multiplication | Bitwise-XOR Homomorphic | Bitwise-AND Homomorphic | Regeneration<br>of Ciphertext |
|
|
71
71
|
| --- | --- | --- | --- | --- | --- | --- |
|
|
@@ -248,22 +248,17 @@ Also, your company's logo will be shown on README on GitHub if you become sponso
|
|
|
248
248
|
Please cite LightPHE in your publications if it helps your research. Here is its BibTex entry:
|
|
249
249
|
|
|
250
250
|
```BibTeX
|
|
251
|
-
@article{
|
|
252
|
-
title={
|
|
253
|
-
author={
|
|
254
|
-
journal={
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
title={Encrypted Vector Similarity Computations Using Partially Homomorphic Encryption: Applications and Performance Analysis},
|
|
263
|
-
author={Serengil, Sefik and Ozpinar, Alper},
|
|
264
|
-
journal={arXiv preprint arXiv:2503.05850},
|
|
265
|
-
note={doi: 10.48550/arXiv.2503.05850. [Online]. Available: \url{https://arxiv.org/abs/2503.05850}},
|
|
266
|
-
year={2025}
|
|
251
|
+
@article{sym18050832,
|
|
252
|
+
title = {Sustainable Cryptography: Carbon Asymmetry in Partially Homomorphic Encryption in the Cloud},
|
|
253
|
+
author = {Ozpinar, Alper and Serengil, Sefik Ilkin},
|
|
254
|
+
journal = {Symmetry},
|
|
255
|
+
volume = {18},
|
|
256
|
+
number = {5},
|
|
257
|
+
pages = {832},
|
|
258
|
+
url = {https://www.mdpi.com/2073-8994/18/5/832},
|
|
259
|
+
doi = {10.3390/sym18050832},
|
|
260
|
+
note = {Special Issue: Symmetry in Cryptography and Cybersecurity},
|
|
261
|
+
year = {2026}
|
|
267
262
|
}
|
|
268
263
|
```
|
|
269
264
|
|
|
@@ -49,7 +49,7 @@ from lightphe import LightPHE
|
|
|
49
49
|
|
|
50
50
|
# Summary of Homomorphic Features of Different Cryptosystems in LightPHE
|
|
51
51
|
|
|
52
|
-
In summary, LightPHE is covering following algorithms and these are partially homomorphic with respect to the operations mentioned in the following table.
|
|
52
|
+
In summary, LightPHE is covering following algorithms and these are partially homomorphic and somewhat homomorphic with respect to the operations mentioned in the following table.
|
|
53
53
|
|
|
54
54
|
| Algorithm | Multiplicatively<br>Homomorphic | Additively<br>Homomorphic | Scalar Multiplication | Bitwise-XOR Homomorphic | Bitwise-AND Homomorphic | Regeneration<br>of Ciphertext |
|
|
55
55
|
| --- | --- | --- | --- | --- | --- | --- |
|
|
@@ -232,22 +232,17 @@ Also, your company's logo will be shown on README on GitHub if you become sponso
|
|
|
232
232
|
Please cite LightPHE in your publications if it helps your research. Here is its BibTex entry:
|
|
233
233
|
|
|
234
234
|
```BibTeX
|
|
235
|
-
@article{
|
|
236
|
-
title={
|
|
237
|
-
author={
|
|
238
|
-
journal={
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
title={Encrypted Vector Similarity Computations Using Partially Homomorphic Encryption: Applications and Performance Analysis},
|
|
247
|
-
author={Serengil, Sefik and Ozpinar, Alper},
|
|
248
|
-
journal={arXiv preprint arXiv:2503.05850},
|
|
249
|
-
note={doi: 10.48550/arXiv.2503.05850. [Online]. Available: \url{https://arxiv.org/abs/2503.05850}},
|
|
250
|
-
year={2025}
|
|
235
|
+
@article{sym18050832,
|
|
236
|
+
title = {Sustainable Cryptography: Carbon Asymmetry in Partially Homomorphic Encryption in the Cloud},
|
|
237
|
+
author = {Ozpinar, Alper and Serengil, Sefik Ilkin},
|
|
238
|
+
journal = {Symmetry},
|
|
239
|
+
volume = {18},
|
|
240
|
+
number = {5},
|
|
241
|
+
pages = {832},
|
|
242
|
+
url = {https://www.mdpi.com/2073-8994/18/5/832},
|
|
243
|
+
doi = {10.3390/sym18050832},
|
|
244
|
+
note = {Special Issue: Symmetry in Cryptography and Cybersecurity},
|
|
245
|
+
year = {2026}
|
|
251
246
|
}
|
|
252
247
|
```
|
|
253
248
|
|
|
@@ -32,12 +32,11 @@ from lightphe.cryptosystems.EllipticCurveElGamal import EllipticCurveElGamal
|
|
|
32
32
|
from lightphe.cryptosystems.SanderYoungYung import SanderYoungYung
|
|
33
33
|
from lightphe.cryptosystems.BonehGohNissim import BonehGohNissim
|
|
34
34
|
|
|
35
|
-
|
|
36
35
|
# pylint: disable=eval-used, simplifiable-if-expression, too-few-public-methods
|
|
37
36
|
|
|
38
37
|
logger = Logger(module="lightphe/__init__.py")
|
|
39
38
|
|
|
40
|
-
VERSION = "0.0.
|
|
39
|
+
VERSION = "0.0.25"
|
|
41
40
|
|
|
42
41
|
|
|
43
42
|
class LightPHE:
|
|
@@ -22,7 +22,7 @@ class NaccacheStern(Homomorphic):
|
|
|
22
22
|
|
|
23
23
|
REQUIRED_KEYS = {
|
|
24
24
|
"public_key": ["n", "g", "sigma"],
|
|
25
|
-
"private_key": ["a", "b", "p", "q", "phi"
|
|
25
|
+
"private_key": ["a", "b", "p", "q", "phi"],
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
def __init__(
|
|
@@ -59,10 +59,11 @@ class NaccacheStern(Homomorphic):
|
|
|
59
59
|
Returns:
|
|
60
60
|
keys (dict): containing 'private_key' and 'public_key'
|
|
61
61
|
"""
|
|
62
|
-
# Small
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
|
|
62
|
+
# Small primes are required so DLP remains solvable during decryption.
|
|
63
|
+
# Picking 4 out of these 8 keeps sigma small (<= ~23^4) and splits
|
|
64
|
+
# evenly into u and v.
|
|
65
|
+
small_primes = [3, 5, 7, 11, 13, 17, 19, 23]
|
|
66
|
+
prime_set = sorted(random.sample(small_primes, 4))
|
|
66
67
|
k = len(prime_set)
|
|
67
68
|
|
|
68
69
|
if all(sympy.isprime(prime) is True for prime in prime_set) is False:
|
|
@@ -172,7 +173,6 @@ class NaccacheStern(Homomorphic):
|
|
|
172
173
|
"p": p,
|
|
173
174
|
"q": q,
|
|
174
175
|
"phi": phi,
|
|
175
|
-
"prime_set": prime_set,
|
|
176
176
|
},
|
|
177
177
|
}
|
|
178
178
|
logger.debug(
|
|
@@ -232,7 +232,9 @@ class NaccacheStern(Homomorphic):
|
|
|
232
232
|
phi = self.keys["private_key"]["phi"]
|
|
233
233
|
n = self.keys["public_key"]["n"]
|
|
234
234
|
g = self.keys["public_key"]["g"]
|
|
235
|
-
|
|
235
|
+
sigma = self.keys["public_key"]["sigma"]
|
|
236
|
+
# sigma is the product of the small primes; recover them by factoring.
|
|
237
|
+
prime_set = sorted(sympy.factorint(sigma).keys())
|
|
236
238
|
|
|
237
239
|
remainders = []
|
|
238
240
|
for i, prime in enumerate(prime_set):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: lightphe
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.25
|
|
4
4
|
Summary: A Lightweight Partially Homomorphic Encryption Library for Python
|
|
5
5
|
Home-page: https://github.com/serengil/LightPHE
|
|
6
6
|
Author: Sefik Ilkin Serengil
|
|
@@ -65,7 +65,7 @@ from lightphe import LightPHE
|
|
|
65
65
|
|
|
66
66
|
# Summary of Homomorphic Features of Different Cryptosystems in LightPHE
|
|
67
67
|
|
|
68
|
-
In summary, LightPHE is covering following algorithms and these are partially homomorphic with respect to the operations mentioned in the following table.
|
|
68
|
+
In summary, LightPHE is covering following algorithms and these are partially homomorphic and somewhat homomorphic with respect to the operations mentioned in the following table.
|
|
69
69
|
|
|
70
70
|
| Algorithm | Multiplicatively<br>Homomorphic | Additively<br>Homomorphic | Scalar Multiplication | Bitwise-XOR Homomorphic | Bitwise-AND Homomorphic | Regeneration<br>of Ciphertext |
|
|
71
71
|
| --- | --- | --- | --- | --- | --- | --- |
|
|
@@ -248,22 +248,17 @@ Also, your company's logo will be shown on README on GitHub if you become sponso
|
|
|
248
248
|
Please cite LightPHE in your publications if it helps your research. Here is its BibTex entry:
|
|
249
249
|
|
|
250
250
|
```BibTeX
|
|
251
|
-
@article{
|
|
252
|
-
title={
|
|
253
|
-
author={
|
|
254
|
-
journal={
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
title={Encrypted Vector Similarity Computations Using Partially Homomorphic Encryption: Applications and Performance Analysis},
|
|
263
|
-
author={Serengil, Sefik and Ozpinar, Alper},
|
|
264
|
-
journal={arXiv preprint arXiv:2503.05850},
|
|
265
|
-
note={doi: 10.48550/arXiv.2503.05850. [Online]. Available: \url{https://arxiv.org/abs/2503.05850}},
|
|
266
|
-
year={2025}
|
|
251
|
+
@article{sym18050832,
|
|
252
|
+
title = {Sustainable Cryptography: Carbon Asymmetry in Partially Homomorphic Encryption in the Cloud},
|
|
253
|
+
author = {Ozpinar, Alper and Serengil, Sefik Ilkin},
|
|
254
|
+
journal = {Symmetry},
|
|
255
|
+
volume = {18},
|
|
256
|
+
number = {5},
|
|
257
|
+
pages = {832},
|
|
258
|
+
url = {https://www.mdpi.com/2073-8994/18/5/832},
|
|
259
|
+
doi = {10.3390/sym18050832},
|
|
260
|
+
note = {Special Issue: Symmetry in Cryptography and Cybersecurity},
|
|
261
|
+
year = {2026}
|
|
267
262
|
}
|
|
268
263
|
```
|
|
269
264
|
|
|
@@ -8,7 +8,7 @@ with open("requirements.txt", "r", encoding="utf-8") as f:
|
|
|
8
8
|
|
|
9
9
|
setuptools.setup(
|
|
10
10
|
name="lightphe",
|
|
11
|
-
version="0.0.
|
|
11
|
+
version="0.0.25",
|
|
12
12
|
author="Sefik Ilkin Serengil",
|
|
13
13
|
author_email="serengil@gmail.com",
|
|
14
14
|
description="A Lightweight Partially Homomorphic Encryption Library for Python",
|
|
@@ -23,7 +23,6 @@ def test_predefined_keys():
|
|
|
23
23
|
"p": 2435378721695886057509882054966317293278393717736720131443144187793510457493213363945300094351007614623267282257550830261688773235268185768920658432760349591,
|
|
24
24
|
"q": 30909025587173888031151320439694649143770740813345918276468695473548278783448460260839705132326515527669756851362284434022860932531472563869828240743607816519,
|
|
25
25
|
"phi": 75275183223356977395233015128636801841182684353869611205877871399639096259927846711964449336873721703958210179653876541687516247046310691985977881277598653806134265954388527744361895141375770783671899073915178636812972605279037227887538978553609742276161772286758627935090233305041395360684118422229078186256527620,
|
|
26
|
-
"prime_set": [3, 5, 7, 11, 13, 17],
|
|
27
26
|
},
|
|
28
27
|
}
|
|
29
28
|
|
|
@@ -33,7 +32,7 @@ def test_predefined_keys():
|
|
|
33
32
|
|
|
34
33
|
security_level = cs.cs.keys["public_key"]["n"].bit_length()
|
|
35
34
|
|
|
36
|
-
logger.
|
|
35
|
+
logger.debug(
|
|
37
36
|
f"Naccache-Stern cs built with {security_level} bits key. Recommended >= 768."
|
|
38
37
|
)
|
|
39
38
|
|
|
@@ -44,13 +43,13 @@ def test_predefined_keys():
|
|
|
44
43
|
c1 = cs.encrypt(plaintext=m1)
|
|
45
44
|
c2 = cs.encrypt(plaintext=m2)
|
|
46
45
|
toc = time.time()
|
|
47
|
-
logger.
|
|
46
|
+
logger.debug(f"Naccache-Stern encryption time: {(toc - tic)/2:.4f} seconds")
|
|
48
47
|
|
|
49
48
|
# homomorphic addition
|
|
50
49
|
tic = time.time()
|
|
51
50
|
assert cs.decrypt(c1 + c2) == m1 + m2
|
|
52
51
|
toc = time.time()
|
|
53
|
-
logger.
|
|
52
|
+
logger.debug(f"Naccache-Stern homomorphic addition time: {(toc - tic):.4f} seconds")
|
|
54
53
|
|
|
55
54
|
# homomorphic scalar multiplication
|
|
56
55
|
tic = time.time()
|
|
@@ -59,7 +58,7 @@ def test_predefined_keys():
|
|
|
59
58
|
m2_times_c1 = m2 * c1
|
|
60
59
|
m1_times_c2 = m1 * c2
|
|
61
60
|
toc = time.time()
|
|
62
|
-
logger.
|
|
61
|
+
logger.debug(
|
|
63
62
|
f"Naccache-Stern homomorphic scalar multiplication time: {(toc - tic)/4:.4f} seconds"
|
|
64
63
|
)
|
|
65
64
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|