mbed client lightswitch demo

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by Austin Blackstone

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 11:cada08fc8a70 1 /**
mbedAustin 11:cada08fc8a70 2 * \file asn1.h
mbedAustin 11:cada08fc8a70 3 *
mbedAustin 11:cada08fc8a70 4 * \brief Generic ASN.1 parsing
mbedAustin 11:cada08fc8a70 5 *
mbedAustin 11:cada08fc8a70 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
mbedAustin 11:cada08fc8a70 7 * SPDX-License-Identifier: Apache-2.0
mbedAustin 11:cada08fc8a70 8 *
mbedAustin 11:cada08fc8a70 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
mbedAustin 11:cada08fc8a70 10 * not use this file except in compliance with the License.
mbedAustin 11:cada08fc8a70 11 * You may obtain a copy of the License at
mbedAustin 11:cada08fc8a70 12 *
mbedAustin 11:cada08fc8a70 13 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 11:cada08fc8a70 14 *
mbedAustin 11:cada08fc8a70 15 * Unless required by applicable law or agreed to in writing, software
mbedAustin 11:cada08fc8a70 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
mbedAustin 11:cada08fc8a70 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 11:cada08fc8a70 18 * See the License for the specific language governing permissions and
mbedAustin 11:cada08fc8a70 19 * limitations under the License.
mbedAustin 11:cada08fc8a70 20 *
mbedAustin 11:cada08fc8a70 21 * This file is part of mbed TLS (https://tls.mbed.org)
mbedAustin 11:cada08fc8a70 22 */
mbedAustin 11:cada08fc8a70 23 #ifndef MBEDTLS_ASN1_H
mbedAustin 11:cada08fc8a70 24 #define MBEDTLS_ASN1_H
mbedAustin 11:cada08fc8a70 25
mbedAustin 11:cada08fc8a70 26 #if !defined(MBEDTLS_CONFIG_FILE)
mbedAustin 11:cada08fc8a70 27 #include "config.h"
mbedAustin 11:cada08fc8a70 28 #else
mbedAustin 11:cada08fc8a70 29 #include MBEDTLS_CONFIG_FILE
mbedAustin 11:cada08fc8a70 30 #endif
mbedAustin 11:cada08fc8a70 31
mbedAustin 11:cada08fc8a70 32 #include <stddef.h>
mbedAustin 11:cada08fc8a70 33
mbedAustin 11:cada08fc8a70 34 #if defined(MBEDTLS_BIGNUM_C)
mbedAustin 11:cada08fc8a70 35 #include "bignum.h"
mbedAustin 11:cada08fc8a70 36 #endif
mbedAustin 11:cada08fc8a70 37
mbedAustin 11:cada08fc8a70 38 /**
mbedAustin 11:cada08fc8a70 39 * \addtogroup asn1_module
mbedAustin 11:cada08fc8a70 40 * \{
mbedAustin 11:cada08fc8a70 41 */
mbedAustin 11:cada08fc8a70 42
mbedAustin 11:cada08fc8a70 43 /**
mbedAustin 11:cada08fc8a70 44 * \name ASN1 Error codes
mbedAustin 11:cada08fc8a70 45 * These error codes are OR'ed to X509 error codes for
mbedAustin 11:cada08fc8a70 46 * higher error granularity.
mbedAustin 11:cada08fc8a70 47 * ASN1 is a standard to specify data structures.
mbedAustin 11:cada08fc8a70 48 * \{
mbedAustin 11:cada08fc8a70 49 */
mbedAustin 11:cada08fc8a70 50 #define MBEDTLS_ERR_ASN1_OUT_OF_DATA -0x0060 /**< Out of data when parsing an ASN1 data structure. */
mbedAustin 11:cada08fc8a70 51 #define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG -0x0062 /**< ASN1 tag was of an unexpected value. */
mbedAustin 11:cada08fc8a70 52 #define MBEDTLS_ERR_ASN1_INVALID_LENGTH -0x0064 /**< Error when trying to determine the length or invalid length. */
mbedAustin 11:cada08fc8a70 53 #define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH -0x0066 /**< Actual length differs from expected length. */
mbedAustin 11:cada08fc8a70 54 #define MBEDTLS_ERR_ASN1_INVALID_DATA -0x0068 /**< Data is invalid. (not used) */
mbedAustin 11:cada08fc8a70 55 #define MBEDTLS_ERR_ASN1_ALLOC_FAILED -0x006A /**< Memory allocation failed */
mbedAustin 11:cada08fc8a70 56 #define MBEDTLS_ERR_ASN1_BUF_TOO_SMALL -0x006C /**< Buffer too small when writing ASN.1 data structure. */
mbedAustin 11:cada08fc8a70 57
mbedAustin 11:cada08fc8a70 58 /* \} name */
mbedAustin 11:cada08fc8a70 59
mbedAustin 11:cada08fc8a70 60 /**
mbedAustin 11:cada08fc8a70 61 * \name DER constants
mbedAustin 11:cada08fc8a70 62 * These constants comply with DER encoded the ANS1 type tags.
mbedAustin 11:cada08fc8a70 63 * DER encoding uses hexadecimal representation.
mbedAustin 11:cada08fc8a70 64 * An example DER sequence is:\n
mbedAustin 11:cada08fc8a70 65 * - 0x02 -- tag indicating INTEGER
mbedAustin 11:cada08fc8a70 66 * - 0x01 -- length in octets
mbedAustin 11:cada08fc8a70 67 * - 0x05 -- value
mbedAustin 11:cada08fc8a70 68 * Such sequences are typically read into \c ::mbedtls_x509_buf.
mbedAustin 11:cada08fc8a70 69 * \{
mbedAustin 11:cada08fc8a70 70 */
mbedAustin 11:cada08fc8a70 71 #define MBEDTLS_ASN1_BOOLEAN 0x01
mbedAustin 11:cada08fc8a70 72 #define MBEDTLS_ASN1_INTEGER 0x02
mbedAustin 11:cada08fc8a70 73 #define MBEDTLS_ASN1_BIT_STRING 0x03
mbedAustin 11:cada08fc8a70 74 #define MBEDTLS_ASN1_OCTET_STRING 0x04
mbedAustin 11:cada08fc8a70 75 #define MBEDTLS_ASN1_NULL 0x05
mbedAustin 11:cada08fc8a70 76 #define MBEDTLS_ASN1_OID 0x06
mbedAustin 11:cada08fc8a70 77 #define MBEDTLS_ASN1_UTF8_STRING 0x0C
mbedAustin 11:cada08fc8a70 78 #define MBEDTLS_ASN1_SEQUENCE 0x10
mbedAustin 11:cada08fc8a70 79 #define MBEDTLS_ASN1_SET 0x11
mbedAustin 11:cada08fc8a70 80 #define MBEDTLS_ASN1_PRINTABLE_STRING 0x13
mbedAustin 11:cada08fc8a70 81 #define MBEDTLS_ASN1_T61_STRING 0x14
mbedAustin 11:cada08fc8a70 82 #define MBEDTLS_ASN1_IA5_STRING 0x16
mbedAustin 11:cada08fc8a70 83 #define MBEDTLS_ASN1_UTC_TIME 0x17
mbedAustin 11:cada08fc8a70 84 #define MBEDTLS_ASN1_GENERALIZED_TIME 0x18
mbedAustin 11:cada08fc8a70 85 #define MBEDTLS_ASN1_UNIVERSAL_STRING 0x1C
mbedAustin 11:cada08fc8a70 86 #define MBEDTLS_ASN1_BMP_STRING 0x1E
mbedAustin 11:cada08fc8a70 87 #define MBEDTLS_ASN1_PRIMITIVE 0x00
mbedAustin 11:cada08fc8a70 88 #define MBEDTLS_ASN1_CONSTRUCTED 0x20
mbedAustin 11:cada08fc8a70 89 #define MBEDTLS_ASN1_CONTEXT_SPECIFIC 0x80
mbedAustin 11:cada08fc8a70 90 /* \} name */
mbedAustin 11:cada08fc8a70 91 /* \} addtogroup asn1_module */
mbedAustin 11:cada08fc8a70 92
mbedAustin 11:cada08fc8a70 93 /** Returns the size of the binary string, without the trailing \\0 */
mbedAustin 11:cada08fc8a70 94 #define MBEDTLS_OID_SIZE(x) (sizeof(x) - 1)
mbedAustin 11:cada08fc8a70 95
mbedAustin 11:cada08fc8a70 96 /**
mbedAustin 11:cada08fc8a70 97 * Compares an mbedtls_asn1_buf structure to a reference OID.
mbedAustin 11:cada08fc8a70 98 *
mbedAustin 11:cada08fc8a70 99 * Only works for 'defined' oid_str values (MBEDTLS_OID_HMAC_SHA1), you cannot use a
mbedAustin 11:cada08fc8a70 100 * 'unsigned char *oid' here!
mbedAustin 11:cada08fc8a70 101 */
mbedAustin 11:cada08fc8a70 102 #define MBEDTLS_OID_CMP(oid_str, oid_buf) \
mbedAustin 11:cada08fc8a70 103 ( ( MBEDTLS_OID_SIZE(oid_str) != (oid_buf)->len ) || \
mbedAustin 11:cada08fc8a70 104 memcmp( (oid_str), (oid_buf)->p, (oid_buf)->len) != 0 )
mbedAustin 11:cada08fc8a70 105
mbedAustin 11:cada08fc8a70 106 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 107 extern "C" {
mbedAustin 11:cada08fc8a70 108 #endif
mbedAustin 11:cada08fc8a70 109
mbedAustin 11:cada08fc8a70 110 /**
mbedAustin 11:cada08fc8a70 111 * \name Functions to parse ASN.1 data structures
mbedAustin 11:cada08fc8a70 112 * \{
mbedAustin 11:cada08fc8a70 113 */
mbedAustin 11:cada08fc8a70 114
mbedAustin 11:cada08fc8a70 115 /**
mbedAustin 11:cada08fc8a70 116 * Type-length-value structure that allows for ASN1 using DER.
mbedAustin 11:cada08fc8a70 117 */
mbedAustin 11:cada08fc8a70 118 typedef struct mbedtls_asn1_buf
mbedAustin 11:cada08fc8a70 119 {
mbedAustin 11:cada08fc8a70 120 int tag; /**< ASN1 type, e.g. MBEDTLS_ASN1_UTF8_STRING. */
mbedAustin 11:cada08fc8a70 121 size_t len; /**< ASN1 length, in octets. */
mbedAustin 11:cada08fc8a70 122 unsigned char *p; /**< ASN1 data, e.g. in ASCII. */
mbedAustin 11:cada08fc8a70 123 }
mbedAustin 11:cada08fc8a70 124 mbedtls_asn1_buf;
mbedAustin 11:cada08fc8a70 125
mbedAustin 11:cada08fc8a70 126 /**
mbedAustin 11:cada08fc8a70 127 * Container for ASN1 bit strings.
mbedAustin 11:cada08fc8a70 128 */
mbedAustin 11:cada08fc8a70 129 typedef struct mbedtls_asn1_bitstring
mbedAustin 11:cada08fc8a70 130 {
mbedAustin 11:cada08fc8a70 131 size_t len; /**< ASN1 length, in octets. */
mbedAustin 11:cada08fc8a70 132 unsigned char unused_bits; /**< Number of unused bits at the end of the string */
mbedAustin 11:cada08fc8a70 133 unsigned char *p; /**< Raw ASN1 data for the bit string */
mbedAustin 11:cada08fc8a70 134 }
mbedAustin 11:cada08fc8a70 135 mbedtls_asn1_bitstring;
mbedAustin 11:cada08fc8a70 136
mbedAustin 11:cada08fc8a70 137 /**
mbedAustin 11:cada08fc8a70 138 * Container for a sequence of ASN.1 items
mbedAustin 11:cada08fc8a70 139 */
mbedAustin 11:cada08fc8a70 140 typedef struct mbedtls_asn1_sequence
mbedAustin 11:cada08fc8a70 141 {
mbedAustin 11:cada08fc8a70 142 mbedtls_asn1_buf buf; /**< Buffer containing the given ASN.1 item. */
mbedAustin 11:cada08fc8a70 143 struct mbedtls_asn1_sequence *next; /**< The next entry in the sequence. */
mbedAustin 11:cada08fc8a70 144 }
mbedAustin 11:cada08fc8a70 145 mbedtls_asn1_sequence;
mbedAustin 11:cada08fc8a70 146
mbedAustin 11:cada08fc8a70 147 /**
mbedAustin 11:cada08fc8a70 148 * Container for a sequence or list of 'named' ASN.1 data items
mbedAustin 11:cada08fc8a70 149 */
mbedAustin 11:cada08fc8a70 150 typedef struct mbedtls_asn1_named_data
mbedAustin 11:cada08fc8a70 151 {
mbedAustin 11:cada08fc8a70 152 mbedtls_asn1_buf oid; /**< The object identifier. */
mbedAustin 11:cada08fc8a70 153 mbedtls_asn1_buf val; /**< The named value. */
mbedAustin 11:cada08fc8a70 154 struct mbedtls_asn1_named_data *next; /**< The next entry in the sequence. */
mbedAustin 11:cada08fc8a70 155 unsigned char next_merged; /**< Merge next item into the current one? */
mbedAustin 11:cada08fc8a70 156 }
mbedAustin 11:cada08fc8a70 157 mbedtls_asn1_named_data;
mbedAustin 11:cada08fc8a70 158
mbedAustin 11:cada08fc8a70 159 /**
mbedAustin 11:cada08fc8a70 160 * \brief Get the length of an ASN.1 element.
mbedAustin 11:cada08fc8a70 161 * Updates the pointer to immediately behind the length.
mbedAustin 11:cada08fc8a70 162 *
mbedAustin 11:cada08fc8a70 163 * \param p The position in the ASN.1 data
mbedAustin 11:cada08fc8a70 164 * \param end End of data
mbedAustin 11:cada08fc8a70 165 * \param len The variable that will receive the value
mbedAustin 11:cada08fc8a70 166 *
mbedAustin 11:cada08fc8a70 167 * \return 0 if successful, MBEDTLS_ERR_ASN1_OUT_OF_DATA on reaching
mbedAustin 11:cada08fc8a70 168 * end of data, MBEDTLS_ERR_ASN1_INVALID_LENGTH if length is
mbedAustin 11:cada08fc8a70 169 * unparseable.
mbedAustin 11:cada08fc8a70 170 */
mbedAustin 11:cada08fc8a70 171 int mbedtls_asn1_get_len( unsigned char **p,
mbedAustin 11:cada08fc8a70 172 const unsigned char *end,
mbedAustin 11:cada08fc8a70 173 size_t *len );
mbedAustin 11:cada08fc8a70 174
mbedAustin 11:cada08fc8a70 175 /**
mbedAustin 11:cada08fc8a70 176 * \brief Get the tag and length of the tag. Check for the requested tag.
mbedAustin 11:cada08fc8a70 177 * Updates the pointer to immediately behind the tag and length.
mbedAustin 11:cada08fc8a70 178 *
mbedAustin 11:cada08fc8a70 179 * \param p The position in the ASN.1 data
mbedAustin 11:cada08fc8a70 180 * \param end End of data
mbedAustin 11:cada08fc8a70 181 * \param len The variable that will receive the length
mbedAustin 11:cada08fc8a70 182 * \param tag The expected tag
mbedAustin 11:cada08fc8a70 183 *
mbedAustin 11:cada08fc8a70 184 * \return 0 if successful, MBEDTLS_ERR_ASN1_UNEXPECTED_TAG if tag did
mbedAustin 11:cada08fc8a70 185 * not match requested tag, or another specific ASN.1 error code.
mbedAustin 11:cada08fc8a70 186 */
mbedAustin 11:cada08fc8a70 187 int mbedtls_asn1_get_tag( unsigned char **p,
mbedAustin 11:cada08fc8a70 188 const unsigned char *end,
mbedAustin 11:cada08fc8a70 189 size_t *len, int tag );
mbedAustin 11:cada08fc8a70 190
mbedAustin 11:cada08fc8a70 191 /**
mbedAustin 11:cada08fc8a70 192 * \brief Retrieve a boolean ASN.1 tag and its value.
mbedAustin 11:cada08fc8a70 193 * Updates the pointer to immediately behind the full tag.
mbedAustin 11:cada08fc8a70 194 *
mbedAustin 11:cada08fc8a70 195 * \param p The position in the ASN.1 data
mbedAustin 11:cada08fc8a70 196 * \param end End of data
mbedAustin 11:cada08fc8a70 197 * \param val The variable that will receive the value
mbedAustin 11:cada08fc8a70 198 *
mbedAustin 11:cada08fc8a70 199 * \return 0 if successful or a specific ASN.1 error code.
mbedAustin 11:cada08fc8a70 200 */
mbedAustin 11:cada08fc8a70 201 int mbedtls_asn1_get_bool( unsigned char **p,
mbedAustin 11:cada08fc8a70 202 const unsigned char *end,
mbedAustin 11:cada08fc8a70 203 int *val );
mbedAustin 11:cada08fc8a70 204
mbedAustin 11:cada08fc8a70 205 /**
mbedAustin 11:cada08fc8a70 206 * \brief Retrieve an integer ASN.1 tag and its value.
mbedAustin 11:cada08fc8a70 207 * Updates the pointer to immediately behind the full tag.
mbedAustin 11:cada08fc8a70 208 *
mbedAustin 11:cada08fc8a70 209 * \param p The position in the ASN.1 data
mbedAustin 11:cada08fc8a70 210 * \param end End of data
mbedAustin 11:cada08fc8a70 211 * \param val The variable that will receive the value
mbedAustin 11:cada08fc8a70 212 *
mbedAustin 11:cada08fc8a70 213 * \return 0 if successful or a specific ASN.1 error code.
mbedAustin 11:cada08fc8a70 214 */
mbedAustin 11:cada08fc8a70 215 int mbedtls_asn1_get_int( unsigned char **p,
mbedAustin 11:cada08fc8a70 216 const unsigned char *end,
mbedAustin 11:cada08fc8a70 217 int *val );
mbedAustin 11:cada08fc8a70 218
mbedAustin 11:cada08fc8a70 219 /**
mbedAustin 11:cada08fc8a70 220 * \brief Retrieve a bitstring ASN.1 tag and its value.
mbedAustin 11:cada08fc8a70 221 * Updates the pointer to immediately behind the full tag.
mbedAustin 11:cada08fc8a70 222 *
mbedAustin 11:cada08fc8a70 223 * \param p The position in the ASN.1 data
mbedAustin 11:cada08fc8a70 224 * \param end End of data
mbedAustin 11:cada08fc8a70 225 * \param bs The variable that will receive the value
mbedAustin 11:cada08fc8a70 226 *
mbedAustin 11:cada08fc8a70 227 * \return 0 if successful or a specific ASN.1 error code.
mbedAustin 11:cada08fc8a70 228 */
mbedAustin 11:cada08fc8a70 229 int mbedtls_asn1_get_bitstring( unsigned char **p, const unsigned char *end,
mbedAustin 11:cada08fc8a70 230 mbedtls_asn1_bitstring *bs);
mbedAustin 11:cada08fc8a70 231
mbedAustin 11:cada08fc8a70 232 /**
mbedAustin 11:cada08fc8a70 233 * \brief Retrieve a bitstring ASN.1 tag without unused bits and its
mbedAustin 11:cada08fc8a70 234 * value.
mbedAustin 11:cada08fc8a70 235 * Updates the pointer to the beginning of the bit/octet string.
mbedAustin 11:cada08fc8a70 236 *
mbedAustin 11:cada08fc8a70 237 * \param p The position in the ASN.1 data
mbedAustin 11:cada08fc8a70 238 * \param end End of data
mbedAustin 11:cada08fc8a70 239 * \param len Length of the actual bit/octect string in bytes
mbedAustin 11:cada08fc8a70 240 *
mbedAustin 11:cada08fc8a70 241 * \return 0 if successful or a specific ASN.1 error code.
mbedAustin 11:cada08fc8a70 242 */
mbedAustin 11:cada08fc8a70 243 int mbedtls_asn1_get_bitstring_null( unsigned char **p, const unsigned char *end,
mbedAustin 11:cada08fc8a70 244 size_t *len );
mbedAustin 11:cada08fc8a70 245
mbedAustin 11:cada08fc8a70 246 /**
mbedAustin 11:cada08fc8a70 247 * \brief Parses and splits an ASN.1 "SEQUENCE OF <tag>"
mbedAustin 11:cada08fc8a70 248 * Updated the pointer to immediately behind the full sequence tag.
mbedAustin 11:cada08fc8a70 249 *
mbedAustin 11:cada08fc8a70 250 * \param p The position in the ASN.1 data
mbedAustin 11:cada08fc8a70 251 * \param end End of data
mbedAustin 11:cada08fc8a70 252 * \param cur First variable in the chain to fill
mbedAustin 11:cada08fc8a70 253 * \param tag Type of sequence
mbedAustin 11:cada08fc8a70 254 *
mbedAustin 11:cada08fc8a70 255 * \return 0 if successful or a specific ASN.1 error code.
mbedAustin 11:cada08fc8a70 256 */
mbedAustin 11:cada08fc8a70 257 int mbedtls_asn1_get_sequence_of( unsigned char **p,
mbedAustin 11:cada08fc8a70 258 const unsigned char *end,
mbedAustin 11:cada08fc8a70 259 mbedtls_asn1_sequence *cur,
mbedAustin 11:cada08fc8a70 260 int tag);
mbedAustin 11:cada08fc8a70 261
mbedAustin 11:cada08fc8a70 262 #if defined(MBEDTLS_BIGNUM_C)
mbedAustin 11:cada08fc8a70 263 /**
mbedAustin 11:cada08fc8a70 264 * \brief Retrieve a MPI value from an integer ASN.1 tag.
mbedAustin 11:cada08fc8a70 265 * Updates the pointer to immediately behind the full tag.
mbedAustin 11:cada08fc8a70 266 *
mbedAustin 11:cada08fc8a70 267 * \param p The position in the ASN.1 data
mbedAustin 11:cada08fc8a70 268 * \param end End of data
mbedAustin 11:cada08fc8a70 269 * \param X The MPI that will receive the value
mbedAustin 11:cada08fc8a70 270 *
mbedAustin 11:cada08fc8a70 271 * \return 0 if successful or a specific ASN.1 or MPI error code.
mbedAustin 11:cada08fc8a70 272 */
mbedAustin 11:cada08fc8a70 273 int mbedtls_asn1_get_mpi( unsigned char **p,
mbedAustin 11:cada08fc8a70 274 const unsigned char *end,
mbedAustin 11:cada08fc8a70 275 mbedtls_mpi *X );
mbedAustin 11:cada08fc8a70 276 #endif /* MBEDTLS_BIGNUM_C */
mbedAustin 11:cada08fc8a70 277
mbedAustin 11:cada08fc8a70 278 /**
mbedAustin 11:cada08fc8a70 279 * \brief Retrieve an AlgorithmIdentifier ASN.1 sequence.
mbedAustin 11:cada08fc8a70 280 * Updates the pointer to immediately behind the full
mbedAustin 11:cada08fc8a70 281 * AlgorithmIdentifier.
mbedAustin 11:cada08fc8a70 282 *
mbedAustin 11:cada08fc8a70 283 * \param p The position in the ASN.1 data
mbedAustin 11:cada08fc8a70 284 * \param end End of data
mbedAustin 11:cada08fc8a70 285 * \param alg The buffer to receive the OID
mbedAustin 11:cada08fc8a70 286 * \param params The buffer to receive the params (if any)
mbedAustin 11:cada08fc8a70 287 *
mbedAustin 11:cada08fc8a70 288 * \return 0 if successful or a specific ASN.1 or MPI error code.
mbedAustin 11:cada08fc8a70 289 */
mbedAustin 11:cada08fc8a70 290 int mbedtls_asn1_get_alg( unsigned char **p,
mbedAustin 11:cada08fc8a70 291 const unsigned char *end,
mbedAustin 11:cada08fc8a70 292 mbedtls_asn1_buf *alg, mbedtls_asn1_buf *params );
mbedAustin 11:cada08fc8a70 293
mbedAustin 11:cada08fc8a70 294 /**
mbedAustin 11:cada08fc8a70 295 * \brief Retrieve an AlgorithmIdentifier ASN.1 sequence with NULL or no
mbedAustin 11:cada08fc8a70 296 * params.
mbedAustin 11:cada08fc8a70 297 * Updates the pointer to immediately behind the full
mbedAustin 11:cada08fc8a70 298 * AlgorithmIdentifier.
mbedAustin 11:cada08fc8a70 299 *
mbedAustin 11:cada08fc8a70 300 * \param p The position in the ASN.1 data
mbedAustin 11:cada08fc8a70 301 * \param end End of data
mbedAustin 11:cada08fc8a70 302 * \param alg The buffer to receive the OID
mbedAustin 11:cada08fc8a70 303 *
mbedAustin 11:cada08fc8a70 304 * \return 0 if successful or a specific ASN.1 or MPI error code.
mbedAustin 11:cada08fc8a70 305 */
mbedAustin 11:cada08fc8a70 306 int mbedtls_asn1_get_alg_null( unsigned char **p,
mbedAustin 11:cada08fc8a70 307 const unsigned char *end,
mbedAustin 11:cada08fc8a70 308 mbedtls_asn1_buf *alg );
mbedAustin 11:cada08fc8a70 309
mbedAustin 11:cada08fc8a70 310 /**
mbedAustin 11:cada08fc8a70 311 * \brief Find a specific named_data entry in a sequence or list based on
mbedAustin 11:cada08fc8a70 312 * the OID.
mbedAustin 11:cada08fc8a70 313 *
mbedAustin 11:cada08fc8a70 314 * \param list The list to seek through
mbedAustin 11:cada08fc8a70 315 * \param oid The OID to look for
mbedAustin 11:cada08fc8a70 316 * \param len Size of the OID
mbedAustin 11:cada08fc8a70 317 *
mbedAustin 11:cada08fc8a70 318 * \return NULL if not found, or a pointer to the existing entry.
mbedAustin 11:cada08fc8a70 319 */
mbedAustin 11:cada08fc8a70 320 mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( mbedtls_asn1_named_data *list,
mbedAustin 11:cada08fc8a70 321 const char *oid, size_t len );
mbedAustin 11:cada08fc8a70 322
mbedAustin 11:cada08fc8a70 323 /**
mbedAustin 11:cada08fc8a70 324 * \brief Free a mbedtls_asn1_named_data entry
mbedAustin 11:cada08fc8a70 325 *
mbedAustin 11:cada08fc8a70 326 * \param entry The named data entry to free
mbedAustin 11:cada08fc8a70 327 */
mbedAustin 11:cada08fc8a70 328 void mbedtls_asn1_free_named_data( mbedtls_asn1_named_data *entry );
mbedAustin 11:cada08fc8a70 329
mbedAustin 11:cada08fc8a70 330 /**
mbedAustin 11:cada08fc8a70 331 * \brief Free all entries in a mbedtls_asn1_named_data list
mbedAustin 11:cada08fc8a70 332 * Head will be set to NULL
mbedAustin 11:cada08fc8a70 333 *
mbedAustin 11:cada08fc8a70 334 * \param head Pointer to the head of the list of named data entries to free
mbedAustin 11:cada08fc8a70 335 */
mbedAustin 11:cada08fc8a70 336 void mbedtls_asn1_free_named_data_list( mbedtls_asn1_named_data **head );
mbedAustin 11:cada08fc8a70 337
mbedAustin 11:cada08fc8a70 338 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 339 }
mbedAustin 11:cada08fc8a70 340 #endif
mbedAustin 11:cada08fc8a70 341
mbedAustin 11:cada08fc8a70 342 #endif /* asn1.h */