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-2024 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.4.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 Private key information
95  **/
96 
97 typedef struct
98 {
99  int32_t version;
101 #if (RSA_SUPPORT == ENABLED)
103 #endif
104 #if (DSA_SUPPORT == ENABLED)
107 #endif
108 #if (EC_SUPPORT == ENABLED)
111 #endif
112 #if (ED25519_SUPPORT == ENABLED || ED448_SUPPORT == ENABLED)
114 #endif
116 
117 
118 /**
119  * @brief Encrypted private key information
120  **/
121 
122 typedef struct
123 {
127 
128 
129 //Key parsing functions
130 error_t pkcs8ParsePrivateKeyInfo(const uint8_t *data, size_t length,
131  Pkcs8PrivateKeyInfo *privateKeyInfo);
132 
133 error_t pkcs8ParsePrivateKeyAlgo(const uint8_t *data, size_t length,
134  size_t *totalLength, Pkcs8PrivateKeyInfo *privateKeyInfo);
135 
136 error_t pkcs8ParseRsaPrivateKey(const uint8_t *data, size_t length,
137  Pkcs8RsaPrivateKey *rsaPrivateKey);
138 
139 error_t pkcs8ParseDsaPrivateKey(const uint8_t *data, size_t length,
140  X509DsaParameters *dsaParams, Pkcs8DsaPrivateKey *dsaPrivateKey);
141 
142 error_t pkcs8ParseEcPrivateKey(const uint8_t *data, size_t length,
143  X509EcParameters *ecParams, Pkcs8EcPrivateKey *ecPrivateKey);
144 
145 error_t pkcs8ParseEddsaPrivateKey(const uint8_t *data, size_t length,
146  Pkcs8EddsaPrivateKey *eddsaPrivateKey);
147 
149  Pkcs8EncryptedPrivateKeyInfo *encryptedPrivateKeyInfo);
150 
151 error_t pkcs8ParseEncryptionAlgoId(const uint8_t *data, size_t length,
152  size_t *totalLength, X509AlgoId *encryptionAlgoId);
153 
155  RsaPrivateKey *privateKey);
156 
158  DsaPrivateKey *privateKey);
159 
161  EcPrivateKey *privateKey);
162 
164  EddsaPrivateKey *privateKey);
165 
166 //C++ guard
167 #ifdef __cplusplus
168 }
169 #endif
170 
171 #endif
X509OctetString dq
X.509 common definitions.
Pkcs8RsaPrivateKey rsaPrivateKey
Private key information.
error_t pkcs8ImportRsaPrivateKey(const Pkcs8PrivateKeyInfo *privateKeyInfo, RsaPrivateKey *privateKey)
Import an RSA private key.
uint8_t data[]
Definition: ethernet.h:222
Encrypted private key information.
RSA private key.
X509OctetString d
uint16_t totalLength
Definition: ipv4.h:322
EdDSA private key.
error_t pkcs8ParseEncryptedPrivateKeyInfo(const uint8_t *data, size_t length, Pkcs8EncryptedPrivateKeyInfo *encryptedPrivateKeyInfo)
Parse EncryptedPrivateKeyInfo structure.
X509OctetString n
error_t pkcs8ImportEddsaPrivateKey(const Pkcs8PrivateKeyInfo *privateKeyInfo, EddsaPrivateKey *privateKey)
Import an EdDSA private key.
Pkcs8EcPrivateKey ecPrivateKey
error_t
Error codes.
Definition: error.h:43
EC parameters.
Definition: x509_common.h:770
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.
error_t pkcs8ImportDsaPrivateKey(const Pkcs8PrivateKeyInfo *privateKeyInfo, DsaPrivateKey *privateKey)
Import a DSA private key.
error_t pkcs8ParseEcPrivateKey(const uint8_t *data, size_t length, X509EcParameters *ecParams, Pkcs8EcPrivateKey *ecPrivateKey)
Parse ECPrivateKey structure.
X509OctetString p
X509DsaParameters dsaParams
General definitions for cryptographic algorithms.
X509OctetString q
EC private key.
Definition: ec.h:104
Pkcs8EddsaPrivateKey eddsaPrivateKey
DSA private key.
Definition: dsa.h:72
uint8_t length
Definition: tcp.h:368
EdDSA private key.
Definition: eddsa.h:59
X509OctetString d
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:748
X509OctetString qinv
error_t pkcs8ImportEcPrivateKey(const Pkcs8PrivateKeyInfo *privateKeyInfo, EcPrivateKey *privateKey)
Import an EC private key.
error_t pkcs8ParseDsaPrivateKey(const uint8_t *data, size_t length, X509DsaParameters *dsaParams, Pkcs8DsaPrivateKey *dsaPrivateKey)
Parse DSAPrivateKey structure.
Pkcs8DsaPrivateKey dsaPrivateKey
Octet string.
Definition: x509_common.h:653
EC private key.
DSA private key.
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:726