pkcs8_key_parse.h
Go to the documentation of this file.
1 /**
2  * @file pkcs8_key_parse.h
3  * @brief PKCS #8 key parsing
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO 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.5.0
29  **/
30 
31 #ifndef _PKCS8_KEY_PARSE_H
32 #define _PKCS8_KEY_PARSE_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "pkix/x509_common.h"
37 
38 //C++ guard
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 
44 /**
45  * @brief RSA private key
46  **/
47 
48 typedef struct
49 {
50  int32_t version;
60 
61 
62 /**
63  * @brief DSA private key
64  **/
65 
66 typedef struct
67 {
70 
71 
72 /**
73  * @brief EC private key
74  **/
75 
76 typedef struct
77 {
78  int32_t version;
81 
82 
83 /**
84  * @brief EdDSA private key
85  **/
86 
87 typedef struct
88 {
91 
92 
93 /**
94  * @brief EdDSA public key
95  **/
96 
97 typedef struct
98 {
101 
102 
103 /**
104  * @brief Private key information
105  **/
106 
107 typedef struct
108 {
109  int32_t version;
111 #if (RSA_SUPPORT == ENABLED)
113 #endif
114 #if (DSA_SUPPORT == ENABLED)
118 #endif
119 #if (EC_SUPPORT == ENABLED)
123 #endif
124 #if (ED25519_SUPPORT == ENABLED || ED448_SUPPORT == ENABLED)
127 #endif
129 
130 
131 /**
132  * @brief Encrypted private key information
133  **/
134 
135 typedef struct
136 {
140 
141 
142 //Key parsing functions
143 error_t pkcs8ParsePrivateKeyInfo(const uint8_t *data, size_t length,
144  Pkcs8PrivateKeyInfo *privateKeyInfo);
145 
146 error_t pkcs8ParsePrivateKeyAlgo(const uint8_t *data, size_t length,
147  size_t *totalLength, Pkcs8PrivateKeyInfo *privateKeyInfo);
148 
149 error_t pkcs8ParseRsaPrivateKey(const uint8_t *data, size_t length,
150  Pkcs8RsaPrivateKey *rsaPrivateKey);
151 
152 error_t pkcs8ParseDsaPrivateKey(const uint8_t *data, size_t length,
153  X509DsaParameters *dsaParams, Pkcs8DsaPrivateKey *dsaPrivateKey,
154  X509DsaPublicKey *dsaPublicKey);
155 
156 error_t pkcs8ParseEcPrivateKey(const uint8_t *data, size_t length,
157  X509EcParameters *ecParams, Pkcs8EcPrivateKey *ecPrivateKey,
158  X509EcPublicKey *ecPublicKey);
159 
160 error_t pkcs8ParseEcPublicKey(const uint8_t *data, size_t length,
161  X509EcPublicKey *ecPublicKey);
162 
163 error_t pkcs8ParseEddsaPrivateKey(const uint8_t *data, size_t length,
164  Pkcs8EddsaPrivateKey *eddsaPrivateKey);
165 
166 error_t pkcs8ParseEddsaPublicKey(const uint8_t *data, size_t length,
167  Pkcs8EddsaPublicKey *eddsaPublicKey);
168 
170  Pkcs8EncryptedPrivateKeyInfo *encryptedPrivateKeyInfo);
171 
172 error_t pkcs8ParseEncryptionAlgoId(const uint8_t *data, size_t length,
173  size_t *totalLength, X509AlgoId *encryptionAlgoId);
174 
176  const Pkcs8PrivateKeyInfo *privateKeyInfo);
177 
179  const Pkcs8PrivateKeyInfo *privateKeyInfo);
180 
182  const Pkcs8PrivateKeyInfo *privateKeyInfo);
183 
185  const Pkcs8PrivateKeyInfo *privateKeyInfo);
186 
187 //C++ guard
188 #ifdef __cplusplus
189 }
190 #endif
191 
192 #endif
X509OctetString dq
X.509 common definitions.
Pkcs8RsaPrivateKey rsaPrivateKey
Private key information.
EdDSA public key.
uint8_t data[]
Definition: ethernet.h:222
Encrypted private key information.
RSA private key.
X509DsaPublicKey dsaPublicKey
X509OctetString d
error_t pkcs8ParseEddsaPublicKey(const uint8_t *data, size_t length, Pkcs8EddsaPublicKey *eddsaPublicKey)
Parse publicKey structure.
uint16_t totalLength
Definition: ipv4.h:323
error_t pkcs8ImportDsaPrivateKey(DsaPrivateKey *privateKey, const Pkcs8PrivateKeyInfo *privateKeyInfo)
Import a DSA private key.
EdDSA private key.
EC public key.
Definition: x509_common.h:828
error_t pkcs8ParseEncryptedPrivateKeyInfo(const uint8_t *data, size_t length, Pkcs8EncryptedPrivateKeyInfo *encryptedPrivateKeyInfo)
Parse EncryptedPrivateKeyInfo structure.
X509OctetString n
Pkcs8EcPrivateKey ecPrivateKey
error_t
Error codes.
Definition: error.h:43
EC parameters.
Definition: x509_common.h:818
X509OctetString dp
error_t pkcs8ParseEddsaPrivateKey(const uint8_t *data, size_t length, Pkcs8EddsaPrivateKey *eddsaPrivateKey)
Parse CurvePrivateKey structure.
X509OctetString e
error_t pkcs8ParseRsaPrivateKey(const uint8_t *data, size_t length, Pkcs8RsaPrivateKey *rsaPrivateKey)
Parse RSAPrivateKey structure.
error_t pkcs8ParsePrivateKeyInfo(const uint8_t *data, size_t length, Pkcs8PrivateKeyInfo *privateKeyInfo)
Parse PrivateKeyInfo structure.
X509OctetString p
X509EcPublicKey ecPublicKey
X509DsaParameters dsaParams
Pkcs8EddsaPublicKey eddsaPublicKey
General definitions for cryptographic algorithms.
X509OctetString q
EC private key.
Definition: ec.h:432
Pkcs8EddsaPrivateKey eddsaPrivateKey
DSA private key.
Definition: dsa.h:72
error_t pkcs8ParseEcPublicKey(const uint8_t *data, size_t length, X509EcPublicKey *ecPublicKey)
Parse publicKey structure.
uint8_t length
Definition: tcp.h:375
EdDSA private key.
Definition: eddsa.h:75
X509OctetString d
error_t pkcs8ImportRsaPrivateKey(RsaPrivateKey *privateKey, const Pkcs8PrivateKeyInfo *privateKeyInfo)
Import an RSA private key.
X509OctetString d
RSA private key.
Definition: rsa.h:68
error_t pkcs8ParseEncryptionAlgoId(const uint8_t *data, size_t length, size_t *totalLength, X509AlgoId *encryptionAlgoId)
Parse EncryptionAlgorithmIdentifier structure.
DSA domain parameters.
Definition: x509_common.h:796
X509OctetString qinv
error_t pkcs8ImportEddsaPrivateKey(EddsaPrivateKey *privateKey, const Pkcs8PrivateKeyInfo *privateKeyInfo)
Import an EdDSA private key.
error_t pkcs8ImportEcPrivateKey(EcPrivateKey *privateKey, const Pkcs8PrivateKeyInfo *privateKeyInfo)
Import an EC private key.
error_t pkcs8ParseDsaPrivateKey(const uint8_t *data, size_t length, X509DsaParameters *dsaParams, Pkcs8DsaPrivateKey *dsaPrivateKey, X509DsaPublicKey *dsaPublicKey)
Parse DSAPrivateKey structure.
X509OctetString q
Pkcs8DsaPrivateKey dsaPrivateKey
Octet string.
Definition: x509_common.h:701
EC private key.
DSA private key.
DSA public key.
Definition: x509_common.h:808
X509EcParameters ecParams
X509OctetString oid
X509OctetString x
error_t pkcs8ParsePrivateKeyAlgo(const uint8_t *data, size_t length, size_t *totalLength, Pkcs8PrivateKeyInfo *privateKeyInfo)
Parse PrivateKeyAlgorithm structure.
Algorithm identifier.
Definition: x509_common.h:774
error_t pkcs8ParseEcPrivateKey(const uint8_t *data, size_t length, X509EcParameters *ecParams, Pkcs8EcPrivateKey *ecPrivateKey, X509EcPublicKey *ecPublicKey)
Parse ECPrivateKey structure.