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-2019 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 1.9.6
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;
51  const uint8_t *n;
52  size_t nLen;
53  const uint8_t *e;
54  size_t eLen;
55  const uint8_t *d;
56  size_t dLen;
57  const uint8_t *p;
58  size_t pLen;
59  const uint8_t *q;
60  size_t qLen;
61  const uint8_t *dp;
62  size_t dpLen;
63  const uint8_t *dq;
64  size_t dqLen;
65  const uint8_t *qinv;
66  size_t qinvLen;
68 
69 
70 /**
71  * @brief DSA private key
72  **/
73 
74 typedef struct
75 {
76  const uint8_t *x;
77  size_t xLen;
79 
80 
81 /**
82  * @brief EC private key
83  **/
84 
85 typedef struct
86 {
87  int32_t version;
88  const uint8_t *d;
89  size_t dLen;
91 
92 
93 /**
94  * @brief EdDSA private key
95  **/
96 
97 typedef struct
98 {
99  const uint8_t *d;
100  size_t dLen;
102 
103 
104 /**
105  * @brief Private key information
106  **/
107 
108 typedef struct
109 {
110  int32_t version;
111  const uint8_t *oid;
112  size_t oidLen;
113 #if (RSA_SUPPORT == ENABLED)
115 #endif
116 #if (DSA_SUPPORT == ENABLED)
119 #endif
120 #if (EC_SUPPORT == ENABLED)
123 #endif
124 #if (ED25519_SUPPORT == ENABLED || ED448_SUPPORT == ENABLED)
126 #endif
128 
129 
130 //Key parsing functions
131 error_t pkcs8ParsePrivateKeyInfo(const uint8_t *data, size_t length,
132  Pkcs8PrivateKeyInfo *privateKeyInfo);
133 
134 error_t pkcs8ParsePrivateKeyAlgo(const uint8_t *data, size_t length,
135  size_t *totalLength, Pkcs8PrivateKeyInfo *privateKeyInfo);
136 
137 error_t pkcs8ParseRsaPrivateKey(const uint8_t *data, size_t length,
138  Pkcs8RsaPrivateKey *rsaPrivateKey);
139 
140 error_t pkcs8ParseDsaPrivateKey(const uint8_t *data, size_t length,
141  X509DsaParameters *dsaParams, Pkcs8DsaPrivateKey *dsaPrivateKey);
142 
143 error_t pkcs8ParseEcPrivateKey(const uint8_t *data, size_t length,
144  X509EcParameters *ecParams, Pkcs8EcPrivateKey *ecPrivateKey);
145 
146 error_t pkcs8ParseEddsaPrivateKey(const uint8_t *data, size_t length,
147  Pkcs8EddsaPrivateKey *eddsaPrivateKey);
148 
150  RsaPrivateKey *privateKey);
151 
153  DsaPrivateKey *privateKey);
154 
156  Mpi *privateKey);
157 
159  EddsaPrivateKey *privateKey);
160 
161 //C++ guard
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 #endif
X.509 common definitions.
Pkcs8RsaPrivateKey rsaPrivateKey
uint8_t length
Definition: dtls_misc.h:149
Private key information.
const uint8_t * oid
Arbitrary precision integer.
Definition: mpi.h:69
error_t pkcs8ImportRsaPrivateKey(const Pkcs8PrivateKeyInfo *privateKeyInfo, RsaPrivateKey *privateKey)
Import an RSA private key.
const uint8_t * d
const uint8_t * q
RSA private key.
const uint8_t * d
EdDSA private key.
error_t pkcs8ImportEddsaPrivateKey(const Pkcs8PrivateKeyInfo *privateKeyInfo, EddsaPrivateKey *privateKey)
Import an EdDSA private key.
Pkcs8EcPrivateKey ecPrivateKey
const uint8_t * n
error_t
Error codes.
Definition: error.h:42
EC parameters.
Definition: x509_common.h:672
error_t pkcs8ParseEddsaPrivateKey(const uint8_t *data, size_t length, Pkcs8EddsaPrivateKey *eddsaPrivateKey)
Parse CurvePrivateKey structure.
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 an DSA private key.
error_t pkcs8ParseEcPrivateKey(const uint8_t *data, size_t length, X509EcParameters *ecParams, Pkcs8EcPrivateKey *ecPrivateKey)
Parse ECPrivateKey structure.
const uint8_t * e
X509DsaParameters dsaParams
General definitions for cryptographic algorithms.
Pkcs8EddsaPrivateKey eddsaPrivateKey
DSA private key.
Definition: dsa.h:73
const uint8_t * qinv
EdDSA private key.
Definition: eddsa.h:58
const uint8_t * x
const uint8_t * dp
RSA private key.
Definition: rsa.h:59
const uint8_t * d
DSA domain parameters.
Definition: x509_common.h:646
error_t pkcs8ImportEcPrivateKey(const Pkcs8PrivateKeyInfo *privateKeyInfo, Mpi *privateKey)
Import an EC private key.
error_t pkcs8ParseDsaPrivateKey(const uint8_t *data, size_t length, X509DsaParameters *dsaParams, Pkcs8DsaPrivateKey *dsaPrivateKey)
Parse DSAPrivateKey structure.
const uint8_t * dq
Pkcs8DsaPrivateKey dsaPrivateKey
uint8_t data[]
Definition: dtls_misc.h:176
EC private key.
DSA private key.
X509EcParameters ecParams
const uint8_t * p
error_t pkcs8ParsePrivateKeyAlgo(const uint8_t *data, size_t length, size_t *totalLength, Pkcs8PrivateKeyInfo *privateKeyInfo)
Parse PrivateKeyAlgorithm structure.