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-2024 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.4.4
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  const EcPublicKey *publicKey, char_t *output, size_t *written,
77  SshPublicKeyFormat format);
78 
80  char_t *output, size_t *written, SshPublicKeyFormat format);
81 
83  char_t *output, size_t *written, SshPublicKeyFormat format);
84 
86  const RsaPublicKey *publicKey, char_t *output, size_t *written,
87  SshPrivateKeyFormat format);
88 
90  const DsaPublicKey *publicKey, char_t *output, size_t *written,
91  SshPrivateKeyFormat format);
92 
94  const EcPrivateKey *privateKey, const EcPublicKey *publicKey,
95  char_t *output, size_t *written, SshPrivateKeyFormat format);
96 
98  const EddsaPublicKey *publicKey, char_t *output, size_t *written,
99  SshPrivateKeyFormat format);
100 
102  const EddsaPublicKey *publicKey, char_t *output, size_t *written,
103  SshPrivateKeyFormat format);
104 
106  const RsaPublicKey *publicKey, char_t *output, size_t *written);
107 
109  const DsaPublicKey *publicKey, char_t *output, size_t *written);
110 
112  const EcPrivateKey *privateKey, const EcPublicKey *publicKey,
113  char_t *output, size_t *written);
114 
116  const EddsaPublicKey *publicKey, char_t *output, size_t *written);
117 
119  const EddsaPublicKey *publicKey, char_t *output, size_t *written);
120 
121 error_t sshEncodePublicKeyFile(const void *input, size_t inputLen,
122  char_t *output, size_t *outputLen, SshPublicKeyFormat format);
123 
124 error_t sshEncodeSsh2PublicKeyFile(const void *input, size_t inputLen,
125  char_t *output, size_t *outputLen);
126 
127 error_t sshEncodeOpenSshPublicKeyFile(const void *input, size_t inputLen,
128  char_t *output, size_t *outputLen);
129 
130 error_t sshEncodeOpenSshPrivateKeyFile(const void *input, size_t inputLen,
131  char_t *output, size_t *outputLen);
132 
133 //C++ guard
134 #ifdef __cplusplus
135 }
136 #endif
137 
138 #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 sshExportOpenSshEd448PrivateKey(const EddsaPrivateKey *privateKey, const EddsaPublicKey *publicKey, char_t *output, size_t *written)
Export an Ed448 private key to OpenSSH private key file format.
error_t sshExportDsaPrivateKey(const DsaPrivateKey *privateKey, const DsaPublicKey *publicKey, char_t *output, size_t *written, SshPrivateKeyFormat format)
Export a DSA private key to SSH private key file format.
EC domain parameters.
Definition: ec.h:76
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 sshExportOpenSshRsaPrivateKey(const RsaPrivateKey *privateKey, const RsaPublicKey *publicKey, char_t *output, size_t *written)
Export an RSA private key to OpenSSH private key file format.
error_t sshExportEd25519PrivateKey(const EddsaPrivateKey *privateKey, const EddsaPublicKey *publicKey, char_t *output, size_t *written, SshPrivateKeyFormat format)
Export an Ed25519 private key to SSH 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:49
@ 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 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)
error_t sshExportOpenSshDsaPrivateKey(const DsaPrivateKey *privateKey, const DsaPublicKey *publicKey, char_t *output, size_t *written)
Export a DSA private key to OpenSSH private key file format.
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:104
DSA private key.
Definition: dsa.h:72
error_t sshExportEcdsaPrivateKey(const EcDomainParameters *params, const EcPrivateKey *privateKey, const EcPublicKey *publicKey, char_t *output, size_t *written, SshPrivateKeyFormat format)
Export an ECDSA private key to SSH private key file format.
EdDSA private key.
Definition: eddsa.h:59
EC public key.
Definition: ec.h:94
char char_t
Definition: compiler_port.h:48
@ 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 sshExportRsaPrivateKey(const RsaPrivateKey *privateKey, const RsaPublicKey *publicKey, char_t *output, size_t *written, SshPrivateKeyFormat format)
Export an RSA private key to SSH private key file format.
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 sshExportEcdsaPublicKey(const EcDomainParameters *params, const EcPublicKey *publicKey, char_t *output, size_t *written, SshPublicKeyFormat format)
Export an ECDSA public key to SSH public key file format.
error_t sshExportOpenSshEcdsaPrivateKey(const EcDomainParameters *params, const EcPrivateKey *privateKey, const EcPublicKey *publicKey, char_t *output, size_t *written)
Export an ECDSA private key to OpenSSH private key file format.
ECC (Elliptic Curve Cryptography)
error_t sshExportEd448PrivateKey(const EddsaPrivateKey *privateKey, const EddsaPublicKey *publicKey, char_t *output, size_t *written, SshPrivateKeyFormat format)
Export an Ed448 private key to SSH private key file format.
error_t sshExportOpenSshEd25519PrivateKey(const EddsaPrivateKey *privateKey, const EddsaPublicKey *publicKey, char_t *output, size_t *written)
Export an Ed25519 private key to OpenSSH private key file format.