ReactOS 0.4.15-dev-8419-g7f0e8a3
oid.c
Go to the documentation of this file.
1
49#if !defined(MBEDTLS_CONFIG_FILE)
50#include "mbedtls/config.h"
51#else
52#include MBEDTLS_CONFIG_FILE
53#endif
54
55#if defined(MBEDTLS_OID_C)
56
57#include "mbedtls/oid.h"
58#include "mbedtls/rsa.h"
59
60#include <stdio.h>
61#include <string.h>
62
63#if defined(MBEDTLS_PLATFORM_C)
64#include "mbedtls/platform.h"
65#else
66#define mbedtls_snprintf snprintf
67#endif
68
69#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
70#include "mbedtls/x509.h"
71#endif
72
73/*
74 * Macro to automatically add the size of #define'd OIDs
75 */
76#define ADD_LEN(s) s, MBEDTLS_OID_SIZE(s)
77
78/*
79 * Macro to generate an internal function for oid_XXX_from_asn1() (used by
80 * the other functions)
81 */
82#define FN_OID_TYPED_FROM_ASN1( TYPE_T, NAME, LIST ) \
83 static const TYPE_T * oid_ ## NAME ## _from_asn1( \
84 const mbedtls_asn1_buf *oid ) \
85 { \
86 const TYPE_T *p = (LIST); \
87 const mbedtls_oid_descriptor_t *cur = \
88 (const mbedtls_oid_descriptor_t *) p; \
89 if( p == NULL || oid == NULL ) return( NULL ); \
90 while( cur->asn1 != NULL ) { \
91 if( cur->asn1_len == oid->len && \
92 memcmp( cur->asn1, oid->p, oid->len ) == 0 ) { \
93 return( p ); \
94 } \
95 p++; \
96 cur = (const mbedtls_oid_descriptor_t *) p; \
97 } \
98 return( NULL ); \
99 }
100
101/*
102 * Macro to generate a function for retrieving a single attribute from the
103 * descriptor of an mbedtls_oid_descriptor_t wrapper.
104 */
105#define FN_OID_GET_DESCRIPTOR_ATTR1(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1) \
106int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \
107{ \
108 const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \
109 if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \
110 *ATTR1 = data->descriptor.ATTR1; \
111 return( 0 ); \
112}
113
114/*
115 * Macro to generate a function for retrieving a single attribute from an
116 * mbedtls_oid_descriptor_t wrapper.
117 */
118#define FN_OID_GET_ATTR1(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1) \
119int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \
120{ \
121 const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \
122 if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \
123 *ATTR1 = data->ATTR1; \
124 return( 0 ); \
125}
126
127/*
128 * Macro to generate a function for retrieving two attributes from an
129 * mbedtls_oid_descriptor_t wrapper.
130 */
131#define FN_OID_GET_ATTR2(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1, \
132 ATTR2_TYPE, ATTR2) \
133int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1, \
134 ATTR2_TYPE * ATTR2 ) \
135{ \
136 const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \
137 if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \
138 *(ATTR1) = data->ATTR1; \
139 *(ATTR2) = data->ATTR2; \
140 return( 0 ); \
141}
142
143/*
144 * Macro to generate a function for retrieving the OID based on a single
145 * attribute from a mbedtls_oid_descriptor_t wrapper.
146 */
147#define FN_OID_GET_OID_BY_ATTR1(FN_NAME, TYPE_T, LIST, ATTR1_TYPE, ATTR1) \
148int FN_NAME( ATTR1_TYPE ATTR1, const char **oid, size_t *olen ) \
149{ \
150 const TYPE_T *cur = (LIST); \
151 while( cur->descriptor.asn1 != NULL ) { \
152 if( cur->ATTR1 == (ATTR1) ) { \
153 *oid = cur->descriptor.asn1; \
154 *olen = cur->descriptor.asn1_len; \
155 return( 0 ); \
156 } \
157 cur++; \
158 } \
159 return( MBEDTLS_ERR_OID_NOT_FOUND ); \
160}
161
162/*
163 * Macro to generate a function for retrieving the OID based on two
164 * attributes from a mbedtls_oid_descriptor_t wrapper.
165 */
166#define FN_OID_GET_OID_BY_ATTR2(FN_NAME, TYPE_T, LIST, ATTR1_TYPE, ATTR1, \
167 ATTR2_TYPE, ATTR2) \
168int FN_NAME( ATTR1_TYPE ATTR1, ATTR2_TYPE ATTR2, const char **oid , \
169 size_t *olen ) \
170{ \
171 const TYPE_T *cur = (LIST); \
172 while( cur->descriptor.asn1 != NULL ) { \
173 if( cur->ATTR1 == (ATTR1) && cur->ATTR2 == (ATTR2) ) { \
174 *oid = cur->descriptor.asn1; \
175 *olen = cur->descriptor.asn1_len; \
176 return( 0 ); \
177 } \
178 cur++; \
179 } \
180 return( MBEDTLS_ERR_OID_NOT_FOUND ); \
181}
182
183#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
184/*
185 * For X520 attribute types
186 */
187typedef struct {
189 const char *short_name;
190} oid_x520_attr_t;
191
192static const oid_x520_attr_t oid_x520_attr_type[] =
193{
194 {
195 { ADD_LEN( MBEDTLS_OID_AT_CN ), "id-at-commonName", "Common Name" },
196 "CN",
197 },
198 {
199 { ADD_LEN( MBEDTLS_OID_AT_COUNTRY ), "id-at-countryName", "Country" },
200 "C",
201 },
202 {
203 { ADD_LEN( MBEDTLS_OID_AT_LOCALITY ), "id-at-locality", "Locality" },
204 "L",
205 },
206 {
207 { ADD_LEN( MBEDTLS_OID_AT_STATE ), "id-at-state", "State" },
208 "ST",
209 },
210 {
211 { ADD_LEN( MBEDTLS_OID_AT_ORGANIZATION ),"id-at-organizationName", "Organization" },
212 "O",
213 },
214 {
215 { ADD_LEN( MBEDTLS_OID_AT_ORG_UNIT ), "id-at-organizationalUnitName", "Org Unit" },
216 "OU",
217 },
218 {
219 { ADD_LEN( MBEDTLS_OID_PKCS9_EMAIL ), "emailAddress", "E-mail address" },
220 "emailAddress",
221 },
222 {
223 { ADD_LEN( MBEDTLS_OID_AT_SERIAL_NUMBER ),"id-at-serialNumber", "Serial number" },
224 "serialNumber",
225 },
226 {
227 { ADD_LEN( MBEDTLS_OID_AT_POSTAL_ADDRESS ),"id-at-postalAddress", "Postal address" },
228 "postalAddress",
229 },
230 {
231 { ADD_LEN( MBEDTLS_OID_AT_POSTAL_CODE ), "id-at-postalCode", "Postal code" },
232 "postalCode",
233 },
234 {
235 { ADD_LEN( MBEDTLS_OID_AT_SUR_NAME ), "id-at-surName", "Surname" },
236 "SN",
237 },
238 {
239 { ADD_LEN( MBEDTLS_OID_AT_GIVEN_NAME ), "id-at-givenName", "Given name" },
240 "GN",
241 },
242 {
243 { ADD_LEN( MBEDTLS_OID_AT_INITIALS ), "id-at-initials", "Initials" },
244 "initials",
245 },
246 {
247 { ADD_LEN( MBEDTLS_OID_AT_GENERATION_QUALIFIER ), "id-at-generationQualifier", "Generation qualifier" },
248 "generationQualifier",
249 },
250 {
251 { ADD_LEN( MBEDTLS_OID_AT_TITLE ), "id-at-title", "Title" },
252 "title",
253 },
254 {
255 { ADD_LEN( MBEDTLS_OID_AT_DN_QUALIFIER ),"id-at-dnQualifier", "Distinguished Name qualifier" },
256 "dnQualifier",
257 },
258 {
259 { ADD_LEN( MBEDTLS_OID_AT_PSEUDONYM ), "id-at-pseudonym", "Pseudonym" },
260 "pseudonym",
261 },
262 {
263 { ADD_LEN( MBEDTLS_OID_DOMAIN_COMPONENT ), "id-domainComponent", "Domain component" },
264 "DC",
265 },
266 {
267 { ADD_LEN( MBEDTLS_OID_AT_UNIQUE_IDENTIFIER ), "id-at-uniqueIdentifier", "Unique Identifier" },
268 "uniqueIdentifier",
269 },
270 {
271 { NULL, 0, NULL, NULL },
272 NULL,
273 }
274};
275
276FN_OID_TYPED_FROM_ASN1(oid_x520_attr_t, x520_attr, oid_x520_attr_type)
277FN_OID_GET_ATTR1(mbedtls_oid_get_attr_short_name, oid_x520_attr_t, x520_attr, const char *, short_name)
278
279/*
280 * For X509 extensions
281 */
282typedef struct {
284 int ext_type;
285} oid_x509_ext_t;
286
287static const oid_x509_ext_t oid_x509_ext[] =
288{
289 {
290 { ADD_LEN( MBEDTLS_OID_BASIC_CONSTRAINTS ), "id-ce-basicConstraints", "Basic Constraints" },
292 },
293 {
294 { ADD_LEN( MBEDTLS_OID_KEY_USAGE ), "id-ce-keyUsage", "Key Usage" },
296 },
297 {
298 { ADD_LEN( MBEDTLS_OID_EXTENDED_KEY_USAGE ), "id-ce-extKeyUsage", "Extended Key Usage" },
300 },
301 {
302 { ADD_LEN( MBEDTLS_OID_SUBJECT_ALT_NAME ), "id-ce-subjectAltName", "Subject Alt Name" },
304 },
305 {
306 { ADD_LEN( MBEDTLS_OID_NS_CERT_TYPE ), "id-netscape-certtype", "Netscape Certificate Type" },
308 },
309 {
310 { NULL, 0, NULL, NULL },
311 0,
312 },
313};
314
315FN_OID_TYPED_FROM_ASN1(oid_x509_ext_t, x509_ext, oid_x509_ext)
316FN_OID_GET_ATTR1(mbedtls_oid_get_x509_ext_type, oid_x509_ext_t, x509_ext, int, ext_type)
317
318static const mbedtls_oid_descriptor_t oid_ext_key_usage[] =
319{
320 { ADD_LEN( MBEDTLS_OID_SERVER_AUTH ), "id-kp-serverAuth", "TLS Web Server Authentication" },
321 { ADD_LEN( MBEDTLS_OID_CLIENT_AUTH ), "id-kp-clientAuth", "TLS Web Client Authentication" },
322 { ADD_LEN( MBEDTLS_OID_CODE_SIGNING ), "id-kp-codeSigning", "Code Signing" },
323 { ADD_LEN( MBEDTLS_OID_EMAIL_PROTECTION ), "id-kp-emailProtection", "E-mail Protection" },
324 { ADD_LEN( MBEDTLS_OID_TIME_STAMPING ), "id-kp-timeStamping", "Time Stamping" },
325 { ADD_LEN( MBEDTLS_OID_OCSP_SIGNING ), "id-kp-OCSPSigning", "OCSP Signing" },
326 { NULL, 0, NULL, NULL },
327};
328
329FN_OID_TYPED_FROM_ASN1(mbedtls_oid_descriptor_t, ext_key_usage, oid_ext_key_usage)
330FN_OID_GET_ATTR1(mbedtls_oid_get_extended_key_usage, mbedtls_oid_descriptor_t, ext_key_usage, const char *, description)
331#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
332
333#if defined(MBEDTLS_MD_C)
334/*
335 * For SignatureAlgorithmIdentifier
336 */
337typedef struct {
339 mbedtls_md_type_t md_alg;
340 mbedtls_pk_type_t pk_alg;
341} oid_sig_alg_t;
342
343static const oid_sig_alg_t oid_sig_alg[] =
344{
345#if defined(MBEDTLS_RSA_C)
346#if defined(MBEDTLS_MD2_C)
347 {
348 { ADD_LEN( MBEDTLS_OID_PKCS1_MD2 ), "md2WithRSAEncryption", "RSA with MD2" },
350 },
351#endif /* MBEDTLS_MD2_C */
352#if defined(MBEDTLS_MD4_C)
353 {
354 { ADD_LEN( MBEDTLS_OID_PKCS1_MD4 ), "md4WithRSAEncryption", "RSA with MD4" },
356 },
357#endif /* MBEDTLS_MD4_C */
358#if defined(MBEDTLS_MD5_C)
359 {
360 { ADD_LEN( MBEDTLS_OID_PKCS1_MD5 ), "md5WithRSAEncryption", "RSA with MD5" },
362 },
363#endif /* MBEDTLS_MD5_C */
364#if defined(MBEDTLS_SHA1_C)
365 {
366 { ADD_LEN( MBEDTLS_OID_PKCS1_SHA1 ), "sha-1WithRSAEncryption", "RSA with SHA1" },
368 },
369#endif /* MBEDTLS_SHA1_C */
370#if defined(MBEDTLS_SHA256_C)
371 {
372 { ADD_LEN( MBEDTLS_OID_PKCS1_SHA224 ), "sha224WithRSAEncryption", "RSA with SHA-224" },
374 },
375 {
376 { ADD_LEN( MBEDTLS_OID_PKCS1_SHA256 ), "sha256WithRSAEncryption", "RSA with SHA-256" },
378 },
379#endif /* MBEDTLS_SHA256_C */
380#if defined(MBEDTLS_SHA512_C)
381 {
382 { ADD_LEN( MBEDTLS_OID_PKCS1_SHA384 ), "sha384WithRSAEncryption", "RSA with SHA-384" },
384 },
385 {
386 { ADD_LEN( MBEDTLS_OID_PKCS1_SHA512 ), "sha512WithRSAEncryption", "RSA with SHA-512" },
388 },
389#endif /* MBEDTLS_SHA512_C */
390#if defined(MBEDTLS_SHA1_C)
391 {
392 { ADD_LEN( MBEDTLS_OID_RSA_SHA_OBS ), "sha-1WithRSAEncryption", "RSA with SHA1" },
394 },
395#endif /* MBEDTLS_SHA1_C */
396#endif /* MBEDTLS_RSA_C */
397#if defined(MBEDTLS_ECDSA_C)
398#if defined(MBEDTLS_SHA1_C)
399 {
400 { ADD_LEN( MBEDTLS_OID_ECDSA_SHA1 ), "ecdsa-with-SHA1", "ECDSA with SHA1" },
402 },
403#endif /* MBEDTLS_SHA1_C */
404#if defined(MBEDTLS_SHA256_C)
405 {
406 { ADD_LEN( MBEDTLS_OID_ECDSA_SHA224 ), "ecdsa-with-SHA224", "ECDSA with SHA224" },
408 },
409 {
410 { ADD_LEN( MBEDTLS_OID_ECDSA_SHA256 ), "ecdsa-with-SHA256", "ECDSA with SHA256" },
412 },
413#endif /* MBEDTLS_SHA256_C */
414#if defined(MBEDTLS_SHA512_C)
415 {
416 { ADD_LEN( MBEDTLS_OID_ECDSA_SHA384 ), "ecdsa-with-SHA384", "ECDSA with SHA384" },
418 },
419 {
420 { ADD_LEN( MBEDTLS_OID_ECDSA_SHA512 ), "ecdsa-with-SHA512", "ECDSA with SHA512" },
422 },
423#endif /* MBEDTLS_SHA512_C */
424#endif /* MBEDTLS_ECDSA_C */
425#if defined(MBEDTLS_RSA_C)
426 {
427 { ADD_LEN( MBEDTLS_OID_RSASSA_PSS ), "RSASSA-PSS", "RSASSA-PSS" },
429 },
430#endif /* MBEDTLS_RSA_C */
431 {
432 { NULL, 0, NULL, NULL },
434 },
435};
436
437FN_OID_TYPED_FROM_ASN1(oid_sig_alg_t, sig_alg, oid_sig_alg)
438FN_OID_GET_DESCRIPTOR_ATTR1(mbedtls_oid_get_sig_alg_desc, oid_sig_alg_t, sig_alg, const char *, description)
439FN_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)
440FN_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)
441#endif /* MBEDTLS_MD_C */
442
443/*
444 * For PublicKeyInfo (PKCS1, RFC 5480)
445 */
446typedef struct {
448 mbedtls_pk_type_t pk_alg;
449} oid_pk_alg_t;
450
451static const oid_pk_alg_t oid_pk_alg[] =
452{
453 {
454 { ADD_LEN( MBEDTLS_OID_PKCS1_RSA ), "rsaEncryption", "RSA" },
456 },
457 {
458 { ADD_LEN( MBEDTLS_OID_EC_ALG_UNRESTRICTED ), "id-ecPublicKey", "Generic EC key" },
460 },
461 {
462 { ADD_LEN( MBEDTLS_OID_EC_ALG_ECDH ), "id-ecDH", "EC key for ECDH" },
464 },
465 {
466 { NULL, 0, NULL, NULL },
468 },
469};
470
471FN_OID_TYPED_FROM_ASN1(oid_pk_alg_t, pk_alg, oid_pk_alg)
472FN_OID_GET_ATTR1(mbedtls_oid_get_pk_alg, oid_pk_alg_t, pk_alg, mbedtls_pk_type_t, pk_alg)
473FN_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)
474
475#if defined(MBEDTLS_ECP_C)
476/*
477 * For namedCurve (RFC 5480)
478 */
479typedef struct {
482} oid_ecp_grp_t;
483
484static const oid_ecp_grp_t oid_ecp_grp[] =
485{
486#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
487 {
488 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP192R1 ), "secp192r1", "secp192r1" },
490 },
491#endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
492#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
493 {
494 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP224R1 ), "secp224r1", "secp224r1" },
496 },
497#endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */
498#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
499 {
500 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP256R1 ), "secp256r1", "secp256r1" },
502 },
503#endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */
504#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
505 {
506 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP384R1 ), "secp384r1", "secp384r1" },
508 },
509#endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */
510#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
511 {
512 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP521R1 ), "secp521r1", "secp521r1" },
514 },
515#endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */
516#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
517 {
518 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP192K1 ), "secp192k1", "secp192k1" },
520 },
521#endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */
522#if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
523 {
524 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP224K1 ), "secp224k1", "secp224k1" },
526 },
527#endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */
528#if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
529 {
530 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP256K1 ), "secp256k1", "secp256k1" },
532 },
533#endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
534#if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
535 {
536 { ADD_LEN( MBEDTLS_OID_EC_GRP_BP256R1 ), "brainpoolP256r1","brainpool256r1" },
538 },
539#endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */
540#if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
541 {
542 { ADD_LEN( MBEDTLS_OID_EC_GRP_BP384R1 ), "brainpoolP384r1","brainpool384r1" },
544 },
545#endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */
546#if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
547 {
548 { ADD_LEN( MBEDTLS_OID_EC_GRP_BP512R1 ), "brainpoolP512r1","brainpool512r1" },
550 },
551#endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */
552 {
553 { NULL, 0, NULL, NULL },
555 },
556};
557
558FN_OID_TYPED_FROM_ASN1(oid_ecp_grp_t, grp_id, oid_ecp_grp)
559FN_OID_GET_ATTR1(mbedtls_oid_get_ec_grp, oid_ecp_grp_t, grp_id, mbedtls_ecp_group_id, grp_id)
560FN_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)
561#endif /* MBEDTLS_ECP_C */
562
563#if defined(MBEDTLS_CIPHER_C)
564/*
565 * For PKCS#5 PBES2 encryption algorithm
566 */
567typedef struct {
569 mbedtls_cipher_type_t cipher_alg;
570} oid_cipher_alg_t;
571
572static const oid_cipher_alg_t oid_cipher_alg[] =
573{
574 {
575 { ADD_LEN( MBEDTLS_OID_DES_CBC ), "desCBC", "DES-CBC" },
577 },
578 {
579 { ADD_LEN( MBEDTLS_OID_DES_EDE3_CBC ), "des-ede3-cbc", "DES-EDE3-CBC" },
581 },
582 {
583 { NULL, 0, NULL, NULL },
585 },
586};
587
588FN_OID_TYPED_FROM_ASN1(oid_cipher_alg_t, cipher_alg, oid_cipher_alg)
589FN_OID_GET_ATTR1(mbedtls_oid_get_cipher_alg, oid_cipher_alg_t, cipher_alg, mbedtls_cipher_type_t, cipher_alg)
590#endif /* MBEDTLS_CIPHER_C */
591
592#if defined(MBEDTLS_MD_C)
593/*
594 * For digestAlgorithm
595 */
596typedef struct {
598 mbedtls_md_type_t md_alg;
599} oid_md_alg_t;
600
601static const oid_md_alg_t oid_md_alg[] =
602{
603#if defined(MBEDTLS_MD2_C)
604 {
605 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_MD2 ), "id-md2", "MD2" },
607 },
608#endif /* MBEDTLS_MD2_C */
609#if defined(MBEDTLS_MD4_C)
610 {
611 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_MD4 ), "id-md4", "MD4" },
613 },
614#endif /* MBEDTLS_MD4_C */
615#if defined(MBEDTLS_MD5_C)
616 {
617 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_MD5 ), "id-md5", "MD5" },
619 },
620#endif /* MBEDTLS_MD5_C */
621#if defined(MBEDTLS_SHA1_C)
622 {
623 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA1 ), "id-sha1", "SHA-1" },
625 },
626#endif /* MBEDTLS_SHA1_C */
627#if defined(MBEDTLS_SHA256_C)
628 {
629 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA224 ), "id-sha224", "SHA-224" },
631 },
632 {
633 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA256 ), "id-sha256", "SHA-256" },
635 },
636#endif /* MBEDTLS_SHA256_C */
637#if defined(MBEDTLS_SHA512_C)
638 {
639 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA384 ), "id-sha384", "SHA-384" },
641 },
642 {
643 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA512 ), "id-sha512", "SHA-512" },
645 },
646#endif /* MBEDTLS_SHA512_C */
647 {
648 { NULL, 0, NULL, NULL },
650 },
651};
652
653FN_OID_TYPED_FROM_ASN1(oid_md_alg_t, md_alg, oid_md_alg)
654FN_OID_GET_ATTR1(mbedtls_oid_get_md_alg, oid_md_alg_t, md_alg, mbedtls_md_type_t, md_alg)
655FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_md, oid_md_alg_t, oid_md_alg, mbedtls_md_type_t, md_alg)
656
657/*
658 * For HMAC digestAlgorithm
659 */
660typedef struct {
663} oid_md_hmac_t;
664
665static const oid_md_hmac_t oid_md_hmac[] =
666{
667#if defined(MBEDTLS_SHA1_C)
668 {
669 { ADD_LEN( MBEDTLS_OID_HMAC_SHA1 ), "hmacSHA1", "HMAC-SHA-1" },
671 },
672#endif /* MBEDTLS_SHA1_C */
673#if defined(MBEDTLS_SHA256_C)
674 {
675 { ADD_LEN( MBEDTLS_OID_HMAC_SHA224 ), "hmacSHA224", "HMAC-SHA-224" },
677 },
678 {
679 { ADD_LEN( MBEDTLS_OID_HMAC_SHA256 ), "hmacSHA256", "HMAC-SHA-256" },
681 },
682#endif /* MBEDTLS_SHA256_C */
683#if defined(MBEDTLS_SHA512_C)
684 {
685 { ADD_LEN( MBEDTLS_OID_HMAC_SHA384 ), "hmacSHA384", "HMAC-SHA-384" },
687 },
688 {
689 { ADD_LEN( MBEDTLS_OID_HMAC_SHA512 ), "hmacSHA512", "HMAC-SHA-512" },
691 },
692#endif /* MBEDTLS_SHA512_C */
693 {
694 { NULL, 0, NULL, NULL },
696 },
697};
698
699FN_OID_TYPED_FROM_ASN1(oid_md_hmac_t, md_hmac, oid_md_hmac)
700FN_OID_GET_ATTR1(mbedtls_oid_get_md_hmac, oid_md_hmac_t, md_hmac, mbedtls_md_type_t, md_hmac)
701#endif /* MBEDTLS_MD_C */
702
703#if defined(MBEDTLS_PKCS12_C)
704/*
705 * For PKCS#12 PBEs
706 */
707typedef struct {
709 mbedtls_md_type_t md_alg;
710 mbedtls_cipher_type_t cipher_alg;
711} oid_pkcs12_pbe_alg_t;
712
713static const oid_pkcs12_pbe_alg_t oid_pkcs12_pbe_alg[] =
714{
715 {
716 { ADD_LEN( MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC ), "pbeWithSHAAnd3-KeyTripleDES-CBC", "PBE with SHA1 and 3-Key 3DES" },
718 },
719 {
720 { ADD_LEN( MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC ), "pbeWithSHAAnd2-KeyTripleDES-CBC", "PBE with SHA1 and 2-Key 3DES" },
722 },
723 {
724 { NULL, 0, NULL, NULL },
726 },
727};
728
729FN_OID_TYPED_FROM_ASN1(oid_pkcs12_pbe_alg_t, pkcs12_pbe_alg, oid_pkcs12_pbe_alg)
730FN_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)
731#endif /* MBEDTLS_PKCS12_C */
732
733#define OID_SAFE_SNPRINTF \
734 do { \
735 if( ret < 0 || (size_t) ret >= n ) \
736 return( MBEDTLS_ERR_OID_BUF_TOO_SMALL ); \
737 \
738 n -= (size_t) ret; \
739 p += (size_t) ret; \
740 } while( 0 )
741
742/* Return the x.y.z.... style numeric string for the given OID */
743int mbedtls_oid_get_numeric_string( char *buf, size_t size,
744 const mbedtls_asn1_buf *oid )
745{
746 int ret;
747 size_t i, n;
748 unsigned int value;
749 char *p;
750
751 p = buf;
752 n = size;
753
754 /* First byte contains first two dots */
755 if( oid->len > 0 )
756 {
757 ret = mbedtls_snprintf( p, n, "%d.%d", oid->p[0] / 40, oid->p[0] % 40 );
758 OID_SAFE_SNPRINTF;
759 }
760
761 value = 0;
762 for( i = 1; i < oid->len; i++ )
763 {
764 /* Prevent overflow in value. */
765 if( ( ( value << 7 ) >> 7 ) != value )
767
768 value <<= 7;
769 value += oid->p[i] & 0x7F;
770
771 if( !( oid->p[i] & 0x80 ) )
772 {
773 /* Last byte */
774 ret = mbedtls_snprintf( p, n, ".%d", value );
775 OID_SAFE_SNPRINTF;
776 value = 0;
777 }
778 }
779
780 return( (int) ( size - n ) );
781}
782
783#endif /* MBEDTLS_OID_C */
const WCHAR * short_name
Definition: reg.c:29
mbedtls_cipher_type_t
Supported {cipher type, cipher mode} pairs.
Definition: cipher.h:129
@ MBEDTLS_CIPHER_DES_EDE3_CBC
Definition: cipher.h:167
@ MBEDTLS_CIPHER_DES_CBC
Definition: cipher.h:163
@ MBEDTLS_CIPHER_NONE
Definition: cipher.h:130
@ MBEDTLS_CIPHER_DES_EDE_CBC
Definition: cipher.h:165
#define md_hmac
Definition: compat-1.3.h:2051
#define NULL
Definition: types.h:112
mbedtls_ecp_group_id
Definition: ecp.h:103
@ MBEDTLS_ECP_DP_SECP192K1
Definition: ecp.h:114
@ MBEDTLS_ECP_DP_SECP384R1
Definition: ecp.h:108
@ MBEDTLS_ECP_DP_NONE
Definition: ecp.h:104
@ MBEDTLS_ECP_DP_SECP256K1
Definition: ecp.h:116
@ MBEDTLS_ECP_DP_BP512R1
Definition: ecp.h:112
@ MBEDTLS_ECP_DP_SECP224R1
Definition: ecp.h:106
@ MBEDTLS_ECP_DP_SECP521R1
Definition: ecp.h:109
@ MBEDTLS_ECP_DP_BP384R1
Definition: ecp.h:111
@ MBEDTLS_ECP_DP_SECP224K1
Definition: ecp.h:115
@ MBEDTLS_ECP_DP_BP256R1
Definition: ecp.h:110
@ MBEDTLS_ECP_DP_SECP192R1
Definition: ecp.h:105
@ MBEDTLS_ECP_DP_SECP256R1
Definition: ecp.h:107
GLsizeiptr size
Definition: glext.h:5919
GLdouble n
Definition: glext.h:7729
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
size_t len
Definition: asn1.h:162
unsigned char * p
Definition: asn1.h:163
#define MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE
Definition: x509.h:182
#define MBEDTLS_X509_EXT_BASIC_CONSTRAINTS
Definition: x509.h:179
#define MBEDTLS_X509_EXT_KEY_USAGE
Definition: x509.h:173
#define MBEDTLS_X509_EXT_SUBJECT_ALT_NAME
Definition: x509.h:176
#define MBEDTLS_X509_EXT_NS_CERT_TYPE
Definition: x509.h:187
mbedtls_md_type_t
Supported message digests.
Definition: md.h:83
@ MBEDTLS_MD_SHA512
Definition: md.h:92
@ MBEDTLS_MD_MD5
Definition: md.h:87
@ MBEDTLS_MD_SHA384
Definition: md.h:91
@ MBEDTLS_MD_NONE
Definition: md.h:84
@ MBEDTLS_MD_SHA256
Definition: md.h:90
@ MBEDTLS_MD_SHA224
Definition: md.h:89
@ MBEDTLS_MD_SHA1
Definition: md.h:88
@ MBEDTLS_MD_MD4
Definition: md.h:86
@ MBEDTLS_MD_MD2
Definition: md.h:85
Object Identifier (OID) database.
#define MBEDTLS_OID_DIGEST_ALG_SHA384
Definition: oid.h:252
#define MBEDTLS_OID_CODE_SIGNING
Definition: oid.h:206
int mbedtls_oid_get_attr_short_name(const mbedtls_asn1_buf *oid, const char **short_name)
Translate an X.509 attribute type OID into the short name (e.g. the OID for an X520 Common Name into ...
#define MBEDTLS_OID_SUBJECT_ALT_NAME
Definition: oid.h:166
#define MBEDTLS_OID_PKCS1_RSA
Definition: oid.h:224
#define MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC
Definition: oid.h:315
#define MBEDTLS_OID_AT_GENERATION_QUALIFIER
Definition: oid.h:151
#define MBEDTLS_OID_DIGEST_ALG_SHA256
Definition: oid.h:250
#define MBEDTLS_OID_DIGEST_ALG_SHA1
Definition: oid.h:248
#define MBEDTLS_OID_EC_GRP_SECP521R1
Definition: oid.h:354
#define MBEDTLS_OID_EC_GRP_SECP224R1
Definition: oid.h:342
int mbedtls_oid_get_cipher_alg(const mbedtls_asn1_buf *oid, mbedtls_cipher_type_t *cipher_alg)
Translate encryption algorithm OID into cipher_type.
#define MBEDTLS_OID_EXTENDED_KEY_USAGE
Definition: oid.h:172
#define MBEDTLS_OID_AT_POSTAL_ADDRESS
Definition: oid.h:147
#define MBEDTLS_ERR_OID_BUF_TOO_SMALL
Definition: oid.h:76
#define MBEDTLS_OID_AT_SERIAL_NUMBER
Definition: oid.h:140
#define MBEDTLS_OID_AT_DN_QUALIFIER
Definition: oid.h:153
#define MBEDTLS_OID_AT_UNIQUE_IDENTIFIER
Definition: oid.h:152
#define MBEDTLS_OID_PKCS1_SHA384
Definition: oid.h:231
#define MBEDTLS_OID_EC_ALG_ECDH
Definition: oid.h:330
#define MBEDTLS_OID_EC_GRP_SECP256K1
Definition: oid.h:366
#define MBEDTLS_OID_EC_ALG_UNRESTRICTED
Definition: oid.h:325
#define MBEDTLS_OID_PKCS1_MD4
Definition: oid.h:226
int mbedtls_oid_get_pk_alg(const mbedtls_asn1_buf *oid, mbedtls_pk_type_t *pk_alg)
Translate PublicKeyAlgorithm OID into pk_type.
#define MBEDTLS_OID_AT_INITIALS
Definition: oid.h:150
#define MBEDTLS_OID_CLIENT_AUTH
Definition: oid.h:205
#define MBEDTLS_OID_DIGEST_ALG_MD5
Definition: oid.h:247
#define MBEDTLS_OID_DIGEST_ALG_SHA512
Definition: oid.h:254
#define MBEDTLS_OID_ECDSA_SHA384
Definition: oid.h:417
#define MBEDTLS_OID_EC_GRP_SECP384R1
Definition: oid.h:350
#define MBEDTLS_OID_AT_LOCALITY
Definition: oid.h:142
#define MBEDTLS_OID_DIGEST_ALG_MD2
Definition: oid.h:245
#define MBEDTLS_OID_BASIC_CONSTRAINTS
Definition: oid.h:169
int mbedtls_oid_get_extended_key_usage(const mbedtls_asn1_buf *oid, const char **desc)
Translate Extended Key Usage OID into description.
#define MBEDTLS_OID_RSA_SHA_OBS
Definition: oid.h:234
#define MBEDTLS_OID_AT_POSTAL_CODE
Definition: oid.h:148
#define MBEDTLS_OID_EC_GRP_SECP192K1
Definition: oid.h:358
#define MBEDTLS_OID_KEY_USAGE
Definition: oid.h:163
int mbedtls_oid_get_oid_by_md(mbedtls_md_type_t md_alg, const char **oid, size_t *olen)
Translate md_type into hash algorithm OID.
#define MBEDTLS_OID_PKCS1_MD2
Definition: oid.h:225
#define MBEDTLS_OID_AT_SUR_NAME
Definition: oid.h:139
#define MBEDTLS_OID_EC_GRP_BP384R1
Definition: oid.h:380
#define MBEDTLS_OID_EC_GRP_SECP224K1
Definition: oid.h:362
#define MBEDTLS_OID_AT_STATE
Definition: oid.h:143
#define MBEDTLS_OID_DES_EDE3_CBC
Definition: oid.h:270
#define MBEDTLS_OID_HMAC_SHA1
Definition: oid.h:256
int mbedtls_oid_get_ec_grp(const mbedtls_asn1_buf *oid, mbedtls_ecp_group_id *grp_id)
Translate NamedCurve OID into an EC group identifier.
#define MBEDTLS_OID_PKCS9_EMAIL
Definition: oid.h:236
#define MBEDTLS_OID_NS_CERT_TYPE
Definition: oid.h:181
#define MBEDTLS_OID_PKCS1_MD5
Definition: oid.h:227
int mbedtls_oid_get_oid_by_sig_alg(mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg, const char **oid, size_t *olen)
Translate md_type and pk_type into SignatureAlgorithm OID.
int mbedtls_oid_get_x509_ext_type(const mbedtls_asn1_buf *oid, int *ext_type)
Translate an X.509 extension OID into local values.
#define MBEDTLS_OID_EMAIL_PROTECTION
Definition: oid.h:207
#define MBEDTLS_OID_DIGEST_ALG_SHA224
Definition: oid.h:249
#define MBEDTLS_OID_DIGEST_ALG_MD4
Definition: oid.h:246
#define MBEDTLS_OID_AT_TITLE
Definition: oid.h:146
#define MBEDTLS_OID_AT_COUNTRY
Definition: oid.h:141
#define MBEDTLS_OID_PKCS1_SHA256
Definition: oid.h:230
#define MBEDTLS_OID_TIME_STAMPING
Definition: oid.h:208
#define MBEDTLS_OID_HMAC_SHA512
Definition: oid.h:264
#define MBEDTLS_OID_ECDSA_SHA512
Definition: oid.h:422
int mbedtls_oid_get_oid_by_ec_grp(mbedtls_ecp_group_id grp_id, const char **oid, size_t *olen)
Translate EC group identifier into NamedCurve OID.
#define MBEDTLS_OID_HMAC_SHA256
Definition: oid.h:260
#define MBEDTLS_OID_HMAC_SHA224
Definition: oid.h:258
#define MBEDTLS_OID_AT_PSEUDONYM
Definition: oid.h:154
#define MBEDTLS_OID_OCSP_SIGNING
Definition: oid.h:209
#define MBEDTLS_OID_RSASSA_PSS
Definition: oid.h:239
#define MBEDTLS_OID_SERVER_AUTH
Definition: oid.h:204
int mbedtls_oid_get_md_hmac(const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_hmac)
Translate hmac algorithm OID into md_type.
#define MBEDTLS_OID_HMAC_SHA384
Definition: oid.h:262
#define MBEDTLS_OID_DES_CBC
Definition: oid.h:269
#define MBEDTLS_OID_EC_GRP_BP512R1
Definition: oid.h:383
int mbedtls_oid_get_sig_alg(const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg)
Translate SignatureAlgorithm OID into md_type and pk_type.
#define MBEDTLS_OID_EC_GRP_SECP256R1
Definition: oid.h:346
#define MBEDTLS_OID_EC_GRP_SECP192R1
Definition: oid.h:338
#define MBEDTLS_OID_DOMAIN_COMPONENT
Definition: oid.h:156
int mbedtls_oid_get_md_alg(const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg)
Translate hash algorithm OID into md_type.
#define MBEDTLS_OID_AT_GIVEN_NAME
Definition: oid.h:149
#define MBEDTLS_OID_AT_ORGANIZATION
Definition: oid.h:144
#define MBEDTLS_OID_ECDSA_SHA1
Definition: oid.h:402
#define MBEDTLS_OID_ECDSA_SHA256
Definition: oid.h:412
int mbedtls_oid_get_sig_alg_desc(const mbedtls_asn1_buf *oid, const char **desc)
Translate SignatureAlgorithm OID into description.
#define MBEDTLS_OID_PKCS1_SHA1
Definition: oid.h:228
#define MBEDTLS_OID_ECDSA_SHA224
Definition: oid.h:407
#define MBEDTLS_OID_AT_CN
Definition: oid.h:138
#define MBEDTLS_OID_PKCS1_SHA512
Definition: oid.h:232
int mbedtls_oid_get_oid_by_pk_alg(mbedtls_pk_type_t pk_alg, const char **oid, size_t *olen)
Translate pk_type into PublicKeyAlgorithm OID.
#define MBEDTLS_OID_PKCS1_SHA224
Definition: oid.h:229
#define MBEDTLS_OID_AT_ORG_UNIT
Definition: oid.h:145
int mbedtls_oid_get_pkcs12_pbe_alg(const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg, mbedtls_cipher_type_t *cipher_alg)
Translate PKCS#12 PBE algorithm OID into md_type and cipher_type.
#define MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC
Definition: oid.h:314
#define MBEDTLS_OID_EC_GRP_BP256R1
Definition: oid.h:377
int mbedtls_oid_get_numeric_string(char *buf, size_t size, const mbedtls_asn1_buf *oid)
Translate an ASN.1 OID into its numeric representation (e.g. "\x2A\x86\x48\x86\xF7\x0D" into "1....
mbedtls_pk_type_t
Public key types.
Definition: pk.h:103
@ MBEDTLS_PK_NONE
Definition: pk.h:104
@ MBEDTLS_PK_ECDSA
Definition: pk.h:108
@ MBEDTLS_PK_RSASSA_PSS
Definition: pk.h:110
@ MBEDTLS_PK_RSA
Definition: pk.h:105
@ MBEDTLS_PK_ECKEY_DH
Definition: pk.h:107
@ MBEDTLS_PK_ECKEY
Definition: pk.h:106
This file provides an API for the RSA public-key cryptosystem.
descriptor
Definition: scsi.h:3951
Configuration options (set of defines)
This file contains the definitions and functions of the Mbed TLS platform abstraction layer.
#define mbedtls_snprintf
Definition: platform.h:254
Base OID descriptor structure.
Definition: oid.h:432
Definition: pdh_main.c:94
int ret
const char * description
Definition: directx.c:2497
X.509 generic defines and structures.