mbed-os5 only for TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Committer:
kenjiArai
Date:
Tue Dec 31 06:02:27 2019 +0000
Revision:
1:9db0e321a9f4
Parent:
0:5b88d5760320
updated based on mbed-os5.15.0

Who changed what in which revision?

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