tls_ffdhe.c
Go to the documentation of this file.
1 /**
2  * @file tls_ffdhe.c
3  * @brief FFDHE key exchange
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneSSL Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL TLS_TRACE_LEVEL
33 
34 //Dependencies
35 #include "tls.h"
36 #include "tls_ffdhe.h"
37 #include "debug.h"
38 
39 //Check TLS library configuration
40 #if (TLS_SUPPORT == ENABLED && TLS_FFDHE_SUPPORT == ENABLED)
41 
42 #if (TLS_FFDHE2048_SUPPORT == ENABLED)
43 
44 /**
45  * @brief ffdhe2048 group
46  **/
47 
49 {
50  //Group name
51  "ffdhe2048",
52  //Prime modulus
53  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A,
54  0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95,
55  0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x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, 0x05,
67  0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA,
68  0x88, 0x6B, 0x42, 0x38, 0x61, 0x28, 0x5C, 0x97, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
69  256,
70  //Generator
71  2
72 };
73 
74 #endif
75 #if (TLS_FFDHE3072_SUPPORT == ENABLED)
76 
77 /**
78  * @brief ffdhe3072 group
79  **/
80 
82 {
83  //Group name
84  "ffdhe3072",
85  //Prime modulus
86  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A,
87  0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95,
88  0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9,
89  0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A,
90  0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0,
91  0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35,
92  0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72,
93  0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, 0x30, 0xAC, 0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, 0xBC, 0x43, 0x79, 0x44,
105  0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF,
106  0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D,
107  0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E,
108  0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C,
109  0x25, 0xE4, 0x1D, 0x2B, 0x66, 0xC6, 0x2E, 0x37, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
110  384,
111  //Generator
112  2
113 };
114 
115 #endif
116 #if (TLS_FFDHE4096_SUPPORT == ENABLED)
117 
118 /**
119  * @brief ffdhe4096 group
120  **/
121 
123 {
124  //Group name
125  "ffdhe4096",
126  //Prime modulus
127  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A,
128  0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95,
129  0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9,
130  0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A,
131  0xD3, 0xDF, 0x1E, 0xD5, 0xD5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8A, 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32,
154  0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38,
155  0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C,
156  0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF,
157  0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1,
158  0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x65, 0x5F, 0x6A, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
159  512,
160  //Generator
161  2
162 };
163 
164 #endif
165 
166 
167 /**
168  * @brief Select the named group to be used when performing FFDHE key exchange
169  * @param[in] context Pointer to the TLS context
170  * @param[in] groupList List of named groups supported by the peer
171  * @return Error code
172  **/
173 
175  const TlsSupportedGroupList *groupList)
176 {
177  error_t error;
178  uint_t i;
179  uint_t j;
180  uint_t n;
181  uint16_t namedGroup;
182  bool_t ffdheGroupFound;
183 
184  //Initialize status code
185  error = ERROR_HANDSHAKE_FAILED;
186 
187  //Initialize flag
188  ffdheGroupFound = FALSE;
189 
190  //Reset the named group to its default value
191  context->namedGroup = TLS_GROUP_NONE;
192 
193  //Check whether a list of named groups is offered by the client
194  if(groupList != NULL)
195  {
196  //Get the number of named groups present in the list
197  n = ntohs(groupList->length) / sizeof(uint16_t);
198 
199  //Any preferred groups?
200  if(context->numSupportedGroups > 0)
201  {
202  //Loop through the list of allowed groups (most preferred first)
203  for(i = 0; i < context->numSupportedGroups; i++)
204  {
205  //Loop through the list of named groups the client supports
206  for(j = 0; j < n; j++)
207  {
208  //Convert the named group to host byte order
209  namedGroup = ntohs(groupList->value[j]);
210 
211  //Check whether the SupportedGroups extension contains codepoints
212  //between 256 and 511, inclusive
213  if(namedGroup >= TLS_GROUP_FFDHE2048 &&
214  namedGroup <= TLS_GROUP_FFDHE_MAX)
215  {
216  //The list contains at least one FFDHE group
217  ffdheGroupFound = TRUE;
218  }
219 
220  //The named group to be used when performing FFDHE key exchange
221  //must be one of those present in the SupportedGroups extension
222  if(context->supportedGroups[i] == namedGroup)
223  {
224  //Acceptable FFDHE group found?
225  if(tlsGetFfdheGroup(context, namedGroup) != NULL)
226  {
227  //Save the named group
228  if(context->namedGroup == TLS_GROUP_NONE)
229  {
230  context->namedGroup = namedGroup;
231  }
232  }
233  }
234  }
235  }
236  }
237  else
238  {
239  //The named group to be used when performing FFDHE key exchange must
240  //be one of those present in the SupportedGroups extension
241  for(j = 0; j < n; j++)
242  {
243  //Convert the named group to host byte order
244  namedGroup = ntohs(groupList->value[j]);
245 
246  //Check whether the SupportedGroups extension contains codepoints
247  //between 256 and 511, inclusive
248  if(namedGroup >= TLS_GROUP_FFDHE2048 &&
249  namedGroup <= TLS_GROUP_FFDHE_MAX)
250  {
251  //The list contains at least one FFDHE group
252  ffdheGroupFound = TRUE;
253  }
254 
255  //Acceptable FFDHE group found?
256  if(tlsGetFfdheGroup(context, namedGroup) != NULL)
257  {
258  //Save the named group
259  if(context->namedGroup == TLS_GROUP_NONE)
260  {
261  context->namedGroup = namedGroup;
262  }
263  }
264  }
265  }
266  }
267 
268  //If the SupportedGroups extension is either absent from the ClientHello
269  //entirely or contains no FFDHE groups, then the server knows that the
270  //client is not compatible with RFC 7919
271  if(!ffdheGroupFound)
272  {
273  //In this scenario, the server may select an FFDHE group of its choice
274  if(tlsGetFfdheGroup(context, TLS_GROUP_FFDHE2048) != NULL)
275  {
276  //Select ffdhe2048 finite field group
277  context->namedGroup = TLS_GROUP_FFDHE2048;
278  }
279  else if(tlsGetFfdheGroup(context, TLS_GROUP_FFDHE3072) != NULL)
280  {
281  //Select ffdhe3072 finite field group
282  context->namedGroup = TLS_GROUP_FFDHE3072;
283  }
284  else if(tlsGetFfdheGroup(context, TLS_GROUP_FFDHE4096) != NULL)
285  {
286  //Select ffdhe4096 finite field group
287  context->namedGroup = TLS_GROUP_FFDHE4096;
288  }
289  else
290  {
291  //Just for sanity
292  context->namedGroup = TLS_GROUP_NONE;
293  }
294  }
295 
296  //If no acceptable choices are presented, then return an error
297  if(context->namedGroup != TLS_GROUP_NONE)
298  {
299  error = NO_ERROR;
300  }
301 
302  //Return status code
303  return error;
304 }
305 
306 
307 /**
308  * @brief Get the FFDHE parameters that match the specified named group
309  * @param[in] context Pointer to the TLS context
310  * @param[in] namedGroup Named group
311  * @return FFDHE parameters
312  **/
313 
314 const TlsFfdheGroup *tlsGetFfdheGroup(TlsContext *context, uint16_t namedGroup)
315 {
316  uint_t i;
317  const TlsFfdheGroup *ffdheGroup;
318 
319  //Check named group
320  switch(namedGroup)
321  {
322 #if (TLS_FFDHE2048_SUPPORT == ENABLED)
323  //ffdhe2048 group?
324  case TLS_GROUP_FFDHE2048:
325  ffdheGroup = &ffdhe2048Group;
326  break;
327 #endif
328 #if (TLS_FFDHE3072_SUPPORT == ENABLED)
329  //ffdhe3072 group?
330  case TLS_GROUP_FFDHE3072:
331  ffdheGroup = &ffdhe3072Group;
332  break;
333 #endif
334 #if (TLS_FFDHE4096_SUPPORT == ENABLED)
335  //ffdhe4096 group?
336  case TLS_GROUP_FFDHE4096:
337  ffdheGroup = &ffdhe4096Group;
338  break;
339 #endif
340  //Unknown group?
341  default:
342  ffdheGroup = NULL;
343  break;
344  }
345 
346  //Restrict the use of certain FFDHE groups
347  if(context->numSupportedGroups > 0)
348  {
349  //Loop through the list of allowed named groups
350  for(i = 0; i < context->numSupportedGroups; i++)
351  {
352  //Compare named groups
353  if(context->supportedGroups[i] == namedGroup)
354  break;
355  }
356 
357  //Check whether the use of the FFDHE group is restricted
358  if(i >= context->numSupportedGroups)
359  ffdheGroup = NULL;
360  }
361 
362  //Return FFDHE parameters, if any
363  return ffdheGroup;
364 }
365 
366 
367 /**
368  * @brief Load FFDHE parameters
369  * @param[out] params Pointer to the structure to be initialized
370  * @param[in] ffdheGroup FFDHE parameters
371  * @return Error code
372  **/
373 
375  const TlsFfdheGroup *ffdheGroup)
376 {
377  error_t error;
378 
379  //Make sure the FFDHE group is supported
380  if(ffdheGroup != NULL)
381  {
382  //Convert the prime modulus to a multiple precision integer
383  error = mpiImport(&params->p, ffdheGroup->p, ffdheGroup->pLen,
385 
386  //Check status code
387  if(!error)
388  {
389  //Convert the generator to a multiple precision integer
390  error = mpiSetValue(&params->g, ffdheGroup->g);
391  }
392  }
393  else
394  {
395  //The specified FFDHE group is not supported
396  error = ERROR_FAILURE;
397  }
398 
399  //Return status code
400  return error;
401 }
402 
403 #endif
int bool_t
Definition: compiler_port.h:53
#define TRUE
Definition: os_port.h:50
error_t mpiSetValue(Mpi *r, int_t a)
Set the value of a multiple precision integer.
Definition: mpi.c:484
@ ERROR_HANDSHAKE_FAILED
Definition: error.h:233
FFDHE parameters.
Definition: tls_ffdhe.h:49
error_t mpiImport(Mpi *r, const uint8_t *data, uint_t length, MpiFormat format)
Octet string to integer conversion.
Definition: mpi.c:624
const TlsFfdheGroup ffdhe2048Group
ffdhe2048 group
Definition: tls_ffdhe.c:48
const TlsFfdheGroup ffdhe3072Group
ffdhe3072 group
Definition: tls_ffdhe.c:81
const TlsFfdheGroup ffdhe4096Group
ffdhe4096 group
Definition: tls_ffdhe.c:122
#define FALSE
Definition: os_port.h:46
#define TlsContext
Definition: tls.h:36
error_t
Error codes.
Definition: error.h:43
@ TLS_GROUP_NONE
Definition: tls.h:1370
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
@ TLS_GROUP_FFDHE4096
Definition: tls.h:1414
Mpi p
Prime modulus.
Definition: dh.h:50
@ TLS_GROUP_FFDHE2048
Definition: tls.h:1412
const TlsFfdheGroup * tlsGetFfdheGroup(TlsContext *context, uint16_t namedGroup)
Get the FFDHE parameters that match the specified named group.
Definition: tls_ffdhe.c:314
error_t tlsLoadFfdheParameters(DhParameters *params, const TlsFfdheGroup *ffdheGroup)
Load FFDHE parameters.
Definition: tls_ffdhe.c:374
error_t tlsSelectFfdheGroup(TlsContext *context, const TlsSupportedGroupList *groupList)
Select the named group to be used when performing FFDHE key exchange.
Definition: tls_ffdhe.c:174
const uint8_t p[512]
Prime modulus.
Definition: tls_ffdhe.h:51
@ TLS_GROUP_FFDHE3072
Definition: tls.h:1413
#define ntohs(value)
Definition: cpu_endian.h:421
uint8_t n
@ TLS_GROUP_FFDHE_MAX
Definition: tls.h:1417
@ MPI_FORMAT_BIG_ENDIAN
Definition: mpi.h:71
TLS (Transport Layer Security)
Mpi g
Generator.
Definition: dh.h:51
FFDHE key exchange.
uint8_t g
Generator.
Definition: tls_ffdhe.h:53
Diffie-Hellman parameters.
Definition: dh.h:49
unsigned int uint_t
Definition: compiler_port.h:50
TlsSupportedGroupList
Definition: tls.h:1651
size_t pLen
Length of the prime modulus, in bytes.
Definition: tls_ffdhe.h:52
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.