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