mbedtls ported to mbed-classic

Fork of mbedtls by Christopher Haster

Committer:
Brian Daniels
Date:
Thu Apr 07 11:11:18 2016 +0100
Revision:
4:bef26f687287
Parent:
1:24750b9ad5ef
Adding ported selftest test case

Who changed what in which revision?

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