1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
%global _empty_manifest_terminate_build 0
Name: python-tinyec
Version: 0.4.0
Release: 1
Summary: A tiny library to perform arithmetic operations on elliptic curves in pure python
License: GPLv3
URL: https://github.com/alexmgr/tinyec
Source0: https://mirrors.aliyun.com/pypi/web/packages/76/2f/1bf6060620aae864597422ed50a0b46ad66a720d22e0f5d6c62e58aebff9/tinyec-0.4.0.tar.gz
BuildArch: noarch
%description
# tinyec
A tiny library to perform arithmetic operations on elliptic curves in pure python. No dependencies.
**This is not a library suitable for production.** It is useful for security professionals to understand the inner workings of EC, and be able to play with pre-defined curves.
## installation
`pip install tinyec`
## usage
There are 2 main classes:
* Curve(), which describes an elliptic curve in a finite field
* Point(), which describes a point belonging to an EC
**Warning** Calculation on points outside the curve are allowed. They will only raise a warning.
### working on existing curves
Example use on the NIST routine samples => https://www.nsa.gov/ia/_files/nist-routines.pdf:
```python
>>> import tinyec.ec as ec
>>> import tinyec.registry as reg
>>> c = reg.get_curve("secp192r1")
>>> s = ec.Point(c, 0xd458e7d127ae671b0c330266d246769353a012073e97acf8, 0x325930500d851f336bddc050cf7fb11b5673a1645086df3b)
>>> t = ec.Point(c, 0xf22c4395213e9ebe67ddecdd87fdbd01be16fb059b9753a4, 0x264424096af2b3597796db48f8dfb41fa9cecc97691a9c79)
>>> r = s + t
>>> r
(1787070900316344022479363585363935252075532448940096815760, 1583034776780933252095415958625802984888372377603917916747) on secp192r1 => y^2 = x^3 + 6277101735386680763835789423207666416083908700390324961276x + 2455155546008943817740293915197451784769108058161191238065
(mod 6277101735386680763835789423207666416083908700390324961279)
>>> hex(r.x)
'0x48e1e4096b9b8e5ca9d0f1f077b8abf58e843894de4d0290L'
>>> hex(r.y)
'0x408fa77c797cd7dbfb16aa48a3648d3d63c94117d7b6aa4bL'
>>> r = s - t
>>> r
(6193438478050209507979672067809269724375390027440522152494, 226636415264149817017346905052752138772359775362461041003) on secp192r1 => y^2 = x^3 + 6277101735386680763835789423207666416083908700390324961276x + 2455155546008943817740293915197451784769108058161191238065 (
mod 6277101735386680763835789423207666416083908700390324961279)
>>> hex(r.x)
'0xfc9683cc5abfb4fe0cc8cc3bc9f61eabc4688f11e9f64a2eL'
>>> hex(r.y)
'0x93e31d00fb78269732b1bd2a73c23cdd31745d0523d816bL'
>>> r = 2 * s
>>> r
(1195895923065450997501505402941681398272052708885411031394, 340030206158745947396451508065335698335058477174385838543) on secp192r1 => y^2 = x^3 + 6277101735386680763835789423207666416083908700390324961276x + 2455155546008943817740293915197451784769108058161191238065 (
mod 6277101735386680763835789423207666416083908700390324961279)
>>> hex(r.x)
'0x30c5bc6b8c7da25354b373dc14dd8a0eba42d25a3f6e6962L'
>>> hex(r.y)
'0xdde14bc4249a721c407aedbf011e2ddbbcb2968c9d889cfL'
>>> d = 0xa78a236d60baec0c5dd41b33a542463a8255391af64c74ee
>>> r = d * s
>>> hex(r.x)
'0x1faee4205a4f669d2d0a8f25e3bcec9a62a6952965bf6d31L'
>>> hex(r.y)
'0x5ff2cdfa508a2581892367087c696f179e7a4d7e8260fb06L'
>>> e = 0xc4be3d53ec3089e71e4de8ceab7cce889bc393cd85b972bc
>>> r = d * s + e * t
>>> r
(39786866609245082371772779541859439402855864496422607838, 547967566579883709478937502153554894699060378424501614148) on secp192r1 => y^2 = x^3 + 6277101735386680763835789423207666416083908700390324961276x + 2455155546008943817740293915197451784769108058161191238065 (mo
d 6277101735386680763835789423207666416083908700390324961279)
>>> hex(r.x)
'0x19f64eed8fa9b72b7dfea82c17c9bfa60ecb9e1778b5bdeL'
>>> hex(r.y)
'0x16590c5fcd8655fa4ced33fb800e2a7e3c61f35d83503644L'
```
### working on custom curves
If needed, you can also work on your own curves. Here we take a a prime field 97, with a generator point (1, 2), an order 5 and a cofactor of 1:
```python
>>> import tinyec.ec as ec
>>> field = ec.SubGroup(97, (1, 2), 5, 1)
>>> curve = ec.Curve(2, 3, field)
tinyec/ec.py:115: UserWarning: Point (1, 2) is not on curve "undefined" => y^2 = x^3 + 2x + 3 (mod 97)
warnings.warn("Point (%d, %d) is not on curve %s" % (self.x, self.y, self.curve))
>>> # Warning is generated because the generator point does not belong to the curve
>>> p1 = ec.Point(curve, -5, 3)
>>> p1.on_curve
False
>>> p2 = ec.Point(curve, 22, 5)
>>> p2.on_curve
True
>>> print(p1 + p2)
(18, 42) off "undefined" => y^2 = x^3 + 2x + 3 (mod 97)
```
%package -n python3-tinyec
Summary: A tiny library to perform arithmetic operations on elliptic curves in pure python
Provides: python-tinyec
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-tinyec
# tinyec
A tiny library to perform arithmetic operations on elliptic curves in pure python. No dependencies.
**This is not a library suitable for production.** It is useful for security professionals to understand the inner workings of EC, and be able to play with pre-defined curves.
## installation
`pip install tinyec`
## usage
There are 2 main classes:
* Curve(), which describes an elliptic curve in a finite field
* Point(), which describes a point belonging to an EC
**Warning** Calculation on points outside the curve are allowed. They will only raise a warning.
### working on existing curves
Example use on the NIST routine samples => https://www.nsa.gov/ia/_files/nist-routines.pdf:
```python
>>> import tinyec.ec as ec
>>> import tinyec.registry as reg
>>> c = reg.get_curve("secp192r1")
>>> s = ec.Point(c, 0xd458e7d127ae671b0c330266d246769353a012073e97acf8, 0x325930500d851f336bddc050cf7fb11b5673a1645086df3b)
>>> t = ec.Point(c, 0xf22c4395213e9ebe67ddecdd87fdbd01be16fb059b9753a4, 0x264424096af2b3597796db48f8dfb41fa9cecc97691a9c79)
>>> r = s + t
>>> r
(1787070900316344022479363585363935252075532448940096815760, 1583034776780933252095415958625802984888372377603917916747) on secp192r1 => y^2 = x^3 + 6277101735386680763835789423207666416083908700390324961276x + 2455155546008943817740293915197451784769108058161191238065
(mod 6277101735386680763835789423207666416083908700390324961279)
>>> hex(r.x)
'0x48e1e4096b9b8e5ca9d0f1f077b8abf58e843894de4d0290L'
>>> hex(r.y)
'0x408fa77c797cd7dbfb16aa48a3648d3d63c94117d7b6aa4bL'
>>> r = s - t
>>> r
(6193438478050209507979672067809269724375390027440522152494, 226636415264149817017346905052752138772359775362461041003) on secp192r1 => y^2 = x^3 + 6277101735386680763835789423207666416083908700390324961276x + 2455155546008943817740293915197451784769108058161191238065 (
mod 6277101735386680763835789423207666416083908700390324961279)
>>> hex(r.x)
'0xfc9683cc5abfb4fe0cc8cc3bc9f61eabc4688f11e9f64a2eL'
>>> hex(r.y)
'0x93e31d00fb78269732b1bd2a73c23cdd31745d0523d816bL'
>>> r = 2 * s
>>> r
(1195895923065450997501505402941681398272052708885411031394, 340030206158745947396451508065335698335058477174385838543) on secp192r1 => y^2 = x^3 + 6277101735386680763835789423207666416083908700390324961276x + 2455155546008943817740293915197451784769108058161191238065 (
mod 6277101735386680763835789423207666416083908700390324961279)
>>> hex(r.x)
'0x30c5bc6b8c7da25354b373dc14dd8a0eba42d25a3f6e6962L'
>>> hex(r.y)
'0xdde14bc4249a721c407aedbf011e2ddbbcb2968c9d889cfL'
>>> d = 0xa78a236d60baec0c5dd41b33a542463a8255391af64c74ee
>>> r = d * s
>>> hex(r.x)
'0x1faee4205a4f669d2d0a8f25e3bcec9a62a6952965bf6d31L'
>>> hex(r.y)
'0x5ff2cdfa508a2581892367087c696f179e7a4d7e8260fb06L'
>>> e = 0xc4be3d53ec3089e71e4de8ceab7cce889bc393cd85b972bc
>>> r = d * s + e * t
>>> r
(39786866609245082371772779541859439402855864496422607838, 547967566579883709478937502153554894699060378424501614148) on secp192r1 => y^2 = x^3 + 6277101735386680763835789423207666416083908700390324961276x + 2455155546008943817740293915197451784769108058161191238065 (mo
d 6277101735386680763835789423207666416083908700390324961279)
>>> hex(r.x)
'0x19f64eed8fa9b72b7dfea82c17c9bfa60ecb9e1778b5bdeL'
>>> hex(r.y)
'0x16590c5fcd8655fa4ced33fb800e2a7e3c61f35d83503644L'
```
### working on custom curves
If needed, you can also work on your own curves. Here we take a a prime field 97, with a generator point (1, 2), an order 5 and a cofactor of 1:
```python
>>> import tinyec.ec as ec
>>> field = ec.SubGroup(97, (1, 2), 5, 1)
>>> curve = ec.Curve(2, 3, field)
tinyec/ec.py:115: UserWarning: Point (1, 2) is not on curve "undefined" => y^2 = x^3 + 2x + 3 (mod 97)
warnings.warn("Point (%d, %d) is not on curve %s" % (self.x, self.y, self.curve))
>>> # Warning is generated because the generator point does not belong to the curve
>>> p1 = ec.Point(curve, -5, 3)
>>> p1.on_curve
False
>>> p2 = ec.Point(curve, 22, 5)
>>> p2.on_curve
True
>>> print(p1 + p2)
(18, 42) off "undefined" => y^2 = x^3 + 2x + 3 (mod 97)
```
%package help
Summary: Development documents and examples for tinyec
Provides: python3-tinyec-doc
%description help
# tinyec
A tiny library to perform arithmetic operations on elliptic curves in pure python. No dependencies.
**This is not a library suitable for production.** It is useful for security professionals to understand the inner workings of EC, and be able to play with pre-defined curves.
## installation
`pip install tinyec`
## usage
There are 2 main classes:
* Curve(), which describes an elliptic curve in a finite field
* Point(), which describes a point belonging to an EC
**Warning** Calculation on points outside the curve are allowed. They will only raise a warning.
### working on existing curves
Example use on the NIST routine samples => https://www.nsa.gov/ia/_files/nist-routines.pdf:
```python
>>> import tinyec.ec as ec
>>> import tinyec.registry as reg
>>> c = reg.get_curve("secp192r1")
>>> s = ec.Point(c, 0xd458e7d127ae671b0c330266d246769353a012073e97acf8, 0x325930500d851f336bddc050cf7fb11b5673a1645086df3b)
>>> t = ec.Point(c, 0xf22c4395213e9ebe67ddecdd87fdbd01be16fb059b9753a4, 0x264424096af2b3597796db48f8dfb41fa9cecc97691a9c79)
>>> r = s + t
>>> r
(1787070900316344022479363585363935252075532448940096815760, 1583034776780933252095415958625802984888372377603917916747) on secp192r1 => y^2 = x^3 + 6277101735386680763835789423207666416083908700390324961276x + 2455155546008943817740293915197451784769108058161191238065
(mod 6277101735386680763835789423207666416083908700390324961279)
>>> hex(r.x)
'0x48e1e4096b9b8e5ca9d0f1f077b8abf58e843894de4d0290L'
>>> hex(r.y)
'0x408fa77c797cd7dbfb16aa48a3648d3d63c94117d7b6aa4bL'
>>> r = s - t
>>> r
(6193438478050209507979672067809269724375390027440522152494, 226636415264149817017346905052752138772359775362461041003) on secp192r1 => y^2 = x^3 + 6277101735386680763835789423207666416083908700390324961276x + 2455155546008943817740293915197451784769108058161191238065 (
mod 6277101735386680763835789423207666416083908700390324961279)
>>> hex(r.x)
'0xfc9683cc5abfb4fe0cc8cc3bc9f61eabc4688f11e9f64a2eL'
>>> hex(r.y)
'0x93e31d00fb78269732b1bd2a73c23cdd31745d0523d816bL'
>>> r = 2 * s
>>> r
(1195895923065450997501505402941681398272052708885411031394, 340030206158745947396451508065335698335058477174385838543) on secp192r1 => y^2 = x^3 + 6277101735386680763835789423207666416083908700390324961276x + 2455155546008943817740293915197451784769108058161191238065 (
mod 6277101735386680763835789423207666416083908700390324961279)
>>> hex(r.x)
'0x30c5bc6b8c7da25354b373dc14dd8a0eba42d25a3f6e6962L'
>>> hex(r.y)
'0xdde14bc4249a721c407aedbf011e2ddbbcb2968c9d889cfL'
>>> d = 0xa78a236d60baec0c5dd41b33a542463a8255391af64c74ee
>>> r = d * s
>>> hex(r.x)
'0x1faee4205a4f669d2d0a8f25e3bcec9a62a6952965bf6d31L'
>>> hex(r.y)
'0x5ff2cdfa508a2581892367087c696f179e7a4d7e8260fb06L'
>>> e = 0xc4be3d53ec3089e71e4de8ceab7cce889bc393cd85b972bc
>>> r = d * s + e * t
>>> r
(39786866609245082371772779541859439402855864496422607838, 547967566579883709478937502153554894699060378424501614148) on secp192r1 => y^2 = x^3 + 6277101735386680763835789423207666416083908700390324961276x + 2455155546008943817740293915197451784769108058161191238065 (mo
d 6277101735386680763835789423207666416083908700390324961279)
>>> hex(r.x)
'0x19f64eed8fa9b72b7dfea82c17c9bfa60ecb9e1778b5bdeL'
>>> hex(r.y)
'0x16590c5fcd8655fa4ced33fb800e2a7e3c61f35d83503644L'
```
### working on custom curves
If needed, you can also work on your own curves. Here we take a a prime field 97, with a generator point (1, 2), an order 5 and a cofactor of 1:
```python
>>> import tinyec.ec as ec
>>> field = ec.SubGroup(97, (1, 2), 5, 1)
>>> curve = ec.Curve(2, 3, field)
tinyec/ec.py:115: UserWarning: Point (1, 2) is not on curve "undefined" => y^2 = x^3 + 2x + 3 (mod 97)
warnings.warn("Point (%d, %d) is not on curve %s" % (self.x, self.y, self.curve))
>>> # Warning is generated because the generator point does not belong to the curve
>>> p1 = ec.Point(curve, -5, 3)
>>> p1.on_curve
False
>>> p2 = ec.Point(curve, 22, 5)
>>> p2.on_curve
True
>>> print(p1 + p2)
(18, 42) off "undefined" => y^2 = x^3 + 2x + 3 (mod 97)
```
%prep
%autosetup -n tinyec-0.4.0
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-tinyec -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Fri Jun 09 2023 Python_Bot <Python_Bot@openeuler.org> - 0.4.0-1
- Package Spec generated
|