ssh_key_export.c File Reference

SSH key file export functions. More...

#include "ssh/ssh.h"
#include "ssh/ssh_key_export.h"
#include "ssh/ssh_key_parse.h"
#include "ssh/ssh_key_format.h"
#include "ssh/ssh_misc.h"
#include "encoding/base64.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   SSH_TRACE_LEVEL
 

Functions

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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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) More...
 
error_t sshEncodeSsh2PublicKeyFile (const void *input, size_t inputLen, char_t *output, size_t *outputLen)
 Encode SSH public key file (SSH2 format) More...
 
error_t sshEncodeOpenSshPublicKeyFile (const void *input, size_t inputLen, char_t *output, size_t *outputLen)
 Encode SSH public key file (OpenSSH format) More...
 
error_t sshEncodeOpenSshPrivateKeyFile (const void *input, size_t inputLen, char_t *output, size_t *outputLen)
 Encode SSH private key file (OpenSSH format) More...
 

Detailed Description

SSH key file export functions.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2019-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneSSH Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file ssh_key_export.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   SSH_TRACE_LEVEL

Definition at line 32 of file ssh_key_export.c.

Function Documentation

◆ sshEncodeOpenSshPrivateKeyFile()

error_t sshEncodeOpenSshPrivateKeyFile ( const void *  input,
size_t  inputLen,
char_t output,
size_t *  outputLen 
)

Encode SSH private key file (OpenSSH format)

Parameters
[in]inputPrivate key structure to encode
[in]inputLenLength of the private key structure to encode
[out]outputSSH private key file (optional parameter)
[out]outputLenLength of the SSH private key file

Definition at line 974 of file ssh_key_export.c.

◆ sshEncodeOpenSshPublicKeyFile()

error_t sshEncodeOpenSshPublicKeyFile ( const void *  input,
size_t  inputLen,
char_t output,
size_t *  outputLen 
)

Encode SSH public key file (OpenSSH format)

Parameters
[in]inputHost key structure to encode
[in]inputLenLength of the host key structure to encode
[out]outputSSH public key file (optional parameter)
[out]outputLenLength of the SSH public key file

Definition at line 915 of file ssh_key_export.c.

◆ sshEncodePublicKeyFile()

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)

Parameters
[in]inputHost key structure to encode
[in]inputLenLength of the host key structure to encode
[out]outputSSH public key file (optional parameter)
[out]outputLenLength of the SSH public key file
[in]formatDesired output format (SSH2 or OpenSSH)

Definition at line 831 of file ssh_key_export.c.

◆ sshEncodeSsh2PublicKeyFile()

error_t sshEncodeSsh2PublicKeyFile ( const void *  input,
size_t  inputLen,
char_t output,
size_t *  outputLen 
)

Encode SSH public key file (SSH2 format)

Parameters
[in]inputHost key structure to encode
[in]inputLenLength of the host key structure to encode
[out]outputSSH public key file (optional parameter)
[out]outputLenLength of the SSH public key file

Definition at line 866 of file ssh_key_export.c.

◆ sshExportDsaPrivateKey()

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.

Parameters
[in]privateKeyDSA private key
[in]publicKeyDSA public key
[out]outputBuffer where to store the SSH private key file
[out]writtenLength of the resulting SSH private key file
[in]formatDesired output format (OpenSSH only is supported)
Returns
Error code

Definition at line 314 of file ssh_key_export.c.

◆ sshExportDsaPublicKey()

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.

Parameters
[in]publicKeyDSA public key
[out]outputBuffer where to store the SSH public key file
[out]writtenLength of the resulting SSH public key file
[in]formatDesired output format (SSH2 or OpenSSH)
Returns
Error code

Definition at line 100 of file ssh_key_export.c.

◆ sshExportEcdsaPrivateKey()

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.

Parameters
[in]paramsEC domain parameters
[in]privateKeyECDSA private key
[in]publicKeyECDSA public key
[out]outputBuffer where to store the SSH private key file
[out]writtenLength of the resulting SSH private key file
[in]formatDesired output format (OpenSSH only is supported)
Returns
Error code

Definition at line 349 of file ssh_key_export.c.

◆ sshExportEcdsaPublicKey()

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.

Parameters
[in]paramsEC domain parameters
[in]publicKeyECDSA public key
[out]outputBuffer where to store the SSH public key file
[out]writtenLength of the resulting SSH public key file
[in]formatDesired output format (SSH2 or OpenSSH)
Returns
Error code

Definition at line 145 of file ssh_key_export.c.

◆ sshExportEd25519PrivateKey()

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.

Parameters
[in]privateKeyEd25519 private key
[in]publicKeyEd25519 public key
[out]outputBuffer where to store the SSH private key file
[out]writtenLength of the resulting SSH private key file
[in]formatDesired output format (OpenSSH only is supported)
Returns
Error code

Definition at line 383 of file ssh_key_export.c.

◆ sshExportEd25519PublicKey()

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.

Parameters
[in]publicKeyEd25519 public key
[out]outputBuffer where to store the SSH public key file
[out]writtenLength of the resulting SSH public key file
[in]formatDesired output format (SSH2 or OpenSSH)
Returns
Error code

Definition at line 190 of file ssh_key_export.c.

◆ sshExportEd448PrivateKey()

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.

Parameters
[in]privateKeyEd448 private key
[in]publicKeyEd448 public key
[out]outputBuffer where to store the SSH private key file
[out]writtenLength of the resulting SSH private key file
[in]formatDesired output format (OpenSSH only is supported)
Returns
Error code

Definition at line 417 of file ssh_key_export.c.

◆ sshExportEd448PublicKey()

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.

Parameters
[in]publicKeyEd448 public key
[out]outputBuffer where to store the SSH public key file
[out]writtenLength of the resulting SSH public key file
[in]formatDesired output format (SSH2 or OpenSSH)
Returns
Error code

Definition at line 235 of file ssh_key_export.c.

◆ sshExportOpenSshDsaPrivateKey()

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.

Parameters
[in]privateKeyDSA private key
[in]publicKeyDSA public key
[out]outputBuffer where to store the OpenSSH private key file
[out]writtenLength of the resulting OpenSSH private key file
Returns
Error code

Definition at line 525 of file ssh_key_export.c.

◆ sshExportOpenSshEcdsaPrivateKey()

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.

Parameters
[in]paramsEC domain parameters
[in]privateKeyECDSA private key
[in]publicKeyECDSA public key
[out]outputBuffer where to store the OpenSSH private key file
[out]writtenLength of the resulting OpenSSH private key file
Returns
Error code

Definition at line 602 of file ssh_key_export.c.

◆ sshExportOpenSshEd25519PrivateKey()

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.

Parameters
[in]privateKeyEd25519 private key
[in]publicKeyEd25519 public key
[out]outputBuffer where to store the OpenSSH private key file
[out]writtenLength of the resulting OpenSSH private key file
Returns
Error code

Definition at line 679 of file ssh_key_export.c.

◆ sshExportOpenSshEd448PrivateKey()

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.

Parameters
[in]privateKeyEd448 private key
[in]publicKeyEd448 public key
[out]outputBuffer where to store the OpenSSH private key file
[out]writtenLength of the resulting OpenSSH private key file
Returns
Error code

Definition at line 755 of file ssh_key_export.c.

◆ sshExportOpenSshRsaPrivateKey()

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.

Parameters
[in]privateKeyRSA private key
[in]publicKeyRSA public key
[out]outputBuffer where to store the OpenSSH private key file
[out]writtenLength of the resulting OpenSSH private key file
Returns
Error code

Definition at line 450 of file ssh_key_export.c.

◆ sshExportRsaPrivateKey()

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.

Parameters
[in]privateKeyRSA private key
[in]publicKeyRSA public key
[out]outputBuffer where to store the SSH private key file
[out]writtenLength of the resulting SSH private key file
[in]formatDesired output format (OpenSSH only is supported)
Returns
Error code

Definition at line 280 of file ssh_key_export.c.

◆ sshExportRsaPublicKey()

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.

Parameters
[in]publicKeyRSA public key
[out]outputBuffer where to store the SSH public key file
[out]writtenLength of the resulting SSH public key file
[in]formatDesired output format (SSH2 or OpenSSH)
Returns
Error code

Definition at line 56 of file ssh_key_export.c.