Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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