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.0
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 Document Signing OID (1.3.6.1.5.5.7.3.36)
154 const uint8_t X509_KP_DOC_SIGNING_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x24};
155 
156 //Access Description CA Issuers OID (1.3.6.1.5.5.7.48.1)
157 const uint8_t X509_AD_CA_ISSUERS[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01};
158 //Access Description OCSP (1.3.6.1.5.5.7.48.2)
159 const uint8_t X509_AD_OCSP[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x02};
160 
161 //PKCS #9 e-mail address OID (1.2.840.113549.1.9.1)
162 const uint8_t X509_EMAIL_ADDRESS_OID[9] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x01};
163 //PKCS #9 Challenge Password OID (1.2.840.113549.1.9.7)
164 const uint8_t X509_CHALLENGE_PASSWORD_OID[9] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x07};
165 //PKCS #9 Extension Request OID (1.2.840.113549.1.9.14)
166 const uint8_t X509_EXTENSION_REQUEST_OID[9] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x0E};
167 
168 
169 /**
170  * @brief Check whether a given signature algorithm is supported
171  * @param[in] signAlgo signature algorithm
172  * @return TRUE is the signature algorithm is supported, else FALSE
173  **/
174 
176 {
177  bool_t acceptable;
178 
179  //Invalid signature algorithm?
180  if(signAlgo == X509_SIGN_ALGO_NONE)
181  {
182  acceptable = FALSE;
183  }
184 #if (X509_RSA_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
185  //RSA signature algorithm?
186  else if(signAlgo == X509_SIGN_ALGO_RSA)
187  {
188  acceptable = TRUE;
189  }
190 #endif
191 #if (X509_RSA_PSS_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
192  //RSA-PSS signature algorithm?
193  else if(signAlgo == X509_SIGN_ALGO_RSA_PSS)
194  {
195  acceptable = TRUE;
196  }
197 #endif
198 #if (X509_DSA_SUPPORT == ENABLED && DSA_SUPPORT == ENABLED)
199  //DSA signature algorithm?
200  else if(signAlgo == X509_SIGN_ALGO_DSA)
201  {
202  acceptable = TRUE;
203  }
204 #endif
205 #if (X509_ECDSA_SUPPORT == ENABLED && ECDSA_SUPPORT == ENABLED)
206  //ECDSA signature algorithm?
207  else if(signAlgo == X509_SIGN_ALGO_ECDSA)
208  {
209  acceptable = TRUE;
210  }
211 #endif
212 #if (X509_SM2_SUPPORT == ENABLED && SM2_SUPPORT == ENABLED)
213  //SM2 signature algorithm?
214  else if(signAlgo == X509_SIGN_ALGO_SM2)
215  {
216  acceptable = TRUE;
217  }
218 #endif
219 #if (X509_ED25519_SUPPORT == ENABLED && ED25519_SUPPORT == ENABLED)
220  //Ed25519 signature algorithm?
221  else if(signAlgo == X509_SIGN_ALGO_ED25519)
222  {
223  acceptable = TRUE;
224  }
225 #endif
226 #if (X509_ED448_SUPPORT == ENABLED && ED448_SUPPORT == ENABLED)
227  //Ed448 signature algorithm?
228  else if(signAlgo == X509_SIGN_ALGO_ED448)
229  {
230  acceptable = TRUE;
231  }
232 #endif
233  //Invalid signature algorithm?
234  else
235  {
236  acceptable = FALSE;
237  }
238 
239  //Return TRUE is the signature algorithm is supported
240  return acceptable;
241 }
242 
243 
244 /**
245  * @brief Check whether a given hash algorithm is supported
246  * @param[in] hashAlgo signature hash
247  * @return TRUE is the signature hash is supported, else FALSE
248  **/
249 
251 {
252  bool_t acceptable;
253 
254  //Invalid hash algorithm?
255  if(hashAlgo == X509_HASH_ALGO_NONE)
256  {
257  acceptable = FALSE;
258  }
259 #if (X509_MD5_SUPPORT == ENABLED && MD5_SUPPORT == ENABLED)
260  //MD5 hash algorithm?
261  else if(hashAlgo == X509_HASH_ALGO_MD5)
262  {
263  acceptable = TRUE;
264  }
265 #endif
266 #if (X509_SHA1_SUPPORT == ENABLED && SHA1_SUPPORT == ENABLED)
267  //SHA-1 hash algorithm?
268  else if(hashAlgo == X509_HASH_ALGO_SHA1)
269  {
270  acceptable = TRUE;
271  }
272 #endif
273 #if (X509_SHA224_SUPPORT == ENABLED && SHA224_SUPPORT == ENABLED)
274  //SHA-224 hash algorithm?
275  else if(hashAlgo == X509_HASH_ALGO_SHA224)
276  {
277  acceptable = TRUE;
278  }
279 #endif
280 #if (X509_SHA256_SUPPORT == ENABLED && SHA256_SUPPORT == ENABLED)
281  //SHA-256 hash algorithm?
282  else if(hashAlgo == X509_HASH_ALGO_SHA256)
283  {
284  acceptable = TRUE;
285  }
286 #endif
287 #if (X509_SHA384_SUPPORT == ENABLED && SHA384_SUPPORT == ENABLED)
288  //SHA-384 hash algorithm?
289  else if(hashAlgo == X509_HASH_ALGO_SHA384)
290  {
291  acceptable = TRUE;
292  }
293 #endif
294 #if (X509_SHA512_SUPPORT == ENABLED && SHA512_SUPPORT == ENABLED)
295  //SHA-512 hash algorithm?
296  else if(hashAlgo == X509_HASH_ALGO_SHA512)
297  {
298  acceptable = TRUE;
299  }
300 #endif
301 #if (X509_SHA3_224_SUPPORT == ENABLED && SHA3_224_SUPPORT == ENABLED)
302  //SHA3-224 hash algorithm?
303  else if(hashAlgo == X509_HASH_ALGO_SHA3_224)
304  {
305  acceptable = TRUE;
306  }
307 #endif
308 #if (X509_SHA3_256_SUPPORT == ENABLED && SHA3_256_SUPPORT == ENABLED)
309  //SHA3-256 hash algorithm?
310  else if(hashAlgo == X509_HASH_ALGO_SHA3_256)
311  {
312  acceptable = TRUE;
313  }
314 #endif
315 #if (X509_SHA3_384_SUPPORT == ENABLED && SHA3_384_SUPPORT == ENABLED)
316  //SHA3-384 hash algorithm?
317  else if(hashAlgo == X509_HASH_ALGO_SHA3_384)
318  {
319  acceptable = TRUE;
320  }
321 #endif
322 #if (X509_SHA3_512_SUPPORT == ENABLED && SHA3_512_SUPPORT == ENABLED)
323  //SHA3-512 hash algorithm?
324  else if(hashAlgo == X509_HASH_ALGO_SHA3_512)
325  {
326  acceptable = TRUE;
327  }
328 #endif
329 #if (X509_SM3_SUPPORT == ENABLED && SM3_SUPPORT == ENABLED)
330  //SM3 hash algorithm?
331  else if(hashAlgo == X509_HASH_ALGO_SM3)
332  {
333  acceptable = TRUE;
334  }
335 #endif
336  //Invalid hash algorithm?
337  else
338  {
339  acceptable = FALSE;
340  }
341 
342  //Return TRUE is the hash algorithm is supported
343  return acceptable;
344 }
345 
346 
347 /**
348  * @brief Check whether a given elliptic curve is supported
349  * @param[in] oid Object identifier
350  * @param[in] length Length of the OID, in bytes
351  * @return TRUE is the elliptic curve is supported, else FALSE
352  **/
353 
354 bool_t x509IsCurveSupported(const uint8_t *oid, size_t length)
355 {
356  //Return TRUE is the elliptic curve is supported
357  if(x509GetCurve(oid, length) != NULL)
358  {
359  return TRUE;
360  }
361  else
362  {
363  return FALSE;
364  }
365 }
366 
367 
368 /**
369  * @brief Get the signature and hash algorithms that match the specified
370  * identifier
371  * @param[in] signAlgoId Signature algorithm identifier
372  * @param[out] signAlgo Signature algorithm
373  * @param[out] hashAlgo Hash algorithm
374  * @return Error code
375  **/
376 
378  X509SignatureAlgo *signAlgo, const HashAlgo **hashAlgo)
379 {
380  error_t error;
381  size_t oidLen;
382  const uint8_t *oid;
383 
384  //Initialize status code
385  error = NO_ERROR;
386 
387  //Point to the object identifier
388  oid = signAlgoId->oid.value;
389  oidLen = signAlgoId->oid.length;
390 
391  //Just for sanity
392  (void) oid;
393  (void) oidLen;
394 
395 #if (X509_RSA_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
396 #if (X509_MD5_SUPPORT == ENABLED && MD5_SUPPORT == ENABLED)
397  //RSA with MD5 signature algorithm?
399  {
400  *signAlgo = X509_SIGN_ALGO_RSA;
401  *hashAlgo = MD5_HASH_ALGO;
402  }
403  else
404 #endif
405 #if (X509_SHA1_SUPPORT == ENABLED && SHA1_SUPPORT == ENABLED)
406  //RSA with SHA-1 signature algorithm?
408  {
409  *signAlgo = X509_SIGN_ALGO_RSA;
410  *hashAlgo = SHA1_HASH_ALGO;
411  }
412  else
413 #endif
414 #if (X509_SHA224_SUPPORT == ENABLED && SHA224_SUPPORT == ENABLED)
415  //RSA with SHA-224 signature algorithm?
417  {
418  *signAlgo = X509_SIGN_ALGO_RSA;
419  *hashAlgo = SHA224_HASH_ALGO;
420  }
421  else
422 #endif
423 #if (X509_SHA256_SUPPORT == ENABLED && SHA256_SUPPORT == ENABLED)
424  //RSA with SHA-256 signature algorithm?
426  {
427  *signAlgo = X509_SIGN_ALGO_RSA;
428  *hashAlgo = SHA256_HASH_ALGO;
429  }
430  else
431 #endif
432 #if (X509_SHA384_SUPPORT == ENABLED && SHA384_SUPPORT == ENABLED)
433  //RSA with SHA-384 signature algorithm?
435  {
436  *signAlgo = X509_SIGN_ALGO_RSA;
437  *hashAlgo = SHA384_HASH_ALGO;
438  }
439  else
440 #endif
441 #if (X509_SHA512_SUPPORT == ENABLED && SHA512_SUPPORT == ENABLED)
442  //RSA with SHA-512 signature algorithm?
444  {
445  *signAlgo = X509_SIGN_ALGO_RSA;
446  *hashAlgo = SHA512_HASH_ALGO;
447  }
448  else
449 #endif
450 #if (X509_SHA3_224_SUPPORT == ENABLED && SHA3_224_SUPPORT == ENABLED)
451  //RSA with SHA3-224 signature algorithm?
453  {
454  *signAlgo = X509_SIGN_ALGO_RSA;
455  *hashAlgo = SHA3_224_HASH_ALGO;
456  }
457  else
458 #endif
459 #if (X509_SHA3_256_SUPPORT == ENABLED && SHA3_256_SUPPORT == ENABLED)
460  //RSA with SHA3-256 signature algorithm?
462  {
463  *signAlgo = X509_SIGN_ALGO_RSA;
464  *hashAlgo = SHA3_256_HASH_ALGO;
465  }
466  else
467 #endif
468 #if (X509_SHA3_384_SUPPORT == ENABLED && SHA3_384_SUPPORT == ENABLED)
469  //RSA with SHA3-384 signature algorithm?
471  {
472  *signAlgo = X509_SIGN_ALGO_RSA;
473  *hashAlgo = SHA3_384_HASH_ALGO;
474  }
475  else
476 #endif
477 #if (X509_SHA3_512_SUPPORT == ENABLED && SHA3_512_SUPPORT == ENABLED)
478  //RSA with SHA3-512 signature algorithm?
480  {
481  *signAlgo = X509_SIGN_ALGO_RSA;
482  *hashAlgo = SHA3_512_HASH_ALGO;
483  }
484  else
485 #endif
486 #endif
487 #if (X509_RSA_PSS_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
488  //RSA-PSS signature algorithm
489  if(OID_COMP(oid, oidLen, RSASSA_PSS_OID) == 0)
490  {
491  //Get the OID of the hash algorithm
492  oid = signAlgoId->rsaPssParams.hashAlgo.value;
493  oidLen = signAlgoId->rsaPssParams.hashAlgo.length;
494 
495 #if (X509_SHA1_SUPPORT == ENABLED && SHA1_SUPPORT == ENABLED)
496  //SHA-1 hash algorithm identifier?
497  if(OID_COMP(oid, oidLen, SHA1_OID) == 0)
498  {
499  //RSA-PSS with SHA-1 signature algorithm
500  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
501  *hashAlgo = SHA1_HASH_ALGO;
502  }
503  else
504 #endif
505 #if (X509_SHA224_SUPPORT == ENABLED && SHA224_SUPPORT == ENABLED)
506  //SHA-224 hash algorithm identifier?
507  if(OID_COMP(oid, oidLen, SHA224_OID) == 0)
508  {
509  //RSA-PSS with SHA-224 signature algorithm
510  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
511  *hashAlgo = SHA224_HASH_ALGO;
512  }
513  else
514 #endif
515 #if (X509_SHA256_SUPPORT == ENABLED && SHA256_SUPPORT == ENABLED)
516  //SHA-256 hash algorithm identifier?
517  if(OID_COMP(oid, oidLen, SHA256_OID) == 0)
518  {
519  //RSA-PSS with SHA-256 signature algorithm
520  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
521  *hashAlgo = SHA256_HASH_ALGO;
522  }
523  else
524 #endif
525 #if (X509_SHA384_SUPPORT == ENABLED && SHA384_SUPPORT == ENABLED)
526  //SHA-384 hash algorithm identifier?
527  if(OID_COMP(oid, oidLen, SHA384_OID) == 0)
528  {
529  //RSA-PSS with SHA-384 signature algorithm
530  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
531  *hashAlgo = SHA384_HASH_ALGO;
532  }
533  else
534 #endif
535 #if (X509_SHA512_SUPPORT == ENABLED && SHA512_SUPPORT == ENABLED)
536  //SHA-512 hash algorithm identifier?
537  if(OID_COMP(oid, oidLen, SHA512_OID) == 0)
538  {
539  //RSA-PSS with SHA-512 signature algorithm
540  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
541  *hashAlgo = SHA512_HASH_ALGO;
542  }
543  else
544 #endif
545 #if (X509_SHA3_224_SUPPORT == ENABLED && SHA3_224_SUPPORT == ENABLED)
546  //SHA3-224 hash algorithm identifier?
547  if(OID_COMP(oid, oidLen, SHA3_224_OID) == 0)
548  {
549  //RSA-PSS with SHA3-224 signature algorithm
550  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
551  *hashAlgo = SHA3_224_HASH_ALGO;
552  }
553  else
554 #endif
555 #if (X509_SHA3_256_SUPPORT == ENABLED && SHA3_256_SUPPORT == ENABLED)
556  //SHA3-256 hash algorithm identifier?
557  if(OID_COMP(oid, oidLen, SHA3_256_OID) == 0)
558  {
559  //RSA-PSS with SHA3-256 signature algorithm
560  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
561  *hashAlgo = SHA3_256_HASH_ALGO;
562  }
563  else
564 #endif
565 #if (X509_SHA3_384_SUPPORT == ENABLED && SHA3_384_SUPPORT == ENABLED)
566  //SHA3-384 hash algorithm identifier?
567  if(OID_COMP(oid, oidLen, SHA3_384_OID) == 0)
568  {
569  //RSA-PSS with SHA3-384 signature algorithm
570  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
571  *hashAlgo = SHA3_384_HASH_ALGO;
572  }
573  else
574 #endif
575 #if (X509_SHA3_512_SUPPORT == ENABLED && SHA3_512_SUPPORT == ENABLED)
576  //SHA3-512 hash algorithm identifier?
577  if(OID_COMP(oid, oidLen, SHA3_512_OID) == 0)
578  {
579  //RSA-PSS with SHA3-512 signature algorithm
580  *signAlgo = X509_SIGN_ALGO_RSA_PSS;
581  *hashAlgo = SHA3_512_HASH_ALGO;
582  }
583  else
584 #endif
585  //Unknown hash algorithm identifier?
586  {
587  //The specified signature algorithm is not supported
589  }
590  }
591  else
592 #endif
593 #if (X509_DSA_SUPPORT == ENABLED && DSA_SUPPORT == ENABLED)
594 #if (X509_SHA1_SUPPORT == ENABLED && SHA1_SUPPORT == ENABLED)
595  //DSA with SHA-1 signature algorithm?
597  {
598  *signAlgo = X509_SIGN_ALGO_DSA;
599  *hashAlgo = SHA1_HASH_ALGO;
600  }
601  else
602 #endif
603 #if (X509_SHA224_SUPPORT == ENABLED && SHA224_SUPPORT == ENABLED)
604  //DSA with SHA-224 signature algorithm?
606  {
607  *signAlgo = X509_SIGN_ALGO_DSA;
608  *hashAlgo = SHA224_HASH_ALGO;
609  }
610  else
611 #endif
612 #if (X509_SHA256_SUPPORT == ENABLED && SHA256_SUPPORT == ENABLED)
613  //DSA with SHA-256 signature algorithm?
615  {
616  *signAlgo = X509_SIGN_ALGO_DSA;
617  *hashAlgo = SHA256_HASH_ALGO;
618  }
619  else
620 #endif
621 #if (X509_SHA384_SUPPORT == ENABLED && SHA384_SUPPORT == ENABLED)
622  //DSA with SHA-384 signature algorithm?
624  {
625  *signAlgo = X509_SIGN_ALGO_DSA;
626  *hashAlgo = SHA384_HASH_ALGO;
627  }
628  else
629 #endif
630 #if (X509_SHA512_SUPPORT == ENABLED && SHA512_SUPPORT == ENABLED)
631  //DSA with SHA-512 signature algorithm?
633  {
634  *signAlgo = X509_SIGN_ALGO_DSA;
635  *hashAlgo = SHA512_HASH_ALGO;
636  }
637  else
638 #endif
639 #if (X509_SHA3_224_SUPPORT == ENABLED && SHA3_224_SUPPORT == ENABLED)
640  //DSA with SHA3-224 signature algorithm?
642  {
643  *signAlgo = X509_SIGN_ALGO_DSA;
644  *hashAlgo = SHA3_224_HASH_ALGO;
645  }
646  else
647 #endif
648 #if (X509_SHA3_256_SUPPORT == ENABLED && SHA3_256_SUPPORT == ENABLED)
649  //DSA with SHA3-256 signature algorithm?
651  {
652  *signAlgo = X509_SIGN_ALGO_DSA;
653  *hashAlgo = SHA3_256_HASH_ALGO;
654  }
655  else
656 #endif
657 #if (X509_SHA3_384_SUPPORT == ENABLED && SHA3_384_SUPPORT == ENABLED)
658  //DSA with SHA3-384 signature algorithm?
660  {
661  *signAlgo = X509_SIGN_ALGO_DSA;
662  *hashAlgo = SHA3_384_HASH_ALGO;
663  }
664  else
665 #endif
666 #if (X509_SHA3_512_SUPPORT == ENABLED && SHA3_512_SUPPORT == ENABLED)
667  //DSA with SHA3-512 signature algorithm?
669  {
670  *signAlgo = X509_SIGN_ALGO_DSA;
671  *hashAlgo = SHA3_512_HASH_ALGO;
672  }
673  else
674 #endif
675 #endif
676 #if (X509_ECDSA_SUPPORT == ENABLED && ECDSA_SUPPORT == ENABLED)
677 #if (X509_SHA1_SUPPORT == ENABLED && SHA1_SUPPORT == ENABLED)
678  //ECDSA with SHA-1 signature algorithm?
680  {
681  *signAlgo = X509_SIGN_ALGO_ECDSA;
682  *hashAlgo = SHA1_HASH_ALGO;
683  }
684  else
685 #endif
686 #if (X509_SHA224_SUPPORT == ENABLED && SHA224_SUPPORT == ENABLED)
687  //ECDSA with SHA-224 signature algorithm?
689  {
690  *signAlgo = X509_SIGN_ALGO_ECDSA;
691  *hashAlgo = SHA224_HASH_ALGO;
692  }
693  else
694 #endif
695 #if (X509_SHA256_SUPPORT == ENABLED && SHA256_SUPPORT == ENABLED)
696  //ECDSA with SHA-256 signature algorithm?
698  {
699  *signAlgo = X509_SIGN_ALGO_ECDSA;
700  *hashAlgo = SHA256_HASH_ALGO;
701  }
702  else
703 #endif
704 #if (X509_SHA384_SUPPORT == ENABLED && SHA384_SUPPORT == ENABLED)
705  //ECDSA with SHA-384 signature algorithm?
707  {
708  *signAlgo = X509_SIGN_ALGO_ECDSA;
709  *hashAlgo = SHA384_HASH_ALGO;
710  }
711  else
712 #endif
713 #if (X509_SHA512_SUPPORT == ENABLED && SHA512_SUPPORT == ENABLED)
714  //ECDSA with SHA-512 signature algorithm?
716  {
717  *signAlgo = X509_SIGN_ALGO_ECDSA;
718  *hashAlgo = SHA512_HASH_ALGO;
719  }
720  else
721 #endif
722 #if (X509_SHA3_224_SUPPORT == ENABLED && SHA3_224_SUPPORT == ENABLED)
723  //ECDSA with SHA3-224 signature algorithm?
725  {
726  *signAlgo = X509_SIGN_ALGO_ECDSA;
727  *hashAlgo = SHA3_224_HASH_ALGO;
728  }
729  else
730 #endif
731 #if (X509_SHA3_256_SUPPORT == ENABLED && SHA3_256_SUPPORT == ENABLED)
732  //ECDSA with SHA3-256 signature algorithm?
734  {
735  *signAlgo = X509_SIGN_ALGO_ECDSA;
736  *hashAlgo = SHA3_256_HASH_ALGO;
737  }
738  else
739 #endif
740 #if (X509_SHA3_384_SUPPORT == ENABLED && SHA3_384_SUPPORT == ENABLED)
741  //ECDSA with SHA3-384 signature algorithm?
743  {
744  *signAlgo = X509_SIGN_ALGO_ECDSA;
745  *hashAlgo = SHA3_384_HASH_ALGO;
746  }
747  else
748 #endif
749 #if (X509_SHA3_512_SUPPORT == ENABLED && SHA3_512_SUPPORT == ENABLED)
750  //ECDSA with SHA3-512 signature algorithm?
752  {
753  *signAlgo = X509_SIGN_ALGO_ECDSA;
754  *hashAlgo = SHA3_512_HASH_ALGO;
755  }
756  else
757 #endif
758 #endif
759 #if (X509_SM2_SUPPORT == ENABLED && SM2_SUPPORT == ENABLED && \
760  X509_SM3_SUPPORT == ENABLED && SM3_SUPPORT == ENABLED)
761  //SM2 with SM3 signature algorithm?
762  if(OID_COMP(oid, oidLen, SM2_WITH_SM3_OID) == 0)
763  {
764  *signAlgo = X509_SIGN_ALGO_SM2;
765  *hashAlgo = SM3_HASH_ALGO;
766  }
767  else
768 #endif
769 #if (X509_ED25519_SUPPORT == ENABLED && ED25519_SUPPORT == ENABLED)
770  //Ed25519 signature algorithm?
771  if(OID_COMP(oid, oidLen, ED25519_OID) == 0)
772  {
773  *signAlgo = X509_SIGN_ALGO_ED25519;
774  *hashAlgo = NULL;
775  }
776  else
777 #endif
778 #if (X509_ED448_SUPPORT == ENABLED && ED448_SUPPORT == ENABLED)
779  //Ed448 signature algorithm?
780  if(OID_COMP(oid, oidLen, ED448_OID) == 0)
781  {
782  *signAlgo = X509_SIGN_ALGO_ED448;
783  *hashAlgo = NULL;
784  }
785  else
786 #endif
787  //Unknown signature algorithm?
788  {
790  }
791 
792  //Return status code
793  return error;
794 }
795 
796 
797 /**
798  * @brief Get the public key type that matches the specified OID
799  * @param[in] oid Object identifier
800  * @param[in] length OID length
801  * @return Public key type
802  **/
803 
805 {
806  X509KeyType keyType;
807 
808  //Invalid parameters?
809  if(oid == NULL || length == 0)
810  {
811  keyType = X509_KEY_TYPE_UNKNOWN;
812  }
813 #if (RSA_SUPPORT == ENABLED)
814  //RSA algorithm identifier?
815  else if(OID_COMP(oid, length, RSA_ENCRYPTION_OID) == 0)
816  {
817  keyType = X509_KEY_TYPE_RSA;
818  }
819  //RSA-PSS algorithm identifier?
820  else if(OID_COMP(oid, length, RSASSA_PSS_OID) == 0)
821  {
822  keyType = X509_KEY_TYPE_RSA_PSS;
823  }
824 #endif
825 #if (DSA_SUPPORT == ENABLED)
826  //DSA algorithm identifier?
827  else if(OID_COMP(oid, length, DSA_OID) == 0)
828  {
829  keyType = X509_KEY_TYPE_DSA;
830  }
831 #endif
832 #if (EC_SUPPORT == ENABLED)
833  //EC public key identifier?
834  else if(OID_COMP(oid, length, EC_PUBLIC_KEY_OID) == 0)
835  {
836  keyType = X509_KEY_TYPE_EC;
837  }
838 #endif
839 #if (X25519_SUPPORT == ENABLED)
840  //X25519 algorithm identifier?
841  else if(OID_COMP(oid, length, X25519_OID) == 0)
842  {
843  keyType = X509_KEY_TYPE_X25519;
844  }
845 #endif
846 #if (ED25519_SUPPORT == ENABLED)
847  //Ed25519 algorithm identifier?
848  else if(OID_COMP(oid, length, ED25519_OID) == 0)
849  {
850  keyType = X509_KEY_TYPE_ED25519;
851  }
852 #endif
853 #if (X448_SUPPORT == ENABLED)
854  //X448 algorithm identifier?
855  else if(OID_COMP(oid, length, X448_OID) == 0)
856  {
857  keyType = X509_KEY_TYPE_X448;
858  }
859 #endif
860 #if (ED448_SUPPORT == ENABLED)
861  //Ed448 algorithm identifier?
862  else if(OID_COMP(oid, length, ED448_OID) == 0)
863  {
864  keyType = X509_KEY_TYPE_ED448;
865  }
866 #endif
867  //Unknown algorithm identifier?
868  else
869  {
870  keyType = X509_KEY_TYPE_UNKNOWN;
871  }
872 
873  //Return public key type
874  return keyType;
875 }
876 
877 
878 /**
879  * @brief Get the elliptic curve that matches the specified OID
880  * @param[in] oid Object identifier
881  * @param[in] length Length of the OID, in bytes
882  * @return Elliptic curve parameters
883  **/
884 
885 const EcCurve *x509GetCurve(const uint8_t *oid, size_t length)
886 {
887  const EcCurve *curve;
888 
889  //Default elliptic curve parameters
890  curve = NULL;
891 
892 #if (X509_ECDSA_SUPPORT == ENABLED && ECDSA_SUPPORT == ENABLED)
893  //Invalid parameters?
894  if(oid == NULL || length == 0)
895  {
896  curve = NULL;
897  }
898 #if (X509_SECP112R1_SUPPORT == ENABLED)
899  //secp112r1 elliptic curve?
900  else if(OID_COMP(oid, length, SECP112R1_OID) == 0)
901  {
902  curve = ecGetCurve(oid, length);
903  }
904 #endif
905 #if (X509_SECP112R2_SUPPORT == ENABLED)
906  //secp112r2 elliptic curve?
907  else if(OID_COMP(oid, length, SECP112R2_OID) == 0)
908  {
909  curve = ecGetCurve(oid, length);
910  }
911 #endif
912 #if (X509_SECP128R1_SUPPORT == ENABLED)
913  //secp128r1 elliptic curve?
914  else if(OID_COMP(oid, length, SECP128R1_OID) == 0)
915  {
916  curve = ecGetCurve(oid, length);
917  }
918 #endif
919 #if (X509_SECP128R2_SUPPORT == ENABLED)
920  //secp128r2 elliptic curve?
921  else if(OID_COMP(oid, length, SECP128R2_OID) == 0)
922  {
923  curve = ecGetCurve(oid, length);
924  }
925 #endif
926 #if (X509_SECP160K1_SUPPORT == ENABLED)
927  //secp160k1 elliptic curve?
928  else if(OID_COMP(oid, length, SECP160K1_OID) == 0)
929  {
930  curve = ecGetCurve(oid, length);
931  }
932 #endif
933 #if (X509_SECP160R1_SUPPORT == ENABLED)
934  //secp160r1 elliptic curve?
935  else if(OID_COMP(oid, length, SECP160R1_OID) == 0)
936  {
937  curve = ecGetCurve(oid, length);
938  }
939 #endif
940 #if (X509_SECP160R2_SUPPORT == ENABLED)
941  //secp160r2 elliptic curve?
942  else if(OID_COMP(oid, length, SECP160R2_OID) == 0)
943  {
944  curve = ecGetCurve(oid, length);
945  }
946 #endif
947 #if (X509_SECP192K1_SUPPORT == ENABLED)
948  //secp192k1 elliptic curve?
949  else if(OID_COMP(oid, length, SECP192K1_OID) == 0)
950  {
951  curve = ecGetCurve(oid, length);
952  }
953 #endif
954 #if (X509_SECP192R1_SUPPORT == ENABLED)
955  //secp192r1 elliptic curve?
956  else if(OID_COMP(oid, length, SECP192R1_OID) == 0)
957  {
958  curve = ecGetCurve(oid, length);
959  }
960 #endif
961 #if (X509_SECP224K1_SUPPORT == ENABLED)
962  //secp224k1 elliptic curve?
963  else if(OID_COMP(oid, length, SECP224K1_OID) == 0)
964  {
965  curve = ecGetCurve(oid, length);
966  }
967 #endif
968 #if (X509_SECP224R1_SUPPORT == ENABLED)
969  //secp224r1 elliptic curve?
970  else if(OID_COMP(oid, length, SECP224R1_OID) == 0)
971  {
972  curve = ecGetCurve(oid, length);
973  }
974 #endif
975 #if (X509_SECP256K1_SUPPORT == ENABLED)
976  //secp256k1 elliptic curve?
977  else if(OID_COMP(oid, length, SECP256K1_OID) == 0)
978  {
979  curve = ecGetCurve(oid, length);
980  }
981 #endif
982 #if (X509_SECP256R1_SUPPORT == ENABLED)
983  //secp256r1 elliptic curve?
984  else if(OID_COMP(oid, length, SECP256R1_OID) == 0)
985  {
986  curve = ecGetCurve(oid, length);
987  }
988 #endif
989 #if (X509_SECP384R1_SUPPORT == ENABLED)
990  //secp384r1 elliptic curve?
991  else if(OID_COMP(oid, length, SECP384R1_OID) == 0)
992  {
993  curve = ecGetCurve(oid, length);
994  }
995 #endif
996 #if (X509_SECP521R1_SUPPORT == ENABLED)
997  //secp521r1 elliptic curve?
998  else if(OID_COMP(oid, length, SECP521R1_OID) == 0)
999  {
1000  curve = ecGetCurve(oid, length);
1001  }
1002 #endif
1003 #if (X509_BRAINPOOLP160R1_SUPPORT == ENABLED)
1004  //brainpoolP160r1 elliptic curve?
1005  else if(OID_COMP(oid, length, BRAINPOOLP160R1_OID) == 0)
1006  {
1007  curve = ecGetCurve(oid, length);
1008  }
1009 #endif
1010 #if (X509_BRAINPOOLP160T1_SUPPORT == ENABLED)
1011  //brainpoolP160t1 elliptic curve?
1012  else if(OID_COMP(oid, length, BRAINPOOLP160T1_OID) == 0)
1013  {
1014  curve = ecGetCurve(oid, length);
1015  }
1016 #endif
1017 #if (X509_BRAINPOOLP192R1_SUPPORT == ENABLED)
1018  //brainpoolP192r1 elliptic curve?
1019  else if(OID_COMP(oid, length, BRAINPOOLP192R1_OID) == 0)
1020  {
1021  curve = ecGetCurve(oid, length);
1022  }
1023 #endif
1024 #if (X509_BRAINPOOLP192T1_SUPPORT == ENABLED)
1025  //brainpoolP192t1 elliptic curve?
1026  else if(OID_COMP(oid, length, BRAINPOOLP192T1_OID) == 0)
1027  {
1028  curve = ecGetCurve(oid, length);
1029  }
1030 #endif
1031 #if (X509_BRAINPOOLP224R1_SUPPORT == ENABLED)
1032  //brainpoolP224r1 elliptic curve?
1033  else if(OID_COMP(oid, length, BRAINPOOLP224R1_OID) == 0)
1034  {
1035  curve = ecGetCurve(oid, length);
1036  }
1037 #endif
1038 #if (X509_BRAINPOOLP224T1_SUPPORT == ENABLED)
1039  //brainpoolP224t1 elliptic curve?
1040  else if(OID_COMP(oid, length, BRAINPOOLP224T1_OID) == 0)
1041  {
1042  curve = ecGetCurve(oid, length);
1043  }
1044 #endif
1045 #if (X509_BRAINPOOLP256R1_SUPPORT == ENABLED)
1046  //brainpoolP256r1 elliptic curve?
1047  else if(OID_COMP(oid, length, BRAINPOOLP256R1_OID) == 0)
1048  {
1049  curve = ecGetCurve(oid, length);
1050  }
1051 #endif
1052 #if (X509_BRAINPOOLP256T1_SUPPORT == ENABLED)
1053  //brainpoolP256t1 elliptic curve?
1054  else if(OID_COMP(oid, length, BRAINPOOLP256T1_OID) == 0)
1055  {
1056  curve = ecGetCurve(oid, length);
1057  }
1058 #endif
1059 #if (X509_BRAINPOOLP320R1_SUPPORT == ENABLED)
1060  //brainpoolP320r1 elliptic curve?
1061  else if(OID_COMP(oid, length, BRAINPOOLP320R1_OID) == 0)
1062  {
1063  curve = ecGetCurve(oid, length);
1064  }
1065 #endif
1066 #if (X509_BRAINPOOLP320T1_SUPPORT == ENABLED)
1067  //brainpoolP320t1 elliptic curve?
1068  else if(OID_COMP(oid, length, BRAINPOOLP320T1_OID) == 0)
1069  {
1070  curve = ecGetCurve(oid, length);
1071  }
1072 #endif
1073 #if (X509_BRAINPOOLP384R1_SUPPORT == ENABLED)
1074  //brainpoolP384r1 elliptic curve?
1075  else if(OID_COMP(oid, length, BRAINPOOLP384R1_OID) == 0)
1076  {
1077  curve = ecGetCurve(oid, length);
1078  }
1079 #endif
1080 #if (X509_BRAINPOOLP384T1_SUPPORT == ENABLED)
1081  //brainpoolP384t1 elliptic curve?
1082  else if(OID_COMP(oid, length, BRAINPOOLP384T1_OID) == 0)
1083  {
1084  curve = ecGetCurve(oid, length);
1085  }
1086 #endif
1087 #if (X509_BRAINPOOLP512R1_SUPPORT == ENABLED)
1088  //brainpoolP512r1 elliptic curve?
1089  else if(OID_COMP(oid, length, BRAINPOOLP512R1_OID) == 0)
1090  {
1091  curve = ecGetCurve(oid, length);
1092  }
1093 #endif
1094 #if (X509_BRAINPOOLP512T1_SUPPORT == ENABLED)
1095  //brainpoolP512t1 elliptic curve?
1096  else if(OID_COMP(oid, length, BRAINPOOLP512T1_OID) == 0)
1097  {
1098  curve = ecGetCurve(oid, length);
1099  }
1100 #endif
1101 #if (X509_FRP256V1_SUPPORT == ENABLED)
1102  //FRP256v1 elliptic curve?
1103  else if(OID_COMP(oid, length, FRP256V1_OID) == 0)
1104  {
1105  curve = ecGetCurve(oid, length);
1106  }
1107 #endif
1108 #if (X509_SM2_SUPPORT == ENABLED)
1109  //SM2 elliptic curve?
1110  else if(OID_COMP(oid, length, SM2_OID) == 0)
1111  {
1112  curve = ecGetCurve(oid, length);
1113  }
1114 #endif
1115 #if (X509_ED25519_SUPPORT == ENABLED)
1116  //Ed25519 elliptic curve?
1117  else if(OID_COMP(oid, length, ED25519_OID) == 0)
1118  {
1119  curve = ecGetCurve(oid, length);
1120  }
1121 #endif
1122 #if (X509_ED448_SUPPORT == ENABLED)
1123  //Ed448 elliptic curve?
1124  else if(OID_COMP(oid, length, ED448_OID) == 0)
1125  {
1126  curve = ecGetCurve(oid, length);
1127  }
1128 #endif
1129  //Unknown elliptic curve?
1130  else
1131  {
1132  curve = NULL;
1133  }
1134 #endif
1135 
1136  //Return the elliptic curve parameters, if any
1137  return curve;
1138 }
1139 
1140 #endif
const uint8_t X509_EMAIL_ADDRESS_OID[9]
Definition: x509_common.c:162
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:354
#define SHA3_512_HASH_ALGO
Definition: sha3_512.h:45
X.509 common definitions.
@ X509_KEY_TYPE_RSA
Definition: x509_common.h:635
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:154
#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:175
bool_t x509IsHashAlgoSupported(X509HashAlgo hashAlgo)
Check whether a given hash algorithm is supported.
Definition: x509_common.c:250
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:642
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:1076
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:61
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:57
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 X509_CHALLENGE_PASSWORD_OID[9]
Definition: x509_common.c:164
const uint8_t X509_EXTENSION_REQUEST_OID[9]
Definition: x509_common.c:166
const uint8_t BRAINPOOLP384R1_OID[9]
Definition: ec_curves.c:96
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:49
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
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:638
#define FALSE
Definition: os_port.h:46
X509SignatureAlgo
Signature algorithms.
Definition: x509_common.h:652
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 EcCurve * x509GetCurve(const uint8_t *oid, size_t length)
Get the elliptic curve that matches the specified OID.
Definition: x509_common.c:885
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:657
@ X509_HASH_ALGO_NONE
Definition: x509_common.h:670
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:51
const uint8_t X509_AUTHORITY_KEY_ID_OID[3]
Definition: x509_common.c:111
@ X509_HASH_ALGO_SHA1
Definition: x509_common.h:672
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:377
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:677
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:636
const uint8_t X509_AD_OCSP[8]
Definition: x509_common.c:159
const uint8_t X509_KP_IPSEC_IKE_OID[8]
Definition: x509_common.c:148
@ X509_HASH_ALGO_SHA224
Definition: x509_common.h:673
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:1089
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:55
X509HashAlgo
Hash algorithms.
Definition: x509_common.h:669
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:45
const uint8_t ECDSA_WITH_SHA224_OID[8]
Definition: ecdsa.c:47
@ X509_SIGN_ALGO_RSA
Definition: x509_common.h:654
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 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:53
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:680
#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:671
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:655
@ X509_KEY_TYPE_ED448
Definition: x509_common.h:643
@ X509_HASH_ALGO_SHA3_256
Definition: x509_common.h:678
@ X509_HASH_ALGO_SHA3_384
Definition: x509_common.h:679
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:157
const uint8_t ECDSA_WITH_SHA3_384_OID[9]
Definition: ecdsa.c:59
@ X509_HASH_ALGO_SHA512
Definition: x509_common.h:676
const uint8_t X509_NS_CERT_TYPE_OID[9]
Definition: x509_common.c:125
@ X509_KEY_TYPE_DSA
Definition: x509_common.h:637
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:675
@ X509_HASH_ALGO_SHA256
Definition: x509_common.h:674
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_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:702
Common interface for hash algorithms.
Definition: crypto.h:1082
@ X509_KEY_TYPE_UNKNOWN
Definition: x509_common.h:634
#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
@ ERROR_UNSUPPORTED_SIGNATURE_ALGO
Definition: error.h:132
@ X509_SIGN_ALGO_SM2
Definition: x509_common.h:658
@ X509_SIGN_ALGO_ED25519
Definition: x509_common.h:659
@ X509_KEY_TYPE_ED25519
Definition: x509_common.h:641
X509KeyType
Public Key types.
Definition: x509_common.h:633
@ X509_SIGN_ALGO_NONE
Definition: x509_common.h:653
X509KeyType x509GetPublicKeyType(const uint8_t *oid, size_t length)
Get the public key type that matches the specified OID.
Definition: x509_common.c:804
const uint8_t SHA384_OID[9]
Definition: sha384.c:47
@ X509_HASH_ALGO_SM3
Definition: x509_common.h:681
X509RsaPssParameters rsaPssParams
Definition: x509_common.h:1091
const uint8_t X509_STATE_OR_PROVINCE_NAME_OID[]
Definition: x509_common.c:56
const uint8_t SHA1_WITH_RSA_ENCRYPTION_OID[9]
Definition: rsa.c:61
#define SHA3_384_HASH_ALGO
Definition: sha3_384.h:45
Signature algorithm identifier.
Definition: x509_common.h:1088
@ 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:640
ASN.1 (Abstract Syntax Notation One)
@ X509_SIGN_ALGO_DSA
Definition: x509_common.h:656
@ X509_SIGN_ALGO_ED448
Definition: x509_common.h:660
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