pem_import.c File Reference

PEM file import functions. More...

#include "core/crypto.h"
#include "pkix/pem_import.h"
#include "pkix/pkcs8_key_parse.h"
#include "pkix/x509_key_parse.h"
#include "encoding/asn1.h"
#include "encoding/oid.h"
#include "encoding/base64.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 (const char_t *input, size_t length, DhParameters *params)
 Decode a PEM file containing Diffie-Hellman parameters. More...
 
error_t pemImportRsaPublicKey (const char_t *input, size_t length, RsaPublicKey *publicKey)
 Decode a PEM file containing an RSA public key. More...
 
error_t pemImportRsaPrivateKey (const char_t *input, size_t length, RsaPrivateKey *privateKey)
 Decode a PEM file containing an RSA private key. More...
 
error_t pemImportDsaPublicKey (const char_t *input, size_t length, DsaPublicKey *publicKey)
 Decode a PEM file containing a DSA public key. More...
 
error_t pemImportDsaPrivateKey (const char_t *input, size_t length, DsaPrivateKey *privateKey)
 Decode a PEM file containing a DSA private key. More...
 
error_t pemImportEcParameters (const char_t *input, size_t length, EcDomainParameters *params)
 Decode a PEM file containing EC domain parameters. More...
 
error_t pemImportEcPublicKey (const char_t *input, size_t length, EcPoint *publicKey)
 Decode a PEM file containing an EC public key. More...
 
error_t pemImportEcPrivateKey (const char_t *input, size_t length, Mpi *privateKey)
 Decode a PEM file containing an EC private key. More...
 
error_t pemImportEddsaPublicKey (const char_t *input, size_t length, EddsaPublicKey *publicKey)
 Decode a PEM file containing a EdDSA public key. More...
 
error_t pemImportEddsaPrivateKey (const char_t *input, size_t length, EddsaPrivateKey *privateKey)
 Decode a PEM file containing a EdDSA private key. More...
 
error_t pemGetPublicKeyType (const char_t *input, size_t length, X509KeyType *keyType)
 Retrieve the type of a PEM-encoded public key. More...
 
error_t pemGetPrivateKeyType (const char_t *input, size_t length, X509KeyType *keyType)
 Retrieve the type of a PEM-encoded private key. More...
 
error_t pemDecodeFile (const char_t *input, size_t inputLen, const char_t *label, uint8_t *output, size_t *outputLen, size_t *consumed)
 Convert PEM container to ASN.1 format. More...
 
int_t pemFindTag (const char_t *input, size_t inputLen, const char_t *tag1, const char_t *tag2, const char_t *tag3)
 Search a string for a given tag. More...
 

Detailed Description

PEM file import functions.

License

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

Copyright (C) 2010-2019 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
1.9.6

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

◆ pemDecodeFile()

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

Convert PEM container to ASN.1 format.

Parameters
[in]inputPEM container to decode
[in]inputLenLength of the PEM container to decode
[in]labelLabel indicating the type of data
[out]outputASN.1 data (optional parameter)
[out]outputLenLength of the ASN.1 data
[out]consumedTotal number of characters that have been consumed (optional parameter)

Definition at line 1468 of file pem_import.c.

◆ pemFindTag()

int_t pemFindTag ( const char_t input,
size_t  inputLen,
const char_t tag1,
const char_t tag2,
const char_t tag3 
)

Search a string for a given tag.

Parameters
[in]inputString to search
[in]inputLenLength of the string to search
[in]tag1First part of the tag (NULL-terminated string)
[in]tag2Second part of the tag (NULL-terminated string)
[in]tag3Third part of the tag (NULL-terminated string)
Returns
The index of the first occurrence of the tag in the string, or -1 if the tag does not appear in the string

Definition at line 1534 of file pem_import.c.

◆ pemGetPrivateKeyType()

error_t pemGetPrivateKeyType ( const char_t input,
size_t  length,
X509KeyType keyType 
)

Retrieve the type of a PEM-encoded private key.

Parameters
[in]inputPointer to the PEM encoding
[in]lengthLength of the PEM encoding
[out]Privatekey type
Returns
Error code

Definition at line 1356 of file pem_import.c.

◆ pemGetPublicKeyType()

error_t pemGetPublicKeyType ( const char_t input,
size_t  length,
X509KeyType keyType 
)

Retrieve the type of a PEM-encoded public key.

Parameters
[in]inputPointer to the PEM encoding
[in]lengthLength of the PEM encoding
[out]Publickey type
Returns
Error code

Definition at line 1264 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 60 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 91 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 120 of file pem_import.c.

◆ pemImportDhParameters()

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

Decode a PEM file containing Diffie-Hellman parameters.

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

Definition at line 148 of file pem_import.c.

◆ pemImportDsaPrivateKey()

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

Decode a PEM file containing a DSA private key.

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

Definition at line 585 of file pem_import.c.

◆ pemImportDsaPublicKey()

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

Decode a PEM file containing a DSA public key.

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

Definition at line 506 of file pem_import.c.

◆ pemImportEcParameters()

error_t pemImportEcParameters ( const char_t input,
size_t  length,
EcDomainParameters params 
)

Decode a PEM file containing EC domain parameters.

Parameters
[in]inputPointer to the PEM encoding
[in]lengthLength of the PEM encoding
[out]paramsEC domain parameters
Returns
Error code

Definition at line 709 of file pem_import.c.

◆ pemImportEcPrivateKey()

error_t pemImportEcPrivateKey ( const char_t input,
size_t  length,
Mpi privateKey 
)

Decode a PEM file containing an EC private key.

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

Definition at line 983 of file pem_import.c.

◆ pemImportEcPublicKey()

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

Decode a PEM file containing an EC public key.

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

Definition at line 904 of file pem_import.c.

◆ pemImportEddsaPrivateKey()

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

Decode a PEM file containing a EdDSA private key.

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

Definition at line 1186 of file pem_import.c.

◆ pemImportEddsaPublicKey()

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

Decode a PEM file containing a EdDSA public key.

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

Definition at line 1107 of file pem_import.c.

◆ pemImportRsaPrivateKey()

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

Decode a PEM file containing an RSA private key.

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

Definition at line 382 of file pem_import.c.

◆ pemImportRsaPublicKey()

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

Decode a PEM file containing an RSA public key.

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

Definition at line 258 of file pem_import.c.