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-2026 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.6.4
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 ML-DSA private key
105  **/
106 
107 typedef struct
108 {
112 
113 
114 /**
115  * @brief ML-DSA public key
116  **/
117 
118 typedef struct
119 {
122 
123 
124 /**
125  * @brief Private key information
126  **/
127 
128 typedef struct
129 {
130  int32_t version;
132 #if (RSA_SUPPORT == ENABLED)
134 #endif
135 #if (DSA_SUPPORT == ENABLED)
139 #endif
140 #if (EC_SUPPORT == ENABLED)
144 #endif
145 #if (ED25519_SUPPORT == ENABLED || ED448_SUPPORT == ENABLED)
148 #endif
149 #if (MLDSA44_SUPPORT == ENABLED || MLDSA65_SUPPORT == ENABLED || \
150  MLDSA87_SUPPORT == ENABLED)
153 #endif
155 
156 
157 /**
158  * @brief Encrypted private key information
159  **/
160 
161 typedef struct
162 {
166 
167 
168 //Key parsing functions
169 error_t pkcs8ParsePrivateKeyInfo(const uint8_t *data, size_t length,
170  Pkcs8PrivateKeyInfo *privateKeyInfo);
171 
172 error_t pkcs8ParsePrivateKeyAlgo(const uint8_t *data, size_t length,
173  size_t *totalLength, Pkcs8PrivateKeyInfo *privateKeyInfo);
174 
175 error_t pkcs8ParseRsaPrivateKey(const uint8_t *data, size_t length,
176  Pkcs8RsaPrivateKey *rsaPrivateKey);
177 
178 error_t pkcs8ParseDsaPrivateKey(const uint8_t *data, size_t length,
179  X509DsaParameters *dsaParams, Pkcs8DsaPrivateKey *dsaPrivateKey,
180  X509DsaPublicKey *dsaPublicKey);
181 
182 error_t pkcs8ParseEcPrivateKey(const uint8_t *data, size_t length,
183  X509EcParameters *ecParams, Pkcs8EcPrivateKey *ecPrivateKey,
184  X509EcPublicKey *ecPublicKey);
185 
186 error_t pkcs8ParseEcPublicKey(const uint8_t *data, size_t length,
187  X509EcPublicKey *ecPublicKey);
188 
189 error_t pkcs8ParseEddsaPrivateKey(const uint8_t *data, size_t length,
190  Pkcs8EddsaPrivateKey *eddsaPrivateKey);
191 
192 error_t pkcs8ParseEddsaPublicKey(const uint8_t *data, size_t length,
193  Pkcs8EddsaPublicKey *eddsaPublicKey);
194 
195 error_t pkcs8ParseMldsaPrivateKey(const uint8_t *data, size_t length,
196  Pkcs8MldsaPrivateKey *mldsaPrivateKey);
197 
199  Pkcs8EncryptedPrivateKeyInfo *encryptedPrivateKeyInfo);
200 
201 error_t pkcs8ParseEncryptionAlgoId(const uint8_t *data, size_t length,
202  size_t *totalLength, X509AlgoId *encryptionAlgoId);
203 
205  const Pkcs8PrivateKeyInfo *privateKeyInfo);
206 
208  const Pkcs8PrivateKeyInfo *privateKeyInfo);
209 
211  const Pkcs8PrivateKeyInfo *privateKeyInfo);
212 
214  const Pkcs8PrivateKeyInfo *privateKeyInfo);
215 
217  const Pkcs8PrivateKeyInfo *privateKeyInfo);
218 
219 //C++ guard
220 #ifdef __cplusplus
221 }
222 #endif
223 
224 #endif
Pkcs8MldsaPrivateKey mldsaPrivateKey
X509OctetString dq
X.509 common definitions.
Pkcs8RsaPrivateKey rsaPrivateKey
X509OctetString pk
Private key information.
EdDSA public key.
uint8_t data[]
Definition: ethernet.h:224
Encrypted private key information.
ML-DSA private key.
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:348
error_t pkcs8ImportDsaPrivateKey(DsaPrivateKey *privateKey, const Pkcs8PrivateKeyInfo *privateKeyInfo)
Import a DSA private key.
EdDSA private key.
EC public key.
Definition: x509_common.h:858
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:848
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.
ML-DSA public key.
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
X509OctetString seed
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.
Pkcs8MldsaPublicKey mldsaPublicKey
DSA domain parameters.
Definition: x509_common.h:826
X509OctetString qinv
X509OctetString expandedKey
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.
ML-DSA private key.
Definition: mldsa.h:94
error_t pkcs8ParseDsaPrivateKey(const uint8_t *data, size_t length, X509DsaParameters *dsaParams, Pkcs8DsaPrivateKey *dsaPrivateKey, X509DsaPublicKey *dsaPublicKey)
Parse DSAPrivateKey structure.
error_t pkcs8ParseMldsaPrivateKey(const uint8_t *data, size_t length, Pkcs8MldsaPrivateKey *mldsaPrivateKey)
Parse ML-DSA-PrivateKey structure.
error_t pkcs8ImportMldsaPrivateKey(MldsaPrivateKey *privateKey, const Pkcs8PrivateKeyInfo *privateKeyInfo)
Import an ML-DSA private key.
X509OctetString q
Pkcs8DsaPrivateKey dsaPrivateKey
Octet string.
Definition: x509_common.h:731
EC private key.
DSA private key.
DSA public key.
Definition: x509_common.h:838
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:804
error_t pkcs8ParseEcPrivateKey(const uint8_t *data, size_t length, X509EcParameters *ecParams, Pkcs8EcPrivateKey *ecPrivateKey, X509EcPublicKey *ecPublicKey)
Parse ECPrivateKey structure.