Skip to content

Commit 3219259

Browse files
committed
add secp128r1
1 parent de82152 commit 3219259

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

src/ecdsa/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
BRAINPOOLP512r1,
2222
SECP112r1,
2323
SECP112r2,
24+
SECP128r1,
2425
)
2526
from .ecdh import (
2627
ECDH,
@@ -76,5 +77,6 @@
7677
BRAINPOOLP512r1,
7778
SECP112r1,
7879
SECP112r2,
80+
SECP128r1,
7981
]
8082
del _hush_pyflakes

src/ecdsa/curves.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"Curve",
1313
"SECP112r1",
1414
"SECP112r2",
15+
"SECP128r1",
1516
"NIST192p",
1617
"NIST224p",
1718
"NIST256p",
@@ -70,6 +71,15 @@ def __repr__(self):
7071
)
7172

7273

74+
SECP128r1 = Curve(
75+
"SECP128r1",
76+
ecdsa.curve_128r1,
77+
ecdsa.generator_128r1,
78+
(1, 3, 132, 0, 28),
79+
"secp128r1",
80+
)
81+
82+
7383
# the NIST curves
7484
NIST192p = Curve(
7585
"NIST192p",
@@ -205,6 +215,7 @@ def __repr__(self):
205215
BRAINPOOLP512r1,
206216
SECP112r1,
207217
SECP112r2,
218+
SECP128r1,
208219
]
209220

210221

src/ecdsa/ecdsa.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,21 @@ def point_is_valid(generator, x, y):
324324
)
325325

326326

327+
# secp128r1 curve
328+
_p = int(remove_whitespace("FFFFFFFD FFFFFFFF FFFFFFFF FFFFFFFF"), 16)
329+
# S = 000E0D4D 69E6768 75615175 0CC03A44 73D03679
330+
# _a = -3
331+
_b = int(remove_whitespace("E87579C1 1079F43D D824993C 2CEE5ED3"), 16)
332+
_Gx = int(remove_whitespace("161FF752 8B899B2D 0C28607C A52C5B86"), 16)
333+
_Gy = int(remove_whitespace("CF5AC839 5BAFEB13 C02DA292 DDED7A83"), 16)
334+
_r = int(remove_whitespace("FFFFFFFE 00000000 75A30D1B 9038A115"), 16)
335+
_h = 1
336+
curve_128r1 = ellipticcurve.CurveFp(_p, -3, _b, _h)
337+
generator_128r1 = ellipticcurve.PointJacobi(
338+
curve_128r1, _Gx, _Gy, 1, _r, generator=True
339+
)
340+
341+
327342
# NIST Curve P-192:
328343
_p = 6277101735386680763835789423207666416083908700390324961279
329344
_r = 6277101735386680763835789423176059013767194773182842284081

src/ecdsa/test_pyecdsa.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from .curves import (
2929
SECP112r1,
3030
SECP112r2,
31+
SECP128r1,
3132
NIST192p,
3233
NIST224p,
3334
NIST256p,
@@ -882,6 +883,14 @@ def test_from_openssl_secp112r1(self):
882883
def test_from_openssl_secp112r2(self):
883884
return self.do_test_from_openssl(SECP112r2)
884885

886+
@pytest.mark.skipif(
887+
"secp128r1" not in OPENSSL_SUPPORTED_CURVES,
888+
reason="system openssl does not support secp128r1",
889+
)
890+
def test_from_openssl_secp128r1(self):
891+
return self.do_test_from_openssl(SECP128r1)
892+
893+
@pytest.mark.slow
885894
@pytest.mark.skipif(
886895
"prime192v1" not in OPENSSL_SUPPORTED_CURVES,
887896
reason="system openssl does not support prime192v1",
@@ -1060,6 +1069,14 @@ def test_to_openssl_secp112r1(self):
10601069
def test_to_openssl_secp112r2(self):
10611070
self.do_test_to_openssl(SECP112r2)
10621071

1072+
@pytest.mark.skipif(
1073+
"secp128r1" not in OPENSSL_SUPPORTED_CURVES,
1074+
reason="system openssl does not support secp128r1",
1075+
)
1076+
def test_to_openssl_secp128r1(self):
1077+
self.do_test_to_openssl(SECP128r1)
1078+
1079+
@pytest.mark.slow
10631080
@pytest.mark.skipif(
10641081
"prime192v1" not in OPENSSL_SUPPORTED_CURVES,
10651082
reason="system openssl does not support prime192v1",

0 commit comments

Comments
 (0)