x509_key_format.c
Go to the documentation of this file.
1 /**
2  * @file x509_key_format.c
3  * @brief Formatting of ASN.1 encoded keys
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 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 1.9.6
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_format.h"
37 #include "encoding/asn1.h"
38 #include "encoding/oid.h"
39 #include "hash/sha1.h"
40 #include "ecc/ed25519.h"
41 #include "ecc/ed448.h"
42 #include "debug.h"
43 
44 //Check crypto library configuration
45 #if (X509_SUPPORT == ENABLED || PEM_SUPPORT == ENABLED)
46 
47 
48 /**
49  * @brief Format SubjectPublicKeyInfo structure
50  * @param[in] publicKeyInfo Subject's public key information
51  * @param[in] publicKey Pointer to the public key (RSA, DSA, ECDSA or EdDSA)
52  * @param[out] keyId Subject's key identifier (optional parameter)
53  * @param[out] output Buffer where to format the ASN.1 structure
54  * @param[out] written Length of the resulting ASN.1 structure
55  * @return Error code
56  **/
57 
59  const void *publicKey, uint8_t *keyId, uint8_t *output, size_t *written)
60 {
61  error_t error;
62  size_t n;
63  size_t length;
64  uint8_t *p;
65  size_t oidLen;
66  const uint8_t *oid;
67  Asn1Tag tag;
68 
69  //Get the public key identifier
70  oid = publicKeyInfo->oid;
71  oidLen = publicKeyInfo->oidLen;
72 
73  //Point to the buffer where to write the ASN.1 structure
74  p = output;
75  //Length of the ASN.1 structure
76  length = 0;
77 
78 #if (DSA_SUPPORT == ENABLED)
79  //Valid DSA public key?
80  if(publicKey != NULL && !oidComp(oid, oidLen, DSA_OID, sizeof(DSA_OID)))
81  {
82  DsaDomainParameters params;
83 
84  //Retrieve DSA domain parameters
85  params.p = ((DsaPublicKey *) publicKey)->p;
86  params.q = ((DsaPublicKey *) publicKey)->q;
87  params.g = ((DsaPublicKey *) publicKey)->g;
88 
89  //Format AlgorithmIdentifier field
90  error = x509FormatAlgorithmIdentifier(publicKeyInfo, &params, p, &n);
91  }
92  else
93 #endif
94  {
95  //Format AlgorithmIdentifier field
96  error = x509FormatAlgorithmIdentifier(publicKeyInfo, NULL, p, &n);
97  }
98 
99  //Any error to report?
100  if(error)
101  return error;
102 
103  //Advance data pointer
104  p += n;
105  length += n;
106 
107  //The bit string shall contain an initial octet which encodes the number
108  //of unused bits in the final subsequent octet
109  p[0] = 0;
110 
111 #if (RSA_SUPPORT == ENABLED)
112  //RSA or RSA-PSS algorithm identifier?
113  if(!oidComp(oid, oidLen, RSA_ENCRYPTION_OID, sizeof(RSA_ENCRYPTION_OID)) ||
114  !oidComp(oid, oidLen, RSASSA_PSS_OID, sizeof(RSASSA_PSS_OID)))
115  {
116  //Valid RSA public key?
117  if(publicKey != NULL)
118  {
119  //Export the RSA public key to ASN.1 format
120  error = x509ExportRsaPublicKey(publicKey, p + 1, &n);
121  }
122  else
123  {
124  //Format RSAPublicKey structure
125  error = x509FormatRsaPublicKey(&publicKeyInfo->rsaPublicKey,
126  p + 1, &n);
127  }
128  }
129  else
130 #endif
131 #if (DSA_SUPPORT == ENABLED)
132  //DSA algorithm identifier?
133  if(!oidComp(oid, oidLen, DSA_OID, sizeof(DSA_OID)))
134  {
135  //Valid DSA public key?
136  if(publicKey != NULL)
137  {
138  //Export the DSA public key to ASN.1 format
139  error = x509ExportDsaPublicKey(publicKey, p + 1, &n);
140  }
141  else
142  {
143  //Format DSAPublicKey structure
144  error = x509FormatDsaPublicKey(&publicKeyInfo->dsaPublicKey,
145  p + 1, &n);
146  }
147  }
148  else
149 #endif
150 #if (ECDSA_SUPPORT == ENABLED)
151  //EC public key identifier?
152  if(!oidComp(oid, oidLen, EC_PUBLIC_KEY_OID, sizeof(EC_PUBLIC_KEY_OID)))
153  {
154  //Valid EC public key?
155  if(publicKey != NULL)
156  {
157  //Export the EC public key to ASN.1 format
158  error = x509ExportEcPublicKey(publicKeyInfo, publicKey,
159  p + 1, &n);
160  }
161  else
162  {
163  //Format ECPublicKey structure
164  error = x509FormatEcPublicKey(&publicKeyInfo->ecPublicKey,
165  p + 1, &n);
166  }
167  }
168  else
169 #endif
170 #if (ED25519_SUPPORT == ENABLED)
171  //Ed25519 algorithm identifier?
172  if(!oidComp(oid, oidLen, ED25519_OID, sizeof(ED25519_OID)))
173  {
174  //Valid EdDSA public key?
175  if(publicKey != NULL)
176  {
177  //Export the EdDSA public key to ASN.1 format
179  p + 1, &n);
180  }
181  else
182  {
183  //The SubjectPublicKey contains the byte stream of the public key
184  error = x509FormatEcPublicKey(&publicKeyInfo->ecPublicKey,
185  p + 1, &n);
186  }
187  }
188  else
189 #endif
190 #if (ED448_SUPPORT == ENABLED)
191  //Ed448 algorithm identifier?
192  if(!oidComp(oid, oidLen, ED448_OID, sizeof(ED448_OID)))
193  {
194  //Valid EdDSA public key?
195  if(publicKey != NULL)
196  {
197  //Export the EdDSA public key to ASN.1 format
199  p + 1, &n);
200  }
201  else
202  {
203  //The SubjectPublicKey contains the byte stream of the public key
204  error = x509FormatEcPublicKey(&publicKeyInfo->ecPublicKey,
205  p + 1, &n);
206  }
207  }
208  else
209 #endif
210  //Unknown algorithm identifier?
211  {
212  //Report an error
213  error = ERROR_INVALID_PARAMETER;
214  }
215 
216  //Any error to report?
217  if(error)
218  return error;
219 
220  //The keyIdentifier parameter is optional
221  if(keyId != NULL)
222  {
223  //The keyIdentifier is composed of the 160-bit SHA-1 hash of the value
224  //of the bit string subjectPublicKey (excluding the tag, length, and
225  //number of unused bits)
226  error = sha1Compute(p + 1, n, keyId);
227  //Any error to report?
228  if(error)
229  return error;
230  }
231 
232  //The public key is encapsulated within a bit string
233  tag.constructed = FALSE;
236  tag.length = n + 1;
237  tag.value = p;
238 
239  //Write the corresponding ASN.1 tag
240  error = asn1WriteTag(&tag, FALSE, p, &n);
241  //Any error to report?
242  if(error)
243  return error;
244 
245  //Advance data pointer
246  p += n;
247  length += n;
248 
249  //The SubjectPublicKeyInfo structure is encapsulated within a sequence
250  tag.constructed = TRUE;
253  tag.length = length;
254  tag.value = output;
255 
256  //Write the corresponding ASN.1 tag
257  error = asn1WriteTag(&tag, FALSE, output, &n);
258  //Any error to report?
259  if(error)
260  return error;
261 
262  //Total number of bytes that have been written
263  *written = n;
264 
265  //Successful processing
266  return NO_ERROR;
267 }
268 
269 
270 /**
271  * @brief Format AlgorithmIdentifier structure
272  * @param[in] publicKeyInfo Subject's public key information
273  * @param[in] params Pointer to the domain parameters (DSA or ECDSA)
274  * @param[out] output Buffer where to format the ASN.1 structure
275  * @param[out] written Length of the resulting ASN.1 structure
276  * @return Error code
277  **/
278 
280  const void *params, uint8_t *output, size_t *written)
281 {
282  error_t error;
283  size_t n;
284  size_t length;
285  uint8_t *p;
286  size_t oidLen;
287  const uint8_t *oid;
288  Asn1Tag tag;
289 
290  //Get the public key identifier
291  oid = publicKeyInfo->oid;
292  oidLen = publicKeyInfo->oidLen;
293 
294  //Point to the buffer where to write the ASN.1 structure
295  p = output;
296  //Length of the ASN.1 structure
297  length = 0;
298 
299  //Format algorithm OID
300  tag.constructed = FALSE;
303  tag.length = oidLen;
304  tag.value = oid;
305 
306  //Write the corresponding ASN.1 tag
307  error = asn1WriteTag(&tag, FALSE, p, &n);
308  //Any error to report?
309  if(error)
310  return error;
311 
312  //Advance data pointer
313  p += n;
314  length += n;
315 
316 #if (RSA_SUPPORT == ENABLED)
317  //RSA algorithm identifier?
318  if(!oidComp(oid, oidLen, RSA_ENCRYPTION_OID, sizeof(RSA_ENCRYPTION_OID)))
319  {
320  //The parameters field must have ASN.1 type NULL for this algorithm
321  //identifier (refer to RFC 3279, section 2.3.1)
322  tag.constructed = FALSE;
324  tag.objType = ASN1_TYPE_NULL;
325  tag.length = 0;
326  tag.value = NULL;
327 
328  //Write the corresponding ASN.1 tag
329  error = asn1WriteTag(&tag, FALSE, p, &n);
330  }
331  //RSA-PSS algorithm identifier?
332  else if(!oidComp(oid, oidLen, RSASSA_PSS_OID, sizeof(RSASSA_PSS_OID)))
333  {
334  //The parameters may be either absent or present when used as subject
335  //public key information (refer to RFC 4055, section 3.1)
336  n = 0;
337  }
338  else
339 #endif
340 #if (DSA_SUPPORT == ENABLED)
341  //DSA algorithm identifier?
342  if(!oidComp(oid, oidLen, DSA_OID, sizeof(DSA_OID)))
343  {
344  //Valid DSA domain parameters?
345  if(params != NULL)
346  {
347  //Export the DSA domain parameters to ASN.1 format
348  error = x509ExportDsaParameters(params, p, &n);
349  }
350  else
351  {
352  //Format DSAParameters structure
353  error = x509FormatDsaParameters(&publicKeyInfo->dsaParams, p, &n);
354  }
355  }
356  else
357 #endif
358 #if (ECDSA_SUPPORT == ENABLED)
359  //ECDSA algorithm identifier?
360  if(!oidComp(oid, oidLen, EC_PUBLIC_KEY_OID, sizeof(EC_PUBLIC_KEY_OID)))
361  {
362  //Format ECParameters structure
363  error = x509FormatEcParameters(&publicKeyInfo->ecParams, p, &n);
364  }
365  else
366 #endif
367 #if (ED25519_SUPPORT == ENABLED)
368  //X25519 or Ed25519 algorithm identifier?
369  if(!oidComp(oid, oidLen, X25519_OID, sizeof(X25519_OID)) ||
370  !oidComp(oid, oidLen, ED25519_OID, sizeof(ED25519_OID)))
371  {
372  //For all of the OIDs, the parameters must be absent (refer to RFC 8410,
373  //section 3)
374  n = 0;
375  }
376  else
377 #endif
378 #if (ED448_SUPPORT == ENABLED)
379  //X448 or Ed448 algorithm identifier?
380  if(!oidComp(oid, oidLen, X448_OID, sizeof(X448_OID)) ||
381  !oidComp(oid, oidLen, ED448_OID, sizeof(ED448_OID)))
382  {
383  //For all of the OIDs, the parameters must be absent (refer to RFC 8410,
384  //section 3)
385  n = 0;
386  }
387  else
388 #endif
389  //Unknown algorithm identifier?
390  {
391  //Report an error
392  error = ERROR_INVALID_PARAMETER;
393  }
394 
395  //Any error to report?
396  if(error)
397  return error;
398 
399  //Advance data pointer
400  p += n;
401  length += n;
402 
403  //The AlgorithmIdentifier structure is encapsulated within a sequence
404  tag.constructed = TRUE;
407  tag.length = length;
408  tag.value = output;
409 
410  //Write the corresponding ASN.1 tag
411  error = asn1WriteTag(&tag, FALSE, output, &n);
412  //Any error to report?
413  if(error)
414  return error;
415 
416  //Total number of bytes that have been written
417  *written = n;
418 
419  //Successful processing
420  return NO_ERROR;
421 }
422 
423 
424 /**
425  * @brief Format RSAPublicKey structure
426  * @param[in] rsaPublicKey Pointer to the RSA public key
427  * @param[out] output Buffer where to format the ASN.1 structure
428  * @param[out] written Length of the resulting ASN.1 structure
429  * @return Error code
430  **/
431 
433  uint8_t *output, size_t *written)
434 {
435  error_t error;
436  size_t n;
437  size_t length;
438  uint8_t *p;
439  Asn1Tag tag;
440 
441  //Point to the buffer where to write the ASN.1 structure
442  p = output;
443  //Length of the ASN.1 structure
444  length = 0;
445 
446  //Write Modulus field
447  tag.constructed = FALSE;
450  tag.length = rsaPublicKey->nLen;
451  tag.value = rsaPublicKey->n;
452 
453  //Write the corresponding ASN.1 tag
454  error = asn1WriteTag(&tag, FALSE, p, &n);
455  //Any error to report?
456  if(error)
457  return error;
458 
459  //Advance data pointer
460  p += n;
461  length += n;
462 
463  //Write PublicExponent field
464  tag.constructed = FALSE;
467  tag.length = rsaPublicKey->eLen;
468  tag.value = rsaPublicKey->e;
469 
470  //Write the corresponding ASN.1 tag
471  error = asn1WriteTag(&tag, FALSE, p, &n);
472  //Any error to report?
473  if(error)
474  return error;
475 
476  //Advance data pointer
477  p += n;
478  length += n;
479 
480  //The public key is encapsulated within a sequence
481  tag.constructed = TRUE;
484  tag.length = length;
485  tag.value = output;
486 
487  //Write RSAPublicKey structure
488  error = asn1WriteTag(&tag, FALSE, output, &n);
489  //Any error to report?
490  if(error)
491  return error;
492 
493  //Total number of bytes that have been written
494  *written = n;
495 
496  //Successful processing
497  return NO_ERROR;
498 }
499 
500 
501 /**
502  * @brief Format RSASSA-PSS parameters
503  * @param[in] rsaPssParams Pointer to the RSA-PSS parameters
504  * @param[out] output Buffer where to format the ASN.1 structure
505  * @param[out] written Length of the resulting ASN.1 structure
506  * @return Error code
507  **/
508 
510  uint8_t *output, size_t *written)
511 {
512  error_t error;
513  size_t n;
514  size_t length;
515  uint8_t *p;
516  Asn1Tag tag;
517 
518  //Point to the buffer where to write the ASN.1 structure
519  p = output;
520  //Length of the ASN.1 structure
521  length = 0;
522 
523  //Format hashAlgorithm parameter
524  error = x509FormatRsaPssHashAlgo(rsaPssParams, p, &n);
525  //Any error to report?
526  if(error)
527  return error;
528 
529  //Advance data pointer
530  p += n;
531  length += n;
532 
533  //Format maskGenAlgorithm parameter
534  error = x509FormatRsaPssMaskGenAlgo(rsaPssParams, p, &n);
535  //Any error to report?
536  if(error)
537  return error;
538 
539  //Advance data pointer
540  p += n;
541  length += n;
542 
543  //Format saltLength parameter
544  error = x509FormatRsaPssSaltLength(rsaPssParams, p, &n);
545  //Any error to report?
546  if(error)
547  return error;
548 
549  //Advance data pointer
550  p += n;
551  length += n;
552 
553  //The RSASSA-PSS parameters are encapsulated within a sequence
554  tag.constructed = TRUE;
557  tag.length = length;
558  tag.value = output;
559 
560  //Write the corresponding ASN.1 tag
561  error = asn1WriteTag(&tag, FALSE, output, &n);
562  //Any error to report?
563  if(error)
564  return error;
565 
566  //Total number of bytes that have been written
567  *written = n;
568 
569  //Successful processing
570  return NO_ERROR;
571 }
572 
573 
574 /**
575  * @brief Format RSASSA-PSS hash algorithm
576  * @param[in] rsaPssParams Pointer to the RSA-PSS parameters
577  * @param[out] output Buffer where to format the ASN.1 structure
578  * @param[out] written Length of the resulting ASN.1 structure
579  * @return Error code
580  **/
581 
583  uint8_t *output, size_t *written)
584 {
585  error_t error;
586  size_t n;
587  Asn1Tag tag;
588 
589  //Length of the ASN.1 structure
590  n = 0;
591 
592  //The default hash algorithm is SHA-1
593  if(rsaPssParams->hashAlgo != NULL && rsaPssParams->hashAlgoLen > 0)
594  {
595  //Write the hash algorithm identifier
596  tag.constructed = FALSE;
599  tag.length = rsaPssParams->hashAlgoLen;
600  tag.value = rsaPssParams->hashAlgo;
601 
602  //Write the corresponding ASN.1 tag
603  error = asn1WriteTag(&tag, FALSE, output, &n);
604  //Any error to report?
605  if(error)
606  return error;
607 
608  //The hashAlgorithm parameter is encapsulated within a sequence
609  tag.constructed = TRUE;
612  tag.length = n;
613  tag.value = output;
614 
615  //Write the corresponding ASN.1 tag
616  error = asn1WriteTag(&tag, FALSE, output, &n);
617  //Any error to report?
618  if(error)
619  return error;
620 
621  //Explicit tagging shall be used to encode each parameter
622  tag.constructed = TRUE;
624  tag.objType = 0;
625  tag.length = n;
626  tag.value = output;
627 
628  //Write the corresponding ASN.1 tag
629  error = asn1WriteTag(&tag, FALSE, output, &n);
630  //Any error to report?
631  if(error)
632  return error;
633  }
634 
635  //Total number of bytes that have been written
636  *written = n;
637 
638  //Successful processing
639  return NO_ERROR;
640 }
641 
642 
643 /**
644  * @brief Format RSASSA-PSS mask generation algorithm
645  * @param[in] rsaPssParams Pointer to the RSA-PSS parameters
646  * @param[out] output Buffer where to format the ASN.1 structure
647  * @param[out] written Length of the resulting ASN.1 structure
648  * @return Error code
649  **/
650 
652  uint8_t *output, size_t *written)
653 {
654  error_t error;
655  size_t n;
656  size_t length;
657  uint8_t *p;
658  Asn1Tag tag;
659 
660  //Point to the buffer where to write the ASN.1 structure
661  p = output;
662  //Length of the ASN.1 structure
663  length = 0;
664 
665  //The default mask generation function is MGF1
666  if(rsaPssParams->maskGenAlgo != NULL && rsaPssParams->maskGenAlgoLen > 0)
667  {
668  //Write the mask generation algorithm identifier
669  tag.constructed = FALSE;
672  tag.length = rsaPssParams->maskGenAlgoLen;
673  tag.value = rsaPssParams->maskGenAlgo;
674 
675  //Write the corresponding ASN.1 tag
676  error = asn1WriteTag(&tag, FALSE, p, &n);
677  //Any error to report?
678  if(error)
679  return error;
680 
681  //Advance data pointer
682  p += n;
683  length += n;
684 
685  //Write the algorithm identifier of the one-way hash function employed
686  //with the mask generation function
687  error = x509FormatRsaPssMaskGenHashAlgo(rsaPssParams, p, &n);
688  //Any error to report?
689  if(error)
690  return error;
691 
692  //Advance data pointer
693  p += n;
694  length += n;
695 
696  //The maskGenAlgorithm parameter is encapsulated within a sequence
697  tag.constructed = TRUE;
700  tag.length = length;
701  tag.value = output;
702 
703  //Write the corresponding ASN.1 tag
704  error = asn1WriteTag(&tag, FALSE, output, &length);
705  //Any error to report?
706  if(error)
707  return error;
708 
709  //Explicit tagging shall be used to encode each parameter
710  tag.constructed = TRUE;
712  tag.objType = 1;
713  tag.length = length;
714  tag.value = output;
715 
716  //Write the corresponding ASN.1 tag
717  error = asn1WriteTag(&tag, FALSE, output, &length);
718  //Any error to report?
719  if(error)
720  return error;
721  }
722 
723  //Total number of bytes that have been written
724  *written = length;
725 
726  //Successful processing
727  return NO_ERROR;
728 }
729 
730 
731 /**
732  * @brief Format RSASSA-PSS mask generation hash algorithm
733  * @param[in] rsaPssParams Pointer to the RSA-PSS parameters
734  * @param[out] output Buffer where to format the ASN.1 structure
735  * @param[out] written Length of the resulting ASN.1 structure
736  * @return Error code
737  **/
738 
740  uint8_t *output, size_t *written)
741 {
742  error_t error;
743  size_t n;
744  Asn1Tag tag;
745 
746  //Length of the ASN.1 structure
747  n = 0;
748 
749  //The default hash algorithm is SHA-1
750  if(rsaPssParams->maskGenHashAlgo != NULL &&
751  rsaPssParams->maskGenHashAlgoLen > 0)
752  {
753  //Write the algorithm identifier of the one-way hash function employed
754  //with the mask generation function
755  tag.constructed = FALSE;
758  tag.length = rsaPssParams->maskGenHashAlgoLen;
759  tag.value = rsaPssParams->maskGenHashAlgo;
760 
761  //Write the corresponding ASN.1 tag
762  error = asn1WriteTag(&tag, FALSE, output, &n);
763  //Any error to report?
764  if(error)
765  return error;
766 
767  //The hash algorithm identifier is encapsulated within a sequence
768  tag.constructed = TRUE;
771  tag.length = n;
772  tag.value = output;
773 
774  //Write the corresponding ASN.1 tag
775  error = asn1WriteTag(&tag, FALSE, output, &n);
776  //Any error to report?
777  if(error)
778  return error;
779  }
780 
781  //Total number of bytes that have been written
782  *written = n;
783 
784  //Successful processing
785  return NO_ERROR;
786 }
787 
788 
789 /**
790  * @brief Format RSASSA-PSS salt length
791  * @param[in] rsaPssParams Pointer to the RSA-PSS parameters
792  * @param[out] output Buffer where to format the ASN.1 structure
793  * @param[out] written Length of the resulting ASN.1 structure
794  * @return Error code
795  **/
796 
798  uint8_t *output, size_t *written)
799 {
800  error_t error;
801  size_t n;
802  Asn1Tag tag;
803 
804  //Length of the ASN.1 structure
805  n = 0;
806 
807  //The default length of the salt is 20
808  if(rsaPssParams->saltLen != 20)
809  {
810  //Write the length of the salt
811  error = asn1WriteInt32((int32_t) rsaPssParams->saltLen, FALSE, output, &n);
812  //Any error to report?
813  if(error)
814  return error;
815 
816  //Explicit tagging shall be used to encode the saltLength parameter
817  tag.constructed = TRUE;
819  tag.objType = 2;
820  tag.length = n;
821  tag.value = output;
822 
823  //Write the corresponding ASN.1 tag
824  error = asn1WriteTag(&tag, FALSE, output, &n);
825  //Any error to report?
826  if(error)
827  return error;
828  }
829 
830  //Total number of bytes that have been written
831  *written = n;
832 
833  //Successful processing
834  return NO_ERROR;
835 }
836 
837 
838 /**
839  * @brief Format DSAPublicKey structure
840  * @param[in] dsaPublicKey Pointer to the DSA public key
841  * @param[out] output Buffer where to format the DSAPublicKey structure
842  * @param[out] written Length of the DSAPublicKey structure
843  * @return Error code
844  **/
845 
847  uint8_t *output, size_t *written)
848 {
849  error_t error;
850  size_t n;
851  Asn1Tag tag;
852 
853  //Write public key
854  tag.constructed = FALSE;
857  tag.length = dsaPublicKey->yLen;
858  tag.value = dsaPublicKey->y;
859 
860  //Write the corresponding ASN.1 tag
861  error = asn1WriteTag(&tag, FALSE, output, &n);
862  //Any error to report?
863  if(error)
864  return error;
865 
866  //Total number of bytes that have been written
867  *written = n;
868 
869  //Successful processing
870  return NO_ERROR;
871 }
872 
873 
874 /**
875  * @brief Format DSA domain parameters
876  * @param[in] dsaParams Pointer to the DSA domain parameters
877  * @param[out] output Buffer where to format the ASN.1 structure
878  * @param[out] written Length of the resulting ASN.1 structure
879  * @return Error code
880  **/
881 
883  uint8_t *output, size_t *written)
884 {
885  error_t error;
886  size_t n;
887  size_t length;
888  uint8_t *p;
889  Asn1Tag tag;
890 
891  //Point to the buffer where to write the ASN.1 structure
892  p = output;
893  //Length of the ASN.1 structure
894  length = 0;
895 
896  //Write parameter p
897  tag.constructed = FALSE;
900  tag.length = dsaParams->pLen;
901  tag.value = dsaParams->p;
902 
903  //Write the corresponding ASN.1 tag
904  error = asn1WriteTag(&tag, FALSE, p, &n);
905  //Any error to report?
906  if(error)
907  return error;
908 
909  //Advance data pointer
910  p += n;
911  length += n;
912 
913  //Write parameter q
914  tag.constructed = FALSE;
917  tag.length = dsaParams->qLen;
918  tag.value = dsaParams->q;
919 
920  //Write the corresponding ASN.1 tag
921  error = asn1WriteTag(&tag, FALSE, p, &n);
922  //Any error to report?
923  if(error)
924  return error;
925 
926  //Advance data pointer
927  p += n;
928  length += n;
929 
930  //Write parameter g
931  tag.constructed = FALSE;
934  tag.length = dsaParams->gLen;
935  tag.value = dsaParams->g;
936 
937  //Write the corresponding ASN.1 tag
938  error = asn1WriteTag(&tag, FALSE, p, &n);
939  //Any error to report?
940  if(error)
941  return error;
942 
943  //Advance data pointer
944  p += n;
945  length += n;
946 
947  //The DSA domain parameters are encapsulated within a sequence
948  tag.constructed = TRUE;
951  tag.length = length;
952  tag.value = output;
953 
954  //Write DSAParameters structure
955  error = asn1WriteTag(&tag, FALSE, output, &n);
956  //Any error to report?
957  if(error)
958  return error;
959 
960  //Total number of bytes that have been written
961  *written = n;
962 
963  //Successful processing
964  return NO_ERROR;
965 }
966 
967 
968 /**
969  * @brief Format ECPublicKey structure
970  * @param[in] ecPublicKey Pointer to the EC public key
971  * @param[out] output Buffer where to format the ASN.1 structure
972  * @param[out] written Length of the resulting ASN.1 structure
973  * @return Error code
974  **/
975 
977  uint8_t *output, size_t *written)
978 {
979  size_t n;
980 
981  //Retrieve the length of the EC public key
982  n = ecPublicKey->qLen;
983 
984  //Copy the EC public key
985  cryptoMemcpy(output, ecPublicKey->q, n);
986 
987  //Total number of bytes that have been written
988  *written = n;
989 
990  //Successful processing
991  return NO_ERROR;
992 }
993 
994 
995 /**
996  * @brief Format ECParameters structure
997  * @param[in] ecParams Pointer to the EC parameters
998  * @param[out] output Buffer where to format the ECParameters structure
999  * @param[out] written Length of the ECParameters structure
1000  * @return Error code
1001  **/
1002 
1004  uint8_t *output, size_t *written)
1005 {
1006  error_t error;
1007  size_t n;
1008  Asn1Tag tag;
1009 
1010  //The namedCurve field identifies all the required values for a particular
1011  //set of elliptic curve domain parameters to be represented by an object
1012  //identifier
1013  tag.constructed = FALSE;
1016  tag.length = ecParams->namedCurveLen;
1017  tag.value = ecParams->namedCurve;
1018 
1019  //Write the corresponding ASN.1 tag
1020  error = asn1WriteTag(&tag, FALSE, output, &n);
1021  //Any error to report?
1022  if(error)
1023  return error;
1024 
1025  //Total number of bytes that have been written
1026  *written = n;
1027 
1028  //Successful processing
1029  return NO_ERROR;
1030 }
1031 
1032 
1033 /**
1034  * @brief Export an RSA public key to ASN.1 format
1035  * @param[in] publicKey Pointer to the RSA public key
1036  * @param[out] output Buffer where to store the ASN.1 structure
1037  * @param[out] written Length of the resulting ASN.1 structure
1038  * @return Error code
1039  **/
1040 
1042  uint8_t *output, size_t *written)
1043 {
1044  error_t error;
1045  size_t n;
1046  size_t length;
1047  uint8_t *p;
1048  Asn1Tag tag;
1049 
1050  //Point to the buffer where to write the ASN.1 structure
1051  p = output;
1052  //Length of the ASN.1 structure
1053  length = 0;
1054 
1055  //Write Modulus field
1056  error = asn1WriteMpi(&publicKey->n, FALSE, p, &n);
1057  //Any error to report?
1058  if(error)
1059  return error;
1060 
1061  //Advance data pointer
1062  p += n;
1063  length += n;
1064 
1065  //Write PublicExponent field
1066  error = asn1WriteMpi(&publicKey->e, FALSE, p, &n);
1067  //Any error to report?
1068  if(error)
1069  return error;
1070 
1071  //Advance data pointer
1072  p += n;
1073  length += n;
1074 
1075  //The public key is encapsulated within a sequence
1076  tag.constructed = TRUE;
1079  tag.length = length;
1080  tag.value = output;
1081 
1082  //Write RSAPublicKey structure
1083  error = asn1WriteTag(&tag, FALSE, output, &n);
1084  //Any error to report?
1085  if(error)
1086  return error;
1087 
1088  //Total number of bytes that have been written
1089  *written = n;
1090 
1091  //Successful processing
1092  return NO_ERROR;
1093 }
1094 
1095 
1096 /**
1097  * @brief Export an RSA private key to ASN.1 format
1098  * @param[in] privateKey Pointer to the RSA private key
1099  * @param[out] output Buffer where to store the ASN.1 structure
1100  * @param[out] written Length of the resulting ASN.1 structure
1101  * @return Error code
1102  **/
1103 
1105  uint8_t *output, size_t *written)
1106 {
1107  error_t error;
1108  size_t n;
1109  size_t length;
1110  uint8_t *p;
1111  Asn1Tag tag;
1112 
1113  //Point to the buffer where to write the ASN.1 structure
1114  p = output;
1115  //Length of the ASN.1 structure
1116  length = 0;
1117 
1118  //Write Version field
1119  error = asn1WriteInt32(0, FALSE, p, &n);
1120  //Any error to report?
1121  if(error)
1122  return error;
1123 
1124  //Update the length of the RSAPrivateKey structure
1125  length += n;
1126 
1127  //Advance data pointer
1128  if(output != NULL)
1129  {
1130  p += n;
1131  }
1132 
1133  //Write Modulus field
1134  error = asn1WriteMpi(&privateKey->n, FALSE, p, &n);
1135  //Any error to report?
1136  if(error)
1137  return error;
1138 
1139  //Update the length of the RSAPrivateKey structure
1140  length += n;
1141 
1142  //Advance data pointer
1143  if(output != NULL)
1144  {
1145  p += n;
1146  }
1147 
1148  //Write PublicExponent field
1149  error = asn1WriteMpi(&privateKey->e, FALSE, p, &n);
1150  //Any error to report?
1151  if(error)
1152  return error;
1153 
1154  //Update the length of the RSAPrivateKey structure
1155  length += n;
1156 
1157  //Advance data pointer
1158  if(output != NULL)
1159  {
1160  p += n;
1161  }
1162 
1163  //Write PrivateExponent field
1164  error = asn1WriteMpi(&privateKey->d, FALSE, p, &n);
1165  //Any error to report?
1166  if(error)
1167  return error;
1168 
1169  //Update the length of the RSAPrivateKey structure
1170  length += n;
1171 
1172  //Advance data pointer
1173  if(output != NULL)
1174  {
1175  p += n;
1176  }
1177 
1178  //Write Prime1 field
1179  error = asn1WriteMpi(&privateKey->p, FALSE, p, &n);
1180  //Any error to report?
1181  if(error)
1182  return error;
1183 
1184  //Update the length of the RSAPrivateKey structure
1185  length += n;
1186 
1187  //Advance data pointer
1188  if(output != NULL)
1189  {
1190  p += n;
1191  }
1192 
1193  //Write Prime2 field
1194  error = asn1WriteMpi(&privateKey->q, FALSE, p, &n);
1195  //Any error to report?
1196  if(error)
1197  return error;
1198 
1199  //Update the length of the RSAPrivateKey structure
1200  length += n;
1201 
1202  //Advance data pointer
1203  if(output != NULL)
1204  {
1205  p += n;
1206  }
1207 
1208  //Write Exponent1 field
1209  error = asn1WriteMpi(&privateKey->dp, FALSE, p, &n);
1210  //Any error to report?
1211  if(error)
1212  return error;
1213 
1214  //Update the length of the RSAPrivateKey structure
1215  length += n;
1216 
1217  //Advance data pointer
1218  if(output != NULL)
1219  {
1220  p += n;
1221  }
1222 
1223  //Write Exponent2 field
1224  error = asn1WriteMpi(&privateKey->dq, FALSE, p, &n);
1225  //Any error to report?
1226  if(error)
1227  return error;
1228 
1229  //Update the length of the RSAPrivateKey structure
1230  length += n;
1231 
1232  //Advance data pointer
1233  if(output != NULL)
1234  {
1235  p += n;
1236  }
1237 
1238  //Write Coefficient field
1239  error = asn1WriteMpi(&privateKey->qinv, FALSE, p, &n);
1240  //Any error to report?
1241  if(error)
1242  return error;
1243 
1244  //Update the length of the RSAPrivateKey structure
1245  length += n;
1246 
1247  //Advance data pointer
1248  if(output != NULL)
1249  {
1250  p += n;
1251  }
1252 
1253  //The private key is encapsulated within a sequence
1254  tag.constructed = TRUE;
1257  tag.length = length;
1258  tag.value = output;
1259 
1260  //Write RSAPrivateKey structure
1261  error = asn1WriteTag(&tag, FALSE, output, &n);
1262  //Any error to report?
1263  if(error)
1264  return error;
1265 
1266  //Total number of bytes that have been written
1267  *written = tag.totalLength;
1268 
1269  //Successful processing
1270  return NO_ERROR;
1271 }
1272 
1273 
1274 /**
1275  * @brief Export a DSA public key to ASN.1 format
1276  * @param[in] publicKey Pointer to the DSA public key
1277  * @param[out] output Buffer where to store the ASN.1 structure
1278  * @param[out] written Length of the resulting ASN.1 structure
1279  * @return Error code
1280  **/
1281 
1283  uint8_t *output, size_t *written)
1284 {
1285  error_t error;
1286  size_t n;
1287 
1288  //Write public key
1289  error = asn1WriteMpi(&publicKey->y, FALSE, output, &n);
1290  //Any error to report?
1291  if(error)
1292  return error;
1293 
1294  //Total number of bytes that have been written
1295  *written = n;
1296 
1297  //Successful processing
1298  return NO_ERROR;
1299 }
1300 
1301 
1302 /**
1303  * @brief Export a DSA private key to ASN.1 format
1304  * @param[in] privateKey Pointer to the DSA private key
1305  * @param[out] output Buffer where to store the ASN.1 structure
1306  * @param[out] written Length of the resulting ASN.1 structure
1307  * @return Error code
1308  **/
1309 
1311  uint8_t *output, size_t *written)
1312 {
1313  error_t error;
1314  size_t n;
1315 
1316  //Write private key
1317  error = asn1WriteMpi(&privateKey->x, FALSE, output, &n);
1318  //Any error to report?
1319  if(error)
1320  return error;
1321 
1322  //Total number of bytes that have been written
1323  *written = n;
1324 
1325  //Successful processing
1326  return NO_ERROR;
1327 }
1328 
1329 
1330 /**
1331  * @brief Export DSA domain parameters to ASN.1 format
1332  * @param[in] params Pointer to the DSA domain parameters
1333  * @param[out] output Buffer where to store the ASN.1 structure
1334  * @param[out] written Length of the resulting ASN.1 structure
1335  * @return Error code
1336  **/
1337 
1339  uint8_t *output, size_t *written)
1340 {
1341  error_t error;
1342  size_t n;
1343  size_t length;
1344  uint8_t *p;
1345  Asn1Tag tag;
1346 
1347  //Point to the buffer where to write the ASN.1 structure
1348  p = output;
1349  //Length of the ASN.1 structure
1350  length = 0;
1351 
1352  //Write parameter p
1353  error = asn1WriteMpi(&params->p, FALSE, p, &n);
1354  //Any error to report?
1355  if(error)
1356  return error;
1357 
1358  //Advance data pointer
1359  p += n;
1360  length += n;
1361 
1362  //Write parameter q
1363  error = asn1WriteMpi(&params->q, FALSE, p, &n);
1364  //Any error to report?
1365  if(error)
1366  return error;
1367 
1368  //Advance data pointer
1369  p += n;
1370  length += n;
1371 
1372  //Write parameter g
1373  error = asn1WriteMpi(&params->g, FALSE, p, &n);
1374  //Any error to report?
1375  if(error)
1376  return error;
1377 
1378  //Advance data pointer
1379  p += n;
1380  length += n;
1381 
1382  //The DSA domain parameters are encapsulated within a sequence
1383  tag.constructed = TRUE;
1386  tag.length = length;
1387  tag.value = output;
1388 
1389  //Write DSAParameters structure
1390  error = asn1WriteTag(&tag, FALSE, output, &n);
1391  //Any error to report?
1392  if(error)
1393  return error;
1394 
1395  //Total number of bytes that have been written
1396  *written = n;
1397 
1398  //Successful processing
1399  return NO_ERROR;
1400 }
1401 
1402 
1403 /**
1404  * @brief Export an EC public key to ASN.1 format
1405  * @param[in] publicKeyInfo Public key information
1406  * @param[in] publicKey Pointer to the EC public key
1407  * @param[out] output Buffer where to store the ASN.1 structure
1408  * @param[out] written Length of the resulting ASN.1 structure
1409  * @return Error code
1410  **/
1411 
1413  const EcPoint *publicKey, uint8_t *output, size_t *written)
1414 {
1415 #if (EC_SUPPORT == ENABLED)
1416  error_t error;
1417  const EcCurveInfo *curveInfo;
1418  EcDomainParameters params;
1419 
1420  //Initialize EC domain parameters
1421  ecInitDomainParameters(&params);
1422 
1423  //Retrieve EC domain parameters
1424  curveInfo = x509GetCurveInfo(publicKeyInfo->ecParams.namedCurve,
1425  publicKeyInfo->ecParams.namedCurveLen);
1426 
1427  //Make sure the specified elliptic curve is supported
1428  if(curveInfo != NULL)
1429  {
1430  //Load EC domain parameters
1431  error = ecLoadDomainParameters(&params, curveInfo);
1432  }
1433  else
1434  {
1435  //Invalid EC domain parameters
1436  error = ERROR_WRONG_IDENTIFIER;
1437  }
1438 
1439  //Check status code
1440  if(!error)
1441  {
1442  //Format ECPublicKey structure
1443  error = ecExport(&params, publicKey, output, written);
1444  }
1445 
1446  //Release EC domain parameters
1447  ecFreeDomainParameters(&params);
1448 
1449  //Return status code
1450  return error;
1451 #else
1452  //Not implemented
1453  return ERROR_NOT_IMPLEMENTED;
1454 #endif
1455 }
1456 
1457 
1458 /**
1459  * @brief Export an EdDSA public key to ASN.1 format
1460  * @param[in] publicKey Pointer to the EdDSA public key
1461  * @param[in] publicKeyLen Length of the EdDSA public key, in bytes
1462  * @param[out] output Buffer where to store the ASN.1 structure
1463  * @param[out] written Length of the resulting ASN.1 structure
1464  * @return Error code
1465  **/
1466 
1468  size_t publicKeyLen, uint8_t *output, size_t *written)
1469 {
1470  error_t error;
1471 
1472  //The SubjectPublicKey contains the byte stream of the public key
1473  error = mpiExport(&publicKey->q, output, publicKeyLen,
1475  //Any error to report?
1476  if(error)
1477  return error;
1478 
1479  //Total number of bytes that have been written
1480  *written = publicKeyLen;
1481 
1482  //Successful processing
1483  return NO_ERROR;
1484 }
1485 
1486 
1487 /**
1488  * @brief Export an EdDSA private key to ASN.1 format
1489  * @param[in] privateKey Pointer to the EdDSA private key
1490  * @param[in] privateKeyLen Length of the EdDSA private key, in bytes
1491  * @param[out] output Buffer where to store the ASN.1 structure
1492  * @param[out] written Length of the resulting ASN.1 structure
1493  * @return Error code
1494  **/
1495 
1497  size_t privateKeyLen, uint8_t *output, size_t *written)
1498 {
1499  error_t error;
1500  size_t n;
1501  Asn1Tag tag;
1502 
1503  //The private key is always an opaque byte sequence
1504  error = mpiExport(&privateKey->d, output, privateKeyLen,
1506  //Any error to report?
1507  if(error)
1508  return error;
1509 
1510  //The private key is encapsulated within an octet string
1511  tag.constructed = FALSE;
1514  tag.length = privateKeyLen;
1515  tag.value = output;
1516 
1517  //Write CurvePrivateKey structure
1518  error = asn1WriteTag(&tag, FALSE, output, &n);
1519  //Any error to report?
1520  if(error)
1521  return error;
1522 
1523  //Total number of bytes that have been written
1524  *written = tag.totalLength;
1525 
1526  //Successful processing
1527  return NO_ERROR;
1528 }
1529 
1530 #endif
error_t x509FormatEcParameters(const X509EcParameters *ecParams, uint8_t *output, size_t *written)
Format ECParameters structure.
uint8_t length
Definition: dtls_misc.h:149
Ed25519 elliptic curve (constant-time implementation)
error_t sha1Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using SHA-1.
Definition: sha1.c:102
const uint8_t * maskGenHashAlgo
Definition: x509_common.h:866
const uint8_t * oid
Definition: x509_common.h:698
const uint8_t * q
Definition: x509_common.h:650
error_t x509FormatRsaPssMaskGenHashAlgo(const X509RsaPssParameters *rsaPssParams, uint8_t *output, size_t *written)
Format RSASSA-PSS mask generation hash algorithm.
Mpi p
First factor.
Definition: rsa.h:64
const EcCurveInfo * x509GetCurveInfo(const uint8_t *oid, size_t length)
Get the elliptic curve that matches the specified OID.
Definition: x509_common.c:860
const uint8_t X25519_OID[3]
Definition: ec_curves.c:92
const uint8_t * maskGenAlgo
Definition: x509_common.h:864
void ecInitDomainParameters(EcDomainParameters *params)
Initialize EC domain parameters.
Definition: ec.c:55
X509DsaPublicKey dsaPublicKey
Definition: x509_common.h:705
#define ED25519_PUBLIC_KEY_LEN
Definition: ed25519.h:41
OID (Object Identifier)
SHA-1 (Secure Hash Algorithm 1)
uint8_t p
Definition: ndp.h:298
Mpi q
Group order.
Definition: dsa.h:51
#define TRUE
Definition: os_port.h:50
#define ED448_PUBLIC_KEY_LEN
Definition: ed448.h:41
const uint8_t EC_PUBLIC_KEY_OID[7]
Definition: ec.c:47
uint32_t keyId
Definition: ntp_common.h:172
error_t x509ExportEddsaPrivateKey(const EddsaPrivateKey *privateKey, size_t privateKeyLen, uint8_t *output, size_t *written)
Export an EdDSA private key to ASN.1 format.
Mpi n
Modulus.
Definition: rsa.h:61
X509EcParameters ecParams
Definition: x509_common.h:708
const uint8_t * q
Definition: x509_common.h:685
Mpi e
Public exponent.
Definition: rsa.h:51
Mpi p
Prime modulus.
Definition: dsa.h:50
const uint8_t RSASSA_PSS_OID[9]
Definition: rsa.c:88
EC domain parameters.
Definition: ec.h:63
void ecFreeDomainParameters(EcDomainParameters *params)
Release EC domain parameters.
Definition: ec.c:75
int_t oidComp(const uint8_t *oid1, size_t oidLen1, const uint8_t *oid2, size_t oidLen2)
Compare object identifiers.
Definition: oid.c:101
Mpi d
Private exponent.
Definition: rsa.h:63
Mpi n
Modulus.
Definition: rsa.h:50
EC public key.
Definition: x509_common.h:683
error_t x509FormatSubjectPublicKeyInfo(const X509SubjectPublicKeyInfo *publicKeyInfo, const void *publicKey, uint8_t *keyId, uint8_t *output, size_t *written)
Format SubjectPublicKeyInfo structure.
const uint8_t DSA_OID[7]
Definition: dsa.c:51
error_t x509FormatRsaPssParameters(const X509RsaPssParameters *rsaPssParams, uint8_t *output, size_t *written)
Format RSASSA-PSS parameters.
size_t totalLength
Definition: asn1.h:104
size_t length
Definition: asn1.h:102
error_t ecLoadDomainParameters(EcDomainParameters *params, const EcCurveInfo *curveInfo)
Load EC domain parameters.
Definition: ec.c:93
#define FALSE
Definition: os_port.h:46
Elliptic curve parameters.
Definition: ec_curves.h:292
error_t mpiExport(const Mpi *a, uint8_t *data, uint_t length, MpiFormat format)
Integer to octet string conversion.
Definition: mpi.c:618
DSA public key.
Definition: dsa.h:60
Invalid parameter.
Definition: error.h:47
error_t x509FormatDsaPublicKey(const X509DsaPublicKey *dsaPublicKey, uint8_t *output, size_t *written)
Format DSAPublicKey structure.
error_t
Error codes.
Definition: error.h:42
Mpi g
Group generator.
Definition: dsa.h:52
const uint8_t * n
Definition: x509_common.h:635
error_t x509ExportDsaPublicKey(const DsaPublicKey *publicKey, uint8_t *output, size_t *written)
Export a DSA public key to ASN.1 format.
EC parameters.
Definition: x509_common.h:672
error_t x509ExportDsaPrivateKey(const DsaPrivateKey *privateKey, uint8_t *output, size_t *written)
Export a DSA private key to ASN.1 format.
Mpi q
Public key.
Definition: eddsa.h:50
EdDSA public key.
Definition: eddsa.h:48
const uint8_t * g
Definition: x509_common.h:652
error_t x509ExportEcPublicKey(const X509SubjectPublicKeyInfo *publicKeyInfo, const EcPoint *publicKey, uint8_t *output, size_t *written)
Export an EC public key to ASN.1 format.
#define ASN1_CLASS_UNIVERSAL
Definition: asn1.h:48
RSA public key.
Definition: x509_common.h:633
error_t x509FormatRsaPssSaltLength(const X509RsaPssParameters *rsaPssParams, uint8_t *output, size_t *written)
Format RSASSA-PSS salt length.
ASN.1 tag.
Definition: asn1.h:97
Mpi q
Second factor.
Definition: rsa.h:65
error_t x509ExportRsaPublicKey(const RsaPublicKey *publicKey, uint8_t *output, size_t *written)
Export an RSA public key to ASN.1 format.
RSA public key.
Definition: rsa.h:48
X509RsaPublicKey rsaPublicKey
Definition: x509_common.h:701
DSA domain parameters.
Definition: dsa.h:48
const uint8_t * e
Definition: x509_common.h:637
General definitions for cryptographic algorithms.
uint8_t oid[1]
Definition: mib_common.h:186
error_t asn1WriteMpi(const Mpi *value, bool_t reverse, uint8_t *data, size_t *written)
Write a multiple-precision integer from the output stream.
Definition: asn1.c:572
error_t asn1WriteTag(Asn1Tag *tag, bool_t reverse, uint8_t *data, size_t *written)
Write an ASN.1 tag.
Definition: asn1.c:377
DSA private key.
Definition: dsa.h:73
X509DsaParameters dsaParams
Definition: x509_common.h:704
uint_t objClass
Definition: asn1.h:100
Elliptic curve point.
Definition: ec.h:51
size_t namedCurveLen
Definition: x509_common.h:675
Mpi e
Public exponent.
Definition: rsa.h:62
error_t x509FormatRsaPublicKey(const X509RsaPublicKey *rsaPublicKey, uint8_t *output, size_t *written)
Format RSAPublicKey structure.
error_t x509ExportRsaPrivateKey(const RsaPrivateKey *privateKey, uint8_t *output, size_t *written)
Export an RSA private key to ASN.1 format.
const uint8_t ED448_OID[3]
Definition: ec_curves.c:98
Mpi qinv
CRT coefficient.
Definition: rsa.h:68
EdDSA private key.
Definition: eddsa.h:58
Mpi dq
second factor's CRT exponent
Definition: rsa.h:67
const uint8_t ED25519_OID[3]
Definition: ec_curves.c:96
const uint8_t RSA_ENCRYPTION_OID[9]
Definition: rsa.c:57
const uint8_t X448_OID[3]
Definition: ec_curves.c:94
Formatting of ASN.1 encoded keys.
error_t x509FormatEcPublicKey(const X509EcPublicKey *ecPublicKey, uint8_t *output, size_t *written)
Format ECPublicKey structure.
error_t x509FormatAlgorithmIdentifier(const X509SubjectPublicKeyInfo *publicKeyInfo, const void *params, uint8_t *output, size_t *written)
Format AlgorithmIdentifier structure.
Mpi d
Private key.
Definition: eddsa.h:60
uint8_t n
RSA private key.
Definition: rsa.h:59
Subject public key information.
Definition: x509_common.h:694
DSA domain parameters.
Definition: x509_common.h:646
#define ASN1_CLASS_CONTEXT_SPECIFIC
Definition: asn1.h:50
#define cryptoMemcpy(dest, src, length)
Definition: crypto.h:642
error_t x509FormatRsaPssHashAlgo(const X509RsaPssParameters *rsaPssParams, uint8_t *output, size_t *written)
Format RSASSA-PSS hash algorithm.
error_t x509FormatDsaParameters(const X509DsaParameters *dsaParams, uint8_t *output, size_t *written)
Format DSA domain parameters.
error_t x509ExportDsaParameters(const DsaDomainParameters *params, uint8_t *output, size_t *written)
Export DSA domain parameters to ASN.1 format.
Mpi x
Secret exponent.
Definition: dsa.h:78
bool_t constructed
Definition: asn1.h:99
Mpi y
Public key value.
Definition: dsa.h:65
RSASSA-PSS parameters.
Definition: x509_common.h:860
error_t ecExport(const EcDomainParameters *params, const EcPoint *a, uint8_t *data, size_t *length)
Convert an EC point to an octet string.
Definition: ec.c:287
const uint8_t * p
Definition: x509_common.h:648
Mpi dp
First factor's CRT exponent.
Definition: rsa.h:66
const uint8_t * y
Definition: x509_common.h:663
X509EcPublicKey ecPublicKey
Definition: x509_common.h:709
error_t asn1WriteInt32(int32_t value, bool_t reverse, uint8_t *data, size_t *written)
Write a 32-bit integer to the output stream.
Definition: asn1.c:516
DSA public key.
Definition: x509_common.h:661
Ed448 elliptic curve (constant-time implementation)
const uint8_t * namedCurve
Definition: x509_common.h:674
const uint8_t * value
Definition: asn1.h:103
Success.
Definition: error.h:44
Debugging facilities.
uint_t objType
Definition: asn1.h:101
error_t x509ExportEddsaPublicKey(const EddsaPublicKey *publicKey, size_t publicKeyLen, uint8_t *output, size_t *written)
Export an EdDSA public key to ASN.1 format.
ASN.1 (Abstract Syntax Notation One)
error_t x509FormatRsaPssMaskGenAlgo(const X509RsaPssParameters *rsaPssParams, uint8_t *output, size_t *written)
Format RSASSA-PSS mask generation algorithm.
const uint8_t * hashAlgo
Definition: x509_common.h:862