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