pem_import.c File Reference

PEM file import functions. More...

#include "core/crypto.h"
#include "pkix/pem_import.h"
#include "pkix/pem_decrypt.h"
#include "pkix/pkcs5_decrypt.h"
#include "pkix/pkcs8_key_parse.h"
#include "pkix/x509_key_parse.h"
#include "encoding/asn1.h"
#include "encoding/oid.h"
#include "mpi/mpi.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

Functions

error_t pemImportCertificate (const char_t *input, size_t inputLen, uint8_t *output, size_t *outputLen, size_t *consumed)
 Decode a PEM file containing a certificate. More...
 
error_t pemImportCrl (const char_t *input, size_t inputLen, uint8_t *output, size_t *outputLen, size_t *consumed)
 Decode a PEM file containing a certificate revocation list. More...
 
error_t pemImportCsr (const char_t *input, size_t inputLen, uint8_t *output, size_t *outputLen)
 Decode a PEM file containing a certification signing request. More...
 
error_t pemImportDhParameters (DhParameters *params, const char_t *input, size_t length)
 Decode a PEM file containing Diffie-Hellman parameters. More...
 
error_t pemImportRsaPublicKey (RsaPublicKey *publicKey, const char_t *input, size_t length)
 Decode a PEM file containing an RSA public key. More...
 
error_t pemImportRsaPrivateKey (RsaPrivateKey *privateKey, const char_t *input, size_t length, const char_t *password)
 Decode a PEM file containing an RSA private key. More...
 
error_t pemImportDsaPublicKey (DsaPublicKey *publicKey, const char_t *input, size_t length)
 Decode a PEM file containing a DSA public key. More...
 
error_t pemImportDsaPrivateKey (DsaPrivateKey *privateKey, const char_t *input, size_t length, const char_t *password)
 Decode a PEM file containing a DSA private key. More...
 
error_t pemImportEcPublicKey (EcPublicKey *publicKey, const char_t *input, size_t length)
 Decode a PEM file containing an EC public key. More...
 
error_t pemImportEcPrivateKey (EcPrivateKey *privateKey, const char_t *input, size_t length, const char_t *password)
 Decode a PEM file containing an EC private key. More...
 
error_t pemImportEddsaPublicKey (EddsaPublicKey *publicKey, const char_t *input, size_t length)
 Decode a PEM file containing a EdDSA public key. More...
 
error_t pemImportEddsaPrivateKey (EddsaPrivateKey *privateKey, const char_t *input, size_t length, const char_t *password)
 Decode a PEM file containing a EdDSA private key. More...
 
X509KeyType pemGetPublicKeyType (const char_t *input, size_t length)
 Extract the public key type from a PEM file. More...
 
const EcCurvepemGetPublicKeyCurve (const char_t *input, size_t length)
 Extract elliptic curve parameters from a PEM file. More...
 

Detailed Description

PEM file import functions.

License

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

Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneCRYPTO 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.5.0

Definition in file pem_import.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file pem_import.c.

Function Documentation

◆ pemGetPublicKeyCurve()

const EcCurve* pemGetPublicKeyCurve ( const char_t input,
size_t  length 
)

Extract elliptic curve parameters from a PEM file.

Parameters
[in]inputPointer to the PEM encoding
[in]lengthLength of the PEM encoding
Returns
Elliptic curve parameters

Definition at line 1455 of file pem_import.c.

◆ pemGetPublicKeyType()

X509KeyType pemGetPublicKeyType ( const char_t input,
size_t  length 
)

Extract the public key type from a PEM file.

Parameters
[in]inputPointer to the PEM encoding
[in]lengthLength of the PEM encoding
Returns
Public key type

Definition at line 1373 of file pem_import.c.

◆ pemImportCertificate()

error_t pemImportCertificate ( const char_t input,
size_t  inputLen,
uint8_t *  output,
size_t *  outputLen,
size_t *  consumed 
)

Decode a PEM file containing a certificate.

Parameters
[in]inputPointer to the PEM encoding
[in]inputLenLength of the PEM structure
[out]outputPointer to the DER-encoded certificate
[out]outputLenLength of the DER-encoded certificate, in bytes
[out]consumedTotal number of characters that have been consumed (optional parameter)
Returns
Error code

Definition at line 61 of file pem_import.c.

◆ pemImportCrl()

error_t pemImportCrl ( const char_t input,
size_t  inputLen,
uint8_t *  output,
size_t *  outputLen,
size_t *  consumed 
)

Decode a PEM file containing a certificate revocation list.

Parameters
[in]inputPointer to the PEM encoding
[in]inputLenLength of the PEM structure
[out]outputPointer to the DER-encoded CRL
[out]outputLenLength of the DER-encoded CRL, in bytes
[out]consumedTotal number of characters that have been consumed (optional parameter)
Returns
Error code

Definition at line 90 of file pem_import.c.

◆ pemImportCsr()

error_t pemImportCsr ( const char_t input,
size_t  inputLen,
uint8_t *  output,
size_t *  outputLen 
)

Decode a PEM file containing a certification signing request.

Parameters
[in]inputPointer to the PEM encoding
[in]inputLenLength of the PEM structure
[out]outputPointer to the DER-encoded CSR
[out]outputLenLength of the DER-encoded CSR, in bytes
Returns
Error code

Definition at line 117 of file pem_import.c.

◆ pemImportDhParameters()

error_t pemImportDhParameters ( DhParameters params,
const char_t input,
size_t  length 
)

Decode a PEM file containing Diffie-Hellman parameters.

Parameters
[out]paramsDiffie-Hellman parameters resulting from the parsing process
[in]inputPointer to the PEM encoding
[in]lengthLength of the PEM encoding
Returns
Error code

Definition at line 143 of file pem_import.c.

◆ pemImportDsaPrivateKey()

error_t pemImportDsaPrivateKey ( DsaPrivateKey privateKey,
const char_t input,
size_t  length,
const char_t password 
)

Decode a PEM file containing a DSA private key.

Parameters
[out]privateKeyDSA private key resulting from the parsing process
[in]inputPointer to the PEM encoding
[in]lengthLength of the PEM encoding
[in]passwordNULL-terminated string containing the password. This parameter is required if the private key is encrypted
Returns
Error code

Definition at line 662 of file pem_import.c.

◆ pemImportDsaPublicKey()

error_t pemImportDsaPublicKey ( DsaPublicKey publicKey,
const char_t input,
size_t  length 
)

Decode a PEM file containing a DSA public key.

Parameters
[out]publicKeyDSA public key resulting from the parsing process
[in]inputPointer to the PEM encoding
[in]lengthLength of the PEM encoding
Returns
Error code

Definition at line 582 of file pem_import.c.

◆ pemImportEcPrivateKey()

error_t pemImportEcPrivateKey ( EcPrivateKey privateKey,
const char_t input,
size_t  length,
const char_t password 
)

Decode a PEM file containing an EC private key.

Parameters
[out]privateKeyEC private key resulting from the parsing process
[in]inputPointer to the PEM encoding
[in]lengthLength of the PEM encoding
[in]passwordNULL-terminated string containing the password. This parameter is required if the private key is encrypted
Returns
Error code

Definition at line 945 of file pem_import.c.

◆ pemImportEcPublicKey()

error_t pemImportEcPublicKey ( EcPublicKey publicKey,
const char_t input,
size_t  length 
)

Decode a PEM file containing an EC public key.

Parameters
[out]publicKeyEC public key resulting from the parsing process
[in]inputPointer to the PEM encoding
[in]lengthLength of the PEM encoding
Returns
Error code

Definition at line 865 of file pem_import.c.

◆ pemImportEddsaPrivateKey()

error_t pemImportEddsaPrivateKey ( EddsaPrivateKey privateKey,
const char_t input,
size_t  length,
const char_t password 
)

Decode a PEM file containing a EdDSA private key.

Parameters
[out]privateKeyEdDSA private key resulting from the parsing process
[in]inputPointer to the PEM encoding
[in]lengthLength of the PEM encoding
[in]passwordNULL-terminated string containing the password. This parameter is required if the private key is encrypted
Returns
Error code

Definition at line 1228 of file pem_import.c.

◆ pemImportEddsaPublicKey()

error_t pemImportEddsaPublicKey ( EddsaPublicKey publicKey,
const char_t input,
size_t  length 
)

Decode a PEM file containing a EdDSA public key.

Parameters
[out]publicKeyEdDSA public key resulting from the parsing process
[in]inputPointer to the PEM encoding
[in]lengthLength of the PEM encoding
Returns
Error code

Definition at line 1148 of file pem_import.c.

◆ pemImportRsaPrivateKey()

error_t pemImportRsaPrivateKey ( RsaPrivateKey privateKey,
const char_t input,
size_t  length,
const char_t password 
)

Decode a PEM file containing an RSA private key.

Parameters
[out]privateKeyRSA private key resulting from the parsing process
[in]inputPointer to the PEM encoding
[in]lengthLength of the PEM encoding
[in]passwordNULL-terminated string containing the password. This parameter is required if the private key is encrypted
Returns
Error code

Definition at line 379 of file pem_import.c.

◆ pemImportRsaPublicKey()

error_t pemImportRsaPublicKey ( RsaPublicKey publicKey,
const char_t input,
size_t  length 
)

Decode a PEM file containing an RSA public key.

Parameters
[out]publicKeyRSA public key resulting from the parsing process
[in]inputPointer to the PEM encoding
[in]lengthLength of the PEM encoding
Returns
Error code

Definition at line 252 of file pem_import.c.