Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

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