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