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