x509_key_format.c File Reference

Formatting of ASN.1 encoded keys. More...

#include "core/crypto.h"
#include "pkix/x509_key_format.h"
#include "encoding/asn1.h"
#include "encoding/oid.h"
#include "ecc/eddsa.h"
#include "hash/sha1.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

Functions

error_t x509FormatSubjectPublicKeyInfo (const X509SubjectPublicKeyInfo *publicKeyInfo, const void *publicKey, uint8_t *keyId, uint8_t *output, size_t *written)
 Format SubjectPublicKeyInfo structure. More...
 
error_t x509FormatAlgoId (const X509SubjectPublicKeyInfo *publicKeyInfo, const void *params, uint8_t *output, size_t *written)
 Format AlgorithmIdentifier structure. More...
 
error_t x509FormatRsaPublicKey (const X509RsaPublicKey *rsaPublicKey, uint8_t *output, size_t *written)
 Format RSAPublicKey structure. More...
 
error_t x509FormatDsaPublicKey (const X509DsaPublicKey *dsaPublicKey, uint8_t *output, size_t *written)
 Format DSAPublicKey structure. More...
 
error_t x509FormatDsaParameters (const X509DsaParameters *dsaParams, uint8_t *output, size_t *written)
 Format DSA domain parameters. More...
 
error_t x509FormatEcPublicKey (const X509EcPublicKey *ecPublicKey, uint8_t *output, size_t *written)
 Format ECPublicKey structure. More...
 
error_t x509FormatEcParameters (const X509EcParameters *ecParams, uint8_t *output, size_t *written)
 Format ECParameters structure. More...
 
error_t x509ExportRsaPublicKey (const RsaPublicKey *publicKey, uint8_t *output, size_t *written)
 Export an RSA public key to ASN.1 format. More...
 
error_t x509ExportRsaPrivateKey (const RsaPrivateKey *privateKey, uint8_t *output, size_t *written)
 Export an RSA private key to ASN.1 format. More...
 
error_t x509ExportDsaPublicKey (const DsaPublicKey *publicKey, uint8_t *output, size_t *written)
 Export a DSA public key to ASN.1 format. More...
 
error_t x509ExportDsaPrivateKey (const DsaPrivateKey *privateKey, uint8_t *output, size_t *written)
 Export a DSA private key to ASN.1 format. More...
 
error_t x509ExportDsaParameters (const DsaDomainParameters *params, uint8_t *output, size_t *written)
 Export DSA domain parameters to ASN.1 format. More...
 
error_t x509ExportEcPublicKey (const X509SubjectPublicKeyInfo *publicKeyInfo, const EcPoint *publicKey, uint8_t *output, size_t *written)
 Export an EC public key to ASN.1 format. More...
 
error_t x509ExportEddsaPublicKey (const EddsaPublicKey *publicKey, size_t publicKeyLen, uint8_t *output, size_t *written)
 Export an EdDSA public key to ASN.1 format. More...
 
error_t x509ExportEddsaPrivateKey (const EddsaPrivateKey *privateKey, size_t privateKeyLen, uint8_t *output, size_t *written)
 Export an EdDSA private key to ASN.1 format. More...
 

Detailed Description

Formatting of ASN.1 encoded keys.

License

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

Copyright (C) 2010-2024 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.4.0

Definition in file x509_key_format.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file x509_key_format.c.

Function Documentation

◆ x509ExportDsaParameters()

error_t x509ExportDsaParameters ( const DsaDomainParameters params,
uint8_t *  output,
size_t *  written 
)

Export DSA domain parameters to ASN.1 format.

Parameters
[in]paramsPointer to the DSA domain parameters
[out]outputBuffer where to store the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 994 of file x509_key_format.c.

◆ x509ExportDsaPrivateKey()

error_t x509ExportDsaPrivateKey ( const DsaPrivateKey privateKey,
uint8_t *  output,
size_t *  written 
)

Export a DSA private key to ASN.1 format.

Parameters
[in]privateKeyPointer to the DSA private key
[out]outputBuffer where to store the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 966 of file x509_key_format.c.

◆ x509ExportDsaPublicKey()

error_t x509ExportDsaPublicKey ( const DsaPublicKey publicKey,
uint8_t *  output,
size_t *  written 
)

Export a DSA public key to ASN.1 format.

Parameters
[in]publicKeyPointer to the DSA public key
[out]outputBuffer where to store the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 938 of file x509_key_format.c.

◆ x509ExportEcPublicKey()

error_t x509ExportEcPublicKey ( const X509SubjectPublicKeyInfo publicKeyInfo,
const EcPoint publicKey,
uint8_t *  output,
size_t *  written 
)

Export an EC public key to ASN.1 format.

Parameters
[in]publicKeyInfoPublic key information
[in]publicKeyPointer to the EC public key
[out]outputBuffer where to store the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 1068 of file x509_key_format.c.

◆ x509ExportEddsaPrivateKey()

error_t x509ExportEddsaPrivateKey ( const EddsaPrivateKey privateKey,
size_t  privateKeyLen,
uint8_t *  output,
size_t *  written 
)

Export an EdDSA private key to ASN.1 format.

Parameters
[in]privateKeyPointer to the EdDSA private key
[in]privateKeyLenLength of the EdDSA private key, in bytes
[out]outputBuffer where to store the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 1152 of file x509_key_format.c.

◆ x509ExportEddsaPublicKey()

error_t x509ExportEddsaPublicKey ( const EddsaPublicKey publicKey,
size_t  publicKeyLen,
uint8_t *  output,
size_t *  written 
)

Export an EdDSA public key to ASN.1 format.

Parameters
[in]publicKeyPointer to the EdDSA public key
[in]publicKeyLenLength of the EdDSA public key, in bytes
[out]outputBuffer where to store the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 1123 of file x509_key_format.c.

◆ x509ExportRsaPrivateKey()

error_t x509ExportRsaPrivateKey ( const RsaPrivateKey privateKey,
uint8_t *  output,
size_t *  written 
)

Export an RSA private key to ASN.1 format.

Parameters
[in]privateKeyPointer to the RSA private key
[out]outputBuffer where to store the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 760 of file x509_key_format.c.

◆ x509ExportRsaPublicKey()

error_t x509ExportRsaPublicKey ( const RsaPublicKey publicKey,
uint8_t *  output,
size_t *  written 
)

Export an RSA public key to ASN.1 format.

Parameters
[in]publicKeyPointer to the RSA public key
[out]outputBuffer where to store the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 697 of file x509_key_format.c.

◆ x509FormatAlgoId()

error_t x509FormatAlgoId ( const X509SubjectPublicKeyInfo publicKeyInfo,
const void *  params,
uint8_t *  output,
size_t *  written 
)

Format AlgorithmIdentifier structure.

Parameters
[in]publicKeyInfoSubject's public key information
[in]paramsPointer to the domain parameters (DSA or ECDSA)
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 277 of file x509_key_format.c.

◆ x509FormatDsaParameters()

error_t x509FormatDsaParameters ( const X509DsaParameters dsaParams,
uint8_t *  output,
size_t *  written 
)

Format DSA domain parameters.

Parameters
[in]dsaParamsPointer to the DSA domain parameters
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 543 of file x509_key_format.c.

◆ x509FormatDsaPublicKey()

error_t x509FormatDsaPublicKey ( const X509DsaPublicKey dsaPublicKey,
uint8_t *  output,
size_t *  written 
)

Format DSAPublicKey structure.

Parameters
[in]dsaPublicKeyPointer to the DSA public key
[out]outputBuffer where to format the DSAPublicKey structure
[out]writtenLength of the DSAPublicKey structure
Returns
Error code

Definition at line 507 of file x509_key_format.c.

◆ x509FormatEcParameters()

error_t x509FormatEcParameters ( const X509EcParameters ecParams,
uint8_t *  output,
size_t *  written 
)

Format ECParameters structure.

Parameters
[in]ecParamsPointer to the EC parameters
[out]outputBuffer where to format the ECParameters structure
[out]writtenLength of the ECParameters structure
Returns
Error code

Definition at line 659 of file x509_key_format.c.

◆ x509FormatEcPublicKey()

error_t x509FormatEcPublicKey ( const X509EcPublicKey ecPublicKey,
uint8_t *  output,
size_t *  written 
)

Format ECPublicKey structure.

Parameters
[in]ecPublicKeyPointer to the EC public key
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 637 of file x509_key_format.c.

◆ x509FormatRsaPublicKey()

error_t x509FormatRsaPublicKey ( const X509RsaPublicKey rsaPublicKey,
uint8_t *  output,
size_t *  written 
)

Format RSAPublicKey structure.

Parameters
[in]rsaPublicKeyPointer to the RSA public key
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 430 of file x509_key_format.c.

◆ x509FormatSubjectPublicKeyInfo()

error_t x509FormatSubjectPublicKeyInfo ( const X509SubjectPublicKeyInfo publicKeyInfo,
const void *  publicKey,
uint8_t *  keyId,
uint8_t *  output,
size_t *  written 
)

Format SubjectPublicKeyInfo structure.

Parameters
[in]publicKeyInfoSubject's public key information
[in]publicKeyPointer to the public key (RSA, DSA, ECDSA or EdDSA)
[out]keyIdSubject's key identifier (optional parameter)
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 57 of file x509_key_format.c.