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-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneSSL Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL TLS_TRACE_LEVEL
33 
34 //Dependencies
35 #include "tls.h"
36 #include "tls_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/dsa.h"
42 #include "ecc/ecdsa.h"
43 #include "ecc/eddsa.h"
44 #include "debug.h"
45 
46 //Check TLS library configuration
47 #if (TLS_SUPPORT == ENABLED)
48 
49 
50 /**
51  * @brief Digital signature verification (TLS 1.0 and TLS 1.1)
52  * @param[in] context Pointer to the TLS context
53  * @param[in] p Pointer to the digitally-signed element to be verified
54  * @param[in] length Length of the digitally-signed element
55  * @return Error code
56  **/
57 
58 error_t tlsVerifySignature(TlsContext *context, const uint8_t *p,
59  size_t length)
60 {
61 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_1)
62  error_t error;
63  const TlsDigitalSignature *signature;
64 
65  //The digitally-signed element does not convey the signature algorithm
66  //to use, and hence implementations need to inspect the certificate to
67  //find out the signature algorithm to use
68  signature = (TlsDigitalSignature *) p;
69 
70  //Check the length of the digitally-signed element
71  if(length < sizeof(TlsDigitalSignature))
72  return ERROR_DECODING_FAILED;
73  if(length != (sizeof(TlsDigitalSignature) + ntohs(signature->length)))
74  return ERROR_DECODING_FAILED;
75 
76 #if (TLS_RSA_SIGN_SUPPORT == ENABLED)
77  //RSA certificate?
78  if(context->peerCertType == TLS_CERT_RSA_SIGN)
79  {
80  //Digest all the handshake messages starting at ClientHello using MD5
82  context->transcriptMd5Context, "", context->clientVerifyData);
83 
84  //Check status code
85  if(!error)
86  {
87  //Digest all the handshake messages starting at ClientHello using SHA-1
89  context->transcriptSha1Context, "",
90  context->clientVerifyData + MD5_DIGEST_SIZE);
91  }
92 
93  //Check status code
94  if(!error)
95  {
96  //Verify RSA signature using client's public key
97  error = tlsVerifyRsaSignature(&context->peerRsaPublicKey,
98  context->clientVerifyData, signature->value,
99  ntohs(signature->length));
100  }
101  }
102  else
103 #endif
104 #if (TLS_DSA_SIGN_SUPPORT == ENABLED)
105  //DSA certificate?
106  if(context->peerCertType == TLS_CERT_DSS_SIGN)
107  {
108  //Digest all the handshake messages starting at ClientHello
109  error = tlsFinalizeTranscriptHash(context, SHA1_HASH_ALGO,
110  context->transcriptSha1Context, "", context->clientVerifyData);
111 
112  //Check status code
113  if(!error)
114  {
115  //Verify DSA signature using client's public key
116  error = tlsVerifyDsaSignature(context, context->clientVerifyData,
117  SHA1_DIGEST_SIZE, signature->value, ntohs(signature->length));
118  }
119  }
120  else
121 #endif
122 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
123  //ECDSA certificate?
124  if(context->peerCertType == TLS_CERT_ECDSA_SIGN)
125  {
126  //Digest all the handshake messages starting at ClientHello
127  error = tlsFinalizeTranscriptHash(context, SHA1_HASH_ALGO,
128  context->transcriptSha1Context, "", context->clientVerifyData);
129 
130  //Check status code
131  if(!error)
132  {
133  //Verify ECDSA signature using client's public key
134  error = tlsVerifyEcdsaSignature(context, context->clientVerifyData,
135  SHA1_DIGEST_SIZE, signature->value, ntohs(signature->length));
136  }
137  }
138  else
139 #endif
140  //Invalid signature algorithm?
141  {
142  //Report an error
143  error = ERROR_INVALID_SIGNATURE;
144  }
145 
146  //Return status code
147  return error;
148 #else
149  //Not implemented
150  return ERROR_NOT_IMPLEMENTED;
151 #endif
152 }
153 
154 
155 /**
156  * @brief Digital signature verification (TLS 1.2)
157  * @param[in] context Pointer to the TLS context
158  * @param[in] p Pointer to the digitally-signed element to be verified
159  * @param[in] length Length of the digitally-signed element
160  * @return Error code
161  **/
162 
163 error_t tls12VerifySignature(TlsContext *context, const uint8_t *p,
164  size_t length)
165 {
166 #if (TLS_MAX_VERSION >= TLS_VERSION_1_2 && TLS_MIN_VERSION <= TLS_VERSION_1_2)
167  error_t error;
168  TlsSignatureScheme signScheme;
169  const Tls12DigitalSignature *signature;
170  const HashAlgo *hashAlgo;
171 
172  //Point to the digitally-signed element
173  signature = (Tls12DigitalSignature *) p;
174 
175  //Check the length of the digitally-signed element
176  if(length < sizeof(Tls12DigitalSignature))
177  return ERROR_DECODING_FAILED;
178  if(length != (sizeof(Tls12DigitalSignature) + ntohs(signature->length)))
179  return ERROR_DECODING_FAILED;
180 
181  //The algorithm field specifies the signature scheme
182  signScheme = (TlsSignatureScheme) ntohs(signature->algorithm);
183 
184  //The certificates must be signed using an acceptable hash/signature
185  //algorithm pair (refer to RFC 5246, section 7.4.6)
186  if(!tlsIsSignAlgoSupported(context, signScheme))
188 
189  //Check signature scheme
190  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_RSA ||
191  TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_DSA ||
192  TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_ECDSA)
193  {
194  //Retrieve the hash algorithm used for signing
195  hashAlgo = tlsGetHashAlgo(TLS_HASH_ALGO(signScheme));
196  }
197  else if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256 ||
199  {
200  //The hashing is intrinsic to the signature algorithm
202  }
203  else if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384 ||
205  {
206  //The hashing is intrinsic to the signature algorithm
208  }
209  else if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA512 ||
211  {
212  //The hashing is intrinsic to the signature algorithm
214  }
215  else
216  {
217  //Unknown signature scheme
218  hashAlgo = NULL;
219  }
220 
221  //Digest all the handshake messages starting at ClientHello
222  if(hashAlgo == SHA1_HASH_ALGO)
223  {
224  //Use SHA-1 hash algorithm
225  error = tlsFinalizeTranscriptHash(context, SHA1_HASH_ALGO,
226  context->transcriptSha1Context, "", context->clientVerifyData);
227  }
228  else if(hashAlgo == context->cipherSuite.prfHashAlgo)
229  {
230  //Use PRF hash algorithm (SHA-256 or SHA-384)
231  error = tlsFinalizeTranscriptHash(context, hashAlgo,
232  context->transcriptHashContext, "", context->clientVerifyData);
233  }
234  else
235  {
236  //The specified hash algorithm is not supported
237  error = ERROR_INVALID_SIGNATURE;
238  }
239 
240  //Check status code
241  if(!error)
242  {
243 #if (TLS_RSA_SIGN_SUPPORT == ENABLED)
244  //RSASSA-PKCS1-v1_5 signature scheme?
245  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_RSA &&
246  context->peerCertType == TLS_CERT_RSA_SIGN)
247  {
248  //Verify RSA signature (RSASSA-PKCS1-v1_5 signature scheme)
249  error = rsassaPkcs1v15Verify(&context->peerRsaPublicKey,
250  hashAlgo, context->clientVerifyData, signature->value,
251  ntohs(signature->length));
252  }
253  else
254 #endif
255 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED)
256  //RSASSA-PSS signature scheme (with public key OID rsaEncryption)?
257  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256 ||
258  signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384 ||
260  {
261  //The signature algorithm must be compatible with the key in the
262  //server's end-entity certificate (refer to RFC 5246, section 7.4.3)
263  if(context->peerCertType == TLS_CERT_RSA_SIGN)
264  {
265  //Verify RSA signature (RSASSA-PSS signature scheme)
266  error = rsassaPssVerify(&context->peerRsaPublicKey, hashAlgo,
267  hashAlgo->digestSize, context->clientVerifyData,
268  signature->value, ntohs(signature->length));
269  }
270  else
271  {
272  //Invalid certificate
273  error = ERROR_INVALID_SIGNATURE;
274  }
275  }
276  else
277 #endif
278 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED)
279  //RSASSA-PSS signature scheme (with public key OID RSASSA-PSS)?
280  if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256 ||
281  signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384 ||
283  {
284  //The signature algorithm must be compatible with the key in the
285  //server's end-entity certificate (refer to RFC 5246, section 7.4.3)
286  if(context->peerCertType == TLS_CERT_RSA_PSS_SIGN)
287  {
288  //Verify RSA signature (RSASSA-PSS signature scheme)
289  error = rsassaPssVerify(&context->peerRsaPublicKey, hashAlgo,
290  hashAlgo->digestSize, context->clientVerifyData,
291  signature->value, ntohs(signature->length));
292  }
293  else
294  {
295  //Invalid certificate
296  error = ERROR_INVALID_SIGNATURE;
297  }
298  }
299  else
300 #endif
301 #if (TLS_DSA_SIGN_SUPPORT == ENABLED)
302  //DSA signature scheme?
303  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_DSA &&
304  context->peerCertType == TLS_CERT_DSS_SIGN)
305  {
306  //Verify DSA signature using client's public key
307  error = tlsVerifyDsaSignature(context, context->clientVerifyData,
308  hashAlgo->digestSize, signature->value, ntohs(signature->length));
309  }
310  else
311 #endif
312 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
313  //ECDSA signature scheme?
314  if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_ECDSA &&
315  context->peerCertType == TLS_CERT_ECDSA_SIGN)
316  {
317  //Verify ECDSA signature using client's public key
318  error = tlsVerifyEcdsaSignature(context, context->clientVerifyData,
319  hashAlgo->digestSize, signature->value, ntohs(signature->length));
320  }
321  else
322 #endif
323  //Invalid signature scheme?
324  {
325  //Report an error
326  error = ERROR_INVALID_SIGNATURE;
327  }
328  }
329 
330  //Return status code
331  return error;
332 #else
333  //Not implemented
334  return ERROR_NOT_IMPLEMENTED;
335 #endif
336 }
337 
338 
339 /**
340  * @brief Verify RSA signature (TLS 1.0 and TLS 1.1)
341  * @param[in] key Signer's RSA public key
342  * @param[in] digest Digest of the message whose signature is to be verified
343  * @param[in] signature Signature to be verified
344  * @param[in] signatureLen Length of the signature to be verified
345  * @return Error code
346  **/
347 
349  const uint8_t *digest, const uint8_t *signature, size_t signatureLen)
350 {
351 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_1 && \
352  TLS_RSA_SIGN_SUPPORT == ENABLED)
353  error_t error;
354  uint_t k;
355  uint8_t *em;
356  Mpi s;
357  Mpi m;
358 
359  //Debug message
360  TRACE_DEBUG("RSA signature verification...\r\n");
361  TRACE_DEBUG(" Modulus:\r\n");
362  TRACE_DEBUG_MPI(" ", &key->n);
363  TRACE_DEBUG(" Public exponent:\r\n");
364  TRACE_DEBUG_MPI(" ", &key->e);
365  TRACE_DEBUG(" Message digest:\r\n");
367  TRACE_DEBUG(" Signature:\r\n");
368  TRACE_DEBUG_ARRAY(" ", signature, signatureLen);
369 
370  //Get the length in octets of the modulus n
371  k = mpiGetByteLength(&key->n);
372 
373  //Check the length of the signature
374  if(signatureLen != k)
376 
377  //Initialize multiple-precision integers
378  mpiInit(&s);
379  mpiInit(&m);
380 
381  //Allocate a memory buffer to hold the encoded message
382  em = tlsAllocMem(k);
383  //Failed to allocate memory?
384  if(em == NULL)
385  return ERROR_OUT_OF_MEMORY;
386 
387  //Start of exception handling block
388  do
389  {
390  //Convert the signature to an integer signature representative s
391  error = mpiImport(&s, signature, signatureLen, MPI_FORMAT_BIG_ENDIAN);
392  //Conversion failed?
393  if(error)
394  break;
395 
396  //Apply the RSAVP1 verification primitive
397  error = rsavp1(key, &s, &m);
398  //Any error to report?
399  if(error)
400  break;
401 
402  //Convert the message representative m to an encoded message EM of
403  //length k octets
404  error = mpiExport(&m, em, k, MPI_FORMAT_BIG_ENDIAN);
405  //Conversion failed?
406  if(error)
407  break;
408 
409  //Debug message
410  TRACE_DEBUG(" Encoded message\r\n");
411  TRACE_DEBUG_ARRAY(" ", em, k);
412 
413  //Verify the encoded message EM
414  error = tlsVerifyRsaEm(digest, em, k);
415 
416  //End of exception handling block
417  } while(0);
418 
419  //Release multiple precision integers
420  mpiFree(&s);
421  mpiFree(&m);
422  //Release previously allocated memory
423  tlsFreeMem(em);
424 
425  //Return status code
426  return error;
427 #else
428  //RSA signature algorithm is not supported
429  return ERROR_NOT_IMPLEMENTED;
430 #endif
431 }
432 
433 
434 /**
435  * @brief Verify RSA encoded message
436  * @param[in] digest Digest value
437  * @param[in] em Encoded message
438  * @param[in] emLen Length of the encoded message
439  * @return Error code
440  **/
441 
442 error_t tlsVerifyRsaEm(const uint8_t *digest, const uint8_t *em, size_t emLen)
443 {
444 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_1 && \
445  TLS_RSA_SIGN_SUPPORT == ENABLED)
446  size_t i;
447  size_t j;
448  size_t n;
449  uint8_t bad;
450 
451  //Check the length of the encoded message
452  if(emLen < (MD5_DIGEST_SIZE + SHA1_DIGEST_SIZE + 11))
453  return ERROR_INVALID_LENGTH;
454 
455  //Point to the first byte of the encoded message
456  i = 0;
457 
458  //The first octet of EM must have hexadecimal value 0x00
459  bad = em[i++];
460  //The second octet of EM must have hexadecimal value 0x01
461  bad |= em[i++] ^ 0x01;
462 
463  //Determine the length of the padding string PS
464  n = emLen - MD5_DIGEST_SIZE - SHA1_DIGEST_SIZE - 3;
465 
466  //Each byte of PS must be set to 0xFF when the block type is 0x01
467  for(j = 0; j < n; j++)
468  {
469  bad |= em[i++] ^ 0xFF;
470  }
471 
472  //The padding string must be followed by a 0x00 octet
473  bad |= em[i++];
474 
475  //Recover the underlying hash value, and then compare it to the newly
476  //computed hash value
477  for(j = 0; j < (MD5_DIGEST_SIZE + SHA1_DIGEST_SIZE); j++)
478  {
479  bad |= em[i++] ^ digest[j];
480  }
481 
482  //Verification result
483  return (bad != 0) ? ERROR_INVALID_SIGNATURE : NO_ERROR;
484 #else
485  //RSA signature algorithm is not supported
486  return ERROR_NOT_IMPLEMENTED;
487 #endif
488 }
489 
490 
491 /**
492  * @brief Verify DSA signature
493  * @param[in] context Pointer to the TLS context
494  * @param[in] digest Digest of the message whose signature is to be verified
495  * @param[in] digestLen Length in octets of the digest
496  * @param[in] signature Signature to be verified
497  * @param[in] signatureLen Length of the signature to be verified
498  * @return Error code
499  **/
500 
501 error_t tlsVerifyDsaSignature(TlsContext *context, const uint8_t *digest,
502  size_t digestLen, const uint8_t *signature, size_t signatureLen)
503 {
504 #if (TLS_DSA_SIGN_SUPPORT == ENABLED)
505  error_t error;
506  DsaSignature dsaSignature;
507 
508  //Initialize DSA signature
509  dsaInitSignature(&dsaSignature);
510 
511  //Read the ASN.1 encoded DSA signature
512  error = dsaReadSignature(signature, signatureLen, &dsaSignature);
513 
514  //Check status code
515  if(!error)
516  {
517  //DSA signature verification
518  error = dsaVerifySignature(&context->peerDsaPublicKey,
519  digest, digestLen, &dsaSignature);
520  }
521  else
522  {
523  //Malformed DSA signature
524  error = ERROR_INVALID_SIGNATURE;
525  }
526 
527  //Free previously allocated resources
528  dsaFreeSignature(&dsaSignature);
529 
530  //Return status code
531  return error;
532 #else
533  //DSA signature algorithm is not supported
534  return ERROR_NOT_IMPLEMENTED;
535 #endif
536 }
537 
538 
539 /**
540  * @brief Verify ECDSA signature
541  * @param[in] context Pointer to the TLS context
542  * @param[in] digest Digest of the message whose signature is to be verified
543  * @param[in] digestLen Length in octets of the digest
544  * @param[in] signature Signature to be verified
545  * @param[in] signatureLen Length of the signature to be verified
546  * @return Error code
547  **/
548 
549 error_t tlsVerifyEcdsaSignature(TlsContext *context, const uint8_t *digest,
550  size_t digestLen, const uint8_t *signature, size_t signatureLen)
551 {
552 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
553  error_t error;
554  EcdsaSignature ecdsaSignature;
555 
556  //Initialize ECDSA signature
557  ecdsaInitSignature(&ecdsaSignature);
558 
559  //Read the ASN.1 encoded ECDSA signature
560  error = ecdsaReadSignature(signature, signatureLen, &ecdsaSignature);
561 
562  //Check status code
563  if(!error)
564  {
565 #if (TLS_ECC_CALLBACK_SUPPORT == ENABLED)
566  //Any registered callback?
567  if(context->ecdsaVerifyCallback != NULL)
568  {
569  //Invoke user callback function
570  error = context->ecdsaVerifyCallback(context, digest, digestLen,
571  &ecdsaSignature);
572  }
573  else
574 #endif
575  {
576  //No callback function defined
578  }
579 
580  //Check status code
581  if(error == ERROR_UNSUPPORTED_ELLIPTIC_CURVE ||
583  {
584  //ECDSA signature verification
585  error = ecdsaVerifySignature(&context->peerEcParams,
586  &context->peerEcPublicKey, digest, digestLen, &ecdsaSignature);
587  }
588  }
589  else
590  {
591  //Malformed ECDSA signature
592  error = ERROR_INVALID_SIGNATURE;
593  }
594 
595  //Free previously allocated resources
596  ecdsaFreeSignature(&ecdsaSignature);
597 
598  //Return status code
599  return error;
600 #else
601  //ECDSA signature algorithm is not supported
602  return ERROR_NOT_IMPLEMENTED;
603 #endif
604 }
605 
606 
607 /**
608  * @brief Verify Ed25519 signature
609  * @param[in] context Pointer to the TLS context
610  * @param[in] messageChunks Array of data chunks representing the message
611  * whose signature is to be verified
612  * @param[in] signature Signature to be verified
613  * @param[in] signatureLen Length of the signature to be verified
614  * @return Error code
615  **/
616 
618  const DataChunk *messageChunks, const uint8_t *signature,
619  size_t signatureLen)
620 {
621 #if (TLS_ED25519_SIGN_SUPPORT == ENABLED)
622  error_t error;
623  uint8_t publicKey[ED25519_PUBLIC_KEY_LEN];
624 
625  //Check the length of the EdDSA signature
626  if(signatureLen == ED25519_SIGNATURE_LEN)
627  {
628  //Get peer's public key
629  error = mpiExport(&context->peerEcPublicKey.q.x, publicKey,
631 
632  //Check status code
633  if(!error)
634  {
635  //Verify Ed25519 signature (PureEdDSA mode)
636  error = ed25519VerifySignatureEx(publicKey, messageChunks, NULL, 0, 0,
637  signature);
638  }
639  }
640  else
641  {
642  //The length of the EdDSA signature is not valid
643  error = ERROR_INVALID_SIGNATURE;
644  }
645 
646  //Return status code
647  return error;
648 #else
649  //Ed25519 signature algorithm is not supported
650  return ERROR_NOT_IMPLEMENTED;
651 #endif
652 }
653 
654 
655 /**
656  * @brief Verify Ed448 signature
657  * @param[in] context Pointer to the TLS context
658  * @param[in] messageChunks Array of data chunks representing the message
659  * whose signature is to be verified
660  * @param[in] signature Signature to be verified
661  * @param[in] signatureLen Length of the signature to be verified
662  * @return Error code
663  **/
664 
666  const DataChunk *messageChunks, const uint8_t *signature,
667  size_t signatureLen)
668 {
669 #if (TLS_ED448_SIGN_SUPPORT == ENABLED)
670  error_t error;
671  uint8_t publicKey[ED448_PUBLIC_KEY_LEN];
672 
673  //Check the length of the EdDSA signature
674  if(signatureLen == ED448_SIGNATURE_LEN)
675  {
676  //Get peer's public key
677  error = mpiExport(&context->peerEcPublicKey.q.x, publicKey,
679 
680  //Check status code
681  if(!error)
682  {
683  //Verify Ed448 signature (PureEdDSA mode)
684  error = ed448VerifySignatureEx(publicKey, messageChunks, NULL, 0, 0,
685  signature);
686  }
687  }
688  else
689  {
690  //The length of the EdDSA signature is not valid
691  error = ERROR_INVALID_SIGNATURE;
692  }
693 
694  //Return status code
695  return error;
696 #else
697  //Ed448 signature algorithm is not supported
698  return ERROR_NOT_IMPLEMENTED;
699 #endif
700 }
701 
702 #endif
#define tlsAllocMem(size)
Definition: tls.h:853
ECDSA signature.
Definition: ecdsa.h:49
@ TLS_SIGN_ALGO_DSA
Definition: tls.h:1233
TLS helper functions.
@ ERROR_UNSUPPORTED_ELLIPTIC_CURVE
Definition: error.h:133
#define SHA1_HASH_ALGO
Definition: sha1.h:49
const HashAlgo * tlsGetHashAlgo(TlsHashAlgo hashAlgoId)
Get the hash algorithm that matches the specified identifier.
Definition: tls_misc.c:1173
TlsDigitalSignature
Definition: tls.h:1717
Arbitrary precision integer.
Definition: mpi.h:80
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256
Definition: tls.h:1253
@ ERROR_NOT_IMPLEMENTED
Definition: error.h:66
@ ERROR_ILLEGAL_PARAMETER
Definition: error.h:243
#define ED25519_PUBLIC_KEY_LEN
Definition: ed25519.h:42
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)
uint8_t p
Definition: ndp.h:300
error_t tls12VerifySignature(TlsContext *context, const uint8_t *p, size_t length)
Digital signature verification (TLS 1.2)
#define ED448_PUBLIC_KEY_LEN
Definition: ed448.h:42
size_t digestSize
Definition: crypto.h:1052
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA512
Definition: tls.h:1258
#define ED448_SIGNATURE_LEN
Definition: ed448.h:44
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
@ TLS_CERT_DSS_SIGN
Definition: tls.h:1189
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA512
Definition: tls.h:1255
#define ED25519_SIGNATURE_LEN
Definition: ed25519.h:44
Mpi e
Public exponent.
Definition: rsa.h:59
error_t mpiImport(Mpi *r, const uint8_t *data, uint_t length, MpiFormat format)
Octet string to integer conversion.
Definition: mpi.c:624
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:1257
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384
Definition: tls.h:1254
void ecdsaFreeSignature(EcdsaSignature *signature)
Release an ECDSA signature.
Definition: ecdsa.c:82
@ TLS_HASH_ALGO_SHA512
Definition: tls.h:1219
@ 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)
error_t mpiExport(const Mpi *a, uint8_t *data, uint_t length, MpiFormat format)
Integer to octet string conversion.
Definition: mpi.c:709
#define TlsContext
Definition: tls.h:36
@ MPI_FORMAT_LITTLE_ENDIAN
Definition: mpi.h:70
error_t
Error codes.
Definition: error.h:43
void dsaInitSignature(DsaSignature *signature)
Initialize a DSA signature.
Definition: dsa.c:164
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256
Definition: tls.h:1256
error_t rsavp1(const RsaPublicKey *key, const Mpi *s, Mpi *m)
RSA verification primitive.
Definition: rsa.c:1323
error_t tlsVerifyDsaSignature(TlsContext *context, const uint8_t *digest, size_t digestLen, const uint8_t *signature, size_t signatureLen)
Verify DSA signature.
RSA public key.
Definition: rsa.h:57
void ecdsaInitSignature(EcdsaSignature *signature)
Initialize an ECDSA signature.
Definition: ecdsa.c:69
__weak_func error_t ecdsaVerifySignature(const EcDomainParameters *params, const EcPublicKey *publicKey, const uint8_t *digest, size_t digestLen, const EcdsaSignature *signature)
ECDSA signature verification.
Definition: ecdsa.c:507
#define MD5_HASH_ALGO
Definition: md5.h:49
Tls12DigitalSignature
Definition: tls.h:1729
@ TLS_HASH_ALGO_SHA384
Definition: tls.h:1218
EdDSA (Edwards-Curve Digital Signature Algorithm)
@ TLS_CERT_RSA_PSS_SIGN
Definition: tls.h:1200
@ ERROR_INVALID_LENGTH
Definition: error.h:111
error_t ed448VerifySignatureEx(const uint8_t *publicKey, const DataChunk *messageChunks, const void *context, uint8_t contextLen, uint8_t flag, const uint8_t *signature)
EdDSA signature verification.
Definition: ed448.c:438
RSA public-key cryptography standard.
DSA (Digital Signature Algorithm)
@ TLS_HASH_ALGO_SHA256
Definition: tls.h:1217
@ TLS_CERT_RSA_SIGN
Definition: tls.h:1188
uint8_t length
Definition: tcp.h:368
#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:981
#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:107
error_t dsaVerifySignature(const DsaPublicKey *key, const uint8_t *digest, size_t digestLen, const DsaSignature *signature)
DSA signature verification.
Definition: dsa.c:585
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:838
#define SHA1_DIGEST_SIZE
Definition: sha1.h:45
#define TRACE_DEBUG_ARRAY(p, a, n)
Definition: debug.h:108
error_t tlsVerifyEd25519Signature(TlsContext *context, const DataChunk *messageChunks, const uint8_t *signature, size_t signatureLen)
Verify Ed25519 signature.
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:1079
error_t ed25519VerifySignatureEx(const uint8_t *publicKey, const DataChunk *messageChunks, const void *context, uint8_t contextLen, uint8_t flag, const uint8_t *signature)
EdDSA signature verification.
Definition: ed25519.c:463
void dsaFreeSignature(DsaSignature *signature)
Release a DSA signature.
Definition: dsa.c:177
Helper functions for signature generation and verification.
error_t dsaReadSignature(const uint8_t *data, size_t length, DsaSignature *signature)
Read an ASN.1 encoded DSA signature.
Definition: dsa.c:349
@ MPI_FORMAT_BIG_ENDIAN
Definition: mpi.h:71
TLS (Transport Layer Security)
@ TLS_SIGN_ALGO_RSA
Definition: tls.h:1232
uint8_t s
Definition: igmp_common.h:234
@ TLS_CERT_ECDSA_SIGN
Definition: tls.h:1195
error_t ecdsaReadSignature(const uint8_t *data, size_t length, EcdsaSignature *signature)
Read an ASN.1 encoded ECDSA signature.
Definition: ecdsa.c:260
Common interface for hash algorithms.
Definition: crypto.h:1046
#define TLS_SIGN_ALGO(signScheme)
Definition: tls_sign_misc.h:38
DSA signature.
Definition: dsa.h:84
TlsSignatureScheme
Signature schemes.
Definition: tls.h:1247
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:241
unsigned int uint_t
Definition: compiler_port.h:50
#define TRACE_DEBUG_MPI(p, a)
Definition: debug.h:110
#define tlsFreeMem(p)
Definition: tls.h:858
@ ERROR_INVALID_SIGNATURE
Definition: error.h:227
@ TLS_SIGN_ALGO_ECDSA
Definition: tls.h:1234
error_t tlsVerifyEd448Signature(TlsContext *context, const DataChunk *messageChunks, const uint8_t *signature, size_t signatureLen)
Verify Ed448 signature.
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
uint_t mpiGetByteLength(const Mpi *a)
Get the actual length in bytes.
Definition: mpi.c:195
void mpiFree(Mpi *r)
Release a multiple precision integer.
Definition: mpi.c:64