4 * \brief Object Identifier (OID) database
6 * Copyright The Mbed TLS Contributors
7 * SPDX-License-Identifier: Apache-2.0
9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
10 * not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
24 #if defined(MBEDTLS_OID_C)
26 #include "mbedtls/oid.h"
27 #include "mbedtls/rsa.h"
28 #include "mbedtls/error.h"
33 #if defined(MBEDTLS_PLATFORM_C)
34 #include "mbedtls/platform.h"
36 #define mbedtls_snprintf snprintf
40 * Macro to automatically add the size of #define'd OIDs
42 #define ADD_LEN(s) s, MBEDTLS_OID_SIZE(s)
45 * Macro to generate an internal function for oid_XXX_from_asn1() (used by
46 * the other functions)
48 #define FN_OID_TYPED_FROM_ASN1( TYPE_T, NAME, LIST ) \
49 static const TYPE_T * oid_ ## NAME ## _from_asn1( \
50 const mbedtls_asn1_buf *oid ) \
52 const TYPE_T *p = (LIST); \
53 const mbedtls_oid_descriptor_t *cur = \
54 (const mbedtls_oid_descriptor_t *) p; \
55 if( p == NULL || oid == NULL ) return( NULL ); \
56 while( cur->asn1 != NULL ) { \
57 if( cur->asn1_len == oid->len && \
58 memcmp( cur->asn1, oid->p, oid->len ) == 0 ) { \
62 cur = (const mbedtls_oid_descriptor_t *) p; \
68 * Macro to generate a function for retrieving a single attribute from the
69 * descriptor of an mbedtls_oid_descriptor_t wrapper.
71 #define FN_OID_GET_DESCRIPTOR_ATTR1(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1) \
72 int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \
74 const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \
75 if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \
76 *ATTR1 = data->descriptor.ATTR1; \
81 * Macro to generate a function for retrieving a single attribute from an
82 * mbedtls_oid_descriptor_t wrapper.
84 #define FN_OID_GET_ATTR1(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1) \
85 int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \
87 const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \
88 if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \
89 *ATTR1 = data->ATTR1; \
94 * Macro to generate a function for retrieving two attributes from an
95 * mbedtls_oid_descriptor_t wrapper.
97 #define FN_OID_GET_ATTR2(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1, \
99 int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1, \
100 ATTR2_TYPE * ATTR2 ) \
102 const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \
103 if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \
104 *(ATTR1) = data->ATTR1; \
105 *(ATTR2) = data->ATTR2; \
110 * Macro to generate a function for retrieving the OID based on a single
111 * attribute from a mbedtls_oid_descriptor_t wrapper.
113 #define FN_OID_GET_OID_BY_ATTR1(FN_NAME, TYPE_T, LIST, ATTR1_TYPE, ATTR1) \
114 int FN_NAME( ATTR1_TYPE ATTR1, const char **oid, size_t *olen ) \
116 const TYPE_T *cur = (LIST); \
117 while( cur->descriptor.asn1 != NULL ) { \
118 if( cur->ATTR1 == (ATTR1) ) { \
119 *oid = cur->descriptor.asn1; \
120 *olen = cur->descriptor.asn1_len; \
125 return( MBEDTLS_ERR_OID_NOT_FOUND ); \
129 * Macro to generate a function for retrieving the OID based on two
130 * attributes from a mbedtls_oid_descriptor_t wrapper.
132 #define FN_OID_GET_OID_BY_ATTR2(FN_NAME, TYPE_T, LIST, ATTR1_TYPE, ATTR1, \
134 int FN_NAME( ATTR1_TYPE ATTR1, ATTR2_TYPE ATTR2, const char **oid , \
137 const TYPE_T *cur = (LIST); \
138 while( cur->descriptor.asn1 != NULL ) { \
139 if( cur->ATTR1 == (ATTR1) && cur->ATTR2 == (ATTR2) ) { \
140 *oid = cur->descriptor.asn1; \
141 *olen = cur->descriptor.asn1_len; \
146 return( MBEDTLS_ERR_OID_NOT_FOUND ); \
150 * For X520 attribute types
153 mbedtls_oid_descriptor_t descriptor
;
154 const char *short_name
;
157 static const oid_x520_attr_t oid_x520_attr_type
[] = {
159 { ADD_LEN(MBEDTLS_OID_AT_CN
), "id-at-commonName", "Common Name" },
163 { ADD_LEN(MBEDTLS_OID_AT_COUNTRY
), "id-at-countryName", "Country" },
167 { ADD_LEN(MBEDTLS_OID_AT_LOCALITY
), "id-at-locality", "Locality" },
171 { ADD_LEN(MBEDTLS_OID_AT_STATE
), "id-at-state", "State" },
175 { ADD_LEN(MBEDTLS_OID_AT_ORGANIZATION
), "id-at-organizationName", "Organization" },
179 { ADD_LEN(MBEDTLS_OID_AT_ORG_UNIT
), "id-at-organizationalUnitName", "Org Unit" },
183 { ADD_LEN(MBEDTLS_OID_PKCS9_EMAIL
), "emailAddress", "E-mail address" },
187 { ADD_LEN(MBEDTLS_OID_AT_SERIAL_NUMBER
), "id-at-serialNumber", "Serial number" },
191 { ADD_LEN(MBEDTLS_OID_AT_POSTAL_ADDRESS
), "id-at-postalAddress", "Postal address" },
195 { ADD_LEN(MBEDTLS_OID_AT_POSTAL_CODE
), "id-at-postalCode", "Postal code" },
199 { ADD_LEN(MBEDTLS_OID_AT_SUR_NAME
), "id-at-surName", "Surname" },
203 { ADD_LEN(MBEDTLS_OID_AT_GIVEN_NAME
), "id-at-givenName", "Given name" },
207 { ADD_LEN(MBEDTLS_OID_AT_INITIALS
), "id-at-initials", "Initials" },
211 { ADD_LEN(MBEDTLS_OID_AT_GENERATION_QUALIFIER
), "id-at-generationQualifier", "Generation qualifier" },
212 "generationQualifier",
215 { ADD_LEN(MBEDTLS_OID_AT_TITLE
), "id-at-title", "Title" },
219 { ADD_LEN(MBEDTLS_OID_AT_DN_QUALIFIER
), "id-at-dnQualifier", "Distinguished Name qualifier" },
223 { ADD_LEN(MBEDTLS_OID_AT_PSEUDONYM
), "id-at-pseudonym", "Pseudonym" },
227 { ADD_LEN(MBEDTLS_OID_DOMAIN_COMPONENT
), "id-domainComponent", "Domain component" },
231 { ADD_LEN(MBEDTLS_OID_AT_UNIQUE_IDENTIFIER
), "id-at-uniqueIdentifier", "Unique Identifier" },
235 { NULL
, 0, NULL
, NULL
},
240 FN_OID_TYPED_FROM_ASN1(oid_x520_attr_t
, x520_attr
, oid_x520_attr_type
)
241 FN_OID_GET_ATTR1(mbedtls_oid_get_attr_short_name
, oid_x520_attr_t
, x520_attr
, const char *, short_name
)
244 * For X509 extensions
247 mbedtls_oid_descriptor_t descriptor
;
251 static const oid_x509_ext_t oid_x509_ext
[] = {
253 { ADD_LEN(MBEDTLS_OID_BASIC_CONSTRAINTS
), "id-ce-basicConstraints", "Basic Constraints" },
254 MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS
,
257 { ADD_LEN(MBEDTLS_OID_KEY_USAGE
), "id-ce-keyUsage", "Key Usage" },
258 MBEDTLS_OID_X509_EXT_KEY_USAGE
,
261 { ADD_LEN(MBEDTLS_OID_EXTENDED_KEY_USAGE
), "id-ce-extKeyUsage", "Extended Key Usage" },
262 MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE
,
265 { ADD_LEN(MBEDTLS_OID_SUBJECT_ALT_NAME
), "id-ce-subjectAltName", "Subject Alt Name" },
266 MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME
,
269 { ADD_LEN(MBEDTLS_OID_NS_CERT_TYPE
), "id-netscape-certtype", "Netscape Certificate Type" },
270 MBEDTLS_OID_X509_EXT_NS_CERT_TYPE
,
273 { ADD_LEN(MBEDTLS_OID_CERTIFICATE_POLICIES
), "id-ce-certificatePolicies", "Certificate Policies" },
274 MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES
,
277 { NULL
, 0, NULL
, NULL
},
282 FN_OID_TYPED_FROM_ASN1(oid_x509_ext_t
, x509_ext
, oid_x509_ext
)
283 FN_OID_GET_ATTR1(mbedtls_oid_get_x509_ext_type
, oid_x509_ext_t
, x509_ext
, int, ext_type
)
285 static const mbedtls_oid_descriptor_t oid_ext_key_usage
[] = {
286 { ADD_LEN(MBEDTLS_OID_SERVER_AUTH
), "id-kp-serverAuth", "TLS Web Server Authentication" },
287 { ADD_LEN(MBEDTLS_OID_CLIENT_AUTH
), "id-kp-clientAuth", "TLS Web Client Authentication" },
288 { ADD_LEN(MBEDTLS_OID_CODE_SIGNING
), "id-kp-codeSigning", "Code Signing" },
289 { ADD_LEN(MBEDTLS_OID_EMAIL_PROTECTION
), "id-kp-emailProtection", "E-mail Protection" },
290 { ADD_LEN(MBEDTLS_OID_TIME_STAMPING
), "id-kp-timeStamping", "Time Stamping" },
291 { ADD_LEN(MBEDTLS_OID_OCSP_SIGNING
), "id-kp-OCSPSigning", "OCSP Signing" },
292 { ADD_LEN(MBEDTLS_OID_WISUN_FAN
), "id-kp-wisun-fan-device", "Wi-SUN Alliance Field Area Network (FAN)" },
293 { NULL
, 0, NULL
, NULL
},
296 FN_OID_TYPED_FROM_ASN1(mbedtls_oid_descriptor_t
, ext_key_usage
, oid_ext_key_usage
)
297 FN_OID_GET_ATTR1(mbedtls_oid_get_extended_key_usage
, mbedtls_oid_descriptor_t
, ext_key_usage
, const char *, description
)
299 static const mbedtls_oid_descriptor_t oid_certificate_policies
[] = {
300 { ADD_LEN(MBEDTLS_OID_ANY_POLICY
), "anyPolicy", "Any Policy" },
301 { NULL
, 0, NULL
, NULL
},
304 FN_OID_TYPED_FROM_ASN1(mbedtls_oid_descriptor_t
, certificate_policies
, oid_certificate_policies
)
305 FN_OID_GET_ATTR1(mbedtls_oid_get_certificate_policies
, mbedtls_oid_descriptor_t
, certificate_policies
, const char *, description
)
307 #if defined(MBEDTLS_MD_C)
309 * For SignatureAlgorithmIdentifier
312 mbedtls_oid_descriptor_t descriptor
;
313 mbedtls_md_type_t md_alg
;
314 mbedtls_pk_type_t pk_alg
;
317 static const oid_sig_alg_t oid_sig_alg
[] = {
318 #if defined(MBEDTLS_RSA_C)
319 #if defined(MBEDTLS_MD2_C)
321 { ADD_LEN(MBEDTLS_OID_PKCS1_MD2
), "md2WithRSAEncryption", "RSA with MD2" },
322 MBEDTLS_MD_MD2
, MBEDTLS_PK_RSA
,
324 #endif /* MBEDTLS_MD2_C */
325 #if defined(MBEDTLS_MD4_C)
327 { ADD_LEN(MBEDTLS_OID_PKCS1_MD4
), "md4WithRSAEncryption", "RSA with MD4" },
328 MBEDTLS_MD_MD4
, MBEDTLS_PK_RSA
,
330 #endif /* MBEDTLS_MD4_C */
331 #if defined(MBEDTLS_MD5_C)
333 { ADD_LEN(MBEDTLS_OID_PKCS1_MD5
), "md5WithRSAEncryption", "RSA with MD5" },
334 MBEDTLS_MD_MD5
, MBEDTLS_PK_RSA
,
336 #endif /* MBEDTLS_MD5_C */
337 #if defined(MBEDTLS_SHA1_C)
339 { ADD_LEN(MBEDTLS_OID_PKCS1_SHA1
), "sha-1WithRSAEncryption", "RSA with SHA1" },
340 MBEDTLS_MD_SHA1
, MBEDTLS_PK_RSA
,
342 #endif /* MBEDTLS_SHA1_C */
343 #if defined(MBEDTLS_SHA256_C)
345 { ADD_LEN(MBEDTLS_OID_PKCS1_SHA224
), "sha224WithRSAEncryption", "RSA with SHA-224" },
346 MBEDTLS_MD_SHA224
, MBEDTLS_PK_RSA
,
349 { ADD_LEN(MBEDTLS_OID_PKCS1_SHA256
), "sha256WithRSAEncryption", "RSA with SHA-256" },
350 MBEDTLS_MD_SHA256
, MBEDTLS_PK_RSA
,
352 #endif /* MBEDTLS_SHA256_C */
353 #if defined(MBEDTLS_SHA512_C)
355 { ADD_LEN(MBEDTLS_OID_PKCS1_SHA384
), "sha384WithRSAEncryption", "RSA with SHA-384" },
356 MBEDTLS_MD_SHA384
, MBEDTLS_PK_RSA
,
359 { ADD_LEN(MBEDTLS_OID_PKCS1_SHA512
), "sha512WithRSAEncryption", "RSA with SHA-512" },
360 MBEDTLS_MD_SHA512
, MBEDTLS_PK_RSA
,
362 #endif /* MBEDTLS_SHA512_C */
363 #if defined(MBEDTLS_SHA1_C)
365 { ADD_LEN(MBEDTLS_OID_RSA_SHA_OBS
), "sha-1WithRSAEncryption", "RSA with SHA1" },
366 MBEDTLS_MD_SHA1
, MBEDTLS_PK_RSA
,
368 #endif /* MBEDTLS_SHA1_C */
369 #endif /* MBEDTLS_RSA_C */
370 #if defined(MBEDTLS_ECDSA_C)
371 #if defined(MBEDTLS_SHA1_C)
373 { ADD_LEN(MBEDTLS_OID_ECDSA_SHA1
), "ecdsa-with-SHA1", "ECDSA with SHA1" },
374 MBEDTLS_MD_SHA1
, MBEDTLS_PK_ECDSA
,
376 #endif /* MBEDTLS_SHA1_C */
377 #if defined(MBEDTLS_SHA256_C)
379 { ADD_LEN(MBEDTLS_OID_ECDSA_SHA224
), "ecdsa-with-SHA224", "ECDSA with SHA224" },
380 MBEDTLS_MD_SHA224
, MBEDTLS_PK_ECDSA
,
383 { ADD_LEN(MBEDTLS_OID_ECDSA_SHA256
), "ecdsa-with-SHA256", "ECDSA with SHA256" },
384 MBEDTLS_MD_SHA256
, MBEDTLS_PK_ECDSA
,
386 #endif /* MBEDTLS_SHA256_C */
387 #if defined(MBEDTLS_SHA512_C)
389 { ADD_LEN(MBEDTLS_OID_ECDSA_SHA384
), "ecdsa-with-SHA384", "ECDSA with SHA384" },
390 MBEDTLS_MD_SHA384
, MBEDTLS_PK_ECDSA
,
393 { ADD_LEN(MBEDTLS_OID_ECDSA_SHA512
), "ecdsa-with-SHA512", "ECDSA with SHA512" },
394 MBEDTLS_MD_SHA512
, MBEDTLS_PK_ECDSA
,
396 #endif /* MBEDTLS_SHA512_C */
397 #endif /* MBEDTLS_ECDSA_C */
398 #if defined(MBEDTLS_RSA_C)
400 { ADD_LEN(MBEDTLS_OID_RSASSA_PSS
), "RSASSA-PSS", "RSASSA-PSS" },
401 MBEDTLS_MD_NONE
, MBEDTLS_PK_RSASSA_PSS
,
403 #endif /* MBEDTLS_RSA_C */
405 { NULL
, 0, NULL
, NULL
},
406 MBEDTLS_MD_NONE
, MBEDTLS_PK_NONE
,
410 FN_OID_TYPED_FROM_ASN1(oid_sig_alg_t
, sig_alg
, oid_sig_alg
)
411 FN_OID_GET_DESCRIPTOR_ATTR1(mbedtls_oid_get_sig_alg_desc
, oid_sig_alg_t
, sig_alg
, const char *, description
)
412 FN_OID_GET_ATTR2(mbedtls_oid_get_sig_alg
, oid_sig_alg_t
, sig_alg
, mbedtls_md_type_t
, md_alg
, mbedtls_pk_type_t
, pk_alg
)
413 FN_OID_GET_OID_BY_ATTR2(mbedtls_oid_get_oid_by_sig_alg
, oid_sig_alg_t
, oid_sig_alg
, mbedtls_pk_type_t
, pk_alg
, mbedtls_md_type_t
, md_alg
)
414 #endif /* MBEDTLS_MD_C */
417 * For PublicKeyInfo (PKCS1, RFC 5480)
420 mbedtls_oid_descriptor_t descriptor
;
421 mbedtls_pk_type_t pk_alg
;
424 static const oid_pk_alg_t oid_pk_alg
[] = {
426 { ADD_LEN(MBEDTLS_OID_PKCS1_RSA
), "rsaEncryption", "RSA" },
430 { ADD_LEN(MBEDTLS_OID_EC_ALG_UNRESTRICTED
), "id-ecPublicKey", "Generic EC key" },
434 { ADD_LEN(MBEDTLS_OID_EC_ALG_ECDH
), "id-ecDH", "EC key for ECDH" },
438 { NULL
, 0, NULL
, NULL
},
443 FN_OID_TYPED_FROM_ASN1(oid_pk_alg_t
, pk_alg
, oid_pk_alg
)
444 FN_OID_GET_ATTR1(mbedtls_oid_get_pk_alg
, oid_pk_alg_t
, pk_alg
, mbedtls_pk_type_t
, pk_alg
)
445 FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_pk_alg
, oid_pk_alg_t
, oid_pk_alg
, mbedtls_pk_type_t
, pk_alg
)
447 #if defined(MBEDTLS_ECP_C)
449 * For namedCurve (RFC 5480)
452 mbedtls_oid_descriptor_t descriptor
;
453 mbedtls_ecp_group_id grp_id
;
456 static const oid_ecp_grp_t oid_ecp_grp
[] = {
457 #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
459 { ADD_LEN(MBEDTLS_OID_EC_GRP_SECP192R1
), "secp192r1", "secp192r1" },
460 MBEDTLS_ECP_DP_SECP192R1
,
462 #endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
463 #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
465 { ADD_LEN(MBEDTLS_OID_EC_GRP_SECP224R1
), "secp224r1", "secp224r1" },
466 MBEDTLS_ECP_DP_SECP224R1
,
468 #endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */
469 #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
471 { ADD_LEN(MBEDTLS_OID_EC_GRP_SECP256R1
), "secp256r1", "secp256r1" },
472 MBEDTLS_ECP_DP_SECP256R1
,
474 #endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */
475 #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
477 { ADD_LEN(MBEDTLS_OID_EC_GRP_SECP384R1
), "secp384r1", "secp384r1" },
478 MBEDTLS_ECP_DP_SECP384R1
,
480 #endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */
481 #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
483 { ADD_LEN(MBEDTLS_OID_EC_GRP_SECP521R1
), "secp521r1", "secp521r1" },
484 MBEDTLS_ECP_DP_SECP521R1
,
486 #endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */
487 #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
489 { ADD_LEN(MBEDTLS_OID_EC_GRP_SECP192K1
), "secp192k1", "secp192k1" },
490 MBEDTLS_ECP_DP_SECP192K1
,
492 #endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */
493 #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
495 { ADD_LEN(MBEDTLS_OID_EC_GRP_SECP224K1
), "secp224k1", "secp224k1" },
496 MBEDTLS_ECP_DP_SECP224K1
,
498 #endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */
499 #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
501 { ADD_LEN(MBEDTLS_OID_EC_GRP_SECP256K1
), "secp256k1", "secp256k1" },
502 MBEDTLS_ECP_DP_SECP256K1
,
504 #endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
505 #if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
507 { ADD_LEN(MBEDTLS_OID_EC_GRP_BP256R1
), "brainpoolP256r1", "brainpool256r1" },
508 MBEDTLS_ECP_DP_BP256R1
,
510 #endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */
511 #if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
513 { ADD_LEN(MBEDTLS_OID_EC_GRP_BP384R1
), "brainpoolP384r1", "brainpool384r1" },
514 MBEDTLS_ECP_DP_BP384R1
,
516 #endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */
517 #if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
519 { ADD_LEN(MBEDTLS_OID_EC_GRP_BP512R1
), "brainpoolP512r1", "brainpool512r1" },
520 MBEDTLS_ECP_DP_BP512R1
,
522 #endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */
524 { NULL
, 0, NULL
, NULL
},
529 FN_OID_TYPED_FROM_ASN1(oid_ecp_grp_t
, grp_id
, oid_ecp_grp
)
530 FN_OID_GET_ATTR1(mbedtls_oid_get_ec_grp
, oid_ecp_grp_t
, grp_id
, mbedtls_ecp_group_id
, grp_id
)
531 FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_ec_grp
, oid_ecp_grp_t
, oid_ecp_grp
, mbedtls_ecp_group_id
, grp_id
)
532 #endif /* MBEDTLS_ECP_C */
534 #if defined(MBEDTLS_CIPHER_C)
536 * For PKCS#5 PBES2 encryption algorithm
539 mbedtls_oid_descriptor_t descriptor
;
540 mbedtls_cipher_type_t cipher_alg
;
543 static const oid_cipher_alg_t oid_cipher_alg
[] = {
545 { ADD_LEN(MBEDTLS_OID_DES_CBC
), "desCBC", "DES-CBC" },
546 MBEDTLS_CIPHER_DES_CBC
,
549 { ADD_LEN(MBEDTLS_OID_DES_EDE3_CBC
), "des-ede3-cbc", "DES-EDE3-CBC" },
550 MBEDTLS_CIPHER_DES_EDE3_CBC
,
553 { NULL
, 0, NULL
, NULL
},
558 FN_OID_TYPED_FROM_ASN1(oid_cipher_alg_t
, cipher_alg
, oid_cipher_alg
)
559 FN_OID_GET_ATTR1(mbedtls_oid_get_cipher_alg
, oid_cipher_alg_t
, cipher_alg
, mbedtls_cipher_type_t
, cipher_alg
)
560 #endif /* MBEDTLS_CIPHER_C */
562 #if defined(MBEDTLS_MD_C)
564 * For digestAlgorithm
567 mbedtls_oid_descriptor_t descriptor
;
568 mbedtls_md_type_t md_alg
;
571 static const oid_md_alg_t oid_md_alg
[] = {
572 #if defined(MBEDTLS_MD2_C)
574 { ADD_LEN(MBEDTLS_OID_DIGEST_ALG_MD2
), "id-md2", "MD2" },
577 #endif /* MBEDTLS_MD2_C */
578 #if defined(MBEDTLS_MD4_C)
580 { ADD_LEN(MBEDTLS_OID_DIGEST_ALG_MD4
), "id-md4", "MD4" },
583 #endif /* MBEDTLS_MD4_C */
584 #if defined(MBEDTLS_MD5_C)
586 { ADD_LEN(MBEDTLS_OID_DIGEST_ALG_MD5
), "id-md5", "MD5" },
589 #endif /* MBEDTLS_MD5_C */
590 #if defined(MBEDTLS_SHA1_C)
592 { ADD_LEN(MBEDTLS_OID_DIGEST_ALG_SHA1
), "id-sha1", "SHA-1" },
595 #endif /* MBEDTLS_SHA1_C */
596 #if defined(MBEDTLS_SHA256_C)
598 { ADD_LEN(MBEDTLS_OID_DIGEST_ALG_SHA224
), "id-sha224", "SHA-224" },
602 { ADD_LEN(MBEDTLS_OID_DIGEST_ALG_SHA256
), "id-sha256", "SHA-256" },
605 #endif /* MBEDTLS_SHA256_C */
606 #if defined(MBEDTLS_SHA512_C)
608 { ADD_LEN(MBEDTLS_OID_DIGEST_ALG_SHA384
), "id-sha384", "SHA-384" },
612 { ADD_LEN(MBEDTLS_OID_DIGEST_ALG_SHA512
), "id-sha512", "SHA-512" },
615 #endif /* MBEDTLS_SHA512_C */
616 #if defined(MBEDTLS_RIPEMD160_C)
618 { ADD_LEN(MBEDTLS_OID_DIGEST_ALG_RIPEMD160
), "id-ripemd160", "RIPEMD-160" },
619 MBEDTLS_MD_RIPEMD160
,
621 #endif /* MBEDTLS_RIPEMD160_C */
623 { NULL
, 0, NULL
, NULL
},
628 FN_OID_TYPED_FROM_ASN1(oid_md_alg_t
, md_alg
, oid_md_alg
)
629 FN_OID_GET_ATTR1(mbedtls_oid_get_md_alg
, oid_md_alg_t
, md_alg
, mbedtls_md_type_t
, md_alg
)
630 FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_md
, oid_md_alg_t
, oid_md_alg
, mbedtls_md_type_t
, md_alg
)
633 * For HMAC digestAlgorithm
636 mbedtls_oid_descriptor_t descriptor
;
637 mbedtls_md_type_t md_hmac
;
640 static const oid_md_hmac_t oid_md_hmac
[] = {
641 #if defined(MBEDTLS_SHA1_C)
643 { ADD_LEN(MBEDTLS_OID_HMAC_SHA1
), "hmacSHA1", "HMAC-SHA-1" },
646 #endif /* MBEDTLS_SHA1_C */
647 #if defined(MBEDTLS_SHA256_C)
649 { ADD_LEN(MBEDTLS_OID_HMAC_SHA224
), "hmacSHA224", "HMAC-SHA-224" },
653 { ADD_LEN(MBEDTLS_OID_HMAC_SHA256
), "hmacSHA256", "HMAC-SHA-256" },
656 #endif /* MBEDTLS_SHA256_C */
657 #if defined(MBEDTLS_SHA512_C)
659 { ADD_LEN(MBEDTLS_OID_HMAC_SHA384
), "hmacSHA384", "HMAC-SHA-384" },
663 { ADD_LEN(MBEDTLS_OID_HMAC_SHA512
), "hmacSHA512", "HMAC-SHA-512" },
666 #endif /* MBEDTLS_SHA512_C */
668 { NULL
, 0, NULL
, NULL
},
673 FN_OID_TYPED_FROM_ASN1(oid_md_hmac_t
, md_hmac
, oid_md_hmac
)
674 FN_OID_GET_ATTR1(mbedtls_oid_get_md_hmac
, oid_md_hmac_t
, md_hmac
, mbedtls_md_type_t
, md_hmac
)
675 #endif /* MBEDTLS_MD_C */
677 #if defined(MBEDTLS_PKCS12_C)
682 mbedtls_oid_descriptor_t descriptor
;
683 mbedtls_md_type_t md_alg
;
684 mbedtls_cipher_type_t cipher_alg
;
685 } oid_pkcs12_pbe_alg_t
;
687 static const oid_pkcs12_pbe_alg_t oid_pkcs12_pbe_alg
[] = {
689 { ADD_LEN(MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC
), "pbeWithSHAAnd3-KeyTripleDES-CBC", "PBE with SHA1 and 3-Key 3DES" },
690 MBEDTLS_MD_SHA1
, MBEDTLS_CIPHER_DES_EDE3_CBC
,
693 { ADD_LEN(MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC
), "pbeWithSHAAnd2-KeyTripleDES-CBC", "PBE with SHA1 and 2-Key 3DES" },
694 MBEDTLS_MD_SHA1
, MBEDTLS_CIPHER_DES_EDE_CBC
,
697 { NULL
, 0, NULL
, NULL
},
698 MBEDTLS_MD_NONE
, MBEDTLS_CIPHER_NONE
,
702 FN_OID_TYPED_FROM_ASN1(oid_pkcs12_pbe_alg_t
, pkcs12_pbe_alg
, oid_pkcs12_pbe_alg
)
703 FN_OID_GET_ATTR2(mbedtls_oid_get_pkcs12_pbe_alg
, oid_pkcs12_pbe_alg_t
, pkcs12_pbe_alg
, mbedtls_md_type_t
, md_alg
, mbedtls_cipher_type_t
, cipher_alg
)
704 #endif /* MBEDTLS_PKCS12_C */
706 #define OID_SAFE_SNPRINTF \
708 if( ret < 0 || (size_t) ret >= n ) \
709 return( MBEDTLS_ERR_OID_BUF_TOO_SMALL ); \
715 /* Return the x.y.z.... style numeric string for the given OID */
716 int mbedtls_oid_get_numeric_string(char *buf
, size_t size
,
717 const mbedtls_asn1_buf
*oid
) {
718 int ret
= MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED
;
726 /* First byte contains first two dots */
728 ret
= mbedtls_snprintf(p
, n
, "%d.%d", oid
->p
[0] / 40, oid
->p
[0] % 40);
733 for (i
= 1; i
< oid
->len
; i
++) {
734 /* Prevent overflow in value. */
735 if (((value
<< 7) >> 7) != value
)
736 return (MBEDTLS_ERR_OID_BUF_TOO_SMALL
);
739 value
+= oid
->p
[i
] & 0x7F;
741 if (!(oid
->p
[i
] & 0x80)) {
743 ret
= mbedtls_snprintf(p
, n
, ".%u", value
);
749 return ((int)(size
- n
));
752 #endif /* MBEDTLS_OID_C */