tls_sign_misc.c
Go to the documentation of this file.
1 /**
2  * @file tls_sign_misc.c
3  * @brief Helper functions for signature generation and verification
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2022-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneIPSEC 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_cipher_suites.h"
37 #include "tls_sign_misc.h"
38 #include "tls_misc.h"
39 #include "debug.h"
40 
41 //Check TLS library configuration
42 #if (TLS_SUPPORT == ENABLED)
43 
44 //List of supported signature algorithms
45 const uint16_t tlsSupportedSignAlgos[] =
46 {
73 };
74 
75 
76 /**
77  * @brief Select the algorithm to be used when generating digital signatures
78  * @param[in] context Pointer to the TLS context
79  * @param[in] cert End entity certificate
80  * @param[in] signAlgoList List of signature/hash algorithm pairs offered by
81  * the peer
82  * @return Error code
83  **/
84 
86  const TlsSignSchemeList *signAlgoList)
87 {
88  error_t error;
89  uint_t i;
90  uint_t n;
91  uint16_t signScheme;
92 
93  //Initialize status code
94  error = NO_ERROR;
95  //Default signature algorithm
96  context->signScheme = TLS_SIGN_SCHEME_NONE;
97 
98  //TLS 1.0 or TLS 1.1 currently selected?
99  if(context->version <= TLS_VERSION_1_1)
100  {
101  //Check certificate type
102  if(cert->type != TLS_CERT_RSA_SIGN &&
103  cert->type != TLS_CERT_DSS_SIGN &&
104  cert->type != TLS_CERT_ECDSA_SIGN)
105  {
106  error = ERROR_HANDSHAKE_FAILED;
107  }
108  }
109  else
110  {
111  //Check whether the peer has provided a list of supported signature
112  //algorithms
113  if(signAlgoList != NULL)
114  {
115  //Any preferred preferred signature algorithms?
116  if(context->numSupportedSignAlgos > 0)
117  {
118  //Loop through the list of allowed signature algorithms (most
119  //preferred first)
120  for(i = 0; i < context->numSupportedSignAlgos; i++)
121  {
122  //Get current signature algorithm
123  signScheme = context->supportedSignAlgos[i];
124 
125  //Check whether the signature algorithm is offered by the peer
126  if(tlsIsSignAlgoOffered(signScheme, signAlgoList))
127  {
128  //The signature algorithm must be compatible with the key in
129  //the end-entity certificate (refer to RFC 5246, section 7.4.3)
130  if(tlsIsSignAlgoAcceptable(context, signScheme, cert))
131  {
132  //Check whether the signature algorithm is supported
133  if(tlsIsSignAlgoSupported(context, signScheme))
134  {
135  context->signScheme = (TlsSignatureScheme) signScheme;
136  break;
137  }
138  }
139  }
140  }
141  }
142  else
143  {
144  //Retrieve the number of items in the list
145  n = ntohs(signAlgoList->length) / sizeof(uint16_t);
146 
147  //Loop through the list of signature algorithms offered by the peer
148  for(i = 0; i < n; i++)
149  {
150  //Each SignatureScheme value lists a single signature algorithm
151  signScheme = ntohs(signAlgoList->value[i]);
152 
153  //The signature algorithm must be compatible with the key in the
154  //end-entity certificate (refer to RFC 5246, section 7.4.3)
155  if(tlsIsSignAlgoAcceptable(context, signScheme, cert))
156  {
157  //Check whether the signature algorithm is supported
158  if(tlsIsSignAlgoSupported(context, signScheme))
159  {
160  context->signScheme = (TlsSignatureScheme) signScheme;
161  break;
162  }
163  }
164  }
165  }
166  }
167  else
168  {
169  //TLS 1.2 clients may omit the SignatureAlgorithms extension
170  if(context->version == TLS_VERSION_1_2)
171  {
172  //Check certificate type
173  if(cert->type == TLS_CERT_RSA_SIGN)
174  {
175  //If the negotiated key exchange algorithm is one of RSA,
176  //DHE_RSA, DH_RSA, RSA_PSK, ECDH_RSA, ECDHE_RSA, behave as if
177  //client had sent the value {sha1,rsa}
178  signScheme = TLS_SIGN_SCHEME(TLS_SIGN_ALGO_RSA,
180  }
181  else if(cert->type == TLS_CERT_DSS_SIGN)
182  {
183  //If the negotiated key exchange algorithm is one of DHE_DSS,
184  //DH_DSS, behave as if the client had sent the value {sha1,dsa}
185  signScheme = TLS_SIGN_SCHEME(TLS_SIGN_ALGO_DSA,
187  }
188  else if(cert->type == TLS_CERT_ECDSA_SIGN)
189  {
190  //If the negotiated key exchange algorithm is one of ECDH_ECDSA,
191  //ECDHE_ECDSA, behave as if the client had sent value {sha1,ecdsa}
194  }
195  else
196  {
197  //Unknown certificate type
198  signScheme = TLS_SIGN_SCHEME_NONE;
199  }
200 
201  //Check whether the signature algorithm is supported
202  if(tlsIsSignAlgoSupported(context, signScheme))
203  {
204  context->signScheme = (TlsSignatureScheme) signScheme;
205  }
206  }
207  }
208 
209  //If no acceptable choices are presented, return an error
210  if(context->signScheme == TLS_SIGN_SCHEME_NONE)
211  {
212  error = ERROR_HANDSHAKE_FAILED;
213  }
214  }
215 
216  //Return status code
217  return error;
218 }
219 
220 
221 /**
222  * @brief Format SignatureAlgorithms extension
223  * @param[in] context Pointer to the TLS context
224  * @param[in] p Output stream where to write the SignatureAlgorithms extension
225  * @param[out] written Total number of bytes that have been written
226  * @return Error code
227  **/
228 
230  size_t *written)
231 {
232  error_t error;
233  size_t n;
234 
235  //Initialize status code
236  error = NO_ERROR;
237 
238 #if (TLS_MAX_VERSION >= TLS_VERSION_1_2 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
239  //Check whether TLS 1.2 or TLS 1.3 is supported
240  if(context->versionMax >= TLS_VERSION_1_2)
241  {
242  TlsExtension *extension;
243 
244  //Add the SignatureAlgorithms extension
245  extension = (TlsExtension *) p;
246  //Type of the extension
247  extension->type = HTONS(TLS_EXT_SIGNATURE_ALGORITHMS);
248 
249  //The SignatureAlgorithms extension indicates which signature/hash
250  //algorithm pairs may be used in digital signatures
251  error = tlsFormatSupportedSignAlgos(context, extension->value, &n);
252 
253  //Check status code
254  if(!error)
255  {
256  //Fix the length of the extension
257  extension->length = htons(n);
258 
259  //Compute the length, in bytes, of the SignatureAlgorithms extension
260  n += sizeof(TlsExtension);
261  }
262  }
263  else
264 #endif
265  {
266  //This extension is not meaningful for TLS versions prior to 1.2.
267  //Clients must not offer it if they are offering prior versions (refer
268  //to RFC 5246, section 7.4.1.4.1)
269  n = 0;
270  }
271 
272  //Check status code
273  if(!error)
274  {
275  //Total number of bytes that have been written
276  *written = n;
277  }
278 
279  //Return status code
280  return error;
281 }
282 
283 
284 /**
285  * @brief Format SignatureAlgorithmsCert extension
286  * @param[in] context Pointer to the TLS context
287  * @param[in] p Output stream where to write the SignatureAlgorithmsCert extension
288  * @param[out] written Total number of bytes that have been written
289  * @return Error code
290  **/
291 
293  uint8_t *p, size_t *written)
294 {
295  size_t n = 0;
296 
297 #if (TLS_MAX_VERSION >= TLS_VERSION_1_2 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
298  //TLS 1.2 implementations should also process this extension
299  if(context->versionMax >= TLS_VERSION_1_2)
300  {
301  uint_t i;
302  TlsExtension *extension;
303  TlsSignSchemeList *signAlgoList;
304 
305  //Add the SignatureAlgorithmsCert extension
306  extension = (TlsExtension *) p;
307  //Type of the extension
308  extension->type = HTONS(TLS_EXT_SIGNATURE_ALGORITHMS_CERT);
309 
310  //The SignatureAlgorithmsCert extension allows an implementation to
311  //indicate which signature algorithms it can validate in X.509
312  //certificates
313  signAlgoList = (TlsSignSchemeList *) extension->value;
314 
315  //Enumerate the hash/signature algorithm pairs in descending order
316  //of preference
317  n = 0;
318 
319  //Loop through the list of supported signature algorithms
320  for(i = 0; i < arraysize(tlsSupportedSignAlgos); i++)
321  {
322  //Check whether the signature algorithm can be used for X.509
323  //certificate validation
325  {
326  //Add the current signature algorithm to the list
327  signAlgoList->value[n++] = htons(tlsSupportedSignAlgos[i]);
328  }
329  }
330 
331  //Compute the length, in bytes, of the list
332  n *= sizeof(uint16_t);
333  //Fix the length of the list
334  signAlgoList->length = htons(n);
335 
336  //Consider the 2-byte length field that precedes the list
337  n += sizeof(TlsSignSchemeList);
338  //Fix the length of the extension
339  extension->length = htons(n);
340 
341  //Compute the length, in bytes, of the SignatureAlgorithmsCert extension
342  n += sizeof(TlsExtension);
343  }
344 #endif
345 
346  //Total number of bytes that have been written
347  *written = n;
348 
349  //Successful processing
350  return NO_ERROR;
351 }
352 
353 
354 /**
355  * @brief Format the list of supported signature algorithms
356  * @param[in] context Pointer to the TLS context
357  * @param[in] p Output stream where to write the list of signature algorithms
358  * @param[out] written Total number of bytes that have been written
359  * @return Error code
360  **/
361 
363  size_t *written)
364 {
365 #if (TLS_MAX_VERSION >= TLS_VERSION_1_2 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
366  uint_t i;
367  size_t n;
368  uint_t numSupportedSignAlgos;
369  const uint16_t *supportedSignAlgos;
370  TlsSignSchemeList *signAlgoList;
371 
372  //The list contains the hash/signature algorithm pairs that the
373  //implementation is able to verify
374  signAlgoList = (TlsSignSchemeList *) p;
375 
376  //Any preferred preferred signature algorithms?
377  if(context->numSupportedSignAlgos > 0)
378  {
379  //Point to the list of preferred signature algorithms
380  supportedSignAlgos = context->supportedSignAlgos;
381  numSupportedSignAlgos = context->numSupportedSignAlgos;
382  }
383  else
384  {
385  //Point to the list of default signature algorithms
386  supportedSignAlgos = tlsSupportedSignAlgos;
387  numSupportedSignAlgos = arraysize(tlsSupportedSignAlgos);
388  }
389 
390  //Enumerate the hash/signature algorithm pairs in descending order of
391  //preference
392  n = 0;
393 
394  //Loop through the list of signature algorithms
395  for(i = 0; i < numSupportedSignAlgos; i++)
396  {
397  //Check whether the signature algorithm can be used in digital signature
398  if(tlsIsSignAlgoSupported(context, supportedSignAlgos[i]))
399  {
400  //Add the current signature algorithm to the list
401  signAlgoList->value[n++] = htons(supportedSignAlgos[i]);
402  }
403  }
404 
405  //Compute the length, in bytes, of the list
406  n *= sizeof(uint16_t);
407  //Fix the length of the list
408  signAlgoList->length = htons(n);
409 
410  //Total number of bytes that have been written
411  *written = n + sizeof(TlsSignSchemeList);
412 
413  //Successful processing
414  return NO_ERROR;
415 #else
416  //Not implemented
417  return FALSE;
418 #endif
419 }
420 
421 
422 /**
423  * @brief Check whether a signature algorithm is offered in the
424  * SignatureAlgorithms extension
425  * @param[in] signScheme Signature scheme
426  * @param[in] signSchemeList List of signature schemes
427  * @return TRUE if the signature algorithm is offered in the
428  * SignatureAlgorithms extension, else FALSE
429  **/
430 
431 bool_t tlsIsSignAlgoOffered(uint16_t signScheme,
432  const TlsSignSchemeList *signSchemeList)
433 {
434  uint_t i;
435  uint_t n;
436  bool_t found;
437 
438  //Initialize flag
439  found = FALSE;
440 
441  //Valid SignatureAlgorithms extension?
442  if(signSchemeList != NULL)
443  {
444  //Get the number of signature algorithms present in the list
445  n = ntohs(signSchemeList->length) / sizeof(uint16_t);
446 
447  //Loop through the list of signature algorithms offered in the
448  //SignatureAlgorithms extension
449  for(i = 0; i < n && !found; i++)
450  {
451  //Matching signature algorithm?
452  if(ntohs(signSchemeList->value[i]) == signScheme)
453  {
454  found = TRUE;
455  }
456  }
457  }
458 
459  //Return TRUE if the signature algorithm is offered in the
460  //SignatureAlgorithms extension
461  return found;
462 }
463 
464 
465 /**
466  * @brief Check whether a signature algorithm is compatible with the specified
467  * end-entity certificate
468  * @param[in] context Pointer to the TLS context
469  * @param[in] signScheme Signature scheme
470  * @param[in] cert End entity certificate
471  * @return TRUE if the signature algorithm is compatible, else FALSE
472  **/
473 
474 bool_t tlsIsSignAlgoAcceptable(TlsContext *context, uint16_t signScheme,
475  const TlsCertDesc *cert)
476 {
477  bool_t acceptable;
478 
479  //Initialize flag
480  acceptable = FALSE;
481 
482 #if (TLS_RSA_SIGN_SUPPORT == ENABLED)
483  //RSA certificate?
484  if(cert->type == TLS_CERT_RSA_SIGN)
485  {
486  //Check signature scheme
487  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_RSA)
488  {
489  //In TLS 1.3, RSASSA-PKCS1-v1_5 signature algorithms refer solely to
490  //signatures which appear in certificates and are not defined for use
491  //in signed TLS handshake messages
492  if(context->version <= TLS_VERSION_1_2)
493  {
494  acceptable = TRUE;
495  }
496  }
497  else if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256 ||
498  signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384 ||
500  {
501  //TLS 1.2 or TLS 1.3 currently selected?
502  if(context->version >= TLS_VERSION_1_2)
503  {
504  acceptable = TRUE;
505  }
506  }
507  else
508  {
509  //Just for sanity
510  }
511  }
512  else
513 #endif
514 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED)
515  //RSA-PSS certificate?
516  if(cert->type == TLS_CERT_RSA_PSS_SIGN)
517  {
518  //TLS 1.2 or TLS 1.3 currently selected?
519  if(context->version >= TLS_VERSION_1_2)
520  {
521  //Check signature scheme
522  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256 ||
523  signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384 ||
525  {
526  acceptable = TRUE;
527  }
528  }
529  }
530  else
531 #endif
532 #if (TLS_DSA_SIGN_SUPPORT == ENABLED)
533  //DSA certificate?
534  if(cert->type == TLS_CERT_DSS_SIGN)
535  {
536  //TLS 1.3 removes support for DSA certificates
537  if(context->version <= TLS_VERSION_1_2)
538  {
539  //Check signature scheme
540  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_DSA)
541  {
542  acceptable = TRUE;
543  }
544  }
545  }
546  else
547 #endif
548 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
549  //ECDSA certificate?
550  if(cert->type == TLS_CERT_ECDSA_SIGN)
551  {
552  //Version of TLS prior to TLS 1.3?
553  if(context->version <= TLS_VERSION_1_2)
554  {
555  //Check signature scheme
556  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_ECDSA)
557  {
558  acceptable = TRUE;
559  }
560  }
561  else
562  {
563  //Check signature scheme against elliptic curve
564  if(signScheme == TLS_SIGN_SCHEME_ECDSA_SECP256R1_SHA256 &&
566  {
567  acceptable = TRUE;
568  }
569  else if(signScheme == TLS_SIGN_SCHEME_ECDSA_SECP384R1_SHA384 &&
571  {
572  acceptable = TRUE;
573  }
574  else if(signScheme == TLS_SIGN_SCHEME_ECDSA_SECP521R1_SHA512 &&
576  {
577  acceptable = TRUE;
578  }
579  else if(signScheme == TLS_SIGN_SCHEME_ECDSA_BP256R1_TLS13_SHA256 &&
581  {
582  acceptable = TRUE;
583  }
584  else if(signScheme == TLS_SIGN_SCHEME_ECDSA_BP384R1_TLS13_SHA384 &&
586  {
587  acceptable = TRUE;
588  }
589  else if(signScheme == TLS_SIGN_SCHEME_ECDSA_BP512R1_TLS13_SHA512 &&
591  {
592  acceptable = TRUE;
593  }
594  else
595  {
596  }
597  }
598  }
599  else
600 #endif
601 #if (TLS_SM2_SIGN_SUPPORT == ENABLED)
602  //SM2 certificate?
603  if(cert->type == TLS_CERT_SM2_SIGN)
604  {
605  //TLS 1.3 currently selected?
606  if(context->version >= TLS_VERSION_1_3)
607  {
608  //Check signature scheme
609  if(signScheme == TLS_SIGN_SCHEME_SM2SIG_SM3)
610  {
611  acceptable = TRUE;
612  }
613  }
614  }
615  else
616 #endif
617 #if (TLS_ED25519_SIGN_SUPPORT == ENABLED)
618  //Ed25519 certificate?
619  if(cert->type == TLS_CERT_ED25519_SIGN)
620  {
621  //TLS 1.2 or TLS 1.3 currently selected?
622  if(context->version >= TLS_VERSION_1_2)
623  {
624  //Check signature scheme
625  if(signScheme == TLS_SIGN_SCHEME_ED25519)
626  {
627  acceptable = TRUE;
628  }
629  }
630  }
631  else
632 #endif
633 #if (TLS_ED448_SIGN_SUPPORT == ENABLED)
634  //Ed448 certificate?
635  if(cert->type == TLS_CERT_ED448_SIGN)
636  {
637  //TLS 1.2 or TLS 1.3 currently selected?
638  if(context->version >= TLS_VERSION_1_2)
639  {
640  //Check signature scheme
641  if(signScheme == TLS_SIGN_SCHEME_ED448)
642  {
643  acceptable = TRUE;
644  }
645  }
646  }
647  else
648 #endif
649  //Unsupported certificate type?
650  {
651  //Just for sanity
652  }
653 
654  //Return TRUE is the signature algorithm is compatible with the key in the
655  //end-entity certificate
656  return acceptable;
657 }
658 
659 
660 /**
661  * @brief Check whether a signature algorithm can be used for digital signatures
662  * @param[in] context Pointer to the TLS context
663  * @param[in] signScheme Signature scheme
664  * @return TRUE if the signature algorithm is supported, else FALSE
665  **/
666 
667 bool_t tlsIsSignAlgoSupported(TlsContext *context, uint16_t signScheme)
668 {
669 #if (TLS_MAX_VERSION >= TLS_VERSION_1_2 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
670  uint_t i;
671  uint_t cipherSuiteTypes;
672  TlsHashAlgo hashAlgoId;
673  const HashAlgo *hashAlgo;
674 
675  //Hash algorithm used by the signature scheme
676  hashAlgoId = TLS_HASH_ALGO_NONE;
677 
678  //Check TLS version
679  if(context->version <= TLS_VERSION_1_2)
680  {
681  //Check current state
682  if(context->state == TLS_STATE_CERTIFICATE_REQUEST ||
683  context->state == TLS_STATE_CLIENT_CERTIFICATE_VERIFY)
684  {
685  cipherSuiteTypes = TLS_CIPHER_SUITE_TYPE_RSA |
687  }
688  else
689  {
690  cipherSuiteTypes = context->cipherSuiteTypes;
691  }
692  }
693  else
694  {
695  cipherSuiteTypes = context->cipherSuiteTypes;
696  }
697 
698 #if (TLS_RSA_SIGN_SUPPORT == ENABLED)
699  //RSASSA-PKCS1-v1_5 signature algorithm?
700  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_RSA)
701  {
702  //Any RSA cipher suite proposed by the client?
703  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_RSA) != 0 ||
704  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
705  {
706  //Filter out hash algorithm
707  if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_MD5 ||
708  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA1 ||
709  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA224 ||
710  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA256 ||
711  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA384 ||
712  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA512)
713  {
714  //Check whether the hash algorithm is supported
715  if(tlsGetHashAlgo(TLS_HASH_ALGO(signScheme)) != NULL)
716  {
717  hashAlgoId = TLS_HASH_ALGO(signScheme);
718  }
719  }
720  }
721  }
722  else
723 #endif
724 #if (TLS_DSA_SIGN_SUPPORT == ENABLED)
725  //DSA signature algorithm?
726  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_DSA)
727  {
728  //Any DSA cipher suite proposed by the client?
729  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_DSA) != 0 ||
730  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
731  {
732  //Filter out hash algorithm
733  if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA1 ||
734  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA224 ||
735  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA256)
736  {
737  //Check whether the hash algorithm is supported
738  if(tlsGetHashAlgo(TLS_HASH_ALGO(signScheme)) != NULL)
739  {
740  hashAlgoId = TLS_HASH_ALGO(signScheme);
741  }
742  }
743  }
744  }
745  else
746 #endif
747 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
748  //ECDSA signature algorithm?
749  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_ECDSA)
750  {
751  //Any ECC cipher suite proposed by the client?
752  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_ECDSA) != 0 ||
753  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
754  {
755  //Filter out hash algorithm
756  if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA1 ||
757  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA224 ||
758  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA256 ||
759  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA384 ||
760  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA512)
761  {
762  //Check whether the hash algorithm is supported
763  if(tlsGetHashAlgo(TLS_HASH_ALGO(signScheme)) != NULL)
764  {
765  hashAlgoId = TLS_HASH_ALGO(signScheme);
766  }
767  }
768  }
769  }
770  else
771 #endif
772 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED && TLS_SHA256_SUPPORT == ENABLED)
773  //RSASSA-PSS RSAE signature algorithm with SHA-256?
774  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256)
775  {
776  //Any RSA cipher suite proposed by the client?
777  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_RSA) != 0 ||
778  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
779  {
780  hashAlgoId = TLS_HASH_ALGO_SHA256;
781  }
782  }
783  else
784 #endif
785 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED && TLS_SHA384_SUPPORT == ENABLED)
786  //RSASSA-PSS RSAE signature algorithm with SHA-384?
787  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384)
788  {
789  //Any RSA cipher suite proposed by the client?
790  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_RSA) != 0 ||
791  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
792  {
793  hashAlgoId = TLS_HASH_ALGO_SHA384;
794  }
795  }
796  else
797 #endif
798 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED && TLS_SHA512_SUPPORT == ENABLED)
799  //RSASSA-PSS RSAE signature algorithm with SHA-512?
800  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA512)
801  {
802  //Any RSA cipher suite proposed by the client?
803  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_RSA) != 0 ||
804  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
805  {
806  hashAlgoId = TLS_HASH_ALGO_SHA512;
807  }
808  }
809  else
810 #endif
811 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED && TLS_SHA256_SUPPORT == ENABLED)
812  //RSASSA-PSS PSS signature algorithm with SHA-256?
813  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256)
814  {
815  //Any RSA cipher suite proposed by the client?
816  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_RSA) != 0 ||
817  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
818  {
819  //Check whether the X.509 library can parse RSA-PSS certificates
821  {
822  hashAlgoId = TLS_HASH_ALGO_SHA256;
823  }
824  }
825  }
826  else
827 #endif
828 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED && TLS_SHA384_SUPPORT == ENABLED)
829  //RSASSA-PSS PSS signature algorithm with SHA-384?
830  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384)
831  {
832  //Any RSA cipher suite proposed by the client?
833  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_RSA) != 0 ||
834  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
835  {
836  //Check whether the X.509 library can parse RSA-PSS certificates
838  {
839  hashAlgoId = TLS_HASH_ALGO_SHA384;
840  }
841  }
842  }
843  else
844 #endif
845 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED && TLS_SHA512_SUPPORT == ENABLED)
846  //RSASSA-PSS PSS signature algorithm with SHA-512?
847  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA512)
848  {
849  //Any RSA cipher suite proposed by the client?
850  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_RSA) != 0 ||
851  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
852  {
853  //Check whether the X.509 library can parse RSA-PSS certificates
855  {
856  hashAlgoId = TLS_HASH_ALGO_SHA512;
857  }
858  }
859  }
860  else
861 #endif
862 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED && TLS_SHA256_SUPPORT == ENABLED && \
863  TLS_BRAINPOOLP256R1_SUPPORT == ENABLED)
864  //ECDSA signature algorithm with brainpoolP256 curve and SHA-256?
866  {
867  //Any TLS 1.3 cipher suite proposed by the client?
868  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
869  {
870  hashAlgoId = TLS_HASH_ALGO_SHA256;
871  }
872  }
873  else
874 #endif
875 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED && TLS_SHA384_SUPPORT == ENABLED && \
876  TLS_BRAINPOOLP384R1_SUPPORT == ENABLED)
877  //ECDSA signature algorithm with brainpoolP384 curve and SHA-384?
879  {
880  //Any TLS 1.3 cipher suite proposed by the client?
881  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
882  {
883  hashAlgoId = TLS_HASH_ALGO_SHA384;
884  }
885  }
886  else
887 #endif
888 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED && TLS_SHA512_SUPPORT == ENABLED && \
889  TLS_BRAINPOOLP512R1_SUPPORT == ENABLED)
890  //ECDSA signature algorithm with brainpoolP512 curve and SHA-512?
892  {
893  //Any TLS 1.3 cipher suite proposed by the client?
894  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
895  {
896  hashAlgoId = TLS_HASH_ALGO_SHA512;
897  }
898  }
899  else
900 #endif
901 #if (TLS_SM2_SIGN_SUPPORT == ENABLED)
902  //SM2 signature algorithm?
903  if(signScheme == TLS_SIGN_SCHEME_SM2SIG_SM3)
904  {
905  //Any ShangMi cipher suite proposed by the client?
906  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_SM) != 0)
907  {
908  hashAlgoId = TLS_HASH_ALGO_INTRINSIC;
909  }
910  }
911  else
912 #endif
913 #if (TLS_ED25519_SIGN_SUPPORT == ENABLED)
914  //Ed25519 signature algorithm?
915  if(signScheme == TLS_SIGN_SCHEME_ED25519)
916  {
917  //Any ECC cipher suite proposed by the client?
918  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_ECDSA) != 0 ||
919  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
920  {
921  hashAlgoId = TLS_HASH_ALGO_INTRINSIC;
922  }
923  }
924  else
925 #endif
926 #if (TLS_ED448_SIGN_SUPPORT == ENABLED)
927  //Ed448 signature algorithm?
928  if(signScheme == TLS_SIGN_SCHEME_ED448)
929  {
930  //Any ECC cipher suite proposed by the client?
931  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_ECDSA) != 0 ||
932  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
933  {
934  hashAlgoId = TLS_HASH_ALGO_INTRINSIC;
935  }
936  }
937  else
938 #endif
939  {
940  //Unknown signature algorithm
941  }
942 
943  //Check TLS version
944  if(context->version <= TLS_VERSION_1_2)
945  {
946  //Check current state
947  if(context->state == TLS_STATE_CERTIFICATE_REQUEST ||
948  context->state == TLS_STATE_CLIENT_CERTIFICATE_VERIFY)
949  {
950  //Get the hash algorithm that matches the specified identifier
951  hashAlgo = tlsGetHashAlgo(hashAlgoId);
952 
953  //Check whether the hash algorithm is supported
954  if(hashAlgo != NULL)
955  {
956  //In TLS versions prior to 1.3, the client implementation can only
957  //generate a CertificateVerify using SHA-1 or the hash used by
958  //the PRF. Supporting all hash algorithms would require the client
959  //to maintain hashes for every possible signature algorithm that
960  //the server may request...
961  if(hashAlgoId != TLS_HASH_ALGO_SHA1 &&
962  hashAlgo != context->cipherSuite.prfHashAlgo)
963  {
964  hashAlgoId = TLS_HASH_ALGO_NONE;
965  }
966  }
967  else
968  {
969  hashAlgoId = TLS_HASH_ALGO_NONE;
970  }
971  }
972  }
973 
974  //Restrict the use of certain signature algorithms
975  if(context->numSupportedSignAlgos > 0)
976  {
977  //Loop through the list of allowed signature algorithms
978  for(i = 0; i < context->numSupportedSignAlgos; i++)
979  {
980  //Compare signature schemes
981  if(context->supportedSignAlgos[i] == signScheme)
982  break;
983  }
984 
985  //Check whether the use of the signature algorithm is restricted
986  if(i >= context->numSupportedSignAlgos)
987  {
988  hashAlgoId = TLS_HASH_ALGO_NONE;
989  }
990  }
991 
992  //Return TRUE is the signature algorithm is supported
993  return (hashAlgoId != TLS_HASH_ALGO_NONE) ? TRUE : FALSE;
994 #else
995  //Not implemented
996  return FALSE;
997 #endif
998 }
999 
1000 
1001 /**
1002  * @brief Check whether a signature algorithm can be used for X.509
1003  * certificate validation
1004  * @param[in] signScheme Signature scheme
1005  * @return TRUE if the signature algorithm is supported, else FALSE
1006  **/
1007 
1009 {
1010  bool_t acceptable;
1011 
1012  //Check signature scheme
1013  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_RSA)
1014  {
1015  //Check whether RSA signature algorithm is supported
1017  {
1018  //Check hash algorithm
1019  if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_MD5)
1020  {
1021  //RSASSA-PKCS1-v1_5 signature algorithm with MD5
1023  }
1024  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA1)
1025  {
1026  //RSASSA-PKCS1-v1_5 signature algorithm with SHA-1
1028  }
1029  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA224)
1030  {
1031  //RSASSA-PKCS1-v1_5 signature algorithm with SHA-224
1033  }
1034  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA256)
1035  {
1036  //RSASSA-PKCS1-v1_5 signature algorithm with SHA-256
1038  }
1039  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA384)
1040  {
1041  //RSASSA-PKCS1-v1_5 signature algorithm with SHA-384
1043  }
1044  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA512)
1045  {
1046  //RSASSA-PKCS1-v1_5 signature algorithm with SHA-512
1048  }
1049  else
1050  {
1051  //Unknown hash algorithm
1052  acceptable = FALSE;
1053  }
1054  }
1055  else
1056  {
1057  //RSASSA-PKCS1-v1_5 signature algorithm is not supported
1058  acceptable = FALSE;
1059  }
1060  }
1061  else if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_DSA)
1062  {
1063  //Check whether DSA signature algorithm is supported
1065  {
1066  //Check hash algorithm
1067  if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA1)
1068  {
1069  //DSA signature algorithm with SHA-1
1071  }
1072  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA224)
1073  {
1074  //DSA signature algorithm with SHA-224
1076  }
1077  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA256)
1078  {
1079  //DSA signature algorithm with SHA-256
1081  }
1082  else
1083  {
1084  //Unknown hash algorithm
1085  acceptable = FALSE;
1086  }
1087  }
1088  else
1089  {
1090  //DSA signature algorithm is not supported
1091  acceptable = FALSE;
1092  }
1093  }
1094  else if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_ECDSA)
1095  {
1096  //Check whether ECDSA signature algorithm is supported
1098  {
1099  //Check hash algorithm
1100  if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA1)
1101  {
1102  //ECDSA signature algorithm with SHA-1
1104  }
1105  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA224)
1106  {
1107  //ECDSA signature algorithm with SHA-224
1109  }
1110  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA256)
1111  {
1112  //ECDSA signature algorithm with SHA-256
1114  }
1115  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA384)
1116  {
1117  //ECDSA signature algorithm with SHA-384
1119  }
1120  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA512)
1121  {
1122  //ECDSA signature algorithm with SHA-512
1124  }
1125  else
1126  {
1127  //Unknown hash algorithm
1128  acceptable = FALSE;
1129  }
1130  }
1131  else
1132  {
1133  //ECDSA signature algorithm is not supported
1134  acceptable = FALSE;
1135  }
1136  }
1137  else if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256 ||
1138  signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256)
1139  {
1140  //RSASSA-PSS signature algorithm with SHA-256
1143  }
1144  else if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384 ||
1145  signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384)
1146  {
1147  //RSASSA-PSS signature algorithm with SHA-384
1150  }
1151  else if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA512 ||
1152  signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA512)
1153  {
1154  //RSASSA-PSS signature algorithm with SHA-512
1157  }
1158 #if (EC_SUPPORT == ENABLED)
1159  else if(signScheme == TLS_SIGN_SCHEME_ECDSA_BP256R1_TLS13_SHA256)
1160  {
1161  //ECDSA signature algorithm with brainpoolP256 curve and SHA-256
1165  }
1166  else if(signScheme == TLS_SIGN_SCHEME_ECDSA_BP384R1_TLS13_SHA384)
1167  {
1168  //ECDSA signature algorithm with brainpoolP384 curve and SHA-384
1172  }
1173  else if(signScheme == TLS_SIGN_SCHEME_ECDSA_BP512R1_TLS13_SHA512)
1174  {
1175  //ECDSA signature algorithm with brainpoolP512 curve and SHA-512
1179  }
1180 #endif
1181  else if(signScheme == TLS_SIGN_SCHEME_SM2SIG_SM3)
1182  {
1183  //SM2 signature algorithm
1185  }
1186  else if(signScheme == TLS_SIGN_SCHEME_ED25519)
1187  {
1188  //Ed25519 signature algorithm (PureEdDSA mode)
1190  }
1191  else if(signScheme == TLS_SIGN_SCHEME_ED448)
1192  {
1193  //Ed448 signature algorithm (PureEdDSA mode)
1195  }
1196  else
1197  {
1198  //Unknown signature algorithm
1199  acceptable = FALSE;
1200  }
1201 
1202  //Return TRUE is the signature algorithm is supported
1203  return acceptable;
1204 }
1205 
1206 #endif
bool_t x509IsCurveSupported(const uint8_t *oid, size_t length)
Check whether a given elliptic curve is supported.
Definition: x509_common.c:354
#define htons(value)
Definition: cpu_endian.h:413
@ TLS_SIGN_ALGO_DSA
Definition: tls.h:1233
@ TLS_CIPHER_SUITE_TYPE_RSA
TLS helper functions.
@ TLS_SIGN_SCHEME_ECDSA_BP256R1_TLS13_SHA256
Definition: tls.h:1263
int bool_t
Definition: compiler_port.h:53
TLS cipher suites.
bool_t x509IsSignAlgoSupported(X509SignatureAlgo signAlgo)
Check whether a given signature algorithm is supported.
Definition: x509_common.c:175
const HashAlgo * tlsGetHashAlgo(TlsHashAlgo hashAlgoId)
Get the hash algorithm that matches the specified identifier.
Definition: tls_misc.c:1173
bool_t x509IsHashAlgoSupported(X509HashAlgo hashAlgo)
Check whether a given hash algorithm is supported.
Definition: x509_common.c:250
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256
Definition: tls.h:1253
bool_t tlsIsCertSignAlgoSupported(uint16_t signScheme)
Check whether a signature algorithm can be used for X.509 certificate validation.
uint8_t p
Definition: ndp.h:300
#define TRUE
Definition: os_port.h:50
@ TLS_STATE_CERTIFICATE_REQUEST
Definition: tls.h:1469
@ TLS_GROUP_SECP256R1
Definition: tls.h:1393
TlsCertificateType type
End entity certificate type.
Definition: tls.h:2087
const uint8_t BRAINPOOLP512R1_OID[9]
Definition: ec_curves.c:90
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA512
Definition: tls.h:1258
error_t tlsFormatSignAlgosExtension(TlsContext *context, uint8_t *p, size_t *written)
Format SignatureAlgorithms extension.
bool_t tlsIsSignAlgoAcceptable(TlsContext *context, uint16_t signScheme, const TlsCertDesc *cert)
Check whether a signature algorithm is compatible with the specified end-entity certificate.
@ TLS_HASH_ALGO_SHA1
Definition: tls.h:1215
TlsHashAlgo
Hash algorithms.
Definition: tls.h:1212
@ ERROR_HANDSHAKE_FAILED
Definition: error.h:233
const uint8_t BRAINPOOLP384R1_OID[9]
Definition: ec_curves.c:88
@ TLS_CERT_DSS_SIGN
Definition: tls.h:1189
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA512
Definition: tls.h:1255
@ TLS_SIGN_SCHEME_NONE
Definition: tls.h:1248
@ TLS_SIGN_SCHEME_ED25519
Definition: tls.h:1267
TlsExtension
Definition: tls.h:1573
@ TLS_GROUP_BRAINPOOLP256R1
Definition: tls.h:1396
#define TLS_HASH_ALGO(signScheme)
Definition: tls_sign_misc.h:41
@ TLS_CIPHER_SUITE_TYPE_TLS13
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384
Definition: tls.h:1257
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384
Definition: tls.h:1254
@ TLS_HASH_ALGO_NONE
Definition: tls.h:1213
@ TLS_CIPHER_SUITE_TYPE_SM
error_t tlsFormatSupportedSignAlgos(TlsContext *context, uint8_t *p, size_t *written)
Format the list of supported signature algorithms.
@ TLS_EXT_SIGNATURE_ALGORITHMS_CERT
Definition: tls.h:1328
@ TLS_HASH_ALGO_SHA224
Definition: tls.h:1216
@ TLS_CIPHER_SUITE_TYPE_ECDSA
@ TLS_HASH_ALGO_SHA512
Definition: tls.h:1219
@ TLS_SIGN_SCHEME_RSA_PKCS1_SHA1
Definition: tls.h:1249
#define FALSE
Definition: os_port.h:46
bool_t tlsIsSignAlgoSupported(TlsContext *context, uint16_t signScheme)
Check whether a signature algorithm can be used for digital signatures.
const uint16_t tlsSupportedSignAlgos[]
Definition: tls_sign_misc.c:45
#define TlsContext
Definition: tls.h:36
error_t
Error codes.
Definition: error.h:43
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256
Definition: tls.h:1256
@ TLS_SIGN_SCHEME_ECDSA_SECP521R1_SHA512
Definition: tls.h:1262
@ TLS_CERT_ED25519_SIGN
Definition: tls.h:1202
#define TLS_VERSION_1_2
Definition: tls.h:96
@ TLS_HASH_ALGO_INTRINSIC
Definition: tls.h:1220
@ X509_SIGN_ALGO_ECDSA
Definition: x509_common.h:609
#define TLS_VERSION_1_3
Definition: tls.h:97
@ TLS_HASH_ALGO_SHA384
Definition: tls.h:1218
@ TLS_CERT_RSA_PSS_SIGN
Definition: tls.h:1200
error_t tlsSelectSignAlgo(TlsContext *context, const TlsCertDesc *cert, const TlsSignSchemeList *signAlgoList)
Select the algorithm to be used when generating digital signatures.
Definition: tls_sign_misc.c:85
@ TLS_SIGN_SCHEME_ECDSA_SHA1
Definition: tls.h:1259
@ X509_HASH_ALGO_SHA1
Definition: x509_common.h:624
@ TLS_SIGN_SCHEME_RSA_PKCS1_SHA256
Definition: tls.h:1250
@ TLS_GROUP_SECP384R1
Definition: tls.h:1394
@ TLS_STATE_CLIENT_CERTIFICATE_VERIFY
Definition: tls.h:1473
@ TLS_SIGN_SCHEME_ECDSA_BP512R1_TLS13_SHA512
Definition: tls.h:1265
TlsSignSchemeList
Definition: tls.h:1539
@ TLS_HASH_ALGO_SHA256
Definition: tls.h:1217
@ TLS_CERT_ED448_SIGN
Definition: tls.h:1203
@ TLS_CERT_RSA_SIGN
Definition: tls.h:1188
@ X509_HASH_ALGO_SHA224
Definition: x509_common.h:625
@ TLS_GROUP_BRAINPOOLP512R1
Definition: tls.h:1398
@ TLS_CERT_SM2_SIGN
Definition: tls.h:1201
@ X509_SIGN_ALGO_RSA
Definition: x509_common.h:606
@ TLS_GROUP_SECP521R1
Definition: tls.h:1395
@ TLS_HASH_ALGO_MD5
Definition: tls.h:1214
Certificate descriptor.
Definition: tls.h:2081
#define ntohs(value)
Definition: cpu_endian.h:421
@ X509_HASH_ALGO_MD5
Definition: x509_common.h:623
#define TLS_VERSION_1_1
Definition: tls.h:95
bool_t tlsIsSignAlgoOffered(uint16_t signScheme, const TlsSignSchemeList *signSchemeList)
Check whether a signature algorithm is offered in the SignatureAlgorithms extension.
@ X509_SIGN_ALGO_RSA_PSS
Definition: x509_common.h:607
#define HTONS(value)
Definition: cpu_endian.h:410
uint8_t n
@ X509_HASH_ALGO_SHA512
Definition: x509_common.h:628
@ TLS_SIGN_SCHEME_SM2SIG_SM3
Definition: tls.h:1266
@ TLS_SIGN_SCHEME_RSA_PKCS1_SHA512
Definition: tls.h:1252
@ TLS_SIGN_SCHEME_ECDSA_BP384R1_TLS13_SHA384
Definition: tls.h:1264
@ TLS_SIGN_SCHEME_ED448
Definition: tls.h:1268
@ TLS_SIGN_SCHEME_RSA_PKCS1_SHA384
Definition: tls.h:1251
@ TLS_SIGN_SCHEME_ECDSA_SECP384R1_SHA384
Definition: tls.h:1261
Helper functions for signature generation and verification.
@ X509_HASH_ALGO_SHA384
Definition: x509_common.h:627
@ X509_HASH_ALGO_SHA256
Definition: x509_common.h:626
TLS (Transport Layer Security)
@ TLS_SIGN_ALGO_RSA
Definition: tls.h:1232
@ TLS_CERT_ECDSA_SIGN
Definition: tls.h:1195
@ TLS_EXT_SIGNATURE_ALGORITHMS
Definition: tls.h:1298
Common interface for hash algorithms.
Definition: crypto.h:1046
#define TLS_SIGN_ALGO(signScheme)
Definition: tls_sign_misc.h:38
@ TLS_SIGN_SCHEME_ECDSA_SECP256R1_SHA256
Definition: tls.h:1260
error_t tlsFormatSignAlgosCertExtension(TlsContext *context, uint8_t *p, size_t *written)
Format SignatureAlgorithmsCert extension.
@ X509_SIGN_ALGO_SM2
Definition: x509_common.h:610
TlsSignatureScheme
Signature schemes.
Definition: tls.h:1247
@ X509_SIGN_ALGO_ED25519
Definition: x509_common.h:611
unsigned int uint_t
Definition: compiler_port.h:50
@ TLS_CIPHER_SUITE_TYPE_DSA
@ TLS_SIGN_ALGO_ECDSA
Definition: tls.h:1234
#define TLS_SIGN_SCHEME(signAlgo, hashAlgo)
Definition: tls.h:941
TlsNamedGroup namedCurve
Named curve used to generate the EC public key.
Definition: tls.h:2089
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
@ TLS_GROUP_BRAINPOOLP384R1
Definition: tls.h:1397
@ X509_SIGN_ALGO_DSA
Definition: x509_common.h:608
#define arraysize(a)
Definition: os_port.h:71
@ X509_SIGN_ALGO_ED448
Definition: x509_common.h:612
const uint8_t BRAINPOOLP256R1_OID[9]
Definition: ec_curves.c:84