ssh_key_export.h
Go to the documentation of this file.
1 /**
2  * @file ssh_key_export.h
3  * @brief SSH key file export functions
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2019-2025 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneSSH Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.5.0
29  **/
30 
31 #ifndef _SSH_KEY_EXPORT_H
32 #define _SSH_KEY_EXPORT_H
33 
34 //Dependencies
35 #include "ssh_types.h"
36 #include "pkc/rsa.h"
37 #include "pkc/dsa.h"
38 #include "ecc/ec.h"
39 #include "ecc/eddsa.h"
40 
41 //C++ guard
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 
47 /**
48  * @brief SSH public key formats
49  **/
50 
51 typedef enum
52 {
53  SSH_PUBLIC_KEY_FORMAT_SSH2 = 1, ///<SSH2 public key format
54  SSH_PUBLIC_KEY_FORMAT_OPENSSH = 2 ///<OpenSSH public key format
56 
57 
58 /**
59  * @brief SSH private key formats
60  **/
61 
62 typedef enum
63 {
64  SSH_PRIVATE_KEY_FORMAT_OPENSSH = 2 ///<OpenSSH private key format
66 
67 
68 //SSH key file export functions
70  char_t *output, size_t *written, SshPublicKeyFormat format);
71 
73  char_t *output, size_t *written, SshPublicKeyFormat format);
74 
76  char_t *output, size_t *written, SshPublicKeyFormat format);
77 
79  char_t *output, size_t *written, SshPublicKeyFormat format);
80 
82  char_t *output, size_t *written, SshPublicKeyFormat format);
83 
85  char_t *output, size_t *written, SshPrivateKeyFormat format);
86 
88  char_t *output, size_t *written, SshPrivateKeyFormat format);
89 
91  char_t *output, size_t *written, SshPrivateKeyFormat format);
92 
94  char_t *output, size_t *written, SshPrivateKeyFormat format);
95 
97  char_t *output, size_t *written, SshPrivateKeyFormat format);
98 
100  char_t *output, size_t *written);
101 
103  char_t *output, size_t *written);
104 
106  char_t *output, size_t *written);
107 
109  char_t *output, size_t *written);
110 
112  char_t *output, size_t *written);
113 
114 error_t sshEncodePublicKeyFile(const void *input, size_t inputLen,
115  char_t *output, size_t *outputLen, SshPublicKeyFormat format);
116 
117 error_t sshEncodeSsh2PublicKeyFile(const void *input, size_t inputLen,
118  char_t *output, size_t *outputLen);
119 
120 error_t sshEncodeOpenSshPublicKeyFile(const void *input, size_t inputLen,
121  char_t *output, size_t *outputLen);
122 
123 error_t sshEncodeOpenSshPrivateKeyFile(const void *input, size_t inputLen,
124  char_t *output, size_t *outputLen);
125 
126 //C++ guard
127 #ifdef __cplusplus
128 }
129 #endif
130 
131 #endif
error_t sshExportEd448PublicKey(const EddsaPublicKey *publicKey, char_t *output, size_t *written, SshPublicKeyFormat format)
Export a Ed448 public key to SSH public key file format.
error_t sshExportRsaPublicKey(const RsaPublicKey *publicKey, char_t *output, size_t *written, SshPublicKeyFormat format)
Export an RSA public key to SSH public key file format.
error_t sshExportOpenSshDsaPrivateKey(const DsaPrivateKey *privateKey, char_t *output, size_t *written)
Export a DSA private key to OpenSSH private key file format.
error_t sshExportDsaPrivateKey(const DsaPrivateKey *privateKey, char_t *output, size_t *written, SshPrivateKeyFormat format)
Export a DSA private key to SSH private key file format.
error_t sshExportDsaPublicKey(const DsaPublicKey *publicKey, char_t *output, size_t *written, SshPublicKeyFormat format)
Export a DSA public key to SSH public key file format.
error_t sshExportOpenSshEd448PrivateKey(const EddsaPrivateKey *privateKey, char_t *output, size_t *written)
Export an Ed448 private key to OpenSSH private key file format.
DSA public key.
Definition: dsa.h:61
error_t sshEncodePublicKeyFile(const void *input, size_t inputLen, char_t *output, size_t *outputLen, SshPublicKeyFormat format)
Encode SSH public key file (SSH2 or OpenSSH format)
SshPublicKeyFormat
SSH public key formats.
error_t
Error codes.
Definition: error.h:43
EdDSA public key.
Definition: eddsa.h:64
error_t sshExportEcdsaPublicKey(const EcPublicKey *publicKey, char_t *output, size_t *written, SshPublicKeyFormat format)
Export an ECDSA public key to SSH public key file format.
@ SSH_PUBLIC_KEY_FORMAT_OPENSSH
OpenSSH public key format.
RSA public key.
Definition: rsa.h:57
@ SSH_PRIVATE_KEY_FORMAT_OPENSSH
OpenSSH private key format.
error_t sshExportOpenSshRsaPrivateKey(const RsaPrivateKey *privateKey, char_t *output, size_t *written)
Export an RSA private key to OpenSSH private key file format.
error_t sshEncodeSsh2PublicKeyFile(const void *input, size_t inputLen, char_t *output, size_t *outputLen)
Encode SSH public key file (SSH2 format)
EdDSA (Edwards-Curve Digital Signature Algorithm)
RSA public-key cryptography standard.
error_t sshExportEd25519PublicKey(const EddsaPublicKey *publicKey, char_t *output, size_t *written, SshPublicKeyFormat format)
Export a Ed25519 public key to SSH public key file format.
DSA (Digital Signature Algorithm)
EC private key.
Definition: ec.h:432
DSA private key.
Definition: dsa.h:72
error_t sshExportOpenSshEcdsaPrivateKey(const EcPrivateKey *privateKey, char_t *output, size_t *written)
Export an ECDSA private key to OpenSSH private key file format.
EdDSA private key.
Definition: eddsa.h:75
error_t sshExportEcdsaPrivateKey(const EcPrivateKey *privateKey, char_t *output, size_t *written, SshPrivateKeyFormat format)
Export an ECDSA private key to SSH private key file format.
EC public key.
Definition: ec.h:421
char char_t
Definition: compiler_port.h:55
error_t sshExportRsaPrivateKey(const RsaPrivateKey *privateKey, char_t *output, size_t *written, SshPrivateKeyFormat format)
Export an RSA private key to SSH private key file format.
error_t sshExportEd25519PrivateKey(const EddsaPrivateKey *privateKey, char_t *output, size_t *written, SshPrivateKeyFormat format)
Export an Ed25519 private key to SSH private key file format.
@ SSH_PUBLIC_KEY_FORMAT_SSH2
SSH2 public key format.
SSH data type representations.
RSA private key.
Definition: rsa.h:68
SshPrivateKeyFormat
SSH private key formats.
error_t sshEncodeOpenSshPrivateKeyFile(const void *input, size_t inputLen, char_t *output, size_t *outputLen)
Encode SSH private key file (OpenSSH format)
error_t sshEncodeOpenSshPublicKeyFile(const void *input, size_t inputLen, char_t *output, size_t *outputLen)
Encode SSH public key file (OpenSSH format)
error_t sshExportEd448PrivateKey(const EddsaPrivateKey *privateKey, char_t *output, size_t *written, SshPrivateKeyFormat format)
Export an Ed448 private key to SSH private key file format.
ECC (Elliptic Curve Cryptography)
error_t sshExportOpenSshEd25519PrivateKey(const EddsaPrivateKey *privateKey, char_t *output, size_t *written)
Export an Ed25519 private key to OpenSSH private key file format.