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