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