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