x509_common.c
Go to the documentation of this file.
1 /**
2  * @file x509_common.c
3  * @brief X.509 common definitions
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2025 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.5.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "pkix/x509_common.h"
37 #include "encoding/asn1.h"
38 #include "encoding/oid.h"
39 #include "hash/hash_algorithms.h"
40 #include "debug.h"
41 
42 //Check crypto library configuration
43 #if (X509_SUPPORT == ENABLED)
44 
45 //Common Name OID (2.5.4.3)
46 const uint8_t X509_COMMON_NAME_OID[3] = {0x55, 0x04, 0x03};
47 //Surname OID (2.5.4.4)
48 const uint8_t X509_SURNAME_OID[3] = {0x55, 0x04, 0x04};
49 //Serial Number OID (2.5.4.5)
50 const uint8_t X509_SERIAL_NUMBER_OID[3] = {0x55, 0x04, 0x05};
51 //Country Name OID (2.5.4.6)
52 const uint8_t X509_COUNTRY_NAME_OID[3] = {0x55, 0x04, 0x06};
53 //Locality Name OID (2.5.4.7)
54 const uint8_t X509_LOCALITY_NAME_OID[3] = {0x55, 0x04, 0x07};
55 //State Or Province Name OID (2.5.4.8)
56 const uint8_t X509_STATE_OR_PROVINCE_NAME_OID[] = {0x55, 0x04, 0x08};
57 //Organization Name OID (2.5.4.10)
58 const uint8_t X509_ORGANIZATION_NAME_OID[3] = {0x55, 0x04, 0x0A};
59 //Organizational Unit Name OID (2.5.4.11)
60 const uint8_t X509_ORGANIZATIONAL_UNIT_NAME_OID[3] = {0x55, 0x04, 0x0B};
61 //Title OID (2.5.4.12)
62 const uint8_t X509_TITLE_OID[3] = {0x55, 0x04, 0x0C};
63 //Name OID (2.5.4.41)
64 const uint8_t X509_NAME_OID[3] = {0x55, 0x04, 0x29};
65 //Given Name OID (2.5.4.42)
66 const uint8_t X509_GIVEN_NAME_OID[3] = {0x55, 0x04, 0x2A};
67 //Initials OID (2.5.4.43)
68 const uint8_t X509_INITIALS_OID[3] = {0x55, 0x04, 0x2B};
69 //Generation Qualifier OID (2.5.4.44)
70 const uint8_t X509_GENERATION_QUALIFIER_OID[3] = {0x55, 0x04, 0x2C};
71 //DN Qualifier OID (2.5.4.46)
72 const uint8_t X509_DN_QUALIFIER_OID[3] = {0x55, 0x04, 0x2E};
73 //Pseudonym OID (2.5.4.65)
74 const uint8_t X509_PSEUDONYM_OID[3] = {0x55, 0x04, 0x41};
75 //Domain Component OID (0.9.2342.19200300.100.1.25)
76 const uint8_t X509_DOMAIN_COMPONENT_OID[10] = {0x09, 0x92, 0x26, 0x89, 0x93, 0xF2, 0x2C, 0x64, 0x01, 0x19};
77 
78 //Subject Directory Attributes OID (2.5.29.9)
79 const uint8_t X509_SUBJECT_DIR_ATTR_OID[3] = {0x55, 0x1D, 0x09};
80 //Subject Key Identifier OID (2.5.29.14)
81 const uint8_t X509_SUBJECT_KEY_ID_OID[3] = {0x55, 0x1D, 0x0E};
82 //Key Usage OID (2.5.29.15)
83 const uint8_t X509_KEY_USAGE_OID[3] = {0x55, 0x1D, 0x0F};
84 //Subject Alternative Name OID (2.5.29.17)
85 const uint8_t X509_SUBJECT_ALT_NAME_OID[3] = {0x55, 0x1D, 0x11};
86 //Issuer Alternative Name OID (2.5.29.18)
87 const uint8_t X509_ISSUER_ALT_NAME_OID[3] = {0x55, 0x1D, 0x12};
88 //Basic Constraints OID (2.5.29.19)
89 const uint8_t X509_BASIC_CONSTRAINTS_OID[3] = {0x55, 0x1D, 0x13};
90 //CRL Number OID (2.5.29.20)
91 const uint8_t X509_CRL_NUMBER_OID[3] = {0x55, 0x1D, 0x14};
92 //Reason Code OID (2.5.29.21)
93 const uint8_t X509_REASON_CODE_OID[3] = {0x55, 0x1D, 0x15};
94 //Invalidity Date OID (2.5.29.24)
95 const uint8_t X509_INVALIDITY_DATE_OID[3] = {0x55, 0x1D, 0x18};
96 //Delta CRL Indicator OID (2.5.29.27)
97 const uint8_t X509_DELTA_CRL_INDICATOR_OID[3] = {0x55, 0x1D, 0x1B};
98 //Issuing Distribution Point OID (2.5.29.28)
99 const uint8_t X509_ISSUING_DISTR_POINT_OID[3] = {0x55, 0x1D, 0x1C};
100 //Certificate Issuer OID (2.5.29.29)
101 const uint8_t X509_CERTIFICATE_ISSUER_OID[3] = {0x55, 0x1D, 0x1D};
102 //Name Constraints OID (2.5.29.30)
103 const uint8_t X509_NAME_CONSTRAINTS_OID[3] = {0x55, 0x1D, 0x1E};
104 //CRL Distribution Points OID (2.5.29.31)
105 const uint8_t X509_CRL_DISTR_POINTS_OID[3] = {0x55, 0x1D, 0x1F};
106 //Certificate Policies OID (2.5.29.32)
107 const uint8_t X509_CERTIFICATE_POLICIES_OID[3] = {0x55, 0x1D, 0x20};
108 //Policy Mappings OID (2.5.29.33)
109 const uint8_t X509_POLICY_MAPPINGS_OID[3] = {0x55, 0x1D, 0x21};
110 //Authority Key Identifier OID (2.5.29.35)
111 const uint8_t X509_AUTHORITY_KEY_ID_OID[3] = {0x55, 0x1D, 0x23};
112 //Policy Constraints OID (2.5.29.36)
113 const uint8_t X509_POLICY_CONSTRAINTS_OID[3] = {0x55, 0x1D, 0x24};
114 //Extended Key Usage OID (2.5.29.37)
115 const uint8_t X509_EXTENDED_KEY_USAGE_OID[3] = {0x55, 0x1D, 0x25};
116 //Freshest CRL OID (2.5.29.46)
117 const uint8_t X509_FRESHEST_CRL_OID[3] = {0x55, 0x1D, 0x2E};
118 //Inhibit Any-Policy OID (2.5.29.54)
119 const uint8_t X509_INHIBIT_ANY_POLICY_OID[3] = {0x55, 0x1D, 0x36};
120 //Authority Information Access OID (1.3.6.1.5.5.7.1.1)
121 const uint8_t X509_AUTH_INFO_ACCESS_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x01, 0x01};
122 //PKIX OCSP No Check OID (1.3.6.1.5.5.7.48.1.5)
123 const uint8_t X509_PKIX_OCSP_NO_CHECK_OID[9] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x05};
124 //Netscape Certificate Type OID (2.16.840.1.113730.1.1)
125 const uint8_t X509_NS_CERT_TYPE_OID[9] = {0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x42, 0x01, 0x01};
126 
127 //Any Extended Key Usage OID (2.5.29.37.0)
128 const uint8_t X509_ANY_EXT_KEY_USAGE_OID[4] = {0x55, 0x1D, 0x25, 0x00};
129 //Key Purpose Server Auth OID (1.3.6.1.5.5.7.3.1)
130 const uint8_t X509_KP_SERVER_AUTH_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01};
131 //Key Purpose Client Auth OID (1.3.6.1.5.5.7.3.2)
132 const uint8_t X509_KP_CLIENT_AUTH_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02};
133 //Key Purpose Code Signing OID (1.3.6.1.5.5.7.3.3)
134 const uint8_t X509_KP_CODE_SIGNING_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x03};
135 //Key Purpose Email Protection OID (1.3.6.1.5.5.7.3.4)
136 const uint8_t X509_KP_EMAIL_PROTECTION_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x04};
137 //Key Purpose IPsec End System OID (1.3.6.1.5.5.7.3.5)
138 const uint8_t X509_KP_IPSEC_END_SYSTEM_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x05};
139 //Key Purpose IPsec Tunnel OID (1.3.6.1.5.5.7.3.6)
140 const uint8_t X509_KP_IPSEC_TUNNEL_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x06};
141 //Key Purpose IPsec User OID (1.3.6.1.5.5.7.3.7)
142 const uint8_t X509_KP_IPSEC_USER_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x07};
143 //Key Purpose Time Stamping OID (1.3.6.1.5.5.7.3.8)
144 const uint8_t X509_KP_TIME_STAMPING_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x08};
145 //Key Purpose OCSP Signing OID (1.3.6.1.5.5.7.3.9)
146 const uint8_t X509_KP_OCSP_SIGNING_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x09};
147 //Key Purpose IPsec IKE OID (1.3.6.1.5.5.7.3.17)
148 const uint8_t X509_KP_IPSEC_IKE_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x11};
149 //Key Purpose Secure Shell Client OID (1.3.6.1.5.5.7.3.21)
150 const uint8_t X509_KP_SSH_CLIENT_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x15};
151 //Key Purpose Secure Shell Client OID (1.3.6.1.5.5.7.3.22)
152 const uint8_t X509_KP_SSH_SERVER_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x16};
153 //Key Purpose CMC Certification Authorities OID (1.3.6.1.5.5.7.3.27)
154 const uint8_t X509_KP_CMC_CA_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x1B};
155 //Key Purpose CMC Registration Authorities OID (1.3.6.1.5.5.7.3.28)
156 const uint8_t X509_KP_CMC_RA_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x1C};
157 //Key Purpose Document Signing OID (1.3.6.1.5.5.7.3.36)
158 const uint8_t X509_KP_DOC_SIGNING_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x24};
159 
160 //Access Description CA Issuers OID (1.3.6.1.5.5.7.48.1)
161 const uint8_t X509_AD_CA_ISSUERS[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01};
162 //Access Description OCSP (1.3.6.1.5.5.7.48.2)
163 const uint8_t X509_AD_OCSP[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x02};
164 
165 //PKCS #9 E-mail Address OID (1.2.840.113549.1.9.1)
166 const uint8_t PKCS9_EMAIL_ADDR_OID[9] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x01};
167 //PKCS #9 Challenge Password OID (1.2.840.113549.1.9.7)
168 const uint8_t PKCS9_CHALLENGE_PASSWORD_OID[9] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x07};
169 //PKCS #9 Extension Request OID (1.2.840.113549.1.9.14)
170 const uint8_t PKCS9_EXTENSION_REQUEST_OID[9] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x0E};
171 
172 //Default certificate parsing options
174 {
175  FALSE //Ignore unknown extensions
176 };
177 
178 
179 /**
180  * @brief Compare distinguished names
181  * @param[in] name1 Pointer to the first distinguished name
182  * @param[in] nameLen1 Length of the first distinguished name
183  * @param[in] name2 Pointer to the second distinguished name
184  * @param[in] nameLen2 Length of the second distinguished name
185  * @return Comparison result
186  **/
187 
188 bool_t x509CompareName(const uint8_t *name1, size_t nameLen1,
189  const uint8_t *name2, size_t nameLen2)
190 {
191  //Compare the length of the distinguished names
192  if(nameLen1 != nameLen2)
193  return FALSE;
194 
195  //Compare the contents of the distinguished names
196  if(osMemcmp(name1, name2, nameLen1))
197  return FALSE;
198 
199  //The distinguished names match
200  return TRUE;
201 }
202 
203 
204 /**
205  * @brief Check whether a given signature algorithm is supported
206  * @param[in] signAlgo signature algorithm
207  * @return TRUE is the signature algorithm is supported, else FALSE
208  **/
209 
211 {
212  bool_t acceptable;
213 
214  //Invalid signature algorithm?
215  if(signAlgo == X509_SIGN_ALGO_NONE)
216  {
217  acceptable = FALSE;
218  }
219 #if (X509_RSA_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
220  //RSA signature algorithm?
221  else if(signAlgo == X509_SIGN_ALGO_RSA)
222  {
223  acceptable = TRUE;
224  }
225 #endif
226 #if (X509_RSA_PSS_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
227  //RSA-PSS signature algorithm?
228  else if(signAlgo == X509_SIGN_ALGO_RSA_PSS)
229  {
230  acceptable = TRUE;
231  }
232 #endif
233 #if (X509_DSA_SUPPORT == ENABLED && DSA_SUPPORT == ENABLED)
234  //DSA signature algorithm?
235  else if(signAlgo == X509_SIGN_ALGO_DSA)
236  {
237  acceptable = TRUE;
238  }
239 #endif
240 #if (X509_ECDSA_SUPPORT == ENABLED && ECDSA_SUPPORT == ENABLED)
241  //ECDSA signature algorithm?
242  else if(signAlgo == X509_SIGN_ALGO_ECDSA)
243  {
244  acceptable = TRUE;
245  }
246 #endif
247 #if (X509_SM2_SUPPORT == ENABLED && SM2_SUPPORT == ENABLED)
248  //SM2 signature algorithm?
249  else if(signAlgo == X509_SIGN_ALGO_SM2)
250  {
251  acceptable = TRUE;
252  }
253 #endif
254 #if (X509_ED25519_SUPPORT == ENABLED && ED25519_SUPPORT == ENABLED)
255  //Ed25519 signature algorithm?
256  else if(signAlgo == X509_SIGN_ALGO_ED25519)
257  {
258  acceptable = TRUE;
259  }
260 #endif
261 #if (X509_ED448_SUPPORT == ENABLED && ED448_SUPPORT == ENABLED)
262  //Ed448 signature algorithm?
263  else if(signAlgo == X509_SIGN_ALGO_ED448)
264  {
265  acceptable = TRUE;
266  }
267 #endif
268  //Invalid signature algorithm?
269  else
270  {
271  acceptable = FALSE;
272  }
273 
274  //Return TRUE is the signature algorithm is supported
275  return acceptable;
276 }
277 
278 
279 /**
280  * @brief Check whether a given hash algorithm is supported
281  * @param[in] hashAlgo signature hash
282  * @return TRUE is the signature hash is supported, else FALSE
283  **/
284 
286 {
287  bool_t acceptable;
288 
289  //Invalid hash algorithm?
290  if(hashAlgo == X509_HASH_ALGO_NONE)
291  {
292  acceptable = FALSE;
293  }
294 #if (X509_MD5_SUPPORT == ENABLED && MD5_SUPPORT == ENABLED)
295  //MD5 hash algorithm?
296  else if(hashAlgo == X509_HASH_ALGO_MD5)
297  {
298  acceptable = TRUE;
299  }
300 #endif
301 #if (X509_SHA1_SUPPORT == ENABLED && SHA1_SUPPORT == ENABLED)
302  //SHA-1 hash algorithm?
303  else if(hashAlgo == X509_HASH_ALGO_SHA1)
304  {
305  acceptable = TRUE;
306  }
307 #endif
308 #if (X509_SHA224_SUPPORT == ENABLED && SHA224_SUPPORT == ENABLED)
309  //SHA-224 hash algorithm?
310  else if(hashAlgo == X509_HASH_ALGO_SHA224)
311  {
312  acceptable = TRUE;
313  }
314 #endif
315 #if (X509_SHA256_SUPPORT == ENABLED && SHA256_SUPPORT == ENABLED)
316  //SHA-256 hash algorithm?
317  else if(hashAlgo == X509_HASH_ALGO_SHA256)
318  {
319  acceptable = TRUE;
320  }
321 #endif
322 #if (X509_SHA384_SUPPORT == ENABLED && SHA384_SUPPORT == ENABLED)
323  //SHA-384 hash algorithm?
324  else if(hashAlgo == X509_HASH_ALGO_SHA384)
325  {
326  acceptable = TRUE;
327  }
328 #endif
329 #if (X509_SHA512_SUPPORT == ENABLED && SHA512_SUPPORT == ENABLED)
330  //SHA-512 hash algorithm?
331  else if(hashAlgo == X509_HASH_ALGO_SHA512)
332  {
333  acceptable = TRUE;
334  }
335 #endif
336 #if (X509_SHA3_224_SUPPORT == ENABLED && SHA3_224_SUPPORT == ENABLED)
337  //SHA3-224 hash algorithm?
338  else if(hashAlgo == X509_HASH_ALGO_SHA3_224)
339  {
340  acceptable = TRUE;
341  }
342 #endif
343 #if (X509_SHA3_256_SUPPORT == ENABLED && SHA3_256_SUPPORT == ENABLED)
344  //SHA3-256 hash algorithm?
345  else if(hashAlgo == X509_HASH_ALGO_SHA3_256)
346  {
347  acceptable = TRUE;
348  }
349 #endif
350 #if (X509_SHA3_384_SUPPORT == ENABLED && SHA3_384_SUPPORT == ENABLED)
351  //SHA3-384 hash algorithm?
352  else if(hashAlgo == X509_HASH_ALGO_SHA3_384)
353  {
354  acceptable = TRUE;
355  }
356 #endif
357 #if (X509_SHA3_512_SUPPORT == ENABLED && SHA3_512_SUPPORT == ENABLED)
358  //SHA3-512 hash algorithm?
359  else if(hashAlgo == X509_HASH_ALGO_SHA3_512)
360  {
361  acceptable = TRUE;
362  }
363 #endif
364 #if (X509_SM3_SUPPORT == ENABLED && SM3_SUPPORT == ENABLED)
365  //SM3 hash algorithm?
366  else if(hashAlgo == X509_HASH_ALGO_SM3)
367  {
368  acceptable = TRUE;
369  }
370 #endif
371  //Invalid hash algorithm?
372  else
373  {
374  acceptable = FALSE;
375  }
376 
377  //Return TRUE is the hash algorithm is supported
378  return acceptable;
379 }
380 
381 
382 /**
383  * @brief Check whether a given elliptic curve is supported
384  * @param[in] oid Object identifier
385  * @param[in] length Length of the OID, in bytes
386  * @return TRUE is the elliptic curve is supported, else FALSE
387  **/
388 
389 bool_t x509IsCurveSupported(const uint8_t *oid, size_t length)
390 {
391  //Return TRUE is the elliptic curve is supported
392  if(x509GetCurve(oid, length) != NULL)
393  {
394  return TRUE;
395  }
396  else
397  {
398  return FALSE;
399  }
400 }
401 
402 
403 /**
404  * @brief Get the signature and hash algorithms that match the specified
405  * identifier
406  * @param[in] signAlgoId Signature algorithm identifier
407  * @param[out] signAlgo Signature algorithm
408  * @param[out] hashAlgo Hash algorithm
409  * @return Error code
410  **/
411 
413  X509SignatureAlgo *signAlgo, const HashAlgo **hashAlgo)
414 {
415  error_t error;
416  size_t oidLen;
417  const uint8_t *oid;
418 
419  //Initialize status code
420  error = NO_ERROR;
421 
422  //Point to the object identifier
423  oid = signAlgoId->oid.value;
424  oidLen = signAlgoId->oid.length;
425 
426  //Just for sanity
427  (void) oid;
428  (void) oidLen;
429 
430 #if (X509_RSA_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
431 #if (X509_MD5_SUPPORT == ENABLED && MD5_SUPPORT == ENABLED)
432  //RSA with MD5 signature algorithm?
434  {
435  *signAlgo = X509_SIGN_ALGO_RSA;
436  *hashAlgo = MD5_HASH_ALGO;
437  }
438  else
439 #endif
440 #if (X509_SHA1_SUPPORT == ENABLED && SHA1_SUPPORT == ENABLED)
441  //RSA with SHA-1 signature algorithm?
443  {
444  *signAlgo = X509_SIGN_ALGO_RSA;
445  *hashAlgo = SHA1_HASH_ALGO;
446  }
447  else
448 #endif
449 #if (X509_SHA224_SUPPORT == ENABLED && SHA224_SUPPORT == ENABLED)
450  //RSA with SHA-224 signature algorithm?
452  {
453  *signAlgo = X509_SIGN_ALGO_RSA;
454  *hashAlgo = SHA224_HASH_ALGO;
455  }
456  else
457 #endif
458 #if (X509_SHA256_SUPPORT == ENABLED && SHA256_SUPPORT == ENABLED)
459  //RSA with SHA-256 signature algorithm?
461  {
462  *signAlgo = X509_SIGN_ALGO_RSA;
463  *hashAlgo = SHA256_HASH_ALGO;
464  }
465  else
466 #endif
467 #if (X509_SHA384_SUPPORT == ENABLED && SHA384_SUPPORT == ENABLED)
468  //RSA with SHA-384 signature algorithm?
470  {
471  *signAlgo = X509_SIGN_ALGO_RSA;
472  *hashAlgo = SHA384_HASH_ALGO;
473  }
474  else
475 #endif
476 #if (X509_SHA512_SUPPORT == ENABLED && SHA512_SUPPORT == ENABLED)
477  //RSA with SHA-512 signature algorithm?
479  {
480  *signAlgo = X509_SIGN_ALGO_RSA;
481  *hashAlgo = SHA512_HASH_ALGO;
482  }
483  else
484 #endif
485 #if (X509_SHA3_224_SUPPORT == ENABLED && SHA3_224_SUPPORT == ENABLED)
486  //RSA with SHA3-224 signature algorithm?
488  {
489  *signAlgo = X509_SIGN_ALGO_RSA;
490  *hashAlgo = SHA3_224_HASH_ALGO;
491  }
492  else
493 #endif
494 #if (X509_SHA3_256_SUPPORT == ENABLED && SHA3_256_SUPPORT == ENABLED)
495  //RSA with SHA3-256 signature algorithm?
497  {
498  *signAlgo = X509_SIGN_ALGO_RSA;
499  *hashAlgo = SHA3_256_HASH_ALGO;
500  }
501  else
502 #endif
503 #if (X509_SHA3_384_SUPPORT == ENABLED && SHA3_384_SUPPORT == ENABLED)
504  //RSA with SHA3-384 signature algorithm?
506  {
507  *signAlgo = X509_SIGN_ALGO_RSA;
508  *hashAlgo = SHA3_384_HASH_ALGO;
509  }
510  else
511 #endif
512 #if (X509_SHA3_512_SUPPORT == ENABLED && SHA3_512_SUPPORT == ENABLED)
513  //RSA with SHA3-512 signature algorithm?
515  {
516  *signAlgo = X509_SIGN_ALGO_RSA;
517  *hashAlgo = SHA3_512_HASH_ALGO;
518  }
519  else
520 #endif
521 #endif
522 #if (X509_RSA_PSS_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
523  //RSA-PSS signature algorithm
524  if(OID_COMP(oid, oidLen, RSASSA_PSS_OID) == 0)
525  {
526  //Get the OID of the hash algorithm
527  oid = signAlgoId->rsaPssParams.hashAlgo.value;
528  oidLen = signAlgoId->rsaPssParams.hashAlgo.length;
529 
530 #if (X509_SHA1_SUPPORT == ENABLED && SHA1_SUPPORT == ENABLED)
531  //SHA-1 hash algorithm identifier?
532  if(OID_COMP(oid, oidLen, SHA1_OID) == 0)
533  {
534  //RSA-PSS with SHA-1 signature algorithm
535  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
536  *hashAlgo = SHA1_HASH_ALGO;
537  }
538  else
539 #endif
540 #if (X509_SHA224_SUPPORT == ENABLED && SHA224_SUPPORT == ENABLED)
541  //SHA-224 hash algorithm identifier?
542  if(OID_COMP(oid, oidLen, SHA224_OID) == 0)
543  {
544  //RSA-PSS with SHA-224 signature algorithm
545  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
546  *hashAlgo = SHA224_HASH_ALGO;
547  }
548  else
549 #endif
550 #if (X509_SHA256_SUPPORT == ENABLED && SHA256_SUPPORT == ENABLED)
551  //SHA-256 hash algorithm identifier?
552  if(OID_COMP(oid, oidLen, SHA256_OID) == 0)
553  {
554  //RSA-PSS with SHA-256 signature algorithm
555  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
556  *hashAlgo = SHA256_HASH_ALGO;
557  }
558  else
559 #endif
560 #if (X509_SHA384_SUPPORT == ENABLED && SHA384_SUPPORT == ENABLED)
561  //SHA-384 hash algorithm identifier?
562  if(OID_COMP(oid, oidLen, SHA384_OID) == 0)
563  {
564  //RSA-PSS with SHA-384 signature algorithm
565  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
566  *hashAlgo = SHA384_HASH_ALGO;
567  }
568  else
569 #endif
570 #if (X509_SHA512_SUPPORT == ENABLED && SHA512_SUPPORT == ENABLED)
571  //SHA-512 hash algorithm identifier?
572  if(OID_COMP(oid, oidLen, SHA512_OID) == 0)
573  {
574  //RSA-PSS with SHA-512 signature algorithm
575  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
576  *hashAlgo = SHA512_HASH_ALGO;
577  }
578  else
579 #endif
580 #if (X509_SHA3_224_SUPPORT == ENABLED && SHA3_224_SUPPORT == ENABLED)
581  //SHA3-224 hash algorithm identifier?
582  if(OID_COMP(oid, oidLen, SHA3_224_OID) == 0)
583  {
584  //RSA-PSS with SHA3-224 signature algorithm
585  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
586  *hashAlgo = SHA3_224_HASH_ALGO;
587  }
588  else
589 #endif
590 #if (X509_SHA3_256_SUPPORT == ENABLED && SHA3_256_SUPPORT == ENABLED)
591  //SHA3-256 hash algorithm identifier?
592  if(OID_COMP(oid, oidLen, SHA3_256_OID) == 0)
593  {
594  //RSA-PSS with SHA3-256 signature algorithm
595  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
596  *hashAlgo = SHA3_256_HASH_ALGO;
597  }
598  else
599 #endif
600 #if (X509_SHA3_384_SUPPORT == ENABLED && SHA3_384_SUPPORT == ENABLED)
601  //SHA3-384 hash algorithm identifier?
602  if(OID_COMP(oid, oidLen, SHA3_384_OID) == 0)
603  {
604  //RSA-PSS with SHA3-384 signature algorithm
605  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
606  *hashAlgo = SHA3_384_HASH_ALGO;
607  }
608  else
609 #endif
610 #if (X509_SHA3_512_SUPPORT == ENABLED && SHA3_512_SUPPORT == ENABLED)
611  //SHA3-512 hash algorithm identifier?
612  if(OID_COMP(oid, oidLen, SHA3_512_OID) == 0)
613  {
614  //RSA-PSS with SHA3-512 signature algorithm
615  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
616  *hashAlgo = SHA3_512_HASH_ALGO;
617  }
618  else
619 #endif
620  //Unknown hash algorithm identifier?
621  {
622  //The specified signature algorithm is not supported
624  }
625  }
626  else
627 #endif
628 #if (X509_DSA_SUPPORT == ENABLED && DSA_SUPPORT == ENABLED)
629 #if (X509_SHA1_SUPPORT == ENABLED && SHA1_SUPPORT == ENABLED)
630  //DSA with SHA-1 signature algorithm?
632  {
633  *signAlgo = X509_SIGN_ALGO_DSA;
634  *hashAlgo = SHA1_HASH_ALGO;
635  }
636  else
637 #endif
638 #if (X509_SHA224_SUPPORT == ENABLED && SHA224_SUPPORT == ENABLED)
639  //DSA with SHA-224 signature algorithm?
641  {
642  *signAlgo = X509_SIGN_ALGO_DSA;
643  *hashAlgo = SHA224_HASH_ALGO;
644  }
645  else
646 #endif
647 #if (X509_SHA256_SUPPORT == ENABLED && SHA256_SUPPORT == ENABLED)
648  //DSA with SHA-256 signature algorithm?
650  {
651  *signAlgo = X509_SIGN_ALGO_DSA;
652  *hashAlgo = SHA256_HASH_ALGO;
653  }
654  else
655 #endif
656 #if (X509_SHA384_SUPPORT == ENABLED && SHA384_SUPPORT == ENABLED)
657  //DSA with SHA-384 signature algorithm?
659  {
660  *signAlgo = X509_SIGN_ALGO_DSA;
661  *hashAlgo = SHA384_HASH_ALGO;
662  }
663  else
664 #endif
665 #if (X509_SHA512_SUPPORT == ENABLED && SHA512_SUPPORT == ENABLED)
666  //DSA with SHA-512 signature algorithm?
668  {
669  *signAlgo = X509_SIGN_ALGO_DSA;
670  *hashAlgo = SHA512_HASH_ALGO;
671  }
672  else
673 #endif
674 #if (X509_SHA3_224_SUPPORT == ENABLED && SHA3_224_SUPPORT == ENABLED)
675  //DSA with SHA3-224 signature algorithm?
677  {
678  *signAlgo = X509_SIGN_ALGO_DSA;
679  *hashAlgo = SHA3_224_HASH_ALGO;
680  }
681  else
682 #endif
683 #if (X509_SHA3_256_SUPPORT == ENABLED && SHA3_256_SUPPORT == ENABLED)
684  //DSA with SHA3-256 signature algorithm?
686  {
687  *signAlgo = X509_SIGN_ALGO_DSA;
688  *hashAlgo = SHA3_256_HASH_ALGO;
689  }
690  else
691 #endif
692 #if (X509_SHA3_384_SUPPORT == ENABLED && SHA3_384_SUPPORT == ENABLED)
693  //DSA with SHA3-384 signature algorithm?
695  {
696  *signAlgo = X509_SIGN_ALGO_DSA;
697  *hashAlgo = SHA3_384_HASH_ALGO;
698  }
699  else
700 #endif
701 #if (X509_SHA3_512_SUPPORT == ENABLED && SHA3_512_SUPPORT == ENABLED)
702  //DSA with SHA3-512 signature algorithm?
704  {
705  *signAlgo = X509_SIGN_ALGO_DSA;
706  *hashAlgo = SHA3_512_HASH_ALGO;
707  }
708  else
709 #endif
710 #endif
711 #if (X509_ECDSA_SUPPORT == ENABLED && ECDSA_SUPPORT == ENABLED)
712 #if (X509_SHA1_SUPPORT == ENABLED && SHA1_SUPPORT == ENABLED)
713  //ECDSA with SHA-1 signature algorithm?
715  {
716  *signAlgo = X509_SIGN_ALGO_ECDSA;
717  *hashAlgo = SHA1_HASH_ALGO;
718  }
719  else
720 #endif
721 #if (X509_SHA224_SUPPORT == ENABLED && SHA224_SUPPORT == ENABLED)
722  //ECDSA with SHA-224 signature algorithm?
724  {
725  *signAlgo = X509_SIGN_ALGO_ECDSA;
726  *hashAlgo = SHA224_HASH_ALGO;
727  }
728  else
729 #endif
730 #if (X509_SHA256_SUPPORT == ENABLED && SHA256_SUPPORT == ENABLED)
731  //ECDSA with SHA-256 signature algorithm?
733  {
734  *signAlgo = X509_SIGN_ALGO_ECDSA;
735  *hashAlgo = SHA256_HASH_ALGO;
736  }
737  else
738 #endif
739 #if (X509_SHA384_SUPPORT == ENABLED && SHA384_SUPPORT == ENABLED)
740  //ECDSA with SHA-384 signature algorithm?
742  {
743  *signAlgo = X509_SIGN_ALGO_ECDSA;
744  *hashAlgo = SHA384_HASH_ALGO;
745  }
746  else
747 #endif
748 #if (X509_SHA512_SUPPORT == ENABLED && SHA512_SUPPORT == ENABLED)
749  //ECDSA with SHA-512 signature algorithm?
751  {
752  *signAlgo = X509_SIGN_ALGO_ECDSA;
753  *hashAlgo = SHA512_HASH_ALGO;
754  }
755  else
756 #endif
757 #if (X509_SHA3_224_SUPPORT == ENABLED && SHA3_224_SUPPORT == ENABLED)
758  //ECDSA with SHA3-224 signature algorithm?
760  {
761  *signAlgo = X509_SIGN_ALGO_ECDSA;
762  *hashAlgo = SHA3_224_HASH_ALGO;
763  }
764  else
765 #endif
766 #if (X509_SHA3_256_SUPPORT == ENABLED && SHA3_256_SUPPORT == ENABLED)
767  //ECDSA with SHA3-256 signature algorithm?
769  {
770  *signAlgo = X509_SIGN_ALGO_ECDSA;
771  *hashAlgo = SHA3_256_HASH_ALGO;
772  }
773  else
774 #endif
775 #if (X509_SHA3_384_SUPPORT == ENABLED && SHA3_384_SUPPORT == ENABLED)
776  //ECDSA with SHA3-384 signature algorithm?
778  {
779  *signAlgo = X509_SIGN_ALGO_ECDSA;
780  *hashAlgo = SHA3_384_HASH_ALGO;
781  }
782  else
783 #endif
784 #if (X509_SHA3_512_SUPPORT == ENABLED && SHA3_512_SUPPORT == ENABLED)
785  //ECDSA with SHA3-512 signature algorithm?
787  {
788  *signAlgo = X509_SIGN_ALGO_ECDSA;
789  *hashAlgo = SHA3_512_HASH_ALGO;
790  }
791  else
792 #endif
793 #endif
794 #if (X509_SM2_SUPPORT == ENABLED && SM2_SUPPORT == ENABLED && \
795  X509_SM3_SUPPORT == ENABLED && SM3_SUPPORT == ENABLED)
796  //SM2 with SM3 signature algorithm?
797  if(OID_COMP(oid, oidLen, SM2_WITH_SM3_OID) == 0)
798  {
799  *signAlgo = X509_SIGN_ALGO_SM2;
800  *hashAlgo = SM3_HASH_ALGO;
801  }
802  else
803 #endif
804 #if (X509_ED25519_SUPPORT == ENABLED && ED25519_SUPPORT == ENABLED)
805  //Ed25519 signature algorithm?
806  if(OID_COMP(oid, oidLen, ED25519_OID) == 0)
807  {
808  *signAlgo = X509_SIGN_ALGO_ED25519;
809  *hashAlgo = NULL;
810  }
811  else
812 #endif
813 #if (X509_ED448_SUPPORT == ENABLED && ED448_SUPPORT == ENABLED)
814  //Ed448 signature algorithm?
815  if(OID_COMP(oid, oidLen, ED448_OID) == 0)
816  {
817  *signAlgo = X509_SIGN_ALGO_ED448;
818  *hashAlgo = NULL;
819  }
820  else
821 #endif
822  //Unknown signature algorithm?
823  {
825  }
826 
827  //Return status code
828  return error;
829 }
830 
831 
832 /**
833  * @brief Get the public key type that matches the specified OID
834  * @param[in] oid Object identifier
835  * @param[in] length OID length
836  * @return Public key type
837  **/
838 
840 {
841  X509KeyType keyType;
842 
843  //Invalid parameters?
844  if(oid == NULL || length == 0)
845  {
846  keyType = X509_KEY_TYPE_UNKNOWN;
847  }
848 #if (RSA_SUPPORT == ENABLED)
849  //RSA algorithm identifier?
850  else if(OID_COMP(oid, length, RSA_ENCRYPTION_OID) == 0)
851  {
852  keyType = X509_KEY_TYPE_RSA;
853  }
854  //RSA-PSS algorithm identifier?
855  else if(OID_COMP(oid, length, RSASSA_PSS_OID) == 0)
856  {
857  keyType = X509_KEY_TYPE_RSA_PSS;
858  }
859 #endif
860 #if (DSA_SUPPORT == ENABLED)
861  //DSA algorithm identifier?
862  else if(OID_COMP(oid, length, DSA_OID) == 0)
863  {
864  keyType = X509_KEY_TYPE_DSA;
865  }
866 #endif
867 #if (EC_SUPPORT == ENABLED)
868  //EC public key identifier?
869  else if(OID_COMP(oid, length, EC_PUBLIC_KEY_OID) == 0)
870  {
871  keyType = X509_KEY_TYPE_EC;
872  }
873 #endif
874 #if (X25519_SUPPORT == ENABLED)
875  //X25519 algorithm identifier?
876  else if(OID_COMP(oid, length, X25519_OID) == 0)
877  {
878  keyType = X509_KEY_TYPE_X25519;
879  }
880 #endif
881 #if (ED25519_SUPPORT == ENABLED)
882  //Ed25519 algorithm identifier?
883  else if(OID_COMP(oid, length, ED25519_OID) == 0)
884  {
885  keyType = X509_KEY_TYPE_ED25519;
886  }
887 #endif
888 #if (X448_SUPPORT == ENABLED)
889  //X448 algorithm identifier?
890  else if(OID_COMP(oid, length, X448_OID) == 0)
891  {
892  keyType = X509_KEY_TYPE_X448;
893  }
894 #endif
895 #if (ED448_SUPPORT == ENABLED)
896  //Ed448 algorithm identifier?
897  else if(OID_COMP(oid, length, ED448_OID) == 0)
898  {
899  keyType = X509_KEY_TYPE_ED448;
900  }
901 #endif
902  //Unknown algorithm identifier?
903  else
904  {
905  keyType = X509_KEY_TYPE_UNKNOWN;
906  }
907 
908  //Return public key type
909  return keyType;
910 }
911 
912 
913 /**
914  * @brief Get the elliptic curve that matches the specified OID
915  * @param[in] oid Object identifier
916  * @param[in] length Length of the OID, in bytes
917  * @return Elliptic curve parameters
918  **/
919 
920 const EcCurve *x509GetCurve(const uint8_t *oid, size_t length)
921 {
922  const EcCurve *curve;
923 
924  //Default elliptic curve parameters
925  curve = NULL;
926 
927 #if (X509_ECDSA_SUPPORT == ENABLED && ECDSA_SUPPORT == ENABLED)
928  //Invalid parameters?
929  if(oid == NULL || length == 0)
930  {
931  curve = NULL;
932  }
933 #if (X509_SECP112R1_SUPPORT == ENABLED)
934  //secp112r1 elliptic curve?
935  else if(OID_COMP(oid, length, SECP112R1_OID) == 0)
936  {
937  curve = ecGetCurve(oid, length);
938  }
939 #endif
940 #if (X509_SECP112R2_SUPPORT == ENABLED)
941  //secp112r2 elliptic curve?
942  else if(OID_COMP(oid, length, SECP112R2_OID) == 0)
943  {
944  curve = ecGetCurve(oid, length);
945  }
946 #endif
947 #if (X509_SECP128R1_SUPPORT == ENABLED)
948  //secp128r1 elliptic curve?
949  else if(OID_COMP(oid, length, SECP128R1_OID) == 0)
950  {
951  curve = ecGetCurve(oid, length);
952  }
953 #endif
954 #if (X509_SECP128R2_SUPPORT == ENABLED)
955  //secp128r2 elliptic curve?
956  else if(OID_COMP(oid, length, SECP128R2_OID) == 0)
957  {
958  curve = ecGetCurve(oid, length);
959  }
960 #endif
961 #if (X509_SECP160K1_SUPPORT == ENABLED)
962  //secp160k1 elliptic curve?
963  else if(OID_COMP(oid, length, SECP160K1_OID) == 0)
964  {
965  curve = ecGetCurve(oid, length);
966  }
967 #endif
968 #if (X509_SECP160R1_SUPPORT == ENABLED)
969  //secp160r1 elliptic curve?
970  else if(OID_COMP(oid, length, SECP160R1_OID) == 0)
971  {
972  curve = ecGetCurve(oid, length);
973  }
974 #endif
975 #if (X509_SECP160R2_SUPPORT == ENABLED)
976  //secp160r2 elliptic curve?
977  else if(OID_COMP(oid, length, SECP160R2_OID) == 0)
978  {
979  curve = ecGetCurve(oid, length);
980  }
981 #endif
982 #if (X509_SECP192K1_SUPPORT == ENABLED)
983  //secp192k1 elliptic curve?
984  else if(OID_COMP(oid, length, SECP192K1_OID) == 0)
985  {
986  curve = ecGetCurve(oid, length);
987  }
988 #endif
989 #if (X509_SECP192R1_SUPPORT == ENABLED)
990  //secp192r1 elliptic curve?
991  else if(OID_COMP(oid, length, SECP192R1_OID) == 0)
992  {
993  curve = ecGetCurve(oid, length);
994  }
995 #endif
996 #if (X509_SECP224K1_SUPPORT == ENABLED)
997  //secp224k1 elliptic curve?
998  else if(OID_COMP(oid, length, SECP224K1_OID) == 0)
999  {
1000  curve = ecGetCurve(oid, length);
1001  }
1002 #endif
1003 #if (X509_SECP224R1_SUPPORT == ENABLED)
1004  //secp224r1 elliptic curve?
1005  else if(OID_COMP(oid, length, SECP224R1_OID) == 0)
1006  {
1007  curve = ecGetCurve(oid, length);
1008  }
1009 #endif
1010 #if (X509_SECP256K1_SUPPORT == ENABLED)
1011  //secp256k1 elliptic curve?
1012  else if(OID_COMP(oid, length, SECP256K1_OID) == 0)
1013  {
1014  curve = ecGetCurve(oid, length);
1015  }
1016 #endif
1017 #if (X509_SECP256R1_SUPPORT == ENABLED)
1018  //secp256r1 elliptic curve?
1019  else if(OID_COMP(oid, length, SECP256R1_OID) == 0)
1020  {
1021  curve = ecGetCurve(oid, length);
1022  }
1023 #endif
1024 #if (X509_SECP384R1_SUPPORT == ENABLED)
1025  //secp384r1 elliptic curve?
1026  else if(OID_COMP(oid, length, SECP384R1_OID) == 0)
1027  {
1028  curve = ecGetCurve(oid, length);
1029  }
1030 #endif
1031 #if (X509_SECP521R1_SUPPORT == ENABLED)
1032  //secp521r1 elliptic curve?
1033  else if(OID_COMP(oid, length, SECP521R1_OID) == 0)
1034  {
1035  curve = ecGetCurve(oid, length);
1036  }
1037 #endif
1038 #if (X509_BRAINPOOLP160R1_SUPPORT == ENABLED)
1039  //brainpoolP160r1 elliptic curve?
1040  else if(OID_COMP(oid, length, BRAINPOOLP160R1_OID) == 0)
1041  {
1042  curve = ecGetCurve(oid, length);
1043  }
1044 #endif
1045 #if (X509_BRAINPOOLP160T1_SUPPORT == ENABLED)
1046  //brainpoolP160t1 elliptic curve?
1047  else if(OID_COMP(oid, length, BRAINPOOLP160T1_OID) == 0)
1048  {
1049  curve = ecGetCurve(oid, length);
1050  }
1051 #endif
1052 #if (X509_BRAINPOOLP192R1_SUPPORT == ENABLED)
1053  //brainpoolP192r1 elliptic curve?
1054  else if(OID_COMP(oid, length, BRAINPOOLP192R1_OID) == 0)
1055  {
1056  curve = ecGetCurve(oid, length);
1057  }
1058 #endif
1059 #if (X509_BRAINPOOLP192T1_SUPPORT == ENABLED)
1060  //brainpoolP192t1 elliptic curve?
1061  else if(OID_COMP(oid, length, BRAINPOOLP192T1_OID) == 0)
1062  {
1063  curve = ecGetCurve(oid, length);
1064  }
1065 #endif
1066 #if (X509_BRAINPOOLP224R1_SUPPORT == ENABLED)
1067  //brainpoolP224r1 elliptic curve?
1068  else if(OID_COMP(oid, length, BRAINPOOLP224R1_OID) == 0)
1069  {
1070  curve = ecGetCurve(oid, length);
1071  }
1072 #endif
1073 #if (X509_BRAINPOOLP224T1_SUPPORT == ENABLED)
1074  //brainpoolP224t1 elliptic curve?
1075  else if(OID_COMP(oid, length, BRAINPOOLP224T1_OID) == 0)
1076  {
1077  curve = ecGetCurve(oid, length);
1078  }
1079 #endif
1080 #if (X509_BRAINPOOLP256R1_SUPPORT == ENABLED)
1081  //brainpoolP256r1 elliptic curve?
1082  else if(OID_COMP(oid, length, BRAINPOOLP256R1_OID) == 0)
1083  {
1084  curve = ecGetCurve(oid, length);
1085  }
1086 #endif
1087 #if (X509_BRAINPOOLP256T1_SUPPORT == ENABLED)
1088  //brainpoolP256t1 elliptic curve?
1089  else if(OID_COMP(oid, length, BRAINPOOLP256T1_OID) == 0)
1090  {
1091  curve = ecGetCurve(oid, length);
1092  }
1093 #endif
1094 #if (X509_BRAINPOOLP320R1_SUPPORT == ENABLED)
1095  //brainpoolP320r1 elliptic curve?
1096  else if(OID_COMP(oid, length, BRAINPOOLP320R1_OID) == 0)
1097  {
1098  curve = ecGetCurve(oid, length);
1099  }
1100 #endif
1101 #if (X509_BRAINPOOLP320T1_SUPPORT == ENABLED)
1102  //brainpoolP320t1 elliptic curve?
1103  else if(OID_COMP(oid, length, BRAINPOOLP320T1_OID) == 0)
1104  {
1105  curve = ecGetCurve(oid, length);
1106  }
1107 #endif
1108 #if (X509_BRAINPOOLP384R1_SUPPORT == ENABLED)
1109  //brainpoolP384r1 elliptic curve?
1110  else if(OID_COMP(oid, length, BRAINPOOLP384R1_OID) == 0)
1111  {
1112  curve = ecGetCurve(oid, length);
1113  }
1114 #endif
1115 #if (X509_BRAINPOOLP384T1_SUPPORT == ENABLED)
1116  //brainpoolP384t1 elliptic curve?
1117  else if(OID_COMP(oid, length, BRAINPOOLP384T1_OID) == 0)
1118  {
1119  curve = ecGetCurve(oid, length);
1120  }
1121 #endif
1122 #if (X509_BRAINPOOLP512R1_SUPPORT == ENABLED)
1123  //brainpoolP512r1 elliptic curve?
1124  else if(OID_COMP(oid, length, BRAINPOOLP512R1_OID) == 0)
1125  {
1126  curve = ecGetCurve(oid, length);
1127  }
1128 #endif
1129 #if (X509_BRAINPOOLP512T1_SUPPORT == ENABLED)
1130  //brainpoolP512t1 elliptic curve?
1131  else if(OID_COMP(oid, length, BRAINPOOLP512T1_OID) == 0)
1132  {
1133  curve = ecGetCurve(oid, length);
1134  }
1135 #endif
1136 #if (X509_FRP256V1_SUPPORT == ENABLED)
1137  //FRP256v1 elliptic curve?
1138  else if(OID_COMP(oid, length, FRP256V1_OID) == 0)
1139  {
1140  curve = ecGetCurve(oid, length);
1141  }
1142 #endif
1143 #if (X509_SM2_SUPPORT == ENABLED)
1144  //SM2 elliptic curve?
1145  else if(OID_COMP(oid, length, SM2_OID) == 0)
1146  {
1147  curve = ecGetCurve(oid, length);
1148  }
1149 #endif
1150 #if (X509_ED25519_SUPPORT == ENABLED)
1151  //Ed25519 elliptic curve?
1152  else if(OID_COMP(oid, length, ED25519_OID) == 0)
1153  {
1154  curve = ecGetCurve(oid, length);
1155  }
1156 #endif
1157 #if (X509_ED448_SUPPORT == ENABLED)
1158  //Ed448 elliptic curve?
1159  else if(OID_COMP(oid, length, ED448_OID) == 0)
1160  {
1161  curve = ecGetCurve(oid, length);
1162  }
1163 #endif
1164  //Unknown elliptic curve?
1165  else
1166  {
1167  curve = NULL;
1168  }
1169 #endif
1170 
1171  //Return the elliptic curve parameters, if any
1172  return curve;
1173 }
1174 
1175 #endif
const uint8_t X509_POLICY_MAPPINGS_OID[3]
Definition: x509_common.c:109
bool_t x509IsCurveSupported(const uint8_t *oid, size_t length)
Check whether a given elliptic curve is supported.
Definition: x509_common.c:389
#define SHA3_512_HASH_ALGO
Definition: sha3_512.h:45
X.509 common definitions.
@ X509_KEY_TYPE_RSA
Definition: x509_common.h:637
const uint8_t X509_DOMAIN_COMPONENT_OID[10]
Definition: x509_common.c:76
const uint8_t X509_CERTIFICATE_POLICIES_OID[3]
Definition: x509_common.c:107
const uint8_t RSASSA_PKCS1_V1_5_WITH_SHA3_512_OID[9]
Definition: rsa.c:82
#define SHA256_HASH_ALGO
Definition: sha256.h:49
int bool_t
Definition: compiler_port.h:61
const uint8_t X509_KP_DOC_SIGNING_OID[8]
Definition: x509_common.c:158
#define SHA1_HASH_ALGO
Definition: sha1.h:49
const uint8_t X509_KP_SERVER_AUTH_OID[8]
Definition: x509_common.c:130
const uint8_t SHA3_384_OID[9]
Definition: sha3_384.c:47
const uint8_t DSA_WITH_SHA224_OID[9]
Definition: dsa.c:55
bool_t x509IsSignAlgoSupported(X509SignatureAlgo signAlgo)
Check whether a given signature algorithm is supported.
Definition: x509_common.c:210
bool_t x509IsHashAlgoSupported(X509HashAlgo hashAlgo)
Check whether a given hash algorithm is supported.
Definition: x509_common.c:285
const uint8_t X509_ISSUER_ALT_NAME_OID[3]
Definition: x509_common.c:87
#define SHA512_HASH_ALGO
Definition: sha512.h:49
const uint8_t X25519_OID[3]
Definition: ec_curves.c:108
const uint8_t MD5_WITH_RSA_ENCRYPTION_OID[9]
Definition: rsa.c:59
const uint8_t X509_SUBJECT_ALT_NAME_OID[3]
Definition: x509_common.c:85
const uint8_t SHA512_WITH_RSA_ENCRYPTION_OID[9]
Definition: rsa.c:69
@ X509_KEY_TYPE_X448
Definition: x509_common.h:644
const uint8_t X509_ORGANIZATION_NAME_OID[3]
Definition: x509_common.c:58
const uint8_t RSASSA_PKCS1_V1_5_WITH_SHA3_384_OID[9]
Definition: rsa.c:80
X509OctetString hashAlgo
Definition: x509_common.h:1078
const uint8_t X509_KP_CODE_SIGNING_OID[8]
Definition: x509_common.c:134
OID (Object Identifier)
#define TRUE
Definition: os_port.h:50
const uint8_t RSASSA_PKCS1_V1_5_WITH_SHA3_224_OID[9]
Definition: rsa.c:76
const uint8_t BRAINPOOLP512T1_OID[9]
Definition: ec_curves.c:102
const uint8_t ECDSA_WITH_SHA3_512_OID[9]
Definition: ecdsa.c:62
const uint8_t EC_PUBLIC_KEY_OID[7]
Definition: ec.c:44
const uint8_t X509_EXTENDED_KEY_USAGE_OID[3]
Definition: x509_common.c:115
const uint8_t X509_ANY_EXT_KEY_USAGE_OID[4]
Definition: x509_common.c:128
const uint8_t SECP224R1_OID[5]
Definition: ec_curves.c:66
const uint8_t BRAINPOOLP512R1_OID[9]
Definition: ec_curves.c:100
const uint8_t X509_INVALIDITY_DATE_OID[3]
Definition: x509_common.c:95
const uint8_t BRAINPOOLP224T1_OID[9]
Definition: ec_curves.c:86
const uint8_t SECP160K1_OID[5]
Definition: ec_curves.c:54
const uint8_t X509_POLICY_CONSTRAINTS_OID[3]
Definition: x509_common.c:113
const uint8_t SECP256K1_OID[5]
Definition: ec_curves.c:68
const uint8_t ECDSA_WITH_SHA3_256_OID[9]
Definition: ecdsa.c:58
#define osMemcmp(p1, p2, length)
Definition: os_port.h:156
const uint8_t X509_KEY_USAGE_OID[3]
Definition: x509_common.c:83
const uint8_t X509_KP_TIME_STAMPING_OID[8]
Definition: x509_common.c:144
#define SM3_HASH_ALGO
Definition: sm3.h:49
const uint8_t BRAINPOOLP384R1_OID[9]
Definition: ec_curves.c:96
const uint8_t PKCS9_CHALLENGE_PASSWORD_OID[9]
Definition: x509_common.c:168
const uint8_t X509_ISSUING_DISTR_POINT_OID[3]
Definition: x509_common.c:99
const uint8_t X509_NAME_CONSTRAINTS_OID[3]
Definition: x509_common.c:103
const uint8_t RSASSA_PSS_OID[9]
Definition: rsa.c:85
const uint8_t X509_KP_OCSP_SIGNING_OID[8]
Definition: x509_common.c:146
const uint8_t X509_COUNTRY_NAME_OID[3]
Definition: x509_common.c:52
const uint8_t ECDSA_WITH_SHA256_OID[8]
Definition: ecdsa.c:50
const uint8_t BRAINPOOLP320R1_OID[9]
Definition: ec_curves.c:92
const uint8_t SECP256R1_OID[8]
Definition: ec_curves.c:70
uint8_t oid[]
Definition: lldp_tlv.h:300
const uint8_t X509_INHIBIT_ANY_POLICY_OID[3]
Definition: x509_common.c:119
const uint8_t DSA_WITH_SHA3_512_OID[9]
Definition: dsa.c:69
const uint8_t X509_PSEUDONYM_OID[3]
Definition: x509_common.c:74
const uint8_t SECP224K1_OID[5]
Definition: ec_curves.c:64
const uint8_t BRAINPOOLP256T1_OID[9]
Definition: ec_curves.c:90
Certificate parsing options.
Definition: x509_common.h:1336
const uint8_t X509_DELTA_CRL_INDICATOR_OID[3]
Definition: x509_common.c:97
const uint8_t DSA_OID[7]
Definition: dsa.c:51
const uint8_t X509_BASIC_CONSTRAINTS_OID[3]
Definition: x509_common.c:89
const uint8_t RSASSA_PKCS1_V1_5_WITH_SHA3_256_OID[9]
Definition: rsa.c:78
#define SHA3_224_HASH_ALGO
Definition: sha3_224.h:45
const uint8_t X509_TITLE_OID[3]
Definition: x509_common.c:62
const uint8_t SHA384_WITH_RSA_ENCRYPTION_OID[9]
Definition: rsa.c:67
const uint8_t SECP112R1_OID[5]
Definition: ec_curves.c:46
const uint8_t SECP521R1_OID[5]
Definition: ec_curves.c:74
@ X509_KEY_TYPE_EC
Definition: x509_common.h:640
#define FALSE
Definition: os_port.h:46
X509SignatureAlgo
Signature algorithms.
Definition: x509_common.h:654
const uint8_t X509_AUTH_INFO_ACCESS_OID[8]
Definition: x509_common.c:121
const uint8_t BRAINPOOLP160R1_OID[9]
Definition: ec_curves.c:76
const X509Options X509_DEFAULT_OPTIONS
Definition: x509_common.c:173
const EcCurve * x509GetCurve(const uint8_t *oid, size_t length)
Get the elliptic curve that matches the specified OID.
Definition: x509_common.c:920
error_t
Error codes.
Definition: error.h:43
const uint8_t DSA_WITH_SHA3_256_OID[9]
Definition: dsa.c:65
const uint8_t X509_INITIALS_OID[3]
Definition: x509_common.c:68
const uint8_t DSA_WITH_SHA384_OID[9]
Definition: dsa.c:59
const uint8_t X509_DN_QUALIFIER_OID[3]
Definition: x509_common.c:72
const uint8_t X509_SUBJECT_DIR_ATTR_OID[3]
Definition: x509_common.c:79
@ X509_SIGN_ALGO_ECDSA
Definition: x509_common.h:659
@ X509_HASH_ALGO_NONE
Definition: x509_common.h:672
const uint8_t SHA256_OID[9]
Definition: sha256.c:80
const uint8_t X509_LOCALITY_NAME_OID[3]
Definition: x509_common.c:54
const uint8_t BRAINPOOLP192T1_OID[9]
Definition: ec_curves.c:82
#define MD5_HASH_ALGO
Definition: md5.h:49
const uint8_t X509_REASON_CODE_OID[3]
Definition: x509_common.c:93
const uint8_t X509_KP_EMAIL_PROTECTION_OID[8]
Definition: x509_common.c:136
const uint8_t X509_SERIAL_NUMBER_OID[3]
Definition: x509_common.c:50
const uint8_t ECDSA_WITH_SHA384_OID[8]
Definition: ecdsa.c:52
const uint8_t X509_AUTHORITY_KEY_ID_OID[3]
Definition: x509_common.c:111
@ X509_HASH_ALGO_SHA1
Definition: x509_common.h:674
const uint8_t SHA3_512_OID[9]
Definition: sha3_512.c:47
const uint8_t DSA_WITH_SHA512_OID[9]
Definition: dsa.c:61
const uint8_t X509_COMMON_NAME_OID[3]
Definition: x509_common.c:46
General definitions for cryptographic algorithms.
error_t x509GetSignHashAlgo(const X509SignAlgoId *signAlgoId, X509SignatureAlgo *signAlgo, const HashAlgo **hashAlgo)
Get the signature and hash algorithms that match the specified identifier.
Definition: x509_common.c:412
const uint8_t X509_KP_IPSEC_USER_OID[8]
Definition: x509_common.c:142
const uint8_t SHA3_224_OID[9]
Definition: sha3_224.c:47
@ X509_HASH_ALGO_SHA3_224
Definition: x509_common.h:679
const uint8_t SECP128R2_OID[5]
Definition: ec_curves.c:52
const uint8_t SECP160R1_OID[5]
Definition: ec_curves.c:56
const uint8_t X509_PKIX_OCSP_NO_CHECK_OID[9]
Definition: x509_common.c:123
@ X509_KEY_TYPE_RSA_PSS
Definition: x509_common.h:638
const uint8_t X509_AD_OCSP[8]
Definition: x509_common.c:163
const uint8_t X509_KP_IPSEC_IKE_OID[8]
Definition: x509_common.c:148
@ X509_HASH_ALGO_SHA224
Definition: x509_common.h:675
uint8_t length
Definition: tcp.h:375
const uint8_t X509_CRL_NUMBER_OID[3]
Definition: x509_common.c:91
const uint8_t SM2_WITH_SM3_OID[8]
Definition: sm2.c:45
X509OctetString oid
Definition: x509_common.h:1091
const uint8_t X509_CERTIFICATE_ISSUER_OID[3]
Definition: x509_common.c:101
const uint8_t ECDSA_WITH_SHA3_224_OID[9]
Definition: ecdsa.c:56
X509HashAlgo
Hash algorithms.
Definition: x509_common.h:671
const uint8_t X509_KP_CLIENT_AUTH_OID[8]
Definition: x509_common.c:132
const uint8_t ECDSA_WITH_SHA1_OID[7]
Definition: ecdsa.c:46
const uint8_t ECDSA_WITH_SHA224_OID[8]
Definition: ecdsa.c:48
@ X509_SIGN_ALGO_RSA
Definition: x509_common.h:656
const uint8_t X509_CRL_DISTR_POINTS_OID[3]
Definition: x509_common.c:105
const uint8_t SHA256_WITH_RSA_ENCRYPTION_OID[9]
Definition: rsa.c:65
const uint8_t PKCS9_EMAIL_ADDR_OID[9]
Definition: x509_common.c:166
const uint8_t SECP192R1_OID[8]
Definition: ec_curves.c:62
const uint8_t ED448_OID[3]
Definition: ec_curves.c:114
const uint8_t ECDSA_WITH_SHA512_OID[8]
Definition: ecdsa.c:54
const uint8_t SECP384R1_OID[5]
Definition: ec_curves.c:72
Collection of hash algorithms.
const uint8_t ED25519_OID[3]
Definition: ec_curves.c:112
const uint8_t RSA_ENCRYPTION_OID[9]
Definition: rsa.c:54
const uint8_t X448_OID[3]
Definition: ec_curves.c:110
const uint8_t DSA_WITH_SHA3_384_OID[9]
Definition: dsa.c:67
@ X509_HASH_ALGO_SHA3_512
Definition: x509_common.h:682
#define SHA384_HASH_ALGO
Definition: sha384.h:45
const uint8_t BRAINPOOLP384T1_OID[9]
Definition: ec_curves.c:98
const uint8_t SECP192K1_OID[5]
Definition: ec_curves.c:60
const uint8_t X509_KP_SSH_SERVER_OID[8]
Definition: x509_common.c:152
const uint8_t DSA_WITH_SHA3_224_OID[9]
Definition: dsa.c:63
@ X509_HASH_ALGO_MD5
Definition: x509_common.h:673
const uint8_t BRAINPOOLP160T1_OID[9]
Definition: ec_curves.c:78
#define SHA3_256_HASH_ALGO
Definition: sha3_256.h:45
const uint8_t X509_FRESHEST_CRL_OID[3]
Definition: x509_common.c:117
const uint8_t SECP112R2_OID[5]
Definition: ec_curves.c:48
@ X509_SIGN_ALGO_RSA_PSS
Definition: x509_common.h:657
@ X509_KEY_TYPE_ED448
Definition: x509_common.h:645
@ X509_HASH_ALGO_SHA3_256
Definition: x509_common.h:680
@ X509_HASH_ALGO_SHA3_384
Definition: x509_common.h:681
const uint8_t BRAINPOOLP320T1_OID[9]
Definition: ec_curves.c:94
const uint8_t X509_NAME_OID[3]
Definition: x509_common.c:64
const uint8_t SHA3_256_OID[9]
Definition: sha3_256.c:47
#define OID_COMP(oid1, oidLen1, oid2)
Definition: oid.h:42
const uint8_t X509_AD_CA_ISSUERS[8]
Definition: x509_common.c:161
const uint8_t ECDSA_WITH_SHA3_384_OID[9]
Definition: ecdsa.c:60
@ X509_HASH_ALGO_SHA512
Definition: x509_common.h:678
const uint8_t X509_NS_CERT_TYPE_OID[9]
Definition: x509_common.c:125
@ X509_KEY_TYPE_DSA
Definition: x509_common.h:639
const uint8_t BRAINPOOLP224R1_OID[9]
Definition: ec_curves.c:84
const uint8_t FRP256V1_OID[10]
Definition: ec_curves.c:104
const uint8_t DSA_WITH_SHA1_OID[7]
Definition: dsa.c:53
const uint8_t DSA_WITH_SHA256_OID[9]
Definition: dsa.c:57
const uint8_t X509_GENERATION_QUALIFIER_OID[3]
Definition: x509_common.c:70
uint8_t oidLen
Definition: lldp_tlv.h:299
@ X509_HASH_ALGO_SHA384
Definition: x509_common.h:677
@ X509_HASH_ALGO_SHA256
Definition: x509_common.h:676
const uint8_t BRAINPOOLP192R1_OID[9]
Definition: ec_curves.c:80
const uint8_t SHA512_OID[9]
Definition: sha512.c:97
const uint8_t X509_KP_IPSEC_TUNNEL_OID[8]
Definition: x509_common.c:140
const uint8_t X509_KP_CMC_RA_OID[8]
Definition: x509_common.c:156
const uint8_t X509_ORGANIZATIONAL_UNIT_NAME_OID[3]
Definition: x509_common.c:60
const EcCurve * ecGetCurve(const uint8_t *oid, size_t length)
Get the elliptic curve that matches the specified OID.
Definition: ec_curves.c:5888
const uint8_t SECP160R2_OID[5]
Definition: ec_curves.c:58
const uint8_t X509_SURNAME_OID[3]
Definition: x509_common.c:48
const uint8_t SHA1_OID[5]
Definition: sha1.c:73
#define SHA224_HASH_ALGO
Definition: sha224.h:45
const uint8_t SHA224_WITH_RSA_ENCRYPTION_OID[9]
Definition: rsa.c:63
const uint8_t X509_GIVEN_NAME_OID[3]
Definition: x509_common.c:66
const uint8_t X509_SUBJECT_KEY_ID_OID[3]
Definition: x509_common.c:81
const uint8_t * value
Definition: x509_common.h:704
Common interface for hash algorithms.
Definition: crypto.h:1124
@ X509_KEY_TYPE_UNKNOWN
Definition: x509_common.h:636
#define EcCurve
Definition: ec.h:346
const uint8_t SHA224_OID[9]
Definition: sha224.c:47
const uint8_t X509_KP_IPSEC_END_SYSTEM_OID[8]
Definition: x509_common.c:138
bool_t x509CompareName(const uint8_t *name1, size_t nameLen1, const uint8_t *name2, size_t nameLen2)
Compare distinguished names.
Definition: x509_common.c:188
@ ERROR_UNSUPPORTED_SIGNATURE_ALGO
Definition: error.h:132
@ X509_SIGN_ALGO_SM2
Definition: x509_common.h:660
@ X509_SIGN_ALGO_ED25519
Definition: x509_common.h:661
@ X509_KEY_TYPE_ED25519
Definition: x509_common.h:643
X509KeyType
Public Key types.
Definition: x509_common.h:635
@ X509_SIGN_ALGO_NONE
Definition: x509_common.h:655
X509KeyType x509GetPublicKeyType(const uint8_t *oid, size_t length)
Get the public key type that matches the specified OID.
Definition: x509_common.c:839
const uint8_t SHA384_OID[9]
Definition: sha384.c:47
@ X509_HASH_ALGO_SM3
Definition: x509_common.h:683
X509RsaPssParameters rsaPssParams
Definition: x509_common.h:1093
const uint8_t X509_STATE_OR_PROVINCE_NAME_OID[]
Definition: x509_common.c:56
const uint8_t X509_KP_CMC_CA_OID[8]
Definition: x509_common.c:154
const uint8_t SHA1_WITH_RSA_ENCRYPTION_OID[9]
Definition: rsa.c:61
const uint8_t PKCS9_EXTENSION_REQUEST_OID[9]
Definition: x509_common.c:170
#define SHA3_384_HASH_ALGO
Definition: sha3_384.h:45
Signature algorithm identifier.
Definition: x509_common.h:1090
@ NO_ERROR
Success.
Definition: error.h:44
const uint8_t SECP128R1_OID[5]
Definition: ec_curves.c:50
Debugging facilities.
@ X509_KEY_TYPE_X25519
Definition: x509_common.h:642
ASN.1 (Abstract Syntax Notation One)
@ X509_SIGN_ALGO_DSA
Definition: x509_common.h:658
@ X509_SIGN_ALGO_ED448
Definition: x509_common.h:662
const uint8_t BRAINPOOLP256R1_OID[9]
Definition: ec_curves.c:88
const uint8_t X509_KP_SSH_CLIENT_OID[8]
Definition: x509_common.c:150
const uint8_t SM2_OID[8]
Definition: ec_curves.c:106