Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcozecchini 0:9fca2b23d0ba 1 /**
marcozecchini 0:9fca2b23d0ba 2 * \file oid.c
marcozecchini 0:9fca2b23d0ba 3 *
marcozecchini 0:9fca2b23d0ba 4 * \brief Object Identifier (OID) database
marcozecchini 0:9fca2b23d0ba 5 *
marcozecchini 0:9fca2b23d0ba 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
marcozecchini 0:9fca2b23d0ba 7 * SPDX-License-Identifier: Apache-2.0
marcozecchini 0:9fca2b23d0ba 8 *
marcozecchini 0:9fca2b23d0ba 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
marcozecchini 0:9fca2b23d0ba 10 * not use this file except in compliance with the License.
marcozecchini 0:9fca2b23d0ba 11 * You may obtain a copy of the License at
marcozecchini 0:9fca2b23d0ba 12 *
marcozecchini 0:9fca2b23d0ba 13 * http://www.apache.org/licenses/LICENSE-2.0
marcozecchini 0:9fca2b23d0ba 14 *
marcozecchini 0:9fca2b23d0ba 15 * Unless required by applicable law or agreed to in writing, software
marcozecchini 0:9fca2b23d0ba 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
marcozecchini 0:9fca2b23d0ba 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
marcozecchini 0:9fca2b23d0ba 18 * See the License for the specific language governing permissions and
marcozecchini 0:9fca2b23d0ba 19 * limitations under the License.
marcozecchini 0:9fca2b23d0ba 20 *
marcozecchini 0:9fca2b23d0ba 21 * This file is part of mbed TLS (https://tls.mbed.org)
marcozecchini 0:9fca2b23d0ba 22 */
marcozecchini 0:9fca2b23d0ba 23
marcozecchini 0:9fca2b23d0ba 24 #if !defined(MBEDTLS_CONFIG_FILE)
marcozecchini 0:9fca2b23d0ba 25 #include "mbedtls/config.h"
marcozecchini 0:9fca2b23d0ba 26 #else
marcozecchini 0:9fca2b23d0ba 27 #include MBEDTLS_CONFIG_FILE
marcozecchini 0:9fca2b23d0ba 28 #endif
marcozecchini 0:9fca2b23d0ba 29
marcozecchini 0:9fca2b23d0ba 30 #if defined(MBEDTLS_OID_C)
marcozecchini 0:9fca2b23d0ba 31
marcozecchini 0:9fca2b23d0ba 32 #include "mbedtls/oid.h"
marcozecchini 0:9fca2b23d0ba 33 #include "mbedtls/rsa.h"
marcozecchini 0:9fca2b23d0ba 34
marcozecchini 0:9fca2b23d0ba 35 #include <stdio.h>
marcozecchini 0:9fca2b23d0ba 36 #include <string.h>
marcozecchini 0:9fca2b23d0ba 37
marcozecchini 0:9fca2b23d0ba 38 #if defined(MBEDTLS_PLATFORM_C)
marcozecchini 0:9fca2b23d0ba 39 #include "mbedtls/platform.h"
marcozecchini 0:9fca2b23d0ba 40 #else
marcozecchini 0:9fca2b23d0ba 41 #define mbedtls_snprintf snprintf
marcozecchini 0:9fca2b23d0ba 42 #endif
marcozecchini 0:9fca2b23d0ba 43
marcozecchini 0:9fca2b23d0ba 44 #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
marcozecchini 0:9fca2b23d0ba 45 #include "mbedtls/x509.h"
marcozecchini 0:9fca2b23d0ba 46 #endif
marcozecchini 0:9fca2b23d0ba 47
marcozecchini 0:9fca2b23d0ba 48 /*
marcozecchini 0:9fca2b23d0ba 49 * Macro to automatically add the size of #define'd OIDs
marcozecchini 0:9fca2b23d0ba 50 */
marcozecchini 0:9fca2b23d0ba 51 #define ADD_LEN(s) s, MBEDTLS_OID_SIZE(s)
marcozecchini 0:9fca2b23d0ba 52
marcozecchini 0:9fca2b23d0ba 53 /*
marcozecchini 0:9fca2b23d0ba 54 * Macro to generate an internal function for oid_XXX_from_asn1() (used by
marcozecchini 0:9fca2b23d0ba 55 * the other functions)
marcozecchini 0:9fca2b23d0ba 56 */
marcozecchini 0:9fca2b23d0ba 57 #define FN_OID_TYPED_FROM_ASN1( TYPE_T, NAME, LIST ) \
marcozecchini 0:9fca2b23d0ba 58 static const TYPE_T * oid_ ## NAME ## _from_asn1( const mbedtls_asn1_buf *oid ) \
marcozecchini 0:9fca2b23d0ba 59 { \
marcozecchini 0:9fca2b23d0ba 60 const TYPE_T *p = LIST; \
marcozecchini 0:9fca2b23d0ba 61 const mbedtls_oid_descriptor_t *cur = (const mbedtls_oid_descriptor_t *) p; \
marcozecchini 0:9fca2b23d0ba 62 if( p == NULL || oid == NULL ) return( NULL ); \
marcozecchini 0:9fca2b23d0ba 63 while( cur->asn1 != NULL ) { \
marcozecchini 0:9fca2b23d0ba 64 if( cur->asn1_len == oid->len && \
marcozecchini 0:9fca2b23d0ba 65 memcmp( cur->asn1, oid->p, oid->len ) == 0 ) { \
marcozecchini 0:9fca2b23d0ba 66 return( p ); \
marcozecchini 0:9fca2b23d0ba 67 } \
marcozecchini 0:9fca2b23d0ba 68 p++; \
marcozecchini 0:9fca2b23d0ba 69 cur = (const mbedtls_oid_descriptor_t *) p; \
marcozecchini 0:9fca2b23d0ba 70 } \
marcozecchini 0:9fca2b23d0ba 71 return( NULL ); \
marcozecchini 0:9fca2b23d0ba 72 }
marcozecchini 0:9fca2b23d0ba 73
marcozecchini 0:9fca2b23d0ba 74 /*
marcozecchini 0:9fca2b23d0ba 75 * Macro to generate a function for retrieving a single attribute from the
marcozecchini 0:9fca2b23d0ba 76 * descriptor of an mbedtls_oid_descriptor_t wrapper.
marcozecchini 0:9fca2b23d0ba 77 */
marcozecchini 0:9fca2b23d0ba 78 #define FN_OID_GET_DESCRIPTOR_ATTR1(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1) \
marcozecchini 0:9fca2b23d0ba 79 int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \
marcozecchini 0:9fca2b23d0ba 80 { \
marcozecchini 0:9fca2b23d0ba 81 const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \
marcozecchini 0:9fca2b23d0ba 82 if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \
marcozecchini 0:9fca2b23d0ba 83 *ATTR1 = data->descriptor.ATTR1; \
marcozecchini 0:9fca2b23d0ba 84 return( 0 ); \
marcozecchini 0:9fca2b23d0ba 85 }
marcozecchini 0:9fca2b23d0ba 86
marcozecchini 0:9fca2b23d0ba 87 /*
marcozecchini 0:9fca2b23d0ba 88 * Macro to generate a function for retrieving a single attribute from an
marcozecchini 0:9fca2b23d0ba 89 * mbedtls_oid_descriptor_t wrapper.
marcozecchini 0:9fca2b23d0ba 90 */
marcozecchini 0:9fca2b23d0ba 91 #define FN_OID_GET_ATTR1(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1) \
marcozecchini 0:9fca2b23d0ba 92 int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \
marcozecchini 0:9fca2b23d0ba 93 { \
marcozecchini 0:9fca2b23d0ba 94 const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \
marcozecchini 0:9fca2b23d0ba 95 if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \
marcozecchini 0:9fca2b23d0ba 96 *ATTR1 = data->ATTR1; \
marcozecchini 0:9fca2b23d0ba 97 return( 0 ); \
marcozecchini 0:9fca2b23d0ba 98 }
marcozecchini 0:9fca2b23d0ba 99
marcozecchini 0:9fca2b23d0ba 100 /*
marcozecchini 0:9fca2b23d0ba 101 * Macro to generate a function for retrieving two attributes from an
marcozecchini 0:9fca2b23d0ba 102 * mbedtls_oid_descriptor_t wrapper.
marcozecchini 0:9fca2b23d0ba 103 */
marcozecchini 0:9fca2b23d0ba 104 #define FN_OID_GET_ATTR2(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1, \
marcozecchini 0:9fca2b23d0ba 105 ATTR2_TYPE, ATTR2) \
marcozecchini 0:9fca2b23d0ba 106 int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1, ATTR2_TYPE * ATTR2 ) \
marcozecchini 0:9fca2b23d0ba 107 { \
marcozecchini 0:9fca2b23d0ba 108 const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \
marcozecchini 0:9fca2b23d0ba 109 if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \
marcozecchini 0:9fca2b23d0ba 110 *ATTR1 = data->ATTR1; \
marcozecchini 0:9fca2b23d0ba 111 *ATTR2 = data->ATTR2; \
marcozecchini 0:9fca2b23d0ba 112 return( 0 ); \
marcozecchini 0:9fca2b23d0ba 113 }
marcozecchini 0:9fca2b23d0ba 114
marcozecchini 0:9fca2b23d0ba 115 /*
marcozecchini 0:9fca2b23d0ba 116 * Macro to generate a function for retrieving the OID based on a single
marcozecchini 0:9fca2b23d0ba 117 * attribute from a mbedtls_oid_descriptor_t wrapper.
marcozecchini 0:9fca2b23d0ba 118 */
marcozecchini 0:9fca2b23d0ba 119 #define FN_OID_GET_OID_BY_ATTR1(FN_NAME, TYPE_T, LIST, ATTR1_TYPE, ATTR1) \
marcozecchini 0:9fca2b23d0ba 120 int FN_NAME( ATTR1_TYPE ATTR1, const char **oid, size_t *olen ) \
marcozecchini 0:9fca2b23d0ba 121 { \
marcozecchini 0:9fca2b23d0ba 122 const TYPE_T *cur = LIST; \
marcozecchini 0:9fca2b23d0ba 123 while( cur->descriptor.asn1 != NULL ) { \
marcozecchini 0:9fca2b23d0ba 124 if( cur->ATTR1 == ATTR1 ) { \
marcozecchini 0:9fca2b23d0ba 125 *oid = cur->descriptor.asn1; \
marcozecchini 0:9fca2b23d0ba 126 *olen = cur->descriptor.asn1_len; \
marcozecchini 0:9fca2b23d0ba 127 return( 0 ); \
marcozecchini 0:9fca2b23d0ba 128 } \
marcozecchini 0:9fca2b23d0ba 129 cur++; \
marcozecchini 0:9fca2b23d0ba 130 } \
marcozecchini 0:9fca2b23d0ba 131 return( MBEDTLS_ERR_OID_NOT_FOUND ); \
marcozecchini 0:9fca2b23d0ba 132 }
marcozecchini 0:9fca2b23d0ba 133
marcozecchini 0:9fca2b23d0ba 134 /*
marcozecchini 0:9fca2b23d0ba 135 * Macro to generate a function for retrieving the OID based on two
marcozecchini 0:9fca2b23d0ba 136 * attributes from a mbedtls_oid_descriptor_t wrapper.
marcozecchini 0:9fca2b23d0ba 137 */
marcozecchini 0:9fca2b23d0ba 138 #define FN_OID_GET_OID_BY_ATTR2(FN_NAME, TYPE_T, LIST, ATTR1_TYPE, ATTR1, \
marcozecchini 0:9fca2b23d0ba 139 ATTR2_TYPE, ATTR2) \
marcozecchini 0:9fca2b23d0ba 140 int FN_NAME( ATTR1_TYPE ATTR1, ATTR2_TYPE ATTR2, const char **oid , \
marcozecchini 0:9fca2b23d0ba 141 size_t *olen ) \
marcozecchini 0:9fca2b23d0ba 142 { \
marcozecchini 0:9fca2b23d0ba 143 const TYPE_T *cur = LIST; \
marcozecchini 0:9fca2b23d0ba 144 while( cur->descriptor.asn1 != NULL ) { \
marcozecchini 0:9fca2b23d0ba 145 if( cur->ATTR1 == ATTR1 && cur->ATTR2 == ATTR2 ) { \
marcozecchini 0:9fca2b23d0ba 146 *oid = cur->descriptor.asn1; \
marcozecchini 0:9fca2b23d0ba 147 *olen = cur->descriptor.asn1_len; \
marcozecchini 0:9fca2b23d0ba 148 return( 0 ); \
marcozecchini 0:9fca2b23d0ba 149 } \
marcozecchini 0:9fca2b23d0ba 150 cur++; \
marcozecchini 0:9fca2b23d0ba 151 } \
marcozecchini 0:9fca2b23d0ba 152 return( MBEDTLS_ERR_OID_NOT_FOUND ); \
marcozecchini 0:9fca2b23d0ba 153 }
marcozecchini 0:9fca2b23d0ba 154
marcozecchini 0:9fca2b23d0ba 155 #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
marcozecchini 0:9fca2b23d0ba 156 /*
marcozecchini 0:9fca2b23d0ba 157 * For X520 attribute types
marcozecchini 0:9fca2b23d0ba 158 */
marcozecchini 0:9fca2b23d0ba 159 typedef struct {
marcozecchini 0:9fca2b23d0ba 160 mbedtls_oid_descriptor_t descriptor;
marcozecchini 0:9fca2b23d0ba 161 const char *short_name;
marcozecchini 0:9fca2b23d0ba 162 } oid_x520_attr_t;
marcozecchini 0:9fca2b23d0ba 163
marcozecchini 0:9fca2b23d0ba 164 static const oid_x520_attr_t oid_x520_attr_type[] =
marcozecchini 0:9fca2b23d0ba 165 {
marcozecchini 0:9fca2b23d0ba 166 {
marcozecchini 0:9fca2b23d0ba 167 { ADD_LEN( MBEDTLS_OID_AT_CN ), "id-at-commonName", "Common Name" },
marcozecchini 0:9fca2b23d0ba 168 "CN",
marcozecchini 0:9fca2b23d0ba 169 },
marcozecchini 0:9fca2b23d0ba 170 {
marcozecchini 0:9fca2b23d0ba 171 { ADD_LEN( MBEDTLS_OID_AT_COUNTRY ), "id-at-countryName", "Country" },
marcozecchini 0:9fca2b23d0ba 172 "C",
marcozecchini 0:9fca2b23d0ba 173 },
marcozecchini 0:9fca2b23d0ba 174 {
marcozecchini 0:9fca2b23d0ba 175 { ADD_LEN( MBEDTLS_OID_AT_LOCALITY ), "id-at-locality", "Locality" },
marcozecchini 0:9fca2b23d0ba 176 "L",
marcozecchini 0:9fca2b23d0ba 177 },
marcozecchini 0:9fca2b23d0ba 178 {
marcozecchini 0:9fca2b23d0ba 179 { ADD_LEN( MBEDTLS_OID_AT_STATE ), "id-at-state", "State" },
marcozecchini 0:9fca2b23d0ba 180 "ST",
marcozecchini 0:9fca2b23d0ba 181 },
marcozecchini 0:9fca2b23d0ba 182 {
marcozecchini 0:9fca2b23d0ba 183 { ADD_LEN( MBEDTLS_OID_AT_ORGANIZATION ),"id-at-organizationName", "Organization" },
marcozecchini 0:9fca2b23d0ba 184 "O",
marcozecchini 0:9fca2b23d0ba 185 },
marcozecchini 0:9fca2b23d0ba 186 {
marcozecchini 0:9fca2b23d0ba 187 { ADD_LEN( MBEDTLS_OID_AT_ORG_UNIT ), "id-at-organizationalUnitName", "Org Unit" },
marcozecchini 0:9fca2b23d0ba 188 "OU",
marcozecchini 0:9fca2b23d0ba 189 },
marcozecchini 0:9fca2b23d0ba 190 {
marcozecchini 0:9fca2b23d0ba 191 { ADD_LEN( MBEDTLS_OID_PKCS9_EMAIL ), "emailAddress", "E-mail address" },
marcozecchini 0:9fca2b23d0ba 192 "emailAddress",
marcozecchini 0:9fca2b23d0ba 193 },
marcozecchini 0:9fca2b23d0ba 194 {
marcozecchini 0:9fca2b23d0ba 195 { ADD_LEN( MBEDTLS_OID_AT_SERIAL_NUMBER ),"id-at-serialNumber", "Serial number" },
marcozecchini 0:9fca2b23d0ba 196 "serialNumber",
marcozecchini 0:9fca2b23d0ba 197 },
marcozecchini 0:9fca2b23d0ba 198 {
marcozecchini 0:9fca2b23d0ba 199 { ADD_LEN( MBEDTLS_OID_AT_POSTAL_ADDRESS ),"id-at-postalAddress", "Postal address" },
marcozecchini 0:9fca2b23d0ba 200 "postalAddress",
marcozecchini 0:9fca2b23d0ba 201 },
marcozecchini 0:9fca2b23d0ba 202 {
marcozecchini 0:9fca2b23d0ba 203 { ADD_LEN( MBEDTLS_OID_AT_POSTAL_CODE ), "id-at-postalCode", "Postal code" },
marcozecchini 0:9fca2b23d0ba 204 "postalCode",
marcozecchini 0:9fca2b23d0ba 205 },
marcozecchini 0:9fca2b23d0ba 206 {
marcozecchini 0:9fca2b23d0ba 207 { ADD_LEN( MBEDTLS_OID_AT_SUR_NAME ), "id-at-surName", "Surname" },
marcozecchini 0:9fca2b23d0ba 208 "SN",
marcozecchini 0:9fca2b23d0ba 209 },
marcozecchini 0:9fca2b23d0ba 210 {
marcozecchini 0:9fca2b23d0ba 211 { ADD_LEN( MBEDTLS_OID_AT_GIVEN_NAME ), "id-at-givenName", "Given name" },
marcozecchini 0:9fca2b23d0ba 212 "GN",
marcozecchini 0:9fca2b23d0ba 213 },
marcozecchini 0:9fca2b23d0ba 214 {
marcozecchini 0:9fca2b23d0ba 215 { ADD_LEN( MBEDTLS_OID_AT_INITIALS ), "id-at-initials", "Initials" },
marcozecchini 0:9fca2b23d0ba 216 "initials",
marcozecchini 0:9fca2b23d0ba 217 },
marcozecchini 0:9fca2b23d0ba 218 {
marcozecchini 0:9fca2b23d0ba 219 { ADD_LEN( MBEDTLS_OID_AT_GENERATION_QUALIFIER ), "id-at-generationQualifier", "Generation qualifier" },
marcozecchini 0:9fca2b23d0ba 220 "generationQualifier",
marcozecchini 0:9fca2b23d0ba 221 },
marcozecchini 0:9fca2b23d0ba 222 {
marcozecchini 0:9fca2b23d0ba 223 { ADD_LEN( MBEDTLS_OID_AT_TITLE ), "id-at-title", "Title" },
marcozecchini 0:9fca2b23d0ba 224 "title",
marcozecchini 0:9fca2b23d0ba 225 },
marcozecchini 0:9fca2b23d0ba 226 {
marcozecchini 0:9fca2b23d0ba 227 { ADD_LEN( MBEDTLS_OID_AT_DN_QUALIFIER ),"id-at-dnQualifier", "Distinguished Name qualifier" },
marcozecchini 0:9fca2b23d0ba 228 "dnQualifier",
marcozecchini 0:9fca2b23d0ba 229 },
marcozecchini 0:9fca2b23d0ba 230 {
marcozecchini 0:9fca2b23d0ba 231 { ADD_LEN( MBEDTLS_OID_AT_PSEUDONYM ), "id-at-pseudonym", "Pseudonym" },
marcozecchini 0:9fca2b23d0ba 232 "pseudonym",
marcozecchini 0:9fca2b23d0ba 233 },
marcozecchini 0:9fca2b23d0ba 234 {
marcozecchini 0:9fca2b23d0ba 235 { ADD_LEN( MBEDTLS_OID_DOMAIN_COMPONENT ), "id-domainComponent", "Domain component" },
marcozecchini 0:9fca2b23d0ba 236 "DC",
marcozecchini 0:9fca2b23d0ba 237 },
marcozecchini 0:9fca2b23d0ba 238 {
marcozecchini 0:9fca2b23d0ba 239 { ADD_LEN( MBEDTLS_OID_AT_UNIQUE_IDENTIFIER ), "id-at-uniqueIdentifier", "Unique Identifier" },
marcozecchini 0:9fca2b23d0ba 240 "uniqueIdentifier",
marcozecchini 0:9fca2b23d0ba 241 },
marcozecchini 0:9fca2b23d0ba 242 {
marcozecchini 0:9fca2b23d0ba 243 { NULL, 0, NULL, NULL },
marcozecchini 0:9fca2b23d0ba 244 NULL,
marcozecchini 0:9fca2b23d0ba 245 }
marcozecchini 0:9fca2b23d0ba 246 };
marcozecchini 0:9fca2b23d0ba 247
marcozecchini 0:9fca2b23d0ba 248 FN_OID_TYPED_FROM_ASN1(oid_x520_attr_t, x520_attr, oid_x520_attr_type)
marcozecchini 0:9fca2b23d0ba 249 FN_OID_GET_ATTR1(mbedtls_oid_get_attr_short_name, oid_x520_attr_t, x520_attr, const char *, short_name)
marcozecchini 0:9fca2b23d0ba 250
marcozecchini 0:9fca2b23d0ba 251 /*
marcozecchini 0:9fca2b23d0ba 252 * For X509 extensions
marcozecchini 0:9fca2b23d0ba 253 */
marcozecchini 0:9fca2b23d0ba 254 typedef struct {
marcozecchini 0:9fca2b23d0ba 255 mbedtls_oid_descriptor_t descriptor;
marcozecchini 0:9fca2b23d0ba 256 int ext_type;
marcozecchini 0:9fca2b23d0ba 257 } oid_x509_ext_t;
marcozecchini 0:9fca2b23d0ba 258
marcozecchini 0:9fca2b23d0ba 259 static const oid_x509_ext_t oid_x509_ext[] =
marcozecchini 0:9fca2b23d0ba 260 {
marcozecchini 0:9fca2b23d0ba 261 {
marcozecchini 0:9fca2b23d0ba 262 { ADD_LEN( MBEDTLS_OID_BASIC_CONSTRAINTS ), "id-ce-basicConstraints", "Basic Constraints" },
marcozecchini 0:9fca2b23d0ba 263 MBEDTLS_X509_EXT_BASIC_CONSTRAINTS,
marcozecchini 0:9fca2b23d0ba 264 },
marcozecchini 0:9fca2b23d0ba 265 {
marcozecchini 0:9fca2b23d0ba 266 { ADD_LEN( MBEDTLS_OID_KEY_USAGE ), "id-ce-keyUsage", "Key Usage" },
marcozecchini 0:9fca2b23d0ba 267 MBEDTLS_X509_EXT_KEY_USAGE,
marcozecchini 0:9fca2b23d0ba 268 },
marcozecchini 0:9fca2b23d0ba 269 {
marcozecchini 0:9fca2b23d0ba 270 { ADD_LEN( MBEDTLS_OID_EXTENDED_KEY_USAGE ), "id-ce-extKeyUsage", "Extended Key Usage" },
marcozecchini 0:9fca2b23d0ba 271 MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE,
marcozecchini 0:9fca2b23d0ba 272 },
marcozecchini 0:9fca2b23d0ba 273 {
marcozecchini 0:9fca2b23d0ba 274 { ADD_LEN( MBEDTLS_OID_SUBJECT_ALT_NAME ), "id-ce-subjectAltName", "Subject Alt Name" },
marcozecchini 0:9fca2b23d0ba 275 MBEDTLS_X509_EXT_SUBJECT_ALT_NAME,
marcozecchini 0:9fca2b23d0ba 276 },
marcozecchini 0:9fca2b23d0ba 277 {
marcozecchini 0:9fca2b23d0ba 278 { ADD_LEN( MBEDTLS_OID_NS_CERT_TYPE ), "id-netscape-certtype", "Netscape Certificate Type" },
marcozecchini 0:9fca2b23d0ba 279 MBEDTLS_X509_EXT_NS_CERT_TYPE,
marcozecchini 0:9fca2b23d0ba 280 },
marcozecchini 0:9fca2b23d0ba 281 {
marcozecchini 0:9fca2b23d0ba 282 { NULL, 0, NULL, NULL },
marcozecchini 0:9fca2b23d0ba 283 0,
marcozecchini 0:9fca2b23d0ba 284 },
marcozecchini 0:9fca2b23d0ba 285 };
marcozecchini 0:9fca2b23d0ba 286
marcozecchini 0:9fca2b23d0ba 287 FN_OID_TYPED_FROM_ASN1(oid_x509_ext_t, x509_ext, oid_x509_ext)
marcozecchini 0:9fca2b23d0ba 288 FN_OID_GET_ATTR1(mbedtls_oid_get_x509_ext_type, oid_x509_ext_t, x509_ext, int, ext_type)
marcozecchini 0:9fca2b23d0ba 289
marcozecchini 0:9fca2b23d0ba 290 static const mbedtls_oid_descriptor_t oid_ext_key_usage[] =
marcozecchini 0:9fca2b23d0ba 291 {
marcozecchini 0:9fca2b23d0ba 292 { ADD_LEN( MBEDTLS_OID_SERVER_AUTH ), "id-kp-serverAuth", "TLS Web Server Authentication" },
marcozecchini 0:9fca2b23d0ba 293 { ADD_LEN( MBEDTLS_OID_CLIENT_AUTH ), "id-kp-clientAuth", "TLS Web Client Authentication" },
marcozecchini 0:9fca2b23d0ba 294 { ADD_LEN( MBEDTLS_OID_CODE_SIGNING ), "id-kp-codeSigning", "Code Signing" },
marcozecchini 0:9fca2b23d0ba 295 { ADD_LEN( MBEDTLS_OID_EMAIL_PROTECTION ), "id-kp-emailProtection", "E-mail Protection" },
marcozecchini 0:9fca2b23d0ba 296 { ADD_LEN( MBEDTLS_OID_TIME_STAMPING ), "id-kp-timeStamping", "Time Stamping" },
marcozecchini 0:9fca2b23d0ba 297 { ADD_LEN( MBEDTLS_OID_OCSP_SIGNING ), "id-kp-OCSPSigning", "OCSP Signing" },
marcozecchini 0:9fca2b23d0ba 298 { NULL, 0, NULL, NULL },
marcozecchini 0:9fca2b23d0ba 299 };
marcozecchini 0:9fca2b23d0ba 300
marcozecchini 0:9fca2b23d0ba 301 FN_OID_TYPED_FROM_ASN1(mbedtls_oid_descriptor_t, ext_key_usage, oid_ext_key_usage)
marcozecchini 0:9fca2b23d0ba 302 FN_OID_GET_ATTR1(mbedtls_oid_get_extended_key_usage, mbedtls_oid_descriptor_t, ext_key_usage, const char *, description)
marcozecchini 0:9fca2b23d0ba 303 #endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
marcozecchini 0:9fca2b23d0ba 304
marcozecchini 0:9fca2b23d0ba 305 #if defined(MBEDTLS_MD_C)
marcozecchini 0:9fca2b23d0ba 306 /*
marcozecchini 0:9fca2b23d0ba 307 * For SignatureAlgorithmIdentifier
marcozecchini 0:9fca2b23d0ba 308 */
marcozecchini 0:9fca2b23d0ba 309 typedef struct {
marcozecchini 0:9fca2b23d0ba 310 mbedtls_oid_descriptor_t descriptor;
marcozecchini 0:9fca2b23d0ba 311 mbedtls_md_type_t md_alg;
marcozecchini 0:9fca2b23d0ba 312 mbedtls_pk_type_t pk_alg;
marcozecchini 0:9fca2b23d0ba 313 } oid_sig_alg_t;
marcozecchini 0:9fca2b23d0ba 314
marcozecchini 0:9fca2b23d0ba 315 static const oid_sig_alg_t oid_sig_alg[] =
marcozecchini 0:9fca2b23d0ba 316 {
marcozecchini 0:9fca2b23d0ba 317 #if defined(MBEDTLS_RSA_C)
marcozecchini 0:9fca2b23d0ba 318 #if defined(MBEDTLS_MD2_C)
marcozecchini 0:9fca2b23d0ba 319 {
marcozecchini 0:9fca2b23d0ba 320 { ADD_LEN( MBEDTLS_OID_PKCS1_MD2 ), "md2WithRSAEncryption", "RSA with MD2" },
marcozecchini 0:9fca2b23d0ba 321 MBEDTLS_MD_MD2, MBEDTLS_PK_RSA,
marcozecchini 0:9fca2b23d0ba 322 },
marcozecchini 0:9fca2b23d0ba 323 #endif /* MBEDTLS_MD2_C */
marcozecchini 0:9fca2b23d0ba 324 #if defined(MBEDTLS_MD4_C)
marcozecchini 0:9fca2b23d0ba 325 {
marcozecchini 0:9fca2b23d0ba 326 { ADD_LEN( MBEDTLS_OID_PKCS1_MD4 ), "md4WithRSAEncryption", "RSA with MD4" },
marcozecchini 0:9fca2b23d0ba 327 MBEDTLS_MD_MD4, MBEDTLS_PK_RSA,
marcozecchini 0:9fca2b23d0ba 328 },
marcozecchini 0:9fca2b23d0ba 329 #endif /* MBEDTLS_MD4_C */
marcozecchini 0:9fca2b23d0ba 330 #if defined(MBEDTLS_MD5_C)
marcozecchini 0:9fca2b23d0ba 331 {
marcozecchini 0:9fca2b23d0ba 332 { ADD_LEN( MBEDTLS_OID_PKCS1_MD5 ), "md5WithRSAEncryption", "RSA with MD5" },
marcozecchini 0:9fca2b23d0ba 333 MBEDTLS_MD_MD5, MBEDTLS_PK_RSA,
marcozecchini 0:9fca2b23d0ba 334 },
marcozecchini 0:9fca2b23d0ba 335 #endif /* MBEDTLS_MD5_C */
marcozecchini 0:9fca2b23d0ba 336 #if defined(MBEDTLS_SHA1_C)
marcozecchini 0:9fca2b23d0ba 337 {
marcozecchini 0:9fca2b23d0ba 338 { ADD_LEN( MBEDTLS_OID_PKCS1_SHA1 ), "sha-1WithRSAEncryption", "RSA with SHA1" },
marcozecchini 0:9fca2b23d0ba 339 MBEDTLS_MD_SHA1, MBEDTLS_PK_RSA,
marcozecchini 0:9fca2b23d0ba 340 },
marcozecchini 0:9fca2b23d0ba 341 #endif /* MBEDTLS_SHA1_C */
marcozecchini 0:9fca2b23d0ba 342 #if defined(MBEDTLS_SHA256_C)
marcozecchini 0:9fca2b23d0ba 343 {
marcozecchini 0:9fca2b23d0ba 344 { ADD_LEN( MBEDTLS_OID_PKCS1_SHA224 ), "sha224WithRSAEncryption", "RSA with SHA-224" },
marcozecchini 0:9fca2b23d0ba 345 MBEDTLS_MD_SHA224, MBEDTLS_PK_RSA,
marcozecchini 0:9fca2b23d0ba 346 },
marcozecchini 0:9fca2b23d0ba 347 {
marcozecchini 0:9fca2b23d0ba 348 { ADD_LEN( MBEDTLS_OID_PKCS1_SHA256 ), "sha256WithRSAEncryption", "RSA with SHA-256" },
marcozecchini 0:9fca2b23d0ba 349 MBEDTLS_MD_SHA256, MBEDTLS_PK_RSA,
marcozecchini 0:9fca2b23d0ba 350 },
marcozecchini 0:9fca2b23d0ba 351 #endif /* MBEDTLS_SHA256_C */
marcozecchini 0:9fca2b23d0ba 352 #if defined(MBEDTLS_SHA512_C)
marcozecchini 0:9fca2b23d0ba 353 {
marcozecchini 0:9fca2b23d0ba 354 { ADD_LEN( MBEDTLS_OID_PKCS1_SHA384 ), "sha384WithRSAEncryption", "RSA with SHA-384" },
marcozecchini 0:9fca2b23d0ba 355 MBEDTLS_MD_SHA384, MBEDTLS_PK_RSA,
marcozecchini 0:9fca2b23d0ba 356 },
marcozecchini 0:9fca2b23d0ba 357 {
marcozecchini 0:9fca2b23d0ba 358 { ADD_LEN( MBEDTLS_OID_PKCS1_SHA512 ), "sha512WithRSAEncryption", "RSA with SHA-512" },
marcozecchini 0:9fca2b23d0ba 359 MBEDTLS_MD_SHA512, MBEDTLS_PK_RSA,
marcozecchini 0:9fca2b23d0ba 360 },
marcozecchini 0:9fca2b23d0ba 361 #endif /* MBEDTLS_SHA512_C */
marcozecchini 0:9fca2b23d0ba 362 #if defined(MBEDTLS_SHA1_C)
marcozecchini 0:9fca2b23d0ba 363 {
marcozecchini 0:9fca2b23d0ba 364 { ADD_LEN( MBEDTLS_OID_RSA_SHA_OBS ), "sha-1WithRSAEncryption", "RSA with SHA1" },
marcozecchini 0:9fca2b23d0ba 365 MBEDTLS_MD_SHA1, MBEDTLS_PK_RSA,
marcozecchini 0:9fca2b23d0ba 366 },
marcozecchini 0:9fca2b23d0ba 367 #endif /* MBEDTLS_SHA1_C */
marcozecchini 0:9fca2b23d0ba 368 #endif /* MBEDTLS_RSA_C */
marcozecchini 0:9fca2b23d0ba 369 #if defined(MBEDTLS_ECDSA_C)
marcozecchini 0:9fca2b23d0ba 370 #if defined(MBEDTLS_SHA1_C)
marcozecchini 0:9fca2b23d0ba 371 {
marcozecchini 0:9fca2b23d0ba 372 { ADD_LEN( MBEDTLS_OID_ECDSA_SHA1 ), "ecdsa-with-SHA1", "ECDSA with SHA1" },
marcozecchini 0:9fca2b23d0ba 373 MBEDTLS_MD_SHA1, MBEDTLS_PK_ECDSA,
marcozecchini 0:9fca2b23d0ba 374 },
marcozecchini 0:9fca2b23d0ba 375 #endif /* MBEDTLS_SHA1_C */
marcozecchini 0:9fca2b23d0ba 376 #if defined(MBEDTLS_SHA256_C)
marcozecchini 0:9fca2b23d0ba 377 {
marcozecchini 0:9fca2b23d0ba 378 { ADD_LEN( MBEDTLS_OID_ECDSA_SHA224 ), "ecdsa-with-SHA224", "ECDSA with SHA224" },
marcozecchini 0:9fca2b23d0ba 379 MBEDTLS_MD_SHA224, MBEDTLS_PK_ECDSA,
marcozecchini 0:9fca2b23d0ba 380 },
marcozecchini 0:9fca2b23d0ba 381 {
marcozecchini 0:9fca2b23d0ba 382 { ADD_LEN( MBEDTLS_OID_ECDSA_SHA256 ), "ecdsa-with-SHA256", "ECDSA with SHA256" },
marcozecchini 0:9fca2b23d0ba 383 MBEDTLS_MD_SHA256, MBEDTLS_PK_ECDSA,
marcozecchini 0:9fca2b23d0ba 384 },
marcozecchini 0:9fca2b23d0ba 385 #endif /* MBEDTLS_SHA256_C */
marcozecchini 0:9fca2b23d0ba 386 #if defined(MBEDTLS_SHA512_C)
marcozecchini 0:9fca2b23d0ba 387 {
marcozecchini 0:9fca2b23d0ba 388 { ADD_LEN( MBEDTLS_OID_ECDSA_SHA384 ), "ecdsa-with-SHA384", "ECDSA with SHA384" },
marcozecchini 0:9fca2b23d0ba 389 MBEDTLS_MD_SHA384, MBEDTLS_PK_ECDSA,
marcozecchini 0:9fca2b23d0ba 390 },
marcozecchini 0:9fca2b23d0ba 391 {
marcozecchini 0:9fca2b23d0ba 392 { ADD_LEN( MBEDTLS_OID_ECDSA_SHA512 ), "ecdsa-with-SHA512", "ECDSA with SHA512" },
marcozecchini 0:9fca2b23d0ba 393 MBEDTLS_MD_SHA512, MBEDTLS_PK_ECDSA,
marcozecchini 0:9fca2b23d0ba 394 },
marcozecchini 0:9fca2b23d0ba 395 #endif /* MBEDTLS_SHA512_C */
marcozecchini 0:9fca2b23d0ba 396 #endif /* MBEDTLS_ECDSA_C */
marcozecchini 0:9fca2b23d0ba 397 #if defined(MBEDTLS_RSA_C)
marcozecchini 0:9fca2b23d0ba 398 {
marcozecchini 0:9fca2b23d0ba 399 { ADD_LEN( MBEDTLS_OID_RSASSA_PSS ), "RSASSA-PSS", "RSASSA-PSS" },
marcozecchini 0:9fca2b23d0ba 400 MBEDTLS_MD_NONE, MBEDTLS_PK_RSASSA_PSS,
marcozecchini 0:9fca2b23d0ba 401 },
marcozecchini 0:9fca2b23d0ba 402 #endif /* MBEDTLS_RSA_C */
marcozecchini 0:9fca2b23d0ba 403 {
marcozecchini 0:9fca2b23d0ba 404 { NULL, 0, NULL, NULL },
marcozecchini 0:9fca2b23d0ba 405 MBEDTLS_MD_NONE, MBEDTLS_PK_NONE,
marcozecchini 0:9fca2b23d0ba 406 },
marcozecchini 0:9fca2b23d0ba 407 };
marcozecchini 0:9fca2b23d0ba 408
marcozecchini 0:9fca2b23d0ba 409 FN_OID_TYPED_FROM_ASN1(oid_sig_alg_t, sig_alg, oid_sig_alg)
marcozecchini 0:9fca2b23d0ba 410 FN_OID_GET_DESCRIPTOR_ATTR1(mbedtls_oid_get_sig_alg_desc, oid_sig_alg_t, sig_alg, const char *, description)
marcozecchini 0:9fca2b23d0ba 411 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)
marcozecchini 0:9fca2b23d0ba 412 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)
marcozecchini 0:9fca2b23d0ba 413 #endif /* MBEDTLS_MD_C */
marcozecchini 0:9fca2b23d0ba 414
marcozecchini 0:9fca2b23d0ba 415 /*
marcozecchini 0:9fca2b23d0ba 416 * For PublicKeyInfo (PKCS1, RFC 5480)
marcozecchini 0:9fca2b23d0ba 417 */
marcozecchini 0:9fca2b23d0ba 418 typedef struct {
marcozecchini 0:9fca2b23d0ba 419 mbedtls_oid_descriptor_t descriptor;
marcozecchini 0:9fca2b23d0ba 420 mbedtls_pk_type_t pk_alg;
marcozecchini 0:9fca2b23d0ba 421 } oid_pk_alg_t;
marcozecchini 0:9fca2b23d0ba 422
marcozecchini 0:9fca2b23d0ba 423 static const oid_pk_alg_t oid_pk_alg[] =
marcozecchini 0:9fca2b23d0ba 424 {
marcozecchini 0:9fca2b23d0ba 425 {
marcozecchini 0:9fca2b23d0ba 426 { ADD_LEN( MBEDTLS_OID_PKCS1_RSA ), "rsaEncryption", "RSA" },
marcozecchini 0:9fca2b23d0ba 427 MBEDTLS_PK_RSA,
marcozecchini 0:9fca2b23d0ba 428 },
marcozecchini 0:9fca2b23d0ba 429 {
marcozecchini 0:9fca2b23d0ba 430 { ADD_LEN( MBEDTLS_OID_EC_ALG_UNRESTRICTED ), "id-ecPublicKey", "Generic EC key" },
marcozecchini 0:9fca2b23d0ba 431 MBEDTLS_PK_ECKEY,
marcozecchini 0:9fca2b23d0ba 432 },
marcozecchini 0:9fca2b23d0ba 433 {
marcozecchini 0:9fca2b23d0ba 434 { ADD_LEN( MBEDTLS_OID_EC_ALG_ECDH ), "id-ecDH", "EC key for ECDH" },
marcozecchini 0:9fca2b23d0ba 435 MBEDTLS_PK_ECKEY_DH,
marcozecchini 0:9fca2b23d0ba 436 },
marcozecchini 0:9fca2b23d0ba 437 {
marcozecchini 0:9fca2b23d0ba 438 { NULL, 0, NULL, NULL },
marcozecchini 0:9fca2b23d0ba 439 MBEDTLS_PK_NONE,
marcozecchini 0:9fca2b23d0ba 440 },
marcozecchini 0:9fca2b23d0ba 441 };
marcozecchini 0:9fca2b23d0ba 442
marcozecchini 0:9fca2b23d0ba 443 FN_OID_TYPED_FROM_ASN1(oid_pk_alg_t, pk_alg, oid_pk_alg)
marcozecchini 0:9fca2b23d0ba 444 FN_OID_GET_ATTR1(mbedtls_oid_get_pk_alg, oid_pk_alg_t, pk_alg, mbedtls_pk_type_t, pk_alg)
marcozecchini 0:9fca2b23d0ba 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)
marcozecchini 0:9fca2b23d0ba 446
marcozecchini 0:9fca2b23d0ba 447 #if defined(MBEDTLS_ECP_C)
marcozecchini 0:9fca2b23d0ba 448 /*
marcozecchini 0:9fca2b23d0ba 449 * For namedCurve (RFC 5480)
marcozecchini 0:9fca2b23d0ba 450 */
marcozecchini 0:9fca2b23d0ba 451 typedef struct {
marcozecchini 0:9fca2b23d0ba 452 mbedtls_oid_descriptor_t descriptor;
marcozecchini 0:9fca2b23d0ba 453 mbedtls_ecp_group_id grp_id;
marcozecchini 0:9fca2b23d0ba 454 } oid_ecp_grp_t;
marcozecchini 0:9fca2b23d0ba 455
marcozecchini 0:9fca2b23d0ba 456 static const oid_ecp_grp_t oid_ecp_grp[] =
marcozecchini 0:9fca2b23d0ba 457 {
marcozecchini 0:9fca2b23d0ba 458 #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
marcozecchini 0:9fca2b23d0ba 459 {
marcozecchini 0:9fca2b23d0ba 460 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP192R1 ), "secp192r1", "secp192r1" },
marcozecchini 0:9fca2b23d0ba 461 MBEDTLS_ECP_DP_SECP192R1,
marcozecchini 0:9fca2b23d0ba 462 },
marcozecchini 0:9fca2b23d0ba 463 #endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
marcozecchini 0:9fca2b23d0ba 464 #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
marcozecchini 0:9fca2b23d0ba 465 {
marcozecchini 0:9fca2b23d0ba 466 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP224R1 ), "secp224r1", "secp224r1" },
marcozecchini 0:9fca2b23d0ba 467 MBEDTLS_ECP_DP_SECP224R1,
marcozecchini 0:9fca2b23d0ba 468 },
marcozecchini 0:9fca2b23d0ba 469 #endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */
marcozecchini 0:9fca2b23d0ba 470 #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
marcozecchini 0:9fca2b23d0ba 471 {
marcozecchini 0:9fca2b23d0ba 472 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP256R1 ), "secp256r1", "secp256r1" },
marcozecchini 0:9fca2b23d0ba 473 MBEDTLS_ECP_DP_SECP256R1,
marcozecchini 0:9fca2b23d0ba 474 },
marcozecchini 0:9fca2b23d0ba 475 #endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */
marcozecchini 0:9fca2b23d0ba 476 #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
marcozecchini 0:9fca2b23d0ba 477 {
marcozecchini 0:9fca2b23d0ba 478 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP384R1 ), "secp384r1", "secp384r1" },
marcozecchini 0:9fca2b23d0ba 479 MBEDTLS_ECP_DP_SECP384R1,
marcozecchini 0:9fca2b23d0ba 480 },
marcozecchini 0:9fca2b23d0ba 481 #endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */
marcozecchini 0:9fca2b23d0ba 482 #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
marcozecchini 0:9fca2b23d0ba 483 {
marcozecchini 0:9fca2b23d0ba 484 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP521R1 ), "secp521r1", "secp521r1" },
marcozecchini 0:9fca2b23d0ba 485 MBEDTLS_ECP_DP_SECP521R1,
marcozecchini 0:9fca2b23d0ba 486 },
marcozecchini 0:9fca2b23d0ba 487 #endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */
marcozecchini 0:9fca2b23d0ba 488 #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
marcozecchini 0:9fca2b23d0ba 489 {
marcozecchini 0:9fca2b23d0ba 490 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP192K1 ), "secp192k1", "secp192k1" },
marcozecchini 0:9fca2b23d0ba 491 MBEDTLS_ECP_DP_SECP192K1,
marcozecchini 0:9fca2b23d0ba 492 },
marcozecchini 0:9fca2b23d0ba 493 #endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */
marcozecchini 0:9fca2b23d0ba 494 #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
marcozecchini 0:9fca2b23d0ba 495 {
marcozecchini 0:9fca2b23d0ba 496 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP224K1 ), "secp224k1", "secp224k1" },
marcozecchini 0:9fca2b23d0ba 497 MBEDTLS_ECP_DP_SECP224K1,
marcozecchini 0:9fca2b23d0ba 498 },
marcozecchini 0:9fca2b23d0ba 499 #endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */
marcozecchini 0:9fca2b23d0ba 500 #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
marcozecchini 0:9fca2b23d0ba 501 {
marcozecchini 0:9fca2b23d0ba 502 { ADD_LEN( MBEDTLS_OID_EC_GRP_SECP256K1 ), "secp256k1", "secp256k1" },
marcozecchini 0:9fca2b23d0ba 503 MBEDTLS_ECP_DP_SECP256K1,
marcozecchini 0:9fca2b23d0ba 504 },
marcozecchini 0:9fca2b23d0ba 505 #endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
marcozecchini 0:9fca2b23d0ba 506 #if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
marcozecchini 0:9fca2b23d0ba 507 {
marcozecchini 0:9fca2b23d0ba 508 { ADD_LEN( MBEDTLS_OID_EC_GRP_BP256R1 ), "brainpoolP256r1","brainpool256r1" },
marcozecchini 0:9fca2b23d0ba 509 MBEDTLS_ECP_DP_BP256R1,
marcozecchini 0:9fca2b23d0ba 510 },
marcozecchini 0:9fca2b23d0ba 511 #endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */
marcozecchini 0:9fca2b23d0ba 512 #if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
marcozecchini 0:9fca2b23d0ba 513 {
marcozecchini 0:9fca2b23d0ba 514 { ADD_LEN( MBEDTLS_OID_EC_GRP_BP384R1 ), "brainpoolP384r1","brainpool384r1" },
marcozecchini 0:9fca2b23d0ba 515 MBEDTLS_ECP_DP_BP384R1,
marcozecchini 0:9fca2b23d0ba 516 },
marcozecchini 0:9fca2b23d0ba 517 #endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */
marcozecchini 0:9fca2b23d0ba 518 #if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
marcozecchini 0:9fca2b23d0ba 519 {
marcozecchini 0:9fca2b23d0ba 520 { ADD_LEN( MBEDTLS_OID_EC_GRP_BP512R1 ), "brainpoolP512r1","brainpool512r1" },
marcozecchini 0:9fca2b23d0ba 521 MBEDTLS_ECP_DP_BP512R1,
marcozecchini 0:9fca2b23d0ba 522 },
marcozecchini 0:9fca2b23d0ba 523 #endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */
marcozecchini 0:9fca2b23d0ba 524 {
marcozecchini 0:9fca2b23d0ba 525 { NULL, 0, NULL, NULL },
marcozecchini 0:9fca2b23d0ba 526 MBEDTLS_ECP_DP_NONE,
marcozecchini 0:9fca2b23d0ba 527 },
marcozecchini 0:9fca2b23d0ba 528 };
marcozecchini 0:9fca2b23d0ba 529
marcozecchini 0:9fca2b23d0ba 530 FN_OID_TYPED_FROM_ASN1(oid_ecp_grp_t, grp_id, oid_ecp_grp)
marcozecchini 0:9fca2b23d0ba 531 FN_OID_GET_ATTR1(mbedtls_oid_get_ec_grp, oid_ecp_grp_t, grp_id, mbedtls_ecp_group_id, grp_id)
marcozecchini 0:9fca2b23d0ba 532 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)
marcozecchini 0:9fca2b23d0ba 533 #endif /* MBEDTLS_ECP_C */
marcozecchini 0:9fca2b23d0ba 534
marcozecchini 0:9fca2b23d0ba 535 #if defined(MBEDTLS_CIPHER_C)
marcozecchini 0:9fca2b23d0ba 536 /*
marcozecchini 0:9fca2b23d0ba 537 * For PKCS#5 PBES2 encryption algorithm
marcozecchini 0:9fca2b23d0ba 538 */
marcozecchini 0:9fca2b23d0ba 539 typedef struct {
marcozecchini 0:9fca2b23d0ba 540 mbedtls_oid_descriptor_t descriptor;
marcozecchini 0:9fca2b23d0ba 541 mbedtls_cipher_type_t cipher_alg;
marcozecchini 0:9fca2b23d0ba 542 } oid_cipher_alg_t;
marcozecchini 0:9fca2b23d0ba 543
marcozecchini 0:9fca2b23d0ba 544 static const oid_cipher_alg_t oid_cipher_alg[] =
marcozecchini 0:9fca2b23d0ba 545 {
marcozecchini 0:9fca2b23d0ba 546 {
marcozecchini 0:9fca2b23d0ba 547 { ADD_LEN( MBEDTLS_OID_DES_CBC ), "desCBC", "DES-CBC" },
marcozecchini 0:9fca2b23d0ba 548 MBEDTLS_CIPHER_DES_CBC,
marcozecchini 0:9fca2b23d0ba 549 },
marcozecchini 0:9fca2b23d0ba 550 {
marcozecchini 0:9fca2b23d0ba 551 { ADD_LEN( MBEDTLS_OID_DES_EDE3_CBC ), "des-ede3-cbc", "DES-EDE3-CBC" },
marcozecchini 0:9fca2b23d0ba 552 MBEDTLS_CIPHER_DES_EDE3_CBC,
marcozecchini 0:9fca2b23d0ba 553 },
marcozecchini 0:9fca2b23d0ba 554 {
marcozecchini 0:9fca2b23d0ba 555 { NULL, 0, NULL, NULL },
marcozecchini 0:9fca2b23d0ba 556 MBEDTLS_CIPHER_NONE,
marcozecchini 0:9fca2b23d0ba 557 },
marcozecchini 0:9fca2b23d0ba 558 };
marcozecchini 0:9fca2b23d0ba 559
marcozecchini 0:9fca2b23d0ba 560 FN_OID_TYPED_FROM_ASN1(oid_cipher_alg_t, cipher_alg, oid_cipher_alg)
marcozecchini 0:9fca2b23d0ba 561 FN_OID_GET_ATTR1(mbedtls_oid_get_cipher_alg, oid_cipher_alg_t, cipher_alg, mbedtls_cipher_type_t, cipher_alg)
marcozecchini 0:9fca2b23d0ba 562 #endif /* MBEDTLS_CIPHER_C */
marcozecchini 0:9fca2b23d0ba 563
marcozecchini 0:9fca2b23d0ba 564 #if defined(MBEDTLS_MD_C)
marcozecchini 0:9fca2b23d0ba 565 /*
marcozecchini 0:9fca2b23d0ba 566 * For digestAlgorithm
marcozecchini 0:9fca2b23d0ba 567 */
marcozecchini 0:9fca2b23d0ba 568 typedef struct {
marcozecchini 0:9fca2b23d0ba 569 mbedtls_oid_descriptor_t descriptor;
marcozecchini 0:9fca2b23d0ba 570 mbedtls_md_type_t md_alg;
marcozecchini 0:9fca2b23d0ba 571 } oid_md_alg_t;
marcozecchini 0:9fca2b23d0ba 572
marcozecchini 0:9fca2b23d0ba 573 static const oid_md_alg_t oid_md_alg[] =
marcozecchini 0:9fca2b23d0ba 574 {
marcozecchini 0:9fca2b23d0ba 575 #if defined(MBEDTLS_MD2_C)
marcozecchini 0:9fca2b23d0ba 576 {
marcozecchini 0:9fca2b23d0ba 577 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_MD2 ), "id-md2", "MD2" },
marcozecchini 0:9fca2b23d0ba 578 MBEDTLS_MD_MD2,
marcozecchini 0:9fca2b23d0ba 579 },
marcozecchini 0:9fca2b23d0ba 580 #endif /* MBEDTLS_MD2_C */
marcozecchini 0:9fca2b23d0ba 581 #if defined(MBEDTLS_MD4_C)
marcozecchini 0:9fca2b23d0ba 582 {
marcozecchini 0:9fca2b23d0ba 583 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_MD4 ), "id-md4", "MD4" },
marcozecchini 0:9fca2b23d0ba 584 MBEDTLS_MD_MD4,
marcozecchini 0:9fca2b23d0ba 585 },
marcozecchini 0:9fca2b23d0ba 586 #endif /* MBEDTLS_MD4_C */
marcozecchini 0:9fca2b23d0ba 587 #if defined(MBEDTLS_MD5_C)
marcozecchini 0:9fca2b23d0ba 588 {
marcozecchini 0:9fca2b23d0ba 589 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_MD5 ), "id-md5", "MD5" },
marcozecchini 0:9fca2b23d0ba 590 MBEDTLS_MD_MD5,
marcozecchini 0:9fca2b23d0ba 591 },
marcozecchini 0:9fca2b23d0ba 592 #endif /* MBEDTLS_MD5_C */
marcozecchini 0:9fca2b23d0ba 593 #if defined(MBEDTLS_SHA1_C)
marcozecchini 0:9fca2b23d0ba 594 {
marcozecchini 0:9fca2b23d0ba 595 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA1 ), "id-sha1", "SHA-1" },
marcozecchini 0:9fca2b23d0ba 596 MBEDTLS_MD_SHA1,
marcozecchini 0:9fca2b23d0ba 597 },
marcozecchini 0:9fca2b23d0ba 598 #endif /* MBEDTLS_SHA1_C */
marcozecchini 0:9fca2b23d0ba 599 #if defined(MBEDTLS_SHA256_C)
marcozecchini 0:9fca2b23d0ba 600 {
marcozecchini 0:9fca2b23d0ba 601 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA224 ), "id-sha224", "SHA-224" },
marcozecchini 0:9fca2b23d0ba 602 MBEDTLS_MD_SHA224,
marcozecchini 0:9fca2b23d0ba 603 },
marcozecchini 0:9fca2b23d0ba 604 {
marcozecchini 0:9fca2b23d0ba 605 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA256 ), "id-sha256", "SHA-256" },
marcozecchini 0:9fca2b23d0ba 606 MBEDTLS_MD_SHA256,
marcozecchini 0:9fca2b23d0ba 607 },
marcozecchini 0:9fca2b23d0ba 608 #endif /* MBEDTLS_SHA256_C */
marcozecchini 0:9fca2b23d0ba 609 #if defined(MBEDTLS_SHA512_C)
marcozecchini 0:9fca2b23d0ba 610 {
marcozecchini 0:9fca2b23d0ba 611 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA384 ), "id-sha384", "SHA-384" },
marcozecchini 0:9fca2b23d0ba 612 MBEDTLS_MD_SHA384,
marcozecchini 0:9fca2b23d0ba 613 },
marcozecchini 0:9fca2b23d0ba 614 {
marcozecchini 0:9fca2b23d0ba 615 { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA512 ), "id-sha512", "SHA-512" },
marcozecchini 0:9fca2b23d0ba 616 MBEDTLS_MD_SHA512,
marcozecchini 0:9fca2b23d0ba 617 },
marcozecchini 0:9fca2b23d0ba 618 #endif /* MBEDTLS_SHA512_C */
marcozecchini 0:9fca2b23d0ba 619 {
marcozecchini 0:9fca2b23d0ba 620 { NULL, 0, NULL, NULL },
marcozecchini 0:9fca2b23d0ba 621 MBEDTLS_MD_NONE,
marcozecchini 0:9fca2b23d0ba 622 },
marcozecchini 0:9fca2b23d0ba 623 };
marcozecchini 0:9fca2b23d0ba 624
marcozecchini 0:9fca2b23d0ba 625 FN_OID_TYPED_FROM_ASN1(oid_md_alg_t, md_alg, oid_md_alg)
marcozecchini 0:9fca2b23d0ba 626 FN_OID_GET_ATTR1(mbedtls_oid_get_md_alg, oid_md_alg_t, md_alg, mbedtls_md_type_t, md_alg)
marcozecchini 0:9fca2b23d0ba 627 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)
marcozecchini 0:9fca2b23d0ba 628 #endif /* MBEDTLS_MD_C */
marcozecchini 0:9fca2b23d0ba 629
marcozecchini 0:9fca2b23d0ba 630 #if defined(MBEDTLS_PKCS12_C)
marcozecchini 0:9fca2b23d0ba 631 /*
marcozecchini 0:9fca2b23d0ba 632 * For PKCS#12 PBEs
marcozecchini 0:9fca2b23d0ba 633 */
marcozecchini 0:9fca2b23d0ba 634 typedef struct {
marcozecchini 0:9fca2b23d0ba 635 mbedtls_oid_descriptor_t descriptor;
marcozecchini 0:9fca2b23d0ba 636 mbedtls_md_type_t md_alg;
marcozecchini 0:9fca2b23d0ba 637 mbedtls_cipher_type_t cipher_alg;
marcozecchini 0:9fca2b23d0ba 638 } oid_pkcs12_pbe_alg_t;
marcozecchini 0:9fca2b23d0ba 639
marcozecchini 0:9fca2b23d0ba 640 static const oid_pkcs12_pbe_alg_t oid_pkcs12_pbe_alg[] =
marcozecchini 0:9fca2b23d0ba 641 {
marcozecchini 0:9fca2b23d0ba 642 {
marcozecchini 0:9fca2b23d0ba 643 { ADD_LEN( MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC ), "pbeWithSHAAnd3-KeyTripleDES-CBC", "PBE with SHA1 and 3-Key 3DES" },
marcozecchini 0:9fca2b23d0ba 644 MBEDTLS_MD_SHA1, MBEDTLS_CIPHER_DES_EDE3_CBC,
marcozecchini 0:9fca2b23d0ba 645 },
marcozecchini 0:9fca2b23d0ba 646 {
marcozecchini 0:9fca2b23d0ba 647 { ADD_LEN( MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC ), "pbeWithSHAAnd2-KeyTripleDES-CBC", "PBE with SHA1 and 2-Key 3DES" },
marcozecchini 0:9fca2b23d0ba 648 MBEDTLS_MD_SHA1, MBEDTLS_CIPHER_DES_EDE_CBC,
marcozecchini 0:9fca2b23d0ba 649 },
marcozecchini 0:9fca2b23d0ba 650 {
marcozecchini 0:9fca2b23d0ba 651 { NULL, 0, NULL, NULL },
marcozecchini 0:9fca2b23d0ba 652 MBEDTLS_MD_NONE, MBEDTLS_CIPHER_NONE,
marcozecchini 0:9fca2b23d0ba 653 },
marcozecchini 0:9fca2b23d0ba 654 };
marcozecchini 0:9fca2b23d0ba 655
marcozecchini 0:9fca2b23d0ba 656 FN_OID_TYPED_FROM_ASN1(oid_pkcs12_pbe_alg_t, pkcs12_pbe_alg, oid_pkcs12_pbe_alg)
marcozecchini 0:9fca2b23d0ba 657 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)
marcozecchini 0:9fca2b23d0ba 658 #endif /* MBEDTLS_PKCS12_C */
marcozecchini 0:9fca2b23d0ba 659
marcozecchini 0:9fca2b23d0ba 660 #define OID_SAFE_SNPRINTF \
marcozecchini 0:9fca2b23d0ba 661 do { \
marcozecchini 0:9fca2b23d0ba 662 if( ret < 0 || (size_t) ret >= n ) \
marcozecchini 0:9fca2b23d0ba 663 return( MBEDTLS_ERR_OID_BUF_TOO_SMALL ); \
marcozecchini 0:9fca2b23d0ba 664 \
marcozecchini 0:9fca2b23d0ba 665 n -= (size_t) ret; \
marcozecchini 0:9fca2b23d0ba 666 p += (size_t) ret; \
marcozecchini 0:9fca2b23d0ba 667 } while( 0 )
marcozecchini 0:9fca2b23d0ba 668
marcozecchini 0:9fca2b23d0ba 669 /* Return the x.y.z.... style numeric string for the given OID */
marcozecchini 0:9fca2b23d0ba 670 int mbedtls_oid_get_numeric_string( char *buf, size_t size,
marcozecchini 0:9fca2b23d0ba 671 const mbedtls_asn1_buf *oid )
marcozecchini 0:9fca2b23d0ba 672 {
marcozecchini 0:9fca2b23d0ba 673 int ret;
marcozecchini 0:9fca2b23d0ba 674 size_t i, n;
marcozecchini 0:9fca2b23d0ba 675 unsigned int value;
marcozecchini 0:9fca2b23d0ba 676 char *p;
marcozecchini 0:9fca2b23d0ba 677
marcozecchini 0:9fca2b23d0ba 678 p = buf;
marcozecchini 0:9fca2b23d0ba 679 n = size;
marcozecchini 0:9fca2b23d0ba 680
marcozecchini 0:9fca2b23d0ba 681 /* First byte contains first two dots */
marcozecchini 0:9fca2b23d0ba 682 if( oid->len > 0 )
marcozecchini 0:9fca2b23d0ba 683 {
marcozecchini 0:9fca2b23d0ba 684 ret = mbedtls_snprintf( p, n, "%d.%d", oid->p[0] / 40, oid->p[0] % 40 );
marcozecchini 0:9fca2b23d0ba 685 OID_SAFE_SNPRINTF;
marcozecchini 0:9fca2b23d0ba 686 }
marcozecchini 0:9fca2b23d0ba 687
marcozecchini 0:9fca2b23d0ba 688 value = 0;
marcozecchini 0:9fca2b23d0ba 689 for( i = 1; i < oid->len; i++ )
marcozecchini 0:9fca2b23d0ba 690 {
marcozecchini 0:9fca2b23d0ba 691 /* Prevent overflow in value. */
marcozecchini 0:9fca2b23d0ba 692 if( ( ( value << 7 ) >> 7 ) != value )
marcozecchini 0:9fca2b23d0ba 693 return( MBEDTLS_ERR_OID_BUF_TOO_SMALL );
marcozecchini 0:9fca2b23d0ba 694
marcozecchini 0:9fca2b23d0ba 695 value <<= 7;
marcozecchini 0:9fca2b23d0ba 696 value += oid->p[i] & 0x7F;
marcozecchini 0:9fca2b23d0ba 697
marcozecchini 0:9fca2b23d0ba 698 if( !( oid->p[i] & 0x80 ) )
marcozecchini 0:9fca2b23d0ba 699 {
marcozecchini 0:9fca2b23d0ba 700 /* Last byte */
marcozecchini 0:9fca2b23d0ba 701 ret = mbedtls_snprintf( p, n, ".%d", value );
marcozecchini 0:9fca2b23d0ba 702 OID_SAFE_SNPRINTF;
marcozecchini 0:9fca2b23d0ba 703 value = 0;
marcozecchini 0:9fca2b23d0ba 704 }
marcozecchini 0:9fca2b23d0ba 705 }
marcozecchini 0:9fca2b23d0ba 706
marcozecchini 0:9fca2b23d0ba 707 return( (int) ( size - n ) );
marcozecchini 0:9fca2b23d0ba 708 }
marcozecchini 0:9fca2b23d0ba 709
marcozecchini 0:9fca2b23d0ba 710 #endif /* MBEDTLS_OID_C */