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