• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1## This file is part of Scapy
2## Copyright (C) 2007, 2008, 2009 Arnaud Ebalard
3##               2015, 2016, 2017 Maxence Tury
4## This program is published under a GPLv2 license
5
6"""
7This is a register for DH groups from RFC 3526 and RFC 4306.
8At this time the groups from RFC 7919 have not been registered by openssl,
9thus they cannot be imported from the cryptography library.
10
11We also provide TLS identifiers for these DH groups and also the ECDH groups.
12(Note that the equivalent of _ffdh_groups for ECDH is ec._CURVE_TYPES.)
13"""
14
15from __future__ import absolute_import
16
17from scapy.config import conf
18from scapy.utils import long_converter
19if conf.crypto_valid:
20    from cryptography.hazmat.backends import default_backend
21    from cryptography.hazmat.primitives.asymmetric import dh
22import scapy.modules.six as six
23
24from scapy.config import conf
25from scapy.utils import long_converter
26
27# We have to start by a dirty hack in order to allow long generators,
28# which some versions of openssl love to use...
29
30if conf.crypto_valid:
31    from cryptography.hazmat.backends import default_backend
32    from cryptography.hazmat.primitives.asymmetric.dh import DHParameterNumbers
33
34    try:
35        # We test with dummy values whether the size limitation has been removed.
36        pn_test = DHParameterNumbers(2, 7)
37    except ValueError:
38        # We get rid of the limitation through the cryptography v1.9 __init__.
39        import six
40        def DHParameterNumbers__init__hack(self, p, g, q=None):
41            if (
42                not isinstance(p, six.integer_types) or
43                not isinstance(g, six.integer_types)
44            ):
45                raise TypeError("p and g must be integers")
46            if q is not None and not isinstance(q, six.integer_types):
47                raise TypeError("q must be integer or None")
48
49            self._p = p
50            self._g = g
51            self._q = q
52
53        DHParameterNumbers.__init__ = DHParameterNumbers__init__hack
54
55    # End of hack.
56
57
58_ffdh_groups = {}
59
60class _FFDHParamsMetaclass(type):
61    def __new__(cls, ffdh_name, bases, dct):
62        the_class = super(_FFDHParamsMetaclass, cls).__new__(cls, ffdh_name,
63                                                             bases, dct)
64        if conf.crypto_valid and ffdh_name != "_FFDHParams":
65            pn = DHParameterNumbers(the_class.m, the_class.g)
66            params = pn.parameters(default_backend())
67            _ffdh_groups[ffdh_name] = [params, the_class.mLen]
68        return the_class
69
70
71class _FFDHParams(six.with_metaclass(_FFDHParamsMetaclass)):
72    pass
73
74
75class modp768(_FFDHParams):
76    g = 0x02
77    m = long_converter("""
78    FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1 29024E08
79    8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD EF9519B3 CD3A431B
80    302B0A6D F25F1437 4FE1356D 6D51C245 E485B576 625E7EC6 F44C42E9
81    A63A3620 FFFFFFFF FFFFFFFF""")
82    mLen = 768
83
84class modp1024(_FFDHParams): # From RFC 4306
85    g = 0x02
86    m = long_converter("""
87    FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1 29024E08
88    8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD EF9519B3 CD3A431B
89    302B0A6D F25F1437 4FE1356D 6D51C245 E485B576 625E7EC6 F44C42E9
90    A637ED6B 0BFF5CB6 F406B7ED EE386BFB 5A899FA5 AE9F2411 7C4B1FE6
91    49286651 ECE65381 FFFFFFFF FFFFFFFF""")
92    mLen  = 1024
93
94class modp1536(_FFDHParams): # From RFC 3526
95    g = 0x02
96    m = long_converter("""
97    FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1
98    29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD
99    EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245
100    E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED
101    EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D
102    C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F
103    83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D
104    670C354E 4ABC9804 F1746C08 CA237327 FFFFFFFF FFFFFFFF""")
105    mLen  = 1536
106
107class modp2048(_FFDHParams): # From RFC 3526
108    g = 0x02
109    m = long_converter("""
110    FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1
111    29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD
112    EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245
113    E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED
114    EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D
115    C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F
116    83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D
117    670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B
118    E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9
119    DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510
120    15728E5A 8AACAA68 FFFFFFFF FFFFFFFF""")
121    mLen  = 2048
122
123class modp3072(_FFDHParams): # From RFC 3526
124    g = 0x02
125    m = long_converter("""
126    FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1
127    29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD
128    EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245
129    E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED
130    EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D
131    C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F
132    83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D
133    670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B
134    E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9
135    DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510
136    15728E5A 8AAAC42D AD33170D 04507A33 A85521AB DF1CBA64
137    ECFB8504 58DBEF0A 8AEA7157 5D060C7D B3970F85 A6E1E4C7
138    ABF5AE8C DB0933D7 1E8C94E0 4A25619D CEE3D226 1AD2EE6B
139    F12FFA06 D98A0864 D8760273 3EC86A64 521F2B18 177B200C
140    BBE11757 7A615D6C 770988C0 BAD946E2 08E24FA0 74E5AB31
141    43DB5BFC E0FD108E 4B82D120 A93AD2CA FFFFFFFF FFFFFFFF""")
142    mLen  = 3072
143
144class modp4096(_FFDHParams): # From RFC 3526
145    g = 0x02
146    m = long_converter("""
147    FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1
148    29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD
149    EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245
150    E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED
151    EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D
152    C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F
153    83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D
154    670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B
155    E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9
156    DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510
157    15728E5A 8AAAC42D AD33170D 04507A33 A85521AB DF1CBA64
158    ECFB8504 58DBEF0A 8AEA7157 5D060C7D B3970F85 A6E1E4C7
159    ABF5AE8C DB0933D7 1E8C94E0 4A25619D CEE3D226 1AD2EE6B
160    F12FFA06 D98A0864 D8760273 3EC86A64 521F2B18 177B200C
161    BBE11757 7A615D6C 770988C0 BAD946E2 08E24FA0 74E5AB31
162    43DB5BFC E0FD108E 4B82D120 A9210801 1A723C12 A787E6D7
163    88719A10 BDBA5B26 99C32718 6AF4E23C 1A946834 B6150BDA
164    2583E9CA 2AD44CE8 DBBBC2DB 04DE8EF9 2E8EFC14 1FBECAA6
165    287C5947 4E6BC05D 99B2964F A090C3A2 233BA186 515BE7ED
166    1F612970 CEE2D7AF B81BDD76 2170481C D0069127 D5B05AA9
167    93B4EA98 8D8FDDC1 86FFB7DC 90A6C08F 4DF435C9 34063199
168    FFFFFFFF FFFFFFFF""")
169    mLen  = 4096
170
171class modp6144(_FFDHParams): # From RFC 3526
172    g = 0x02
173    m = long_converter("""
174    FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1 29024E08
175    8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD EF9519B3 CD3A431B
176    302B0A6D F25F1437 4FE1356D 6D51C245 E485B576 625E7EC6 F44C42E9
177    A637ED6B 0BFF5CB6 F406B7ED EE386BFB 5A899FA5 AE9F2411 7C4B1FE6
178    49286651 ECE45B3D C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8
179    FD24CF5F 83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D
180    670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B E39E772C
181    180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9 DE2BCBF6 95581718
182    3995497C EA956AE5 15D22618 98FA0510 15728E5A 8AAAC42D AD33170D
183    04507A33 A85521AB DF1CBA64 ECFB8504 58DBEF0A 8AEA7157 5D060C7D
184    B3970F85 A6E1E4C7 ABF5AE8C DB0933D7 1E8C94E0 4A25619D CEE3D226
185    1AD2EE6B F12FFA06 D98A0864 D8760273 3EC86A64 521F2B18 177B200C
186    BBE11757 7A615D6C 770988C0 BAD946E2 08E24FA0 74E5AB31 43DB5BFC
187    E0FD108E 4B82D120 A9210801 1A723C12 A787E6D7 88719A10 BDBA5B26
188    99C32718 6AF4E23C 1A946834 B6150BDA 2583E9CA 2AD44CE8 DBBBC2DB
189    04DE8EF9 2E8EFC14 1FBECAA6 287C5947 4E6BC05D 99B2964F A090C3A2
190    233BA186 515BE7ED 1F612970 CEE2D7AF B81BDD76 2170481C D0069127
191    D5B05AA9 93B4EA98 8D8FDDC1 86FFB7DC 90A6C08F 4DF435C9 34028492
192    36C3FAB4 D27C7026 C1D4DCB2 602646DE C9751E76 3DBA37BD F8FF9406
193    AD9E530E E5DB382F 413001AE B06A53ED 9027D831 179727B0 865A8918
194    DA3EDBEB CF9B14ED 44CE6CBA CED4BB1B DB7F1447 E6CC254B 33205151
195    2BD7AF42 6FB8F401 378CD2BF 5983CA01 C64B92EC F032EA15 D1721D03
196    F482D7CE 6E74FEF6 D55E702F 46980C82 B5A84031 900B1C9E 59E7C97F
197    BEC7E8F3 23A97A7E 36CC88BE 0F1D45B7 FF585AC5 4BD407B2 2B4154AA
198    CC8F6D7E BF48E1D8 14CC5ED2 0F8037E0 A79715EE F29BE328 06A1D58B
199    B7C5DA76 F550AA3D 8A1FBFF0 EB19CCB1 A313D55C DA56C9EC 2EF29632
200    387FE8D7 6E3C0468 043E8F66 3F4860EE 12BF2D5B 0B7474D6 E694F91E
201    6DCC4024 FFFFFFFF FFFFFFFF""")
202    mLen = 6144
203
204class modp8192(_FFDHParams): # From RFC 3526
205    g = 0x02
206    m = long_converter("""
207    FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1
208    29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD
209    EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245
210    E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED
211    EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D
212    C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F
213    83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D
214    670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B
215    E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9
216    DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510
217    15728E5A 8AAAC42D AD33170D 04507A33 A85521AB DF1CBA64
218    ECFB8504 58DBEF0A 8AEA7157 5D060C7D B3970F85 A6E1E4C7
219    ABF5AE8C DB0933D7 1E8C94E0 4A25619D CEE3D226 1AD2EE6B
220    F12FFA06 D98A0864 D8760273 3EC86A64 521F2B18 177B200C
221    BBE11757 7A615D6C 770988C0 BAD946E2 08E24FA0 74E5AB31
222    43DB5BFC E0FD108E 4B82D120 A9210801 1A723C12 A787E6D7
223    88719A10 BDBA5B26 99C32718 6AF4E23C 1A946834 B6150BDA
224    2583E9CA 2AD44CE8 DBBBC2DB 04DE8EF9 2E8EFC14 1FBECAA6
225    287C5947 4E6BC05D 99B2964F A090C3A2 233BA186 515BE7ED
226    1F612970 CEE2D7AF B81BDD76 2170481C D0069127 D5B05AA9
227    93B4EA98 8D8FDDC1 86FFB7DC 90A6C08F 4DF435C9 34028492
228    36C3FAB4 D27C7026 C1D4DCB2 602646DE C9751E76 3DBA37BD
229    F8FF9406 AD9E530E E5DB382F 413001AE B06A53ED 9027D831
230    179727B0 865A8918 DA3EDBEB CF9B14ED 44CE6CBA CED4BB1B
231    DB7F1447 E6CC254B 33205151 2BD7AF42 6FB8F401 378CD2BF
232    5983CA01 C64B92EC F032EA15 D1721D03 F482D7CE 6E74FEF6
233    D55E702F 46980C82 B5A84031 900B1C9E 59E7C97F BEC7E8F3
234    23A97A7E 36CC88BE 0F1D45B7 FF585AC5 4BD407B2 2B4154AA
235    CC8F6D7E BF48E1D8 14CC5ED2 0F8037E0 A79715EE F29BE328
236    06A1D58B B7C5DA76 F550AA3D 8A1FBFF0 EB19CCB1 A313D55C
237    DA56C9EC 2EF29632 387FE8D7 6E3C0468 043E8F66 3F4860EE
238    12BF2D5B 0B7474D6 E694F91E 6DBE1159 74A3926F 12FEE5E4
239    38777CB6 A932DF8C D8BEC4D0 73B931BA 3BC832B6 8D9DD300
240    741FA7BF 8AFC47ED 2576F693 6BA42466 3AAB639C 5AE4F568
241    3423B474 2BF1C978 238F16CB E39D652D E3FDB8BE FC848AD9
242    22222E04 A4037C07 13EB57A8 1A23F0C7 3473FC64 6CEA306B
243    4BCBC886 2F8385DD FA9D4B7F A2C087E8 79683303 ED5BDD3A
244    062B3CF5 B3A278A6 6D2A13F8 3F44F82D DF310EE0 74AB6A36
245    4597E899 A0255DC1 64F31CC5 0846851D F9AB4819 5DED7EA1
246    B1D510BD 7EE74D73 FAF36BC3 1ECFA268 359046F4 EB879F92
247    4009438B 481C6CD7 889A002E D5EE382B C9190DA6 FC026E47
248    9558E447 5677E9AA 9E3050E2 765694DF C81F56E8 80B96E71
249    60C980DD 98EDD3DF FFFFFFFF FFFFFFFF""")
250    mLen = 8192
251
252class ffdhe2048(_FFDHParams): # From RFC 7919
253    g = 0x02
254    m = long_converter("""
255    FFFFFFFF FFFFFFFF ADF85458 A2BB4A9A AFDC5620 273D3CF1
256    D8B9C583 CE2D3695 A9E13641 146433FB CC939DCE 249B3EF9
257    7D2FE363 630C75D8 F681B202 AEC4617A D3DF1ED5 D5FD6561
258    2433F51F 5F066ED0 85636555 3DED1AF3 B557135E 7F57C935
259    984F0C70 E0E68B77 E2A689DA F3EFE872 1DF158A1 36ADE735
260    30ACCA4F 483A797A BC0AB182 B324FB61 D108A94B B2C8E3FB
261    B96ADAB7 60D7F468 1D4F42A3 DE394DF4 AE56EDE7 6372BB19
262    0B07A7C8 EE0A6D70 9E02FCE1 CDF7E2EC C03404CD 28342F61
263    9172FE9C E98583FF 8E4F1232 EEF28183 C3FE3B1B 4C6FAD73
264    3BB5FCBC 2EC22005 C58EF183 7D1683B2 C6F34A26 C1B2EFFA
265    886B4238 61285C97 FFFFFFFF FFFFFFFF
266    """)
267    mLen = 2048
268
269class ffdhe3072(_FFDHParams): # From RFC 7919
270    g = 0x02
271    m = long_converter("""
272    FFFFFFFF FFFFFFFF ADF85458 A2BB4A9A AFDC5620 273D3CF1
273    D8B9C583 CE2D3695 A9E13641 146433FB CC939DCE 249B3EF9
274    7D2FE363 630C75D8 F681B202 AEC4617A D3DF1ED5 D5FD6561
275    2433F51F 5F066ED0 85636555 3DED1AF3 B557135E 7F57C935
276    984F0C70 E0E68B77 E2A689DA F3EFE872 1DF158A1 36ADE735
277    30ACCA4F 483A797A BC0AB182 B324FB61 D108A94B B2C8E3FB
278    B96ADAB7 60D7F468 1D4F42A3 DE394DF4 AE56EDE7 6372BB19
279    0B07A7C8 EE0A6D70 9E02FCE1 CDF7E2EC C03404CD 28342F61
280    9172FE9C E98583FF 8E4F1232 EEF28183 C3FE3B1B 4C6FAD73
281    3BB5FCBC 2EC22005 C58EF183 7D1683B2 C6F34A26 C1B2EFFA
282    886B4238 611FCFDC DE355B3B 6519035B BC34F4DE F99C0238
283    61B46FC9 D6E6C907 7AD91D26 91F7F7EE 598CB0FA C186D91C
284    AEFE1309 85139270 B4130C93 BC437944 F4FD4452 E2D74DD3
285    64F2E21E 71F54BFF 5CAE82AB 9C9DF69E E86D2BC5 22363A0D
286    ABC52197 9B0DEADA 1DBF9A42 D5C4484E 0ABCD06B FA53DDEF
287    3C1B20EE 3FD59D7C 25E41D2B 66C62E37 FFFFFFFF FFFFFFFF
288    """)
289    mLen = 3072
290
291class ffdhe4096(_FFDHParams): # From RFC 7919
292    g = 0x02
293    m = long_converter("""
294    FFFFFFFF FFFFFFFF ADF85458 A2BB4A9A AFDC5620 273D3CF1
295    D8B9C583 CE2D3695 A9E13641 146433FB CC939DCE 249B3EF9
296    7D2FE363 630C75D8 F681B202 AEC4617A D3DF1ED5 D5FD6561
297    2433F51F 5F066ED0 85636555 3DED1AF3 B557135E 7F57C935
298    984F0C70 E0E68B77 E2A689DA F3EFE872 1DF158A1 36ADE735
299    30ACCA4F 483A797A BC0AB182 B324FB61 D108A94B B2C8E3FB
300    B96ADAB7 60D7F468 1D4F42A3 DE394DF4 AE56EDE7 6372BB19
301    0B07A7C8 EE0A6D70 9E02FCE1 CDF7E2EC C03404CD 28342F61
302    9172FE9C E98583FF 8E4F1232 EEF28183 C3FE3B1B 4C6FAD73
303    3BB5FCBC 2EC22005 C58EF183 7D1683B2 C6F34A26 C1B2EFFA
304    886B4238 611FCFDC DE355B3B 6519035B BC34F4DE F99C0238
305    61B46FC9 D6E6C907 7AD91D26 91F7F7EE 598CB0FA C186D91C
306    AEFE1309 85139270 B4130C93 BC437944 F4FD4452 E2D74DD3
307    64F2E21E 71F54BFF 5CAE82AB 9C9DF69E E86D2BC5 22363A0D
308    ABC52197 9B0DEADA 1DBF9A42 D5C4484E 0ABCD06B FA53DDEF
309    3C1B20EE 3FD59D7C 25E41D2B 669E1EF1 6E6F52C3 164DF4FB
310    7930E9E4 E58857B6 AC7D5F42 D69F6D18 7763CF1D 55034004
311    87F55BA5 7E31CC7A 7135C886 EFB4318A ED6A1E01 2D9E6832
312    A907600A 918130C4 6DC778F9 71AD0038 092999A3 33CB8B7A
313    1A1DB93D 7140003C 2A4ECEA9 F98D0ACC 0A8291CD CEC97DCF
314    8EC9B55A 7F88A46B 4DB5A851 F44182E1 C68A007E 5E655F6A
315    FFFFFFFF FFFFFFFF
316    """)
317    mLen = 4096
318
319class ffdhe6144(_FFDHParams): # From RFC 7919
320    g = 0x02
321    m = long_converter("""
322    FFFFFFFF FFFFFFFF ADF85458 A2BB4A9A AFDC5620 273D3CF1
323    D8B9C583 CE2D3695 A9E13641 146433FB CC939DCE 249B3EF9
324    7D2FE363 630C75D8 F681B202 AEC4617A D3DF1ED5 D5FD6561
325    2433F51F 5F066ED0 85636555 3DED1AF3 B557135E 7F57C935
326    984F0C70 E0E68B77 E2A689DA F3EFE872 1DF158A1 36ADE735
327    30ACCA4F 483A797A BC0AB182 B324FB61 D108A94B B2C8E3FB
328    B96ADAB7 60D7F468 1D4F42A3 DE394DF4 AE56EDE7 6372BB19
329    0B07A7C8 EE0A6D70 9E02FCE1 CDF7E2EC C03404CD 28342F61
330    9172FE9C E98583FF 8E4F1232 EEF28183 C3FE3B1B 4C6FAD73
331    3BB5FCBC 2EC22005 C58EF183 7D1683B2 C6F34A26 C1B2EFFA
332    886B4238 611FCFDC DE355B3B 6519035B BC34F4DE F99C0238
333    61B46FC9 D6E6C907 7AD91D26 91F7F7EE 598CB0FA C186D91C
334    AEFE1309 85139270 B4130C93 BC437944 F4FD4452 E2D74DD3
335    64F2E21E 71F54BFF 5CAE82AB 9C9DF69E E86D2BC5 22363A0D
336    ABC52197 9B0DEADA 1DBF9A42 D5C4484E 0ABCD06B FA53DDEF
337    3C1B20EE 3FD59D7C 25E41D2B 669E1EF1 6E6F52C3 164DF4FB
338    7930E9E4 E58857B6 AC7D5F42 D69F6D18 7763CF1D 55034004
339    87F55BA5 7E31CC7A 7135C886 EFB4318A ED6A1E01 2D9E6832
340    A907600A 918130C4 6DC778F9 71AD0038 092999A3 33CB8B7A
341    1A1DB93D 7140003C 2A4ECEA9 F98D0ACC 0A8291CD CEC97DCF
342    8EC9B55A 7F88A46B 4DB5A851 F44182E1 C68A007E 5E0DD902
343    0BFD64B6 45036C7A 4E677D2C 38532A3A 23BA4442 CAF53EA6
344    3BB45432 9B7624C8 917BDD64 B1C0FD4C B38E8C33 4C701C3A
345    CDAD0657 FCCFEC71 9B1F5C3E 4E46041F 388147FB 4CFDB477
346    A52471F7 A9A96910 B855322E DB6340D8 A00EF092 350511E3
347    0ABEC1FF F9E3A26E 7FB29F8C 183023C3 587E38DA 0077D9B4
348    763E4E4B 94B2BBC1 94C6651E 77CAF992 EEAAC023 2A281BF6
349    B3A739C1 22611682 0AE8DB58 47A67CBE F9C9091B 462D538C
350    D72B0374 6AE77F5E 62292C31 1562A846 505DC82D B854338A
351    E49F5235 C95B9117 8CCF2DD5 CACEF403 EC9D1810 C6272B04
352    5B3B71F9 DC6B80D6 3FDD4A8E 9ADB1E69 62A69526 D43161C1
353    A41D570D 7938DAD4 A40E329C D0E40E65 FFFFFFFF FFFFFFFF
354    """)
355    mLen = 6144
356
357class ffdhe8192(_FFDHParams): # From RFC 7919
358    g = 0x02
359    m = long_converter("""
360    FFFFFFFF FFFFFFFF ADF85458 A2BB4A9A AFDC5620 273D3CF1
361    D8B9C583 CE2D3695 A9E13641 146433FB CC939DCE 249B3EF9
362    7D2FE363 630C75D8 F681B202 AEC4617A D3DF1ED5 D5FD6561
363    2433F51F 5F066ED0 85636555 3DED1AF3 B557135E 7F57C935
364    984F0C70 E0E68B77 E2A689DA F3EFE872 1DF158A1 36ADE735
365    30ACCA4F 483A797A BC0AB182 B324FB61 D108A94B B2C8E3FB
366    B96ADAB7 60D7F468 1D4F42A3 DE394DF4 AE56EDE7 6372BB19
367    0B07A7C8 EE0A6D70 9E02FCE1 CDF7E2EC C03404CD 28342F61
368    9172FE9C E98583FF 8E4F1232 EEF28183 C3FE3B1B 4C6FAD73
369    3BB5FCBC 2EC22005 C58EF183 7D1683B2 C6F34A26 C1B2EFFA
370    886B4238 611FCFDC DE355B3B 6519035B BC34F4DE F99C0238
371    61B46FC9 D6E6C907 7AD91D26 91F7F7EE 598CB0FA C186D91C
372    AEFE1309 85139270 B4130C93 BC437944 F4FD4452 E2D74DD3
373    64F2E21E 71F54BFF 5CAE82AB 9C9DF69E E86D2BC5 22363A0D
374    ABC52197 9B0DEADA 1DBF9A42 D5C4484E 0ABCD06B FA53DDEF
375    3C1B20EE 3FD59D7C 25E41D2B 669E1EF1 6E6F52C3 164DF4FB
376    7930E9E4 E58857B6 AC7D5F42 D69F6D18 7763CF1D 55034004
377    87F55BA5 7E31CC7A 7135C886 EFB4318A ED6A1E01 2D9E6832
378    A907600A 918130C4 6DC778F9 71AD0038 092999A3 33CB8B7A
379    1A1DB93D 7140003C 2A4ECEA9 F98D0ACC 0A8291CD CEC97DCF
380    8EC9B55A 7F88A46B 4DB5A851 F44182E1 C68A007E 5E0DD902
381    0BFD64B6 45036C7A 4E677D2C 38532A3A 23BA4442 CAF53EA6
382    3BB45432 9B7624C8 917BDD64 B1C0FD4C B38E8C33 4C701C3A
383    CDAD0657 FCCFEC71 9B1F5C3E 4E46041F 388147FB 4CFDB477
384    A52471F7 A9A96910 B855322E DB6340D8 A00EF092 350511E3
385    0ABEC1FF F9E3A26E 7FB29F8C 183023C3 587E38DA 0077D9B4
386    763E4E4B 94B2BBC1 94C6651E 77CAF992 EEAAC023 2A281BF6
387    B3A739C1 22611682 0AE8DB58 47A67CBE F9C9091B 462D538C
388    D72B0374 6AE77F5E 62292C31 1562A846 505DC82D B854338A
389    E49F5235 C95B9117 8CCF2DD5 CACEF403 EC9D1810 C6272B04
390    5B3B71F9 DC6B80D6 3FDD4A8E 9ADB1E69 62A69526 D43161C1
391    A41D570D 7938DAD4 A40E329C CFF46AAA 36AD004C F600C838
392    1E425A31 D951AE64 FDB23FCE C9509D43 687FEB69 EDD1CC5E
393    0B8CC3BD F64B10EF 86B63142 A3AB8829 555B2F74 7C932665
394    CB2C0F1C C01BD702 29388839 D2AF05E4 54504AC7 8B758282
395    2846C0BA 35C35F5C 59160CC0 46FD8251 541FC68C 9C86B022
396    BB709987 6A460E74 51A8A931 09703FEE 1C217E6C 3826E52C
397    51AA691E 0E423CFC 99E9E316 50C1217B 624816CD AD9A95F9
398    D5B80194 88D9C0A0 A1FE3075 A577E231 83F81D4A 3F2FA457
399    1EFC8CE0 BA8A4FE8 B6855DFE 72B0A66E DED2FBAB FBE58A30
400    FAFABE1C 5D71A87E 2F741EF8 C1FE86FE A6BBFDE5 30677F0D
401    97D11D49 F7A8443D 0822E506 A9F4614E 011E2A94 838FF88C
402    D68C8BB7 C5C6424C FFFFFFFF FFFFFFFF
403    """)
404    mLen = 8192
405
406
407_tls_named_ffdh_groups = { 256: "ffdhe2048", 257: "ffdhe3072",
408                           258: "ffdhe4096", 259: "ffdhe6144",
409                           260: "ffdhe8192" }
410
411_tls_named_curves = {  1: "sect163k1",  2: "sect163r1",  3: "sect163r2",
412                       4: "sect193r1",  5: "sect193r2",  6: "sect233k1",
413                       7: "sect233r1",  8: "sect239k1",  9: "sect283k1",
414                      10: "sect283r1", 11: "sect409k1", 12: "sect409r1",
415                      13: "sect571k1", 14: "sect571r1", 15: "secp160k1",
416                      16: "secp160r1", 17: "secp160r2", 18: "secp192k1",
417                      19: "secp192r1", 20: "secp224k1", 21: "secp224r1",
418                      22: "secp256k1", 23: "secp256r1", 24: "secp384r1",
419                      25: "secp521r1", 26: "brainpoolP256r1",
420                      27: "brainpoolP384r1", 28: "brainpoolP512r1",
421                      29: "x25519",    30: "x448",
422                      0xff01: "arbitrary_explicit_prime_curves",
423                      0xff02: "arbitrary_explicit_char2_curves"}
424
425_tls_named_groups = {}
426_tls_named_groups.update(_tls_named_ffdh_groups)
427_tls_named_groups.update(_tls_named_curves)
428
429
430# Below lies ghost code since the shift from 'ecdsa' to 'cryptography' lib.
431# Part of the code has been kept, but commented out, in case anyone would like
432# to improve ECC support in 'cryptography' (namely for the compressed point
433# format and additional curves).
434#
435# Recommended curve parameters from www.secg.org/SEC2-Ver-1.0.pdf
436# and www.ecc-brainpool.org/download/Domain-parameters.pdf
437#
438#
439#import math
440#
441#from scapy.utils import long_converter, binrepr
442#from scapy.layers.tls.crypto.pkcs1 import pkcs_i2osp, pkcs_os2ip
443#
444#
445#def encode_point(point, point_format=0):
446#    """
447#    Return a string representation of the Point p, according to point_format.
448#    """
449#    pLen = len(binrepr(point.curve().p()))
450#    x = pkcs_i2osp(point.x(), math.ceil(pLen/8))
451#    y = pkcs_i2osp(point.y(), math.ceil(pLen/8))
452#    if point_format == 0:
453#        frmt = b'\x04'
454#    elif point_format == 1:
455#        frmt = chr(2 + y%2)
456#        y = ''
457#    else:
458#        raise Exception("No support for point_format %d" % point_format)
459#    return frmt + x + y
460#
461#
462#try:
463#    import ecdsa
464#    ecdsa_support = True
465#except ImportError:
466#    import logging
467#    log_loading = logging.getLogger("scapy.loading")
468#    log_loading.info("Can't import python ecdsa lib. No curves.")
469#
470#
471#if ecdsa_support:
472#
473#    from ecdsa.ellipticcurve import CurveFp, Point
474#    from ecdsa.curves import Curve
475#    from ecdsa.numbertheory import square_root_mod_prime
476#
477#
478#    def extract_coordinates(g, curve):
479#        """
480#        Return the coordinates x and y as integers,
481#        regardless of the point format of string g.
482#        Second expected parameter is a CurveFp.
483#        """
484#        p = curve.p()
485#        point_format = g[0]
486#        point = g[1:]
487#        if point_format == b'\x04':
488#            point_len = len(point)
489#            if point_len % 2 != 0:
490#                raise Exception("Point length is not even.")
491#            x_bytes = point[:point_len>>1]
492#            x = pkcs_os2ip(x_bytes) % p
493#            y_bytes = point[point_len>>1:]
494#            y = pkcs_os2ip(y_bytes) % p
495#        elif point_format in [b'\x02', b'\x03']:
496#            x_bytes = point
497#            x = pkcs_os2ip(x_bytes) % p
498#            # perform the y coordinate computation with self.tls_ec
499#            y_square = (x*x*x + curve.a()*x + curve.b()) % p
500#            y = square_root_mod_prime(y_square, p)
501#            y_parity = ord(point_format) % 2    # \x02 means even, \x03 means odd
502#            if y % 2 != y_parity:
503#                y = -y % p
504#        else:
505#            raise Exception("Point starts with %s. This encoding "
506#                            "is not recognized." % repr(point_format))
507#        if not curve.contains_point(x, y):
508#            raise Exception("The point we extracted does not belong on the curve!")
509#        return x, y
510#
511#    def import_curve(p, a, b, g, r, name="dummyName", oid=(1, 3, 132, 0, 0xff)):
512#        """
513#        Create an ecdsa.curves.Curve from the usual parameters.
514#        Arguments may be either octet strings or integers,
515#        except g which we expect to be an octet string.
516#        """
517#        if isinstance(p, str):
518#            p = pkcs_os2ip(p)
519#        if isinstance(a, str):
520#            a = pkcs_os2ip(a)
521#        if isinstance(b, str):
522#            b = pkcs_os2ip(b)
523#        if isinstance(r, str):
524#            r = pkcs_os2ip(r)
525#        curve = CurveFp(p, a, b)
526#        x, y = extract_coordinates(g, curve)
527#        generator = Point(curve, x, y, r)
528#        return Curve(name, curve, generator, oid)
529
530
531    ### Named curves
532
533    # We always provide _a as a positive integer.
534
535#    _p          = long_converter("""
536#                  ffffffff ffffffff ffffffff fffffffe ffffac73""")
537#    _a          = 0
538#    _b          = 7
539#    _Gx         = long_converter("""
540#                  3b4c382c e37aa192 a4019e76 3036f4f5 dd4d7ebb""")
541#    _Gy         = long_converter("""
542#                  938cf935 318fdced 6bc28286 531733c3 f03c4fee""")
543#    _r          = long_converter("""01
544#                  00000000 00000000 0001b8fa 16dfab9a ca16b6b3""")
545#    curve       = CurveFp(_p, _a, _b)
546#    generator   = Point(curve, _Gx, _Gy, _r)
547#    SECP160k1   = Curve("SECP160k1", curve, generator,
548#                        (1, 3, 132, 0, 9), "secp160k1")
549
550#    _p          = long_converter("""
551#                  ffffffff ffffffff ffffffff ffffffff 7fffffff""")
552#    _a          = -3 % _p
553#    _b          = long_converter("""
554#                  1c97befc 54bd7a8b 65acf89f 81d4d4ad c565fa45""")
555#    _Gx         = long_converter("""
556#                  4a96b568 8ef57328 46646989 68c38bb9 13cbfc82""")
557#    _Gy         = long_converter("""
558#                  23a62855 3168947d 59dcc912 04235137 7ac5fb32""")
559#    _r          = long_converter("""01
560#                  00000000 00000000 0001f4c8 f927aed3 ca752257""")
561#    curve       = CurveFp(_p, _a, _b)
562#    generator   = Point(curve, _Gx, _Gy, _r)
563#    SECP160r1   = Curve("SECP160r1", curve, generator,
564#                        (1, 3, 132, 0, 8), "secp160r1")
565
566#    _p          = long_converter("""
567#                  ffffffff ffffffff ffffffff fffffffe ffffac73""")
568#    _a          = -3 % _p
569#    _b          = long_converter("""
570#                  b4e134d3 fb59eb8b ab572749 04664d5a f50388ba""")
571#    _Gx         = long_converter("""
572#                  52dcb034 293a117e 1f4ff11b 30f7199d 3144ce6d""")
573#    _Gy         = long_converter("""
574#                  feaffef2 e331f296 e071fa0d f9982cfe a7d43f2e""")
575#    _r          = long_converter("""01
576#                  00000000 00000000 0000351e e786a818 f3a1a16b""")
577#    curve       = CurveFp(_p, _a, _b)
578#    generator   = Point(curve, _Gx, _Gy, _r)
579#    SECP160r2   = Curve("SECP160r2", curve, generator,
580#                        (1, 3, 132, 0, 30), "secp160r2")
581
582#    _p          = long_converter("""
583#                  ffffffff ffffffff ffffffff ffffffff fffffffe ffffee37""")
584#    _a          = 0
585#    _b          = 3
586#    _Gx         = long_converter("""
587#                  db4ff10e c057e9ae 26b07d02 80b7f434 1da5d1b1 eae06c7d""")
588#    _Gy         = long_converter("""
589#                  9b2f2f6d 9c5628a7 844163d0 15be8634 4082aa88 d95e2f9d""")
590#    _r          = long_converter("""
591#                  ffffffff ffffffff fffffffe 26f2fc17 0f69466a 74defd8d""")
592#    curve       = CurveFp(_p, _a, _b)
593#    generator   = Point(curve, _Gx, _Gy, _r)
594#    SECP192k1   = Curve("SECP192k1", curve, generator,
595#                        (1, 3, 132, 0, 31), "secp192k1")
596
597#    _p          = long_converter("""
598#                  ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe
599#                  ffffe56d""")
600#    _a          = 0
601#    _b          = 5
602#    _Gx         = long_converter("""
603#                  a1455b33 4df099df 30fc28a1 69a467e9 e47075a9 0f7e650e
604#                  b6b7a45c""")
605#    _Gy         = long_converter("""
606#                  7e089fed 7fba3442 82cafbd6 f7e319f7 c0b0bd59 e2ca4bdb
607#                  556d61a5""")
608#    _r          = long_converter("""01
609#                  00000000 00000000 00000000 0001dce8 d2ec6184 caf0a971
610#                  769fb1f7""")
611#    curve       = CurveFp(_p, _a, _b)
612#    generator   = Point(curve, _Gx, _Gy, _r)
613#    SECP224k1   = Curve("SECP224k1", curve, generator,
614#                        (1, 3, 132, 0, 32), "secp224k1")
615
616#    _p          = long_converter("""
617#                  A9FB57DB A1EEA9BC 3E660A90 9D838D72 6E3BF623 D5262028
618#                  2013481D 1F6E5377""")
619#    _a          = long_converter("""
620#                  7D5A0975 FC2C3057 EEF67530 417AFFE7 FB8055C1 26DC5C6C
621#                  E94A4B44 F330B5D9""")
622#    _b          = long_converter("""
623#                  26DC5C6C E94A4B44 F330B5D9 BBD77CBF 95841629 5CF7E1CE
624#                  6BCCDC18 FF8C07B6""")
625#    _Gx         = long_converter("""
626#                  8BD2AEB9 CB7E57CB 2C4B482F FC81B7AF B9DE27E1 E3BD23C2
627#                  3A4453BD 9ACE3262""")
628#    _Gy         = long_converter("""
629#                  547EF835 C3DAC4FD 97F8461A 14611DC9 C2774513 2DED8E54
630#                  5C1D54C7 2F046997""")
631#    _r          = long_converter("""
632#                  A9FB57DB A1EEA9BC 3E660A90 9D838D71 8C397AA3 B561A6F7
633#                  901E0E82 974856A7""")
634#    curve       = CurveFp(_p, _a, _b)
635#    generator   = Point(curve, _Gx, _Gy, _r)
636#    BRNP256r1   = Curve("BRNP256r1", curve, generator,
637#                        (1, 3, 36, 3, 3, 2, 8, 1, 1, 7), "brainpoolP256r1")
638
639#    _p          = long_converter("""
640#                  8CB91E82 A3386D28 0F5D6F7E 50E641DF 152F7109 ED5456B4
641#                  12B1DA19 7FB71123 ACD3A729 901D1A71 87470013 3107EC53""")
642#    _a          = long_converter("""
643#                  7BC382C6 3D8C150C 3C72080A CE05AFA0 C2BEA28E 4FB22787
644#                  139165EF BA91F90F 8AA5814A 503AD4EB 04A8C7DD 22CE2826""")
645#    _b          = long_converter("""
646#                  04A8C7DD 22CE2826 8B39B554 16F0447C 2FB77DE1 07DCD2A6
647#                  2E880EA5 3EEB62D5 7CB43902 95DBC994 3AB78696 FA504C11""")
648#    _Gx         = long_converter("""
649#                  1D1C64F0 68CF45FF A2A63A81 B7C13F6B 8847A3E7 7EF14FE3
650#                  DB7FCAFE 0CBD10E8 E826E034 36D646AA EF87B2E2 47D4AF1E""")
651#    _Gy         = long_converter("""
652#                  8ABE1D75 20F9C2A4 5CB1EB8E 95CFD552 62B70B29 FEEC5864
653#                  E19C054F F9912928 0E464621 77918111 42820341 263C5315""")
654#    _r          = long_converter("""
655#                  8CB91E82 A3386D28 0F5D6F7E 50E641DF 152F7109 ED5456B3
656#                  1F166E6C AC0425A7 CF3AB6AF 6B7FC310 3B883202 E9046565""")
657#    curve       = CurveFp(_p, _a, _b)
658#    generator   = Point(curve, _Gx, _Gy, _r)
659#    BRNP384r1   = Curve("BRNP384r1", curve, generator,
660#                        (1, 3, 36, 3, 3, 2, 8, 1, 1, 11), "brainpoolP384r1")
661
662#    _p          = long_converter("""
663#                  AADD9DB8 DBE9C48B 3FD4E6AE 33C9FC07 CB308DB3 B3C9D20E
664#                  D6639CCA 70330871 7D4D9B00 9BC66842 AECDA12A E6A380E6
665#                  2881FF2F 2D82C685 28AA6056 583A48F3""")
666#    _a          = long_converter("""
667#                  7830A331 8B603B89 E2327145 AC234CC5 94CBDD8D 3DF91610
668#                  A83441CA EA9863BC 2DED5D5A A8253AA1 0A2EF1C9 8B9AC8B5
669#                  7F1117A7 2BF2C7B9 E7C1AC4D 77FC94CA""")
670#    _b          = long_converter("""
671#                  3DF91610 A83441CA EA9863BC 2DED5D5A A8253AA1 0A2EF1C9
672#                  8B9AC8B5 7F1117A7 2BF2C7B9 E7C1AC4D 77FC94CA DC083E67
673#                  984050B7 5EBAE5DD 2809BD63 8016F723""")
674#    _Gx         = long_converter("""
675#                  81AEE4BD D82ED964 5A21322E 9C4C6A93 85ED9F70 B5D916C1
676#                  B43B62EE F4D0098E FF3B1F78 E2D0D48D 50D1687B 93B97D5F
677#                  7C6D5047 406A5E68 8B352209 BCB9F822""")
678#    _Gy         = long_converter("""
679#                  7DDE385D 566332EC C0EABFA9 CF7822FD F209F700 24A57B1A
680#                  A000C55B 881F8111 B2DCDE49 4A5F485E 5BCA4BD8 8A2763AE
681#                  D1CA2B2F A8F05406 78CD1E0F 3AD80892""")
682#    _r          = long_converter("""
683#                  AADD9DB8 DBE9C48B 3FD4E6AE 33C9FC07 CB308DB3 B3C9D20E
684#                  D6639CCA 70330870 553E5C41 4CA92619 41866119 7FAC1047
685#                  1DB1D381 085DDADD B5879682 9CA90069""")
686#    curve       = CurveFp(_p, _a, _b)
687#    generator   = Point(curve, _Gx, _Gy, _r)
688#    BRNP512r1   = Curve("BRNP512r1", curve, generator,
689#                        (1, 3, 36, 3, 3, 2, 8, 1, 1, 13), "brainpoolP512r1")
690
691