mbed TLS upgraded to 2.6.0

Fork of mbedtls by Mark Radbourne

Committer:
Jasper Wallace
Date:
Fri Sep 29 19:50:30 2017 +0100
Revision:
2:bbdeda018a3c
Parent:
0:cdf462088d13
Update to mbedtls 2.6.0, many changes.

Changes to mbedtls sources made:

in include/mbedtls/config.h comment out:

#define MBEDTLS_FS_IO
#define MBEDTLS_NET_C
#define MBEDTLS_TIMING_C

uncomment:

#define MBEDTLS_NO_PLATFORM_ENTROPY

remove the following directorys:

programs
yotta
visualc

Who changed what in which revision?

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