This is a fork due to permission issues

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of 6_songs-from-the-cloud by MakingMusicWorkshop

Committer:
timbeight
Date:
Thu May 19 16:02:10 2016 +0000
Revision:
1:0ddbe2d3319c
Parent:
0:f7c60d3e7b8a
This is my first commit while in the class.

Who changed what in which revision?

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