Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/ecdsa/ecdsa.py: 62%
260 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
1#! /usr/bin/env python
3"""
4Low level implementation of Elliptic-Curve Digital Signatures.
6.. note ::
7 You're most likely looking for the :py:class:`~ecdsa.keys` module.
8 This is a low-level implementation of the ECDSA that operates on
9 integers, not byte strings.
11NOTE: This a low level implementation of ECDSA, for normal applications
12you should be looking at the keys.py module.
14Classes and methods for elliptic-curve signatures:
15private keys, public keys, signatures,
16and definitions of prime-modulus curves.
18Example:
20.. code-block:: python
22 # (In real-life applications, you would probably want to
23 # protect against defects in SystemRandom.)
24 from random import SystemRandom
25 randrange = SystemRandom().randrange
27 # Generate a public/private key pair using the NIST Curve P-192:
29 g = generator_192
30 n = g.order()
31 secret = randrange( 1, n )
32 pubkey = Public_key( g, g * secret )
33 privkey = Private_key( pubkey, secret )
35 # Signing a hash value:
37 hash = randrange( 1, n )
38 signature = privkey.sign( hash, randrange( 1, n ) )
40 # Verifying a signature for a hash value:
42 if pubkey.verifies( hash, signature ):
43 print_("Demo verification succeeded.")
44 else:
45 print_("*** Demo verification failed.")
47 # Verification fails if the hash value is modified:
49 if pubkey.verifies( hash-1, signature ):
50 print_("**** Demo verification failed to reject tampered hash.")
51 else:
52 print_("Demo verification correctly rejected tampered hash.")
54Revision history:
55 2005.12.31 - Initial version.
57 2008.11.25 - Substantial revisions introducing new classes.
59 2009.05.16 - Warn against using random.randrange in real applications.
61 2009.05.17 - Use random.SystemRandom by default.
63Originally written in 2005 by Peter Pearson and placed in the public domain,
64modified as part of the python-ecdsa package.
65"""
67from six import int2byte, b
68from . import ellipticcurve
69from . import numbertheory
70from .util import bit_length
71from ._compat import remove_whitespace
74class RSZeroError(RuntimeError):
75 pass
78class InvalidPointError(RuntimeError):
79 pass
82class Signature(object):
83 """
84 ECDSA signature.
86 :ivar int r: the ``r`` element of the ECDSA signature
87 :ivar int s: the ``s`` element of the ECDSA signature
88 """
90 def __init__(self, r, s):
91 self.r = r
92 self.s = s
94 def recover_public_keys(self, hash, generator):
95 """
96 Returns two public keys for which the signature is valid
98 :param int hash: signed hash
99 :param AbstractPoint generator: is the generator used in creation
100 of the signature
101 :rtype: tuple(Public_key, Public_key)
102 :return: a pair of public keys that can validate the signature
103 """
104 curve = generator.curve()
105 n = generator.order()
106 r = self.r
107 s = self.s
108 e = hash
109 x = r
111 # Compute the curve point with x as x-coordinate
112 alpha = (
113 pow(x, 3, curve.p()) + (curve.a() * x) + curve.b()
114 ) % curve.p()
115 beta = numbertheory.square_root_mod_prime(alpha, curve.p())
116 y = beta if beta % 2 == 0 else curve.p() - beta
118 # Compute the public key
119 R1 = ellipticcurve.PointJacobi(curve, x, y, 1, n)
120 Q1 = numbertheory.inverse_mod(r, n) * (s * R1 + (-e % n) * generator)
121 Pk1 = Public_key(generator, Q1)
123 # And the second solution
124 R2 = ellipticcurve.PointJacobi(curve, x, -y, 1, n)
125 Q2 = numbertheory.inverse_mod(r, n) * (s * R2 + (-e % n) * generator)
126 Pk2 = Public_key(generator, Q2)
128 return [Pk1, Pk2]
131class Public_key(object):
132 """Public key for ECDSA."""
134 def __init__(self, generator, point, verify=True):
135 """Low level ECDSA public key object.
137 :param generator: the Point that generates the group (the base point)
138 :param point: the Point that defines the public key
139 :param bool verify: if True check if point is valid point on curve
141 :raises InvalidPointError: if the point parameters are invalid or
142 point does not lay on the curve
143 """
145 self.curve = generator.curve()
146 self.generator = generator
147 self.point = point
148 n = generator.order()
149 p = self.curve.p()
150 if not (0 <= point.x() < p) or not (0 <= point.y() < p):
151 raise InvalidPointError(
152 "The public point has x or y out of range."
153 )
154 if verify and not self.curve.contains_point(point.x(), point.y()):
155 raise InvalidPointError("Point does not lay on the curve")
156 if not n:
157 raise InvalidPointError("Generator point must have order.")
158 # for curve parameters with base point with cofactor 1, all points
159 # that are on the curve are scalar multiples of the base point, so
160 # verifying that is not necessary. See Section 3.2.2.1 of SEC 1 v2
161 if (
162 verify
163 and self.curve.cofactor() != 1
164 and not n * point == ellipticcurve.INFINITY
165 ):
166 raise InvalidPointError("Generator point order is bad.")
168 def __eq__(self, other):
169 """Return True if the keys are identical, False otherwise.
171 Note: for comparison, only placement on the same curve and point
172 equality is considered, use of the same generator point is not
173 considered.
174 """
175 if isinstance(other, Public_key):
176 return self.curve == other.curve and self.point == other.point
177 return NotImplemented
179 def __ne__(self, other):
180 """Return False if the keys are identical, True otherwise."""
181 return not self == other
183 def verifies(self, hash, signature):
184 """Verify that signature is a valid signature of hash.
185 Return True if the signature is valid.
186 """
188 # From X9.62 J.3.1.
190 G = self.generator
191 n = G.order()
192 r = signature.r
193 s = signature.s
194 if r < 1 or r > n - 1:
195 return False
196 if s < 1 or s > n - 1:
197 return False
198 c = numbertheory.inverse_mod(s, n)
199 u1 = (hash * c) % n
200 u2 = (r * c) % n
201 if hasattr(G, "mul_add"):
202 xy = G.mul_add(u1, self.point, u2)
203 else:
204 xy = u1 * G + u2 * self.point
205 v = xy.x() % n
206 return v == r
209class Private_key(object):
210 """Private key for ECDSA."""
212 def __init__(self, public_key, secret_multiplier):
213 """public_key is of class Public_key;
214 secret_multiplier is a large integer.
215 """
217 self.public_key = public_key
218 self.secret_multiplier = secret_multiplier
220 def __eq__(self, other):
221 """Return True if the points are identical, False otherwise."""
222 if isinstance(other, Private_key):
223 return (
224 self.public_key == other.public_key
225 and self.secret_multiplier == other.secret_multiplier
226 )
227 return NotImplemented
229 def __ne__(self, other):
230 """Return False if the points are identical, True otherwise."""
231 return not self == other
233 def sign(self, hash, random_k):
234 """Return a signature for the provided hash, using the provided
235 random nonce. It is absolutely vital that random_k be an unpredictable
236 number in the range [1, self.public_key.point.order()-1]. If
237 an attacker can guess random_k, he can compute our private key from a
238 single signature. Also, if an attacker knows a few high-order
239 bits (or a few low-order bits) of random_k, he can compute our private
240 key from many signatures. The generation of nonces with adequate
241 cryptographic strength is very difficult and far beyond the scope
242 of this comment.
244 May raise RuntimeError, in which case retrying with a new
245 random value k is in order.
246 """
248 G = self.public_key.generator
249 n = G.order()
250 k = random_k % n
251 # Fix the bit-length of the random nonce,
252 # so that it doesn't leak via timing.
253 # This does not change that ks = k mod n
254 ks = k + n
255 kt = ks + n
256 if bit_length(ks) == bit_length(n):
257 p1 = kt * G
258 else:
259 p1 = ks * G
260 r = p1.x() % n
261 if r == 0:
262 raise RSZeroError("amazingly unlucky random number r")
263 s = (
264 numbertheory.inverse_mod(k, n)
265 * (hash + (self.secret_multiplier * r) % n)
266 ) % n
267 if s == 0:
268 raise RSZeroError("amazingly unlucky random number s")
269 return Signature(r, s)
272def int_to_string(x):
273 """Convert integer x into a string of bytes, as per X9.62."""
274 assert x >= 0
275 if x == 0:
276 return b("\0")
277 result = []
278 while x:
279 ordinal = x & 0xFF
280 result.append(int2byte(ordinal))
281 x >>= 8
283 result.reverse()
284 return b("").join(result)
287def string_to_int(s):
288 """Convert a string of bytes into an integer, as per X9.62."""
289 result = 0
290 for c in s:
291 if not isinstance(c, int):
292 c = ord(c)
293 result = 256 * result + c
294 return result
297def digest_integer(m):
298 """Convert an integer into a string of bytes, compute
299 its SHA-1 hash, and convert the result to an integer."""
300 #
301 # I don't expect this function to be used much. I wrote
302 # it in order to be able to duplicate the examples
303 # in ECDSAVS.
304 #
305 from hashlib import sha1
307 return string_to_int(sha1(int_to_string(m)).digest())
310def point_is_valid(generator, x, y):
311 """Is (x,y) a valid public key based on the specified generator?"""
313 # These are the tests specified in X9.62.
315 n = generator.order()
316 curve = generator.curve()
317 p = curve.p()
318 if not (0 <= x < p) or not (0 <= y < p):
319 return False
320 if not curve.contains_point(x, y):
321 return False
322 if (
323 curve.cofactor() != 1
324 and not n * ellipticcurve.PointJacobi(curve, x, y, 1)
325 == ellipticcurve.INFINITY
326 ):
327 return False
328 return True
331# secp112r1 curve
332_p = int(remove_whitespace("DB7C 2ABF62E3 5E668076 BEAD208B"), 16)
333# s = 00F50B02 8E4D696E 67687561 51752904 72783FB1
334_a = int(remove_whitespace("DB7C 2ABF62E3 5E668076 BEAD2088"), 16)
335_b = int(remove_whitespace("659E F8BA0439 16EEDE89 11702B22"), 16)
336_Gx = int(remove_whitespace("09487239 995A5EE7 6B55F9C2 F098"), 16)
337_Gy = int(remove_whitespace("A89C E5AF8724 C0A23E0E 0FF77500"), 16)
338_r = int(remove_whitespace("DB7C 2ABF62E3 5E7628DF AC6561C5"), 16)
339_h = 1
340curve_112r1 = ellipticcurve.CurveFp(_p, _a, _b, _h)
341generator_112r1 = ellipticcurve.PointJacobi(
342 curve_112r1, _Gx, _Gy, 1, _r, generator=True
343)
346# secp112r2 curve
347_p = int(remove_whitespace("DB7C 2ABF62E3 5E668076 BEAD208B"), 16)
348# s = 022757A1 114D69E 67687561 51755316 C05E0BD4
349_a = int(remove_whitespace("6127 C24C05F3 8A0AAAF6 5C0EF02C"), 16)
350_b = int(remove_whitespace("51DE F1815DB5 ED74FCC3 4C85D709"), 16)
351_Gx = int(remove_whitespace("4BA30AB5 E892B4E1 649DD092 8643"), 16)
352_Gy = int(remove_whitespace("ADCD 46F5882E 3747DEF3 6E956E97"), 16)
353_r = int(remove_whitespace("36DF 0AAFD8B8 D7597CA1 0520D04B"), 16)
354_h = 4
355curve_112r2 = ellipticcurve.CurveFp(_p, _a, _b, _h)
356generator_112r2 = ellipticcurve.PointJacobi(
357 curve_112r2, _Gx, _Gy, 1, _r, generator=True
358)
361# secp128r1 curve
362_p = int(remove_whitespace("FFFFFFFD FFFFFFFF FFFFFFFF FFFFFFFF"), 16)
363# S = 000E0D4D 69E6768 75615175 0CC03A44 73D03679
364# a and b are mod p, so a is equal to p-3, or simply -3
365# _a = -3
366_b = int(remove_whitespace("E87579C1 1079F43D D824993C 2CEE5ED3"), 16)
367_Gx = int(remove_whitespace("161FF752 8B899B2D 0C28607C A52C5B86"), 16)
368_Gy = int(remove_whitespace("CF5AC839 5BAFEB13 C02DA292 DDED7A83"), 16)
369_r = int(remove_whitespace("FFFFFFFE 00000000 75A30D1B 9038A115"), 16)
370_h = 1
371curve_128r1 = ellipticcurve.CurveFp(_p, -3, _b, _h)
372generator_128r1 = ellipticcurve.PointJacobi(
373 curve_128r1, _Gx, _Gy, 1, _r, generator=True
374)
377# secp160r1
378_p = int(remove_whitespace("FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF 7FFFFFFF"), 16)
379# S = 1053CDE4 2C14D696 E6768756 1517533B F3F83345
380# a and b are mod p, so a is equal to p-3, or simply -3
381# _a = -3
382_b = int(remove_whitespace("1C97BEFC 54BD7A8B 65ACF89F 81D4D4AD C565FA45"), 16)
383_Gx = int(
384 remove_whitespace("4A96B568 8EF57328 46646989 68C38BB9 13CBFC82"),
385 16,
386)
387_Gy = int(
388 remove_whitespace("23A62855 3168947D 59DCC912 04235137 7AC5FB32"),
389 16,
390)
391_r = int(
392 remove_whitespace("01 00000000 00000000 0001F4C8 F927AED3 CA752257"),
393 16,
394)
395_h = 1
396curve_160r1 = ellipticcurve.CurveFp(_p, -3, _b, _h)
397generator_160r1 = ellipticcurve.PointJacobi(
398 curve_160r1, _Gx, _Gy, 1, _r, generator=True
399)
402# NIST Curve P-192:
403_p = 6277101735386680763835789423207666416083908700390324961279
404_r = 6277101735386680763835789423176059013767194773182842284081
405# s = 0x3045ae6fc8422f64ed579528d38120eae12196d5L
406# c = 0x3099d2bbbfcb2538542dcd5fb078b6ef5f3d6fe2c745de65L
407_b = int(
408 remove_whitespace(
409 """
410 64210519 E59C80E7 0FA7E9AB 72243049 FEB8DEEC C146B9B1"""
411 ),
412 16,
413)
414_Gx = int(
415 remove_whitespace(
416 """
417 188DA80E B03090F6 7CBF20EB 43A18800 F4FF0AFD 82FF1012"""
418 ),
419 16,
420)
421_Gy = int(
422 remove_whitespace(
423 """
424 07192B95 FFC8DA78 631011ED 6B24CDD5 73F977A1 1E794811"""
425 ),
426 16,
427)
429curve_192 = ellipticcurve.CurveFp(_p, -3, _b, 1)
430generator_192 = ellipticcurve.PointJacobi(
431 curve_192, _Gx, _Gy, 1, _r, generator=True
432)
435# NIST Curve P-224:
436_p = int(
437 remove_whitespace(
438 """
439 2695994666715063979466701508701963067355791626002630814351
440 0066298881"""
441 )
442)
443_r = int(
444 remove_whitespace(
445 """
446 2695994666715063979466701508701962594045780771442439172168
447 2722368061"""
448 )
449)
450# s = 0xbd71344799d5c7fcdc45b59fa3b9ab8f6a948bc5L
451# c = 0x5b056c7e11dd68f40469ee7f3c7a7d74f7d121116506d031218291fbL
452_b = int(
453 remove_whitespace(
454 """
455 B4050A85 0C04B3AB F5413256 5044B0B7 D7BFD8BA 270B3943
456 2355FFB4"""
457 ),
458 16,
459)
460_Gx = int(
461 remove_whitespace(
462 """
463 B70E0CBD 6BB4BF7F 321390B9 4A03C1D3 56C21122 343280D6
464 115C1D21"""
465 ),
466 16,
467)
468_Gy = int(
469 remove_whitespace(
470 """
471 BD376388 B5F723FB 4C22DFE6 CD4375A0 5A074764 44D58199
472 85007E34"""
473 ),
474 16,
475)
477curve_224 = ellipticcurve.CurveFp(_p, -3, _b, 1)
478generator_224 = ellipticcurve.PointJacobi(
479 curve_224, _Gx, _Gy, 1, _r, generator=True
480)
482# NIST Curve P-256:
483_p = int(
484 remove_whitespace(
485 """
486 1157920892103562487626974469494075735300861434152903141955
487 33631308867097853951"""
488 )
489)
490_r = int(
491 remove_whitespace(
492 """
493 115792089210356248762697446949407573529996955224135760342
494 422259061068512044369"""
495 )
496)
497# s = 0xc49d360886e704936a6678e1139d26b7819f7e90L
498# c = 0x7efba1662985be9403cb055c75d4f7e0ce8d84a9c5114abcaf3177680104fa0dL
499_b = int(
500 remove_whitespace(
501 """
502 5AC635D8 AA3A93E7 B3EBBD55 769886BC 651D06B0 CC53B0F6
503 3BCE3C3E 27D2604B"""
504 ),
505 16,
506)
507_Gx = int(
508 remove_whitespace(
509 """
510 6B17D1F2 E12C4247 F8BCE6E5 63A440F2 77037D81 2DEB33A0
511 F4A13945 D898C296"""
512 ),
513 16,
514)
515_Gy = int(
516 remove_whitespace(
517 """
518 4FE342E2 FE1A7F9B 8EE7EB4A 7C0F9E16 2BCE3357 6B315ECE
519 CBB64068 37BF51F5"""
520 ),
521 16,
522)
524curve_256 = ellipticcurve.CurveFp(_p, -3, _b, 1)
525generator_256 = ellipticcurve.PointJacobi(
526 curve_256, _Gx, _Gy, 1, _r, generator=True
527)
529# NIST Curve P-384:
530_p = int(
531 remove_whitespace(
532 """
533 3940200619639447921227904010014361380507973927046544666794
534 8293404245721771496870329047266088258938001861606973112319"""
535 )
536)
537_r = int(
538 remove_whitespace(
539 """
540 3940200619639447921227904010014361380507973927046544666794
541 6905279627659399113263569398956308152294913554433653942643"""
542 )
543)
544# s = 0xa335926aa319a27a1d00896a6773a4827acdac73L
545# c = int(remove_whitespace(
546# """
547# 79d1e655 f868f02f ff48dcde e14151dd b80643c1 406d0ca1
548# 0dfe6fc5 2009540a 495e8042 ea5f744f 6e184667 cc722483"""
549# ), 16)
550_b = int(
551 remove_whitespace(
552 """
553 B3312FA7 E23EE7E4 988E056B E3F82D19 181D9C6E FE814112
554 0314088F 5013875A C656398D 8A2ED19D 2A85C8ED D3EC2AEF"""
555 ),
556 16,
557)
558_Gx = int(
559 remove_whitespace(
560 """
561 AA87CA22 BE8B0537 8EB1C71E F320AD74 6E1D3B62 8BA79B98
562 59F741E0 82542A38 5502F25D BF55296C 3A545E38 72760AB7"""
563 ),
564 16,
565)
566_Gy = int(
567 remove_whitespace(
568 """
569 3617DE4A 96262C6F 5D9E98BF 9292DC29 F8F41DBD 289A147C
570 E9DA3113 B5F0B8C0 0A60B1CE 1D7E819D 7A431D7C 90EA0E5F"""
571 ),
572 16,
573)
575curve_384 = ellipticcurve.CurveFp(_p, -3, _b, 1)
576generator_384 = ellipticcurve.PointJacobi(
577 curve_384, _Gx, _Gy, 1, _r, generator=True
578)
580# NIST Curve P-521:
581_p = int(
582 "686479766013060971498190079908139321726943530014330540939"
583 "446345918554318339765605212255964066145455497729631139148"
584 "0858037121987999716643812574028291115057151"
585)
586_r = int(
587 "686479766013060971498190079908139321726943530014330540939"
588 "446345918554318339765539424505774633321719753296399637136"
589 "3321113864768612440380340372808892707005449"
590)
591# s = 0xd09e8800291cb85396cc6717393284aaa0da64baL
592# c = int(remove_whitespace(
593# """
594# 0b4 8bfa5f42 0a349495 39d2bdfc 264eeeeb 077688e4
595# 4fbf0ad8 f6d0edb3 7bd6b533 28100051 8e19f1b9 ffbe0fe9
596# ed8a3c22 00b8f875 e523868c 70c1e5bf 55bad637"""
597# ), 16)
598_b = int(
599 remove_whitespace(
600 """
601 051 953EB961 8E1C9A1F 929A21A0 B68540EE A2DA725B
602 99B315F3 B8B48991 8EF109E1 56193951 EC7E937B 1652C0BD
603 3BB1BF07 3573DF88 3D2C34F1 EF451FD4 6B503F00"""
604 ),
605 16,
606)
607_Gx = int(
608 remove_whitespace(
609 """
610 C6 858E06B7 0404E9CD 9E3ECB66 2395B442 9C648139
611 053FB521 F828AF60 6B4D3DBA A14B5E77 EFE75928 FE1DC127
612 A2FFA8DE 3348B3C1 856A429B F97E7E31 C2E5BD66"""
613 ),
614 16,
615)
616_Gy = int(
617 remove_whitespace(
618 """
619 118 39296A78 9A3BC004 5C8A5FB4 2C7D1BD9 98F54449
620 579B4468 17AFBD17 273E662C 97EE7299 5EF42640 C550B901
621 3FAD0761 353C7086 A272C240 88BE9476 9FD16650"""
622 ),
623 16,
624)
626curve_521 = ellipticcurve.CurveFp(_p, -3, _b, 1)
627generator_521 = ellipticcurve.PointJacobi(
628 curve_521, _Gx, _Gy, 1, _r, generator=True
629)
631# Certicom secp256-k1
632_a = 0x0000000000000000000000000000000000000000000000000000000000000000
633_b = 0x0000000000000000000000000000000000000000000000000000000000000007
634_p = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
635_Gx = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798
636_Gy = 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8
637_r = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
639curve_secp256k1 = ellipticcurve.CurveFp(_p, _a, _b, 1)
640generator_secp256k1 = ellipticcurve.PointJacobi(
641 curve_secp256k1, _Gx, _Gy, 1, _r, generator=True
642)
644# Brainpool P-160-r1
645_a = 0x340E7BE2A280EB74E2BE61BADA745D97E8F7C300
646_b = 0x1E589A8595423412134FAA2DBDEC95C8D8675E58
647_p = 0xE95E4A5F737059DC60DFC7AD95B3D8139515620F
648_Gx = 0xBED5AF16EA3F6A4F62938C4631EB5AF7BDBCDBC3
649_Gy = 0x1667CB477A1A8EC338F94741669C976316DA6321
650_q = 0xE95E4A5F737059DC60DF5991D45029409E60FC09
652curve_brainpoolp160r1 = ellipticcurve.CurveFp(_p, _a, _b, 1)
653generator_brainpoolp160r1 = ellipticcurve.PointJacobi(
654 curve_brainpoolp160r1, _Gx, _Gy, 1, _q, generator=True
655)
657# Brainpool P-192-r1
658_a = 0x6A91174076B1E0E19C39C031FE8685C1CAE040E5C69A28EF
659_b = 0x469A28EF7C28CCA3DC721D044F4496BCCA7EF4146FBF25C9
660_p = 0xC302F41D932A36CDA7A3463093D18DB78FCE476DE1A86297
661_Gx = 0xC0A0647EAAB6A48753B033C56CB0F0900A2F5C4853375FD6
662_Gy = 0x14B690866ABD5BB88B5F4828C1490002E6773FA2FA299B8F
663_q = 0xC302F41D932A36CDA7A3462F9E9E916B5BE8F1029AC4ACC1
665curve_brainpoolp192r1 = ellipticcurve.CurveFp(_p, _a, _b, 1)
666generator_brainpoolp192r1 = ellipticcurve.PointJacobi(
667 curve_brainpoolp192r1, _Gx, _Gy, 1, _q, generator=True
668)
670# Brainpool P-224-r1
671_a = 0x68A5E62CA9CE6C1C299803A6C1530B514E182AD8B0042A59CAD29F43
672_b = 0x2580F63CCFE44138870713B1A92369E33E2135D266DBB372386C400B
673_p = 0xD7C134AA264366862A18302575D1D787B09F075797DA89F57EC8C0FF
674_Gx = 0x0D9029AD2C7E5CF4340823B2A87DC68C9E4CE3174C1E6EFDEE12C07D
675_Gy = 0x58AA56F772C0726F24C6B89E4ECDAC24354B9E99CAA3F6D3761402CD
676_q = 0xD7C134AA264366862A18302575D0FB98D116BC4B6DDEBCA3A5A7939F
678curve_brainpoolp224r1 = ellipticcurve.CurveFp(_p, _a, _b, 1)
679generator_brainpoolp224r1 = ellipticcurve.PointJacobi(
680 curve_brainpoolp224r1, _Gx, _Gy, 1, _q, generator=True
681)
683# Brainpool P-256-r1
684_a = 0x7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9
685_b = 0x26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6
686_p = 0xA9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377
687_Gx = 0x8BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262
688_Gy = 0x547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997
689_q = 0xA9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7
691curve_brainpoolp256r1 = ellipticcurve.CurveFp(_p, _a, _b, 1)
692generator_brainpoolp256r1 = ellipticcurve.PointJacobi(
693 curve_brainpoolp256r1, _Gx, _Gy, 1, _q, generator=True
694)
696# Brainpool P-320-r1
697_a = int(
698 remove_whitespace(
699 """
700 3EE30B568FBAB0F883CCEBD46D3F3BB8A2A73513F5EB79DA66190EB085FFA9
701 F492F375A97D860EB4"""
702 ),
703 16,
704)
705_b = int(
706 remove_whitespace(
707 """
708 520883949DFDBC42D3AD198640688A6FE13F41349554B49ACC31DCCD884539
709 816F5EB4AC8FB1F1A6"""
710 ),
711 16,
712)
713_p = int(
714 remove_whitespace(
715 """
716 D35E472036BC4FB7E13C785ED201E065F98FCFA6F6F40DEF4F92B9EC7893EC
717 28FCD412B1F1B32E27"""
718 ),
719 16,
720)
721_Gx = int(
722 remove_whitespace(
723 """
724 43BD7E9AFB53D8B85289BCC48EE5BFE6F20137D10A087EB6E7871E2A10A599
725 C710AF8D0D39E20611"""
726 ),
727 16,
728)
729_Gy = int(
730 remove_whitespace(
731 """
732 14FDD05545EC1CC8AB4093247F77275E0743FFED117182EAA9C77877AAAC6A
733 C7D35245D1692E8EE1"""
734 ),
735 16,
736)
737_q = int(
738 remove_whitespace(
739 """
740 D35E472036BC4FB7E13C785ED201E065F98FCFA5B68F12A32D482EC7EE8658
741 E98691555B44C59311"""
742 ),
743 16,
744)
746curve_brainpoolp320r1 = ellipticcurve.CurveFp(_p, _a, _b, 1)
747generator_brainpoolp320r1 = ellipticcurve.PointJacobi(
748 curve_brainpoolp320r1, _Gx, _Gy, 1, _q, generator=True
749)
751# Brainpool P-384-r1
752_a = int(
753 remove_whitespace(
754 """
755 7BC382C63D8C150C3C72080ACE05AFA0C2BEA28E4FB22787139165EFBA91F9
756 0F8AA5814A503AD4EB04A8C7DD22CE2826"""
757 ),
758 16,
759)
760_b = int(
761 remove_whitespace(
762 """
763 04A8C7DD22CE28268B39B55416F0447C2FB77DE107DCD2A62E880EA53EEB62
764 D57CB4390295DBC9943AB78696FA504C11"""
765 ),
766 16,
767)
768_p = int(
769 remove_whitespace(
770 """
771 8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB711
772 23ACD3A729901D1A71874700133107EC53"""
773 ),
774 16,
775)
776_Gx = int(
777 remove_whitespace(
778 """
779 1D1C64F068CF45FFA2A63A81B7C13F6B8847A3E77EF14FE3DB7FCAFE0CBD10
780 E8E826E03436D646AAEF87B2E247D4AF1E"""
781 ),
782 16,
783)
784_Gy = int(
785 remove_whitespace(
786 """
787 8ABE1D7520F9C2A45CB1EB8E95CFD55262B70B29FEEC5864E19C054FF991292
788 80E4646217791811142820341263C5315"""
789 ),
790 16,
791)
792_q = int(
793 remove_whitespace(
794 """
795 8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B31F166E6CAC0425
796 A7CF3AB6AF6B7FC3103B883202E9046565"""
797 ),
798 16,
799)
801curve_brainpoolp384r1 = ellipticcurve.CurveFp(_p, _a, _b, 1)
802generator_brainpoolp384r1 = ellipticcurve.PointJacobi(
803 curve_brainpoolp384r1, _Gx, _Gy, 1, _q, generator=True
804)
806# Brainpool P-512-r1
807_a = int(
808 remove_whitespace(
809 """
810 7830A3318B603B89E2327145AC234CC594CBDD8D3DF91610A83441CAEA9863
811 BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CA"""
812 ),
813 16,
814)
815_b = int(
816 remove_whitespace(
817 """
818 3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117
819 A72BF2C7B9E7C1AC4D77FC94CADC083E67984050B75EBAE5DD2809BD638016F723"""
820 ),
821 16,
822)
823_p = int(
824 remove_whitespace(
825 """
826 AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308
827 717D4D9B009BC66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3"""
828 ),
829 16,
830)
831_Gx = int(
832 remove_whitespace(
833 """
834 81AEE4BDD82ED9645A21322E9C4C6A9385ED9F70B5D916C1B43B62EEF4D009
835 8EFF3B1F78E2D0D48D50D1687B93B97D5F7C6D5047406A5E688B352209BCB9F822"""
836 ),
837 16,
838)
839_Gy = int(
840 remove_whitespace(
841 """
842 7DDE385D566332ECC0EABFA9CF7822FDF209F70024A57B1AA000C55B881F81
843 11B2DCDE494A5F485E5BCA4BD88A2763AED1CA2B2FA8F0540678CD1E0F3AD80892"""
844 ),
845 16,
846)
847_q = int(
848 remove_whitespace(
849 """
850 AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308
851 70553E5C414CA92619418661197FAC10471DB1D381085DDADDB58796829CA90069"""
852 ),
853 16,
854)
856curve_brainpoolp512r1 = ellipticcurve.CurveFp(_p, _a, _b, 1)
857generator_brainpoolp512r1 = ellipticcurve.PointJacobi(
858 curve_brainpoolp512r1, _Gx, _Gy, 1, _q, generator=True
859)