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.0
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  * @return TRUE if the signature algorithm is compatible, else FALSE
471  **/
472 
473 bool_t tlsIsSignAlgoAcceptable(TlsContext *context, uint16_t signScheme,
474  const TlsCertDesc *cert)
475 {
476  bool_t acceptable;
477 
478  //Initialize flag
479  acceptable = FALSE;
480 
481 #if (TLS_RSA_SIGN_SUPPORT == ENABLED)
482  //RSA certificate?
483  if(cert->type == TLS_CERT_RSA_SIGN)
484  {
485  //Check signature scheme
486  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_RSA)
487  {
488  //In TLS 1.3, RSASSA-PKCS1-v1_5 signature algorithms refer solely to
489  //signatures which appear in certificates and are not defined for use
490  //in signed TLS handshake messages
491  if(context->version <= TLS_VERSION_1_2)
492  {
493  acceptable = TRUE;
494  }
495  }
496  else if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256 ||
497  signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384 ||
499  {
500  //TLS 1.2 or TLS 1.3 currently selected?
501  if(context->version >= TLS_VERSION_1_2)
502  {
503  acceptable = TRUE;
504  }
505  }
506  else
507  {
508  //Just for sanity
509  }
510  }
511  else
512 #endif
513 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED)
514  //RSA-PSS certificate?
515  if(cert->type == TLS_CERT_RSA_PSS_SIGN)
516  {
517  //TLS 1.2 or TLS 1.3 currently selected?
518  if(context->version >= TLS_VERSION_1_2)
519  {
520  //Check signature scheme
521  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256 ||
522  signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384 ||
524  {
525  acceptable = TRUE;
526  }
527  }
528  }
529  else
530 #endif
531 #if (TLS_DSA_SIGN_SUPPORT == ENABLED)
532  //DSA certificate?
533  if(cert->type == TLS_CERT_DSS_SIGN)
534  {
535  //TLS 1.3 removes support for DSA certificates
536  if(context->version <= TLS_VERSION_1_2)
537  {
538  //Check signature scheme
539  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_DSA)
540  {
541  acceptable = TRUE;
542  }
543  }
544  }
545  else
546 #endif
547 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
548  //ECDSA certificate?
549  if(cert->type == TLS_CERT_ECDSA_SIGN)
550  {
551  //Version of TLS prior to TLS 1.3?
552  if(context->version <= TLS_VERSION_1_2)
553  {
554  //Check signature scheme
555  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_ECDSA)
556  {
557  acceptable = TRUE;
558  }
559  }
560  else
561  {
562  //Check signature scheme against elliptic curve
563  if(signScheme == TLS_SIGN_SCHEME_ECDSA_SECP256R1_SHA256 &&
565  {
566  acceptable = TRUE;
567  }
568  else if(signScheme == TLS_SIGN_SCHEME_ECDSA_SECP384R1_SHA384 &&
570  {
571  acceptable = TRUE;
572  }
573  else if(signScheme == TLS_SIGN_SCHEME_ECDSA_SECP521R1_SHA512 &&
575  {
576  acceptable = TRUE;
577  }
578  else if(signScheme == TLS_SIGN_SCHEME_ECDSA_BP256R1_TLS13_SHA256 &&
580  {
581  acceptable = TRUE;
582  }
583  else if(signScheme == TLS_SIGN_SCHEME_ECDSA_BP384R1_TLS13_SHA384 &&
585  {
586  acceptable = TRUE;
587  }
588  else if(signScheme == TLS_SIGN_SCHEME_ECDSA_BP512R1_TLS13_SHA512 &&
590  {
591  acceptable = TRUE;
592  }
593  else
594  {
595  }
596  }
597  }
598  else
599 #endif
600 #if (TLS_SM2_SIGN_SUPPORT == ENABLED)
601  //SM2 certificate?
602  if(cert->type == TLS_CERT_SM2_SIGN)
603  {
604  //TLS 1.3 currently selected?
605  if(context->version >= TLS_VERSION_1_3)
606  {
607  //Check signature scheme
608  if(signScheme == TLS_SIGN_SCHEME_SM2SIG_SM3)
609  {
610  acceptable = TRUE;
611  }
612  }
613  }
614  else
615 #endif
616 #if (TLS_ED25519_SIGN_SUPPORT == ENABLED)
617  //Ed25519 certificate?
618  if(cert->type == TLS_CERT_ED25519_SIGN)
619  {
620  //TLS 1.2 or TLS 1.3 currently selected?
621  if(context->version >= TLS_VERSION_1_2)
622  {
623  //Check signature scheme
624  if(signScheme == TLS_SIGN_SCHEME_ED25519)
625  {
626  acceptable = TRUE;
627  }
628  }
629  }
630  else
631 #endif
632 #if (TLS_ED448_SIGN_SUPPORT == ENABLED)
633  //Ed448 certificate?
634  if(cert->type == TLS_CERT_ED448_SIGN)
635  {
636  //TLS 1.2 or TLS 1.3 currently selected?
637  if(context->version >= TLS_VERSION_1_2)
638  {
639  //Check signature scheme
640  if(signScheme == TLS_SIGN_SCHEME_ED448)
641  {
642  acceptable = TRUE;
643  }
644  }
645  }
646  else
647 #endif
648  //Unsupported certificate type?
649  {
650  //Just for sanity
651  }
652 
653  //Return TRUE is the signature algorithm is compatible with the key in the
654  //end-entity certificate
655  return acceptable;
656 }
657 
658 
659 /**
660  * @brief Check whether a signature algorithm can be used for digital signatures
661  * @param[in] context Pointer to the TLS context
662  * @param[in] signScheme Signature scheme
663  * @return TRUE if the signature algorithm is supported, else FALSE
664  **/
665 
666 bool_t tlsIsSignAlgoSupported(TlsContext *context, uint16_t signScheme)
667 {
668 #if (TLS_MAX_VERSION >= TLS_VERSION_1_2 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
669  uint_t i;
670  uint_t cipherSuiteTypes;
671  TlsHashAlgo hashAlgoId;
672  const HashAlgo *hashAlgo;
673 
674  //Hash algorithm used by the signature scheme
675  hashAlgoId = TLS_HASH_ALGO_NONE;
676 
677  //Check TLS version
678  if(context->version <= TLS_VERSION_1_2)
679  {
680  //Check current state
681  if(context->state == TLS_STATE_CERTIFICATE_REQUEST ||
682  context->state == TLS_STATE_CLIENT_CERTIFICATE_VERIFY)
683  {
684  cipherSuiteTypes = TLS_CIPHER_SUITE_TYPE_RSA |
686  }
687  else
688  {
689  cipherSuiteTypes = context->cipherSuiteTypes;
690  }
691  }
692  else
693  {
694  cipherSuiteTypes = context->cipherSuiteTypes;
695  }
696 
697 #if (TLS_RSA_SIGN_SUPPORT == ENABLED)
698  //RSASSA-PKCS1-v1_5 signature algorithm?
699  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_RSA)
700  {
701  //Any RSA cipher suite proposed by the client?
702  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_RSA) != 0 ||
703  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
704  {
705  //Filter out hash algorithm
706  if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_MD5 ||
707  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA1 ||
708  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA224 ||
709  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA256 ||
710  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA384 ||
711  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA512)
712  {
713  //Check whether the hash algorithm is supported
714  if(tlsGetHashAlgo(TLS_HASH_ALGO(signScheme)) != NULL)
715  {
716  hashAlgoId = TLS_HASH_ALGO(signScheme);
717  }
718  }
719  }
720  }
721  else
722 #endif
723 #if (TLS_DSA_SIGN_SUPPORT == ENABLED)
724  //DSA signature algorithm?
725  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_DSA)
726  {
727  //Any DSA cipher suite proposed by the client?
728  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_DSA) != 0 ||
729  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
730  {
731  //Filter out hash algorithm
732  if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA1 ||
733  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA224 ||
734  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA256)
735  {
736  //Check whether the hash algorithm is supported
737  if(tlsGetHashAlgo(TLS_HASH_ALGO(signScheme)) != NULL)
738  {
739  hashAlgoId = TLS_HASH_ALGO(signScheme);
740  }
741  }
742  }
743  }
744  else
745 #endif
746 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
747  //ECDSA signature algorithm?
748  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_ECDSA)
749  {
750  //Any ECC cipher suite proposed by the client?
751  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_ECDSA) != 0 ||
752  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
753  {
754  //Filter out hash algorithm
755  if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA1 ||
756  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA224 ||
757  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA256 ||
758  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA384 ||
759  TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA512)
760  {
761  //Check whether the hash algorithm is supported
762  if(tlsGetHashAlgo(TLS_HASH_ALGO(signScheme)) != NULL)
763  {
764  hashAlgoId = TLS_HASH_ALGO(signScheme);
765  }
766  }
767  }
768  }
769  else
770 #endif
771 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED && TLS_SHA256_SUPPORT == ENABLED)
772  //RSASSA-PSS RSAE signature algorithm with SHA-256?
773  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256)
774  {
775  //Any RSA cipher suite proposed by the client?
776  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_RSA) != 0 ||
777  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
778  {
779  hashAlgoId = TLS_HASH_ALGO_SHA256;
780  }
781  }
782  else
783 #endif
784 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED && TLS_SHA384_SUPPORT == ENABLED)
785  //RSASSA-PSS RSAE signature algorithm with SHA-384?
786  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384)
787  {
788  //Any RSA cipher suite proposed by the client?
789  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_RSA) != 0 ||
790  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
791  {
792  hashAlgoId = TLS_HASH_ALGO_SHA384;
793  }
794  }
795  else
796 #endif
797 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED && TLS_SHA512_SUPPORT == ENABLED)
798  //RSASSA-PSS RSAE signature algorithm with SHA-512?
799  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA512)
800  {
801  //Any RSA cipher suite proposed by the client?
802  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_RSA) != 0 ||
803  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
804  {
805  hashAlgoId = TLS_HASH_ALGO_SHA512;
806  }
807  }
808  else
809 #endif
810 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED && TLS_SHA256_SUPPORT == ENABLED)
811  //RSASSA-PSS PSS signature algorithm with SHA-256?
812  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256)
813  {
814  //Any RSA cipher suite proposed by the client?
815  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_RSA) != 0 ||
816  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
817  {
818  //Check whether the X.509 library can parse RSA-PSS certificates
820  {
821  hashAlgoId = TLS_HASH_ALGO_SHA256;
822  }
823  }
824  }
825  else
826 #endif
827 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED && TLS_SHA384_SUPPORT == ENABLED)
828  //RSASSA-PSS PSS signature algorithm with SHA-384?
829  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384)
830  {
831  //Any RSA cipher suite proposed by the client?
832  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_RSA) != 0 ||
833  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
834  {
835  //Check whether the X.509 library can parse RSA-PSS certificates
837  {
838  hashAlgoId = TLS_HASH_ALGO_SHA384;
839  }
840  }
841  }
842  else
843 #endif
844 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED && TLS_SHA512_SUPPORT == ENABLED)
845  //RSASSA-PSS PSS signature algorithm with SHA-512?
846  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA512)
847  {
848  //Any RSA cipher suite proposed by the client?
849  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_RSA) != 0 ||
850  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
851  {
852  //Check whether the X.509 library can parse RSA-PSS certificates
854  {
855  hashAlgoId = TLS_HASH_ALGO_SHA512;
856  }
857  }
858  }
859  else
860 #endif
861 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED && TLS_SHA256_SUPPORT == ENABLED && \
862  TLS_BRAINPOOLP256R1_SUPPORT == ENABLED)
863  //ECDSA signature algorithm with brainpoolP256 curve and SHA-256?
865  {
866  //Any TLS 1.3 cipher suite proposed by the client?
867  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
868  {
869  hashAlgoId = TLS_HASH_ALGO_SHA256;
870  }
871  }
872  else
873 #endif
874 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED && TLS_SHA384_SUPPORT == ENABLED && \
875  TLS_BRAINPOOLP384R1_SUPPORT == ENABLED)
876  //ECDSA signature algorithm with brainpoolP384 curve and SHA-384?
878  {
879  //Any TLS 1.3 cipher suite proposed by the client?
880  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
881  {
882  hashAlgoId = TLS_HASH_ALGO_SHA384;
883  }
884  }
885  else
886 #endif
887 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED && TLS_SHA512_SUPPORT == ENABLED && \
888  TLS_BRAINPOOLP512R1_SUPPORT == ENABLED)
889  //ECDSA signature algorithm with brainpoolP512 curve and SHA-512?
891  {
892  //Any TLS 1.3 cipher suite proposed by the client?
893  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
894  {
895  hashAlgoId = TLS_HASH_ALGO_SHA512;
896  }
897  }
898  else
899 #endif
900 #if (TLS_SM2_SIGN_SUPPORT == ENABLED)
901  //SM2 signature algorithm?
902  if(signScheme == TLS_SIGN_SCHEME_SM2SIG_SM3)
903  {
904  //Any ShangMi cipher suite proposed by the client?
905  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_SM) != 0)
906  {
907  hashAlgoId = TLS_HASH_ALGO_INTRINSIC;
908  }
909  }
910  else
911 #endif
912 #if (TLS_ED25519_SIGN_SUPPORT == ENABLED)
913  //Ed25519 signature algorithm?
914  if(signScheme == TLS_SIGN_SCHEME_ED25519)
915  {
916  //Any ECC cipher suite proposed by the client?
917  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_ECDSA) != 0 ||
918  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
919  {
920  hashAlgoId = TLS_HASH_ALGO_INTRINSIC;
921  }
922  }
923  else
924 #endif
925 #if (TLS_ED448_SIGN_SUPPORT == ENABLED)
926  //Ed448 signature algorithm?
927  if(signScheme == TLS_SIGN_SCHEME_ED448)
928  {
929  //Any ECC cipher suite proposed by the client?
930  if((cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_ECDSA) != 0 ||
931  (cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_TLS13) != 0)
932  {
933  hashAlgoId = TLS_HASH_ALGO_INTRINSIC;
934  }
935  }
936  else
937 #endif
938  {
939  //Unknown signature algorithm
940  }
941 
942  //Check TLS version
943  if(context->version <= TLS_VERSION_1_2)
944  {
945  //Check current state
946  if(context->state == TLS_STATE_CERTIFICATE_REQUEST ||
947  context->state == TLS_STATE_CLIENT_CERTIFICATE_VERIFY)
948  {
949  //Get the hash algorithm that matches the specified identifier
950  hashAlgo = tlsGetHashAlgo(hashAlgoId);
951 
952  //Check whether the hash algorithm is supported
953  if(hashAlgo != NULL)
954  {
955  //In TLS versions prior to 1.3, the client implementation can only
956  //generate a CertificateVerify using SHA-1 or the hash used by
957  //the PRF. Supporting all hash algorithms would require the client
958  //to maintain hashes for every possible signature algorithm that
959  //the server may request...
960  if(hashAlgoId != TLS_HASH_ALGO_SHA1 &&
961  hashAlgo != context->cipherSuite.prfHashAlgo)
962  {
963  hashAlgoId = TLS_HASH_ALGO_NONE;
964  }
965  }
966  else
967  {
968  hashAlgoId = TLS_HASH_ALGO_NONE;
969  }
970  }
971  }
972 
973  //Restrict the use of certain signature algorithms
974  if(context->numSupportedSignAlgos > 0)
975  {
976  //Loop through the list of allowed signature algorithms
977  for(i = 0; i < context->numSupportedSignAlgos; i++)
978  {
979  //Compare signature schemes
980  if(context->supportedSignAlgos[i] == signScheme)
981  break;
982  }
983 
984  //Check whether the use of the signature algorithm is restricted
985  if(i >= context->numSupportedSignAlgos)
986  {
987  hashAlgoId = TLS_HASH_ALGO_NONE;
988  }
989  }
990 
991  //Return TRUE is the signature algorithm is supported
992  return (hashAlgoId != TLS_HASH_ALGO_NONE) ? TRUE : FALSE;
993 #else
994  //Not implemented
995  return FALSE;
996 #endif
997 }
998 
999 
1000 /**
1001  * @brief Check whether a signature algorithm can be used for X.509
1002  * certificate validation
1003  * @param[in] signScheme Signature scheme
1004  * @return TRUE if the signature algorithm is supported, else FALSE
1005  **/
1006 
1008 {
1009  bool_t acceptable;
1010 
1011  //Check signature scheme
1012  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_RSA)
1013  {
1014  //Check whether RSA signature algorithm is supported
1016  {
1017  //Check hash algorithm
1018  if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_MD5)
1019  {
1020  //RSASSA-PKCS1-v1_5 signature algorithm with MD5
1022  }
1023  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA1)
1024  {
1025  //RSASSA-PKCS1-v1_5 signature algorithm with SHA-1
1027  }
1028  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA224)
1029  {
1030  //RSASSA-PKCS1-v1_5 signature algorithm with SHA-224
1032  }
1033  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA256)
1034  {
1035  //RSASSA-PKCS1-v1_5 signature algorithm with SHA-256
1037  }
1038  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA384)
1039  {
1040  //RSASSA-PKCS1-v1_5 signature algorithm with SHA-384
1042  }
1043  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA512)
1044  {
1045  //RSASSA-PKCS1-v1_5 signature algorithm with SHA-512
1047  }
1048  else
1049  {
1050  //Unknown hash algorithm
1051  acceptable = FALSE;
1052  }
1053  }
1054  else
1055  {
1056  //RSASSA-PKCS1-v1_5 signature algorithm is not supported
1057  acceptable = FALSE;
1058  }
1059  }
1060  else if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_DSA)
1061  {
1062  //Check whether DSA signature algorithm is supported
1064  {
1065  //Check hash algorithm
1066  if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA1)
1067  {
1068  //DSA signature algorithm with SHA-1
1070  }
1071  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA224)
1072  {
1073  //DSA signature algorithm with SHA-224
1075  }
1076  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA256)
1077  {
1078  //DSA signature algorithm with SHA-256
1080  }
1081  else
1082  {
1083  //Unknown hash algorithm
1084  acceptable = FALSE;
1085  }
1086  }
1087  else
1088  {
1089  //DSA signature algorithm is not supported
1090  acceptable = FALSE;
1091  }
1092  }
1093  else if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_ECDSA)
1094  {
1095  //Check whether ECDSA signature algorithm is supported
1097  {
1098  //Check hash algorithm
1099  if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA1)
1100  {
1101  //ECDSA signature algorithm with SHA-1
1103  }
1104  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA224)
1105  {
1106  //ECDSA signature algorithm with SHA-224
1108  }
1109  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA256)
1110  {
1111  //ECDSA signature algorithm with SHA-256
1113  }
1114  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA384)
1115  {
1116  //ECDSA signature algorithm with SHA-384
1118  }
1119  else if(TLS_HASH_ALGO(signScheme) == TLS_HASH_ALGO_SHA512)
1120  {
1121  //ECDSA signature algorithm with SHA-512
1123  }
1124  else
1125  {
1126  //Unknown hash algorithm
1127  acceptable = FALSE;
1128  }
1129  }
1130  else
1131  {
1132  //ECDSA signature algorithm is not supported
1133  acceptable = FALSE;
1134  }
1135  }
1136  else if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256 ||
1137  signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256)
1138  {
1139  //RSASSA-PSS signature algorithm with SHA-256
1142  }
1143  else if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384 ||
1144  signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384)
1145  {
1146  //RSASSA-PSS signature algorithm with SHA-384
1149  }
1150  else if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA512 ||
1151  signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA512)
1152  {
1153  //RSASSA-PSS signature algorithm with SHA-512
1156  }
1157 #if (EC_SUPPORT == ENABLED)
1158  else if(signScheme == TLS_SIGN_SCHEME_ECDSA_BP256R1_TLS13_SHA256)
1159  {
1160  //ECDSA signature algorithm with brainpoolP256 curve and SHA-256
1164  }
1165  else if(signScheme == TLS_SIGN_SCHEME_ECDSA_BP384R1_TLS13_SHA384)
1166  {
1167  //ECDSA signature algorithm with brainpoolP384 curve and SHA-384
1171  }
1172  else if(signScheme == TLS_SIGN_SCHEME_ECDSA_BP512R1_TLS13_SHA512)
1173  {
1174  //ECDSA signature algorithm with brainpoolP512 curve and SHA-512
1178  }
1179 #endif
1180  else if(signScheme == TLS_SIGN_SCHEME_SM2SIG_SM3)
1181  {
1182  //SM2 signature algorithm
1184  }
1185  else if(signScheme == TLS_SIGN_SCHEME_ED25519)
1186  {
1187  //Ed25519 signature algorithm (PureEdDSA mode)
1189  }
1190  else if(signScheme == TLS_SIGN_SCHEME_ED448)
1191  {
1192  //Ed448 signature algorithm (PureEdDSA mode)
1194  }
1195  else
1196  {
1197  //Unknown signature algorithm
1198  acceptable = FALSE;
1199  }
1200 
1201  //Return TRUE is the signature algorithm is supported
1202  return acceptable;
1203 }
1204 
1205 #endif
unsigned int uint_t
Definition: compiler_port.h:50
int bool_t
Definition: compiler_port.h:53
#define HTONS(value)
Definition: cpu_endian.h:410
#define htons(value)
Definition: cpu_endian.h:413
#define ntohs(value)
Definition: cpu_endian.h:421
Debugging facilities.
uint8_t n
const uint8_t BRAINPOOLP512R1_OID[9]
Definition: ec_curves.c:90
const uint8_t BRAINPOOLP256R1_OID[9]
Definition: ec_curves.c:84
const uint8_t BRAINPOOLP384R1_OID[9]
Definition: ec_curves.c:88
error_t
Error codes.
Definition: error.h:43
@ ERROR_HANDSHAKE_FAILED
Definition: error.h:232
@ NO_ERROR
Success.
Definition: error.h:44
uint8_t p
Definition: ndp.h:300
#define arraysize(a)
Definition: os_port.h:71
#define TRUE
Definition: os_port.h:50
#define FALSE
Definition: os_port.h:46
Common interface for hash algorithms.
Definition: crypto.h:1014
Certificate descriptor.
Definition: tls.h:2064
TlsNamedGroup namedCurve
Named curve used to generate the EC public key.
Definition: tls.h:2072
TlsCertificateType type
End entity certificate type.
Definition: tls.h:2070
TLS (Transport Layer Security)
@ TLS_STATE_CLIENT_CERTIFICATE_VERIFY
Definition: tls.h:1456
@ TLS_STATE_CERTIFICATE_REQUEST
Definition: tls.h:1452
#define TLS_SIGN_SCHEME(signAlgo, hashAlgo)
Definition: tls.h:926
TlsExtension
Definition: tls.h:1556
TlsSignatureScheme
Signature schemes.
Definition: tls.h:1230
@ TLS_SIGN_SCHEME_ECDSA_SHA1
Definition: tls.h:1242
@ TLS_SIGN_SCHEME_ECDSA_BP384R1_TLS13_SHA384
Definition: tls.h:1247
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256
Definition: tls.h:1239
@ TLS_SIGN_SCHEME_ECDSA_SECP521R1_SHA512
Definition: tls.h:1245
@ TLS_SIGN_SCHEME_ECDSA_SECP384R1_SHA384
Definition: tls.h:1244
@ TLS_SIGN_SCHEME_RSA_PKCS1_SHA512
Definition: tls.h:1235
@ TLS_SIGN_SCHEME_ECDSA_BP256R1_TLS13_SHA256
Definition: tls.h:1246
@ TLS_SIGN_SCHEME_RSA_PKCS1_SHA384
Definition: tls.h:1234
@ TLS_SIGN_SCHEME_RSA_PKCS1_SHA1
Definition: tls.h:1232
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384
Definition: tls.h:1237
@ TLS_SIGN_SCHEME_RSA_PKCS1_SHA256
Definition: tls.h:1233
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA512
Definition: tls.h:1238
@ TLS_SIGN_SCHEME_ECDSA_SECP256R1_SHA256
Definition: tls.h:1243
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384
Definition: tls.h:1240
@ TLS_SIGN_SCHEME_SM2SIG_SM3
Definition: tls.h:1249
@ TLS_SIGN_SCHEME_ED25519
Definition: tls.h:1250
@ TLS_SIGN_SCHEME_ED448
Definition: tls.h:1251
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA512
Definition: tls.h:1241
@ TLS_SIGN_SCHEME_NONE
Definition: tls.h:1231
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256
Definition: tls.h:1236
@ TLS_SIGN_SCHEME_ECDSA_BP512R1_TLS13_SHA512
Definition: tls.h:1248
@ TLS_EXT_SIGNATURE_ALGORITHMS_CERT
Definition: tls.h:1311
@ TLS_EXT_SIGNATURE_ALGORITHMS
Definition: tls.h:1281
TlsHashAlgo
Hash algorithms.
Definition: tls.h:1195
@ TLS_HASH_ALGO_SHA224
Definition: tls.h:1199
@ TLS_HASH_ALGO_SHA384
Definition: tls.h:1201
@ TLS_HASH_ALGO_NONE
Definition: tls.h:1196
@ TLS_HASH_ALGO_SHA256
Definition: tls.h:1200
@ TLS_HASH_ALGO_SHA512
Definition: tls.h:1202
@ TLS_HASH_ALGO_MD5
Definition: tls.h:1197
@ TLS_HASH_ALGO_INTRINSIC
Definition: tls.h:1203
@ TLS_HASH_ALGO_SHA1
Definition: tls.h:1198
@ TLS_CERT_ED448_SIGN
Definition: tls.h:1186
@ TLS_CERT_RSA_SIGN
Definition: tls.h:1171
@ TLS_CERT_SM2_SIGN
Definition: tls.h:1184
@ TLS_CERT_DSS_SIGN
Definition: tls.h:1172
@ TLS_CERT_ED25519_SIGN
Definition: tls.h:1185
@ TLS_CERT_RSA_PSS_SIGN
Definition: tls.h:1183
@ TLS_CERT_ECDSA_SIGN
Definition: tls.h:1178
#define TLS_VERSION_1_1
Definition: tls.h:95
TlsSignSchemeList
Definition: tls.h:1522
#define TLS_VERSION_1_3
Definition: tls.h:97
@ TLS_SIGN_ALGO_ECDSA
Definition: tls.h:1217
@ TLS_SIGN_ALGO_RSA
Definition: tls.h:1215
@ TLS_SIGN_ALGO_DSA
Definition: tls.h:1216
#define TlsContext
Definition: tls.h:36
@ TLS_GROUP_SECP521R1
Definition: tls.h:1378
@ TLS_GROUP_SECP256R1
Definition: tls.h:1376
@ TLS_GROUP_SECP384R1
Definition: tls.h:1377
@ TLS_GROUP_BRAINPOOLP512R1
Definition: tls.h:1381
@ TLS_GROUP_BRAINPOOLP256R1
Definition: tls.h:1379
@ TLS_GROUP_BRAINPOOLP384R1
Definition: tls.h:1380
#define TLS_VERSION_1_2
Definition: tls.h:96
TLS cipher suites.
@ TLS_CIPHER_SUITE_TYPE_RSA
@ TLS_CIPHER_SUITE_TYPE_DSA
@ TLS_CIPHER_SUITE_TYPE_TLS13
@ TLS_CIPHER_SUITE_TYPE_SM
@ TLS_CIPHER_SUITE_TYPE_ECDSA
const HashAlgo * tlsGetHashAlgo(TlsHashAlgo hashAlgoId)
Get the hash algorithm that matches the specified identifier.
Definition: tls_misc.c:1173
TLS helper functions.
error_t tlsFormatSignAlgosCertExtension(TlsContext *context, uint8_t *p, size_t *written)
Format SignatureAlgorithmsCert extension.
error_t tlsFormatSupportedSignAlgos(TlsContext *context, uint8_t *p, size_t *written)
Format the list of supported signature algorithms.
bool_t tlsIsSignAlgoOffered(uint16_t signScheme, const TlsSignSchemeList *signSchemeList)
Check whether a signature algorithm is offered in the 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.
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
const uint16_t tlsSupportedSignAlgos[]
Definition: tls_sign_misc.c:45
bool_t tlsIsSignAlgoSupported(TlsContext *context, uint16_t signScheme)
Check whether a signature algorithm can be used for digital signatures.
error_t tlsFormatSignAlgosExtension(TlsContext *context, uint8_t *p, size_t *written)
Format SignatureAlgorithms extension.
bool_t tlsIsCertSignAlgoSupported(uint16_t signScheme)
Check whether a signature algorithm can be used for X.509 certificate validation.
Helper functions for signature generation and verification.
#define TLS_HASH_ALGO(signScheme)
Definition: tls_sign_misc.h:41
#define TLS_SIGN_ALGO(signScheme)
Definition: tls_sign_misc.h:38
bool_t x509IsSignAlgoSupported(X509SignatureAlgo signAlgo)
Check whether a given signature algorithm is supported.
Definition: x509_common.c:175
bool_t x509IsCurveSupported(const uint8_t *oid, size_t length)
Check whether a given elliptic curve is supported.
Definition: x509_common.c:354
bool_t x509IsHashAlgoSupported(X509HashAlgo hashAlgo)
Check whether a given hash algorithm is supported.
Definition: x509_common.c:250
@ X509_HASH_ALGO_SHA256
Definition: x509_common.h:619
@ X509_HASH_ALGO_MD5
Definition: x509_common.h:616
@ X509_HASH_ALGO_SHA512
Definition: x509_common.h:621
@ X509_HASH_ALGO_SHA224
Definition: x509_common.h:618
@ X509_HASH_ALGO_SHA384
Definition: x509_common.h:620
@ X509_HASH_ALGO_SHA1
Definition: x509_common.h:617
@ X509_SIGN_ALGO_ED448
Definition: x509_common.h:605
@ X509_SIGN_ALGO_ED25519
Definition: x509_common.h:604
@ X509_SIGN_ALGO_SM2
Definition: x509_common.h:603
@ X509_SIGN_ALGO_RSA
Definition: x509_common.h:599
@ X509_SIGN_ALGO_DSA
Definition: x509_common.h:601
@ X509_SIGN_ALGO_ECDSA
Definition: x509_common.h:602
@ X509_SIGN_ALGO_RSA_PSS
Definition: x509_common.h:600