lightecc 0.0.1__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.
- lightecc-0.0.1/LICENSE +21 -0
- lightecc-0.0.1/PKG-INFO +294 -0
- lightecc-0.0.1/README.md +277 -0
- lightecc-0.0.1/lightecc/__init__.py +55 -0
- lightecc-0.0.1/lightecc/commons/__init__.py +0 -0
- lightecc-0.0.1/lightecc/commons/binary_operations.py +147 -0
- lightecc-0.0.1/lightecc/commons/logger.py +42 -0
- lightecc-0.0.1/lightecc/curves/__init__.py +0 -0
- lightecc-0.0.1/lightecc/curves/edwards.py +139 -0
- lightecc-0.0.1/lightecc/curves/inventory.py +83 -0
- lightecc-0.0.1/lightecc/curves/koblitz.py +433 -0
- lightecc-0.0.1/lightecc/curves/weierstrass.py +931 -0
- lightecc-0.0.1/lightecc/forms/__init__.py +0 -0
- lightecc-0.0.1/lightecc/forms/edwards.py +89 -0
- lightecc-0.0.1/lightecc/forms/koblitz.py +166 -0
- lightecc-0.0.1/lightecc/forms/weierstrass.py +120 -0
- lightecc-0.0.1/lightecc/interfaces/__init__.py +0 -0
- lightecc-0.0.1/lightecc/interfaces/elliptic_curve.py +196 -0
- lightecc-0.0.1/lightecc/interfaces/form.py +29 -0
- lightecc-0.0.1/lightecc.egg-info/PKG-INFO +294 -0
- lightecc-0.0.1/lightecc.egg-info/SOURCES.txt +25 -0
- lightecc-0.0.1/lightecc.egg-info/dependency_links.txt +1 -0
- lightecc-0.0.1/lightecc.egg-info/requires.txt +2 -0
- lightecc-0.0.1/lightecc.egg-info/top_level.txt +1 -0
- lightecc-0.0.1/requirements.txt +2 -0
- lightecc-0.0.1/setup.cfg +4 -0
- lightecc-0.0.1/setup.py +27 -0
lightecc-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Sefik Ilkin Serengil
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
lightecc-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: lightecc
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Lightweight Elliptic Curve Cryptography for Python
|
|
5
|
+
Home-page: https://github.com/serengil/LightECC
|
|
6
|
+
Author: Sefik Ilkin Serengil
|
|
7
|
+
Author-email: serengil@gmail.com
|
|
8
|
+
License: UNKNOWN
|
|
9
|
+
Platform: UNKNOWN
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Requires-Python: >=3.5.5
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
|
|
17
|
+
# LightECC
|
|
18
|
+
|
|
19
|
+
<div align="center">
|
|
20
|
+
|
|
21
|
+
[](https://pepy.tech/project/lightecc)
|
|
22
|
+
[](https://github.com/serengil/LightECC/stargazers)
|
|
23
|
+
[](https://github.com/serengil/LightECC/actions/workflows/tests.yml)
|
|
24
|
+
[](https://github.com/serengil/LightECC/blob/master/LICENSE)
|
|
25
|
+
|
|
26
|
+
[](https://sefiks.com)
|
|
27
|
+
[](https://www.youtube.com/@sefiks?sub_confirmation=1)
|
|
28
|
+
[](https://twitter.com/intent/user?screen_name=serengil)
|
|
29
|
+
|
|
30
|
+
[](https://www.patreon.com/serengil?repo=lightecc)
|
|
31
|
+
[](https://github.com/sponsors/serengil)
|
|
32
|
+
[](https://buymeacoffee.com/serengil)
|
|
33
|
+
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
<p align="center"><img src="https://raw.githubusercontent.com/serengil/LightECC/master/images/starfish.jpg" width="240" height="240"></p>
|
|
37
|
+
|
|
38
|
+
LightECC is a lightweight elliptic curve cryptography library for its arithmetic for python. It is a hybrid library wrapping many elliptic curve forms such as [Weierstrass](https://sefiks.com/2016/03/13/the-math-behind-elliptic-curve-cryptography/), [Koblitz](https://sefiks.com/2016/03/13/the-math-behind-elliptic-curves-over-binary-field/) and [Edwards](https://sefiks.com/2018/12/19/a-gentle-introduction-to-edwards-curves/).
|
|
39
|
+
|
|
40
|
+
# Elliptic Curve Arithmetic
|
|
41
|
+
|
|
42
|
+
Building an elliptic curve cryptosystem is very straightforward in LightECC. You basically need to initialize a LightECC object with a form name and a curve name. By default, it constructs elliptic curves in Weierstras form.After that, you can retrieve the base point of the curve and perform various elliptic curve arithmetic operations, including addition, subtraction, multiplication, and division.
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from lightecc import LightECC
|
|
46
|
+
|
|
47
|
+
forms = ["weierstrass", "koblitz", "edwards"]
|
|
48
|
+
|
|
49
|
+
ec = LightECC(
|
|
50
|
+
form_name = "edwards",
|
|
51
|
+
curve_name = "ed25519",
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# get the base point
|
|
55
|
+
G = ec.G
|
|
56
|
+
|
|
57
|
+
# addition
|
|
58
|
+
_2G = G + G
|
|
59
|
+
_3G = _2G + G
|
|
60
|
+
_5G = _3G + _2G
|
|
61
|
+
_10G = _5G + _5G
|
|
62
|
+
|
|
63
|
+
# subtraction
|
|
64
|
+
_9G = _10G - G
|
|
65
|
+
|
|
66
|
+
# multiplication
|
|
67
|
+
_20G = 20 * G
|
|
68
|
+
_50G = 50 * G
|
|
69
|
+
|
|
70
|
+
# division
|
|
71
|
+
_25G = _50G / G
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Here, the [double-and-add](https://sefiks.com/2016/03/27/double-and-add-method/) method is used for multiplication, allowing it to be performed very quickly, regardless of the size of the multiplier.
|
|
75
|
+
|
|
76
|
+
On the other hand, division requires solving the [elliptic curve discrete logarithm problem](https://sefiks.com/2018/02/28/attacking-elliptic-curve-discrete-logarithm-problem/), which is computationally difficult.
|
|
77
|
+
|
|
78
|
+
# Point at Infinity or Neutral & Identity Element
|
|
79
|
+
|
|
80
|
+
The order of the elliptic curve is defined by the argument n in the constructed LightECC object. This represents the total number of points on the curve. It also serves as the [neutral or identity element](https://sefiks.com/2023/09/29/understanding-identity-element-in-elliptic-curves/) of the curve, meaning that adding this point to any other point does not change the result. Additionally, elliptic curves exhibit cyclic group properties beyond this point.
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
ec = LightECC()
|
|
84
|
+
|
|
85
|
+
# order of elliptic curve
|
|
86
|
+
n = ec.n
|
|
87
|
+
|
|
88
|
+
# neutral element
|
|
89
|
+
nG = n * G
|
|
90
|
+
|
|
91
|
+
# scalar multiplication
|
|
92
|
+
_17G = 17 * G
|
|
93
|
+
|
|
94
|
+
# proof of work for neutralism
|
|
95
|
+
assert _17G == _17G + nG
|
|
96
|
+
|
|
97
|
+
# proof of work for cyclic group
|
|
98
|
+
assert (n + 1) * G == G
|
|
99
|
+
assert (n + 2) * G == 2 * G
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
# Supported Curves
|
|
103
|
+
|
|
104
|
+
Below is a list of elliptic curves supported by LightECC. Each curve has a specific order (n), which defines the number of points in the finite field. The order directly impacts the cryptosystem's security strength. A higher order typically corresponds to a stronger cryptosystem, making it more resistant to cryptographic attacks.
|
|
105
|
+
|
|
106
|
+
## Edwards Curves
|
|
107
|
+
|
|
108
|
+
| form | curve | field | n (bits) |
|
|
109
|
+
| --- | --- | --- | --- |
|
|
110
|
+
| edwards | e521 | prime | 519 |
|
|
111
|
+
| edwards | id-tc26-gost-3410-2012-512-paramsetc | prime | 510 |
|
|
112
|
+
| edwards | numsp512t1 | prime | 510 |
|
|
113
|
+
| edwards | ed448 | prime | 446 |
|
|
114
|
+
| edwards | curve41417 | prime | 411 |
|
|
115
|
+
| edwards | numsp384t1 | prime | 382 |
|
|
116
|
+
| edwards | id-tc26-gost-3410-2012-256-paramseta | prime | 255 |
|
|
117
|
+
| edwards | ed25519 | prime | 254 |
|
|
118
|
+
| edwards | mdc201601 | prime | 254 |
|
|
119
|
+
| edwards | numsp256t1 | prime | 254 |
|
|
120
|
+
| edwards | jubjub | prime | 252 |
|
|
121
|
+
|
|
122
|
+
## Weierstass Form
|
|
123
|
+
|
|
124
|
+
| form | curve | field | n (bits) |
|
|
125
|
+
| --- | --- | --- | --- |
|
|
126
|
+
| weierstrass | bn638 | prime | 638 |
|
|
127
|
+
| weierstrass | bn606 | prime | 606 |
|
|
128
|
+
| weierstrass | bn574 | prime | 574 |
|
|
129
|
+
| weierstrass | bn542 | prime | 542 |
|
|
130
|
+
| weierstrass | p521 | prime | 521 |
|
|
131
|
+
| weierstrass | brainpoolp512r1 | prime | 512 |
|
|
132
|
+
| weierstrass | brainpoolp512t1 | prime | 512 |
|
|
133
|
+
| weierstrass | fp512bn | prime | 512 |
|
|
134
|
+
| weierstrass | numsp512d1 | prime | 512 |
|
|
135
|
+
| weierstrass | gost512 | prime | 511 |
|
|
136
|
+
| weierstrass | bn510 | prime | 510 |
|
|
137
|
+
| weierstrass | bn478 | prime | 478 |
|
|
138
|
+
| weierstrass | bn446 | prime | 446 |
|
|
139
|
+
| weierstrass | bls12-638 | prime | 427 |
|
|
140
|
+
| weierstrass | bn414 | prime | 414 |
|
|
141
|
+
| weierstrass | brainpoolp384r1 | prime | 384 |
|
|
142
|
+
| weierstrass | brainpoolp384t1 | prime | 384 |
|
|
143
|
+
| weierstrass | fp384bn | prime | 384 |
|
|
144
|
+
| weierstrass | numsp384d1 | prime | 384 |
|
|
145
|
+
| weierstrass | p384 | prime | 384 |
|
|
146
|
+
| weierstrass | bls24-477 | prime | 383 |
|
|
147
|
+
| weierstrass | bn382 | prime | 382 |
|
|
148
|
+
| weierstrass | curve67254 | prime | 380 |
|
|
149
|
+
| weierstrass | bn350 | prime | 350 |
|
|
150
|
+
| weierstrass | brainpoolp320r1 | prime | 320 |
|
|
151
|
+
| weierstrass | brainpoolp320t1 | prime | 320 |
|
|
152
|
+
| weierstrass | bn318 | prime | 318 |
|
|
153
|
+
| weierstrass | bls12-455 | prime | 305 |
|
|
154
|
+
| weierstrass | bls12-446 | prime | 299 |
|
|
155
|
+
| weierstrass | bn286 | prime | 286 |
|
|
156
|
+
| weierstrass | brainpoolp256r1 | prime | 256 |
|
|
157
|
+
| weierstrass | brainpoolp256t1 | prime | 256 |
|
|
158
|
+
| weierstrass | fp256bn | prime | 256 |
|
|
159
|
+
| weierstrass | gost256 | prime | 256 |
|
|
160
|
+
| weierstrass | numsp256d1 | prime | 256 |
|
|
161
|
+
| weierstrass | p256 | prime | 256 |
|
|
162
|
+
| weierstrass | secp256k1 | prime | 256 |
|
|
163
|
+
| weierstrass | tom256 | prime | 256 |
|
|
164
|
+
| weierstrass | bls12-381 | prime | 255 |
|
|
165
|
+
| weierstrass | pallas | prime | 255 |
|
|
166
|
+
| weierstrass | tweedledee | prime | 255 |
|
|
167
|
+
| weierstrass | tweedledum | prime | 255 |
|
|
168
|
+
| weierstrass | vesta | prime | 255 |
|
|
169
|
+
| weierstrass | bn254 | prime | 254 |
|
|
170
|
+
| weierstrass | fp254bna | prime | 254 |
|
|
171
|
+
| weierstrass | fp254bnb | prime | 254 |
|
|
172
|
+
| weierstrass | bls12-377 | prime | 253 |
|
|
173
|
+
| weierstrass | curve1174 | prime | 249 |
|
|
174
|
+
| weierstrass | mnt4 | prime | 240 |
|
|
175
|
+
| weierstrass | mnt5-1 | prime | 240 |
|
|
176
|
+
| weierstrass | mnt5-2 | prime | 240 |
|
|
177
|
+
| weierstrass | mnt5-3 | prime | 240 |
|
|
178
|
+
| weierstrass | prime239v1 | prime | 239 |
|
|
179
|
+
| weierstrass | prime239v2 | prime | 239 |
|
|
180
|
+
| weierstrass | prime239v3 | prime | 239 |
|
|
181
|
+
| weierstrass | secp224k1 | prime | 225 |
|
|
182
|
+
| weierstrass | brainpoolp224r1 | prime | 224 |
|
|
183
|
+
| weierstrass | brainpoolp224t1 | prime | 224 |
|
|
184
|
+
| weierstrass | curve4417 | prime | 224 |
|
|
185
|
+
| weierstrass | fp224bn | prime | 224 |
|
|
186
|
+
| weierstrass | p224 | prime | 224 |
|
|
187
|
+
| weierstrass | bn222 | prime | 222 |
|
|
188
|
+
| weierstrass | curve22103 | prime | 218 |
|
|
189
|
+
| weierstrass | brainpoolp192r1 | prime | 192 |
|
|
190
|
+
| weierstrass | brainpoolp192t1 | prime | 192 |
|
|
191
|
+
| weierstrass | p192 | prime | 192 |
|
|
192
|
+
| weierstrass | prime192v2 | prime | 192 |
|
|
193
|
+
| weierstrass | prime192v3 | prime | 192 |
|
|
194
|
+
| weierstrass | secp192k1 | prime | 192 |
|
|
195
|
+
| weierstrass | bn190 | prime | 190 |
|
|
196
|
+
| weierstrass | secp160k1 | prime | 161 |
|
|
197
|
+
| weierstrass | secp160r1 | prime | 161 |
|
|
198
|
+
| weierstrass | secp160r2 | prime | 161 |
|
|
199
|
+
| weierstrass | brainpoolp160r1 | prime | 160 |
|
|
200
|
+
| weierstrass | brainpoolp160t1 | prime | 160 |
|
|
201
|
+
| weierstrass | mnt3-1 | prime | 160 |
|
|
202
|
+
| weierstrass | mnt3-2 | prime | 160 |
|
|
203
|
+
| weierstrass | mnt3-3 | prime | 160 |
|
|
204
|
+
| weierstrass | mnt2-1 | prime | 159 |
|
|
205
|
+
| weierstrass | mnt2-2 | prime | 159 |
|
|
206
|
+
| weierstrass | bn158 | prime | 158 |
|
|
207
|
+
| weierstrass | mnt1 | prime | 156 |
|
|
208
|
+
| weierstrass | secp128r1 | prime | 128 |
|
|
209
|
+
| weierstrass | secp128r2 | prime | 126 |
|
|
210
|
+
| weierstrass | secp112r1 | prime | 112 |
|
|
211
|
+
| weierstrass | secp112r2 | prime | 110 |
|
|
212
|
+
|
|
213
|
+
## Koblitz Form
|
|
214
|
+
|
|
215
|
+
| form | curve | field | n (bits) |
|
|
216
|
+
| --- | --- | --- | --- |
|
|
217
|
+
| koblitz | b571 | binary | 570 |
|
|
218
|
+
| koblitz | k571 | binary | 570 |
|
|
219
|
+
| koblitz | c2tnb431r1 | binary | 418 |
|
|
220
|
+
| koblitz | b409 | binary | 409 |
|
|
221
|
+
| koblitz | k409 | binary | 407 |
|
|
222
|
+
| koblitz | c2pnb368w1 | binary | 353 |
|
|
223
|
+
| koblitz | c2tnb359v1 | binary | 353 |
|
|
224
|
+
| koblitz | c2pnb304w1 | binary | 289 |
|
|
225
|
+
| koblitz | b283 | binary | 282 |
|
|
226
|
+
| koblitz | k283 | binary | 281 |
|
|
227
|
+
| koblitz | c2pnb272w1 | binary | 257 |
|
|
228
|
+
| koblitz | ansit239k1 | binary | 238 |
|
|
229
|
+
| koblitz | c2tnb239v1 | binary | 238 |
|
|
230
|
+
| koblitz | c2tnb239v2 | binary | 237 |
|
|
231
|
+
| koblitz | c2tnb239v3 | binary | 236 |
|
|
232
|
+
| koblitz | b233 | binary | 233 |
|
|
233
|
+
| koblitz | k233 | binary | 232 |
|
|
234
|
+
| koblitz | ansit193r1 | binary | 193 |
|
|
235
|
+
| koblitz | ansit193r2 | binary | 193 |
|
|
236
|
+
| koblitz | c2pnb208w1 | binary | 193 |
|
|
237
|
+
| koblitz | c2tnb191v1 | binary | 191 |
|
|
238
|
+
| koblitz | c2tnb191v2 | binary | 190 |
|
|
239
|
+
| koblitz | c2tnb191v3 | binary | 189 |
|
|
240
|
+
| koblitz | b163 | binary | 163 |
|
|
241
|
+
| koblitz | c2pnb163v1 | binary | 163 |
|
|
242
|
+
| koblitz | k163 | binary | 163 |
|
|
243
|
+
| koblitz | ansit163r1 | binary | 162 |
|
|
244
|
+
| koblitz | c2pnb163v2 | binary | 162 |
|
|
245
|
+
| koblitz | c2pnb163v3 | binary | 162 |
|
|
246
|
+
| koblitz | c2pnb176w1 | binary | 161 |
|
|
247
|
+
| koblitz | sect131r1 | binary | 131 |
|
|
248
|
+
| koblitz | sect131r2 | binary | 131 |
|
|
249
|
+
| koblitz | sect113r1 | binary | 113 |
|
|
250
|
+
| koblitz | sect113r2 | binary | 113 |
|
|
251
|
+
| koblitz | wap-wsg-idm-ecid-wtls1 | binary | 112 |
|
|
252
|
+
|
|
253
|
+
# Contributing
|
|
254
|
+
|
|
255
|
+
All PRs are more than welcome! If you are planning to contribute a large patch, please create an issue first to get any upfront questions or design decisions out of the way first.
|
|
256
|
+
|
|
257
|
+
You should be able run `make test` and `make lint` commands successfully before committing. Once a PR is created, GitHub test workflow will be run automatically and unit test results will be available in [GitHub actions](https://github.com/serengil/LightECC/actions/workflows/tests.yml) before approval.
|
|
258
|
+
|
|
259
|
+
# Support
|
|
260
|
+
|
|
261
|
+
There are many ways to support a project - starring⭐️ the GitHub repo is just one 🙏
|
|
262
|
+
|
|
263
|
+
You can also support this work on [Patreon](https://www.patreon.com/serengil?repo=lightecc), [GitHub Sponsors](https://github.com/sponsors/serengil) or [Buy Me a Coffee](https://buymeacoffee.com/serengil).
|
|
264
|
+
|
|
265
|
+
<a href="https://www.patreon.com/serengil?repo=lightecc">
|
|
266
|
+
<img src="https://raw.githubusercontent.com/serengil/LightPHE/master/icons/patreon.png" width="30%" height="30%">
|
|
267
|
+
</a>
|
|
268
|
+
|
|
269
|
+
<a href="https://buymeacoffee.com/serengil">
|
|
270
|
+
<img src="https://raw.githubusercontent.com/serengil/LightPHE/master/icons/bmc-button.png" width="25%" height="25%">
|
|
271
|
+
</a>
|
|
272
|
+
|
|
273
|
+
Also, your company's logo will be shown on README on GitHub if you become sponsor in gold, silver or bronze tiers.
|
|
274
|
+
|
|
275
|
+
# Citation
|
|
276
|
+
|
|
277
|
+
Please cite LightECC in your publications if it helps your research. Here is its BibTex entry:
|
|
278
|
+
|
|
279
|
+
```BibTeX
|
|
280
|
+
@misc{serengil2025lightecc
|
|
281
|
+
author = {Serengil, Sefik},
|
|
282
|
+
title = {LightECC: A Lightweight Elliptic Curve Cryptography Arithmetic Library for Python},
|
|
283
|
+
year = {2025},
|
|
284
|
+
publisher = {GitHub},
|
|
285
|
+
howpublished = {\url{https://github.com/serengil/LightECC}},
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
# License
|
|
290
|
+
|
|
291
|
+
LightECC is licensed under the MIT License - see [`LICENSE`](https://github.com/serengil/LightECC/blob/master/LICENSE) for more details.
|
|
292
|
+
|
|
293
|
+
LightECC's [logo](https://thenounproject.com/icon/starfish-757257/) is designed by Identidea Portfolio.
|
|
294
|
+
|
lightecc-0.0.1/README.md
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
# LightECC
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
[](https://pepy.tech/project/lightecc)
|
|
6
|
+
[](https://github.com/serengil/LightECC/stargazers)
|
|
7
|
+
[](https://github.com/serengil/LightECC/actions/workflows/tests.yml)
|
|
8
|
+
[](https://github.com/serengil/LightECC/blob/master/LICENSE)
|
|
9
|
+
|
|
10
|
+
[](https://sefiks.com)
|
|
11
|
+
[](https://www.youtube.com/@sefiks?sub_confirmation=1)
|
|
12
|
+
[](https://twitter.com/intent/user?screen_name=serengil)
|
|
13
|
+
|
|
14
|
+
[](https://www.patreon.com/serengil?repo=lightecc)
|
|
15
|
+
[](https://github.com/sponsors/serengil)
|
|
16
|
+
[](https://buymeacoffee.com/serengil)
|
|
17
|
+
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
<p align="center"><img src="https://raw.githubusercontent.com/serengil/LightECC/master/images/starfish.jpg" width="240" height="240"></p>
|
|
21
|
+
|
|
22
|
+
LightECC is a lightweight elliptic curve cryptography library for its arithmetic for python. It is a hybrid library wrapping many elliptic curve forms such as [Weierstrass](https://sefiks.com/2016/03/13/the-math-behind-elliptic-curve-cryptography/), [Koblitz](https://sefiks.com/2016/03/13/the-math-behind-elliptic-curves-over-binary-field/) and [Edwards](https://sefiks.com/2018/12/19/a-gentle-introduction-to-edwards-curves/).
|
|
23
|
+
|
|
24
|
+
# Elliptic Curve Arithmetic
|
|
25
|
+
|
|
26
|
+
Building an elliptic curve cryptosystem is very straightforward in LightECC. You basically need to initialize a LightECC object with a form name and a curve name. By default, it constructs elliptic curves in Weierstras form.After that, you can retrieve the base point of the curve and perform various elliptic curve arithmetic operations, including addition, subtraction, multiplication, and division.
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from lightecc import LightECC
|
|
30
|
+
|
|
31
|
+
forms = ["weierstrass", "koblitz", "edwards"]
|
|
32
|
+
|
|
33
|
+
ec = LightECC(
|
|
34
|
+
form_name = "edwards",
|
|
35
|
+
curve_name = "ed25519",
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
# get the base point
|
|
39
|
+
G = ec.G
|
|
40
|
+
|
|
41
|
+
# addition
|
|
42
|
+
_2G = G + G
|
|
43
|
+
_3G = _2G + G
|
|
44
|
+
_5G = _3G + _2G
|
|
45
|
+
_10G = _5G + _5G
|
|
46
|
+
|
|
47
|
+
# subtraction
|
|
48
|
+
_9G = _10G - G
|
|
49
|
+
|
|
50
|
+
# multiplication
|
|
51
|
+
_20G = 20 * G
|
|
52
|
+
_50G = 50 * G
|
|
53
|
+
|
|
54
|
+
# division
|
|
55
|
+
_25G = _50G / G
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Here, the [double-and-add](https://sefiks.com/2016/03/27/double-and-add-method/) method is used for multiplication, allowing it to be performed very quickly, regardless of the size of the multiplier.
|
|
59
|
+
|
|
60
|
+
On the other hand, division requires solving the [elliptic curve discrete logarithm problem](https://sefiks.com/2018/02/28/attacking-elliptic-curve-discrete-logarithm-problem/), which is computationally difficult.
|
|
61
|
+
|
|
62
|
+
# Point at Infinity or Neutral & Identity Element
|
|
63
|
+
|
|
64
|
+
The order of the elliptic curve is defined by the argument n in the constructed LightECC object. This represents the total number of points on the curve. It also serves as the [neutral or identity element](https://sefiks.com/2023/09/29/understanding-identity-element-in-elliptic-curves/) of the curve, meaning that adding this point to any other point does not change the result. Additionally, elliptic curves exhibit cyclic group properties beyond this point.
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
ec = LightECC()
|
|
68
|
+
|
|
69
|
+
# order of elliptic curve
|
|
70
|
+
n = ec.n
|
|
71
|
+
|
|
72
|
+
# neutral element
|
|
73
|
+
nG = n * G
|
|
74
|
+
|
|
75
|
+
# scalar multiplication
|
|
76
|
+
_17G = 17 * G
|
|
77
|
+
|
|
78
|
+
# proof of work for neutralism
|
|
79
|
+
assert _17G == _17G + nG
|
|
80
|
+
|
|
81
|
+
# proof of work for cyclic group
|
|
82
|
+
assert (n + 1) * G == G
|
|
83
|
+
assert (n + 2) * G == 2 * G
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
# Supported Curves
|
|
87
|
+
|
|
88
|
+
Below is a list of elliptic curves supported by LightECC. Each curve has a specific order (n), which defines the number of points in the finite field. The order directly impacts the cryptosystem's security strength. A higher order typically corresponds to a stronger cryptosystem, making it more resistant to cryptographic attacks.
|
|
89
|
+
|
|
90
|
+
## Edwards Curves
|
|
91
|
+
|
|
92
|
+
| form | curve | field | n (bits) |
|
|
93
|
+
| --- | --- | --- | --- |
|
|
94
|
+
| edwards | e521 | prime | 519 |
|
|
95
|
+
| edwards | id-tc26-gost-3410-2012-512-paramsetc | prime | 510 |
|
|
96
|
+
| edwards | numsp512t1 | prime | 510 |
|
|
97
|
+
| edwards | ed448 | prime | 446 |
|
|
98
|
+
| edwards | curve41417 | prime | 411 |
|
|
99
|
+
| edwards | numsp384t1 | prime | 382 |
|
|
100
|
+
| edwards | id-tc26-gost-3410-2012-256-paramseta | prime | 255 |
|
|
101
|
+
| edwards | ed25519 | prime | 254 |
|
|
102
|
+
| edwards | mdc201601 | prime | 254 |
|
|
103
|
+
| edwards | numsp256t1 | prime | 254 |
|
|
104
|
+
| edwards | jubjub | prime | 252 |
|
|
105
|
+
|
|
106
|
+
## Weierstass Form
|
|
107
|
+
|
|
108
|
+
| form | curve | field | n (bits) |
|
|
109
|
+
| --- | --- | --- | --- |
|
|
110
|
+
| weierstrass | bn638 | prime | 638 |
|
|
111
|
+
| weierstrass | bn606 | prime | 606 |
|
|
112
|
+
| weierstrass | bn574 | prime | 574 |
|
|
113
|
+
| weierstrass | bn542 | prime | 542 |
|
|
114
|
+
| weierstrass | p521 | prime | 521 |
|
|
115
|
+
| weierstrass | brainpoolp512r1 | prime | 512 |
|
|
116
|
+
| weierstrass | brainpoolp512t1 | prime | 512 |
|
|
117
|
+
| weierstrass | fp512bn | prime | 512 |
|
|
118
|
+
| weierstrass | numsp512d1 | prime | 512 |
|
|
119
|
+
| weierstrass | gost512 | prime | 511 |
|
|
120
|
+
| weierstrass | bn510 | prime | 510 |
|
|
121
|
+
| weierstrass | bn478 | prime | 478 |
|
|
122
|
+
| weierstrass | bn446 | prime | 446 |
|
|
123
|
+
| weierstrass | bls12-638 | prime | 427 |
|
|
124
|
+
| weierstrass | bn414 | prime | 414 |
|
|
125
|
+
| weierstrass | brainpoolp384r1 | prime | 384 |
|
|
126
|
+
| weierstrass | brainpoolp384t1 | prime | 384 |
|
|
127
|
+
| weierstrass | fp384bn | prime | 384 |
|
|
128
|
+
| weierstrass | numsp384d1 | prime | 384 |
|
|
129
|
+
| weierstrass | p384 | prime | 384 |
|
|
130
|
+
| weierstrass | bls24-477 | prime | 383 |
|
|
131
|
+
| weierstrass | bn382 | prime | 382 |
|
|
132
|
+
| weierstrass | curve67254 | prime | 380 |
|
|
133
|
+
| weierstrass | bn350 | prime | 350 |
|
|
134
|
+
| weierstrass | brainpoolp320r1 | prime | 320 |
|
|
135
|
+
| weierstrass | brainpoolp320t1 | prime | 320 |
|
|
136
|
+
| weierstrass | bn318 | prime | 318 |
|
|
137
|
+
| weierstrass | bls12-455 | prime | 305 |
|
|
138
|
+
| weierstrass | bls12-446 | prime | 299 |
|
|
139
|
+
| weierstrass | bn286 | prime | 286 |
|
|
140
|
+
| weierstrass | brainpoolp256r1 | prime | 256 |
|
|
141
|
+
| weierstrass | brainpoolp256t1 | prime | 256 |
|
|
142
|
+
| weierstrass | fp256bn | prime | 256 |
|
|
143
|
+
| weierstrass | gost256 | prime | 256 |
|
|
144
|
+
| weierstrass | numsp256d1 | prime | 256 |
|
|
145
|
+
| weierstrass | p256 | prime | 256 |
|
|
146
|
+
| weierstrass | secp256k1 | prime | 256 |
|
|
147
|
+
| weierstrass | tom256 | prime | 256 |
|
|
148
|
+
| weierstrass | bls12-381 | prime | 255 |
|
|
149
|
+
| weierstrass | pallas | prime | 255 |
|
|
150
|
+
| weierstrass | tweedledee | prime | 255 |
|
|
151
|
+
| weierstrass | tweedledum | prime | 255 |
|
|
152
|
+
| weierstrass | vesta | prime | 255 |
|
|
153
|
+
| weierstrass | bn254 | prime | 254 |
|
|
154
|
+
| weierstrass | fp254bna | prime | 254 |
|
|
155
|
+
| weierstrass | fp254bnb | prime | 254 |
|
|
156
|
+
| weierstrass | bls12-377 | prime | 253 |
|
|
157
|
+
| weierstrass | curve1174 | prime | 249 |
|
|
158
|
+
| weierstrass | mnt4 | prime | 240 |
|
|
159
|
+
| weierstrass | mnt5-1 | prime | 240 |
|
|
160
|
+
| weierstrass | mnt5-2 | prime | 240 |
|
|
161
|
+
| weierstrass | mnt5-3 | prime | 240 |
|
|
162
|
+
| weierstrass | prime239v1 | prime | 239 |
|
|
163
|
+
| weierstrass | prime239v2 | prime | 239 |
|
|
164
|
+
| weierstrass | prime239v3 | prime | 239 |
|
|
165
|
+
| weierstrass | secp224k1 | prime | 225 |
|
|
166
|
+
| weierstrass | brainpoolp224r1 | prime | 224 |
|
|
167
|
+
| weierstrass | brainpoolp224t1 | prime | 224 |
|
|
168
|
+
| weierstrass | curve4417 | prime | 224 |
|
|
169
|
+
| weierstrass | fp224bn | prime | 224 |
|
|
170
|
+
| weierstrass | p224 | prime | 224 |
|
|
171
|
+
| weierstrass | bn222 | prime | 222 |
|
|
172
|
+
| weierstrass | curve22103 | prime | 218 |
|
|
173
|
+
| weierstrass | brainpoolp192r1 | prime | 192 |
|
|
174
|
+
| weierstrass | brainpoolp192t1 | prime | 192 |
|
|
175
|
+
| weierstrass | p192 | prime | 192 |
|
|
176
|
+
| weierstrass | prime192v2 | prime | 192 |
|
|
177
|
+
| weierstrass | prime192v3 | prime | 192 |
|
|
178
|
+
| weierstrass | secp192k1 | prime | 192 |
|
|
179
|
+
| weierstrass | bn190 | prime | 190 |
|
|
180
|
+
| weierstrass | secp160k1 | prime | 161 |
|
|
181
|
+
| weierstrass | secp160r1 | prime | 161 |
|
|
182
|
+
| weierstrass | secp160r2 | prime | 161 |
|
|
183
|
+
| weierstrass | brainpoolp160r1 | prime | 160 |
|
|
184
|
+
| weierstrass | brainpoolp160t1 | prime | 160 |
|
|
185
|
+
| weierstrass | mnt3-1 | prime | 160 |
|
|
186
|
+
| weierstrass | mnt3-2 | prime | 160 |
|
|
187
|
+
| weierstrass | mnt3-3 | prime | 160 |
|
|
188
|
+
| weierstrass | mnt2-1 | prime | 159 |
|
|
189
|
+
| weierstrass | mnt2-2 | prime | 159 |
|
|
190
|
+
| weierstrass | bn158 | prime | 158 |
|
|
191
|
+
| weierstrass | mnt1 | prime | 156 |
|
|
192
|
+
| weierstrass | secp128r1 | prime | 128 |
|
|
193
|
+
| weierstrass | secp128r2 | prime | 126 |
|
|
194
|
+
| weierstrass | secp112r1 | prime | 112 |
|
|
195
|
+
| weierstrass | secp112r2 | prime | 110 |
|
|
196
|
+
|
|
197
|
+
## Koblitz Form
|
|
198
|
+
|
|
199
|
+
| form | curve | field | n (bits) |
|
|
200
|
+
| --- | --- | --- | --- |
|
|
201
|
+
| koblitz | b571 | binary | 570 |
|
|
202
|
+
| koblitz | k571 | binary | 570 |
|
|
203
|
+
| koblitz | c2tnb431r1 | binary | 418 |
|
|
204
|
+
| koblitz | b409 | binary | 409 |
|
|
205
|
+
| koblitz | k409 | binary | 407 |
|
|
206
|
+
| koblitz | c2pnb368w1 | binary | 353 |
|
|
207
|
+
| koblitz | c2tnb359v1 | binary | 353 |
|
|
208
|
+
| koblitz | c2pnb304w1 | binary | 289 |
|
|
209
|
+
| koblitz | b283 | binary | 282 |
|
|
210
|
+
| koblitz | k283 | binary | 281 |
|
|
211
|
+
| koblitz | c2pnb272w1 | binary | 257 |
|
|
212
|
+
| koblitz | ansit239k1 | binary | 238 |
|
|
213
|
+
| koblitz | c2tnb239v1 | binary | 238 |
|
|
214
|
+
| koblitz | c2tnb239v2 | binary | 237 |
|
|
215
|
+
| koblitz | c2tnb239v3 | binary | 236 |
|
|
216
|
+
| koblitz | b233 | binary | 233 |
|
|
217
|
+
| koblitz | k233 | binary | 232 |
|
|
218
|
+
| koblitz | ansit193r1 | binary | 193 |
|
|
219
|
+
| koblitz | ansit193r2 | binary | 193 |
|
|
220
|
+
| koblitz | c2pnb208w1 | binary | 193 |
|
|
221
|
+
| koblitz | c2tnb191v1 | binary | 191 |
|
|
222
|
+
| koblitz | c2tnb191v2 | binary | 190 |
|
|
223
|
+
| koblitz | c2tnb191v3 | binary | 189 |
|
|
224
|
+
| koblitz | b163 | binary | 163 |
|
|
225
|
+
| koblitz | c2pnb163v1 | binary | 163 |
|
|
226
|
+
| koblitz | k163 | binary | 163 |
|
|
227
|
+
| koblitz | ansit163r1 | binary | 162 |
|
|
228
|
+
| koblitz | c2pnb163v2 | binary | 162 |
|
|
229
|
+
| koblitz | c2pnb163v3 | binary | 162 |
|
|
230
|
+
| koblitz | c2pnb176w1 | binary | 161 |
|
|
231
|
+
| koblitz | sect131r1 | binary | 131 |
|
|
232
|
+
| koblitz | sect131r2 | binary | 131 |
|
|
233
|
+
| koblitz | sect113r1 | binary | 113 |
|
|
234
|
+
| koblitz | sect113r2 | binary | 113 |
|
|
235
|
+
| koblitz | wap-wsg-idm-ecid-wtls1 | binary | 112 |
|
|
236
|
+
|
|
237
|
+
# Contributing
|
|
238
|
+
|
|
239
|
+
All PRs are more than welcome! If you are planning to contribute a large patch, please create an issue first to get any upfront questions or design decisions out of the way first.
|
|
240
|
+
|
|
241
|
+
You should be able run `make test` and `make lint` commands successfully before committing. Once a PR is created, GitHub test workflow will be run automatically and unit test results will be available in [GitHub actions](https://github.com/serengil/LightECC/actions/workflows/tests.yml) before approval.
|
|
242
|
+
|
|
243
|
+
# Support
|
|
244
|
+
|
|
245
|
+
There are many ways to support a project - starring⭐️ the GitHub repo is just one 🙏
|
|
246
|
+
|
|
247
|
+
You can also support this work on [Patreon](https://www.patreon.com/serengil?repo=lightecc), [GitHub Sponsors](https://github.com/sponsors/serengil) or [Buy Me a Coffee](https://buymeacoffee.com/serengil).
|
|
248
|
+
|
|
249
|
+
<a href="https://www.patreon.com/serengil?repo=lightecc">
|
|
250
|
+
<img src="https://raw.githubusercontent.com/serengil/LightPHE/master/icons/patreon.png" width="30%" height="30%">
|
|
251
|
+
</a>
|
|
252
|
+
|
|
253
|
+
<a href="https://buymeacoffee.com/serengil">
|
|
254
|
+
<img src="https://raw.githubusercontent.com/serengil/LightPHE/master/icons/bmc-button.png" width="25%" height="25%">
|
|
255
|
+
</a>
|
|
256
|
+
|
|
257
|
+
Also, your company's logo will be shown on README on GitHub if you become sponsor in gold, silver or bronze tiers.
|
|
258
|
+
|
|
259
|
+
# Citation
|
|
260
|
+
|
|
261
|
+
Please cite LightECC in your publications if it helps your research. Here is its BibTex entry:
|
|
262
|
+
|
|
263
|
+
```BibTeX
|
|
264
|
+
@misc{serengil2025lightecc
|
|
265
|
+
author = {Serengil, Sefik},
|
|
266
|
+
title = {LightECC: A Lightweight Elliptic Curve Cryptography Arithmetic Library for Python},
|
|
267
|
+
year = {2025},
|
|
268
|
+
publisher = {GitHub},
|
|
269
|
+
howpublished = {\url{https://github.com/serengil/LightECC}},
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
# License
|
|
274
|
+
|
|
275
|
+
LightECC is licensed under the MIT License - see [`LICENSE`](https://github.com/serengil/LightECC/blob/master/LICENSE) for more details.
|
|
276
|
+
|
|
277
|
+
LightECC's [logo](https://thenounproject.com/icon/starfish-757257/) is designed by Identidea Portfolio.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# built-in dependencies
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
# project dependencies
|
|
5
|
+
from lightecc.forms.weierstrass import Weierstrass
|
|
6
|
+
from lightecc.forms.edwards import TwistedEdwards
|
|
7
|
+
from lightecc.forms.koblitz import Koblitz
|
|
8
|
+
from lightecc.interfaces.elliptic_curve import EllipticCurvePoint
|
|
9
|
+
from lightecc.commons.logger import Logger
|
|
10
|
+
|
|
11
|
+
logger = Logger(module="lightecc/__init__.py")
|
|
12
|
+
|
|
13
|
+
VERSION = "0.0.1"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# pylint: disable=too-few-public-methods
|
|
17
|
+
class LightECC:
|
|
18
|
+
__version__ = VERSION
|
|
19
|
+
|
|
20
|
+
def __init__(
|
|
21
|
+
self, form_name: Optional[str] = None, curve_name: Optional[str] = None
|
|
22
|
+
):
|
|
23
|
+
"""
|
|
24
|
+
Construct an Elliptic Curve over a finite field (prime or binary)
|
|
25
|
+
Args:
|
|
26
|
+
form_name (str): specifies the form of the elliptic curve.
|
|
27
|
+
Options: 'weierstrass' (default), 'edwards', 'koblitz'.
|
|
28
|
+
curve_name (str): specifies the elliptic curve to use.
|
|
29
|
+
Options:
|
|
30
|
+
- e.g. ed25519, ed448 for edwards form
|
|
31
|
+
- e.g. secp256k1 for weierstrass form
|
|
32
|
+
- e.g. k-409 for koblitz form
|
|
33
|
+
List of all available curves:
|
|
34
|
+
github.com/serengil/LightECC
|
|
35
|
+
"""
|
|
36
|
+
if form_name is None or form_name == "weierstrass":
|
|
37
|
+
self.curve = Weierstrass(curve=curve_name)
|
|
38
|
+
elif form_name in "edwards":
|
|
39
|
+
self.curve = TwistedEdwards(curve=curve_name)
|
|
40
|
+
elif form_name in "koblitz":
|
|
41
|
+
self.curve = Koblitz(curve=curve_name)
|
|
42
|
+
else:
|
|
43
|
+
raise ValueError(f"unimplemented curve form - {form_name}")
|
|
44
|
+
|
|
45
|
+
# base point
|
|
46
|
+
self.G = EllipticCurvePoint(self.curve.G[0], self.curve.G[1], self.curve)
|
|
47
|
+
|
|
48
|
+
# order of the curve
|
|
49
|
+
self.n = self.curve.n
|
|
50
|
+
|
|
51
|
+
# point at infinity or neutral / identity element
|
|
52
|
+
self.O = EllipticCurvePoint(self.curve.O[0], self.curve.O[1], self.curve)
|
|
53
|
+
|
|
54
|
+
# modulo
|
|
55
|
+
self.modulo = self.curve.modulo
|
|
File without changes
|