tls13_signature.c
Go to the documentation of this file.
1 /**
2  * @file tls13_signature.c
3  * @brief RSA/DSA/ECDSA/EdDSA signature generation and verification
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2023 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.3.2
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_signature.h"
37 #include "tls_transcript_hash.h"
38 #include "tls_misc.h"
39 #include "tls13_signature.h"
40 #include "pkix/pem_import.h"
41 #include "debug.h"
42 
43 //Check TLS library configuration
44 #if (TLS_SUPPORT == ENABLED && TLS_MAX_VERSION >= TLS_VERSION_1_3)
45 
46 
47 /**
48  * @brief Digital signature generation (TLS 1.3)
49  * @param[in] context Pointer to the TLS context
50  * @param[out] p Buffer where to store the digitally-signed element
51  * @param[out] length Length of the digitally-signed element
52  * @return Error code
53  **/
54 
56  size_t *length)
57 {
58  error_t error;
59  size_t n;
60  uint8_t *buffer;
62  const HashAlgo *hashAlgo;
63 
64  //Point to the digitally-signed element
66 
67  //The hash function used by HKDF is the cipher suite hash algorithm
68  hashAlgo = context->cipherSuite.prfHashAlgo;
69  //Make sure the hash algorithm is valid
70  if(hashAlgo == NULL)
71  return ERROR_FAILURE;
72 
73  //Calculate the length of the content covered by the digital signature
74  n = hashAlgo->digestSize + 98;
75 
76  //Allocate a memory buffer
77  buffer = tlsAllocMem(n);
78 
79  //Successful memory allocation?
80  if(buffer != NULL)
81  {
82  //Form a string that consists of octet 32 (0x20) repeated 64 times
83  osMemset(buffer, ' ', 64);
84 
85  //Append the context string. It is used to provide separation between
86  //signatures made in different contexts, helping against potential
87  //cross-protocol attacks
88  if(context->entity == TLS_CONNECTION_END_CLIENT)
89  {
90  osMemcpy(buffer + 64, "TLS 1.3, client CertificateVerify", 33);
91  }
92  else
93  {
94  osMemcpy(buffer + 64, "TLS 1.3, server CertificateVerify", 33);
95  }
96 
97  //Append a single 0 byte which serves as the separator
98  buffer[97] = 0x00;
99 
100  //Compute the transcript hash
101  error = tlsFinalizeTranscriptHash(context, hashAlgo,
102  context->transcriptHashContext, "", buffer + 98);
103 
104  //Check status code
105  if(!error)
106  {
107 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED)
108  //RSA-PSS signature scheme?
109  if(context->signAlgo == TLS_SIGN_ALGO_RSA_PSS_RSAE_SHA256 ||
110  context->signAlgo == TLS_SIGN_ALGO_RSA_PSS_RSAE_SHA384 ||
111  context->signAlgo == TLS_SIGN_ALGO_RSA_PSS_RSAE_SHA512 ||
112  context->signAlgo == TLS_SIGN_ALGO_RSA_PSS_PSS_SHA256 ||
113  context->signAlgo == TLS_SIGN_ALGO_RSA_PSS_PSS_SHA384 ||
114  context->signAlgo == TLS_SIGN_ALGO_RSA_PSS_PSS_SHA512)
115  {
116  //Generate an RSA-PSS signature
117  error = tls13GenerateRsaPssSignature(context, buffer, n, signature);
118  }
119  else
120 #endif
121 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
122  //ECDSA signature scheme?
123  if(context->signAlgo == TLS_SIGN_ALGO_ECDSA)
124  {
125  //Generate an ECDSA signature
126  error = tls13GenerateEcdsaSignature(context, buffer, n, signature);
127  }
128  else
129 #endif
130 #if (TLS_EDDSA_SIGN_SUPPORT == ENABLED)
131  //EdDSA signature scheme?
132  if(context->signAlgo == TLS_SIGN_ALGO_ED25519 ||
133  context->signAlgo == TLS_SIGN_ALGO_ED448)
134  {
135  //Generate an EdDSA signature
136  error = tls13GenerateEddsaSignature(context, buffer, n, signature);
137  }
138  else
139 #endif
140  //Invalid signature scheme?
141  {
142  //Report an error
144  }
145  }
146 
147  //Release memory buffer
148  tlsFreeMem(buffer);
149  }
150  else
151  {
152  //Failed to allocate memory
153  error = ERROR_OUT_OF_MEMORY;
154  }
155 
156  //Check status code
157  if(!error)
158  {
159  //Total length of the digitally-signed element
160  *length = sizeof(Tls13DigitalSignature) + ntohs(signature->length);
161  }
162 
163  //Return status code
164  return error;
165 }
166 
167 
168 /**
169  * @brief RSA-PSS signature generation (TLS 1.3)
170  * @param[in] context Pointer to the TLS context
171  * @param[in] message Pointer to the message to be signed
172  * @param[in] length Length of the message, in bytes
173  * @param[out] signature Buffer where to store the digital signature
174  * @return Error code
175  **/
176 
179 {
180 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED)
181  error_t error;
182  size_t n;
183  RsaPrivateKey privateKey;
184  const HashAlgo *hashAlgo;
185 
186  //Initialize status code
187  error = NO_ERROR;
188 
189  //Initialize RSA private key
190  rsaInitPrivateKey(&privateKey);
191 
192  //The algorithm field specifies the signature scheme and the corresponding
193  //hash algorithm
194  if(context->signAlgo == TLS_SIGN_ALGO_RSA_PSS_RSAE_SHA256)
195  {
196  //Select rsa_pss_rsae_sha256 signature algorithm
199  }
200  else if(context->signAlgo == TLS_SIGN_ALGO_RSA_PSS_RSAE_SHA384)
201  {
202  //Select rsa_pss_rsae_sha384 signature algorithm
205  }
206  else if(context->signAlgo == TLS_SIGN_ALGO_RSA_PSS_RSAE_SHA512)
207  {
208  //Select rsa_pss_rsae_sha512 signature algorithm
211  }
212  else if(context->signAlgo == TLS_SIGN_ALGO_RSA_PSS_PSS_SHA256)
213  {
214  //Select rsa_pss_pss_sha256 signature algorithm
217  }
218  else if(context->signAlgo == TLS_SIGN_ALGO_RSA_PSS_PSS_SHA384)
219  {
220  //Select rsa_pss_pss_sha384 signature algorithm
223  }
224  else if(context->signAlgo == TLS_SIGN_ALGO_RSA_PSS_PSS_SHA512)
225  {
226  //Select rsa_pss_pss_sha512 signature algorithm
229  }
230  else
231  {
232  //Invalid signature algorithm
234  }
235 
236  //Check status code
237  if(!error)
238  {
239  //Pre-hash the content covered by the digital signature
240  if(hashAlgo != NULL)
241  {
242  error = hashAlgo->compute(message, length, context->clientVerifyData);
243  }
244  else
245  {
247  }
248  }
249 
250  //Check status code
251  if(!error)
252  {
253  //Retrieve the RSA private key corresponding to the certificate sent in
254  //the previous message
255  error = pemImportRsaPrivateKey(context->cert->privateKey,
256  context->cert->privateKeyLen, context->cert->password, &privateKey);
257  }
258 
259  //Check status code
260  if(!error)
261  {
262  //RSA signatures must use an RSASSA-PSS algorithm, regardless of whether
263  //RSASSA-PKCS1-v1_5 algorithms appear in SignatureAlgorithms
264  error = rsassaPssSign(context->prngAlgo, context->prngContext,
265  &privateKey, hashAlgo, hashAlgo->digestSize,
266  context->clientVerifyData, signature->value, &n);
267  }
268 
269  //Check status code
270  if(!error)
271  {
272  //The signature is preceded by a 2-byte length field
273  signature->length = htons(n);
274  }
275 
276  //Release previously allocated resources
277  rsaFreePrivateKey(&privateKey);
278 
279  //Return status code
280  return error;
281 #else
282  //Not implemented
283  return ERROR_NOT_IMPLEMENTED;
284 #endif
285 }
286 
287 
288 /**
289  * @brief ECDSA signature generation (TLS 1.3)
290  * @param[in] context Pointer to the TLS context
291  * @param[in] message Pointer to the message to be signed
292  * @param[in] length Length of the message, in bytes
293  * @param[out] signature Buffer where to store the digital signature
294  * @return Error code
295  **/
296 
299 {
300 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
301  error_t error;
302  size_t n;
303  const HashAlgo *hashAlgo;
304 
305  //Initialize status code
306  error = NO_ERROR;
307 
308  //The algorithm field specifies the signature scheme, the corresponding
309  //curve and the corresponding hash algorithm
310  if(context->cert->namedCurve == TLS_GROUP_SECP256R1 &&
311  context->signHashAlgo == TLS_HASH_ALGO_SHA256)
312  {
313  //Select ecdsa_secp256r1_sha256 signature algorithm
316  }
317  else if(context->cert->namedCurve == TLS_GROUP_SECP384R1 &&
318  context->signHashAlgo == TLS_HASH_ALGO_SHA384)
319  {
320  //Select ecdsa_secp384r1_sha384 signature algorithm
323  }
324  else if(context->cert->namedCurve == TLS_GROUP_SECP521R1 &&
325  context->signHashAlgo == TLS_HASH_ALGO_SHA512)
326  {
327  //Select ecdsa_secp521r1_sha512 signature algorithm
330  }
331  else
332  {
333  //Invalid signature algorithm
335  }
336 
337  //Check status code
338  if(!error)
339  {
340  //Pre-hash the content covered by the digital signature
341  if(hashAlgo != NULL)
342  {
343  error = hashAlgo->compute(message, length, context->clientVerifyData);
344  }
345  else
346  {
348  }
349  }
350 
351  //Check status code
352  if(!error)
353  {
354  //Generate an ECDSA signature
355  error = tlsGenerateEcdsaSignature(context, context->clientVerifyData,
356  hashAlgo->digestSize, signature->value, &n);
357  }
358 
359  //Check status code
360  if(!error)
361  {
362  //The signature is preceded by a 2-byte length field
363  signature->length = htons(n);
364  }
365 
366  //Return status code
367  return error;
368 #else
369  //Not implemented
370  return ERROR_NOT_IMPLEMENTED;
371 #endif
372 }
373 
374 
375 /**
376  * @brief EdDSA signature generation (TLS 1.3)
377  * @param[in] context Pointer to the TLS context
378  * @param[in] message Pointer to the message to be signed
379  * @param[in] length Length of the message, in bytes
380  * @param[out] signature Buffer where to store the digital signature
381  * @return Error code
382  **/
383 
386 {
387 #if (TLS_EDDSA_SIGN_SUPPORT == ENABLED)
388  error_t error;
389  size_t n;
390  EddsaMessageChunk messageChunks[2];
391 
392  //Initialize status code
393  error = NO_ERROR;
394 
395  //The algorithm field specifies the signature algorithm used
396  if(context->signAlgo == TLS_SIGN_ALGO_ED25519)
397  {
398  //Select ed25519 signature algorithm
400  }
401  else if(context->signAlgo == TLS_SIGN_ALGO_ED448)
402  {
403  //Select ed448 signature algorithm
404  signature->algorithm = HTONS(TLS_SIGN_SCHEME_ED448);
405  }
406  else
407  {
408  //Invalid signature algorithm
410  }
411 
412  //Check status code
413  if(!error)
414  {
415  //Data to be signed is run through the EdDSA algorithm without
416  //pre-hashing
417  messageChunks[0].buffer = message;
418  messageChunks[0].length = length;
419  messageChunks[1].buffer = NULL;
420  messageChunks[1].length = 0;
421 
422  //Generate a signature in PureEdDSA mode
423  error = tlsGenerateEddsaSignature(context, messageChunks,
424  signature->value, &n);
425  }
426 
427  //Check status code
428  if(!error)
429  {
430  //The signature is preceded by a 2-byte length field
431  signature->length = htons(n);
432  }
433 
434  //Return status code
435  return error;
436 #else
437  //Not implemented
438  return ERROR_NOT_IMPLEMENTED;
439 #endif
440 }
441 
442 
443 /**
444  * @brief Digital signature verification (TLS 1.3)
445  * @param[in] context Pointer to the TLS context
446  * @param[in] p Pointer to the digitally-signed element to be verified
447  * @param[in] length Length of the digitally-signed element
448  * @return Error code
449  **/
450 
451 error_t tls13VerifySignature(TlsContext *context, const uint8_t *p,
452  size_t length)
453 {
454  error_t error;
455  size_t n;
456  uint8_t *buffer;
457  Tls13SignatureScheme signAlgo;
459  const HashAlgo *hashAlgo;
460 
461  //Point to the digitally-signed element
463 
464  //Malformed CertificateVerify message?
465  if(length < sizeof(Tls13DigitalSignature))
466  return ERROR_DECODING_FAILED;
467  if(length != (sizeof(Tls13DigitalSignature) + ntohs(signature->length)))
468  return ERROR_DECODING_FAILED;
469 
470  //The hash function used by HKDF is the cipher suite hash algorithm
471  hashAlgo = context->cipherSuite.prfHashAlgo;
472  //Make sure the hash algorithm is valid
473  if(hashAlgo == NULL)
474  return ERROR_FAILURE;
475 
476  //Calculate the length of the content covered by the digital signature
477  n = hashAlgo->digestSize + 98;
478 
479  //Allocate a memory buffer
480  buffer = tlsAllocMem(n);
481 
482  //Successful memory allocation?
483  if(buffer != NULL)
484  {
485  //Form a string that consists of octet 32 (0x20) repeated 64 times
486  osMemset(buffer, ' ', 64);
487 
488  //Append the context string. It is used to provide separation between
489  //signatures made in different contexts, helping against potential
490  //cross-protocol attacks
491  if(context->entity == TLS_CONNECTION_END_CLIENT)
492  {
493  osMemcpy(buffer + 64, "TLS 1.3, server CertificateVerify", 33);
494  }
495  else
496  {
497  osMemcpy(buffer + 64, "TLS 1.3, client CertificateVerify", 33);
498  }
499 
500  //Append a single 0 byte which serves as the separator
501  buffer[97] = 0x00;
502 
503  //Compute the transcript hash
504  error = tlsFinalizeTranscriptHash(context, hashAlgo,
505  context->transcriptHashContext, "", buffer + 98);
506 
507  //Check status code
508  if(!error)
509  {
510  //The algorithm field specifies the signature scheme
511  signAlgo = (Tls13SignatureScheme) ntohs(signature->algorithm);
512 
513 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED)
514  //RSASSA-PSS signature scheme?
515  if(signAlgo == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256 ||
521  {
522  //Verify RSA-PSS signature
523  error = tls13VerifyRsaPssSignature(context, buffer, n, signature);
524  }
525  else
526 #endif
527 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
528  //ECDSA signature scheme?
532  {
533  //Verify ECDSA signature
534  error = tls13VerifyEcdsaSignature(context, buffer, n, signature);
535  }
536  else
537 #endif
538 #if (TLS_EDDSA_SIGN_SUPPORT == ENABLED)
539  //EdDSA signature scheme?
540  if(signAlgo == TLS_SIGN_SCHEME_ED25519 ||
541  signAlgo == TLS_SIGN_SCHEME_ED448)
542  {
543  //Verify EdDSA signature
544  error = tls13VerifyEddsaSignature(context, buffer, n, signature);
545  }
546  else
547 #endif
548  //Unknown signature scheme?
549  {
550  //Report an error
551  error = ERROR_ILLEGAL_PARAMETER;
552  }
553  }
554 
555  //Release memory buffer
556  tlsFreeMem(buffer);
557  }
558  else
559  {
560  //Failed to allocate memory
561  error = ERROR_OUT_OF_MEMORY;
562  }
563 
564  //Return status code
565  return error;
566 }
567 
568 
569 /**
570  * @brief RSA-PSS signature verification (TLS 1.3)
571  * @param[in] context Pointer to the TLS context
572  * @param[in] message Message whose signature is to be verified
573  * @param[in] length Length of the message, in bytes
574  * @param[in] signature Pointer to the digital signature to be verified
575  * @return Error code
576  **/
577 
579  size_t length, const Tls13DigitalSignature *signature)
580 {
581 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED)
582  error_t error;
583  Tls13SignatureScheme signAlgo;
584  const HashAlgo *hashAlgo;
585 
586  //The algorithm field specifies the signature scheme
587  signAlgo = (Tls13SignatureScheme) ntohs(signature->algorithm);
588 
589  //Enforce the type of the certificate provided by the peer
590  if(context->peerCertType == TLS_CERT_RSA_SIGN)
591  {
592  //Retrieve the hash algorithm used for signing
594  {
595  //Select SHA-256 hash algorithm
597  }
598  else if(signAlgo == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384)
599  {
600  //Select SHA-384 hash algorithm
602  }
603  else if(signAlgo == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA512)
604  {
605  //Select SHA-512 hash algorithm
607  }
608  else
609  {
610  //Invalid signature scheme
611  hashAlgo = NULL;
612  }
613  }
614  else if(context->peerCertType == TLS_CERT_RSA_PSS_SIGN)
615  {
616  //Retrieve the hash algorithm used for signing
617  if(signAlgo == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256)
618  {
619  //Select SHA-256 hash algorithm
621  }
622  else if(signAlgo == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384)
623  {
624  //Select SHA-384 hash algorithm
626  }
627  else if(signAlgo == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA512)
628  {
629  //Select SHA-512 hash algorithm
631  }
632  else
633  {
634  //Invalid signature scheme
635  hashAlgo = NULL;
636  }
637  }
638  else
639  {
640  //Invalid certificate
641  hashAlgo = NULL;
642  }
643 
644  //Pre-hash the content covered by the digital signature
645  if(hashAlgo != NULL)
646  {
647  error = hashAlgo->compute(message, length, context->clientVerifyData);
648  }
649  else
650  {
651  error = ERROR_ILLEGAL_PARAMETER;
652  }
653 
654  //Check status code
655  if(!error)
656  {
657  //Verify RSASSA-PSS signature
658  error = rsassaPssVerify(&context->peerRsaPublicKey, hashAlgo,
659  hashAlgo->digestSize, context->clientVerifyData, signature->value,
660  ntohs(signature->length));
661  }
662 
663  //Return status code
664  return error;
665 #else
666  //Not implemented
667  return ERROR_NOT_IMPLEMENTED;
668 #endif
669 }
670 
671 
672 /**
673  * @brief ECDSA signature verification (TLS 1.3)
674  * @param[in] context Pointer to the TLS context
675  * @param[in] message Message whose signature is to be verified
676  * @param[in] length Length of the message, in bytes
677  * @param[in] signature Pointer to the digital signature to be verified
678  * @return Error code
679  **/
680 
682  size_t length, const Tls13DigitalSignature *signature)
683 {
684 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
685  error_t error;
686  Tls13SignatureScheme signAlgo;
687  const HashAlgo *hashAlgo;
688 
689  //The algorithm field specifies the signature scheme
690  signAlgo = (Tls13SignatureScheme) ntohs(signature->algorithm);
691 
692  //Enforce the type of the certificate provided by the peer
693  if(context->peerCertType == TLS_CERT_ECDSA_SIGN)
694  {
695  //Retrieve the hash algorithm used for signing
696  if(context->peerEcParams.name == NULL)
697  {
698  //Invalid signature scheme
699  hashAlgo = NULL;
700  }
701  else if(signAlgo == TLS_SIGN_SCHEME_ECDSA_SECP256R1_SHA256 &&
702  osStrcmp(context->peerEcParams.name, "secp256r1") == 0)
703  {
704  //Select SHA-256 hash algorithm
706  }
707  else if(signAlgo == TLS_SIGN_SCHEME_ECDSA_SECP384R1_SHA384 &&
708  osStrcmp(context->peerEcParams.name, "secp384r1") == 0)
709  {
710  //Select SHA-384 hash algorithm
712  }
713  else if(signAlgo == TLS_SIGN_SCHEME_ECDSA_SECP521R1_SHA512 &&
714  osStrcmp(context->peerEcParams.name, "secp521r1") == 0)
715  {
716  //Select SHA-512 hash algorithm
718  }
719  else
720  {
721  //Invalid signature scheme
722  hashAlgo = NULL;
723  }
724  }
725  else
726  {
727  //Invalid certificate
728  hashAlgo = NULL;
729  }
730 
731  //Pre-hash the content covered by the digital signature
732  if(hashAlgo != NULL)
733  {
734  error = hashAlgo->compute(message, length, context->clientVerifyData);
735  }
736  else
737  {
738  error = ERROR_ILLEGAL_PARAMETER;
739  }
740 
741  //Check status code
742  if(!error)
743  {
744  //Verify ECDSA signature
745  error = tlsVerifyEcdsaSignature(context, context->clientVerifyData,
746  hashAlgo->digestSize, signature->value, ntohs(signature->length));
747  }
748 
749  //Return status code
750  return error;
751 #else
752  //Not implemented
753  return ERROR_NOT_IMPLEMENTED;
754 #endif
755 }
756 
757 
758 /**
759  * @brief EdDSA signature verification (TLS 1.3)
760  * @param[in] context Pointer to the TLS context
761  * @param[in] message Message whose signature is to be verified
762  * @param[in] length Length of the message, in bytes
763  * @param[in] signature Pointer to the digital signature to be verified
764  * @return Error code
765  **/
766 
768  size_t length, const Tls13DigitalSignature *signature)
769 {
770 #if (TLS_EDDSA_SIGN_SUPPORT == ENABLED)
771  error_t error;
772  Tls13SignatureScheme signAlgo;
773  EddsaMessageChunk messageChunks[2];
774 
775  //The algorithm field specifies the signature scheme
776  signAlgo = (Tls13SignatureScheme) ntohs(signature->algorithm);
777 
778  //Data to be verified is run through the EdDSA algorithm without pre-hashing
779  messageChunks[0].buffer = message;
780  messageChunks[0].length = length;
781  messageChunks[1].buffer = NULL;
782  messageChunks[1].length = 0;
783 
784 #if (TLS_ED25519_SUPPORT == ENABLED)
785  //Ed25519 signature scheme?
786  if(signAlgo == TLS_SIGN_SCHEME_ED25519 &&
787  context->peerCertType == TLS_CERT_ED25519_SIGN)
788  {
789  //Verify Ed25519 signature (PureEdDSA mode)
790  error = tlsVerifyEddsaSignature(context, messageChunks,
791  signature->value, ntohs(signature->length));
792  }
793  else
794 #endif
795 #if (TLS_ED448_SUPPORT == ENABLED)
796  //Ed448 signature scheme?
797  if(signAlgo == TLS_SIGN_SCHEME_ED448 &&
798  context->peerCertType == TLS_CERT_ED448_SIGN)
799  {
800  //Verify Ed448 signature (PureEdDSA mode)
801  error = tlsVerifyEddsaSignature(context, messageChunks,
802  signature->value, ntohs(signature->length));
803  }
804  else
805 #endif
806  //Invalid signature scheme?
807  {
808  //Report an error
809  error = ERROR_ILLEGAL_PARAMETER;
810  }
811 
812  //Return status code
813  return error;
814 #else
815  //Not implemented
816  return ERROR_NOT_IMPLEMENTED;
817 #endif
818 }
819 
820 #endif
uint8_t message[]
Definition: chap.h:152
#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
error_t
Error codes.
Definition: error.h:43
@ ERROR_ILLEGAL_PARAMETER
Definition: error.h:242
@ ERROR_UNSUPPORTED_SIGNATURE_ALGO
Definition: error.h:132
@ ERROR_DECODING_FAILED
Definition: error.h:240
@ ERROR_NOT_IMPLEMENTED
Definition: error.h:66
@ NO_ERROR
Success.
Definition: error.h:44
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
uint8_t p
Definition: ndp.h:298
#define osMemset(p, value, length)
Definition: os_port.h:137
#define osStrcmp(s1, s2)
Definition: os_port.h:173
#define osMemcpy(dest, src, length)
Definition: os_port.h:143
error_t pemImportRsaPrivateKey(const char_t *input, size_t length, const char_t *password, RsaPrivateKey *privateKey)
Decode a PEM file containing an RSA private key.
Definition: pem_import.c:388
PEM file import functions.
void rsaFreePrivateKey(RsaPrivateKey *key)
Release an RSA private key.
Definition: rsa.c:153
error_t rsassaPssSign(const PrngAlgo *prngAlgo, void *prngContext, const RsaPrivateKey *key, const HashAlgo *hash, size_t saltLen, const uint8_t *digest, uint8_t *signature, size_t *signatureLen)
RSASSA-PSS signature generation operation.
Definition: rsa.c:959
error_t rsassaPssVerify(const RsaPublicKey *key, const HashAlgo *hash, size_t saltLen, const uint8_t *digest, const uint8_t *signature, size_t signatureLen)
RSASSA-PSS signature verification operation.
Definition: rsa.c:1079
void rsaInitPrivateKey(RsaPrivateKey *key)
Initialize an RSA private key.
Definition: rsa.c:131
Message chunk descriptor.
Definition: eddsa.h:71
const void * buffer
Definition: eddsa.h:72
size_t length
Definition: eddsa.h:73
Common interface for hash algorithms.
Definition: crypto.h:1007
HashAlgoCompute compute
Definition: crypto.h:1016
size_t digestSize
Definition: crypto.h:1013
RSA private key.
Definition: rsa.h:68
uint8_t length
Definition: tcp.h:366
Tls13DigitalSignature
Definition: tls13_misc.h:305
Tls13SignatureScheme
Signature schemes (TLS 1.3)
Definition: tls13_misc.h:136
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256
Definition: tls13_misc.h:145
@ TLS_SIGN_SCHEME_ECDSA_SECP521R1_SHA512
Definition: tls13_misc.h:151
@ TLS_SIGN_SCHEME_ECDSA_SECP384R1_SHA384
Definition: tls13_misc.h:150
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384
Definition: tls13_misc.h:143
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA512
Definition: tls13_misc.h:144
@ TLS_SIGN_SCHEME_ECDSA_SECP256R1_SHA256
Definition: tls13_misc.h:149
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384
Definition: tls13_misc.h:146
@ TLS_SIGN_SCHEME_ED25519
Definition: tls13_misc.h:163
@ TLS_SIGN_SCHEME_ED448
Definition: tls13_misc.h:164
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA512
Definition: tls13_misc.h:147
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256
Definition: tls13_misc.h:142
error_t tls13GenerateRsaPssSignature(TlsContext *context, const uint8_t *message, size_t length, Tls13DigitalSignature *signature)
RSA-PSS signature generation (TLS 1.3)
error_t tls13GenerateSignature(TlsContext *context, uint8_t *p, size_t *length)
Digital signature generation (TLS 1.3)
error_t tls13VerifySignature(TlsContext *context, const uint8_t *p, size_t length)
Digital signature verification (TLS 1.3)
error_t tls13GenerateEcdsaSignature(TlsContext *context, const uint8_t *message, size_t length, Tls13DigitalSignature *signature)
ECDSA signature generation (TLS 1.3)
error_t tls13VerifyRsaPssSignature(TlsContext *context, const uint8_t *message, size_t length, const Tls13DigitalSignature *signature)
RSA-PSS signature verification (TLS 1.3)
error_t tls13VerifyEcdsaSignature(TlsContext *context, const uint8_t *message, size_t length, const Tls13DigitalSignature *signature)
ECDSA signature verification (TLS 1.3)
error_t tls13VerifyEddsaSignature(TlsContext *context, const uint8_t *message, size_t length, const Tls13DigitalSignature *signature)
EdDSA signature verification (TLS 1.3)
error_t tls13GenerateEddsaSignature(TlsContext *context, const uint8_t *message, size_t length, Tls13DigitalSignature *signature)
EdDSA signature generation (TLS 1.3)
RSA/DSA/ECDSA/EdDSA signature generation and verification.
TLS (Transport Layer Security)
#define tlsAllocMem(size)
Definition: tls.h:840
#define tlsFreeMem(p)
Definition: tls.h:845
@ TLS_HASH_ALGO_SHA384
Definition: tls.h:1190
@ TLS_HASH_ALGO_SHA256
Definition: tls.h:1189
@ TLS_HASH_ALGO_SHA512
Definition: tls.h:1191
@ TLS_CERT_ED448_SIGN
Definition: tls.h:1175
@ TLS_CERT_RSA_SIGN
Definition: tls.h:1161
@ TLS_CERT_ED25519_SIGN
Definition: tls.h:1174
@ TLS_CERT_RSA_PSS_SIGN
Definition: tls.h:1173
@ TLS_CERT_ECDSA_SIGN
Definition: tls.h:1168
@ TLS_SIGN_ALGO_RSA_PSS_PSS_SHA512
Definition: tls.h:1213
@ TLS_SIGN_ALGO_ECDSA
Definition: tls.h:1205
@ TLS_SIGN_ALGO_RSA_PSS_RSAE_SHA512
Definition: tls.h:1208
@ TLS_SIGN_ALGO_ED448
Definition: tls.h:1210
@ TLS_SIGN_ALGO_RSA_PSS_PSS_SHA256
Definition: tls.h:1211
@ TLS_SIGN_ALGO_ED25519
Definition: tls.h:1209
@ TLS_SIGN_ALGO_RSA_PSS_RSAE_SHA256
Definition: tls.h:1206
@ TLS_SIGN_ALGO_RSA_PSS_PSS_SHA384
Definition: tls.h:1212
@ TLS_SIGN_ALGO_RSA_PSS_RSAE_SHA384
Definition: tls.h:1207
#define TlsContext
Definition: tls.h:36
@ TLS_CONNECTION_END_CLIENT
Definition: tls.h:943
@ TLS_GROUP_SECP521R1
Definition: tls.h:1338
@ TLS_GROUP_SECP256R1
Definition: tls.h:1336
@ TLS_GROUP_SECP384R1
Definition: tls.h:1337
uint8_t signature
Definition: tls.h:1481
const HashAlgo * tlsGetHashAlgo(uint8_t hashAlgoId)
Get the hash algorithm that matches the specified identifier.
Definition: tls_misc.c:1166
TLS helper functions.
error_t tlsVerifyEddsaSignature(TlsContext *context, const EddsaMessageChunk *messageChunks, const uint8_t *signature, size_t signatureLen)
Verify EdDSA signature.
error_t tlsVerifyEcdsaSignature(TlsContext *context, const uint8_t *digest, size_t digestLen, const uint8_t *signature, size_t signatureLen)
Verify ECDSA signature.
error_t tlsGenerateEddsaSignature(TlsContext *context, const EddsaMessageChunk *messageChunks, uint8_t *signature, size_t *signatureLen)
Generate EdDSA signature.
error_t tlsGenerateEcdsaSignature(TlsContext *context, const uint8_t *digest, size_t digestLen, uint8_t *signature, size_t *signatureLen)
Generate ECDSA signature.
RSA/DSA/ECDSA/EdDSA signature generation and verification (TLS 1.3)
error_t tlsFinalizeTranscriptHash(TlsContext *context, const HashAlgo *hash, const void *hashContext, const char_t *label, uint8_t *output)
Finalize hash calculation from previous handshake messages.
Transcript hash calculation.