Skip to content

Commit 54e5301

Browse files
committed
depend on lightecc
1 parent b289514 commit 54e5301

19 files changed

+13
-2805
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,19 +236,17 @@ ECC is a powerful public-key cryptosystem based on the algebraic structure of el
236236
In LightPHE, the [Elliptic Curve ElGamal](https://sefiks.com/2018/08/21/elliptic-curve-elgamal-encryption/) scheme is implemented, offering a secure and efficient homomorphic encryption option.
237237

238238
```python
239-
forms = ["weierstass", "edwards", "koblitz"]
240-
241239
phe = LightPHE(
242240
algorithm_name="EllipticCurve-ElGamal",
243-
form=forms[1],
241+
form="edwards", # or weierstrass, koblitz
244242
)
245243
```
246244

247245
One of the crucial factors that define the security level of an elliptic curve cryptosystem is the order of the curve. The order of a curve is the number of points on the curve, and it directly influences the strength of the encryption. A higher order typically corresponds to a stronger cryptosystem, making it more resistant to cryptographic attacks.
248246

249247
Each curve in LightPHE has a specific order, which is carefully chosen to balance performance and security. By selecting an elliptic curve with a larger order, you increase the security of your cryptographic system, but this may come with a trade-off in computational efficiency. Therefore, choosing the appropriate curve order is a crucial decision based on your application’s security and performance requirements.
250248

251-
See [`curves`](https://github.com/serengil/LightPHE/tree/master/lightphe/elliptic_curve_forms) page for a list of all supported forms, curves and their details.
249+
See [`curves`](https://github.com/serengil/LightECC) page for a list of all supported forms, curves and their details.
252250

253251
### Vector Embeddings and Tensors
254252

lightphe/__init__.py

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99

1010
# 3rd party dependencies
1111
from tqdm import tqdm
12+
from lightecc.interfaces.elliptic_curve import EllipticCurvePoint
13+
from lightecc.forms.weierstrass import Weierstrass
14+
from lightecc.forms.edwards import TwistedEdwards
15+
from lightecc.forms.koblitz import Koblitz
1216

1317
# project dependencies
1418
from lightphe.models.Homomorphic import Homomorphic
1519
from lightphe.models.Ciphertext import Ciphertext
1620
from lightphe.models.Algorithm import Algorithm
1721
from lightphe.models.Tensor import Fraction, EncryptedTensor
18-
from lightphe.models.EllipticCurve import EllipticCurvePoint
1922
from lightphe.commons import phe_utils
2023
from lightphe.commons.logger import Logger
2124

@@ -29,9 +32,6 @@
2932
from lightphe.cryptosystems.NaccacheStern import NaccacheStern
3033
from lightphe.cryptosystems.GoldwasserMicali import GoldwasserMicali
3134
from lightphe.cryptosystems.EllipticCurveElGamal import EllipticCurveElGamal
32-
from lightphe.elliptic_curve_forms.weierstrass import Weierstrass
33-
from lightphe.elliptic_curve_forms.edwards import TwistedEdwards
34-
from lightphe.elliptic_curve_forms.koblitz import Koblitz
3535

3636

3737
# pylint: disable=eval-used, simplifiable-if-expression, too-few-public-methods
@@ -465,44 +465,3 @@ def encrypt_float(
465465
logger.error(f"Exception while running encrypt_float: {str(err)}")
466466
logger.error(traceback.format_exc())
467467
raise err
468-
469-
470-
class ECC:
471-
__version__ = VERSION
472-
473-
def __init__(
474-
self, form_name: Optional[str] = None, curve_name: Optional[str] = None
475-
):
476-
"""
477-
Construct an Elliptic Curve over a finite field (prime or binary)
478-
Args:
479-
form_name (str): specifies the form of the elliptic curve.
480-
Options: 'weierstrass' (default), 'edwards', 'koblitz'.
481-
curve_name (str): specifies the elliptic curve to use.
482-
Options:
483-
- e.g. ed25519, ed448 for edwards form
484-
- e.g. secp256k1 for weierstrass form
485-
- e.g. k-409 for koblitz form
486-
List of all available curves:
487-
github.com/serengil/LightPHE/blob/master/lightphe/elliptic_curve_forms/README.md
488-
"""
489-
if form_name is None or form_name == "weierstrass":
490-
self.curve = Weierstrass(curve=curve_name)
491-
elif form_name in "edwards":
492-
self.curve = TwistedEdwards(curve=curve_name)
493-
elif form_name in "koblitz":
494-
self.curve = Koblitz(curve=curve_name)
495-
else:
496-
raise ValueError(f"unimplemented curve form - {form_name}")
497-
498-
# base point
499-
self.G = EllipticCurvePoint(self.curve.G[0], self.curve.G[1], self.curve)
500-
501-
# order of the curve
502-
self.n = self.curve.n
503-
504-
# point at infinity or neutral / identity element
505-
self.O = EllipticCurvePoint(self.curve.O[0], self.curve.O[1], self.curve)
506-
507-
# modulo
508-
self.modulo = self.curve.modulo

lightphe/commons/binary_operations.py

Lines changed: 0 additions & 147 deletions
This file was deleted.

lightphe/cryptosystems/EllipticCurveElGamal.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
import random
33
from typing import Optional
44

5+
# 3rd party dependencies
6+
from lightecc import LightECC as ECC
7+
from lightecc.interfaces.elliptic_curve import EllipticCurvePoint
8+
59
# project dependencies
610
from lightphe.models.Homomorphic import Homomorphic
7-
from lightphe.models.EllipticCurve import EllipticCurvePoint
811
from lightphe.commons.logger import Logger
912

1013
logger = Logger(module="lightphe/cryptosystems/EllipticCurveElGamal.py")
@@ -40,9 +43,6 @@ def __init__(
4043
- secp256k1 for weierstrass form
4144
This parameter is only used if `algorithm_name` is 'EllipticCurve-ElGamal'.
4245
"""
43-
# to avoid circular import, import ECC class here
44-
from lightphe import ECC
45-
4646
self.ecc = ECC(form_name=form, curve_name=curve)
4747

4848
self.keys = keys or self.generate_keys(key_size or self.ecc.n.bit_length())

0 commit comments

Comments
 (0)