pem_key_export.h
Go to the documentation of this file.
1 /**
2  * @file pem_key_export.h
3  * @brief PEM key file export functions
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of 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.5.2
29  **/
30 
31 #ifndef _PEM_KEY_EXPORT_H
32 #define _PEM_KEY_EXPORT_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "pkix/pem_common.h"
37 #include "pkc/rsa.h"
38 #include "pkc/dsa.h"
39 #include "ecc/ec.h"
40 #include "ecc/eddsa.h"
41 
42 //C++ guard
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 
48 /**
49  * @brief PEM public key formats
50  **/
51 
52 typedef enum
53 {
54  PEM_PUBLIC_KEY_FORMAT_DEFAULT = 0, ///<Default format
55  PEM_PUBLIC_KEY_FORMAT_PKCS1 = 1, ///<PKCS #1 format
56  PEM_PUBLIC_KEY_FORMAT_RFC7468 = 2 ///<RFC 7468 format
58 
59 
60 /**
61  * @brief PEM private key formats
62  **/
63 
64 typedef enum
65 {
66  PEM_PRIVATE_KEY_FORMAT_DEFAULT = 0, ///<Default format
67  PEM_PRIVATE_KEY_FORMAT_PKCS1 = 1, ///<PKCS #1 format
68  PEM_PRIVATE_KEY_FORMAT_PKCS8 = 2, ///<PKCS #8 v1 format
69  PEM_PRIVATE_KEY_FORMAT_PKCS8_V2 = 3, ///<PKCS #8 v2 format
70  PEM_PRIVATE_KEY_FORMAT_RFC5915 = 4 ///<RFC 5915 format
72 
73 
74 //PEM related functions
76  char_t *output, size_t *written, PemPublicKeyFormat format);
77 
79  char_t *output, size_t *written, PemPrivateKeyFormat format);
80 
82  char_t *output, size_t *written, PemPublicKeyFormat format);
83 
85  char_t *output, size_t *written, PemPrivateKeyFormat format);
86 
88  char_t *output, size_t *written, PemPublicKeyFormat format);
89 
91  char_t *output, size_t *written, PemPrivateKeyFormat format);
92 
94  char_t *output, size_t *written, PemPublicKeyFormat format);
95 
97  char_t *output, size_t *written, PemPrivateKeyFormat format);
98 
100  char_t *output, size_t *written, PemPublicKeyFormat format);
101 
103  char_t *output, size_t *written, PemPrivateKeyFormat format);
104 
105 //C++ guard
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif
error_t pemExportRsaPrivateKey(const RsaPrivateKey *privateKey, char_t *output, size_t *written, PemPrivateKeyFormat format)
Export an RSA private key to PEM format.
@ PEM_PRIVATE_KEY_FORMAT_DEFAULT
Default format.
error_t pemExportEddsaPrivateKey(const EddsaPrivateKey *privateKey, char_t *output, size_t *written, PemPrivateKeyFormat format)
Export an EdDSA private key to PEM format.
@ PEM_PRIVATE_KEY_FORMAT_PKCS1
PKCS #1 format.
PEM common definitions.
@ PEM_PUBLIC_KEY_FORMAT_DEFAULT
Default format.
error_t pemExportEcPublicKey(const EcPublicKey *publicKey, char_t *output, size_t *written, PemPublicKeyFormat format)
Export an EC public key to PEM format.
PemPublicKeyFormat
PEM public key formats.
DSA public key.
Definition: dsa.h:61
error_t
Error codes.
Definition: error.h:43
EdDSA public key.
Definition: eddsa.h:64
RSA public key.
Definition: rsa.h:57
EdDSA (Edwards-Curve Digital Signature Algorithm)
General definitions for cryptographic algorithms.
RSA public-key cryptography standard.
DSA (Digital Signature Algorithm)
EC private key.
Definition: ec.h:432
DSA private key.
Definition: dsa.h:72
@ PEM_PUBLIC_KEY_FORMAT_PKCS1
PKCS #1 format.
PemPrivateKeyFormat
PEM private key formats.
@ PEM_PRIVATE_KEY_FORMAT_PKCS8
PKCS #8 v1 format.
@ PEM_PUBLIC_KEY_FORMAT_RFC7468
RFC 7468 format.
error_t pemExportRsaPssPublicKey(const RsaPublicKey *publicKey, char_t *output, size_t *written, PemPublicKeyFormat format)
Export an RSA-PSS public key to PEM format.
EdDSA private key.
Definition: eddsa.h:75
EC public key.
Definition: ec.h:421
char char_t
Definition: compiler_port.h:55
error_t pemExportDsaPrivateKey(const DsaPrivateKey *privateKey, char_t *output, size_t *written, PemPrivateKeyFormat format)
Export a DSA private key to PEM format.
@ PEM_PRIVATE_KEY_FORMAT_PKCS8_V2
PKCS #8 v2 format.
RSA private key.
Definition: rsa.h:68
error_t pemExportRsaPublicKey(const RsaPublicKey *publicKey, char_t *output, size_t *written, PemPublicKeyFormat format)
Export an RSA public key to PEM format.
error_t pemExportEddsaPublicKey(const EddsaPublicKey *publicKey, char_t *output, size_t *written, PemPublicKeyFormat format)
Export an EdDSA public key to PEM format.
error_t pemExportEcPrivateKey(const EcPrivateKey *privateKey, char_t *output, size_t *written, PemPrivateKeyFormat format)
Export an EC private key to PEM format.
error_t pemExportDsaPublicKey(const DsaPublicKey *publicKey, char_t *output, size_t *written, PemPublicKeyFormat format)
Export a DSA public key to PEM format.
@ PEM_PRIVATE_KEY_FORMAT_RFC5915
RFC 5915 format.
ECC (Elliptic Curve Cryptography)
error_t pemExportRsaPssPrivateKey(const RsaPrivateKey *privateKey, char_t *output, size_t *written, PemPrivateKeyFormat format)
Export an RSA-PSS private key to PEM format.