tls_sign_verify.c
Go to the documentation of this file.
1 /**
2  * @file tls_sign_verify.c
3  * @brief RSA/DSA/ECDSA/EdDSA signature verification
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2025 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.5.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_sign_verify.h"
37 #include "tls_sign_misc.h"
38 #include "tls_transcript_hash.h"
39 #include "tls_misc.h"
40 #include "pkc/rsa.h"
41 #include "pkc/rsa_misc.h"
42 #include "pkc/dsa.h"
43 #include "ecc/ecdsa.h"
44 #include "ecc/eddsa.h"
45 #include "ecc/ec_misc.h"
46 #include "debug.h"
47 
48 //Check TLS library configuration
49 #if (TLS_SUPPORT == ENABLED)
50 
51 
52 /**
53  * @brief Digital signature verification (TLS 1.0 and TLS 1.1)
54  * @param[in] context Pointer to the TLS context
55  * @param[in] p Pointer to the digitally-signed element to be verified
56  * @param[in] length Length of the digitally-signed element
57  * @return Error code
58  **/
59 
60 error_t tlsVerifySignature(TlsContext *context, const uint8_t *p,
61  size_t length)
62 {
63 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_1)
64  error_t error;
65  const TlsDigitalSignature *signature;
66 
67  //The digitally-signed element does not convey the signature algorithm
68  //to use, and hence implementations need to inspect the certificate to
69  //find out the signature algorithm to use
70  signature = (TlsDigitalSignature *) p;
71 
72  //Check the length of the digitally-signed element
73  if(length < sizeof(TlsDigitalSignature))
74  return ERROR_DECODING_FAILED;
75  if(length != (sizeof(TlsDigitalSignature) + ntohs(signature->length)))
76  return ERROR_DECODING_FAILED;
77 
78 #if (TLS_RSA_SIGN_SUPPORT == ENABLED)
79  //RSA certificate?
80  if(context->peerCertType == TLS_CERT_RSA_SIGN)
81  {
82  //Digest all the handshake messages starting at ClientHello using MD5
84  context->transcriptMd5Context, "", context->clientVerifyData);
85 
86  //Check status code
87  if(!error)
88  {
89  //Digest all the handshake messages starting at ClientHello using SHA-1
91  context->transcriptSha1Context, "",
92  context->clientVerifyData + MD5_DIGEST_SIZE);
93  }
94 
95  //Check status code
96  if(!error)
97  {
98  //Verify RSA signature using client's public key
99  error = tlsVerifyRsaSignature(&context->peerRsaPublicKey,
100  context->clientVerifyData, signature->value,
101  ntohs(signature->length));
102  }
103  }
104  else
105 #endif
106 #if (TLS_DSA_SIGN_SUPPORT == ENABLED)
107  //DSA certificate?
108  if(context->peerCertType == TLS_CERT_DSS_SIGN)
109  {
110  //Digest all the handshake messages starting at ClientHello
111  error = tlsFinalizeTranscriptHash(context, SHA1_HASH_ALGO,
112  context->transcriptSha1Context, "", context->clientVerifyData);
113 
114  //Check status code
115  if(!error)
116  {
117  //Verify DSA signature using client's public key
118  error = tlsVerifyDsaSignature(context, context->clientVerifyData,
119  SHA1_DIGEST_SIZE, signature->value, ntohs(signature->length));
120  }
121  }
122  else
123 #endif
124 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
125  //ECDSA certificate?
126  if(context->peerCertType == TLS_CERT_ECDSA_SIGN)
127  {
128  //Digest all the handshake messages starting at ClientHello
129  error = tlsFinalizeTranscriptHash(context, SHA1_HASH_ALGO,
130  context->transcriptSha1Context, "", context->clientVerifyData);
131 
132  //Check status code
133  if(!error)
134  {
135  //Verify ECDSA signature using client's public key
136  error = tlsVerifyEcdsaSignature(context, context->clientVerifyData,
137  SHA1_DIGEST_SIZE, signature->value, ntohs(signature->length));
138  }
139  }
140  else
141 #endif
142  //Invalid signature algorithm?
143  {
144  //Report an error
145  error = ERROR_INVALID_SIGNATURE;
146  }
147 
148  //Return status code
149  return error;
150 #else
151  //Not implemented
152  return ERROR_NOT_IMPLEMENTED;
153 #endif
154 }
155 
156 
157 /**
158  * @brief Digital signature verification (TLS 1.2)
159  * @param[in] context Pointer to the TLS context
160  * @param[in] p Pointer to the digitally-signed element to be verified
161  * @param[in] length Length of the digitally-signed element
162  * @return Error code
163  **/
164 
165 error_t tls12VerifySignature(TlsContext *context, const uint8_t *p,
166  size_t length)
167 {
168 #if (TLS_MAX_VERSION >= TLS_VERSION_1_2 && TLS_MIN_VERSION <= TLS_VERSION_1_2)
169  error_t error;
170  TlsSignatureScheme signScheme;
171  const Tls12DigitalSignature *signature;
172  const HashAlgo *hashAlgo;
173 
174  //Point to the digitally-signed element
175  signature = (Tls12DigitalSignature *) p;
176 
177  //Check the length of the digitally-signed element
178  if(length < sizeof(Tls12DigitalSignature))
179  return ERROR_DECODING_FAILED;
180  if(length != (sizeof(Tls12DigitalSignature) + ntohs(signature->length)))
181  return ERROR_DECODING_FAILED;
182 
183  //The algorithm field specifies the signature scheme
184  signScheme = (TlsSignatureScheme) ntohs(signature->algorithm);
185 
186  //The certificates must be signed using an acceptable hash/signature
187  //algorithm pair (refer to RFC 5246, section 7.4.6)
188  if(!tlsIsSignAlgoSupported(context, signScheme))
190 
191  //Check signature scheme
192  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_RSA ||
193  TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_DSA ||
194  TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_ECDSA)
195  {
196  //Retrieve the hash algorithm used for signing
197  hashAlgo = tlsGetHashAlgo(TLS_HASH_ALGO(signScheme));
198  }
199  else if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256 ||
201  {
202  //The hashing is intrinsic to the signature algorithm
204  }
205  else if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384 ||
207  {
208  //The hashing is intrinsic to the signature algorithm
210  }
211  else if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA512 ||
213  {
214  //The hashing is intrinsic to the signature algorithm
216  }
217  else
218  {
219  //Unknown signature scheme
220  hashAlgo = NULL;
221  }
222 
223  //Digest all the handshake messages starting at ClientHello
224  if(hashAlgo == SHA1_HASH_ALGO)
225  {
226  //Use SHA-1 hash algorithm
227  error = tlsFinalizeTranscriptHash(context, SHA1_HASH_ALGO,
228  context->transcriptSha1Context, "", context->clientVerifyData);
229  }
230  else if(hashAlgo == context->cipherSuite.prfHashAlgo)
231  {
232  //Use PRF hash algorithm (SHA-256 or SHA-384)
233  error = tlsFinalizeTranscriptHash(context, hashAlgo,
234  context->transcriptHashContext, "", context->clientVerifyData);
235  }
236  else
237  {
238  //The specified hash algorithm is not supported
239  error = ERROR_INVALID_SIGNATURE;
240  }
241 
242  //Check status code
243  if(!error)
244  {
245 #if (TLS_RSA_SIGN_SUPPORT == ENABLED)
246  //RSASSA-PKCS1-v1_5 signature scheme?
247  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_RSA &&
248  context->peerCertType == TLS_CERT_RSA_SIGN)
249  {
250  //Verify RSA signature (RSASSA-PKCS1-v1_5 signature scheme)
251  error = rsassaPkcs1v15Verify(&context->peerRsaPublicKey,
252  hashAlgo, context->clientVerifyData, signature->value,
253  ntohs(signature->length));
254  }
255  else
256 #endif
257 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED)
258  //RSASSA-PSS signature scheme (with public key OID rsaEncryption)?
259  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256 ||
260  signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384 ||
262  {
263  //The signature algorithm must be compatible with the key in the
264  //server's end-entity certificate (refer to RFC 5246, section 7.4.3)
265  if(context->peerCertType == TLS_CERT_RSA_SIGN)
266  {
267  //Verify RSA signature (RSASSA-PSS signature scheme)
268  error = rsassaPssVerify(&context->peerRsaPublicKey, hashAlgo,
269  hashAlgo->digestSize, context->clientVerifyData,
270  signature->value, ntohs(signature->length));
271  }
272  else
273  {
274  //Invalid certificate
275  error = ERROR_INVALID_SIGNATURE;
276  }
277  }
278  else
279 #endif
280 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED)
281  //RSASSA-PSS signature scheme (with public key OID RSASSA-PSS)?
282  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256 ||
283  signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384 ||
285  {
286  //The signature algorithm must be compatible with the key in the
287  //server's end-entity certificate (refer to RFC 5246, section 7.4.3)
288  if(context->peerCertType == TLS_CERT_RSA_PSS_SIGN)
289  {
290  //Verify RSA signature (RSASSA-PSS signature scheme)
291  error = rsassaPssVerify(&context->peerRsaPublicKey, hashAlgo,
292  hashAlgo->digestSize, context->clientVerifyData,
293  signature->value, ntohs(signature->length));
294  }
295  else
296  {
297  //Invalid certificate
298  error = ERROR_INVALID_SIGNATURE;
299  }
300  }
301  else
302 #endif
303 #if (TLS_DSA_SIGN_SUPPORT == ENABLED)
304  //DSA signature scheme?
305  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_DSA &&
306  context->peerCertType == TLS_CERT_DSS_SIGN)
307  {
308  //Verify DSA signature using client's public key
309  error = tlsVerifyDsaSignature(context, context->clientVerifyData,
310  hashAlgo->digestSize, signature->value, ntohs(signature->length));
311  }
312  else
313 #endif
314 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
315  //ECDSA signature scheme?
316  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_ECDSA &&
317  context->peerCertType == TLS_CERT_ECDSA_SIGN)
318  {
319  //Verify ECDSA signature using client's public key
320  error = tlsVerifyEcdsaSignature(context, context->clientVerifyData,
321  hashAlgo->digestSize, signature->value, ntohs(signature->length));
322  }
323  else
324 #endif
325  //Invalid signature scheme?
326  {
327  //Report an error
328  error = ERROR_INVALID_SIGNATURE;
329  }
330  }
331 
332  //Return status code
333  return error;
334 #else
335  //Not implemented
336  return ERROR_NOT_IMPLEMENTED;
337 #endif
338 }
339 
340 
341 /**
342  * @brief Verify RSA signature (TLS 1.0 and TLS 1.1)
343  * @param[in] key Signer's RSA public key
344  * @param[in] digest Digest of the message whose signature is to be verified
345  * @param[in] signature Signature to be verified
346  * @param[in] signatureLen Length of the signature to be verified
347  * @return Error code
348  **/
349 
351  const uint8_t *digest, const uint8_t *signature, size_t signatureLen)
352 {
353 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_1 && \
354  TLS_RSA_SIGN_SUPPORT == ENABLED)
355  error_t error;
356  uint_t k;
357  uint8_t *em;
358  Mpi s;
359  Mpi m;
360 
361  //Debug message
362  TRACE_DEBUG("RSA signature verification...\r\n");
363  TRACE_DEBUG(" Modulus:\r\n");
364  TRACE_DEBUG_MPI(" ", &key->n);
365  TRACE_DEBUG(" Public exponent:\r\n");
366  TRACE_DEBUG_MPI(" ", &key->e);
367  TRACE_DEBUG(" Message digest:\r\n");
369  TRACE_DEBUG(" Signature:\r\n");
370  TRACE_DEBUG_ARRAY(" ", signature, signatureLen);
371 
372  //Get the length in octets of the modulus n
373  k = mpiGetByteLength(&key->n);
374 
375  //Check the length of the signature
376  if(signatureLen != k)
378 
379  //Initialize multiple-precision integers
380  mpiInit(&s);
381  mpiInit(&m);
382 
383  //Allocate a memory buffer to hold the encoded message
384  em = tlsAllocMem(k);
385  //Failed to allocate memory?
386  if(em == NULL)
387  return ERROR_OUT_OF_MEMORY;
388 
389  //Start of exception handling block
390  do
391  {
392  //Convert the signature to an integer signature representative s
393  error = mpiImport(&s, signature, signatureLen, MPI_FORMAT_BIG_ENDIAN);
394  //Conversion failed?
395  if(error)
396  break;
397 
398  //Apply the RSAVP1 verification primitive
399  error = rsavp1(key, &s, &m);
400  //Any error to report?
401  if(error)
402  break;
403 
404  //Convert the message representative m to an encoded message EM of
405  //length k octets
406  error = mpiExport(&m, em, k, MPI_FORMAT_BIG_ENDIAN);
407  //Conversion failed?
408  if(error)
409  break;
410 
411  //Debug message
412  TRACE_DEBUG(" Encoded message\r\n");
413  TRACE_DEBUG_ARRAY(" ", em, k);
414 
415  //Verify the encoded message EM
416  error = tlsVerifyRsaEm(digest, em, k);
417 
418  //End of exception handling block
419  } while(0);
420 
421  //Release multiple precision integers
422  mpiFree(&s);
423  mpiFree(&m);
424  //Release previously allocated memory
425  tlsFreeMem(em);
426 
427  //Return status code
428  return error;
429 #else
430  //RSA signature algorithm is not supported
431  return ERROR_NOT_IMPLEMENTED;
432 #endif
433 }
434 
435 
436 /**
437  * @brief Verify RSA encoded message
438  * @param[in] digest Digest value
439  * @param[in] em Encoded message
440  * @param[in] emLen Length of the encoded message
441  * @return Error code
442  **/
443 
444 error_t tlsVerifyRsaEm(const uint8_t *digest, const uint8_t *em, size_t emLen)
445 {
446 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_1 && \
447  TLS_RSA_SIGN_SUPPORT == ENABLED)
448  size_t i;
449  size_t j;
450  size_t n;
451  uint8_t bad;
452 
453  //Check the length of the encoded message
454  if(emLen < (MD5_DIGEST_SIZE + SHA1_DIGEST_SIZE + 11))
455  return ERROR_INVALID_LENGTH;
456 
457  //Point to the first byte of the encoded message
458  i = 0;
459 
460  //The first octet of EM must have hexadecimal value 0x00
461  bad = em[i++];
462  //The second octet of EM must have hexadecimal value 0x01
463  bad |= em[i++] ^ 0x01;
464 
465  //Determine the length of the padding string PS
466  n = emLen - MD5_DIGEST_SIZE - SHA1_DIGEST_SIZE - 3;
467 
468  //Each byte of PS must be set to 0xFF when the block type is 0x01
469  for(j = 0; j < n; j++)
470  {
471  bad |= em[i++] ^ 0xFF;
472  }
473 
474  //The padding string must be followed by a 0x00 octet
475  bad |= em[i++];
476 
477  //Recover the underlying hash value, and then compare it to the newly
478  //computed hash value
479  for(j = 0; j < (MD5_DIGEST_SIZE + SHA1_DIGEST_SIZE); j++)
480  {
481  bad |= em[i++] ^ digest[j];
482  }
483 
484  //Verification result
485  return (bad != 0) ? ERROR_INVALID_SIGNATURE : NO_ERROR;
486 #else
487  //RSA signature algorithm is not supported
488  return ERROR_NOT_IMPLEMENTED;
489 #endif
490 }
491 
492 
493 /**
494  * @brief Verify DSA signature
495  * @param[in] context Pointer to the TLS context
496  * @param[in] digest Digest of the message whose signature is to be verified
497  * @param[in] digestLen Length in octets of the digest
498  * @param[in] signature Signature to be verified
499  * @param[in] signatureLen Length of the signature to be verified
500  * @return Error code
501  **/
502 
503 error_t tlsVerifyDsaSignature(TlsContext *context, const uint8_t *digest,
504  size_t digestLen, const uint8_t *signature, size_t signatureLen)
505 {
506 #if (TLS_DSA_SIGN_SUPPORT == ENABLED)
507  error_t error;
508  DsaSignature dsaSignature;
509 
510  //Initialize DSA signature
511  dsaInitSignature(&dsaSignature);
512 
513  //Read the ASN.1 encoded DSA signature
514  error = dsaImportSignature(&dsaSignature, signature, signatureLen);
515 
516  //Check status code
517  if(!error)
518  {
519  //DSA signature verification
520  error = dsaVerifySignature(&context->peerDsaPublicKey,
521  digest, digestLen, &dsaSignature);
522  }
523  else
524  {
525  //Malformed DSA signature
526  error = ERROR_INVALID_SIGNATURE;
527  }
528 
529  //Free previously allocated resources
530  dsaFreeSignature(&dsaSignature);
531 
532  //Return status code
533  return error;
534 #else
535  //DSA signature algorithm is not supported
536  return ERROR_NOT_IMPLEMENTED;
537 #endif
538 }
539 
540 
541 /**
542  * @brief Verify ECDSA signature
543  * @param[in] context Pointer to the TLS context
544  * @param[in] digest Digest of the message whose signature is to be verified
545  * @param[in] digestLen Length in octets of the digest
546  * @param[in] signature Signature to be verified
547  * @param[in] signatureLen Length of the signature to be verified
548  * @return Error code
549  **/
550 
551 error_t tlsVerifyEcdsaSignature(TlsContext *context, const uint8_t *digest,
552  size_t digestLen, const uint8_t *signature, size_t signatureLen)
553 {
554 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
555  error_t error;
556  EcdsaSignature ecdsaSignature;
557 
558  //Initialize ECDSA signature
559  ecdsaInitSignature(&ecdsaSignature);
560 
561  //Read the ASN.1 encoded ECDSA signature
562  error = ecdsaImportSignature(&ecdsaSignature,
563  context->peerEcPublicKey.curve, signature, signatureLen,
565 
566  //Check status code
567  if(!error)
568  {
569 #if (TLS_ECC_CALLBACK_SUPPORT == ENABLED)
570  //Any registered callback?
571  if(context->ecdsaVerifyCallback != NULL)
572  {
573  //Invoke user callback function
574  error = context->ecdsaVerifyCallback(context, digest, digestLen,
575  &ecdsaSignature);
576  }
577  else
578 #endif
579  {
580  //No callback function defined
582  }
583 
584  //Check status code
585  if(error == ERROR_UNSUPPORTED_ELLIPTIC_CURVE ||
587  {
588  //ECDSA signature verification
589  error = ecdsaVerifySignature(&context->peerEcPublicKey, digest,
590  digestLen, &ecdsaSignature);
591  }
592  }
593  else
594  {
595  //Malformed ECDSA signature
596  error = ERROR_INVALID_SIGNATURE;
597  }
598 
599  //Free previously allocated resources
600  ecdsaFreeSignature(&ecdsaSignature);
601 
602  //Return status code
603  return error;
604 #else
605  //ECDSA signature algorithm is not supported
606  return ERROR_NOT_IMPLEMENTED;
607 #endif
608 }
609 
610 
611 /**
612  * @brief Verify Ed25519 signature
613  * @param[in] context Pointer to the TLS context
614  * @param[in] message Array of data chunks representing the message whose
615  * signature is to be verified
616  * @param[in] messageLen Number of data chunks representing the message
617  * @param[in] signature Signature to be verified
618  * @param[in] signatureLen Length of the signature to be verified
619  * @return Error code
620  **/
621 
623  const DataChunk *message, uint_t messageLen, const uint8_t *signature,
624  size_t signatureLen)
625 {
626 #if (TLS_ED25519_SIGN_SUPPORT == ENABLED)
627  error_t error;
628 
629  //Valid Ed25519 public key?
630  if(context->peerEddsaPublicKey.curve == ED25519_CURVE)
631  {
632  //The Ed25519 signature shall consist of 32 octets
633  if(signatureLen == ED25519_SIGNATURE_LEN)
634  {
635  //Verify Ed25519 signature (PureEdDSA mode)
636  error = ed25519VerifySignatureEx(context->peerEddsaPublicKey.q,
637  message, messageLen, NULL, 0, 0, signature);
638  }
639  else
640  {
641  //The length of the Ed25519 signature is not valid
642  error = ERROR_INVALID_SIGNATURE;
643  }
644  }
645  else
646  {
647  //The public key is not valid
648  error = ERROR_INVALID_KEY;
649  }
650 
651  //Return status code
652  return error;
653 #else
654  //Ed25519 signature algorithm is not supported
655  return ERROR_NOT_IMPLEMENTED;
656 #endif
657 }
658 
659 
660 /**
661  * @brief Verify Ed448 signature
662  * @param[in] context Pointer to the TLS context
663  * @param[in] message Array of data chunks representing the message whose
664  * signature is to be verified
665  * @param[in] messageLen Number of data chunks representing the message
666  * @param[in] signature Signature to be verified
667  * @param[in] signatureLen Length of the signature to be verified
668  * @return Error code
669  **/
670 
672  const DataChunk *message, uint_t messageLen, const uint8_t *signature,
673  size_t signatureLen)
674 {
675 #if (TLS_ED448_SIGN_SUPPORT == ENABLED)
676  error_t error;
677 
678  //Valid Ed448 public key?
679  if(context->peerEddsaPublicKey.curve == ED448_CURVE)
680  {
681  //The Ed448 signature shall consist of 32 octets
682  if(signatureLen == ED448_SIGNATURE_LEN)
683  {
684  //Verify Ed448 signature (PureEdDSA mode)
685  error = ed448VerifySignatureEx(context->peerEddsaPublicKey.q, message,
686  messageLen, NULL, 0, 0, signature);
687  }
688  else
689  {
690  //The length of the Ed448 signature is not valid
691  error = ERROR_INVALID_SIGNATURE;
692  }
693  }
694  else
695  {
696  //The public key is not valid
697  error = ERROR_INVALID_KEY;
698  }
699 
700  //Return status code
701  return error;
702 #else
703  //Ed448 signature algorithm is not supported
704  return ERROR_NOT_IMPLEMENTED;
705 #endif
706 }
707 
708 #endif
#define tlsAllocMem(size)
Definition: tls.h:867
ECDSA signature.
Definition: ecdsa.h:63
@ TLS_SIGN_ALGO_DSA
Definition: tls.h:1257
TLS helper functions.
@ ERROR_UNSUPPORTED_ELLIPTIC_CURVE
Definition: error.h:133
#define SHA1_HASH_ALGO
Definition: sha1.h:49
error_t tlsVerifyEd448Signature(TlsContext *context, const DataChunk *message, uint_t messageLen, const uint8_t *signature, size_t signatureLen)
Verify Ed448 signature.
const HashAlgo * tlsGetHashAlgo(TlsHashAlgo hashAlgoId)
Get the hash algorithm that matches the specified identifier.
Definition: tls_misc.c:1184
TlsDigitalSignature
Definition: tls.h:1755
Arbitrary precision integer.
Definition: mpi.h:102
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256
Definition: tls.h:1277
@ ERROR_NOT_IMPLEMENTED
Definition: error.h:66
@ ERROR_ILLEGAL_PARAMETER
Definition: error.h:244
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.
ECDSA (Elliptic Curve Digital Signature Algorithm)
error_t dsaImportSignature(DsaSignature *signature, const uint8_t *data, size_t length)
Import an ASN.1 encoded DSA signature.
Definition: dsa.c:197
uint8_t p
Definition: ndp.h:300
const EcCurve * curve
Elliptic curve parameters.
Definition: ecdsa.h:64
uint8_t message[]
Definition: chap.h:154
error_t tls12VerifySignature(TlsContext *context, const uint8_t *p, size_t length)
Digital signature verification (TLS 1.2)
size_t digestSize
Definition: crypto.h:1088
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA512
Definition: tls.h:1282
#define ED25519_CURVE
Definition: ec_curves.h:72
#define ED448_SIGNATURE_LEN
Definition: ed448.h:44
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
#define ED448_CURVE
Definition: ec_curves.h:73
@ TLS_CERT_DSS_SIGN
Definition: tls.h:1213
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA512
Definition: tls.h:1279
#define ED25519_SIGNATURE_LEN
Definition: ed25519.h:44
Mpi e
Public exponent.
Definition: rsa.h:59
void mpiInit(Mpi *r)
Initialize a multiple precision integer.
Definition: mpi.c:48
#define TLS_HASH_ALGO(signScheme)
Definition: tls_sign_misc.h:41
Mpi n
Modulus.
Definition: rsa.h:58
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384
Definition: tls.h:1281
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384
Definition: tls.h:1278
void ecdsaFreeSignature(EcdsaSignature *signature)
Release an ECDSA signature.
Definition: ecdsa.c:86
@ TLS_HASH_ALGO_SHA512
Definition: tls.h:1243
@ ERROR_UNSUPPORTED_HASH_ALGO
Definition: error.h:130
bool_t tlsIsSignAlgoSupported(TlsContext *context, uint16_t signScheme)
Check whether a signature algorithm can be used for digital signatures.
error_t tlsVerifyRsaSignature(const RsaPublicKey *key, const uint8_t *digest, const uint8_t *signature, size_t signatureLen)
Verify RSA signature (TLS 1.0 and TLS 1.1)
#define TlsContext
Definition: tls.h:36
error_t
Error codes.
Definition: error.h:43
void dsaInitSignature(DsaSignature *signature)
Initialize a DSA signature.
Definition: dsa.c:168
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256
Definition: tls.h:1280
error_t ecdsaImportSignature(EcdsaSignature *signature, const EcCurve *curve, const uint8_t *data, size_t length, EcdsaSignatureFormat format)
Import an ECDSA signature.
Definition: ecdsa.c:104
error_t tlsVerifyDsaSignature(TlsContext *context, const uint8_t *digest, size_t digestLen, const uint8_t *signature, size_t signatureLen)
Verify DSA signature.
error_t tlsVerifyEd25519Signature(TlsContext *context, const DataChunk *message, uint_t messageLen, const uint8_t *signature, size_t signatureLen)
Verify Ed25519 signature.
Helper routines for ECC.
RSA public key.
Definition: rsa.h:57
void ecdsaInitSignature(EcdsaSignature *signature)
Initialize an ECDSA signature.
Definition: ecdsa.c:73
#define MD5_HASH_ALGO
Definition: md5.h:49
error_t mpiImport(Mpi *r, const uint8_t *input, size_t length, MpiFormat format)
Octet string to integer conversion.
Definition: mpi.c:712
Tls12DigitalSignature
Definition: tls.h:1767
@ TLS_HASH_ALGO_SHA384
Definition: tls.h:1242
EdDSA (Edwards-Curve Digital Signature Algorithm)
@ TLS_CERT_RSA_PSS_SIGN
Definition: tls.h:1224
@ ERROR_INVALID_LENGTH
Definition: error.h:111
RSA public-key cryptography standard.
DSA (Digital Signature Algorithm)
@ TLS_HASH_ALGO_SHA256
Definition: tls.h:1241
error_t rsavp1(const RsaPublicKey *key, const Mpi *s, Mpi *m)
RSA verification primitive.
Definition: rsa_misc.c:189
@ TLS_CERT_RSA_SIGN
Definition: tls.h:1212
error_t mpiExport(const Mpi *a, uint8_t *output, size_t length, MpiFormat format)
Integer to octet string conversion.
Definition: mpi.c:809
uint8_t length
Definition: tcp.h:375
#define MD5_DIGEST_SIZE
Definition: md5.h:45
RSA/DSA/ECDSA/EdDSA signature verification.
error_t tlsVerifyRsaEm(const uint8_t *digest, const uint8_t *em, size_t emLen)
Verify RSA encoded message.
Transcript hash calculation.
Data chunk descriptor.
Definition: crypto.h:1017
#define ntohs(value)
Definition: cpu_endian.h:421
error_t tlsVerifyEcdsaSignature(TlsContext *context, const uint8_t *digest, size_t digestLen, const uint8_t *signature, size_t signatureLen)
Verify ECDSA signature.
#define TRACE_DEBUG(...)
Definition: debug.h:119
error_t ed448VerifySignatureEx(const uint8_t *publicKey, const DataChunk *message, uint_t messageLen, const void *context, uint8_t contextLen, uint8_t flag, const uint8_t *signature)
EdDSA signature verification.
Definition: ed448.c:437
error_t dsaVerifySignature(const DsaPublicKey *key, const uint8_t *digest, size_t digestLen, const DsaSignature *signature)
DSA signature verification.
Definition: dsa.c:601
error_t rsassaPkcs1v15Verify(const RsaPublicKey *key, const HashAlgo *hash, const uint8_t *digest, const uint8_t *signature, size_t signatureLen)
RSASSA-PKCS1-v1_5 signature verification operation.
Definition: rsa.c:1068
Helper routines for RSA.
#define SHA1_DIGEST_SIZE
Definition: sha1.h:45
#define TRACE_DEBUG_ARRAY(p, a, n)
Definition: debug.h:120
@ ECDSA_SIGNATURE_FORMAT_ASN1
Definition: ecdsa.h:51
uint8_t m
Definition: ndp.h:304
uint8_t n
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:1309
__weak_func error_t ecdsaVerifySignature(const EcPublicKey *publicKey, const uint8_t *digest, size_t digestLen, const EcdsaSignature *signature)
ECDSA signature verification.
Definition: ecdsa.c:655
void dsaFreeSignature(DsaSignature *signature)
Release a DSA signature.
Definition: dsa.c:181
Helper functions for signature generation and verification.
@ MPI_FORMAT_BIG_ENDIAN
Definition: mpi.h:93
TLS (Transport Layer Security)
@ TLS_SIGN_ALGO_RSA
Definition: tls.h:1256
uint8_t s
Definition: igmp_common.h:234
@ TLS_CERT_ECDSA_SIGN
Definition: tls.h:1219
Common interface for hash algorithms.
Definition: crypto.h:1082
#define TLS_SIGN_ALGO(signScheme)
Definition: tls_sign_misc.h:38
DSA signature.
Definition: dsa.h:85
TlsSignatureScheme
Signature schemes.
Definition: tls.h:1271
error_t tlsVerifySignature(TlsContext *context, const uint8_t *p, size_t length)
Digital signature verification (TLS 1.0 and TLS 1.1)
@ ERROR_DECODING_FAILED
Definition: error.h:242
unsigned int uint_t
Definition: compiler_port.h:57
#define TRACE_DEBUG_MPI(p, a)
Definition: debug.h:122
#define tlsFreeMem(p)
Definition: tls.h:872
@ ERROR_INVALID_SIGNATURE
Definition: error.h:228
@ TLS_SIGN_ALGO_ECDSA
Definition: tls.h:1258
@ ERROR_INVALID_KEY
Definition: error.h:106
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
uint_t mpiGetByteLength(const Mpi *a)
Get the actual length in bytes.
Definition: mpi.c:215
void mpiFree(Mpi *r)
Release a multiple precision integer.
Definition: mpi.c:64
error_t ed25519VerifySignatureEx(const uint8_t *publicKey, const DataChunk *message, uint_t messageLen, const void *context, uint8_t contextLen, uint8_t flag, const uint8_t *signature)
EdDSA signature verification.
Definition: ed25519.c:459