Hannes Tschofenig
/
aes-gcm-test-program
Example program to test AES-GCM functionality. Used for a workshop
SSL/include/polarssl/asn1.h@0:796d0f61a05b, 2018-09-27 (annotated)
- Committer:
- HannesTschofenig
- Date:
- Thu Sep 27 06:34:22 2018 +0000
- Revision:
- 0:796d0f61a05b
Example AES-GCM test program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
HannesTschofenig | 0:796d0f61a05b | 1 | /** |
HannesTschofenig | 0:796d0f61a05b | 2 | * \file asn1.h |
HannesTschofenig | 0:796d0f61a05b | 3 | * |
HannesTschofenig | 0:796d0f61a05b | 4 | * \brief Generic ASN.1 parsing |
HannesTschofenig | 0:796d0f61a05b | 5 | * |
HannesTschofenig | 0:796d0f61a05b | 6 | * Copyright (C) 2006-2013, Brainspark B.V. |
HannesTschofenig | 0:796d0f61a05b | 7 | * |
HannesTschofenig | 0:796d0f61a05b | 8 | * This file is part of PolarSSL (http://www.polarssl.org) |
HannesTschofenig | 0:796d0f61a05b | 9 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
HannesTschofenig | 0:796d0f61a05b | 10 | * |
HannesTschofenig | 0:796d0f61a05b | 11 | * All rights reserved. |
HannesTschofenig | 0:796d0f61a05b | 12 | * |
HannesTschofenig | 0:796d0f61a05b | 13 | * This program is free software; you can redistribute it and/or modify |
HannesTschofenig | 0:796d0f61a05b | 14 | * it under the terms of the GNU General Public License as published by |
HannesTschofenig | 0:796d0f61a05b | 15 | * the Free Software Foundation; either version 2 of the License, or |
HannesTschofenig | 0:796d0f61a05b | 16 | * (at your option) any later version. |
HannesTschofenig | 0:796d0f61a05b | 17 | * |
HannesTschofenig | 0:796d0f61a05b | 18 | * This program is distributed in the hope that it will be useful, |
HannesTschofenig | 0:796d0f61a05b | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
HannesTschofenig | 0:796d0f61a05b | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
HannesTschofenig | 0:796d0f61a05b | 21 | * GNU General Public License for more details. |
HannesTschofenig | 0:796d0f61a05b | 22 | * |
HannesTschofenig | 0:796d0f61a05b | 23 | * You should have received a copy of the GNU General Public License along |
HannesTschofenig | 0:796d0f61a05b | 24 | * with this program; if not, write to the Free Software Foundation, Inc., |
HannesTschofenig | 0:796d0f61a05b | 25 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
HannesTschofenig | 0:796d0f61a05b | 26 | */ |
HannesTschofenig | 0:796d0f61a05b | 27 | #ifndef POLARSSL_ASN1_H |
HannesTschofenig | 0:796d0f61a05b | 28 | #define POLARSSL_ASN1_H |
HannesTschofenig | 0:796d0f61a05b | 29 | |
HannesTschofenig | 0:796d0f61a05b | 30 | #if !defined(POLARSSL_CONFIG_FILE) |
HannesTschofenig | 0:796d0f61a05b | 31 | #include "config.h" |
HannesTschofenig | 0:796d0f61a05b | 32 | #else |
HannesTschofenig | 0:796d0f61a05b | 33 | #include POLARSSL_CONFIG_FILE |
HannesTschofenig | 0:796d0f61a05b | 34 | #endif |
HannesTschofenig | 0:796d0f61a05b | 35 | |
HannesTschofenig | 0:796d0f61a05b | 36 | #if defined(POLARSSL_BIGNUM_C) |
HannesTschofenig | 0:796d0f61a05b | 37 | #include "bignum.h" |
HannesTschofenig | 0:796d0f61a05b | 38 | #endif |
HannesTschofenig | 0:796d0f61a05b | 39 | |
HannesTschofenig | 0:796d0f61a05b | 40 | #include <string.h> |
HannesTschofenig | 0:796d0f61a05b | 41 | |
HannesTschofenig | 0:796d0f61a05b | 42 | /** |
HannesTschofenig | 0:796d0f61a05b | 43 | * \addtogroup asn1_module |
HannesTschofenig | 0:796d0f61a05b | 44 | * \{ |
HannesTschofenig | 0:796d0f61a05b | 45 | */ |
HannesTschofenig | 0:796d0f61a05b | 46 | |
HannesTschofenig | 0:796d0f61a05b | 47 | /** |
HannesTschofenig | 0:796d0f61a05b | 48 | * \name ASN1 Error codes |
HannesTschofenig | 0:796d0f61a05b | 49 | * These error codes are OR'ed to X509 error codes for |
HannesTschofenig | 0:796d0f61a05b | 50 | * higher error granularity. |
HannesTschofenig | 0:796d0f61a05b | 51 | * ASN1 is a standard to specify data structures. |
HannesTschofenig | 0:796d0f61a05b | 52 | * \{ |
HannesTschofenig | 0:796d0f61a05b | 53 | */ |
HannesTschofenig | 0:796d0f61a05b | 54 | #define POLARSSL_ERR_ASN1_OUT_OF_DATA -0x0060 /**< Out of data when parsing an ASN1 data structure. */ |
HannesTschofenig | 0:796d0f61a05b | 55 | #define POLARSSL_ERR_ASN1_UNEXPECTED_TAG -0x0062 /**< ASN1 tag was of an unexpected value. */ |
HannesTschofenig | 0:796d0f61a05b | 56 | #define POLARSSL_ERR_ASN1_INVALID_LENGTH -0x0064 /**< Error when trying to determine the length or invalid length. */ |
HannesTschofenig | 0:796d0f61a05b | 57 | #define POLARSSL_ERR_ASN1_LENGTH_MISMATCH -0x0066 /**< Actual length differs from expected length. */ |
HannesTschofenig | 0:796d0f61a05b | 58 | #define POLARSSL_ERR_ASN1_INVALID_DATA -0x0068 /**< Data is invalid. (not used) */ |
HannesTschofenig | 0:796d0f61a05b | 59 | #define POLARSSL_ERR_ASN1_MALLOC_FAILED -0x006A /**< Memory allocation failed */ |
HannesTschofenig | 0:796d0f61a05b | 60 | #define POLARSSL_ERR_ASN1_BUF_TOO_SMALL -0x006C /**< Buffer too small when writing ASN.1 data structure. */ |
HannesTschofenig | 0:796d0f61a05b | 61 | |
HannesTschofenig | 0:796d0f61a05b | 62 | /* \} name */ |
HannesTschofenig | 0:796d0f61a05b | 63 | |
HannesTschofenig | 0:796d0f61a05b | 64 | /** |
HannesTschofenig | 0:796d0f61a05b | 65 | * \name DER constants |
HannesTschofenig | 0:796d0f61a05b | 66 | * These constants comply with DER encoded the ANS1 type tags. |
HannesTschofenig | 0:796d0f61a05b | 67 | * DER encoding uses hexadecimal representation. |
HannesTschofenig | 0:796d0f61a05b | 68 | * An example DER sequence is:\n |
HannesTschofenig | 0:796d0f61a05b | 69 | * - 0x02 -- tag indicating INTEGER |
HannesTschofenig | 0:796d0f61a05b | 70 | * - 0x01 -- length in octets |
HannesTschofenig | 0:796d0f61a05b | 71 | * - 0x05 -- value |
HannesTschofenig | 0:796d0f61a05b | 72 | * Such sequences are typically read into \c ::x509_buf. |
HannesTschofenig | 0:796d0f61a05b | 73 | * \{ |
HannesTschofenig | 0:796d0f61a05b | 74 | */ |
HannesTschofenig | 0:796d0f61a05b | 75 | #define ASN1_BOOLEAN 0x01 |
HannesTschofenig | 0:796d0f61a05b | 76 | #define ASN1_INTEGER 0x02 |
HannesTschofenig | 0:796d0f61a05b | 77 | #define ASN1_BIT_STRING 0x03 |
HannesTschofenig | 0:796d0f61a05b | 78 | #define ASN1_OCTET_STRING 0x04 |
HannesTschofenig | 0:796d0f61a05b | 79 | #define ASN1_NULL 0x05 |
HannesTschofenig | 0:796d0f61a05b | 80 | #define ASN1_OID 0x06 |
HannesTschofenig | 0:796d0f61a05b | 81 | #define ASN1_UTF8_STRING 0x0C |
HannesTschofenig | 0:796d0f61a05b | 82 | #define ASN1_SEQUENCE 0x10 |
HannesTschofenig | 0:796d0f61a05b | 83 | #define ASN1_SET 0x11 |
HannesTschofenig | 0:796d0f61a05b | 84 | #define ASN1_PRINTABLE_STRING 0x13 |
HannesTschofenig | 0:796d0f61a05b | 85 | #define ASN1_T61_STRING 0x14 |
HannesTschofenig | 0:796d0f61a05b | 86 | #define ASN1_IA5_STRING 0x16 |
HannesTschofenig | 0:796d0f61a05b | 87 | #define ASN1_UTC_TIME 0x17 |
HannesTschofenig | 0:796d0f61a05b | 88 | #define ASN1_GENERALIZED_TIME 0x18 |
HannesTschofenig | 0:796d0f61a05b | 89 | #define ASN1_UNIVERSAL_STRING 0x1C |
HannesTschofenig | 0:796d0f61a05b | 90 | #define ASN1_BMP_STRING 0x1E |
HannesTschofenig | 0:796d0f61a05b | 91 | #define ASN1_PRIMITIVE 0x00 |
HannesTschofenig | 0:796d0f61a05b | 92 | #define ASN1_CONSTRUCTED 0x20 |
HannesTschofenig | 0:796d0f61a05b | 93 | #define ASN1_CONTEXT_SPECIFIC 0x80 |
HannesTschofenig | 0:796d0f61a05b | 94 | /* \} name */ |
HannesTschofenig | 0:796d0f61a05b | 95 | /* \} addtogroup asn1_module */ |
HannesTschofenig | 0:796d0f61a05b | 96 | |
HannesTschofenig | 0:796d0f61a05b | 97 | /** Returns the size of the binary string, without the trailing \\0 */ |
HannesTschofenig | 0:796d0f61a05b | 98 | #define OID_SIZE(x) (sizeof(x) - 1) |
HannesTschofenig | 0:796d0f61a05b | 99 | |
HannesTschofenig | 0:796d0f61a05b | 100 | /** Compares two asn1_buf structures for the same OID. Only works for |
HannesTschofenig | 0:796d0f61a05b | 101 | * 'defined' oid_str values (OID_HMAC_SHA1), you cannot use a 'unsigned |
HannesTschofenig | 0:796d0f61a05b | 102 | * char *oid' here! |
HannesTschofenig | 0:796d0f61a05b | 103 | */ |
HannesTschofenig | 0:796d0f61a05b | 104 | #define OID_CMP(oid_str, oid_buf) \ |
HannesTschofenig | 0:796d0f61a05b | 105 | ( ( OID_SIZE(oid_str) == (oid_buf)->len ) && \ |
HannesTschofenig | 0:796d0f61a05b | 106 | memcmp( (oid_str), (oid_buf)->p, (oid_buf)->len) == 0 ) |
HannesTschofenig | 0:796d0f61a05b | 107 | |
HannesTschofenig | 0:796d0f61a05b | 108 | #ifdef __cplusplus |
HannesTschofenig | 0:796d0f61a05b | 109 | extern "C" { |
HannesTschofenig | 0:796d0f61a05b | 110 | #endif |
HannesTschofenig | 0:796d0f61a05b | 111 | |
HannesTschofenig | 0:796d0f61a05b | 112 | /** |
HannesTschofenig | 0:796d0f61a05b | 113 | * \name Functions to parse ASN.1 data structures |
HannesTschofenig | 0:796d0f61a05b | 114 | * \{ |
HannesTschofenig | 0:796d0f61a05b | 115 | */ |
HannesTschofenig | 0:796d0f61a05b | 116 | |
HannesTschofenig | 0:796d0f61a05b | 117 | /** |
HannesTschofenig | 0:796d0f61a05b | 118 | * Type-length-value structure that allows for ASN1 using DER. |
HannesTschofenig | 0:796d0f61a05b | 119 | */ |
HannesTschofenig | 0:796d0f61a05b | 120 | typedef struct _asn1_buf |
HannesTschofenig | 0:796d0f61a05b | 121 | { |
HannesTschofenig | 0:796d0f61a05b | 122 | int tag; /**< ASN1 type, e.g. ASN1_UTF8_STRING. */ |
HannesTschofenig | 0:796d0f61a05b | 123 | size_t len; /**< ASN1 length, e.g. in octets. */ |
HannesTschofenig | 0:796d0f61a05b | 124 | unsigned char *p; /**< ASN1 data, e.g. in ASCII. */ |
HannesTschofenig | 0:796d0f61a05b | 125 | } |
HannesTschofenig | 0:796d0f61a05b | 126 | asn1_buf; |
HannesTschofenig | 0:796d0f61a05b | 127 | |
HannesTschofenig | 0:796d0f61a05b | 128 | /** |
HannesTschofenig | 0:796d0f61a05b | 129 | * Container for ASN1 bit strings. |
HannesTschofenig | 0:796d0f61a05b | 130 | */ |
HannesTschofenig | 0:796d0f61a05b | 131 | typedef struct _asn1_bitstring |
HannesTschofenig | 0:796d0f61a05b | 132 | { |
HannesTschofenig | 0:796d0f61a05b | 133 | size_t len; /**< ASN1 length, e.g. in octets. */ |
HannesTschofenig | 0:796d0f61a05b | 134 | unsigned char unused_bits; /**< Number of unused bits at the end of the string */ |
HannesTschofenig | 0:796d0f61a05b | 135 | unsigned char *p; /**< Raw ASN1 data for the bit string */ |
HannesTschofenig | 0:796d0f61a05b | 136 | } |
HannesTschofenig | 0:796d0f61a05b | 137 | asn1_bitstring; |
HannesTschofenig | 0:796d0f61a05b | 138 | |
HannesTschofenig | 0:796d0f61a05b | 139 | /** |
HannesTschofenig | 0:796d0f61a05b | 140 | * Container for a sequence of ASN.1 items |
HannesTschofenig | 0:796d0f61a05b | 141 | */ |
HannesTschofenig | 0:796d0f61a05b | 142 | typedef struct _asn1_sequence |
HannesTschofenig | 0:796d0f61a05b | 143 | { |
HannesTschofenig | 0:796d0f61a05b | 144 | asn1_buf buf; /**< Buffer containing the given ASN.1 item. */ |
HannesTschofenig | 0:796d0f61a05b | 145 | struct _asn1_sequence *next; /**< The next entry in the sequence. */ |
HannesTschofenig | 0:796d0f61a05b | 146 | } |
HannesTschofenig | 0:796d0f61a05b | 147 | asn1_sequence; |
HannesTschofenig | 0:796d0f61a05b | 148 | |
HannesTschofenig | 0:796d0f61a05b | 149 | /** |
HannesTschofenig | 0:796d0f61a05b | 150 | * Container for a sequence or list of 'named' ASN.1 data items |
HannesTschofenig | 0:796d0f61a05b | 151 | */ |
HannesTschofenig | 0:796d0f61a05b | 152 | typedef struct _asn1_named_data |
HannesTschofenig | 0:796d0f61a05b | 153 | { |
HannesTschofenig | 0:796d0f61a05b | 154 | asn1_buf oid; /**< The object identifier. */ |
HannesTschofenig | 0:796d0f61a05b | 155 | asn1_buf val; /**< The named value. */ |
HannesTschofenig | 0:796d0f61a05b | 156 | struct _asn1_named_data *next; /**< The next entry in the sequence. */ |
HannesTschofenig | 0:796d0f61a05b | 157 | } |
HannesTschofenig | 0:796d0f61a05b | 158 | asn1_named_data; |
HannesTschofenig | 0:796d0f61a05b | 159 | |
HannesTschofenig | 0:796d0f61a05b | 160 | /** |
HannesTschofenig | 0:796d0f61a05b | 161 | * \brief Get the length of an ASN.1 element. |
HannesTschofenig | 0:796d0f61a05b | 162 | * Updates the pointer to immediately behind the length. |
HannesTschofenig | 0:796d0f61a05b | 163 | * |
HannesTschofenig | 0:796d0f61a05b | 164 | * \param p The position in the ASN.1 data |
HannesTschofenig | 0:796d0f61a05b | 165 | * \param end End of data |
HannesTschofenig | 0:796d0f61a05b | 166 | * \param len The variable that will receive the value |
HannesTschofenig | 0:796d0f61a05b | 167 | * |
HannesTschofenig | 0:796d0f61a05b | 168 | * \return 0 if successful, POLARSSL_ERR_ASN1_OUT_OF_DATA on reaching |
HannesTschofenig | 0:796d0f61a05b | 169 | * end of data, POLARSSL_ERR_ASN1_INVALID_LENGTH if length is |
HannesTschofenig | 0:796d0f61a05b | 170 | * unparseable. |
HannesTschofenig | 0:796d0f61a05b | 171 | */ |
HannesTschofenig | 0:796d0f61a05b | 172 | int asn1_get_len( unsigned char **p, |
HannesTschofenig | 0:796d0f61a05b | 173 | const unsigned char *end, |
HannesTschofenig | 0:796d0f61a05b | 174 | size_t *len ); |
HannesTschofenig | 0:796d0f61a05b | 175 | |
HannesTschofenig | 0:796d0f61a05b | 176 | /** |
HannesTschofenig | 0:796d0f61a05b | 177 | * \brief Get the tag and length of the tag. Check for the requested tag. |
HannesTschofenig | 0:796d0f61a05b | 178 | * Updates the pointer to immediately behind the tag and length. |
HannesTschofenig | 0:796d0f61a05b | 179 | * |
HannesTschofenig | 0:796d0f61a05b | 180 | * \param p The position in the ASN.1 data |
HannesTschofenig | 0:796d0f61a05b | 181 | * \param end End of data |
HannesTschofenig | 0:796d0f61a05b | 182 | * \param len The variable that will receive the length |
HannesTschofenig | 0:796d0f61a05b | 183 | * \param tag The expected tag |
HannesTschofenig | 0:796d0f61a05b | 184 | * |
HannesTschofenig | 0:796d0f61a05b | 185 | * \return 0 if successful, POLARSSL_ERR_ASN1_UNEXPECTED_TAG if tag did |
HannesTschofenig | 0:796d0f61a05b | 186 | * not match requested tag, or another specific ASN.1 error code. |
HannesTschofenig | 0:796d0f61a05b | 187 | */ |
HannesTschofenig | 0:796d0f61a05b | 188 | int asn1_get_tag( unsigned char **p, |
HannesTschofenig | 0:796d0f61a05b | 189 | const unsigned char *end, |
HannesTschofenig | 0:796d0f61a05b | 190 | size_t *len, int tag ); |
HannesTschofenig | 0:796d0f61a05b | 191 | |
HannesTschofenig | 0:796d0f61a05b | 192 | /** |
HannesTschofenig | 0:796d0f61a05b | 193 | * \brief Retrieve a boolean ASN.1 tag and its value. |
HannesTschofenig | 0:796d0f61a05b | 194 | * Updates the pointer to immediately behind the full tag. |
HannesTschofenig | 0:796d0f61a05b | 195 | * |
HannesTschofenig | 0:796d0f61a05b | 196 | * \param p The position in the ASN.1 data |
HannesTschofenig | 0:796d0f61a05b | 197 | * \param end End of data |
HannesTschofenig | 0:796d0f61a05b | 198 | * \param val The variable that will receive the value |
HannesTschofenig | 0:796d0f61a05b | 199 | * |
HannesTschofenig | 0:796d0f61a05b | 200 | * \return 0 if successful or a specific ASN.1 error code. |
HannesTschofenig | 0:796d0f61a05b | 201 | */ |
HannesTschofenig | 0:796d0f61a05b | 202 | int asn1_get_bool( unsigned char **p, |
HannesTschofenig | 0:796d0f61a05b | 203 | const unsigned char *end, |
HannesTschofenig | 0:796d0f61a05b | 204 | int *val ); |
HannesTschofenig | 0:796d0f61a05b | 205 | |
HannesTschofenig | 0:796d0f61a05b | 206 | /** |
HannesTschofenig | 0:796d0f61a05b | 207 | * \brief Retrieve an integer ASN.1 tag and its value. |
HannesTschofenig | 0:796d0f61a05b | 208 | * Updates the pointer to immediately behind the full tag. |
HannesTschofenig | 0:796d0f61a05b | 209 | * |
HannesTschofenig | 0:796d0f61a05b | 210 | * \param p The position in the ASN.1 data |
HannesTschofenig | 0:796d0f61a05b | 211 | * \param end End of data |
HannesTschofenig | 0:796d0f61a05b | 212 | * \param val The variable that will receive the value |
HannesTschofenig | 0:796d0f61a05b | 213 | * |
HannesTschofenig | 0:796d0f61a05b | 214 | * \return 0 if successful or a specific ASN.1 error code. |
HannesTschofenig | 0:796d0f61a05b | 215 | */ |
HannesTschofenig | 0:796d0f61a05b | 216 | int asn1_get_int( unsigned char **p, |
HannesTschofenig | 0:796d0f61a05b | 217 | const unsigned char *end, |
HannesTschofenig | 0:796d0f61a05b | 218 | int *val ); |
HannesTschofenig | 0:796d0f61a05b | 219 | |
HannesTschofenig | 0:796d0f61a05b | 220 | /** |
HannesTschofenig | 0:796d0f61a05b | 221 | * \brief Retrieve a bitstring ASN.1 tag and its value. |
HannesTschofenig | 0:796d0f61a05b | 222 | * Updates the pointer to immediately behind the full tag. |
HannesTschofenig | 0:796d0f61a05b | 223 | * |
HannesTschofenig | 0:796d0f61a05b | 224 | * \param p The position in the ASN.1 data |
HannesTschofenig | 0:796d0f61a05b | 225 | * \param end End of data |
HannesTschofenig | 0:796d0f61a05b | 226 | * \param bs The variable that will receive the value |
HannesTschofenig | 0:796d0f61a05b | 227 | * |
HannesTschofenig | 0:796d0f61a05b | 228 | * \return 0 if successful or a specific ASN.1 error code. |
HannesTschofenig | 0:796d0f61a05b | 229 | */ |
HannesTschofenig | 0:796d0f61a05b | 230 | int asn1_get_bitstring( unsigned char **p, const unsigned char *end, |
HannesTschofenig | 0:796d0f61a05b | 231 | asn1_bitstring *bs); |
HannesTschofenig | 0:796d0f61a05b | 232 | |
HannesTschofenig | 0:796d0f61a05b | 233 | /** |
HannesTschofenig | 0:796d0f61a05b | 234 | * \brief Retrieve a bitstring ASN.1 tag without unused bits and its |
HannesTschofenig | 0:796d0f61a05b | 235 | * value. |
HannesTschofenig | 0:796d0f61a05b | 236 | * Updates the pointer to the beginning of the bit/octet string. |
HannesTschofenig | 0:796d0f61a05b | 237 | * |
HannesTschofenig | 0:796d0f61a05b | 238 | * \param p The position in the ASN.1 data |
HannesTschofenig | 0:796d0f61a05b | 239 | * \param end End of data |
HannesTschofenig | 0:796d0f61a05b | 240 | * \param len Length of the actual bit/octect string in bytes |
HannesTschofenig | 0:796d0f61a05b | 241 | * |
HannesTschofenig | 0:796d0f61a05b | 242 | * \return 0 if successful or a specific ASN.1 error code. |
HannesTschofenig | 0:796d0f61a05b | 243 | */ |
HannesTschofenig | 0:796d0f61a05b | 244 | int asn1_get_bitstring_null( unsigned char **p, const unsigned char *end, |
HannesTschofenig | 0:796d0f61a05b | 245 | size_t *len ); |
HannesTschofenig | 0:796d0f61a05b | 246 | |
HannesTschofenig | 0:796d0f61a05b | 247 | /** |
HannesTschofenig | 0:796d0f61a05b | 248 | * \brief Parses and splits an ASN.1 "SEQUENCE OF <tag>" |
HannesTschofenig | 0:796d0f61a05b | 249 | * Updated the pointer to immediately behind the full sequence tag. |
HannesTschofenig | 0:796d0f61a05b | 250 | * |
HannesTschofenig | 0:796d0f61a05b | 251 | * \param p The position in the ASN.1 data |
HannesTschofenig | 0:796d0f61a05b | 252 | * \param end End of data |
HannesTschofenig | 0:796d0f61a05b | 253 | * \param cur First variable in the chain to fill |
HannesTschofenig | 0:796d0f61a05b | 254 | * \param tag Type of sequence |
HannesTschofenig | 0:796d0f61a05b | 255 | * |
HannesTschofenig | 0:796d0f61a05b | 256 | * \return 0 if successful or a specific ASN.1 error code. |
HannesTschofenig | 0:796d0f61a05b | 257 | */ |
HannesTschofenig | 0:796d0f61a05b | 258 | int asn1_get_sequence_of( unsigned char **p, |
HannesTschofenig | 0:796d0f61a05b | 259 | const unsigned char *end, |
HannesTschofenig | 0:796d0f61a05b | 260 | asn1_sequence *cur, |
HannesTschofenig | 0:796d0f61a05b | 261 | int tag); |
HannesTschofenig | 0:796d0f61a05b | 262 | |
HannesTschofenig | 0:796d0f61a05b | 263 | #if defined(POLARSSL_BIGNUM_C) |
HannesTschofenig | 0:796d0f61a05b | 264 | /** |
HannesTschofenig | 0:796d0f61a05b | 265 | * \brief Retrieve a MPI value from an integer ASN.1 tag. |
HannesTschofenig | 0:796d0f61a05b | 266 | * Updates the pointer to immediately behind the full tag. |
HannesTschofenig | 0:796d0f61a05b | 267 | * |
HannesTschofenig | 0:796d0f61a05b | 268 | * \param p The position in the ASN.1 data |
HannesTschofenig | 0:796d0f61a05b | 269 | * \param end End of data |
HannesTschofenig | 0:796d0f61a05b | 270 | * \param X The MPI that will receive the value |
HannesTschofenig | 0:796d0f61a05b | 271 | * |
HannesTschofenig | 0:796d0f61a05b | 272 | * \return 0 if successful or a specific ASN.1 or MPI error code. |
HannesTschofenig | 0:796d0f61a05b | 273 | */ |
HannesTschofenig | 0:796d0f61a05b | 274 | int asn1_get_mpi( unsigned char **p, |
HannesTschofenig | 0:796d0f61a05b | 275 | const unsigned char *end, |
HannesTschofenig | 0:796d0f61a05b | 276 | mpi *X ); |
HannesTschofenig | 0:796d0f61a05b | 277 | #endif /* POLARSSL_BIGNUM_C */ |
HannesTschofenig | 0:796d0f61a05b | 278 | |
HannesTschofenig | 0:796d0f61a05b | 279 | /** |
HannesTschofenig | 0:796d0f61a05b | 280 | * \brief Retrieve an AlgorithmIdentifier ASN.1 sequence. |
HannesTschofenig | 0:796d0f61a05b | 281 | * Updates the pointer to immediately behind the full |
HannesTschofenig | 0:796d0f61a05b | 282 | * AlgorithmIdentifier. |
HannesTschofenig | 0:796d0f61a05b | 283 | * |
HannesTschofenig | 0:796d0f61a05b | 284 | * \param p The position in the ASN.1 data |
HannesTschofenig | 0:796d0f61a05b | 285 | * \param end End of data |
HannesTschofenig | 0:796d0f61a05b | 286 | * \param alg The buffer to receive the OID |
HannesTschofenig | 0:796d0f61a05b | 287 | * \param params The buffer to receive the params (if any) |
HannesTschofenig | 0:796d0f61a05b | 288 | * |
HannesTschofenig | 0:796d0f61a05b | 289 | * \return 0 if successful or a specific ASN.1 or MPI error code. |
HannesTschofenig | 0:796d0f61a05b | 290 | */ |
HannesTschofenig | 0:796d0f61a05b | 291 | int asn1_get_alg( unsigned char **p, |
HannesTschofenig | 0:796d0f61a05b | 292 | const unsigned char *end, |
HannesTschofenig | 0:796d0f61a05b | 293 | asn1_buf *alg, asn1_buf *params ); |
HannesTschofenig | 0:796d0f61a05b | 294 | |
HannesTschofenig | 0:796d0f61a05b | 295 | /** |
HannesTschofenig | 0:796d0f61a05b | 296 | * \brief Retrieve an AlgorithmIdentifier ASN.1 sequence with NULL or no |
HannesTschofenig | 0:796d0f61a05b | 297 | * params. |
HannesTschofenig | 0:796d0f61a05b | 298 | * Updates the pointer to immediately behind the full |
HannesTschofenig | 0:796d0f61a05b | 299 | * AlgorithmIdentifier. |
HannesTschofenig | 0:796d0f61a05b | 300 | * |
HannesTschofenig | 0:796d0f61a05b | 301 | * \param p The position in the ASN.1 data |
HannesTschofenig | 0:796d0f61a05b | 302 | * \param end End of data |
HannesTschofenig | 0:796d0f61a05b | 303 | * \param alg The buffer to receive the OID |
HannesTschofenig | 0:796d0f61a05b | 304 | * |
HannesTschofenig | 0:796d0f61a05b | 305 | * \return 0 if successful or a specific ASN.1 or MPI error code. |
HannesTschofenig | 0:796d0f61a05b | 306 | */ |
HannesTschofenig | 0:796d0f61a05b | 307 | int asn1_get_alg_null( unsigned char **p, |
HannesTschofenig | 0:796d0f61a05b | 308 | const unsigned char *end, |
HannesTschofenig | 0:796d0f61a05b | 309 | asn1_buf *alg ); |
HannesTschofenig | 0:796d0f61a05b | 310 | |
HannesTschofenig | 0:796d0f61a05b | 311 | /** |
HannesTschofenig | 0:796d0f61a05b | 312 | * \brief Find a specific named_data entry in a sequence or list based on |
HannesTschofenig | 0:796d0f61a05b | 313 | * the OID. |
HannesTschofenig | 0:796d0f61a05b | 314 | * |
HannesTschofenig | 0:796d0f61a05b | 315 | * \param list The list to seek through |
HannesTschofenig | 0:796d0f61a05b | 316 | * \param oid The OID to look for |
HannesTschofenig | 0:796d0f61a05b | 317 | * \param len Size of the OID |
HannesTschofenig | 0:796d0f61a05b | 318 | * |
HannesTschofenig | 0:796d0f61a05b | 319 | * \return NULL if not found, or a pointer to the existing entry. |
HannesTschofenig | 0:796d0f61a05b | 320 | */ |
HannesTschofenig | 0:796d0f61a05b | 321 | asn1_named_data *asn1_find_named_data( asn1_named_data *list, |
HannesTschofenig | 0:796d0f61a05b | 322 | const char *oid, size_t len ); |
HannesTschofenig | 0:796d0f61a05b | 323 | |
HannesTschofenig | 0:796d0f61a05b | 324 | /** |
HannesTschofenig | 0:796d0f61a05b | 325 | * \brief Free a asn1_named_data entry |
HannesTschofenig | 0:796d0f61a05b | 326 | * |
HannesTschofenig | 0:796d0f61a05b | 327 | * \param entry The named data entry to free |
HannesTschofenig | 0:796d0f61a05b | 328 | */ |
HannesTschofenig | 0:796d0f61a05b | 329 | void asn1_free_named_data( asn1_named_data *entry ); |
HannesTschofenig | 0:796d0f61a05b | 330 | |
HannesTschofenig | 0:796d0f61a05b | 331 | /** |
HannesTschofenig | 0:796d0f61a05b | 332 | * \brief Free all entries in a asn1_named_data list |
HannesTschofenig | 0:796d0f61a05b | 333 | * Head will be set to NULL |
HannesTschofenig | 0:796d0f61a05b | 334 | * |
HannesTschofenig | 0:796d0f61a05b | 335 | * \param head Pointer to the head of the list of named data entries to free |
HannesTschofenig | 0:796d0f61a05b | 336 | */ |
HannesTschofenig | 0:796d0f61a05b | 337 | void asn1_free_named_data_list( asn1_named_data **head ); |
HannesTschofenig | 0:796d0f61a05b | 338 | |
HannesTschofenig | 0:796d0f61a05b | 339 | #ifdef __cplusplus |
HannesTschofenig | 0:796d0f61a05b | 340 | } |
HannesTschofenig | 0:796d0f61a05b | 341 | #endif |
HannesTschofenig | 0:796d0f61a05b | 342 | |
HannesTschofenig | 0:796d0f61a05b | 343 | #endif /* asn1.h */ |
HannesTschofenig | 0:796d0f61a05b | 344 | |
HannesTschofenig | 0:796d0f61a05b | 345 |