x509_signature.c
Go to the documentation of this file.
1 /**
2  * @file x509_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 CycloneCRYPTO 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.2.2
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "pkix/x509_key_parse.h"
37 #include "pkix/x509_signature.h"
38 #include "pkc/rsa.h"
39 #include "pkc/dsa.h"
40 #include "ecc/ecdsa.h"
41 #include "ecc/eddsa.h"
42 #include "debug.h"
43 
44 //Check crypto library configuration
45 #if (X509_SUPPORT == ENABLED)
46 
47 //Signature generation/verification callback functions
48 #if (X509_SIGN_CALLBACK_SUPPORT == ENABLED)
49  static X509SignGenCallback x509SignGenCallback = NULL;
50  static X509SignVerifyCallback x509SignVerifyCallback = NULL;
51 #endif
52 
53 
54 /**
55  * @brief Register signature generation callback function
56  * @param[in] callback Signature generation callback function
57  * @return Error code
58  **/
59 
61 {
62 #if (X509_SIGN_CALLBACK_SUPPORT == ENABLED)
63  //Save callback function
64  x509SignGenCallback = callback;
65  //Successful processing
66  return NO_ERROR;
67 #else
68  //Not implemented
69  return ERROR_NOT_IMPLEMENTED;
70 #endif
71 }
72 
73 
74 /**
75  * @brief Register signature verification callback function
76  * @param[in] callback Signature verification callback function
77  * @return Error code
78  **/
79 
81 {
82 #if (X509_SIGN_CALLBACK_SUPPORT == ENABLED)
83  //Save callback function
84  x509SignVerifyCallback = callback;
85  //Successful processing
86  return NO_ERROR;
87 #else
88  //Not implemented
89  return ERROR_NOT_IMPLEMENTED;
90 #endif
91 }
92 
93 
94 /**
95  * @brief Certificate signature generation
96  * @param[in] prngAlgo PRNG algorithm
97  * @param[in] prngContext Pointer to the PRNG context
98  * @param[in] tbsCert Pointer to the TBSCertificate to be signed
99  * @param[in] tbsCertLen Length of the TBSCertificate, in bytes
100  * @param[in] signatureAlgoId Signature algorithm identifier
101  * @param[in] publicKeyInfo Signer's public key information
102  * @param[in] privateKey Signer's private key
103  * @param[out] output Resulting signature
104  * @param[out] written Length of the resulting signature
105  * @return Error code
106  **/
107 
108 error_t x509GenerateSignature(const PrngAlgo *prngAlgo, void *prngContext,
109  const uint8_t *tbsCert, size_t tbsCertLen, const X509SignatureAlgoId *signatureAlgoId,
110  const X509SubjectPublicKeyInfo *publicKeyInfo, const void *privateKey,
111  uint8_t *output, size_t *written)
112 {
113  error_t error;
114  X509SignatureAlgo signAlgo;
115  const HashAlgo *hashAlgo;
116 
117 #if (X509_SIGN_CALLBACK_SUPPORT == ENABLED)
118  //Valid signature generation callback function?
119  if(x509SignGenCallback != NULL)
120  {
121  //Invoke user-defined callback
122  error = x509SignGenCallback(prngAlgo, prngContext, tbsCert, tbsCertLen,
123  signatureAlgoId, publicKeyInfo, privateKey, output, written);
124  }
125  else
126 #endif
127  {
128  //No callback function registered
130  }
131 
132  //Check status code
133  if(error == ERROR_UNSUPPORTED_SIGNATURE_ALGO ||
134  error == ERROR_UNKOWN_KEY)
135  {
136  //Retrieve the signature algorithm that will be used to sign the
137  //certificate
138  error = x509GetSignHashAlgo(signatureAlgoId, &signAlgo, &hashAlgo);
139 
140  //Check status code
141  if(!error)
142  {
143 #if (X509_RSA_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
144  //RSA signature algorithm?
145  if(signAlgo == X509_SIGN_ALGO_RSA)
146  {
147  //Generate RSA signature (RSASSA-PKCS1-v1_5 signature scheme)
148  error = x509GenerateRsaSignature(tbsCert, tbsCertLen, hashAlgo,
149  privateKey, output, written);
150  }
151  else
152 #endif
153 #if (X509_RSA_PSS_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
154  //RSA-PSS signature algorithm?
155  if(signAlgo == X509_SIGN_ALGO_RSA_PSS)
156  {
157  //Generate RSA signature (RSASSA-PSS signature scheme)
158  error = x509GenerateRsaPssSignature(prngAlgo, prngContext, tbsCert,
159  tbsCertLen, hashAlgo, signatureAlgoId->rsaPssParams.saltLen,
160  privateKey, output, written);
161  }
162  else
163 #endif
164 #if (X509_DSA_SUPPORT == ENABLED && DSA_SUPPORT == ENABLED)
165  //DSA signature algorithm?
166  if(signAlgo == X509_SIGN_ALGO_DSA)
167  {
168  //Generate DSA signature
169  error = x509GenerateDsaSignature(prngAlgo, prngContext, tbsCert,
170  tbsCertLen, hashAlgo, privateKey, output, written);
171  }
172  else
173 #endif
174 #if (X509_ECDSA_SUPPORT == ENABLED && ECDSA_SUPPORT == ENABLED)
175  //ECDSA signature algorithm?
176  if(signAlgo == X509_SIGN_ALGO_ECDSA)
177  {
178  //Generate ECDSA signature
179  error = x509GenerateEcdsaSignature(prngAlgo, prngContext, tbsCert,
180  tbsCertLen, hashAlgo, publicKeyInfo, privateKey, output,
181  written);
182  }
183  else
184 #endif
185 #if (X509_ED25519_SUPPORT == ENABLED && ED25519_SUPPORT == ENABLED)
186  //Ed25519 signature algorithm?
187  if(signAlgo == X509_SIGN_ALGO_ED25519)
188  {
189  //Generate Ed25519 signature (PureEdDSA mode)
190  error = x509GenerateEd25519Signature(tbsCert, tbsCertLen,
191  privateKey, output, written);
192  }
193  else
194 #endif
195 #if (X509_ED448_SUPPORT == ENABLED && ED448_SUPPORT == ENABLED)
196  //Ed448 signature algorithm?
197  if(signAlgo == X509_SIGN_ALGO_ED448)
198  {
199  //Generate Ed448 signature (PureEdDSA mode)
200  error = x509GenerateEd448Signature(tbsCert, tbsCertLen, privateKey,
201  output, written);
202  }
203  else
204 #endif
205  //Invalid signature algorithm?
206  {
207  //Report an error
209  }
210  }
211  }
212 
213  //Return status code
214  return error;
215 }
216 
217 
218 /**
219  * @brief RSA signature generation
220  * @param[in] tbsCert Pointer to the TBSCertificate to be signed
221  * @param[in] tbsCertLen Length of the TBSCertificate, in bytes
222  * @param[in] hashAlgo Underlying hash function
223  * @param[in] privateKey Signer's private key
224  * @param[out] output Resulting signature
225  * @param[out] written Length of the resulting signature
226  * @return Error code
227  **/
228 
229 error_t x509GenerateRsaSignature(const uint8_t *tbsCert, size_t tbsCertLen,
230  const HashAlgo *hashAlgo, const RsaPrivateKey *privateKey, uint8_t *output,
231  size_t *written)
232 {
233 #if (X509_RSA_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
234  error_t error;
235  uint8_t digest[MAX_HASH_DIGEST_SIZE];
236 
237  //Digest the TBSCertificate structure using the specified hash algorithm
238  error = hashAlgo->compute(tbsCert, tbsCertLen, digest);
239 
240  //Check status code
241  if(!error)
242  {
243  //Generate RSA signature
244  error = rsassaPkcs1v15Sign(privateKey, hashAlgo, digest, output,
245  written);
246  }
247 
248  //Return status code
249  return error;
250 #else
251  //Not implemented
252  return ERROR_NOT_IMPLEMENTED;
253 #endif
254 }
255 
256 
257 /**
258  * @brief RSA-PSS signature generation
259  * @param[in] prngAlgo PRNG algorithm
260  * @param[in] prngContext Pointer to the PRNG context
261  * @param[in] tbsCert Pointer to the TBSCertificate to be signed
262  * @param[in] tbsCertLen Length of the TBSCertificate, in bytes
263  * @param[in] hashAlgo Underlying hash function
264  * @param[in] saltLen Length of the salt, in bytes
265  * @param[in] privateKey Signer's private key
266  * @param[out] output Resulting signature
267  * @param[out] written Length of the resulting signature
268  * @return Error code
269  **/
270 
271 error_t x509GenerateRsaPssSignature(const PrngAlgo *prngAlgo, void *prngContext,
272  const uint8_t *tbsCert, size_t tbsCertLen, const HashAlgo *hashAlgo,
273  size_t saltLen, const RsaPrivateKey *privateKey, uint8_t *output,
274  size_t *written)
275 {
276 #if (X509_RSA_PSS_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
277  error_t error;
278  uint8_t digest[MAX_HASH_DIGEST_SIZE];
279 
280  //Digest the TBSCertificate structure using the specified hash algorithm
281  error = hashAlgo->compute(tbsCert, tbsCertLen, digest);
282 
283  //Check status code
284  if(!error)
285  {
286  //Generate RSA-PSS signature
287  error = rsassaPssSign(prngAlgo, prngContext, privateKey, hashAlgo,
288  saltLen, digest, output, written);
289  }
290 
291  //Return status code
292  return error;
293 #else
294  //Not implemented
295  return ERROR_NOT_IMPLEMENTED;
296 #endif
297 }
298 
299 
300 /**
301  * @brief DSA signature generation
302  * @param[in] prngAlgo PRNG algorithm
303  * @param[in] prngContext Pointer to the PRNG context
304  * @param[in] tbsCert Pointer to the TBSCertificate to be signed
305  * @param[in] tbsCertLen Length of the TBSCertificate, in bytes
306  * @param[in] hashAlgo Underlying hash function
307  * @param[in] privateKey Signer's private key
308  * @param[out] output Resulting signature
309  * @param[out] written Length of the resulting signature
310  * @return Error code
311  **/
312 
313 error_t x509GenerateDsaSignature(const PrngAlgo *prngAlgo, void *prngContext,
314  const uint8_t *tbsCert, size_t tbsCertLen, const HashAlgo *hashAlgo,
315  const DsaPrivateKey *privateKey, uint8_t *output, size_t *written)
316 {
317 #if (X509_DSA_SUPPORT == ENABLED && DSA_SUPPORT == ENABLED)
318  error_t error;
320  uint8_t digest[MAX_HASH_DIGEST_SIZE];
321 
322  //Initialize DSA signature
324 
325  //Digest the TBSCertificate structure using the specified hash algorithm
326  error = hashAlgo->compute(tbsCert, tbsCertLen, digest);
327 
328  //Check status code
329  if(!error)
330  {
331  //Generate DSA signature
332  error = dsaGenerateSignature(prngAlgo, prngContext, privateKey, digest,
333  hashAlgo->digestSize, &signature);
334  }
335 
336  //Check status code
337  if(!error)
338  {
339  //Encode DSA signature using ASN.1
340  error = dsaWriteSignature(&signature, output, written);
341  }
342 
343  //Release previously allocated resources
345 
346  //Return status code
347  return error;
348 #else
349  //Not implemented
350  return ERROR_NOT_IMPLEMENTED;
351 #endif
352 }
353 
354 
355 /**
356  * @brief ECDSA signature generation
357  * @param[in] prngAlgo PRNG algorithm
358  * @param[in] prngContext Pointer to the PRNG context
359  * @param[in] tbsCert Pointer to the TBSCertificate to be signed
360  * @param[in] tbsCertLen Length of the TBSCertificate, in bytes
361  * @param[in] hashAlgo Underlying hash function
362  * @param[in] publicKeyInfo Signer's public key information
363  * @param[in] privateKey Signer's private key
364  * @param[out] output Resulting signature
365  * @param[out] written Length of the resulting signature
366  * @return Error code
367  **/
368 
369 error_t x509GenerateEcdsaSignature(const PrngAlgo *prngAlgo, void *prngContext,
370  const uint8_t *tbsCert, size_t tbsCertLen, const HashAlgo *hashAlgo,
371  const X509SubjectPublicKeyInfo *publicKeyInfo, const EcPrivateKey *privateKey,
372  uint8_t *output, size_t *written)
373 {
374 #if (X509_ECDSA_SUPPORT == ENABLED && ECDSA_SUPPORT == ENABLED)
375  error_t error;
376  const EcCurveInfo *curveInfo;
377  EcDomainParameters params;
379  uint8_t digest[MAX_HASH_DIGEST_SIZE];
380 
381  //Initialize EC domain parameters
382  ecInitDomainParameters(&params);
383  //Initialize ECDSA signature
385 
386  //Retrieve EC domain parameters
387  curveInfo = x509GetCurveInfo(publicKeyInfo->ecParams.namedCurve,
388  publicKeyInfo->ecParams.namedCurveLen);
389 
390  //Make sure the specified elliptic curve is supported
391  if(curveInfo != NULL)
392  {
393  //Load EC domain parameters
394  error = ecLoadDomainParameters(&params, curveInfo);
395  }
396  else
397  {
398  //Invalid EC domain parameters
399  error = ERROR_BAD_CERTIFICATE;
400  }
401 
402  //Check status code
403  if(!error)
404  {
405  //Digest the TBSCertificate structure using the specified hash algorithm
406  error = hashAlgo->compute(tbsCert, tbsCertLen, digest);
407  }
408 
409  //Check status code
410  if(!error)
411  {
412  //Generate ECDSA signature
413  error = ecdsaGenerateSignature(prngAlgo, prngContext, &params, privateKey,
414  digest, hashAlgo->digestSize, &signature);
415  }
416 
417  //Check status code
418  if(!error)
419  {
420  //Encode ECDSA signature using ASN.1
421  error = ecdsaWriteSignature(&signature, output, written);
422  }
423 
424  //Release previously allocated resources
425  ecFreeDomainParameters(&params);
427 
428  //Return status code
429  return error;
430 #else
431  //Not implemented
432  return ERROR_NOT_IMPLEMENTED;
433 #endif
434 }
435 
436 
437 /**
438  * @brief Ed25519 signature generation
439  * @param[in] tbsCert Pointer to the TBSCertificate to be signed
440  * @param[in] tbsCertLen Length of the TBSCertificate, in bytes
441  * @param[in] privateKey Signer's private key
442  * @param[out] output Resulting signature
443  * @param[out] written Length of the resulting signature
444  * @return Error code
445  **/
446 
447 error_t x509GenerateEd25519Signature(const uint8_t *tbsCert, size_t tbsCertLen,
448  const EddsaPrivateKey *privateKey, uint8_t *output, size_t *written)
449 {
450 #if (X509_ED25519_SUPPORT == ENABLED && ED25519_SUPPORT == ENABLED)
451  error_t error;
452 
453  //Check the length of the EdDSA private key
454  if(mpiGetByteLength(&privateKey->d) == ED25519_PRIVATE_KEY_LEN)
455  {
456  uint8_t d[ED25519_PRIVATE_KEY_LEN];
457 
458  //Retrieve private key
459  error = mpiExport(&privateKey->d, d, ED25519_PRIVATE_KEY_LEN,
461 
462  //Check status code
463  if(!error)
464  {
465  //Generate Ed25519 signature (PureEdDSA mode)
466  error = ed25519GenerateSignature(d, NULL, tbsCert, tbsCertLen,
467  NULL, 0, 0, output);
468  }
469 
470  //Length of the resulting EdDSA signature
471  *written = ED25519_SIGNATURE_LEN;
472  }
473  else
474  {
475  //The length of the EdDSA private key is not valid
476  error = ERROR_INVALID_KEY;
477  }
478 
479  //Return status code
480  return error;
481 #else
482  //Not implemented
483  return ERROR_NOT_IMPLEMENTED;
484 #endif
485 }
486 
487 
488 /**
489  * @brief Ed448 signature generation
490  * @param[in] tbsCert Pointer to the TBSCertificate to be signed
491  * @param[in] tbsCertLen Length of the TBSCertificate, in bytes
492  * @param[in] privateKey Signer's private key
493  * @param[out] output Resulting signature
494  * @param[out] written Length of the resulting signature
495  * @return Error code
496  **/
497 
498 error_t x509GenerateEd448Signature(const uint8_t *tbsCert, size_t tbsCertLen,
499  const EddsaPrivateKey *privateKey, uint8_t *output, size_t *written)
500 {
501 #if (X509_ED448_SUPPORT == ENABLED && ED448_SUPPORT == ENABLED)
502  error_t error;
503 
504  //Check the length of the EdDSA private key
505  if(mpiGetByteLength(&privateKey->d) == ED448_PRIVATE_KEY_LEN)
506  {
507  uint8_t d[ED448_PRIVATE_KEY_LEN];
508 
509  //Retrieve private key
510  error = mpiExport(&privateKey->d, d, ED448_PRIVATE_KEY_LEN,
512 
513  //Check status code
514  if(!error)
515  {
516  //Generate Ed448 signature (PureEdDSA mode)
517  error = ed448GenerateSignature(d, NULL, tbsCert, tbsCertLen,
518  NULL, 0, 0, output);
519  }
520 
521  //Length of the resulting EdDSA signature
522  *written = ED448_SIGNATURE_LEN;
523  }
524  else
525  {
526  //The length of the EdDSA private key is not valid
527  error = ERROR_INVALID_KEY;
528  }
529 
530  //Return status code
531  return error;
532 #else
533  //Not implemented
534  return ERROR_NOT_IMPLEMENTED;
535 #endif
536 }
537 
538 
539 /**
540  * @brief Certificate signature verification
541  * @param[in] tbsCert TBSCertificate whose signature is to be verified
542  * @param[in] tbsCertLen Length of the TBSCertificate, in bytes
543  * @param[in] signatureAlgoId Signature algorithm identifier
544  * @param[in] publicKeyInfo Issuer's public key
545  * @param[in] signatureValue Signature to be verified
546  * @return Error code
547  **/
548 
549 error_t x509VerifySignature(const uint8_t *tbsCert, size_t tbsCertLen,
550  const X509SignatureAlgoId *signatureAlgoId,
551  const X509SubjectPublicKeyInfo *publicKeyInfo,
552  const X509SignatureValue *signatureValue)
553 {
554  error_t error;
555  X509SignatureAlgo signAlgo;
556  const HashAlgo *hashAlgo;
557 
558 #if (X509_SIGN_CALLBACK_SUPPORT == ENABLED)
559  //Valid signature verification callback function?
560  if(x509SignVerifyCallback != NULL)
561  {
562  //Invoke user-defined callback
563  error = x509SignVerifyCallback(tbsCert, tbsCertLen, signatureAlgoId,
564  publicKeyInfo, signatureValue);
565  }
566  else
567 #endif
568  {
569  //No callback function registered
571  }
572 
573  //Check status code
575  {
576  //Retrieve the signature algorithm that was used to sign the certificate
577  error = x509GetSignHashAlgo(signatureAlgoId, &signAlgo, &hashAlgo);
578 
579  //Check status code
580  if(!error)
581  {
582 #if (X509_RSA_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
583  //RSA signature algorithm?
584  if(signAlgo == X509_SIGN_ALGO_RSA)
585  {
586  //Verify RSA signature (RSASSA-PKCS1-v1_5 signature scheme)
587  error = x509VerifyRsaSignature(tbsCert, tbsCertLen, hashAlgo,
588  publicKeyInfo, signatureValue);
589  }
590  else
591 #endif
592 #if (X509_RSA_PSS_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
593  //RSA-PSS signature algorithm?
594  if(signAlgo == X509_SIGN_ALGO_RSA_PSS)
595  {
596  //Verify RSA signature (RSASSA-PSS signature scheme)
597  error = x509VerifyRsaPssSignature(tbsCert, tbsCertLen, hashAlgo,
598  signatureAlgoId->rsaPssParams.saltLen, publicKeyInfo,
599  signatureValue);
600  }
601  else
602 #endif
603 #if (X509_DSA_SUPPORT == ENABLED && DSA_SUPPORT == ENABLED)
604  //DSA signature algorithm?
605  if(signAlgo == X509_SIGN_ALGO_DSA)
606  {
607  //Verify DSA signature
608  error = x509VerifyDsaSignature(tbsCert, tbsCertLen, hashAlgo,
609  publicKeyInfo, signatureValue);
610  }
611  else
612 #endif
613 #if (X509_ECDSA_SUPPORT == ENABLED && ECDSA_SUPPORT == ENABLED)
614  //ECDSA signature algorithm?
615  if(signAlgo == X509_SIGN_ALGO_ECDSA)
616  {
617  //Verify ECDSA signature
618  error = x509VerifyEcdsaSignature(tbsCert, tbsCertLen, hashAlgo,
619  publicKeyInfo, signatureValue);
620  }
621  else
622 #endif
623 #if (X509_ED25519_SUPPORT == ENABLED && ED25519_SUPPORT == ENABLED)
624  //Ed25519 signature algorithm?
625  if(signAlgo == X509_SIGN_ALGO_ED25519)
626  {
627  //Verify Ed25519 signature (PureEdDSA mode)
628  error = x509VerifyEd25519Signature(tbsCert, tbsCertLen,
629  publicKeyInfo, signatureValue);
630  }
631  else
632 #endif
633 #if (X509_ED448_SUPPORT == ENABLED && ED448_SUPPORT == ENABLED)
634  //Ed448 signature algorithm?
635  if(signAlgo == X509_SIGN_ALGO_ED448)
636  {
637  //Verify Ed448 signature (PureEdDSA mode)
638  error = x509VerifyEd448Signature(tbsCert, tbsCertLen, publicKeyInfo,
639  signatureValue);
640  }
641  else
642 #endif
643  //Invalid signature algorithm?
644  {
645  //Report an error
647  }
648  }
649  }
650 
651  //Return status code
652  return error;
653 }
654 
655 
656 /**
657  * @brief RSA signature verification
658  * @param[in] tbsCert TBSCertificate whose signature is to be verified
659  * @param[in] tbsCertLen Length of the TBSCertificate, in bytes
660  * @param[in] hashAlgo Underlying hash function
661  * @param[in] publicKeyInfo Issuer's public key
662  * @param[in] signatureValue Signature to be verified
663  * @return Error code
664  **/
665 
666 error_t x509VerifyRsaSignature(const uint8_t *tbsCert, size_t tbsCertLen,
667  const HashAlgo *hashAlgo, const X509SubjectPublicKeyInfo *publicKeyInfo,
668  const X509SignatureValue *signatureValue)
669 {
670 #if (X509_RSA_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
671  error_t error;
672  uint_t k;
673  RsaPublicKey publicKey;
674  uint8_t digest[MAX_HASH_DIGEST_SIZE];
675 
676  //Initialize RSA public key
677  rsaInitPublicKey(&publicKey);
678 
679  //Digest the TBSCertificate structure using the specified hash algorithm
680  error = hashAlgo->compute(tbsCert, tbsCertLen, digest);
681 
682  //Check status code
683  if(!error)
684  {
685  //Import the RSA public key
686  error = x509ImportRsaPublicKey(publicKeyInfo, &publicKey);
687  }
688 
689  //Check status code
690  if(!error)
691  {
692  //Get the length of the modulus, in bits
693  k = mpiGetBitLength(&publicKey.n);
694 
695  //Make sure the modulus is acceptable
696  if(k < X509_MIN_RSA_MODULUS_SIZE || k > X509_MAX_RSA_MODULUS_SIZE)
697  {
698  //Report an error
699  error = ERROR_INVALID_KEY;
700  }
701  }
702 
703  //Check status code
704  if(!error)
705  {
706  //Verify RSA signature (RSASSA-PKCS1-v1_5 signature scheme)
707  error = rsassaPkcs1v15Verify(&publicKey, hashAlgo, digest,
708  signatureValue->data, signatureValue->length);
709  }
710 
711  //Release previously allocated resources
712  rsaFreePublicKey(&publicKey);
713 
714  //Return status code
715  return error;
716 #else
717  //Not implemented
718  return ERROR_NOT_IMPLEMENTED;
719 #endif
720 }
721 
722 
723 /**
724  * @brief RSA-PSS signature verification
725  * @param[in] tbsCert TBSCertificate whose signature is to be verified
726  * @param[in] tbsCertLen Length of the TBSCertificate, in bytes
727  * @param[in] hashAlgo Underlying hash function
728  * @param[in] saltLen Length of the salt, in bytes
729  * @param[in] publicKeyInfo Issuer's public key
730  * @param[in] signatureValue Signature to be verified
731  * @return Error code
732  **/
733 
734 error_t x509VerifyRsaPssSignature(const uint8_t *tbsCert, size_t tbsCertLen,
735  const HashAlgo *hashAlgo, size_t saltLen,
736  const X509SubjectPublicKeyInfo *publicKeyInfo,
737  const X509SignatureValue *signatureValue)
738 {
739 #if (X509_RSA_PSS_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
740  error_t error;
741  uint_t k;
742  RsaPublicKey publicKey;
743  uint8_t digest[MAX_HASH_DIGEST_SIZE];
744 
745  //Initialize RSA public key
746  rsaInitPublicKey(&publicKey);
747 
748  //Digest the TBSCertificate structure using the specified hash algorithm
749  error = hashAlgo->compute(tbsCert, tbsCertLen, digest);
750 
751  //Check status code
752  if(!error)
753  {
754  //Import the RSA public key
755  error = x509ImportRsaPublicKey(publicKeyInfo, &publicKey);
756  }
757 
758  //Check status code
759  if(!error)
760  {
761  //Get the length of the modulus, in bits
762  k = mpiGetBitLength(&publicKey.n);
763 
764  //Make sure the modulus is acceptable
765  if(k < X509_MIN_RSA_MODULUS_SIZE || k > X509_MAX_RSA_MODULUS_SIZE)
766  {
767  //Report an error
768  error = ERROR_INVALID_KEY;
769  }
770  }
771 
772  //Check status code
773  if(!error)
774  {
775  //Verify RSA signature (RSASSA-PSS signature scheme)
776  error = rsassaPssVerify(&publicKey, hashAlgo, saltLen, digest,
777  signatureValue->data, signatureValue->length);
778  }
779 
780  //Release previously allocated resources
781  rsaFreePublicKey(&publicKey);
782 
783  //Return status code
784  return error;
785 #else
786  //Not implemented
787  return ERROR_NOT_IMPLEMENTED;
788 #endif
789 }
790 
791 
792 /**
793  * @brief DSA signature verification
794  * @param[in] tbsCert TBSCertificate whose signature is to be verified
795  * @param[in] tbsCertLen Length of the TBSCertificate, in bytes
796  * @param[in] hashAlgo Underlying hash function
797  * @param[in] publicKeyInfo Issuer's public key
798  * @param[in] signatureValue Signature to be verified
799  * @return Error code
800  **/
801 
802 error_t x509VerifyDsaSignature(const uint8_t *tbsCert, size_t tbsCertLen,
803  const HashAlgo *hashAlgo, const X509SubjectPublicKeyInfo *publicKeyInfo,
804  const X509SignatureValue *signatureValue)
805 {
806 #if (X509_DSA_SUPPORT == ENABLED && DSA_SUPPORT == ENABLED)
807  error_t error;
808  uint_t k;
809  DsaPublicKey publicKey;
811  uint8_t digest[MAX_HASH_DIGEST_SIZE];
812 
813  //Initialize DSA public key
814  dsaInitPublicKey(&publicKey);
815  //Initialize DSA signature
817 
818  //Digest the TBSCertificate structure using the specified hash algorithm
819  error = hashAlgo->compute(tbsCert, tbsCertLen, digest);
820 
821  //Check status code
822  if(!error)
823  {
824  //Import the DSA public key
825  error = x509ImportDsaPublicKey(publicKeyInfo, &publicKey);
826  }
827 
828  //Check status code
829  if(!error)
830  {
831  //Get the length of the prime modulus, in bits
832  k = mpiGetBitLength(&publicKey.params.p);
833 
834  //Make sure the prime modulus is acceptable
835  if(k < X509_MIN_DSA_MODULUS_SIZE || k > X509_MAX_DSA_MODULUS_SIZE)
836  {
837  //Report an error
838  error = ERROR_INVALID_KEY;
839  }
840  }
841 
842  //Check status code
843  if(!error)
844  {
845  //Read the ASN.1 encoded signature
846  error = dsaReadSignature(signatureValue->data, signatureValue->length,
847  &signature);
848  }
849 
850  //Check status code
851  if(!error)
852  {
853  //Verify DSA signature
854  error = dsaVerifySignature(&publicKey, digest, hashAlgo->digestSize,
855  &signature);
856  }
857 
858  //Release previously allocated resources
859  dsaFreePublicKey(&publicKey);
861 
862  //Return status code
863  return error;
864 #else
865  //Not implemented
866  return ERROR_NOT_IMPLEMENTED;
867 #endif
868 }
869 
870 
871 /**
872  * @brief ECDSA signature verification
873  * @param[in] tbsCert TBSCertificate whose signature is to be verified
874  * @param[in] tbsCertLen Length of the TBSCertificate, in bytes
875  * @param[in] hashAlgo Underlying hash function
876  * @param[in] publicKeyInfo Issuer's public key
877  * @param[in] signatureValue Signature to be verified
878  * @return Error code
879  **/
880 
881 error_t x509VerifyEcdsaSignature(const uint8_t *tbsCert, size_t tbsCertLen,
882  const HashAlgo *hashAlgo, const X509SubjectPublicKeyInfo *publicKeyInfo,
883  const X509SignatureValue *signatureValue)
884 {
885 #if (X509_ECDSA_SUPPORT == ENABLED && ECDSA_SUPPORT == ENABLED)
886  error_t error;
887  const EcCurveInfo *curveInfo;
888  EcDomainParameters params;
889  EcPublicKey publicKey;
891  uint8_t digest[MAX_HASH_DIGEST_SIZE];
892 
893  //Initialize EC domain parameters
894  ecInitDomainParameters(&params);
895  //Initialize EC public key
896  ecInitPublicKey(&publicKey);
897  //Initialize ECDSA signature
899 
900  //Retrieve EC domain parameters
901  curveInfo = x509GetCurveInfo(publicKeyInfo->ecParams.namedCurve,
902  publicKeyInfo->ecParams.namedCurveLen);
903 
904  //Make sure the specified elliptic curve is supported
905  if(curveInfo != NULL)
906  {
907  //Load EC domain parameters
908  error = ecLoadDomainParameters(&params, curveInfo);
909  }
910  else
911  {
912  //Invalid EC domain parameters
913  error = ERROR_BAD_CERTIFICATE;
914  }
915 
916  //Check status code
917  if(!error)
918  {
919  //Digest the TBSCertificate structure using the specified hash algorithm
920  error = hashAlgo->compute(tbsCert, tbsCertLen, digest);
921  }
922 
923  //Check status code
924  if(!error)
925  {
926  //Retrieve the EC public key
927  error = ecImport(&params, &publicKey.q, publicKeyInfo->ecPublicKey.q,
928  publicKeyInfo->ecPublicKey.qLen);
929  }
930 
931  //Check status code
932  if(!error)
933  {
934  //Read the ASN.1 encoded signature
935  error = ecdsaReadSignature(signatureValue->data,
936  signatureValue->length, &signature);
937  }
938 
939  //Check status code
940  if(!error)
941  {
942  //Verify ECDSA signature
943  error = ecdsaVerifySignature(&params, &publicKey, digest,
944  hashAlgo->digestSize, &signature);
945  }
946 
947  //Release previously allocated resources
948  ecFreeDomainParameters(&params);
949  ecFreePublicKey(&publicKey);
951 
952  //Return status code
953  return error;
954 #else
955  //Not implemented
956  return ERROR_NOT_IMPLEMENTED;
957 #endif
958 }
959 
960 
961 /**
962  * @brief Ed25519 signature verification
963  * @param[in] tbsCert TBSCertificate whose signature is to be verified
964  * @param[in] tbsCertLen Length of the TBSCertificate, in bytes
965  * @param[in] publicKeyInfo Issuer's public key
966  * @param[in] signatureValue Signature to be verified
967  * @return Error code
968  **/
969 
970 error_t x509VerifyEd25519Signature(const uint8_t *tbsCert, size_t tbsCertLen,
971  const X509SubjectPublicKeyInfo *publicKeyInfo,
972  const X509SignatureValue *signatureValue)
973 {
974 #if (X509_ED25519_SUPPORT == ENABLED && ED25519_SUPPORT == ENABLED)
975  error_t error;
976 
977  //Check the length of the public key
978  if(publicKeyInfo->ecPublicKey.qLen == ED25519_PUBLIC_KEY_LEN)
979  {
980  //Check the length of the EdDSA signature
981  if(signatureValue->length == ED25519_SIGNATURE_LEN)
982  {
983  //Verify signature (PureEdDSA mode)
984  error = ed25519VerifySignature(publicKeyInfo->ecPublicKey.q,
985  tbsCert, tbsCertLen, NULL, 0, 0, signatureValue->data);
986  }
987  else
988  {
989  //The length of the EdDSA signature is not valid
990  error = ERROR_INVALID_SIGNATURE;
991  }
992  }
993  else
994  {
995  //The length of the Ed25519 public key is not valid
996  error = ERROR_ILLEGAL_PARAMETER;
997  }
998 
999  //Return status code
1000  return error;
1001 #else
1002  //Not implemented
1003  return ERROR_NOT_IMPLEMENTED;
1004 #endif
1005 }
1006 
1007 
1008 /**
1009  * @brief Ed448 signature verification
1010  * @param[in] tbsCert TBSCertificate whose signature is to be verified
1011  * @param[in] tbsCertLen Length of the TBSCertificate, in bytes
1012  * @param[in] publicKeyInfo Issuer's public key
1013  * @param[in] signatureValue Signature to be verified
1014  * @return Error code
1015  **/
1016 
1017 error_t x509VerifyEd448Signature(const uint8_t *tbsCert, size_t tbsCertLen,
1018  const X509SubjectPublicKeyInfo *publicKeyInfo,
1019  const X509SignatureValue *signatureValue)
1020 {
1021 #if (X509_ED448_SUPPORT == ENABLED && ED448_SUPPORT == ENABLED)
1022  error_t error;
1023 
1024  //Check the length of the public key
1025  if(publicKeyInfo->ecPublicKey.qLen == ED448_PUBLIC_KEY_LEN)
1026  {
1027  //Check the length of the EdDSA signature
1028  if(signatureValue->length == ED448_SIGNATURE_LEN)
1029  {
1030  //Verify signature (PureEdDSA mode)
1031  error = ed448VerifySignature(publicKeyInfo->ecPublicKey.q,
1032  tbsCert, tbsCertLen, NULL, 0, 0, signatureValue->data);
1033  }
1034  else
1035  {
1036  //The length of the EdDSA signature is not valid
1037  error = ERROR_INVALID_SIGNATURE;
1038  }
1039  }
1040  else
1041  {
1042  //The length of the Ed448 public key is not valid
1043  error = ERROR_ILLEGAL_PARAMETER;
1044  }
1045 
1046  //Return status code
1047  return error;
1048 #else
1049  //Not implemented
1050  return ERROR_NOT_IMPLEMENTED;
1051 #endif
1052 }
1053 
1054 #endif
error_t x509VerifyEd448Signature(const uint8_t *tbsCert, size_t tbsCertLen, const X509SubjectPublicKeyInfo *publicKeyInfo, const X509SignatureValue *signatureValue)
Ed448 signature verification.
error_t x509VerifySignature(const uint8_t *tbsCert, size_t tbsCertLen, const X509SignatureAlgoId *signatureAlgoId, const X509SubjectPublicKeyInfo *publicKeyInfo, const X509SignatureValue *signatureValue)
Certificate signature verification.
ECDSA signature.
Definition: ecdsa.h:49
void rsaFreePublicKey(RsaPublicKey *key)
Release an RSA public key.
Definition: rsa.c:118
const EcCurveInfo * x509GetCurveInfo(const uint8_t *oid, size_t length)
Get the elliptic curve that matches the specified OID.
Definition: x509_common.c:843
const uint8_t * data
Definition: x509_common.h:899
error_t x509ImportRsaPublicKey(const X509SubjectPublicKeyInfo *publicKeyInfo, RsaPublicKey *publicKey)
Import an RSA public key.
Signature algorithm identifier.
Definition: x509_common.h:884
#define PrngAlgo
Definition: crypto.h:840
@ ERROR_NOT_IMPLEMENTED
Definition: error.h:66
@ ERROR_ILLEGAL_PARAMETER
Definition: error.h:242
void ecInitDomainParameters(EcDomainParameters *params)
Initialize EC domain parameters.
Definition: ec.c:51
error_t ecImport(const EcDomainParameters *params, EcPoint *r, const uint8_t *data, size_t length)
Convert an octet string to an EC point.
Definition: ec.c:365
error_t x509GenerateSignature(const PrngAlgo *prngAlgo, void *prngContext, const uint8_t *tbsCert, size_t tbsCertLen, const X509SignatureAlgoId *signatureAlgoId, const X509SubjectPublicKeyInfo *publicKeyInfo, const void *privateKey, uint8_t *output, size_t *written)
Certificate signature generation.
#define ED25519_PUBLIC_KEY_LEN
Definition: ed25519.h:42
error_t x509VerifyRsaPssSignature(const uint8_t *tbsCert, size_t tbsCertLen, const HashAlgo *hashAlgo, size_t saltLen, const X509SubjectPublicKeyInfo *publicKeyInfo, const X509SignatureValue *signatureValue)
RSA-PSS signature verification.
ECDSA (Elliptic Curve Digital Signature Algorithm)
error_t(* X509SignGenCallback)(const PrngAlgo *prngAlgo, void *prngContext, const uint8_t *tbsCert, size_t tbsCertLen, const X509SignatureAlgoId *signatureAlgoId, const X509SubjectPublicKeyInfo *publicKeyInfo, const void *privateKey, uint8_t *output, size_t *written)
Signature generation callback function.
#define ED448_PUBLIC_KEY_LEN
Definition: ed448.h:42
error_t x509VerifyEcdsaSignature(const uint8_t *tbsCert, size_t tbsCertLen, const HashAlgo *hashAlgo, const X509SubjectPublicKeyInfo *publicKeyInfo, const X509SignatureValue *signatureValue)
ECDSA signature verification.
X509RsaPssParameters rsaPssParams
Definition: x509_common.h:888
size_t digestSize
Definition: crypto.h:943
uint8_t signature
Definition: tls.h:1455
X509EcParameters ecParams
Definition: x509_common.h:712
error_t ed448VerifySignature(const uint8_t *publicKey, const void *message, size_t messageLen, const void *context, uint8_t contextLen, uint8_t flag, const uint8_t *signature)
EdDSA signature verification.
Definition: ed448.c:386
RSA/DSA/ECDSA/EdDSA signature generation and verification.
#define ED448_SIGNATURE_LEN
Definition: ed448.h:44
error_t x509GetSignHashAlgo(const X509SignatureAlgoId *signAlgoId, X509SignatureAlgo *signAlgo, const HashAlgo **hashAlgo)
Get the signature and hash algorithms that match the specified identifier.
Definition: x509_common.c:320
const uint8_t * q
Definition: x509_common.h:689
#define ED25519_SIGNATURE_LEN
Definition: ed25519.h:44
Mpi p
Prime modulus.
Definition: dsa.h:50
EC domain parameters.
Definition: ec.h:76
void ecFreeDomainParameters(EcDomainParameters *params)
Release EC domain parameters.
Definition: ec.c:72
#define ED25519_PRIVATE_KEY_LEN
Definition: ed25519.h:40
Mpi n
Modulus.
Definition: rsa.h:51
void ecdsaFreeSignature(EcdsaSignature *signature)
Release an ECDSA signature.
Definition: ecdsa.c:82
error_t x509GenerateEd25519Signature(const uint8_t *tbsCert, size_t tbsCertLen, const EddsaPrivateKey *privateKey, uint8_t *output, size_t *written)
Ed25519 signature generation.
#define MAX_HASH_DIGEST_SIZE
error_t ecLoadDomainParameters(EcDomainParameters *params, const EcCurveInfo *curveInfo)
Load EC domain parameters.
Definition: ec.c:90
X509SignatureAlgo
Signature algorithms.
Definition: x509_common.h:513
Elliptic curve parameters.
Definition: ec_curves.h:293
error_t ed25519GenerateSignature(const uint8_t *privateKey, const uint8_t *publicKey, const void *message, size_t messageLen, const void *context, uint8_t contextLen, uint8_t flag, uint8_t *signature)
EdDSA signature generation.
Definition: ed25519.c:227
error_t x509RegisterSignVerifyCallback(X509SignVerifyCallback callback)
Register signature verification callback function.
error_t mpiExport(const Mpi *a, uint8_t *data, uint_t length, MpiFormat format)
Integer to octet string conversion.
Definition: mpi.c:662
DSA public key.
Definition: dsa.h:61
__weak_func error_t ecdsaGenerateSignature(const PrngAlgo *prngAlgo, void *prngContext, const EcDomainParameters *params, const EcPrivateKey *privateKey, const uint8_t *digest, size_t digestLen, EcdsaSignature *signature)
ECDSA signature generation.
Definition: ecdsa.c:397
error_t x509ImportDsaPublicKey(const X509SubjectPublicKeyInfo *publicKeyInfo, DsaPublicKey *publicKey)
Import a DSA public key.
@ MPI_FORMAT_LITTLE_ENDIAN
Definition: mpi.h:60
error_t
Error codes.
Definition: error.h:43
void dsaInitSignature(DsaSignature *signature)
Initialize a DSA signature.
Definition: dsa.c:164
void ecInitPublicKey(EcPublicKey *key)
Initialize an EC public key.
Definition: ec.c:153
HashAlgoCompute compute
Definition: crypto.h:946
error_t x509VerifyRsaSignature(const uint8_t *tbsCert, size_t tbsCertLen, const HashAlgo *hashAlgo, const X509SubjectPublicKeyInfo *publicKeyInfo, const X509SignatureValue *signatureValue)
RSA signature verification.
@ X509_SIGN_ALGO_ECDSA
Definition: x509_common.h:518
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:923
RSA public key.
Definition: rsa.h:50
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
error_t dsaGenerateSignature(const PrngAlgo *prngAlgo, void *prngContext, const DsaPrivateKey *key, const uint8_t *digest, size_t digestLen, DsaSignature *signature)
DSA signature generation.
Definition: dsa.c:484
EdDSA (Edwards-Curve Digital Signature Algorithm)
#define X509_MAX_DSA_MODULUS_SIZE
Definition: x509_common.h:331
General definitions for cryptographic algorithms.
error_t x509GenerateEcdsaSignature(const PrngAlgo *prngAlgo, void *prngContext, const uint8_t *tbsCert, size_t tbsCertLen, const HashAlgo *hashAlgo, const X509SubjectPublicKeyInfo *publicKeyInfo, const EcPrivateKey *privateKey, uint8_t *output, size_t *written)
ECDSA signature generation.
RSA public-key cryptography standard.
@ ERROR_BAD_CERTIFICATE
Definition: error.h:234
DSA (Digital Signature Algorithm)
EC private key.
Definition: ec.h:104
DsaDomainParameters params
DSA domain parameters.
Definition: dsa.h:62
DSA private key.
Definition: dsa.h:72
size_t namedCurveLen
Definition: x509_common.h:679
error_t(* X509SignVerifyCallback)(const uint8_t *tbsCert, size_t tbsCertLen, const X509SignatureAlgoId *signatureAlgoId, const X509SubjectPublicKeyInfo *publicKeyInfo, const X509SignatureValue *signatureValue)
Signature verification callback function.
Signature value.
Definition: x509_common.h:898
error_t x509GenerateDsaSignature(const PrngAlgo *prngAlgo, void *prngContext, const uint8_t *tbsCert, size_t tbsCertLen, const HashAlgo *hashAlgo, const DsaPrivateKey *privateKey, uint8_t *output, size_t *written)
DSA signature generation.
@ X509_SIGN_ALGO_RSA
Definition: x509_common.h:515
error_t dsaWriteSignature(const DsaSignature *signature, uint8_t *data, size_t *length)
Encode DSA signature using ASN.1.
Definition: dsa.c:193
uint_t mpiGetBitLength(const Mpi *a)
Get the actual length in bits.
Definition: mpi.c:195
EdDSA private key.
Definition: eddsa.h:59
#define ED448_PRIVATE_KEY_LEN
Definition: ed448.h:40
error_t x509VerifyDsaSignature(const uint8_t *tbsCert, size_t tbsCertLen, const HashAlgo *hashAlgo, const X509SubjectPublicKeyInfo *publicKeyInfo, const X509SignatureValue *signatureValue)
DSA signature verification.
error_t x509RegisterSignGenCallback(X509SignGenCallback callback)
Register signature generation callback function.
EC public key.
Definition: ec.h:94
error_t ecdsaWriteSignature(const EcdsaSignature *signature, uint8_t *data, size_t *length)
Encode ECDSA signature using ASN.1.
Definition: ecdsa.c:98
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:814
Mpi d
Private key.
Definition: eddsa.h:60
@ X509_SIGN_ALGO_RSA_PSS
Definition: x509_common.h:516
RSA private key.
Definition: rsa.h:61
Subject public key information.
Definition: x509_common.h:699
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:1043
@ ERROR_UNKOWN_KEY
Definition: error.h:293
error_t x509GenerateRsaPssSignature(const PrngAlgo *prngAlgo, void *prngContext, const uint8_t *tbsCert, size_t tbsCertLen, const HashAlgo *hashAlgo, size_t saltLen, const RsaPrivateKey *privateKey, uint8_t *output, size_t *written)
RSA-PSS signature generation.
void dsaFreeSignature(DsaSignature *signature)
Release a DSA signature.
Definition: dsa.c:177
error_t dsaReadSignature(const uint8_t *data, size_t length, DsaSignature *signature)
Read an ASN.1 encoded DSA signature.
Definition: dsa.c:349
EcPoint q
Public key.
Definition: ec.h:95
#define X509_MAX_RSA_MODULUS_SIZE
Definition: x509_common.h:317
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:937
error_t x509GenerateRsaSignature(const uint8_t *tbsCert, size_t tbsCertLen, const HashAlgo *hashAlgo, const RsaPrivateKey *privateKey, uint8_t *output, size_t *written)
RSA signature generation.
error_t ed25519VerifySignature(const uint8_t *publicKey, const void *message, size_t messageLen, const void *context, uint8_t contextLen, uint8_t flag, const uint8_t *signature)
EdDSA signature verification.
Definition: ed25519.c:411
error_t rsassaPkcs1v15Sign(const RsaPrivateKey *key, const HashAlgo *hash, const uint8_t *digest, uint8_t *signature, size_t *signatureLen)
RSASSA-PKCS1-v1_5 signature generation operation.
Definition: rsa.c:681
DSA signature.
Definition: dsa.h:84
Parsing of ASN.1 encoded keys.
@ ERROR_UNSUPPORTED_SIGNATURE_ALGO
Definition: error.h:132
@ X509_SIGN_ALGO_ED25519
Definition: x509_common.h:519
unsigned int uint_t
Definition: compiler_port.h:50
X509EcPublicKey ecPublicKey
Definition: x509_common.h:713
@ ERROR_INVALID_SIGNATURE
Definition: error.h:226
error_t x509GenerateEd448Signature(const uint8_t *tbsCert, size_t tbsCertLen, const EddsaPrivateKey *privateKey, uint8_t *output, size_t *written)
Ed448 signature generation.
void dsaFreePublicKey(DsaPublicKey *key)
Release a DSA public key.
Definition: dsa.c:119
const uint8_t * namedCurve
Definition: x509_common.h:678
error_t ed448GenerateSignature(const uint8_t *privateKey, const uint8_t *publicKey, const void *message, size_t messageLen, const void *context, uint8_t contextLen, uint8_t flag, uint8_t *signature)
EdDSA signature generation.
Definition: ed448.c:214
void dsaInitPublicKey(DsaPublicKey *key)
Initialize a DSA public key.
Definition: dsa.c:105
@ ERROR_INVALID_KEY
Definition: error.h:106
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
void rsaInitPublicKey(RsaPublicKey *key)
Initialize an RSA public key.
Definition: rsa.c:105
void ecFreePublicKey(EcPublicKey *key)
Release an EC public key.
Definition: ec.c:165
error_t x509VerifyEd25519Signature(const uint8_t *tbsCert, size_t tbsCertLen, const X509SubjectPublicKeyInfo *publicKeyInfo, const X509SignatureValue *signatureValue)
Ed25519 signature verification.
@ X509_SIGN_ALGO_DSA
Definition: x509_common.h:517
@ X509_SIGN_ALGO_ED448
Definition: x509_common.h:520
uint_t mpiGetByteLength(const Mpi *a)
Get the actual length in bytes.
Definition: mpi.c:156