Modified mbed TLS headers for AES functionality only to reduce build size

Dependents:   BLE_Gateway_Linker_fix BLE_Gateway

Fork of mbedtls by sandbox

Committer:
electronichamsters
Date:
Mon Jul 10 04:00:25 2017 +0000
Revision:
5:f09f5ed830ca
Parent:
1:24750b9ad5ef
working gateway

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Christopher Haster 1:24750b9ad5ef 1 /**
Christopher Haster 1:24750b9ad5ef 2 * \file x509.h
Christopher Haster 1:24750b9ad5ef 3 *
Christopher Haster 1:24750b9ad5ef 4 * \brief X.509 generic defines and structures
Christopher Haster 1:24750b9ad5ef 5 *
Christopher Haster 1:24750b9ad5ef 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Christopher Haster 1:24750b9ad5ef 7 * SPDX-License-Identifier: Apache-2.0
Christopher Haster 1:24750b9ad5ef 8 *
Christopher Haster 1:24750b9ad5ef 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Christopher Haster 1:24750b9ad5ef 10 * not use this file except in compliance with the License.
Christopher Haster 1:24750b9ad5ef 11 * You may obtain a copy of the License at
Christopher Haster 1:24750b9ad5ef 12 *
Christopher Haster 1:24750b9ad5ef 13 * http://www.apache.org/licenses/LICENSE-2.0
Christopher Haster 1:24750b9ad5ef 14 *
Christopher Haster 1:24750b9ad5ef 15 * Unless required by applicable law or agreed to in writing, software
Christopher Haster 1:24750b9ad5ef 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Christopher Haster 1:24750b9ad5ef 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Christopher Haster 1:24750b9ad5ef 18 * See the License for the specific language governing permissions and
Christopher Haster 1:24750b9ad5ef 19 * limitations under the License.
Christopher Haster 1:24750b9ad5ef 20 *
Christopher Haster 1:24750b9ad5ef 21 * This file is part of mbed TLS (https://tls.mbed.org)
Christopher Haster 1:24750b9ad5ef 22 */
Christopher Haster 1:24750b9ad5ef 23 #ifndef MBEDTLS_X509_H
Christopher Haster 1:24750b9ad5ef 24 #define MBEDTLS_X509_H
Christopher Haster 1:24750b9ad5ef 25
Christopher Haster 1:24750b9ad5ef 26 #if !defined(MBEDTLS_CONFIG_FILE)
Christopher Haster 1:24750b9ad5ef 27 #include "config.h"
Christopher Haster 1:24750b9ad5ef 28 #else
Christopher Haster 1:24750b9ad5ef 29 #include MBEDTLS_CONFIG_FILE
Christopher Haster 1:24750b9ad5ef 30 #endif
Christopher Haster 1:24750b9ad5ef 31
Christopher Haster 1:24750b9ad5ef 32 #include "asn1.h"
Christopher Haster 1:24750b9ad5ef 33 #include "pk.h"
Christopher Haster 1:24750b9ad5ef 34
Christopher Haster 1:24750b9ad5ef 35 #if defined(MBEDTLS_RSA_C)
Christopher Haster 1:24750b9ad5ef 36 #include "rsa.h"
Christopher Haster 1:24750b9ad5ef 37 #endif
Christopher Haster 1:24750b9ad5ef 38
Christopher Haster 1:24750b9ad5ef 39 /**
Christopher Haster 1:24750b9ad5ef 40 * \addtogroup x509_module
Christopher Haster 1:24750b9ad5ef 41 * \{
Christopher Haster 1:24750b9ad5ef 42 */
Christopher Haster 1:24750b9ad5ef 43
Christopher Haster 1:24750b9ad5ef 44 #if !defined(MBEDTLS_X509_MAX_INTERMEDIATE_CA)
Christopher Haster 1:24750b9ad5ef 45 /**
Christopher Haster 1:24750b9ad5ef 46 * Maximum number of intermediate CAs in a verification chain.
Christopher Haster 1:24750b9ad5ef 47 * That is, maximum length of the chain, excluding the end-entity certificate
Christopher Haster 1:24750b9ad5ef 48 * and the trusted root certificate.
Christopher Haster 1:24750b9ad5ef 49 *
Christopher Haster 1:24750b9ad5ef 50 * Set this to a low value to prevent an adversary from making you waste
Christopher Haster 1:24750b9ad5ef 51 * resources verifying an overlong certificate chain.
Christopher Haster 1:24750b9ad5ef 52 */
Christopher Haster 1:24750b9ad5ef 53 #define MBEDTLS_X509_MAX_INTERMEDIATE_CA 8
Christopher Haster 1:24750b9ad5ef 54 #endif
Christopher Haster 1:24750b9ad5ef 55
Christopher Haster 1:24750b9ad5ef 56 /**
Christopher Haster 1:24750b9ad5ef 57 * \name X509 Error codes
Christopher Haster 1:24750b9ad5ef 58 * \{
Christopher Haster 1:24750b9ad5ef 59 */
Christopher Haster 1:24750b9ad5ef 60 #define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE -0x2080 /**< Unavailable feature, e.g. RSA hashing/encryption combination. */
Christopher Haster 1:24750b9ad5ef 61 #define MBEDTLS_ERR_X509_UNKNOWN_OID -0x2100 /**< Requested OID is unknown. */
Christopher Haster 1:24750b9ad5ef 62 #define MBEDTLS_ERR_X509_INVALID_FORMAT -0x2180 /**< The CRT/CRL/CSR format is invalid, e.g. different type expected. */
Christopher Haster 1:24750b9ad5ef 63 #define MBEDTLS_ERR_X509_INVALID_VERSION -0x2200 /**< The CRT/CRL/CSR version element is invalid. */
Christopher Haster 1:24750b9ad5ef 64 #define MBEDTLS_ERR_X509_INVALID_SERIAL -0x2280 /**< The serial tag or value is invalid. */
Christopher Haster 1:24750b9ad5ef 65 #define MBEDTLS_ERR_X509_INVALID_ALG -0x2300 /**< The algorithm tag or value is invalid. */
Christopher Haster 1:24750b9ad5ef 66 #define MBEDTLS_ERR_X509_INVALID_NAME -0x2380 /**< The name tag or value is invalid. */
Christopher Haster 1:24750b9ad5ef 67 #define MBEDTLS_ERR_X509_INVALID_DATE -0x2400 /**< The date tag or value is invalid. */
Christopher Haster 1:24750b9ad5ef 68 #define MBEDTLS_ERR_X509_INVALID_SIGNATURE -0x2480 /**< The signature tag or value invalid. */
Christopher Haster 1:24750b9ad5ef 69 #define MBEDTLS_ERR_X509_INVALID_EXTENSIONS -0x2500 /**< The extension tag or value is invalid. */
Christopher Haster 1:24750b9ad5ef 70 #define MBEDTLS_ERR_X509_UNKNOWN_VERSION -0x2580 /**< CRT/CRL/CSR has an unsupported version number. */
Christopher Haster 1:24750b9ad5ef 71 #define MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG -0x2600 /**< Signature algorithm (oid) is unsupported. */
Christopher Haster 1:24750b9ad5ef 72 #define MBEDTLS_ERR_X509_SIG_MISMATCH -0x2680 /**< Signature algorithms do not match. (see \c ::mbedtls_x509_crt sig_oid) */
Christopher Haster 1:24750b9ad5ef 73 #define MBEDTLS_ERR_X509_CERT_VERIFY_FAILED -0x2700 /**< Certificate verification failed, e.g. CRL, CA or signature check failed. */
Christopher Haster 1:24750b9ad5ef 74 #define MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT -0x2780 /**< Format not recognized as DER or PEM. */
Christopher Haster 1:24750b9ad5ef 75 #define MBEDTLS_ERR_X509_BAD_INPUT_DATA -0x2800 /**< Input invalid. */
Christopher Haster 1:24750b9ad5ef 76 #define MBEDTLS_ERR_X509_ALLOC_FAILED -0x2880 /**< Allocation of memory failed. */
Christopher Haster 1:24750b9ad5ef 77 #define MBEDTLS_ERR_X509_FILE_IO_ERROR -0x2900 /**< Read/write of file failed. */
Christopher Haster 1:24750b9ad5ef 78 #define MBEDTLS_ERR_X509_BUFFER_TOO_SMALL -0x2980 /**< Destination buffer is too small. */
Christopher Haster 1:24750b9ad5ef 79 /* \} name */
Christopher Haster 1:24750b9ad5ef 80
Christopher Haster 1:24750b9ad5ef 81 /**
Christopher Haster 1:24750b9ad5ef 82 * \name X509 Verify codes
Christopher Haster 1:24750b9ad5ef 83 * \{
Christopher Haster 1:24750b9ad5ef 84 */
Christopher Haster 1:24750b9ad5ef 85 /* Reminder: update x509_crt_verify_strings[] in library/x509_crt.c */
Christopher Haster 1:24750b9ad5ef 86 #define MBEDTLS_X509_BADCERT_EXPIRED 0x01 /**< The certificate validity has expired. */
Christopher Haster 1:24750b9ad5ef 87 #define MBEDTLS_X509_BADCERT_REVOKED 0x02 /**< The certificate has been revoked (is on a CRL). */
Christopher Haster 1:24750b9ad5ef 88 #define MBEDTLS_X509_BADCERT_CN_MISMATCH 0x04 /**< The certificate Common Name (CN) does not match with the expected CN. */
Christopher Haster 1:24750b9ad5ef 89 #define MBEDTLS_X509_BADCERT_NOT_TRUSTED 0x08 /**< The certificate is not correctly signed by the trusted CA. */
Christopher Haster 1:24750b9ad5ef 90 #define MBEDTLS_X509_BADCRL_NOT_TRUSTED 0x10 /**< The CRL is not correctly signed by the trusted CA. */
Christopher Haster 1:24750b9ad5ef 91 #define MBEDTLS_X509_BADCRL_EXPIRED 0x20 /**< The CRL is expired. */
Christopher Haster 1:24750b9ad5ef 92 #define MBEDTLS_X509_BADCERT_MISSING 0x40 /**< Certificate was missing. */
Christopher Haster 1:24750b9ad5ef 93 #define MBEDTLS_X509_BADCERT_SKIP_VERIFY 0x80 /**< Certificate verification was skipped. */
Christopher Haster 1:24750b9ad5ef 94 #define MBEDTLS_X509_BADCERT_OTHER 0x0100 /**< Other reason (can be used by verify callback) */
Christopher Haster 1:24750b9ad5ef 95 #define MBEDTLS_X509_BADCERT_FUTURE 0x0200 /**< The certificate validity starts in the future. */
Christopher Haster 1:24750b9ad5ef 96 #define MBEDTLS_X509_BADCRL_FUTURE 0x0400 /**< The CRL is from the future */
Christopher Haster 1:24750b9ad5ef 97 #define MBEDTLS_X509_BADCERT_KEY_USAGE 0x0800 /**< Usage does not match the keyUsage extension. */
Christopher Haster 1:24750b9ad5ef 98 #define MBEDTLS_X509_BADCERT_EXT_KEY_USAGE 0x1000 /**< Usage does not match the extendedKeyUsage extension. */
Christopher Haster 1:24750b9ad5ef 99 #define MBEDTLS_X509_BADCERT_NS_CERT_TYPE 0x2000 /**< Usage does not match the nsCertType extension. */
Christopher Haster 1:24750b9ad5ef 100 #define MBEDTLS_X509_BADCERT_BAD_MD 0x4000 /**< The certificate is signed with an unacceptable hash. */
Christopher Haster 1:24750b9ad5ef 101 #define MBEDTLS_X509_BADCERT_BAD_PK 0x8000 /**< The certificate is signed with an unacceptable PK alg (eg RSA vs ECDSA). */
Christopher Haster 1:24750b9ad5ef 102 #define MBEDTLS_X509_BADCERT_BAD_KEY 0x010000 /**< The certificate is signed with an unacceptable key (eg bad curve, RSA too short). */
Christopher Haster 1:24750b9ad5ef 103 #define MBEDTLS_X509_BADCRL_BAD_MD 0x020000 /**< The CRL is signed with an unacceptable hash. */
Christopher Haster 1:24750b9ad5ef 104 #define MBEDTLS_X509_BADCRL_BAD_PK 0x040000 /**< The CRL is signed with an unacceptable PK alg (eg RSA vs ECDSA). */
Christopher Haster 1:24750b9ad5ef 105 #define MBEDTLS_X509_BADCRL_BAD_KEY 0x080000 /**< The CRL is signed with an unacceptable key (eg bad curve, RSA too short). */
Christopher Haster 1:24750b9ad5ef 106
Christopher Haster 1:24750b9ad5ef 107 /* \} name */
Christopher Haster 1:24750b9ad5ef 108 /* \} addtogroup x509_module */
Christopher Haster 1:24750b9ad5ef 109
Christopher Haster 1:24750b9ad5ef 110 /*
Christopher Haster 1:24750b9ad5ef 111 * X.509 v3 Key Usage Extension flags
Christopher Haster 1:24750b9ad5ef 112 * Reminder: update x509_info_key_usage() when adding new flags.
Christopher Haster 1:24750b9ad5ef 113 */
Christopher Haster 1:24750b9ad5ef 114 #define MBEDTLS_X509_KU_DIGITAL_SIGNATURE (0x80) /* bit 0 */
Christopher Haster 1:24750b9ad5ef 115 #define MBEDTLS_X509_KU_NON_REPUDIATION (0x40) /* bit 1 */
Christopher Haster 1:24750b9ad5ef 116 #define MBEDTLS_X509_KU_KEY_ENCIPHERMENT (0x20) /* bit 2 */
Christopher Haster 1:24750b9ad5ef 117 #define MBEDTLS_X509_KU_DATA_ENCIPHERMENT (0x10) /* bit 3 */
Christopher Haster 1:24750b9ad5ef 118 #define MBEDTLS_X509_KU_KEY_AGREEMENT (0x08) /* bit 4 */
Christopher Haster 1:24750b9ad5ef 119 #define MBEDTLS_X509_KU_KEY_CERT_SIGN (0x04) /* bit 5 */
Christopher Haster 1:24750b9ad5ef 120 #define MBEDTLS_X509_KU_CRL_SIGN (0x02) /* bit 6 */
Christopher Haster 1:24750b9ad5ef 121 #define MBEDTLS_X509_KU_ENCIPHER_ONLY (0x01) /* bit 7 */
Christopher Haster 1:24750b9ad5ef 122 #define MBEDTLS_X509_KU_DECIPHER_ONLY (0x8000) /* bit 8 */
Christopher Haster 1:24750b9ad5ef 123
Christopher Haster 1:24750b9ad5ef 124 /*
Christopher Haster 1:24750b9ad5ef 125 * Netscape certificate types
Christopher Haster 1:24750b9ad5ef 126 * (http://www.mozilla.org/projects/security/pki/nss/tech-notes/tn3.html)
Christopher Haster 1:24750b9ad5ef 127 */
Christopher Haster 1:24750b9ad5ef 128
Christopher Haster 1:24750b9ad5ef 129 #define MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT (0x80) /* bit 0 */
Christopher Haster 1:24750b9ad5ef 130 #define MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER (0x40) /* bit 1 */
Christopher Haster 1:24750b9ad5ef 131 #define MBEDTLS_X509_NS_CERT_TYPE_EMAIL (0x20) /* bit 2 */
Christopher Haster 1:24750b9ad5ef 132 #define MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING (0x10) /* bit 3 */
Christopher Haster 1:24750b9ad5ef 133 #define MBEDTLS_X509_NS_CERT_TYPE_RESERVED (0x08) /* bit 4 */
Christopher Haster 1:24750b9ad5ef 134 #define MBEDTLS_X509_NS_CERT_TYPE_SSL_CA (0x04) /* bit 5 */
Christopher Haster 1:24750b9ad5ef 135 #define MBEDTLS_X509_NS_CERT_TYPE_EMAIL_CA (0x02) /* bit 6 */
Christopher Haster 1:24750b9ad5ef 136 #define MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING_CA (0x01) /* bit 7 */
Christopher Haster 1:24750b9ad5ef 137
Christopher Haster 1:24750b9ad5ef 138 /*
Christopher Haster 1:24750b9ad5ef 139 * X.509 extension types
Christopher Haster 1:24750b9ad5ef 140 *
Christopher Haster 1:24750b9ad5ef 141 * Comments refer to the status for using certificates. Status can be
Christopher Haster 1:24750b9ad5ef 142 * different for writing certificates or reading CRLs or CSRs.
Christopher Haster 1:24750b9ad5ef 143 */
Christopher Haster 1:24750b9ad5ef 144 #define MBEDTLS_X509_EXT_AUTHORITY_KEY_IDENTIFIER (1 << 0)
Christopher Haster 1:24750b9ad5ef 145 #define MBEDTLS_X509_EXT_SUBJECT_KEY_IDENTIFIER (1 << 1)
Christopher Haster 1:24750b9ad5ef 146 #define MBEDTLS_X509_EXT_KEY_USAGE (1 << 2)
Christopher Haster 1:24750b9ad5ef 147 #define MBEDTLS_X509_EXT_CERTIFICATE_POLICIES (1 << 3)
Christopher Haster 1:24750b9ad5ef 148 #define MBEDTLS_X509_EXT_POLICY_MAPPINGS (1 << 4)
Christopher Haster 1:24750b9ad5ef 149 #define MBEDTLS_X509_EXT_SUBJECT_ALT_NAME (1 << 5) /* Supported (DNS) */
Christopher Haster 1:24750b9ad5ef 150 #define MBEDTLS_X509_EXT_ISSUER_ALT_NAME (1 << 6)
Christopher Haster 1:24750b9ad5ef 151 #define MBEDTLS_X509_EXT_SUBJECT_DIRECTORY_ATTRS (1 << 7)
Christopher Haster 1:24750b9ad5ef 152 #define MBEDTLS_X509_EXT_BASIC_CONSTRAINTS (1 << 8) /* Supported */
Christopher Haster 1:24750b9ad5ef 153 #define MBEDTLS_X509_EXT_NAME_CONSTRAINTS (1 << 9)
Christopher Haster 1:24750b9ad5ef 154 #define MBEDTLS_X509_EXT_POLICY_CONSTRAINTS (1 << 10)
Christopher Haster 1:24750b9ad5ef 155 #define MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE (1 << 11)
Christopher Haster 1:24750b9ad5ef 156 #define MBEDTLS_X509_EXT_CRL_DISTRIBUTION_POINTS (1 << 12)
Christopher Haster 1:24750b9ad5ef 157 #define MBEDTLS_X509_EXT_INIHIBIT_ANYPOLICY (1 << 13)
Christopher Haster 1:24750b9ad5ef 158 #define MBEDTLS_X509_EXT_FRESHEST_CRL (1 << 14)
Christopher Haster 1:24750b9ad5ef 159
Christopher Haster 1:24750b9ad5ef 160 #define MBEDTLS_X509_EXT_NS_CERT_TYPE (1 << 16) /* Parsed (and then ?) */
Christopher Haster 1:24750b9ad5ef 161
Christopher Haster 1:24750b9ad5ef 162 /*
Christopher Haster 1:24750b9ad5ef 163 * Storage format identifiers
Christopher Haster 1:24750b9ad5ef 164 * Recognized formats: PEM and DER
Christopher Haster 1:24750b9ad5ef 165 */
Christopher Haster 1:24750b9ad5ef 166 #define MBEDTLS_X509_FORMAT_DER 1
Christopher Haster 1:24750b9ad5ef 167 #define MBEDTLS_X509_FORMAT_PEM 2
Christopher Haster 1:24750b9ad5ef 168
Christopher Haster 1:24750b9ad5ef 169 #define MBEDTLS_X509_MAX_DN_NAME_SIZE 256 /**< Maximum value size of a DN entry */
Christopher Haster 1:24750b9ad5ef 170
Christopher Haster 1:24750b9ad5ef 171 #ifdef __cplusplus
Christopher Haster 1:24750b9ad5ef 172 extern "C" {
Christopher Haster 1:24750b9ad5ef 173 #endif
Christopher Haster 1:24750b9ad5ef 174
Christopher Haster 1:24750b9ad5ef 175 /**
Christopher Haster 1:24750b9ad5ef 176 * \addtogroup x509_module
Christopher Haster 1:24750b9ad5ef 177 * \{ */
Christopher Haster 1:24750b9ad5ef 178
Christopher Haster 1:24750b9ad5ef 179 /**
Christopher Haster 1:24750b9ad5ef 180 * \name Structures for parsing X.509 certificates, CRLs and CSRs
Christopher Haster 1:24750b9ad5ef 181 * \{
Christopher Haster 1:24750b9ad5ef 182 */
Christopher Haster 1:24750b9ad5ef 183
Christopher Haster 1:24750b9ad5ef 184 /**
Christopher Haster 1:24750b9ad5ef 185 * Type-length-value structure that allows for ASN1 using DER.
Christopher Haster 1:24750b9ad5ef 186 */
Christopher Haster 1:24750b9ad5ef 187 typedef mbedtls_asn1_buf mbedtls_x509_buf;
Christopher Haster 1:24750b9ad5ef 188
Christopher Haster 1:24750b9ad5ef 189 /**
Christopher Haster 1:24750b9ad5ef 190 * Container for ASN1 bit strings.
Christopher Haster 1:24750b9ad5ef 191 */
Christopher Haster 1:24750b9ad5ef 192 typedef mbedtls_asn1_bitstring mbedtls_x509_bitstring;
Christopher Haster 1:24750b9ad5ef 193
Christopher Haster 1:24750b9ad5ef 194 /**
Christopher Haster 1:24750b9ad5ef 195 * Container for ASN1 named information objects.
Christopher Haster 1:24750b9ad5ef 196 * It allows for Relative Distinguished Names (e.g. cn=localhost,ou=code,etc.).
Christopher Haster 1:24750b9ad5ef 197 */
Christopher Haster 1:24750b9ad5ef 198 typedef mbedtls_asn1_named_data mbedtls_x509_name;
Christopher Haster 1:24750b9ad5ef 199
Christopher Haster 1:24750b9ad5ef 200 /**
Christopher Haster 1:24750b9ad5ef 201 * Container for a sequence of ASN.1 items
Christopher Haster 1:24750b9ad5ef 202 */
Christopher Haster 1:24750b9ad5ef 203 typedef mbedtls_asn1_sequence mbedtls_x509_sequence;
Christopher Haster 1:24750b9ad5ef 204
Christopher Haster 1:24750b9ad5ef 205 /** Container for date and time (precision in seconds). */
Christopher Haster 1:24750b9ad5ef 206 typedef struct mbedtls_x509_time
Christopher Haster 1:24750b9ad5ef 207 {
Christopher Haster 1:24750b9ad5ef 208 int year, mon, day; /**< Date. */
Christopher Haster 1:24750b9ad5ef 209 int hour, min, sec; /**< Time. */
Christopher Haster 1:24750b9ad5ef 210 }
Christopher Haster 1:24750b9ad5ef 211 mbedtls_x509_time;
Christopher Haster 1:24750b9ad5ef 212
Christopher Haster 1:24750b9ad5ef 213 /** \} name Structures for parsing X.509 certificates, CRLs and CSRs */
Christopher Haster 1:24750b9ad5ef 214 /** \} addtogroup x509_module */
Christopher Haster 1:24750b9ad5ef 215
Christopher Haster 1:24750b9ad5ef 216 /**
Christopher Haster 1:24750b9ad5ef 217 * \brief Store the certificate DN in printable form into buf;
Christopher Haster 1:24750b9ad5ef 218 * no more than size characters will be written.
Christopher Haster 1:24750b9ad5ef 219 *
Christopher Haster 1:24750b9ad5ef 220 * \param buf Buffer to write to
Christopher Haster 1:24750b9ad5ef 221 * \param size Maximum size of buffer
Christopher Haster 1:24750b9ad5ef 222 * \param dn The X509 name to represent
Christopher Haster 1:24750b9ad5ef 223 *
Christopher Haster 1:24750b9ad5ef 224 * \return The length of the string written (not including the
Christopher Haster 1:24750b9ad5ef 225 * terminated nul byte), or a negative error code.
Christopher Haster 1:24750b9ad5ef 226 */
Christopher Haster 1:24750b9ad5ef 227 int mbedtls_x509_dn_gets( char *buf, size_t size, const mbedtls_x509_name *dn );
Christopher Haster 1:24750b9ad5ef 228
Christopher Haster 1:24750b9ad5ef 229 /**
Christopher Haster 1:24750b9ad5ef 230 * \brief Store the certificate serial in printable form into buf;
Christopher Haster 1:24750b9ad5ef 231 * no more than size characters will be written.
Christopher Haster 1:24750b9ad5ef 232 *
Christopher Haster 1:24750b9ad5ef 233 * \param buf Buffer to write to
Christopher Haster 1:24750b9ad5ef 234 * \param size Maximum size of buffer
Christopher Haster 1:24750b9ad5ef 235 * \param serial The X509 serial to represent
Christopher Haster 1:24750b9ad5ef 236 *
Christopher Haster 1:24750b9ad5ef 237 * \return The length of the string written (not including the
Christopher Haster 1:24750b9ad5ef 238 * terminated nul byte), or a negative error code.
Christopher Haster 1:24750b9ad5ef 239 */
Christopher Haster 1:24750b9ad5ef 240 int mbedtls_x509_serial_gets( char *buf, size_t size, const mbedtls_x509_buf *serial );
Christopher Haster 1:24750b9ad5ef 241
Christopher Haster 1:24750b9ad5ef 242 /**
Christopher Haster 1:24750b9ad5ef 243 * \brief Check a given mbedtls_x509_time against the system time
Christopher Haster 1:24750b9ad5ef 244 * and tell if it's in the past.
Christopher Haster 1:24750b9ad5ef 245 *
Christopher Haster 1:24750b9ad5ef 246 * \note Intended usage is "if( is_past( valid_to ) ) ERROR".
Christopher Haster 1:24750b9ad5ef 247 * Hence the return value of 1 if on internal errors.
Christopher Haster 1:24750b9ad5ef 248 *
Christopher Haster 1:24750b9ad5ef 249 * \param time mbedtls_x509_time to check
Christopher Haster 1:24750b9ad5ef 250 *
Christopher Haster 1:24750b9ad5ef 251 * \return 1 if the given time is in the past or an error occured,
Christopher Haster 1:24750b9ad5ef 252 * 0 otherwise.
Christopher Haster 1:24750b9ad5ef 253 */
Christopher Haster 1:24750b9ad5ef 254 int mbedtls_x509_time_is_past( const mbedtls_x509_time *time );
Christopher Haster 1:24750b9ad5ef 255
Christopher Haster 1:24750b9ad5ef 256 /**
Christopher Haster 1:24750b9ad5ef 257 * \brief Check a given mbedtls_x509_time against the system time
Christopher Haster 1:24750b9ad5ef 258 * and tell if it's in the future.
Christopher Haster 1:24750b9ad5ef 259 *
Christopher Haster 1:24750b9ad5ef 260 * \note Intended usage is "if( is_future( valid_from ) ) ERROR".
Christopher Haster 1:24750b9ad5ef 261 * Hence the return value of 1 if on internal errors.
Christopher Haster 1:24750b9ad5ef 262 *
Christopher Haster 1:24750b9ad5ef 263 * \param time mbedtls_x509_time to check
Christopher Haster 1:24750b9ad5ef 264 *
Christopher Haster 1:24750b9ad5ef 265 * \return 1 if the given time is in the future or an error occured,
Christopher Haster 1:24750b9ad5ef 266 * 0 otherwise.
Christopher Haster 1:24750b9ad5ef 267 */
Christopher Haster 1:24750b9ad5ef 268 int mbedtls_x509_time_is_future( const mbedtls_x509_time *time );
Christopher Haster 1:24750b9ad5ef 269
Christopher Haster 1:24750b9ad5ef 270 /**
Christopher Haster 1:24750b9ad5ef 271 * \brief Checkup routine
Christopher Haster 1:24750b9ad5ef 272 *
Christopher Haster 1:24750b9ad5ef 273 * \return 0 if successful, or 1 if the test failed
Christopher Haster 1:24750b9ad5ef 274 */
Christopher Haster 1:24750b9ad5ef 275 int mbedtls_x509_self_test( int verbose );
Christopher Haster 1:24750b9ad5ef 276
Christopher Haster 1:24750b9ad5ef 277 /*
Christopher Haster 1:24750b9ad5ef 278 * Internal module functions. You probably do not want to use these unless you
Christopher Haster 1:24750b9ad5ef 279 * know you do.
Christopher Haster 1:24750b9ad5ef 280 */
Christopher Haster 1:24750b9ad5ef 281 int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end,
Christopher Haster 1:24750b9ad5ef 282 mbedtls_x509_name *cur );
Christopher Haster 1:24750b9ad5ef 283 int mbedtls_x509_get_alg_null( unsigned char **p, const unsigned char *end,
Christopher Haster 1:24750b9ad5ef 284 mbedtls_x509_buf *alg );
Christopher Haster 1:24750b9ad5ef 285 int mbedtls_x509_get_alg( unsigned char **p, const unsigned char *end,
Christopher Haster 1:24750b9ad5ef 286 mbedtls_x509_buf *alg, mbedtls_x509_buf *params );
Christopher Haster 1:24750b9ad5ef 287 #if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
Christopher Haster 1:24750b9ad5ef 288 int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params,
Christopher Haster 1:24750b9ad5ef 289 mbedtls_md_type_t *md_alg, mbedtls_md_type_t *mgf_md,
Christopher Haster 1:24750b9ad5ef 290 int *salt_len );
Christopher Haster 1:24750b9ad5ef 291 #endif
Christopher Haster 1:24750b9ad5ef 292 int mbedtls_x509_get_sig( unsigned char **p, const unsigned char *end, mbedtls_x509_buf *sig );
Christopher Haster 1:24750b9ad5ef 293 int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x509_buf *sig_params,
Christopher Haster 1:24750b9ad5ef 294 mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg,
Christopher Haster 1:24750b9ad5ef 295 void **sig_opts );
Christopher Haster 1:24750b9ad5ef 296 int mbedtls_x509_get_time( unsigned char **p, const unsigned char *end,
Christopher Haster 1:24750b9ad5ef 297 mbedtls_x509_time *time );
Christopher Haster 1:24750b9ad5ef 298 int mbedtls_x509_get_serial( unsigned char **p, const unsigned char *end,
Christopher Haster 1:24750b9ad5ef 299 mbedtls_x509_buf *serial );
Christopher Haster 1:24750b9ad5ef 300 int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end,
Christopher Haster 1:24750b9ad5ef 301 mbedtls_x509_buf *ext, int tag );
Christopher Haster 1:24750b9ad5ef 302 int mbedtls_x509_sig_alg_gets( char *buf, size_t size, const mbedtls_x509_buf *sig_oid,
Christopher Haster 1:24750b9ad5ef 303 mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg,
Christopher Haster 1:24750b9ad5ef 304 const void *sig_opts );
Christopher Haster 1:24750b9ad5ef 305 int mbedtls_x509_key_size_helper( char *buf, size_t buf_size, const char *name );
Christopher Haster 1:24750b9ad5ef 306 int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *name );
Christopher Haster 1:24750b9ad5ef 307 int mbedtls_x509_set_extension( mbedtls_asn1_named_data **head, const char *oid, size_t oid_len,
Christopher Haster 1:24750b9ad5ef 308 int critical, const unsigned char *val,
Christopher Haster 1:24750b9ad5ef 309 size_t val_len );
Christopher Haster 1:24750b9ad5ef 310 int mbedtls_x509_write_extensions( unsigned char **p, unsigned char *start,
Christopher Haster 1:24750b9ad5ef 311 mbedtls_asn1_named_data *first );
Christopher Haster 1:24750b9ad5ef 312 int mbedtls_x509_write_names( unsigned char **p, unsigned char *start,
Christopher Haster 1:24750b9ad5ef 313 mbedtls_asn1_named_data *first );
Christopher Haster 1:24750b9ad5ef 314 int mbedtls_x509_write_sig( unsigned char **p, unsigned char *start,
Christopher Haster 1:24750b9ad5ef 315 const char *oid, size_t oid_len,
Christopher Haster 1:24750b9ad5ef 316 unsigned char *sig, size_t size );
Christopher Haster 1:24750b9ad5ef 317
Christopher Haster 1:24750b9ad5ef 318 #define MBEDTLS_X509_SAFE_SNPRINTF \
Christopher Haster 1:24750b9ad5ef 319 do { \
Christopher Haster 1:24750b9ad5ef 320 if( ret < 0 || (size_t) ret >= n ) \
Christopher Haster 1:24750b9ad5ef 321 return( MBEDTLS_ERR_X509_BUFFER_TOO_SMALL ); \
Christopher Haster 1:24750b9ad5ef 322 \
Christopher Haster 1:24750b9ad5ef 323 n -= (size_t) ret; \
Christopher Haster 1:24750b9ad5ef 324 p += (size_t) ret; \
Christopher Haster 1:24750b9ad5ef 325 } while( 0 )
Christopher Haster 1:24750b9ad5ef 326
Christopher Haster 1:24750b9ad5ef 327 #ifdef __cplusplus
Christopher Haster 1:24750b9ad5ef 328 }
Christopher Haster 1:24750b9ad5ef 329 #endif
Christopher Haster 1:24750b9ad5ef 330
Christopher Haster 1:24750b9ad5ef 331 #endif /* x509.h */