4 * \brief Object Identifier (OID) database
6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
7 * SPDX-License-Identifier: GPL-2.0
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * This file is part of mbed TLS (https://tls.mbed.org)
26 #if !defined(MBEDTLS_CONFIG_FILE)
27 #include "mbedtls/config.h"
29 #include MBEDTLS_CONFIG_FILE
32 #if defined(MBEDTLS_OID_C)
34 #include "mbedtls/oid.h"
35 #include "mbedtls/rsa.h"
40 #if defined(MBEDTLS_PLATFORM_C)
41 #include "mbedtls/platform.h"
43 #define mbedtls_snprintf snprintf
46 #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
47 #include "mbedtls/x509.h"
51 * Macro to automatically add the size of #define'd OIDs
53 #define ADD_LEN(s) s, MBEDTLS_OID_SIZE(s)
56 * Macro to generate an internal function for oid_XXX_from_asn1() (used by
57 * the other functions)
59 #define FN_OID_TYPED_FROM_ASN1( TYPE_T, NAME, LIST ) \
60 static const TYPE_T * oid_ ## NAME ## _from_asn1( const mbedtls_asn1_buf *oid ) \
62 const TYPE_T *p = LIST; \
63 const mbedtls_oid_descriptor_t *cur = (const mbedtls_oid_descriptor_t *) p; \
64 if( p == NULL || oid == NULL ) return( NULL ); \
65 while( cur->asn1 != NULL ) { \
66 if( cur->asn1_len == oid->len && \
67 memcmp( cur->asn1, oid->p, oid->len ) == 0 ) { \
71 cur = (const mbedtls_oid_descriptor_t *) p; \
77 * Macro to generate a function for retrieving a single attribute from the
78 * descriptor of an mbedtls_oid_descriptor_t wrapper.
80 #define FN_OID_GET_DESCRIPTOR_ATTR1(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1) \
81 int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \
83 const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \
84 if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \
85 *ATTR1 = data->descriptor.ATTR1; \
90 * Macro to generate a function for retrieving a single attribute from an
91 * mbedtls_oid_descriptor_t wrapper.
93 #define FN_OID_GET_ATTR1(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1) \
94 int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \
96 const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \
97 if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \
98 *ATTR1 = data->ATTR1; \
103 * Macro to generate a function for retrieving two attributes from an
104 * mbedtls_oid_descriptor_t wrapper.
106 #define FN_OID_GET_ATTR2(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1, \
108 int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1, ATTR2_TYPE * ATTR2 ) \
110 const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \
111 if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \
112 *ATTR1 = data->ATTR1; \
113 *ATTR2 = data->ATTR2; \
118 * Macro to generate a function for retrieving the OID based on a single
119 * attribute from a mbedtls_oid_descriptor_t wrapper.
121 #define FN_OID_GET_OID_BY_ATTR1(FN_NAME, TYPE_T, LIST, ATTR1_TYPE, ATTR1) \
122 int FN_NAME( ATTR1_TYPE ATTR1, const char **oid, size_t *olen ) \
124 const TYPE_T *cur = LIST; \
125 while( cur->descriptor.asn1 != NULL ) { \
126 if( cur->ATTR1 == ATTR1 ) { \
127 *oid = cur->descriptor.asn1; \
128 *olen = cur->descriptor.asn1_len; \
133 return( MBEDTLS_ERR_OID_NOT_FOUND ); \
137 * Macro to generate a function for retrieving the OID based on two
138 * attributes from a mbedtls_oid_descriptor_t wrapper.
140 #define FN_OID_GET_OID_BY_ATTR2(FN_NAME, TYPE_T, LIST, ATTR1_TYPE, ATTR1, \
142 int FN_NAME( ATTR1_TYPE ATTR1, ATTR2_TYPE ATTR2, const char **oid , \
145 const TYPE_T *cur = LIST; \
146 while( cur->descriptor.asn1 != NULL ) { \
147 if( cur->ATTR1 == ATTR1 && cur->ATTR2 == ATTR2 ) { \
148 *oid = cur->descriptor.asn1; \
149 *olen = cur->descriptor.asn1_len; \
154 return( MBEDTLS_ERR_OID_NOT_FOUND ); \
157 #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
159 * For X520 attribute types
162 mbedtls_oid_descriptor_t descriptor
;
163 const char *short_name
;
166 static const oid_x520_attr_t oid_x520_attr_type
[] =
169 { ADD_LEN( MBEDTLS_OID_AT_CN
), "id-at-commonName", "Common Name" },
173 { ADD_LEN( MBEDTLS_OID_AT_COUNTRY
), "id-at-countryName", "Country" },
177 { ADD_LEN( MBEDTLS_OID_AT_LOCALITY
), "id-at-locality", "Locality" },
181 { ADD_LEN( MBEDTLS_OID_AT_STATE
), "id-at-state", "State" },
185 { ADD_LEN( MBEDTLS_OID_AT_ORGANIZATION
),"id-at-organizationName", "Organization" },
189 { ADD_LEN( MBEDTLS_OID_AT_ORG_UNIT
), "id-at-organizationalUnitName", "Org Unit" },
193 { ADD_LEN( MBEDTLS_OID_PKCS9_EMAIL
), "emailAddress", "E-mail address" },
197 { ADD_LEN( MBEDTLS_OID_AT_SERIAL_NUMBER
),"id-at-serialNumber", "Serial number" },
201 { ADD_LEN( MBEDTLS_OID_AT_POSTAL_ADDRESS
),"id-at-postalAddress", "Postal address" },
205 { ADD_LEN( MBEDTLS_OID_AT_POSTAL_CODE
), "id-at-postalCode", "Postal code" },
209 { ADD_LEN( MBEDTLS_OID_AT_SUR_NAME
), "id-at-surName", "Surname" },
213 { ADD_LEN( MBEDTLS_OID_AT_GIVEN_NAME
), "id-at-givenName", "Given name" },
217 { ADD_LEN( MBEDTLS_OID_AT_INITIALS
), "id-at-initials", "Initials" },
221 { ADD_LEN( MBEDTLS_OID_AT_GENERATION_QUALIFIER
), "id-at-generationQualifier", "Generation qualifier" },
222 "generationQualifier",
225 { ADD_LEN( MBEDTLS_OID_AT_TITLE
), "id-at-title", "Title" },
229 { ADD_LEN( MBEDTLS_OID_AT_DN_QUALIFIER
),"id-at-dnQualifier", "Distinguished Name qualifier" },
233 { ADD_LEN( MBEDTLS_OID_AT_PSEUDONYM
), "id-at-pseudonym", "Pseudonym" },
237 { ADD_LEN( MBEDTLS_OID_DOMAIN_COMPONENT
), "id-domainComponent", "Domain component" },
241 { ADD_LEN( MBEDTLS_OID_AT_UNIQUE_IDENTIFIER
), "id-at-uniqueIdentifier", "Unique Identifier" },
245 { NULL
, 0, NULL
, NULL
},
250 FN_OID_TYPED_FROM_ASN1(oid_x520_attr_t
, x520_attr
, oid_x520_attr_type
)
251 FN_OID_GET_ATTR1(mbedtls_oid_get_attr_short_name
, oid_x520_attr_t
, x520_attr
, const char *, short_name
)
254 * For X509 extensions
257 mbedtls_oid_descriptor_t descriptor
;
261 static const oid_x509_ext_t oid_x509_ext
[] =
264 { ADD_LEN( MBEDTLS_OID_BASIC_CONSTRAINTS
), "id-ce-basicConstraints", "Basic Constraints" },
265 MBEDTLS_X509_EXT_BASIC_CONSTRAINTS
,
268 { ADD_LEN( MBEDTLS_OID_KEY_USAGE
), "id-ce-keyUsage", "Key Usage" },
269 MBEDTLS_X509_EXT_KEY_USAGE
,
272 { ADD_LEN( MBEDTLS_OID_EXTENDED_KEY_USAGE
), "id-ce-extKeyUsage", "Extended Key Usage" },
273 MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE
,
276 { ADD_LEN( MBEDTLS_OID_SUBJECT_ALT_NAME
), "id-ce-subjectAltName", "Subject Alt Name" },
277 MBEDTLS_X509_EXT_SUBJECT_ALT_NAME
,
280 { ADD_LEN( MBEDTLS_OID_NS_CERT_TYPE
), "id-netscape-certtype", "Netscape Certificate Type" },
281 MBEDTLS_X509_EXT_NS_CERT_TYPE
,
284 { NULL
, 0, NULL
, NULL
},
289 FN_OID_TYPED_FROM_ASN1(oid_x509_ext_t
, x509_ext
, oid_x509_ext
)
290 FN_OID_GET_ATTR1(mbedtls_oid_get_x509_ext_type
, oid_x509_ext_t
, x509_ext
, int, ext_type
)
292 static const mbedtls_oid_descriptor_t oid_ext_key_usage
[] =
294 { ADD_LEN( MBEDTLS_OID_SERVER_AUTH
), "id-kp-serverAuth", "TLS Web Server Authentication" },
295 { ADD_LEN( MBEDTLS_OID_CLIENT_AUTH
), "id-kp-clientAuth", "TLS Web Client Authentication" },
296 { ADD_LEN( MBEDTLS_OID_CODE_SIGNING
), "id-kp-codeSigning", "Code Signing" },
297 { ADD_LEN( MBEDTLS_OID_EMAIL_PROTECTION
), "id-kp-emailProtection", "E-mail Protection" },
298 { ADD_LEN( MBEDTLS_OID_TIME_STAMPING
), "id-kp-timeStamping", "Time Stamping" },
299 { ADD_LEN( MBEDTLS_OID_OCSP_SIGNING
), "id-kp-OCSPSigning", "OCSP Signing" },
300 { NULL
, 0, NULL
, NULL
},
303 FN_OID_TYPED_FROM_ASN1(mbedtls_oid_descriptor_t
, ext_key_usage
, oid_ext_key_usage
)
304 FN_OID_GET_ATTR1(mbedtls_oid_get_extended_key_usage
, mbedtls_oid_descriptor_t
, ext_key_usage
, const char *, description
)
305 #endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
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
[] =
319 #if defined(MBEDTLS_RSA_C)
320 #if defined(MBEDTLS_MD2_C)
322 { ADD_LEN( MBEDTLS_OID_PKCS1_MD2
), "md2WithRSAEncryption", "RSA with MD2" },
323 MBEDTLS_MD_MD2
, MBEDTLS_PK_RSA
,
325 #endif /* MBEDTLS_MD2_C */
326 #if defined(MBEDTLS_MD4_C)
328 { ADD_LEN( MBEDTLS_OID_PKCS1_MD4
), "md4WithRSAEncryption", "RSA with MD4" },
329 MBEDTLS_MD_MD4
, MBEDTLS_PK_RSA
,
331 #endif /* MBEDTLS_MD4_C */
332 #if defined(MBEDTLS_MD5_C)
334 { ADD_LEN( MBEDTLS_OID_PKCS1_MD5
), "md5WithRSAEncryption", "RSA with MD5" },
335 MBEDTLS_MD_MD5
, MBEDTLS_PK_RSA
,
337 #endif /* MBEDTLS_MD5_C */
338 #if defined(MBEDTLS_SHA1_C)
340 { ADD_LEN( MBEDTLS_OID_PKCS1_SHA1
), "sha-1WithRSAEncryption", "RSA with SHA1" },
341 MBEDTLS_MD_SHA1
, MBEDTLS_PK_RSA
,
343 #endif /* MBEDTLS_SHA1_C */
344 #if defined(MBEDTLS_SHA256_C)
346 { ADD_LEN( MBEDTLS_OID_PKCS1_SHA224
), "sha224WithRSAEncryption", "RSA with SHA-224" },
347 MBEDTLS_MD_SHA224
, MBEDTLS_PK_RSA
,
350 { ADD_LEN( MBEDTLS_OID_PKCS1_SHA256
), "sha256WithRSAEncryption", "RSA with SHA-256" },
351 MBEDTLS_MD_SHA256
, MBEDTLS_PK_RSA
,
353 #endif /* MBEDTLS_SHA256_C */
354 #if defined(MBEDTLS_SHA512_C)
356 { ADD_LEN( MBEDTLS_OID_PKCS1_SHA384
), "sha384WithRSAEncryption", "RSA with SHA-384" },
357 MBEDTLS_MD_SHA384
, MBEDTLS_PK_RSA
,
360 { ADD_LEN( MBEDTLS_OID_PKCS1_SHA512
), "sha512WithRSAEncryption", "RSA with SHA-512" },
361 MBEDTLS_MD_SHA512
, MBEDTLS_PK_RSA
,
363 #endif /* MBEDTLS_SHA512_C */
364 #if defined(MBEDTLS_SHA1_C)
366 { ADD_LEN( MBEDTLS_OID_RSA_SHA_OBS
), "sha-1WithRSAEncryption", "RSA with SHA1" },
367 MBEDTLS_MD_SHA1
, MBEDTLS_PK_RSA
,
369 #endif /* MBEDTLS_SHA1_C */
370 #endif /* MBEDTLS_RSA_C */
371 #if defined(MBEDTLS_ECDSA_C)
372 #if defined(MBEDTLS_SHA1_C)
374 { ADD_LEN( MBEDTLS_OID_ECDSA_SHA1
), "ecdsa-with-SHA1", "ECDSA with SHA1" },
375 MBEDTLS_MD_SHA1
, MBEDTLS_PK_ECDSA
,
377 #endif /* MBEDTLS_SHA1_C */
378 #if defined(MBEDTLS_SHA256_C)
380 { ADD_LEN( MBEDTLS_OID_ECDSA_SHA224
), "ecdsa-with-SHA224", "ECDSA with SHA224" },
381 MBEDTLS_MD_SHA224
, MBEDTLS_PK_ECDSA
,
384 { ADD_LEN( MBEDTLS_OID_ECDSA_SHA256
), "ecdsa-with-SHA256", "ECDSA with SHA256" },
385 MBEDTLS_MD_SHA256
, MBEDTLS_PK_ECDSA
,
387 #endif /* MBEDTLS_SHA256_C */
388 #if defined(MBEDTLS_SHA512_C)
390 { ADD_LEN( MBEDTLS_OID_ECDSA_SHA384
), "ecdsa-with-SHA384", "ECDSA with SHA384" },
391 MBEDTLS_MD_SHA384
, MBEDTLS_PK_ECDSA
,
394 { ADD_LEN( MBEDTLS_OID_ECDSA_SHA512
), "ecdsa-with-SHA512", "ECDSA with SHA512" },
395 MBEDTLS_MD_SHA512
, MBEDTLS_PK_ECDSA
,
397 #endif /* MBEDTLS_SHA512_C */
398 #endif /* MBEDTLS_ECDSA_C */
399 #if defined(MBEDTLS_RSA_C)
401 { ADD_LEN( MBEDTLS_OID_RSASSA_PSS
), "RSASSA-PSS", "RSASSA-PSS" },
402 MBEDTLS_MD_NONE
, MBEDTLS_PK_RSASSA_PSS
,
404 #endif /* MBEDTLS_RSA_C */
406 { NULL
, 0, NULL
, NULL
},
407 MBEDTLS_MD_NONE
, MBEDTLS_PK_NONE
,
411 FN_OID_TYPED_FROM_ASN1(oid_sig_alg_t
, sig_alg
, oid_sig_alg
)
412 FN_OID_GET_DESCRIPTOR_ATTR1(mbedtls_oid_get_sig_alg_desc
, oid_sig_alg_t
, sig_alg
, const char *, description
)
413 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
)
414 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
)
415 #endif /* MBEDTLS_MD_C */
418 * For PublicKeyInfo (PKCS1, RFC 5480)
421 mbedtls_oid_descriptor_t descriptor
;
422 mbedtls_pk_type_t pk_alg
;
425 static const oid_pk_alg_t oid_pk_alg
[] =
428 { ADD_LEN( MBEDTLS_OID_PKCS1_RSA
), "rsaEncryption", "RSA" },
432 { ADD_LEN( MBEDTLS_OID_EC_ALG_UNRESTRICTED
), "id-ecPublicKey", "Generic EC key" },
436 { ADD_LEN( MBEDTLS_OID_EC_ALG_ECDH
), "id-ecDH", "EC key for ECDH" },
440 { NULL
, 0, NULL
, NULL
},
445 FN_OID_TYPED_FROM_ASN1(oid_pk_alg_t
, pk_alg
, oid_pk_alg
)
446 FN_OID_GET_ATTR1(mbedtls_oid_get_pk_alg
, oid_pk_alg_t
, pk_alg
, mbedtls_pk_type_t
, pk_alg
)
447 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
)
449 #if defined(MBEDTLS_ECP_C)
451 * For namedCurve (RFC 5480)
454 mbedtls_oid_descriptor_t descriptor
;
455 mbedtls_ecp_group_id grp_id
;
458 static const oid_ecp_grp_t oid_ecp_grp
[] =
460 #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
462 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP192R1
), "secp192r1", "secp192r1" },
463 MBEDTLS_ECP_DP_SECP192R1
,
465 #endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
466 #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
468 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP224R1
), "secp224r1", "secp224r1" },
469 MBEDTLS_ECP_DP_SECP224R1
,
471 #endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */
472 #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
474 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP256R1
), "secp256r1", "secp256r1" },
475 MBEDTLS_ECP_DP_SECP256R1
,
477 #endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */
478 #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
480 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP384R1
), "secp384r1", "secp384r1" },
481 MBEDTLS_ECP_DP_SECP384R1
,
483 #endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */
484 #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
486 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP521R1
), "secp521r1", "secp521r1" },
487 MBEDTLS_ECP_DP_SECP521R1
,
489 #endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */
490 #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
492 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP192K1
), "secp192k1", "secp192k1" },
493 MBEDTLS_ECP_DP_SECP192K1
,
495 #endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */
496 #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
498 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP224K1
), "secp224k1", "secp224k1" },
499 MBEDTLS_ECP_DP_SECP224K1
,
501 #endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */
502 #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
504 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP256K1
), "secp256k1", "secp256k1" },
505 MBEDTLS_ECP_DP_SECP256K1
,
507 #endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
508 #if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
510 { ADD_LEN( MBEDTLS_OID_EC_GRP_BP256R1
), "brainpoolP256r1","brainpool256r1" },
511 MBEDTLS_ECP_DP_BP256R1
,
513 #endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */
514 #if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
516 { ADD_LEN( MBEDTLS_OID_EC_GRP_BP384R1
), "brainpoolP384r1","brainpool384r1" },
517 MBEDTLS_ECP_DP_BP384R1
,
519 #endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */
520 #if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
522 { ADD_LEN( MBEDTLS_OID_EC_GRP_BP512R1
), "brainpoolP512r1","brainpool512r1" },
523 MBEDTLS_ECP_DP_BP512R1
,
525 #endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */
527 { NULL
, 0, NULL
, NULL
},
532 FN_OID_TYPED_FROM_ASN1(oid_ecp_grp_t
, grp_id
, oid_ecp_grp
)
533 FN_OID_GET_ATTR1(mbedtls_oid_get_ec_grp
, oid_ecp_grp_t
, grp_id
, mbedtls_ecp_group_id
, grp_id
)
534 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
)
535 #endif /* MBEDTLS_ECP_C */
537 #if defined(MBEDTLS_CIPHER_C)
539 * For PKCS#5 PBES2 encryption algorithm
542 mbedtls_oid_descriptor_t descriptor
;
543 mbedtls_cipher_type_t cipher_alg
;
546 static const oid_cipher_alg_t oid_cipher_alg
[] =
549 { ADD_LEN( MBEDTLS_OID_DES_CBC
), "desCBC", "DES-CBC" },
550 MBEDTLS_CIPHER_DES_CBC
,
553 { ADD_LEN( MBEDTLS_OID_DES_EDE3_CBC
), "des-ede3-cbc", "DES-EDE3-CBC" },
554 MBEDTLS_CIPHER_DES_EDE3_CBC
,
557 { NULL
, 0, NULL
, NULL
},
562 FN_OID_TYPED_FROM_ASN1(oid_cipher_alg_t
, cipher_alg
, oid_cipher_alg
)
563 FN_OID_GET_ATTR1(mbedtls_oid_get_cipher_alg
, oid_cipher_alg_t
, cipher_alg
, mbedtls_cipher_type_t
, cipher_alg
)
564 #endif /* MBEDTLS_CIPHER_C */
566 #if defined(MBEDTLS_MD_C)
568 * For digestAlgorithm
571 mbedtls_oid_descriptor_t descriptor
;
572 mbedtls_md_type_t md_alg
;
575 static const oid_md_alg_t oid_md_alg
[] =
577 #if defined(MBEDTLS_MD2_C)
579 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_MD2
), "id-md2", "MD2" },
582 #endif /* MBEDTLS_MD2_C */
583 #if defined(MBEDTLS_MD4_C)
585 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_MD4
), "id-md4", "MD4" },
588 #endif /* MBEDTLS_MD4_C */
589 #if defined(MBEDTLS_MD5_C)
591 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_MD5
), "id-md5", "MD5" },
594 #endif /* MBEDTLS_MD5_C */
595 #if defined(MBEDTLS_SHA1_C)
597 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA1
), "id-sha1", "SHA-1" },
600 #endif /* MBEDTLS_SHA1_C */
601 #if defined(MBEDTLS_SHA256_C)
603 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA224
), "id-sha224", "SHA-224" },
607 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA256
), "id-sha256", "SHA-256" },
610 #endif /* MBEDTLS_SHA256_C */
611 #if defined(MBEDTLS_SHA512_C)
613 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA384
), "id-sha384", "SHA-384" },
617 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA512
), "id-sha512", "SHA-512" },
620 #endif /* MBEDTLS_SHA512_C */
622 { NULL
, 0, NULL
, NULL
},
627 FN_OID_TYPED_FROM_ASN1(oid_md_alg_t
, md_alg
, oid_md_alg
)
628 FN_OID_GET_ATTR1(mbedtls_oid_get_md_alg
, oid_md_alg_t
, md_alg
, mbedtls_md_type_t
, md_alg
)
629 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
)
632 * For HMAC digestAlgorithm
635 mbedtls_oid_descriptor_t descriptor
;
636 mbedtls_md_type_t md_hmac
;
639 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
[] =
690 { ADD_LEN( MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC
), "pbeWithSHAAnd3-KeyTripleDES-CBC", "PBE with SHA1 and 3-Key 3DES" },
691 MBEDTLS_MD_SHA1
, MBEDTLS_CIPHER_DES_EDE3_CBC
,
694 { ADD_LEN( MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC
), "pbeWithSHAAnd2-KeyTripleDES-CBC", "PBE with SHA1 and 2-Key 3DES" },
695 MBEDTLS_MD_SHA1
, MBEDTLS_CIPHER_DES_EDE_CBC
,
698 { NULL
, 0, NULL
, NULL
},
699 MBEDTLS_MD_NONE
, MBEDTLS_CIPHER_NONE
,
703 FN_OID_TYPED_FROM_ASN1(oid_pkcs12_pbe_alg_t
, pkcs12_pbe_alg
, oid_pkcs12_pbe_alg
)
704 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
)
705 #endif /* MBEDTLS_PKCS12_C */
707 #define OID_SAFE_SNPRINTF \
709 if( ret < 0 || (size_t) ret >= n ) \
710 return( MBEDTLS_ERR_OID_BUF_TOO_SMALL ); \
716 /* Return the x.y.z.... style numeric string for the given OID */
717 int mbedtls_oid_get_numeric_string( char *buf
, size_t size
,
718 const mbedtls_asn1_buf
*oid
)
728 /* First byte contains first two dots */
731 ret
= mbedtls_snprintf( p
, n
, "%d.%d", oid
->p
[0] / 40, oid
->p
[0] % 40 );
736 for( i
= 1; i
< oid
->len
; i
++ )
738 /* Prevent overflow in value. */
739 if( ( ( value
<< 7 ) >> 7 ) != value
)
740 return( MBEDTLS_ERR_OID_BUF_TOO_SMALL
);
743 value
+= oid
->p
[i
] & 0x7F;
745 if( !( oid
->p
[i
] & 0x80 ) )
748 ret
= mbedtls_snprintf( p
, n
, ".%d", value
);
754 return( (int) ( size
- n
) );
757 #endif /* MBEDTLS_OID_C */