pkcs5_common.h
Go to the documentation of this file.
1 /**
2  * @file pkcs5_common.h
3  * @brief PKCS #5 common definitions
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.0
29  **/
30 
31 #ifndef _PKCS5_COMMON_H
32 #define _PKCS5_COMMON_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //RC2 encryption support (insecure)
38 #ifndef PKCS5_RC2_SUPPORT
39  #define PKCS5_RC2_SUPPORT DISABLED
40 #elif (PKCS5_RC2_SUPPORT != ENABLED && PKCS5_RC2_SUPPORT != DISABLED)
41  #error PKCS5_RC2_SUPPORT parameter is not valid
42 #endif
43 
44 //DES encryption support (insecure)
45 #ifndef PKCS5_DES_SUPPORT
46  #define PKCS5_DES_SUPPORT DISABLED
47 #elif (PKCS5_DES_SUPPORT != ENABLED && PKCS5_DES_SUPPORT != DISABLED)
48  #error PKCS5_DES_SUPPORT parameter is not valid
49 #endif
50 
51 //Triple DES encryption support (weak)
52 #ifndef PKCS5_3DES_SUPPORT
53  #define PKCS5_3DES_SUPPORT DISABLED
54 #elif (PKCS5_3DES_SUPPORT != ENABLED && PKCS5_3DES_SUPPORT != DISABLED)
55  #error PKCS5_3DES_SUPPORT parameter is not valid
56 #endif
57 
58 //AES encryption support
59 #ifndef PKCS5_AES_SUPPORT
60  #define PKCS5_AES_SUPPORT ENABLED
61 #elif (PKCS5_AES_SUPPORT != ENABLED && PKCS5_AES_SUPPORT != DISABLED)
62  #error PKCS5_AES_SUPPORT parameter is not valid
63 #endif
64 
65 //Camellia encryption support
66 #ifndef PKCS5_CAMELLIA_SUPPORT
67  #define PKCS5_CAMELLIA_SUPPORT DISABLED
68 #elif (PKCS5_CAMELLIA_SUPPORT != ENABLED && PKCS5_CAMELLIA_SUPPORT != DISABLED)
69  #error PKCS5_CAMELLIA_SUPPORT parameter is not valid
70 #endif
71 
72 //ARIA encryption support
73 #ifndef PKCS5_ARIA_SUPPORT
74  #define PKCS5_ARIA_SUPPORT DISABLED
75 #elif (PKCS5_ARIA_SUPPORT != ENABLED && PKCS5_ARIA_SUPPORT != DISABLED)
76  #error PKCS5_ARIA_SUPPORT parameter is not valid
77 #endif
78 
79 //SM4 encryption support
80 #ifndef PKCS5_SM4_SUPPORT
81  #define PKCS5_SM4_SUPPORT DISABLED
82 #elif (PKCS5_SM4_SUPPORT != ENABLED && PKCS5_SM4_SUPPORT != DISABLED)
83  #error PKCS5_SM4_SUPPORT parameter is not valid
84 #endif
85 
86 //MD2 hash support (insecure)
87 #ifndef PKCS5_MD2_SUPPORT
88  #define PKCS5_MD2_SUPPORT DISABLED
89 #elif (PKCS5_MD2_SUPPORT != ENABLED && PKCS5_MD2_SUPPORT != DISABLED)
90  #error PKCS5_MD2_SUPPORT parameter is not valid
91 #endif
92 
93 //MD5 hash support (insecure)
94 #ifndef PKCS5_MD5_SUPPORT
95  #define PKCS5_MD5_SUPPORT DISABLED
96 #elif (PKCS5_MD5_SUPPORT != ENABLED && PKCS5_MD5_SUPPORT != DISABLED)
97  #error PKCS5_MD5_SUPPORT parameter is not valid
98 #endif
99 
100 //SHA-1 hash support (weak)
101 #ifndef PKCS5_SHA1_SUPPORT
102  #define PKCS5_SHA1_SUPPORT DISABLED
103 #elif (PKCS5_SHA1_SUPPORT != ENABLED && PKCS5_SHA1_SUPPORT != DISABLED)
104  #error PKCS5_SHA1_SUPPORT parameter is not valid
105 #endif
106 
107 //SHA-224 hash support (weak)
108 #ifndef PKCS5_SHA224_SUPPORT
109  #define PKCS5_SHA224_SUPPORT DISABLED
110 #elif (PKCS5_SHA224_SUPPORT != ENABLED && PKCS5_SHA224_SUPPORT != DISABLED)
111  #error PKCS5_SHA224_SUPPORT parameter is not valid
112 #endif
113 
114 //SHA-256 hash support
115 #ifndef PKCS5_SHA256_SUPPORT
116  #define PKCS5_SHA256_SUPPORT ENABLED
117 #elif (PKCS5_SHA256_SUPPORT != ENABLED && PKCS5_SHA256_SUPPORT != DISABLED)
118  #error PKCS5_SHA256_SUPPORT parameter is not valid
119 #endif
120 
121 //SHA-384 hash support
122 #ifndef PKCS5_SHA384_SUPPORT
123  #define PKCS5_SHA384_SUPPORT ENABLED
124 #elif (PKCS5_SHA384_SUPPORT != ENABLED && PKCS5_SHA384_SUPPORT != DISABLED)
125  #error PKCS5_SHA384_SUPPORT parameter is not valid
126 #endif
127 
128 //SHA-512 hash support
129 #ifndef PKCS5_SHA512_SUPPORT
130  #define PKCS5_SHA512_SUPPORT ENABLED
131 #elif (PKCS5_SHA512_SUPPORT != ENABLED && PKCS5_SHA512_SUPPORT != DISABLED)
132  #error PKCS5_SHA512_SUPPORT parameter is not valid
133 #endif
134 
135 //SHA-512/224 hash support
136 #ifndef PKCS5_SHA512_224_SUPPORT
137  #define PKCS5_SHA512_224_SUPPORT DISABLED
138 #elif (PKCS5_SHA512_224_SUPPORT != ENABLED && PKCS5_SHA512_224_SUPPORT != DISABLED)
139  #error PKCS5_SHA512_224_SUPPORT parameter is not valid
140 #endif
141 
142 //SHA-512/256 hash support
143 #ifndef PKCS5_SHA512_256_SUPPORT
144  #define PKCS5_SHA512_256_SUPPORT DISABLED
145 #elif (PKCS5_SHA512_256_SUPPORT != ENABLED && PKCS5_SHA512_256_SUPPORT != DISABLED)
146  #error PKCS5_SHA512_256_SUPPORT parameter is not valid
147 #endif
148 
149 //SM3 hash support
150 #ifndef PKCS5_SM3_SUPPORT
151  #define PKCS5_SM3_SUPPORT DISABLED
152 #elif (PKCS5_SM3_SUPPORT != ENABLED && PKCS5_SM3_SUPPORT != DISABLED)
153  #error PKCS5_SM3_SUPPORT parameter is not valid
154 #endif
155 
156 //C++ guard
157 #ifdef __cplusplus
158 extern "C" {
159 #endif
160 
161 
162 /**
163  * @brief Octet string
164  **/
165 
166 typedef struct
167 {
168  const uint8_t *value;
169  size_t length;
171 
172 
173 /**
174  * @brief PBES1 parameters
175  **/
176 
177 typedef struct
178 {
182 
183 
184 /**
185  * @brief Key derivation function
186  **/
187 
188 typedef struct
189 {
196 
197 
198 /**
199  * @brief Encryption scheme
200  **/
201 
202 typedef struct
203 {
207 
208 
209 /**
210  * @brief PBES2 parameters
211  **/
212 
213 typedef struct
214 {
218 
219 
220 //PKCS #5 related constants
221 extern const uint8_t PBE_WITH_MD2_AND_DES_CBC_OID[9];
222 extern const uint8_t PBE_WITH_MD5_AND_DES_CBC_OID[9];
223 extern const uint8_t PBE_WITH_MD2_AND_RC2_CBC_OID[9];
224 extern const uint8_t PBE_WITH_MD5_AND_RC2_CBC_OID[9];
225 extern const uint8_t PBE_WITH_SHA1_AND_DES_CBC_OID[9];
226 extern const uint8_t PBE_WITH_SHA1_AND_RC2_CBC_OID[9];
227 extern const uint8_t PBES2_OID[9];
228 
229 //PKCS #5 related functions
230 const HashAlgo *pkcs5GetPbes1HashAlgo(const uint8_t *oid, size_t length);
231 const HashAlgo *pkcs5GetPbes2HashAlgo(const uint8_t *oid, size_t length);
232 
233 const CipherAlgo *pkcs5GetPbes1CipherAlgo(const uint8_t *oid, size_t length);
234 const CipherAlgo *pkcs5GetPbes2CipherAlgo(const uint8_t *oid, size_t length);
235 
236 uint_t pkcs5GetPbes2KeyLength(const uint8_t *oid, size_t length);
237 
238 //C++ guard
239 #ifdef __cplusplus
240 }
241 #endif
242 
243 #endif
unsigned int uint_t
Definition: compiler_port.h:50
General definitions for cryptographic algorithms.
uint8_t oid[]
Definition: lldp_tlv.h:300
uint_t pkcs5GetPbes2KeyLength(const uint8_t *oid, size_t length)
Get the encryption key length to be used for PBES2 operation.
Definition: pkcs5_common.c:384
const uint8_t PBE_WITH_MD2_AND_DES_CBC_OID[9]
Definition: pkcs5_common.c:46
const uint8_t PBE_WITH_MD5_AND_DES_CBC_OID[9]
Definition: pkcs5_common.c:48
const uint8_t PBE_WITH_SHA1_AND_RC2_CBC_OID[9]
Definition: pkcs5_common.c:56
const CipherAlgo * pkcs5GetPbes1CipherAlgo(const uint8_t *oid, size_t length)
Get the cipher algorithm to be used for PBES1 operation.
Definition: pkcs5_common.c:222
const CipherAlgo * pkcs5GetPbes2CipherAlgo(const uint8_t *oid, size_t length)
Get the cipher algorithm to be used for PBES2 operation.
Definition: pkcs5_common.c:285
const HashAlgo * pkcs5GetPbes2HashAlgo(const uint8_t *oid, size_t length)
Get the hash algorithm to be used for PBES2 operation.
Definition: pkcs5_common.c:135
const uint8_t PBE_WITH_MD2_AND_RC2_CBC_OID[9]
Definition: pkcs5_common.c:50
const uint8_t PBE_WITH_SHA1_AND_DES_CBC_OID[9]
Definition: pkcs5_common.c:54
const uint8_t PBES2_OID[9]
Definition: pkcs5_common.c:59
const uint8_t PBE_WITH_MD5_AND_RC2_CBC_OID[9]
Definition: pkcs5_common.c:52
const HashAlgo * pkcs5GetPbes1HashAlgo(const uint8_t *oid, size_t length)
Get the hash algorithm to be used for PBES1 operation.
Definition: pkcs5_common.c:69
Common interface for encryption algorithms.
Definition: crypto.h:1036
Common interface for hash algorithms.
Definition: crypto.h:1014
Encryption scheme.
Definition: pkcs5_common.h:203
Pkcs5OctetString iv
Definition: pkcs5_common.h:205
Pkcs5OctetString oid
Definition: pkcs5_common.h:204
Key derivation function.
Definition: pkcs5_common.h:189
Pkcs5OctetString prfAlgoId
Definition: pkcs5_common.h:194
Pkcs5OctetString salt
Definition: pkcs5_common.h:191
Pkcs5OctetString kdfAlgoId
Definition: pkcs5_common.h:190
Octet string.
Definition: pkcs5_common.h:167
const uint8_t * value
Definition: pkcs5_common.h:168
PBES1 parameters.
Definition: pkcs5_common.h:178
Pkcs5OctetString salt
Definition: pkcs5_common.h:179
PBES2 parameters.
Definition: pkcs5_common.h:214
Pkcs5EncryptionScheme encryptionScheme
Definition: pkcs5_common.h:216
Pkcs5KeyDerivationFunc keyDerivationFunc
Definition: pkcs5_common.h:215
uint8_t length
Definition: tcp.h:368