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-2023 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.2.4
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 //MD2 hash support (insecure)
66 #ifndef PKCS5_MD2_SUPPORT
67  #define PKCS5_MD2_SUPPORT DISABLED
68 #elif (PKCS5_MD2_SUPPORT != ENABLED && PKCS5_MD2_SUPPORT != DISABLED)
69  #error PKCS5_MD2_SUPPORT parameter is not valid
70 #endif
71 
72 //MD5 hash support (insecure)
73 #ifndef PKCS5_MD5_SUPPORT
74  #define PKCS5_MD5_SUPPORT DISABLED
75 #elif (PKCS5_MD5_SUPPORT != ENABLED && PKCS5_MD5_SUPPORT != DISABLED)
76  #error PKCS5_MD5_SUPPORT parameter is not valid
77 #endif
78 
79 //SHA-1 hash support (weak)
80 #ifndef PKCS5_SHA1_SUPPORT
81  #define PKCS5_SHA1_SUPPORT DISABLED
82 #elif (PKCS5_SHA1_SUPPORT != ENABLED && PKCS5_SHA1_SUPPORT != DISABLED)
83  #error PKCS5_SHA1_SUPPORT parameter is not valid
84 #endif
85 
86 //SHA-224 hash support (weak)
87 #ifndef PKCS5_SHA224_SUPPORT
88  #define PKCS5_SHA224_SUPPORT DISABLED
89 #elif (PKCS5_SHA224_SUPPORT != ENABLED && PKCS5_SHA224_SUPPORT != DISABLED)
90  #error PKCS5_SHA224_SUPPORT parameter is not valid
91 #endif
92 
93 //SHA-256 hash support
94 #ifndef PKCS5_SHA256_SUPPORT
95  #define PKCS5_SHA256_SUPPORT ENABLED
96 #elif (PKCS5_SHA256_SUPPORT != ENABLED && PKCS5_SHA256_SUPPORT != DISABLED)
97  #error PKCS5_SHA256_SUPPORT parameter is not valid
98 #endif
99 
100 //SHA-384 hash support
101 #ifndef PKCS5_SHA384_SUPPORT
102  #define PKCS5_SHA384_SUPPORT ENABLED
103 #elif (PKCS5_SHA384_SUPPORT != ENABLED && PKCS5_SHA384_SUPPORT != DISABLED)
104  #error PKCS5_SHA384_SUPPORT parameter is not valid
105 #endif
106 
107 //SHA-512 hash support
108 #ifndef PKCS5_SHA512_SUPPORT
109  #define PKCS5_SHA512_SUPPORT ENABLED
110 #elif (PKCS5_SHA512_SUPPORT != ENABLED && PKCS5_SHA512_SUPPORT != DISABLED)
111  #error PKCS5_SHA512_SUPPORT parameter is not valid
112 #endif
113 
114 //SHA-512/224 hash support
115 #ifndef PKCS5_SHA512_224_SUPPORT
116  #define PKCS5_SHA512_224_SUPPORT DISABLED
117 #elif (PKCS5_SHA512_224_SUPPORT != ENABLED && PKCS5_SHA512_224_SUPPORT != DISABLED)
118  #error PKCS5_SHA512_224_SUPPORT parameter is not valid
119 #endif
120 
121 //SHA-512/256 hash support
122 #ifndef PKCS5_SHA512_256_SUPPORT
123  #define PKCS5_SHA512_256_SUPPORT DISABLED
124 #elif (PKCS5_SHA512_256_SUPPORT != ENABLED && PKCS5_SHA512_256_SUPPORT != DISABLED)
125  #error PKCS5_SHA512_256_SUPPORT parameter is not valid
126 #endif
127 
128 //C++ guard
129 #ifdef __cplusplus
130 extern "C" {
131 #endif
132 
133 
134 /**
135  * @brief PBES1 parameters
136  **/
137 
138 typedef struct
139 {
140  const uint8_t *salt;
141  size_t saltLen;
144 
145 
146 /**
147  * @brief Key derivation function
148  **/
149 
150 typedef struct
151 {
152  const uint8_t *kdfAlgoId;
153  size_t kdfAlgoIdLen;
154  const uint8_t *salt;
155  size_t saltLen;
158  const uint8_t *prfAlgoId;
159  size_t prfAlgoIdLen;
161 
162 
163 /**
164  * @brief Encryption scheme
165  **/
166 
167 typedef struct
168 {
169  const uint8_t *oid;
170  size_t oidLen;
171  const uint8_t *iv;
172  size_t ivLen;
174 
175 
176 /**
177  * @brief PBES2 parameters
178  **/
179 
180 typedef struct
181 {
185 
186 
187 //PKCS #5 related constants
188 extern const uint8_t PBE_WITH_MD2_AND_DES_CBC_OID[9];
189 extern const uint8_t PBE_WITH_MD5_AND_DES_CBC_OID[9];
190 extern const uint8_t PBE_WITH_MD2_AND_RC2_CBC_OID[9];
191 extern const uint8_t PBE_WITH_MD5_AND_RC2_CBC_OID[9];
192 extern const uint8_t PBE_WITH_SHA1_AND_DES_CBC_OID[9];
193 extern const uint8_t PBE_WITH_SHA1_AND_RC2_CBC_OID[9];
194 
195 extern const uint8_t PBES2_OID[9];
196 
197 extern const uint8_t DES_CBC_PAD_OID[5];
198 extern const uint8_t DES_EDE3_CBC_PAD_OID[8];
199 extern const uint8_t AES128_CBC_PAD_OID[9];
200 extern const uint8_t AES192_CBC_PAD_OID[9];
201 extern const uint8_t AES256_CBC_PAD_OID[9];
202 
203 //PKCS #5 related functions
204 const HashAlgo *pkcs5GetPbes1HashAlgo(const uint8_t *oid, size_t length);
205 const HashAlgo *pkcs5GetPbes2HashAlgo(const uint8_t *oid, size_t length);
206 
207 const CipherAlgo *pkcs5GetPbes1CipherAlgo(const uint8_t *oid, size_t length);
208 const CipherAlgo *pkcs5GetPbes2CipherAlgo(const uint8_t *oid, size_t length);
209 
210 uint_t pkcs5GetPbes2KeyLength(const uint8_t *oid, size_t length);
211 
212 //C++ guard
213 #ifdef __cplusplus
214 }
215 #endif
216 
217 #endif
const uint8_t * oid
Definition: pkcs5_common.h:169
const HashAlgo * pkcs5GetPbes2HashAlgo(const uint8_t *oid, size_t length)
Get the hash algorithm to be used for PBES2 operation.
Definition: pkcs5_common.c:146
uint8_t length
Definition: coap_common.h:193
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:343
const uint8_t PBE_WITH_SHA1_AND_RC2_CBC_OID[9]
Definition: pkcs5_common.c:56
const uint8_t PBE_WITH_MD2_AND_DES_CBC_OID[9]
Definition: pkcs5_common.c:46
const uint8_t * kdfAlgoId
Definition: pkcs5_common.h:152
const uint8_t PBE_WITH_MD5_AND_RC2_CBC_OID[9]
Definition: pkcs5_common.c:52
const uint8_t PBE_WITH_MD2_AND_RC2_CBC_OID[9]
Definition: pkcs5_common.c:50
const uint8_t AES128_CBC_PAD_OID[9]
Definition: pkcs5_common.c:66
const uint8_t * iv
Definition: pkcs5_common.h:171
const HashAlgo * pkcs5GetPbes1HashAlgo(const uint8_t *oid, size_t length)
Get the hash algorithm to be used for PBES1 operation.
Definition: pkcs5_common.c:80
uint8_t oid[]
Definition: lldp_tlv.h:298
PBES2 parameters.
Definition: pkcs5_common.h:181
const CipherAlgo * pkcs5GetPbes1CipherAlgo(const uint8_t *oid, size_t length)
Get the cipher algorithm to be used for PBES1 operation.
Definition: pkcs5_common.c:225
const uint8_t * salt
Definition: pkcs5_common.h:140
const uint8_t DES_CBC_PAD_OID[5]
Definition: pkcs5_common.c:62
Pkcs5EncryptionScheme encryptionScheme
Definition: pkcs5_common.h:183
PBES1 parameters.
Definition: pkcs5_common.h:139
const uint8_t * salt
Definition: pkcs5_common.h:154
const uint8_t DES_EDE3_CBC_PAD_OID[8]
Definition: pkcs5_common.c:64
General definitions for cryptographic algorithms.
const uint8_t PBE_WITH_MD5_AND_DES_CBC_OID[9]
Definition: pkcs5_common.c:48
const uint8_t AES192_CBC_PAD_OID[9]
Definition: pkcs5_common.c:68
const uint8_t * prfAlgoId
Definition: pkcs5_common.h:158
Key derivation function.
Definition: pkcs5_common.h:151
Common interface for encryption algorithms.
Definition: crypto.h:980
const CipherAlgo * pkcs5GetPbes2CipherAlgo(const uint8_t *oid, size_t length)
Get the cipher algorithm to be used for PBES2 operation.
Definition: pkcs5_common.c:288
Common interface for hash algorithms.
Definition: crypto.h:958
const uint8_t AES256_CBC_PAD_OID[9]
Definition: pkcs5_common.c:70
const uint8_t PBE_WITH_SHA1_AND_DES_CBC_OID[9]
Definition: pkcs5_common.c:54
unsigned int uint_t
Definition: compiler_port.h:50
Encryption scheme.
Definition: pkcs5_common.h:168
const uint8_t PBES2_OID[9]
Definition: pkcs5_common.c:59
Pkcs5KeyDerivationFunc keyDerivationFunc
Definition: pkcs5_common.h:182