The WDCInterface is is a drop-in replacement for an EthernetInterface class that allows the user to connect to the Internet with a Wistron NeWeb Corporation (WNC) M14A2A Series data module using the standard network Socket API's. This interface class is used in the AT&T Cellular IoT Starter Kit which is sold by Avnet (http://cloudconnectkits.org/product/att-cellular-iot-starter-kit).
Dependencies: WncControllerK64F
Dependents: WNCProximityMqtt Pubnub_ATT_IoT_SK_WNC_sync BluemixDemo BluemixQS ... more
See the WNCInterface README in the Wiki tab for detailed information on this library.
mbedtls/source/asn1parse.c@29:b278b745fb4f, 2017-03-24 (annotated)
- Committer:
- JMF
- Date:
- Fri Mar 24 22:26:23 2017 +0000
- Revision:
- 29:b278b745fb4f
- Parent:
- 12:0071cb144c7a
updated Class name of TCPSocketConnection to WncTCPSocketConnection;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JMF | 12:0071cb144c7a | 1 | /* |
JMF | 12:0071cb144c7a | 2 | * Generic ASN.1 parsing |
JMF | 12:0071cb144c7a | 3 | * |
JMF | 12:0071cb144c7a | 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
JMF | 12:0071cb144c7a | 5 | * SPDX-License-Identifier: Apache-2.0 |
JMF | 12:0071cb144c7a | 6 | * |
JMF | 12:0071cb144c7a | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
JMF | 12:0071cb144c7a | 8 | * not use this file except in compliance with the License. |
JMF | 12:0071cb144c7a | 9 | * You may obtain a copy of the License at |
JMF | 12:0071cb144c7a | 10 | * |
JMF | 12:0071cb144c7a | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
JMF | 12:0071cb144c7a | 12 | * |
JMF | 12:0071cb144c7a | 13 | * Unless required by applicable law or agreed to in writing, software |
JMF | 12:0071cb144c7a | 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
JMF | 12:0071cb144c7a | 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
JMF | 12:0071cb144c7a | 16 | * See the License for the specific language governing permissions and |
JMF | 12:0071cb144c7a | 17 | * limitations under the License. |
JMF | 12:0071cb144c7a | 18 | * |
JMF | 12:0071cb144c7a | 19 | * This file is part of mbed TLS (https://tls.mbed.org) |
JMF | 12:0071cb144c7a | 20 | */ |
JMF | 12:0071cb144c7a | 21 | |
JMF | 12:0071cb144c7a | 22 | #if !defined(MBEDTLS_CONFIG_FILE) |
JMF | 12:0071cb144c7a | 23 | #include "mbedtls/config.h" |
JMF | 12:0071cb144c7a | 24 | #else |
JMF | 12:0071cb144c7a | 25 | #include MBEDTLS_CONFIG_FILE |
JMF | 12:0071cb144c7a | 26 | #endif |
JMF | 12:0071cb144c7a | 27 | |
JMF | 12:0071cb144c7a | 28 | #if defined(MBEDTLS_ASN1_PARSE_C) |
JMF | 12:0071cb144c7a | 29 | |
JMF | 12:0071cb144c7a | 30 | #include "mbedtls/asn1.h" |
JMF | 12:0071cb144c7a | 31 | |
JMF | 12:0071cb144c7a | 32 | #include <string.h> |
JMF | 12:0071cb144c7a | 33 | |
JMF | 12:0071cb144c7a | 34 | #if defined(MBEDTLS_BIGNUM_C) |
JMF | 12:0071cb144c7a | 35 | #include "mbedtls/bignum.h" |
JMF | 12:0071cb144c7a | 36 | #endif |
JMF | 12:0071cb144c7a | 37 | |
JMF | 12:0071cb144c7a | 38 | #if defined(MBEDTLS_PLATFORM_C) |
JMF | 12:0071cb144c7a | 39 | #include "mbedtls/platform.h" |
JMF | 12:0071cb144c7a | 40 | #else |
JMF | 12:0071cb144c7a | 41 | #include <stdlib.h> |
JMF | 12:0071cb144c7a | 42 | #define mbedtls_calloc calloc |
JMF | 12:0071cb144c7a | 43 | #define mbedtls_free free |
JMF | 12:0071cb144c7a | 44 | #endif |
JMF | 12:0071cb144c7a | 45 | |
JMF | 12:0071cb144c7a | 46 | /* Implementation that should never be optimized out by the compiler */ |
JMF | 12:0071cb144c7a | 47 | static void mbedtls_zeroize( void *v, size_t n ) { |
JMF | 12:0071cb144c7a | 48 | volatile unsigned char *p = (unsigned char*)v; while( n-- ) *p++ = 0; |
JMF | 12:0071cb144c7a | 49 | } |
JMF | 12:0071cb144c7a | 50 | |
JMF | 12:0071cb144c7a | 51 | /* |
JMF | 12:0071cb144c7a | 52 | * ASN.1 DER decoding routines |
JMF | 12:0071cb144c7a | 53 | */ |
JMF | 12:0071cb144c7a | 54 | int mbedtls_asn1_get_len( unsigned char **p, |
JMF | 12:0071cb144c7a | 55 | const unsigned char *end, |
JMF | 12:0071cb144c7a | 56 | size_t *len ) |
JMF | 12:0071cb144c7a | 57 | { |
JMF | 12:0071cb144c7a | 58 | if( ( end - *p ) < 1 ) |
JMF | 12:0071cb144c7a | 59 | return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); |
JMF | 12:0071cb144c7a | 60 | |
JMF | 12:0071cb144c7a | 61 | if( ( **p & 0x80 ) == 0 ) |
JMF | 12:0071cb144c7a | 62 | *len = *(*p)++; |
JMF | 12:0071cb144c7a | 63 | else |
JMF | 12:0071cb144c7a | 64 | { |
JMF | 12:0071cb144c7a | 65 | switch( **p & 0x7F ) |
JMF | 12:0071cb144c7a | 66 | { |
JMF | 12:0071cb144c7a | 67 | case 1: |
JMF | 12:0071cb144c7a | 68 | if( ( end - *p ) < 2 ) |
JMF | 12:0071cb144c7a | 69 | return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); |
JMF | 12:0071cb144c7a | 70 | |
JMF | 12:0071cb144c7a | 71 | *len = (*p)[1]; |
JMF | 12:0071cb144c7a | 72 | (*p) += 2; |
JMF | 12:0071cb144c7a | 73 | break; |
JMF | 12:0071cb144c7a | 74 | |
JMF | 12:0071cb144c7a | 75 | case 2: |
JMF | 12:0071cb144c7a | 76 | if( ( end - *p ) < 3 ) |
JMF | 12:0071cb144c7a | 77 | return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); |
JMF | 12:0071cb144c7a | 78 | |
JMF | 12:0071cb144c7a | 79 | *len = ( (size_t)(*p)[1] << 8 ) | (*p)[2]; |
JMF | 12:0071cb144c7a | 80 | (*p) += 3; |
JMF | 12:0071cb144c7a | 81 | break; |
JMF | 12:0071cb144c7a | 82 | |
JMF | 12:0071cb144c7a | 83 | case 3: |
JMF | 12:0071cb144c7a | 84 | if( ( end - *p ) < 4 ) |
JMF | 12:0071cb144c7a | 85 | return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); |
JMF | 12:0071cb144c7a | 86 | |
JMF | 12:0071cb144c7a | 87 | *len = ( (size_t)(*p)[1] << 16 ) | |
JMF | 12:0071cb144c7a | 88 | ( (size_t)(*p)[2] << 8 ) | (*p)[3]; |
JMF | 12:0071cb144c7a | 89 | (*p) += 4; |
JMF | 12:0071cb144c7a | 90 | break; |
JMF | 12:0071cb144c7a | 91 | |
JMF | 12:0071cb144c7a | 92 | case 4: |
JMF | 12:0071cb144c7a | 93 | if( ( end - *p ) < 5 ) |
JMF | 12:0071cb144c7a | 94 | return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); |
JMF | 12:0071cb144c7a | 95 | |
JMF | 12:0071cb144c7a | 96 | *len = ( (size_t)(*p)[1] << 24 ) | ( (size_t)(*p)[2] << 16 ) | |
JMF | 12:0071cb144c7a | 97 | ( (size_t)(*p)[3] << 8 ) | (*p)[4]; |
JMF | 12:0071cb144c7a | 98 | (*p) += 5; |
JMF | 12:0071cb144c7a | 99 | break; |
JMF | 12:0071cb144c7a | 100 | |
JMF | 12:0071cb144c7a | 101 | default: |
JMF | 12:0071cb144c7a | 102 | return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); |
JMF | 12:0071cb144c7a | 103 | } |
JMF | 12:0071cb144c7a | 104 | } |
JMF | 12:0071cb144c7a | 105 | |
JMF | 12:0071cb144c7a | 106 | if( *len > (size_t) ( end - *p ) ) |
JMF | 12:0071cb144c7a | 107 | return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); |
JMF | 12:0071cb144c7a | 108 | |
JMF | 12:0071cb144c7a | 109 | return( 0 ); |
JMF | 12:0071cb144c7a | 110 | } |
JMF | 12:0071cb144c7a | 111 | |
JMF | 12:0071cb144c7a | 112 | int mbedtls_asn1_get_tag( unsigned char **p, |
JMF | 12:0071cb144c7a | 113 | const unsigned char *end, |
JMF | 12:0071cb144c7a | 114 | size_t *len, int tag ) |
JMF | 12:0071cb144c7a | 115 | { |
JMF | 12:0071cb144c7a | 116 | if( ( end - *p ) < 1 ) |
JMF | 12:0071cb144c7a | 117 | return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); |
JMF | 12:0071cb144c7a | 118 | |
JMF | 12:0071cb144c7a | 119 | if( **p != tag ) |
JMF | 12:0071cb144c7a | 120 | return( MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ); |
JMF | 12:0071cb144c7a | 121 | |
JMF | 12:0071cb144c7a | 122 | (*p)++; |
JMF | 12:0071cb144c7a | 123 | |
JMF | 12:0071cb144c7a | 124 | return( mbedtls_asn1_get_len( p, end, len ) ); |
JMF | 12:0071cb144c7a | 125 | } |
JMF | 12:0071cb144c7a | 126 | |
JMF | 12:0071cb144c7a | 127 | int mbedtls_asn1_get_bool( unsigned char **p, |
JMF | 12:0071cb144c7a | 128 | const unsigned char *end, |
JMF | 12:0071cb144c7a | 129 | int *val ) |
JMF | 12:0071cb144c7a | 130 | { |
JMF | 12:0071cb144c7a | 131 | int ret; |
JMF | 12:0071cb144c7a | 132 | size_t len; |
JMF | 12:0071cb144c7a | 133 | |
JMF | 12:0071cb144c7a | 134 | if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_BOOLEAN ) ) != 0 ) |
JMF | 12:0071cb144c7a | 135 | return( ret ); |
JMF | 12:0071cb144c7a | 136 | |
JMF | 12:0071cb144c7a | 137 | if( len != 1 ) |
JMF | 12:0071cb144c7a | 138 | return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); |
JMF | 12:0071cb144c7a | 139 | |
JMF | 12:0071cb144c7a | 140 | *val = ( **p != 0 ) ? 1 : 0; |
JMF | 12:0071cb144c7a | 141 | (*p)++; |
JMF | 12:0071cb144c7a | 142 | |
JMF | 12:0071cb144c7a | 143 | return( 0 ); |
JMF | 12:0071cb144c7a | 144 | } |
JMF | 12:0071cb144c7a | 145 | |
JMF | 12:0071cb144c7a | 146 | int mbedtls_asn1_get_int( unsigned char **p, |
JMF | 12:0071cb144c7a | 147 | const unsigned char *end, |
JMF | 12:0071cb144c7a | 148 | int *val ) |
JMF | 12:0071cb144c7a | 149 | { |
JMF | 12:0071cb144c7a | 150 | int ret; |
JMF | 12:0071cb144c7a | 151 | size_t len; |
JMF | 12:0071cb144c7a | 152 | |
JMF | 12:0071cb144c7a | 153 | if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 ) |
JMF | 12:0071cb144c7a | 154 | return( ret ); |
JMF | 12:0071cb144c7a | 155 | |
JMF | 12:0071cb144c7a | 156 | if( len > sizeof( int ) || ( **p & 0x80 ) != 0 ) |
JMF | 12:0071cb144c7a | 157 | return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); |
JMF | 12:0071cb144c7a | 158 | |
JMF | 12:0071cb144c7a | 159 | *val = 0; |
JMF | 12:0071cb144c7a | 160 | |
JMF | 12:0071cb144c7a | 161 | while( len-- > 0 ) |
JMF | 12:0071cb144c7a | 162 | { |
JMF | 12:0071cb144c7a | 163 | *val = ( *val << 8 ) | **p; |
JMF | 12:0071cb144c7a | 164 | (*p)++; |
JMF | 12:0071cb144c7a | 165 | } |
JMF | 12:0071cb144c7a | 166 | |
JMF | 12:0071cb144c7a | 167 | return( 0 ); |
JMF | 12:0071cb144c7a | 168 | } |
JMF | 12:0071cb144c7a | 169 | |
JMF | 12:0071cb144c7a | 170 | #if defined(MBEDTLS_BIGNUM_C) |
JMF | 12:0071cb144c7a | 171 | int mbedtls_asn1_get_mpi( unsigned char **p, |
JMF | 12:0071cb144c7a | 172 | const unsigned char *end, |
JMF | 12:0071cb144c7a | 173 | mbedtls_mpi *X ) |
JMF | 12:0071cb144c7a | 174 | { |
JMF | 12:0071cb144c7a | 175 | int ret; |
JMF | 12:0071cb144c7a | 176 | size_t len; |
JMF | 12:0071cb144c7a | 177 | |
JMF | 12:0071cb144c7a | 178 | if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 ) |
JMF | 12:0071cb144c7a | 179 | return( ret ); |
JMF | 12:0071cb144c7a | 180 | |
JMF | 12:0071cb144c7a | 181 | ret = mbedtls_mpi_read_binary( X, *p, len ); |
JMF | 12:0071cb144c7a | 182 | |
JMF | 12:0071cb144c7a | 183 | *p += len; |
JMF | 12:0071cb144c7a | 184 | |
JMF | 12:0071cb144c7a | 185 | return( ret ); |
JMF | 12:0071cb144c7a | 186 | } |
JMF | 12:0071cb144c7a | 187 | #endif /* MBEDTLS_BIGNUM_C */ |
JMF | 12:0071cb144c7a | 188 | |
JMF | 12:0071cb144c7a | 189 | int mbedtls_asn1_get_bitstring( unsigned char **p, const unsigned char *end, |
JMF | 12:0071cb144c7a | 190 | mbedtls_asn1_bitstring *bs) |
JMF | 12:0071cb144c7a | 191 | { |
JMF | 12:0071cb144c7a | 192 | int ret; |
JMF | 12:0071cb144c7a | 193 | |
JMF | 12:0071cb144c7a | 194 | /* Certificate type is a single byte bitstring */ |
JMF | 12:0071cb144c7a | 195 | if( ( ret = mbedtls_asn1_get_tag( p, end, &bs->len, MBEDTLS_ASN1_BIT_STRING ) ) != 0 ) |
JMF | 12:0071cb144c7a | 196 | return( ret ); |
JMF | 12:0071cb144c7a | 197 | |
JMF | 12:0071cb144c7a | 198 | /* Check length, subtract one for actual bit string length */ |
JMF | 12:0071cb144c7a | 199 | if( bs->len < 1 ) |
JMF | 12:0071cb144c7a | 200 | return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); |
JMF | 12:0071cb144c7a | 201 | bs->len -= 1; |
JMF | 12:0071cb144c7a | 202 | |
JMF | 12:0071cb144c7a | 203 | /* Get number of unused bits, ensure unused bits <= 7 */ |
JMF | 12:0071cb144c7a | 204 | bs->unused_bits = **p; |
JMF | 12:0071cb144c7a | 205 | if( bs->unused_bits > 7 ) |
JMF | 12:0071cb144c7a | 206 | return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); |
JMF | 12:0071cb144c7a | 207 | (*p)++; |
JMF | 12:0071cb144c7a | 208 | |
JMF | 12:0071cb144c7a | 209 | /* Get actual bitstring */ |
JMF | 12:0071cb144c7a | 210 | bs->p = *p; |
JMF | 12:0071cb144c7a | 211 | *p += bs->len; |
JMF | 12:0071cb144c7a | 212 | |
JMF | 12:0071cb144c7a | 213 | if( *p != end ) |
JMF | 12:0071cb144c7a | 214 | return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); |
JMF | 12:0071cb144c7a | 215 | |
JMF | 12:0071cb144c7a | 216 | return( 0 ); |
JMF | 12:0071cb144c7a | 217 | } |
JMF | 12:0071cb144c7a | 218 | |
JMF | 12:0071cb144c7a | 219 | /* |
JMF | 12:0071cb144c7a | 220 | * Get a bit string without unused bits |
JMF | 12:0071cb144c7a | 221 | */ |
JMF | 12:0071cb144c7a | 222 | int mbedtls_asn1_get_bitstring_null( unsigned char **p, const unsigned char *end, |
JMF | 12:0071cb144c7a | 223 | size_t *len ) |
JMF | 12:0071cb144c7a | 224 | { |
JMF | 12:0071cb144c7a | 225 | int ret; |
JMF | 12:0071cb144c7a | 226 | |
JMF | 12:0071cb144c7a | 227 | if( ( ret = mbedtls_asn1_get_tag( p, end, len, MBEDTLS_ASN1_BIT_STRING ) ) != 0 ) |
JMF | 12:0071cb144c7a | 228 | return( ret ); |
JMF | 12:0071cb144c7a | 229 | |
JMF | 12:0071cb144c7a | 230 | if( (*len)-- < 2 || *(*p)++ != 0 ) |
JMF | 12:0071cb144c7a | 231 | return( MBEDTLS_ERR_ASN1_INVALID_DATA ); |
JMF | 12:0071cb144c7a | 232 | |
JMF | 12:0071cb144c7a | 233 | return( 0 ); |
JMF | 12:0071cb144c7a | 234 | } |
JMF | 12:0071cb144c7a | 235 | |
JMF | 12:0071cb144c7a | 236 | |
JMF | 12:0071cb144c7a | 237 | |
JMF | 12:0071cb144c7a | 238 | /* |
JMF | 12:0071cb144c7a | 239 | * Parses and splits an ASN.1 "SEQUENCE OF <tag>" |
JMF | 12:0071cb144c7a | 240 | */ |
JMF | 12:0071cb144c7a | 241 | int mbedtls_asn1_get_sequence_of( unsigned char **p, |
JMF | 12:0071cb144c7a | 242 | const unsigned char *end, |
JMF | 12:0071cb144c7a | 243 | mbedtls_asn1_sequence *cur, |
JMF | 12:0071cb144c7a | 244 | int tag) |
JMF | 12:0071cb144c7a | 245 | { |
JMF | 12:0071cb144c7a | 246 | int ret; |
JMF | 12:0071cb144c7a | 247 | size_t len; |
JMF | 12:0071cb144c7a | 248 | mbedtls_asn1_buf *buf; |
JMF | 12:0071cb144c7a | 249 | |
JMF | 12:0071cb144c7a | 250 | /* Get main sequence tag */ |
JMF | 12:0071cb144c7a | 251 | if( ( ret = mbedtls_asn1_get_tag( p, end, &len, |
JMF | 12:0071cb144c7a | 252 | MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) |
JMF | 12:0071cb144c7a | 253 | return( ret ); |
JMF | 12:0071cb144c7a | 254 | |
JMF | 12:0071cb144c7a | 255 | if( *p + len != end ) |
JMF | 12:0071cb144c7a | 256 | return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); |
JMF | 12:0071cb144c7a | 257 | |
JMF | 12:0071cb144c7a | 258 | while( *p < end ) |
JMF | 12:0071cb144c7a | 259 | { |
JMF | 12:0071cb144c7a | 260 | buf = &(cur->buf); |
JMF | 12:0071cb144c7a | 261 | buf->tag = **p; |
JMF | 12:0071cb144c7a | 262 | |
JMF | 12:0071cb144c7a | 263 | if( ( ret = mbedtls_asn1_get_tag( p, end, &buf->len, tag ) ) != 0 ) |
JMF | 12:0071cb144c7a | 264 | return( ret ); |
JMF | 12:0071cb144c7a | 265 | |
JMF | 12:0071cb144c7a | 266 | buf->p = *p; |
JMF | 12:0071cb144c7a | 267 | *p += buf->len; |
JMF | 12:0071cb144c7a | 268 | |
JMF | 12:0071cb144c7a | 269 | /* Allocate and assign next pointer */ |
JMF | 12:0071cb144c7a | 270 | if( *p < end ) |
JMF | 12:0071cb144c7a | 271 | { |
JMF | 12:0071cb144c7a | 272 | cur->next = (mbedtls_asn1_sequence*)mbedtls_calloc( 1, |
JMF | 12:0071cb144c7a | 273 | sizeof( mbedtls_asn1_sequence ) ); |
JMF | 12:0071cb144c7a | 274 | |
JMF | 12:0071cb144c7a | 275 | if( cur->next == NULL ) |
JMF | 12:0071cb144c7a | 276 | return( MBEDTLS_ERR_ASN1_ALLOC_FAILED ); |
JMF | 12:0071cb144c7a | 277 | |
JMF | 12:0071cb144c7a | 278 | cur = cur->next; |
JMF | 12:0071cb144c7a | 279 | } |
JMF | 12:0071cb144c7a | 280 | } |
JMF | 12:0071cb144c7a | 281 | |
JMF | 12:0071cb144c7a | 282 | /* Set final sequence entry's next pointer to NULL */ |
JMF | 12:0071cb144c7a | 283 | cur->next = NULL; |
JMF | 12:0071cb144c7a | 284 | |
JMF | 12:0071cb144c7a | 285 | if( *p != end ) |
JMF | 12:0071cb144c7a | 286 | return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); |
JMF | 12:0071cb144c7a | 287 | |
JMF | 12:0071cb144c7a | 288 | return( 0 ); |
JMF | 12:0071cb144c7a | 289 | } |
JMF | 12:0071cb144c7a | 290 | |
JMF | 12:0071cb144c7a | 291 | int mbedtls_asn1_get_alg( unsigned char **p, |
JMF | 12:0071cb144c7a | 292 | const unsigned char *end, |
JMF | 12:0071cb144c7a | 293 | mbedtls_asn1_buf *alg, mbedtls_asn1_buf *params ) |
JMF | 12:0071cb144c7a | 294 | { |
JMF | 12:0071cb144c7a | 295 | int ret; |
JMF | 12:0071cb144c7a | 296 | size_t len; |
JMF | 12:0071cb144c7a | 297 | |
JMF | 12:0071cb144c7a | 298 | if( ( ret = mbedtls_asn1_get_tag( p, end, &len, |
JMF | 12:0071cb144c7a | 299 | MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) |
JMF | 12:0071cb144c7a | 300 | return( ret ); |
JMF | 12:0071cb144c7a | 301 | |
JMF | 12:0071cb144c7a | 302 | if( ( end - *p ) < 1 ) |
JMF | 12:0071cb144c7a | 303 | return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); |
JMF | 12:0071cb144c7a | 304 | |
JMF | 12:0071cb144c7a | 305 | alg->tag = **p; |
JMF | 12:0071cb144c7a | 306 | end = *p + len; |
JMF | 12:0071cb144c7a | 307 | |
JMF | 12:0071cb144c7a | 308 | if( ( ret = mbedtls_asn1_get_tag( p, end, &alg->len, MBEDTLS_ASN1_OID ) ) != 0 ) |
JMF | 12:0071cb144c7a | 309 | return( ret ); |
JMF | 12:0071cb144c7a | 310 | |
JMF | 12:0071cb144c7a | 311 | alg->p = *p; |
JMF | 12:0071cb144c7a | 312 | *p += alg->len; |
JMF | 12:0071cb144c7a | 313 | |
JMF | 12:0071cb144c7a | 314 | if( *p == end ) |
JMF | 12:0071cb144c7a | 315 | { |
JMF | 12:0071cb144c7a | 316 | mbedtls_zeroize( params, sizeof(mbedtls_asn1_buf) ); |
JMF | 12:0071cb144c7a | 317 | return( 0 ); |
JMF | 12:0071cb144c7a | 318 | } |
JMF | 12:0071cb144c7a | 319 | |
JMF | 12:0071cb144c7a | 320 | params->tag = **p; |
JMF | 12:0071cb144c7a | 321 | (*p)++; |
JMF | 12:0071cb144c7a | 322 | |
JMF | 12:0071cb144c7a | 323 | if( ( ret = mbedtls_asn1_get_len( p, end, ¶ms->len ) ) != 0 ) |
JMF | 12:0071cb144c7a | 324 | return( ret ); |
JMF | 12:0071cb144c7a | 325 | |
JMF | 12:0071cb144c7a | 326 | params->p = *p; |
JMF | 12:0071cb144c7a | 327 | *p += params->len; |
JMF | 12:0071cb144c7a | 328 | |
JMF | 12:0071cb144c7a | 329 | if( *p != end ) |
JMF | 12:0071cb144c7a | 330 | return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); |
JMF | 12:0071cb144c7a | 331 | |
JMF | 12:0071cb144c7a | 332 | return( 0 ); |
JMF | 12:0071cb144c7a | 333 | } |
JMF | 12:0071cb144c7a | 334 | |
JMF | 12:0071cb144c7a | 335 | int mbedtls_asn1_get_alg_null( unsigned char **p, |
JMF | 12:0071cb144c7a | 336 | const unsigned char *end, |
JMF | 12:0071cb144c7a | 337 | mbedtls_asn1_buf *alg ) |
JMF | 12:0071cb144c7a | 338 | { |
JMF | 12:0071cb144c7a | 339 | int ret; |
JMF | 12:0071cb144c7a | 340 | mbedtls_asn1_buf params; |
JMF | 12:0071cb144c7a | 341 | |
JMF | 12:0071cb144c7a | 342 | memset( ¶ms, 0, sizeof(mbedtls_asn1_buf) ); |
JMF | 12:0071cb144c7a | 343 | |
JMF | 12:0071cb144c7a | 344 | if( ( ret = mbedtls_asn1_get_alg( p, end, alg, ¶ms ) ) != 0 ) |
JMF | 12:0071cb144c7a | 345 | return( ret ); |
JMF | 12:0071cb144c7a | 346 | |
JMF | 12:0071cb144c7a | 347 | if( ( params.tag != MBEDTLS_ASN1_NULL && params.tag != 0 ) || params.len != 0 ) |
JMF | 12:0071cb144c7a | 348 | return( MBEDTLS_ERR_ASN1_INVALID_DATA ); |
JMF | 12:0071cb144c7a | 349 | |
JMF | 12:0071cb144c7a | 350 | return( 0 ); |
JMF | 12:0071cb144c7a | 351 | } |
JMF | 12:0071cb144c7a | 352 | |
JMF | 12:0071cb144c7a | 353 | void mbedtls_asn1_free_named_data( mbedtls_asn1_named_data *cur ) |
JMF | 12:0071cb144c7a | 354 | { |
JMF | 12:0071cb144c7a | 355 | if( cur == NULL ) |
JMF | 12:0071cb144c7a | 356 | return; |
JMF | 12:0071cb144c7a | 357 | |
JMF | 12:0071cb144c7a | 358 | mbedtls_free( cur->oid.p ); |
JMF | 12:0071cb144c7a | 359 | mbedtls_free( cur->val.p ); |
JMF | 12:0071cb144c7a | 360 | |
JMF | 12:0071cb144c7a | 361 | mbedtls_zeroize( cur, sizeof( mbedtls_asn1_named_data ) ); |
JMF | 12:0071cb144c7a | 362 | } |
JMF | 12:0071cb144c7a | 363 | |
JMF | 12:0071cb144c7a | 364 | void mbedtls_asn1_free_named_data_list( mbedtls_asn1_named_data **head ) |
JMF | 12:0071cb144c7a | 365 | { |
JMF | 12:0071cb144c7a | 366 | mbedtls_asn1_named_data *cur; |
JMF | 12:0071cb144c7a | 367 | |
JMF | 12:0071cb144c7a | 368 | while( ( cur = *head ) != NULL ) |
JMF | 12:0071cb144c7a | 369 | { |
JMF | 12:0071cb144c7a | 370 | *head = cur->next; |
JMF | 12:0071cb144c7a | 371 | mbedtls_asn1_free_named_data( cur ); |
JMF | 12:0071cb144c7a | 372 | mbedtls_free( cur ); |
JMF | 12:0071cb144c7a | 373 | } |
JMF | 12:0071cb144c7a | 374 | } |
JMF | 12:0071cb144c7a | 375 | |
JMF | 12:0071cb144c7a | 376 | mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( mbedtls_asn1_named_data *list, |
JMF | 12:0071cb144c7a | 377 | const char *oid, size_t len ) |
JMF | 12:0071cb144c7a | 378 | { |
JMF | 12:0071cb144c7a | 379 | while( list != NULL ) |
JMF | 12:0071cb144c7a | 380 | { |
JMF | 12:0071cb144c7a | 381 | if( list->oid.len == len && |
JMF | 12:0071cb144c7a | 382 | memcmp( list->oid.p, oid, len ) == 0 ) |
JMF | 12:0071cb144c7a | 383 | { |
JMF | 12:0071cb144c7a | 384 | break; |
JMF | 12:0071cb144c7a | 385 | } |
JMF | 12:0071cb144c7a | 386 | |
JMF | 12:0071cb144c7a | 387 | list = list->next; |
JMF | 12:0071cb144c7a | 388 | } |
JMF | 12:0071cb144c7a | 389 | |
JMF | 12:0071cb144c7a | 390 | return( list ); |
JMF | 12:0071cb144c7a | 391 | } |
JMF | 12:0071cb144c7a | 392 | |
JMF | 12:0071cb144c7a | 393 | #endif /* MBEDTLS_ASN1_PARSE_C */ |